Browse Source

Implemented color palette in memory

aarch64
neauoire 5 years ago
parent
commit
7f3b8b3dea
  1. 1
      README.md
  2. 16
      emulator.c
  3. 1
      examples/blank.usm
  4. 1
      examples/controller.usm
  5. 1
      examples/drag.usm
  6. 1
      examples/draw.usm
  7. 1
      examples/hello.usm
  8. 1
      examples/line.usm
  9. 1
      examples/mouse.usm
  10. 14
      examples/paint.usm
  11. 1
      examples/pixels.usm
  12. 1
      examples/screen.usm
  13. 1
      examples/sprite.usm
  14. 1
      examples/test.usm

1
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

16
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) {

1
examples/blank.usm

@ -7,4 +7,5 @@
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/controller.usm

@ -61,4 +61,5 @@ BRK
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
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

1
examples/draw.usm

@ -92,4 +92,5 @@ RTS
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/hello.usm

@ -94,4 +94,5 @@ BRK
|c000 @FRAME
|d000 @ERROR
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/line.usm

@ -77,4 +77,5 @@ RTS
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/mouse.usm

@ -37,4 +37,5 @@ BRK
RTS
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

14
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

1
examples/pixels.usm

@ -39,4 +39,5 @@ BRK
RTS
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/screen.usm

@ -32,4 +32,5 @@ BRK
RTS
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/sprite.usm

@ -31,4 +31,5 @@ BRK
|c000 @FRAME BRK
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

1
examples/test.usm

@ -55,4 +55,5 @@ BRK
|d000 @ERROR BRK
|FFF0 [ f2ac 35bb 2b53 ] ( palette )
|FFFA .RESET .FRAME .ERROR

Loading…
Cancel
Save