X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fvideoport.c;h=b5e3f86ceaa791da564c35e6398c6dec8dd6750e;hb=0e4bde9b2d981c264343aa66809f2f26ce7843c8;hp=fe96139f05c7158582c9a6593e5fe05ab09388f3;hpb=e0bcb7a90d06b295b1ca989b6ad70412912cca5b;p=picodrive.git diff --git a/pico/videoport.c b/pico/videoport.c index fe96139..b5e3f86 100644 --- a/pico/videoport.c +++ b/pico/videoport.c @@ -11,7 +11,6 @@ #define NEED_DMA_SOURCE #include "memory.h" -int line_base_cycles; extern const unsigned char hcounts_32[]; extern const unsigned char hcounts_40[]; @@ -33,23 +32,24 @@ static NOINLINE void VideoWrite128(u32 a, u16 d) { // nasty a = ((a & 2) >> 1) | ((a & 0x400) >> 9) | (a & 0x3FC) | ((a & 0x1F800) >> 1); - ((u8 *)Pico.vram)[a] = d; + ((u8 *)PicoMem.vram)[a] = d; } static void VideoWrite(u16 d) { - unsigned int a=Pico.video.addr; + unsigned int a = Pico.video.addr; switch (Pico.video.type) { - case 1: if(a&1) d=(u16)((d<<8)|(d>>8)); // If address is odd, bytes are swapped (which game needs this?) - Pico.vram [(a>>1)&0x7fff]=d; + case 1: if (a & 1) + d = (u16)((d << 8) | (d >> 8)); + PicoMem.vram [(a >> 1) & 0x7fff] = d; if (a - ((unsigned)(Pico.video.reg[5]&0x7f) << 9) < 0x400) Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES; break; case 3: Pico.m.dirtyPal = 1; - Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike) - case 5: Pico.vsram[(a>>1)&0x003f]=d; break; + PicoMem.cram [(a >> 1) & 0x3f] = d; break; + case 5: PicoMem.vsram[(a >> 1) & 0x3f] = d; break; case 0x81: a |= Pico.video.addr_u << 16; VideoWrite128(a, d); @@ -68,9 +68,9 @@ static unsigned int VideoRead(void) switch (Pico.video.type) { - case 0: d=Pico.vram [a&0x7fff]; break; - case 8: d=Pico.cram [a&0x003f]; break; - case 4: d=Pico.vsram[a&0x003f]; break; + case 0: d=PicoMem.vram [a & 0x7fff]; break; + case 8: d=PicoMem.cram [a & 0x003f]; break; + case 4: d=PicoMem.vsram[a & 0x003f]; break; default:elprintf(EL_ANOMALY, "VDP read with bad type %i", Pico.video.type); break; } @@ -106,7 +106,7 @@ static void DmaSlow(int len, unsigned int source) SekCyclesBurnRun(CheckDMA()); if ((source & 0xe00000) == 0xe00000) { // Ram - base = (u16 *)Pico.ram; + base = (u16 *)PicoMem.ram; mask = 0xffff; } else if (PicoAHW & PAHW_MCD) @@ -154,7 +154,7 @@ static void DmaSlow(int len, unsigned int source) switch (Pico.video.type) { case 1: // vram - r = Pico.vram; + r = PicoMem.vram; if (inc == 2 && !(a & 1) && a + len * 2 < 0x10000 && !(((source + len - 1) ^ source) & ~mask)) { @@ -178,7 +178,7 @@ static void DmaSlow(int len, unsigned int source) case 3: // cram Pico.m.dirtyPal = 1; - r = Pico.cram; + r = PicoMem.cram; for (; len; len--) { r[(a / 2) & 0x3f] = base[source++ & mask]; @@ -188,7 +188,7 @@ static void DmaSlow(int len, unsigned int source) break; case 5: // vsram - r = Pico.vsram; + r = PicoMem.vsram; for (; len; len--) { r[(a / 2) & 0x3f] = base[source++ & mask]; @@ -219,11 +219,11 @@ static void DmaSlow(int len, unsigned int source) static void DmaCopy(int len) { - u16 a=Pico.video.addr; - unsigned char *vr = (unsigned char *) Pico.vram; - unsigned char inc=Pico.video.reg[0xf]; + u16 a = Pico.video.addr; + u8 *vr = (u8 *)PicoMem.vram; + u8 inc = Pico.video.reg[0xf]; int source; - elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone()); + elprintf(EL_VDPDMA, "DmaCopy len %i [%u]", len, SekCyclesDone()); Pico.m.dma_xfers += len; if (Pico.m.dma_xfers < len) @@ -246,15 +246,15 @@ static void DmaCopy(int len) static NOINLINE void DmaFill(int data) { - unsigned short a=Pico.video.addr; - unsigned char *vr=(unsigned char *) Pico.vram; - unsigned char high = (unsigned char) (data >> 8); - unsigned char inc=Pico.video.reg[0xf]; + u16 a = Pico.video.addr; + u8 *vr = (u8 *)PicoMem.vram; + u8 high = (u8)(data >> 8); + u8 inc = Pico.video.reg[0xf]; int source; int len, l; len = GetDmaLength(); - elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone()); + elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%u]", len, inc, SekCyclesDone()); Pico.m.dma_xfers += len; if (Pico.m.dma_xfers < len) // lame 16bit var @@ -357,17 +357,17 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d) { struct PicoVideo *pvid=&Pico.video; - //if (Pico.m.scanline < 224) - // elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x", a, d); - a&=0x1c; + //elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x [%u] @ %06x", + // a, d, SekCyclesDone(), SekPc); + a &= 0x1c; switch (a) { case 0x00: // Data port 0 or 2 // try avoiding the sync.. if (Pico.m.scanline < 224 && (pvid->reg[1]&0x40) && !(!pvid->pending && - ((pvid->command & 0xc00000f0) == 0x40000010 && Pico.vsram[pvid->addr>>1] == d)) + ((pvid->command & 0xc00000f0) == 0x40000010 && PicoMem.vsram[pvid->addr>>1] == d)) ) DrawSync(0); @@ -376,17 +376,14 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d) pvid->pending=0; } - // preliminary FIFO emulation for Chaos Engine, The (E) - if (!(pvid->status&8) && (pvid->reg[1]&0x40) && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display? + if (!(pvid->status & SR_VB) && !(PicoOpt&POPT_DIS_VDP_FIFO)) { - pvid->status&=~0x200; // FIFO no longer empty - pvid->lwrite_cnt++; - if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full - if (pvid->lwrite_cnt > 4) { - SekCyclesBurnRun(32); // penalty // 488/12-8 - } - elprintf(EL_ASVDP, "VDP data write: %04x [%06x] {%i} #%i @ %06x", d, Pico.video.addr, - Pico.video.type, pvid->lwrite_cnt, SekPc); + int use = pvid->type == 1 ? 2 : 1; + pvid->lwrite_cnt -= use; + if (pvid->lwrite_cnt < 0) + SekCyclesLeft = 0; + elprintf(EL_ASVDP, "VDP data write: [%04x] %04x [%u] {%i} #%i @ %06x", + Pico.video.addr, d, SekCyclesDone(), Pico.video.type, pvid->lwrite_cnt, SekPc); } VideoWrite(d); @@ -423,19 +420,22 @@ PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d) return; } - if (num == 1 && !(d&0x40) && SekCyclesDone() - line_base_cycles <= 488-390) + if (num == 1 && !(d&0x40) && SekCyclesDone() - Pico.t.m68c_line_start <= 488-390) blank_on = 1; DrawSync(blank_on); pvid->reg[num]=(unsigned char)d; switch (num) { case 0x00: - elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x10)>>4, + elprintf(EL_INTSW, "hint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x10)>>4, (d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc); goto update_irq; case 0x01: - elprintf(EL_INTSW, "vint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x20)>>5, + elprintf(EL_INTSW, "vint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x20)>>5, (d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc); + if (!(pvid->status & PVS_VB2)) + pvid->status &= ~SR_VB; + pvid->status |= ((d >> 3) ^ SR_VB) & SR_VB; // forced blanking goto update_irq; case 0x05: //elprintf(EL_STATUS, "spritep moved to %04x", (unsigned)(Pico.video.reg[5]&0x7f) << 9); @@ -453,14 +453,15 @@ update_irq: // update IRQ level if (!SekShouldInterrupt()) // hack { - int lines, pints, irq=0; + int lines, pints, irq = 0; lines = (pvid->reg[1] & 0x20) | (pvid->reg[0] & 0x10); - pints = (pvid->pending_ints&lines); + pints = pvid->pending_ints & lines; if (pints & 0x20) irq = 6; else if (pints & 0x10) irq = 4; SekInterrupt(irq); // update line - if (irq) SekEndRun(24); // make it delayed + // this is broken because cost of current insn isn't known here + if (irq) SekEndRun(21); // make it delayed } #endif } @@ -504,26 +505,26 @@ update_irq: } } -PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) +static u32 SrLow(const struct PicoVideo *pv) { - a&=0x1c; - - if (a==0x04) // control port - { - struct PicoVideo *pv=&Pico.video; - unsigned int d; - d=pv->status; - //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast) - if (SekCyclesDone() - line_base_cycles >= 488-88) - d|=0x0004; // H-Blank (Sonic3 vs) + unsigned int c, d = pv->status; - d |= ((pv->reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled - d |= (pv->pending_ints&0x20)<<2; // V-int pending? - if (d&0x100) pv->status&=~0x100; // FIFO no longer full + c = SekCyclesDone() - Pico.t.m68c_line_start - 39; + if (c < 92) + d |= SR_HB; + return d; +} - pv->pending = 0; // ctrl port reads clear write-pending flag (Charles MacDonald) +PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) +{ + a &= 0x1c; - elprintf(EL_SR, "SR read: %04x @ %06x", d, SekPc); + if (a == 0x04) // control port + { + struct PicoVideo *pv = &Pico.video; + unsigned int d = SrLow(pv); + pv->pending = 0; + elprintf(EL_SR, "SR read: %04x [%u] @ %06x", d, SekCyclesDone(), SekPc); return d; } @@ -546,12 +547,12 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) { unsigned int d; - d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME + d = (SekCyclesDone() - Pico.t.m68c_line_start) & 0x1ff; // FIXME if (Pico.video.reg[12]&1) d = hcounts_40[d]; else d = hcounts_32[d]; - elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", d, Pico.video.v_counter, SekCyclesDone(), SekPc); + elprintf(EL_HVCNT, "hv: %02x %02x [%u] @ %06x", d, Pico.video.v_counter, SekCyclesDone(), SekPc); return d | (Pico.video.v_counter << 8); } @@ -563,43 +564,47 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) return 0; } -unsigned int PicoVideoRead8(unsigned int a) +unsigned char PicoVideoRead8DataH(void) { - unsigned int d; - a&=0x1d; + return VideoRead() >> 8; +} - switch (a) - { - case 0: return VideoRead() >> 8; - case 1: return VideoRead() & 0xff; - case 4: // control port/status reg - d = Pico.video.status >> 8; - if (d&1) Pico.video.status&=~0x100; // FIFO no longer full - Pico.video.pending = 0; - elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc); - return d; - case 5: - d = Pico.video.status & 0xff; - //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast) - d |= ((Pico.video.reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled - d |= (Pico.video.pending_ints&0x20)<<2; // V-int pending? - if (SekCyclesDone() - line_base_cycles >= 488-88) d |= 4; // H-Blank - Pico.video.pending = 0; - elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc); - return d; - case 8: // hv counter - elprintf(EL_HVCNT, "vcounter: %02x (%i) @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc); - return Pico.video.v_counter; - case 9: - d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME - if (Pico.video.reg[12]&1) - d = hcounts_40[d]; - else d = hcounts_32[d]; - elprintf(EL_HVCNT, "hcounter: %02x (%i) @ %06x", d, SekCyclesDone(), SekPc); - return d; - } +unsigned char PicoVideoRead8DataL(void) +{ + return VideoRead(); +} - return 0; +unsigned char PicoVideoRead8CtlH(void) +{ + u8 d = (u8)(Pico.video.status >> 8); + Pico.video.pending = 0; + elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc); + return d; +} + +unsigned char PicoVideoRead8CtlL(void) +{ + u8 d = SrLow(&Pico.video); + Pico.video.pending = 0; + elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc); + return d; +} + +unsigned char PicoVideoRead8HV_H(void) +{ + elprintf(EL_HVCNT, "vcounter: %02x [%u] @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc); + return Pico.video.v_counter; +} + +// FIXME: broken +unsigned char PicoVideoRead8HV_L(void) +{ + u32 d = (SekCyclesDone() - Pico.t.m68c_line_start) & 0x1ff; // FIXME + if (Pico.video.reg[12]&1) + d = hcounts_40[d]; + else d = hcounts_32[d]; + elprintf(EL_HVCNT, "hcounter: %02x [%u] @ %06x", d, SekCyclesDone(), SekPc); + return d; } // vim:shiftwidth=2:ts=2:expandtab