Browse code

(life.tal) Migrated to immediate opcodes

Devine Lu Linvega authored on 06/03/2023 04:58:55
Showing 1 changed files
... ...
@@ -24,18 +24,19 @@
24 24
 	#02ff .System/g DEO2
25 25
 	#024f .System/b DEO2
26 26
 	( resize )
27
-	#00c0 .Screen/width DEO2
28
-	#00c0 .Screen/height DEO2
27
+	#00c0
28
+		DUP2 .Screen/width DEO2
29
+		.Screen/height DEO2
29 30
 	( vectors )
30 31
 	;on-frame .Screen/vector DEO2
31 32
 	;on-mouse .Mouse/vector DEO2
32 33
 	;on-control .Controller/vector DEO2
33 34
 	( glider )
34
-	#0703 ;set-cell JSR2
35
-	#0704 ;set-cell JSR2
36
-	#0504 ;set-cell JSR2
37
-	#0705 ;set-cell JSR2
38
-	#0605 ;set-cell JSR2
35
+	#0703 set-cell
36
+	#0704 set-cell
37
+	#0504 set-cell
38
+	#0705 set-cell
39
+	#0605 set-cell
39 40
 	( center )
40 41
 	.Screen/width DEI2 #01 SFT2 #0040 SUB2
41 42
 		DUP2 .anchor/x STZ2
... ...
@@ -47,19 +48,19 @@
47 48
 BRK
48 49
 
49 50
 @on-frame ( -> )
50
-	
51
+
51 52
 	.Mouse/state DEI #00 EQU #01 JCN [ BRK ]
52 53
 	#0000 .world/count STZ2
53 54
 	.world/frame LDZ INC
54 55
 		DUP .world/frame STZ
55 56
 		#03 AND #00 EQU #01 JCN [ BRK ]
56
-	;run JSR2
57
+	run
57 58
 	&paused
58 59
 
59 60
 BRK
60 61
 
61 62
 @on-mouse ( -> )
62
-	
63
+
63 64
 	( clear last cursor )
64 65
 	;cursor .Screen/addr DEO2
65 66
 	.pointer/x LDZ2 .Screen/x DEO2
... ...
@@ -72,29 +73,29 @@ BRK
72 73
 	#42 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/sprite DEO
73 74
 	( on touch in rect )
74 75
 	.Mouse/state DEI #00 NEQ #01 JCN [ BRK ]
75
-	.Mouse/x DEI2 .Mouse/y DEI2 .anchor ;within-rect JSR2 JMP [ BRK ]
76
+	.Mouse/x DEI2 .Mouse/y DEI2 .anchor within-rect [ JMP BRK ]
76 77
 	( paint )
77 78
 	.Mouse/x DEI2 .anchor/x LDZ2 SUB2 #01 SFT NIP
78 79
 	.Mouse/y DEI2 .anchor/y LDZ2 SUB2 #01 SFT NIP
79
-		;set-cell JSR2
80
+		set-cell
80 81
 	( draw )
81
-	;draw-grid JSR2
82
+	draw-grid
82 83
 
83 84
 BRK
84 85
 
85 86
 @on-control ( -> )
86 87
 
87 88
 	( toggle play )
88
-	.Controller/key DEI #20 NEQ ,&no-toggle JCN
89
+	.Controller/key DEI #20 NEQ ?&no-toggle
89 90
 		;on-frame
90
-		.Screen/vector DEI2 ;on-frame/paused EQU2 ,&swap JCN
91
+		.Screen/vector DEI2 ;on-frame/paused EQU2 ?&swap
91 92
 			POP2 ;on-frame/paused
92 93
 			&swap
93 94
 		.Screen/vector DEO2
94 95
 		&no-toggle
95 96
 	( clear on home )
96
-	.Controller/button DEI #08 NEQ ,&no-reset JCN
97
-		;bank1 #0400 ;mclr JSR2
97
+	.Controller/button DEI #08 NEQ ?&no-reset
98
+		;bank1 #0400 mclr
98 99
 		&no-reset
99 100
 
100 101
 BRK
... ...
@@ -102,88 +103,87 @@ BRK
102 103
 @run ( -- )
