mirror of
https://github.com/TomHarte/CLK.git
synced 2025-11-05 06:16:26 +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_
|
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 Literal = Address::Literal;
|
||||||
using ZeroPage = Address::ZeroPage;
|
using ZeroPage = Address::ZeroPage;
|
||||||
@@ -101,16 +109,9 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ADC and SBC decimal take an extra cycle on the 65c02.
|
// ADC and SBC decimal take an extra cycle on the 65c02.
|
||||||
if constexpr (is_65c02(model)) {
|
if(needs_65c02_extra_arithmetic_cycle()) {
|
||||||
if(
|
|
||||||
(
|
|
||||||
Storage::decoded_.operation == Operation::ADC ||
|
|
||||||
Storage::decoded_.operation == Operation::SBC
|
|
||||||
) && registers.flags.decimal
|
|
||||||
) {
|
|
||||||
goto access_zero_65c02_decimal;
|
goto access_zero_65c02_decimal;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Read.
|
// Read.
|
||||||
check_interrupt();
|
check_interrupt();
|
||||||
@@ -156,16 +157,9 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ADC and SBC decimal take an extra cycle on the 65c02.
|
// ADC and SBC decimal take an extra cycle on the 65c02.
|
||||||
if constexpr (is_65c02(model)) {
|
if(needs_65c02_extra_arithmetic_cycle()) {
|
||||||
if(
|
|
||||||
(
|
|
||||||
Storage::decoded_.operation == Operation::ADC ||
|
|
||||||
Storage::decoded_.operation == Operation::SBC
|
|
||||||
) && registers.flags.decimal
|
|
||||||
) {
|
|
||||||
goto access_absolute_65c02_decimal;
|
goto access_absolute_65c02_decimal;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Read.
|
// Read.
|
||||||
check_interrupt();
|
check_interrupt();
|
||||||
@@ -235,6 +229,9 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
|||||||
// MARK: - Immediate, Implied, Accumulator.
|
// MARK: - Immediate, Implied, Accumulator.
|
||||||
|
|
||||||
case access_program(Immediate):
|
case access_program(Immediate):
|
||||||
|
if(needs_65c02_extra_arithmetic_cycle()) {
|
||||||
|
goto immediate_65c02_decimal;
|
||||||
|
}
|
||||||
++registers.pc.full;
|
++registers.pc.full;
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
|
||||||
@@ -242,6 +239,14 @@ void Processor<model, Traits>::run_for(const Cycles cycles) {
|
|||||||
perform_operation();
|
perform_operation();
|
||||||
goto fetch_decode;
|
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):
|
case access_program(Accumulator):
|
||||||
CPU::MOS6502Mk2::perform<model>(
|
CPU::MOS6502Mk2::perform<model>(
|
||||||
Storage::decoded_.operation,
|
Storage::decoded_.operation,
|
||||||
|
|||||||
Reference in New Issue
Block a user