28 #include "sidplayfp/event.h"
29 #include "sidplayfp/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;
74 event_clock_t ciaEventPauseTime;
94 uint8_t lastControlValue;
111 void cycleSkippingEvent();
123 inline void reschedule();
133 virtual void underFlow() =0;
138 virtual void serialPort() {};
150 m_cycleSkippingEvent(
"Skip CIA clock decrement cycles", *this, &
Timer::cycleSkippingEvent),
151 event_context(*context),
223 inline uint_least16_t
getTimer()
const {
return timer; }
231 inline bool getPb(uint8_t reg)
const {
return (reg & 0x04) ? pbToggle : (
state & CIAT_OUT); }
234 void Timer::reschedule()
245 const int_least32_t unwanted = CIAT_OUT | CIAT_CR_FLOAD | CIAT_LOAD1 | CIAT_LOAD;
246 if ((
state & unwanted) != 0)
252 if ((
state & CIAT_COUNT3) != 0)
257 const int_least32_t wanted = CIAT_CR_START | CIAT_PHI2IN | CIAT_COUNT2 | CIAT_COUNT3;
258 if (timer > 2 && (
state & wanted) == wanted)
263 ciaEventPauseTime = event_context.
getTime(EVENT_CLOCK_PHI1) + 1;
265 event_context.
schedule(m_cycleSkippingEvent, timer - 1);
276 const int_least32_t unwanted1 = CIAT_CR_START | CIAT_PHI2IN;
277 const int_least32_t unwanted2 = CIAT_CR_START | CIAT_STEP;
279 if ((
state & unwanted1) == unwanted1
280 || (
state & unwanted2) == unwanted2)
286 ciaEventPauseTime = -1;
Definition: mos6526.h:102
void reset()
Definition: timer.cpp:128
void latchLo(uint8_t data)
Definition: timer.cpp:139
void setPbToggle(bool state)
Definition: timer.h:209
bool getPb(uint8_t reg) const
Definition: timer.h:231
Timer(const char *name, EventContext *context, MOS6526 *parent)
Definition: timer.h:148
int_least32_t getState() const
Definition: timer.h:216
MOS6526 *const parent
Definition: timer.h:100
virtual void schedule(Event &event, event_clock_t cycles, event_phase_t phase)=0
int_least32_t state
Definition: timer.h:105
uint_least16_t getTimer() const
Definition: timer.h:223
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