103 104
 
104 105
 	( clear buffer )
105
-	;bank2 #1000 ;mclr JSR2
106
+	;bank2 #1000 mclr
106 107
 	( run grid )
107 108
 	#4000
108 109
 	&ver
109 110
 		STHk
110 111
 		#4000
111 112
 		&hor
112
-			DUP STHkr ,run-cell JSR
113
-			INC GTHk ,&hor JCN
113
+			DUP STHkr run-cell
114
+			INC GTHk ?&hor
114 115
 		POP2
115 116
 		POPr
116
-		INC GTHk ,&ver JCN
117
+		INC GTHk ?&ver
117 118
 	POP2
118 119
 	( move buffer )
119
-	;bank2 ;bank1 #1000 ;mcpy JSR2
120
+	;bank2 ;bank1 #1000 mcpy
120 121
 	( draw )
121
-	;draw-grid ( .. )
122
-
123
-JMP2
122
+!draw-grid
124 123
 
125 124
 @run-cell ( x y -- )
126 125
 
127 126
 	( x y ) DUP2k
128
-	( neighbours ) ;get-neighbours JSR2
129
-	( state ) ROT ROT ;get-cell JSR2
130
-	#00 EQU ,&dead JCN
131
-		DUP #02 LTH ,&dies JCN
132
-		DUP #03 GTH ,&dies JCN
133
-		POP ;&save JMP2
127
+	( neighbours ) get-neighbours
128
+	( state ) ROT ROT get-cell
129
+	#00 EQU ?&dead
130
+		DUP #02 LTH ?&dies
131
+		DUP #03 GTH ?&dies
132
+		POP !&save
134 133
 		&dies POP POP2 JMP2r
135 134
 	&dead
136
-		DUP #03 EQU ,&birth JCN POP POP2 JMP2r
137
-		&birth POP ;&save ( .. )
135
+		DUP #03 EQU ?&birth POP POP2 JMP2r
136
+		&birth POP 
137
+
138
+!&save
138 139
 
139
-JMP2
140
-	&save ( x y -- ) 
141
-		STH2 #01 STH2r ,get-index JSR [ #1000 ADD2 ] STA
140
+	&save ( x y -- )
141
+		STH2 #01 STH2r get-index #1000 ADD2 STA
142 142
 		.world/count LDZ2 INC2 .world/count STZ2
143 143
 	JMP2r
144 144
 
145 145
 @get-index ( x y -- index* )
146
-	
147
-	( y ) #3f AND #00 SWP #60 SFT2 
146
+
147
+	( y ) #3f AND #00 SWP #60 SFT2
148 148
 	( x ) ROT #3f AND #00 SWP ADD2
149 149
 		;bank1 ADD2
150 150
 
151 151
 JMP2r
152 152
 
153 153
 @set-cell ( x y -- )
154
-	
155
-	STH2 #01 STH2r ,get-index JSR STA
154
+
155
+	STH2 #01 STH2r get-index STA
156 156
 
157 157
 JMP2r
158 158
 
159 159
 @get-cell ( x y -- cell )
160
-	
161
-	,get-index JSR LDA
160
+
161
+	get-index LDA
162 162
 
163 163
 JMP2r
164 164
 
165 165
 @get-neighbours ( x y -- neighbours )
166
-	
166
+
167 167
 	,&origin STR2
168 168
 	LITr 00
169 169
 	#0800
170 170
 	&loop
171 171
 		#00 OVRk ADD2 ;&mask ADD2 LDA2 [ LIT2 &origin $2 ]
172
-		ROT ADD STH ADD STHr ;get-cell JSR2 STH ADDr
173
-		INC GTHk ,&loop JCN
172
+		ROT ADD STH ADD STHr get-cell STH ADDr
173
+		INC GTHk ?&loop
174 174
 	POP2
175 175
 	STHr
176 176
 
177 177
 JMP2r
178
-	&mask ffff 00ff 01ff ff00 0100 ff01 0001 0101
178
+	&mask [ ffff 00ff 01ff ff00 0100 ff01 0001 0101 ]
179 179
 
180 180
 @draw-grid ( -- )
181
-	
181
+
182 182
 	( draw cell count )
