X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2FMemory.c;h=2b253d80e0322f141587eb77ea0458daae995c2c;hb=a4f0cc8647c019f149541df380a2d30e14aeb75c;hp=c9c9a020cc0f9a000f930bc9d56934b13478f3a0;hpb=fa1e5e2948e9b06dec3353081081173f7ae4d742;p=picodrive.git diff --git a/Pico/Memory.c b/Pico/Memory.c index c9c9a02..2b253d8 100644 --- a/Pico/Memory.c +++ b/Pico/Memory.c @@ -7,7 +7,7 @@ // For commercial use, separate licencing terms must be obtained. -//#define __debug_io +#define __debug_io #include "PicoInt.h" @@ -22,8 +22,8 @@ typedef unsigned int u32; 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 @@ -69,9 +69,13 @@ static u32 CPU_CALL PicoCheckPc(u32 pc) u32 ret=0; #if defined(EMU_C68K) pc-=PicoCpu.membase; // Get real pc - pc&=0xfffffe; +// 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) @@ -192,6 +196,7 @@ static void OtherWrite8End(u32 a,u32 d,int realsize) //if(a==0x200000) dprintf("cc : %02x @ %06x [%i|%i]", d, SekPc, SekCyclesDoneT(), SekCyclesDone()); //if(a==0x200001) dprintf("w8 : %02x @ %06x [%i]", d, SekPc, SekCyclesDoneT()); if(a >= SRam.start && a <= SRam.end) { + dprintf("sram w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc); unsigned int sreg = Pico.m.sram_reg; if(!(sreg & 0x10)) { // not detected SRAM @@ -229,7 +234,9 @@ static void OtherWrite8End(u32 a,u32 d,int realsize) #else // sram access register if(a == 0xA130F1) { - Pico.m.sram_reg = (u8)(d&3); + dprintf("sram reg=%02x", d); + Pico.m.sram_reg &= ~3; + Pico.m.sram_reg |= (u8)(d&3); return; } #endif @@ -259,7 +266,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) +u32 CPU_CALL PicoRead8(u32 a) { u32 d=0; @@ -302,17 +309,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) +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 @@ -321,14 +328,14 @@ 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; } @@ -369,7 +376,7 @@ u32 CPU_CALL PicoRead32(u32 a) dprintf("r32: %06x, %08x @%06x", a&0xffffff, 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] = d; } @@ -392,16 +399,13 @@ static void CPU_CALL PicoWrite8(u32 a,u8 d) //if ((a&0xe0ffff)==0xe0a9ba+0x69c) // dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); - - if ((a&0xe00000)==0xe00000) { - if((a&0xffff)==0xf62a) dprintf("(f62a) = %02x [%i|%i] @ %x", d, Pico.m.scanline, SekCyclesDone(), SekPc); - u8 *pm=(u8 *)(Pico.ram+((a^1)&0xffff)); pm[0]=d; return; } // Ram + if ((a&0xe00000)==0xe00000) { *(u8 *)(Pico.ram+((a^1)&0xffff))=d; return; } // Ram a&=0xffffff; OtherWrite8(a,d,8); } -static void CPU_CALL PicoWrite16(u32 a,u16 d) +void CPU_CALL PicoWrite16(u32 a,u16 d) { #ifdef __debug_io dprintf("w16: %06x, %04x", a&0xffffff, d); @@ -498,39 +502,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