forked from Timendus/chip8-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-quirks.8o
412 lines (374 loc) · 7.27 KB
/
5-quirks.8o
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# Quirks test
# This is a visual adaptation of some of the tests I wrote for Silicon8
# (https://github.com/Timendus/silicon8/tree/main/tests) and some newly written
# tests for specific quirks.
:include "../utils/helpers.8o"
:include "../utils/menu.8o"
:include "../utils/text-rendering.8o"
:macro show X address {
v0 := X
i := address
sprite v0 v1 15
}
: main
clear
i := 0x1FF
load v0
if v0 == 1 then jump quirks-chip8
if v0 == 2 then jump quirks-schip
if v0 == 3 then jump quirks-xochip
text 6 2 quirks-choose
text 16 10 quirks-str-chip8
text 16 15 quirks-str-schip
text 16 20 quirks-str-xochip
# Show version number in bottom right corner
x := 50
y := 27
i := version-0-0
sprite x y 4
x := 58
i := version-1-0
sprite x y 4
:unpack 0xA quirks-menu
v2 := 2
jump menu-start
: quirks-chip8
i := scratchpad
v0 := 1
save v0
jump quirks-run-tests
: quirks-schip
i := scratchpad
v0 := 2
save v0
jump quirks-run-tests
: quirks-xochip
i := scratchpad
v0 := 3
save v0
: quirks-run-tests
waitKeyRelease
# Determine frames per second for dispQuirk
clear
v1 := 0
show 8 splash-0-0
show 16 splash-1-0
show 24 splash-2-0
show 32 splash-3-0
show 40 splash-4-0
show 48 splash-5-0
v1 := 15
show 8 splash-0-1
show 16 splash-1-1
show 24 splash-2-1
show 32 splash-3-1
show 40 splash-4-1
show 48 splash-5-1
i := quirks-values
load v6
i := quirks-image
delay := v5
loop
v5 := 30
loop
sprite v0 v1 1
if vF == 0 begin
v0 := 54
v6 := delay
v6 >>= v6
v6 >>= v6
v0 -= v6
end
v5 -= 1
if v5 != 0 then
again
v2 += v4
v3 += vF
vE := delay
if vE != 0 then again
# We expect the inner loop with 30 `sprite`s to have been able to run six
# times in the timespan of 180 interrupts
v0 := 1
if v3 != 0 then v0 := 0
if v2 > 6 then v0 := 0
if v2 < 6 then v0 := 2
i := scratchpad-plus-1
save v0
# Determine if sprites get clipped vertically
clear
i := cursor
v0 := 28
v1 := 29
sprite v0 v1 6
v0 := 22
v1 := 2
sprite v0 v1 2
v5 := vF
v0 := 34
sprite v0 v1 2
v6 := vF
# Determine if sprites get clipped horizontally
clear
i := cursor
v0 := 61
v1 := 5
sprite v0 v1 6
v0 := 3
v1 := 4
sprite v0 v1 2
v7 := vF
v1 := 10
sprite v0 v1 2
v8 := vF
# Determine if sprites get wrapped (both directions)
clear
v0 := 110
v1 := 50
sprite v0 v1 6 # Should draw at 46,18
v0 := 40
v1 := 17
sprite v0 v1 2
v9 := vF
v0 := 52
sprite v0 v1 2
v9 += vF
v1 := 23
sprite v0 v1 2
v9 += vF
v0 := 40
sprite v0 v1 2
v9 += vF
# Save result
v0 := 0
# Clipping
if v5 == 0 then v0 := 1
if v5 != v6 then v0 := 2
if v5 != v7 then v0 := 2
if v5 != v8 then v0 := 2
# Wrapping
if v9 != 4 then v0 := 3
i := scratchpad-plus-2
save v0
# Present results
clear
# vfQuirk
# When using &, | or ^, the flags register always gets reset to 0
text 1 1 quirks-vf
v5 := 0
vF := 15
v0 &= v0
if vF == 0 then v5 := 1
v6 := 0
vF := 15
v0 |= v0
if vF == 0 then v6 := 1
v7 := 0
vF := 15
v0 ^= v0
if vF == 0 then v7 := 1
i := scratchpad
load v0
i := flag-err
if v0 == 1 begin
# Selected CHIP-8
if v5 == 1 then i := flag-ok
else
# Selected SCHIP or XO-CHIP
if v5 == 0 then i := flag-ok
end
x := 59
y := 2
sprite x y 3
i := quirks-off
if v5 == 1 then i := quirks-on
if v5 != v6 then i := quirks-inconsistent-1
if v5 != v7 then i := quirks-inconsistent-2
vD := 44
vE := 1
drawText
# memQuirk
# When reading or writing memory, i gets incremented
text 1 6 quirks-mem
v0 := 5
i := scratchpad-plus-16
save v0
load v0
v5 := v0
i := scratchpad
load v0
i := flag-err
if v0 == 2 begin
# Selected SCHIP
if v5 == 5 then i := flag-ok
else
# Selected CHIP-8 or XO-CHIP
if v5 != 5 then i := flag-ok
end
x := 59
y := 7
sprite x y 3
i := quirks-on
if v5 == 5 then i := quirks-off
vD := 44
vE := 6
drawText
# dispQuirk
# When drawing a sprite to the screen, the interpreter waits for v-blank
text 1 11 quirks-disp
i := scratchpad
load v1
i := flag-err
if v0 == 1 begin
# Selected CHIP-8
if v1 == 1 then i := flag-ok
else
# Selected SCHIP or XO-CHIP
if v1 == 0 then i := flag-ok
end
x := 59
y := 12
sprite x y 3
i := quirks-off
if v1 == 1 then i := quirks-on
if v1 == 2 then i := quirks-low
vD := 44
vE := 11
drawText
# clipQuirk
# Sprites wrap to the top of the screen
text 1 16 quirks-clip
i := scratchpad
load v2
i := flag-err
if v0 == 3 begin
# Selected XO-CHIP
if v2 == 0 then i := flag-ok
else
# Selected CHIP-8 or SCHIP
if v2 == 1 then i := flag-ok
end
x := 59
y := 17
sprite x y 3
i := quirks-off
if v2 == 1 then i := quirks-on
if v2 == 2 then i := quirks-inconsistent-1
if v2 == 3 then i := quirks-inconsistent-2
vD := 44
vE := 16
drawText
# shiftQuirk
# When shifting a register, the interpreter always shifts register X into
# register X (instead of shifting register Y into register X)
text 1 21 quirks-shift
v5 := 0
v6 := 8
v7 := 0
v8 := 32
v5 <<= v6
v7 >>= v8
i := scratchpad
load v0
i := flag-err
if v0 == 2 begin
# Selected SCHIP
if v5 == 0 then i := flag-ok
else
# Selected CHIP-8 or XO-CHIP
if v5 != 0 then i := flag-ok
end
x := 59
y := 22
sprite x y 3
i := quirks-off
if v5 == 0 then i := quirks-on
if v5 != v7 then i := quirks-inconsistent-1
vD := 44
vE := 21
drawText
# jumpQuirk
# When using `jump0` (BNNN) the interpreter doesn't jump to NNN + v0 but to
# NNN + vX where X is the highest nibble of NNN
text 1 26 quirks-jump
v0 := 0x98
vE := 0x9C
jump0 0xE00 # This jumps to one of two routines defined in index.8o (for
: quirks-resume # reasons of having to put them in precisely the right spot)
i := scratchpad
load v0
i := flag-err
if v0 == 2 begin
# Selected SCHIP
if v5 != 0 then i := flag-ok
else
# Selected CHIP-8 or XO-CHIP
if v5 == 0 then i := flag-ok
end
x := 59
y := 27
sprite x y 3
i := quirks-off
if v5 == 1 then i := quirks-on
vD := 44
vE := 26
drawText
v0 := key
waitKeyRelease
jump main
:segment data
: quirks-menu
12 11 :pointer quirks-chip8
12 16 :pointer quirks-schip
12 21 :pointer quirks-xochip
: quirks-choose
str "PICK PLATFORM" 0
: quirks-str-chip8
str "1 CHIP-8" 0
: quirks-str-schip
str "2 SCHIP" 0
: quirks-str-xochip
str "3 XO-CHIP" 0
: quirks-vf
str "VF RESET" 0
: quirks-mem
str "MEMORY" 0
: quirks-disp
str "DISP.WAIT" 0
: quirks-clip
str "CLIPPING" 0
: quirks-shift
str "SHIFTING" 0
: quirks-jump
str "JUMPING" 0
: quirks-on
str "ON" 0
: quirks-off
str "OFF" 0
: quirks-inconsistent-1
str "E1" 0
: quirks-inconsistent-2
str "E2" 0
: quirks-low
str "LOW" 0
: quirks-values
10 31 0 0 1 180 0
: quirks-image
0b10000000
: cursor
0b11111110
0b11111110
0b11111110
0b11111110
0b11111110
0b11111110
:include "../../pictures/version.png"
:include "../../pictures/splash.png"
# Jump quirk targets:
:org 0xE98
# We jump here when using v0 in the `jump0` quirks test
v5 := 0
jump quirks-resume
:org 0xE9C
# We jump here when using vE in the `jump0` quirks test
v5 := 1
jump quirks-resume