uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit a1bc5f3593910a793a1132f6e6561de94debcd3f
parent b01987b1759c27636412ceadaf3f69b96f075994
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 21 Feb 2021 16:52:51 -0800

Added blending modes to color

Diffstat:
MREADME.md | 6++----
Mbuild.sh | 2+-
Memulator.c | 15+++++++--------
Aexamples/blending.usm | 47+++++++++++++++++++++++++++++++++++++++++++++++
Mexamples/devconsole.usm | 3++-
Mexamples/devctrl.usm | 4++--
Mexamples/devmouse.usm | 2+-
Aexamples/label.usm | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mexamples/shapes.usm | 14+++++++-------
Dexamples/text.usm | 99-------------------------------------------------------------------------------
10 files changed, 153 insertions(+), 123 deletions(-)

diff --git a/README.md b/README.md @@ -98,17 +98,15 @@ A device that works like a NES controller, each button is a bit from a single by ## TODOs -- LDR/STR helpers - Line routine -- On-screen debugger. - Getting rid of IOR/IOW would be nice.. -- Sending from the wst to the rst, balance counter? ### Misc TODOs - Includes - Defines -- Lint, print unused labels +- Print unused labels +- Blending mode ## Refs diff --git 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/paint.usm bin/boot.rom +./bin/assembler examples/devmouse.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/emulator.c b/emulator.c @@ -106,14 +106,13 @@ paintchr(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite) } void -painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 fg, Uint8 alpha) +painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 blend) { Uint16 v, h; for(v = 0; v < 8; v++) for(h = 0; h < 8; h++) { Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); - if(!alpha || (alpha && ch1)) - paintpixel(dst, x + h, y + v, ch1 ? fg : 0); + paintpixel(dst, x + h, y + v, ch1 ? blend % 4 : blend / 4); } } @@ -357,12 +356,12 @@ spritew(Device *d, Memory *m, Uint8 b) Uint16 x = (d->mem[2] << 8) + d->mem[3]; Uint16 y = (d->mem[0] << 8) + d->mem[1]; Uint16 a = (d->mem[4] << 8) + d->mem[5]; - Uint8 clr = d->mem[6] & 0xf; - Uint8 layer = d->mem[6] >> 4 & 0xf; - if(clr > 7) - paintchr(layer ? screen.fg : screen.bg, x, y, &m->dat[a]); + Uint8 source = d->mem[6] >> 4 & 0xf; + Uint8 *layer = source % 2 ? screen.fg : screen.bg; + if(source / 2) + paintchr(layer, x, y, &m->dat[a]); else - painticn(layer ? screen.fg : screen.bg, x, y, &m->dat[a], clr % 4, clr > 3); + painticn(layer, x, y, &m->dat[a], d->mem[6] & 0xf); screen.reqdraw = 1; d->ptr = 0; } diff --git a/examples/blending.usm b/examples/blending.usm @@ -0,0 +1,46 @@ +( desktop ) + +:dev/w fff9 ( const write port ) + +;x1 2 ;y1 2 + +;x 2 ;y 2 ;color 1 + +|0100 @RESET + + #02 =dev/w + + #01 =color + #00 ,icon #0040 #0040 ,draw-sprite JSR + #01 ,icon #0048 #0040 ,draw-sprite JSR + #02 ,icon #0050 #0040 ,draw-sprite JSR + #03 ,icon #0058 #0040 ,draw-sprite JSR + #04 ,icon #0040 #0048 ,draw-sprite JSR + #05 ,icon #0048 #0048 ,draw-sprite JSR + #06 ,icon #0050 #0048 ,draw-sprite JSR + #07 ,icon #0058 #0048 ,draw-sprite JSR + #08 ,icon #0040 #0050 ,draw-sprite JSR + #09 ,icon #0048 #0050 ,draw-sprite JSR + #0a ,icon #0050 #0050 ,draw-sprite JSR + #0b ,icon #0058 #0050 ,draw-sprite JSR + #0c ,icon #0040 #0058 ,draw-sprite JSR + #0d ,icon #0048 #0058 ,draw-sprite JSR + #0e ,icon #0050 #0058 ,draw-sprite JSR + #0f ,icon #0058 #0058 ,draw-sprite JSR + +BRK + +@icon [ 3c7e e7c3 c3e7 7e3c ] + +@draw-sprite + IOW2 ( y byte ) + IOW2 ( x byte ) + IOW2 ( sprite address ) + IOW ( layer-color ) + RTS + +|c000 @FRAME +|d000 @ERROR + +|FFF0 [ f3f0 f30b f30a ] ( palette ) +|FFFA .RESET .FRAME .ERROR +\ No newline at end of file diff --git a/examples/devconsole.usm b/examples/devconsole.usm @@ -14,11 +14,12 @@ 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 ) diff --git a/examples/devctrl.usm b/examples/devctrl.usm @@ -11,7 +11,7 @@ #02 =dev/w ( set dev/write to sprite ) #0080 =x #0040 =y ( origin ) - #02 ,up_icn ~x ~y ,draw-sprite JSR + #12 ,up_icn ~x ~y ,draw-sprite JSR BRK @@ -38,7 +38,7 @@ BRK ~x #0001 ADD2 =x @end ( redraw ) - #03 ~sprite ~x ~y ,draw-sprite JSR + #13 ~sprite ~x ~y ,draw-sprite JSR BRK diff --git a/examples/devmouse.usm b/examples/devmouse.usm @@ -103,7 +103,7 @@ RTS IOW2 ( y byte ) IOW2 ( x byte ) IOW2 ( sprite address ) - #08 IOW ( layer-color ) + #20 IOW ( layer-color ) RTS @clear_icn [ 0000 0000 0000 0000 ] diff --git a/examples/label.usm b/examples/label.usm @@ -0,0 +1,83 @@ +( desktop ) + +:dev/w fff9 ( const write port ) + +;x1 2 ;y1 2 + +;x 2 ;y 2 ;color 1 + +|0100 @RESET + + #02 =dev/w + + #01 =color + ,text #0020 #0030 ,draw-label JSR + #02 =color + ,text #0022 #0038 ,draw-label JSR + #03 =color + ,text #0024 #0040 ,draw-label JSR + #04 =color + ,text #0026 #0048 ,draw-label JSR + #06 =color + ,text #0028 #0050 ,draw-label JSR + #07 =color + ,text #002a #0058 ,draw-label JSR + #08 =color + ,text #002c #0060 ,draw-label JSR + #09 =color + ,text #002e #0068 ,draw-label JSR + +BRK + +@text " Hello World " ( add string to memory ) + +@draw-label ( x1 y1 text ) + =y1 =x1 + @draw-label-loop + ( draw ) ~x1 ~y1 IOW2 IOW2 DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 IOW2 ~color IOW + ( incr ) #0001 ADD2 + ( incr ) ~x1 #0008 ADD2 =x1 + DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2 +RTS + +@font ( spectrum-zx font ) +[ + 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 + 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 + 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 + 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 + 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 + 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 + 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 + 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 + 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 + 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 + 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 + 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 + 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 + 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 + 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 + 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 + 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 + 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 + 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 + 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 + 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 + 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 + 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 + 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 + 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 + 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c + 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 + 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 + 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 + 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 + 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 + 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c +] + +|c000 @FRAME +|d000 @ERROR + +|FFF0 [ f3f0 f30b f30a ] ( palette ) +|FFFA .RESET .FRAME .ERROR +\ No newline at end of file diff --git a/examples/shapes.usm b/examples/shapes.usm @@ -10,18 +10,18 @@ #01 =dev/w ( set dev/write to screen ) #01 =color - #0020 #0020 #0060 #0060 ,fill-rect JSR + #0010 #0020 #0040 #0060 ,fill-rect JSR #02 =color - #0030 #0030 #0070 #0070 ,fill-rect JSR + #0020 #0030 #0050 #0070 ,fill-rect JSR #03 =color - #0040 #0040 #0080 #0080 ,fill-rect JSR + #0030 #0040 #0060 #0080 ,fill-rect JSR #01 =color - #0090 #0020 #00d0 #0060 ,line-rect JSR + #0070 #0020 #00a0 #0060 ,line-rect JSR #02 =color - #00a0 #0030 #00e0 #0070 ,line-rect JSR + #0080 #0030 #00b0 #0070 ,line-rect JSR #03 =color - #00b0 #0040 #00f0 #0080 ,line-rect JSR + #0090 #0040 #00c0 #0080 ,line-rect JSR BRK @@ -71,5 +71,5 @@ RTS |c000 @FRAME BRK |d000 @ERROR BRK -|FFF0 [ f2ac 35bb 2b5f ] ( palette ) +|FFF0 [ 0f0f 0fff 0ff0 ] ( palette ) |FFFA .RESET .FRAME .ERROR ( vectors ) \ No newline at end of file diff --git a/examples/text.usm b/examples/text.usm @@ -1,98 +0,0 @@ -( hello world ) - -:dev/w fff9 ( const write port ) - -;x 2 ;y 2 ;color 1 - -|0100 @RESET - - ( print to console ) - ,string ,displaycli JSR - - ( print to screen ) - #0008 =x #0030 =y #01 =color - ,string ,displaygui JSR - #0010 =x #0038 =y #02 =color - ,string ,displaygui JSR - #0018 =x #0040 =y #03 =color - ,string ,displaygui JSR - - -BRK - -@string " Hello Merveilles " ( add string to memory ) - -@displaycli - #00 =dev/w ( set dev/write to console ) - @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 - -@displaygui - #02 =dev/w ( set dev/write to sprite ) - @guiloop - DUP2 LDR ,printchar JSR - #0001 ADD2 - ~x #0008 ADD2 =x - DUP2 LDR #00 NEQ ,guiloop ROT JMP? POP2 - RTS - -@printchar - ~color ,getchar JSR ~x ~y ,draw-sprite JSR - RTS - -@getchar - #00 SWP #0008 MUL2 ,SPRITESHEET ADD2 - RTS - -@draw-sprite - IOW2 ( y byte ) - IOW2 ( x byte ) - IOW2 ( sprite address ) - IOW ( layer-color ) - RTS - -|0300 @SPRITESHEET ( first 128 characters of the spectrum-zx font ) - -[ - 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 - 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 - 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 - 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 - 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 - 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 - 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 - 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 - 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 - 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 - 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 - 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 - 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 - 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 - 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 - 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 - 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 - 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 - 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 - 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 - 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 - 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 - 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 - 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 - 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 - 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c - 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 - 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 - 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 - 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 - 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 - 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c -] - -|c000 @FRAME -|d000 @ERROR - -|FFF0 [ f3f0 f30b f30a ] ( palette ) -|FFFA .RESET .FRAME .ERROR -\ No newline at end of file