X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=Pico%2FVideoPort.c;h=a4fe3c88bf740add99aa09a8df6de847ca64d839;hb=e5f426aa2e86d56357b8af2795e73cc0c9b17e8f;hp=024cf6f4e3dc76d82866c51ea7d0d2ae07425a6b;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/VideoPort.c b/Pico/VideoPort.c index 024cf6f..a4fe3c8 100644 --- a/Pico/VideoPort.c +++ b/Pico/VideoPort.c @@ -1,20 +1,26 @@ // This is part of Pico Library // (c) Copyright 2004 Dave, All rights reserved. -// (c) Copyright 2006 notaz, All rights reserved. +// (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. #include "PicoInt.h" +#include "cd/gfx_cd.h" extern const unsigned char hcounts_32[]; extern const unsigned char hcounts_40[]; extern const unsigned short vcounts[]; extern int rendstatus; +#ifndef UTYPES_DEFINED +typedef unsigned char u8; typedef unsigned short u16; +typedef unsigned int u32; +#define UTYPES_DEFINED +#endif static __inline void AutoIncrement() @@ -53,29 +59,11 @@ static unsigned int VideoRead() case 8: d=Pico.cram [a&0x003f]; break; case 4: d=Pico.vsram[a&0x003f]; break; } - + AutoIncrement(); return d; } -// calculate the number of cycles 68k->VDP dma operation would take -static int DmaSlowBurn(int len) -{ - // test: Legend of Galahad, Time Killers - int burn,maxlen,line=Pico.m.scanline; - - if(line == -1) line=vcounts[SekCyclesDone()>>8]; - maxlen=(224-line)*18; - if(len <= maxlen) - burn = len*(((488<<8)/18))>>8; - else { - burn = maxlen*(((488<<8)/18))>>8; - burn += (len-maxlen)*(((488<<8)/180))>>8; - } - - return burn; -} - static int GetDmaLength() { struct PicoVideo *pvid=&Pico.video; @@ -93,58 +81,108 @@ static void DmaSlow(int len) u16 *pd=0, *pdend, *r; unsigned int a=Pico.video.addr, a2, d; unsigned char inc=Pico.video.reg[0xf]; - unsigned int source, burn; + unsigned int source; source =Pico.video.reg[0x15]<<1; source|=Pico.video.reg[0x16]<<9; source|=Pico.video.reg[0x17]<<17; - //dprintf("DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i|%i]", Pico.video.type, source, a, len, inc, - // (Pico.video.status&8)||!(Pico.video.reg[1]&0x40), Pico.m.scanline, SekCyclesDone()); + dprintf("DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i|%i] @ %x", + Pico.video.type, source, a, len, inc, (Pico.video.status&8)||!(Pico.video.reg[1]&0x40), + Pico.m.scanline, SekCyclesDone(), SekPc); + + if(Pico.m.scanline != -1) { + Pico.m.dma_bytes += len; + if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCyclesBurn(CheckDMA()); + else SekSetCyclesLeftNoMCD(SekCyclesLeftNoMCD - CheckDMA()); + } else { + // be approximate in non-accurate mode + SekSetCyclesLeft(SekCyclesLeft - (len*(((488<<8)/167))>>8)); + } - if ((source&0xe00000)==0xe00000) { pd=(u16 *)(Pico.ram+(source&0xfffe)); pdend=(u16 *)(Pico.ram+0x10000); } // Ram - else if(sources68k_regs[3]); + if(source<0x20000) { // Bios area + pd=(u16 *)(Pico_mcd->bios+(source&~1)); + pdend=(u16 *)(Pico_mcd->bios+0x20000); + } else if ((source&0xfc0000)==0x200000) { // Word Ram + source -= 2; + if (!(Pico_mcd->s68k_regs[3]&4)) { // 2M mode + pd=(u16 *)(Pico_mcd->word_ram2M+(source&0x3fffe)); + pdend=(u16 *)(Pico_mcd->word_ram2M+0x40000); + } else { + if (source < 0x220000) { // 1M mode + int bank = Pico_mcd->s68k_regs[3]&1; + pd=(u16 *)(Pico_mcd->word_ram1M[bank]+(source&0x1fffe)); + pdend=(u16 *)(Pico_mcd->word_ram1M[bank]+0x20000); + } else { + DmaSlowCell(source, a, len, inc); + return; + } + } + } else if ((source&0xfe0000)==0x020000) { // Prg Ram + u8 *prg_ram = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; + pd=(u16 *)(prg_ram+(source&0x1fffe)); + pdend=(u16 *)(prg_ram+0x20000); + } else { + dprintf("DmaSlow FIXME: unsupported src"); + return; + } + } else { + if(source>8); // very approximate - if(!(Pico.video.status&8)) burn+=burn>>1; // a hack for Legend of Galahad - } else burn = DmaSlowBurn(len); - SekCyclesBurn(burn); - if(!(Pico.video.status&8)) - SekEndRun(0); - //dprintf("DmaSlow burn: %i @ %06x", burn, SekPc); + // overflow protection, might break something.. + if (len > pdend - pd) { + len = pdend - pd; + dprintf("DmaSlow overflow"); + } switch (Pico.video.type) { case 1: // vram r = Pico.vram; - for(; len; len--) + if (inc == 2 && !(a&1) && a+len*2 < 0x10000) { - d=*pd++; - if(a&1) d=(d<<8)|(d>>8); - r[a>>1] = (u16)d; // will drop the upper bits - // AutoIncrement - a=(u16)(a+inc); - // didn't src overlap? - if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM + // most used DMA mode + memcpy16(r + (a>>1), pd, len); + a += len*2; + } + else + { + for(; len; len--) + { + d=*pd++; + if(a&1) d=(d<<8)|(d>>8); + r[a>>1] = (u16)d; // will drop the upper bits + // AutoIncrement + a=(u16)(a+inc); + // didn't src overlap? + //if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM + } } rendstatus|=0x10; break; - + case 3: // cram - //dprintf("DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i|%i]", Pico.video.type, source, a, len, inc, - // (Pico.video.status&8)||!(Pico.video.reg[1]&0x40), Pico.m.scanline, SekCyclesDone()); Pico.m.dirtyPal = 1; r = Pico.cram; for(a2=a&0x7f; len; len--) { - r[a2>>1] = (u16)*pd++;; // bit 0 is ignored + r[a2>>1] = (u16)*pd++; // bit 0 is ignored // AutoIncrement a2+=inc; // didn't src overlap? - if(pd >= pdend) pd-=0x8000; + //if(pd >= pdend) pd-=0x8000; // good dest? if(a2 >= 0x80) break; // Todds Adventures in Slime World / Andre Agassi tennis } @@ -159,7 +197,7 @@ static void DmaSlow(int len) // AutoIncrement a2+=inc; // didn't src overlap? - if(pd >= pdend) pd-=0x8000; + //if(pd >= pdend) pd-=0x8000; // good dest? if(a2 >= 0x80) break; } @@ -177,7 +215,11 @@ static void DmaCopy(int len) unsigned char *vrs; unsigned char inc=Pico.video.reg[0xf]; int source; - //dprintf("DmaCopy len %i [%i|%i]", len, Pico.m.scanline, SekCyclesDone()); + dprintf("DmaCopy len %i [%i|%i]", len, Pico.m.scanline, SekCyclesDone()); + + Pico.m.dma_bytes += len; + if(Pico.m.scanline != -1) + Pico.video.status|=2; // dma busy source =Pico.video.reg[0x15]; source|=Pico.video.reg[0x16]<<8; @@ -205,9 +247,13 @@ static void DmaFill(int data) unsigned char *vr=(unsigned char *) Pico.vram; unsigned char high = (unsigned char) (data >> 8); unsigned char inc=Pico.video.reg[0xf]; - + len=GetDmaLength(); - //dprintf("DmaFill len %i inc %i [%i|%i]", len, inc, Pico.m.scanline, SekCyclesDone()); + dprintf("DmaFill len %i inc %i [%i|%i]", len, inc, Pico.m.scanline, SekCyclesDone()); + + Pico.m.dma_bytes += len; + if(Pico.m.scanline != -1) + Pico.video.status|=2; // dma busy (in accurate mode) // from Charles MacDonald's genvdp.txt: // Write lower byte to address specified @@ -266,14 +312,14 @@ static void CommandChange() if (cmd&0x80) CommandDma(); } -void PicoVideoWrite(unsigned int a,unsigned short d) +PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d) { struct PicoVideo *pvid=&Pico.video; a&=0x1c; if (a==0x00) // Data port 0 or 2 - { + { if (pvid->pending) CommandChange(); pvid->pending=0; @@ -304,8 +350,8 @@ void PicoVideoWrite(unsigned int a,unsigned short d) { // Register write: int num=(d>>8)&0x1f; - //if(num==00) dprintf("hint_onoff: %i->%i [%i|%i] pend=%i @ %06x", (pvid->reg[0]&0x10)>>4, (d&0x10)>>4, Pico.m.scanline, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc); - //if(num==01) dprintf("vint_onoff: %i->%i [%i|%i] pend=%i @ %06x", (pvid->reg[1]&0x20)>>5, (d&0x20)>>5, Pico.m.scanline, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc); + if(num==00) dprintf("hint_onoff: %i->%i [%i|%i] pend=%i @ %06x", (pvid->reg[0]&0x10)>>4, (d&0x10)>>4, Pico.m.scanline, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc); + if(num==01) dprintf("vint_onoff: %i->%i [%i|%i] pend=%i @ %06x", (pvid->reg[1]&0x20)>>5, (d&0x20)>>5, Pico.m.scanline, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc); //if(num==01) dprintf("set_blank: %i @ %06x [%i|%i]", !((d&0x40)>>6), SekPc, Pico.m.scanline, SekCyclesDone()); //if(num==05) dprintf("spr_set: %i @ %06x [%i|%i]", (unsigned char)d, SekPc, Pico.m.scanline, SekCyclesDone()); //if(num==10) dprintf("hint_set: %i @ %06x [%i|%i]", (unsigned char)d, SekPc, Pico.m.scanline, SekCyclesDone()); @@ -348,10 +394,10 @@ void PicoVideoWrite(unsigned int a,unsigned short d) } } -unsigned int PicoVideoRead(unsigned int a) +PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) { unsigned int d=0; - + a&=0x1c; if (a==0x00) // data port @@ -362,12 +408,12 @@ unsigned int PicoVideoRead(unsigned int a) if (a==0x04) // control port { - //dprintf("sr_read @ %06x [%i|%i]", SekPc, Pico.m.scanline, SekCyclesDone()); d=Pico.video.status; if(PicoOpt&0x10) d|=0x0020; // sprite collision (Shadow of the Beast) if(Pico.m.rotate++&8) d|=0x0100; else d|=0x0200; // Toggle fifo full empty (who uses that stuff?) if(!(Pico.video.reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled if(SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs) + // dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone()); Pico.video.pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald) @@ -387,7 +433,7 @@ unsigned int PicoVideoRead(unsigned int a) // |---------------------|--------------------------| // E4 (hc[0x43]==0) 07 B1 // 40 // E8 (hc[0x45]==0) 05 91 // 32 - + // check: Sonic 3D Blast bonus, Cannon Fodder, Chase HQ II, 3 Ninjas kick back, Road Rash 3, Skitchin', Wheel of Fortune if ((a&0x1c)==0x08) { @@ -401,7 +447,7 @@ unsigned int PicoVideoRead(unsigned int a) hc=hcounts_40[lineCycles]; else hc=hcounts_32[lineCycles]; - if(lineCycles > 488-12) d++; // Wheel of Fortune + //if(lineCycles > 488-12) d++; // Wheel of Fortune } else { // get approximate V-Counter d=vcounts[SekCyclesDone()>>8]; @@ -420,7 +466,7 @@ unsigned int PicoVideoRead(unsigned int a) if (d&0xf00) d|= 1; } - //dprintf("hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc); + dprintf("hv: %02x %02x (%i) @ %06x", hc, d, SekCyclesDone(), SekPc); d&=0xff; d<<=8; d|=hc; goto end;