r6502 0.0.1 → 0.0.2

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.
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib',__FILE__)
3
+ require 'r6502'
4
+ require 'pry'
5
+
6
+ @mem = R6502::Memory.new
7
+ @asm = R6502::Assembler.new(@mem)
8
+ @cpu = R6502::Cpu.new(@mem)
9
+ @cpu.pc = 0x0400
10
+
11
+ code = IO.read('6502_functional_test.bin')
12
+ raise 'too much code' if code.bytesize > 2**16
13
+
14
+ @mem.instance_variable_set( :@mem_array, code.unpack('C*') )
15
+
16
+ begin
17
+ last_pc = @cpu.pc
18
+ @cpu.step
19
+ end while last_pc != @cpu.pc #run it until we hit a `jmp *` loop
20
+
21
+ puts "loop at pc = 0x#{@cpu.pc.to_s(16)}"
22
+
23
+ binding.pry
@@ -30,6 +30,8 @@ module R6502
30
30
  case mode
31
31
  when :imp
32
32
  nil
33
+ when :acc
34
+ nil
33
35
  when :imm
34
36
  sec_word
35
37
  when :zp
@@ -58,7 +60,7 @@ module R6502
58
60
  lb = @mem.get( 0xff & sec_word )
59
61
  hb = @mem.get( 0xff & sec_word + 1)
60
62
  addr = (hb<<8) + lb
61
- @mem.get( addr + @y )
63
+ addr + @y
62
64
  end
63
65
  end
64
66
  def inc_pc_by_mode(mode)
@@ -330,14 +330,7 @@ module R6502
330
330
  inc_pc_by_mode(mode)
331
331
  end
332
332
  def jmp(arg, mode)
333
- case mode
334
- when :abs
335
- @pc = arg
336
- else #indirect
337
- lsb = @mem.get( arg )
338
- msb = @mem.get( arg + 1)
339
- @pc = lsb + msb<<8
340
- end
333
+ @pc = arg
341
334
  end
342
335
  def lda(arg, mode)
343
336
  case mode
@@ -390,8 +383,8 @@ module R6502
390
383
  addr = 0x0100 + (0xff & @s)
391
384
  val = @n #bit 7
392
385
  val = (val<<1) + @v #bit 6
393
- val = (val<<1) + 1 #bit 5
394
- val = (val<<1) + @b #bit 4
386
+ val = (val<<1) + 1 #bit 5, reserved
387
+ val = (val<<1) + 1 #bit 4, break
395
388
  val = (val<<1) + @d #bit 3
396
389
  val = (val<<1) + @i #bit 2
397
390
  val = (val<<1) + @z #bit 1
@@ -412,6 +405,7 @@ module R6502
412
405
  # bit 5
413
406
  @v = 0x1 & (val>>6)
414
407
  @n = 0x1 & (val>>7)
408
+ @s += 1
415
409
  inc_pc_by_mode(mode)
416
410
  end
417
411
  def sta(arg, mode)
@@ -500,17 +494,17 @@ module R6502
500
494
  @pc = 0xffff&((hi<<8) + lo)
501
495
  end
502
496
  def jsr( arg, mode )
503
- @mem.set(0x0100 + @s, @pc>>8)
497
+ @mem.set(0x0100 + @s, (@pc+2)>>8)
504
498
  @s -= 1
505
- @mem.set(0x0100 + @s, (0xff&@pc) + 2)
499
+ @mem.set(0x0100 + @s, 0xff&(@pc+2))
506
500
  @s -= 1
507
501
  @pc = arg
508
502
  end
509
503
  def rts( arg, mode )
510
- hi = @mem.get(0x0100 + @s + 1)
511
- @s += 1
512
504
  lo = @mem.get(0x0100 + @s + 1)
513
505
  @s += 1
506
+ hi = @mem.get(0x0100 + @s + 1)
507
+ @s += 1
514
508
  @pc = 0xffff&((hi<<8) + lo + 1)
515
509
  end
516
510
  end
@@ -123,7 +123,7 @@ module R6502
123
123
  0xac => [:ldy, :abs],
124
124
  0xbc => [:ldy, :absx],
125
125
  #lsr,
126
- 0x4a => [:lsr, :imp],
126
+ 0x4a => [:lsr, :acc],
127
127
  0x46 => [:lsr, :zp],
128
128
  0x56 => [:lsr, :zpx],
