From 9f12ce2fb8c701b199ee28eb992a67f8cbd46e99 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 20 Jan 2021 20:16:55 -0500 Subject: [PATCH] Corrects RTS, adds the remainder of the direct flag manipulations. --- InstructionSets/M50740/Executor.cpp | 10 +++++++--- InstructionSets/M50740/Executor.hpp | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/InstructionSets/M50740/Executor.cpp b/InstructionSets/M50740/Executor.cpp index 20033027c..69cff9cc7 100644 --- a/InstructionSets/M50740/Executor.cpp +++ b/InstructionSets/M50740/Executor.cpp @@ -105,7 +105,7 @@ template void Executor::pe #define next8() memory_[(program_counter_ + 1) & 0x1fff] #define next16() (memory_[(program_counter_ + 1) & 0x1fff] | (memory_[(program_counter_ + 2) & 0x1fff] << 8)) - printf("%04x\t%d %d\n", program_counter_ & 0x1fff, int(operation), int(addressing_mode)); + printf("%04x\t%02x\t%d %d\t[x:%02x s:%02x]\n", program_counter_ & 0x1fff, memory_[program_counter_ & 0x1fff], int(operation), int(addressing_mode), x_, s_); // Underlying assumption below: the instruction stream will never // overlap with IO ports. @@ -261,6 +261,9 @@ template void Executor::perform(uint8_t *operand [[maybe_u case Operation::SET: index_mode_ = true; break; case Operation::CLD: decimal_mode_ = false; break; case Operation::SED: decimal_mode_ = true; break; + case Operation::CLC: carry_flag_ = 0; break; + case Operation::SEC: carry_flag_ = 1; break; + case Operation::CLV: overflow_result_ = 0; break; case Operation::DEX: --x_; set_nz(x_); break; case Operation::INX: ++x_; set_nz(x_); break; @@ -272,8 +275,9 @@ template void Executor::perform(uint8_t *operand [[maybe_u case Operation::RTS: { uint16_t target = pull(); target |= pull() << 8; - ++target; - set_program_counter(target); + set_program_counter(target+1); + --program_counter_; // To undo the unavoidable increment + // after exiting from here. } break; /* diff --git a/InstructionSets/M50740/Executor.hpp b/InstructionSets/M50740/Executor.hpp index 5c99623c5..404c41962 100644 --- a/InstructionSets/M50740/Executor.hpp +++ b/InstructionSets/M50740/Executor.hpp @@ -22,6 +22,12 @@ namespace M50740 { class Executor; using CachingExecutor = CachingExecutor; +/*! + Executes M50740 code subject to heavy limitations: + + * the instruction stream cannot run across any of the specialised IO addresses; and + * timing is correct to whole-opcode boundaries only. +*/ class Executor: public CachingExecutor { public: Executor(); @@ -115,6 +121,8 @@ class Executor: public CachingExecutor { uint8_t negative_result_ = 0; uint8_t zero_result_ = 0; uint8_t interrupt_disable_ = 0; + uint8_t carry_flag_ = 0; + uint8_t overflow_result_; bool index_mode_ = false; bool decimal_mode_ = false;