Browse code

Optimizing drawing routines

neauoire authored on 14/04/2021 19:11:01
Showing 5 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/gui.picture.usm bin/boot.rom
36 36
 
37 37
 echo "Running.."
38 38
 if [ "${2}" = '--cli' ]; 
... ...
@@ -1,13 +1,14 @@
1 1
 ( GUI Picture )
2 2
 
3 3
 %RTN { JMP2r }
4
+%8+  { #0008 ADD2 }
4 5
 
5
-;pointer { x 2 y 2 sprite 2 } 
6
-;pict { x 2 y 2 width 2 height 2 color 1 addr 2 }
6
+;color { byte 1 }
7
+;position { x 2 y 2 }
8
+;size { width 2 height 2 }
7 9
 
8 10
 |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
9 11
 |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 }
10
-|0160 ;Mouse  { vector 2 x 2 y 2 state 1 chord 1 }
11 12
 |0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 }
12 13
 
13 14
 ( program )
... ...
@@ -15,18 +16,15 @@
15 16
 |0200
16 17
 
17 18
 	( theme ) #ac52 =System.r #a362 =System.g #b253 =System.b
18
-	( vectors ) ,on-mouse =Mouse.vector
19 19
 	( vectors ) ,on-transfer =File.vector
20 20
 
21
-	( load )
21
+	( background ) ,checker_icn #23 ,cover-pattern JSR2
22 22
 	
23
-	#0000 #0000 #0100 #0100 #2c ,pict_large ,draw-picture JSR2
23
+	#0008 #0008 #0100 #00c0 #2c ,pict_large ,draw-icn JSR2
24 24
 
25
+	#0020 #00d0 #0020 #0020 #25 ,pict_small ,draw-icn JSR2
25 26
 
26
-	#0128 #0010 #0080 #0080 #2e ,pict_medium ,draw-picture JSR2
27
-	#0020 #00d0 #0020 #0020 #25 ,pict_small ,draw-picture JSR2
28
-
29
-	#0010 #0010 #0020 #0010 #25 ,dvd_icn ,draw-picture JSR2
27
+	#0010 #0010 #0020 #0010 #25 ,dvd_icn ,draw-icn JSR2
30 28
 
31 29
 	( load ) ,filepath =File.name #4000 =File.length ,img =File.load
32 30
 
... ...
@@ -35,58 +33,71 @@ BRK
35 33
 @on-transfer ( -> )
36 34
 
37 35
 	( draw ) #0080 #0020 #0100 #0100 #41 ,img ,draw-chr JSR2
36
+	#0128 #0010 #0080 #0080 #2e ,pict_medium ,draw-icn JSR2
38 37
 
39 38
 BRK
40 39
 
41
-@on-mouse ( -> )
42
-
43
-	( clear last cursor )
44
-	,clear_icn =Screen.addr 
45
-	~pointer.x =Screen.x 
46
-	~pointer.y =Screen.y 
47
-	#30 =Screen.color
48
-
49
-	( record pointer positions )
50
-	~Mouse.x =pointer.x ~Mouse.y =pointer.y
51
-
52
-	( draw new cursor )
53
-	,pointer_icn =Screen.addr 
54
-	~pointer.x =Screen.x 
55
-	~pointer.y =Screen.y 
56
-	#33 =Screen.color
40
+@draw-icn ( x y width height color addr -- )
41
+	
42
+	( load ) =Screen.addr =color =size.height =size.width =position.y =position.x
43
+	#0000 ~size.height
44
+	$ver
45
+		( save ) OVR2 ~position.y ADD2 =Screen.y
46
+		#0000 ~size.width
47
+		$hor
48
+			( save ) OVR2 ~position.x ADD2 =Screen.x
49
+			( draw ) ~color =Screen.color
50
+			( incr ) ~Screen.addr 8+ =Screen.addr
51
+			( incr ) SWP2 8+ SWP2
52
+			OVR2 OVR2 LTH2 ^$hor JNZ
53
+		POP2 POP2
54
+		( incr ) SWP2 8+ SWP2
55
+		OVR2 OVR2 LTH2 ^$ver JNZ
56
+	POP2 POP2
57 57
 
58
-BRK 
58
+RTN
59 59
 
