diff --git a/build.sh b/build.sh index 75e5f41..a6e2477 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ else fi echo "Assembling.." -./bin/assembler projects/software/nasu.usm bin/boot.rom +./bin/assembler projects/software/left.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/projects/software/left.usm b/projects/software/left.usm index ae702ff..aa7bbf8 100644 --- a/projects/software/left.usm +++ b/projects/software/left.usm @@ -42,24 +42,21 @@ ( devices ) -|0100 ;Console { pad 8 char 1 byte 1 short 2 } -|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } -|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } -|0130 ;Controller { buttons 1 } -|0140 ;Keys { key 1 } -|0150 ;Mouse { x 2 y 2 state 1 chord 1 } -|0160 ;File { pad 8 name 2 length 2 load 2 save 2 } -|01F0 ;System { pad 8 r 2 g 2 b 2 } - -|0200 ^RESET JMP -|0204 ,ERROR JMP2 -|0208 ,FRAME JMP2 +|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { pad 8 char 1 byte 1 short 2 } +|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 } +|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } +|0140 ;Controller { buttons 1 } +|0150 ;Keys { key 1 } +|0160 ;Mouse { x 2 y 2 state 1 chord 1 } +|0170 ;File { pad 8 name 2 length 2 load 2 save 2 } ( program ) -@RESET +|0200 @RESET ( theme ) #e0fa =System.r #30fa =System.g #30fa =System.b + ( vectors ) ,FRAME =Screen.vector ( load file ) ,filepath ,load-file JSR2 diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm index 290f43d..2aca4cd 100644 --- a/projects/software/nasu.usm +++ b/projects/software/nasu.usm @@ -31,24 +31,23 @@ ( devices ) -|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } -|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } -|0130 ;Controller { buttons 1 } -|0140 ;Keys { key 1 } -|0150 ;Mouse { x 2 y 2 state 1 chord 1 change 1 } -|0160 ;File { pad 8 name 2 length 2 load 2 save 2 } -|01F0 ;System { pad 8 r 2 g 2 b 2 } - -|0200 ^RESET JMP -|0204 ,ERROR JMP2 -|0208 ,FRAME JMP2 +|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { pad 8 char 1 byte 1 short 2 } +|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 } +|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } +|0140 ;Controller { buttons 1 } +|0150 ;Keys { key 1 } +|0160 ;Mouse { x 2 y 2 state 1 chord 1 change 1 } +|0170 ;File { pad 8 name 2 length 2 load 2 save 2 } ( program ) -@RESET +|0200 @RESET ( theme ) #e0fc =System.r #30cc =System.g #30ac =System.b + ,FRAME =Screen.vector + ~Screen.width 2/ #008a SUB2 =bankview.x ~Screen.height 2/ #003f SUB2 =bankview.y ,bank =bankview.addr diff --git a/projects/software/neralie.usm b/projects/software/neralie.usm index 16676c7..4a9b848 100644 --- a/projects/software/neralie.usm +++ b/projects/software/neralie.usm @@ -11,18 +11,18 @@ ;neralie { n0123 2 n4 1 n5 1 n6 1 n7 1 n8 1 n9 1 color 1 x 2 y 2 w 2 h 2 } ;mul { ahi 1 alo 1 bhi 1 blo 1 } -|0100 ;Console { pad 8 char 1 byte 1 short 2 } -|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } -|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } -|0190 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 } -|01F0 ;System { pad 8 r 2 g 2 b 2 } +|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { pad 8 char 1 byte 1 short 2 } +|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 } +|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } +|01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dow 1 doy 2 isdst 1 pad 4 get 1 } -|0200 ^RESET JMP -|0204 ,ERROR JMP2 -|0208 ,FRAME JMP2 +( program ) + +|0200 @RESET -@RESET ( theme ) #03fd =System.r #0ef3 =System.g #0bf2 =System.b + ( vectors ) ,FRAME =Screen.vector #01 =fps.current #000c diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm index 1b03142..da59ba6 100644 --- a/projects/software/noodle.usm +++ b/projects/software/noodle.usm @@ -51,25 +51,23 @@ ( devices ) -|0100 ;Console { pad 8 char 1 byte 1 short 2 string 2 } -|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } -|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } -|0130 ;Controller { p1 1 } -|0140 ;Keys { key 1 } -|0150 ;Mouse { x 2 y 2 state 1 chord 1 } -|0160 ;File { pad 8 name 2 length 2 load 2 save 2 } -|01F0 ;System { pad 8 r 2 g 2 b 2 } -|0200 ^RESET JMP -|0204 ,ERROR JMP2 -|0208 ,FRAME JMP2 +|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { pad 8 char 1 byte 1 short 2 } +|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 color 1 } +|0130 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } +|0140 ;Controller { p1 1 } +|0150 ;Keys { key 1 } +|0160 ;Mouse { x 2 y 2 state 1 chord 1 } +|0170 ;File { pad 8 name 2 length 2 load 2 save 2 } ( program ) -@RESET ( -- ) +|0200 @RESET ( theme ) #e0fa =theme.r0 #30fa =theme.g0 #30fa =theme.b0 ( normal mode ) #00fe =theme.r1 #00f3 =theme.g1 #00f3 =theme.b1 ( presentation mode ) + ( vectors ) ,FRAME =Screen.vector ~theme.r0 =System.r ~theme.g0 =System.g ~theme.b0 =System.b diff --git a/src/emulator.c b/src/emulator.c index 36e5883..dd34cec 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -80,7 +80,7 @@ static SDL_Renderer *gRenderer; static SDL_Texture *gTexture; static SDL_AudioDeviceID audio_id; static Screen screen; -static Device *devscreen, *devmouse, *devkey, *devctrl, *devaudio; +static Device *devsystem, *devscreen, *devmouse, *devkey, *devctrl, *devaudio; #pragma mark - Helpers @@ -582,7 +582,7 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) int start(Uxn *u) { - evaluxn(u, PAGE_VECTORS); + inituxn(u, 0x0200); redraw(pixels, u); while(1) { SDL_Event event; @@ -602,12 +602,13 @@ start(Uxn *u) break; } } - evaluxn(u, PAGE_VECTORS + 0x08); + evaluxn(u, devscreen->vector); if(screen.reqdraw) redraw(pixels, u); elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f; SDL_Delay(clamp(16.666f - elapsed, 0, 1000)); } + return 1; } int @@ -624,28 +625,28 @@ main(int argc, char **argv) if(!init()) return error("Init", "Failed"); - portuxn(&u, 0x00, "console", console_poke); - devscreen = portuxn(&u, 0x01, "screen", screen_poke); - portuxn(&u, 0x02, "sprite", sprite_poke); - devctrl = portuxn(&u, 0x03, "controller", ppnil); - devkey = portuxn(&u, 0x04, "key", ppnil); - devmouse = portuxn(&u, 0x05, "mouse", ppnil); - portuxn(&u, 0x06, "file", file_poke); - devaudio = portuxn(&u, 0x07, "audio", audio_poke); - portuxn(&u, 0x08, "midi", ppnil); - portuxn(&u, 0x09, "datetime", datetime_poke); - portuxn(&u, 0x0a, "---", ppnil); + devsystem = portuxn(&u, 0x00, "system", system_poke); + portuxn(&u, 0x01, "console", console_poke); + devscreen = portuxn(&u, 0x02, "screen", screen_poke); + portuxn(&u, 0x03, "sprite", sprite_poke); + devctrl = portuxn(&u, 0x04, "controller", ppnil); + devkey = portuxn(&u, 0x05, "key", ppnil); + devmouse = portuxn(&u, 0x06, "mouse", ppnil); + portuxn(&u, 0x07, "file", file_poke); + devaudio = portuxn(&u, 0x08, "audio", audio_poke); + portuxn(&u, 0x09, "midi", ppnil); + portuxn(&u, 0x0a, "datetime", datetime_poke); portuxn(&u, 0x0b, "---", ppnil); portuxn(&u, 0x0c, "---", ppnil); portuxn(&u, 0x0d, "---", ppnil); portuxn(&u, 0x0e, "---", ppnil); - portuxn(&u, 0x0f, "system", system_poke); + portuxn(&u, 0x0f, "---", ppnil); /* Write screen size to dev/screen */ - u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff; - u.ram.dat[devscreen->addr + 1] = HOR * 8 & 0xff; - u.ram.dat[devscreen->addr + 2] = (VER * 8 >> 8) & 0xff; - u.ram.dat[devscreen->addr + 3] = VER * 8 & 0xff; + u.ram.dat[devscreen->addr + 2] = (HOR * 8 >> 8) & 0xff; + u.ram.dat[devscreen->addr + 3] = HOR * 8 & 0xff; + u.ram.dat[devscreen->addr + 4] = (VER * 8 >> 8) & 0xff; + u.ram.dat[devscreen->addr + 5] = VER * 8 & 0xff; start(&u); quit(); diff --git a/src/uxn.c b/src/uxn.c index 53d0d22..1101f49 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -151,6 +151,17 @@ evaluxn(Uxn *u, Uint16 vec) return 1; } +int +inituxn(Uxn *u, Uint16 vec) +{ + Uint8 i = 0; + if(!evaluxn(u, vec)) + return 0; + for(i = 0; i < 0x10; ++i) + u->dev[i].vector = mempeek16(u, u->dev[i].addr); + return 1; +} + int bootuxn(Uxn *u) { @@ -178,6 +189,6 @@ portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0 Device *d = &u->dev[id]; d->addr = PAGE_DEVICE + id * 0x10; d->poke = pofn; - printf("Device #%d: %s, at 0x%04x \n", id, name, d->addr); + printf("Device added #%d: %s, at 0x%04x \n", id, name, d->addr); return d; } diff --git a/src/uxn.h b/src/uxn.h index 7cd3a53..91d6ffc 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -32,7 +32,7 @@ typedef struct { struct Uxn; typedef struct Device { - Uint16 addr; + Uint16 addr, vector; Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8); } Device; @@ -44,5 +44,6 @@ typedef struct Uxn { int loaduxn(Uxn *c, char *filepath); int bootuxn(Uxn *c); +int inituxn(Uxn *u, Uint16 vec); int evaluxn(Uxn *u, Uint16 vec); Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8));