bugfixes, new scaling, double ym upd at 940
[picodrive.git] / Pico / cd / Memory.c
index 08a4486..fc6e4de 100644 (file)
@@ -30,10 +30,13 @@ typedef unsigned int   u32;
 #define rdprintf(...)\r
 //#define wrdprintf dprintf\r
 #define wrdprintf(...)\r
+//#define plprintf dprintf\r
+#define plprintf(...)\r
 \r
 // -----------------------------------------------------------------\r
 \r
 // poller detection\r
+//#undef USE_POLL_DETECT\r
 #define POLL_LIMIT 16\r
 #define POLL_CYCLES 124\r
 // int m68k_poll_addr, m68k_poll_cnt;\r
@@ -143,7 +146,7 @@ void m68k_reg_write8(u32 a, u32 d)
 #ifdef USE_POLL_DETECT\r
       if ((s68k_poll_adclk&0xfe) == 2 && s68k_poll_cnt > POLL_LIMIT) {\r
         SekSetStopS68k(0); s68k_poll_adclk = 0;\r
-        //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);\r
+        plprintf("s68k poll release, a=%02x\n", a);\r
       }\r
 #endif\r
       return;\r
@@ -163,7 +166,7 @@ void m68k_reg_write8(u32 a, u32 d)
 #ifdef USE_POLL_DETECT\r
       if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) {\r
         SekSetStopS68k(0); s68k_poll_adclk = 0;\r
-        //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);\r
+        plprintf("s68k poll release, a=%02x\n", a);\r
       }\r
 #endif\r
       return;\r
@@ -174,7 +177,7 @@ void m68k_reg_write8(u32 a, u32 d)
 #ifdef USE_POLL_DETECT\r
       if ((a&0xfe) == (s68k_poll_adclk&0xfe) && s68k_poll_cnt > POLL_LIMIT) {\r
         SekSetStopS68k(0); s68k_poll_adclk = 0;\r
-        //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);\r
+        plprintf("s68k poll release, a=%02x\n", a);\r
       }\r
 #endif\r
       return;\r
@@ -183,6 +186,31 @@ void m68k_reg_write8(u32 a, u32 d)
   dprintf("m68k FIXME: invalid write? [%02x] %02x", a, d);\r
 }\r
 \r
+#ifndef _ASM_CD_MEMORY_C\r
+static\r
+#endif\r
+u32 s68k_poll_detect(u32 a, u32 d)\r
+{\r
+#ifdef USE_POLL_DETECT\r
+  // polling detection\r
+  if (a == (s68k_poll_adclk&0xff)) {\r
+    unsigned int clkdiff = SekCyclesDoneS68k() - (s68k_poll_adclk>>8);\r
+    if (clkdiff <= POLL_CYCLES) {\r
+      s68k_poll_cnt++;\r
+      //printf("-- diff: %u, cnt = %i\n", clkdiff, s68k_poll_cnt);\r
+      if (s68k_poll_cnt > POLL_LIMIT) {\r
+        SekSetStopS68k(1);\r
+        plprintf("s68k poll detected @ %06x, a=%02x\n", SekPcS68k, a);\r
+      }\r
+      s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;\r
+      return d;\r
+    }\r
+  }\r
+  s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;\r
+  s68k_poll_cnt = 0;\r
+#endif\r
+  return d;\r
+}\r
 \r
 #define READ_FONT_DATA(basemask) \\r
 { \\r
@@ -208,9 +236,9 @@ u32 s68k_reg_read16(u32 a)
     case 0:\r
       return ((Pico_mcd->s68k_regs[0]&3)<<8) | 1; // ver = 0, not in reset state\r
     case 2:\r
-      d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0x1f);\r
+      d = (Pico_mcd->s68k_regs[2]<<8) | (Pico_mcd->s68k_regs[3]&0x1f);\r
       //printf("s68k_regs r3: %02x @%06x\n", (u8)d, SekPcS68k);\r
-      goto poll_detect;\r
+      return s68k_poll_detect(a, d);\r
     case 6:\r
       return CDC_Read_Reg();\r
     case 8:\r
@@ -240,30 +268,9 @@ u32 s68k_reg_read16(u32 a)
 \r
   d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1];\r
 \r
