32x: some mapping corrections
[picodrive.git] / pico / 32x / memory.c
index eabc1b6..3b12cbb 100644 (file)
@@ -195,8 +195,10 @@ static u32 p32x_reg_read16(u32 a)
       m68k_poll.cnt = 0;
     dr2 = SekDar(2);
 
-    if (cycles - msh2.m68krcycles_done > 500)
+    if (cycles - msh2.m68krcycles_done > 244
+        || (Pico32x.comm_dirty_68k & comreg))
       p32x_sync_sh2s(cycles);
+
     if (Pico32x.comm_dirty_sh2 & comreg)
       Pico32x.comm_dirty_sh2 &= ~comreg;
     else if (m68k_poll_detect(a, cycles, P32XF_68KCPOLL)) {
@@ -569,7 +571,7 @@ static void p32x_vdp_write16(u32 a, u32 d, SH2 *sh2)
 static u32 p32x_sh2reg_read16(u32 a, SH2 *sh2)
 {
   u16 *r = Pico32x.regs;
-  a &= 0xfe; // ?
+  a &= 0x3e;
 
   switch (a) {
     case 0x00: // adapter/irq ctl
@@ -626,7 +628,7 @@ static void p32x_sh2reg_write8(u32 a, u32 d, SH2 *sh2)
   u16 *r = Pico32x.regs;
   u32 old;
 
-  a &= 0xff;
+  a &= 0x3f;
   sh2->poll_addr = 0;
 
   switch (a) {
@@ -722,7 +724,7 @@ static void p32x_sh2reg_write8(u32 a, u32 d, SH2 *sh2)
 
 static void p32x_sh2reg_write16(u32 a, u32 d, SH2 *sh2)
 {
-  a &= 0xfe;
+  a &= 0x3e;
 
   sh2->poll_addr = 0;
 
@@ -1192,13 +1194,13 @@ static u32 sh2_read8_cs0(u32 a, SH2 *sh2)
 
   sh2_burn_cycles(sh2, 1*2);
 
-  // 0x3ff00 is veridied
-  if ((a & 0x3ff00) == 0x4000) {
+  // 0x3ffc0 is veridied
+  if ((a & 0x3ffc0) == 0x4000) {
     d = p32x_sh2reg_read16(a, sh2);
     goto out_16to8;
   }
 
-  if ((a & 0x3ff00) == 0x4100) {
+  if ((a & 0x3fff0) == 0x4100) {
     d = p32x_vdp_read16(a);
     sh2_poll_detect(sh2, a, SH2_STATE_VPOLL, 7);
     goto out_16to8;
@@ -1247,14 +1249,14 @@ static u32 sh2_read16_cs0(u32 a, SH2 *sh2)
 
   sh2_burn_cycles(sh2, 1*2);
 
-  if ((a & 0x3ff00) == 0x4000) {
+  if ((a & 0x3ffc0) == 0x4000) {
     d = p32x_sh2reg_read16(a, sh2);
     if (!(EL_LOGMASK & EL_PWM) && (a & 0x30) == 0x30) // hide PWM
       return d;
     goto out;
   }
 
-  if ((a & 0x3ff00) == 0x4100) {
+  if ((a & 0x3fff0) == 0x4100) {
     d = p32x_vdp_read16(a);
     sh2_poll_detect(sh2, a, SH2_STATE_VPOLL, 7);
     goto out;
@@ -1301,14 +1303,14 @@ static void REGPARM(3) sh2_write8_cs0(u32 a, u32 d, SH2 *sh2)
     a, d & 0xff, sh2_pc(sh2));
 
   if (Pico32x.regs[0] & P32XS_FM) {
-    if ((a & 0x3ff00) == 0x4100) {
+    if ((a & 0x3fff0) == 0x4100) {
       sh2->poll_addr = 0;
       p32x_vdp_write8(a, d);
       return;
     }
   }
 
-  if ((a & 0x3ff00) == 0x4000) {
+  if ((a & 0x3ffc0) == 0x4000) {
     p32x_sh2reg_write8(a, d, sh2);
     return;
   }
@@ -1372,7 +1374,7 @@ static void REGPARM(3) sh2_write16_cs0(u32 a, u32 d, SH2 *sh2)
       a, d & 0xffff, sh2_pc(sh2));
 
   if (Pico32x.regs[0] & P32XS_FM) {
-    if ((a & 0x3ff00) == 0x4100) {
+    if ((a & 0x3fff0) == 0x4100) {
       sh2->poll_addr = 0;
       p32x_vdp_write16(a, d, sh2);
       return;
@@ -1385,7 +1387,7 @@ static void REGPARM(3) sh2_write16_cs0(u32 a, u32 d, SH2 *sh2)
     }
   }
 
-  if ((a & 0x3ff00) == 0x4000) {
+  if ((a & 0x3ffc0) == 0x4000) {
     p32x_sh2reg_write16(a, d, sh2);
     return;
   }
@@ -1523,6 +1525,21 @@ void REGPARM(3) p32x_sh2_write32(u32 a, u32 d, SH2 *sh2)
 
 // -----------------------------------------------------------------
 
+static void z80_md_bank_write_32x(unsigned int a, unsigned char d)
+{
+  unsigned int addr68k;
+
+  addr68k = Pico.m.z80_bank68k << 15;
+  addr68k += a & 0x7fff;
+  if ((addr68k & 0xfff000) == 0xa15000)
+    Pico32x.emu_flags |= P32XF_Z80_32X_IO;
+
+  elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, d);
+  m68k_write8(addr68k, d);
+}
+
+// -----------------------------------------------------------------
+
 static const u16 msh2_code[] = {
   // trap instructions
   0xaffe, // bra <self>
@@ -1779,6 +1796,9 @@ void PicoMemSetup32x(void)
 
   sh2_drc_mem_setup(&msh2);
   sh2_drc_mem_setup(&ssh2);
+
+  // z80 hack
+  z80_map_set(z80_write_map, 0x8000, 0xffff, z80_md_bank_write_32x, 1);
 }
 
 void Pico32xMemStateLoaded(void)