183 183
 	.anchor/x LDZ2 .Screen/x DEO2
184 184
 	.anchor/y2 LDZ2 #0008 ADD2 .Screen/y DEO2
185 185
 	#01 .Screen/auto DEO
186
-	.world/count LDZ2 ;draw-short JSR2
186
+	.world/count LDZ2 draw-short
187 187
 	#00 .Screen/auto DEO
188 188
 	#4000
189 189
 	&ver
... ...
@@ -192,53 +192,50 @@ JMP2r
192 192
 		#4000
193 193
 		&hor
194 194
 			#00 OVRk ADD2 .anchor/x LDZ2 ADD2 .Screen/x DEO2
195
-			DUP STHkr ;get-cell JSR2 INC .Screen/pixel DEO
196
-			INC GTHk ,&hor JCN
195
+			DUP STHkr get-cell INC .Screen/pixel DEO
196
+			INC GTHk ?&hor
197 197
 		POP2
198 198
 		POPr
199
-		INC GTHk ,&ver JCN
199
+		INC GTHk ?&ver
200 200
 	POP2
201 201
 
202 202
 JMP2r
203 203
 
204 204
 @draw-short ( short* -- )
205 205
 
206
-	SWP ,draw-byte JSR
206
+	SWP draw-byte
207 207
 
208 208
 @draw-byte ( byte color -- )
209 209
 
210
-	DUP #04 SFT ,draw-hex JSR #0f AND
210
+	DUP #04 SFT draw-hex #0f AND
211 211
 
212 212
 @draw-hex ( char color -- )
213 213
 
214 214
 	#00 SWP #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
215
-	#03 .Screen/sprite DEO
215
+	[ LIT2 03 -Screen/sprite ] DEO
216 216
 
217 217
 JMP2r
218 218
 
219 219
 @within-rect ( x* y* rect -- flag )
220
-	
220
+
221 221
 	STH
222
-	( y < rect.y1 ) DUP2 STHkr INC INC LDZ2 LTH2 ,&skip JCN
223
-	( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ,&skip JCN
222
+	( y < rect.y1 ) DUP2 STHkr INC INC LDZ2 LTH2 ?&skip
223
+	( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ?&skip
224 224
 	SWP2
225
-	( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN
226
-	( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN
225
+	( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ?&skip
226
+	( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ?&skip
227 227
 	POP2 POP2 POPr
228 228
 	#01
229 229
 JMP2r
230 230
 	&skip
231
-	POP2 POP2 POPr
232
-	#00
233
-
234
-JMP2r
231
+	POP2 POP2 POPr #00 JMP2r
235 232
 
236 233
 @mclr ( addr* len* -- )
237 234
 
238 235
 	OVR2 ADD2 SWP2
239 236
 	&loop
240 237
 		STH2k #00 STH2r STA
241
-		INC2 GTH2k ,&loop JCN
238
+		INC2 GTH2k ?&loop
242 239
 	POP2 POP2
243 240
 
244 241
 JMP2r
... ...
@@ -249,16 +246,16 @@ JMP2r
249 246
 	OVR2 ADD2 SWP2
250 247
 	&loop
251 248
 		LDAk STH2kr STA INC2r
252
-		INC2 GTH2k ,&loop JCN
249
+		INC2 GTH2k ?&loop
253 250
 	POP2 POP2
254 251
 	POP2r
255 252
 
256 253
 JMP2r
257 254
 
258
-@cursor
259
-	80c0 e0f0 f8e0 1000
255
+@cursor [
256
+	80c0 e0f0 f8e0 1000 ]
260 257
 
261
-@font-hex
258
+@font-hex [
262 259
 	7c82 8282 8282 7c00
263 260
 	3010 1010 1010 3800
264 261
 	7c82 027c 8080 fe00
... ...
@@ -274,6 +271,6 @@ JMP2r
274 271
 	7c82 8080 8082 7c00
275 272
 	fc82 8282 8282 fc00
276 273
 	fe80 80f0 8080 fe00
277
-	fe80 80f0 8080 8000
274
+	fe80 80f0 8080 8000 ]
278 275
 
279 276
 @bank1 $1000 @bank2