diff --git a/Processors/6502/6502.hpp b/Processors/6502/6502.hpp index b170cee36..0bc9d6d85 100644 --- a/Processors/6502/6502.hpp +++ b/Processors/6502/6502.hpp @@ -558,15 +558,14 @@ template class Processor: public MicroOpScheduler { // without touching the class storage (i.e. it explicitly says they need be completely up // to date in this stack frame only); which saves some complicated addressing unsigned int scheduleProgramsReadPointer = schedule_programs_read_pointer_; - unsigned int scheduleProgramProgramCounter = schedule_program_program_counter_; RegisterPair nextAddress = next_address_; BusOperation nextBusOperation = next_bus_operation_; uint16_t busAddress = bus_address_; uint8_t *busValue = bus_value_; #define checkSchedule(op) \ - if(!scheduled_programs_[scheduleProgramsReadPointer]) {\ - scheduleProgramsReadPointer = schedule_programs_write_pointer_ = scheduleProgramProgramCounter = 0;\ + if(!scheduled_program_counter_) {\ + scheduleProgramsReadPointer = schedule_programs_write_pointer_ = 0;\ if(interrupt_requests_) {\ if(interrupt_requests_ & (InterruptRequestFlags::Reset | InterruptRequestFlags::PowerOn)) {\ interrupt_requests_ &= ~InterruptRequestFlags::PowerOn;\ @@ -607,8 +606,8 @@ template class Processor: public MicroOpScheduler { while(1) { - const MicroOp cycle = program[scheduleProgramProgramCounter]; - scheduleProgramProgramCounter++; + const MicroOp cycle = *scheduled_program_counter_; + scheduled_program_counter_++; #define read_op(val, addr) nextBusOperation = BusOperation::ReadOpcode; busAddress = addr; busValue = &val; val = 0xff #define read_mem(val, addr) nextBusOperation = BusOperation::Read; busAddress = addr; busValue = &val; val = 0xff @@ -649,7 +648,7 @@ template class Processor: public MicroOpScheduler { case OperationMoveToNextProgram: scheduled_programs_[scheduleProgramsReadPointer] = NULL; scheduleProgramsReadPointer = (scheduleProgramsReadPointer+1)&3; - scheduleProgramProgramCounter = 0; + scheduled_program_counter_ = scheduled_programs_[scheduleProgramsReadPointer]; checkSchedule(); program = scheduled_programs_[scheduleProgramsReadPointer]; continue; @@ -1083,7 +1082,6 @@ template class Processor: public MicroOpScheduler { cycles_left_to_run_ = number_of_cycles; schedule_programs_read_pointer_ = scheduleProgramsReadPointer; - schedule_program_program_counter_ = scheduleProgramProgramCounter; next_address_ = nextAddress; next_bus_operation_ = nextBusOperation; bus_address_ = busAddress; diff --git a/Processors/MicroOpScheduler.hpp b/Processors/MicroOpScheduler.hpp index 587885669..846fce754 100644 --- a/Processors/MicroOpScheduler.hpp +++ b/Processors/MicroOpScheduler.hpp @@ -17,7 +17,7 @@ template class MicroOpScheduler { scheduled_programs_{nullptr, nullptr, nullptr, nullptr}, schedule_programs_write_pointer_(0), schedule_programs_read_pointer_(0), - schedule_program_program_counter_(0) {} + scheduled_program_counter_(nullptr) {} protected: /* @@ -28,7 +28,8 @@ template class MicroOpScheduler { queue to take that step. */ const T *scheduled_programs_[4]; - unsigned int schedule_programs_write_pointer_, schedule_programs_read_pointer_, schedule_program_program_counter_; + const T *scheduled_program_counter_; + unsigned int schedule_programs_write_pointer_, schedule_programs_read_pointer_; /*! Schedules a new program, adding it to the end of the queue. Programs should be @@ -39,13 +40,14 @@ template class MicroOpScheduler { */ inline void schedule_program(const T *program) { scheduled_programs_[schedule_programs_write_pointer_] = program; + if(schedule_programs_write_pointer_ == schedule_programs_read_pointer_) scheduled_program_counter_ = program; schedule_programs_write_pointer_ = (schedule_programs_write_pointer_+1)&3; } inline void move_to_next_program() { - scheduled_programs_[schedule_programs_read_pointer_] = NULL; + scheduled_programs_[schedule_programs_read_pointer_] = nullptr; schedule_programs_read_pointer_ = (schedule_programs_read_pointer_+1)&3; - schedule_program_program_counter_ = 0; + scheduled_program_counter_ = scheduled_programs_[schedule_programs_read_pointer_]; } }; diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index 540fc4eb1..9af5d6c9d 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -686,8 +686,8 @@ template class Processor: public MicroOpScheduler { checkSchedule(); while(1) { - const MicroOp *operation = &scheduled_programs_[schedule_programs_read_pointer_][schedule_program_program_counter_]; - schedule_program_program_counter_++; + const MicroOp *operation = scheduled_program_counter_; + scheduled_program_counter_++; #define set_parity(v) \ parity_overflow_result_ = v^1;\ @@ -697,7 +697,7 @@ template class Processor: public MicroOpScheduler { switch(operation->type) { case MicroOp::BusOperation: - if(number_of_cycles_ < operation->machine_cycle.length) { schedule_program_program_counter_--; return; } + if(number_of_cycles_ < operation->machine_cycle.length) { scheduled_program_counter_--; return; } number_of_cycles_ -= operation->machine_cycle.length; number_of_cycles_ -= static_cast(this)->perform_machine_cycle(&operation->machine_cycle); break;