Removed GETVEC macro

This commit is contained in:
Devine Lu Linvega 2023-04-10 10:08:40 -07:00
parent 5917f409c5
commit 416f37c71a
9 changed files with 65 additions and 33 deletions

View File

@ -2,8 +2,8 @@
RELEASE_FLAGS="-Os -DNDEBUG -g0 -s" RELEASE_FLAGS="-Os -DNDEBUG -g0 -s"
DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined" DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined"
EMU_INC="src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11" EMU_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11"
CLI_INC="src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli" CLI_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli"
# find X11 libs on various systems # find X11 libs on various systems
if [ -e /usr/X11R6 ]; then if [ -e /usr/X11R6 ]; then

35
src/devices/console.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include "../uxn.h"
#include "console.h"
/*
Copyright (c) 2022-2023 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
int
console_input(Uxn *u, char c)
{
Uint8 *d = &u->dev[0x10];
d[0x02] = c;
return uxn_eval(u, PEEK2(d));
}
void
console_deo(Uint8 *d, Uint8 port)
{
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr :
0;
if(fd) {
fputc(d[port], fd);
fflush(fd);
}
}

13
src/devices/console.h Normal file
View File

@ -0,0 +1,13 @@
/*
Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
int console_input(Uxn *u, char c);
void console_deo(Uint8 *d, Uint8 port);

View File

@ -17,7 +17,7 @@ controller_down(Uxn *u, Uint8 *d, Uint8 mask)
{ {
if(mask) { if(mask) {
d[2] |= mask; d[2] |= mask;
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
} }
} }
@ -26,7 +26,7 @@ controller_up(Uxn *u, Uint8 *d, Uint8 mask)
{ {
if(mask) { if(mask) {
d[2] &= (~mask); d[2] &= (~mask);
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
} }
} }
@ -35,7 +35,7 @@ controller_key(Uxn *u, Uint8 *d, Uint8 key)
{ {
if(key) { if(key) {
d[3] = key; d[3] = key;
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
d[3] = 0x00; d[3] = 0x00;
} }
} }

View File

@ -16,14 +16,14 @@ void
mouse_down(Uxn *u, Uint8 *d, Uint8 mask) mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
{ {
d[6] |= mask; d[6] |= mask;
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
} }
void void
mouse_up(Uxn *u, Uint8 *d, Uint8 mask) mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
{ {
d[6] &= (~mask); d[6] &= (~mask);
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
} }
void void
@ -31,7 +31,7 @@ mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{ {
POKDEV(0x2, x); POKDEV(0x2, x);
POKDEV(0x4, y); POKDEV(0x4, y);
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
} }
void void
@ -39,7 +39,7 @@ mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{ {
POKDEV(0xa, x); POKDEV(0xa, x);
POKDEV(0xc, -y); POKDEV(0xc, -y);
uxn_eval(u, GETVEC(d)); uxn_eval(u, PEEK2(d));
POKDEV(0xa, 0); POKDEV(0xa, 0);
POKDEV(0xc, 0); POKDEV(0xc, 0);
} }

View File

@ -89,7 +89,7 @@ int
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
{ {
Uint8 *d = &u->dev[0x00]; Uint8 *d = &u->dev[0x00];
Uint16 handler = GETVEC(d); Uint16 handler = PEEK2(d);
if(handler) { if(handler) {
u->wst->ptr = 4; u->wst->ptr = 4;
u->wst->dat[0] = addr >> 0x8; u->wst->dat[0] = addr >> 0x8;

View File

@ -19,7 +19,9 @@ typedef unsigned int Uint32;
/* clang-format off */ /* clang-format off */
#define GETVEC(d) ((d)[0] << 8 | (d)[1]) #define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
#define PEEK2(d) ((d)[0] << 8 | (d)[1])
#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); } #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; } #define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }

View File

@ -9,6 +9,7 @@
#include "uxn.h" #include "uxn.h"
#include "devices/system.h" #include "devices/system.h"
#include "devices/console.h"
#include "devices/screen.h" #include "devices/screen.h"
#include "devices/controller.h" #include "devices/controller.h"
#include "devices/mouse.h" #include "devices/mouse.h"
@ -46,25 +47,6 @@ emu_error(char *msg, const char *err)
return 0; return 0;
} }
static int
console_input(Uxn *u, char c)
{
Uint8 *d = &u->dev[0x10];
d[0x02] = c;
return uxn_eval(u, GETVEC(d));
}
static void
console_deo(Uint8 *d, Uint8 port)
{
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr :
0;
if(fd) {
fputc(d[port], fd);
fflush(fd);
}
}
static Uint8 static Uint8
emu_dei(Uxn *u, Uint8 addr) emu_dei(Uxn *u, Uint8 addr)
{ {
@ -260,8 +242,8 @@ main(int argc, char **argv)
while(XPending(display)) while(XPending(display))
emu_event(&u); emu_event(&u);
if(poll(&fds[1], 1, 0)) { if(poll(&fds[1], 1, 0)) {
read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */ read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */
uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */ uxn_eval(&u, PEEK2(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
} }
if((fds[2].revents & POLLIN) != 0) { if((fds[2].revents & POLLIN) != 0) {
n = read(fds[2].fd, coninp, CONINBUFSIZE - 1); n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);

View File

@ -31,7 +31,7 @@ console_input(Uxn *u, char c)
{ {
Uint8 *d = &u->dev[0x10]; Uint8 *d = &u->dev[0x10];
d[0x02] = c; d[0x02] = c;
return uxn_eval(u, GETVEC(d)); return uxn_eval(u, PEEK2(d));
} }
static void static void