*/\r
\r
#include "pico_int.h"\r
+#define NEED_DMA_SOURCE\r
#include "memory.h"\r
\r
int line_base_cycles;\r
#define UTYPES_DEFINED\r
#endif\r
\r
-int (*PicoDmaHook)(unsigned int source, int len, unsigned short **srcp, unsigned short **limitp) = NULL;\r
+int (*PicoDmaHook)(unsigned int source, int len, unsigned short **base, unsigned int *mask) = NULL;\r
\r
static __inline void AutoIncrement(void)\r
{\r
// 16-bit words to transfer:\r
len =pvid->reg[0x13];\r
len|=pvid->reg[0x14]<<8;\r
- // Charles MacDonald:\r
- if(!len) len = 0xffff;\r
+ len = ((len - 1) & 0xffff) + 1;\r
return len;\r
}\r
\r
-static void DmaSlow(int len)\r
+static void DmaSlow(int len, unsigned int source)\r
{\r
- u16 *pd=0, *pdend, *r;\r
- unsigned int a=Pico.video.addr, a2, d;\r
- unsigned char inc=Pico.video.reg[0xf];\r
- unsigned int source;\r
-\r
- source =Pico.video.reg[0x15]<<1;\r
- source|=Pico.video.reg[0x16]<<9;\r
- source|=Pico.video.reg[0x17]<<17;\r
+ u32 inc = Pico.video.reg[0xf];\r
+ u32 a = Pico.video.addr;\r
+ u16 *r, *base = NULL;\r
+ u32 mask = 0x1ffff;\r
\r
- elprintf(EL_VDPDMA, "DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%i] @ %06x",\r
+ elprintf(EL_VDPDMA, "DmaSlow[%i] %06x->%04x len %i inc=%i blank %i [%u] @ %06x",\r
Pico.video.type, source, a, len, inc, (Pico.video.status&8)||!(Pico.video.reg[1]&0x40),\r
SekCyclesDone(), SekPc);\r
\r
Pico.m.dma_xfers += len;\r
+ if (Pico.m.dma_xfers < len) // lame 16bit var\r
+ Pico.m.dma_xfers = ~0;\r
SekCyclesBurnRun(CheckDMA());\r
\r
- if ((source&0xe00000)==0xe00000) { // Ram\r
- pd=(u16 *)(Pico.ram+(source&0xfffe));\r
- pdend=(u16 *)(Pico.ram+0x10000);\r
+ if ((source & 0xe00000) == 0xe00000) { // Ram\r
+ base = (u16 *)Pico.ram;\r
+ mask = 0xffff;\r
}\r
else if (PicoAHW & PAHW_MCD)\r
{\r
- elprintf(EL_VDPDMA, "DmaSlow CD, r3=%02x", Pico_mcd->s68k_regs[3]);\r
- if(source<0x20000) { // Bios area\r
- pd=(u16 *)(Pico_mcd->bios+(source&~1));\r
- pdend=(u16 *)(Pico_mcd->bios+0x20000);\r
- } else if ((source&0xfc0000)==0x200000) { // Word Ram\r
- source -= 2;\r
- if (!(Pico_mcd->s68k_regs[3]&4)) { // 2M mode\r
- pd=(u16 *)(Pico_mcd->word_ram2M+(source&0x3fffe));\r
- pdend=(u16 *)(Pico_mcd->word_ram2M+0x40000);\r
+ u8 r3 = Pico_mcd->s68k_regs[3];\r
+ elprintf(EL_VDPDMA, "DmaSlow CD, r3=%02x", r3);\r
+ if (source < 0x20000) { // Bios area\r
+ base = (u16 *)Pico_mcd->bios;\r
+ } else if ((source & 0xfc0000) == 0x200000) { // Word Ram\r
+ if (!(r3 & 4)) { // 2M mode\r
+ base = (u16 *)(Pico_mcd->word_ram2M + (source & 0x20000));\r
} else {\r
if (source < 0x220000) { // 1M mode\r
- int bank = Pico_mcd->s68k_regs[3]&1;\r
- pd=(u16 *)(Pico_mcd->word_ram1M[bank]+(source&0x1fffe));\r
- pdend=(u16 *)(Pico_mcd->word_ram1M[bank]+0x20000);\r
+ int bank = r3 & 1;\r
+ base = (u16 *)(Pico_mcd->word_ram1M[bank]);\r
} else {\r
- DmaSlowCell(source, a, len, inc);\r
+ DmaSlowCell(source - 2, a, len, inc);\r
return;\r
}\r
}\r
- } else if ((source&0xfe0000)==0x020000) { // Prg Ram\r
- u8 *prg_ram = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
- pd=(u16 *)(prg_ram+(source&0x1fffe));\r
- pdend=(u16 *)(prg_ram+0x20000);\r
- } else {\r
- elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow[%i] %06x->%04x: FIXME: unsupported src", Pico.video.type, source, a);\r
- return;\r
+ source -= 2;\r
+ } else if ((source & 0xfe0000) == 0x020000) { // Prg Ram\r
+ base = (u16 *)Pico_mcd->prg_ram_b[r3 >> 6];\r
+ source -= 2; // XXX: test\r
}\r
}\r
else\r
{\r
// if we have DmaHook, let it handle ROM because of possible DMA delay\r
- if (PicoDmaHook && PicoDmaHook(source, len, &pd, &pdend));\r
- else if (source<Pico.romsize) { // Rom\r
- pd=m68k_dma_source(source);\r
- pdend=(u16 *)(Pico.rom+Pico.romsize);\r
- }\r
- if (!pd) {\r
- elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow[%i] %06x->%04x: invalid src", Pico.video.type, source, a);\r
- return;\r
- }\r
+ u32 source2;\r
+ if (PicoDmaHook && (source2 = PicoDmaHook(source, len, &base, &mask)))\r
+ source = source2;\r
+ else // Rom\r
+ base = m68k_dma_source(source);\r
}\r
-\r
- // overflow protection, might break something..\r
- if (len > pdend - pd) {\r
- len = pdend - pd;\r
- elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow overflow");\r
+ if (!base) {\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "DmaSlow[%i] %06x->%04x: invalid src", Pico.video.type, source, a);\r
+ return;\r
}\r
\r
+ // operate in words\r
+ source >>= 1;\r
+ mask >>= 1;\r
+\r
switch (Pico.video.type)\r
{\r
case 1: // vram\r
r = Pico.vram;\r
- if (inc == 2 && !(a&1) && a+len*2 < 0x10000)\r
+ if (inc == 2 && !(a & 1) && a + len * 2 < 0x10000\r
+ && !(((source + len - 1) ^ source) & ~mask))\r
{\r
// most used DMA mode\r
- memcpy16(r + (a>>1), pd, len);\r
- a += len*2;\r
+ memcpy((char *)r + a, base + (source & mask), len * 2);\r
+ a += len * 2;\r
}\r
else\r
{\r
for(; len; len--)\r
{\r
- d=*pd++;\r
- if(a&1) d=(d<<8)|(d>>8);\r
- r[a>>1] = (u16)d; // will drop the upper bits\r
+ u16 d = base[source++ & mask];\r
+ if(a & 1) d=(d<<8)|(d>>8);\r
+ r[a >> 1] = d;\r
// AutoIncrement\r
- a=(u16)(a+inc);\r
- // didn't src overlap?\r
- //if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM\r
+ a = (u16)(a + inc);\r
}\r
}\r
Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
case 3: // cram\r
Pico.m.dirtyPal = 1;\r
r = Pico.cram;\r
- for(a2=a&0x7f; len; len--)\r
+ for (; len; len--)\r
{\r
- r[a2>>1] = (u16)*pd++; // bit 0 is ignored\r
+ r[(a / 2) & 0x3f] = base[source++ & mask];\r
// AutoIncrement\r
- a2+=inc;\r
- // didn't src overlap?\r
- //if(pd >= pdend) pd-=0x8000;\r
- // good dest?\r
- if(a2 >= 0x80) break; // Todds Adventures in Slime World / Andre Agassi tennis\r
+ a += inc;\r
}\r
- a=(a&0xff00)|a2;\r
break;\r
\r
- case 5: // vsram[a&0x003f]=d;\r
+ case 5: // vsram\r
r = Pico.vsram;\r
- for(a2=a&0x7f; len; len--)\r
+ for (; len; len--)\r
{\r
- r[a2>>1] = (u16)*pd++;\r
+ r[(a / 2) & 0x3f] = base[source++ & mask];\r
// AutoIncrement\r
- a2+=inc;\r
- // didn't src overlap?\r
- //if(pd >= pdend) pd-=0x8000;\r
- // good dest?\r
- if(a2 >= 0x80) break;\r
+ a += inc;\r
}\r
- a=(a&0xff00)|a2;\r
break;\r
\r
default:\r
{\r
u16 a=Pico.video.addr;\r
unsigned char *vr = (unsigned char *) Pico.vram;\r
- unsigned char *vrs;\r
unsigned char inc=Pico.video.reg[0xf];\r
int source;\r
elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone());\r
\r
Pico.m.dma_xfers += len;\r
+ if (Pico.m.dma_xfers < len)\r
+ Pico.m.dma_xfers = ~0;\r
Pico.video.status |= 2; // dma busy\r
\r
source =Pico.video.reg[0x15];\r
source|=Pico.video.reg[0x16]<<8;\r
- vrs=vr+source;\r
-\r
- if (source+len > 0x10000) len=0x10000-source; // clip??\r
\r
for (; len; len--)\r
{\r
- vr[a] = *vrs++;\r
+ vr[a] = vr[source++ & 0xffff];\r
// AutoIncrement\r
a=(u16)(a+inc);\r
}\r
Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
}\r
\r
-// check: Contra, Megaman\r
-// note: this is still inaccurate\r
-static void DmaFill(int data)\r
+static NOINLINE void DmaFill(int data)\r
{\r
- int len;\r
unsigned short a=Pico.video.addr;\r
unsigned char *vr=(unsigned char *) Pico.vram;\r
unsigned char high = (unsigned char) (data >> 8);\r
unsigned char inc=Pico.video.reg[0xf];\r
+ int source;\r
+ int len, l;\r
\r
- len=GetDmaLength();\r
+ len = GetDmaLength();\r
elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone());\r
\r
Pico.m.dma_xfers += len;\r
+ if (Pico.m.dma_xfers < len) // lame 16bit var\r
+ Pico.m.dma_xfers = ~0;\r
Pico.video.status |= 2; // dma busy\r
\r
- // from Charles MacDonald's genvdp.txt:\r
- // Write lower byte to address specified\r
- vr[a] = (unsigned char) data;\r
- a=(u16)(a+inc);\r
-\r
- if (!inc) len=1;\r
-\r
- for (; len; len--) {\r
- // Write upper byte to adjacent address\r
- // (here we are byteswapped, so address is already 'adjacent')\r
- vr[a] = high;\r
+ switch (Pico.video.type)\r
+ {\r
+ case 1: // vram\r
+ for (l = len; l; l--) {\r
+ // Write upper byte to adjacent address\r
+ // (here we are byteswapped, so address is already 'adjacent')\r
+ vr[a] = high;\r
\r
- // Increment address register\r
- a=(u16)(a+inc);\r
+ // Increment address register\r
+ a = (u16)(a + inc);\r
+ }\r
+ break;\r
+ case 3: // cram\r
+ case 5: { // vsram\r
+ // TODO: needs fifo; anyone using these?\r
+ static int once;\r
+ if (!once++)\r
+ elprintf(EL_STATUS|EL_ANOMALY|EL_VDPDMA, "TODO: cram/vsram fill");\r
+ }\r
+ default:\r
+ a += len * inc;\r
+ break;\r
}\r
+\r
// remember addr\r
- Pico.video.addr=a;\r
- // update length\r
- Pico.video.reg[0x13] = Pico.video.reg[0x14] = 0; // Dino Dini's Soccer (E) (by Haze)\r
+ Pico.video.addr = a;\r
+ // register update\r
+ Pico.video.reg[0x13] = Pico.video.reg[0x14] = 0;\r
+ source = Pico.video.reg[0x15];\r
+ source |= Pico.video.reg[0x16] << 8;\r
+ source += len;\r
+ Pico.video.reg[0x15] = source;\r
+ Pico.video.reg[0x16] = source >> 8;\r
\r
Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
}\r
\r
-static void CommandDma(void)\r
+static NOINLINE void CommandDma(void)\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
- int len=0,method=0;\r
+ u32 len, method;\r
+ u32 source;\r
\r
if ((pvid->reg[1]&0x10)==0) return; // DMA not enabled\r
\r
- len=GetDmaLength();\r
+ len = GetDmaLength();\r
+ source =Pico.video.reg[0x15];\r
+ source|=Pico.video.reg[0x16] << 8;\r
+ source|=Pico.video.reg[0x17] << 16;\r
\r
method=pvid->reg[0x17]>>6;\r
- if (method< 2) DmaSlow(len); // 68000 to VDP\r
- if (method==3) DmaCopy(len); // VRAM Copy\r
+ if (method < 2)\r
+ DmaSlow(len, source << 1); // 68000 to VDP\r
+ else if (method == 3)\r
+ DmaCopy(len); // VRAM Copy\r
+ else\r
+ return;\r
+\r
+ source += len;\r
+ Pico.video.reg[0x13] = Pico.video.reg[0x14] = 0;\r
+ Pico.video.reg[0x15] = source;\r
+ Pico.video.reg[0x16] = source >> 8;\r
}\r
\r
static void CommandChange(void)\r
addr =(cmd>>16)&0x3fff;\r
addr|=(cmd<<14)&0xc000;\r
pvid->addr=(unsigned short)addr;\r
-\r
- // Check for dma:\r
- if (cmd&0x80) CommandDma();\r
}\r
\r
static void DrawSync(int blank_on)\r
pvid->pending=0;\r
}\r
\r
- // If a DMA fill has been set up, do it\r
- if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)\r
+ // preliminary FIFO emulation for Chaos Engine, The (E)\r
+ if (!(pvid->status&8) && (pvid->reg[1]&0x40) && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display?\r
{\r
- DmaFill(d);\r
- }\r
- else\r
- {\r
- // preliminary FIFO emulation for Chaos Engine, The (E)\r
- if (!(pvid->status&8) && (pvid->reg[1]&0x40) && !(PicoOpt&POPT_DIS_VDP_FIFO)) // active display?\r
- {\r
- pvid->status&=~0x200; // FIFO no longer empty\r
- pvid->lwrite_cnt++;\r
- if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full\r
- if (pvid->lwrite_cnt > 4) {\r
- SekCyclesBurnRun(32); // penalty // 488/12-8\r
- }\r
- elprintf(EL_ASVDP, "VDP data write: %04x [%06x] {%i} #%i @ %06x", d, Pico.video.addr,\r
- Pico.video.type, pvid->lwrite_cnt, SekPc);\r
+ pvid->status&=~0x200; // FIFO no longer empty\r
+ pvid->lwrite_cnt++;\r
+ if (pvid->lwrite_cnt >= 4) pvid->status|=0x100; // FIFO full\r
+ if (pvid->lwrite_cnt > 4) {\r
+ SekCyclesBurnRun(32); // penalty // 488/12-8\r
}\r
- VideoWrite(d);\r
+ elprintf(EL_ASVDP, "VDP data write: %04x [%06x] {%i} #%i @ %06x", d, Pico.video.addr,\r
+ Pico.video.type, pvid->lwrite_cnt, SekPc);\r
}\r
+ VideoWrite(d);\r
+\r
+ if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)\r
+ DmaFill(d);\r
+\r
return;\r
}\r
\r
{\r
if (pvid->pending)\r
{\r
- if (d & 0x80) DrawSync(0); // only need sync for DMA\r
// Low word of command:\r
- pvid->command&=0xffff0000;\r
- pvid->command|=d;\r
- pvid->pending=0;\r
+ pvid->command &= 0xffff0000;\r
+ pvid->command |= d;\r
+ pvid->pending = 0;\r
CommandChange();\r
+ // Check for dma:\r
+ if (d & 0x80) {\r
+ DrawSync(0);\r
+ CommandDma();\r
+ }\r
}\r
else\r
{\r