Class: Mos6502::Cpu
- Inherits:
-
Object
- Object
- Mos6502::Cpu
- Extended by:
- Forwardable
- Defined in:
- lib/mos6502/cpu.rb,
lib/mos6502/cpu_ops.rb,
lib/mos6502/cpu_instructions.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#pc ⇒ Object
readonly
Returns the value of attribute pc.
-
#sp ⇒ Object
readonly
Returns the value of attribute sp.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #dump_memory(start, length) ⇒ Object
-
#initialize(initial_pc: 0x600, code: nil) ⇒ Cpu
constructor
A new instance of Cpu.
- #inspect ⇒ Object
- #load!(code = nil) ⇒ Object
- #load_image(image = nil, start = 0) ⇒ Object
- #load_image!(image = nil, start = 0) ⇒ Object
- #step ⇒ Object
Constructor Details
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
17 18 19 |
# File 'lib/mos6502/cpu.rb', line 17 def a @a end |
#pc ⇒ Object (readonly)
Returns the value of attribute pc.
17 18 19 |
# File 'lib/mos6502/cpu.rb', line 17 def pc @pc end |
#sp ⇒ Object (readonly)
Returns the value of attribute sp.
17 18 19 |
# File 'lib/mos6502/cpu.rb', line 17 def sp @sp end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
17 18 19 |
# File 'lib/mos6502/cpu.rb', line 17 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
17 18 19 |
# File 'lib/mos6502/cpu.rb', line 17 def y @y end |
Instance Method Details
#dump_memory(start, length) ⇒ Object
57 58 59 |
# File 'lib/mos6502/cpu.rb', line 57 def dump_memory(start, length) @memory.dump(start, length) end |
#inspect ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/mos6502/cpu.rb', line 61 def inspect format( 'a: 0x%02x, x: 0x%02x, y: 0x%02x, sp: 0x%02x, ' \ 'pc: 0x%04x, op: 0x%02x, status: 0b%08b', @a, @x, @y, @sp, @pc, @memory.get(@pc), @status.encode ) end |
#load!(code = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mos6502/cpu.rb', line 34 def load!(code = nil) reset! return if code.nil? loc = @pc code = code.bytes if code.respond_to?(:bytes) code.each do |b| @memory.set(loc, b) loc += 1 end end |
#load_image(image = nil, start = 0) ⇒ Object
46 47 48 49 50 |
# File 'lib/mos6502/cpu.rb', line 46 def load_image(image = nil, start = 0) return if image.nil? @memory.load(image, start) end |
#load_image!(image = nil, start = 0) ⇒ Object
52 53 54 55 |
# File 'lib/mos6502/cpu.rb', line 52 def load_image!(image = nil, start = 0) reset! load_image(image, start) end |
#step ⇒ Object
29 30 31 32 |
# File 'lib/mos6502/cpu.rb', line 29 def step inst = next_byte @instructions[inst].call end |