X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FMemory.c;h=b4e473bf200750da0e2ba3949744ec1b62107600;hb=b923ecbe75225bc7a1b6fbf419fd962a59066d59;hp=a3372d6000c174d68da3c1107b3cc47cb9495aab;hpb=81fda4e8d854c96e70dc2e6b7cd2f48a51f55d86;p=picodrive.git diff --git a/Pico/Memory.c b/Pico/Memory.c index a3372d6..b4e473b 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" @@ -39,6 +37,8 @@ extern unsigned int ppop; #ifdef IO_STATS void log_io(unsigned int addr, int bits, int rw); +#elif defined(_MSC_VER) +#define log_io #else #define log_io(...) #endif @@ -112,7 +112,8 @@ int PadRead(int i) // orr the bits, which are set as output value = data_reg&(Pico.ioports[i+4]|0x80); - if(PicoOpt & 0x20) { // 6 button gamepad enabled + if (PicoOpt & POPT_6BTN_PAD) + { int phase = Pico.m.padTHPhase[i]; if(phase == 2 && !(data_reg&0x40)) { // TH @@ -141,16 +142,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 +206,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; @@ -289,23 +304,11 @@ static void OtherWrite8End(u32 a,u32 d,int realsize) #endif elprintf(EL_UIO, "strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc); - if(a >= 0xA13004 && a < 0xA13040) { - // dumb 12-in-1 or 4-in-1 banking support - int len; - a &= 0x3f; a <<= 16; - len = Pico.romsize - a; - if (len <= 0) return; // invalid/missing bank - if (len > 0x200000) len = 0x200000; // 2 megs - memcpy(Pico.rom, Pico.rom+a, len); // code which does this is in RAM so this is safe. - return; - } - // for games with simple protection devices, discovered by Haze - else if ((a>>22) == 1) + if ((a>>22) == 1) Pico.m.prot_bytes[(a>>2)&1] = (u8)d; } - #include "MemoryCmn.c" @@ -340,9 +343,7 @@ PICO_INTERNAL_ASM u32 PicoRead8(u32 a) if ((a&1)==0) d>>=8; end: -#ifdef __debug_io - dprintf("r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc); -#endif + 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 +364,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 +378,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 +398,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 +411,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 +428,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 +443,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 +458,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 +487,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: @@ -548,7 +557,7 @@ static unsigned int m68k_read_8 (unsigned int a, int do_fake) #ifdef EMU_CORE_DEBUG if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15]; #endif - if(PicoMCD&1) return m68k_read_pcrelative_CD8(a); + if(PicoAHW&1) return m68k_read_pcrelative_CD8(a); if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram return 0; } @@ -559,7 +568,7 @@ static unsigned int m68k_read_16(unsigned int a, int do_fake) #ifdef EMU_CORE_DEBUG if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15]; #endif - if(PicoMCD&1) return m68k_read_pcrelative_CD16(a); + if(PicoAHW&1) return m68k_read_pcrelative_CD16(a); if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram return 0; } @@ -570,7 +579,7 @@ static unsigned int m68k_read_32(unsigned int a, int do_fake) #ifdef EMU_CORE_DEBUG if(do_fake&&((ppop&0x3f)==0x3a||(ppop&0x3f)==0x3b)) return lastread_d[lrp_mus++&15]; #endif - if(PicoMCD&1) return m68k_read_pcrelative_CD32(a); + if(PicoAHW&1) return m68k_read_pcrelative_CD32(a); if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram return 0; } @@ -592,9 +601,7 @@ unsigned int m68k_read_memory_8(unsigned int a) if (a>13)==2) // 0x4000-0x5fff (Charles MacDonald) { - if (PicoOpt&1) ret = (u8) YM2612Read(); + if (PicoOpt&POPT_EN_FM) ret = (u8) YM2612Read(); return ret; } @@ -689,7 +692,7 @@ PICO_INTERNAL unsigned char z80_read(unsigned short a) addr68k=Pico.m.z80_bank68k<<15; addr68k+=a&0x7fff; - if (PicoMCD & 1) + if (PicoAHW & PAHW_MCD) ret = PicoReadM68k8(addr68k); else ret = PicoRead8(addr68k); elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret); @@ -711,13 +714,13 @@ PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data) { if ((a>>13)==2) // 0x4000-0x5fff (Charles MacDonald) { - if(PicoOpt&1) emustatus|=YM2612Write(a, data) & 1; + if(PicoOpt&POPT_EN_FM) emustatus|=YM2612Write(a, data) & 1; return; } if ((a&0xfff9)==0x7f11) // 7f11 7f13 7f15 7f17 { - if(PicoOpt&2) SN76496Write(data); + if(PicoOpt&POPT_EN_PSG) SN76496Write(data); return; } @@ -736,7 +739,7 @@ PICO_INTERNAL_ASM void z80_write(unsigned int a, unsigned char data) addr68k=Pico.m.z80_bank68k<<15; addr68k+=a&0x7fff; elprintf(EL_Z80BNK, "z80->68k w8 [%06x] %02x", addr68k, data); - if (PicoMCD & 1) + if (PicoAHW & PAHW_MCD) PicoWriteM68k8(addr68k, data); else PicoWrite8(addr68k, data); return;