60
-@draw-chr ( x y width height color addr )
60
+@draw-chr ( x y width height color addr -- )
61 61
 	
62
-	DUP2 =Screen.addr =pict.addr =pict.color =pict.height =pict.width DUP2 =Screen.y =pict.y =pict.x
62
+	( load ) =Screen.addr =color =size.height =size.width =position.y =position.x
63
+	#0000 ~size.height
63 64
 	$ver
64
-		~pict.x =Screen.x 
65
+		( save ) OVR2 ~position.y ADD2 =Screen.y
66
+		#0000 ~size.width
65 67
 		$hor
66
-			( draw ) ~pict.color =Screen.color
67
-			( incr ) ~Screen.x #0008 ADD2 =Screen.x
68
+			( save ) OVR2 ~position.x ADD2 =Screen.x
69
+			( draw ) ~color =Screen.color
68 70
 			( incr ) ~Screen.addr #0010 ADD2 =Screen.addr
69
-		~Screen.x ~pict.width ~pict.x ADD2 LTH2 ^$hor JNZ
70
-		( incr ) ~Screen.y #0008 ADD2 =Screen.y
71
-	~Screen.y ~pict.height ~pict.y ADD2 LTH2 ^$ver JNZ
71
+			( incr ) SWP2 8+ SWP2
72
+			OVR2 OVR2 LTH2 ^$hor JNZ
73
+		POP2 POP2
74
+		( incr ) SWP2 8+ SWP2
75
+		OVR2 OVR2 LTH2 ^$ver JNZ
76
+	POP2 POP2
72 77
 
73 78
 RTN
74 79
 
75
-@draw-picture ( x y width height color addr )
80
+@cover-pattern ( addr color -- )
76 81
 	
77
-	DUP2 =Screen.addr =pict.addr =pict.color =pict.height =pict.width DUP2 =Screen.y =pict.y =pict.x
82
+	( load ) =color =Screen.addr
83
+	#0000 ~Screen.height
78 84
 	$ver
79
-		~pict.x =Screen.x 
85
+		( save ) OVR2 =Screen.y
86
+		#0000 ~Screen.width
80 87
 		$hor
81
-			( draw ) ~pict.color =Screen.color
82
-			( incr ) ~Screen.x #0008 ADD2 =Screen.x
83
-			( incr ) ~Screen.addr #0008 ADD2 =Screen.addr
84
-		~Screen.x ~pict.width ~pict.x ADD2 LTH2 ^$hor JNZ
85
-		( incr ) ~Screen.y #0008 ADD2 =Screen.y
86
-	~Screen.y ~pict.height ~pict.y ADD2 LTH2 ^$ver JNZ
88
+			( save ) OVR2 =Screen.x
89
+			( draw ) ~color =Screen.color
90
+			( incr ) SWP2 8+ SWP2
91
+			OVR2 OVR2 LTH2 ^$hor JNZ
92
+		POP2 POP2
93
+		( incr ) SWP2 8+ SWP2
94
+		OVR2 OVR2 LTH2 ^$ver JNZ
95
+	POP2 POP2
87 96
 
88 97
 RTN
89 98
 
99
+@checker_icn [ f0f0 f0f0 0f0f 0f0f ]
100
+
90 101
 @dvd_icn [
91 102
 	001f 3f38 3838 787f
92 103
 	00fe fe7e 7777 e3c3
... ...
@@ -98,9 +109,6 @@ RTN
98 109
 	f000 00e0 fcfc 8000
99 110
 ]
100 111
 
101
-@clear_icn   [ 0000 0000 0000 0000 ]
102
-@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
103
-
104 112
 @pict_small [
105 113
 	ff80 8080 8080 8088 ffff fffc f8f9 f1f4
106 114
 	ffff 0010 c721 2120 ffff 3f0f 0717 c343
... ...
@@ -6,10 +6,15 @@
6 6
 %8+  { #0008 ADD2 }
7 7
 %ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 }
8 8
 
9
-;pict { x 2 y 2 width 2 height 2 color 1 addr 2 }
9
+%SIZE-TO-RECT {
10
+	STH2 STH2 OVR2 STH2r ADD2 OVR2 STH2r ADD2 
11
+} ( x y w h -- x1 y1 x2 y2 )
12
+
13
+( draw requirements )
14
+;color { byte 1 }
15
+
10 16
 ;rect { x1 2 y1 2 x2 2 y2 2 }
11 17
 ;line { x0 2 y0 2 x 2 y 2 sx 2 sy 2 dx 2 dy 2 e1 2 e2 2 }
12
-;color { byte 1 }
13 18
 ;circle { xc 2 yc 2 x 2 y 2 r 2 d 2 }
14 19
 
15 20
 |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 }
