allow compiling without 32x and sms code
[picodrive.git] / pico / memory.c
index 13fc67e..2fff489 100644 (file)
 \r
 extern unsigned int lastSSRamWrite; // used by serial eeprom code\r
 \r
-unsigned long m68k_read8_map  [0x1000000 >> M68K_MEM_SHIFT];\r
-unsigned long m68k_read16_map [0x1000000 >> M68K_MEM_SHIFT];\r
-unsigned long m68k_write8_map [0x1000000 >> M68K_MEM_SHIFT];\r
-unsigned long m68k_write16_map[0x1000000 >> M68K_MEM_SHIFT];\r
+uptr m68k_read8_map  [0x1000000 >> M68K_MEM_SHIFT];\r
+uptr m68k_read16_map [0x1000000 >> M68K_MEM_SHIFT];\r
+uptr m68k_write8_map [0x1000000 >> M68K_MEM_SHIFT];\r
+uptr m68k_write16_map[0x1000000 >> M68K_MEM_SHIFT];\r
 \r
-static void xmap_set(unsigned long *map, int shift, int start_addr, int end_addr,\r
+static void xmap_set(uptr *map, int shift, int start_addr, int end_addr,\r
     const void *func_or_mh, int is_func)\r
 {\r
-  unsigned long addr = (unsigned long)func_or_mh;\r
+  uptr addr = (uptr)func_or_mh;\r
   int mask = (1 << shift) - 1;\r
   int i;\r
 \r
@@ -44,17 +44,17 @@ static void xmap_set(unsigned long *map, int shift, int start_addr, int end_addr
   for (i = start_addr >> shift; i <= end_addr >> shift; i++) {\r
     map[i] = addr >> 1;\r
     if (is_func)\r
-      map[i] |= 1 << (sizeof(addr) * 8 - 1);\r
+      map[i] |= (uptr)1 << (sizeof(addr) * 8 - 1);\r
   }\r
 }\r
 \r
-void z80_map_set(unsigned long *map, int start_addr, int end_addr,\r
+void z80_map_set(uptr *map, int start_addr, int end_addr,\r
     const void *func_or_mh, int is_func)\r
 {\r
   xmap_set(map, Z80_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func);\r
 }\r
 \r
-void cpu68k_map_set(unsigned long *map, int start_addr, int end_addr,\r
+void cpu68k_map_set(uptr *map, int start_addr, int end_addr,\r
     const void *func_or_mh, int is_func)\r
 {\r
   xmap_set(map, M68K_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func);\r
@@ -63,8 +63,8 @@ void cpu68k_map_set(unsigned long *map, int start_addr, int end_addr,
 // more specialized/optimized function (does same as above)\r
 void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub)\r
 {\r
-  unsigned long *r8map, *r16map, *w8map, *w16map;\r
-  unsigned long addr = (unsigned long)ptr;\r
+  uptr *r8map, *r16map, *w8map, *w16map;\r
+  uptr addr = (uptr)ptr;\r
   int shift = M68K_MEM_SHIFT;\r
   int i;\r
 \r
@@ -110,23 +110,23 @@ static void m68k_unmapped_write16(u32 a, u32 d)
 \r
 void m68k_map_unmap(int start_addr, int end_addr)\r
 {\r
-  unsigned long addr;\r
+  uptr addr;\r
   int shift = M68K_MEM_SHIFT;\r
   int i;\r
 \r
-  addr = (unsigned long)m68k_unmapped_read8;\r
+  addr = (uptr)m68k_unmapped_read8;\r
   for (i = start_addr >> shift; i <= end_addr >> shift; i++)\r
     m68k_read8_map[i] = (addr >> 1) | (1 << 31);\r
 \r
-  addr = (unsigned long)m68k_unmapped_read16;\r
+  addr = (uptr)m68k_unmapped_read16;\r
   for (i = start_addr >> shift; i <= end_addr >> shift; i++)\r
     m68k_read16_map[i] = (addr >> 1) | (1 << 31);\r
 \r
-  addr = (unsigned long)m68k_unmapped_write8;\r
+  addr = (uptr)m68k_unmapped_write8;\r
   for (i = start_addr >> shift; i <= end_addr >> shift; i++)\r
     m68k_write8_map[i] = (addr >> 1) | (1 << 31);\r
 \r
-  addr = (unsigned long)m68k_unmapped_write16;\r
+  addr = (uptr)m68k_unmapped_write16;\r
   for (i = start_addr >> shift; i <= end_addr >> shift; i++)\r
     m68k_write16_map[i] = (addr >> 1) | (1 << 31);\r
 }\r
@@ -257,8 +257,11 @@ void NOINLINE ctl_write_z80busreq(u32 d)
     else\r
     {\r
       z80stopCycle = SekCyclesDone();\r
-      if ((PicoOpt&POPT_EN_Z80) && !Pico.m.z80_reset)\r
+      if ((PicoOpt&POPT_EN_Z80) && !Pico.m.z80_reset) {\r
+        pprof_start(m68k);\r
         PicoSyncZ80(z80stopCycle);\r
+        pprof_end_sub(m68k);\r
+      }\r
     }\r
     Pico.m.z80Run = d;\r
   }\r
@@ -272,8 +275,11 @@ void NOINLINE ctl_write_z80reset(u32 d)
   {\r
     if (d)\r
     {\r
-      if ((PicoOpt&POPT_EN_Z80) && Pico.m.z80Run)\r
+      if ((PicoOpt&POPT_EN_Z80) && Pico.m.z80Run) {\r
+        pprof_start(m68k);\r
         PicoSyncZ80(SekCyclesDone());\r
+        pprof_end_sub(m68k);\r
+      }\r
       YM2612ResetChip();\r
       timers_reset();\r
     }\r
@@ -316,7 +322,7 @@ static u32 PicoRead8_sram(u32 a)
 static u32 PicoRead16_sram(u32 a)\r
 {\r
   u32 d;\r
-  if (SRam.end >= a && a >= SRam.start && (Pico.m.sram_reg & SRR_MAPPED))\r
+  if (SRam.start <= a && a <= SRam.end && (Pico.m.sram_reg & SRR_MAPPED))\r
   {\r
     if (SRam.flags & SRF_EEPROM)\r
       d = EEPROM_read();\r
@@ -476,7 +482,7 @@ u32 PicoRead8_io(u32 a)
     goto end;\r
   }\r
 \r
-  if (!(PicoOpt & POPT_DIS_32X)) {\r
+  if (PicoOpt & POPT_EN_32X) {\r
     d = PicoRead8_32x(a);\r
     goto end;\r
   }\r
@@ -511,7 +517,7 @@ u32 PicoRead16_io(u32 a)
     goto end;\r
   }\r
 \r
-  if (!(PicoOpt & POPT_DIS_32X)) {\r
+  if (PicoOpt & POPT_EN_32X) {\r
     d = PicoRead16_32x(a);\r
     goto end;\r
   }\r
@@ -541,7 +547,7 @@ void PicoWrite8_io(u32 a, u32 d)
     Pico.m.sram_reg |= (u8)(d & 3);\r
     return;\r
   }\r
-  if (!(PicoOpt & POPT_DIS_32X)) {\r
+  if (PicoOpt & POPT_EN_32X) {\r
     PicoWrite8_32x(a, d);\r
     return;\r
   }\r
@@ -569,7 +575,7 @@ void PicoWrite16_io(u32 a, u32 d)
     Pico.m.sram_reg |= (u8)(d & 3);\r
     return;\r
   }\r
-  if (!(PicoOpt & POPT_DIS_32X)) {\r
+  if (PicoOpt & POPT_EN_32X) {\r
     PicoWrite16_32x(a, d);\r
     return;\r
   }\r
@@ -957,7 +963,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
   if (xcycles >= timer_b_next_oflow) \\r
     ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 2\r
 \r
-static u32 MEMH_FUNC ym2612_read_local_z80(void)\r
+static u32 ym2612_read_local_z80(void)\r
 {\r
   int xcycles = z80_cyclesDone() << 8;\r
 \r
@@ -1052,17 +1058,25 @@ void ym2612_unpack_state(void)
   elprintf(EL_YMTIMER, "load: %i/%i, timer_b_next_oflow %i", tbt>>16, tbc>>16, timer_b_next_oflow >> 8);\r
 }\r
 \r
+#if defined(NO_32X) && defined(_ASM_MEMORY_C)\r
+// referenced by asm code\r
+u32 PicoRead8_32x(u32 a) { return 0; }\r
+u32 PicoRead16_32x(u32 a) { return 0; }\r
+void PicoWrite8_32x(u32 a, u32 d) {}\r
+void PicoWrite16_32x(u32 a, u32 d) {}\r
+#endif\r
+\r
 // -----------------------------------------------------------------\r
 //                        z80 memhandlers\r
 \r
-static unsigned char MEMH_FUNC z80_md_vdp_read(unsigned short a)\r
+static unsigned char z80_md_vdp_read(unsigned short a)\r
 {\r
   // TODO?\r
   elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, 0xff);\r
   return 0xff;\r
 }\r
 \r
-static unsigned char MEMH_FUNC z80_md_bank_read(unsigned short a)\r
+static unsigned char z80_md_bank_read(unsigned short a)\r
 {\r
   unsigned int addr68k;\r
   unsigned char ret;\r
@@ -1076,13 +1090,13 @@ static unsigned char MEMH_FUNC z80_md_bank_read(unsigned short a)
   return ret;\r
 }\r
 \r
-static void MEMH_FUNC z80_md_ym2612_write(unsigned int a, unsigned char data)\r
+static void z80_md_ym2612_write(unsigned int a, unsigned char data)\r
 {\r
   if (PicoOpt & POPT_EN_FM)\r
     emustatus |= ym2612_write_local(a, data, 1) & 1;\r
 }\r
 \r
-static void MEMH_FUNC z80_md_vdp_br_write(unsigned int a, unsigned char data)\r
+static void z80_md_vdp_br_write(unsigned int a, unsigned char data)\r
 {\r
   // TODO: allow full VDP access\r
   if ((a&0xfff9) == 0x7f11) // 7f11 7f13 7f15 7f17\r
@@ -1103,7 +1117,7 @@ static void MEMH_FUNC z80_md_vdp_br_write(unsigned int a, unsigned char data)
   elprintf(EL_ANOMALY, "z80 invalid w8 [%06x] %02x", a, data);\r
 }\r
 \r
-static void MEMH_FUNC z80_md_bank_write(unsigned int a, unsigned char data)\r
+static void z80_md_bank_write(unsigned int a, unsigned char data)\r
 {\r
   unsigned int addr68k;\r
 \r
@@ -1146,8 +1160,8 @@ static void z80_mem_setup(void)
   drZ80.z80_out = z80_md_out;\r
 #endif\r
 #ifdef _USE_CZ80\r
-  Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM\r
-  Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram); // mirror\r
+  Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (FPTR)Pico.zram); // main RAM\r
+  Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (FPTR)Pico.zram); // mirror\r
   Cz80_Set_INPort(&CZ80, z80_md_in);\r
   Cz80_Set_OUTPort(&CZ80, z80_md_out);\r
 #endif\r