29 #include "EventCallback.h"
30 #include "EventScheduler.h"
34 namespace libsidplayfp
45 static const int_least32_t CIAT_CR_START = 0x01;
46 static const int_least32_t CIAT_STEP = 0x04;
47 static const int_least32_t CIAT_CR_ONESHOT = 0x08;
48 static const int_least32_t CIAT_CR_FLOAD = 0x10;
49 static const int_least32_t CIAT_PHI2IN = 0x20;
50 static const int_least32_t CIAT_CR_MASK = CIAT_CR_START | CIAT_CR_ONESHOT | CIAT_CR_FLOAD | CIAT_PHI2IN;
52 static const int_least32_t CIAT_COUNT2 = 0x100;
53 static const int_least32_t CIAT_COUNT3 = 0x200;
55 static const int_least32_t CIAT_ONESHOT0 = 0x08 << 8;
56 static const int_least32_t CIAT_ONESHOT = 0x08 << 16;
57 static const int_least32_t CIAT_LOAD1 = 0x10 << 8;
58 static const int_least32_t CIAT_LOAD = 0x10 << 16;
60 static const int_least32_t CIAT_OUT = 0x80000000;
76 event_clock_t ciaEventPauseTime;
88 uint8_t lastControlValue;
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),
212 inline uint_least16_t
getTimer()
const {
return timer; }
220 inline bool getPb(uint8_t reg)
const {
return (reg & 0x04) ? pbToggle : (
state & CIAT_OUT); }
223 void Timer::reschedule()
233 const int_least32_t unwanted = CIAT_OUT | CIAT_CR_FLOAD | CIAT_LOAD1 | CIAT_LOAD;
234 if ((
state & unwanted) != 0)
236 eventScheduler.schedule(*
this, 1);
240 if ((
state & CIAT_COUNT3) != 0)
245 const int_least32_t wanted = CIAT_CR_START | CIAT_PHI2IN | CIAT_COUNT2 | CIAT_COUNT3;
246 if (timer > 2 && (
state & wanted) == wanted)
251 ciaEventPauseTime = eventScheduler.
getTime(EVENT_CLOCK_PHI1) + 1;
253 eventScheduler.schedule(m_cycleSkippingEvent, timer - 1);
258 eventScheduler.schedule(*
this, 1);
264 const int_least32_t unwanted1 = CIAT_CR_START | CIAT_PHI2IN;
265 const int_least32_t unwanted2 = CIAT_CR_START | CIAT_STEP;
267 if ((
state & unwanted1) == unwanted1
268 || (
state & unwanted2) == unwanted2)
270 eventScheduler.schedule(*
this, 1);
274 ciaEventPauseTime = -1;