aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-08-28 15:25:31 +0200
committerBad Diode <bd@badd10de.dev>2023-08-28 15:25:31 +0200
commita8b0b69c14f2eef465fdb99ea099bbeeb6d3e2f8 (patch)
tree16e7c799075db6d5400461cdd02d649c388c9b90 /src
parentaaff9e5fbcb0ff3939750429de9b9900feb17178 (diff)
downloaduxngba-a8b0b69c14f2eef465fdb99ea099bbeeb6d3e2f8.tar.gz
uxngba-a8b0b69c14f2eef465fdb99ea099bbeeb6d3e2f8.zip
Replace recurring patterns with macros
Diffstat (limited to 'src')
-rw-r--r--src/main.c47
-rw-r--r--src/uxn-core.s248
2 files changed, 133 insertions, 162 deletions
diff --git a/src/main.c b/src/main.c
index 47a5eef..31d97b3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,8 +48,7 @@ init_uxn() {
48 48
49 // Copy rom to VM. 49 // Copy rom to VM.
50 u8 uxn_rom[] = { 50 u8 uxn_rom[] = {
51 // 51 // // ADD test.
52 // ADD test.
53 // 0x80, 0x04, 0x80, 0x08, 0x18, // #04 #08 ADD -> 0c 52 // 0x80, 0x04, 0x80, 0x08, 0x18, // #04 #08 ADD -> 0c
54 // 0xa0, 0x00, 0x04, 0xa0, 0x00, 0x08, 0x38, // #0004 #0008 ADD2 -> 000c 53 // 0xa0, 0x00, 0x04, 0xa0, 0x00, 0x08, 0x38, // #0004 #0008 ADD2 -> 000c
55 // 0xa0, 0x00, 0xff, 0xa0, 0x00, 0x02, 0x38, // #00ff #0002 ADD2 -> 0101 54 // 0xa0, 0x00, 0xff, 0xa0, 0x00, 0x02, 0x38, // #00ff #0002 ADD2 -> 0101
@@ -85,26 +84,30 @@ init_uxn() {
85 // // OVR. 84 // // OVR.
86 // 0xa0, 0x12, 0x34, 0x07, // -> ( 12 34 12 ) 85 // 0xa0, 0x12, 0x34, 0x07, // -> ( 12 34 12 )
87 // 0xa0, 0x12, 0x34, 0xa0, 0x56, 0x78, 0x27, // -> ( 12 34 56 78 12 34 ) 86 // 0xa0, 0x12, 0x34, 0xa0, 0x56, 0x78, 0x27, // -> ( 12 34 56 78 12 34 )
88 // EQU. 87 // // EQU.
89 0xa0, 0x12, 0x12, 0x08, // -> ( 01 ) 88 // 0xa0, 0x12, 0x12, 0x08, // -> ( 01 )
90 0xa0, 0x12, 0x34, 0x08, // -> ( 00 ) 89 // 0xa0, 0x12, 0x34, 0x08, // -> ( 00 )
91 0xa0, 0x12, 0x34, 0xa0, 0x12, 0x34, 0x28, // -> ( 01 ) 90 // 0xa0, 0x12, 0x34, 0xa0, 0x12, 0x34, 0x28, // -> ( 01 )
92 0xa0, 0x12, 0x34, 0xa0, 0x56, 0x78, 0x28, // -> ( 00 ) 91 // 0xa0, 0x12, 0x34, 0xa0, 0x56, 0x78, 0x28, // -> ( 00 )
93 // NEQ. 92 // // NEQ.
94 0xa0, 0x12, 0x12, 0x09, // -> ( 00 ) 93 // 0xa0, 0x12, 0x12, 0x09, // -> ( 00 )
95 0xa0, 0x12, 0x34, 0x09, // -> ( 01 ) 94 // 0xa0, 0x12, 0x34, 0x09, // -> ( 01 )
96 0xa0, 0x12, 0x34, 0xa0, 0x12, 0x34, 0x29, // -> ( 00 ) 95 // 0xa0, 0x12, 0x34, 0xa0, 0x12, 0x34, 0x29, // -> ( 00 )
97 0xa0, 0x12, 0x34, 0xa0, 0x56, 0x78, 0x29, // -> ( 01 ) 96 // 0xa0, 0x12, 0x34, 0xa0, 0x56, 0x78, 0x29, // -> ( 01 )
98 // GTH. 97 // // GTH.
99 0xa0, 0x12, 0x34, 0x0a, // -> ( 00 ) 98 // 0xa0, 0x12, 0x34, 0x0a, // -> ( 00 )
100 0xa0, 0x34, 0x12, 0x0a, // -> ( 01 ) 99 // 0xa0, 0x34, 0x12, 0x0a, // -> ( 01 )
101 0xa0, 0x12, 0x34, 0xa0, 0x34, 0x56, 0x2a, // -> ( 00 ) 100 // 0xa0, 0x12, 0x34, 0xa0, 0x34, 0x56, 0x2a, // -> ( 00 )
102 0xa0, 0x34, 0x56, 0xa0, 0x12, 0x34, 0x2a, // -> ( 01 ) 101 // 0xa0, 0x34, 0x56, 0xa0, 0x12, 0x34, 0x2a, // -> ( 01 )
103 // LTH. 102 // // LTH.
104 0xa0, 0x12, 0x34, 0x0b, // -> ( 01 ) 103 // 0xa0, 0x12, 0x34, 0x0b, // -> ( 01 )
105 0xa0, 0x34, 0x12, 0x0b, // -> ( 00 ) 104 // 0xa0, 0x34, 0x12, 0x0b, // -> ( 00 )
106 0xa0, 0x12, 0x34, 0xa0, 0x34, 0x56, 0x2b, // -> ( 01 ) 105 // 0xa0, 0x12, 0x34, 0xa0, 0x34, 0x56, 0x2b, // -> ( 01 )
107 0xa0, 0x34, 0x56, 0xa0, 0x12, 0x34, 0x2b, // -> ( 00 ) 106 // 0xa0, 0x34, 0x56, 0xa0, 0x12, 0x34, 0x2b, // -> ( 00 )
107 // AND.
108 // 0xa0, 0x0f, 0x88, 0x1c, // -> ( 08 )
109 // 0xa0, 0xf0, 0x88, 0x1c, // -> ( 80 )
110 // 0xa0, 0x0f, 0x88, 0x3c, // -> ( 01 )
108 111
109 }; 112 };
110 memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); 113 memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom));
diff --git a/src/uxn-core.s b/src/uxn-core.s
index 6a4b84d..732b6c2 100644
--- a/src/uxn-core.s
+++ b/src/uxn-core.s
@@ -51,6 +51,34 @@ uxn_ret:
51 bx lr 51 bx lr
52 52
53@ 53@
54@ Macros.
55@
56
57.macro wpop8 a
58 ldrb \a, [r1, #-1]!
59.endm
60
61.macro wpop16 a, b
62 ldrb \a, [r1, #-1]!
63 ldrb \b, [r1, #-1]!
64 orr \a, \a, \b, lsl #8
65.endm
66
67.macro wpush8 a
68 strb \a, [r1], #1
69.endm
70
71.macro wpush16 a
72 strb \a, [r1, #1]
73 lsr \a, #8
74 strb \a, [r1], #2
75.endm
76
77.macro wpeek a, b
78 ldrb \a, [r1, \b]
79.endm
80
81@
54@ OP implementations. 82@ OP implementations.
55@ 83@
56 84
@@ -79,19 +107,15 @@ lit2r:
79 b uxn_decode 107 b uxn_decode
80 108
81inc: 109inc:
82 ldrb r3, [r1, #-1]! 110 wpop8 r3
83 add r3, #1 111 add r3, #1
84 strb r3, [r1], #1 112 wpush8 r3
85 b uxn_decode 113 b uxn_decode
86 114
87inc2: 115inc2:
88 ldrb r3, [r1, #-1]! 116 wpop16 r3, r5
89 ldrb r5, [r1, #-1]!
90 orr r3, r3, r5, lsl #8
91 add r3, r3, #1 117 add r3, r3, #1
92 strb r3, [r1, #1] 118 wpush16 r3
93 lsr r3, #8
94 strb r3, [r1], #2
95 b uxn_decode 119 b uxn_decode
96 120
97pop: 121pop:
@@ -103,179 +127,141 @@ pop2:
103 b uxn_decode 127 b uxn_decode
104 128
105nip: 129nip:
106 ldrb r3, [r1, #-1]! 130 wpop8 r3
107 strb r3, [r1, #-1] 131 strb r3, [r1, #-1]
108 b uxn_decode 132 b uxn_decode
109 133
110nip2: 134nip2:
111 ldrb r3, [r1, #-1]! 135 wpop16 r3, r5
112 ldrb r5, [r1, #-1]!
113 orr r3, r3, r5, lsl #8
114 strb r3, [r1, #-1] 136 strb r3, [r1, #-1]
115 lsr r3, #8 137 lsr r3, #8
116 strb r3, [r1, #-2] 138 strb r3, [r1, #-2]
117 b uxn_decode 139 b uxn_decode
118 140
119swp: 141swp:
120 ldrb r3, [r1, #-1]! 142 wpop8 r3
121 ldrb r4, [r1, #-1]! 143 wpop8 r4
122 strb r3, [r1], #1 144 wpush8 r3
123 strb r4, [r1], #1 145 wpush8 r4
124 b uxn_decode 146 b uxn_decode
125 147
126swp2: 148swp2:
127 ldrb r3, [r1, #-1]! 149 wpop16 r3, r5
128 ldrb r5, [r1, #-1]! 150 wpop16 r4, r5
129 orr r3, r3, r5, lsl #8 151 wpush16 r3
130 ldrb r4, [r1, #-1]! 152 wpush16 r4
131 ldrb r5, [r1, #-1]!
132 orr r4, r4, r5, lsl #8
133 strb r3, [r1, #1]
134 lsr r3, #8
135 strb r3, [r1], #2
136 strb r4, [r1, #1]
137 lsr r4, #8
138 strb r4, [r1], #2
139 b uxn_decode 153 b uxn_decode
140 154
141rot: 155rot:
142 ldrb r5, [r1, #-1]! 156 wpop8 r5
143 ldrb r4, [r1, #-1]! 157 wpop8 r4
144 ldrb r3, [r1, #-1]! 158 wpop8 r3
145 strb r4, [r1], #1 159 wpush8 r4
146 strb r5, [r1], #1 160 wpush8 r5
147 strb r3, [r1], #1 161 wpush8 r3
148 b uxn_decode 162 b uxn_decode
149 163
150rot2: 164rot2:
151 ldrb r5, [r1, #-1]! 165 wpop16 r5, r6
152 ldrb r6, [r1, #-1]! 166 wpop16 r4, r6
153 orr r5, r5, r6, lsl #8 167 wpop16 r3, r6
154 ldrb r4, [r1, #-1]! 168 wpush16 r4
155 ldrb r6, [r1, #-1]! 169 wpush16 r5
156 orr r4, r4, r6, lsl #8 170 wpush16 r3
157 ldrb r3, [r1, #-1]!
158 ldrb r6, [r1, #-1]!
159 orr r3, r3, r6, lsl #8
160 strb r4, [r1, #1]
161 lsr r4, #8
162 strb r4, [r1], #2
163 strb r5, [r1, #1]
164 lsr r5, #8
165 strb r5, [r1], #2
166 strb r3, [r1, #1]
167 lsr r3, #8
168 strb r3, [r1], #2
169 b uxn_decode 171 b uxn_decode
170 172
171dup: 173dup:
172 ldrb r3, [r1, #-1] 174 wpeek r3, #-1
173 strb r3, [r1], #1 175 wpush8 r3
174 b uxn_decode 176 b uxn_decode
175 177
176dup2: 178dup2:
177 ldrb r3, [r1, #-2] 179 wpeek r3, #-2
178 ldrb r4, [r1, #-1] 180 wpeek r4, #-1
179 strb r3, [r1], #1 181 wpush8 r3
180 strb r4, [r1], #1 182 wpush8 r4
181 b uxn_decode 183 b uxn_decode
182 184
183ovr: 185ovr:
184 ldrb r3, [r1, #-2] 186 wpeek r3, #-2
185 strb r3, [r1], #1 187 wpush8 r3
186 b uxn_decode 188 b uxn_decode
187 189
188ovr2: 190ovr2:
189 ldrb r3, [r1, #-4] 191 wpeek r3, #-4
190 ldrb r4, [r1, #-3] 192 wpeek r4, #-3
191 strb r3, [r1], #1 193 wpush8 r3
192 strb r4, [r1], #1 194 wpush8 r4
193 b uxn_decode 195 b uxn_decode
194 196
195equ: 197equ:
196 ldrb r3, [r1, #-1]! 198 wpop8 r3
197 ldrb r4, [r1, #-1]! 199 wpop8 r4
198 sub r3, r4, r3 200 sub r3, r4, r3
199 rsbs r4, r3, #0 201 rsbs r4, r3, #0
200 adc r4, r4, r3 202 adc r4, r4, r3
201 strb r4, [r1], #1 203 wpush8 r4
202 b uxn_decode 204 b uxn_decode
203 205
204equ2: 206equ2:
205 ldrb r3, [r1, #-1]! 207 wpop16 r3, r5
206 ldrb r5, [r1, #-1]! 208 wpop16 r4, r5
207 orr r3, r3, r5, lsl #8
208 ldrb r4, [r1, #-1]!
209 ldrb r5, [r1, #-1]!
210 orr r4, r4, r5, lsl #8
211 sub r3, r4, r3 209 sub r3, r4, r3
212 rsbs r4, r3, #0 210 rsbs r4, r3, #0
213 adc r4, r4, r3 211 adc r4, r4, r3
214 strb r4, [r1], #1 212 wpush8 r4
215 b uxn_decode 213 b uxn_decode
216 214
217neq: 215neq:
218 ldrb r3, [r1, #-1]! 216 wpop8 r3
219 ldrb r4, [r1, #-1]! 217 wpop8 r4
220 subs r3, r4, r3 218 subs r3, r4, r3
221 movne r3, #1 219 movne r3, #1
222 strb r3, [r1], #1 220 wpush8 r3
223 b uxn_decode 221 b uxn_decode
224 222
225neq2: 223neq2:
226 ldrb r3, [r1, #-1]! 224 wpop16 r3, r5
227 ldrb r5, [r1, #-1]! 225 wpop16 r4, r5
228 orr r3, r3, r5, lsl #8
229 ldrb r4, [r1, #-1]!
230 ldrb r5, [r1, #-1]!
231 orr r4, r4, r5, lsl #8
232 subs r3, r4, r3 226 subs r3, r4, r3
233 movne r3, #1 227 movne r3, #1
234 strb r3, [r1], #1 228 wpush8 r3
235 b uxn_decode 229 b uxn_decode
236 230
237gth: 231gth:
238 ldrb r3, [r1, #-1]! 232 wpop8 r3
239 ldrb r4, [r1, #-1]! 233 wpop8 r4
240 cmp r4, r3 234 cmp r4, r3
241 movls r3, #0 235 movls r3, #0
242 movhi r3, #1 236 movhi r3, #1
243 strb r3, [r1], #1 237 wpush8 r3
244 b uxn_decode 238 b uxn_decode
245 239
246gth2: 240gth2:
247 ldrb r3, [r1, #-1]! 241 wpop16 r3, r5
248 ldrb r5, [r1, #-1]! 242 wpop16 r4, r5
249 orr r3, r3, r5, lsl #8
250 ldrb r4, [r1, #-1]!
251 ldrb r5, [r1, #-1]!
252 orr r4, r4, r5, lsl #8
253 cmp r4, r3 243 cmp r4, r3
254 movls r3, #0 244 movls r3, #0
255 movhi r3, #1 245 movhi r3, #1
256 strb r3, [r1], #1 246 wpush8 r3
257 b uxn_decode 247 b uxn_decode
258 248
259lth: 249lth:
260 ldrb r3, [r1, #-1]! 250 wpop8 r3
261 ldrb r4, [r1, #-1]! 251 wpop8 r4
262 cmp r4, r3 252 cmp r4, r3
263 movcs r3, #0 253 movcs r3, #0
264 movcc r3, #1 254 movcc r3, #1
265 strb r3, [r1], #1 255 wpush8 r3
266 b uxn_decode 256 b uxn_decode
267 257
268lth2: 258lth2:
269 ldrb r3, [r1, #-1]! 259 wpop16 r3, r5
270 ldrb r5, [r1, #-1]! 260 wpop16 r4, r5
271 orr r3, r3, r5, lsl #8
272 ldrb r4, [r1, #-1]!
273 ldrb r5, [r1, #-1]!
274 orr r4, r4, r5, lsl #8
275 cmp r4, r3 261 cmp r4, r3
276 movcs r3, #0 262 movcs r3, #0
277 movcc r3, #1 263 movcc r3, #1
278 strb r3, [r1], #1 264 wpush8 r3
279 b uxn_decode 265 b uxn_decode
280 266
281jmp: 267jmp:
@@ -351,63 +337,45 @@ deo2:
351 b uxn_decode 337 b uxn_decode
352 338
353add: 339add:
354 ldrb r3, [r1, #-1]! 340 wpop8 r3
355 ldrb r4, [r1, #-1]! 341 wpop8 r4
356 add r3, r3, r4 342 add r3, r3, r4
357 strb r3, [r1], #1 343 wpush8 r3
358 b uxn_decode 344 b uxn_decode
359 345
360add2: 346add2:
361 ldrb r3, [r1, #-1]! 347 wpop16 r3, r5
362 ldrb r5, [r1, #-1]! 348 wpop16 r4, r5
363 orr r3, r3, r5, lsl #8
364 ldrb r4, [r1, #-1]!
365 ldrb r5, [r1, #-1]!
366 orr r4, r4, r5, lsl #8
367 add r3, r3, r4 349 add r3, r3, r4
368 strb r3, [r1, #1] 350 wpush16 r3
369 lsr r3, #8
370 strb r3, [r1], #2
371 b uxn_decode 351 b uxn_decode
372 352
373sub: 353sub:
374 ldr r3, [r1, #-1]! 354 wpop8 r3
375 ldr r4, [r1, #-1]! 355 wpop8 r4
376 sub r4, r4, r3 356 sub r4, r4, r3
377 strb r4, [r1], #1 357 wpush8 r4
378 b uxn_decode 358 b uxn_decode
379 359
380sub2: 360sub2:
381 ldrb r3, [r1, #-1]! 361 wpop16 r3, r5
382 ldrb r5, [r1, #-1]! 362 wpop16 r4, r5
383 orr r3, r3, r5, lsl #8
384 ldrb r4, [r1, #-1]!
385 ldrb r5, [r1, #-1]!
386 orr r4, r4, r5, lsl #8
387 sub r3, r4, r3 363 sub r3, r4, r3
388 strb r3, [r1, #1] 364 wpush16 r3
389 lsr r3, #8
390 strb r3, [r1], #2
391 b uxn_decode 365 b uxn_decode
392 366
393mul: 367mul:
394 ldr r3, [r1, #-1]! 368 wpop8 r3
395 ldr r4, [r1, #-1]! 369 wpop8 r4
396 mul r4, r3, r4 370 mul r4, r3, r4
397 strb r4, [r1], #1 371 wpush8 r4
398 b uxn_decode 372 b uxn_decode
399 373
400mul2: 374mul2:
401 ldrb r3, [r1, #-1]! 375 wpop16 r3, r5
402 ldrb r5, [r1, #-1]! 376 wpop16 r4, r5
403 orr r3, r3, r5, lsl #8
404 ldrb r4, [r1, #-1]!
405 ldrb r5, [r1, #-1]!
406 orr r4, r4, r5, lsl #8
407 mul r3, r4, r3 377 mul r3, r4, r3
408 strb r3, [r1, #1] 378 wpush16 r3
409 lsr r3, #8
410 strb r3, [r1], #2
411 b uxn_decode 379 b uxn_decode
412 380
413div: 381div: