From 86fdc75feb584d0fd7b684e6f46bf9d99d070070 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 23 Jun 2019 18:37:32 -0400 Subject: [PATCH] Incorporates RTR test, adding a ProcessorState helper. --- .../Mac/Clock SignalTests/68000Tests.mm | 20 +++++++++++++ Processors/68000/68000.hpp | 28 +++++++++++-------- .../Implementation/68000Implementation.hpp | 2 +- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/68000Tests.mm b/OSBindings/Mac/Clock SignalTests/68000Tests.mm index 5b01a622d..59e55432f 100644 --- a/OSBindings/Mac/Clock SignalTests/68000Tests.mm +++ b/OSBindings/Mac/Clock SignalTests/68000Tests.mm @@ -1839,6 +1839,26 @@ class CPU::MC68000::ProcessorStorageTests { XCTAssertEqual(state.status & Flag::ConditionCodes, Flag::Zero); } +// MARK: RTR + +- (void)testRTR { + _machine->set_program({ + 0x4e77 // RTR + }); + _machine->set_initial_stack_pointer(0x2000); + *_machine->ram_at(0x2000) = 0x7fff; + *_machine->ram_at(0x2002) = 0; + *_machine->ram_at(0x2004) = 0xc; + + _machine->run_for_instructions(1); + + const auto state = _machine->get_processor_state(); + XCTAssertEqual(state.stack_pointer(), 0x2006); + XCTAssertEqual(state.program_counter, 0x10); + XCTAssertEqual(state.status & Flag::ConditionCodes, Flag::ConditionCodes); + XCTAssertEqual(20, _machine->get_cycle_count()); +} + // MARK: Scc - (void)testSFDn { diff --git a/Processors/68000/68000.hpp b/Processors/68000/68000.hpp index ad9c9793c..cf56842fc 100644 --- a/Processors/68000/68000.hpp +++ b/Processors/68000/68000.hpp @@ -220,18 +220,6 @@ class BusHandler { class ProcessorBase: public ProcessorStorage { }; -struct ProcessorState { - uint32_t data[8]; - uint32_t address[7]; - uint32_t user_stack_pointer, supervisor_stack_pointer; - uint32_t program_counter; - uint16_t status; - - // TODO: More state needed to indicate current instruction, the processor's - // progress through it, and anything it has fetched so far. -// uint16_t current_instruction; -}; - enum Flag: uint16_t { Trace = 0x8000, Supervisor = 0x2000, @@ -245,6 +233,22 @@ enum Flag: uint16_t { Carry = 0x0001 }; +struct ProcessorState { + uint32_t data[8]; + uint32_t address[7]; + uint32_t user_stack_pointer, supervisor_stack_pointer; + uint32_t program_counter; + uint16_t status; + + uint32_t stack_pointer() const { + return (status & Flag::Supervisor) ? supervisor_stack_pointer : user_stack_pointer; + } + + // TODO: More state needed to indicate current instruction, the processor's + // progress through it, and anything it has fetched so far. +// uint16_t current_instruction; +}; + template class Processor: public ProcessorBase { public: Processor(T &bus_handler) : ProcessorBase(), bus_handler_(bus_handler) {} diff --git a/Processors/68000/Implementation/68000Implementation.hpp b/Processors/68000/Implementation/68000Implementation.hpp index c75c797e6..855374fdb 100644 --- a/Processors/68000/Implementation/68000Implementation.hpp +++ b/Processors/68000/Implementation/68000Implementation.hpp @@ -19,7 +19,7 @@ uint16_t( \ get_ccr() | \ (interrupt_level_ << 8) | \ - (trace_flag_ ? 0x8000 : 0x0000) | \ + (trace_flag_ ? 0x8000 : 0x0000) | \ (is_supervisor_ << 13) \ )