31 #include "sidplayfp/event.h"
32 #include "c64/component.h"
33 #include "EventScheduler.h"
50 unsigned int rasterLines;
51 unsigned int cyclesPerLine;
52 event_clock_t (
MOS656X::*clock)();
56 static const char *credit;
61 static const int IRQ_RASTER = 1 << 0;
64 static const int IRQ_LIGHTPEN = 1 << 3;
67 static const unsigned int FIRST_DMA_LINE = 0x30;
70 static const unsigned int LAST_DMA_LINE = 0xf7;
73 event_clock_t (
MOS656X::*clock)();
75 event_clock_t rasterClk;
81 unsigned int cyclesPerLine;
84 unsigned int maxRasters;
87 unsigned int lineCycle;
96 bool areBadLinesEnabled;
102 bool rasterYIRQCondition;
126 event_clock_t clockPAL();
127 event_clock_t clockNTSC();
128 event_clock_t clockOldNTSC();
133 void handleIrqState();
140 void badLineStateChange() { setBA(!isBadLine); }
147 void rasterYIRQEdgeDetector()
149 const bool oldRasterYIRQCondition = rasterYIRQCondition;
150 rasterYIRQCondition = rasterY == readRasterLineIRQ();
151 if (!oldRasterYIRQCondition && rasterYIRQCondition)
152 activateIRQFlag(IRQ_RASTER);
159 void activateIRQFlag(
int flag)
170 unsigned int readRasterLineIRQ()
const
172 return (regs[0x12] & 0xff) + ((regs[0x11] & 0x80) << 1);
180 bool readDEN()
const {
return (regs[0x11] & 0x10) != 0; }
182 bool evaluateIsBadLine()
const
184 return areBadLinesEnabled
185 && rasterY >= FIRST_DMA_LINE
186 && rasterY <= LAST_DMA_LINE
187 && (rasterY & 7) == yscroll;
193 inline unsigned int oldRasterY()
const
195 return rasterY > 0 ? rasterY - 1 : maxRasters - 1;
200 event_context.
cancel(*
this);
207 inline void checkVblank()
210 if (rasterY == (maxRasters - 1))
216 if (rasterY == FIRST_DMA_LINE
217 && !areBadLinesEnabled
220 areBadLinesEnabled =
true;
224 if (rasterY == LAST_DMA_LINE)
226 areBadLinesEnabled =
false;
234 rasterYIRQEdgeDetector();
237 if (evaluateIsBadLine())
248 rasterYIRQEdgeDetector();
250 if (lpAsserted && lp.
retrigger(lineCycle, rasterY))
252 activateIRQFlag(IRQ_LIGHTPEN);
261 inline void startDma()
263 if (sprites.
isDma(0x01 << n))
273 if (!sprites.
isDma(0x06 << n))
280 inline void startBadline()
291 virtual void interrupt (
bool state) = 0;
292 virtual void setBA (
bool state) = 0;
300 uint8_t
read(uint_least8_t addr);
310 void write(uint_least8_t addr, uint8_t data);
330 static const char *credits() {
return credit; }
339 inline void MOS656X::startDma<0>()
341 setBA(!sprites.
isDma(0x01));
348 inline void MOS656X::endDma<7>()
bool isDma(unsigned int val) const
Definition: sprites.h:159
void untrigger()
Definition: lightpen.h:133
model_t
Definition: mos656x.h:39
void event()
Definition: mos656x.cpp:246
PAL-N.
Definition: mos656x.h:44
Definition: component.h:28
Definition: lightpen.h:30
uint8_t read(uint_least8_t addr)
Definition: mos656x.cpp:102
void clearLightpen()
Definition: mos656x.cpp:679
void write(uint_least8_t addr, uint8_t data)
Definition: mos656x.cpp:138
bool retrigger(unsigned int lineCycle, unsigned int rasterY)
Definition: lightpen.h:88
virtual void cancel(Event &event)=0
OLD NTSC CHIP.
Definition: mos656x.h:41
NTSC-M.
Definition: mos656x.h:42
void triggerLightpen()
Definition: mos656x.cpp:666
PAL-B.
Definition: mos656x.h:43