29#include "EventCallback.h"
30#include "EventScheduler.h"
45 static constexpr int_least32_t CIAT_CR_START = 0x01;
46 static constexpr int_least32_t CIAT_STEP = 0x04;
47 static constexpr int_least32_t CIAT_CR_ONESHOT = 0x08;
48 static constexpr int_least32_t CIAT_CR_FLOAD = 0x10;
49 static constexpr int_least32_t CIAT_PHI2IN = 0x20;
50 static constexpr int_least32_t CIAT_CR_MASK = CIAT_CR_START | CIAT_CR_ONESHOT | CIAT_CR_FLOAD | CIAT_PHI2IN;
52 static constexpr int_least32_t CIAT_COUNT2 = 0x100;
53 static constexpr int_least32_t CIAT_COUNT3 = 0x200;
55 static constexpr int_least32_t CIAT_ONESHOT0 = 0x08 << 8;
56 static constexpr int_least32_t CIAT_ONESHOT = 0x08 << 16;
57 static constexpr int_least32_t CIAT_LOAD1 = 0x10 << 8;
58 static constexpr int_least32_t CIAT_LOAD = 0x10 << 16;
60 static constexpr int_least32_t CIAT_OUT = 0x80000000;
76 event_clock_t ciaEventPauseTime;
79 bool pbToggle =
false;
82 uint_least16_t timer = 0;
85 uint_least16_t latch = 0;
88 uint8_t lastControlValue = 0;
101 void cycleSkippingEvent();
113 inline void reschedule();
118 void event()
override;
123 virtual void underFlow() =0;
128 virtual void serialPort() {}
140 m_cycleSkippingEvent(
"Skip CIA clock decrement cycles", *this, &
Timer::cycleSkippingEvent),
141 eventScheduler(scheduler),
207 inline uint_least16_t
getTimer()
const {
return timer; }
215 inline bool getPb(uint8_t reg)
const {
return (reg & 0x04) ? pbToggle : (
state & CIAT_OUT); }
218void Timer::reschedule()
228 const int_least32_t unwanted = CIAT_OUT | CIAT_CR_FLOAD | CIAT_LOAD1 | CIAT_LOAD;
229 if ((
state & unwanted) != 0)
231 eventScheduler.schedule(*
this, 1);
235 if ((
state & CIAT_COUNT3) != 0)
240 const int_least32_t wanted = CIAT_CR_START | CIAT_PHI2IN | CIAT_COUNT2 | CIAT_COUNT3;
241 if (timer > 2 && (
state & wanted) == wanted)
246 ciaEventPauseTime = eventScheduler.
getTime(EVENT_CLOCK_PHI1) + 1;
248 eventScheduler.schedule(m_cycleSkippingEvent, timer - 1);
253 eventScheduler.schedule(*
this, 1);
259 const int_least32_t unwanted1 = CIAT_CR_START | CIAT_PHI2IN;
260 const int_least32_t unwanted2 = CIAT_CR_START | CIAT_STEP;
262 if ((
state & unwanted1) == unwanted1
263 || (
state & unwanted2) == unwanted2)
265 eventScheduler.schedule(*
this, 1);
269 ciaEventPauseTime = -1;
Definition EventCallback.h:36
Definition EventScheduler.h:62
event_clock_t getTime(event_phase_t phase) const
Definition EventScheduler.h:158
const char * name() const
Definition Event.h:72
void reset()
Definition timer.cpp:131
uint_least16_t getTimer() const
Definition timer.h:207
bool getPb(uint8_t reg) const
Definition timer.h:215
void wakeUpAfterSyncWithCpu()
Definition timer.cpp:60
int_least32_t getState() const
Definition timer.h:200
void syncWithCpu()
Definition timer.cpp:37
Timer(const char *name, EventScheduler &scheduler, MOS652X &parent)
Definition timer.h:138
int_least32_t state
CRA/CRB control register / state.
Definition timer.h:95
void latchHi(uint8_t data)
Definition timer.cpp:149
MOS652X & parent
Pointer to the MOS6526 which this Timer belongs to.
Definition timer.h:92
void latchLo(uint8_t data)
Definition timer.cpp:142
void setPbToggle(bool state)
Definition timer.h:193
void setControlRegister(uint8_t cr)
Definition timer.cpp:30