X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FMemory.c;h=48c32a6581b6224cdb7ed89fc5ec077cd7a6919e;hb=f8ef8ff7100baa0ac0ecfcacb47aea3a9e24bc38;hp=1e6630da76ba0bb0f743723150418337c0414788;hpb=b542be4686241c9e0722ff8e452980f9ac2b4d7c;p=picodrive.git diff --git a/Pico/Memory.c b/Pico/Memory.c index 1e6630d..48c32a6 100644 --- a/Pico/Memory.c +++ b/Pico/Memory.c @@ -1,14 +1,12 @@ // This is part of Pico Library // (c) Copyright 2004 Dave, All rights reserved. -// (c) Copyright 2006 notaz, All rights reserved. +// (c) Copyright 2006,2007 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. -//#define __debug_io - #include "PicoInt.h" #include "sound/ym2612.h" @@ -141,16 +139,33 @@ static u32 SRAMRead(u32 a) { unsigned int sreg = Pico.m.sram_reg; - if(!(sreg & 0x10) && (sreg & 1) && a > 0x200001) { // not yet detected SRAM + if (!(sreg & 0x10) && (sreg & 1) && a > 0x200001) { // not yet detected SRAM elprintf(EL_SRAMIO, "normal sram detected."); Pico.m.sram_reg|=0x10; // should be normal SRAM } - if(sreg & 4) // EEPROM read + if (sreg & 4) // EEPROM read return SRAMReadEEPROM(); else // if(sreg & 1) // (sreg&5) is one of prerequisites return *(u8 *)(SRam.data-SRam.start+a); } +#ifndef _ASM_MEMORY_C +static +#endif +u32 SRAMRead16(u32 a) +{ + u32 d; + if (Pico.m.sram_reg & 4) { + d = SRAMReadEEPROM(); + d |= d << 8; + } else { + u8 *pm=(u8 *)(SRam.data-SRam.start+a); + d =*pm++ << 8; + d|=*pm++; + } + return d; +} + static void SRAMWrite(u32 a, u32 d) { unsigned int sreg = Pico.m.sram_reg; @@ -188,10 +203,7 @@ static void SRAMWrite(u32 a, u32 d) } // for nonstandard reads -#ifndef _ASM_MEMORY_C -static -#endif -u32 OtherRead16End(u32 a, int realsize) +static u32 OtherRead16End(u32 a, int realsize) { u32 d=0; @@ -305,7 +317,6 @@ static void OtherWrite8End(u32 a,u32 d,int realsize) Pico.m.prot_bytes[(a>>2)&1] = (u8)d; } - #include "MemoryCmn.c" @@ -339,10 +350,8 @@ PICO_INTERNAL_ASM u32 PicoRead8(u32 a) else d=OtherRead16(a&~1, 8); if ((a&1)==0) d>>=8; - -#ifdef __debug_io - dprintf("r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc); -#endif +end: + elprintf(EL_IO, "r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc); #ifdef EMU_CORE_DEBUG if (a>=Pico.romsize) { lastread_a = a; @@ -363,8 +372,7 @@ PICO_INTERNAL_ASM u32 PicoRead16(u32 a) #ifndef EMU_CORE_DEBUG // sram if (a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) { - d = SRAMRead(a); - d |= d<<8; + d = SRAMRead16(a); elprintf(EL_SRAMIO, "sram r16 [%06x] %04x @ %06x", a, d, SekPc); goto end; } @@ -378,9 +386,7 @@ PICO_INTERNAL_ASM u32 PicoRead16(u32 a) else d = OtherRead16(a, 16); end: -#ifdef __debug_io - dprintf("r16: %06x, %04x @%06x", a&0xffffff, d, SekPc); -#endif + elprintf(EL_IO, "r16: %06x, %04x @%06x", a&0xffffff, d, SekPc); #ifdef EMU_CORE_DEBUG if (a>=Pico.romsize) { lastread_a = a; @@ -400,8 +406,7 @@ PICO_INTERNAL_ASM u32 PicoRead32(u32 a) // sram if(a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg&5)) { - d = (SRAMRead(a)<<16)|SRAMRead(a+2); - d |= d<<8; + d = (SRAMRead16(a)<<16)|SRAMRead16(a+2); elprintf(EL_SRAMIO, "sram r32 [%06x] %08x @ %06x", a, d, SekPc); goto end; } @@ -414,9 +419,7 @@ PICO_INTERNAL_ASM u32 PicoRead32(u32 a) else d = (OtherRead16(a, 32)<<16)|OtherRead16(a+2, 32); end: -#ifdef __debug_io - dprintf("r32: %06x, %08x @%06x", a&0xffffff, d, SekPc); -#endif + elprintf(EL_IO, "r32: %06x, %08x @%06x", a&0xffffff, d, SekPc); #ifdef EMU_CORE_DEBUG if (a>=Pico.romsize) { lastread_a = a; @@ -433,9 +436,7 @@ end: #if !defined(_ASM_MEMORY_C) || defined(_ASM_MEMORY_C_AMIPS) PICO_INTERNAL_ASM void PicoWrite8(u32 a,u8 d) { -#ifdef __debug_io - dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); -#endif + elprintf(EL_IO, "w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); #ifdef EMU_CORE_DEBUG lastwrite_cyc_d[lwp_cyc++&15] = d; #endif @@ -450,9 +451,7 @@ PICO_INTERNAL_ASM void PicoWrite8(u32 a,u8 d) void PicoWrite16(u32 a,u16 d) { -#ifdef __debug_io - dprintf("w16: %06x, %04x", a&0xffffff, d); -#endif + elprintf(EL_IO, "w16: %06x, %04x", a&0xffffff, d); #ifdef EMU_CORE_DEBUG lastwrite_cyc_d[lwp_cyc++&15] = d; #endif @@ -467,9 +466,7 @@ void PicoWrite16(u32 a,u16 d) static void PicoWrite32(u32 a,u32 d) { -#ifdef __debug_io - dprintf("w32: %06x, %08x", a&0xffffff, d); -#endif + elprintf(EL_IO, "w32: %06x, %08x", a&0xffffff, d); #ifdef EMU_CORE_DEBUG lastwrite_cyc_d[lwp_cyc++&15] = d; #endif @@ -498,6 +495,26 @@ static void PicoWrite32(u32 a,u32 d) // ----------------------------------------------------------------- + +// TODO: asm code +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; +} + PICO_INTERNAL void PicoMemSetup(void) { // Setup memory callbacks: @@ -592,9 +609,7 @@ unsigned int m68k_read_memory_8(unsigned int a) if (a=0x8000) { + extern u32 PicoReadM68k8(u32 a); u32 addr68k; addr68k=Pico.m.z80_bank68k<<15; addr68k+=a&0x7fff; - ret = (u8) PicoRead8(addr68k); + if (PicoMCD & 1) + ret = PicoReadM68k8(addr68k); + else ret = PicoRead8(addr68k); elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret); return ret; } @@ -728,11 +742,14 @@ PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data) if (a>=0x8000) { + extern void PicoWriteM68k8(u32 a,u8 d); u32 addr68k; addr68k=Pico.m.z80_bank68k<<15; addr68k+=a&0x7fff; elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data); - PicoWrite8(addr68k, data); + if (PicoMCD & 1) + PicoWriteM68k8(addr68k, data); + else PicoWrite8(addr68k, data); return; }