diff --git a/build.sh b/build.sh index 85d115b..2610770 100755 --- a/build.sh +++ b/build.sh @@ -81,8 +81,8 @@ else fi ${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm -${CC} ${CFLAGS} src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} ${FILE_LDFLAGS} -o bin/uxnemu -${CC} ${CFLAGS} src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c ${FILE_LDFLAGS} -o bin/uxncli +${CC} ${CFLAGS} src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} ${FILE_LDFLAGS} -o bin/uxnemu +${CC} ${CFLAGS} src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c src/uxncli.c ${FILE_LDFLAGS} -o bin/uxncli if [ $install = 1 ] then diff --git a/mkfile b/mkfile index a9caaca..b4bc1ef 100644 --- a/mkfile +++ b/mkfile @@ -14,6 +14,7 @@ HFILES=\ src/devices/mouse.h\ src/devices/screen.h\ src/devices/system.h\ + src/devices/console.h\ src/uxn.h\ CLEANFILES=$TARG $ROM @@ -34,19 +35,19 @@ bin: %.rom:Q: %.tal bin/uxnasm bin/uxnasm $stem.tal $target >/dev/null -bin/uxncli: file.$O datetime.$O system.$O uxncli.$O uxn.$O +bin/uxncli: file.$O datetime.$O system.$O console.$O uxncli.$O uxn.$O $LD $LDFLAGS -o $target $prereq bin/uxnasm: uxnasm.$O $LD $LDFLAGS -o $target $prereq -bin/uxnemu: audio.$O controller.$O datetime.$O file.$O mouse.$O screen.$O system.$O uxn.$O uxnemu.$O +bin/uxnemu: audio.$O controller.$O datetime.$O file.$O mouse.$O screen.$O system.$O console.$O uxn.$O uxnemu.$O $LD $LDFLAGS -o $target $prereq (uxnasm|uxncli|uxnemu|uxn)\.$O:R: src/\1.c $CC $CFLAGS -Isrc -o $target src/$stem1.c -(audio|controller|datetime|file|mouse|screen|system)\.$O:R: src/devices/\1.c +(audio|controller|datetime|file|mouse|screen|system|console)\.$O:R: src/devices/\1.c $CC $CFLAGS -Isrc -o $target src/devices/$stem1.c nuke:V: clean diff --git a/src/devices/audio.h b/src/devices/audio.h index bbf4afd..eab4c47 100644 --- a/src/devices/audio.h +++ b/src/devices/audio.h @@ -12,6 +12,11 @@ WITH REGARD TO THIS SOFTWARE. typedef signed int Sint32; + +#define AUDIO_VERSION 1 +#define AUDIO_DEIMASK 0x0000 +#define AUDIO_DEOMASK 0x0000 + #define SAMPLE_FREQUENCY 44100 #define POLYPHONY 4 diff --git a/src/devices/console.c b/src/devices/console.c new file mode 100644 index 0000000..db0dd20 --- /dev/null +++ b/src/devices/console.c @@ -0,0 +1,40 @@ +#include +#include + +#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, int type) +{ + Uint8 *d = &u->dev[0x10]; + d[0x2] = c; + d[0x7] = type; + return uxn_eval(u, PEEK2(d)); +} + +void +console_deo(Uint8 *d, Uint8 port) +{ + switch(port) { + case 0x8: + fputc(d[port], stdout); + fflush(stdout); + return; + case 0x9: + fputc(d[port], stderr); + fflush(stderr); + return; + } +} \ No newline at end of file diff --git a/src/devices/console.h b/src/devices/console.h new file mode 100644 index 0000000..7e10d5b --- /dev/null +++ b/src/devices/console.h @@ -0,0 +1,22 @@ +/* +Copyright (c) 2022 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. +*/ + +#define CONSOLE_VERSION 1 +#define CONSOLE_DEIMASK 0x0000 +#define CONSOLE_DEOMASK 0x0000 + +#define CONSOLE_STD 0x1 +#define CONSOLE_ARG 0x2 +#define CONSOLE_EOA 0x3 +#define CONSOLE_END 0x4 + +int console_input(Uxn *u, char c, int type); +void console_deo(Uint8 *d, Uint8 port); diff --git a/src/devices/controller.h b/src/devices/controller.h index 487cb86..bbc68e1 100644 --- a/src/devices/controller.h +++ b/src/devices/controller.h @@ -9,6 +9,10 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +#define CONTROL_VERSION 1 +#define CONTROL_DEIMASK 0x0000 +#define CONTROL_DEOMASK 0x0000 + void controller_down(Uxn *u, Uint8 *d, Uint8 mask); void controller_up(Uxn *u, Uint8 *d, Uint8 mask); void controller_key(Uxn *u, Uint8 *d, Uint8 key); diff --git a/src/devices/datetime.h b/src/devices/datetime.h index d007531..c01f70f 100644 --- a/src/devices/datetime.h +++ b/src/devices/datetime.h @@ -9,4 +9,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +#define DATETIME_VERSION 1 +#define DATETIME_DEIMASK 0x0000 +#define DATETIME_DEOMASK 0x0000 + Uint8 datetime_dei(Uxn *u, Uint8 addr); diff --git a/src/devices/file.h b/src/devices/file.h index c839cfc..7bdb6a0 100644 --- a/src/devices/file.h +++ b/src/devices/file.h @@ -9,6 +9,10 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +#define FILE_VERSION 1 +#define FILE_DEIMASK 0x0000 +#define FILE_DEOMASK 0x0000 + #define POLYFILEY 2 #define DEV_FILE0 0xa diff --git a/src/devices/mouse.h b/src/devices/mouse.h index d63ded8..d422f92 100644 --- a/src/devices/mouse.h +++ b/src/devices/mouse.h @@ -9,6 +9,11 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ + +#define MOUSE_VERSION 1 +#define MOUSE_DEIMASK 0x0000 +#define MOUSE_DEOMASK 0x0000 + void mouse_down(Uxn *u, Uint8 *d, Uint8 mask); void mouse_up(Uxn *u, Uint8 *d, Uint8 mask); void mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y); diff --git a/src/devices/screen.h b/src/devices/screen.h index 6620909..e392e5e 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -10,6 +10,10 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +#define SCREEN_VERSION 1 +#define SCREEN_DEIMASK 0x0000 +#define SCREEN_DEOMASK 0x0000 + typedef struct UxnScreen { int width, height, x1, y1, x2, y2; Uint32 palette[4], *pixels; diff --git a/src/devices/system.c b/src/devices/system.c index 0c7b4c4..82e09a9 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -96,32 +96,6 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port) } } -/* Console */ - -int -console_input(Uxn *u, char c, int type) -{ - Uint8 *d = &u->dev[0x10]; - d[0x2] = c; - d[0x7] = type; - return uxn_eval(u, PEEK2(d)); -} - -void -console_deo(Uint8 *d, Uint8 port) -{ - switch(port) { - case 0x8: - fputc(d[port], stdout); - fflush(stdout); - return; - case 0x9: - fputc(d[port], stderr); - fflush(stderr); - return; - } -} - /* Errors */ int diff --git a/src/devices/system.h b/src/devices/system.h index 9059736..a4efdce 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -9,16 +9,13 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -#define RAM_PAGES 0x10 +#define SYSTEM_VERSION 1 +#define SYSTEM_DEIMASK 0x0000 +#define SYSTEM_DEOMASK 0x0000 -#define CONSOLE_STD 0x1 -#define CONSOLE_ARG 0x2 -#define CONSOLE_EOA 0x3 -#define CONSOLE_END 0x4 +#define RAM_PAGES 0x10 int system_load(Uxn *u, char *filename); void system_inspect(Uxn *u); int system_error(char *msg, const char *err); void system_deo(Uxn *u, Uint8 *d, Uint8 port); -int console_input(Uxn *u, char c, int type); -void console_deo(Uint8 *d, Uint8 port); diff --git a/src/uxncli.c b/src/uxncli.c index bbeb519..3250a78 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -3,6 +3,7 @@ #include "uxn.h" #include "devices/system.h" +#include "devices/console.h" #include "devices/file.h" #include "devices/datetime.h" diff --git a/src/uxnemu.c b/src/uxnemu.c index 1334f2b..7ad5b9b 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -10,6 +10,7 @@ #pragma clang diagnostic ignored "-Wtypedef-redefinition" #include #include "devices/system.h" +#include "devices/console.h" #include "devices/screen.h" #include "devices/audio.h" #include "devices/file.h"