From ab0607f7e4bb7cb12e6c0c18dce6f9c77ac466ad Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 14 Jan 2007 19:27:47 +0000 Subject: [PATCH] Sonic CD shows it's title screen git-svn-id: file:///home/notaz/opt/svn/PicoDrive@19 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/PicoInt.h | 9 ++-- Pico/VideoPort.c | 50 +++++++++++++---- Pico/cd/Memory.c | 128 ++++++++++++++++++++++++++++++++++++-------- platform/gp2x/emu.c | 29 ++++++---- 4 files changed, 172 insertions(+), 44 deletions(-) diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index 8f328ea..fa7f7ec 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -13,7 +13,7 @@ #include "Pico.h" -// to select core, define EMU_C68K, EMU_M68K or EMU_A68K in your makefile +// to select core, define EMU_C68K, EMU_M68K or EMU_A68K in your makefile or project #ifdef __cplusplus extern "C" { @@ -172,12 +172,13 @@ struct mcd_misc typedef struct { - unsigned char bios[0x20000]; + unsigned char bios[0x20000]; // 128K union { - unsigned char prg_ram[0x80000]; + unsigned char prg_ram[0x80000]; // 512K unsigned char prg_ram_b[4][0x20000]; }; - unsigned char word_ram[0x40000]; + unsigned char word_ram[0x40000]; // 256K + unsigned char bram[0x2000]; // 8K unsigned char s68k_regs[0x200]; CDD cdd; CDC cdc; diff --git a/Pico/VideoPort.c b/Pico/VideoPort.c index 537e917..0edf1be 100644 --- a/Pico/VideoPort.c +++ b/Pico/VideoPort.c @@ -14,6 +14,7 @@ extern const unsigned char hcounts_40[]; extern const unsigned short vcounts[]; extern int rendstatus; +typedef unsigned char u8; typedef unsigned short u16; @@ -93,13 +94,44 @@ static void DmaSlow(int len) SekSetCyclesLeft(SekCyclesLeft - (len*(((488<<8)/167))>>8)); } - if ((source&0xe00000)==0xe00000) { pd=(u16 *)(Pico.ram+(source&0xfffe)); pdend=(u16 *)(Pico.ram+0x10000); } // Ram - else if(PicoMCD & 1) { - if(source<0x20000) { pd=(u16 *)(Pico_mcd->bios+(source&~1)); pdend=(u16 *)(Pico_mcd->bios+0x20000); } // Bios area - else { dprintf("unsupported src"); return; } // Invalid source address + if ((source&0xe00000)==0xe00000) { // Ram + pd=(u16 *)(Pico.ram+(source&0xfffe)); + pdend=(u16 *)(Pico.ram+0x10000); + } else if(PicoMCD & 1) { + dprintf("DmaSlow CD"); + if(source<0x20000) { // Bios area + pd=(u16 *)(Pico_mcd->bios+(source&~1)); + pdend=(u16 *)(Pico_mcd->bios+0x20000); + } else if ((source&0xfc0000)==0x200000 && (!(Pico_mcd->s68k_regs[3]&4))) { // Word Ram + if (!(Pico_mcd->s68k_regs[3]&4)) { // 2M mode + pd=(u16 *)(Pico_mcd->word_ram+(source&0x3fffe)); + pdend=(u16 *)(Pico_mcd->word_ram+0x40000); + } else { + dprintf("DmaSlow: unsupported src"); + return; + } + } else if ((source&0xfe0000)==0x020000) { // Prg Ram + u8 *prg_ram = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; + pd=(u16 *)(prg_ram+(source&0x1fffe)); + pdend=(u16 *)(prg_ram+0x20000); + } else { + dprintf("DmaSlow: unsupported src"); + return; + } } else { - if(source pdend - pd) { + len = pdend - pd; + dprintf("DmaSlow overflow"); } switch (Pico.video.type) @@ -114,7 +146,7 @@ static void DmaSlow(int len) // AutoIncrement a=(u16)(a+inc); // didn't src overlap? - if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM + //if(pd >= pdend) pd-=0x8000; // should be good for RAM, bad for ROM } rendstatus|=0x10; break; @@ -128,7 +160,7 @@ static void DmaSlow(int len) // AutoIncrement a2+=inc; // didn't src overlap? - if(pd >= pdend) pd-=0x8000; + //if(pd >= pdend) pd-=0x8000; // good dest? if(a2 >= 0x80) break; // Todds Adventures in Slime World / Andre Agassi tennis } @@ -143,7 +175,7 @@ static void DmaSlow(int len) // AutoIncrement a2+=inc; // didn't src overlap? - if(pd >= pdend) pd-=0x8000; + //if(pd >= pdend) pd-=0x8000; // good dest? if(a2 >= 0x80) break; } diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index 739f3bf..21cc12a 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -24,8 +24,8 @@ typedef unsigned int u32; //#define __debug_io //#define __debug_io2 -//#define rdprintf dprintf -#define rdprintf(...) +#define rdprintf dprintf +//#define rdprintf(...) // ----------------------------------------------------------------- @@ -500,6 +500,7 @@ u8 PicoReadM68k8(u32 a) return (u8)d; } + u16 PicoReadM68k16(u32 a) { u16 d=0; @@ -552,6 +553,7 @@ u16 PicoReadM68k16(u32 a) return d; } + u32 PicoReadM68k32(u32 a) { u32 d=0; @@ -577,11 +579,10 @@ u32 PicoReadM68k32(u32 a) if (a >= 0x220000) { dprintf("cell"); } else { - u16 *pm; a=((a&0x1fffe)<<1); if (Pico_mcd->s68k_regs[3]&1) a+=2; - pm=(u16 *)(Pico_mcd->word_ram+a); - d = (pm[0]<<16)|pm[1]; + d = *(u16 *)(Pico_mcd->word_ram+a) << 16; + d |= *(u16 *)(Pico_mcd->word_ram+a+4); } } else { // allow access in any mode, like Gens does @@ -606,6 +607,7 @@ u32 PicoReadM68k32(u32 a) return d; } + // ----------------------------------------------------------------- // Write Ram @@ -618,7 +620,10 @@ void PicoWriteM68k8(u32 a,u8 d) // dprintf("w8 : %06x, %02x @%06x", a&0xffffff, d, SekPc); - if ((a&0xe00000)==0xe00000) { u8 *pm=(u8 *)(Pico.ram+((a^1)&0xffff)); pm[0]=d; return; } // Ram + if ((a&0xe00000)==0xe00000) { // Ram + *(u8 *)(Pico.ram+((a^1)&0xffff)) = d; + return; + } a&=0xffffff; @@ -653,6 +658,7 @@ void PicoWriteM68k8(u32 a,u8 d) OtherWrite8(a,d,8); } + void PicoWriteM68k16(u32 a,u16 d) { #ifdef __debug_io @@ -660,7 +666,10 @@ void PicoWriteM68k16(u32 a,u16 d) #endif // dprintf("w16: %06x, %04x @%06x", a&0xffffff, d, SekPc); - if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram + if ((a&0xe00000)==0xe00000) { // Ram + *(u16 *)(Pico.ram+(a&0xfffe))=d; + return; + } a&=0xfffffe; @@ -695,6 +704,7 @@ void PicoWriteM68k16(u32 a,u16 d) OtherWrite16(a,d); } + void PicoWriteM68k32(u32 a,u32 d) { #ifdef __debug_io @@ -727,11 +737,10 @@ void PicoWriteM68k32(u32 a,u32 d) if (a >= 0x220000) { dprintf("cell"); } else { - u16 *pm; a=((a&0x1fffe)<<1); if (Pico_mcd->s68k_regs[3]&1) a+=2; - pm=(u16 *)(Pico_mcd->word_ram+a); - pm[0]=(u16)(d>>16); pm[1]=(u16)d; + *(u16 *)(Pico_mcd->word_ram+a) = d>>16; + *(u16 *)(Pico_mcd->word_ram+a+4) = d; } } else { // allow access in any mode, like Gens does @@ -744,6 +753,22 @@ void PicoWriteM68k32(u32 a,u32 d) if ((a&0xffffc0)==0xa12000) rdprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc); +#if 0 + if ((a&0x3f) == 0x1c && SekPc == 0xffff05ba) + { + int i; + FILE *ff; + unsigned short *ram = (unsigned short *) Pico.ram; + // unswap and dump RAM + for (i = 0; i < 0x10000/2; i++) + ram[i] = (ram[i]>>8) | (ram[i]<<8); + ff = fopen("ram.bin", "wb"); + fwrite(ram, 1, 0x10000, ff); + fclose(ff); + exit(0); + } +#endif + OtherWrite16(a, (u16)(d>>16)); OtherWrite16(a+2,(u16)d); } @@ -800,6 +825,12 @@ u8 PicoReadS68k8(u32 a) goto end; } + // bram + if ((a&0xff0000)==0xfe0000) { + d = Pico_mcd->bram[(a>>1)&0x1fff]; + goto end; + } + dprintf("s68k r8 : %06x, %02x @%06x", a&0xffffff, (u8)d, SekPcS68k); end: @@ -810,6 +841,7 @@ u8 PicoReadS68k8(u32 a) return (u8)d; } + u16 PicoReadS68k16(u32 a) { u16 d=0; @@ -843,7 +875,7 @@ u16 PicoReadS68k16(u32 a) // allow access in any mode, like Gens does d = *(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); } - dprintf("ret = %04x", (u8)d); + dprintf("ret = %04x", d); goto end; } @@ -853,7 +885,17 @@ u16 PicoReadS68k16(u32 a) a=((a&0x1fffe)<<1); if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; d = *(u16 *)(Pico_mcd->word_ram+a); - dprintf("ret = %04x", (u8)d); + dprintf("ret = %04x", d); + goto end; + } + + // bram + if ((a&0xff0000)==0xfe0000) { + dprintf("s68k_bram r16: [%06x] @%06x", a, SekPc); + a = (a>>1)&0x1fff; + d = Pico_mcd->bram[a++]; // Gens does little endian here, an so do we.. + d|= Pico_mcd->bram[a++] << 8; + dprintf("ret = %04x", d); goto end; } @@ -867,6 +909,7 @@ u16 PicoReadS68k16(u32 a) return d; } + u32 PicoReadS68k32(u32 a) { u32 d=0; @@ -901,19 +944,30 @@ u32 PicoReadS68k32(u32 a) // allow access in any mode, like Gens does u16 *pm=(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); d = (pm[0]<<16)|pm[1]; } - dprintf("ret = %08x", (u8)d); + dprintf("ret = %08x", d); goto end; } // word RAM (1M area) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff - u16 *pm; - dprintf("s68k_wram1M 32: [%06x] @%06x", a, SekPc); + dprintf("s68k_wram1M r32: [%06x] @%06x", a, SekPc); a=((a&0x1fffe)<<1); if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; - pm=(u16 *)(Pico_mcd->word_ram+a); - d = (pm[0]<<16)|pm[1]; - dprintf("ret = %08x", (u8)d); + d = *(u16 *)(Pico_mcd->word_ram+a) << 16; + d |= *(u16 *)(Pico_mcd->word_ram+a+4); + dprintf("ret = %08x", d); + goto end; + } + + // bram + if ((a&0xff0000)==0xfe0000) { + dprintf("s68k_bram r32: [%06x] @%06x", a, SekPc); + a = (a>>1)&0x1fff; + d = Pico_mcd->bram[a++] << 16; // middle endian? TODO: verify against Fusion.. + d|= Pico_mcd->bram[a++] << 24; + d|= Pico_mcd->bram[a++]; + d|= Pico_mcd->bram[a++] << 8; + dprintf("ret = %08x", d); goto end; } @@ -927,6 +981,7 @@ u32 PicoReadS68k32(u32 a) return d; } + // ----------------------------------------------------------------- void PicoWriteS68k8(u32 a,u8 d) @@ -980,9 +1035,17 @@ void PicoWriteS68k8(u32 a,u8 d) return; } + // bram + if ((a&0xff0000)==0xfe0000) { + Pico_mcd->bram[(a>>1)&0x1fff] = d; + SRam.changed = 1; + return; + } + dprintf("s68k w8 : %06x, %02x @%06x", a&0xffffff, d, SekPcS68k); } + void PicoWriteS68k16(u32 a,u16 d) { #ifdef __debug_io2 @@ -1033,9 +1096,20 @@ void PicoWriteS68k16(u32 a,u16 d) return; } + // bram + if ((a&0xff0000)==0xfe0000) { + dprintf("s68k_bram w16: [%06x] %04x @%06x", a, d, SekPc); + a = (a>>1)&0x1fff; + Pico_mcd->bram[a++] = d; // Gens does little endian here, an so do we.. + Pico_mcd->bram[a++] = d >> 8; + SRam.changed = 1; + return; + } + dprintf("s68k w16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k); } + void PicoWriteS68k32(u32 a,u32 d) { #ifdef __debug_io2 @@ -1083,15 +1157,27 @@ void PicoWriteS68k32(u32 a,u32 d) // word RAM (1M area) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff - u16 *pm; if (d) dprintf("s68k_wram1M w32: [%06x] %08x @%06x", a, d, SekPc); a=((a&0x1fffe)<<1); if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; - pm=(u16 *)(Pico_mcd->word_ram+a); - pm[0]=(u16)(d>>16); pm[1]=(u16)d; + *(u16 *)(Pico_mcd->word_ram+a) = d>>16; + *(u16 *)(Pico_mcd->word_ram+a+4) = d; return; } + + // bram + if ((a&0xff0000)==0xfe0000) { + dprintf("s68k_bram w32: [%06x] %08x @%06x", a, d, SekPc); + a = (a>>1)&0x1fff; + Pico_mcd->bram[a++] = d >> 16; // middle endian? verify? + Pico_mcd->bram[a++] = d >> 24; + Pico_mcd->bram[a++] = d; + Pico_mcd->bram[a++] = d >> 8; + SRam.changed = 1; + return; + } + dprintf("s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k); } diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 666537c..bea1569 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -771,8 +771,6 @@ static void RunEvents(unsigned int which) } if (do_it) { blit("", (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); - if(movie_data) { - } emu_SaveLoadGame(which & 0x1000, 0); } @@ -1269,7 +1267,7 @@ int emu_SaveLoadGame(int load, int sram) // make save filename romfname_ext(saveFname, ""); - if(sram) strcat(saveFname, ".srm"); + if(sram) strcat(saveFname, (PicoMCD&1) ? ".brm" : ".srm"); else { if(state_slot > 0 && state_slot < 10) sprintf(saveFname, "%s.%i", saveFname, state_slot); strcat(saveFname, ".mds"); @@ -1279,30 +1277,41 @@ int emu_SaveLoadGame(int load, int sram) if(sram) { FILE *sramFile; - int sram_size = SRam.end-SRam.start+1; - if(SRam.reg_back & 4) sram_size=0x2000; - if(!SRam.data) return 0; // SRam forcefully disabled for this game + int sram_size; + unsigned char *sram_data; + if (PicoMCD&1) { + sram_size = 0x2000; + sram_data = Pico_mcd->bram; + } else { + sram_size = SRam.end-SRam.start+1; + if(SRam.reg_back & 4) sram_size=0x2000; + sram_data = SRam.data; + } + if(!sram_data) return 0; // SRam forcefully disabled for this game + if(load) { sramFile = fopen(saveFname, "rb"); if(!sramFile) return -1; - fread(SRam.data, 1, sram_size, sramFile); + fread(sram_data, 1, sram_size, sramFile); fclose(sramFile); } else { // sram save needs some special processing // see if we have anything to save for(; sram_size > 0; sram_size--) - if(SRam.data[sram_size-1]) break; + if(sram_data[sram_size-1]) break; if(sram_size) { sramFile = fopen(saveFname, "wb"); - ret = fwrite(SRam.data, 1, sram_size, sramFile); + ret = fwrite(sram_data, 1, sram_size, sramFile); ret = (ret != sram_size) ? -1 : 0; fclose(sramFile); sync(); } } return ret; - } else { + } + else + { void *PmovFile = NULL; // try gzip first if(currentConfig.EmuOpt & 8) { -- 2.39.2