bugfixes, but silpheed is broken
[picodrive.git] / Pico / cd / Memory.c
index ce23433..1a1bb84 100644 (file)
@@ -34,12 +34,6 @@ typedef unsigned int   u32;
 // -----------------------------------------------------------------\r
 \r
 \r
-#ifndef _ASM_CD_MEMORY_C\r
-void PicoMemResetCD(int r3)\r
-{\r
-}\r
-#endif\r
-\r
 #ifndef _ASM_CD_MEMORY_C\r
 static u32 m68k_reg_read16(u32 a)\r
 {\r
@@ -237,6 +231,7 @@ void s68k_reg_write8(u32 a, u32 d)
   //dprintf("s68k_regs w%2i: [%02x] %02x @ %06x", realsize, a, d, SekPcS68k);\r
 \r
   // TODO: review against Gens\r
+  // Warning: d might have upper bits set\r
   switch (a) {\r
     case 2:\r
       return; // only m68k can change WP\r
@@ -252,6 +247,10 @@ void s68k_reg_write8(u32 a, u32 d)
           PicoMemResetCD(d);\r
 #endif\r
         }\r
+#ifdef _ASM_CD_MEMORY_C\r
+        if ((d ^ dold) & 0x1d)\r
+          PicoMemResetCDdecode(d);\r
+#endif\r
         if (!(dold & 4)) {\r
           dprintf("wram mode 2M->1M");\r
           wram_2M_to_1M(Pico_mcd->word_ram2M);\r
@@ -298,7 +297,7 @@ void s68k_reg_write8(u32 a, u32 d)
       return;\r
     case 0x31:\r
       dprintf("s68k set int3 timer: %02x", d);\r
-      Pico_mcd->m.timer_int3 = d << 16;\r
+      Pico_mcd->m.timer_int3 = (d & 0xff) << 16;\r
       break;\r
     case 0x33: // IRQ mask\r
       dprintf("s68k irq mask: %02x", d);\r
@@ -1048,6 +1047,8 @@ static void decode_write16(u32 a, u16 d, int r3)
 \r
 // -----------------------------------------------------------------\r
 \r
+//void PicoWriteS68k8_(u32 a,u8 d);\r
+//void PicoWriteS68k8__(u32 a,u8 d);\r
 #ifdef _ASM_CD_MEMORY_C\r
 void PicoWriteS68k8(u32 a,u8 d);\r
 #else\r
@@ -1058,6 +1059,16 @@ static void PicoWriteS68k8(u32 a,u8 d)
 #endif\r
 \r
   a&=0xffffff;\r
+#if 0\r
+    PicoWriteS68k8_(a, d);\r
+/*  if ((a&0xfc0000)!=0x080000) {\r
+    PicoWriteS68k8_(a, d);\r
+    return;\r
+  }\r
+  printf("r3: %02x\n", Pico_mcd->s68k_regs[3]);\r
+  PicoWriteS68k8__(a,d);*/\r
+  return;\r
+#endif\r
 \r
   // prg RAM\r
   if (a < 0x80000) {\r
@@ -1071,7 +1082,7 @@ static void PicoWriteS68k8(u32 a,u8 d)
     a &= 0x1ff;\r
     rdprintf("s68k_regs w8: [%02x] %02x @ %06x", a, d, SekPcS68k);\r
     if (a >= 0x58 && a < 0x68)\r
-         gfx_cd_write(a&~1, (d<<8)|d);\r
+         gfx_cd_write16(a&~1, (d<<8)|d);\r
     else s68k_reg_write8(a,d);\r
     return;\r
   }\r
@@ -1146,7 +1157,7 @@ static void PicoWriteS68k16(u32 a,u16 d)
     a &= 0x1fe;\r
     rdprintf("s68k_regs w16: [%02x] %04x @ %06x", a, d, SekPcS68k);\r
     if (a >= 0x58 && a < 0x68)\r
-      gfx_cd_write(a, d);\r
+      gfx_cd_write16(a, d);\r
     else {\r
       if (a == 0xe) { // special case, 2 byte writes would be handled differently\r
         Pico_mcd->s68k_regs[0xf] = d;\r
@@ -1231,8 +1242,8 @@ static void PicoWriteS68k32(u32 a,u32 d)
     a &= 0x1fe;\r
     rdprintf("s68k_regs w32: [%02x] %08x @ %06x", a, d, SekPcS68k);\r
     if (a >= 0x58 && a < 0x68) {\r
-      gfx_cd_write(a,   d>>16);\r
-      gfx_cd_write(a+2, d&0xffff);\r
+      gfx_cd_write16(a,   d>>16);\r
+      gfx_cd_write16(a+2, d&0xffff);\r
     } else {\r
       s68k_reg_write8(a,   d>>24);\r
       s68k_reg_write8(a+1,(d>>16)&0xff);\r