-
Notifications
You must be signed in to change notification settings - Fork 15
/
testall.asm
954 lines (843 loc) · 9.86 KB
/
testall.asm
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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
; Testing 6502 opcodes.
; Copied and adapted from AllSuiteA.asm from project hmc-6502:
; https://code.google.com/archive/p/hmc-6502/
; EXPECTED FINAL RESULTS: $0210 = FF
; (any other number will be the test that failed)
; To build with cl65:
; cl65 -C testall_cl65.cfg -l --start-addr 16384 -t none -o tall.bin testall.asm
; then load to simulator from debug console with 'L B TALL.BIN'
; and execute with 'X 4000'.
.segment "CODE1"
.segment "CODE2"
.ORG $4000
start:
; initialize:
LDA #$00
STA $0210
; store each test's expected
LDA #$55
STA $0200
LDA #$AA
STA $0201
LDA #$FF
STA $0202
LDA #$6E
STA $0203
LDA #$42
STA $0204
LDA #$33
STA $0205
LDA #$9D
STA $0206
LDA #$7F
STA $0207
LDA #$A5
STA $0208
LDA #$1F
STA $0209
LDA #$CE
STA $020A
LDA #$29
STA $020B
LDA #$42
STA $020C
LDA #$6C
STA $020D
LDA #$42
STA $020E
; expected result: $022A = 0x55
test00:
LDA #85
LDX #42
LDY #115
STA $81
LDA #$01
STA $61
LDA #$7E
LDA $81
STA $0910
LDA #$7E
LDA $0910
STA $56,X
LDA #$7E
LDA $56,X
STY $60
STA ($60),Y
LDA #$7E
LDA ($60),Y
STA $07ff,X
LDA #$7E
LDA $07ff,X
STA $07ff,Y
LDA #$7E
LDA $07ff,Y
STA ($36,X)
LDA #$7E
LDA ($36,X)
STX $50
LDX $60
LDY $50
STX $0913
LDX #$22
LDX $0913
STY $0914
LDY #$99
LDY $0914
STY $2D,X
STX $77,Y
LDY #$99
LDY $2D,X
LDX #$22
LDX $77,Y
LDY #$99
LDY $08A0,X
LDX #$22
LDX $08A1,Y
STA $0200,X
; CHECK test00:
LDA $022A
CMP $0200
BEQ test00pass
JMP theend
test00pass:
LDA #$FE
STA $0210
; expected result: $A9 = 0xAA
test01:
; imm
LDA #85
AND #83
ORA #56
EOR #17
; zpg
STA $99
LDA #185
STA $10
LDA #231
STA $11
LDA #57
STA $12
LDA $99
AND $10
ORA $11
EOR $12
; zpx
LDX #16
STA $99
LDA #188
STA $20
LDA #49
STA $21
LDA #23
STA $22
LDA $99
AND $10,X
ORA $11,X
EOR $12,X
; abs
STA $99
LDA #111
STA $0110
LDA #60
STA $0111
LDA #39
STA $0112
LDA $99
AND $0110
ORA $0111
EOR $0112
; abx
STA $99
LDA #138
STA $0120
LDA #71
STA $0121
LDA #143
STA $0122
LDA $99
AND $0110,X
ORA $0111,X
EOR $0112,X
; aby
LDY #32
STA $99
LDA #115
STA $0130
LDA #42
STA $0131
LDA #241
STA $0132
LDA $99
AND $0110,Y
ORA $0111,Y
EOR $0112,Y
; idx
STA $99
LDA #112
STA $30
LDA #$01
STA $31
LDA #113
STA $32
LDA #$01
STA $33
LDA #114
STA $34
LDA #$01
STA $35
LDA #197
STA $0170
LDA #124
STA $0171
LDA #161
STA $0172
LDA $99
AND ($20,X)
ORA ($22,X)
EOR ($24,X)
; idy
STA $99
LDA #96
STA $40
LDA #$01
STA $41
LDA #97
STA $42
LDA #$01
STA $43
LDA #98
STA $44
LDA #$01
STA $45
LDA #55
STA $0250
LDA #35
STA $0251
LDA #157
STA $0252
LDA $99
LDY #$F0
AND ($40),Y
ORA ($42),Y
EOR ($44),Y
STA $A9
; CHECK test01
LDA $A9
CMP $0201
BEQ test02
LDA #$01
STA $0210
JMP theend
; expected result: $71 = 0xFF
test02:
LDA #$FF
LDX #$00
STA $90
INC $90
INC $90
LDA $90
LDX $90
STA $90,X
INC $90,X
LDA $90,X
LDX $91
STA $0190,X
INC $0192
LDA $0190,X
LDX $0192
STA $0190,X
INC $0190,X
LDA $0190,X
LDX $0193
STA $0170,X
DEC $0170,X
LDA $0170,X
LDX $0174
STA $0170,X
DEC $0173
LDA $0170,X
LDX $0173
STA $70,X
DEC $70,X
LDA $70,X
LDX $72
STA $70,X
DEC $71
DEC $71
; CHECK test02
LDA $71
CMP $0202
BEQ test03
LDA #$02
STA $0210
JMP theend
; expected result: $01DD = 0x6E
test03:
LDA #$4B
LSR
ASL
STA $50
ASL $50
ASL $50
LSR $50
LDA $50
LDX $50
ORA #$C9
STA $60
ASL $4C,X
LSR $4C,X
LSR $4C,X
LDA $4C,X
LDX $60
ORA #$41
STA $012E
LSR $0100,X
LSR $0100,X
ASL $0100,X
LDA $0100,X
LDX $012E
ORA #$81
STA $0100,X
LSR $0136
LSR $0136
ASL $0136
LDA $0100,X
; rol & ror
ROL
ROL
ROR
STA $70
LDX $70
ORA #$03
STA $0C,X
ROL $C0
ROR $C0
ROR $C0
LDA $0C,X
LDX $C0
STA $D0
ROL $75,X
ROL $75,X
ROR $75,X
LDA $D0
LDX $D0
STA $0100,X
ROL $01B7
ROL $01B7
ROL $01B7
ROR $01B7
LDA $0100,X
LDX $01B7
STA $01DD
ROL $0100,X
ROR $0100,X
ROR $0100,X
; CHECK test03
LDA $01DD
CMP $0203
BEQ test04
LDA #$03
STA $0210
JMP theend
; expected result: $40 = 0x42
test04:
LDA #$E8 ;originally:#$7C
STA $20
LDA #$42 ;originally:#$02
STA $21
LDA #$00
ORA #$03
JMP jump1
ORA #$FF ; not done
jump1:
ORA #$30
JSR subr
ORA #$42
JMP ($0020)
ORA #$FF ; not done
subr:
STA $30
LDX $30
LDA #$00
RTS
final:
STA $0D,X
; CHECK test04
LDA $40
CMP $0204
BEQ test05
LDA #$04
STA $0210
JMP theend
; expected result: $40 = 0x33
test05:
LDA #$35
TAX
DEX
DEX
INX
TXA
TAY
DEY
DEY
INY
TYA
TAX
LDA #$20
TXS
LDX #$10
TSX
TXA
STA $40
; CHECK test05
LDA $40
CMP $0205
BEQ test06
LDA #$05
STA $0210
JMP theend
; expected result: $30 = 9D
test06:
; RESET TO CARRY FLAG = 0
ROL
LDA #$6A
STA $50
LDA #$6B
STA $51
LDA #$A1
STA $60
LDA #$A2
STA $61
LDA #$FF
ADC #$FF
ADC #$FF
SBC #$AE
STA $40
LDX $40
ADC $00,X
SBC $01,X
ADC $60
SBC $61
STA $0120
LDA #$4D
STA $0121
LDA #$23
ADC $0120
SBC $0121
STA $F0
LDX $F0
LDA #$64
STA $0124
LDA #$62
STA $0125
LDA #$26
ADC $0100,X
SBC $0101,X
STA $F1
LDY $F1
LDA #$E5
STA $0128
LDA #$E9
STA $0129
LDA #$34
ADC $0100,Y
SBC $0101,Y
STA $F2
LDX $F2
LDA #$20
STA $70
LDA #$01
STA $71
LDA #$24
STA $72
LDA #$01
STA $73
ADC ($41,X)
SBC ($3F,X)
STA $F3
LDY $F3
LDA #$DA
STA $80
LDA #$00
STA $81
LDA #$DC
STA $82
LDA #$00
STA $83
LDA #$AA
ADC ($80),Y
SBC ($82),Y
STA $30
; CHECK test06
LDA $30
CMP $0206
BEQ test07
LDA #$06
STA $0210
JMP theend
; expected result: $15 = 0x7F
test07:
; prepare memory
LDA #$00
STA $34
LDA #$FF
STA $0130
LDA #$99
STA $019D
LDA #$DB
STA $0199
LDA #$2F
STA $32
LDA #$32
STA $4F
LDA #$30
STA $33
LDA #$70
STA $AF
LDA #$18
STA $30
; imm
CMP #$18
BEQ beq1 ; taken
AND #$00 ; not done
beq1:
; zpg
ORA #$01
CMP $30
BNE bne1 ; taken
AND #$00 ; not done
bne1:
; abs
LDX #$00
CMP $0130
BEQ beq2 ; not taken
STA $40
LDX $40
beq2:
; zpx
CMP $27,X
BNE bne2 ; not taken
ORA #$84
STA $41
LDX $41
bne2:
; abx
AND #$DB
CMP $0100,X
BEQ beq3 ; taken
AND #$00 ; not done
beq3:
; aby
STA $42
LDY $42
AND #$00
CMP $0100,Y
BNE bne3 ; taken
ORA #$0F ; not done
bne3:
; idx
STA $43
LDX $43
ORA #$24
CMP ($40,X)
BEQ beq4 ; not taken
ORA #$7F
beq4:
; idy
STA $44
LDY $44
EOR #$0F
CMP ($33),Y
BNE bne4 ; not taken
LDA $44
STA $15
bne4:
; CHECK test07
LDA $15
CMP $0207
BEQ test08
LDA #$07
STA $0210
JMP theend
; expected result: $42 = 0xA5
test08:
; prepare memory
LDA #$A5
STA $20
STA $0120
LDA #$5A
STA $21
; cpx imm...
LDX #$A5
CPX #$A5
BEQ b1 ; taken
LDX #$01 ; not done
b1:
; cpx zpg...
CPX $20
BEQ b2 ; taken
LDX #$02 ; not done
b2:
; cpx abs...
CPX $0120
BEQ b3 ; taken
LDX #$03 ; not done
b3:
; cpy imm...
STX $30
LDY $30
CPY #$A5
BEQ b4 ; taken
LDY #$04 ; not done
b4:
; cpy zpg...
CPY $20
BEQ b5 ; taken
LDY #$05 ; not done
b5:
; cpy abs...
CPY $0120
BEQ b6 ; taken
LDY #$06 ; not done
b6:
; bit zpg...
STY $31
LDA $31
BIT $20
BNE b7 ; taken
LDA #$07 ; not done
b7:
; bit abs...
BIT $0120
BNE b8 ; taken
LDA #$08 ; not done
b8:
BIT $21
BNE b9 ; not taken
STA $42
b9:
; CHECK test08
LDA $42
CMP $0208
BEQ test09
LDA #$08
STA $0210
JMP theend
; expected result: $80 = 0x1F
test09:
; prepare memory
LDA #$54
STA $32
LDA #$B3
STA $A1
LDA #$87
STA $43
; BPL
LDX #$A1
BPL bpl1 ; not taken
LDX #$32
bpl1:
LDY $00,X
BPL bpl2 ; taken
LDA #$05 ; not done
LDX $A1 ; not done
bpl2:
; BMI
BMI bmi1 ; not taken
SBC #$03
bmi1:
BMI bmi2 ; taken
LDA #$41 ; not done
bmi2:
; BVC
EOR #$30
STA $32
ADC $00,X
BVC bvc1 ; not taken
LDA #$03
bvc1:
STA $54
LDX $00,Y
ADC $51,X
BVC bvc2 ; taken
LDA #$E5 ; not done
bvc2:
; BVS
ADC $40,X
BVS bvs1 ; not taken
STA $0001,Y
ADC $55
bvs1:
BVS bvs2 ; taken
LDA #$00
bvs2:
; BCC
ADC #$F0
BCC bcc1 ; not taken
STA $60
ADC $43
bcc1:
BCC bcc2 ; taken
LDA #$FF
bcc2:
; BCS
ADC $54
BCS bcs1 ; not taken
ADC #$87
LDX $60
bcs1:
BCS bcs2 ; taken
LDA #$00 ; not done
bcs2:
STA $73,X
; CHECK test09
LDA $80
CMP $0209
BEQ test10
LDA #$09
STA $0210
JMP theend
; expected result: $30 = 0xCE
test10:
; RESET TO CARRY = 0 & OVERFLOW = 0
ADC #$00
LDA #$99
ADC #$87
CLC
NOP
BCC t10bcc1 ; taken
ADC #$60 ; not done
ADC #$93 ; not done
t10bcc1:
SEC
NOP
BCC t10bcc2 ; not taken
CLV
t10bcc2:
BVC t10bvc1 ; taken
LDA #$00 ; not done
t10bvc1:
ADC #$AD
NOP
STA $30
; CHECK test10
LDA $30
CMP $020A
BEQ test11
LDA #$0A
STA $0210
JMP theend
; expected result: $30 = 0x29
test11:
; RESET TO CARRY = 0 & ZERO = 0
ADC #$01
LDA #$27
ADC #$01
SEC
PHP
CLC
PLP
ADC #$00
PHA
LDA #$00
PLA
STA $30
; CHECK test11
LDA $30
CMP $020B
BEQ test12
LDA #$0B
STA $0210
JMP theend
; expected result: $33 = 0x42
test12:
CLC
LDA #$42
BCC runstuff
STA $33
BCS t12end
runstuff:
LDA #$45
PHA
LDA #$61
PHA
SEC
PHP
CLC
RTI
t12end:
; CHECK test12
LDA $33
CMP $020C
BEQ test13
LDA #$0C
STA $0210
JMP theend
; expected result: $21 = 0x6C (simulator)
; $21 = 0x0C (ours)
test13:
; RESET TO CARRY = 0 & ZERO = 0
ADC #$01
SEI
SED
PHP
PLA
STA $20
CLI
CLD
PHP
PLA
ADC $20
STA $21
; CHECK test13
LDA $21
CMP $020D
BEQ test14
LDA #$0D
STA $0210
JMP theend
; expect result: $60 = 0x42
test14:
; !!! NOTICE: BRK doesn't work in this
; simulator, so commented instructions
; are what should be executed...
;JMP pass_intrp
LDA #$41
STA $60
;RTI
;pass_intrp:
;LDA #$FF
;STA $60
;BRK (two bytes)
INC $60
; CHECK test14
LDA $60
CMP $020E
BEQ suiteafinal
LDA #$0E
STA $0210
JMP theend
suiteafinal:
; IF $0210 == 0xFE, INCREMENT
; (checking that it didn't
; happen to wander off and
; not run our instructions
; to say which tests failed...)
LDA #$FE
CMP $0210
BNE theend
INC $0210
theend:
BRK
BRK
;JMP theend
LDX #$FF
TXS
RTS
.segment "KERN"
.ORG $FF00
RTI
.segment "VECT"
.ORG $FFFA
.BYTE $00,$FF,$00,$FF,$00,$FF
;-------------------------- END