vdp, fix for 68k access timing

This commit is contained in:
kub 2020-12-12 17:29:31 +01:00
parent 1613ec6c30
commit dda72beae4
3 changed files with 47 additions and 35 deletions

View file

@ -75,6 +75,11 @@ static struct VdpFIFO { // XXX this must go into save file!
enum { FQ_BYTE = 1, FQ_BGDMA = 2, FQ_FGDMA = 4 }; // queue flags, NB: BYTE = 1!
// NB must limit cyc2sl to table size in case 68k overdraws its aim. That can
// happen if the last insn is a blocking acess to VDP, or for exceptions (e.g.irq)
#define Cyc2Sl(vf,lc) ((lc) < 256*2 ? vf->fifo_cyc2sl[(lc)>>1] : vf->fifo_cyc2sl[255])
#define Sl2Cyc(vf,sl) (vf->fifo_sl2cyc[sl]*2)
// do the FIFO math
static __inline int AdvanceFIFOEntry(struct VdpFIFO *vf, struct PicoVideo *pv, int slots)
{
@ -140,7 +145,7 @@ void PicoVideoFIFOSync(int cycles)
int slots, done;
// calculate #slots since last executed slot
slots = vf->fifo_cyc2sl[cycles>>1] - vf->fifo_slot;
slots = Cyc2Sl(vf, cycles) - vf->fifo_slot;
// advance FIFO queue by #done slots
done = slots;
@ -176,7 +181,7 @@ static int PicoVideoFIFODrain(int level, int cycles, int bgdma)
cycles = 488;
} else {
// advance FIFO to target slot and CPU to cycles at that slot
cycles = vf->fifo_sl2cyc[slot]<<1;
cycles = Sl2Cyc(vf, slot);
}
if (slot > vf->fifo_slot) {
AdvanceFIFOEntry(vf, pv, slot - vf->fifo_slot);
@ -210,8 +215,8 @@ static int PicoVideoFIFORead(void)
pv->status |= PVS_CPURD; // target slot is in later scanline
else {
// use next VDP access slot for reading, block 68k until then
vf->fifo_slot = vf->fifo_cyc2sl[lc>>1] + 1;
burn += (vf->fifo_sl2cyc[vf->fifo_slot]<<1) - lc;
vf->fifo_slot = Cyc2Sl(vf, lc) + 1;
burn += Sl2Cyc(vf, vf->fifo_slot) - lc;
}
return burn;
@ -259,7 +264,7 @@ int PicoVideoFIFOWrite(int count, int flags, unsigned sr_mask,unsigned sr_flags)
// update FIFO state if it was empty
if (!(pv->status & PVS_FIFORUN)) {
vf->fifo_slot = vf->fifo_cyc2sl[(lc+8)>>1]; // FIFO latency ~3 vdp slots
vf->fifo_slot = Cyc2Sl(vf, lc+8); // FIFO latency ~3 vdp slots
pv->status |= PVS_FIFORUN;
pv->fifo_cnt = count << (flags & FQ_BYTE);
}
@ -312,8 +317,8 @@ void PicoVideoFIFOMode(int active, int h40)
vf->fifo_cyc2sl = vdpcyc2sl[active][h40];
vf->fifo_sl2cyc = vdpsl2cyc[active][h40];
// recalculate FIFO slot for new mode
vf->fifo_slot = vf->fifo_cyc2sl[lc>>1]-1;
vf->fifo_maxslot = vf->fifo_cyc2sl[488>>1];
vf->fifo_slot = Cyc2Sl(vf, lc)-1;
vf->fifo_maxslot = Cyc2Sl(vf, 488);
}