Browse code

Added blending modes to color

neauoire authored on 22/02/2021 00:52:51
Showing 9 changed files
... ...
@@ -98,17 +98,15 @@ A device that works like a NES controller, each button is a bit from a single by
98 98
 
99 99
 ## TODOs
100 100
 
101
-- LDR/STR helpers
102 101
 - Line routine
103
-- On-screen debugger.
104 102
 - Getting rid of IOR/IOW would be nice..
105
-- Sending from the wst to the rst, balance counter?
106 103
 
107 104
 ### Misc TODOs
108 105
 
109 106
 - Includes
110 107
 - Defines
111
-- Lint, print unused labels
108
+- Print unused labels
109
+- Blending mode
112 110
 
113 111
 ## Refs
114 112
 
... ...
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
20 20
 # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
21 21
 
22 22
 # run
23
-./bin/assembler examples/paint.usm bin/boot.rom
23
+./bin/assembler examples/devmouse.usm bin/boot.rom
24 24
 ./bin/emulator bin/boot.rom
... ...
@@ -106,14 +106,13 @@ paintchr(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite)
106 106
 }
107 107
 
108 108
 void
109
-painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 fg, Uint8 alpha)
109
+painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 blend)
110 110
 {
111 111
 	Uint16 v, h;
112 112
 	for(v = 0; v < 8; v++)
113 113
 		for(h = 0; h < 8; h++) {
114 114
 			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
115
-			if(!alpha || (alpha && ch1))
116
-				paintpixel(dst, x + h, y + v, ch1 ? fg : 0);
115
+			paintpixel(dst, x + h, y + v, ch1 ? blend % 4 : blend / 4);
117 116
 		}
118 117
 }
119 118
 
... ...
@@ -357,12 +356,12 @@ spritew(Device *d, Memory *m, Uint8 b)
357 356
 		Uint16 x = (d->mem[2] << 8) + d->mem[3];
358 357
 		Uint16 y = (d->mem[0] << 8) + d->mem[1];
359 358
 		Uint16 a = (d->mem[4] << 8) + d->mem[5];
360
-		Uint8 clr = d->mem[6] & 0xf;
361
-		Uint8 layer = d->mem[6] >> 4 & 0xf;
362
-		if(clr > 7)
363
-			paintchr(layer ? screen.fg : screen.bg, x, y, &m->dat[a]);
359
+		Uint8 source = d->mem[6] >> 4 & 0xf;
360
+		Uint8 *layer = source % 2 ? screen.fg : screen.bg;
361
+		if(source / 2)
362
+			paintchr(layer, x, y, &m->dat[a]);
364 363
 		else
365
-			painticn(layer ? screen.fg : screen.bg, x, y, &m->dat[a], clr % 4, clr > 3);
364
+			painticn(layer, x, y, &m->dat[a], d->mem[6] & 0xf);
366 365
 		screen.reqdraw = 1;
367 366
 		d->ptr = 0;
368 367
 	}
