Sonic CD runs on GP2X

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@21 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-01-19 22:08:50 +00:00
parent d1df87866b
commit b837b69b3f
20 changed files with 364 additions and 184 deletions

View file

@ -1,7 +1,7 @@
// This is part of Pico Library
// (c) Copyright 2004 Dave, All rights reserved.
// (c) Copyright 2006 notaz, All rights reserved.
// (c) Copyright 2007 notaz, All rights reserved.
// Free for non-commercial use.
// For commercial use, separate licencing terms must be obtained.
@ -474,6 +474,22 @@ u8 PicoReadM68k8(u32 a)
goto end;
}
#if 0
if (a == 0x200000 && SekPc == 0xff0b66 && Pico.m.frame_count > 1000)
{
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
// word RAM
if ((a&0xfc0000)==0x200000) {
dprintf("m68k_wram r8: [%06x] @%06x", a, SekPc);
@ -764,22 +780,6 @@ 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);
}
@ -1196,6 +1196,97 @@ void PicoWriteS68k32(u32 a,u32 d)
// -----------------------------------------------------------------
#if defined(EMU_C68K)
static __inline int PicoMemBaseM68k(u32 pc)
{
int membase=0;
if (pc < 0x20000)
{
membase=(int)Pico_mcd->bios; // Program Counter in BIOS
}
else if ((pc&0xe00000)==0xe00000)
{
membase=(int)Pico.ram-(pc&0xff0000); // Program Counter in Ram
}
else if ((pc&0xfc0000)==0x200000 && !(Pico_mcd->s68k_regs[3]&4))
{
membase=(int)Pico_mcd->word_ram-0x200000; // Program Counter in Word Ram
}
else
{
// Error - Program Counter is invalid
dprintf("m68k: unhandled jump to %06x", pc);
membase=(int)Pico.rom;
}
return membase;
}
static u32 PicoCheckPcM68k(u32 pc)
{
pc-=PicoCpu.membase; // Get real pc
pc&=0xfffffe;
PicoCpu.membase=PicoMemBaseM68k(pc);
return PicoCpu.membase+pc;
}
static __inline int PicoMemBaseS68k(u32 pc)
{
int membase;
membase=(int)Pico_mcd->prg_ram; // Program Counter in Prg RAM
if (pc >= 0x80000)
{
// Error - Program Counter is invalid
dprintf("s68k: unhandled jump to %06x", pc);
}
return membase;
}
static u32 PicoCheckPcS68k(u32 pc)
{
pc-=PicoCpuS68k.membase; // Get real pc
pc&=0xfffffe;
PicoCpuS68k.membase=PicoMemBaseS68k(pc);
return PicoCpuS68k.membase+pc;
}
#endif
void PicoMemSetupCD()
{
dprintf("PicoMemSetupCD()");
#ifdef EMU_C68K
// Setup m68k memory callbacks:
PicoCpu.checkpc=PicoCheckPcM68k;
PicoCpu.fetch8 =PicoCpu.read8 =PicoReadM68k8;
PicoCpu.fetch16=PicoCpu.read16=PicoReadM68k16;
PicoCpu.fetch32=PicoCpu.read32=PicoReadM68k32;
PicoCpu.write8 =PicoWriteM68k8;
PicoCpu.write16=PicoWriteM68k16;
PicoCpu.write32=PicoWriteM68k32;
// s68k
PicoCpuS68k.checkpc=PicoCheckPcS68k;
PicoCpuS68k.fetch8 =PicoCpuS68k.read8 =PicoReadS68k8;
PicoCpuS68k.fetch16=PicoCpuS68k.read16=PicoReadS68k16;
PicoCpuS68k.fetch32=PicoCpuS68k.read32=PicoReadS68k32;
PicoCpuS68k.write8 =PicoWriteS68k8;
PicoCpuS68k.write16=PicoWriteS68k16;
PicoCpuS68k.write32=PicoWriteS68k32;
#endif
}
#ifdef EMU_M68K
unsigned char PicoReadCD8w (unsigned int a) {
return m68ki_cpu_p == &PicoS68kCPU ? PicoReadS68k8(a) : PicoReadM68k8(a);
@ -1221,10 +1312,13 @@ unsigned int m68k_read_pcrelative_CD8 (unsigned int a) {
a&=0xffffff;
if(m68ki_cpu_p == &PicoS68kCPU) {
if (a < 0x80000) return *(u8 *)(Pico_mcd->prg_ram+(a^1)); // PRG Ram
else dprintf("s68k read_pcrel8 @ %06x", a);
dprintf("s68k_read_pcrelative_CD8: can't handle %06x", a);
} else {
if(a<Pico.romsize) return *(u8 *)(Pico.rom+(a^1)); // Rom
if(a<0x20000) return *(u8 *)(Pico.rom+(a^1)); // Bios
if((a&0xe00000)==0xe00000) return *(u8 *)(Pico.ram+((a^1)&0xffff)); // Ram
if(!(Pico_mcd->s68k_regs[3]&4) && (a&0xfc0000)==0x200000)
return Pico_mcd->word_ram[(a^1)&0x3fffe];
dprintf("m68k_read_pcrelative_CD8: can't handle %06x", a);
}
return 0;//(u8) lastread_d;
}
@ -1232,23 +1326,29 @@ unsigned int m68k_read_pcrelative_CD16(unsigned int a) {
a&=0xffffff;
if(m68ki_cpu_p == &PicoS68kCPU) {
if (a < 0x80000) return *(u16 *)(Pico_mcd->prg_ram+(a&~1)); // PRG Ram
else dprintf("s68k read_pcrel16 @ %06x", a);
dprintf("s68k_read_pcrelative_CD16: can't handle %06x", a);
} else {
if(a<Pico.romsize) return *(u16 *)(Pico.rom+(a&~1)); // Rom
if(a<0x20000) return *(u16 *)(Pico.rom+(a&~1)); // Bios
if((a&0xe00000)==0xe00000) return *(u16 *)(Pico.ram+(a&0xfffe)); // Ram
if(!(Pico_mcd->s68k_regs[3]&4) && (a&0xfc0000)==0x200000)
return *(u16 *)(Pico_mcd->word_ram+(a&0x3fffe));
dprintf("m68k_read_pcrelative_CD16: can't handle %06x", a);
}
return 0;//(u16) lastread_d;
return 0;
}
unsigned int m68k_read_pcrelative_CD32(unsigned int a) {
a&=0xffffff;
if(m68ki_cpu_p == &PicoS68kCPU) {
if (a < 0x80000) { u16 *pm=(u16 *)(Pico_mcd->prg_ram+(a&~1)); return (pm[0]<<16)|pm[1]; } // PRG Ram
else dprintf("s68k read_pcrel32 @ %06x", a);
dprintf("s68k_read_pcrelative_CD32: can't handle %06x", a);
} else {
if(a<Pico.romsize) { u16 *pm=(u16 *)(Pico.rom+(a&~1)); return (pm[0]<<16)|pm[1]; }
if(a<0x20000) { u16 *pm=(u16 *)(Pico.rom+(a&~1)); return (pm[0]<<16)|pm[1]; }
if((a&0xe00000)==0xe00000) { u16 *pm=(u16 *)(Pico.ram+(a&0xfffe)); return (pm[0]<<16)|pm[1]; } // Ram
if(!(Pico_mcd->s68k_regs[3]&4) && (a&0xfc0000)==0x200000)
{ u16 *pm=(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); return (pm[0]<<16)|pm[1]; }
dprintf("m68k_read_pcrelative_CD32: can't handle %06x", a);
}
return 0; //lastread_d;
return 0;
}
#endif // EMU_M68K

View file

@ -33,7 +33,7 @@ int PicoResetMCD(int hard)
// clear everything except BIOS
memset(Pico_mcd->prg_ram, 0, sizeof(mcd_state) - sizeof(Pico_mcd->bios));
*(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6)
PicoMCD |= 2; // s68k reset pending
PicoMCD |= 2; // s68k reset pending. TODO: move
Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode with m68k access after reset
counter75hz = 0;
@ -48,7 +48,11 @@ static __inline void SekRun(int cyc)
int cyc_do;
SekCycleAim+=cyc;
if((cyc_do=SekCycleAim-SekCycleCnt) < 0) return;
#if defined(EMU_M68K)
#if defined(EMU_C68K)
PicoCpu.cycles=cyc_do;
CycloneRun(&PicoCpu);
SekCycleCnt+=cyc_do-PicoCpu.cycles;
#elif defined(EMU_M68K)
m68k_set_context(&PicoM68kCPU);
SekCycleCnt+=m68k_execute(cyc_do);
#endif
@ -59,7 +63,11 @@ static __inline void SekRunS68k(int cyc)
int cyc_do;
SekCycleAimS68k+=cyc;
if((cyc_do=SekCycleAimS68k-SekCycleCntS68k) < 0) return;
#if defined(EMU_M68K)
#if defined(EMU_C68K)
PicoCpuS68k.cycles=cyc_do;
CycloneRun(&PicoCpuS68k);
SekCycleCntS68k+=cyc_do-PicoCpuS68k.cycles;
#elif defined(EMU_M68K)
m68k_set_context(&PicoS68kCPU);
SekCycleCntS68k+=m68k_execute(cyc_do);
#endif
@ -82,6 +90,27 @@ static __inline void check_cd_dma(void)
Update_CDC_TRansfer(ddx); // now go and do the actual transfer
}
// to be called on 224 or line_sample scanlines only
static __inline void getSamples(int y)
{
if(y == 224) {
//dprintf("sta%i: %i [%i]", (emustatus & 2), emustatus, y);
if(emustatus & 2)
sound_render(PsndLen/2, PsndLen-PsndLen/2);
else sound_render(0, PsndLen);
if (emustatus&1) emustatus|=2; else emustatus&=~2;
if (PicoWriteSound) PicoWriteSound();
// clear sound buffer
memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1));
}
else if(emustatus & 3) {
emustatus|= 2;
emustatus&=~1;
sound_render(0, PsndLen/2);
}
}
// Accurate but slower frame which does hints
static int PicoFrameHintsMCD(void)
@ -176,7 +205,7 @@ static int PicoFrameHintsMCD(void)
if(y == 32 && PsndOut)
emustatus &= ~1;
else if((y == 224 || y == line_sample) && PsndOut)
;//getSamples(y);
getSamples(y);
// Run scanline:
//dprintf("m68k starting exec @ %06x", SekPc);

