uxn

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

commit b826d78a56ca2370abc2123f1eb60145bc0cf3d6
parent f3b237f0f9d1eb378d43b3fa7e673730c1d0ccd6
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun,  1 Aug 2021 11:00:07 -0700

Pushed new blending modes

Diffstat:
Mbuild.sh | 4++--
Mprojects/examples/devices/screen.tal | 66+++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/devices/ppu.c | 18++++++++++++++----
3 files changed, 67 insertions(+), 21 deletions(-)

diff --git a/build.sh b/build.sh @@ -54,9 +54,9 @@ then fi echo "Assembling.." -./bin/uxnasm projects/examples/demos/piano.tal bin/piano.rom +./bin/uxnasm projects/examples/devices/screen.tal bin/screen.rom echo "Running.." -./bin/uxnemu bin/piano.rom +./bin/uxnemu bin/screen.rom echo "Done." diff --git a/projects/examples/devices/screen.tal b/projects/examples/devices/screen.tal @@ -1,7 +1,6 @@ ( dev/screen ) %RTN { JMP2r } -%2// { #01 SFT2 } ( devices ) @@ -24,13 +23,16 @@ #f0c0 .System/b DEO2 ( find screen center ) - .Screen/width DEI2 2// .center/x STZ2 - .Screen/height DEI2 2// .center/y STZ2 + .Screen/width DEI2 #01 SFT2 #0020 SUB2 .center/x STZ2 + .Screen/height DEI2 #01 SFT2 .center/y STZ2 ( draw ) ;draw-table JSR2 ;draw-sprites JSR2 - ;draw-circle JSR2 + + ;draw-1bpp JSR2 + ;draw-2bpp JSR2 + ;draw-pixels JSR2 BRK @@ -72,19 +74,53 @@ RTN RTN -@draw-circle ( -- ) +@draw-1bpp ( -- ) + + #00 #10 + &loop + ( color ) OVR STH + ( y ) OVR #04 DIV [ #00 SWP ] #0010 MUL2 + [ .center/y LDZ2 #0040 SUB2 ADD2 ] STH2 + ( x ) OVR #03 AND [ #00 SWP ] #0010 MUL2 #0040 ADD2 + [ .center/x LDZ2 #0008 ADD2 ADD2 ] + STH2r STHr #00 ;draw-circle JSR2 + SWP #01 ADD SWP + LTHk ,&loop JCN + POP2 + +RTN + +@draw-2bpp ( -- ) + + #00 #10 + &loop + ( color ) OVR STH + ( y ) OVR #04 DIV [ #00 SWP ] #0010 MUL2 + [ .center/y LDZ2 ADD2 ] STH2 + ( x ) OVR #03 AND [ #00 SWP ] #0010 MUL2 #0040 ADD2 + [ .center/x LDZ2 #0008 ADD2 ADD2 ] + STH2r STHr #80 ;draw-circle JSR2 + SWP #01 ADD SWP + LTHk ,&loop JCN + POP2 +RTN + +@draw-circle ( x* y* color depth -- ) + + ADD STH ;preview_icn .Screen/addr DEO2 - .center/x LDZ2 #0048 ADD2 .Screen/x DEO2 - .center/y LDZ2 #0030 ADD2 .Screen/y DEO2 - #81 .Screen/sprite DEO - .center/x LDZ2 #0050 ADD2 .Screen/x DEO2 - #91 .Screen/sprite DEO - .center/x LDZ2 #0048 ADD2 .Screen/x DEO2 - .center/y LDZ2 #0038 ADD2 .Screen/y DEO2 - #a1 .Screen/sprite DEO - .center/x LDZ2 #0050 ADD2 .Screen/x DEO2 - #b1 .Screen/sprite DEO + .Screen/y DEO2 + .Screen/x DEO2 + + #00 STHkr ADD .Screen/sprite DEO + .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 + #10 STHkr ADD .Screen/sprite DEO + .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2 + .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 + #20 STHkr ADD .Screen/sprite DEO + .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 + #30 STHr ADD .Screen/sprite DEO RTN diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -12,6 +12,16 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +static Uint8 blending1bpp[2][16] = { + {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}, + {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3}}; + +static Uint8 blending2bpp[4][16] = { + {0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0}, + {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3}, + {1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1}, + {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}}; + void clear(Ppu *p) { @@ -40,7 +50,7 @@ puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint layer, x + (flipx ? 7 - h : h), y + (flipy ? 7 - v : v), - ch1 ? (color & 0x3) : (color >> 0x2)); + blending1bpp[ch1][color]); } } @@ -52,13 +62,13 @@ putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint for(h = 0; h < 8; h++) { Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1); - Uint8 id = ch1 + ch2 * 2; - if(id || color > 0x7) + Uint8 ch = ch1 + ch2 * 2; + if(ch || (color != 0x05 && color != 0x0a && color != 0x0f)) putpixel(p, layer, x + (flipx ? 7 - h : h), y + (flipy ? 7 - v : v), - (id < 2 ? id : color / 2 + id * (color % 8)) & 0x3); + blending2bpp[ch][color]); } }