From a4c9724dc0f20274ef7568128c4be56de43282ac Mon Sep 17 00:00:00 2001 From: Robert Haines Date: Sat, 24 Oct 2020 20:39:04 +0100 Subject: [PATCH] Implement INC (absolute, X). --- lib/mos6502/cpu_instructions.rb | 6 ++++++ test/cpu_instructions_test.rb | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/mos6502/cpu_instructions.rb b/lib/mos6502/cpu_instructions.rb index 81e6c13..3e3bee5 100644 --- a/lib/mos6502/cpu_instructions.rb +++ b/lib/mos6502/cpu_instructions.rb @@ -650,6 +650,12 @@ def instructions # SED 0xf8 => lambda { @status.decimal_mode = true + }, + + # INC (absolute, X) + 0xfe => lambda { + address = absolute(@x) + @memory.set(address, inc(@memory.get(address))) } } end diff --git a/test/cpu_instructions_test.rb b/test/cpu_instructions_test.rb index 5ae2baa..b3d759b 100644 --- a/test/cpu_instructions_test.rb +++ b/test/cpu_instructions_test.rb @@ -1551,4 +1551,24 @@ def test_0xf6 assert(@cpu.zero?) end + def test_0xfe + @cpu.load!( + [ + 0xa9, 0xfe, 0xa2, 0x08, 0x9d, 0x92, 0x32, + 0xfe, 0x92, 0x32, 0xfe, 0x92, 0x32 + ] + ) + @cpu.step + @cpu.step + @cpu.step + assert_equal([0xfe], @cpu.dump_memory(0x329a, 1)) + @cpu.step + assert_equal([0xff], @cpu.dump_memory(0x329a, 1)) + assert(@cpu.negative?) + refute(@cpu.zero?) + @cpu.step + assert_equal([0x00], @cpu.dump_memory(0x329a, 1)) + refute(@cpu.negative?) + assert(@cpu.zero?) + end end