-// PicoDrive\r
-\r
-// (c) Copyright 2004 Dave, All rights reserved.\r
-// (c) Copyright 2006-2008, Grazvydas "notaz" Ignotas\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
-\r
+/*\r
+ * PicoDrive\r
+ * (c) Copyright Dave, 2004\r
+ * (C) notaz, 2006-2009\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
\r
#include "pico_int.h"\r
-#include "cd/gfx_cd.h"\r
+#define NEED_DMA_SOURCE\r
+#include "memory.h"\r
\r
extern const unsigned char hcounts_32[];\r
extern const unsigned char hcounts_40[];\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
Pico.video.addr=(unsigned short)(Pico.video.addr+Pico.video.reg[0xf]);\r
}\r
\r
+static NOINLINE void VideoWrite128(u32 a, u16 d)\r
+{\r
+ // nasty\r
+ a = ((a & 2) >> 1) | ((a & 0x400) >> 9) | (a & 0x3FC) | ((a & 0x1F800) >> 1);\r
+ ((u8 *)PicoMem.vram)[a] = d;\r
+}\r
+\r
static void VideoWrite(u16 d)\r
{\r
- unsigned int a=Pico.video.addr;\r
+ unsigned int a = Pico.video.addr;\r
\r
switch (Pico.video.type)\r
{\r
- case 1: if(a&1) d=(u16)((d<<8)|(d>>8)); // If address is odd, bytes are swapped (which game needs this?)\r
- Pico.vram [(a>>1)&0x7fff]=d;\r
+ case 1: if (a & 1)\r
+ d = (u16)((d << 8) | (d >> 8));\r
+ PicoMem.vram [(a >> 1) & 0x7fff] = d;\r
if (a - ((unsigned)(Pico.video.reg[5]&0x7f) << 9) < 0x400)\r
- rendstatus |= PDRAW_DIRTY_SPRITES;\r
+ Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
break;\r
case 3: Pico.m.dirtyPal = 1;\r
- Pico.cram [(a>>1)&0x003f]=d; break; // wraps (Desert Strike)\r
- case 5: Pico.vsram[(a>>1)&0x003f]=d; break;\r
+ PicoMem.cram [(a >> 1) & 0x3f] = d; break;\r
+ case 5: PicoMem.vsram[(a >> 1) & 0x3f] = d; break;\r
+ case 0x81:\r
+ a |= Pico.video.addr_u << 16;\r
+ VideoWrite128(a, d);\r
+ break;\r
//default:elprintf(EL_ANOMALY, "VDP write %04x with bad type %i", d, Pico.video.type); break;\r
}\r
\r
\r
switch (Pico.video.type)\r
{\r
- case 0: d=Pico.vram [a&0x7fff]; break;\r
- case 8: d=Pico.cram [a&0x003f]; break;\r
- case 4: d=Pico.vsram[a&0x003f]; break;\r
+ case 0: d=PicoMem.vram [a & 0x7fff]; break;\r
+ case 8: d=PicoMem.cram [a & 0x003f]; break;\r
+ case 4: d=PicoMem.vsram[a & 0x003f]; break;\r
default:elprintf(EL_ANOMALY, "VDP read with bad type %i", Pico.video.type); break;\r
}\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 ((PicoAHW & PAHW_MCD) && (PicoOpt & POPT_EN_MCD_PSYNC)) SekCyclesBurn(CheckDMA());\r
- else SekSetCyclesLeftNoMCD(SekCyclesLeftNoMCD - CheckDMA());\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 *)PicoMem.ram;\r
+ mask = 0xffff;\r
}\r
- else if (PicoAHW & PAHW_MCD)\r
+ else if (PicoIn.AHW & 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=(u16 *)(Pico.rom+(source&~1));\r
- pdend=(u16 *)(Pico.rom+Pico.romsize);\r
- }\r
- else {\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
+ r = PicoMem.vram;\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
- rendstatus |= PDRAW_DIRTY_SPRITES;\r
+ Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES;\r
break;\r
\r
case 3: // cram\r
Pico.m.dirtyPal = 1;\r
- r = Pico.cram;\r
- for(a2=a&0x7f; len; len--)\r
+ r = PicoMem.cram;\r
+ for (; len; len--)\r
+ {\r
+ r[(a / 2) & 0x3f] = base[source++ & mask];\r
+ // AutoIncrement\r
+ a += inc;\r
+ }\r
+ break;\r
+\r
+ case 5: // vsram\r
+ r = PicoMem.vsram;\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
- r = Pico.vsram;\r
- for(a2=a&0x7f; len; len--)\r
+ case 0x81: // vram 128k\r
+ a |= Pico.video.addr_u << 16;\r
+ for(; len; len--)\r
{\r
- r[a2>>1] = (u16)*pd++;\r
+ VideoWrite128(a, 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 = (a + inc) & 0x1ffff;\r
}\r
- a=(a&0xff00)|a2;\r
+ Pico.video.addr_u = a >> 16;\r
break;\r
\r
default:\r
- elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);\r
+ if (Pico.video.type != 0 || (EL_LOGMASK & EL_VDPDMA))\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "DMA with bad type %i", Pico.video.type);\r
break;\r
}\r
// remember addr\r
\r
static void DmaCopy(int len)\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
+ u16 a = Pico.video.addr;\r
+ u8 *vr = (u8 *)PicoMem.vram;\r
+ u8 inc = Pico.video.reg[0xf];\r
int source;\r
- elprintf(EL_VDPDMA, "DmaCopy len %i [%i]", len, SekCyclesDone());\r
+ elprintf(EL_VDPDMA, "DmaCopy len %i [%u]", len, SekCyclesDone());\r
\r
- Pico.m.dma_xfers += len;\r
- Pico.video.status |= 2; // dma busy\r
+ Pico.m.dma_xfers = len;\r
+ if (Pico.m.dma_xfers < len)\r
+ Pico.m.dma_xfers = ~0;\r
+ Pico.video.status |= SR_DMA;\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
// remember addr\r
Pico.video.addr=a;\r
- rendstatus |= PDRAW_DIRTY_SPRITES;\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
-\r
- len=GetDmaLength();\r
- elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%i]", len, inc, SekCyclesDone());\r
-\r
- Pico.m.dma_xfers += len;\r
- Pico.video.status |= 2; // dma busy\r
+ u16 a = Pico.video.addr;\r
+ u8 *vr = (u8 *)PicoMem.vram;\r
+ u8 high = (u8)(data >> 8);\r
+ u8 inc = Pico.video.reg[0xf];\r
+ int source;\r
+ int len, l;\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
+ len = GetDmaLength();\r
+ elprintf(EL_VDPDMA, "DmaFill len %i inc %i [%u]", len, inc, SekCyclesDone());\r
\r
- if (!inc) len=1;\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 |= SR_DMA;\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
- // 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
\r
- rendstatus |= PDRAW_DIRTY_SPRITES;\r
+ // remember addr\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
+ if (Pico.m.dma_xfers)\r
+ elprintf(EL_VDPDMA|EL_ANOMALY, "Dma overlap, left=%d @ %06x",\r
+ Pico.m.dma_xfers, SekPc);\r
+\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
+static NOINLINE void CommandChange(void)\r
{\r
- struct PicoVideo *pvid=&Pico.video;\r
- unsigned int cmd=0,addr=0;\r
+ struct PicoVideo *pvid = &Pico.video;\r
+ unsigned int cmd, addr;\r
\r
- cmd=pvid->command;\r
+ cmd = pvid->command;\r
\r
// Get type of transfer 0xc0000030 (v/c/vsram read/write)\r
- pvid->type=(unsigned char)(((cmd>>2)&0xc)|(cmd>>30));\r
+ pvid->type = (u8)(((cmd >> 2) & 0xc) | (cmd >> 30));\r
+ if (pvid->type == 1) // vram\r
+ pvid->type |= pvid->reg[1] & 0x80; // 128k\r
\r
// Get address 0x3fff0003\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
+ addr = (cmd >> 16) & 0x3fff;\r
+ addr |= (cmd << 14) & 0xc000;\r
+ pvid->addr = (u16)addr;\r
+ pvid->addr_u = (u8)((cmd >> 2) & 1);\r
}\r
\r
-static __inline void DrawSync(int blank_on)\r
+static void DrawSync(int blank_on)\r
{\r
- if (Pico.m.scanline < 224 && !(PicoOpt & POPT_ALT_RENDERER) &&\r
- !PicoSkipFrame && DrawScanline <= Pico.m.scanline) {\r
+ if (Pico.m.scanline < 224 && !(PicoIn.opt & POPT_ALT_RENDERER) &&\r
+ !PicoIn.skipFrame && Pico.est.DrawScanline <= Pico.m.scanline) {\r
//elprintf(EL_ANOMALY, "sync");\r
PicoDrawSync(Pico.m.scanline, blank_on);\r
}\r
{\r
struct PicoVideo *pvid=&Pico.video;\r
\r
- //if (Pico.m.scanline < 224)\r
- // elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x", a, d);\r
- a&=0x1c;\r
+ //elprintf(EL_STATUS, "PicoVideoWrite [%06x] %04x [%u] @ %06x",\r
+ // a, d, SekCyclesDone(), SekPc);\r
\r
- if (a==0x00) // Data port 0 or 2\r
+ a &= 0x1c;\r
+ switch (a)\r
{\r
+ case 0x00: // Data port 0 or 2\r
// try avoiding the sync..\r
if (Pico.m.scanline < 224 && (pvid->reg[1]&0x40) &&\r
!(!pvid->pending &&\r
- ((pvid->command & 0xc00000f0) == 0x40000010 && Pico.vsram[pvid->addr>>1] == d))\r
+ ((pvid->command & 0xc00000f0) == 0x40000010 && PicoMem.vsram[pvid->addr>>1] == d))\r
)\r
DrawSync(0);\r
\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
+ if (!(pvid->status & SR_VB) && !(PicoIn.opt&POPT_DIS_VDP_FIFO))\r
{\r
- DmaFill(d);\r
+ int use = pvid->type == 1 ? 2 : 1;\r
+ pvid->lwrite_cnt -= use;\r
+ if (pvid->lwrite_cnt < 0)\r
+ SekCyclesLeft = 0;\r
+ elprintf(EL_ASVDP, "VDP data write: [%04x] %04x [%u] {%i} #%i @ %06x",\r
+ Pico.video.addr, d, SekCyclesDone(), Pico.video.type, pvid->lwrite_cnt, SekPc);\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
- SekCyclesBurn(32); // penalty // 488/12-8\r
- if (SekCycleCnt>=SekCycleAim) SekEndRun(0);\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
- }\r
- VideoWrite(d);\r
- }\r
- return;\r
- }\r
+ VideoWrite(d);\r
\r
- if (a==0x04) // Control (command) port 4 or 6\r
- {\r
+ if ((pvid->command&0x80) && (pvid->reg[1]&0x10) && (pvid->reg[0x17]>>6)==2)\r
+ DmaFill(d);\r
+\r
+ break;\r
+\r
+ case 0x04: // Control (command) port 4 or 6\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
return;\r
}\r
\r
- if (num == 1 && !(d&0x40) && SekCyclesLeft > 390) blank_on = 1;\r
+ if (num == 1 && !(d&0x40) && SekCyclesDone() - Pico.t.m68c_line_start <= 488-390)\r
+ blank_on = 1;\r
DrawSync(blank_on);\r
pvid->reg[num]=(unsigned char)d;\r
switch (num)\r
{\r
case 0x00:\r
- elprintf(EL_INTSW, "hint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x10)>>4,\r
+ elprintf(EL_INTSW, "hint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x10)>>4,\r
(d&0x10)>>4, SekCyclesDone(), (pvid->pending_ints&0x10)>>4, SekPc);\r
goto update_irq;\r
case 0x01:\r
- elprintf(EL_INTSW, "vint_onoff: %i->%i [%i] pend=%i @ %06x", (dold&0x20)>>5,\r
+ elprintf(EL_INTSW, "vint_onoff: %i->%i [%u] pend=%i @ %06x", (dold&0x20)>>5,\r
(d&0x20)>>5, SekCyclesDone(), (pvid->pending_ints&0x20)>>5, SekPc);\r
+ if (!(pvid->status & PVS_VB2))\r
+ pvid->status &= ~SR_VB;\r
+ pvid->status |= ((d >> 3) ^ SR_VB) & SR_VB; // forced blanking\r
goto update_irq;\r
case 0x05:\r
//elprintf(EL_STATUS, "spritep moved to %04x", (unsigned)(Pico.video.reg[5]&0x7f) << 9);\r
- if (d^dold) rendstatus |= PDRAW_SPRITES_MOVED;\r
+ if (d^dold) Pico.est.rendstatus |= PDRAW_SPRITES_MOVED;\r
break;\r
case 0x0c:\r
// renderers should update their palettes if sh/hi mode is changed\r
update_irq:\r
#ifndef EMU_CORE_DEBUG\r
// update IRQ level\r
- if (!SekShouldInterrupt) // hack\r
+ if (!SekShouldInterrupt()) // hack\r
{\r
- int lines, pints, irq=0;\r
+ int lines, pints, irq = 0;\r
lines = (pvid->reg[1] & 0x20) | (pvid->reg[0] & 0x10);\r
- pints = (pvid->pending_ints&lines);\r
+ pints = pvid->pending_ints & lines;\r
if (pints & 0x20) irq = 6;\r
else if (pints & 0x10) irq = 4;\r
SekInterrupt(irq); // update line\r
\r
- if (irq) SekEndRun(24); // make it delayed\r
+ // this is broken because cost of current insn isn't known here\r
+ if (irq) SekEndRun(21); // make it delayed\r
}\r
#endif\r
}\r
pvid->pending=1;\r
}\r
}\r
+ break;\r
+\r
+ // case 0x08: // 08 0a - HV counter - lock up\r
+ // case 0x0c: // 0c 0e - HV counter - lock up\r
+ // case 0x10: // 10 12 - PSG - handled by caller\r
+ // case 0x14: // 14 16 - PSG - handled by caller\r
+ // case 0x18: // 18 1a - no effect?\r
+ case 0x1c: // 1c 1e - debug\r
+ pvid->debug = d;\r
+ pvid->debug_p = 0;\r
+ if (d & (1 << 6)) {\r
+ pvid->debug_p |= PVD_KILL_A | PVD_KILL_B;\r
+ pvid->debug_p |= PVD_KILL_S_LO | PVD_KILL_S_HI;\r
+ }\r
+ switch ((d >> 7) & 3) {\r
+ case 1:\r
+ pvid->debug_p &= ~(PVD_KILL_S_LO | PVD_KILL_S_HI);\r
+ pvid->debug_p |= PVD_FORCE_S;\r
+ break;\r
+ case 2:\r
+ pvid->debug_p &= ~PVD_KILL_A;\r
+ pvid->debug_p |= PVD_FORCE_A;\r
+ break;\r
+ case 3:\r
+ pvid->debug_p &= ~PVD_KILL_B;\r
+ pvid->debug_p |= PVD_FORCE_B;\r
+ break;\r
+ }\r
+ break;\r
}\r
}\r
\r
-PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)\r
+static u32 SrLow(const struct PicoVideo *pv)\r
{\r
- a&=0x1c;\r
+ unsigned int c, d = pv->status;\r
\r
- if (a==0x04) // control port\r
- {\r
- struct PicoVideo *pv=&Pico.video;\r
- unsigned int d;\r
- d=pv->status;\r
- //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast)\r
- if (SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs)\r
-\r
- d |= ((pv->reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled\r
- d |= (pv->pending_ints&0x20)<<2; // V-int pending?\r
- if (d&0x100) pv->status&=~0x100; // FIFO no longer full\r
+ c = SekCyclesDone() - Pico.t.m68c_line_start - 39;\r
+ if (c < 92)\r
+ d |= SR_HB;\r
+ return d;\r
+}\r
\r
- pv->pending = 0; // ctrl port reads clear write-pending flag (Charles MacDonald)\r
+PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a)\r
+{\r
+ a &= 0x1c;\r
\r
- elprintf(EL_SR, "SR read: %04x @ %06x", d, SekPc);\r
+ if (a == 0x04) // control port\r
+ {\r
+ struct PicoVideo *pv = &Pico.video;\r
+ unsigned int d = SrLow(pv);\r
+ pv->pending = 0;\r
+ elprintf(EL_SR, "SR read: %04x [%u] @ %06x", d, SekCyclesDone(), SekPc);\r
return d;\r
}\r
\r
if ((a&0x1c)==0x08)\r
{\r
unsigned int d;\r
- int lineCycles;\r
\r
- lineCycles = (488-SekCyclesLeft)&0x1ff;\r
+ d = (SekCyclesDone() - Pico.t.m68c_line_start) & 0x1ff; // FIXME\r
if (Pico.video.reg[12]&1)\r
- d = hcounts_40[lineCycles];\r
- else d = hcounts_32[lineCycles];\r
+ d = hcounts_40[d];\r
+ else d = hcounts_32[d];\r
\r
- elprintf(EL_HVCNT, "hv: %02x %02x (%i) @ %06x", d, Pico.video.v_counter, SekCyclesDone(), SekPc);\r
+ elprintf(EL_HVCNT, "hv: %02x %02x [%u] @ %06x", d, Pico.video.v_counter, SekCyclesDone(), SekPc);\r
return d | (Pico.video.v_counter << 8);\r
}\r
\r
return 0;\r
}\r
\r
-unsigned int PicoVideoRead8(unsigned int a)\r
+unsigned char PicoVideoRead8DataH(void)\r
{\r
- unsigned int d;\r
- a&=0x1d;\r
+ return VideoRead() >> 8;\r
+}\r
\r
- switch (a)\r
- {\r
- case 0: return VideoRead() >> 8;\r
- case 1: return VideoRead() & 0xff;\r
- case 4: // control port/status reg\r
- d = Pico.video.status >> 8;\r
- if (d&1) Pico.video.status&=~0x100; // FIFO no longer full\r
- Pico.video.pending = 0;\r
- elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc);\r
- return d;\r
- case 5:\r
- d = Pico.video.status & 0xff;\r
- //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast)\r
- d |= ((Pico.video.reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled\r
- d |= (Pico.video.pending_ints&0x20)<<2; // V-int pending?\r
- if (SekCyclesLeft < 84+4) d |= 4; // H-Blank\r
- Pico.video.pending = 0;\r
- elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc);\r
- return d;\r
- case 8: // hv counter\r
- elprintf(EL_HVCNT, "vcounter: %02x (%i) @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc);\r
- return Pico.video.v_counter;\r
- case 9:\r
- d = (488-SekCyclesLeft)&0x1ff;\r
- if (Pico.video.reg[12]&1)\r
- d = hcounts_40[d];\r
- else d = hcounts_32[d];\r
- elprintf(EL_HVCNT, "hcounter: %02x (%i) @ %06x", d, SekCyclesDone(), SekPc);\r
- return d;\r
- }\r
+unsigned char PicoVideoRead8DataL(void)\r
+{\r
+ return VideoRead();\r
+}\r
\r
- return 0;\r
+unsigned char PicoVideoRead8CtlH(void)\r
+{\r
+ u8 d = (u8)(Pico.video.status >> 8);\r
+ Pico.video.pending = 0;\r
+ elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc);\r
+ return d;\r
}\r
+\r
+unsigned char PicoVideoRead8CtlL(void)\r
+{\r
+ u8 d = SrLow(&Pico.video);\r
+ Pico.video.pending = 0;\r
+ elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc);\r
+ return d;\r
+}\r
+\r
+unsigned char PicoVideoRead8HV_H(void)\r
+{\r
+ elprintf(EL_HVCNT, "vcounter: %02x [%u] @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc);\r
+ return Pico.video.v_counter;\r
+}\r
+\r
+// FIXME: broken\r
+unsigned char PicoVideoRead8HV_L(void)\r
+{\r
+ u32 d = (SekCyclesDone() - Pico.t.m68c_line_start) & 0x1ff; // FIXME\r
+ if (Pico.video.reg[12]&1)\r
+ d = hcounts_40[d];\r
+ else d = hcounts_32[d];\r
+ elprintf(EL_HVCNT, "hcounter: %02x [%u] @ %06x", d, SekCyclesDone(), SekPc);\r
+ return d;\r
+}\r
+\r
+// vim:shiftwidth=2:ts=2:expandtab\r