mirror of
https://github.com/TomHarte/CLK.git
synced 2025-11-01 11:16:16 +00:00
Add extra cycle to immediate decimal arithmetic.
This commit is contained in:
@@ -76,6 +76,14 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
||||
Storage::opcode_
|
||||
);
|
||||
};
|
||||
const auto needs_65c02_extra_arithmetic_cycle = [&] {
|
||||
return
|
||||
is_65c02(model) &&
|
||||
(
|
||||
Storage::decoded_.operation == Operation::ADC ||
|
||||
Storage::decoded_.operation == Operation::SBC
|
||||
) && registers.flags.decimal;
|
||||
};
|
||||
|
||||
using Literal = Address::Literal;
|
||||
using ZeroPage = Address::ZeroPage;
|
||||
@@ -101,15 +109,8 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
||||
}
|
||||
|
||||
// ADC and SBC decimal take an extra cycle on the 65c02.
|
||||
if constexpr (is_65c02(model)) {
|
||||
if(
|
||||
(
|
||||
Storage::decoded_.operation == Operation::ADC ||
|
||||
Storage::decoded_.operation == Operation::SBC
|
||||
) && registers.flags.decimal
|
||||
) {
|
||||
goto access_zero_65c02_decimal;
|
||||
}
|
||||
if(needs_65c02_extra_arithmetic_cycle()) {
|
||||
goto access_zero_65c02_decimal;
|
||||
}
|
||||
|
||||
// Read.
|
||||
@@ -156,15 +157,8 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
||||
}
|
||||
|
||||
// ADC and SBC decimal take an extra cycle on the 65c02.
|
||||
if constexpr (is_65c02(model)) {
|
||||
if(
|
||||
(
|
||||
Storage::decoded_.operation == Operation::ADC ||
|
||||
Storage::decoded_.operation == Operation::SBC
|
||||
) && registers.flags.decimal
|
||||
) {
|
||||
goto access_absolute_65c02_decimal;
|
||||
}
|
||||
if(needs_65c02_extra_arithmetic_cycle()) {
|
||||
goto access_absolute_65c02_decimal;
|
||||
}
|
||||
|
||||
// Read.
|
||||
@@ -235,6 +229,9 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
||||
// MARK: - Immediate, Implied, Accumulator.
|
||||
|
||||
case access_program(Immediate):
|
||||
if(needs_65c02_extra_arithmetic_cycle()) {
|
||||
goto immediate_65c02_decimal;
|
||||
}
|
||||
++registers.pc.full;
|
||||
[[fallthrough]];
|
||||
|
||||
@@ -242,6 +239,14 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
||||
perform_operation();
|
||||
goto fetch_decode;
|
||||
|
||||
immediate_65c02_decimal:
|
||||
check_interrupt();
|
||||
access(BusOperation::Read, Literal(registers.pc.full), Storage::operand_);
|
||||
|
||||
++registers.pc.full;
|
||||
perform_operation();
|
||||
goto fetch_decode;
|
||||
|
||||
case access_program(Accumulator):
|
||||
CPU::MOS6502Mk2::perform<model>(
|
||||
Storage::decoded_.operation,
|
||||
|
||||
Reference in New Issue
Block a user