uxn

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

commit b324bac097bc5b8acf77e8606f71ac6609bb893a
parent 594fd475a242da18a8607535030a3c533c68ca8e
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sat, 18 Jan 2025 19:51:54 -0800

Removed bios core

Diffstat:
Msrc/devices/audio.c | 2+-
Msrc/devices/console.c | 11++++++-----
Msrc/devices/console.h | 6+++---
Msrc/devices/controller.c | 6+++---
Msrc/devices/mouse.c | 8++++----
Msrc/devices/system.c | 2401++-----------------------------------------------------------------------------
Msrc/devices/system.h | 8++++----
Msrc/uxn.c | 42+++++++++++++++++++++---------------------
Msrc/uxn.h | 10+++++-----
Msrc/uxncli.c | 25+++++++++----------------
Msrc/uxnemu.c | 27+++++++++++----------------
11 files changed, 105 insertions(+), 2441 deletions(-)

diff --git a/src/devices/audio.c b/src/devices/audio.c @@ -250,7 +250,7 @@ audio_handler(void *ctx, Uint8 *out_stream, int len) Uxn *u = (Uxn *)ctx; Uint8 *addr = &u->dev[device]; if(channel[n].duration <= 0 && PEEK2(addr)) { - uxn_eval(&uxn, PEEK2(addr)); + uxn_eval(PEEK2(addr)); } channel[n].duration -= SOUND_TIMER; int x = 0; diff --git a/src/devices/console.c b/src/devices/console.c @@ -16,11 +16,12 @@ WITH REGARD TO THIS SOFTWARE. */ int -console_input(Uint8 c, int type) +console_input(int c, int type) { - uxn.dev[0x12] = c; - uxn.dev[0x17] = type; - return uxn_eval(&uxn, PEEK2(&uxn.dev[0x10])); + if(c == EOF) c = 0, type = 4; + uxn.dev[0x12] = c, uxn.dev[0x17] = type; + uxn_eval(uxn.dev[0x10] << 8 | uxn.dev[0x11]); + return type != 4; } void @@ -34,7 +35,7 @@ console_listen(int i, int argc, char **argv) } void -console_deo(Uxn *u, Uint8 addr) +console_deo(Uint8 addr) { FILE *fd; switch(addr) { diff --git a/src/devices/console.h b/src/devices/console.h @@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE. #define CONSOLE_EOA 0x3 #define CONSOLE_END 0x4 -int console_input(Uint8 c, int type); +int console_input(int c, int type); void console_listen(int i, int argc, char **argv); -Uint8 console_dei(Uxn *u, Uint8 addr); -void console_deo(Uxn *u, Uint8 addr); +Uint8 console_dei(Uint8 addr); +void console_deo(Uint8 addr); diff --git a/src/devices/controller.c b/src/devices/controller.c @@ -17,7 +17,7 @@ controller_down(Uint8 mask) { if(mask) { uxn.dev[0x82] |= mask; - uxn_eval(&uxn, PEEK2(&uxn.dev[0x80])); + uxn_eval(PEEK2(&uxn.dev[0x80])); } } @@ -26,7 +26,7 @@ controller_up(Uint8 mask) { if(mask) { uxn.dev[0x82] &= (~mask); - uxn_eval(&uxn, PEEK2(&uxn.dev[0x80])); + uxn_eval(PEEK2(&uxn.dev[0x80])); } } @@ -35,7 +35,7 @@ controller_key(Uint8 key) { if(key) { uxn.dev[0x83] = key; - uxn_eval(&uxn, PEEK2(&uxn.dev[0x80])); + uxn_eval(PEEK2(&uxn.dev[0x80])); uxn.dev[0x83] = 0; } } diff --git a/src/devices/mouse.c b/src/devices/mouse.c @@ -16,14 +16,14 @@ void mouse_down(Uint8 mask) { uxn.dev[0x96] |= mask; - uxn_eval(&uxn, PEEK2(&uxn.dev[0x90])); + uxn_eval(PEEK2(&uxn.dev[0x90])); } void mouse_up(Uint8 mask) { uxn.dev[0x96] &= (~mask); - uxn_eval(&uxn, PEEK2(&uxn.dev[0x90])); + uxn_eval(PEEK2(&uxn.dev[0x90])); } void @@ -31,7 +31,7 @@ mouse_pos(Uint16 x, Uint16 y) { uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x; uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y; - uxn_eval(&uxn, PEEK2(&uxn.dev[0x90])); + uxn_eval(PEEK2(&uxn.dev[0x90])); } void @@ -39,7 +39,7 @@ mouse_scroll(Uint16 x, Uint16 y) { uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x; uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y; - uxn_eval(&uxn, PEEK2(&uxn.dev[0x90])); + uxn_eval(PEEK2(&uxn.dev[0x90])); uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0; uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0; } diff --git a/src/devices/system.c b/src/devices/system.c @@ -16,2338 +16,17 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -Uxn bios; char *boot_rom; -static unsigned char bios_rom[] = { - 0xa0, - 0x01, - 0x14, - 0x80, - 0x20, - 0x37, - 0x80, - 0x24, - 0x36, - 0xa0, - 0x00, - 0x30, - 0x39, - 0x80, - 0x17, - 0x33, - 0x60, - 0x00, - 0x80, - 0x00, - 0x80, - 0x00, - 0x81, - 0x80, - 0xfb, - 0x13, - 0x80, - 0x07, - 0x1c, - 0x20, - 0x00, - 0x72, - 0xa0, - 0x00, - 0x08, - 0x80, - 0x28, - 0x37, - 0xa0, - 0x00, - 0x00, - 0x80, - 0x2a, - 0x37, - 0xa0, - 0x80, - 0x00, - 0x80, - 0x04, - 0x16, - 0xa0, - 0x03, - 0x35, - 0x60, - 0x00, - 0xed, - 0xa0, - 0x00, - 0x08, - 0x80, - 0x28, - 0x37, - 0x80, - 0x2a, - 0xb6, - 0xa0, - 0x00, - 0x19, - 0x38, - 0x05, - 0x37, - 0xa0, - 0x81, - 0x00, - 0x80, - 0x05, - 0x16, - 0xa0, - 0x03, - 0x39, - 0x60, - 0x00, - 0xd2, - 0x80, - 0x01, - 0x20, - 0x00, - 0x3a, - 0xa0, - 0x00, - 0x28, - 0x80, - 0x28, - 0x37, - 0xa0, - 0x00, - 0x08, - 0x80, - 0x2a, - 0x37, - 0x80, - 0x01, - 0xa0, - 0x03, - 0x0e, - 0x15, - 0xa0, - 0x0a, - 0x0e, - 0x60, - 0x01, - 0x49, - 0xa0, - 0x00, - 0x00, - 0x1d, - 0x20, - 0x00, - 0x01, - 0x00, - 0xa0, - 0x26, - 0x26, - 0x17, - 0xa0, - 0x00, - 0x08, - 0x26, - 0x80, - 0x28, - 0x37, - 0x80, - 0x2a, - 0x37, - 0xa0, - 0x09, - 0x7d, - 0x80, - 0x2c, - 0x37, - 0xa0, - 0xc5, - 0x2f, - 0x97, - 0x97, - 0x17, - 0x00, - 0xa0, - 0x02, - 0x04, - 0x80, - 0x02, - 0x37, - 0x80, - 0x65, - 0x32, - 0xa0, - 0x80, - 0x06, - 0x28, - 0x80, - 0x60, - 0x12, - 0x80, - 0x37, - 0x08, - 0x1c, - 0x20, - 0x00, - 0x01, - 0x6c, - 0x80, - 0x51, - 0x32, - 0xa0, - 0x02, - 0x14, - 0x35, - 0xa0, - 0x02, - 0x0f, - 0x80, - 0x02, - 0x37, - 0x80, - 0x00, - 0xa0, - 0x01, - 0x54, - 0x15, - 0xa0, - 0x0a, - 0x0e, - 0x60, - 0x01, - 0x4e, - 0x21, - 0x94, - 0x20, - 0x00, - 0x02, - 0x22, - 0x6c, - 0x94, - 0x0f, - 0x21, - 0x26, - 0x80, - 0x00, - 0x4f, - 0x80, - 0x03, - 0x1a, - 0x38, - 0x24, - 0x94, - 0x80, - 0x83, - 0x08, - 0x20, - 0x00, - 0x0b, - 0xa0, - 0x00, - 0x03, - 0x38, - 0xaa, - 0x20, - 0xff, - 0xf1, - 0x22, - 0x22, - 0x6c, - 0x21, - 0x34, - 0xa0, - 0x02, - 0x1f, - 0x35, - 0xa0, - 0x02, - 0x1a, - 0x80, - 0x02, - 0x37, - 0xa0, - 0x09, - 0x7d, - 0xa0, - 0x01, - 0x71, - 0x35, - 0x22, - 0x6c, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x01, - 0x00, - 0x06, - 0x00, - 0x01, - 0x01, - 0x00, - 0x00, - 0x00, - 0x01, - 0xfe, - 0x01, - 0x00, - 0x80, - 0x00, - 0x01, - 0x00, - 0x00, - 0x00, - 0x00, - 0x0a, - 0x0d, - 0x01, - 0x00, - 0x90, - 0x00, - 0x01, - 0x00, - 0x00, - 0x00, - 0x00, - 0x09, - 0x7d, - 0x60, - 0x00, - 0x91, - 0x80, - 0x28, - 0xb6, - 0xa0, - 0x00, - 0x08, - 0x38, - 0x05, - 0x37, - 0x80, - 0x03, - 0xa0, - 0x03, - 0x0e, - 0x15, - 0x06, - 0x60, - 0x00, - 0xac, - 0x80, - 0x28, - 0xb6, - 0xa0, - 0x00, - 0x08, - 0x38, - 0x05, - 0x37, - 0x80, - 0x01, - 0xa0, - 0x03, - 0x0e, - 0x15, - 0x80, - 0x08, - 0x19, - 0x80, - 0x00, - 0x04, - 0x38, - 0x26, - 0xa0, - 0x00, - 0x08, - 0x38, - 0x24, - 0x8f, - 0xcf, - 0x80, - 0x80, - 0x0b, - 0x80, - 0x02, - 0x04, - 0x19, - 0xa0, - 0x03, - 0x0e, - 0x15, - 0x94, - 0x60, - 0x00, - 0x7f, - 0xcf, - 0x80, - 0xff, - 0x09, - 0x20, - 0x00, - 0x29, - 0xa0, - 0x25, - 0x26, - 0x17, - 0xa0, - 0x03, - 0x65, - 0x80, - 0x2c, - 0x37, - 0x80, - 0x2a, - 0xb6, - 0xa0, - 0x00, - 0x04, - 0x39, - 0x05, - 0x37, - 0xa0, - 0x03, - 0x2f, - 0x17, - 0x80, - 0x28, - 0xb6, - 0xa0, - 0x00, - 0x08, - 0x39, - 0x05, - 0x37, - 0x80, - 0x2a, - 0xb6, - 0xa0, - 0x00, - 0x04, - 0x38, - 0x05, - 0x37, - 0x80, - 0x28, - 0xb6, - 0xa0, - 0x00, - 0x08, - 0x38, - 0x05, - 0x37, - 0x41, - 0x21, - 0xaa, - 0x20, - 0xff, - 0xb1, - 0x22, - 0x22, - 0x42, - 0xa0, - 0x15, - 0x26, - 0x17, - 0xa0, - 0x03, - 0x7d, - 0x80, - 0x2c, - 0x37, - 0xa0, - 0x01, - 0x2f, - 0x17, - 0x6c, - 0x80, - 0x28, - 0x36, - 0x80, - 0x0c, - 0x33, - 0xa0, - 0x15, - 0x26, - 0x17, - 0x94, - 0x80, - 0x0a, - 0x09, - 0x20, - 0x00, - 0x12, - 0xa0, - 0x00, - 0x00, - 0x80, - 0x28, - 0x37, - 0x80, - 0x2a, - 0xb6, - 0xa0, - 0x00, - 0x10, - 0x38, - 0x05, - 0x37, - 0x40, - 0x00, - 0x04, - 0x94, - 0x60, - 0x00, - 0x1d, - 0x21, - 0x94, - 0x20, - 0xff, - 0xde, - 0x22, - 0x6c, - 0xa0, - 0x15, - 0x26, - 0x17, - 0x06, - 0x80, - 0x04, - 0x1f, - 0x60, - 0x00, - 0x00, - 0x80, - 0x0f, - 0x1c, - 0x80, - 0x00, - 0x04, - 0xa0, - 0x03, - 0x3d, - 0x38, - 0x14, - 0x80, - 0x20, - 0x19, - 0x80, - 0x00, - 0x04, - 0x80, - 0x40, - 0x3f, - 0xa0, - 0x03, - 0x8d, - 0x38, - 0x80, - 0x2c, - 0x37, - 0xa0, - 0x01, - 0x2f, - 0x17, - 0x6c, - 0x21, - 0x94, - 0x20, - 0xff, - 0xfb, - 0x6c, - 0x04, - 0x60, - 0x00, - 0x00, - 0x06, - 0x80, - 0x04, - 0x1f, - 0x60, - 0x00, - 0x00, - 0x80, - 0x0f, - 0x1c, - 0x06, - 0x80, - 0x09, - 0x0a, - 0x80, - 0x27, - 0x1a, - 0x18, - 0x80, - 0x30, - 0x18, - 0x80, - 0x19, - 0x17, - 0x6c, - 0x57, - 0x53, - 0x54, - 0x00, - 0x52, - 0x53, - 0x54, - 0x00, - 0x30, - 0x31, - 0x32, - 0x33, - 0x34, - 0x35, - 0x36, - 0x37, - 0x38, - 0x39, - 0x61, - 0x62, - 0x63, - 0x64, - 0x65, - 0x66, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xff, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x10, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x20, - 0x40, - 0x80, - 0x40, - 0x20, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x38, - 0x38, - 0x38, - 0x38, - 0x38, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, - 0x00, - 0x10, - 0x38, - 0x10, - 0x6c, - 0x6c, - 0x24, - 0x24, - 0x48, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x12, - 0x12, - 0x12, - 0x7f, - 0x24, - 0x24, - 0x24, - 0x24, - 0x24, - 0xfe, - 0x48, - 0x48, - 0x48, - 0x48, - 0x00, - 0x10, - 0x38, - 0x54, - 0x92, - 0x96, - 0x90, - 0x50, - 0x38, - 0x14, - 0x12, - 0xd2, - 0x92, - 0x94, - 0x78, - 0x10, - 0x10, - 0x02, - 0x62, - 0x94, - 0x94, - 0x94, - 0x98, - 0x68, - 0x10, - 0x10, - 0x2c, - 0x32, - 0x52, - 0x52, - 0x52, - 0x8c, - 0x80, - 0x00, - 0x30, - 0x48, - 0x48, - 0x48, - 0x50, - 0x20, - 0x2e, - 0x54, - 0x54, - 0x94, - 0x88, - 0x8c, - 0x72, - 0x00, - 0x00, - 0xe0, - 0xe0, - 0x20, - 0x20, - 0xc0, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x02, - 0x04, - 0x08, - 0x08, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x08, - 0x08, - 0x04, - 0x02, - 0x80, - 0x40, - 0x20, - 0x20, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x20, - 0x20, - 0x40, - 0x80, - 0x00, - 0x00, - 0x00, - 0x10, - 0x38, - 0x92, - 0xd6, - 0x38, - 0xd6, - 0x92, - 0x38, - 0x10, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0xfe, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xe0, - 0xe0, - 0x20, - 0x20, - 0xc0, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x40, - 0xe0, - 0xe0, - 0x40, - 0x00, - 0x02, - 0x02, - 0x04, - 0x04, - 0x08, - 0x08, - 0x08, - 0x10, - 0x10, - 0x10, - 0x20, - 0x20, - 0x40, - 0x40, - 0x80, - 0x80, - 0x00, - 0x18, - 0x24, - 0x24, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x24, - 0x24, - 0x18, - 0x00, - 0x00, - 0x10, - 0x70, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x7c, - 0x00, - 0x00, - 0x00, - 0x18, - 0x24, - 0x42, - 0x62, - 0x02, - 0x04, - 0x08, - 0x08, - 0x10, - 0x20, - 0x22, - 0x42, - 0x7e, - 0x00, - 0x00, - 0x00, - 0x38, - 0x44, - 0x82, - 0x82, - 0x02, - 0x04, - 0x38, - 0x04, - 0x02, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0x08, - 0x18, - 0x28, - 0x28, - 0x48, - 0x48, - 0x88, - 0x88, - 0xfe, - 0x08, - 0x08, - 0x08, - 0x3c, - 0x00, - 0x00, - 0x00, - 0xfc, - 0x80, - 0x80, - 0x80, - 0xb8, - 0xc4, - 0x82, - 0x02, - 0x02, - 0xc2, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0x3c, - 0x42, - 0x46, - 0x80, - 0x80, - 0xb8, - 0xc4, - 0x82, - 0x82, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x82, - 0x82, - 0x04, - 0x04, - 0x04, - 0x08, - 0x08, - 0x08, - 0x08, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, - 0x00, - 0x38, - 0x44, - 0x82, - 0x82, - 0x82, - 0x44, - 0x38, - 0x44, - 0x82, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0x38, - 0x44, - 0x82, - 0x82, - 0x82, - 0x82, - 0x46, - 0x3a, - 0x02, - 0x02, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x38, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x38, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x38, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x38, - 0x18, - 0x10, - 0x30, - 0x02, - 0x04, - 0x04, - 0x08, - 0x08, - 0x10, - 0x10, - 0x20, - 0x20, - 0x10, - 0x10, - 0x08, - 0x08, - 0x04, - 0x04, - 0x02, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x80, - 0x40, - 0x40, - 0x20, - 0x20, - 0x10, - 0x10, - 0x08, - 0x08, - 0x10, - 0x10, - 0x20, - 0x20, - 0x40, - 0x40, - 0x80, - 0x00, - 0x38, - 0x44, - 0x82, - 0xc2, - 0x02, - 0x04, - 0x04, - 0x08, - 0x10, - 0x10, - 0x00, - 0x00, - 0x10, - 0x38, - 0x10, - 0x00, - 0x3c, - 0x42, - 0x82, - 0x9a, - 0xa6, - 0xa2, - 0xa2, - 0xa2, - 0xa6, - 0x9a, - 0x80, - 0x42, - 0x3c, - 0x00, - 0x00, - 0x00, - 0x10, - 0x28, - 0x28, - 0x28, - 0x44, - 0x44, - 0x44, - 0x44, - 0x7c, - 0x82, - 0x82, - 0x82, - 0xc6, - 0x00, - 0x00, - 0x00, - 0xf8, - 0x44, - 0x42, - 0x42, - 0x42, - 0x44, - 0x78, - 0x44, - 0x42, - 0x42, - 0x42, - 0x42, - 0xfc, - 0x00, - 0x00, - 0x00, - 0x3a, - 0x46, - 0x42, - 0x80, - 0x80, - 0x80, - 0x80, - 0x80, - 0x80, - 0x82, - 0x42, - 0x42, - 0x3c, - 0x00, - 0x00, - 0x00, - 0xf8, - 0x44, - 0x44, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x44, - 0x44, - 0xf8, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x42, - 0x42, - 0x40, - 0x48, - 0x48, - 0x78, - 0x48, - 0x48, - 0x42, - 0x42, - 0x42, - 0xfe, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x42, - 0x42, - 0x40, - 0x48, - 0x48, - 0x78, - 0x48, - 0x48, - 0x40, - 0x40, - 0x40, - 0xf0, - 0x00, - 0x00, - 0x00, - 0x1a, - 0x26, - 0x42, - 0x40, - 0x80, - 0x80, - 0x8f, - 0x82, - 0x82, - 0x82, - 0x42, - 0x66, - 0x1a, - 0x00, - 0x00, - 0x00, - 0xe7, - 0x42, - 0x42, - 0x42, - 0x42, - 0x7e, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0xe7, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0xfe, - 0x00, - 0x00, - 0x00, - 0x1f, - 0x02, - 0x02, - 0x02, - 0x02, - 0x02, - 0x02, - 0x02, - 0x82, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0xe6, - 0x44, - 0x44, - 0x48, - 0x48, - 0x70, - 0x50, - 0x48, - 0x48, - 0x44, - 0x44, - 0x42, - 0xe3, - 0x00, - 0x00, - 0x00, - 0xf0, - 0x40, - 0x40, - 0x40, - 0x40, - 0x40, - 0x40, - 0x40, - 0x40, - 0x42, - 0x42, - 0x42, - 0xfe, - 0x00, - 0x00, - 0x00, - 0x82, - 0xc6, - 0xaa, - 0xaa, - 0xaa, - 0x92, - 0x92, - 0x92, - 0x82, - 0x82, - 0x82, - 0x82, - 0xc6, - 0x00, - 0x00, - 0x00, - 0x87, - 0xc2, - 0xa2, - 0xa2, - 0xa2, - 0x92, - 0x92, - 0x92, - 0x8a, - 0x8a, - 0x8a, - 0x86, - 0xc2, - 0x00, - 0x00, - 0x00, - 0x38, - 0x44, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0xf8, - 0x44, - 0x42, - 0x42, - 0x42, - 0x42, - 0x44, - 0x78, - 0x40, - 0x40, - 0x40, - 0x40, - 0xf0, - 0x00, - 0x00, - 0x00, - 0x38, - 0x44, - 0x44, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0xba, - 0x44, - 0x44, - 0x38, - 0x08, - 0x06, - 0x00, - 0xf8, - 0x44, - 0x42, - 0x42, - 0x42, - 0x44, - 0x78, - 0x48, - 0x44, - 0x44, - 0x44, - 0x42, - 0xe3, - 0x00, - 0x00, - 0x00, - 0x34, - 0x4c, - 0x84, - 0x80, - 0x80, - 0x60, - 0x18, - 0x04, - 0x82, - 0x82, - 0x82, - 0xc4, - 0xb8, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x92, - 0x92, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x7c, - 0x00, - 0x00, - 0x00, - 0xe7, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x3c, - 0x00, - 0x00, - 0x00, - 0xc6, - 0x82, - 0x82, - 0x82, - 0x82, - 0x44, - 0x44, - 0x44, - 0x44, - 0x28, - 0x28, - 0x10, - 0x10, - 0x00, - 0x00, - 0x00, - 0xc6, - 0x82, - 0x82, - 0x82, - 0x92, - 0x92, - 0x92, - 0xaa, - 0xaa, - 0xaa, - 0x44, - 0x44, - 0x44, - 0x00, - 0x00, - 0x00, - 0xee, - 0x44, - 0x44, - 0x28, - 0x28, - 0x10, - 0x28, - 0x28, - 0x28, - 0x44, - 0x44, - 0x82, - 0xc6, - 0x00, - 0x00, - 0x00, - 0xc6, - 0x82, - 0x44, - 0x44, - 0x44, - 0x28, - 0x28, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x7c, - 0x00, - 0x00, - 0x00, - 0xfe, - 0x84, - 0x88, - 0x08, - 0x10, - 0x10, - 0x10, - 0x20, - 0x20, - 0x42, - 0x42, - 0x82, - 0xfe, - 0x00, - 0x00, - 0x1e, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x1e, - 0x00, - 0x80, - 0x80, - 0x40, - 0x40, - 0x20, - 0x20, - 0x10, - 0x10, - 0x08, - 0x08, - 0x04, - 0x04, - 0x02, - 0x02, - 0x00, - 0xf0, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0xf0, - 0x10, - 0x28, - 0x44, - 0x82, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xff, - 0x30, - 0x30, - 0x20, - 0x20, - 0x10, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x3c, - 0x42, - 0x02, - 0x3e, - 0x42, - 0x82, - 0x82, - 0x86, - 0x7b, - 0x00, - 0x00, - 0x00, - 0xc0, - 0x40, - 0x40, - 0x40, - 0x78, - 0x44, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x44, - 0x78, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x3a, - 0x46, - 0x82, - 0x80, - 0x80, - 0x80, - 0x82, - 0x42, - 0x3c, - 0x00, - 0x00, - 0x00, - 0x06, - 0x04, - 0x04, - 0x04, - 0x3c, - 0x44, - 0x84, - 0x84, - 0x84, - 0x84, - 0x84, - 0x44, - 0x3e, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x44, - 0x82, - 0xfe, - 0x80, - 0x80, - 0x82, - 0x42, - 0x3c, - 0x00, - 0x00, - 0x00, - 0x0e, - 0x11, - 0x10, - 0x10, - 0xfe, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x7c, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x3b, - 0x44, - 0x44, - 0x44, - 0x38, - 0x40, - 0x78, - 0x84, - 0x82, - 0x82, - 0x7c, - 0x00, - 0xc0, - 0x40, - 0x40, - 0x40, - 0x5c, - 0x62, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0xe7, - 0x00, - 0x00, - 0x18, - 0x18, - 0x00, - 0x00, - 0x00, - 0x78, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0xff, - 0x00, - 0x00, - 0x06, - 0x06, - 0x00, - 0x00, - 0x00, - 0x3e, - 0x02, - 0x02, - 0x02, - 0x02, - 0x02, - 0x02, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0xc0, - 0x40, - 0x40, - 0x40, - 0x42, - 0x44, - 0x48, - 0x58, - 0x64, - 0x44, - 0x42, - 0x42, - 0xe3, - 0x00, - 0x00, - 0x00, - 0x78, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0xff, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x6c, - 0x92, - 0x92, - 0x92, - 0x92, - 0x92, - 0x92, - 0x92, - 0xdb, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xdc, - 0x62, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0xe7, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x44, - 0x82, - 0x82, - 0x82, - 0x82, - 0x82, - 0x44, - 0x38, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xf8, - 0x44, - 0x42, - 0x42, - 0x42, - 0x42, - 0x44, - 0x78, - 0x40, - 0x40, - 0xf0, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x3e, - 0x44, - 0x84, - 0x84, - 0x84, - 0x84, - 0x44, - 0x3c, - 0x04, - 0x04, - 0x1e, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xec, - 0x32, - 0x22, - 0x20, - 0x20, - 0x20, - 0x20, - 0x20, - 0xfc, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x3a, - 0x46, - 0x42, - 0x40, - 0x3c, - 0x02, - 0x82, - 0xc2, - 0xbc, - 0x00, - 0x00, - 0x00, - 0x00, - 0x20, - 0x20, - 0x20, - 0xfc, - 0x20, - 0x20, - 0x20, - 0x20, - 0x20, - 0x22, - 0x22, - 0x1c, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xc6, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x42, - 0x46, - 0x39, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xc6, - 0x82, - 0x82, - 0x44, - 0x44, - 0x44, - 0x28, - 0x28, - 0x10, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x92, - 0x92, - 0x92, - 0x92, - 0xaa, - 0xaa, - 0x44, - 0x44, - 0x44, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xee, - 0x44, - 0x28, - 0x28, - 0x10, - 0x28, - 0x28, - 0x44, - 0xee, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xe7, - 0x42, - 0x22, - 0x24, - 0x14, - 0x08, - 0x08, - 0x10, - 0x90, - 0xa0, - 0x40, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x7e, - 0x44, - 0x08, - 0x08, - 0x10, - 0x10, - 0x22, - 0x42, - 0xfe, - 0x00, - 0x00, - 0x06, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x10, - 0x20, - 0x10, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x06, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0xc0, - 0x20, - 0x20, - 0x20, - 0x20, - 0x20, - 0x10, - 0x08, - 0x10, - 0x20, - 0x20, - 0x20, - 0x20, - 0x20, - 0x20, - 0xc0, - 0x60, - 0x92, - 0x0c, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, - 0xaa, - 0x55, -}; - static void -system_zero(Uxn *u, int soft) +system_zero(int soft) { int i; for(i = soft ? 0x100 : 0; i < 0x10000; i++) - u->ram[i] = 0; + uxn.ram[i] = 0; for(i = 0x0; i < 0x100; i++) - u->dev[i] = 0; - u->wst.ptr = u->rst.ptr = 0; + uxn.dev[i] = 0; + uxn.wst.ptr = uxn.rst.ptr = 0; } static int @@ -2379,6 +58,18 @@ system_inspect(void) fprintf(stderr, "RST "), system_print(&uxn.rst); } +void +system_image(void) +{ + int i, len = 0; + FILE *f = fopen("image.rom", "wb"); + for(i = PAGE_PROGRAM; i < 0x10000; i++) + if(uxn.ram[i]) + len = i; + fwrite(uxn.ram + PAGE_PROGRAM, len - PAGE_PROGRAM + 1, 1, f), fclose(f); + printf("Saved image.rom, %d bytes\n", len); +} + int system_error(char *msg, const char *err) { @@ -2389,77 +80,61 @@ system_error(char *msg, const char *err) void system_reboot(int soft) { - system_zero(&uxn, soft); + system_zero(soft); if(system_load(&uxn.ram[PAGE_PROGRAM], boot_rom)) - uxn_eval(&uxn, PAGE_PROGRAM); + uxn_eval(PAGE_PROGRAM); } int system_boot(Uint8 *ram, char *boot) { - /* Load rom(bios) */ - bios.ram = ram; - bios.dev = bios.ram + 0x8300; - bios.wst.dat = bios.ram + 0x8400; - bios.rst.dat = bios.ram + 0x8500; - bios.dev[0xe] = 0xff; - if(!system_load(bios.ram + PAGE_PROGRAM, "bios.rom")) { - size_t i, bios_len = sizeof(bios_rom) / sizeof(bios_rom[0]); - for(i = 0; i < bios_len; i++) - bios.ram[PAGE_PROGRAM + i] = bios_rom[i]; - } - /* Load rom(main) */ - uxn.ram = ram + 0x10000; - uxn.dev = bios.ram + 0x8000; - uxn.wst.dat = bios.ram + 0x8100; - uxn.rst.dat = bios.ram + 0x8200; - boot_rom = boot; + uxn.ram = ram, boot_rom = boot; return system_load(uxn.ram + PAGE_PROGRAM, boot); } /* IO */ Uint8 -system_dei(Uxn *u, Uint8 addr) +system_dei(Uint8 addr) { switch(addr) { case 0x4: return uxn.wst.ptr; case 0x5: return uxn.rst.ptr; - default: return u->dev[addr]; + default: return uxn.dev[addr]; } } void -system_deo(Uxn *u, Uint8 port) +system_deo(Uint8 port) { switch(port) { case 0x3: { - Uint16 addr = PEEK2(u->dev + 2); - if(u->ram[addr] == 0x0) { - Uint16 i, value = u->ram[addr + 7], length = PEEK2(u->ram + addr + 1); - unsigned int dst_page = PEEK2(u->ram + addr + 3), dst_addr = PEEK2(u->ram + addr + 5); + Uint16 addr = PEEK2(uxn.dev + 2); + if(uxn.ram[addr] == 0x0) { + Uint16 i, value = uxn.ram[addr + 7], length = PEEK2(uxn.ram + addr + 1); + unsigned int dst_page = PEEK2(uxn.ram + addr + 3), dst_addr = PEEK2(uxn.ram + addr + 5); unsigned int dst = dst_page * 0x10000; if(dst_page < RAM_PAGES) for(i = 0; i < length; i++) - u->ram[dst + (Uint16)(dst_addr + i)] = value; - } else if(u->ram[addr] == 0x1) { - Uint16 i, length = PEEK2(u->ram + addr + 1); - unsigned int a_page = PEEK2(u->ram + addr + 3), a_addr = PEEK2(u->ram + addr + 5); - unsigned int b_page = PEEK2(u->ram + addr + 7), b_addr = PEEK2(u->ram + addr + 9); + uxn.ram[dst + (Uint16)(dst_addr + i)] = value; + } else if(uxn.ram[addr] == 0x1) { + Uint16 i, length = PEEK2(uxn.ram + addr + 1); + unsigned int a_page = PEEK2(uxn.ram + addr + 3), a_addr = PEEK2(uxn.ram + addr + 5); + unsigned int b_page = PEEK2(uxn.ram + addr + 7), b_addr = PEEK2(uxn.ram + addr + 9); unsigned int src = a_page * 0x10000, dst = b_page * 0x10000; if(a_page < RAM_PAGES && b_page < RAM_PAGES) for(i = 0; i < length; i++) - u->ram[dst + (Uint16)(b_addr + i)] = u->ram[src + (Uint16)(a_addr + i)]; - } else if(u->ram[addr] == 0x2) { - Uint16 i, length = PEEK2(u->ram + addr + 1); - unsigned int a_page = PEEK2(u->ram + addr + 3), a_addr = PEEK2(u->ram + addr + 5); - unsigned int b_page = PEEK2(u->ram + addr + 7), b_addr = PEEK2(u->ram + addr + 9); + uxn.ram[dst + (Uint16)(b_addr + i)] = uxn.ram[src + (Uint16)(a_addr + i)]; + } else if(uxn.ram[addr] == 0x2) { + Uint16 i, length = PEEK2(uxn.ram + addr + 1); + unsigned int a_page = PEEK2(uxn.ram + addr + 3), a_addr = PEEK2(uxn.ram + addr + 5); + unsigned int b_page = PEEK2(uxn.ram + addr + 7), b_addr = PEEK2(uxn.ram + addr + 9); unsigned int src = a_page * 0x10000, dst = b_page * 0x10000; if(a_page < RAM_PAGES && b_page < RAM_PAGES) for(i = length - 1; i != 0xffff; i--) - u->ram[dst + (Uint16)(b_addr + i)] = u->ram[src + (Uint16)(a_addr + i)]; + uxn.ram[dst + (Uint16)(b_addr + i)] = uxn.ram[src + (Uint16)(a_addr + i)]; } else - fprintf(stderr, "Unknown Expansion Command 0x%02x\n", u->ram[addr]); + fprintf(stderr, "Unknown Expansion Command 0x%02x\n", uxn.ram[addr]); break; } case 0x4: diff --git a/src/devices/system.h b/src/devices/system.h @@ -13,10 +13,9 @@ WITH REGARD TO THIS SOFTWARE. void system_reboot(int soft); void system_inspect(void); +void system_image(void); int system_error(char *msg, const char *err); int system_boot(Uint8 *ram, char *rom); -Uint8 system_dei(Uxn *u, Uint8 addr); -void system_deo(Uxn *u, Uint8 addr); - -extern Uxn bios; +Uint8 system_dei(Uint8 addr); +void system_deo(Uint8 addr); +\ No newline at end of file diff --git a/src/uxn.c b/src/uxn.c @@ -16,20 +16,20 @@ WITH REGARD TO THIS SOFTWARE. case 0x20|opc: {const int _2=1,_r=0;init body;} break;\ case 0x40|opc: {const int _2=0,_r=1;init body;} break;\ case 0x60|opc: {const int _2=1,_r=1;init body;} break;\ - case 0x80|opc: {const int _2=0,_r=0,k=u->wst.ptr;init u->wst.ptr=k;body;} break;\ - case 0xa0|opc: {const int _2=1,_r=0,k=u->wst.ptr;init u->wst.ptr=k;body;} break;\ - case 0xc0|opc: {const int _2=0,_r=1,k=u->rst.ptr;init u->rst.ptr=k;body;} break;\ - case 0xe0|opc: {const int _2=1,_r=1,k=u->rst.ptr;init u->rst.ptr=k;body;} break;\ + case 0x80|opc: {const int _2=0,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\ + case 0xa0|opc: {const int _2=1,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\ + case 0xc0|opc: {const int _2=0,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\ + case 0xe0|opc: {const int _2=1,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\ } /* Microcode */ -#define JMI a = u->ram[pc] << 8 | u->ram[pc + 1], pc += a + 2; -#define REM if(_r) u->rst.ptr -= 1 + _2; else u->wst.ptr -= 1 + _2; -#define INC(s) u->s.dat[u->s.ptr++] -#define DEC(s) u->s.dat[--u->s.ptr] -#define JMP(i) pc = _2 ? i : pc + (Sint8)i; -#define PO1(o) o = _r ? DEC(rst) : DEC(wst); +#define JMI a = uxn.ram[pc] << 8 | uxn.ram[pc + 1], pc += a + 2; +#define REM if(_r) uxn.rst.ptr -= 1 + _2; else uxn.wst.ptr -= 1 + _2; +#define INC(s) uxn.s.dat[uxn.s.ptr++] +#define DEC(s) uxn.s.dat[--uxn.s.ptr] +#define JMP(x) { if(_2) pc = x; else pc += (Sint8)x; } +#define PO1(o) { o = _r ? DEC(rst) : DEC(wst);} #define PO2(o) { if(_r) o = DEC(rst), o |= DEC(rst) << 8; else o = DEC(wst), o |= DEC(wst) << 8; } #define POx(o) { if(_2) PO2(o) else PO1(o) } #define PU1(i) { if(_r) INC(rst) = i; else INC(wst) = i; } @@ -37,26 +37,26 @@ WITH REGARD TO THIS SOFTWARE. #define PUx(i) { if(_2) { c = (i); PU1(c >> 8) PU1(c) } else PU1(i) } #define GET(o) { if(_2) PO1(o[1]) PO1(o[0]) } #define PUT(i) { PU1(i[0]) if(_2) PU1(i[1]) } -#define DEI(i,o) o[0] = emu_dei(u, i); if(_2) o[1] = emu_dei(u, i + 1); PUT(o) -#define DEO(i,j) emu_deo(u, i, j[0]); if(_2) emu_deo(u, i + 1, j[1]); -#define PEK(i,o,m) o[0] = u->ram[i]; if(_2) o[1] = u->ram[(i + 1) & m]; PUT(o) -#define POK(i,j,m) u->ram[i] = j[0]; if(_2) u->ram[(i + 1) & m] = j[1]; +#define DEI(i,o) o[0] = emu_dei(i); if(_2) o[1] = emu_dei(i + 1); PUT(o) +#define DEO(i,j) emu_deo(i, j[0]); if(_2) emu_deo(i + 1, j[1]); +#define PEK(i,o,m) o[0] = uxn.ram[i]; if(_2) o[1] = uxn.ram[(i + 1) & m]; PUT(o) +#define POK(i,j,m) uxn.ram[i] = j[0]; if(_2) uxn.ram[(i + 1) & m] = j[1]; int -uxn_eval(Uxn *u, Uint16 pc) +uxn_eval(Uint16 pc) { unsigned int a, b, c, x[2], y[2], z[2], step; - if(!pc || u->dev[0x0f]) return 0; + if(!pc || uxn.dev[0x0f]) return 0; for(step = STEP_MAX; step; step--) { - switch(u->ram[pc++]) { + switch(uxn.ram[pc++]) { /* BRK */ case 0x00: return 1; /* JCI */ case 0x20: if(DEC(wst)) { JMI break; } pc += 2; break; /* JMI */ case 0x40: JMI break; /* JSI */ case 0x60: c = pc + 2; INC(rst) = c >> 8; INC(rst) = c; JMI break; - /* LI2 */ case 0xa0: INC(wst) = u->ram[pc++]; /* fall-through */ - /* LIT */ case 0x80: INC(wst) = u->ram[pc++]; break; - /* L2r */ case 0xe0: INC(rst) = u->ram[pc++]; /* fall-through */ - /* LIr */ case 0xc0: INC(rst) = u->ram[pc++]; break; + /* LI2 */ case 0xa0: INC(wst) = uxn.ram[pc++]; /* fall-through */ + /* LIT */ case 0x80: INC(wst) = uxn.ram[pc++]; break; + /* L2r */ case 0xe0: INC(rst) = uxn.ram[pc++]; /* fall-through */ + /* LIr */ case 0xc0: INC(rst) = uxn.ram[pc++]; break; /* INC */ OPC(0x01,POx(a),PUx(a + 1)) /* POP */ OPC(0x02,REM ,{}) /* NIP */ OPC(0x03,GET(x) REM ,PUT(x)) diff --git a/src/uxn.h b/src/uxn.h @@ -26,16 +26,16 @@ typedef signed short Sint16; typedef unsigned int Uint32; typedef struct { - Uint8 *dat, ptr; + Uint8 dat[0x100], ptr; } Stack; typedef struct Uxn { - Uint8 *ram, *dev; + Uint8 *ram, dev[0x100]; Stack wst, rst; } Uxn; -extern Uint8 emu_dei(Uxn *u, Uint8 addr); -extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value); +extern Uint8 emu_dei(Uint8 addr); +extern void emu_deo( Uint8 addr, Uint8 value); extern Uxn uxn; -int uxn_eval(Uxn *u, Uint16 pc); +int uxn_eval(Uint16 pc); diff --git a/src/uxncli.c b/src/uxncli.c @@ -8,7 +8,7 @@ #include "devices/datetime.h" /* -Copyright (c) 2021-2024 Devine Lu Linvega, Andrew Alderwick +Copyright (c) 2021-2025 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 @@ -21,22 +21,22 @@ WITH REGARD TO THIS SOFTWARE. Uxn uxn; Uint8 -emu_dei(Uxn *u, Uint8 addr) +emu_dei(Uint8 addr) { switch(addr & 0xf0) { - case 0x00: return system_dei(u, addr); + case 0x00: return system_dei(addr); case 0xc0: return datetime_dei(addr); } return uxn.dev[addr]; } void -emu_deo(Uxn *u, Uint8 addr, Uint8 value) +emu_deo(Uint8 addr, Uint8 value) { uxn.dev[addr] = value; switch(addr & 0xf0) { - case 0x00: system_deo(u, addr); break; - case 0x10: console_deo(u, addr); break; + case 0x00: system_deo(addr); break; + case 0x10: console_deo(addr); break; case 0xa0: file_deo(addr); break; case 0xb0: file_deo(addr); break; } @@ -47,13 +47,13 @@ main(int argc, char **argv) { int i = 1; if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v') - return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 1 Jan 2025.\n"); + return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 18 Jan 2025.\n"); else if(argc == 1) return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]); uxn.dev[0x17] = argc > 2; - if(uxn_eval(&uxn, PAGE_PROGRAM) && uxn.dev[0x10]) { + if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) { /* arguments input */ for(; i < argc; i++) { char *p = argv[i]; @@ -61,14 +61,7 @@ main(int argc, char **argv) console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); } /* console input */ - while(!uxn.dev[0x0f]) { - int c = fgetc(stdin); - if(c == EOF) { - console_input(0x00, CONSOLE_END); - break; - } - console_input(c, CONSOLE_STD); - } + while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1)); } return uxn.dev[0x0f] & 0x7f; } diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -80,11 +80,11 @@ audio_deo(int instance, Uint8 *d, Uint8 port) } Uint8 -emu_dei(Uxn *u, Uint8 addr) +emu_dei(Uint8 addr) { Uint8 p = addr & 0x0f, d = addr & 0xf0; switch(d) { - case 0x00: return system_dei(u, addr); + case 0x00: return system_dei(addr); case 0x20: return screen_dei(addr); case 0x30: return audio_dei(0, &uxn.dev[d], p); case 0x40: return audio_dei(1, &uxn.dev[d], p); @@ -96,16 +96,16 @@ emu_dei(Uxn *u, Uint8 addr) } void -emu_deo(Uxn *u, Uint8 addr, Uint8 value) +emu_deo(Uint8 addr, Uint8 value) { Uint8 p = addr & 0x0f, d = addr & 0xf0; uxn.dev[addr] = value; switch(d) { case 0x00: - system_deo(u, addr); + system_deo(addr); if(p > 0x7 && p < 0xe) screen_palette(); break; - case 0x10: console_deo(u, addr); break; + case 0x10: console_deo(addr); break; case 0x20: screen_deo(addr); break; case 0x30: audio_deo(0, &uxn.dev[d], p); break; case 0x40: audio_deo(1, &uxn.dev[d], p); break; @@ -260,7 +260,7 @@ emu_init(void) } static void -emu_restart(char *drop, int soft) +emu_restart(int soft) { screen_resize(WIDTH, HEIGHT, uxn_screen.scale); screen_fill(uxn_screen.bg, 0); @@ -327,10 +327,6 @@ handle_events(void) return 0; else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED) emu_redraw(); - else if(event.type == SDL_DROPFILE) { - emu_restart(event.drop.file, 0); - SDL_free(event.drop.file); - } /* Mouse */ else if(event.type == SDL_MOUSEMOTION) mouse_pos(clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1)); @@ -358,9 +354,9 @@ handle_events(void) else if(event.key.keysym.sym == SDLK_F3) uxn.dev[0x0f] = 0xff; else if(event.key.keysym.sym == SDLK_F4) - emu_restart(NULL, 0); + emu_restart(0); else if(event.key.keysym.sym == SDLK_F5) - emu_restart(NULL, 1); + emu_restart(1); else if(event.key.keysym.sym == SDLK_F11) set_fullscreen(!fullscreen, 1); else if(event.key.keysym.sym == SDLK_F12) @@ -434,7 +430,7 @@ emu_run(char *rom) if(now >= next_refresh) { now = SDL_GetPerformanceCounter(); next_refresh = now + frame_interval; - uxn_eval(&uxn, uxn_screen.vector); + uxn_eval(uxn_screen.vector); if(screen_changed()) emu_redraw(); } @@ -458,7 +454,6 @@ emu_end(void) close(0); /* make stdin thread exit */ #endif SDL_Quit(); - free(bios.ram); return exitcode; } @@ -470,7 +465,7 @@ main(int argc, char **argv) /* flags */ if(argc > 1 && argv[i][0] == '-') { if(!strcmp(argv[i], "-v")) - return system_error("Uxn(gui) - Varvara Emulator", "3 Jan 2025."); + return system_error("Uxn(gui) - Varvara Emulator", "18 Jan 2025."); else if(!strcmp(argv[i], "-2x")) set_zoom(2, 0); else if(!strcmp(argv[i], "-3x")) @@ -487,7 +482,7 @@ main(int argc, char **argv) return system_error("Init", "Failed to initialize varvara."); /* loop */ uxn.dev[0x17] = argc > i; - if(uxn_eval(&uxn, PAGE_PROGRAM)) { + if(uxn_eval(PAGE_PROGRAM)) { console_listen(i, argc, argv); emu_run(rom); }