369 368
new file mode 100644
... ...
@@ -0,0 +1,46 @@
1
+( desktop )
2
+
3
+:dev/w fff9 ( const write port )
4
+
5
+;x1 2 ;y1 2
6
+
7
+;x 2 ;y 2 ;color 1
8
+
9
+|0100 @RESET 
10
+	
11
+	#02 =dev/w 
12
+
13
+	#01 =color
14
+	#00 ,icon #0040 #0040 ,draw-sprite JSR
15
+	#01 ,icon #0048 #0040 ,draw-sprite JSR
16
+	#02 ,icon #0050 #0040 ,draw-sprite JSR
17
+	#03 ,icon #0058 #0040 ,draw-sprite JSR
18
+	#04 ,icon #0040 #0048 ,draw-sprite JSR
19
+	#05 ,icon #0048 #0048 ,draw-sprite JSR
20
+	#06 ,icon #0050 #0048 ,draw-sprite JSR
21
+	#07 ,icon #0058 #0048 ,draw-sprite JSR
22
+	#08 ,icon #0040 #0050 ,draw-sprite JSR
23
+	#09 ,icon #0048 #0050 ,draw-sprite JSR
24
+	#0a ,icon #0050 #0050 ,draw-sprite JSR
25
+	#0b ,icon #0058 #0050 ,draw-sprite JSR
26
+	#0c ,icon #0040 #0058 ,draw-sprite JSR
27
+	#0d ,icon #0048 #0058 ,draw-sprite JSR
28
+	#0e ,icon #0050 #0058 ,draw-sprite JSR
29
+	#0f ,icon #0058 #0058 ,draw-sprite JSR
30
+
31
+BRK
32
+
33
+@icon [ 3c7e e7c3 c3e7 7e3c ]
34
+
35
+@draw-sprite
36
+	IOW2 ( y byte )
37
+	IOW2 ( x byte )
38
+	IOW2 ( sprite address )
39
+	IOW ( layer-color )
40
+	RTS
41
+
42
+|c000 @FRAME
43
+|d000 @ERROR 
44
+
45
+|FFF0 [ f3f0 f30b f30a ] ( palette )
46
+|FFFA .RESET .FRAME .ERROR
0 47
\ No newline at end of file
... ...
@@ -14,11 +14,12 @@
14 14
 BRK
15 15
 
16 16
 @displaycli
17
-	
17
+
18 18
 	@cliloop
19 19
 		DUP2 LDR IOW                             ( write pointer value to console )
20 20
 		#0001 ADD2                               ( increment string pointer )
21 21
 		DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2  ( while *ptr!=0 goto loop )
22
+		
22 23
 RTS
23 24
 
24 25
 @text " Hello World "                     ( add characters to memory )
... ...
@@ -11,7 +11,7 @@
11 11
 	#02 =dev/w ( set dev/write to sprite ) 
12 12
 	#0080 =x #0040 =y ( origin )
13 13
 
14
-	#02 ,up_icn ~x ~y ,draw-sprite JSR
14
+	#12 ,up_icn ~x ~y ,draw-sprite JSR
15 15
 
16 16
 BRK
17 17
 
... ...
@@ -38,7 +38,7 @@ BRK
38 38
 		~x #0001 ADD2 =x
39 39
 	@end
40 40
 	( redraw )
41
-	#03 ~sprite ~x ~y ,draw-sprite JSR
41
+	#13 ~sprite ~x ~y ,draw-sprite JSR
42 42
 
43 43
 BRK
44 44
 
... ...
@@ -103,7 +103,7 @@ RTS
103 103
 	IOW2 ( y byte )
104 104
 	IOW2 ( x byte )
105 105
 	IOW2 ( sprite address )
106
-	#08 IOW ( layer-color )
106
+	#20 IOW ( layer-color )
107 107
 	RTS
108 108
 
109 109
 @clear_icn   [ 0000 0000 0000 0000 ]
110 110
similarity index 70%
111 111
rename from examples/text.usm
112 112
rename to examples/label.usm
... ...
@@ -1,61 +1,46 @@
1
-( hello world )
1
+( desktop )
2 2
 
3 3
 :dev/w fff9 ( const write port )
4 4
 
5
+;x1 2 ;y1 2
6
+
5 7
 ;x 2 ;y 2 ;color 1
6 8
 
7 9
 |0100 @RESET 
8
-
9
-	( print to console )
10
-	,string ,displaycli JSR
11
-	
12
-	( print to screen )
13
-	#0008 =x #0030 =y #01 =color
14
-	,string ,displaygui JSR 
15
-	#0010 =x #0038 =y #02 =color
16
-	,string ,displaygui JSR 
17
-	#0018 =x #0040 =y #03 =color
18
-	,string ,displaygui JSR 
19 10
 	
11
+	#02 =dev/w 
20 12
 
