Browse code

Revamped the screen example

neauoire authored on 09/04/2021 19:15:38
Showing 7 changed files
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/examples/gui.shapes.usm bin/boot.rom
35
+./bin/assembler projects/examples/dev.screen.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -11,7 +11,7 @@
11 11
 |0140 ;Keys { key 1 }
12 12
 |0150 ;Mouse { x 2 y 2 state 1 chord 1 }
13 13
 |0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
14
-|0180 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
14
+|0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
15 15
 |01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dotw 1 doty 2 isdst 1 refresh 1 }
16 16
 |01F0 ;System { pad 8 r 2 g 2 b 2 }
17 17
 
... ...
@@ -33,7 +33,7 @@
33 33
 |0150 ;Keys { vector 2 key 1 }
34 34
 |0160 ;Mouse  { vector 2 x 2 y 2 state 1 chord 1 }
35 35
 |0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
36
-|0180 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
36
+|0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
37 37
 
38 38
 ( vectors )
39 39
 
... ...
@@ -15,6 +15,7 @@
15 15
 ;label { x 2 y 2 addr 2 }
16 16
 ;slider { x1 2 y 2 x2 2 pos 2 }
17 17
 ;selection { byte 1 }
18
+;addr { short 2 }
18 19
 ;theme { 
19 20
 	r1 1 r2 1 r3 1 r4 1 
20 21
 	g1 1 g2 1 g3 1 g4 1 
... ...
@@ -32,7 +33,7 @@
32 33
 	( theme ) #127f =System.r #34e7 =System.g #56c4 =System.b
33 34
 	( vectors ) ,on-mouse =Mouse.vector
34 35
 	
35
-	#00a0 =window.w
36
+	#00b0 =window.w
36 37
 	#0050 =window.h
37 38
 
38 39
 	( center window )
... ...
@@ -64,19 +65,19 @@ BRK
64 65
 	~Mouse.y ~window.y1 SUB2 STEP8 
65 66
 
66 67
 	DUP2 #0010 NEQ2 ^$no-touch-red JNZ
67
-		~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-red JNZ
68
-		~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-red JNZ
69
-		( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.r1 #00 ~selection ADD2 POK2
68
+		~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-red JNZ
69
+		~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-red JNZ
70
+		( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.r1 #00 ~selection ADD2 POK2
70 71
 	$no-touch-red
71 72
 	DUP2 #0020 NEQ2 ^$no-touch-green JNZ
72
-		~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-green JNZ
73
-		~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-green JNZ
74
-		( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.g1 #00 ~selection ADD2 POK2
73
+		~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-green JNZ
74
+		~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-green JNZ
75
+		( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.g1 #00 ~selection ADD2 POK2
75 76
 	$no-touch-green
76 77
 	DUP2 #0030 NEQ2 ^$no-touch-blue JNZ
77
-		~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-blue JNZ
78
-		~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-blue JNZ
79
-		( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.b1 #00 ~selection ADD2 POK2
78
+		~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-blue JNZ
79
+		~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-blue JNZ
80
+		( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.b1 #00 ~selection ADD2 POK2
80 81
 	$no-touch-blue
81 82
 	DUP2 #0040 NEQ2 ^$no-touch-radio JNZ
82 83
 		~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-radio JNZ
... ...
@@ -129,13 +130,54 @@ RTN
129 130
 	POP2 POP2
130 131
 
131 132
 	( draw blending modes )
132
-	#0000 =Screen.x #0020 =Screen.y ,icon_icn =Screen.addr
133
-	#20 #30
134
-	$draw-blends
135
-		( move ) OVR #00 SWP #0008 MUL2 =Screen.x
133
+	,preview_icn =Screen.addr
134
+	#0010 =Screen.y 
135
+	#00 #08
136
+	$draw-pixel1
137
+		( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
136 138
 		( draw ) OVR =Screen.color
137 139
 		( incr ) SWP #01 ADD SWP 
138
-		DUP2 LTH ^$draw-blends JNZ
140
+		DUP2 LTH ^$draw-pixel1 JNZ
141
+	POP POP
142
+	#0018 =Screen.y
143
+	#00 #08
144
+	$draw-pixel2
145
+		( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
146
+		( draw ) OVR #08 ADD =Screen.color
147
+		( incr ) SWP #01 ADD SWP 
148
+		DUP2 LTH ^$draw-pixel2 JNZ
149
+	POP POP
150
+	#0020 =Screen.y 
151
+	#00 #08
152
+	$draw-icn1
153
+		( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
154
+		( draw ) OVR #20 ADD =Screen.color
155
+		( incr ) SWP #01 ADD SWP 
156
+		DUP2 LTH ^$draw-icn1 JNZ
157
+	POP POP
158
+	#0028 =Screen.y
159
+	#00 #08
160
+	$draw-icn2
161
+		( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
162
+		( draw ) OVR #28 ADD =Screen.color
163
+		( incr ) SWP #01 ADD SWP 
164
+		DUP2 LTH ^$draw-icn2 JNZ
165
+	POP POP
166
+	#0030 =Screen.y 
167
+	#00 #08
168
+	$draw-chr1
169
+		( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
170
+		( draw ) OVR #40 ADD =Screen.color
171
+		( incr ) SWP #01 ADD SWP 
172
+		DUP2 LTH ^$draw-chr1 JNZ
173
+	POP POP
174
+	#0038 =Screen.y
175
+	#00 #08
176
+	$draw-chr2
177
+		( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
178
+		( draw ) OVR #48 ADD =Screen.color
179
+		( incr ) SWP #01 ADD SWP 
180
+		DUP2 LTH ^$draw-chr2 JNZ
139 181
 	POP POP
140 182
 
141 183
 RTN
... ...
@@ -149,12 +191,20 @@ RTN
149 191
 	~window.x1 #0002 SUB2 ~window.y1 #0002 SUB2 ~window.x2 #0002 ADD2 ~window.y2 #0002 ADD2 #01 ,line-rect JSR2
150 192
 
151 193
 	~window.x1 #0008 ADD2 ~window.y1 #0010 ADD2 #25 ,red_txt ,draw-label JSR2
194
+	~window.x1 #0038 ADD2 ~window.y1 #0010 ADD2 #28 ,System.r ,draw-byte JSR2
195
+	~window.x1 #0048 ADD2 ~window.y1 #0010 ADD2 #28 ,System.r #0001 ADD2 ,draw-byte JSR2
196
+
152 197
 	~window.x1 #0008 ADD2 ~window.y1 #0020 ADD2 #25 ,green_txt ,draw-label JSR2
198
+	~window.x1 #0038 ADD2 ~window.y1 #0020 ADD2 #28 ,System.g ,draw-byte JSR2
199
+	~window.x1 #0048 ADD2 ~window.y1 #0020 ADD2 #28 ,System.g #0001 ADD2 ,draw-byte JSR2
200
+
153 201
 	~window.x1 #0008 ADD2 ~window.y1 #0030 ADD2 #25 ,blue_txt ,draw-label JSR2
202
+	~window.x1 #0038 ADD2 ~window.y1 #0030 ADD2 #28 ,System.b ,draw-byte JSR2
203
+	~window.x1 #0048 ADD2 ~window.y1 #0030 ADD2 #28 ,System.b #0001 ADD2 ,draw-byte JSR2
154 204
 
155
-	~window.x1 #0050 ADD2 ~window.y1 #0010 ADD2 ~window.x1 #0080 ADD2 #00 ,theme.r1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
156
-	~window.x1 #0050 ADD2 ~window.y1 #0020 ADD2 ~window.x1 #0080 ADD2 #00 ,theme.g1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
157
-	~window.x1 #0050 ADD2 ~window.y1 #0030 ADD2 ~window.x1 #0080 ADD2 #00 ,theme.b1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
205
+	~window.x1 #0060 ADD2 ~window.y1 #0010 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.r1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
206
+	~window.x1 #0060 ADD2 ~window.y1 #0020 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.g1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
207
+	~window.x1 #0060 ADD2 ~window.y1 #0030 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.b1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
158 208
 
159 209
 	~window.x1 #0050 ADD2 =Screen.x
160 210
 	~window.y1 #0040 ADD2 =Screen.y
... ...
@@ -178,7 +228,7 @@ RTN
178 228
 
179 229
 RTN
180 230
 
181
-@draw-cursor
231
+@draw-cursor ( -- )
182 232
 
183 233
 	( clear last cursor )
184 234
 	,clear_icn =Screen.addr 
... ...
@@ -193,11 +243,11 @@ RTN
193 243
 	,pointer_icn =Screen.addr 
194 244
 	~pointer.x =Screen.x 
195 245
 	~pointer.y =Screen.y 
196
-	#33 =Screen.color
246
+	#33 ~Mouse.state #00 NEQ #02 MUL SUB =Screen.color
197 247
 
198 248
 RTN
199 249
 
200
-@draw-slider ( x1 y x2 pos color )
250
+@draw-slider ( x1 y x2 pos color -- )
201 251
 	
202 252
 	( load ) =color =slider.pos =slider.x2 =slider.y =slider.x1
203 253
 
... ...
@@ -224,7 +274,7 @@ RTN
224 274
 
225 275
 RTN
226 276
 
227
-@fill-rect ( x1 y1 x2 y2 color )
277
+@fill-rect ( x1 y1 x2 y2 color -- )
228 278
 
229 279
 	( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
230 280
 	$ver
... ...
@@ -238,7 +288,7 @@ RTN
238 288
 
239 289
 RTN
240 290
 
241
-@line-rect ( x1 y1 x2 y2 color )
291
+@line-rect ( x1 y1 x2 y2 color -- )
242 292
 
243 293
 	( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
244 294
 	$hor
... ...
@@ -255,7 +305,7 @@ RTN
255 305
 
256 306
 RTN
257 307
 
258
-@draw-label ( x y color addr )
308
+@draw-label ( x y color addr -- )
259 309
 	
260 310
 	( load ) =label.addr =color =Screen.y =Screen.x ~label.addr
261 311
 	$loop
... ...
@@ -267,6 +317,19 @@ RTN
267 317
 
268 318
 RTN
269 319
 
320
+@draw-byte ( x y color addr -- )
321
+
322
+	=addr STH
323
+	=Screen.y
324
+	=Screen.x
325
+	,font_hex #00 ~addr PEK2 #04 SFT #0008 MUL2 ADD2 =Screen.addr
326
+	STHr DUP STH =Screen.color
327
+	,font_hex #00 ~addr PEK2 #0f AND #0008 MUL2 ADD2 =Screen.addr
328
+	~Screen.x 8+ =Screen.x
329
+	STHr =Screen.color
330
+
331
+RTN
332
+
270 333
 @clear_icn    [ 0000 0000 0000 0000 ]
271 334
 @pointer_icn  [ 80c0 e0f0 f8e0 1000 ]
272 335
 @halftone_icn [ aa55 aa55 aa55 aa55 ]
... ...
@@ -274,7 +337,7 @@ RTN
274 337
 @sliderb_icn  [ ffff ffff ffff ffff ]
275 338
 @sliderc_icn  [ fcfe ffff ffff fefc ]
276 339
 @sliderd_icn  [ 003c 7e7e 7e7e 3c00 ]
277
-@icon_icn     [ 3c7e e7c3 c3e7 7e3c ]
340
+@preview_icn     [ 183c 66db db66 3c18 0000 183c 3c18 0000 ]
278 341
 @radio_icns  
279 342
 	[ 3c42 8181 8181 423c ]
280 343
 	[ 3c42 99bd bd99 423c ]
... ...
@@ -283,6 +346,18 @@ RTN
283 346
 @green_txt    [ Green 00 ]
284 347
 @blue_txt     [ Blue 00 ]
285 348
 
349
+@font_hex ( 0-F TODO: should pull from @font instead.. ) 
350
+[
351
+	003c 464a 5262 3c00 0018 0808 0808 1c00
352
+	003c 4202 3c40 7e00 003c 421c 0242 3c00
353
+	000c 1424 447e 0400 007e 407c 0242 3c00
354
+	003c 407c 4242 3c00 007e 0204 0810 1000
355
+	003c 423c 4242 3c00 003c 4242 3e02 3c00
356
+	003c 4242 7e42 4200 007c 427c 4242 7c00 
357
+	003c 4240 4042 3c00 007c 4242 4242 7c00 
358
+	007e 4078 4040 7e00 007e 4078 4040 4000
359
+]
360
+
286 361
 @font ( spectrum-zx font ) 
287 362
 [
288 363
 	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
... ...
@@ -215,10 +215,11 @@ screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
215 215
 		Uint16 y = mempeek16(u, ptr + 10);
216 216
 		Uint8 *addr = &u->ram.dat[mempeek16(u, ptr + 12)];
217 217
 		Uint8 *layer = (b1 >> 4 & 0xf) % 2 ? ppu.fg : ppu.bg;
218
-		if((b1 >> 4 & 0xf) / 2)
219
-			putsprite(&ppu, layer, x, y, addr, b1 & 0xf);
220
-		else
221
-			putpixel(&ppu, layer, x, y, b1 & 0xf);
218
+		switch((b1 >> 4) / 2) {
219
+		case 0: putpixel(&ppu, layer, x, y, b1 & 0x3); break;
220
+		case 1: puticn(&ppu, layer, x, y, addr, b1 & 0xf); break;
221
+		case 2: putchr(&ppu, layer, x, y, addr, b1 & 0xf); break;
222
+		}
222 223
 		reqdraw = 1;
223 224
 	}
224 225
 	return b1;
... ...
@@ -384,13 +385,12 @@ main(int argc, char **argv)
384 385
 	devsystem = portuxn(&u, 0x00, "system", system_poke);
385 386
 	portuxn(&u, 0x01, "console", console_poke);
386 387
 	devscreen = portuxn(&u, 0x02, "screen", screen_poke);
387
-	portuxn(&u, 0x03, "---", ppnil);
388
+	devapu = portuxn(&u, 0x03, "audio", audio_poke);
388 389
 	devctrl = portuxn(&u, 0x04, "controller", ppnil);
389 390
 	devkey = portuxn(&u, 0x05, "key", ppnil);
390 391
 	devmouse = portuxn(&u, 0x06, "mouse", ppnil);
391 392
 	portuxn(&u, 0x07, "file", file_poke);
392
-	devapu = portuxn(&u, 0x08, "audio", audio_poke);
393
-	apu.channel_addr = devapu->addr + 0xa;
393
+	portuxn(&u, 0x03, "---", ppnil);
394 394
 	portuxn(&u, 0x09, "midi", ppnil);
395 395
 	portuxn(&u, 0x0a, "datetime", datetime_poke);
396 396
 	portuxn(&u, 0x0b, "---", ppnil);
... ...
@@ -399,6 +399,8 @@ main(int argc, char **argv)
399 399
 	portuxn(&u, 0x0e, "---", ppnil);
400 400
 	portuxn(&u, 0x0f, "---", ppnil);
401 401
 
402
+	apu.channel_addr = devapu->addr + 0xa;
403
+
402 404
 	/* Write screen size to dev/screen */
403 405
 	mempoke16(&u, devscreen->addr + 2, ppu.hor * 8);
404 406
 	mempoke16(&u, devscreen->addr + 4, ppu.ver * 8);
... ...
@@ -110,7 +110,7 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
110 110
 }
111 111
 
112 112
 void
113
-putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
113
+puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
114 114
 {
115 115
 	Uint16 v, h;
116 116
 	for(v = 0; v < 8; v++)
... ...
@@ -122,6 +122,18 @@ putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
122 122
 		}
123 123
 }
124 124
 
125
+void
126
+putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
127
+{
128
+	Uint16 v, h;
129
+	for(v = 0; v < 8; v++)
130
+		for(h = 0; h < 8; h++) {
131
+			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color;
132
+			Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color;
133
+			putpixel(p, layer, x + h, y + v, (ch1 - ch2 + color / 4) & 0x3);
134
+		}
135
+}
136
+
125 137
 void
126 138
 getcolors(Ppu *p, Uint8 *addr)
127 139
 {
... ...
@@ -27,4 +27,5 @@ void drawppu(Ppu *p);
27 27
 void drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr);
28 28
 void getcolors(Ppu *p, Uint8 *addr);
29 29
 void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
30
-void putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
31 30
\ No newline at end of file
31
+void puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
32
+void putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
32 33
\ No newline at end of file