mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
core, improve vdp save/load
This commit is contained in:
parent
2cd6dfde6f
commit
b72662e224
1 changed files with 22 additions and 18 deletions
|
@ -186,6 +186,7 @@ static struct VdpFIFO { // XXX this must go into save file!
|
||||||
u32 fifo_queue[8], fifo_qx, fifo_ql;
|
u32 fifo_queue[8], fifo_qx, fifo_ql;
|
||||||
int fifo_total; // total# of pending FIFO entries (w/o BGDMA)
|
int fifo_total; // total# of pending FIFO entries (w/o BGDMA)
|
||||||
|
|
||||||
|
int fifo_cnt; // remaining entries in currently active transfer
|
||||||
unsigned short fifo_slot; // last executed slot in current scanline
|
unsigned short fifo_slot; // last executed slot in current scanline
|
||||||
unsigned short fifo_maxslot;// #slots in scanline
|
unsigned short fifo_maxslot;// #slots in scanline
|
||||||
|
|
||||||
|
@ -205,7 +206,7 @@ enum { FQ_BYTE = 1, FQ_BGDMA = 2, FQ_FGDMA = 4 }; // queue flags, NB: BYTE = 1!
|
||||||
static __inline int AdvanceFIFOEntry(struct VdpFIFO *vf, struct PicoVideo *pv, int slots)
|
static __inline int AdvanceFIFOEntry(struct VdpFIFO *vf, struct PicoVideo *pv, int slots)
|
||||||
{
|
{
|
||||||
int l = slots, b = vf->fifo_queue[vf->fifo_qx] & FQ_BYTE;
|
int l = slots, b = vf->fifo_queue[vf->fifo_qx] & FQ_BYTE;
|
||||||
int cnt = pv->fifo_cnt;
|
int cnt = vf->fifo_cnt;
|
||||||
|
|
||||||
// advance currently active FIFO entry
|
// advance currently active FIFO entry
|
||||||
if (l > cnt)
|
if (l > cnt)
|
||||||
|
@ -213,7 +214,7 @@ static __inline int AdvanceFIFOEntry(struct VdpFIFO *vf, struct PicoVideo *pv, i
|
||||||
if (!(vf->fifo_queue[vf->fifo_qx] & FQ_BGDMA))
|
if (!(vf->fifo_queue[vf->fifo_qx] & FQ_BGDMA))
|
||||||
vf->fifo_total -= ((cnt & b) + l) >> b;
|
vf->fifo_total -= ((cnt & b) + l) >> b;
|
||||||
cnt -= l;
|
cnt -= l;
|
||||||
pv->fifo_cnt = cnt;
|
vf->fifo_cnt = cnt;
|
||||||
|
|
||||||
// if entry has been processed...
|
// if entry has been processed...
|
||||||
if (cnt == 0) {
|
if (cnt == 0) {
|
||||||
|
@ -223,7 +224,7 @@ static __inline int AdvanceFIFOEntry(struct VdpFIFO *vf, struct PicoVideo *pv, i
|
||||||
// start processing for next entry if there is one
|
// start processing for next entry if there is one
|
||||||
if (vf->fifo_ql) {
|
if (vf->fifo_ql) {
|
||||||
b = vf->fifo_queue[vf->fifo_qx] & FQ_BYTE;
|
b = vf->fifo_queue[vf->fifo_qx] & FQ_BYTE;
|
||||||
pv->fifo_cnt = (vf->fifo_queue[vf->fifo_qx] >> 3) << b;
|
vf->fifo_cnt = (vf->fifo_queue[vf->fifo_qx] >> 3) << b;
|
||||||
} else { // FIFO empty
|
} else { // FIFO empty
|
||||||
pv->status &= ~PVS_FIFORUN;
|
pv->status &= ~PVS_FIFORUN;
|
||||||
vf->fifo_total = 0;
|
vf->fifo_total = 0;
|
||||||
|
@ -244,7 +245,7 @@ static __inline void SetFIFOState(struct VdpFIFO *vf, struct PicoVideo *pv)
|
||||||
cmd &= ~0x80;
|
cmd &= ~0x80;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pv->fifo_cnt == 0) {
|
if (vf->fifo_cnt == 0) {
|
||||||
st &= ~PVS_CPURD;
|
st &= ~PVS_CPURD;
|
||||||
// terminate DMA if applicable
|
// terminate DMA if applicable
|
||||||
if (!(st & (PVS_FIFORUN|PVS_DMAFILL))) {
|
if (!(st & (PVS_FIFORUN|PVS_DMAFILL))) {
|
||||||
|
@ -268,7 +269,7 @@ void PicoVideoFIFOSync(int cycles)
|
||||||
|
|
||||||
// advance FIFO queue by #done slots
|
// advance FIFO queue by #done slots
|
||||||
done = slots;
|
done = slots;
|
||||||
while (done > 0 && pv->fifo_cnt) {
|
while (done > 0 && vf->fifo_cnt) {
|
||||||
int l = AdvanceFIFOEntry(vf, pv, done);
|
int l = AdvanceFIFOEntry(vf, pv, done);
|
||||||
vf->fifo_slot += l;
|
vf->fifo_slot += l;
|
||||||
done -= l;
|
done -= l;
|
||||||
|
@ -291,8 +292,8 @@ static int PicoVideoFIFODrain(int level, int cycles, int bgdma)
|
||||||
while (vf->fifo_slot < vf->fifo_maxslot &&
|
while (vf->fifo_slot < vf->fifo_maxslot &&
|
||||||
vf->fifo_ql && ((vf->fifo_total > level) | bd)) {
|
vf->fifo_ql && ((vf->fifo_total > level) | bd)) {
|
||||||
int b = vf->fifo_queue[vf->fifo_qx] & FQ_BYTE;
|
int b = vf->fifo_queue[vf->fifo_qx] & FQ_BYTE;
|
||||||
int cnt = bd ? pv->fifo_cnt : ((vf->fifo_total-level)<<b) - (pv->fifo_cnt&b);
|
int cnt = bd ? vf->fifo_cnt : ((vf->fifo_total-level)<<b) - (vf->fifo_cnt&b);
|
||||||
int slot = (pv->fifo_cnt<cnt ? pv->fifo_cnt:cnt) + vf->fifo_slot;
|
int slot = (vf->fifo_cnt<cnt ? vf->fifo_cnt:cnt) + vf->fifo_slot;
|
||||||
|
|
||||||
if (slot > vf->fifo_maxslot) {
|
if (slot > vf->fifo_maxslot) {
|
||||||
// target slot in later scanline, advance to eol
|
// target slot in later scanline, advance to eol
|
||||||
|
@ -323,14 +324,14 @@ static int PicoVideoFIFORead(void)
|
||||||
int lc = SekCyclesDone()-Pico.t.m68c_line_start;
|
int lc = SekCyclesDone()-Pico.t.m68c_line_start;
|
||||||
int burn = 0;
|
int burn = 0;
|
||||||
|
|
||||||
if (pv->fifo_cnt) {
|
if (vf->fifo_cnt) {
|
||||||
PicoVideoFIFOSync(lc);
|
PicoVideoFIFOSync(lc);
|
||||||
// advance FIFO and CPU until FIFO is empty
|
// advance FIFO and CPU until FIFO is empty
|
||||||
burn = PicoVideoFIFODrain(0, lc, FQ_BGDMA);
|
burn = PicoVideoFIFODrain(0, lc, FQ_BGDMA);
|
||||||
lc += burn;
|
lc += burn;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pv->fifo_cnt)
|
if (vf->fifo_cnt)
|
||||||
pv->status |= PVS_CPURD; // target slot is in later scanline
|
pv->status |= PVS_CPURD; // target slot is in later scanline
|
||||||
else {
|
else {
|
||||||
// use next VDP access slot for reading, block 68k until then
|
// use next VDP access slot for reading, block 68k until then
|
||||||
|
@ -349,7 +350,7 @@ int PicoVideoFIFOWrite(int count, int flags, unsigned sr_mask,unsigned sr_flags)
|
||||||
int lc = SekCyclesDone()-Pico.t.m68c_line_start;
|
int lc = SekCyclesDone()-Pico.t.m68c_line_start;
|
||||||
int burn = 0;
|
int burn = 0;
|
||||||
|
|
||||||
if (pv->fifo_cnt)
|
if (vf->fifo_cnt)
|
||||||
PicoVideoFIFOSync(lc);
|
PicoVideoFIFOSync(lc);
|
||||||
pv->status = (pv->status & ~sr_mask) | sr_flags;
|
pv->status = (pv->status & ~sr_mask) | sr_flags;
|
||||||
|
|
||||||
|
@ -361,7 +362,7 @@ int PicoVideoFIFOWrite(int count, int flags, unsigned sr_mask,unsigned sr_flags)
|
||||||
// XXX if interrupting a DMA fill, fill data changes
|
// XXX if interrupting a DMA fill, fill data changes
|
||||||
if (x == vf->fifo_qx) { // overtaking to queue head?
|
if (x == vf->fifo_qx) { // overtaking to queue head?
|
||||||
int f = vf->fifo_queue[x] & 7;
|
int f = vf->fifo_queue[x] & 7;
|
||||||
vf->fifo_queue[x] = (pv->fifo_cnt >> (f & FQ_BYTE) << 3) | f;
|
vf->fifo_queue[x] = (vf->fifo_cnt >> (f & FQ_BYTE) << 3) | f;
|
||||||
pv->status &= ~PVS_FIFORUN;
|
pv->status &= ~PVS_FIFORUN;
|
||||||
}
|
}
|
||||||
// push background DMA back
|
// push background DMA back
|
||||||
|
@ -373,7 +374,7 @@ int PicoVideoFIFOWrite(int count, int flags, unsigned sr_mask,unsigned sr_flags)
|
||||||
// amalgamate entries if of same type
|
// amalgamate entries if of same type
|
||||||
vf->fifo_queue[x] += (count << 3);
|
vf->fifo_queue[x] += (count << 3);
|
||||||
if (x == vf->fifo_qx)
|
if (x == vf->fifo_qx)
|
||||||
pv->fifo_cnt += count << (flags & FQ_BYTE);
|
vf->fifo_cnt += count << (flags & FQ_BYTE);
|
||||||
} else {
|
} else {
|
||||||
// create new xfer queue entry
|
// create new xfer queue entry
|
||||||
vf->fifo_ql ++;
|
vf->fifo_ql ++;
|
||||||
|
@ -385,7 +386,7 @@ int PicoVideoFIFOWrite(int count, int flags, unsigned sr_mask,unsigned sr_flags)
|
||||||
if (!(pv->status & PVS_FIFORUN)) {
|
if (!(pv->status & PVS_FIFORUN)) {
|
||||||
vf->fifo_slot = Cyc2Sl(vf, lc+7); // FIFO latency ~3 vdp slots
|
vf->fifo_slot = Cyc2Sl(vf, lc+7); // FIFO latency ~3 vdp slots
|
||||||
pv->status |= PVS_FIFORUN;
|
pv->status |= PVS_FIFORUN;
|
||||||
pv->fifo_cnt = count << (flags & FQ_BYTE);
|
vf->fifo_cnt = count << (flags & FQ_BYTE);
|
||||||
}
|
}
|
||||||
if (!(flags & FQ_BGDMA))
|
if (!(flags & FQ_BGDMA))
|
||||||
vf->fifo_total += count;
|
vf->fifo_total += count;
|
||||||
|
@ -760,7 +761,7 @@ static NOINLINE void DmaFill(int data)
|
||||||
|
|
||||||
static NOINLINE void CommandDma(void)
|
static NOINLINE void CommandDma(void)
|
||||||
{
|
{
|
||||||
struct PicoVideo *pvid=&Pico.video;
|
struct PicoVideo *pvid = &Pico.video;
|
||||||
u32 len, method;
|
u32 len, method;
|
||||||
u32 source;
|
u32 source;
|
||||||
|
|
||||||
|
@ -768,7 +769,7 @@ static NOINLINE void CommandDma(void)
|
||||||
if (pvid->status & SR_DMA) {
|
if (pvid->status & SR_DMA) {
|
||||||
elprintf(EL_VDPDMA, "Dma overlap, left=%d @ %06x",
|
elprintf(EL_VDPDMA, "Dma overlap, left=%d @ %06x",
|
||||||
VdpFIFO.fifo_total, SekPc);
|
VdpFIFO.fifo_total, SekPc);
|
||||||
pvid->fifo_cnt = VdpFIFO.fifo_total = VdpFIFO.fifo_ql = 0;
|
VdpFIFO.fifo_cnt = VdpFIFO.fifo_total = VdpFIFO.fifo_ql = 0;
|
||||||
pvid->status &= ~(PVS_FIFORUN|PVS_DMAFILL);
|
pvid->status &= ~(PVS_FIFORUN|PVS_DMAFILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1137,6 +1138,7 @@ void PicoVideoSave(void)
|
||||||
int l, x;
|
int l, x;
|
||||||
|
|
||||||
// account for all outstanding xfers XXX kludge, entry attr's not saved
|
// account for all outstanding xfers XXX kludge, entry attr's not saved
|
||||||
|
pv->fifo_cnt = vf->fifo_cnt;
|
||||||
for (l = vf->fifo_ql, x = vf->fifo_qx + l-1; l > 1; l--, x--)
|
for (l = vf->fifo_ql, x = vf->fifo_qx + l-1; l > 1; l--, x--)
|
||||||
pv->fifo_cnt += (vf->fifo_queue[x&7] >> 3) << (vf->fifo_queue[x&7] & FQ_BYTE);
|
pv->fifo_cnt += (vf->fifo_queue[x&7] >> 3) << (vf->fifo_queue[x&7] & FQ_BYTE);
|
||||||
}
|
}
|
||||||
|
@ -1154,14 +1156,16 @@ void PicoVideoLoad(void)
|
||||||
Pico.m.dma_xfers = 0;
|
Pico.m.dma_xfers = 0;
|
||||||
}
|
}
|
||||||
// make an entry in the FIFO if there are outstanding transfers
|
// make an entry in the FIFO if there are outstanding transfers
|
||||||
vf->fifo_ql = vf->fifo_total = 0;
|
vf->fifo_ql = vf->fifo_qx = vf->fifo_total = 0;
|
||||||
if (pv->fifo_cnt) {
|
if (pv->fifo_cnt) {
|
||||||
|
int wc = (pv->fifo_cnt + b) >> b;
|
||||||
pv->status |= PVS_FIFORUN|PVS_CPUWR;
|
pv->status |= PVS_FIFORUN|PVS_CPUWR;
|
||||||
|
vf->fifo_cnt = pv->fifo_cnt;
|
||||||
if (!(pv->status & PVS_DMABG))
|
if (!(pv->status & PVS_DMABG))
|
||||||
vf->fifo_total = (pv->fifo_cnt + b) >> b;
|
vf->fifo_total = wc;
|
||||||
if ((pv->status & SR_DMA) && !(pv->status & PVS_DMAFILL))
|
if ((pv->status & SR_DMA) && !(pv->status & PVS_DMAFILL))
|
||||||
b |= (pv->status & PVS_DMABG) ? FQ_BGDMA : FQ_FGDMA;
|
b |= (pv->status & PVS_DMABG) ? FQ_BGDMA : FQ_FGDMA;
|
||||||
vf->fifo_queue[vf->fifo_qx] = (vf->fifo_total << 3) | b;
|
vf->fifo_queue[vf->fifo_qx] = (wc << 3) | b;
|
||||||
vf->fifo_ql = 1;
|
vf->fifo_ql = 1;
|
||||||
}
|
}
|
||||||
PicoVideoCacheSAT();
|
PicoVideoCacheSAT();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue