diff --git a/Components/6532/6532.hpp b/Components/6532/6532.hpp index 69780a2cd..4ee0c18b6 100644 --- a/Components/6532/6532.hpp +++ b/Components/6532/6532.hpp @@ -11,6 +11,7 @@ #include #include +#include "../ClockReceiver.hpp" namespace MOS { @@ -25,7 +26,7 @@ namespace MOS { Consumers should derive their own curiously-recurring-template-pattern subclass, implementing bus communications as required. */ -template class MOS6532 { +template class MOS6532: public ClockReceiver> { public: inline void set_ram(uint16_t address, uint8_t value) { ram_[address&0x7f] = value; } inline uint8_t get_ram(uint16_t address) { return ram_[address & 0x7f]; } @@ -104,7 +105,9 @@ template class MOS6532 { return 0xff; } - inline void run_for_cycles(unsigned int number_of_cycles) { + inline void run_for(const Cycles &cycles) { + unsigned int number_of_cycles = (unsigned int)cycles.as_int(); + // permit counting _to_ zero; counting _through_ zero initiates the other behaviour if(timer_.value >= number_of_cycles) { timer_.value -= number_of_cycles; diff --git a/Machines/Atari2600/Bus.hpp b/Machines/Atari2600/Bus.hpp index 76beb3796..f440d8093 100644 --- a/Machines/Atari2600/Bus.hpp +++ b/Machines/Atari2600/Bus.hpp @@ -55,7 +55,7 @@ class Bus { // RIOT backlog accumulation counter unsigned int cycles_since_6532_update_; inline void update_6532() { - mos6532_.run_for_cycles(cycles_since_6532_update_); + mos6532_.run_for(Cycles((int)cycles_since_6532_update_)); cycles_since_6532_update_ = 0; } }; diff --git a/OSBindings/Mac/Clock SignalTests/Bridges/MOS6532Bridge.mm b/OSBindings/Mac/Clock SignalTests/Bridges/MOS6532Bridge.mm index 12ced175b..585c91d0a 100644 --- a/OSBindings/Mac/Clock SignalTests/Bridges/MOS6532Bridge.mm +++ b/OSBindings/Mac/Clock SignalTests/Bridges/MOS6532Bridge.mm @@ -11,45 +11,37 @@ class VanillaRIOT: public MOS::MOS6532 { public: - uint8_t get_port_input(int port) - { + uint8_t get_port_input(int port) { return input[port]; } uint8_t input[2]; }; -@implementation MOS6532Bridge -{ +@implementation MOS6532Bridge { VanillaRIOT _riot; } -- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber -{ +- (void)setValue:(uint8_t)value forRegister:(NSUInteger)registerNumber { _riot.set_register((int)registerNumber, value); } -- (uint8_t)valueForRegister:(NSUInteger)registerNumber -{ +- (uint8_t)valueForRegister:(NSUInteger)registerNumber { return _riot.get_register((int)registerNumber); } -- (void)runForCycles:(NSUInteger)numberOfCycles -{ - _riot.run_for_cycles((int)numberOfCycles); +- (void)runForCycles:(NSUInteger)numberOfCycles { + _riot.run_for(Cycles((int)numberOfCycles)); } -- (BOOL)irqLine -{ +- (BOOL)irqLine { return _riot.get_inerrupt_line(); } -- (void)setPortAInput:(uint8_t)portAInput -{ +- (void)setPortAInput:(uint8_t)portAInput { _riot.input[0] = _portAInput = portAInput; } -- (void)setPortBInput:(uint8_t)portBInput -{ +- (void)setPortBInput:(uint8_t)portBInput { _riot.input[1] = _portBInput = portBInput; }