From e511d33a7c281548c550388d7216a90c15f68636 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 14 Oct 2020 21:42:41 -0400 Subject: [PATCH] Adds test for [d], y; fixes implementation. --- .../65816AddressingTests.swift | 26 ++++++++++++++++--- .../Implementation/65816Implementation.hpp | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/65816AddressingTests.swift b/OSBindings/Mac/Clock SignalTests/65816AddressingTests.swift index bbb66db99..caea8529b 100644 --- a/OSBindings/Mac/Clock SignalTests/65816AddressingTests.swift +++ b/OSBindings/Mac/Clock SignalTests/65816AddressingTests.swift @@ -428,9 +428,7 @@ class WDC65816AddressingTests: XCTestCase { XCTAssertEqual(machine.value(for: .A), 0xcdab) } - // TODO: all tests from this point downward. - - func testIndirectDirectYLong() { + func testIndirectYLong() { // "If the D register is $FF00 and the m flag is 0, then for LDA [$FE],Y, the address // of the low byte of the pointer is $00FFFE, the address of the middle byte is $00FFFF, // and the address of the high byte is $000000. Furthermore, if the Y register is $000A, and @@ -439,8 +437,30 @@ class WDC65816AddressingTests: XCTestCase { // * $00FFFF contains $FF // then LDA [$FE],Y loads the low byte of the data from address $130006, and the high byte // from $130007." + let machine = machine16() + + machine.setValue(0xff00, for: .direct) + machine.setValue(0x000a, for: .Y) + machine.setValue(0x12, for: .dataBank) + + machine.setValue(0x12, forAddress: 0x0000) + machine.setValue(0xfc, forAddress: 0xfffe) + machine.setValue(0xff, forAddress: 0xffff) + + machine.setValue(0xab, forAddress: 0x130006) + machine.setValue(0xcd, forAddress: 0x130007) + + // LDA [$fe], y; NOP + machine.setData(Data([0xb7, 0xfe, 0xea]), atAddress: 0x0200) + + machine.setValue(0x200, for: .programCounter) + machine.runForNumber(ofCycles: 8) + + XCTAssertEqual(machine.value(for: .A), 0xcdab) } + // TODO: all tests from this point downward. + func testLong() { // "If the m flag is 0, then LDA $12FFFF loads the low byte of the data from address $12FFFF, // and the high byte from address $130000." diff --git a/Processors/65816/Implementation/65816Implementation.hpp b/Processors/65816/Implementation/65816Implementation.hpp index 9366747c7..2cbb792bb 100644 --- a/Processors/65816/Implementation/65816Implementation.hpp +++ b/Processors/65816/Implementation/65816Implementation.hpp @@ -315,8 +315,9 @@ template void Processor::run_for(const Cycles continue; case OperationConstructDirectIndirectIndexedLong: - data_address_ = y() + instruction_buffer_.value; + data_address_ = y() + data_buffer_.value; data_address_increment_mask_ = 0xff'ff'ff; + data_buffer_.clear(); continue; case OperationConstructDirectIndirectLong: