28 #include "sidplayfp/event.h" 29 #include "EventScheduler.h" 41 static const int_least32_t CIAT_CR_START = 0x01;
42 static const int_least32_t CIAT_STEP = 0x04;
43 static const int_least32_t CIAT_CR_ONESHOT = 0x08;
44 static const int_least32_t CIAT_CR_FLOAD = 0x10;
45 static const int_least32_t CIAT_PHI2IN = 0x20;
46 static const int_least32_t CIAT_CR_MASK = CIAT_CR_START | CIAT_CR_ONESHOT | CIAT_CR_FLOAD | CIAT_PHI2IN;
48 static const int_least32_t CIAT_COUNT2 = 0x100;
49 static const int_least32_t CIAT_COUNT3 = 0x200;
51 static const int_least32_t CIAT_ONESHOT0 = 0x08 << 8;
52 static const int_least32_t CIAT_ONESHOT = 0x08 << 16;
53 static const int_least32_t CIAT_LOAD1 = 0x10 << 8;
54 static const int_least32_t CIAT_LOAD = 0x10 << 16;
56 static const int_least32_t CIAT_OUT = 0x80000000;
72 event_clock_t ciaEventPauseTime;
84 uint8_t lastControlValue;
97 void cycleSkippingEvent();
109 inline void reschedule();
119 virtual void underFlow() =0;
124 virtual void serialPort() {};
136 m_cycleSkippingEvent(
"Skip CIA clock decrement cycles", *this, &
Timer::cycleSkippingEvent),
137 event_context(*context),
208 inline uint_least16_t
getTimer()
const {
return timer; }
216 inline bool getPb(uint8_t reg)
const {
return (reg & 0x04) ? pbToggle : (state & CIAT_OUT); }
219 void Timer::reschedule()
230 const int_least32_t unwanted = CIAT_OUT | CIAT_CR_FLOAD | CIAT_LOAD1 | CIAT_LOAD;
231 if ((
state & unwanted) != 0)
237 if ((
state & CIAT_COUNT3) != 0)
242 const int_least32_t wanted = CIAT_CR_START | CIAT_PHI2IN | CIAT_COUNT2 | CIAT_COUNT3;
243 if (timer > 2 && (
state & wanted) == wanted)
248 ciaEventPauseTime = event_context.
getTime(EVENT_CLOCK_PHI1) + 1;
250 event_context.
schedule(m_cycleSkippingEvent, timer - 1);
261 const int_least32_t unwanted1 = CIAT_CR_START | CIAT_PHI2IN;
262 const int_least32_t unwanted2 = CIAT_CR_START | CIAT_STEP;
264 if ((
state & unwanted1) == unwanted1
265 || (
state & unwanted2) == unwanted2)
271 ciaEventPauseTime = -1;
bool getPb(uint8_t reg) const
Definition: timer.h:216
Definition: mos6526.h:103
void reset()
Definition: timer.cpp:128
void latchLo(uint8_t data)
Definition: timer.cpp:139
void setPbToggle(bool state)
Definition: timer.h:194
Timer(const char *name, EventContext *context, MOS6526 *parent)
Definition: timer.h:134
virtual void schedule(Event &event, unsigned int cycles, event_phase_t phase)=0
MOS6526 *const parent
Pointer to the MOS6526 which this Timer belongs to.
Definition: timer.h:88
int_least32_t state
CRA/CRB control register / state.
Definition: timer.h:91
uint_least16_t getTimer() const
Definition: timer.h:208
int_least32_t getState() const
Definition: timer.h:201
void latchHi(uint8_t data)
Definition: timer.cpp:146
void syncWithCpu()
Definition: timer.cpp:34
virtual event_clock_t getTime(event_phase_t phase) const =0
void wakeUpAfterSyncWithCpu()
Definition: timer.cpp:57
void setControlRegister(uint8_t cr)
Definition: timer.cpp:27