diff --git a/README.md b/README.md index c2105b3..445a191 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,6 @@ A device that works like a NES controller, each button is a bit from a single by ### Misc TODOs -- Defining theme colors in memory - Includes - Defines - Lint, print unused labels diff --git a/emulator.c b/emulator.c index a150a72..ad17107 100644 --- a/emulator.c +++ b/emulator.c @@ -172,6 +172,20 @@ error(char *msg, const char *err) return 0; } +void +loadtheme(Uint8 *addr) +{ + Uint8 r, g, b; + r = *(addr + 0) >> 4 & 0xf, g = *(addr + 2) >> 4 & 0xf, b = *(addr + 4) >> 4 & 0xf; + theme[0] = ((r + (r << 4)) << 16) + ((g + (g << 4)) << 8) + (b + (b << 4)); + r = *(addr + 0) & 0xf, g = *(addr + 2) & 0xf, b = *(addr + 4) & 0xf; + theme[1] = ((r + (r << 4)) << 16) + ((g + (g << 4)) << 8) + (b + (b << 4)); + r = *(addr + 1) >> 4 & 0xf, g = *(addr + 3) >> 4 & 0xf, b = *(addr + 5) >> 4 & 0xf; + theme[2] = ((r + (r << 4)) << 16) + ((g + (g << 4)) << 8) + (b + (b << 4)); + r = *(addr + 1) & 0xf, g = *(addr + 3) & 0xf, b = *(addr + 5) & 0xf; + theme[3] = ((r + (r << 4)) << 16) + ((g + (g << 4)) << 8) + (b + (b << 4)); +} + void drawdebugger(Uint32 *dst, Uxn *u) { @@ -307,6 +321,7 @@ screenr(Device *d, Memory *m, Uint8 b) case 2: return (HEIGHT >> 8) & 0xff; case 3: return HEIGHT & 0xff; } + loadtheme(m->dat + 0xfff0); (void)m; return d->mem[b]; } @@ -355,6 +370,7 @@ start(Uxn *u) { int ticknext = 0; evaluxn(u, u->vreset); + loadtheme(u->ram.dat + 0xfff0); if(screen.reqdraw) redraw(pixels, u); while(1) { diff --git a/examples/blank.usm b/examples/blank.usm index 4f2fc76..7d679c2 100644 --- a/examples/blank.usm +++ b/examples/blank.usm @@ -7,4 +7,5 @@ |c000 @FRAME BRK |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/controller.usm b/examples/controller.usm index 8f5337d..6029a63 100644 --- a/examples/controller.usm +++ b/examples/controller.usm @@ -61,4 +61,5 @@ BRK |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/drag.usm b/examples/drag.usm index 731a7ae..fc859c2 100644 --- a/examples/drag.usm +++ b/examples/drag.usm @@ -114,4 +114,5 @@ BRK @eyeeye_chr [ aa55 aa55 aa55 aa55 aa55 aa55 aa55 aa55 ] |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/draw.usm b/examples/draw.usm index b7ec9ac..0ef6e83 100644 --- a/examples/draw.usm +++ b/examples/draw.usm @@ -92,4 +92,5 @@ RTS |c000 @FRAME BRK |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/hello.usm b/examples/hello.usm index 7deb656..95d63ff 100644 --- a/examples/hello.usm +++ b/examples/hello.usm @@ -94,4 +94,5 @@ BRK |c000 @FRAME |d000 @ERROR +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR \ No newline at end of file diff --git a/examples/line.usm b/examples/line.usm index 7921013..107492b 100644 --- a/examples/line.usm +++ b/examples/line.usm @@ -77,4 +77,5 @@ RTS |c000 @FRAME BRK |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/mouse.usm b/examples/mouse.usm index 15f7e1a..16ba049 100644 --- a/examples/mouse.usm +++ b/examples/mouse.usm @@ -37,4 +37,5 @@ BRK RTS |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/paint.usm b/examples/paint.usm index df4c673..5e65759 100644 --- a/examples/paint.usm +++ b/examples/paint.usm @@ -3,22 +3,23 @@ :dev/r fff8 ( std read port ) :dev/w fff9 ( std write port ) -;mousex 2 ;mousey 2 ;lastx 2 ;lasty 2 ;color 1 ;mode 1 ;state 1 ;brush 2 +;mousex 2 ;mousey 2 ;lastx 2 ;lasty 2 +;state 1 ;color 1 ;brush 2 |0100 @RESET #05 =dev/r ( set dev/read mouse ) #02 =dev/w ( set dev/write to sprite ) - #05 =color - ,draw-interface JSR - ,brush_large ,brush STR2 + #05 =color ( select a default color ) + ,brush_large ,brush STR2 ( select a default brush ) + + ,draw-interface JSR BRK |c000 @FRAME - #02 =dev/w ( set dev/write to sprite ) ( clear last cursor ) #10 ,clear_icn ~lastx ~lasty ,draw-sprite JSR ( record mouse values ) @@ -58,7 +59,7 @@ BRK ~color ~brush ~mousex #0004 SUB2 ~mousey #0004 SUB2 ,draw-sprite JSR @end-touch - ~mousex =lastx ~mousey =lasty + ~mousex =lastx ~mousey =lasty ( update last post ) BRK @@ -90,4 +91,5 @@ BRK |d000 @ERROR BRK +|FFF0 [ f2af 35bb 2b5f ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/pixels.usm b/examples/pixels.usm index 0d46b52..6d576fd 100644 --- a/examples/pixels.usm +++ b/examples/pixels.usm @@ -39,4 +39,5 @@ BRK RTS |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/screen.usm b/examples/screen.usm index ce84ccd..0e2ec46 100644 --- a/examples/screen.usm +++ b/examples/screen.usm @@ -32,4 +32,5 @@ BRK RTS |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/sprite.usm b/examples/sprite.usm index 6f040ea..5a83e14 100644 --- a/examples/sprite.usm +++ b/examples/sprite.usm @@ -31,4 +31,5 @@ BRK |c000 @FRAME BRK |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR diff --git a/examples/test.usm b/examples/test.usm index 2cb7cdf..6fffa7f 100644 --- a/examples/test.usm +++ b/examples/test.usm @@ -55,4 +55,5 @@ BRK |d000 @ERROR BRK +|FFF0 [ f2ac 35bb 2b53 ] ( palette ) |FFFA .RESET .FRAME .ERROR