... ...
@@ -20,43 +25,20 @@
20 25
 
21 26
 |0200
22 27
 	
23
-	( theme ) #13fd =System.r #1ef3 =System.g #1bf2 =System.b
24
-	
25
-	#0010 #0020 #0040 #0060 #01 ,fill-rect-fast JSR2
26
-	#0020 #0030 #0050 #0070 #02 ,fill-rect-fast JSR2
27
-	#0030 #0040 #0060 #0080 #03 ,fill-rect-fast JSR2
28
-	#0070 #0020 #00a0 #0060 #01 ,line-rect-slow JSR2
29
-	#0080 #0030 #00b0 #0070 #02 ,line-rect-slow JSR2
30
-	#0090 #0040 #00c0 #0080 #03 ,line-rect-slow JSR2
31
-
32
-	#0000 #0080 #0020 #0020 #21 ,pict_small ,draw-picture JSR2
33
-	#0010 #0088 #0020 #0020 #22 ,pict_small ,draw-picture JSR2
34
-	#0020 #0090 #0020 #0020 #23 ,pict_small ,draw-picture JSR2
35
-	#0030 #0098 #0020 #0020 #24 ,pict_small ,draw-picture JSR2
36
-
37
-	#0020 #0020 #0070 #0080 #01 ,draw-line JSR2
38
-	#0020 #0080 #0070 #0030 #02 ,draw-line JSR2
39
-	#00a0 #0020 #0050 #00b0 #03 ,draw-line JSR2
40
-	#00b0 #0090 #0030 #0010 #01 ,draw-line JSR2
41
-
42
-	#0040 #0040 #0030 #01 ,draw-circle JSR2
43
-	#0070 #0030 #0040 #02 ,draw-circle JSR2
44
-	#0050 #0080 #0050 #03 ,draw-circle JSR2
45
-
46
-	( benchmark )
47
-	#0000 #0000 #0008 #000f #01 ,fill-rect-fast JSR2
48
-	#0008 #0000 #0010 #000f #02 ,fill-rect-medium JSR2
49
-	#0010 #0000 #0018 #000f #03 ,fill-rect-slow JSR2
50
-
51
-	( #0000 #0010 #0008 #001f #01 ,line-rect-fast JSR2 )
52
-	#0008 #0010 #000f #001f #02 ,line-rect-medium JSR2
53
-	#0010 #0010 #0017 #001f #03 ,line-rect-slow JSR2
28
+	( theme ) #f03f =System.r #f03f =System.g #003f =System.b
29
+
30
+	( background ) ,checker_icn #23 ,cover-pattern JSR2
31
+
32
+	#0010 #0030 #0020 #0020 SIZE-TO-RECT #01 ,line-slow JSR2
33
+	#0070 #0040 #0010 #01 ,draw-circle JSR2
34
+	#0038 #0030 #0020 #0020 SIZE-TO-RECT #01 ,line-rect JSR2
35
+	#0038 #0058 #0020 #0020 SIZE-TO-RECT #01 ,fill-rect JSR2
54 36
 	
55 37
 BRK
56 38
 
57
-@draw-line ( x1 y1 x2 y2 color )
39
+@line-slow ( x1 y1 x2 y2 color -- )
58 40
 	
59
-	( load ) =color =line.y0 =line.x0 =line.y =line.x
41
+	( load ) =color -- =line.y0 -- =line.x0 =line.y =line.x
60 42
 	~line.x0 ~line.x SUB2 ABS2 =line.dx
61 43
 	~line.y0 ~line.y SUB2 ABS2 #0000 SWP2 SUB2 =line.dy
62 44
 	#ffff #00 ~line.x ~line.x0 LTS2 #0002 MUL2 ADD2 =line.sx 
... ...
@@ -80,43 +62,29 @@ BRK
80 62
 
81 63
 RTN
82 64
 
83
-@line-rect-medium ( x1 y1 x2 y2 color -- )
65
+@line-rect ( x1 y1 x2 y2 color -- )
84 66
 
85
-	( load ) =color DUP2 ++ STH2 =rect.y2 =rect.x2 DUP2 STH2 =rect.y1 =rect.x1
67
+	( load ) =color DUP2 STH2 -- =rect.y2 -- =rect.x2 DUP2 STH2 =rect.y1 =rect.x1
86 68
 	STH2r STH2r
87 69
 	$ver
88 70
 		( save ) OVR2 =Screen.y
89
-		( draw ) ~rect.x1 =Screen.x ~color DUP =Screen.color ~rect.x2 =Screen.x =Screen.color
71
+		( draw ) ~rect.x1 =Screen.x ~color DUP =Screen.color 
72
+		( draw ) ~rect.x2 =Screen.x =Screen.color
90 73
 		( incr ) SWP2 ++ SWP2
91 74
 		OVR2 OVR2 LTH2 ^$ver JNZ
92 75
 	POP2 POP2
93
-	~rect.x1 ++ ~rect.x2 --
76
+	~rect.x1 ~rect.x2
94 77
 	$hor
95 78
 		( save ) OVR2 =Screen.x
96
-		( draw ) ~rect.y1 =Screen.y ~color DUP =Screen.color ~rect.y2 =Screen.y =Screen.color
79
+		( draw ) ~rect.y1 =Screen.y ~color DUP =Screen.color 
80
+		( draw ) ~rect.y2 =Screen.y =Screen.color
97 81
 		( incr ) SWP2 ++ SWP2
98 82
 		OVR2 OVR2 ++ LTH2 ^$hor JNZ
99 83
 	POP2 POP2
100
-RTN
101
-
102
-@line-rect-slow ( x1 y1 x2 y2 color -- )
103
-
104
-	( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
105
-	$hor
106
-		( incr ) ~Screen.x ++ =Screen.x
107
-		( draw ) ~rect.y1 =Screen.y ~color =Screen.color
108
-		( draw ) ~rect.y2 =Screen.y ~color =Screen.color
109
-		~Screen.x ~rect.x2 LTH2 ^$hor JNZ
110
-	~rect.y1 =Screen.y
111
-	$ver
112
-		( draw ) ~rect.x1 =Screen.x ~color =Screen.color
113
-		( draw ) ~rect.x2 =Screen.x ~color =Screen.color
114
-		( incr ) ~Screen.y ++ =Screen.y
115
-		~Screen.y ~rect.y2 ++ LTH2 ^$ver JNZ
116 84
 
117 85
 RTN
118 86
 
119
-@fill-rect-fast ( x1 y1 x2 y2 color -- )
87
+@fill-rect ( x1 y1 x2 y2 color -- )
120 88
 	
121 89
 	=color
122 90
 	( x1 x2 y1 y2 ) ROT2 SWP2
... ...
@@ -135,67 +103,20 @@ RTN
135 103
 
136 104
 RTN
137 105
 
138
-@fill-rect-medium ( x1 y1 x2 y2 color -- )
139
-
140
-	( load ) =color SWP2 =rect.x2 ROT2 =rect.x1
141
-	$ver
142
-		( save ) OVR2 =Screen.y
143
-		~rect.x1 ~rect.x2
144
-		$hor
145
-			( save ) OVR2 =Screen.x
146
-			( draw ) ~color =Screen.color
147
-			( incr ) SWP2 ++ SWP2
148
-			OVR2 OVR2 LTH2 ^$hor JNZ
149
-		POP2 POP2
150
-		( incr ) SWP2 ++ SWP2
151
-		OVR2 OVR2 LTH2 ^$ver JNZ
152
-	POP2 POP2
153
-
154
-RTN
155
-
156
-@fill-rect-slow ( x1 y1 x2 y2 color -- )
157
-
158
-	( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
159
-	$ver
160
-		~rect.x1 =Screen.x
161
-		$hor
162
-			( draw ) ~color =Screen.color
163
-			( incr ) ~Screen.x ++ =Screen.x
164
-			~Screen.x ~rect.x2 LTH2 ^$hor JNZ
165
-		( incr ) ~Screen.y ++ =Screen.y
166
-		~Screen.y ~rect.y2 LTH2 ^$ver JNZ
167
-
168
-RTN
169
-
170
-@draw-picture ( x y width height color addr )
171
-	
172
-	( load ) DUP2 =Screen.addr =pict.addr =pict.color =pict.height =pict.width DUP2 =Screen.y =pict.y =pict.x
173
-	$ver
174
-		~pict.x =Screen.x 
175
-		$hor
176
-			( draw ) ~pict.color =Screen.color
177
-			( incr ) ~Screen.x 8+ =Screen.x
178
-			( incr ) ~Screen.addr 8+ =Screen.addr
179
-		~Screen.x ~pict.width ~pict.x ADD2 LTH2 ^$hor JNZ
180
-		( incr ) ~Screen.y 8+ =Screen.y
181
-	~Screen.y ~pict.height ~pict.y ADD2 LTH2 ^$ver JNZ
182
-
183
-RTN
184
-
185
-@draw-circle ( xc yc r color )
106
+@draw-circle ( xc yc r color -- )
186 107
 
187 108
 	( load ) =color =circle.r =circle.yc =circle.xc
188 109
 	#0000 =circle.x ~circle.r =circle.y
189
-	~circle.r #0002 MUL2 #0003 SUB2 =circle.d
110
+	~circle.r #0002 MUL2 =circle.d
190 111
 	( draw ) ,$seg JSR2
191 112
 	$loop
192 113
 		( incr ) ~circle.x ++ =circle.x
193
-		~circle.d #0000 ++ LTS2 ^$else JNZ
114
+		~circle.d #0001 LTS2 ^$else JNZ
194 115
 			( decr ) ~circle.y -- =circle.y
195
-			~circle.x ~circle.y SUB2 #0004 MUL2 ~circle.d ADD2 #000a ADD2 =circle.d
116
+			~circle.x ~circle.y SUB2 #0004 MUL2 ~circle.d ADD2 =circle.d
196 117
 			,$end JMP2
197 118
 		$else
198
-			~circle.x #0004 MUL2 ~circle.d ADD2 #0006 ADD2 =circle.d
119
+			~circle.x #0004 MUL2 ~circle.d ADD2 =circle.d
199 120
 		$end
200 121
 		( draw ) ,$seg JSR2
201 122
 		~circle.y ~circle.x -- GTS2 ^$loop JNZ
... ...
@@ -212,14 +133,23 @@ RTN
212 133
 
213 134
 RTN
214 135
 
215
-@pict_small [
216
-
217
-	ff80 8080 8080 8088 ffff fffc f8f9 f1f4
218
-	ffff 0010 c721 2120 ffff 3f0f 0717 c343
219
-	8888 8080 8080 8080 f0f1 f2f5 f2f1 f0f4
220
-	1208 804c 9212 4c00 7303 0343 1b1b fbfb
221
-	8080 8f83 8383 8393 f0f3 f1f0 e4c0 80ff
222
-	00c7 c7c6 4606 00ff c3d3 c307 870f 3fff
223
-	8f83 8383 8383 83ff fff7 fdff c0e2 f1ff
224
-	7fef bfff 07af 5fff ffff ffff ffff ffff
225
-]
136
+@cover-pattern ( addr color -- )
137
+	
138
+	( load ) =color =Screen.addr
139
+	#0000 ~Screen.height
140
+	$ver
141
+		( save ) OVR2 =Screen.y
142
+		#0000 ~Screen.width
143
+		$hor
144
+			( save ) OVR2 =Screen.x
145
+			( draw ) ~color =Screen.color
146
+			( incr ) SWP2 8+ SWP2
147
+			OVR2 OVR2 LTH2 ^$hor JNZ
148
+		POP2 POP2
149
+		( incr ) SWP2 8+ SWP2
150
+		OVR2 OVR2 LTH2 ^$ver JNZ
151
+	POP2 POP2
152
+
153
+RTN
154
+
155
+@checker_icn [ f0f0 f0f0 0f0f 0f0f ]
226 156
new file mode 100644
227 157
Binary files /dev/null and b/projects/pictures/ergo100x0c0.chr differ
228 158
new file mode 100644
229 159
Binary files /dev/null and b/projects/pictures/felix0c0c.chr differ