View file

@ -13,24 +13,79 @@
int SekCycleCntS68k=0; // cycles done in this frame
int SekCycleAimS68k=0; // cycle aim
#ifdef EMU_C68K
// ---------------------- Cyclone 68000 ----------------------
struct Cyclone PicoCpuS68k;
#endif
#ifdef EMU_M68K
// ---------------------- MUSASHI 68000 ----------------------
m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU
#endif
static int irqs = 0; // TODO: 2 context
#ifdef EMU_M68K
int SekIntAckS68k(int level)
static int SekIntAckS68k(int level)
{
dprintf("s68kACK %i", level);
CPU_INT_LEVEL = 0;
int level_new = 0;
irqs &= ~(1 << level);
irqs &= Pico_mcd->s68k_regs[0x33];
if (irqs) {
level_new = 6;
while (level_new > 0) { if (irqs & (1 << level_new)) break; level_new--; }
}
dprintf("s68kACK %i -> %i", level, level_new);
CPU_INT_LEVEL = level_new << 8;
return M68K_INT_ACK_AUTOVECTOR;
}
#endif
#ifdef EMU_C68K
// interrupt acknowledgment
static void SekIntAck(int level)
{
int level_new = 0;
irqs &= ~(1 << level);
irqs &= Pico_mcd->s68k_regs[0x33];
if (irqs) {
level_new = 6;
while (level_new > 0) { if (irqs & (1 << level_new)) break; level_new--; }
}
dprintf("s68kACK %i -> %i", level, level_new);
PicoCpuS68k.irq = level_new;
}
static void SekResetAck()
{
dprintf("s68k: Reset encountered @ %06x", SekPcS68k);
}
static int SekUnrecognizedOpcode()
{
unsigned int pc, op;
pc = SekPcS68k;
op = PicoCpuS68k.read16(pc);
dprintf("Unrecognized Opcode %04x @ %06x", op, pc);
//exit(1);
return 0;
}
#endif
int SekInitS68k()
{
#ifdef EMU_C68K
// CycloneInit();
memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k));
PicoCpuS68k.IrqCallback=SekIntAck;
PicoCpuS68k.ResetCallback=SekResetAck;
PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode;
#endif
#ifdef EMU_M68K
{
// Musashi is not very context friendly..
@ -52,6 +107,16 @@ int SekResetS68k()
{
if (Pico.rom==NULL) return 1;
#ifdef EMU_C68K
PicoCpuS68k.stopped=0;
PicoCpuS68k.osp=0;
PicoCpuS68k.srh =0x27; // Supervisor mode
PicoCpuS68k.flags=4; // Z set
PicoCpuS68k.irq=0;
PicoCpuS68k.a[7]=PicoCpuS68k.read32(0); // Stack Pointer
PicoCpuS68k.membase=0;
PicoCpuS68k.pc=PicoCpuS68k.checkpc(PicoCpuS68k.read32(4)); // Program Counter
#endif
#ifdef EMU_M68K
{
void *oldcontext = m68ki_cpu_p;
@ -67,6 +132,10 @@ int SekResetS68k()
int SekInterruptS68k(int irq)
{
irqs |= 1 << irq;
#ifdef EMU_C68K
PicoCpuS68k.irq=irq;
#endif
#ifdef EMU_M68K
void *oldcontext = m68ki_cpu_p;
m68k_set_context(&PicoS68kCPU);