Skip to content

Commit

Permalink
Implement DEC (absolute, X).
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Oct 24, 2020
1 parent a4c9724 commit 80169b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/mos6502/cpu_instructions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ def instructions
compare(@a, @memory.get(absolute(@x)))
},

# DEC (absolute, X)
0xde => lambda {
address = absolute(@x)
@memory.set(address, dec(@memory.get(address)))
},

# CPX (immediate)
0xe0 => lambda {
compare(@x, next_byte)
Expand Down
21 changes: 21 additions & 0 deletions test/cpu_instructions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,27 @@ def test_0xdd
assert(@cpu.zero?)
end

def test_0xde
@cpu.load!(
[
0xa9, 0x01, 0xa2, 0x08, 0x9d, 0x92, 0x53,
0xde, 0x92, 0x53, 0xde, 0x92, 0x53
]
)
@cpu.step
@cpu.step
@cpu.step
assert_equal([0x01], @cpu.dump_memory(0x539a, 1))
@cpu.step
assert_equal([0x00], @cpu.dump_memory(0x539a, 1))
refute(@cpu.negative?)
assert(@cpu.zero?)
@cpu.step
assert_equal([0xff], @cpu.dump_memory(0x539a, 1))
assert(@cpu.negative?)
refute(@cpu.zero?)
end

def test_0xe0
@cpu.load!([0xa2, 0x20, 0xe0, 0x10, 0xe0, 0x30, 0xe0, 0x20])
@cpu.step
Expand Down

0 comments on commit 80169b2

Please sign in to comment.