129
129
  0x4e => [:lsr, :abs],
@@ -156,13 +156,13 @@ module R6502
156
156
  #iny,
157
157
  0xc8 => [:iny, :imp],
158
158
  #rol,
159
- 0x2a => [:rol, :imp],
159
+ 0x2a => [:rol, :acc],
160
160
  0x26 => [:rol, :zp],
161
161
  0x36 => [:rol, :zpx],
162
162
  0x2e => [:rol, :abs],
163
163
  0x3e => [:rol, :absx],
164
164
  #ror,
165
- 0x6a => [:ror, :imp],
165
+ 0x6a => [:ror, :acc],
166
166
  0x66 => [:ror, :zp],
167
167
  0x76 => [:ror, :zpx],
168
168
  0x6e => [:ror, :abs],
data/r6502.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'r6502'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.date = '2014-04-09'
5
5
  s.summary = "6502 simulator and assembler"
6
6
  s.description = "6502 simulator and assembler, work-in-progress, not cycle-accurate, etc."
@@ -69,7 +69,7 @@ module R6502
69
69
  @cpu.mem.set( 0x10, 0xa0 )
70
70
  @cpu.mem.set( 0x11, 0xb0 )
71
71
  @cpu.mem.set( 0xb0a4, 0xcd )
72
- @cpu.decode_arg(:indy, 0x10, 0x66).should == 0xcd
72
+ @cpu.decode_arg(:indy, 0x10, 0x66).should == 0xb0a4
73
73
  end
74
74
  it "executes a single instr. from PC value and mem" do
75
75
  @cpu.pc = 0x2000
@@ -983,10 +983,8 @@ module R6502
983
983
  @cpu.pc.should == 0x2000
984
984
 
985
985
  @cpu.pc = 0x1000
986
- @mem.set( 0x2000, 0x00 )
987
- @mem.set( 0x2001, 0x11 )
988
986
  @cpu.jmp(0x2000, :ind)
989
- @cpu.pc.should == 0x1100
987
+ @cpu.pc.should == 0x2000
990
988
  end
991
989
  it "jsr" do
992
990
  @cpu.s = 0xff
@@ -995,11 +993,18 @@ module R6502
995
993
  @mem.get(0x01ff).should == 0x06
996
994
  @mem.get(0x01fe).should == 0x02
997
995
  @cpu.pc.should == 0x1000
996
+
997
+ @cpu.s = 0xff
998
+ @cpu.pc = 0x06ff
999
+ @cpu.jsr(0x1000, :abs)
1000
+ @mem.get(0x01ff).should == 0x07
1001
+ @mem.get(0x01fe).should == 0x01
1002
+ @cpu.pc.should == 0x1000
998
1003
  end
999
1004
  it "rts" do
1000
1005
  @cpu.s = 0xfd
1001
- @mem.set(0x01ff, 0xcd)
1002
- @mem.set(0x01fe, 0xab)
1006
+ @mem.set(0x01ff, 0xab)
1007
+ @mem.set(0x01fe, 0xcd)
1003
1008
  @cpu.rts(nil, :imp)
1004
1009
  @cpu.pc.should == 0xabce
1005
1010
  end
@@ -1125,7 +1130,7 @@ module R6502
1125
1130
  @cpu.s = 0xfe
1126
1131
  @cpu.php(nil, :imp)
1127
1132
  @cpu.s.should == 0xfd
1128
- @mem.get( 0x01fe ).should == 0b01101010
1133
+ @mem.get( 0x01fe ).should == 0b01111010
1129
1134
  end
1130
1135
  it "plp" do
1131
1136
  @cpu.c = 1
@@ -1142,6 +1147,7 @@ module R6502
1142
1147
  @cpu.s = 0xfe
1143
1148
  @cpu.plp(nil, :imp)
1144
1149
  @cpu.pc.should == 0x0101
1150
+ @cpu.s.should == 0xff
1145
1151
 
1146
1152
  @cpu.c.should == 0
1147
1153
  @cpu.z.should == 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r6502
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Landers
@@ -18,6 +18,9 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - LICENSE
20
20
  - README.md
21
+ - bin/6502_functional_test.bin
22
+ - bin/6502_functional_test.lst
23
+ - bin/klaus_dormann_test.rb
21
24
  - bin/r6502
22
25
  - lib/r6502.rb
23
26
  - lib/r6502/assembler.rb