uxn

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

commit d2c3d0e524e801485c3f5cae89ea976d8146941f
parent 486e79c48db26f02bedeb0469a53e9f81fbabc80
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri, 30 Jul 2021 19:23:02 -0700

Started implementing the sprite port for the screen device

Diffstat:
Mbuild.sh | 2+-
Mprojects/examples/devices/screen.tal | 19+++++++++----------
Msrc/devices/ppu.c | 14++++++++------
Msrc/uxnemu.c | 10++++++++++
4 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/build.sh b/build.sh @@ -54,7 +54,7 @@ then fi echo "Assembling.." -./bin/uxnasm projects/examples/demos/piano.tal bin/piano.rom +./bin/uxnasm projects/examples/devices/piano.tal bin/piano.rom echo "Running.." ./bin/uxnemu bin/piano.rom diff --git a/projects/examples/devices/screen.tal b/projects/examples/devices/screen.tal @@ -7,7 +7,7 @@ ( devices ) |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] -|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] +|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 &sprite $1 ] ( variables ) @@ -44,7 +44,7 @@ BRK .center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2 ( move ) OVR #f0 AND #02 DIV #00 SWP .center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2 - ( draw ) OVR .Screen/color DEO + ( draw ) OVR .Screen/sprite DEO ( incr ) SWP #01 ADD SWP NEQk ,&loop JCN POP2 @@ -60,12 +60,12 @@ RTN OVR #08 MUL #00 SWP .center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2 .center/y LDZ2 #0050 SUB2 .Screen/y DEO2 - ( draw ) #21 .Screen/color DEO + ( draw ) #01 .Screen/sprite DEO ( y-axis ) OVR #08 MUL #00 SWP .center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2 .center/x LDZ2 #0050 SUB2 .Screen/x DEO2 - ( draw ) #21 .Screen/color DEO + ( draw ) #01 .Screen/sprite DEO ( incr ) SWP #01 ADD SWP LTHk ,&loop JCN POP2 @@ -77,14 +77,14 @@ RTN ;preview_icn .Screen/addr DEO2 .center/x LDZ2 #0048 ADD2 .Screen/x DEO2 .center/y LDZ2 #0030 ADD2 .Screen/y DEO2 - #21 .Screen/color DEO + #01 .Screen/sprite DEO .center/x LDZ2 #0050 ADD2 .Screen/x DEO2 - #61 .Screen/color DEO + #11 .Screen/sprite DEO .center/x LDZ2 #0048 ADD2 .Screen/x DEO2 .center/y LDZ2 #0038 ADD2 .Screen/y DEO2 - #a1 .Screen/color DEO + #21 .Screen/sprite DEO .center/x LDZ2 #0050 ADD2 .Screen/x DEO2 - #f1 .Screen/color DEO + #31 .Screen/sprite DEO RTN @@ -99,4 +99,4 @@ RTN 007c 8282 7c82 827c 007c 8282 7e02 827c 007c 8202 7e82 827e 00fc 8282 fc82 82fc 007c 8280 8080 827c 00fc 8282 8282 82fc - 007c 8280 f080 827c 007c 8280 f080 8080 -\ No newline at end of file + 007c 8280 f080 827c 007c 8280 f080 8080 diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -53,12 +53,14 @@ puticn(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uin for(v = 0; v < 8; v++) for(h = 0; h < 8; h++) { Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); - if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f)) - putpixel(p, - layer, - x + (flipx ? 7 - h : h), - y + (flipy ? 7 - v : v), - ch1 ? color % 4 : color / 4); + if(!(ch1 || color % 0x5)) + continue; + if(x < p->width && y < p->height) { + Uint16 px = x + (flipx ? 7 - h : h); + Uint16 py = y + (flipy ? 7 - v : v); + Uint8 pc = ch1 ? (color & 0x3) : (color >> 0x2); + layer->pixels[py * p->width + px] = layer->colors[pc]; + } } } diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -306,6 +306,16 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); } reqdraw = 1; + } else if(w && b0 == 0xf) { + Uint16 x = mempeek16(d->dat, 0x8); + Uint16 y = mempeek16(d->dat, 0xa); + Layer *layer = d->dat[0xf] >> 0x6 & 0x1 ? &ppu.fg : &ppu.bg; + Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; + if(d->dat[0xf] >> 0x7 & 0x1) + putchr(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); + else + puticn(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); + reqdraw = 1; } }