Browse code

Optimized line-rect routine

neauoire authored on 21/02/2022 18:30:55
Showing 5 changed files
... ...
@@ -551,23 +551,28 @@ RTN
551 551
 
552 552
 @line-rect ( x1* y1* x2* y2* color -- )
553 553
 
554
-	( load ) .color STZ STH2k .rect/y2 STZ2 .rect/x2 STZ2 STH2k .rect/y1 STZ2 .rect/x1 STZ2
555
-	STH2r INC2 STH2r
556
-	&ver
557
-		( save ) OVR2 .Screen/y DEO2
558
-		( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO
559
-		( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO
560
-		( incr ) SWP2 INC2 SWP2
561
-		OVR2 OVR2 LTS2 ,&ver JCN
562
-	POP2 POP2
563
-	.rect/x1 LDZ2 INC2 .rect/x2 LDZ2 #0001 --
554
+	STH
555
+	DUP2 ,&ver-y2 STR2 ,&hor-y2 STR2
556
+	DUP2 ,&ver-x2 STR2 ,&hor-x2 STR2
557
+	DUP2 ,&ver-y1 STR2 ,&hor-y1 STR2
558
+	DUP2 ,&ver-x1 STR2 ,&hor-x1 STR2
559
+	( horizontal )
560
+	[ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
564 561
 	&hor
565
-		( save ) OVR2 .Screen/x DEO2
566
-		( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO
567
-		( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO
568
-		( incr ) SWP2 INC2 SWP2
569
-		OVR2 OVR2 INC2 LTS2 ,&hor JCN
562
+		DUP2 .Screen/x DEO2
563
+		[ LIT2 &hor-y1 $2 ] .Screen/y DEO2 STHkr .Screen/pixel DEOk
564
+		[ LIT2 &hor-y2 $2 ] .Screen/y DEO2 DEO
565
+		INC2 GTH2k ,&hor JCN
570 566
 	POP2 POP2
567
+	( vertical )
568
+	[ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
569
+	&ver
570
+		DUP2 .Screen/y DEO2
571
+		[ LIT2 &ver-x1 $2 ] .Screen/x DEO2 STHkr .Screen/pixel DEOk
572
+		[ LIT2 &ver-x2 $2 ] .Screen/x DEO2 DEO
573
+		INC2 GTH2k ,&ver JCN
574
+	POP2 POP2
575
+	POPr
571 576
 
572 577
 RTN
573 578
 
... ...
@@ -305,18 +305,28 @@ RTN
305 305
 
306 306
 @line-rect ( x1* y1* x2* y2* color -- )
307 307
 
308
-	( load ) .color STZ .rect/y2 STZ2 .rect/x2 STZ2 DUP2 .Screen/y DEO2 .rect/y1 STZ2 DUP2 .Screen/x DEO2 .rect/x1 STZ2
308
+	STH
309
+	DUP2 ,&ver-y2 STR2 ,&hor-y2 STR2
310
+	DUP2 ,&ver-x2 STR2 ,&hor-x2 STR2
311
+	DUP2 ,&ver-y1 STR2 ,&hor-y1 STR2
312
+	DUP2 ,&ver-x1 STR2 ,&hor-x1 STR2
313
+	( horizontal )
314
+	[ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
309 315
 	&hor
310
-		( incr ) .Screen/x DEI2 ++ .Screen/x DEO2
311
-		( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ .Screen/pixel DEO
312
-		( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .color LDZ .Screen/pixel DEO
313
-		.Screen/x DEI2 .rect/x2 LDZ2 LTH2 ,&hor JCN
314
-	.rect/y1 LDZ2 .Screen/y DEO2
316
+		DUP2 .Screen/x DEO2
317
+		[ LIT2 &hor-y1 $2 ] .Screen/y DEO2 STHkr .Screen/pixel DEOk
318
+		[ LIT2 &hor-y2 $2 ] .Screen/y DEO2 DEO
319
+		INC2 GTH2k ,&hor JCN
320
+	POP2 POP2
321
+	( vertical )
322
+	[ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
315 323
 	&ver
316
-		( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ .Screen/pixel DEO
317
-		( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .color LDZ .Screen/pixel DEO
318
-		( incr ) .Screen/y DEI2 ++ .Screen/y DEO2
319
-		.Screen/y DEI2 .rect/y2 LDZ2 ++ LTH2 ,&ver JCN
324
+		DUP2 .Screen/y DEO2
325
+		[ LIT2 &ver-x1 $2 ] .Screen/x DEO2 STHkr .Screen/pixel DEOk
326
+		[ LIT2 &ver-x2 $2 ] .Screen/x DEO2 DEO
327
+		INC2 GTH2k ,&ver JCN
328
+	POP2 POP2
329
+	POPr
320 330
 
321 331
 RTN
322 332
 
... ...
@@ -28,10 +28,6 @@
28 28
 	&w $2 &h $2
29 29
 	&x0 $2 &y0 $2
30 30
 	&x1 $2 &y1 $2
31
-@color $1
32
-@rect
33
-	&x1 $2 &y1 $2 
34
-	&x2 $2 &y2 $2
35 31
 
36 32
 ( init )
37 33
 
... ...
@@ -57,6 +53,11 @@
57 53
 	( vectors ) 
58 54
 	;on-button .Controller/vector DEO2
59 55
 
56
+	( frame )
57
+	.frame/x0 LDZ2 .frame/y0 LDZ2
58
+	.frame/x1 LDZ2 .frame/y1 LDZ2
59
+		#03 ;line-rect JSR2
60
+
60 61
 	,draw-controller JSR
61 62
 
62 63
 BRK
... ...
@@ -74,10 +75,6 @@ BRK
74 75
 
75 76
 	.Controller/button DEI STH
76 77
 
77
-	( frame )
78
-	.frame/x0 LDZ2 .frame/y0 LDZ2
79
-	.frame/x1 LDZ2 .frame/y1 LDZ2
80
-		#01 ;line-rect JSR2
81 78
 	( d-pad )
82 79
 	.frame/x0 LDZ2 #0010 ++ .Screen/x DEO2
83 80
 	.frame/y0 LDZ2 #0010 ++ .Screen/y DEO2
... ...
@@ -135,7 +132,7 @@ RTN
135 132
 
136 133
 @draw-short ( short* color -- )
137 134
 
138
-	STH  SWP STHkr ,draw-byte JSR STHr 
135
+	STH SWP STHkr ,draw-byte JSR STHr 
139 136
 
140 137
 @draw-byte ( byte color -- )
141 138
 
... ...
@@ -150,23 +147,28 @@ RTN
150 147
 
151 148
 @line-rect ( x1* y1* x2* y2* color -- )
152 149
 
153
-	( load ) .color STZ DUP2 STH2 .rect/y2 STZ2 .rect/x2 STZ2 DUP2 STH2 .rect/y1 STZ2 .rect/x1 STZ2
154
-	STH2r INC2 STH2r
155
-	&ver
156
-		( save ) OVR2 .Screen/y DEO2
157
-		( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO
158
-		( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO
159
-		( incr ) SWP2 INC2 SWP2
160
-		OVR2 OVR2 LTS2 ,&ver JCN
161
-	POP2 POP2
162
-	.rect/x1 LDZ2 INC2 .rect/x2 LDZ2 #0001 --
150
+	STH
151
+	DUP2 ,&ver-y2 STR2 ,&hor-y2 STR2
152
+	DUP2 ,&ver-x2 STR2 ,&hor-x2 STR2
153
+	DUP2 ,&ver-y1 STR2 ,&hor-y1 STR2
154
+	DUP2 ,&ver-x1 STR2 ,&hor-x1 STR2
155
+	( horizontal )
156
+	[ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
163 157
 	&hor
164
-		( save ) OVR2 .Screen/x DEO2
165
-		( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO
166
-		( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO
167
-		( incr ) SWP2 INC2 SWP2
168
-		OVR2 OVR2 INC2 LTS2 ,&hor JCN
158
+		DUP2 .Screen/x DEO2
159
+		[ LIT2 &hor-y1 $2 ] .Screen/y DEO2 STHkr .Screen/pixel DEOk
160
+		[ LIT2 &hor-y2 $2 ] .Screen/y DEO2 DEO
161
+		INC2 GTH2k ,&hor JCN
162
+	POP2 POP2
163
+	( vertical )
164
+	[ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
165
+	&ver
166
+		DUP2 .Screen/y DEO2
167
+		[ LIT2 &ver-x1 $2 ] .Screen/x DEO2 STHkr .Screen/pixel DEOk
168
+		[ LIT2 &ver-x2 $2 ] .Screen/x DEO2 DEO
169
+		INC2 GTH2k ,&ver JCN
169 170
 	POP2 POP2
171
+	POPr
170 172
 
171 173
 RTN
172 174
 
... ...
@@ -96,25 +96,28 @@ RTN
96 96
 
97 97
 @line-rect ( x1* y1* x2* y2* color -- )
98 98
 
99
-	( load ) .color STZ 
100
-	STH2k .rect/y2 STZ2 .rect/x2 STZ2 
101
-	STH2k .rect/y1 STZ2 .rect/x1 STZ2
102
-	STH2r STH2r SWP2
103
-	&ver
104
-		( save ) DUP2 .Screen/y DEO2
105
-		( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO
106
-		( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO
107
-		( incr ) INC2
108
-		OVR2 OVR2 GTS2 ,&ver JCN
109
-	POP2 POP2
110
-	.rect/x1 LDZ2 .rect/x2 LDZ2 SWP2
99
+	STH
100
+	DUP2 ,&ver-y2 STR2 ,&hor-y2 STR2
101
+	DUP2 ,&ver-x2 STR2 ,&hor-x2 STR2
102
+	DUP2 ,&ver-y1 STR2 ,&hor-y1 STR2
103
+	DUP2 ,&ver-x1 STR2 ,&hor-x1 STR2
104
+	( horizontal )
105
+	[ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
111 106
 	&hor
112
-		( save ) DUP2 .Screen/x DEO2
113
-		( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO
114
-		( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO
115
-		( incr ) INC2
116
-		OVR2 OVR2 GTS2 ,&hor JCN
107
+		DUP2 .Screen/x DEO2
108
+		[ LIT2 &hor-y1 $2 ] .Screen/y DEO2 STHkr .Screen/pixel DEOk
109
+		[ LIT2 &hor-y2 $2 ] .Screen/y DEO2 DEO
110
+		INC2 GTH2k ,&hor JCN
111
+	POP2 POP2
112
+	( vertical )
113
+	[ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
114
+	&ver
115
+		DUP2 .Screen/y DEO2
116
+		[ LIT2 &ver-x1 $2 ] .Screen/x DEO2 STHkr .Screen/pixel DEOk
117
+		[ LIT2 &ver-x2 $2 ] .Screen/x DEO2 DEO
118
+		INC2 GTH2k ,&ver JCN
117 119
 	POP2 POP2
120
+	POPr
118 121
 
119 122
 RTN
120 123
 
... ...
@@ -93,28 +93,30 @@ RTN
93 93
 
94 94
 @line-rect ( x1* y1* x2* y2* color -- )
95 95
 
96
-	( load ) STH
97
-	STH2k ,&y2 STR2 ,&x2 STR2 
98
-	STH2k ,&y1 STR2 ,&x1 STR2
99
-	STH2r STH2r SWP2
96
+	STH
97
+	DUP2 ,&ver-y2 STR2 ,&hor-y2 STR2
98
+	DUP2 ,&ver-x2 STR2 ,&hor-x2 STR2
99
+	DUP2 ,&ver-y1 STR2 ,&hor-y1 STR2
100
+	DUP2 ,&ver-x1 STR2 ,&hor-x1 STR2
101
+	( horizontal )
102
+	[ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
103
+	&hor
104
+		DUP2 .Screen/x DEO2
105
+		[ LIT2 &hor-y1 $2 ] .Screen/y DEO2 STHkr .Screen/pixel DEOk
106
+		[ LIT2 &hor-y2 $2 ] .Screen/y DEO2 DEO
107
+		INC2 GTH2k ,&hor JCN
108
+	POP2 POP2
109
+	( vertical )
110
+	[ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
100 111
 	&ver
101
-		( save ) DUP2 .Screen/y DEO2
102
-		( draw ) ,&x1 LDR2 .Screen/x DEO2 STHkr .Screen/pixel DEO
103
-		( draw ) ,&x2 LDR2 .Screen/x DEO2 STHkr .Screen/pixel DEO
104
-		( incr ) INC2
105
-		OVR2 OVR2 GTS2 ,&ver JCN
112
+		DUP2 .Screen/y DEO2
113
+		[ LIT2 &ver-x1 $2 ] .Screen/x DEO2 STHkr .Screen/pixel DEOk
114
+		[ LIT2 &ver-x2 $2 ] .Screen/x DEO2 DEO
115
+		INC2 GTH2k ,&ver JCN
106 116
 	POP2 POP2
107
-	,&x1 LDR2 ,&x2 LDR2 SWP2
108
-	&hor
109
-		( save ) DUP2 .Screen/x DEO2
110
-		( draw ) ,&y1 LDR2 .Screen/y DEO2 STHkr .Screen/pixel DEO
111
-		( draw ) ,&y2 LDR2 .Screen/y DEO2 STHkr .Screen/pixel DEO
112
-		( incr ) INC2
113
-		OVR2 INC2 OVR2 GTS2 ,&hor JCN
114
-	POP2 POP2 POPr
117
+	POPr
115 118
 
116 119
 RTN
117
-	&x1 $2 &y1 $2 &x2 $2 &y2 $2 
118 120
 
119 121
 @fill-rect ( x1* y1* x2* y2* color -- )
120 122