-  if (a >= 0x0e && a < 0x30) goto poll_detect;\r
-\r
-  return d;\r
-\r
-poll_detect:\r
-#ifdef USE_POLL_DETECT\r
-  // polling detection\r
-  if (a == (s68k_poll_adclk&0xfe)) {\r
-    unsigned int clkdiff = SekCyclesDoneS68k() - (s68k_poll_adclk>>8);\r
-    if (clkdiff <= POLL_CYCLES) {\r
-      s68k_poll_cnt++;\r
-      //printf("-- diff: %u, cnt = %i\n", clkdiff, s68k_poll_cnt);\r
-      if (s68k_poll_cnt > POLL_LIMIT) {\r
-        SekSetStopS68k(1);\r
-        //printf("%05i:%03i: s68k poll detected @ %06x, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, SekPcS68k, a);\r
-      }\r
-      s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;\r
-      return d;\r
-    }\r
-  }\r
-  s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;\r
-  s68k_poll_cnt = 0;\r
+  if (a >= 0x0e && a < 0x30)\r
+    return s68k_poll_detect(a, d);\r
 \r
-#endif\r
   return d;\r
 }\r
 \r
@@ -407,6 +414,7 @@ static void OtherWrite8End(u32 a, u32 d, int realsize)
 #include "cell_map.c"\r
 #endif // !def _ASM_CD_MEMORY_C\r
 \r
+\r
 // -----------------------------------------------------------------\r
 //                     Read Rom and read Ram\r
 \r
@@ -631,8 +639,11 @@ static void PicoWriteM68k8(u32 a,u8 d)
     return;\r
   }\r
 \r
-  if ((a&0xffffc0)==0xa12000)\r
+  if ((a&0xffffc0)==0xa12000) {\r
     rdprintf("m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc);\r
+    m68k_reg_write8(a, d);\r
+    return;\r
+  }\r
 \r
   OtherWrite8(a,d,8);\r
 }\r
@@ -688,7 +699,7 @@ static void PicoWriteM68k16(u32 a,u16 d)
 #ifdef USE_POLL_DETECT\r
       if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) {\r
         SekSetStopS68k(0); s68k_poll_adclk = -1;\r
-        //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);\r
+        plprintf("s68k poll release, a=%02x\n", a);\r
       }\r
 #endif\r
       return;\r
@@ -755,8 +766,10 @@ static void PicoWriteM68k32(u32 a,u32 d)
     return;\r
   }\r
 \r
-  if ((a&0xffffc0)==0xa12000)\r
+  if ((a&0xffffc0)==0xa12000) {\r
     rdprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc);\r
+    if ((a&0x3e) == 0xe) dprintf("m68k FIXME: w32 [%02x]", a&0x3f);\r
+  }\r
 \r
   OtherWrite16(a,  (u16)(d>>16));\r
   OtherWrite16(a+2,(u16)d);\r
@@ -785,7 +798,13 @@ static u8 PicoReadS68k8(u32 a)
   if ((a&0xfffe00) == 0xff8000) {\r
     a &= 0x1ff;\r
     rdprintf("s68k_regs r8: [%02x] @ %06x", a, SekPcS68k);\r
-    if (a >= 0x58 && a < 0x68)\r
+    if (a >= 0x0e && a < 0x30) {\r
+      d = Pico_mcd->s68k_regs[a];\r
+      s68k_poll_detect(a, d);\r
+      rdprintf("ret = %02x", (u8)d);\r
+      goto end;\r
+    }\r
+    else if (a >= 0x58 && a < 0x68)\r
          d = gfx_cd_read(a&~1);\r
     else d = s68k_reg_read16(a&~1);\r
     if ((a&1)==0) d>>=8;\r
@@ -1008,7 +1027,7 @@ static u32 PicoReadS68k32(u32 a)
 \r
   // PCM\r
   if ((a&0xff8000)==0xff0000) {\r
-    dprintf("FIXME: s68k_pcm r32: [%06x] @%06x", a, SekPcS68k);\r
+    dprintf("s68k_pcm r32: [%06x] @%06x", a, SekPcS68k);\r
     a &= 0x7fff;\r
     if (a >= 0x2000) {\r
       a >>= 1;\r
@@ -1293,6 +1312,7 @@ static void PicoWriteS68k32(u32 a,u32 d)
       gfx_cd_write16(a,   d>>16);\r
       gfx_cd_write16(a+2, d&0xffff);\r
     } else {\r
+      if ((a&0x1fe) == 0xe) dprintf("s68k FIXME: w32 [%02x]", a&0x3f);\r
       s68k_reg_write8(a,   d>>24);\r
       s68k_reg_write8(a+1,(d>>16)&0xff);\r
       s68k_reg_write8(a+2,(d>>8) &0xff);\r