uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 1b1c9fc7101257f377a9c690798ed03c91d14559
parent d3081fd93d6841a04d229129ecd9294bb699a45f
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri, 25 Aug 2023 09:38:03 -0700

Make emu_masks globals

Diffstat:
Msrc/devices/system.c | 10++++++----
Msrc/devices/system.h | 4++--
Msrc/uxn.h | 9+++++----
Msrc/uxncli.c | 14++++++--------
Msrc/uxnemu.c | 29++++++++++++++---------------
5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/src/devices/system.c b/src/devices/system.c @@ -16,6 +16,8 @@ WITH REGARD TO THIS SOFTWARE. */ char *boot_rom; +Uint8 dei_masks[0x100], deo_masks[0x100]; +Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10]; static const char *errors[] = { "underflow", @@ -64,12 +66,12 @@ system_inspect(Uxn *u) } void -system_connect(Uxn *u, Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo) +system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo) { int i, d = (device << 0x4); for(i = 0; i < 0x10; i++) { - u->dei_masks[d + i] = (dei >> i) & 0x1; - u->deo_masks[d + i] = (deo >> i) & 0x1; + dei_masks[d + i] = (dei >> i) & 0x1; + deo_masks[d + i] = (deo >> i) & 0x1; } dev_vers[device] = ver; dei_mask[device] = dei; @@ -77,7 +79,7 @@ system_connect(Uxn *u, Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo) } int -system_version(Uxn *u, char *name, char *date) +system_version(char *name, char *date) { int i; printf("%s, %s.\n", name, date); diff --git a/src/devices/system.h b/src/devices/system.h @@ -17,10 +17,10 @@ WITH REGARD TO THIS SOFTWARE. extern char *boot_rom; -void system_connect(Uxn *u, Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo); +void system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo); void system_reboot(Uxn *u, char *rom, int soft); void system_inspect(Uxn *u); -int system_version(Uxn *u, char *emulator, char *date); +int system_version(char *emulator, char *date); int system_error(char *msg, const char *err); int system_init(Uxn *u, Uint8 *ram, char *rom); diff --git a/src/uxn.h b/src/uxn.h @@ -11,10 +11,10 @@ WITH REGARD TO THIS SOFTWARE. /* clang-format off */ -#define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); } #define PEEK2(d) (*(d) << 8 | (d)[1]) -#define DEI(p) (u->dei_masks[p] ? emu_dei(u, (p)) : u->dev[(p)]) -#define DEO(p, v) { u->dev[p] = v; if(u->deo_masks[p]) emu_deo(u, p); } +#define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); } +#define DEI(p) (dei_masks[p] ? emu_dei(u, (p)) : u->dev[(p)]) +#define DEO(p, v) { u->dev[p] = v; if(deo_masks[p]) emu_deo(u, p); } /* clang-format on */ @@ -31,7 +31,7 @@ typedef struct { } Stack; typedef struct Uxn { - Uint8 *ram, dev[0x100], dei_masks[0x100], deo_masks[0x100]; + Uint8 *ram, dev[0x100]; Stack wst, rst; } Uxn; @@ -40,6 +40,7 @@ typedef struct Uxn { extern Uint8 emu_dei(Uxn *u, Uint8 addr); extern void emu_deo(Uxn *u, Uint8 addr); extern int emu_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr); +extern Uint8 dei_masks[0x100], deo_masks[0x100]; extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10]; /* built-ins */ diff --git a/src/uxncli.c b/src/uxncli.c @@ -18,8 +18,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10]; - Uint8 emu_dei(Uxn *u, Uint8 addr) { @@ -67,14 +65,14 @@ main(int argc, char **argv) if(i == argc) return system_error("usage", "uxncli [-v] file.rom [args..]"); /* Connect Varvara */ - system_connect(&u, 0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK); - system_connect(&u, 0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK); - system_connect(&u, 0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); - system_connect(&u, 0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); - system_connect(&u, 0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK); + system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK); + system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK); + system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); + system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); + system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK); /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') - return system_version(&u, "Uxncli - Console Varvara Emulator", "19 Aug 2023"); + return system_version("Uxncli - Console Varvara Emulator", "19 Aug 2023"); if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) return system_error("Init", "Failed to initialize uxn."); /* Game Loop */ diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -59,8 +59,6 @@ static int window_created = 0; static Uint32 stdin_event, audio0_event, zoom = 1; static Uint64 exec_deadline, deadline_interval, ms_interval; -Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10]; - static int clamp(int v, int min, int max) { @@ -485,6 +483,7 @@ emu_run(Uxn *u, char *rom) static int emu_end(Uxn *u) { + free(u->ram); #ifdef _WIN32 #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0); @@ -503,21 +502,21 @@ main(int argc, char **argv) if(i == argc) return system_error("usage", "uxnemu [-v][-2x][-3x] file.rom [args...]"); /* Connect Varvara */ - system_connect(&u, 0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK); - system_connect(&u, 0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK); - system_connect(&u, 0x2, SCREEN_VERSION, SCREEN_DEIMASK, SCREEN_DEOMASK); - system_connect(&u, 0x3, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); - system_connect(&u, 0x4, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); - system_connect(&u, 0x5, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); - system_connect(&u, 0x6, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); - system_connect(&u, 0x8, CONTROL_VERSION, CONTROL_DEIMASK, CONTROL_DEOMASK); - system_connect(&u, 0x9, MOUSE_VERSION, MOUSE_DEIMASK, MOUSE_DEOMASK); - system_connect(&u, 0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); - system_connect(&u, 0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); - system_connect(&u, 0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK); + system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK); + system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK); + system_connect(0x2, SCREEN_VERSION, SCREEN_DEIMASK, SCREEN_DEOMASK); + system_connect(0x3, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); + system_connect(0x4, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); + system_connect(0x5, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); + system_connect(0x6, AUDIO_VERSION, AUDIO_DEIMASK, AUDIO_DEOMASK); + system_connect(0x8, CONTROL_VERSION, CONTROL_DEIMASK, CONTROL_DEOMASK); + system_connect(0x9, MOUSE_VERSION, MOUSE_DEIMASK, MOUSE_DEOMASK); + system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); + system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK); + system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK); /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') - return system_version(&u, "Uxnemu - Graphical Varvara Emulator", "19 Aug 2023"); + return system_version("Uxnemu - Graphical Varvara Emulator", "19 Aug 2023"); if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) set_zoom(argv[i++][1] - '0', 0); if(!emu_init())