21
-BRK
22
-
23
-@string " Hello Merveilles "                     ( add string to memory )
13
+	#01 =color
14
+	,text #0020 #0030 ,draw-label JSR
15
+	#02 =color
16
+	,text #0022 #0038 ,draw-label JSR
17
+	#03 =color
18
+	,text #0024 #0040 ,draw-label JSR
19
+	#04 =color
20
+	,text #0026 #0048 ,draw-label JSR
21
+	#06 =color
22
+	,text #0028 #0050 ,draw-label JSR
23
+	#07 =color
24
+	,text #002a #0058 ,draw-label JSR
25
+	#08 =color
26
+	,text #002c #0060 ,draw-label JSR
27
+	#09 =color
28
+	,text #002e #0068 ,draw-label JSR
24 29
 
25
-@displaycli
26
-	#00 =dev/w                                   ( set dev/write to console ) 
27
-	@cliloop
28
-		DUP2 LDR IOW                             ( write pointer value to console )
29
-		#0001 ADD2                               ( increment string pointer )
30
-		DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2  ( while *ptr!=0 goto loop )
31
-	RTS
32
-
33
-@displaygui
34
-	#02 =dev/w                                   ( set dev/write to sprite ) 
35
-	@guiloop
36
-		DUP2 LDR ,printchar JSR
37
-		#0001 ADD2
38
-		~x #0008 ADD2 =x
39
-		DUP2 LDR #00 NEQ ,guiloop ROT JMP? POP2
40
-	RTS
41
-
42
-@printchar
43
-	~color ,getchar JSR ~x ~y ,draw-sprite JSR
44
-	RTS
45
-
46
-@getchar
47
-	#00 SWP #0008 MUL2 ,SPRITESHEET ADD2
48
-	RTS
30
+BRK
49 31
 
50
-@draw-sprite
51
-	IOW2 ( y byte )
52
-	IOW2 ( x byte )
53
-	IOW2 ( sprite address )
54
-	IOW ( layer-color )
55
-	RTS
32
+@text " Hello World " ( add string to memory )
56 33
 
57
-|0300 @SPRITESHEET ( first 128 characters of the spectrum-zx font ) 
34
+@draw-label ( x1 y1 text )
35
+	=y1 =x1
36
+	@draw-label-loop
37
+		( draw ) ~x1 ~y1 IOW2 IOW2 DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 IOW2 ~color IOW
38
+		( incr ) #0001 ADD2
39
+		( incr ) ~x1 #0008 ADD2 =x1
40
+		DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2
41
+RTS
58 42
 
43
+@font ( spectrum-zx font ) 
59 44
 [
60 45
 	0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
61 46
 	0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
... ...
@@ -10,18 +10,18 @@
10 10
 	#01 =dev/w ( set dev/write to screen ) 
11 11
 
12 12
 	#01 =color
13
-	#0020 #0020 #0060 #0060 ,fill-rect JSR
13
+	#0010 #0020 #0040 #0060 ,fill-rect JSR
14 14
 	#02 =color
15
-	#0030 #0030 #0070 #0070 ,fill-rect JSR
15
+	#0020 #0030 #0050 #0070 ,fill-rect JSR
16 16
 	#03 =color
17
-	#0040 #0040 #0080 #0080 ,fill-rect JSR
17
+	#0030 #0040 #0060 #0080 ,fill-rect JSR
18 18
 
19 19
 	#01 =color
20
-	#0090 #0020 #00d0 #0060 ,line-rect JSR
20
+	#0070 #0020 #00a0 #0060 ,line-rect JSR
21 21
 	#02 =color
22
-	#00a0 #0030 #00e0 #0070 ,line-rect JSR
22
+	#0080 #0030 #00b0 #0070 ,line-rect JSR
23 23
 	#03 =color
24
-	#00b0 #0040 #00f0 #0080 ,line-rect JSR
24
+	#0090 #0040 #00c0 #0080 ,line-rect JSR
25 25
 	
26 26
 BRK
27 27
 
... ...
@@ -71,5 +71,5 @@ RTS
71 71
 
72 72
 |c000 @FRAME BRK 
73 73
 |d000 @ERROR BRK 
74
-|FFF0 [ f2ac 35bb 2b5f ] ( palette )
74
+|FFF0 [ 0f0f 0fff 0ff0 ] ( palette )
75 75
 |FFFA .RESET .FRAME .ERROR ( vectors )
76 76
\ No newline at end of file