mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-08 17:29:34 +00:00
Adds various asserts, some comments.
This commit is contained in:
parent
83d0cfc24e
commit
c8471eb993
@ -484,31 +484,37 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
//
|
//
|
||||||
|
|
||||||
case LDA:
|
case LDA:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
LDA(data_buffer_.value);
|
LDA(data_buffer_.value);
|
||||||
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LDX:
|
case LDX:
|
||||||
|
assert(data_buffer_.size == 2 - x_flag());
|
||||||
LDXY(registers_.x, data_buffer_.value);
|
LDXY(registers_.x, data_buffer_.value);
|
||||||
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LDY:
|
case LDY:
|
||||||
|
assert(data_buffer_.size == 2 - x_flag());
|
||||||
LDXY(registers_.y, data_buffer_.value);
|
LDXY(registers_.y, data_buffer_.value);
|
||||||
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLB:
|
case PLB:
|
||||||
|
assert(data_buffer_.size == 1);
|
||||||
registers_.data_bank = (data_buffer_.value & 0xff) << 16;
|
registers_.data_bank = (data_buffer_.value & 0xff) << 16;
|
||||||
registers_.flags.set_nz(uint8_t(data_buffer_.value));
|
registers_.flags.set_nz(uint8_t(data_buffer_.value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLD:
|
case PLD:
|
||||||
|
assert(data_buffer_.size == 2);
|
||||||
registers_.direct = uint16_t(data_buffer_.value);
|
registers_.direct = uint16_t(data_buffer_.value);
|
||||||
registers_.flags.set_nz(uint16_t(data_buffer_.value), 8);
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), 8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLP:
|
case PLP:
|
||||||
|
assert(data_buffer_.size == 1);
|
||||||
set_flags(uint8_t(data_buffer_.value));
|
set_flags(uint8_t(data_buffer_.value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -616,7 +622,9 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
|
|
||||||
case TCS:
|
case TCS:
|
||||||
registers_.s.full = registers_.a.full;
|
registers_.s.full = registers_.a.full;
|
||||||
// No need to worry about byte masking here; for the stack it's handled as the emulation runs.
|
// No need to worry about byte masking here;
|
||||||
|
// for the stack it's handled as the emulation runs.
|
||||||
|
// Cf. the stack_address() macro.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TSC:
|
case TSC:
|
||||||
@ -645,6 +653,7 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case JMPind:
|
case JMPind:
|
||||||
|
assert(data_buffer_.size == 2);
|
||||||
registers_.pc = uint16_t(data_buffer_.value);
|
registers_.pc = uint16_t(data_buffer_.value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -653,6 +662,7 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
||||||
case RTS:
|
case RTS:
|
||||||
|
assert(data_buffer_.size == 2 + (active_instruction_->operation == RTL));
|
||||||
registers_.pc = uint16_t(data_buffer_.value + 1);
|
registers_.pc = uint16_t(data_buffer_.value + 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -661,8 +671,11 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
||||||
case JSR:
|
case JSR:
|
||||||
|
assert(instruction_buffer_.size == 2 + (active_instruction_->operation == JSL));
|
||||||
data_buffer_.value = registers_.pc;
|
data_buffer_.value = registers_.pc;
|
||||||
data_buffer_.size = 2;
|
data_buffer_.size = 2;
|
||||||
|
// The per-cycle scheduling for JSL means that the program
|
||||||
|
// bank register has already been pushed to the stack by now.
|
||||||
|
|
||||||
registers_.pc = uint16_t(instruction_buffer_.value);
|
registers_.pc = uint16_t(instruction_buffer_.value);
|
||||||
break;
|
break;
|
||||||
@ -671,6 +684,7 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
registers_.pc = uint16_t(data_buffer_.value >> 8);
|
registers_.pc = uint16_t(data_buffer_.value >> 8);
|
||||||
set_flags(uint8_t(data_buffer_.value));
|
set_flags(uint8_t(data_buffer_.value));
|
||||||
|
|
||||||
|
assert(data_buffer_.size == 4 - registers_.emulation_flag);
|
||||||
if(!registers_.emulation_flag) {
|
if(!registers_.emulation_flag) {
|
||||||
registers_.program_bank = (data_buffer_.value & 0xff000000) >> 8;
|
registers_.program_bank = (data_buffer_.value & 0xff000000) >> 8;
|
||||||
}
|
}
|
||||||
@ -728,11 +742,13 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
//
|
//
|
||||||
|
|
||||||
case INC:
|
case INC:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
++data_buffer_.value;
|
++data_buffer_.value;
|
||||||
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
||||||
break;;
|
break;;
|
||||||
|
|
||||||
case DEC:
|
case DEC:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
--data_buffer_.value;
|
--data_buffer_.value;
|
||||||
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
||||||
break;
|
break;
|
||||||
@ -777,21 +793,25 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BIT:
|
case BIT:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
registers_.flags.set_n(uint16_t(data_buffer_.value), registers_.m_shift);
|
registers_.flags.set_n(uint16_t(data_buffer_.value), registers_.m_shift);
|
||||||
registers_.flags.set_z(uint16_t(data_buffer_.value & registers_.a.full), registers_.m_shift);
|
registers_.flags.set_z(uint16_t(data_buffer_.value & registers_.a.full), registers_.m_shift);
|
||||||
registers_.flags.overflow = data_buffer_.value & Flag::Overflow;
|
registers_.flags.overflow = data_buffer_.value & Flag::Overflow;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BITimm:
|
case BITimm:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRB:
|
case TRB:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
||||||
data_buffer_.value &= ~registers_.a.full;
|
data_buffer_.value &= ~registers_.a.full;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TSB:
|
case TSB:
|
||||||
|
assert(data_buffer_.size == 2 - m_flag());
|
||||||
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
||||||
data_buffer_.value |= registers_.a.full;
|
data_buffer_.value |= registers_.a.full;
|
||||||
break;
|
break;
|
||||||
@ -800,12 +820,13 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
// Branches.
|
// Branches.
|
||||||
//
|
//
|
||||||
|
|
||||||
#define BRA(condition) \
|
#define BRA(condition) \
|
||||||
if(!(condition)) { \
|
assert(instruction_buffer_.size == 1); \
|
||||||
next_op_ += 3; \
|
if(!(condition)) { \
|
||||||
} else { \
|
next_op_ += 3; \
|
||||||
data_buffer_.size = 2; \
|
} else { \
|
||||||
data_buffer_.value = uint32_t(registers_.pc + int8_t(instruction_buffer_.value)); \
|
data_buffer_.value = uint32_t(registers_.pc + int8_t(instruction_buffer_.value)); \
|
||||||
|
data_buffer_.size = 2; \
|
||||||
\
|
\
|
||||||
if((registers_.pc & 0xff00) == (instruction_buffer_.value & 0xff00)) { \
|
if((registers_.pc & 0xff00) == (instruction_buffer_.value & 0xff00)) { \
|
||||||
++next_op_; \
|
++next_op_; \
|
||||||
@ -825,6 +846,7 @@ template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler,
|
|||||||
#undef BRA
|
#undef BRA
|
||||||
|
|
||||||
case BRL:
|
case BRL:
|
||||||
|
assert(instruction_buffer_.size == 2);
|
||||||
registers_.pc += int16_t(instruction_buffer_.value);
|
registers_.pc += int16_t(instruction_buffer_.value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user