Browse code

Improved picture example

neauoire authored on 10/04/2021 19:19:38
Showing 5 changed files
... ...
@@ -32,7 +32,7 @@ else
32 32
 fi
33 33
 
34 34
 echo "Assembling.."
35
-./bin/assembler projects/examples/dev.mouse.usm bin/boot.rom
35
+./bin/assembler projects/examples/gui.mouse.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -4,31 +4,15 @@
4 4
 
5 5
 ( devices )
6 6
 
7
-|0100 ;Console { pad 8 char 1 byte 1 short 2 string 2 }
8
-|0110 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
9
-|0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
10
-|0130 ;Controller { p1 1 }
11
-|0140 ;Keys { key 1 }
12
-|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
13
-|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
7
+|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
8
+|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 string 2 }
9
+|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
14 10
 |0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
11
+|0140 ;Controller { vector 2 player1 1 player2 1 player3 1 player4 1 }
12
+|0150 ;Keyboard { vector 2 key 1 }
13
+|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
14
+|0170 ;File { vector 2 pad 6 name 2 length 2 load 3 save 2 }
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
-|01F0 ;System { pad 8 r 2 g 2 b 2 }
17 16
 
18
-( vectors )
17
+|0200 
19 18
 
20
-|0200 ^RESET JMP
21
-|0204 ,ERROR JMP2
22
-|0208 ,FRAME JMP2
23
-
24
-@RESET
25
-
26
-BRK
27
-
28
-@FRAME
29
-
30
-BRK
31
-
32
-@ERROR
33
-
34
-BRK
... ...
@@ -2,6 +2,7 @@
2 2
 
3 3
 %RTN { JMP2r }
4 4
 
5
+;pointer { x 2 y 2 sprite 2 } 
5 6
 ;pict { x 2 y 2 width 2 height 2 color 1 addr 2 }
6 7
 
7 8
 |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
... ...
@@ -10,19 +11,61 @@
10 11
 |0140 ;Controller { vector 2 button 1 }
11 12
 |0150 ;Keys { vector 2 key 1 }
12 13
 |0160 ;Mouse  { vector 2 x 2 y 2 state 1 chord 1 }
14
+|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
13 15
 
14 16
 ( program )
15 17
 
16 18
 |0200
17 19
 
18
-	( theme ) #0ffc =System.r #0f0b =System.g #0f03 =System.b
20
+	( theme ) #ac52 =System.r #a362 =System.g #b253 =System.b
21
+	( vectors ) ,on-mouse =Mouse.vector
22
+
23
+	( load )
19 24
 	
20
-	#0000 #0000 #0100 #0100 #21 ,pict_large ,draw-picture JSR2
21
-	#0098 #0060 #0080 #0080 #21 ,pict_medium ,draw-picture JSR2
22
-	#0020 #0090 #0020 #0020 #2a ,pict_small ,draw-picture JSR2
25
+	#0000 #0000 #0100 #0100 #2c ,pict_large ,draw-picture JSR2
26
+
27
+	( load ) ,filepath =File.name #4000 =File.length ,img =File.load
28
+	( draw ) #0080 #0020 #0100 #0100 #41 ,img ,draw-chr JSR2
29
+
30
+	#0128 #0010 #0080 #0080 #2e ,pict_medium ,draw-picture JSR2
31
+	#0020 #00d0 #0020 #0020 #25 ,pict_small ,draw-picture JSR2
23 32
 
24 33
 BRK
25 34
 
35
+@on-mouse 
36
+
37
+	( clear last cursor )
38
+	,clear_icn =Screen.addr 
39
+	~pointer.x =Screen.x 
40
+	~pointer.y =Screen.y 
41
+	#30 =Screen.color
42
+
43
+	( record pointer positions )
44
+	~Mouse.x =pointer.x ~Mouse.y =pointer.y
45
+
46
+	( draw new cursor )
47
+	,pointer_icn =Screen.addr 
48
+	~pointer.x =Screen.x 
49
+	~pointer.y =Screen.y 
50
+	#33 =Screen.color
51
+
52
+BRK 
53
+
54
+@draw-chr ( x y width height color addr )
55
+	
56
+	DUP2 =Screen.addr =pict.addr =pict.color =pict.height =pict.width DUP2 =Screen.y =pict.y =pict.x
57
+	$ver
58
+		~pict.x =Screen.x 
59
+		$hor
60
+			( draw ) ~pict.color =Screen.color
61
+			( incr ) ~Screen.x #0008 ADD2 =Screen.x
62
+			( incr ) ~Screen.addr #0010 ADD2 =Screen.addr
63
+		~Screen.x ~pict.width ~pict.x ADD2 LTH2 ^$hor JNZ
64
+		( incr ) ~Screen.y #0008 ADD2 =Screen.y
65
+	~Screen.y ~pict.height ~pict.y ADD2 LTH2 ^$ver JNZ
66
+
67
+RTN
68
+
26 69
 @draw-picture ( x y width height color addr )
27 70
 	
28 71
 	DUP2 =Screen.addr =pict.addr =pict.color =pict.height =pict.width DUP2 =Screen.y =pict.y =pict.x
... ...
@@ -38,6 +81,9 @@ BRK
38 81
 
39 82
 RTN
40 83
 
84
+@clear_icn   [ 0000 0000 0000 0000 ]
85
+@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
86
+
41 87
 @pict_small [
42 88
 	ff80 8080 8080 8088 ffff fffc f8f9 f1f4
43 89
 	ffff 0010 c721 2120 ffff 3f0f 0717 c343
... ...
@@ -312,3 +358,7 @@ RTN
312 358
 	1081 4182 0500 0000 aa25 512a 44aa 0000 0254 0992 4984 0000 9452 4925 5289 0000
313 359
 
314 360
 ]
361
+
362
+@filepath      [ projects/pictures/zerotwo2020.chr 00 ]
363
+
364
+|3000 @img
315 365
\ No newline at end of file
316 366
new file mode 100644
317 367
Binary files /dev/null and b/projects/pictures/zerotwo2020.chr differ
... ...
@@ -130,7 +130,7 @@ putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
130 130
 		for(h = 0; h < 8; h++) {
131 131
 			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color;
132 132
 			Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color;
133
-			putpixel(p, layer, x + h, y + v, (ch1 - ch2 + color / 4) & 0x3);
133
+			putpixel(p, layer, x + h, y + v, (((ch1 + ch2 * 2) + color - 1) & 0x3));
134 134
 		}
135 135
 }
136 136