X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fmemory.c;h=2fff489b6cec31b7cca905a4706d4009de35e19d;hb=a505b5f14bc28268d6366d1d9c231ab57ff0159d;hp=aa2a54e7cdd91662f754915241f860a4b6dc1287;hpb=af37bca858874b5cbd5ab126eaba1fad6ff7ab72;p=picodrive.git diff --git a/pico/memory.c b/pico/memory.c index aa2a54e..2fff489 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -15,15 +15,15 @@ extern unsigned int lastSSRamWrite; // used by serial eeprom code -unsigned long m68k_read8_map [0x1000000 >> M68K_MEM_SHIFT]; -unsigned long m68k_read16_map [0x1000000 >> M68K_MEM_SHIFT]; -unsigned long m68k_write8_map [0x1000000 >> M68K_MEM_SHIFT]; -unsigned long m68k_write16_map[0x1000000 >> M68K_MEM_SHIFT]; +uptr m68k_read8_map [0x1000000 >> M68K_MEM_SHIFT]; +uptr m68k_read16_map [0x1000000 >> M68K_MEM_SHIFT]; +uptr m68k_write8_map [0x1000000 >> M68K_MEM_SHIFT]; +uptr m68k_write16_map[0x1000000 >> M68K_MEM_SHIFT]; -static void xmap_set(unsigned long *map, int shift, int start_addr, int end_addr, - void *func_or_mh, int is_func) +static void xmap_set(uptr *map, int shift, int start_addr, int end_addr, + const void *func_or_mh, int is_func) { - unsigned long addr = (unsigned long)func_or_mh; + uptr addr = (uptr)func_or_mh; int mask = (1 << shift) - 1; int i; @@ -44,18 +44,18 @@ 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++) { map[i] = addr >> 1; if (is_func) - map[i] |= 1 << (sizeof(addr) * 8 - 1); + map[i] |= (uptr)1 << (sizeof(addr) * 8 - 1); } } -void z80_map_set(unsigned long *map, int start_addr, int end_addr, - void *func_or_mh, int is_func) +void z80_map_set(uptr *map, int start_addr, int end_addr, + const void *func_or_mh, int is_func) { xmap_set(map, Z80_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func); } -void cpu68k_map_set(unsigned long *map, int start_addr, int end_addr, - void *func_or_mh, int is_func) +void cpu68k_map_set(uptr *map, int start_addr, int end_addr, + const void *func_or_mh, int is_func) { xmap_set(map, M68K_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func); } @@ -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) void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub) { - unsigned long *r8map, *r16map, *w8map, *w16map; - unsigned long addr = (unsigned long)ptr; + uptr *r8map, *r16map, *w8map, *w16map; + uptr addr = (uptr)ptr; int shift = M68K_MEM_SHIFT; int i; @@ -110,23 +110,23 @@ static void m68k_unmapped_write16(u32 a, u32 d) void m68k_map_unmap(int start_addr, int end_addr) { - unsigned long addr; + uptr addr; int shift = M68K_MEM_SHIFT; int i; - addr = (unsigned long)m68k_unmapped_read8; + addr = (uptr)m68k_unmapped_read8; for (i = start_addr >> shift; i <= end_addr >> shift; i++) m68k_read8_map[i] = (addr >> 1) | (1 << 31); - addr = (unsigned long)m68k_unmapped_read16; + addr = (uptr)m68k_unmapped_read16; for (i = start_addr >> shift; i <= end_addr >> shift; i++) m68k_read16_map[i] = (addr >> 1) | (1 << 31); - addr = (unsigned long)m68k_unmapped_write8; + addr = (uptr)m68k_unmapped_write8; for (i = start_addr >> shift; i <= end_addr >> shift; i++) m68k_write8_map[i] = (addr >> 1) | (1 << 31); - addr = (unsigned long)m68k_unmapped_write16; + addr = (uptr)m68k_unmapped_write16; for (i = start_addr >> shift; i <= end_addr >> shift; i++) m68k_write16_map[i] = (addr >> 1) | (1 << 31); } @@ -144,6 +144,10 @@ static u32 ym2612_read_local_68k(void); static int ym2612_write_local(u32 a, u32 d, int is_from_z80); static void z80_mem_setup(void); +#ifdef _ASM_MEMORY_C +u32 PicoRead8_sram(u32 a); +u32 PicoRead16_sram(u32 a); +#endif #ifdef EMU_CORE_DEBUG u32 lastread_a, lastread_d[16]={0,}, lastwrite_cyc_d[16]={0,}, lastwrite_mus_d[16]={0,}; @@ -160,61 +164,22 @@ void log_io(unsigned int addr, int bits, int rw); #endif #if defined(EMU_C68K) -static __inline int PicoMemBase(u32 pc) +void cyclone_crashed(u32 pc, struct Cyclone *context) { - int membase=0; - - if (pcmembase = (u32)Pico.rom; + context->pc = (u32)Pico.rom + Pico.romsize; } #endif - -PICO_INTERNAL u32 PicoCheckPc(u32 pc) -{ - u32 ret=0; -#if defined(EMU_C68K) - pc-=PicoCpuCM68k.membase; // Get real pc -// pc&=0xfffffe; - pc&=~1; - if ((pc<<8) == 0) - { - elprintf(EL_STATUS|EL_ANOMALY, "%i:%03i: game crash detected @ %06x\n", - Pico.m.frame_count, Pico.m.scanline, SekPc); - return (int)Pico.rom + Pico.romsize; // common crash condition, may happen with bad ROMs - } - - PicoCpuCM68k.membase=PicoMemBase(pc&0x00ffffff); - PicoCpuCM68k.membase-=pc&0xff000000; - - ret = PicoCpuCM68k.membase+pc; -#endif - return ret; -} - - -PICO_INTERNAL void PicoInitPc(u32 pc) -{ - PicoCheckPc(pc); -} - // ----------------------------------------------------------------- // memmap helpers -static int PadRead(int i) +#ifndef _ASM_MEMORY_C +static +#endif +int PadRead(int i) { int pad,value,data_reg; pad=~PicoPadInt[i]; // Get inverse of pad MXYZ SACB RLDU @@ -246,6 +211,8 @@ static int PadRead(int i) return value; // will mirror later } +#ifndef _ASM_MEMORY_C + static u32 io_ports_read(u32 a) { u32 d; @@ -259,7 +226,7 @@ static u32 io_ports_read(u32 a) return d; } -static void io_ports_write(u32 a, u32 d) +static void NOINLINE io_ports_write(u32 a, u32 d) { a = (a>>1) & 0xf; @@ -271,11 +238,13 @@ static void io_ports_write(u32 a, u32 d) Pico.m.padTHPhase[a - 1]++; } - // cartain IO ports can be used as RAM + // certain IO ports can be used as RAM Pico.ioports[a] = d; } -static void ctl_write_z80busreq(u32 d) +#endif // _ASM_MEMORY_C + +void NOINLINE ctl_write_z80busreq(u32 d) { d&=1; d^=1; elprintf(EL_BUSREQ, "set_zrun: %i->%i [%i] @%06x", Pico.m.z80Run, d, SekCyclesDone(), SekPc); @@ -288,14 +257,17 @@ static void ctl_write_z80busreq(u32 d) else { z80stopCycle = SekCyclesDone(); - if ((PicoOpt&POPT_EN_Z80) && !Pico.m.z80_reset) + if ((PicoOpt&POPT_EN_Z80) && !Pico.m.z80_reset) { + pprof_start(m68k); PicoSyncZ80(z80stopCycle); + pprof_end_sub(m68k); + } } Pico.m.z80Run = d; } } -static void ctl_write_z80reset(u32 d) +void NOINLINE ctl_write_z80reset(u32 d) { d&=1; d^=1; elprintf(EL_BUSREQ, "set_zreset: %i->%i [%i] @%06x", Pico.m.z80_reset, d, SekCyclesDone(), SekPc); @@ -303,8 +275,11 @@ static void ctl_write_z80reset(u32 d) { if (d) { - if ((PicoOpt&POPT_EN_Z80) && Pico.m.z80Run) + if ((PicoOpt&POPT_EN_Z80) && Pico.m.z80Run) { + pprof_start(m68k); PicoSyncZ80(SekCyclesDone()); + pprof_end_sub(m68k); + } YM2612ResetChip(); timers_reset(); } @@ -317,127 +292,27 @@ static void ctl_write_z80reset(u32 d) } } - -// for nonstandard reads -// TODO: mv to carthw -static u32 OtherRead16End(u32 a, int realsize) -{ - u32 d=0; - - // 32x test -/* - if (a == 0xa130ec) { d = 0x4d41; goto end; } // MA - else if (a == 0xa130ee) { d = 0x5253; goto end; } // RS - else if (a == 0xa15100) { d = 0x0080; goto end; } - else -*/ - - // for games with simple protection devices, discovered by Haze - // some dumb detection is used, but that should be enough to make things work - if ((a>>22) == 1 && Pico.romsize >= 512*1024) { - if (*(int *)(Pico.rom+0x123e4) == 0x00550c39 && *(int *)(Pico.rom+0x123e8) == 0x00000040) { // Super Bubble Bobble (Unl) [!] - if (a == 0x400000) { d=0x55<<8; goto end; } - else if (a == 0x400002) { d=0x0f<<8; goto end; } - } - else if (*(int *)(Pico.rom+0x008c4) == 0x66240055 && *(int *)(Pico.rom+0x008c8) == 0x00404df9) { // Smart Mouse (Unl) - if (a == 0x400000) { d=0x55<<8; goto end; } - else if (a == 0x400002) { d=0x0f<<8; goto end; } - else if (a == 0x400004) { d=0xaa<<8; goto end; } - else if (a == 0x400006) { d=0xf0<<8; goto end; } - } - else if (*(int *)(Pico.rom+0x00404) == 0x00a90600 && *(int *)(Pico.rom+0x00408) == 0x6708b013) { // King of Fighters '98, The (Unl) [!] - if (a == 0x480000 || a == 0x4800e0 || a == 0x4824a0 || a == 0x488880) { d=0xaa<<8; goto end; } - else if (a == 0x4a8820) { d=0x0a<<8; goto end; } - // there is also a read @ 0x4F8820 which needs 0, but that is returned in default case - } - else if (*(int *)(Pico.rom+0x01b24) == 0x004013f9 && *(int *)(Pico.rom+0x01b28) == 0x00ff0000) { // Mahjong Lover (Unl) [!] - if (a == 0x400000) { d=0x90<<8; goto end; } - else if (a == 0x401000) { d=0xd3<<8; goto end; } // this one doesn't seem to be needed, the code does 2 comparisons and only then - // checks the result, which is of the above one. Left it just in case. - } - else if (*(int *)(Pico.rom+0x05254) == 0x0c3962d0 && *(int *)(Pico.rom+0x05258) == 0x00400055) { // Elf Wor (Unl) - if (a == 0x400000) { d=0x55<<8; goto end; } - else if (a == 0x400004) { d=0xc9<<8; goto end; } // this check is done if the above one fails - else if (a == 0x400002) { d=0x0f<<8; goto end; } - else if (a == 0x400006) { d=0x18<<8; goto end; } // similar to above - } - // our default behaviour is to return whatever was last written a 0x400000-0x7fffff range (used by Squirrel King (R) [!]) - // Lion King II, The (Unl) [!] writes @ 400000 and wants to get that val @ 400002 and wites another val - // @ 400004 which is expected @ 400006, so we really remember 2 values here - d = Pico.m.prot_bytes[(a>>2)&1]<<8; - } - else if (a == 0xa13000 && Pico.romsize >= 1024*1024) { - if (*(int *)(Pico.rom+0xc8af0) == 0x30133013 && *(int *)(Pico.rom+0xc8af4) == 0x000f0240) { // Rockman X3 (Unl) [!] - d=0x0c; goto end; - } - else if (*(int *)(Pico.rom+0x28888) == 0x07fc0000 && *(int *)(Pico.rom+0x2888c) == 0x4eb94e75) { // Bug's Life, A (Unl) [!] - d=0x28; goto end; // does the check from RAM - } - else if (*(int *)(Pico.rom+0xc8778) == 0x30133013 && *(int *)(Pico.rom+0xc877c) == 0x000f0240) { // Super Mario Bros. (Unl) [!] - d=0x0c; goto end; // seems to be the same code as in Rockman X3 (Unl) [!] - } - else if (*(int *)(Pico.rom+0xf20ec) == 0x30143013 && *(int *)(Pico.rom+0xf20f0) == 0x000f0200) { // Super Mario 2 1998 (Unl) [!] - d=0x0a; goto end; - } - } - else if (a == 0xa13002) { // Pocket Monsters (Unl) - d=0x01; goto end; - } - else if (a == 0xa1303E) { // Pocket Monsters (Unl) - d=0x1f; goto end; - } - else if (a == 0x30fe02) { - // Virtua Racing - just for fun - // this seems to be some flag that SVP is ready or something similar - d=1; goto end; - } - -end: - elprintf(EL_UIO, "strange r%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc); - return d; -} - -static void OtherWrite8End(u32 a,u32 d,int realsize) -{ -#ifdef _ASM_MEMORY_C - // special ROM hardware (currently only banking and sram reg supported) - if((a&0xfffff1) == 0xA130F1) { - PicoWriteRomHW_SSF2(a, d); // SSF2 or SRAM - return; - } -#else - // sram access register - if(a == 0xA130F1) { - elprintf(EL_SRAMIO, "sram reg=%02x", d); - Pico.m.sram_status &= ~(SRS_MAPPED|SRS_READONLY); - Pico.m.sram_status |= (u8)(d&3); - return; - } -#endif - elprintf(EL_UIO, "strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc); - - // for games with simple protection devices, discovered by Haze - if ((a>>22) == 1) - Pico.m.prot_bytes[(a>>2)&1] = (u8)d; -} - // ----------------------------------------------------------------- +#ifndef _ASM_MEMORY_C + // cart (save) RAM area (usually 0x200000 - ...) static u32 PicoRead8_sram(u32 a) { - int srs = Pico.m.sram_status; u32 d; - if (SRam.end >= a && a >= SRam.start && (srs & (SRS_MAPPED|SRS_EEPROM))) + if (SRam.start <= a && a <= SRam.end && (Pico.m.sram_reg & SRR_MAPPED)) { - if (srs & SRS_EEPROM) + if (SRam.flags & SRF_EEPROM) { d = EEPROM_read(); - else + if (!(a & 1)) + d >>= 8; + } else d = *(u8 *)(SRam.data - SRam.start + a); - elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc); + elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc); return d; } + // XXX: this is banking unfriendly if (a < Pico.romsize) return Pico.rom[a ^ 1]; @@ -446,14 +321,12 @@ static u32 PicoRead8_sram(u32 a) static u32 PicoRead16_sram(u32 a) { - int srs = Pico.m.sram_status; u32 d; - if (SRam.end >= a && a >= SRam.start && (srs & (SRS_MAPPED|SRS_EEPROM))) + if (SRam.start <= a && a <= SRam.end && (Pico.m.sram_reg & SRR_MAPPED)) { - if (srs & SRS_EEPROM) { + if (SRam.flags & SRF_EEPROM) d = EEPROM_read(); - d |= d << 8; - } else { + else { u8 *pm = (u8 *)(SRam.data - SRam.start + a); d = pm[0] << 8; d |= pm[1]; @@ -468,27 +341,22 @@ static u32 PicoRead16_sram(u32 a) return m68k_unmapped_read16(a); } +#endif // _ASM_MEMORY_C + static void PicoWrite8_sram(u32 a, u32 d) { - unsigned int srs = Pico.m.sram_status; - elprintf(EL_SRAMIO, "sram wX [%06x] %02x @ %06x", a, d & 0xffff, SekPc); - if (srs & SRS_EEPROM) // EEPROM write + if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { + m68k_unmapped_write8(a, d); + return; + } + + elprintf(EL_SRAMIO, "sram w8 [%06x] %02x @ %06x", a, d & 0xff, SekPc); + if (SRam.flags & SRF_EEPROM) { - // this diff must be at most 16 for NBA Jam to work - if (SekCyclesDoneT() - lastSSRamWrite < 16) { - // just update pending state - elprintf(EL_EEPROM, "eeprom: skip because cycles=%i", - SekCyclesDoneT() - lastSSRamWrite); - EEPROM_upd_pending(a, d); - } else { - EEPROM_write(srs >> 6); // execute pending - EEPROM_upd_pending(a, d); - if ((srs ^ Pico.m.sram_status) & 0xc0) // update time only if SDA/SCL changed - lastSSRamWrite = SekCyclesDoneT(); - } + EEPROM_write8(a, d); } - else if (!(srs & SRS_READONLY)) { - u8 *pm=(u8 *)(SRam.data - SRam.start + a); + else { + u8 *pm = (u8 *)(SRam.data - SRam.start + a); if (*pm != (u8)d) { SRam.changed = 1; *pm = (u8)d; @@ -498,8 +366,24 @@ static void PicoWrite8_sram(u32 a, u32 d) static void PicoWrite16_sram(u32 a, u32 d) { - // XXX: hardware could easily use MSB too.. - PicoWrite8_sram(a + 1, d); + if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { + m68k_unmapped_write16(a, d); + return; + } + + elprintf(EL_SRAMIO, "sram w16 [%06x] %04x @ %06x", a, d & 0xffff, SekPc); + if (SRam.flags & SRF_EEPROM) + { + EEPROM_write16(d); + } + else { + // XXX: hardware could easily use MSB too.. + u8 *pm = (u8 *)(SRam.data - SRam.start + a); + if (*pm != (u8)d) { + SRam.changed = 1; + *pm = (u8)d; + } + } } // z80 area (0xa00000 - 0xa0ffff) @@ -552,7 +436,6 @@ static void PicoWrite8_z80(u32 a, u32 d) SN76496Write(d); return; } -#if !defined(_ASM_MEMORY_C) || defined(_ASM_MEMORY_C_AMIPS) if ((a & 0x7f00) == 0x6000) // Z80 BANK register { Pico.m.z80_bank68k >>= 1; @@ -561,7 +444,6 @@ static void PicoWrite8_z80(u32 a, u32 d) elprintf(EL_Z80BNK, "z80 bank=%06x", Pico.m.z80_bank68k << 15); return; } -#endif elprintf(EL_UIO|EL_ANOMALY, "68k bad write [%06x] %02x @ %06x", a, d&0xff, SekPc); } @@ -572,6 +454,8 @@ static void PicoWrite16_z80(u32 a, u32 d) PicoWrite8_z80(a, d >> 8); } +#ifndef _ASM_MEMORY_C + // IO/control area (0xa10000 - 0xa1ffff) u32 PicoRead8_io(u32 a) { @@ -586,13 +470,20 @@ u32 PicoRead8_io(u32 a) d = Pico.m.rotate++; d ^= d << 6; - // bit8 seems to be readable in this range - if ((a & 0xfc01) == 0x1000) - d &= ~0x01; + if ((a & 0xfc00) == 0x1000) { + // bit8 seems to be readable in this range + if (!(a & 1)) + d &= ~0x01; - if ((a & 0xff01) == 0x1100) { // z80 busreq (verified) - d |= (Pico.m.z80Run | Pico.m.z80_reset) & 1; - elprintf(EL_BUSREQ, "get_zrun: %02x [%i] @%06x", d, SekCyclesDone(), SekPc); + if ((a & 0xff01) == 0x1100) { // z80 busreq (verified) + d |= (Pico.m.z80Run | Pico.m.z80_reset) & 1; + elprintf(EL_BUSREQ, "get_zrun: %02x [%i] @%06x", d, SekCyclesDone(), SekPc); + } + goto end; + } + + if (PicoOpt & POPT_EN_32X) { + d = PicoRead8_32x(a); goto end; } @@ -607,6 +498,7 @@ u32 PicoRead16_io(u32 a) if ((a & 0xffe0) == 0x0000) { // I/O ports d = io_ports_read(a); + d |= d << 8; goto end; } @@ -615,12 +507,18 @@ u32 PicoRead16_io(u32 a) d ^= (d << 5) ^ (d << 8); // bit8 seems to be readable in this range - if ((a & 0xfc00) == 0x1000) + if ((a & 0xfc00) == 0x1000) { d &= ~0x0100; - if ((a & 0xff00) == 0x1100) { // z80 busreq - d |= ((Pico.m.z80Run | Pico.m.z80_reset) & 1) << 8; - elprintf(EL_BUSREQ, "get_zrun: %04x [%i] @%06x", d, SekCyclesDone(), SekPc); + if ((a & 0xff00) == 0x1100) { // z80 busreq + d |= ((Pico.m.z80Run | Pico.m.z80_reset) & 1) << 8; + elprintf(EL_BUSREQ, "get_zrun: %04x [%i] @%06x", d, SekCyclesDone(), SekPc); + } + goto end; + } + + if (PicoOpt & POPT_EN_32X) { + d = PicoRead16_32x(a); goto end; } @@ -645,10 +543,15 @@ void PicoWrite8_io(u32 a, u32 d) } if (a == 0xa130f1) { // sram access register elprintf(EL_SRAMIO, "sram reg=%02x", d); - Pico.m.sram_status &= ~(SRS_MAPPED|SRS_READONLY); - Pico.m.sram_status |= (u8)(d & 3); + Pico.m.sram_reg &= ~(SRR_MAPPED|SRR_READONLY); + Pico.m.sram_reg |= (u8)(d & 3); return; } + if (PicoOpt & POPT_EN_32X) { + PicoWrite8_32x(a, d); + return; + } + m68k_unmapped_write8(a, d); } @@ -668,13 +571,19 @@ void PicoWrite16_io(u32 a, u32 d) } if (a == 0xa130f0) { // sram access register elprintf(EL_SRAMIO, "sram reg=%02x", d); - Pico.m.sram_status &= ~(SRS_MAPPED|SRS_READONLY); - Pico.m.sram_status |= (u8)(d & 3); + Pico.m.sram_reg &= ~(SRR_MAPPED|SRR_READONLY); + Pico.m.sram_reg |= (u8)(d & 3); + return; + } + if (PicoOpt & POPT_EN_32X) { + PicoWrite16_32x(a, d); return; } m68k_unmapped_write16(a, d); } +#endif // _ASM_MEMORY_C + // VDP area (0xc00000 - 0xdfffff) // TODO: verify if lower byte goes to PSG on word writes static u32 PicoRead8_vdp(u32 a) @@ -728,25 +637,6 @@ static void PicoWrite16_vdp(u32 a, u32 d) // ----------------------------------------------------------------- -// TODO: rm -static void OtherWrite16End(u32 a,u32 d,int realsize) -{ - PicoWrite8Hook(a, d>>8, realsize); - PicoWrite8Hook(a+1,d&0xff, realsize); -} - -u32 (*PicoRead16Hook) (u32 a, int realsize) = OtherRead16End; -void (*PicoWrite8Hook) (u32 a, u32 d, int realsize) = OtherWrite8End; -void (*PicoWrite16Hook)(u32 a, u32 d, int realsize) = OtherWrite16End; - -PICO_INTERNAL void PicoMemResetHooks(void) -{ - // default unmapped/cart specific handlers - PicoRead16Hook = OtherRead16End; - PicoWrite8Hook = OtherWrite8End; - PicoWrite16Hook = OtherWrite16End; -} - #ifdef EMU_M68K static void m68k_mem_setup(void); #endif @@ -769,8 +659,8 @@ PICO_INTERNAL void PicoMemSetup(void) cpu68k_map_set(m68k_read16_map, 0x000000, rs - 1, Pico.rom, 0); // Common case of on-cart (save) RAM, usually at 0x200000-... - rs = SRam.end - SRam.start; - if (rs > 0 && SRam.data != NULL) { + if ((SRam.flags & SRF_ENABLED) && SRam.data != NULL) { + rs = SRam.end - SRam.start; rs = (rs + mask) & ~mask; if (SRam.start + rs >= 0x1000000) rs = 0x1000000 - SRam.start; @@ -812,13 +702,16 @@ PICO_INTERNAL void PicoMemSetup(void) // Setup memory callbacks: #ifdef EMU_C68K - PicoCpuCM68k.checkpc = PicoCheckPc; - PicoCpuCM68k.fetch8 = PicoCpuCM68k.read8 = m68k_read8; - PicoCpuCM68k.fetch16 = PicoCpuCM68k.read16 = m68k_read16; - PicoCpuCM68k.fetch32 = PicoCpuCM68k.read32 = m68k_read32; - PicoCpuCM68k.write8 = m68k_write8; - PicoCpuCM68k.write16 = m68k_write16; - PicoCpuCM68k.write32 = m68k_write32; + PicoCpuCM68k.read8 = (void *)m68k_read8_map; + PicoCpuCM68k.read16 = (void *)m68k_read16_map; + PicoCpuCM68k.read32 = (void *)m68k_read16_map; + PicoCpuCM68k.write8 = (void *)m68k_write8_map; + PicoCpuCM68k.write16 = (void *)m68k_write16_map; + PicoCpuCM68k.write32 = (void *)m68k_write16_map; + PicoCpuCM68k.checkpc = NULL; /* unused */ + PicoCpuCM68k.fetch8 = NULL; + PicoCpuCM68k.fetch16 = NULL; + PicoCpuCM68k.fetch32 = NULL; #endif #ifdef EMU_F68K PicoCpuFM68k.read_byte = m68k_read8; @@ -849,7 +742,6 @@ PICO_INTERNAL void PicoMemSetup(void) z80_mem_setup(); } -/* some nasty things below :( */ #ifdef EMU_M68K unsigned int (*pm68k_read_memory_8) (unsigned int address) = NULL; unsigned int (*pm68k_read_memory_16)(unsigned int address) = NULL; @@ -857,103 +749,6 @@ unsigned int (*pm68k_read_memory_32)(unsigned int address) = NULL; void (*pm68k_write_memory_8) (unsigned int address, unsigned char value) = NULL; void (*pm68k_write_memory_16)(unsigned int address, unsigned short value) = NULL; void (*pm68k_write_memory_32)(unsigned int address, unsigned int value) = NULL; -unsigned int (*pm68k_read_memory_pcr_8) (unsigned int address) = NULL; -unsigned int (*pm68k_read_memory_pcr_16)(unsigned int address) = NULL; -unsigned int (*pm68k_read_memory_pcr_32)(unsigned int address) = NULL; - -// these are here for core debugging mode -static unsigned int m68k_read_8 (unsigned int a, int do_fake) -{ - a&=0xffffff; - if(a= timer_b_next_oflow) \ ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 2 -static u32 MEMH_FUNC ym2612_read_local_z80(void) +static u32 ym2612_read_local_z80(void) { int xcycles = z80_cyclesDone() << 8; @@ -1267,45 +1058,45 @@ 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); } +#if defined(NO_32X) && defined(_ASM_MEMORY_C) +// referenced by asm code +u32 PicoRead8_32x(u32 a) { return 0; } +u32 PicoRead16_32x(u32 a) { return 0; } +void PicoWrite8_32x(u32 a, u32 d) {} +void PicoWrite16_32x(u32 a, u32 d) {} +#endif + // ----------------------------------------------------------------- // z80 memhandlers -static unsigned char MEMH_FUNC z80_md_vdp_read(unsigned short a) +static unsigned char z80_md_vdp_read(unsigned short a) { // TODO? elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, 0xff); return 0xff; } -static unsigned char MEMH_FUNC z80_md_bank_read(unsigned short a) +static unsigned char z80_md_bank_read(unsigned short a) { - extern unsigned int PicoReadM68k8(unsigned int a); unsigned int addr68k; unsigned char ret; addr68k = Pico.m.z80_bank68k<<15; addr68k += a & 0x7fff; - if (addr68k < Pico.romsize) { - ret = Pico.rom[addr68k^1]; - goto out; - } - ret = m68k_read8(addr68k); - elprintf(EL_ANOMALY, "z80->68k upper read [%06x] %02x", addr68k, ret); -out: elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret); return ret; } -static void MEMH_FUNC z80_md_ym2612_write(unsigned int a, unsigned char data) +static void z80_md_ym2612_write(unsigned int a, unsigned char data) { if (PicoOpt & POPT_EN_FM) emustatus |= ym2612_write_local(a, data, 1) & 1; } -static void MEMH_FUNC z80_md_vdp_br_write(unsigned int a, unsigned char data) +static void z80_md_vdp_br_write(unsigned int a, unsigned char data) { // TODO: allow full VDP access if ((a&0xfff9) == 0x7f11) // 7f11 7f13 7f15 7f17 @@ -1326,9 +1117,8 @@ 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); } -static void MEMH_FUNC z80_md_bank_write(unsigned int a, unsigned char data) +static void z80_md_bank_write(unsigned int a, unsigned char data) { - extern void PicoWriteM68k8(unsigned int a, unsigned char d); unsigned int addr68k; addr68k = Pico.m.z80_bank68k << 15; @@ -1370,8 +1160,8 @@ static void z80_mem_setup(void) drZ80.z80_out = z80_md_out; #endif #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM - Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram); // mirror + Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (FPTR)Pico.zram); // main RAM + Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (FPTR)Pico.zram); // mirror Cz80_Set_INPort(&CZ80, z80_md_in); Cz80_Set_OUTPort(&CZ80, z80_md_out); #endif