From: notaz Date: Fri, 19 Jan 2007 22:08:50 +0000 (+0000) Subject: Sonic CD runs on GP2X X-Git-Tag: v1.85~766 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b837b69b3fcff1737431c8be1c78d1cfd64003a6;p=picodrive.git Sonic CD runs on GP2X git-svn-id: file:///home/notaz/opt/svn/PicoDrive@21 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/Pico/Memory.c b/Pico/Memory.c index 3104eb4..509fead 100644 --- a/Pico/Memory.c +++ b/Pico/Memory.c @@ -319,14 +319,16 @@ static void OtherWrite8(u32 a,u32 d,int realsize) //int lineCycles=(488-SekCyclesLeft)&0x1ff; d&=1; d^=1; if(!d) { - // hack: detect a nasty situation where Z80 was enabled and disabled in the same 68k timeslice (Golden Axe III) - // if((PicoOpt&4) && Pico.m.z80Run==1) z80_run(20); // FIXME: movies - z80stopCycle = SekCyclesDone(); - //z80ExtraCycles += (lineCycles>>1)-(lineCycles>>5); // only meaningful in PicoFrameHints() + // this is for a nasty situation where Z80 was enabled and disabled in the same 68k timeslice (Golden Axe III) + if (Pico.m.z80Run) { + int lineCycles=(488-SekCyclesLeft)&0x1ff; + z80stopCycle = SekCyclesDone(); + lineCycles=(lineCycles>>1)-(lineCycles>>5); + z80_run(lineCycles); + } } else { z80startCycle = SekCyclesDone(); //if(Pico.m.scanline != -1) - //z80ExtraCycles -= (lineCycles>>1)-(lineCycles>>5)+16; } dprintf("set_zrun: %02x [%i|%i] @%06x", d, Pico.m.scanline, SekCyclesDone(), /*mz80GetRegisterValue(NULL, 0),*/ SekPc); Pico.m.z80Run=(u8)d; return; @@ -621,7 +623,7 @@ static void CPU_CALL PicoWrite32(u32 a,u32 d) // ----------------------------------------------------------------- -int PicoMemInit() +void PicoMemSetup() { #ifdef EMU_C68K // Setup memory callbacks: @@ -633,7 +635,6 @@ int PicoMemInit() PicoCpu.write16=PicoWrite16; PicoCpu.write32=PicoWrite32; #endif - return 0; } #ifdef EMU_A68K diff --git a/Pico/Pico.c b/Pico/Pico.c index bd21a56..f821cf4 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -11,7 +11,7 @@ #include "sound/sound.h" #include "sound/ym2612.h" -int PicoVer=0x0080; +int PicoVer=0x0110; struct Pico Pico; int PicoOpt=0; // disable everything by default int PicoSkipFrame=0; // skip rendering frame? @@ -36,9 +36,6 @@ int PicoInit(void) SekInit(); z80_init(); // init even if we aren't going to use it - // Setup memory callbacks: - PicoMemInit(); - PicoInitMCD(); // notaz: sram @@ -66,6 +63,10 @@ int PicoReset(int hard) if (Pico.romsize<=0) return 1; + // setup correct memory map + if (PicoMCD & 1) + PicoMemSetupCD(); + else PicoMemSetup(); PicoMemReset(); SekReset(); SekCycleCntT=0; @@ -237,31 +238,6 @@ static __inline void SekRun(int cyc) { int cyc_do; SekCycleAim+=cyc; -#if 0 - if(Pico.m.dma_bytes) { - int burn=0; - if((Pico.video.status&8)||!(Pico.video.reg[1]&0x40)) { // vblank? - if(Pico.m.dma_bytes < 205) { - burn = Pico.m.dma_bytes*(((488<<8)/205))>>8; - Pico.m.dma_bytes = 0; - } else { - burn += 488; - Pico.m.dma_bytes -= 205; - } - } else { - if(Pico.m.dma_bytes < 18) { - burn = Pico.m.dma_bytes*(((488<<8)/18))>>8; - Pico.m.dma_bytes = 0; - } else { - burn += 488; - Pico.m.dma_bytes -= 18; - } - } - SekCycleCnt+=burn; - dprintf("~DmaSlow %i burn=%i do=%i [%i|%i]", Pico.m.dma_bytes, burn, SekCycleAim-SekCycleCnt, - Pico.m.scanline, SekCyclesDone()); - } -#endif //dprintf("aim: %i, cnt: %i", SekCycleAim, SekCycleCnt); if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return; //dprintf("cyc_do: %i", cyc_do); diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index c85b99f..64768b1 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -23,10 +23,11 @@ extern "C" { // ----------------------- 68000 CPU ----------------------- #ifdef EMU_C68K #include "../cpu/Cyclone/Cyclone.h" -extern struct Cyclone PicoCpu; +extern struct Cyclone PicoCpu, PicoCpuS68k; #define SekCyclesLeft PicoCpu.cycles // cycles left for this run #define SekSetCyclesLeft(c) PicoCpu.cycles=c #define SekPc (PicoCpu.pc-PicoCpu.membase) +#define SekPcS68k (PicoCpuS68k.pc-PicoCpuS68k.membase) #endif #ifdef EMU_A68K @@ -201,15 +202,16 @@ void PicoFrameFull(); // Memory.c int PicoInitPc(unsigned int pc); unsigned int CPU_CALL PicoRead32(unsigned int a); -int PicoMemInit(); +void PicoMemSetup(); void PicoMemReset(); -void PicoDasm(int start,int len); +//void PicoDasm(int start,int len); unsigned char z80_read(unsigned short a); unsigned short z80_read16(unsigned short a); void z80_write(unsigned char data, unsigned short a); void z80_write16(unsigned short data, unsigned short a); // cd/Memory.c +void PicoMemSetupCD(); unsigned char PicoReadCD8 (unsigned int a); unsigned short PicoReadCD16(unsigned int a); unsigned int PicoReadCD32(unsigned int a); diff --git a/Pico/Sek.c b/Pico/Sek.c index b3b35a3..0ca575f 100644 --- a/Pico/Sek.c +++ b/Pico/Sek.c @@ -41,8 +41,8 @@ static int (*ResetCallback)()=DoReset; -// interrupt acknowledgment #ifdef EMU_C68K +// interrupt acknowledgment static void SekIntAck(int level) { // try to emulate VDP's reaction to 68000 int ack @@ -143,12 +143,8 @@ int SekReset() PicoInitPc(M68000_regs.pc); #endif #ifdef EMU_M68K - { - void *oldcontext = m68ki_cpu_p; - m68k_set_context(&PicoM68kCPU); - m68k_pulse_reset(); - m68k_set_context(oldcontext); - } + m68k_set_context(&PicoM68kCPU); // if we ever reset m68k, we always need it's context to be set + m68k_pulse_reset(); #endif return 0; diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index 58fb5c2..fd48416 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -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(as68k_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(as68k_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(as68k_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 diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 9e87e9e..19b6f15 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -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); diff --git a/Pico/cd/Sek.c b/Pico/cd/Sek.c index e0ea83a..5def9c1 100644 --- a/Pico/cd/Sek.c +++ b/Pico/cd/Sek.c @@ -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); diff --git a/platform/gp2x/940.c b/platform/gp2x/940.c index c3f0b11..e94bf21 100644 --- a/platform/gp2x/940.c +++ b/platform/gp2x/940.c @@ -1,9 +1,5 @@ #include "940shared.h" -/* this code assumes that we live @ 0x3000000 bank */ -//static volatile unsigned short *gp2x_memregs = (void *) 0x0xbd000000; -//static volatile unsigned long *gp2x_memregl = (void *) 0x0xbd000000; - static _940_data_t *shared_data = (_940_data_t *) 0x100000; static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x200000; YM2612 *ym2612_940; @@ -28,10 +24,10 @@ void Main940(int startvector) shared_ctl->vstarts[startvector]++; asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); - /* unmask IRQs */ for (;; shared_ctl->loopc++) { + int job_num; /* while (!shared_ctl->busy) { @@ -44,50 +40,54 @@ void Main940(int startvector) wait_irq(); } - switch (shared_ctl->job) + for (job_num = 0; job_num < MAX_940JOBS; job_num++) { - case JOB940_YM2612INIT: - shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff; - YM2612Init_(shared_ctl->baseclock, shared_ctl->rate); - break; + switch (shared_ctl->jobs[job_num]) + { + case JOB940_YM2612INIT: + shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff; + YM2612Init_(shared_ctl->baseclock, shared_ctl->rate); + break; - case JOB940_YM2612RESETCHIP: - YM2612ResetChip_(); - break; + case JOB940_YM2612RESETCHIP: + YM2612ResetChip_(); + break; - case JOB940_PICOSTATELOAD: - YM2612PicoStateLoad_(); - break; + case JOB940_PICOSTATELOAD: + YM2612PicoStateLoad_(); + break; - case JOB940_YM2612UPDATEONE: { - int i, dw, *wbuff; - if (shared_ctl->writebuffsel == 1) { - wbuff = (int *) shared_ctl->writebuff1; - } else { - wbuff = (int *) shared_ctl->writebuff0; - } + case JOB940_YM2612UPDATEONE: { + int i, dw, *wbuff; + if (shared_ctl->writebuffsel == 1) { + wbuff = (int *) shared_ctl->writebuff1; + } else { + wbuff = (int *) shared_ctl->writebuff0; + } - /* playback all writes */ - for (i = 2048/2; i > 0; i--) { - UINT16 d; - dw = *wbuff++; - d = dw; - if (d == 0xffff) break; - YM2612Write_(d >> 8, d); - d = (dw>>16); - if (d == 0xffff) break; - YM2612Write_(d >> 8, d); - } + /* playback all writes */ + for (i = 2048/2; i > 0; i--) { + UINT16 d; + dw = *wbuff++; + d = dw; + if (d == 0xffff) break; + YM2612Write_(d >> 8, d); + d = (dw>>16); + if (d == 0xffff) break; + YM2612Write_(d >> 8, d); + } - YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo); -// cache_clean_flush(); - cache_clean(); -// asm volatile ("mov r0, #0" ::: "r0"); -// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer, should be done on nonbuffered write */ - break; + YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo); + break; + } } } shared_ctl->busy = 0; +// cache_clean_flush(); + cache_clean(); +// asm volatile ("mov r0, #0" ::: "r0"); +// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer, should be done on nonbuffered write */ } } + diff --git a/platform/gp2x/940ctl_ym2612.c b/platform/gp2x/940ctl_ym2612.c index d8a10b2..4dc320d 100644 --- a/platform/gp2x/940ctl_ym2612.c +++ b/platform/gp2x/940ctl_ym2612.c @@ -250,9 +250,10 @@ static void wait_busy_940(void) } -static void add_job_940(int job) +static void add_job_940(int job0, int job1) { - shared_ctl->job = job; + shared_ctl->jobs[0] = job0; + shared_ctl->jobs[1] = job1; shared_ctl->busy = 1; gp2x_memregs[0x3B3E>>1] = 0xffff; // cause an IRQ for 940 } @@ -276,7 +277,7 @@ void YM2612PicoStateLoad_940(void) addr_A1 = old_A1; - add_job_940(JOB940_PICOSTATELOAD); + add_job_940(JOB940_PICOSTATELOAD, 0); } @@ -299,10 +300,9 @@ extern char **g_argv; void YM2612Init_940(int baseclock, int rate) { printf("YM2612Init_940()\n"); - //printf("sizeof(*shared_data): %i (%x)\n", sizeof(*shared_data), sizeof(*shared_data)); - //printf("sizeof(*shared_ctl): %i (%x)\n", sizeof(*shared_ctl), sizeof(*shared_ctl)); + printf("Mem usage: shared_data: %i, shared_ctl: %i\n", sizeof(*shared_data), sizeof(*shared_ctl)); - Reset940(1); + Reset940(1, 2); Pause940(1); gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940 @@ -312,7 +312,7 @@ void YM2612Init_940(int baseclock, int rate) if (shared_mem == NULL) { - shared_mem = (unsigned char *) mmap(0, 0x210000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x3000000); + shared_mem = (unsigned char *) mmap(0, 0x210000, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x2000000); if(shared_mem == MAP_FAILED) { printf("mmap(shared_data) failed with %i\n", errno); @@ -373,11 +373,12 @@ void YM2612Init_940(int baseclock, int rate) /* now cause 940 to init it's ym2612 stuff */ shared_ctl->baseclock = baseclock; shared_ctl->rate = rate; - shared_ctl->job = JOB940_YM2612INIT; + shared_ctl->jobs[0] = JOB940_YM2612INIT; + shared_ctl->jobs[1] = 0; shared_ctl->busy = 1; /* start the 940 */ - Reset940(0); + Reset940(0, 2); Pause940(0); // YM2612ResetChip_940(); // will be done on JOB940_YM2612INIT @@ -396,7 +397,7 @@ void YM2612ResetChip_940(void) internal_reset(); - add_job_940(JOB940_YM2612RESETCHIP); + add_job_940(JOB940_YM2612RESETCHIP, 0); } @@ -444,7 +445,7 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo) shared_ctl->writebuffsel ^= 1; shared_ctl->length = length; shared_ctl->stereo = stereo; - add_job_940(JOB940_YM2612UPDATEONE); + add_job_940(JOB940_YM2612UPDATEONE, 0); //spend_cycles(512); //printf("SRCPND: %08lx, INTMODE: %08lx, INTMASK: %08lx, INTPEND: %08lx\n", // gp2x_memregl[0x4500>>2], gp2x_memregl[0x4504>>2], gp2x_memregl[0x4508>>2], gp2x_memregl[0x4510>>2]); diff --git a/platform/gp2x/940init.s b/platform/gp2x/940init.s index e28b453..771511f 100644 --- a/platform/gp2x/940init.s +++ b/platform/gp2x/940init.s @@ -31,9 +31,9 @@ code940: @ interrupt table: b .Begin .b_irq: mov r12, #6 - mov sp, #0x100000 @ reset stack - sub sp, sp, #4 - mov r1, #0xbd000000 @ assume we live @ 0x3000000 bank + mov sp, #0x100000 @ reset stack + sub sp, sp, #4 + mov r1, #0xbe000000 @ assume we live @ 0x2000000 bank orr r2, r1, #0x3B00 orr r2, r2, #0x0046 mvn r3, #0 @@ -48,51 +48,51 @@ code940: @ interrupt table: b .Begin .Begin: - mov sp, #0x100000 @ set the stack top (1M) - sub sp, sp, #4 @ minus 4 + mov sp, #0x100000 @ set the stack top (1M) + sub sp, sp, #4 @ minus 4 - @ set up memory region 0 -- the whole 4GB address space - mov r0, #(0x1f<<1)|1 @ region data - mcr p15, 0, r0, c6, c0, 0 @ opcode2 ~ data/instr - mcr p15, 0, r0, c6, c0, 1 + @ set up memory region 0 -- the whole 4GB address space + mov r0, #(0x1f<<1)|1 @ region data + mcr p15, 0, r0, c6, c0, 0 @ opcode2 ~ data/instr + mcr p15, 0, r0, c6, c0, 1 @ set up region 1 which is the first 2 megabytes. - mov r0, #(0x14<<1)|1 @ region data - mcr p15, 0, r0, c6, c1, 0 - mcr p15, 0, r0, c6, c1, 1 + mov r0, #(0x14<<1)|1 @ region data + mcr p15, 0, r0, c6, c1, 0 + mcr p15, 0, r0, c6, c1, 1 @ set up region 2: 64k 0x200000-0x210000 - mov r0, #(0x0f<<1)|1 + mov r0, #(0x0f<<1)|1 orr r0, r0, #0x200000 - mcr p15, 0, r0, c6, c2, 0 - mcr p15, 0, r0, c6, c2, 1 + mcr p15, 0, r0, c6, c2, 0 + mcr p15, 0, r0, c6, c2, 1 - @ set up region 3: 64k 0xbd000000-0xbd010000 (hw control registers) - mov r0, #(0x0f<<1)|1 - orr r0, r0, #0xbd000000 - mcr p15, 0, r0, c6, c3, 0 - mcr p15, 0, r0, c6, c3, 1 + @ set up region 3: 64k 0xbe000000-0xbe010000 (hw control registers) + mov r0, #(0x0f<<1)|1 + orr r0, r0, #0xbe000000 + mcr p15, 0, r0, c6, c3, 0 + mcr p15, 0, r0, c6, c3, 1 @ set region 1 to be cacheable (so the first 2M will be cacheable) - mov r0, #2 - mcr p15, 0, r0, c2, c0, 0 - mcr p15, 0, r0, c2, c0, 1 + mov r0, #2 + mcr p15, 0, r0, c2, c0, 0 + mcr p15, 0, r0, c2, c0, 1 @ set region 1 to be bufferable too (only data) - mcr p15, 0, r0, c3, c0, 0 + mcr p15, 0, r0, c3, c0, 0 @ set protection, allow accsess only to regions 1 and 2 - mov r0, #(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, no access] for regions [3 2 1 0] - mcr p15, 0, r0, c5, c0, 0 - mov r0, #(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, full, no] - mcr p15, 0, r0, c5, c0, 1 - - mrc p15, 0, r0, c1, c0, 0 @ fetch current control reg - orr r0, r0, #1 @ 0x00000001: enable protection unit - orr r0, r0, #4 @ 0x00000004: enable D cache - orr r0, r0, #0x1000 @ 0x00001000: enable I cache - orr r0, r0, #0xC0000000 @ 0xC0000000: async+fastbus - mcr p15, 0, r0, c1, c0, 0 @ set control reg + mov r0, #(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, no access] for regions [3 2 1 0] + mcr p15, 0, r0, c5, c0, 0 + mov r0, #(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, full, no] + mcr p15, 0, r0, c5, c0, 1 + + mrc p15, 0, r0, c1, c0, 0 @ fetch current control reg + orr r0, r0, #1 @ 0x00000001: enable protection unit + orr r0, r0, #4 @ 0x00000004: enable D cache + orr r0, r0, #0x1000 @ 0x00001000: enable I cache + orr r0, r0, #0xC0000000 @ 0xC0000000: async+fastbus + mcr p15, 0, r0, c1, c0, 0 @ set control reg @ flush (invalidate) the cache (just in case) mov r0, #0 @@ -172,3 +172,5 @@ wait_irq: b .b_reserved .pool + +@ vim:filetype=ignored: diff --git a/platform/gp2x/940shared.h b/platform/gp2x/940shared.h index 71114da..bad0f3c 100644 --- a/platform/gp2x/940shared.h +++ b/platform/gp2x/940shared.h @@ -8,24 +8,26 @@ enum _940_job_t { JOB940_NUMJOBS }; +#define MAX_940JOBS 2 typedef struct { YM2612 ym2612; /* current state of the emulated YM2612 */ - int mix_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */ + int mix_buffer[44100/50*2]; /* this is where the YM2612 samples will be mixed to */ + short mp3_buffer[2][1152*2]; /* buffer for mp3 decoder's output */ } _940_data_t; typedef struct { - int job; /* a job for second core */ + int jobs[MAX_940JOBS]; /* jobs for second core */ int busy; /* busy status of the 940 core */ int length; /* number of samples to mix (882 max) */ int stereo; /* mix samples as stereo, doubles sample count automatically */ int baseclock; /* ym2612 settings */ int rate; int writebuffsel; /* which write buffer to use (from 940 side) */ - UINT16 writebuff0[2048]; /* 1024 for savestates, 1024 extra */ + UINT16 writebuff0[2048]; /* list of writes to ym2612, 1024 for savestates, 1024 extra */ UINT16 writebuff1[2048]; int vstarts[8]; /* debug: number of starts from each of 8 vectors */ int loopc; /* debug: main loop counter */ diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index fc729b0..602e4f6 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -10,7 +10,7 @@ CROSS = arm-linux- dprint = 1 #mz80 = 1 #debug_cyclone = 1 -asm_memory = 1 +asm_memory = 0 # TODO asm_render = 1 asm_ym2612 = 1 #profile = 1 @@ -42,7 +42,7 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory ../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o # Pico - CD OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ - ../../Pico/cd/cd_sys.o + ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o # asm stuff ifeq "$(asm_render)" "1" DEFINC += -D_ASM_DRAW_C diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index bea1569..49291ec 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -374,7 +374,7 @@ int emu_ReloadRom(void) } } gettimeofday(¬iceMsgTime, 0); - +printf("PicoMCD: %x\n", PicoMCD); // load SRAM for this ROM if(currentConfig.EmuOpt & 1) emu_SaveLoadGame(1, 1); @@ -586,8 +586,10 @@ void osd_text(int x, int y, char *text) static void cd_leds(void) { - static int old_reg = 0; - if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change + // mmu problems? +// static + int old_reg; +// if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change old_reg = Pico_mcd->s68k_regs[0]; if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { @@ -1021,7 +1023,7 @@ void emu_Loop(void) if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) { /* if 940 is turned off, we need it to be put back to sleep */ if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) { - Reset940(1); + Reset940(1, 2); Pause940(1); } sound_rerate(); diff --git a/platform/gp2x/gp2x.c b/platform/gp2x/gp2x.c index 84e5f7e..d1a844f 100644 --- a/platform/gp2x/gp2x.c +++ b/platform/gp2x/gp2x.c @@ -223,9 +223,9 @@ void Pause940(int yes) } -void Reset940(int yes) +void Reset940(int yes, int bank) { - gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (0x03); /* bank=3 */ + gp2x_memregs[0x3B48>>1] = ((yes&1) << 7) | (bank & 0x03); /* bank=3 */ } @@ -280,7 +280,7 @@ char *ext_menu = 0, *ext_state = 0; void gp2x_deinit(void) { - Reset940(1); + Reset940(1, 3); Pause940(1); gp2x_video_changemode(15); diff --git a/platform/gp2x/gp2x.h b/platform/gp2x/gp2x.h index 113f674..f76736d 100644 --- a/platform/gp2x/gp2x.h +++ b/platform/gp2x/gp2x.h @@ -25,7 +25,7 @@ unsigned long gp2x_joystick_read(int allow_usb_joy); /* 940 core */ void Pause940(int yes); -void Reset940(int yes); +void Reset940(int yes, int bank); extern void *gp2x_screen; diff --git a/platform/gp2x/main.c b/platform/gp2x/main.c index f21ebd7..5422b2b 100644 --- a/platform/gp2x/main.c +++ b/platform/gp2x/main.c @@ -86,8 +86,8 @@ int main(int argc, char *argv[]) mmuhack_status = ret; } cpuctrl_init(); - Reset940(1); - Pause940(1); + // Reset940(1); + // Pause940(1); if (currentConfig.EmuOpt&0x100) { printf("setting RAM timings.. "); fflush(stdout); // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2 @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) case PGS_Quit: goto endloop; - + default: printf("engine got into unknown state (%i), exitting\n", engineState); goto endloop; diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 1232e87..003bb40 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -959,7 +959,7 @@ static void draw_menu_root(int menu_sel) } else { y += 30; } - gp2x_text_out8(tl_x, (y+=10), "Load new ROM"); + gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO"); gp2x_text_out8(tl_x, (y+=10), "Change options"); gp2x_text_out8(tl_x, (y+=10), "Configure controls"); gp2x_text_out8(tl_x, (y+=10), "Credits"); diff --git a/platform/gp2x/port_config.h b/platform/gp2x/port_config.h index 239df01..a6a15af 100644 --- a/platform/gp2x/port_config.h +++ b/platform/gp2x/port_config.h @@ -12,7 +12,7 @@ // pico.c #define CAN_HANDLE_240_LINES 1 -//#define dprintf(f,...) printf(f"\n",##__VA_ARGS__) +//#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__) #define dprintf(x...) #endif //PORT_CONFIG_H diff --git a/platform/gp2x/version.h b/platform/gp2x/version.h index 8d13814..bbb221d 100644 --- a/platform/gp2x/version.h +++ b/platform/gp2x/version.h @@ -1,2 +1,2 @@ -#define VERSION "0.965" +#define VERSION "1.10" diff --git a/platform/linux/gp2x.c b/platform/linux/gp2x.c index 2651a50..d0efee8 100644 --- a/platform/linux/gp2x.c +++ b/platform/linux/gp2x.c @@ -327,7 +327,7 @@ void Pause940(int yes) { } -void Reset940(int yes) +void Reset940(int yes, int bank) { }