X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FMemory.c;h=ec31ea25e65753e7cb336bd1f86f5abdc2aebcce;hb=a5ccbfbaf07e1d91c71b08485a1bd3ee8a06128f;hp=21db15e481bce97052599602f0026d783b831163;hpb=721cd3963fa4ba82ca218345e8f543703dc46c90;p=picodrive.git diff --git a/Pico/Memory.c b/Pico/Memory.c index 21db15e..ec31ea2 100644 --- a/Pico/Memory.c +++ b/Pico/Memory.c @@ -7,23 +7,25 @@ // For commercial use, separate licencing terms must be obtained. -//#define __debug_io +#define __debug_io #include "PicoInt.h" -#include "sound/sound.h" #include "sound/ym2612.h" #include "sound/sn76496.h" +#ifndef UTYPES_DEFINED typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; +#define UTYPES_DEFINED +#endif extern unsigned int lastSSRamWrite; // used by serial SRAM code #ifdef _ASM_MEMORY_C -u8 PicoRead8(u32 a); -u16 PicoRead16(u32 a); +u32 PicoRead8(u32 a); +u32 PicoRead16(u32 a); void PicoWriteRomHW_SSF2(u32 a,u32 d); void PicoWriteRomHW_in1 (u32 a,u32 d); #endif @@ -36,6 +38,12 @@ int lrp_cyc=0, lrp_mus=0, lwp_cyc=0, lwp_mus=0; extern unsigned int ppop; #endif +#ifdef IO_STATS +void log_io(unsigned int addr, int bits, int rw); +#else +#define log_io(...) +#endif + #if defined(EMU_C68K) || defined(EMU_A68K) static __inline int PicoMemBase(u32 pc) { @@ -69,11 +77,13 @@ static u32 CPU_CALL PicoCheckPc(u32 pc) u32 ret=0; #if defined(EMU_C68K) pc-=PicoCpu.membase; // Get real pc - pc&=0xfffffe; - if (pc == 0) +// pc&=0xfffffe; + pc&=~1; + if ((pc<<8) == 0) return (int)Pico.rom + Pico.romsize; // common crash condition, can happen if acc timing is off - PicoCpu.membase=PicoMemBase(pc); + PicoCpu.membase=PicoMemBase(pc&0x00ffffff); + PicoCpu.membase-=pc&0xff000000; ret = PicoCpu.membase+pc; #elif defined(EMU_A68K) @@ -86,14 +96,14 @@ static u32 CPU_CALL PicoCheckPc(u32 pc) } -int PicoInitPc(u32 pc) +PICO_INTERNAL int PicoInitPc(u32 pc) { PicoCheckPc(pc); return 0; } #ifndef _ASM_MEMORY_C -void PicoMemReset() +PICO_INTERNAL_ASM void PicoMemReset(void) { } #endif @@ -264,7 +274,7 @@ static void OtherWrite8End(u32 a,u32 d,int realsize) // Read Rom and read Ram #ifndef _ASM_MEMORY_C -u8 CPU_CALL PicoRead8(u32 a) +PICO_INTERNAL_ASM u32 CPU_CALL PicoRead8(u32 a) { u32 d=0; @@ -290,6 +300,7 @@ u8 CPU_CALL PicoRead8(u32 a) #endif if (a>=8; @@ -307,17 +318,17 @@ u8 CPU_CALL PicoRead8(u32 a) dprintf("r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPc); #endif #if defined(EMU_C68K) && defined(EMU_M68K) - if(a>=Pico.romsize&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b) { + if(a>=Pico.romsize/*&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b*/) { lastread_a = a; lastread_d[lrp_cyc++&15] = (u8)d; } #endif - return (u8)d; + return d; } -u16 CPU_CALL PicoRead16(u32 a) +PICO_INTERNAL_ASM u32 CPU_CALL PicoRead16(u32 a) { - u16 d=0; + u32 d=0; if ((a&0xe00000)==0xe00000) { d=*(u16 *)(Pico.ram+(a&0xfffe)); goto end; } // Ram @@ -326,14 +337,15 @@ u16 CPU_CALL PicoRead16(u32 a) #if !(defined(EMU_C68K) && defined(EMU_M68K)) // sram if(a >= SRam.start && a <= SRam.end && (Pico.m.sram_reg & 1)) { - d = (u16) SRAMRead(a); + d = SRAMRead(a); goto end; } #endif if (a=Pico.romsize&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b) { + if(a>=Pico.romsize/*&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b*/) { lastread_a = a; lastread_d[lrp_cyc++&15] = d; } @@ -351,7 +363,7 @@ u16 CPU_CALL PicoRead16(u32 a) return d; } -u32 CPU_CALL PicoRead32(u32 a) +PICO_INTERNAL_ASM u32 CPU_CALL PicoRead32(u32 a) { u32 d=0; @@ -366,6 +378,7 @@ u32 CPU_CALL PicoRead32(u32 a) } if (a=Pico.romsize&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b) { + if(a>=Pico.romsize/*&&(ppop&0x3f)!=0x3a&&(ppop&0x3f)!=0x3b*/) { lastread_a = a; lastread_d[lrp_cyc++&15] = d; } @@ -398,6 +411,7 @@ static void CPU_CALL PicoWrite8(u32 a,u8 d) // dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram + log_io(a, 8, 1); a&=0xffffff; OtherWrite8(a,d,8); @@ -415,6 +429,7 @@ void CPU_CALL PicoWrite16(u32 a,u16 d) // dprintf("w16: %06x, %04x @%06x", a&0xffffff, d, SekPc); if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram + log_io(a, 16, 1); a&=0xfffffe; OtherWrite16(a,d); @@ -436,6 +451,7 @@ static void CPU_CALL PicoWrite32(u32 a,u32 d) pm[0]=(u16)(d>>16); pm[1]=(u16)d; return; } + log_io(a, 32, 1); a&=0xfffffe; OtherWrite16(a, (u16)(d>>16)); @@ -444,7 +460,7 @@ static void CPU_CALL PicoWrite32(u32 a,u32 d) // ----------------------------------------------------------------- -void PicoMemSetup() +PICO_INTERNAL void PicoMemSetup(void) { #ifdef EMU_C68K // Setup memory callbacks: @@ -500,39 +516,78 @@ unsigned int m68k_read_pcrelative_CD16(unsigned int a); unsigned int m68k_read_pcrelative_CD32(unsigned int a); // these are allowed to access RAM -unsigned int m68k_read_pcrelative_8 (unsigned int a) { +static unsigned int m68k_read_8 (unsigned int a, int do_fake) { a&=0xffffff; if(PicoMCD&1) return m68k_read_pcrelative_CD8(a); if(a