1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-30 22:56:03 +00:00

Corrects RTS, adds the remainder of the direct flag manipulations.

This commit is contained in:
Thomas Harte 2021-01-20 20:16:55 -05:00
parent b9672c0669
commit 9f12ce2fb8
2 changed files with 15 additions and 3 deletions

View File

@ -105,7 +105,7 @@ template <Operation operation, AddressingMode addressing_mode> 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 <Operation operation> 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 <Operation operation> 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;
/*

View File

@ -22,6 +22,12 @@ namespace M50740 {
class Executor;
using CachingExecutor = CachingExecutor<Executor, 0x1fff, 255, Instruction, false>;
/*!
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;