-
Notifications
You must be signed in to change notification settings - Fork 22
/
cputest.a65
193 lines (161 loc) · 2.46 KB
/
cputest.a65
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
.word $0801
.org $0801
; BASIC program that just calls our machine language code
.scope
.word _next, 10 ; Next line and current line number
.byte $9e," 2304",0 ; SYS 2062
_next: .word 0 ; End of program
; temporary storage
old_nmi: .word 0
old_irq: .word 0
temp_a: .byte 0
temp_x: .byte 0
temp_y: .byte 0
temp_p: .byte 0
temp1: .byte 0
flag: .byte 0
.scend
.data zp ; Zero Page memory segment.
.org $0002
.text
.advance $0900
.scope
jsr test00
sta $0401
stx $0402
sty $0403
; write contents of Carry Flag (carry clear marks success)
lda #$00
rol
sta $0400
jsr test01
sta $0405
stx $0406
sty $0407
; write contents of Carry Flag (carry clear marks success)
lda #$00
rol
sta $0404
rts
test00: ; BRK implied mode (but with "virtual immediate" operand)
sei
lda #$00
tax
tay
sta flag
; save BRK vector
lda $0316
sta old_irq
lda $0317
sta old_irq+1
; insert our own BRK routine
lda #<brkirq
sta $0316
lda #>brkirq
sta $0317
php
pla
sta temp_p
; Run BRK instruction
brk
.byte $42
brkreturnaddress:
; restore BRK vector
lda old_irq
sta $0316
lda old_irq+1
sta $0317
; check that BRK routine was actually called.
lda flag
cmp #$01
bne brknoirq
; all was fine
clc
lda #$00
tax
tay
rts
signalerror1:
lda #$01
commonerror:
ldx #$00
ldy #$00
sec
rts
signalerror2:
lda #$02
jmp commonerror
signalerror3:
lda #$03
jmp commonerror
signalerror4:
lda #$04
jmp commonerror
brkirq: lda #$01
sta flag
; pop registers that the kernel pushes
pla
pla
pla
; check that P gets pushed with B flag set
pla
sta temp1
and #$10
beq brkflagwrong
; check that PCL gets pushed
pla
cmp #<brkreturnaddress
bne brkpclwrong
; check that PCH gets pushed
pla
cmp #>brkreturnaddress
bne brkpchwrong
; Everything seems fine, go back to where we left off.
jmp brkreturnaddress
test01: ; ORA ($xx,X)
; test with X zero
ldx #$00
lda #<flag
sta $fd
lda #>flag
sta $fe
lda #$55
sta flag
lda #$00
ORA ($fd,X)
cmp #$55
bne fail01a
; test with X non zero
lda #<flag
sta $fe
lda #>flag
sta $ff
lda #$aa
sta flag
ldx #$01
lda #$00
ORA ($fd,X)
cmp #$aa
bne fail01b
; test wrapping around past the end of ZP
ldx #$ff
lda #$00
ORA ($ff,X)
cmp #$aa
bne fail01c
lda #$55
sta flag
lda #$00
ORA ($ff,X)
cmp #$55
bne fail01c
; all passed
lda #$00
tax
tay
clc
rts
fail01a: jmp signalerror1
fail01b: jmp signalerror2
fail01c: jmp signalerror3
.scend