X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fmemory.c;h=13fc67e6b9f06706f2eb571b21b6a0e65fa69d7f;hb=0ace9b9aac5de8f1ee5bf181132f98a1f81f4a1d;hp=5160df15bfe2d7d4552f592066bf411c461e3032;hpb=974fdb5bfda8ed006661031e22c920828ddb60dc;p=picodrive.git diff --git a/pico/memory.c b/pico/memory.c index 5160df1..13fc67e 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -21,7 +21,7 @@ unsigned long m68k_write8_map [0x1000000 >> M68K_MEM_SHIFT]; unsigned long 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) + const void *func_or_mh, int is_func) { unsigned long addr = (unsigned long)func_or_mh; int mask = (1 << shift) - 1; @@ -49,13 +49,13 @@ static void xmap_set(unsigned long *map, int shift, int start_addr, int end_addr } void z80_map_set(unsigned long *map, int start_addr, int end_addr, - void *func_or_mh, int is_func) + 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) + const void *func_or_mh, int is_func) { xmap_set(map, M68K_MEM_SHIFT, start_addr, end_addr, func_or_mh, is_func); } @@ -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); @@ -295,7 +264,7 @@ static void ctl_write_z80busreq(u32 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); @@ -319,6 +288,8 @@ static void ctl_write_z80reset(u32 d) // ----------------------------------------------------------------- +#ifndef _ASM_MEMORY_C + // cart (save) RAM area (usually 0x200000 - ...) static u32 PicoRead8_sram(u32 a) { @@ -364,6 +335,8 @@ static u32 PicoRead16_sram(u32 a) return m68k_unmapped_read16(a); } +#endif // _ASM_MEMORY_C + static void PicoWrite8_sram(u32 a, u32 d) { if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { @@ -457,7 +430,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; @@ -466,7 +438,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); } @@ -477,6 +448,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) { @@ -491,13 +464,15 @@ 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; } @@ -517,6 +492,7 @@ u32 PicoRead16_io(u32 a) if ((a & 0xffe0) == 0x0000) { // I/O ports d = io_ports_read(a); + d |= d << 8; goto end; } @@ -525,12 +501,13 @@ 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; } @@ -599,6 +576,8 @@ void PicoWrite16_io(u32 a, u32 d) 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) @@ -717,13 +696,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;