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; }
185 inline unsigned int oldRasterY()
187 const int prevRasterY = rasterY - 1;
188 return prevRasterY >= 0 ? prevRasterY : cyclesPerLine - 1;
193 event_context.
cancel(*
this);
200 inline void checkVblank()
203 if (rasterY == (maxRasters - 1))
209 if (rasterY == FIRST_DMA_LINE
210 && !areBadLinesEnabled
213 areBadLinesEnabled =
true;
217 if (rasterY == LAST_DMA_LINE)
219 areBadLinesEnabled =
false;
227 rasterYIRQEdgeDetector();
238 rasterYIRQEdgeDetector();
240 if (lpAsserted && lp.
retrigger(lineCycle, rasterY))
242 activateIRQFlag(IRQ_LIGHTPEN);
251 inline void startDma()
253 if (sprites.
isDma(0x01 << n))
263 if (!sprites.
isDma(0x06 << n))
270 inline void startBadline()
281 virtual void interrupt (
bool state) = 0;
282 virtual void setBA (
bool state) = 0;
290 uint8_t
read(uint_least8_t addr);
300 void write(uint_least8_t addr, uint8_t data);
320 static const char *credits() {
return credit; }
329 inline void MOS656X::startDma<0>()
331 setBA(!sprites.
isDma(0x01));
338 inline void MOS656X::endDma<7>()
void untrigger()
Definition: lightpen.h:133
model_t
Definition: mos656x.h:39
void event()
Definition: mos656x.cpp:246
PAL-N.
Definition: mos656x.h:44
bool isDma(unsigned int val)
Definition: sprites.h:159
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