-
Notifications
You must be signed in to change notification settings - Fork 7
/
5-quirks.8o
788 lines (723 loc) · 14.3 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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# 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"
:const OFF 0
:const ON 1
:const BOTH 2
:const NONE 3
:const LORES 4
:const HIRES 5
:const ERR1 6
:const ERR2 7
:const ERR3 8
:const CHIP8 1
:const SCHIP_MODERN 2
:const XOCHIP 3
:const SCHIP_LEGACY 4
: main
clear
i := 0x1FF
load v0
if v0 == CHIP8 then jump quirks-chip8
if v0 == SCHIP_MODERN then jump quirks-schip
if v0 == SCHIP_LEGACY then jump quirks-schip-legacy
if v0 == XOCHIP then jump quirks-xochip
text 6 2 quirks-choose
text 10 10 quirks-str-chip8
text 10 15 quirks-str-schip
text 10 20 quirks-str-xochip
render-version
:unpack 0xA quirks-menu
v2 := 2
jump menu-start
: superchip-menu
clear
text 10 2 quirks-choose-superchip
text 18 12 quirks-str-modern
text 18 17 quirks-str-legacy
render-version
:unpack 0xA superchip-target-menu
v2 := 1
jump menu-start
: render-version
x := 50
y := 27
i := version-0-0
sprite x y 4
x := 58
i := version-1-0
sprite x y 4
return
:segment data
: quirks-menu
6 11 :pointer quirks-chip8
6 16 :pointer superchip-menu
6 21 :pointer quirks-xochip
: quirks-choose
str "PICK PLATFORM" 0
: quirks-str-chip8
str "1 CHIP-8" 0
: quirks-str-schip
str "2 SUPER-CHIP" 0
: quirks-str-xochip
str "3 XO-CHIP" 0
: superchip-target-menu
14 13 :pointer quirks-schip
14 18 :pointer quirks-schip-legacy
: quirks-choose-superchip
str "PICK TARGET" 0
: quirks-str-modern
str "1 MODERN" 0
: quirks-str-legacy
str "2 LEGACY" 0
:segment code
: quirks-chip8
i := scratchpad
v0 := CHIP8
save v0
jump quirks-run-tests
: quirks-schip
i := scratchpad
v0 := SCHIP_MODERN
save v0
jump quirks-run-tests
: quirks-schip-legacy
i := scratchpad
v0 := SCHIP_LEGACY
save v0
jump quirks-run-tests
: quirks-xochip
i := scratchpad
v0 := XOCHIP
save v0
: quirks-run-tests
waitKeyRelease
clear
# Determine frames per second for dispQuirk
i := scratchpad
load v0
if v0 == CHIP8 begin
get-frames-per-second-chip8
# We expect the inner loop with 30 `sprite`s to have been able to run six
# times in the timespan of 180 interrupts
v0 := ON
if v3 != 0 then v0 := OFF
if v2 > 6 then v0 := OFF
if v2 < 6 then v0 := ERR1
i := scratchpad-plus-1
save v0
else # Superchip & XO-CHIP
get-frames-per-second-schip-xochip
# We expect the inner loop with 30 `sprite`s to have been able to run 3
# times in the timespan of 90 interrupts
v0 := ON
if v3 != 0 then v0 := OFF
if v2 > 3 then v0 := OFF
if v2 < 3 then v0 := ERR1
i := scratchpad-plus-1
save v0
# Do the test again, but now in hires mode
hires
clear
get-frames-per-second-hires
# We expect the inner loop with 30 `sprite`s to have been able to run 3
# times in the timespan of 90 interrupts
v1 := ON
if v3 != 0 then v1 := OFF
if v2 > 3 then v1 := OFF
if v2 < 3 then v1 := ERR1
i := scratchpad-plus-1
load v0
if v0 == ERR1 then jump quirks-combined-vblank-skip
if v1 == ERR1 begin
v0 := ERR1
jump quirks-combined-vblank-skip
end
if v0 == OFF begin
if v1 == OFF then v0 := NONE
if v1 == ON then v0 := HIRES
end
if v0 == ON begin
if v1 == OFF then v0 := LORES
if v1 == ON then v0 := BOTH
end
: quirks-combined-vblank-skip
i := scratchpad-plus-1
save v0
lores
end
# 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 := OFF
# Clipping
if v5 == 0 then v0 := ON
if v5 != v6 then v0 := ERR1
if v5 != v7 then v0 := ERR1
if v5 != v8 then v0 := ERR1
# Wrapping
if v9 != 4 then v0 := ERR2
i := scratchpad-plus-2
save v0
# If SuperCHIP or XO-CHIP, do it again in hires
i := scratchpad
load v0
if v0 != CHIP8 begin
hires
# Determine if sprites get clipped vertically
clear
i := cursor
v0 := 60
v1 := 61
sprite v0 v1 6
v0 := 54
v1 := 2
sprite v0 v1 2
v5 := vF
v0 := 66
sprite v0 v1 2
v6 := vF
# Determine if sprites get clipped horizontally
clear
i := cursor
v0 := 125
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 := 174
v1 := 82
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
# Determine result
v1 := OFF
# Clipping
if v5 == 0 then v1 := ON
if v5 != v6 then v1 := ERR1
if v5 != v7 then v1 := ERR1
if v5 != v8 then v1 := ERR1
# Wrapping
if v9 != 4 then v1 := ERR2
# Compare with previous result
i := scratchpad-plus-2
load v0
if v0 == ERR1 begin
if v1 == ERR1 then jump quirks-combined-wrapping-skip
v0 := ERR3
jump quirks-combined-wrapping-skip
end
if v0 == ERR2 begin
if v1 == ERR2 then jump quirks-combined-wrapping-skip
v0 := ERR3
jump quirks-combined-wrapping-skip
end
if v1 == ERR1 begin
v0 := ERR3
jump quirks-combined-wrapping-skip
end
if v1 == ERR2 begin
v0 := ERR3
jump quirks-combined-wrapping-skip
end
if v0 == ON begin
if v1 == ON then v0 := BOTH
if v1 == OFF then v0 := LORES
end
if v0 == OFF begin
if v1 == ON then v0 := HIRES
if v1 == OFF then v0 := NONE
end
: quirks-combined-wrapping-skip
i := scratchpad-plus-2
save v0
lores
end
# 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 == CHIP8 begin
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 := 42
vE := 1
drawText
# memQuirk
# When reading or writing memory, i gets incremented
text 1 6 quirks-mem
v0 := 1
v1 := 2
v2 := 3
v3 := 4
v4 := 5
i := scratchpad-plus-3
save v4
v0 := 11
v1 := 12
v2 := 13
i := scratchpad-plus-3
save v2
load v0
v5 := v0
load v0
v6 := v0
i := scratchpad
load v0
i := flag-err
v1 := 0
if v0 == CHIP8 then jump expect-memquirk
if v0 == SCHIP_MODERN then jump expect-no-memquirk
if v0 == SCHIP_LEGACY then jump expect-no-memquirk
if v0 == XOCHIP then jump expect-memquirk
: expect-memquirk
if v5 == 4 begin
if v6 == 5 begin
i := flag-ok
else
v1 := 1
end
end
jump memquirk-done
: expect-no-memquirk
if v5 == 11 begin
if v6 == 11 begin
i := flag-ok
else
v1 := 1
end
end
: memquirk-done
x := 59
y := 7
sprite x y 3
i := quirks-on
if v5 == 11 then i := quirks-off
if v1 == 1 then i := quirks-inconsistent-1
vD := 42
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 == CHIP8 begin
if v1 == ON then i := flag-ok
end
if v0 == SCHIP_MODERN begin
if v1 == NONE then i := flag-ok
end
if v0 == SCHIP_LEGACY begin
if v1 == LORES then i := flag-ok
end
if v0 == XOCHIP begin
if v1 == NONE then i := flag-ok
end
x := 59
y := 12
sprite x y 3
i := quirks-off
if v1 == ON then i := quirks-on
if v1 == ERR1 then i := quirks-slow
if v1 == LORES then i := quirks-lores
if v1 == HIRES then i := quirks-hires
if v1 == BOTH then i := quirks-both
if v1 == NONE then i := quirks-none
vD := 42
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 == CHIP8 begin
if v2 == ON then i := flag-ok
end
if v0 == SCHIP_MODERN begin
if v2 == BOTH then i := flag-ok
end
if v0 == SCHIP_LEGACY begin
if v2 == BOTH then i := flag-ok
end
if v0 == XOCHIP begin
if v2 == NONE then i := flag-ok
end
x := 59
y := 17
sprite x y 3
i := quirks-off
if v2 == ON then i := quirks-on
if v2 == LORES then i := quirks-lores
if v2 == HIRES then i := quirks-hires
if v2 == BOTH then i := quirks-both
if v2 == NONE then i := quirks-none
if v2 == ERR1 then i := quirks-inconsistent-1
if v2 == ERR2 then i := quirks-inconsistent-2
if v2 == ERR3 then i := quirks-inconsistent-3
vD := 42
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 == CHIP8 begin
if v5 != 0 then i := flag-ok
end
if v0 == SCHIP_MODERN begin
if v5 == 0 then i := flag-ok
end
if v0 == SCHIP_LEGACY begin
if v5 == 0 then i := flag-ok
end
if v0 == XOCHIP begin
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 := 42
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 == CHIP8 begin
if v5 == 0 then i := flag-ok
end
if v0 == SCHIP_MODERN begin
if v5 != 0 then i := flag-ok
end
if v0 == SCHIP_LEGACY begin
if v5 != 0 then i := flag-ok
end
if v0 == XOCHIP begin
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 := 42
vE := 26
drawText
v0 := key
waitKeyRelease
jump main
:segment data
: 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-slow
str "SLOW" 0
: quirks-lores
str "LRES" 0
: quirks-hires
str "HRES" 0
: quirks-both
str "BOTH" 0
: quirks-none
str "NONE" 0
: quirks-inconsistent-1
str "ERR1" 0
: quirks-inconsistent-2
str "ERR2" 0
: quirks-inconsistent-3
str "ERR3" 0
: cursor
0b11111110
0b11111110
0b11111110
0b11111110
0b11111110
0b11111110
:segment code
: get-frames-per-second-chip8
quirks-show-splash-lores
i := quirks-values
load v6
# v0 := 10
# v1 := 31
# v2 := 0
# v3 := 0
# v4 := 1
# v5 := 180
# v6 := 0
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
return
: get-frames-per-second-schip-xochip
quirks-show-splash-lores
i := quirks-values
load v6
# v0 := 10
# v1 := 31
# v2 := 0
# v3 := 0
# v4 := 1
# v5 := 180
# v6 := 0
v5 >>= v5
i := quirks-image
delay := v5
loop
v5 := 30
loop
sprite v0 v1 1
if vF == 0 begin
v0 := 32
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
return
: quirks-show-splash-lores
v0 := 8
v1 := 0
v2 := 15
i := splash-0-0
loop
sprite v0 v1 15
i += v2
v0 += 8
if v0 == 56 begin
v0 := 8
v1 += 15
end
if v1 != 30 then
again
return
: get-frames-per-second-hires
v0 := 16
v1 := 0
v2 := 32
i := splash2x-0-0
loop
sprite v0 v1 0
i += v2
v0 += 16
if v0 == 112 begin
v0 := 16
v1 += 16
end
if v1 != 64 then
again
# 11th pixel
i := quirks-values
load v6
# v0 := 10
# v1 := 31
# v2 := 0
# v3 := 0
# v4 := 1
# v5 := 180
# v6 := 0
v0 += v0
v1 += v1
v5 >>= v5
i := quirks-line
loop
sprite v0 v1 2
v0 += 8
if v0 != 60 then
again
i := quirks-image
loop
sprite v0 v1 2
v0 += 1
if v0 != 64 then
again
delay := v5
loop
v5 := 15
loop
sprite v0 v1 2
if vF == 0 begin
v0 := 108
v6 := delay
v6 >>= v6
v0 -= v6
end
v5 -= 1
if v5 != 0 then
again
v2 += v4
v3 += vF
vE := delay
if vE != 0 then again
return
:segment data
: quirks-values
10 31 0 0 1 180 0
: quirks-image
0b10000000
0b10000000
: quirks-line
0b11111111
0b11111111
:include "../../pictures/version.png"
:include "../../pictures/splash.png"
:include "../../pictures/splash2x.png" 16x16
# 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