Browse code

Started implementing the sprite port for the screen device

neauoire authored on 31/07/2021 02:23:02
Showing 4 changed files
... ...
@@ -54,7 +54,7 @@ then
54 54
 fi
55 55
 
56 56
 echo "Assembling.."
57
-./bin/uxnasm projects/examples/demos/piano.tal bin/piano.rom
57
+./bin/uxnasm projects/examples/devices/piano.tal bin/piano.rom
58 58
 
59 59
 echo "Running.."
60 60
 ./bin/uxnemu bin/piano.rom
... ...
@@ -7,7 +7,7 @@
7 7
 ( devices )
8 8
 
9 9
 |00 @System     [ &vector $2 &pad      $6 &r      $2 &g     $2 &b      $2 ]
10
-|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr $2 &color $1 ]
10
+|20 @Screen     [ &vector $2 &width    $2 &height $2 &pad   $2 &x      $2 &y     $2 &addr $2 &color $1 &sprite $1 ]
11 11
 
12 12
 ( variables )
13 13
 
... ...
@@ -44,7 +44,7 @@ BRK
44 44
 			.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
45 45
 		( move ) OVR #f0 AND #02 DIV #00 SWP 
46 46
 			.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
47
-		( draw ) OVR .Screen/color DEO
47
+		( draw ) OVR .Screen/sprite DEO
48 48
 		( incr ) SWP #01 ADD SWP
49 49
 		NEQk ,&loop JCN
50 50
 	POP2
... ...
@@ -60,12 +60,12 @@ RTN
60 60
 		OVR #08 MUL #00 SWP 
61 61
 		.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
62 62
 		.center/y LDZ2 #0050 SUB2 .Screen/y DEO2
63
-		( draw ) #21 .Screen/color DEO
63
+		( draw ) #01 .Screen/sprite DEO
64 64
 		( y-axis )
65 65
 		OVR #08 MUL #00 SWP 
66 66
 		.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
67 67
 		.center/x LDZ2 #0050 SUB2 .Screen/x DEO2
68
-		( draw ) #21 .Screen/color DEO
68
+		( draw ) #01 .Screen/sprite DEO
69 69
 		( incr ) SWP #01 ADD SWP
70 70
 		LTHk ,&loop JCN
71 71
 	POP2
... ...
@@ -77,14 +77,14 @@ RTN
77 77
 	;preview_icn .Screen/addr DEO2
78 78
 	.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
79 79
 	.center/y LDZ2 #0030 ADD2 .Screen/y DEO2
80
-	#21 .Screen/color DEO
80
+	#01 .Screen/sprite DEO
81 81
 	.center/x LDZ2 #0050 ADD2 .Screen/x DEO2
82
-	#61 .Screen/color DEO
82
+	#11 .Screen/sprite DEO
83 83
 	.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
84 84
 	.center/y LDZ2 #0038 ADD2 .Screen/y DEO2
85
-	#a1 .Screen/color DEO
85
+	#21 .Screen/sprite DEO
86 86
 	.center/x LDZ2 #0050 ADD2 .Screen/x DEO2
87
-	#f1 .Screen/color DEO
87
+	#31 .Screen/sprite DEO
88 88
 
89 89
 RTN
90 90
 
... ...
@@ -99,4 +99,4 @@ RTN
99 99
 	007c 8282 7c82 827c 007c 8282 7e02 827c
100 100
 	007c 8202 7e82 827e 00fc 8282 fc82 82fc
101 101
 	007c 8280 8080 827c 00fc 8282 8282 82fc
102
-	007c 8280 f080 827c 007c 8280 f080 8080 
103 102
\ No newline at end of file
103
+	007c 8280 f080 827c 007c 8280 f080 8080
... ...
@@ -53,12 +53,14 @@ puticn(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uin
53 53
 	for(v = 0; v < 8; v++)
54 54
 		for(h = 0; h < 8; h++) {
55 55
 			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
56
-			if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f))
57
-				putpixel(p,
58
-					layer,
59
-					x + (flipx ? 7 - h : h),
60
-					y + (flipy ? 7 - v : v),
61
-					ch1 ? color % 4 : color / 4);
56
+			if(!(ch1 || color % 0x5))
57
+				continue;
58
+			if(x < p->width && y < p->height) {
59
+				Uint16 px = x + (flipx ? 7 - h : h);
60
+				Uint16 py = y + (flipy ? 7 - v : v);
61
+				Uint8 pc = ch1 ? (color & 0x3) : (color >> 0x2);
62
+				layer->pixels[py * p->width + px] = layer->colors[pc];
63
+			}
62 64
 		}
63 65
 }
64 66
 
... ...
@@ -306,6 +306,16 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
306 306
 				putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4);
307 307
 		}
308 308
 		reqdraw = 1;
309
+	} else if(w && b0 == 0xf) {
310
+		Uint16 x = mempeek16(d->dat, 0x8);
311
+		Uint16 y = mempeek16(d->dat, 0xa);
312
+		Layer *layer = d->dat[0xf] >> 0x6 & 0x1 ? &ppu.fg : &ppu.bg;
313
+		Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
314
+		if(d->dat[0xf] >> 0x7 & 0x1)
315
+			putchr(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1);
316
+		else
317
+			puticn(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1);
318
+		reqdraw = 1;
309 319
 	}
310 320
 }
311 321