From af973138df3275f4c85ec1c52d8ad67e1a7c23cf Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 3 May 2022 15:32:54 -0400 Subject: [PATCH] Correct decoding of Bcc.b, satisfying Bcc and BSR tests. --- InstructionSets/M68k/Decoder.cpp | 7 ++++++- InstructionSets/M68k/Executor.hpp | 1 + .../M68k/Implementation/ExecutorImplementation.hpp | 7 +++++++ .../M68k/Implementation/PerformImplementation.hpp | 10 ++++++++++ InstructionSets/M68k/Instruction.hpp | 1 + .../Mac/Clock SignalTests/68000ComparativeTests.mm | 5 +++-- 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/InstructionSets/M68k/Decoder.cpp b/InstructionSets/M68k/Decoder.cpp index edfc86ec8..45e3e5c31 100644 --- a/InstructionSets/M68k/Decoder.cpp +++ b/InstructionSets/M68k/Decoder.cpp @@ -812,10 +812,15 @@ template Preinstruction Predecoder::decode(ui // No further operands decoded, but note that one is somewhere in the opcode. // case OpT(Operation::TRAP): - case OpT(Operation::Bccb): case OpT(Operation::BSRb): return validated(AddressingMode::Quick); + case OpT(Operation::Bccb): + return validated( + AddressingMode::Quick, 0, + AddressingMode::None, 0, + Condition((instruction >> 8) & 0xf)); + // // MARK: LINKw // diff --git a/InstructionSets/M68k/Executor.hpp b/InstructionSets/M68k/Executor.hpp index 917f44114..b2abd9c61 100644 --- a/InstructionSets/M68k/Executor.hpp +++ b/InstructionSets/M68k/Executor.hpp @@ -45,6 +45,7 @@ template class Executor { void add_pc(uint32_t); void decline_branch() {} void did_update_status(); + void bsr(uint32_t offset); // TODO: ownership of this shouldn't be here. struct Registers { diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index cf541a5e5..683512f91 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -364,6 +364,13 @@ void Executor::add_pc(uint32_t offset) { program_counter_.l = instruction_address_ + offset; } +template +void Executor::bsr(uint32_t offset) { + address_[7].l -= 4; + bus_handler_.template write(address_[7].l, program_counter_.l); + program_counter_.l = instruction_address_ + offset; +} + } } diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 5f8bd6af6..c72e45be8 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -302,6 +302,16 @@ template < } break; + case Operation::BSRb: + flow_controller.bsr(int8_t(src.b) + 2); + break; + case Operation::BSRw: + flow_controller.bsr(int16_t(src.w) + 2); + break; + case Operation::BSRl: + flow_controller.bsr(src.l + 2); + break; + case Operation::DBcc: // Decide what sort of DBcc this is. if(!status.evaluate_condition(instruction.condition())) { diff --git a/InstructionSets/M68k/Instruction.hpp b/InstructionSets/M68k/Instruction.hpp index 8868f01fc..51fd07fe2 100644 --- a/InstructionSets/M68k/Instruction.hpp +++ b/InstructionSets/M68k/Instruction.hpp @@ -273,6 +273,7 @@ template uint8_t ope case Operation::ANDItoSR: case Operation::ANDItoCCR: case Operation::EORItoSR: case Operation::EORItoCCR: case Operation::Bccb: case Operation::Bccw: case Operation::Bccl: + case Operation::BSRb: case Operation::BSRw: case Operation::BSRl: return FetchOp1; // diff --git a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm index 4862534d8..7d24a212e 100644 --- a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm +++ b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm @@ -35,11 +35,12 @@ // eor_and_or // addq_subq // addx_subx +// bcc - (void)setUp { // To limit tests run to a subset of files and/or of tests, uncomment and fill in below. - _fileSet = [NSSet setWithArray:@[@"bcc.json"]]; -// _testSet = [NSSet setWithArray:@[@"Bcc 6000 [0]"]]; + _fileSet = [NSSet setWithArray:@[@"btst_bchg_bclr_bset.json"]]; +// _testSet = [NSSet setWithArray:@[@"Bcc 6206"]]; // _fileSet = [NSSet setWithArray:@[@"jmp_jsr.json"]]; // _testSet = [NSSet setWithArray:@[@"CHK 41a8"]]; }