diff --git a/build.sh b/build.sh index 348f669..51180f1 100755 --- a/build.sh +++ b/build.sh @@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator # run -./bin/assembler examples/devmouse.usm bin/boot.rom +./bin/assembler examples/paint.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/emulator.c b/emulator.c index c72ccca..77fccef 100644 --- a/emulator.c +++ b/emulator.c @@ -322,10 +322,10 @@ Uint8 screenr(Device *d, Memory *m, Uint8 b) { switch(b) { - case 0: return (WIDTH >> 8) & 0xff; - case 1: return WIDTH & 0xff; - case 2: return (HEIGHT >> 8) & 0xff; - case 3: return HEIGHT & 0xff; + case 0: return (HOR * 8 >> 8) & 0xff; + case 1: return HOR * 8 & 0xff; + case 2: return (VER * 8 >> 8) & 0xff; + case 3: return VER * 8 & 0xff; } loadtheme(m->dat + 0xfff0); (void)m; @@ -336,13 +336,13 @@ Uint8 screenw(Device *d, Memory *m, Uint8 b) { d->mem[d->ptr++] = b; - if(d->ptr > 5) { - putpixel(pixels, - (d->mem[2] << 8) + d->mem[3], - (d->mem[0] << 8) + d->mem[1], - d->mem[4]); - if(d->mem[5] == 1) - screen.reqdraw = 1; + if(d->ptr > 4) { + Uint16 x = (d->mem[2] << 8) + d->mem[3]; + Uint16 y = (d->mem[0] << 8) + d->mem[1]; + Uint8 clr = d->mem[4] & 0xf; + Uint8 layer = d->mem[4] >> 4 & 0xf; + paintpixel(layer ? screen.fg : screen.bg, x, y, clr); + screen.reqdraw = 1; d->ptr = 0; } (void)m; diff --git a/examples/devconsole.usm b/examples/devconsole.usm new file mode 100644 index 0000000..9845b5e --- /dev/null +++ b/examples/devconsole.usm @@ -0,0 +1,30 @@ +( hello world ) + +:dev/w fff9 ( const write port ) + +;x 2 ;y 2 ;color 1 + +|0100 @RESET + + ( set dev/write to console ) + #00 =dev/w + ( print to console ) + ,text ,displaycli JSR + +BRK + +@displaycli + + @cliloop + DUP2 LDR IOW ( write pointer value to console ) + #0001 ADD2 ( increment string pointer ) + DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop ) +RTS + +@text " Hello World " ( add characters to memory ) + +|c000 @FRAME +|d000 @ERROR + +|FFF0 [ f3f0 f30b f30a ] ( palette ) +|FFFA .RESET .FRAME .ERROR \ No newline at end of file diff --git a/examples/devmouse.usm b/examples/devmouse.usm index 99614fe..d4327bf 100644 --- a/examples/devmouse.usm +++ b/examples/devmouse.usm @@ -111,7 +111,7 @@ RTS @cursor_icn [ 80c0 e0f0 f8e0 1000 ] @polycat [ - 0081c 3e3e 7f7f ffff 081c 3e3e 7f7f fffc + 081c 3e3e 7f7f ffff 081c 3e3e 7f7f fffc 081c 3c3e 7e7e ffff 081c 3c3e 7e7e ff1f ffff ffff ff7f 3f0f f0e7 cfef f77c 3f0f ffff ffff fffe fcf0 0783 c1c3 871e fcf0 diff --git a/examples/devscreen.usm b/examples/devscreen.usm new file mode 100644 index 0000000..8008f93 --- /dev/null +++ b/examples/devscreen.usm @@ -0,0 +1,45 @@ +( screen ) + +:dev/r fff8 ( std read port ) +:dev/w fff9 ( std write port ) + +;centerx 2 ;centery 2 ;i 2 + +|0100 @RESET + + ( set read/write to dev/screen ) + #01 DUP =dev/r =dev/w + + ( find screen center ) + #00 IOR2 #0002 DIV2 =centerx + #02 IOR2 #0002 DIV2 =centery + + ( draw hor line ) + #0000 =i + @draw-hor + #03 ~i ~centery ,draw-pixel JSR + ~i #0002 ADD2 =i ( increment ) + ~i #00 IOR2 LTH2 ,draw-hor ROT JMP? POP2 + + ( draw ver line ) + #0000 =i + @draw-ver + #03 ~centerx ~i ,draw-pixel JSR + ~i #0002 ADD2 =i ( increment ) + ~i #02 IOR2 LTH2 ,draw-ver ROT JMP? POP2 + + ( draw pixel in the middle ) + #01 ~centerx ~centery ,draw-pixel JSR + +BRK + +@draw-pixel + IOW2 ( y short ) + IOW2 ( x short ) + IOW ( color byte ) + RTS + +|c000 @FRAME BRK +|d000 @ERROR BRK +|FFF0 [ f0ac f0bb f053 ] ( palette ) +|FFFA .RESET .FRAME .ERROR diff --git a/examples/pixels.usm b/examples/pixels.usm deleted file mode 100644 index 6d576fd..0000000 --- a/examples/pixels.usm +++ /dev/null @@ -1,43 +0,0 @@ -( pixels ) - -:dev/r fff8 ( std read port ) -:dev/w fff9 ( std write port ) - -;x 2 ;y 2 ;color 1 ;alive 1 - -|0100 @RESET - - #01 =dev/w ( set dev/write to screen ) - #01 =color ( set color ) - #0020 =x #0030 =y ( set origin ) - #01 =alive ( set alive = true ) - -BRK - -|c000 @FRAME - - ~alive #00 EQU BRK? - #01 ~color ~x ~y ,putpixel JSR - ,move JSR - -BRK - -@move - ~x #0001 ADD2 =x ( incr x ) - ~x #0040 LTH2 RTS? ( if x > 60 ) - #0020 =x ( x = 0x0020 ) - ~y #0001 ADD2 =y ( incr y ) - ~y #0050 LTH2 RTS? ( y > 50 ) - #00 ,alive STR ( alive = 0 ) - RTS - -@putpixel - IOW2 ( y short ) - IOW2 ( x short ) - IOW ( color byte ) - IOW ( redraw byte ) - RTS - -|d000 @ERROR BRK -|FFF0 [ f2ac 35bb 2b53 ] ( palette ) -|FFFA .RESET .FRAME .ERROR diff --git a/examples/screen.usm b/examples/screen.usm deleted file mode 100644 index 0e2ec46..0000000 --- a/examples/screen.usm +++ /dev/null @@ -1,36 +0,0 @@ -( screen ) - -:dev/r fff8 ( std read port ) -:dev/w fff9 ( std write port ) - -;width 2 ;height 2 - -|0100 @RESET - - ( set read/write to dev/screen ) - #01 DUP =dev/r =dev/w - - ( load screen size ) - #00 IOR2 =width - #02 IOR2 =height - - ( draw pixel at screen center ) - #0101 - ~width #0002 DIV2 - ~height #0002 DIV2 - ,putpixel JSR - -BRK - -|c000 @FRAME BRK - -@putpixel - IOW2 ( y short ) - IOW2 ( x short ) - IOW ( color byte ) - IOW ( redraw byte ) - RTS - -|d000 @ERROR BRK -|FFF0 [ f2ac 35bb 2b53 ] ( palette ) -|FFFA .RESET .FRAME .ERROR diff --git a/examples/sprite.usm b/examples/sprite.usm deleted file mode 100644 index 5a83e14..0000000 --- a/examples/sprite.usm +++ /dev/null @@ -1,35 +0,0 @@ -( sprite ) - -:dev/w fff9 ( const write port ) - -|0100 @RESET - - #01 =dev/w ( set dev/write to screen ) - #02 =dev/w ( set dev/write to sprite ) - - #0110 ,cursor_icn #20 #38 ,drawsprite JSR - #0010 ,rounds_chr #28 #38 ,drawsprite JSR - #3210 ,cursor_icn #20 #40 ,drawsprite JSR - #0010 ,rounds_chr #28 #40 ,drawsprite JSR - -BRK - -@drawsprite - IOW ( y byte ) - IOW ( x byte ) - IOW2 ( sprite address ) - IOW2 ( redraw byte ) - RTS - -|0200 @SPRITESHEET - -@cursor_icn [ 80c0 e0f0 f8e0 1000 ] -@rounds_chr [ 3844 92aa 9244 3800 0038 7c7c 7c38 0000 ] - -BRK - -|c000 @FRAME BRK -|d000 @ERROR BRK - -|FFF0 [ f2ac 35bb 2b53 ] ( palette ) -|FFFA .RESET .FRAME .ERROR diff --git a/examples/hello.usm b/examples/text.usm similarity index 100% rename from examples/hello.usm rename to examples/text.usm