X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fmemory.c;h=da73961cc352595c4f333ed87a92728ef3937729;hb=000f53350cb0d6540310d8c4b02eb034c9662f0d;hp=aa2a54e7cdd91662f754915241f860a4b6dc1287;hpb=af37bca858874b5cbd5ab126eaba1fad6ff7ab72;p=picodrive.git diff --git a/pico/memory.c b/pico/memory.c index aa2a54e..da73961 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -317,127 +317,25 @@ static void ctl_write_z80reset(u32 d) } } - -// for nonstandard reads -// TODO: mv to carthw -static u32 OtherRead16End(u32 a, int realsize) -{ - u32 d=0; - - // 32x test -/* - if (a == 0xa130ec) { d = 0x4d41; goto end; } // MA - else if (a == 0xa130ee) { d = 0x5253; goto end; } // RS - else if (a == 0xa15100) { d = 0x0080; goto end; } - else -*/ - - // for games with simple protection devices, discovered by Haze - // some dumb detection is used, but that should be enough to make things work - if ((a>>22) == 1 && Pico.romsize >= 512*1024) { - if (*(int *)(Pico.rom+0x123e4) == 0x00550c39 && *(int *)(Pico.rom+0x123e8) == 0x00000040) { // Super Bubble Bobble (Unl) [!] - if (a == 0x400000) { d=0x55<<8; goto end; } - else if (a == 0x400002) { d=0x0f<<8; goto end; } - } - else if (*(int *)(Pico.rom+0x008c4) == 0x66240055 && *(int *)(Pico.rom+0x008c8) == 0x00404df9) { // Smart Mouse (Unl) - if (a == 0x400000) { d=0x55<<8; goto end; } - else if (a == 0x400002) { d=0x0f<<8; goto end; } - else if (a == 0x400004) { d=0xaa<<8; goto end; } - else if (a == 0x400006) { d=0xf0<<8; goto end; } - } - else if (*(int *)(Pico.rom+0x00404) == 0x00a90600 && *(int *)(Pico.rom+0x00408) == 0x6708b013) { // King of Fighters '98, The (Unl) [!] - if (a == 0x480000 || a == 0x4800e0 || a == 0x4824a0 || a == 0x488880) { d=0xaa<<8; goto end; } - else if (a == 0x4a8820) { d=0x0a<<8; goto end; } - // there is also a read @ 0x4F8820 which needs 0, but that is returned in default case - } - else if (*(int *)(Pico.rom+0x01b24) == 0x004013f9 && *(int *)(Pico.rom+0x01b28) == 0x00ff0000) { // Mahjong Lover (Unl) [!] - if (a == 0x400000) { d=0x90<<8; goto end; } - else if (a == 0x401000) { d=0xd3<<8; goto end; } // this one doesn't seem to be needed, the code does 2 comparisons and only then - // checks the result, which is of the above one. Left it just in case. - } - else if (*(int *)(Pico.rom+0x05254) == 0x0c3962d0 && *(int *)(Pico.rom+0x05258) == 0x00400055) { // Elf Wor (Unl) - if (a == 0x400000) { d=0x55<<8; goto end; } - else if (a == 0x400004) { d=0xc9<<8; goto end; } // this check is done if the above one fails - else if (a == 0x400002) { d=0x0f<<8; goto end; } - else if (a == 0x400006) { d=0x18<<8; goto end; } // similar to above - } - // our default behaviour is to return whatever was last written a 0x400000-0x7fffff range (used by Squirrel King (R) [!]) - // Lion King II, The (Unl) [!] writes @ 400000 and wants to get that val @ 400002 and wites another val - // @ 400004 which is expected @ 400006, so we really remember 2 values here - d = Pico.m.prot_bytes[(a>>2)&1]<<8; - } - else if (a == 0xa13000 && Pico.romsize >= 1024*1024) { - if (*(int *)(Pico.rom+0xc8af0) == 0x30133013 && *(int *)(Pico.rom+0xc8af4) == 0x000f0240) { // Rockman X3 (Unl) [!] - d=0x0c; goto end; - } - else if (*(int *)(Pico.rom+0x28888) == 0x07fc0000 && *(int *)(Pico.rom+0x2888c) == 0x4eb94e75) { // Bug's Life, A (Unl) [!] - d=0x28; goto end; // does the check from RAM - } - else if (*(int *)(Pico.rom+0xc8778) == 0x30133013 && *(int *)(Pico.rom+0xc877c) == 0x000f0240) { // Super Mario Bros. (Unl) [!] - d=0x0c; goto end; // seems to be the same code as in Rockman X3 (Unl) [!] - } - else if (*(int *)(Pico.rom+0xf20ec) == 0x30143013 && *(int *)(Pico.rom+0xf20f0) == 0x000f0200) { // Super Mario 2 1998 (Unl) [!] - d=0x0a; goto end; - } - } - else if (a == 0xa13002) { // Pocket Monsters (Unl) - d=0x01; goto end; - } - else if (a == 0xa1303E) { // Pocket Monsters (Unl) - d=0x1f; goto end; - } - else if (a == 0x30fe02) { - // Virtua Racing - just for fun - // this seems to be some flag that SVP is ready or something similar - d=1; goto end; - } - -end: - elprintf(EL_UIO, "strange r%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc); - return d; -} - -static void OtherWrite8End(u32 a,u32 d,int realsize) -{ -#ifdef _ASM_MEMORY_C - // special ROM hardware (currently only banking and sram reg supported) - if((a&0xfffff1) == 0xA130F1) { - PicoWriteRomHW_SSF2(a, d); // SSF2 or SRAM - return; - } -#else - // sram access register - if(a == 0xA130F1) { - elprintf(EL_SRAMIO, "sram reg=%02x", d); - Pico.m.sram_status &= ~(SRS_MAPPED|SRS_READONLY); - Pico.m.sram_status |= (u8)(d&3); - return; - } -#endif - elprintf(EL_UIO, "strange w%i: %06x, %08x @%06x", realsize, a&0xffffff, d, SekPc); - - // for games with simple protection devices, discovered by Haze - if ((a>>22) == 1) - Pico.m.prot_bytes[(a>>2)&1] = (u8)d; -} - // ----------------------------------------------------------------- // cart (save) RAM area (usually 0x200000 - ...) static u32 PicoRead8_sram(u32 a) { - int srs = Pico.m.sram_status; u32 d; - if (SRam.end >= a && a >= SRam.start && (srs & (SRS_MAPPED|SRS_EEPROM))) + if (SRam.start <= a && a <= SRam.end && (Pico.m.sram_reg & SRR_MAPPED)) { - if (srs & SRS_EEPROM) + if (SRam.flags & SRF_EEPROM) { d = EEPROM_read(); - else + if (!(a & 1)) + d >>= 8; + } else d = *(u8 *)(SRam.data - SRam.start + a); - elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc); + elprintf(EL_SRAMIO, "sram r8 [%06x] %02x @ %06x", a, d, SekPc); return d; } + // XXX: this is banking unfriendly if (a < Pico.romsize) return Pico.rom[a ^ 1]; @@ -446,14 +344,12 @@ static u32 PicoRead8_sram(u32 a) static u32 PicoRead16_sram(u32 a) { - int srs = Pico.m.sram_status; u32 d; - if (SRam.end >= a && a >= SRam.start && (srs & (SRS_MAPPED|SRS_EEPROM))) + if (SRam.end >= a && a >= SRam.start && (Pico.m.sram_reg & SRR_MAPPED)) { - if (srs & SRS_EEPROM) { + if (SRam.flags & SRF_EEPROM) d = EEPROM_read(); - d |= d << 8; - } else { + else { u8 *pm = (u8 *)(SRam.data - SRam.start + a); d = pm[0] << 8; d |= pm[1]; @@ -470,25 +366,18 @@ static u32 PicoRead16_sram(u32 a) static void PicoWrite8_sram(u32 a, u32 d) { - unsigned int srs = Pico.m.sram_status; - elprintf(EL_SRAMIO, "sram wX [%06x] %02x @ %06x", a, d & 0xffff, SekPc); - if (srs & SRS_EEPROM) // EEPROM write + if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { + m68k_unmapped_write8(a, d); + return; + } + + elprintf(EL_SRAMIO, "sram w8 [%06x] %02x @ %06x", a, d & 0xff, SekPc); + if (SRam.flags & SRF_EEPROM) { - // this diff must be at most 16 for NBA Jam to work - if (SekCyclesDoneT() - lastSSRamWrite < 16) { - // just update pending state - elprintf(EL_EEPROM, "eeprom: skip because cycles=%i", - SekCyclesDoneT() - lastSSRamWrite); - EEPROM_upd_pending(a, d); - } else { - EEPROM_write(srs >> 6); // execute pending - EEPROM_upd_pending(a, d); - if ((srs ^ Pico.m.sram_status) & 0xc0) // update time only if SDA/SCL changed - lastSSRamWrite = SekCyclesDoneT(); - } + EEPROM_write8(a, d); } - else if (!(srs & SRS_READONLY)) { - u8 *pm=(u8 *)(SRam.data - SRam.start + a); + else { + u8 *pm = (u8 *)(SRam.data - SRam.start + a); if (*pm != (u8)d) { SRam.changed = 1; *pm = (u8)d; @@ -498,8 +387,24 @@ static void PicoWrite8_sram(u32 a, u32 d) static void PicoWrite16_sram(u32 a, u32 d) { - // XXX: hardware could easily use MSB too.. - PicoWrite8_sram(a + 1, d); + if (a > SRam.end || a < SRam.start || !(Pico.m.sram_reg & SRR_MAPPED)) { + m68k_unmapped_write16(a, d); + return; + } + + elprintf(EL_SRAMIO, "sram w16 [%06x] %04x @ %06x", a, d & 0xffff, SekPc); + if (SRam.flags & SRF_EEPROM) + { + EEPROM_write16(d); + } + else { + // XXX: hardware could easily use MSB too.. + u8 *pm = (u8 *)(SRam.data - SRam.start + a); + if (*pm != (u8)d) { + SRam.changed = 1; + *pm = (u8)d; + } + } } // z80 area (0xa00000 - 0xa0ffff) @@ -645,8 +550,8 @@ void PicoWrite8_io(u32 a, u32 d) } if (a == 0xa130f1) { // sram access register elprintf(EL_SRAMIO, "sram reg=%02x", d); - Pico.m.sram_status &= ~(SRS_MAPPED|SRS_READONLY); - Pico.m.sram_status |= (u8)(d & 3); + Pico.m.sram_reg &= ~(SRR_MAPPED|SRR_READONLY); + Pico.m.sram_reg |= (u8)(d & 3); return; } m68k_unmapped_write8(a, d); @@ -668,8 +573,8 @@ void PicoWrite16_io(u32 a, u32 d) } if (a == 0xa130f0) { // sram access register elprintf(EL_SRAMIO, "sram reg=%02x", d); - Pico.m.sram_status &= ~(SRS_MAPPED|SRS_READONLY); - Pico.m.sram_status |= (u8)(d & 3); + Pico.m.sram_reg &= ~(SRR_MAPPED|SRR_READONLY); + Pico.m.sram_reg |= (u8)(d & 3); return; } m68k_unmapped_write16(a, d); @@ -728,25 +633,6 @@ static void PicoWrite16_vdp(u32 a, u32 d) // ----------------------------------------------------------------- -// TODO: rm -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; -} - #ifdef EMU_M68K static void m68k_mem_setup(void); #endif @@ -769,8 +655,8 @@ PICO_INTERNAL void PicoMemSetup(void) cpu68k_map_set(m68k_read16_map, 0x000000, rs - 1, Pico.rom, 0); // Common case of on-cart (save) RAM, usually at 0x200000-... - rs = SRam.end - SRam.start; - if (rs > 0 && SRam.data != NULL) { + if ((SRam.flags & SRF_ENABLED) && SRam.data != NULL) { + rs = SRam.end - SRam.start; rs = (rs + mask) & ~mask; if (SRam.start + rs >= 0x1000000) rs = 0x1000000 - SRam.start; @@ -849,7 +735,6 @@ PICO_INTERNAL void PicoMemSetup(void) z80_mem_setup(); } -/* some nasty things below :( */ #ifdef EMU_M68K unsigned int (*pm68k_read_memory_8) (unsigned int address) = NULL; unsigned int (*pm68k_read_memory_16)(unsigned int address) = NULL; @@ -857,103 +742,6 @@ unsigned int (*pm68k_read_memory_32)(unsigned int address) = NULL; void (*pm68k_write_memory_8) (unsigned int address, unsigned char value) = NULL; void (*pm68k_write_memory_16)(unsigned int address, unsigned short value) = NULL; void (*pm68k_write_memory_32)(unsigned int address, unsigned int value) = NULL; -unsigned int (*pm68k_read_memory_pcr_8) (unsigned int address) = NULL; -unsigned int (*pm68k_read_memory_pcr_16)(unsigned int address) = NULL; -unsigned int (*pm68k_read_memory_pcr_32)(unsigned int address) = NULL; - -// these are here for core debugging mode -static unsigned int m68k_read_8 (unsigned int a, int do_fake) -{ - a&=0xffffff; - if(a68k upper read [%06x] %02x", addr68k, ret); -out: elprintf(EL_Z80BNK, "z80->68k r8 [%06x] %02x", addr68k, ret); return ret; }