From 5a87506f3d49841968ad2f1abdeabd930c143a7c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 3 May 2022 15:21:42 -0400 Subject: [PATCH] Fix Bcc, making decision that `add_pc` is relative to start of instruction. --- .../M68k/Implementation/ExecutorImplementation.hpp | 2 +- .../M68k/Implementation/PerformImplementation.hpp | 8 ++++---- OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index db1cb0ea1..cf541a5e5 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -361,7 +361,7 @@ void Executor::set_pc(uint32_t address) { template void Executor::add_pc(uint32_t offset) { - program_counter_.l += offset; + program_counter_.l = instruction_address_ + offset; } } diff --git a/InstructionSets/M68k/Implementation/PerformImplementation.hpp b/InstructionSets/M68k/Implementation/PerformImplementation.hpp index 105707d5c..5f8bd6af6 100644 --- a/InstructionSets/M68k/Implementation/PerformImplementation.hpp +++ b/InstructionSets/M68k/Implementation/PerformImplementation.hpp @@ -280,7 +280,7 @@ template < // is the trailing step of a BSR. case Operation::Bccb: if(status.evaluate_condition(instruction.condition())) { - flow_controller.add_pc(int8_t(src.b) - 2); + flow_controller.add_pc(int8_t(src.b) + 2); } else { flow_controller.decline_branch(); } @@ -288,7 +288,7 @@ template < case Operation::Bccw: if(status.evaluate_condition(instruction.condition())) { - flow_controller.add_pc(int16_t(src.b) - 2); + flow_controller.add_pc(int16_t(src.w) + 2); } else { flow_controller.decline_branch(); } @@ -296,7 +296,7 @@ template < case Operation::Bccl: if(status.evaluate_condition(instruction.condition())) { - flow_controller.add_pc(src.l - 2); + flow_controller.add_pc(src.l + 2); } else { flow_controller.decline_branch(); } @@ -312,7 +312,7 @@ template < flow_controller.decline_branch(); } else { // Take the branch. - flow_controller.add_pc(int16_t(dest.l) - 2); + flow_controller.add_pc(int16_t(dest.l) + 2); } } else { // This DBcc will be ignored as the condition is true. diff --git a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm index eb0300ece..4862534d8 100644 --- a/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm +++ b/OSBindings/Mac/Clock SignalTests/68000ComparativeTests.mm @@ -39,7 +39,7 @@ - (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:@[@"ADDQ 00d0"]]; +// _testSet = [NSSet setWithArray:@[@"Bcc 6000 [0]"]]; // _fileSet = [NSSet setWithArray:@[@"jmp_jsr.json"]]; // _testSet = [NSSet setWithArray:@[@"CHK 41a8"]]; }