bugfixes, CD swap, autorepeat
[picodrive.git] / Pico / cd / Memory.c
index fc6e4de..564623e 100644 (file)
@@ -26,12 +26,12 @@ typedef unsigned int   u32;
 //#define __debug_io\r
 //#define __debug_io2\r
 \r
-//#define rdprintf dprintf\r
-#define rdprintf(...)\r
+#define rdprintf dprintf\r
+//#define rdprintf(...)\r
 //#define wrdprintf dprintf\r
 #define wrdprintf(...)\r
-//#define plprintf dprintf\r
-#define plprintf(...)\r
+#define plprintf dprintf\r
+//#define plprintf(...)\r
 \r
 // -----------------------------------------------------------------\r
 \r
@@ -118,6 +118,7 @@ void m68k_reg_write8(u32 a, u32 d)
       Pico_mcd->m.busreq = d;\r
       return;\r
     case 2:\r
+      dprintf("m68k: prg wp=%02x", d);\r
       Pico_mcd->s68k_regs[2] = d; // really use s68k side register\r
       return;\r
     case 3: {\r
@@ -405,7 +406,7 @@ static void OtherWrite8End(u32 a, u32 d, int realsize)
 {\r
   if ((a&0xffffc0)==0xa12000) { m68k_reg_write8(a, d); return; }\r
 \r
-  dprintf("m68k FIXME: strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc);\r
+  dprintf("m68k FIXME: strange w%i: [%06x], %08x @%06x", realsize, a&0xffffff, d, SekPc);\r
 }\r
 \r
 \r
@@ -433,7 +434,7 @@ static u8 PicoReadM68k8(u32 a)
   if (a < 0x20000) { d = *(u8 *)(Pico_mcd->bios+(a^1)); goto end; } // bios\r
 \r
   // prg RAM\r
-  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
     u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
     d = *(prg_bank+((a^1)&0x1ffff));\r
     goto end;\r
@@ -490,7 +491,7 @@ static u16 PicoReadM68k16(u32 a)
   if (a < 0x20000) { d = *(u16 *)(Pico_mcd->bios+a); goto end; } // bios\r
 \r
   // prg RAM\r
-  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
     u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
     wrdprintf("m68k_prgram r16: [%i,%06x] @%06x", Pico_mcd->s68k_regs[3]>>6, a, SekPc);\r
     d = *(u16 *)(prg_bank+(a&0x1fffe));\r
@@ -547,7 +548,7 @@ static u32 PicoReadM68k32(u32 a)
   if (a < 0x20000) { u16 *pm=(u16 *)(Pico_mcd->bios+a); d = (pm[0]<<16)|pm[1]; goto end; } // bios\r
 \r
   // prg RAM\r
-  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
     u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
     u16 *pm=(u16 *)(prg_bank+(a&0x1fffe));\r
     d = (pm[0]<<16)|pm[1];\r
@@ -595,7 +596,6 @@ static u32 PicoReadM68k32(u32 a)
 \r
 \r
 // -----------------------------------------------------------------\r
-//                            Write Ram\r
 \r
 #ifdef _ASM_CD_MEMORY_C\r
 void PicoWriteM68k8(u32 a,u8 d);\r
@@ -617,7 +617,7 @@ static void PicoWriteM68k8(u32 a,u8 d)
   a&=0xffffff;\r
 \r
   // prg RAM\r
-  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
     u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
     *(u8 *)(prg_bank+((a^1)&0x1ffff))=d;\r
     return;\r
@@ -668,7 +668,7 @@ static void PicoWriteM68k16(u32 a,u16 d)
   a&=0xfffffe;\r
 \r
   // prg RAM\r
-  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
     u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
     wrdprintf("m68k_prgram w16: [%i,%06x] %04x @%06x", Pico_mcd->s68k_regs[3]>>6, a, d, SekPc);\r
     *(u16 *)(prg_bank+(a&0x1fffe))=d;\r
@@ -734,7 +734,7 @@ static void PicoWriteM68k32(u32 a,u32 d)
   a&=0xfffffe;\r
 \r
   // prg RAM\r
-  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&2)) {\r
+  if ((a&0xfe0000)==0x020000 && (Pico_mcd->m.busreq&3)!=1) {\r
     u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
     u16 *pm=(u16 *)(prg_bank+(a&0x1fffe));\r
     pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
@@ -777,6 +777,8 @@ static void PicoWriteM68k32(u32 a,u32 d)
 #endif\r
 \r
 \r
+// -----------------------------------------------------------------\r
+//                            S68k\r
 // -----------------------------------------------------------------\r
 \r
 #ifdef _ASM_CD_MEMORY_C\r
@@ -1139,7 +1141,7 @@ static void PicoWriteS68k8(u32 a,u8 d)
   // prg RAM\r
   if (a < 0x80000) {\r
     u8 *pm=(u8 *)(Pico_mcd->prg_ram+(a^1));\r
-    *pm=d;\r
+    if (a >= (Pico_mcd->s68k_regs[2]<<8)) *pm=d;\r
     return;\r
   }\r
 \r
@@ -1215,7 +1217,8 @@ static void PicoWriteS68k16(u32 a,u16 d)
   // prg RAM\r
   if (a < 0x80000) {\r
     wrdprintf("s68k_prgram w16: [%06x] %04x @%06x", a, d, SekPcS68k);\r
-    *(u16 *)(Pico_mcd->prg_ram+a)=d;\r
+    if (a >= (Pico_mcd->s68k_regs[2]<<8)) // needed for Dungeon Explorer\r
+      *(u16 *)(Pico_mcd->prg_ram+a)=d;\r
     return;\r
   }\r
 \r
@@ -1299,8 +1302,10 @@ static void PicoWriteS68k32(u32 a,u32 d)
 \r
   // prg RAM\r
   if (a < 0x80000) {\r
-    u16 *pm=(u16 *)(Pico_mcd->prg_ram+a);\r
-    pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
+    if (a >= (Pico_mcd->s68k_regs[2]<<8)) {\r
+      u16 *pm=(u16 *)(Pico_mcd->prg_ram+a);\r
+      pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
+    }\r
     return;\r
   }\r
 \r