r6502 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/LICENSE +20 -0
- data/README.md +27 -0
- data/bin/r6502 +41 -0
- data/lib/r6502.rb +6 -0
- data/lib/r6502/assembler.rb +204 -0
- data/lib/r6502/cpu_execution.rb +95 -0
- data/lib/r6502/cpu_instructions.rb +517 -0
- data/lib/r6502/instr_table.rb +213 -0
- data/lib/r6502/memory.rb +21 -0
- data/lib/r6502/opcode_table.rb +64 -0
- data/r6502.gemspec +13 -0
- data/spec/r6502/assembler_spec.rb +226 -0
- data/spec/r6502/cpu_execution_spec.rb +119 -0
- data/spec/r6502/cpu_instructions_spec.rb +1284 -0
- data/spec/r6502/memory_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -0
- metadata +60 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module R6502
|
4
|
+
describe "Cpu Execution" do
|
5
|
+
before(:each) do
|
6
|
+
@mem = Memory.new
|
7
|
+
@mem.set(0xfffc, 0x00)
|
8
|
+
@mem.set(0xfffd, 0x20)
|
9
|
+
@cpu = Cpu.new(@mem)
|
10
|
+
end
|
11
|
+
it "has PC, S, X, Y, A registers" do
|
12
|
+
@cpu.pc.should == 0x2000
|
13
|
+
@cpu.s.should == 0xff
|
14
|
+
@cpu.x.should == 0x00
|
15
|
+
@cpu.y.should == 0x00
|
16
|
+
@cpu.a.should == 0x00
|
17
|
+
end
|
18
|
+
it "has processor status flags" do
|
19
|
+
@cpu.c.should == 0
|
20
|
+
@cpu.z.should == 0
|
21
|
+
@cpu.i.should == 0
|
22
|
+
@cpu.d.should == 0
|
23
|
+
@cpu.b.should == 0
|
24
|
+
@cpu.v.should == 0
|
25
|
+
@cpu.n.should == 0
|
26
|
+
end
|
27
|
+
it "Finds instruction and mode from opcode" do
|
28
|
+
@cpu.instr_mode(0xa9).should == [:lda, :imm]
|
29
|
+
@cpu.instr_mode(0x69).should == [:adc, :imm]
|
30
|
+
@cpu.instr_mode(0x65).should == [:adc, :zp]
|
31
|
+
@cpu.instr_mode(0x75).should == [:adc, :zpx]
|
32
|
+
@cpu.instr_mode(0x0a).should == [:asl, :acc]
|
33
|
+
end
|
34
|
+
it "Finds the argument to the instruction" do
|
35
|
+
# IMPLIED
|
36
|
+
@cpu.decode_arg(:imp, 0x66, 0x66).should == nil
|
37
|
+
# IMMEDIATE
|
38
|
+
@cpu.decode_arg(:imm, 0x40, 0x66).should == 0x40
|
39
|
+
# ZERO PAGE
|
40
|
+
@cpu.decode_arg(:zp, 0x50, 0x66).should == 0x50
|
41
|
+
# ZPX
|
42
|
+
@cpu.x = 0xc0
|
43
|
+
@cpu.decode_arg(:zpx, 0x0f, 0x66).should == 0xcf
|
44
|
+
# ZPY
|
45
|
+
@cpu.y = 0xb0
|
46
|
+
@cpu.decode_arg(:zpy, 0x0f, 0x66).should == 0xbf
|
47
|
+
# RELATIVE
|
48
|
+
@cpu.decode_arg(:rel, 0xff, 0x66).should == -1
|
49
|
+
# ABSOLUTE
|
50
|
+
@cpu.decode_arg(:abs, 0xff, 0x66).should == 0x66ff
|
51
|
+
# ABSX
|
52
|
+
@cpu.x = 0x10
|
53
|
+
@cpu.decode_arg(:absx, 0xef, 0x66).should == 0x66ff
|
54
|
+
# ABSY
|
55
|
+
@cpu.y = 0x20
|
56
|
+
@cpu.decode_arg(:absy, 0xdf, 0x66).should == 0x66ff
|
57
|
+
# INDIRECT
|
58
|
+
@cpu.mem.set(0x1000, 0x30)
|
59
|
+
@cpu.mem.set(0x1001, 0x40)
|
60
|
+
@cpu.decode_arg(:ind, 0x00, 0x10).should == 0x4030
|
61
|
+
# INDX
|
62
|
+
@cpu.x = 0x03
|
63
|
+
@cpu.mem.set( 0xd0, 0xf0 )
|
64
|
+
@cpu.mem.set( 0xd1, 0xd0 )
|
65
|
+
@cpu.mem.set( 0xd0f0, 0x34 )
|
66
|
+
@cpu.decode_arg(:indx, 0xcd, 0x66).should == 0x34
|
67
|
+
# INDY
|
68
|
+
@cpu.y = 0x04
|
69
|
+
@cpu.mem.set( 0x10, 0xa0 )
|
70
|
+
@cpu.mem.set( 0x11, 0xb0 )
|
71
|
+
@cpu.mem.set( 0xb0a4, 0xcd )
|
72
|
+
@cpu.decode_arg(:indy, 0x10, 0x66).should == 0xcd
|
73
|
+
end
|
74
|
+
it "executes a single instr. from PC value and mem" do
|
75
|
+
@cpu.pc = 0x2000
|
76
|
+
@mem.set(0x2000, 0xea) #nop
|
77
|
+
@cpu.step
|
78
|
+
@cpu.pc.should == 0x2001
|
79
|
+
end
|
80
|
+
it "incr.s PC by correct amount for most instructions" do
|
81
|
+
@cpu.pc = 0x1000
|
82
|
+
@cpu.inc_pc_by_mode(:imp)
|
83
|
+
@cpu.pc.should == 0x1001
|
84
|
+
|
85
|
+
@cpu.inc_pc_by_mode(:acc)
|
86
|
+
@cpu.pc.should == 0x1002
|
87
|
+
|
88
|
+
@cpu.inc_pc_by_mode(:imm)
|
89
|
+
@cpu.pc.should == 0x1004
|
90
|
+
|
91
|
+
@cpu.inc_pc_by_mode(:zp)
|
92
|
+
@cpu.pc.should == 0x1006
|
93
|
+
|
94
|
+
@cpu.inc_pc_by_mode(:zpx)
|
95
|
+
@cpu.pc.should == 0x1008
|
96
|
+
|
97
|
+
@cpu.inc_pc_by_mode(:abs)
|
98
|
+
@cpu.pc.should == 0x100b
|
99
|
+
|
100
|
+
@cpu.inc_pc_by_mode(:absx)
|
101
|
+
@cpu.pc.should == 0x100e
|
102
|
+
|
103
|
+
@cpu.inc_pc_by_mode(:absy)
|
104
|
+
@cpu.pc.should == 0x1011
|
105
|
+
|
106
|
+
@cpu.inc_pc_by_mode(:indx)
|
107
|
+
@cpu.pc.should == 0x1013
|
108
|
+
|
109
|
+
@cpu.inc_pc_by_mode(:indy)
|
110
|
+
@cpu.pc.should == 0x1015
|
111
|
+
|
112
|
+
@cpu.inc_pc_by_mode(:rel)
|
113
|
+
@cpu.pc.should == 0x1017
|
114
|
+
|
115
|
+
@cpu.inc_pc_by_mode(:ind)
|
116
|
+
@cpu.pc.should == 0x101a
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,1284 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module R6502
|
4
|
+
describe "Cpu Instructions set flags" do
|
5
|
+
before(:each) do
|
6
|
+
@mem = Memory.new
|
7
|
+
@cpu = Cpu.new(@mem)
|
8
|
+
end
|
9
|
+
describe "ADC sets flags" do
|
10
|
+
it "adc 0" do
|
11
|
+
@cpu.v = 0x1
|
12
|
+
@cpu.z = 0x1
|
13
|
+
@cpu.c = 0x1
|
14
|
+
@cpu.n = 0x1
|
15
|
+
|
16
|
+
@cpu.a = 0x01
|
17
|
+
@cpu.adc(0x02, :imm)
|
18
|
+
@cpu.a.should == 0x04
|
19
|
+
@cpu.v.should == 0x0 #overflow
|
20
|
+
@cpu.z.should == 0x0 #zero
|
21
|
+
@cpu.c.should == 0x0 #carry
|
22
|
+
@cpu.n.should == 0x0 #negative
|
23
|
+
end
|
24
|
+
it "adc 1" do
|
25
|
+
@cpu.v = 0x1
|
26
|
+
@cpu.z = 0x1
|
27
|
+
@cpu.c = 0x0
|
28
|
+
@cpu.n = 0x1
|
29
|
+
|
30
|
+
@cpu.a = 0x0a
|
31
|
+
@cpu.adc(0xff, :imm)
|
32
|
+
@cpu.a.should == 0x09
|
33
|
+
@cpu.v.should == 0x0 #overflow
|
34
|
+
@cpu.z.should == 0x0 #zero
|
35
|
+
@cpu.c.should == 0x1 #carry
|
36
|
+
@cpu.n.should == 0x0 #negative
|
37
|
+
end
|
38
|
+
it "adc 2" do
|
39
|
+
@cpu.v = 0x0
|
40
|
+
@cpu.z = 0x1
|
41
|
+
@cpu.c = 0x1
|
42
|
+
@cpu.n = 0x0
|
43
|
+
|
44
|
+
@cpu.a = 0x70
|
45
|
+
@cpu.adc(0x70, :imm)
|
46
|
+
@cpu.a.should == 0xe1
|
47
|
+
@cpu.v.should == 0x1 #overflow
|
48
|
+
@cpu.z.should == 0x0 #zero
|
49
|
+
@cpu.c.should == 0x0 #carry
|
50
|
+
@cpu.n.should == 0x1 #negative
|
51
|
+
end
|
52
|
+
it "adc 3" do
|
53
|
+
@cpu.v = 0x0
|
54
|
+
@cpu.z = 0x1
|
55
|
+
@cpu.c = 0x0
|
56
|
+
@cpu.n = 0x1
|
57
|
+
|
58
|
+
@cpu.a = 0x80
|
59
|
+
@cpu.adc(0x90, :imm)
|
60
|
+
@cpu.a.should == 0x10
|
61
|
+
@cpu.v.should == 0x1 #overflow
|
62
|
+
@cpu.z.should == 0x0 #zero
|
63
|
+
@cpu.c.should == 0x1 #carry
|
64
|
+
@cpu.n.should == 0x0 #negative
|
65
|
+
end
|
66
|
+
it "adc 4" do
|
67
|
+
@cpu.v = 0x1
|
68
|
+
@cpu.z = 0x1
|
69
|
+
@cpu.c = 0x0
|
70
|
+
@cpu.n = 0x0
|
71
|
+
|
72
|
+
@cpu.a = 0xf0
|
73
|
+
@cpu.adc(0xf0, :imm)
|
74
|
+
@cpu.a.should == 0xe0
|
75
|
+
@cpu.v.should == 0x0 #overflow
|
76
|
+
@cpu.z.should == 0x0 #zero
|
77
|
+
@cpu.c.should == 0x1 #carry
|
78
|
+
@cpu.n.should == 0x1 #negative
|
79
|
+
end
|
80
|
+
it "adc 5" do
|
81
|
+
@cpu.v = 0x0
|
82
|
+
@cpu.z = 0x1
|
83
|
+
@cpu.c = 0x1
|
84
|
+
@cpu.n = 0x1
|
85
|
+
|
86
|
+
@cpu.a = 0x70
|
87
|
+
@cpu.adc(0x80, :imm)
|
88
|
+
@cpu.a.should == 0xf1
|
89
|
+
@cpu.v.should == 0x0 #overflow
|
90
|
+
@cpu.z.should == 0x0 #zero
|
91
|
+
@cpu.c.should == 0x0 #carry
|
92
|
+
@cpu.n.should == 0x1 #negative
|
93
|
+
end
|
94
|
+
it "adc 6" do
|
95
|
+
@cpu.v = 0x0
|
96
|
+
@cpu.z = 0x1
|
97
|
+
@cpu.c = 0x1
|
98
|
+
@cpu.n = 0x0
|
99
|
+
|
100
|
+
@cpu.a = 0x70
|
101
|
+
@cpu.adc(0x0f, :imm)
|
102
|
+
@cpu.a.should == 0x80
|
103
|
+
@cpu.v.should == 0x1 #overflow
|
104
|
+
@cpu.z.should == 0x0 #zero
|
105
|
+
@cpu.c.should == 0x0 #carry
|
106
|
+
@cpu.n.should == 0x1 #negative
|
107
|
+
end
|
108
|
+
it "adc 7" do
|
109
|
+
@cpu.v = 0x0
|
110
|
+
@cpu.z = 0x0
|
111
|
+
@cpu.c = 0x0
|
112
|
+
@cpu.n = 0x1
|
113
|
+
|
114
|
+
@cpu.a = 0x80
|
115
|
+
@cpu.adc(0x80, :imm)
|
116
|
+
@cpu.a.should == 0x00
|
117
|
+
@cpu.v.should == 0x1 #overflow
|
118
|
+
@cpu.z.should == 0x1 #zero
|
119
|
+
@cpu.c.should == 0x1 #carry
|
120
|
+
@cpu.n.should == 0x0 #negative
|
121
|
+
end
|
122
|
+
it "adc 8" do
|
123
|
+
@cpu.v = 0x0
|
124
|
+
@cpu.z = 0x0
|
125
|
+
@cpu.c = 0x1
|
126
|
+
@cpu.n = 0x1
|
127
|
+
|
128
|
+
@cpu.a = 0x7f
|
129
|
+
@cpu.adc(0x80, :imm)
|
130
|
+
@cpu.a.should == 0x00
|
131
|
+
@cpu.v.should == 0x0 #overflow
|
132
|
+
@cpu.z.should == 0x1 #zero
|
133
|
+
@cpu.c.should == 0x1 #carry
|
134
|
+
@cpu.n.should == 0x0 #negative
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "SBC sets flags" do
|
139
|
+
it "sbc 0" do
|
140
|
+
@cpu.z = 0
|
141
|
+
@cpu.c = 1
|
142
|
+
|
143
|
+
@cpu.a = 0x10
|
144
|
+
@cpu.sbc(0x10, :imm)
|
145
|
+
@cpu.a.should == 0x0
|
146
|
+
@cpu.z.should == 0x1
|
147
|
+
@cpu.c.should == 1
|
148
|
+
@cpu.v.should == 0
|
149
|
+
@cpu.n.should == 0
|
150
|
+
end
|
151
|
+
it "sbc 1" do
|
152
|
+
@cpu.z = 1
|
153
|
+
@cpu.c = 1
|
154
|
+
|
155
|
+
@cpu.a = 0x00
|
156
|
+
@cpu.sbc(0x01, :imm)
|
157
|
+
@cpu.a.should == 0xff
|
158
|
+
@cpu.z.should == 0
|
159
|
+
@cpu.c.should == 0
|
160
|
+
@cpu.v.should == 0
|
161
|
+
@cpu.n.should == 1
|
162
|
+
end
|
163
|
+
it "sbc 2" do
|
164
|
+
@cpu.z = 1
|
165
|
+
@cpu.c = 1
|
166
|
+
|
167
|
+
@cpu.a = 0x80
|
168
|
+
@cpu.sbc(0x01, :imm)
|
169
|
+
@cpu.a.should == 0x7f
|
170
|
+
@cpu.z.should == 0
|
171
|
+
@cpu.c.should == 1
|
172
|
+
@cpu.v.should == 1
|
173
|
+
@cpu.n.should == 0
|
174
|
+
end
|
175
|
+
it "sbc 3" do
|
176
|
+
@cpu.z = 1
|
177
|
+
@cpu.c = 1
|
178
|
+
|
179
|
+
@cpu.a = 0x7f
|
180
|
+
@cpu.sbc(0xff, :imm)
|
181
|
+
@cpu.a.should == 0x80
|
182
|
+
@cpu.z.should == 0
|
183
|
+
@cpu.c.should == 0
|
184
|
+
@cpu.v.should == 1
|
185
|
+
@cpu.n.should == 1
|
186
|
+
end
|
187
|
+
it "sbc 4" do
|
188
|
+
@cpu.z = 1
|
189
|
+
@cpu.c = 1
|
190
|
+
|
191
|
+
@cpu.a = 0x00
|
192
|
+
@cpu.sbc(0x00, :imm)
|
193
|
+
@cpu.a.should == 0x00
|
194
|
+
@cpu.z.should == 1
|
195
|
+
@cpu.c.should == 1
|
196
|
+
@cpu.v.should == 0
|
197
|
+
@cpu.n.should == 0
|
198
|
+
end
|
199
|
+
it "sbc 5" do
|
200
|
+
@cpu.z = 1
|
201
|
+
@cpu.c = 0
|
202
|
+
|
203
|
+
@cpu.a = 0x00
|
204
|
+
@cpu.sbc(0x00, :imm)
|
205
|
+
@cpu.a.should == 0xff
|
206
|
+
@cpu.z.should == 0
|
207
|
+
@cpu.c.should == 0
|
208
|
+
@cpu.v.should == 0
|
209
|
+
@cpu.n.should == 1
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "ADC and SBC BCD" do
|
214
|
+
it "adc bcd" do
|
215
|
+
@cpu.d = 1
|
216
|
+
|
217
|
+
@cpu.a = 0x09
|
218
|
+
@cpu.clc(nil, :imp)
|
219
|
+
@cpu.adc(0x02, :imm)
|
220
|
+
@cpu.a.should == 0x11
|
221
|
+
@cpu.c.should == 0
|
222
|
+
@cpu.z.should == 0
|
223
|
+
@cpu.n.should == 0
|
224
|
+
|
225
|
+
@cpu.a = 0x49
|
226
|
+
@cpu.clc(nil, :imp)
|
227
|
+
@cpu.adc(0x49, :imm)
|
228
|
+
@cpu.a.should == 0x98
|
229
|
+
@cpu.c.should == 0
|
230
|
+
@cpu.z.should == 0
|
231
|
+
@cpu.n.should == 1
|
232
|
+
|
233
|
+
@cpu.a = 0x90
|
234
|
+
@cpu.clc(nil, :imp)
|
235
|
+
@cpu.adc(0x10, :imm)
|
236
|
+
@cpu.a.should == 0x00
|
237
|
+
@cpu.c.should == 1
|
238
|
+
@cpu.z.should == 1
|
239
|
+
@cpu.n.should == 0
|
240
|
+
|
241
|
+
@cpu.a = 0x99
|
242
|
+
@cpu.clc(nil, :imp)
|
243
|
+
@cpu.adc(0x99, :imm)
|
244
|
+
@cpu.a.should == 0x98
|
245
|
+
@cpu.c.should == 1
|
246
|
+
@cpu.z.should == 0
|
247
|
+
@cpu.n.should == 1
|
248
|
+
|
249
|
+
@cpu.a = 0x99
|
250
|
+
@cpu.clc(nil, :imp)
|
251
|
+
@cpu.adc(0x00, :imm)
|
252
|
+
@cpu.a.should == 0x99
|
253
|
+
@cpu.c.should == 0
|
254
|
+
@cpu.z.should == 0
|
255
|
+
@cpu.n.should == 1
|
256
|
+
|
257
|
+
@cpu.a = 0x99
|
258
|
+
@cpu.clc(nil, :imp)
|
259
|
+
@cpu.adc(0x01, :imm)
|
260
|
+
@cpu.a.should == 0x00
|
261
|
+
@cpu.c.should == 1
|
262
|
+
@cpu.z.should == 1
|
263
|
+
@cpu.n.should == 0
|
264
|
+
|
265
|
+
@cpu.a = 0x00
|
266
|
+
@cpu.clc(nil, :imp)
|
267
|
+
@cpu.adc(0x00, :imm)
|
268
|
+
@cpu.a.should == 0x00
|
269
|
+
@cpu.c.should == 0
|
270
|
+
@cpu.z.should == 1
|
271
|
+
@cpu.n.should == 0
|
272
|
+
|
273
|
+
@cpu.a = 0x99
|
274
|
+
@cpu.sec(nil, :imp)
|
275
|
+
@cpu.adc(0x00, :imm)
|
276
|
+
@cpu.a.should == 0x00
|
277
|
+
@cpu.c.should == 1
|
278
|
+
@cpu.z.should == 1
|
279
|
+
@cpu.n.should == 0
|
280
|
+
end
|
281
|
+
|
282
|
+
it "sbc bcd" do
|
283
|
+
@cpu.d = 1
|
284
|
+
|
285
|
+
@cpu.a = 0x11
|
286
|
+
@cpu.sec(nil, :imp)
|
287
|
+
@cpu.sbc(0x02, :imm)
|
288
|
+
@cpu.a.should == 0x09
|
289
|
+
@cpu.c.should == 1
|
290
|
+
@cpu.z.should == 0
|
291
|
+
@cpu.n.should == 0
|
292
|
+
|
293
|
+
@cpu.a = 0x01
|
294
|
+
@cpu.sec(nil, :imp)
|
295
|
+
@cpu.sbc(0x01, :imm)
|
296
|
+
@cpu.a.should == 0x00
|
297
|
+
@cpu.c.should == 1
|
298
|
+
@cpu.z.should == 1
|
299
|
+
@cpu.n.should == 0
|
300
|
+
|
301
|
+
@cpu.a = 0x98
|
302
|
+
@cpu.sec(nil, :imp)
|
303
|
+
@cpu.sbc(0x99, :imm)
|
304
|
+
@cpu.a.should == 0x99
|
305
|
+
@cpu.c.should == 0
|
306
|
+
@cpu.z.should == 0
|
307
|
+
@cpu.n.should == 1
|
308
|
+
|
309
|
+
@cpu.a = 0x00
|
310
|
+
@cpu.sec(nil, :imp)
|
311
|
+
@cpu.sbc(0x32, :imm)
|
312
|
+
@cpu.a.should == 0x68
|
313
|
+
@cpu.c.should == 0
|
314
|
+
@cpu.z.should == 0
|
315
|
+
@cpu.n.should == 0
|
316
|
+
|
317
|
+
@cpu.a = 0x00
|
318
|
+
@cpu.clc(nil, :imp)
|
319
|
+
@cpu.sbc(0x00, :imm)
|
320
|
+
@cpu.a.should == 0x99
|
321
|
+
@cpu.c.should == 0
|
322
|
+
@cpu.z.should == 0
|
323
|
+
@cpu.n.should == 1
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
describe "Cpu Instructions" do
|
328
|
+
before(:each) do
|
329
|
+
@mem = Memory.new
|
330
|
+
@cpu = Cpu.new(@mem)
|
331
|
+
end
|
332
|
+
it "adc" do
|
333
|
+
@cpu.pc = 0x0100
|
334
|
+
@cpu.a = 0x02
|
335
|
+
@cpu.adc(0x01, :imm)
|
336
|
+
@cpu.a.should == 0x03
|
337
|
+
@cpu.pc.should == 0x0102
|
338
|
+
|
339
|
+
@cpu.pc = 0x0100
|
340
|
+
@mem.set(0x1000, 0xf0)
|
341
|
+
@cpu.adc(0x1000, :abs)
|
342
|
+
@cpu.a.should == 0xf3
|
343
|
+
@cpu.pc.should == 0x0103
|
344
|
+
end
|
345
|
+
it "and" do
|
346
|
+
@cpu.pc = 0x0100
|
347
|
+
@cpu.a = 0xab
|
348
|
+
@cpu.and(0x0f, :imm)
|
349
|
+
@cpu.a.should == 0x0b
|
350
|
+
@cpu.z.should == 0
|
351
|
+
@cpu.n.should == 0
|
352
|
+
@cpu.pc.should == 0x0102
|
353
|
+
|
354
|
+
@cpu.pc = 0x0100
|
355
|
+
@cpu.a = 0xff
|
356
|
+
@mem.set(0x0010, 0x00)
|
357
|
+
@cpu.and(0x10, :zp)
|
358
|
+
@cpu.a.should == 0x00
|
359
|
+
@cpu.z.should == 1
|
360
|
+
@cpu.n.should == 0
|
361
|
+
@cpu.pc.should == 0x0102
|
362
|
+
|
363
|
+
@cpu.a = 0xff
|
364
|
+
@mem.set(0x00f0, 0xff)
|
365
|
+
@cpu.and(0xf0, :zp)
|
366
|
+
@cpu.a.should == 0xff
|
367
|
+
@cpu.z.should == 0
|
368
|
+
@cpu.n.should == 1
|
369
|
+
end
|
370
|
+
it "asl" do
|
371
|
+
@cpu.pc = 0x0100
|
372
|
+
@cpu.a = 0x01
|
373
|
+
@cpu.asl(nil, :acc)
|
374
|
+
@cpu.a.should == 0x02
|
375
|
+
@cpu.z.should == 0
|
376
|
+
@cpu.n.should == 0
|
377
|
+
@cpu.pc.should == 0x0101
|
378
|
+
|
379
|
+
@cpu.asl(nil, :acc)
|
380
|
+
@cpu.asl(nil, :acc)
|
381
|
+
@cpu.asl(nil, :acc)
|
382
|
+
@cpu.asl(nil, :acc)
|
383
|
+
@cpu.asl(nil, :acc)
|
384
|
+
@cpu.asl(nil, :acc)
|
385
|
+
@cpu.a.should == 0x80
|
386
|
+
@cpu.n.should == 1
|
387
|
+
@cpu.c.should == 0
|
388
|
+
|
389
|
+
@cpu.asl(nil, :acc)
|
390
|
+
@cpu.a.should == 0x00
|
391
|
+
@cpu.z.should == 1
|
392
|
+
@cpu.n.should == 0
|
393
|
+
@cpu.c.should == 1
|
394
|
+
|
395
|
+
@mem.set(0x2010, 0x04)
|
396
|
+
@cpu.asl(0x2010, :abs)
|
397
|
+
@mem.get(0x2010).should == 0x08
|
398
|
+
@cpu.asl(0x2010, :abs)
|
399
|
+
@mem.get(0x2010).should == 0x10
|
400
|
+
end
|
401
|
+
it "bit" do
|
402
|
+
@mem.set(0x3010, 0xf1)
|
403
|
+
@cpu.a = 0x02
|
404
|
+
@cpu.z = 0
|
405
|
+
@cpu.v = 0
|
406
|
+
@cpu.n = 0
|
407
|
+
|
408
|
+
@cpu.pc = 0x0100
|
409
|
+
@cpu.bit(0x3010, :abs)
|
410
|
+
@cpu.z.should == 1
|
411
|
+
@cpu.a.should == 0x02
|
412
|
+
@mem.get(0x3010).should == 0xf1
|
413
|
+
@cpu.v.should == 1
|
414
|
+
@cpu.n.should == 1
|
415
|
+
@cpu.pc.should == 0x0103
|
416
|
+
end
|
417
|
+
it "dec" do
|
418
|
+
@mem.set(0x4010, 0x02)
|
419
|
+
@cpu.dec(0x4010, :abs)
|
420
|
+
@mem.get(0x4010).should == 0x01
|
421
|
+
@cpu.z.should == 0
|
422
|
+
@cpu.n.should == 0
|
423
|
+
|
424
|
+
@cpu.pc = 0x0100
|
425
|
+
@cpu.dec(0x4010, :abs)
|
426
|
+
@mem.get(0x4010).should == 0x00
|
427
|
+
@cpu.z.should == 1
|
428
|
+
@cpu.n.should == 0
|
429
|
+
@cpu.pc.should == 0x0103
|
430
|
+
|
431
|
+
@cpu.dec(0x4010, :abs)
|
432
|
+
@mem.get(0x4010).should == 0xff
|
433
|
+
@cpu.z.should == 0
|
434
|
+
@cpu.n.should == 1
|
435
|
+
end
|
436
|
+
it "dex" do
|
437
|
+
@cpu.x = 0x02
|
438
|
+
@cpu.dex(nil, :imp)
|
439
|
+
@cpu.x.should == 0x01
|
440
|
+
@cpu.z.should == 0
|
441
|
+
@cpu.n.should == 0
|
442
|
+
|
443
|
+
@cpu.pc = 0x0100
|
444
|
+
@cpu.dex(nil, :imp)
|
445
|
+
@cpu.x.should == 0x00
|
446
|
+
@cpu.z.should == 1
|
447
|
+
@cpu.n.should == 0
|
448
|
+
@cpu.pc.should == 0x0101
|
449
|
+
|
450
|
+
@cpu.dex(nil, :imp)
|
451
|
+
@cpu.x.should == 0xff
|
452
|
+
@cpu.z.should == 0
|
453
|
+
@cpu.n.should == 1
|
454
|
+
end
|
455
|
+
it "dey" do
|
456
|
+
@cpu.y = 0x02
|
457
|
+
@cpu.dey(nil, :imp)
|
458
|
+
@cpu.y.should == 0x01
|
459
|
+
@cpu.z.should == 0
|
460
|
+
@cpu.n.should == 0
|
461
|
+
|
462
|
+
@cpu.pc = 0x0100
|
463
|
+
@cpu.dey(nil, :imp)
|
464
|
+
@cpu.y.should == 0x00
|
465
|
+
@cpu.z.should == 1
|
466
|
+
@cpu.n.should == 0
|
467
|
+
@cpu.pc.should == 0x0101
|
468
|
+
|
469
|
+
@cpu.dey(nil, :imp)
|
470
|
+
@cpu.y.should == 0xff
|
471
|
+
@cpu.z.should == 0
|
472
|
+
@cpu.n.should == 1
|
473
|
+
end
|
474
|
+
it "eor" do
|
475
|
+
@mem.set(0x1000, 0x05)
|
476
|
+
@cpu.a = 0x06
|
477
|
+
@cpu.eor(0x1000, :abs)
|
478
|
+
@cpu.a.should == 0x03
|
479
|
+
|
480
|
+
@cpu.pc = 0x0100
|
481
|
+
@cpu.a = 0x06
|
482
|
+
@cpu.eor(0x05, :imm)
|
483
|
+
@cpu.a.should == 0x03
|
484
|
+
@cpu.pc.should == 0x0102
|
485
|
+
|
486
|
+
@cpu.a = 0x01
|
487
|
+
@cpu.eor(0x01, :imm)
|
488
|
+
@cpu.a.should == 0x00
|
489
|
+
@cpu.z.should == 1
|
490
|
+
@cpu.n.should == 0
|
491
|
+
|
492
|
+
@cpu.eor(0x80, :imm)
|
493
|
+
@cpu.a.should == 0x80
|
494
|
+
@cpu.z.should == 0
|
495
|
+
@cpu.n.should == 1
|
496
|
+
end
|
497
|
+
it "inc" do
|
498
|
+
@mem.set(0x2000, 0x0f)
|
499
|
+
@cpu.inc(0x2000, :abs)
|
500
|
+
@mem.get(0x2000).should == 0x10
|
501
|
+
@cpu.inc(0x2000, :abs)
|
502
|
+
@mem.get(0x2000).should == 0x11
|
503
|
+
|
504
|
+
@cpu.pc = 0x0100
|
505
|
+
@mem.set(0x00f0, 0xfe)
|
506
|
+
@cpu.inc(0xf0, :zp)
|
507
|
+
@mem.get(0x00f0).should == 0xff
|
508
|
+
@cpu.z.should == 0
|
509
|
+
@cpu.n.should == 1
|
510
|
+
@cpu.pc.should == 0x0102
|
511
|
+
|
512
|
+
@cpu.inc(0xf0, :zp)
|
513
|
+
@mem.get(0x00f0).should == 0x00
|
514
|
+
@cpu.z.should == 1
|
515
|
+
@cpu.n.should == 0
|
516
|
+
|
517
|
+
@cpu.inc(0xf0, :zp)
|
518
|
+
@mem.get(0x00f0).should == 0x01
|
519
|
+
@cpu.z.should == 0
|
520
|
+
@cpu.n.should == 0
|
521
|
+
end
|
522
|
+
it "inx" do
|
523
|
+
@cpu.x = 0x00
|
524
|
+
@cpu.inx(nil, :imp)
|
525
|
+
@cpu.x.should == 0x01
|
526
|
+
@cpu.inx(nil, :imp)
|
527
|
+
@cpu.x.should == 0x02
|
528
|
+
|
529
|
+
@cpu.pc = 0x0100
|
530
|
+
@cpu.x = 0xfe
|
531
|
+
@cpu.inx(nil, :imp)
|
532
|
+
@cpu.x.should == 0xff
|
533
|
+
@cpu.z.should == 0
|
534
|
+
@cpu.n.should == 1
|
535
|
+
@cpu.pc.should == 0x0101
|
536
|
+
|
537
|
+
@cpu.inx(nil, :imp)
|
538
|
+
@cpu.x.should == 0x00
|
539
|
+
@cpu.z.should == 1
|
540
|
+
@cpu.n.should == 0
|
541
|
+
|
542
|
+
@cpu.pc = 0x0100
|
543
|
+
@cpu.x = 0x81
|
544
|
+
@cpu.inx(nil, :imp)
|
545
|
+
@cpu.pc.should == 0x0101
|
546
|
+
@cpu.x.should == 0x82
|
547
|
+
@cpu.z.should == 0
|
548
|
+
@cpu.n.should == 1
|
549
|
+
|
550
|
+
@cpu.x = 0xff
|
551
|
+
@cpu.inx(nil, :imp)
|
552
|
+
@cpu.x.should == 0x00
|
553
|
+
@cpu.z.should == 1
|
554
|
+
@cpu.n.should == 0
|
555
|
+
end
|
556
|
+
it "iny" do
|
557
|
+
@cpu.y = 0x03
|
558
|
+
@cpu.iny(nil, :imp)
|
559
|
+
@cpu.y.should == 0x04
|
560
|
+
@cpu.iny(nil, :imp)
|
561
|
+
@cpu.y.should == 0x05
|
562
|
+
|
563
|
+
@cpu.pc = 0x0100
|
564
|
+
@cpu.y = 0xfe
|
565
|
+
@cpu.iny(nil, :imp)
|
566
|
+
@cpu.y.should == 0xff
|
567
|
+
@cpu.z.should == 0
|
568
|
+
@cpu.n.should == 1
|
569
|
+
@cpu.pc.should == 0x0101
|
570
|
+
|
571
|
+
@cpu.iny(nil, :imp)
|
572
|
+
@cpu.y.should == 0x00
|
573
|
+
@cpu.z.should == 1
|
574
|
+
@cpu.n.should == 0
|
575
|
+
|
576
|
+
@cpu.y = 0x02
|
577
|
+
@cpu.iny(nil, :imp)
|
578
|
+
@cpu.y.should == 0x03
|
579
|
+
|
580
|
+
@cpu.y = 0xff
|
581
|
+
@cpu.iny(nil, :imp)
|
582
|
+
@cpu.y.should == 0x00
|
583
|
+
@cpu.z.should == 1
|
584
|
+
@cpu.n.should == 0
|
585
|
+
end
|
586
|
+
it "lsr" do
|
587
|
+
@cpu.a = 0x05
|
588
|
+
@cpu.lsr(nil, :acc)
|
589
|
+
@cpu.a.should == 0x02
|
590
|
+
@cpu.lsr(nil, :acc)
|
591
|
+
@cpu.a.should == 0x01
|
592
|
+
|
593
|
+
@cpu.pc = 0x0100
|
594
|
+
@mem.set(0x1010, 0x07)
|
595
|
+
@cpu.lsr(0x1010, :abs)
|
596
|
+
@mem.get(0x1010).should == 0x03
|
597
|
+
@cpu.pc.should == 0x0103
|
598
|
+
|
599
|
+
@cpu.a = 0x02
|
600
|
+
@cpu.lsr(nil, :acc)
|
601
|
+
@cpu.a.should == 0x01
|
602
|
+
@cpu.c.should == 0
|
603
|
+
@cpu.z.should == 0
|
604
|
+
@cpu.n.should == 0
|
605
|
+
|
606
|
+
@cpu.lsr(nil, :acc)
|
607
|
+
@cpu.a.should == 0x00
|
608
|
+
@cpu.c.should == 1
|
609
|
+
@cpu.z.should == 1
|
610
|
+
@cpu.n.should == 0
|
611
|
+
|
612
|
+
@cpu.a = 0xff
|
613
|
+
@cpu.lsr(nil, :acc)
|
614
|
+
@cpu.a.should == 0x7f
|
615
|
+
@cpu.c.should == 1
|
616
|
+
@cpu.z.should == 0
|
617
|
+
@cpu.n.should == 0
|
618
|
+
end
|
619
|
+
it "ora" do
|
620
|
+
@cpu.a = 0x05
|
621
|
+
@mem.set(0x1000, 0x06)
|
622
|
+
@cpu.ora(0x1000, :abs)
|
623
|
+
@cpu.a.should == 0x07
|
624
|
+
|
625
|
+
@cpu.pc = 0x0100
|
626
|
+
@cpu.a = 0x05
|
627
|
+
@cpu.ora(0x06, :imm)
|
628
|
+
@cpu.a.should == 0x07
|
629
|
+
@cpu.pc.should == 0x0102
|
630
|
+
|
631
|
+
@cpu.a = 0x01
|
632
|
+
@mem.set(0x0040, 0x80)
|
633
|
+
@cpu.ora(0x40, :zp)
|
634
|
+
@cpu.a.should == 0x81
|
635
|
+
@cpu.z.should == 0
|
636
|
+
@cpu.n.should == 1
|
637
|
+
|
638
|
+
@cpu.a = 0x00
|
639
|
+
@mem.set(0x0040, 0x00)
|
640
|
+
@cpu.ora(0x40, :zp)
|
641
|
+
@cpu.a.should == 0x00
|
642
|
+
@cpu.z.should == 1
|
643
|
+
@cpu.n.should == 0
|
644
|
+
end
|
645
|
+
it "rol" do
|
646
|
+
@cpu.pc = 0x0100
|
647
|
+
@cpu.a = 0x80
|
648
|
+
@cpu.rol(nil, :acc)
|
649
|
+
@cpu.a.should == 0x00
|
650
|
+
@cpu.c.should == 1
|
651
|
+
@cpu.pc.should == 0x0101
|
652
|
+
@cpu.rol(nil, :acc)
|
653
|
+
@cpu.a.should == 0x01
|
654
|
+
@cpu.c.should == 0
|
655
|
+
|
656
|
+
@mem.set(0x900, 0x40)
|
657
|
+
@cpu.rol(0x900, :abs)
|
658
|
+
@mem.get(0x900).should == 0x80
|
659
|
+
@cpu.c.should == 0
|
660
|
+
@cpu.z.should == 0
|
661
|
+
@cpu.n.should == 1
|
662
|
+
@cpu.rol(0x900, :abs)
|
663
|
+
@mem.get(0x900).should == 0x00
|
664
|
+
@cpu.c.should == 1
|
665
|
+
@cpu.z.should == 1
|
666
|
+
@cpu.n.should == 0
|
667
|
+
end
|
668
|
+
it "ror" do
|
669
|
+
@cpu.pc = 0x0100
|
670
|
+
@cpu.a = 0x01
|
671
|
+
@cpu.ror(nil, :acc)
|
672
|
+
@cpu.pc.should == 0x0101
|
673
|
+
@cpu.a.should == 0x00
|
674
|
+
@cpu.z.should == 1
|
675
|
+
@cpu.c.should == 1
|
676
|
+
@cpu.n.should == 0
|
677
|
+
@cpu.ror(nil, :acc)
|
678
|
+
@cpu.a.should == 0x80
|
679
|
+
@cpu.z.should == 0
|
680
|
+
@cpu.c.should == 0
|
681
|
+
@cpu.n.should == 1
|
682
|
+
|
683
|
+
@cpu.c = 1
|
684
|
+
@mem.set(0x900, 0x80)
|
685
|
+
@cpu.ror(0x900, :abs)
|
686
|
+
@mem.get(0x900).should == 0xc0
|
687
|
+
@cpu.c.should == 0
|
688
|
+
@cpu.z.should == 0
|
689
|
+
@cpu.n.should == 1
|
690
|
+
@cpu.ror(0x900, :abs)
|
691
|
+
@mem.get(0x900).should == 0x60
|
692
|
+
@cpu.c.should == 0
|
693
|
+
@cpu.z.should == 0
|
694
|
+
@cpu.n.should == 0
|
695
|
+
end
|
696
|
+
it "sbc" do
|
697
|
+
@cpu.pc = 0x0100
|
698
|
+
@cpu.c = 1
|
699
|
+
@cpu.a = 0x10
|
700
|
+
@mem.set(0x100, 0x0a)
|
701
|
+
@cpu.sbc(0x100, :abs)
|
702
|
+
@cpu.a.should == 0x06
|
703
|
+
@cpu.pc.should == 0x0103
|
704
|
+
|
705
|
+
@cpu.c = 0
|
706
|
+
@cpu.a = 0x10
|
707
|
+
@cpu.sbc(0x0a, :imm)
|
708
|
+
@cpu.a.should == 0x05
|
709
|
+
end
|
710
|
+
it "nop" do
|
711
|
+
@cpu.pc = 0x0100
|
712
|
+
@cpu.nop(nil, :imp)
|
713
|
+
@cpu.pc.should == 0x0101
|
714
|
+
end
|
715
|
+
it "sec" do
|
716
|
+
@cpu.pc = 0x0100
|
717
|
+
@cpu.c = 0
|
718
|
+
@cpu.sec(nil, :imp)
|
719
|
+
@cpu.c.should == 1
|
720
|
+
@cpu.pc.should == 0x0101
|
721
|
+
end
|
722
|
+
it "sed" do
|
723
|
+
@cpu.pc = 0x0100
|
724
|
+
@cpu.d = 0
|
725
|
+
@cpu.sed(nil, :imp)
|
726
|
+
@cpu.d.should == 1
|
727
|
+
@cpu.pc.should == 0x0101
|
728
|
+
end
|
729
|
+
it "sei" do
|
730
|
+
@cpu.pc = 0x0100
|
731
|
+
@cpu.i = 0
|
732
|
+
@cpu.sei(nil, :imp)
|
733
|
+
@cpu.i.should == 1
|
734
|
+
@cpu.pc.should == 0x0101
|
735
|
+
end
|
736
|
+
it "bcc" do
|
737
|
+
@cpu.pc = 0x1000
|
738
|
+
@cpu.c = 1
|
739
|
+
@cpu.bcc(0x10, :rel)
|
740
|
+
@cpu.pc.should == 0x1002
|
741
|
+
|
742
|
+
@cpu.pc = 0x1000
|
743
|
+
@cpu.c = 0
|
744
|
+
@cpu.bcc(0x10, :rel)
|
745
|
+
@cpu.pc.should == 0x1012
|
746
|
+
end
|
747
|
+
it "bcs" do
|
748
|
+
@cpu.pc = 0x1000
|
749
|
+
@cpu.c = 0
|
750
|
+
@cpu.bcs(0x10, :rel)
|
751
|
+
@cpu.pc.should == 0x1002
|
752
|
+
|
753
|
+
@cpu.pc = 0x1000
|
754
|
+
@cpu.c = 1
|
755
|
+
@cpu.bcs(0x10, :rel)
|
756
|
+
@cpu.pc.should == 0x1012
|
757
|
+
end
|
758
|
+
it "beq" do
|
759
|
+
@cpu.pc = 0x1000
|
760
|
+
@cpu.z = 0
|
761
|
+
@cpu.beq(0x10, :rel)
|
762
|
+
@cpu.pc.should == 0x1002
|
763
|
+
|
764
|
+
@cpu.pc = 0x1000
|
765
|
+
@cpu.z = 1
|
766
|
+
@cpu.beq(0x10, :rel)
|
767
|
+
@cpu.pc.should == 0x1012
|
768
|
+
end
|
769
|
+
it "bmi" do
|
770
|
+
@cpu.pc = 0x1000
|
771
|
+
@cpu.n = 0
|
772
|
+
@cpu.bmi(0x10, :rel)
|
773
|
+
@cpu.pc.should == 0x1002
|
774
|
+
|
775
|
+
@cpu.pc = 0x1000
|
776
|
+
@cpu.n = 1
|
777
|
+
@cpu.bmi(0x10, :rel)
|
778
|
+
@cpu.pc.should == 0x1012
|
779
|
+
end
|
780
|
+
it "bne" do
|
781
|
+
@cpu.pc = 0x1000
|
782
|
+
@cpu.z = 1
|
783
|
+
@cpu.bne(0x10, :rel)
|
784
|
+
@cpu.pc.should == 0x1002
|
785
|
+
|
786
|
+
@cpu.pc = 0x1000
|
787
|
+
@cpu.z = 0
|
788
|
+
@cpu.bne(0x10, :rel)
|
789
|
+
@cpu.pc.should == 0x1012
|
790
|
+
end
|
791
|
+
it "bpl" do
|
792
|
+
@cpu.pc = 0x1000
|
793
|
+
@cpu.n = 1
|
794
|
+
@cpu.bpl(0x10, :rel)
|
795
|
+
@cpu.pc.should == 0x1002
|
796
|
+
|
797
|
+
@cpu.pc = 0x1000
|
798
|
+
@cpu.n = 0
|
799
|
+
@cpu.bpl(0x10, :rel)
|
800
|
+
@cpu.pc.should == 0x1012
|
801
|
+
end
|
802
|
+
it "bvc" do
|
803
|
+
@cpu.pc = 0x1000
|
804
|
+
@cpu.v = 1
|
805
|
+
@cpu.bvc(0x10, :rel)
|
806
|
+
@cpu.pc.should == 0x1002
|
807
|
+
|
808
|
+
@cpu.pc = 0x1000
|
809
|
+
@cpu.v = 0
|
810
|
+
@cpu.bvc(0x10, :rel)
|
811
|
+
@cpu.pc.should == 0x1012
|
812
|
+
end
|
813
|
+
it "bvs" do
|
814
|
+
@cpu.pc = 0x1000
|
815
|
+
@cpu.v = 0
|
816
|
+
@cpu.bvs(0x10, :rel)
|
817
|
+
@cpu.pc.should == 0x1002
|
818
|
+
|
819
|
+
@cpu.pc = 0x1000
|
820
|
+
@cpu.v = 1
|
821
|
+
@cpu.bvs(0x10, :rel)
|
822
|
+
@cpu.pc.should == 0x1012
|
823
|
+
end
|
824
|
+
it "brk" do
|
825
|
+
@cpu.c = 1
|
826
|
+
@cpu.s = 0xff
|
827
|
+
@cpu.pc = 0xabcd
|
828
|
+
@mem.set(0xfffe, 0x40)
|
829
|
+
@mem.set(0xffff, 0x80)
|
830
|
+
@cpu.brk(nil, :imp)
|
831
|
+
@cpu.pc.should == 0x8040
|
832
|
+
@cpu.s.should == 0xfc
|
833
|
+
@mem.get(0x01ff).should == 0xab
|
834
|
+
@mem.get(0x01fe).should == 0xcd
|
835
|
+
@mem.get(0x01fd).should == 0b00110001
|
836
|
+
end
|
837
|
+
it "rti" do
|
838
|
+
@cpu.s = 0xfc
|
839
|
+
@mem.set(0x01fd, 0b10100001)
|
840
|
+
@mem.set(0x01fe, 0x80)
|
841
|
+
@mem.set(0x01ff, 0x40)
|
842
|
+
@cpu.rti(nil, :imp)
|
843
|
+
@cpu.c.should == 1
|
844
|
+
@cpu.n.should == 1
|
845
|
+
@cpu.v.should == 0
|
846
|
+
@cpu.pc.should == 0x8040
|
847
|
+
end
|
848
|
+
it "clc" do
|
849
|
+
@cpu.pc = 0x0100
|
850
|
+
@cpu.c = 1
|
851
|
+
@cpu.clc(nil, :imp)
|
852
|
+
@cpu.c.should == 0
|
853
|
+
@cpu.pc.should == 0x0101
|
854
|
+
|
855
|
+
@cpu.c = 0
|
856
|
+
@cpu.clc(nil, :imp)
|
857
|
+
@cpu.c.should == 0
|
858
|
+
end
|
859
|
+
it "cld" do
|
860
|
+
@cpu.pc = 0x0100
|
861
|
+
@cpu.d = 1
|
862
|
+
@cpu.cld(nil, :imp)
|
863
|
+
@cpu.d.should == 0
|
864
|
+
@cpu.pc.should == 0x0101
|
865
|
+
|
866
|
+
@cpu.d = 0
|
867
|
+
@cpu.cld(nil, :imp)
|
868
|
+
@cpu.d.should == 0
|
869
|
+
end
|
870
|
+
it "cli" do
|
871
|
+
@cpu.pc = 0x0100
|
872
|
+
@cpu.i = 1
|
873
|
+
@cpu.cli(nil, :imp)
|
874
|
+
@cpu.i.should == 0
|
875
|
+
@cpu.pc.should == 0x0101
|
876
|
+
|
877
|
+
@cpu.i = 0
|
878
|
+
@cpu.cli(nil, :imp)
|
879
|
+
@cpu.i.should == 0
|
880
|
+
end
|
881
|
+
it "clv" do
|
882
|
+
@cpu.pc = 0x0100
|
883
|
+
@cpu.v = 1
|
884
|
+
@cpu.clv(nil, :imp)
|
885
|
+
@cpu.v.should == 0
|
886
|
+
@cpu.pc.should == 0x0101
|
887
|
+
|
888
|
+
@cpu.v = 0
|
889
|
+
@cpu.clv(nil, :imp)
|
890
|
+
@cpu.v.should == 0
|
891
|
+
end
|
892
|
+
it "cmp" do
|
893
|
+
@mem.set(0x1000, 0x10)
|
894
|
+
@cpu.a = 0x20
|
895
|
+
@cpu.c = 0
|
896
|
+
@cpu.z = 1
|
897
|
+
@cpu.cmp(0x1000, :abs)
|
898
|
+
@cpu.a.should == 0x20
|
899
|
+
@cpu.c.should == 1
|
900
|
+
@cpu.z.should == 0
|
901
|
+
@cpu.n.should == 0
|
902
|
+
|
903
|
+
@cpu.pc = 0x0100
|
904
|
+
@cpu.a = 0x10
|
905
|
+
@cpu.c = 0
|
906
|
+
@cpu.z = 0
|
907
|
+
@cpu.cmp(0x10, :imm)
|
908
|
+
@cpu.pc.should == 0x0102
|
909
|
+
@cpu.a.should == 0x10
|
910
|
+
@cpu.c.should == 1
|
911
|
+
@cpu.z.should == 1
|
912
|
+
@cpu.n.should == 0
|
913
|
+
|
914
|
+
@cpu.a = 0x90
|
915
|
+
@cpu.cmp(0x10, :imm)
|
916
|
+
@cpu.a.should == 0x90
|
917
|
+
@cpu.c.should == 1
|
918
|
+
@cpu.z.should == 0
|
919
|
+
@cpu.n.should == 1
|
920
|
+
end
|
921
|
+
it "cpx" do
|
922
|
+
@mem.set(0x1000, 0x10)
|
923
|
+
@cpu.x = 0x20
|
924
|
+
@cpu.c = 0
|
925
|
+
@cpu.z = 1
|
926
|
+
@cpu.cpx(0x1000, :abs)
|
927
|
+
@cpu.x.should == 0x20
|
928
|
+
@cpu.c.should == 1
|
929
|
+
@cpu.z.should == 0
|
930
|
+
|
931
|
+
@cpu.x = 0x10
|
932
|
+
@cpu.c = 0
|
933
|
+
@cpu.z = 0
|
934
|
+
@cpu.pc = 0x0100
|
935
|
+
@cpu.cpx(0x10, :imm)
|
936
|
+
@cpu.pc.should == 0x0102
|
937
|
+
@cpu.x.should == 0x10
|
938
|
+
@cpu.c.should == 1
|
939
|
+
@cpu.z.should == 1
|
940
|
+
|
941
|
+
@cpu.x = 0x00
|
942
|
+
@cpu.cpx(0x01, :imm)
|
943
|
+
@cpu.x.should == 0x00
|
944
|
+
@cpu.c.should == 0
|
945
|
+
@cpu.z.should == 0
|
946
|
+
@cpu.n.should == 1
|
947
|
+
end
|
948
|
+
it "cpy" do
|
949
|
+
@mem.set(0x1000, 0x10)
|
950
|
+
@cpu.y = 0x20
|
951
|
+
@cpu.c = 0
|
952
|
+
@cpu.z = 1
|
953
|
+
@cpu.cpy(0x1000, :abs)
|
954
|
+
@cpu.y.should == 0x20
|
955
|
+
@cpu.c.should == 1
|
956
|
+
@cpu.z.should == 0
|
957
|
+
|
958
|
+
@cpu.y = 0x10
|
959
|
+
@cpu.c = 0
|
960
|
+
@cpu.z = 0
|
961
|
+
@cpu.pc = 0x0100
|
962
|
+
@cpu.cpy(0x10, :imm)
|
963
|
+
@cpu.pc.should == 0x0102
|
964
|
+
@cpu.y.should == 0x10
|
965
|
+
@cpu.c.should == 1
|
966
|
+
@cpu.z.should == 1
|
967
|
+
|
968
|
+
@cpu.y = 0x00
|
969
|
+
@cpu.cpy(0x00, :imm)
|
970
|
+
@cpu.y.should == 0x00
|
971
|
+
@cpu.c.should == 1
|
972
|
+
@cpu.z.should == 1
|
973
|
+
@cpu.n.should == 0
|
974
|
+
|
975
|
+
@cpu.cpy(0x01, :imm)
|
976
|
+
@cpu.c.should == 0
|
977
|
+
@cpu.z.should == 0
|
978
|
+
@cpu.n.should == 1
|
979
|
+
end
|
980
|
+
it "jmp" do
|
981
|
+
@cpu.pc = 0x1000
|
982
|
+
@cpu.jmp(0x2000, :abs)
|
983
|
+
@cpu.pc.should == 0x2000
|
984
|
+
|
985
|
+
@cpu.pc = 0x1000
|
986
|
+
@mem.set( 0x2000, 0x00 )
|
987
|
+
@mem.set( 0x2001, 0x11 )
|
988
|
+
@cpu.jmp(0x2000, :ind)
|
989
|
+
@cpu.pc.should == 0x1100
|
990
|
+
end
|
991
|
+
it "jsr" do
|
992
|
+
@cpu.s = 0xff
|
993
|
+
@cpu.pc = 0x0600
|
994
|
+
@cpu.jsr(0x1000, :abs)
|
995
|
+
@mem.get(0x01ff).should == 0x06
|
996
|
+
@mem.get(0x01fe).should == 0x02
|
997
|
+
@cpu.pc.should == 0x1000
|
998
|
+
end
|
999
|
+
it "rts" do
|
1000
|
+
@cpu.s = 0xfd
|
1001
|
+
@mem.set(0x01ff, 0xcd)
|
1002
|
+
@mem.set(0x01fe, 0xab)
|
1003
|
+
@cpu.rts(nil, :imp)
|
1004
|
+
@cpu.pc.should == 0xabce
|
1005
|
+
end
|
1006
|
+
it "lda" do
|
1007
|
+
@cpu.a = 0x66
|
1008
|
+
@cpu.lda(0x33, :imm)
|
1009
|
+
@cpu.a.should == 0x33
|
1010
|
+
|
1011
|
+
@cpu.pc = 0x0100
|
1012
|
+
@cpu.a = 0x66
|
1013
|
+
@mem.set( 0x1000, 0x44 )
|
1014
|
+
@cpu.lda(0x1000, :abs)
|
1015
|
+
@cpu.a.should == 0x44
|
1016
|
+
@cpu.pc.should == 0x0103
|
1017
|
+
|
1018
|
+
@cpu.lda(0x00, :imm)
|
1019
|
+
@cpu.z.should == 1
|
1020
|
+
@cpu.n.should == 0
|
1021
|
+
|
1022
|
+
@cpu.lda(0xff, :imm)
|
1023
|
+
@cpu.z.should == 0
|
1024
|
+
@cpu.n.should == 1
|
1025
|
+
end
|
1026
|
+
it "ldx" do
|
1027
|
+
@cpu.x = 0x66
|
1028
|
+
@cpu.ldx(0x33, :imm)
|
1029
|
+
@cpu.x.should == 0x33
|
1030
|
+
|
1031
|
+
@cpu.x = 0x66
|
1032
|
+
@mem.set( 0x1000, 0x44 )
|
1033
|
+
@cpu.ldx(0x1000, :abs)
|
1034
|
+
@cpu.x.should == 0x44
|
1035
|
+
|
1036
|
+
@cpu.pc = 0x0100
|
1037
|
+
@cpu.ldx(0x00, :imm)
|
1038
|
+
@cpu.z.should == 1
|
1039
|
+
@cpu.n.should == 0
|
1040
|
+
@cpu.pc.should == 0x0102
|
1041
|
+
|
1042
|
+
@cpu.ldx(0xff, :imm)
|
1043
|
+
@cpu.z.should == 0
|
1044
|
+
@cpu.n.should == 1
|
1045
|
+
end
|
1046
|
+
it "ldy" do
|
1047
|
+
@cpu.y = 0x66
|
1048
|
+
@cpu.ldy(0x33, :imm)
|
1049
|
+
@cpu.y.should == 0x33
|
1050
|
+
|
1051
|
+
@cpu.y = 0x66
|
1052
|
+
@mem.set( 0x1000, 0x44 )
|
1053
|
+
@cpu.ldy(0x1000, :abs)
|
1054
|
+
@cpu.y.should == 0x44
|
1055
|
+
|
1056
|
+
@cpu.pc = 0x0100
|
1057
|
+
@cpu.ldy(0x00, :imm)
|
1058
|
+
@cpu.z.should == 1
|
1059
|
+
@cpu.n.should == 0
|
1060
|
+
@cpu.pc.should == 0x0102
|
1061
|
+
|
1062
|
+
@cpu.ldy(0xff, :imm)
|
1063
|
+
@cpu.z.should == 0
|
1064
|
+
@cpu.n.should == 1
|
1065
|
+
end
|
1066
|
+
it "pha" do
|
1067
|
+
@cpu.pc = 0x0100
|
1068
|
+
@cpu.a = 0x33
|
1069
|
+
@cpu.s = 0xff
|
1070
|
+
@cpu.pha(nil, :imp)
|
1071
|
+
@cpu.s.should == 0xfe
|
1072
|
+
@mem.get(0x01ff).should == 0x33
|
1073
|
+
@cpu.pc.should == 0x0101
|
1074
|
+
end
|
1075
|
+
it "pla" do
|
1076
|
+
@cpu.a = 0x66
|
1077
|
+
@cpu.s = 0xfe
|
1078
|
+
@mem.set(0x01ff, 0x34)
|
1079
|
+
@cpu.pla(nil, :imp)
|
1080
|
+
@cpu.a.should == 0x34
|
1081
|
+
@cpu.s.should == 0xff
|
1082
|
+
@cpu.z.should == 0
|
1083
|
+
@cpu.n.should == 0
|
1084
|
+
|
1085
|
+
@cpu.pc = 0x0100
|
1086
|
+
@cpu.s = 0xfe
|
1087
|
+
@mem.set(0x01ff, 0x00)
|
1088
|
+
@cpu.pla(nil, :imp)
|
1089
|
+
@cpu.z.should == 1
|
1090
|
+
@cpu.n.should == 0
|
1091
|
+
@cpu.pc.should == 0x0101
|
1092
|
+
|
1093
|
+
@cpu.s = 0xfe
|
1094
|
+
@mem.set(0x01ff, 0x80)
|
1095
|
+
@cpu.pla(nil, :imp)
|
1096
|
+
@cpu.z.should == 0
|
1097
|
+
@cpu.n.should == 1
|
1098
|
+
end
|
1099
|
+
it "php" do
|
1100
|
+
@cpu.c = 1
|
1101
|
+
@cpu.z = 0
|
1102
|
+
@cpu.i = 1
|
1103
|
+
@cpu.d = 0
|
1104
|
+
@cpu.b = 1
|
1105
|
+
#bit 5 1
|
1106
|
+
@cpu.v = 0
|
1107
|
+
@cpu.n = 1
|
1108
|
+
|
1109
|
+
@cpu.pc = 0x0100
|
1110
|
+
@cpu.s = 0xff
|
1111
|
+
@cpu.php(nil, :imp)
|
1112
|
+
@cpu.s.should == 0xfe
|
1113
|
+
@mem.get( 0x01ff ).should == 0b10110101
|
1114
|
+
@cpu.pc.should == 0x0101
|
1115
|
+
|
1116
|
+
@cpu.c = 0
|
1117
|
+
@cpu.z = 1
|
1118
|
+
@cpu.i = 0
|
1119
|
+
@cpu.d = 1
|
1120
|
+
@cpu.b = 0
|
1121
|
+
#bit 5 1
|
1122
|
+
@cpu.v = 1
|
1123
|
+
@cpu.n = 0
|
1124
|
+
|
1125
|
+
@cpu.s = 0xfe
|
1126
|
+
@cpu.php(nil, :imp)
|
1127
|
+
@cpu.s.should == 0xfd
|
1128
|
+
@mem.get( 0x01fe ).should == 0b01101010
|
1129
|
+
end
|
1130
|
+
it "plp" do
|
1131
|
+
@cpu.c = 1
|
1132
|
+
@cpu.z = 0
|
1133
|
+
@cpu.i = 1
|
1134
|
+
@cpu.d = 0
|
1135
|
+
@cpu.b = 1
|
1136
|
+
#bit 5 1
|
1137
|
+
@cpu.v = 0
|
1138
|
+
@cpu.n = 1
|
1139
|
+
|
1140
|
+
@cpu.pc = 0x0100
|
1141
|
+
@mem.set(0x01ff, 0b01101010)
|
1142
|
+
@cpu.s = 0xfe
|
1143
|
+
@cpu.plp(nil, :imp)
|
1144
|
+
@cpu.pc.should == 0x0101
|
1145
|
+
|
1146
|
+
@cpu.c.should == 0
|
1147
|
+
@cpu.z.should == 1
|
1148
|
+
@cpu.i.should == 0
|
1149
|
+
@cpu.d.should == 1
|
1150
|
+
@cpu.b.should == 0
|
1151
|
+
#bit 5 1
|
1152
|
+
@cpu.v.should == 1
|
1153
|
+
@cpu.n.should == 0
|
1154
|
+
end
|
1155
|
+
it "sta" do
|
1156
|
+
@cpu.pc = 0x0100
|
1157
|
+
@cpu.a = 0xfa
|
1158
|
+
@mem.set( 0x1000, 0xaf )
|
1159
|
+
@cpu.sta(0x1000, :abs)
|
1160
|
+
@mem.get( 0x1000 ).should == 0xfa
|
1161
|
+
@cpu.pc.should == 0x0103
|
1162
|
+
end
|
1163
|
+
it "stx" do
|
1164
|
+
@cpu.pc = 0x0100
|
1165
|
+
@cpu.x = 0xfa
|
1166
|
+
@mem.set( 0x1000, 0xaf )
|
1167
|
+
@cpu.stx(0x1000, :abs)
|
1168
|
+
@mem.get( 0x1000 ).should == 0xfa
|
1169
|
+
@cpu.pc.should == 0x0103
|
1170
|
+
end
|
1171
|
+
it "sty" do
|
1172
|
+
@cpu.pc = 0x0100
|
1173
|
+
@cpu.y = 0xfa
|
1174
|
+
@mem.set( 0x1000, 0xaf )
|
1175
|
+
@cpu.sty(0x1000, :abs)
|
1176
|
+
@mem.get( 0x1000 ).should == 0xfa
|
1177
|
+
@cpu.pc.should == 0x0103
|
1178
|
+
end
|
1179
|
+
it "tax" do
|
1180
|
+
@cpu.x = 0xea
|
1181
|
+
@cpu.a = 0xbd
|
1182
|
+
@cpu.tax(nil, :imp)
|
1183
|
+
@cpu.a.should == 0xbd
|
1184
|
+
@cpu.x.should == 0xbd
|
1185
|
+
|
1186
|
+
@cpu.pc = 0x0100
|
1187
|
+
@cpu.a = 0x00
|
1188
|
+
@cpu.tax(nil, :imp)
|
1189
|
+
@cpu.z.should == 1
|
1190
|
+
@cpu.n.should == 0
|
1191
|
+
@cpu.pc.should == 0x0101
|
1192
|
+
|
1193
|
+
@cpu.a = 0x80
|
1194
|
+
@cpu.tax(nil, :imp)
|
1195
|
+
@cpu.z.should == 0
|
1196
|
+
@cpu.n.should == 1
|
1197
|
+
end
|
1198
|
+
it "tay" do
|
1199
|
+
@cpu.y = 0xea
|
1200
|
+
@cpu.a = 0xbd
|
1201
|
+
@cpu.tay(nil, :imp)
|
1202
|
+
@cpu.a.should == 0xbd
|
1203
|
+
@cpu.y.should == 0xbd
|
1204
|
+
|
1205
|
+
@cpu.pc = 0x0100
|
1206
|
+
@cpu.a = 0x00
|
1207
|
+
@cpu.tay(nil, :imp)
|
1208
|
+
@cpu.z.should == 1
|
1209
|
+
@cpu.n.should == 0
|
1210
|
+
@cpu.pc.should == 0x0101
|
1211
|
+
|
1212
|
+
@cpu.a = 0x80
|
1213
|
+
@cpu.tay(nil, :imp)
|
1214
|
+
@cpu.z.should == 0
|
1215
|
+
@cpu.n.should == 1
|
1216
|
+
end
|
1217
|
+
it "tsx" do
|
1218
|
+
@cpu.x = 0xea
|
1219
|
+
@cpu.s = 0xbd
|
1220
|
+
@cpu.tsx(nil, :imp)
|
1221
|
+
@cpu.s.should == 0xbd
|
1222
|
+
@cpu.x.should == 0xbd
|
1223
|
+
|
1224
|
+
@cpu.pc = 0x0100
|
1225
|
+
@cpu.s = 0x00
|
1226
|
+
@cpu.tsx(nil, :imp)
|
1227
|
+
@cpu.z.should == 1
|
1228
|
+
@cpu.n.should == 0
|
1229
|
+
@cpu.pc.should == 0x0101
|
1230
|
+
|
1231
|
+
@cpu.s = 0x80
|
1232
|
+
@cpu.tsx(nil, :imp)
|
1233
|
+
@cpu.z.should == 0
|
1234
|
+
@cpu.n.should == 1
|
1235
|
+
end
|
1236
|
+
it "txa" do
|
1237
|
+
@cpu.a = 0xea
|
1238
|
+
@cpu.x = 0xbd
|
1239
|
+
@cpu.txa(nil, :imp)
|
1240
|
+
@cpu.x.should == 0xbd
|
1241
|
+
@cpu.a.should == 0xbd
|
1242
|
+
|
1243
|
+
@cpu.pc = 0x0100
|
1244
|
+
@cpu.x = 0x00
|
1245
|
+
@cpu.txa(nil, :imp)
|
1246
|
+
@cpu.z.should == 1
|
1247
|
+
@cpu.n.should == 0
|
1248
|
+
@cpu.pc.should == 0x0101
|
1249
|
+
|
1250
|
+
@cpu.x = 0x80
|
1251
|
+
@cpu.txa(nil, :imp)
|
1252
|
+
@cpu.z.should == 0
|
1253
|
+
@cpu.n.should == 1
|
1254
|
+
end
|
1255
|
+
it "txs" do
|
1256
|
+
@cpu.pc = 0x0100
|
1257
|
+
@cpu.s = 0xea
|
1258
|
+
@cpu.x = 0xbd
|
1259
|
+
@cpu.txs(nil, :imp)
|
1260
|
+
@cpu.x.should == 0xbd
|
1261
|
+
@cpu.s.should == 0xbd
|
1262
|
+
@cpu.pc.should == 0x0101
|
1263
|
+
end
|
1264
|
+
it "tya" do
|
1265
|
+
@cpu.a = 0xea
|
1266
|
+
@cpu.y = 0xbd
|
1267
|
+
@cpu.tya(nil, :imp)
|
1268
|
+
@cpu.y.should == 0xbd
|
1269
|
+
@cpu.a.should == 0xbd
|
1270
|
+
|
1271
|
+
@cpu.pc = 0x0100
|
1272
|
+
@cpu.y = 0x00
|
1273
|
+
@cpu.tya(nil, :imp)
|
1274
|
+
@cpu.z.should == 1
|
1275
|
+
@cpu.n.should == 0
|
1276
|
+
@cpu.pc.should == 0x0101
|
1277
|
+
|
1278
|
+
@cpu.y = 0x80
|
1279
|
+
@cpu.tya(nil, :imp)
|
1280
|
+
@cpu.z.should == 0
|
1281
|
+
@cpu.n.should == 1
|
1282
|
+
end
|
1283
|
+
end
|
1284
|
+
end
|