From 882ae2a693a50cdfa072462be2d57b93078cf916 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 18 Aug 2021 09:42:00 +0200 Subject: Update UXN core with INC/DEC changes --- roms/audio.rom | Bin 435 -> 435 bytes roms/automata.rom | Bin 255 -> 255 bytes roms/bifurcan.rom | Bin 584 -> 583 bytes roms/controller.rom | Bin 985 -> 958 bytes roms/dvd.rom | Bin 315 -> 307 bytes roms/file.load.rom | Bin 1233 -> 1233 bytes roms/file.save.rom | Bin 108 -> 108 bytes roms/hover.rom | Bin 508 -> 502 bytes roms/label.rom | Bin 1457 -> 1439 bytes roms/multichannel.audio.rom | Bin 1235 -> 1228 bytes roms/polycat.rom | Bin 801 -> 793 bytes roms/proportional_fonts.rom | Bin 1333 -> 1333 bytes roms/screen.rom | Bin 800 -> 785 bytes roms/shapes.rom | Bin 1077 -> 1055 bytes roms/theme.rom | Bin 3227 -> 3224 bytes roms/wallpaper.rom | Bin 190 -> 190 bytes src/main.c | 46 ++++++------ src/uxn.c | 174 ++++++++++++++++++++++++++++++++++++-------- src/uxn.h | 6 +- 19 files changed, 169 insertions(+), 57 deletions(-) diff --git a/roms/audio.rom b/roms/audio.rom index ad4924d..614c817 100644 Binary files a/roms/audio.rom and b/roms/audio.rom differ diff --git a/roms/automata.rom b/roms/automata.rom index 285d439..ec6dfb9 100644 Binary files a/roms/automata.rom and b/roms/automata.rom differ diff --git a/roms/bifurcan.rom b/roms/bifurcan.rom index 796491f..284e22a 100644 Binary files a/roms/bifurcan.rom and b/roms/bifurcan.rom differ diff --git a/roms/controller.rom b/roms/controller.rom index 47a56a2..3e786fb 100644 Binary files a/roms/controller.rom and b/roms/controller.rom differ diff --git a/roms/dvd.rom b/roms/dvd.rom index 4d3fc61..7ddabe9 100644 Binary files a/roms/dvd.rom and b/roms/dvd.rom differ diff --git a/roms/file.load.rom b/roms/file.load.rom index 292933e..e99bae3 100644 Binary files a/roms/file.load.rom and b/roms/file.load.rom differ diff --git a/roms/file.save.rom b/roms/file.save.rom index a2af61d..8680264 100644 Binary files a/roms/file.save.rom and b/roms/file.save.rom differ diff --git a/roms/hover.rom b/roms/hover.rom index fa2c544..9ad97a1 100644 Binary files a/roms/hover.rom and b/roms/hover.rom differ diff --git a/roms/label.rom b/roms/label.rom index 535c7ee..c8fe6b8 100644 Binary files a/roms/label.rom and b/roms/label.rom differ diff --git a/roms/multichannel.audio.rom b/roms/multichannel.audio.rom index d7f652b..dc1d708 100644 Binary files a/roms/multichannel.audio.rom and b/roms/multichannel.audio.rom differ diff --git a/roms/polycat.rom b/roms/polycat.rom index 42fe18c..a8c3a22 100644 Binary files a/roms/polycat.rom and b/roms/polycat.rom differ diff --git a/roms/proportional_fonts.rom b/roms/proportional_fonts.rom index 96a8ee1..2208d35 100644 Binary files a/roms/proportional_fonts.rom and b/roms/proportional_fonts.rom differ diff --git a/roms/screen.rom b/roms/screen.rom index 6fd8f99..de04425 100644 Binary files a/roms/screen.rom and b/roms/screen.rom differ diff --git a/roms/shapes.rom b/roms/shapes.rom index b633b77..0aeabac 100644 Binary files a/roms/shapes.rom and b/roms/shapes.rom differ diff --git a/roms/theme.rom b/roms/theme.rom index 4fe36e6..b3eb1ef 100644 Binary files a/roms/theme.rom and b/roms/theme.rom differ diff --git a/roms/wallpaper.rom b/roms/wallpaper.rom index 3bd6406..81a55f0 100644 Binary files a/roms/wallpaper.rom and b/roms/wallpaper.rom differ diff --git a/src/main.c b/src/main.c index 06d2d5b..c15a9e3 100644 --- a/src/main.c +++ b/src/main.c @@ -229,22 +229,22 @@ init_uxn(Uxn *u) { memcpy(u->ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); // Prepare devices. - portuxn(u, 0x0, "system", system_talk); - portuxn(u, 0x1, "console", console_talk); - devscreen = portuxn(u, 0x2, "screen", screen_talk); - devaudio = portuxn(u, 0x3, "audio0", audio_talk); - portuxn(u, 0x4, "audio1", audio_talk); - portuxn(u, 0x5, "audio2", audio_talk); - portuxn(u, 0x6, "audio3", audio_talk); - portuxn(u, 0x7, "---", nil_talk); - devctrl = portuxn(u, 0x8, "controller", nil_talk); - devmouse = portuxn(u, 0x9, "mouse", nil_talk); - portuxn(u, 0xa, "file", file_talk); - portuxn(u, 0xb, "datetime", datetime_talk); - portuxn(u, 0xc, "---", nil_talk); - portuxn(u, 0xd, "---", nil_talk); - portuxn(u, 0xe, "---", nil_talk); - portuxn(u, 0xf, "---", nil_talk); + uxn_port(u, 0x0, "system", system_talk); + uxn_port(u, 0x1, "console", console_talk); + devscreen = uxn_port(u, 0x2, "screen", screen_talk); + devaudio = uxn_port(u, 0x3, "audio0", audio_talk); + uxn_port(u, 0x4, "audio1", audio_talk); + uxn_port(u, 0x5, "audio2", audio_talk); + uxn_port(u, 0x6, "audio3", audio_talk); + uxn_port(u, 0x7, "---", nil_talk); + devctrl = uxn_port(u, 0x8, "controller", nil_talk); + devmouse = uxn_port(u, 0x9, "mouse", nil_talk); + uxn_port(u, 0xa, "file", file_talk); + uxn_port(u, 0xb, "datetime", datetime_talk); + uxn_port(u, 0xc, "---", nil_talk); + uxn_port(u, 0xd, "---", nil_talk); + uxn_port(u, 0xe, "---", nil_talk); + uxn_port(u, 0xf, "---", nil_talk); mempoke16(devscreen->dat, 2, ppu.hor * 8); mempoke16(devscreen->dat, 4, ppu.ver * 8); } @@ -258,7 +258,7 @@ handle_input(Uxn *u) { switch (ctrl_methods[ctrl_idx]) { case CONTROL_CONTROLLER: { devctrl->dat[2] = 0; - evaluxn(u, mempeek16(devctrl->dat, 0)); + uxn_eval(u, mempeek16(devctrl->dat, 0)); devctrl->dat[3] = 0; } break; case CONTROL_MOUSE: { @@ -266,7 +266,7 @@ handle_input(Uxn *u) { devmouse->dat[7] = 0; mempoke16(devmouse->dat, 0x2, -10); mempoke16(devmouse->dat, 0x4, -10); - evaluxn(u, mempeek16(devmouse->dat, 0)); + uxn_eval(u, mempeek16(devmouse->dat, 0)); } break; case CONTROL_KEYBOARD: { toggle_keyboard(); @@ -327,7 +327,7 @@ handle_input(Uxn *u) { *flag &= ~0x80; } - evaluxn(u, mempeek16(devctrl->dat, 0)); + uxn_eval(u, mempeek16(devctrl->dat, 0)); devctrl->dat[3] = 0; } else if (ctrl_methods[ctrl_idx] == CONTROL_MOUSE) { // Detect "mouse key press". @@ -367,7 +367,7 @@ handle_input(Uxn *u) { // Eval mouse. mempoke16(devmouse->dat, 0x2, mouse.x); mempoke16(devmouse->dat, 0x4, mouse.y); - evaluxn(u, mempeek16(devmouse->dat, 0)); + uxn_eval(u, mempeek16(devmouse->dat, 0)); } else if (ctrl_methods[ctrl_idx] == CONTROL_KEYBOARD) { if (key_tap(KEY_LEFT)) { update_cursor(cursor_position - 1); @@ -411,7 +411,7 @@ handle_input(Uxn *u) { devctrl->dat[3] = symbol; } break; } - evaluxn(u, mempeek16(devctrl->dat, 0)); + uxn_eval(u, mempeek16(devctrl->dat, 0)); devctrl->dat[3] = 0; } } @@ -445,12 +445,12 @@ int main(void) { init_sound(); // Main loop. - evaluxn(&u, 0x0100); + uxn_eval(&u, 0x0100); PROF_INIT(); while(true) { bios_vblank_wait(); PROF(handle_input(&u), input_cycles); - PROF(evaluxn(&u, mempeek16(devscreen->dat, 0)), eval_cycles); + PROF(uxn_eval(&u, mempeek16(devscreen->dat, 0)), eval_cycles); PROF(sound_mix(), mix_cycles); PROF_SHOW(); PROF(flipbuf(&ppu), flip_cycles); diff --git a/src/uxn.c b/src/uxn.c index 3a8cdb3..3934e1b 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -30,35 +30,21 @@ See etc/mkuxn-fast.moon for instructions. IWRAM_CODE int -evaluxn(Uxn *u, u16 vec) +uxn_eval(Uxn *u, u16 vec) { u8 instr; - if(u->dev[0].dat[0xf]) + if(!vec || u->dev[0].dat[0xf]) return 0; u->ram.ptr = vec; if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8; - while(u->ram.ptr) { - instr = u->ram.dat[u->ram.ptr++]; + while((instr = u->ram.dat[u->ram.ptr++])) { switch(instr) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-value" #pragma GCC diagnostic ignored "-Wunused-variable" - case 0x00: /* BRK */ - case 0x20: /* BRK2 */ - case 0x40: /* BRKr */ - case 0x60: /* BRK2r */ - case 0x80: /* BRKk */ - case 0xa0: /* BRK2k */ - case 0xc0: /* BRKkr */ - case 0xe0: /* BRK2kr */ - __asm__("evaluxn_00_BRK:"); - { - u->ram.ptr = 0; - } - break; - case 0x01: /* LIT */ - case 0x81: /* LITk */ - __asm__("evaluxn_01_LIT:"); + case 0x00: /* LIT */ + case 0x80: /* LITk */ + __asm__("evaluxn_00_LIT:"); { u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); #ifndef NO_STACK_CHECKS @@ -70,6 +56,19 @@ evaluxn(Uxn *u, u16 vec) u->wst.ptr += 1; } break; + case 0x01: /* INC */ + __asm__("evaluxn_01_INC:"); + { + u8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr - 1] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; case 0x02: /* POP */ __asm__("evaluxn_02_POP:"); { @@ -522,9 +521,9 @@ evaluxn(Uxn *u, u16 vec) u->wst.ptr -= 1; } break; - case 0x21: /* LIT2 */ - case 0xa1: /* LIT2k */ - __asm__("evaluxn_21_LIT2:"); + case 0x20: /* LIT2 */ + case 0xa0: /* LIT2k */ + __asm__("evaluxn_20_LIT2:"); { u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); @@ -537,6 +536,20 @@ evaluxn(Uxn *u, u16 vec) u->wst.ptr += 2; } break; + case 0x21: /* INC2 */ + __asm__("evaluxn_21_INC2:"); + { + u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr - 2] = (a + 1) >> 8; + u->wst.dat[u->wst.ptr - 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } +#endif + } + break; case 0x22: /* POP2 */ __asm__("evaluxn_22_POP2:"); { @@ -1024,9 +1037,9 @@ evaluxn(Uxn *u, u16 vec) u->wst.ptr -= 1; } break; - case 0x41: /* LITr */ - case 0xc1: /* LITkr */ - __asm__("evaluxn_41_LITr:"); + case 0x40: /* LITr */ + case 0xc0: /* LITkr */ + __asm__("evaluxn_40_LITr:"); { u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); #ifndef NO_STACK_CHECKS @@ -1038,6 +1051,19 @@ evaluxn(Uxn *u, u16 vec) u->rst.ptr += 1; } break; + case 0x41: /* INCr */ + __asm__("evaluxn_41_INCr:"); + { + u8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr - 1] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; case 0x42: /* POPr */ __asm__("evaluxn_42_POPr:"); { @@ -1490,9 +1516,9 @@ evaluxn(Uxn *u, u16 vec) u->rst.ptr -= 1; } break; - case 0x61: /* LIT2r */ - case 0xe1: /* LIT2kr */ - __asm__("evaluxn_61_LIT2r:"); + case 0x60: /* LIT2r */ + case 0xe0: /* LIT2kr */ + __asm__("evaluxn_60_LIT2r:"); { u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); @@ -1505,6 +1531,20 @@ evaluxn(Uxn *u, u16 vec) u->rst.ptr += 2; } break; + case 0x61: /* INC2r */ + __asm__("evaluxn_61_INC2r:"); + { + u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr - 2] = (a + 1) >> 8; + u->rst.dat[u->rst.ptr - 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } +#endif + } + break; case 0x62: /* POP2r */ __asm__("evaluxn_62_POP2r:"); { @@ -1992,6 +2032,24 @@ evaluxn(Uxn *u, u16 vec) u->rst.ptr -= 1; } break; + case 0x81: /* INCk */ + __asm__("evaluxn_81_INCk:"); + { + u8 a = u->wst.dat[u->wst.ptr - 1]; + u->wst.dat[u->wst.ptr] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 1, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 1; + } + break; case 0x82: /* POPk */ __asm__("evaluxn_82_POPk:"); { @@ -2515,6 +2573,25 @@ evaluxn(Uxn *u, u16 vec) u->wst.ptr += 1; } break; + case 0xa1: /* INC2k */ + __asm__("evaluxn_a1_INC2k:"); + { + u16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); + u->wst.dat[u->wst.ptr] = (a + 1) >> 8; + u->wst.dat[u->wst.ptr + 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->wst.ptr < 2, 0)) { + u->wst.error = 1; + goto error; + } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } +#endif + u->wst.ptr += 2; + } + break; case 0xa2: /* POP2k */ __asm__("evaluxn_a2_POP2k:"); { @@ -3062,6 +3139,24 @@ evaluxn(Uxn *u, u16 vec) u->wst.ptr += 2; } break; + case 0xc1: /* INCkr */ + __asm__("evaluxn_c1_INCkr:"); + { + u8 a = u->rst.dat[u->rst.ptr - 1]; + u->rst.dat[u->rst.ptr] = a + 1; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 1, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 1; + } + break; case 0xc2: /* POPkr */ __asm__("evaluxn_c2_POPkr:"); { @@ -3585,6 +3680,25 @@ evaluxn(Uxn *u, u16 vec) u->rst.ptr += 1; } break; + case 0xe1: /* INC2kr */ + __asm__("evaluxn_e1_INC2kr:"); + { + u16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); + u->rst.dat[u->rst.ptr] = (a + 1) >> 8; + u->rst.dat[u->rst.ptr + 1] = (a + 1) & 0xff; +#ifndef NO_STACK_CHECKS + if(__builtin_expect(u->rst.ptr < 2, 0)) { + u->rst.error = 1; + goto error; + } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } +#endif + u->rst.ptr += 2; + } + break; case 0xe2: /* POP2kr */ __asm__("evaluxn_e2_POP2kr:"); { @@ -4143,7 +4257,7 @@ error: } Device * -portuxn(Uxn *u, u8 id, char *name, void (*talkfn)(Device *d, u8 b0, u8 w)) +uxn_port(Uxn *u, u8 id, char *name, void (*talkfn)(Device *d, u8 b0, u8 w)) { Device *d = &u->dev[id]; d->addr = id * 0x10; diff --git a/src/uxn.h b/src/uxn.h index a4ab428..bd9379c 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -49,8 +49,6 @@ static inline u8 devpeek8(Device *d, u8 a) { d->talk(d, a & 0x0f, 0); return d-> static inline void devpoke16(Device *d, u8 a, u16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } static inline u16 devpeek16(Device *d, u16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } -int loaduxn(Uxn *c, char *filepath); -int bootuxn(Uxn *c); -int evaluxn(Uxn *u, u16 vec); -Device *portuxn(Uxn *u, u8 id, char *name, void (*talkfn)(Device *, u8, u8)); +int uxn_eval(Uxn *u, u16 vec); +Device *uxn_port(Uxn *u, u8 id, char *name, void (*talkfn)(Device *, u8, u8)); #endif // UXNGBA_UXN_H -- cgit v1.2.1