From 51a902ae2512cffdb3ac7751988c1bde4a641be4 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 28 Jan 2007 22:51:16 +0000 Subject: [PATCH] region detection, cd states wip, fixes, stuff git-svn-id: file:///home/notaz/opt/svn/PicoDrive@25 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Area.c | 86 ++++++------- Pico/Pico.c | 17 ++- Pico/Pico.h | 7 +- Pico/PicoInt.h | 11 +- Pico/cd/Area.c | 151 +++++++++++++++++++++++ Pico/cd/LC89510.c | 26 ++-- Pico/cd/LC89510.h | 4 +- Pico/cd/Memory.c | 10 +- Pico/cd/Misc.c | 16 +++ Pico/cd/Pico.c | 21 ++-- Pico/cd/Sek.c | 41 +++---- Pico/cd/cd_file.c | 21 +--- Pico/cd/cd_sys.c | 56 ++++----- Pico/cd/cd_sys.h | 5 +- Pico/cd/gfx_cd.c | 6 + Pico/cd/gfx_cd.h | 2 + platform/gp2x/940ctl_ym2612.c | 12 +- platform/gp2x/Makefile | 3 +- platform/gp2x/code940/940.c | 76 +++++++----- platform/gp2x/code940/940init.s | 10 ++ platform/gp2x/code940/Makefile | 4 + platform/gp2x/emu.c | 10 +- platform/gp2x/emu.h | 1 + platform/gp2x/menu.c | 208 +++++++++++++++++--------------- platform/linux/940ctl_ym2612.c | 4 +- platform/linux/Makefile | 3 +- 26 files changed, 520 insertions(+), 291 deletions(-) create mode 100644 Pico/cd/Area.c create mode 100644 Pico/cd/Misc.c diff --git a/Pico/Area.c b/Pico/Area.c index 1faea1f..5ae50e8 100644 --- a/Pico/Area.c +++ b/Pico/Area.c @@ -22,8 +22,9 @@ struct PicoArea { void *data; int len; char *name; }; // taking an address of fread or fwrite causes "application could't be started" error // on startup randomly depending on binary layout of executable file. -arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for -arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability +arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for +arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability +areaeof *areaEof = (areaeof *) 0; // Scan one variable and callback @@ -39,7 +40,7 @@ static int ScanVar(void *data,int len,char *name,void *PmovFile,int PmovAction) #define SCANP(x) ScanVar(&Pico.x,sizeof(Pico.x),#x,PmovFile,PmovAction); // Pack the cpu into a common format: -static int PackCpu(unsigned char *cpu) +int PicoAreaPackCpu(unsigned char *cpu, int is_sub) { unsigned int pc=0; @@ -52,29 +53,27 @@ static int PackCpu(unsigned char *cpu) #endif #ifdef EMU_C68K - memcpy(cpu,PicoCpu.d,0x40); - pc=PicoCpu.pc-PicoCpu.membase; - *(unsigned int *)(cpu+0x44)=CycloneGetSr(&PicoCpu); - *(unsigned int *)(cpu+0x48)=PicoCpu.osp; + struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu; + memcpy(cpu,context->d,0x40); + pc=context->pc-context->membase; + *(unsigned int *)(cpu+0x44)=CycloneGetSr(context); + *(unsigned int *)(cpu+0x48)=context->osp; #endif #ifdef EMU_M68K - memcpy(cpu,m68ki_cpu.dar,0x40); - pc=m68ki_cpu.pc; + m68ki_cpu_core *context = is_sub ? &PicoS68kCPU : &PicoM68kCPU; + memcpy(cpu,context->dar,0x40); + pc=context->pc; *(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR); - *(unsigned int *)(cpu+0x48)=m68ki_cpu.sp[0]; + *(unsigned int *)(cpu+0x48)=context->sp[0]; #endif *(unsigned int *)(cpu+0x40)=pc; return 0; } -static int UnpackCpu(unsigned char *cpu) +int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub) { - unsigned int pc=0; - - pc=*(unsigned int *)(cpu+0x40); - #ifdef EMU_A68K memcpy(M68000_regs.d,cpu,0x40); M68000_regs.pc=pc; @@ -84,18 +83,20 @@ static int UnpackCpu(unsigned char *cpu) #endif #ifdef EMU_C68K - CycloneSetSr(&PicoCpu, *(unsigned int *)(cpu+0x44)); - PicoCpu.osp=*(unsigned int *)(cpu+0x48); - memcpy(PicoCpu.d,cpu,0x40); - PicoCpu.membase=0; - PicoCpu.pc =PicoCpu.checkpc(pc); // Base pc + struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu; + CycloneSetSr(context, *(unsigned int *)(cpu+0x44)); + context->osp=*(unsigned int *)(cpu+0x48); + memcpy(context->d,cpu,0x40); + context->membase=0; + context->pc = context->checkpc(*(unsigned int *)(cpu+0x40)); // Base pc #endif #ifdef EMU_M68K - memcpy(m68ki_cpu.dar,cpu,0x40); - m68ki_cpu.pc=pc; + m68ki_cpu_core *context = is_sub ? &PicoS68kCPU : &PicoM68kCPU; + memcpy(context->dar,cpu,0x40); + context->pc=*(unsigned int *)(cpu+0x40); m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44)); - m68ki_cpu.sp[0]=*(unsigned int *)(cpu+0x48); + context->sp[0]=*(unsigned int *)(cpu+0x48); #endif return 0; } @@ -117,42 +118,35 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile) { Pico.m.scanline=0; - // Scan all the memory areas: + // Scan all the memory areas: SCANP(ram) SCANP(vram) SCANP(zram) SCANP(cram) SCANP(vsram) // Pack, scan and unpack the cpu data: - if((PmovAction&3)==1) PackCpu(cpu); + if((PmovAction&3)==1) PicoAreaPackCpu(cpu, 0); //SekInit(); // notaz: do we really have to do this here? //PicoMemInit(); SCAN_VAR(cpu,"cpu") - if((PmovAction&3)==2) UnpackCpu(cpu); + if((PmovAction&3)==2) PicoAreaUnpackCpu(cpu, 0); SCAN_VAR(Pico.m ,"misc") SCAN_VAR(Pico.video,"video") - - if(ver == 0x0030) { // zram was being saved incorrectly in 0x0030 (byteswaped?) - Byteswap(Pico.zram, 0x2000); - return 0; // do not try to load sound stuff - } - - //SCAN_VAR(Pico.s ,"sound") - // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway) - if(PicoOpt&7) { - if((PmovAction&3)==1) z80_pack(cpu_z80); + // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway) + if(PicoOpt&7) { + if((PmovAction&3)==1) z80_pack(cpu_z80); ret = SCAN_VAR(cpu_z80,"cpu_z80") - // do not unpack if we fail to load z80 state - if((PmovAction&3)==2) { + // do not unpack if we fail to load z80 state + if((PmovAction&3)==2) { if(ret) z80_reset(); else z80_unpack(cpu_z80); } - } - if(PicoOpt&3) + } + if(PicoOpt&3) ScanVar(sn76496_regs,28*4,"SN76496state", PmovFile, PmovAction); // regs and other stuff - if(PicoOpt&1) { + if(PicoOpt&1) { ScanVar(ym2612_regs, 0x200+4, "YM2612state", PmovFile, PmovAction); // regs + addr line - if((PmovAction&3)==2) YM2612PicoStateLoad(); // reload YM2612 state from it's regs - } + if((PmovAction&3)==2) YM2612PicoStateLoad(); // reload YM2612 state from it's regs + } } return 0; @@ -167,6 +161,12 @@ int PmovState(int PmovAction, void *PmovFile) int minimum=0; unsigned char head[32]; + // testing + { + if (PmovAction&1) return PicoCdSaveState(PmovFile); + if (PmovAction&2) return PicoCdLoadState(PmovFile); + } + memset(head,0,sizeof(head)); // Find out minimal compatible version: diff --git a/Pico/Pico.c b/Pico/Pico.c index f821cf4..1f201f4 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -16,6 +16,7 @@ struct Pico Pico; int PicoOpt=0; // disable everything by default int PicoSkipFrame=0; // skip rendering frame? int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe +int PicoAutoRgnOrder = 0; int emustatus = 0; void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware @@ -106,9 +107,12 @@ int PicoReset(int hard) c=region>>(i<<3); c&=0xff; if (c<=' ') continue; - if (c=='J') support|=1; - else if (c=='U') support|=4; - else if (c=='E') support|=8; + if (c=='J') support|=1; + else if (c=='U') support|=4; + else if (c=='E') support|=8; + else if (c=='j') {support|=1; break; } + else if (c=='u') {support|=4; break; } + else if (c=='e') {support|=8; break; } else { // New style code: @@ -119,6 +123,13 @@ int PicoReset(int hard) } } + // auto detection order override + if (PicoAutoRgnOrder) { + if (((PicoAutoRgnOrder>>0)&0xf) & support) support = (PicoAutoRgnOrder>>0)&0xf; + else if (((PicoAutoRgnOrder>>4)&0xf) & support) support = (PicoAutoRgnOrder>>4)&0xf; + else if (((PicoAutoRgnOrder>>8)&0xf) & support) support = (PicoAutoRgnOrder>>8)&0xf; + } + // Try to pick the best hardware value for English/50hz: if (support&8) { hw=0xc0; pal=1; } // Europe else if (support&4) hw=0x80; // USA diff --git a/Pico/Pico.h b/Pico/Pico.h index 4884051..05ae4b8 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -33,6 +33,7 @@ extern int PicoOpt; extern int PicoVer; extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff extern int PicoRegionOverride; // override the region detection 0: auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe +extern int PicoAutoRgnOrder; // packed priority list of regions, for example 0x148 means this detection order: EUR, USA, JAP int PicoInit(void); void PicoExit(void); int PicoReset(int hard); @@ -45,10 +46,12 @@ int PicoFrameMCD(void); // Area.c typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file); +typedef size_t (areaeof)(void *file); // Save or load the state from PmovFile: int PmovState(int PmovAction, void *PmovFile); // &1=for reading &2=for writing &4=volatile &8=non-volatile -extern arearw *areaRead; // read and write function pointers for -extern arearw *areaWrite; // gzip save state ability +extern arearw *areaRead; // external read and write function pointers for +extern arearw *areaWrite; // gzip save state ability +extern areaeof *areaEof; // Cart.c int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize); diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index 64768b1..2be566b 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -168,7 +168,9 @@ struct mcd_misc { unsigned short hint_vector; unsigned char busreq; - unsigned char pad0; + unsigned char s68k_pend_ints; + unsigned int state_flags; // emu state: reset_pending, + unsigned int counter75hz; }; @@ -191,6 +193,13 @@ typedef struct #define Pico_mcd ((mcd_state *)Pico.rom) +// Area.c +int PicoAreaPackCpu(unsigned char *cpu, int is_sub); +int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub); + +// cd/Area.c +int PicoCdSaveState(void *file); +int PicoCdLoadState(void *file); // Draw.c int PicoLine(int scan); diff --git a/Pico/cd/Area.c b/Pico/cd/Area.c new file mode 100644 index 0000000..9b67861 --- /dev/null +++ b/Pico/cd/Area.c @@ -0,0 +1,151 @@ +// This is part of Pico Library + +// (c) Copyright 2006 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + + +#include "../PicoInt.h" + +// ym2612 +#include "../sound/ym2612.h" + +// sn76496 +extern int *sn76496_regs; + + +typedef enum { + CHUNK_M68K = 1, + CHUNK_RAM, + CHUNK_VRAM, + CHUNK_ZRAM, + CHUNK_CRAM, + CHUNK_VSRAM, + CHUNK_MISC, + CHUNK_VIDEO, + CHUNK_Z80, + CHUNK_PSG, + CHUNK_FM, + // CD stuff +} chunk_name_e; + + +static int write_chunk(chunk_name_e name, int len, void *data, void *file) +{ + size_t bwritten = 0; + bwritten += areaWrite(&name, 1, 1, file); + bwritten += areaWrite(&len, 1, 4, file); + bwritten += areaWrite(data, 1, len, file); + + return (bwritten == len + 4 + 1); +} + + +#define CHECKED_WRITE(name,len,data) \ + if (!write_chunk(name, len, data, file)) return 1; + +#define CHECKED_WRITE_BUFF(name,buff) \ + if (!write_chunk(name, sizeof(buff), &buff, file)) return 1; + +int PicoCdSaveState(void *file) +{ + unsigned char buff[0x60]; + void *ym2612_regs = YM2612GetRegs(); + + areaWrite("PicoSMCD", 1, 8, file); + areaWrite(&PicoVer, 1, 4, file); + + memset(buff, 0, sizeof(buff)); + PicoAreaPackCpu(buff, 0); + CHECKED_WRITE_BUFF(CHUNK_M68K, buff); + CHECKED_WRITE_BUFF(CHUNK_RAM, Pico.ram); + CHECKED_WRITE_BUFF(CHUNK_VRAM, Pico.vram); + CHECKED_WRITE_BUFF(CHUNK_ZRAM, Pico.zram); + CHECKED_WRITE_BUFF(CHUNK_CRAM, Pico.cram); + CHECKED_WRITE_BUFF(CHUNK_VSRAM, Pico.vsram); + CHECKED_WRITE_BUFF(CHUNK_MISC, Pico.m); + CHECKED_WRITE_BUFF(CHUNK_VIDEO, Pico.video); + if(PicoOpt&7) { + memset(buff, 0, sizeof(buff)); + z80_pack(buff); + CHECKED_WRITE_BUFF(CHUNK_Z80, buff); + } + if(PicoOpt&3) + CHECKED_WRITE(CHUNK_PSG, 28*4, sn76496_regs); + if(PicoOpt&1) + CHECKED_WRITE(CHUNK_FM, 0x200+4, ym2612_regs); + + // TODO: cd stuff + + return 0; +} + +static int g_read_offs = 0; + +#define CHECKED_READ(len,data) \ + if (areaRead(data, 1, len, file) != len) { \ + g_read_offs += len; \ + printf("areaRead: premature EOF\n"); \ + return 0; \ + } + +#define R_ERROR_RETURN(error) \ +{ \ + printf("PicoCdLoadState @ %x: " error "\n", g_read_offs); \ + return 1; \ +} + +#define CHECKED_READ2(len2,data) \ + if (len2 != len) R_ERROR_RETURN("unexpected len, wanted " #len2); \ + CHECKED_READ(len2, data) + +#define CHECKED_READ_BUFF(buff) CHECKED_READ2(sizeof(buff), &buff); + +int PicoCdLoadState(void *file) +{ + unsigned char buff[0x60]; + int ver, len; + void *ym2612_regs = YM2612GetRegs(); + + g_read_offs = 0; + CHECKED_READ(8, buff); + if (strncmp((char *)buff, "PicoSMCD", 8)) R_ERROR_RETURN("bad header"); + CHECKED_READ(4, &ver); + + while (!areaEof(file)) + { + CHECKED_READ(1, buff); + CHECKED_READ(4, &len); + if (len < 0 || len > 1024*256) R_ERROR_RETURN("bad length"); + + switch (buff[0]) + { + case CHUNK_M68K: + CHECKED_READ_BUFF(buff); + PicoAreaUnpackCpu(buff, 0); + break; + + case CHUNK_Z80: + CHECKED_READ_BUFF(buff); + z80_unpack(buff); + break; + + case CHUNK_RAM: CHECKED_READ_BUFF(Pico.ram); break; + case CHUNK_VRAM: CHECKED_READ_BUFF(Pico.vram); break; + case CHUNK_ZRAM: CHECKED_READ_BUFF(Pico.zram); break; + case CHUNK_CRAM: CHECKED_READ_BUFF(Pico.cram); break; + case CHUNK_VSRAM: CHECKED_READ_BUFF(Pico.vsram); break; + case CHUNK_MISC: CHECKED_READ_BUFF(Pico.m); break; + case CHUNK_VIDEO: CHECKED_READ_BUFF(Pico.video); break; + case CHUNK_PSG: CHECKED_READ2(28*4, sn76496_regs); break; + case CHUNK_FM: + CHECKED_READ2(0x200+4, ym2612_regs); + YM2612PicoStateLoad(); + break; + } + } + + return 0; +} + diff --git a/Pico/cd/LC89510.c b/Pico/cd/LC89510.c index a6503ca..f877171 100644 --- a/Pico/cd/LC89510.c +++ b/Pico/cd/LC89510.c @@ -15,8 +15,6 @@ #define CDC_DMA_SPEED 256 -int CDC_Decode_Reg_Read; // 2 context? - static void CDD_Reset(void) { @@ -55,7 +53,7 @@ static void CDC_Reset(void) Pico_mcd->cdc.IFCTRL = 0; Pico_mcd->cdc.CTRL.N = 0; - CDC_Decode_Reg_Read = 0; + Pico_mcd->cdd.CDC_Decode_Reg_Read = 0; Pico_mcd->scd.Status_CDC &= ~0x08; } @@ -259,7 +257,7 @@ unsigned char CDC_Read_Reg(void) case 0x1: // IFSTAT cdprintf("CDC read reg 01 = %.2X", Pico_mcd->cdc.IFSTAT); - CDC_Decode_Reg_Read |= (1 << 1); // Reg 1 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 1); // Reg 1 (decoding) Pico_mcd->s68k_regs[5] = 0x2; return Pico_mcd->cdc.IFSTAT; @@ -278,42 +276,42 @@ unsigned char CDC_Read_Reg(void) case 0x4: // HEAD0 cdprintf("CDC read reg 04 = %.2X", Pico_mcd->cdc.HEAD.B.B0); - CDC_Decode_Reg_Read |= (1 << 4); // Reg 4 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 4); // Reg 4 (decoding) Pico_mcd->s68k_regs[5] = 0x5; return Pico_mcd->cdc.HEAD.B.B0; case 0x5: // HEAD1 cdprintf("CDC read reg 05 = %.2X", Pico_mcd->cdc.HEAD.B.B1); - CDC_Decode_Reg_Read |= (1 << 5); // Reg 5 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 5); // Reg 5 (decoding) Pico_mcd->s68k_regs[5] = 0x6; return Pico_mcd->cdc.HEAD.B.B1; case 0x6: // HEAD2 cdprintf("CDC read reg 06 = %.2X", Pico_mcd->cdc.HEAD.B.B2); - CDC_Decode_Reg_Read |= (1 << 6); // Reg 6 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 6); // Reg 6 (decoding) Pico_mcd->s68k_regs[5] = 0x7; return Pico_mcd->cdc.HEAD.B.B2; case 0x7: // HEAD3 cdprintf("CDC read reg 07 = %.2X", Pico_mcd->cdc.HEAD.B.B3); - CDC_Decode_Reg_Read |= (1 << 7); // Reg 7 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 7); // Reg 7 (decoding) Pico_mcd->s68k_regs[5] = 0x8; return Pico_mcd->cdc.HEAD.B.B3; case 0x8: // PTL cdprintf("CDC read reg 08 = %.2X", Pico_mcd->cdc.PT.B.L); - CDC_Decode_Reg_Read |= (1 << 8); // Reg 8 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 8); // Reg 8 (decoding) Pico_mcd->s68k_regs[5] = 0x9; return Pico_mcd->cdc.PT.B.L; case 0x9: // PTH cdprintf("CDC read reg 09 = %.2X", Pico_mcd->cdc.PT.B.H); - CDC_Decode_Reg_Read |= (1 << 9); // Reg 9 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 9); // Reg 9 (decoding) Pico_mcd->s68k_regs[5] = 0xA; return Pico_mcd->cdc.PT.B.H; @@ -332,21 +330,21 @@ unsigned char CDC_Read_Reg(void) case 0xC: // STAT0 cdprintf("CDC read reg 12 = %.2X", Pico_mcd->cdc.STAT.B.B0); - CDC_Decode_Reg_Read |= (1 << 12); // Reg 12 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 12); // Reg 12 (decoding) Pico_mcd->s68k_regs[5] = 0xD; return Pico_mcd->cdc.STAT.B.B0; case 0xD: // STAT1 cdprintf("CDC read reg 13 = %.2X", Pico_mcd->cdc.STAT.B.B1); - CDC_Decode_Reg_Read |= (1 << 13); // Reg 13 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 13); // Reg 13 (decoding) Pico_mcd->s68k_regs[5] = 0xE; return Pico_mcd->cdc.STAT.B.B1; case 0xE: // STAT2 cdprintf("CDC read reg 14 = %.2X", Pico_mcd->cdc.STAT.B.B2); - CDC_Decode_Reg_Read |= (1 << 14); // Reg 14 (decoding) + Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 14); // Reg 14 (decoding) Pico_mcd->s68k_regs[5] = 0xF; return Pico_mcd->cdc.STAT.B.B2; @@ -357,7 +355,7 @@ unsigned char CDC_Read_Reg(void) Pico_mcd->cdc.IFSTAT |= 0x20; // decoding interrupt flag cleared if ((Pico_mcd->cdc.CTRL.B.B0 & 0x80) && (Pico_mcd->cdc.IFCTRL & 0x20)) { - if ((CDC_Decode_Reg_Read & 0x73F2) == 0x73F2) + if ((Pico_mcd->cdd.CDC_Decode_Reg_Read & 0x73F2) == 0x73F2) Pico_mcd->cdc.STAT.B.B3 = 0x80; } return ret; diff --git a/Pico/cd/LC89510.h b/Pico/cd/LC89510.h index 7acfe8a..85e1615 100644 --- a/Pico/cd/LC89510.h +++ b/Pico/cd/LC89510.h @@ -88,6 +88,7 @@ typedef struct } B; unsigned int N; } CTRL; + unsigned int CDC_Decode_Reg_Read; } CDC; typedef struct @@ -105,9 +106,6 @@ typedef struct } CDD; -extern int CDC_Decode_Reg_Read; - - void LC89510_Reset(void); unsigned short Read_CDC_Host(int is_sub); void Update_CDC_TRansfer(int which); diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index fd48416..c56425b 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -31,8 +31,6 @@ typedef unsigned int u32; // extern m68ki_cpu_core m68ki_cpu; -extern int counter75hz; - static u32 m68k_reg_read16(u32 a) { @@ -91,12 +89,12 @@ static void m68k_reg_write8(u32 a, u32 d) return; case 1: d &= 3; - if (!(d&1)) PicoMCD |= 2; // reset pending, needed to be sure we fetch the right vectors on reset + if (!(d&1)) Pico_mcd->m.state_flags |= 1; // reset pending, needed to be sure we fetch the right vectors on reset if ( (Pico_mcd->m.busreq&1) != (d&1)) dprintf("m68k: s68k reset %i", !(d&1)); if ( (Pico_mcd->m.busreq&2) != (d&2)) dprintf("m68k: s68k brq %i", (d&2)>>1); - if ((PicoMCD&2) && (d&3)==1) { + if ((Pico_mcd->m.state_flags&1) && (d&3)==1) { SekResetS68k(); // S68k comes out of RESET or BRQ state - PicoMCD&=~2; + Pico_mcd->m.state_flags&=~1; dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft); } Pico_mcd->m.busreq = d; @@ -225,7 +223,6 @@ static void s68k_reg_write8(u32 a, u32 d) dprintf("s68k irq mask: %02x", d); if ((d&(1<<4)) && (Pico_mcd->s68k_regs[0x37]&4) && !(Pico_mcd->s68k_regs[0x33]&(1<<4))) { CDD_Export_Status(); - // counter75hz = 0; // ??? } break; case 0x34: // fader @@ -238,7 +235,6 @@ static void s68k_reg_write8(u32 a, u32 d) Pico_mcd->s68k_regs[0x37] = d&7; if ((d&4) && !(d_old&4)) { CDD_Export_Status(); - // counter75hz = 0; // ??? } return; } diff --git a/Pico/cd/Misc.c b/Pico/cd/Misc.c new file mode 100644 index 0000000..3ea974b --- /dev/null +++ b/Pico/cd/Misc.c @@ -0,0 +1,16 @@ + + +unsigned char formatted_bram[8*0x10] = +{ + 0x00, 0xd4, 0x63, 0x00, 0x00, 0x03, 0x03, 0x00, 0x03, 0x03, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x53, 0xd2, 0xf5, 0x3a, 0x48, 0x50, 0x35, 0x0f, + 0x47, 0x14, 0xf5, 0x7e, 0x5c, 0xd4, 0xf3, 0x03, 0x00, 0x03, 0x12, 0x00, 0x0a, 0xff, 0xca, 0xa6, + 0xf5, 0x27, 0xed, 0x22, 0x47, 0xfa, 0x22, 0x96, 0x6c, 0xa5, 0x88, 0x14, 0x48, 0x48, 0x0a, 0xbb, + 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x7d, 0x00, 0x7d, 0x00, 0x7d, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x53, 0x45, 0x47, 0x41, 0x5f, 0x43, 0x44, 0x5f, 0x52, 0x4f, 0x4d, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x52, 0x41, 0x4d, 0x5f, 0x43, 0x41, 0x52, 0x54, 0x52, 0x49, 0x44, 0x47, 0x45, 0x5f, 0x5f, 0x5f, + // SEGA_CD_ROM.....RAM_CART +}; + + diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 19b6f15..8b4c9e5 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -11,7 +11,7 @@ #include "../sound/sound.h" -static int counter75hz = 0; // TODO: move 2 context +extern unsigned char formatted_bram[8*0x10]; int PicoInitMCD(void) @@ -30,15 +30,22 @@ void PicoExitMCD(void) int PicoResetMCD(int hard) { - // clear everything except BIOS - memset(Pico_mcd->prg_ram, 0, sizeof(mcd_state) - sizeof(Pico_mcd->bios)); + memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram)); + memset(Pico_mcd->word_ram, 0, sizeof(Pico_mcd->word_ram)); + if (hard) { + memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram)); + memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - 8*0x10, formatted_bram, 8*0x10); + } + memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs)); + *(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6) - PicoMCD |= 2; // s68k reset pending. TODO: move + Pico_mcd->m.state_flags |= 2; // s68k reset pending Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode with m68k access after reset - counter75hz = 0; + Pico_mcd->m.counter75hz = 0; LC89510_Reset(); Reset_CD(); + gfx_cd_reset(); return 0; } @@ -235,8 +242,8 @@ static int PicoFrameHintsMCD(void) total_z80+=z80_run(z80CycleAim-total_z80); } - if ((counter75hz+=10) >= counter75hz_lim) { - counter75hz -= counter75hz_lim; + if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) { + Pico_mcd->m.counter75hz -= counter75hz_lim; Check_CD_Command(); } diff --git a/Pico/cd/Sek.c b/Pico/cd/Sek.c index 5def9c1..fc30045 100644 --- a/Pico/cd/Sek.c +++ b/Pico/cd/Sek.c @@ -23,20 +23,21 @@ struct Cyclone PicoCpuS68k; m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU #endif -static int irqs = 0; // TODO: 2 context +static int new_irq_level(int level) +{ + int level_new = 0, irqs; + Pico_mcd->m.s68k_pend_ints &= ~(1 << level); + irqs = Pico_mcd->m.s68k_pend_ints; + irqs &= Pico_mcd->s68k_regs[0x33]; + while ((irqs >>= 1)) level_new++; + return level_new; +} #ifdef EMU_M68K static int SekIntAckS68k(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--; } - } - + int level_new = new_irq_level(level); dprintf("s68kACK %i -> %i", level, level_new); CPU_INT_LEVEL = level_new << 8; return M68K_INT_ACK_AUTOVECTOR; @@ -45,15 +46,9 @@ static int SekIntAckS68k(int level) #ifdef EMU_C68K // interrupt acknowledgment -static void SekIntAck(int level) +static void SekIntAckS68k(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--; } - } + int level_new = new_irq_level(level); dprintf("s68kACK %i -> %i", level, level_new); PicoCpuS68k.irq = level_new; @@ -82,7 +77,7 @@ int SekInitS68k() #ifdef EMU_C68K // CycloneInit(); memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k)); - PicoCpuS68k.IrqCallback=SekIntAck; + PicoCpuS68k.IrqCallback=SekIntAckS68k; PicoCpuS68k.ResetCallback=SekResetAck; PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode; #endif @@ -132,14 +127,18 @@ int SekResetS68k() int SekInterruptS68k(int irq) { - irqs |= 1 << irq; + int irqs, real_irq = 1; + Pico_mcd->m.s68k_pend_ints |= 1 << irq; + irqs = Pico_mcd->m.s68k_pend_ints >> 1; + while ((irqs >>= 1)) real_irq++; // this is probably only needed for Cyclone + #ifdef EMU_C68K - PicoCpuS68k.irq=irq; + PicoCpuS68k.irq=real_irq; #endif #ifdef EMU_M68K void *oldcontext = m68ki_cpu_p; m68k_set_context(&PicoS68kCPU); - m68k_set_irq(irq); // raise irq (gets lowered after taken or must be done in ack) + m68k_set_irq(real_irq); // raise irq (gets lowered after taken or must be done in ack) m68k_set_context(oldcontext); #endif return 0; diff --git a/Pico/cd/cd_file.c b/Pico/cd/cd_file.c index 277f485..cb78675 100644 --- a/Pico/cd/cd_file.c +++ b/Pico/cd/cd_file.c @@ -1,20 +1,3 @@ -/* -#include -#include -#if defined(__WIN__) -#include -#else -#include "port.h" -#endif -#include "cd_sys.h" -#include "cd_file.h" -#include "lc89510.h" -#include "cdda_mp3.h" -#include "star_68k.h" -#include "rom.h" -#include "mem_s68k.h" -*/ - #include #include "cd_file.h" @@ -24,6 +7,7 @@ //#define cdprintf(x...) #define DEBUG_CD +// TODO: check refs, move 2 context struct _file_track Tracks[100]; char Track_Played; @@ -53,6 +37,7 @@ int Load_ISO(const char *iso_name, int is_bin) static char *exts[] = { "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3", "%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3", + "%02d.MP3", " %02d.MP3", "-%02d.MP3", "_%02d.MP3", " - %02d.MP3", /* "%02d.wav", " %02d.wav", "-%02d.wav", "_%02d.wav", " - %02d.wav", "%d.wav", " %d.wav", "-%d.wav", "_%d.wav", " - %2d.wav" */ }; @@ -103,8 +88,6 @@ int Load_ISO(const char *iso_name, int is_bin) for (num_track = 2, i = 0; i < 100; i++) { - if (sizeof(exts)/sizeof(char *) != 10) { printf("eee"); exit(1); } - for(j = 0; j < sizeof(exts)/sizeof(char *); j++) { int ext_len; diff --git a/Pico/cd/cd_sys.c b/Pico/cd/cd_sys.c index 2c70ea2..d754424 100644 --- a/Pico/cd/cd_sys.c +++ b/Pico/cd/cd_sys.c @@ -28,11 +28,7 @@ int CD_Audio_Starting; */ static int CD_Present = 0; -int CD_Timer_Counter = 0; // TODO: check refs - -static int CDD_Complete; - -static int File_Add_Delay = 0; +// int CD_Timer_Counter = 0; // TODO: check refs @@ -46,7 +42,7 @@ if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) \ Pico_mcd->cdd.Frame = 0; \ Pico_mcd->cdd.Ext = 0; \ \ - CDD_Complete = 1; \ + Pico_mcd->scd.CDD_Complete = 1; \ \ return 2; \ } @@ -63,7 +59,7 @@ if (!CD_Present) \ Pico_mcd->cdd.Frame = 0; \ Pico_mcd->cdd.Ext = 0; \ \ - CDD_Complete = 1; \ + Pico_mcd->scd.CDD_Complete = 1; \ \ return 3; \ } @@ -158,9 +154,9 @@ void Check_CD_Command(void) // Check CDD - if (CDD_Complete) + if (Pico_mcd->scd.CDD_Complete) { - CDD_Complete = 0; + Pico_mcd->scd.CDD_Complete = 0; CDD_Export_Status(); } @@ -176,11 +172,11 @@ void Check_CD_Command(void) Pico_mcd->s68k_regs[0x36] |= 0x01; else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO - if (File_Add_Delay == 0) + if (Pico_mcd->scd.File_Add_Delay == 0) { FILE_Read_One_LBA_CDC(); } - else File_Add_Delay--; + else Pico_mcd->scd.File_Add_Delay--; } if (Pico_mcd->scd.Status_CDD == FAST_FOW) @@ -217,7 +213,7 @@ void Reset_CD(void) Pico_mcd->scd.Cur_Track = 0; Pico_mcd->scd.Cur_LBA = -150; Pico_mcd->scd.Status_CDD = READY; - CDD_Complete = 0; + Pico_mcd->scd.CDD_Complete = 0; } @@ -267,7 +263,7 @@ int Get_Status_CDD_c0(void) else if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0E00) Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF); - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -290,7 +286,7 @@ int Stop_CDD_c1(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -322,7 +318,7 @@ int Get_Pos_CDD_c20(void) Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F); Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -356,7 +352,7 @@ int Get_Track_Pos_CDD_c21(void) Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F); Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -385,7 +381,7 @@ int Get_Current_Track_CDD_c22(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -415,7 +411,7 @@ int Get_Total_Lenght_CDD_c23(void) // FIXME: remove //Pico_mcd->cdd.Seconde = 2; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -441,7 +437,7 @@ int Get_First_Last_Track_CDD_c24(void) // FIXME: remove //Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -476,7 +472,7 @@ int Get_Track_Adr_CDD_c25(void) if (Pico_mcd->scd.TOC.Tracks[track_number - Pico_mcd->scd.TOC.First_Track].Type) Pico_mcd->cdd.Frame |= 0x0800; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -513,7 +509,7 @@ int Play_CDD_c3(void) Pico_mcd->cdd.Status = 0x0102; // Pico_mcd->cdd.Status = COMM_OK; - if (File_Add_Delay == 0) File_Add_Delay = delay; + if (Pico_mcd->scd.File_Add_Delay == 0) Pico_mcd->scd.File_Add_Delay = delay; if (Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type) { @@ -534,7 +530,7 @@ int Play_CDD_c3(void) Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -571,7 +567,7 @@ int Seek_CDD_c4(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -594,7 +590,7 @@ int Pause_CDD_c6(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -637,7 +633,7 @@ int Resume_CDD_c7(void) Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -657,7 +653,7 @@ int Fast_Foward_CDD_c8(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -678,7 +674,7 @@ int Fast_Rewind_CDD_c9(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -712,7 +708,7 @@ int Close_Tray_CDD_cC(void) Pico_mcd->cdd.Ext = 0; } - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -735,7 +731,7 @@ int Open_Tray_CDD_cD(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -756,7 +752,7 @@ int CDD_cA(void) Pico_mcd->cdd.Frame = INT_TO_BCDW(1); Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } diff --git a/Pico/cd/cd_sys.h b/Pico/cd/cd_sys.h index 7ec9cda..ec47080 100644 --- a/Pico/cd/cd_sys.h +++ b/Pico/cd/cd_sys.h @@ -46,12 +46,11 @@ typedef struct { _scd_toc TOC; int Cur_LBA; unsigned int Cur_Track; + int File_Add_Delay; + char CDD_Complete; } _scd; -extern int CD_Timer_Counter; - - void LBA_to_MSF(int lba, _msf *MSF); int Track_to_LBA(int track); diff --git a/Pico/cd/gfx_cd.c b/Pico/cd/gfx_cd.c index 4f393bd..c548846 100644 --- a/Pico/cd/gfx_cd.c +++ b/Pico/cd/gfx_cd.c @@ -1,5 +1,6 @@ // TODO... +// #include #include "../PicoInt.h" #define rot_comp Pico_mcd->rot_comp @@ -197,3 +198,8 @@ void gfx_cd_write(unsigned int a, unsigned int d) } +void gfx_cd_reset(void) +{ + memset(&rot_comp.Reg_58, 0, 0/*sizeof(Pico_mcd->rot_comp)*/); +} + diff --git a/Pico/cd/gfx_cd.h b/Pico/cd/gfx_cd.h index cc200ac..32fab74 100644 --- a/Pico/cd/gfx_cd.h +++ b/Pico/cd/gfx_cd.h @@ -36,5 +36,7 @@ void gfx_cd_update(void); unsigned int gfx_cd_read(unsigned int a); void gfx_cd_write(unsigned int a, unsigned int d); +void gfx_cd_reset(void); + #endif // _GFX_CD_H diff --git a/platform/gp2x/940ctl_ym2612.c b/platform/gp2x/940ctl_ym2612.c index f1949e6..1352172 100644 --- a/platform/gp2x/940ctl_ym2612.c +++ b/platform/gp2x/940ctl_ym2612.c @@ -27,6 +27,7 @@ static unsigned char *mp3_mem = 0; int crashed_940 = 0; +static FILE *loaded_mp3 = 0; /***********************************************************/ @@ -380,6 +381,8 @@ void YM2612Init_940(int baseclock, int rate) internal_reset(); + loaded_mp3 = 0; + /* now cause 940 to init it's ym2612 stuff */ shared_ctl->baseclock = baseclock; shared_ctl->rate = rate; @@ -468,13 +471,12 @@ static void mix_samples(short *dest_buf, int *ym_buf, short *mp3_buf, int len, i // here we assume that length is different between games, but constant in one game -static FILE *loaded_mp3 = 0; +static int mp3_samples_ready = 0, mp3_buffer_offs = 0; +static int mp3_play_bufsel = 0; void YM2612UpdateOne_940(short *buffer, int length, int stereo) { int cdda_on, *ym_buffer = shared_data->mix_buffer, mp3_job = 0; - static int mp3_samples_ready = 0, mp3_buffer_offs = 0; - static int mp3_play_bufsel = 1; //printf("YM2612UpdateOne_940()\n"); if (shared_ctl->busy) wait_busy_940(); @@ -567,6 +569,10 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len); shared_ctl->mp3_offs = byte_offs; + + // reset buffer pointers.. + mp3_samples_ready = mp3_buffer_offs = mp3_play_bufsel = 0; + shared_ctl->mp3_buffsel = 1; // will change to 0 on first decode } diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index 7b41be9..d253dcc 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -40,7 +40,8 @@ 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_file.o ../../Pico/cd/gfx_cd.o + ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \ + ../../Pico/cd/Area.o ../../Pico/cd/Misc.o # asm stuff ifeq "$(asm_render)" "1" DEFINC += -D_ASM_DRAW_C diff --git a/platform/gp2x/code940/940.c b/platform/gp2x/code940/940.c index e0c4002..34b42b9 100644 --- a/platform/gp2x/code940/940.c +++ b/platform/gp2x/code940/940.c @@ -11,11 +11,52 @@ void wait_irq(void); void spend_cycles(int c); void cache_clean(void); void cache_clean_flush(void); +// this should help to resolve race confition where shared var +// is changed by other core just before we update it +void set_if_not_changed(int *val, int oldval, int newval); // asm volatile ("mov r0, #0" ::: "r0"); // asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */ // asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */ + +static void mp3_decode(void) +{ + int mp3_offs = shared_ctl->mp3_offs; + unsigned char *readPtr = mp3_data + mp3_offs; + int bytesLeft = shared_ctl->mp3_len - mp3_offs; + int offset; // frame offset from readPtr + int err; + + if (bytesLeft <= 0) return; // EOF, nothing to do + + offset = MP3FindSyncWord(readPtr, bytesLeft); + if (offset < 0) { + set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len); + return; // EOF + } + readPtr += offset; + bytesLeft -= offset; + + err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft, + shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0); + if (err) { + if (err == ERR_MP3_INDATA_UNDERFLOW) { + shared_ctl->mp3_offs = shared_ctl->mp3_len; // EOF + set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len); + return; + } else if (err <= -6 && err >= -12) { + // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_* + // just try to skip the offending frame.. + readPtr++; + } + shared_ctl->mp3_errors++; + shared_ctl->mp3_lasterr = err; + } + set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data); +} + + void Main940(int startvector) { ym2612_940 = &shared_data->ym2612; @@ -85,40 +126,9 @@ void Main940(int startvector) break; } - case JOB940_MP3DECODE: { - int mp3_offs = shared_ctl->mp3_offs; - unsigned char *readPtr = mp3_data + mp3_offs; - int bytesLeft = shared_ctl->mp3_len - mp3_offs; - int offset; // frame offset from readPtr - int err; - - if (bytesLeft <= 0) break; // EOF, nothing to do - - offset = MP3FindSyncWord(readPtr, bytesLeft); - if (offset < 0) { - shared_ctl->mp3_offs = shared_ctl->mp3_len; - break; // EOF - } - readPtr += offset; - bytesLeft -= offset; - - err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft, - shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0); - if (err) { - if (err == ERR_MP3_INDATA_UNDERFLOW) { - shared_ctl->mp3_offs = shared_ctl->mp3_len; // EOF - break; - } else if (err <= -6 && err >= -12) { - // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_* - // just try to skip the offending frame.. - readPtr++; - } - shared_ctl->mp3_errors++; - shared_ctl->mp3_lasterr = err; - } - shared_ctl->mp3_offs = readPtr - mp3_data; + case JOB940_MP3DECODE: + mp3_decode(); break; - } } } diff --git a/platform/gp2x/code940/940init.s b/platform/gp2x/code940/940init.s index dcf4368..904ccba 100644 --- a/platform/gp2x/code940/940init.s +++ b/platform/gp2x/code940/940init.s @@ -182,4 +182,14 @@ wait_irq: .pool + +.global set_if_not_changed @ int *val, int oldval, int newval + +set_if_not_changed: + swp r3, r2, [r0] + cmp r1, r3 + bxeq lr + strne r3, [r0] @ restore value which was changed there by other core + bx lr + @ vim:filetype=armasm: diff --git a/platform/gp2x/code940/Makefile b/platform/gp2x/code940/Makefile index 8fe170a..a8322bb 100644 --- a/platform/gp2x/code940/Makefile +++ b/platform/gp2x/code940/Makefile @@ -61,6 +61,10 @@ code940.gpe : $(OBJS940) ../helix/helix_mp3.a @make -C ../helix/ +up: + @cp -v code940.bin /mnt/gp2x/mnt/sd/games/PicoDrive/ + + # cleanup clean: tidy @$(RM) code940.bin diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index dcc8f6e..17e7028 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -456,6 +456,7 @@ int emu_ReadConfig(int game) currentConfig.PicoOpt = 0x0f | 0x200; // | use_940 currentConfig.PsndRate = 44100; currentConfig.PicoRegion = 0; // auto + currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP currentConfig.Frameskip = -1; // auto currentConfig.CPUclock = 200; currentConfig.volume = 50; @@ -490,6 +491,7 @@ int emu_ReadConfig(int game) PicoOpt = currentConfig.PicoOpt; PsndRate = currentConfig.PsndRate; PicoRegionOverride = currentConfig.PicoRegion; + PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder; if (PicoOpt & 0x20) { actionNames[ 8] = "Z"; actionNames[ 9] = "Y"; actionNames[10] = "X"; actionNames[11] = "MODE"; @@ -527,6 +529,7 @@ int emu_WriteConfig(int game) currentConfig.PicoOpt = PicoOpt; currentConfig.PsndRate = PsndRate; currentConfig.PicoRegion = PicoRegionOverride; + currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder; bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f); fflush(f); fclose(f); @@ -1231,6 +1234,7 @@ if (Pico.m.frame_count == 31563) { // save SRAM if((currentConfig.EmuOpt & 1) && SRam.changed) { + blit("", "Writing SRAM/BRAM.."); emu_SaveLoadGame(0, 1); SRam.changed = 0; } @@ -1321,14 +1325,16 @@ int emu_SaveLoadGame(int load, int sram) if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) { areaRead = gzRead2; areaWrite = gzWrite2; + areaEof = (areaeof *) gzeof; if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY); } else saveFname[strlen(saveFname)-3] = 0; } if(!PmovFile) { // gzip failed or was disabled if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) { - areaRead = (STATE_SL_FUNC) fread; - areaWrite = (STATE_SL_FUNC) fwrite; + areaRead = (arearw *) fread; + areaWrite = (arearw *) fwrite; + areaEof = (areaeof *) feof; } } if(PmovFile) { diff --git a/platform/gp2x/emu.h b/platform/gp2x/emu.h index 3c90fdc..e5a7f30 100644 --- a/platform/gp2x/emu.h +++ b/platform/gp2x/emu.h @@ -30,6 +30,7 @@ typedef struct { int volume; int gamma; int JoyBinds[4][32]; + int PicoAutoRgnOrder; } currentConfig_t; extern char romFileName[]; diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index b771ee5..16c9ab5 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -562,18 +562,6 @@ static void kc_sel_loop(void) -// order must match that of currentConfig_t - -struct { - int EmuOpt; - int PicoOpt; - int PsndRate; - int PicoRegion; - int Frameskip; - int CPUclock; -} tmp_opts; -int tmp_gamma; - // --------- sega/mega cd options ---------- static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp) @@ -585,8 +573,8 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0 gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1 gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2 - gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (tmp_opts.EmuOpt &0x400)?"ON":"OFF"); // 3 - gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (tmp_opts.EmuOpt &0x800)?"ON":"OFF"); // 4 + gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x400)?"ON":"OFF"); // 3 + gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.EmuOpt &0x800)?"ON":"OFF"); // 4 gp2x_text_out8(tl_x, (y+=10), "Done"); // draw cursor @@ -629,8 +617,8 @@ static void cd_menu_loop_options(void) if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 3: tmp_opts.EmuOpt ^=0x400; break; - case 4: tmp_opts.EmuOpt ^=0x800; break; + case 3: currentConfig.EmuOpt ^=0x400; break; + case 4: currentConfig.EmuOpt ^=0x800; break; case 5: return; } } @@ -670,16 +658,16 @@ static void draw_amenu_options(int menu_sel) y = tl_y; memset(gp2x_screen, 0, 320*240); - gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (tmp_opts.PicoOpt&0x100)?"ON":"OFF"); // 0 - gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", tmp_gamma / 100, tmp_gamma%100); // 1 - gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (tmp_opts.PicoOpt&0x004)?"ON":"OFF"); // 2 - gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (tmp_opts.PicoOpt&0x001)?"ON":"OFF"); // 3 - gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (tmp_opts.PicoOpt&0x002)?"ON":"OFF"); // 4 - gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (tmp_opts.EmuOpt &0x008)?"ON":"OFF"); // 5 - gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (tmp_opts.EmuOpt &0x020)?"ON":"OFF"); // 6 + gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (currentConfig.PicoOpt&0x100)?"ON":"OFF"); // 0 + gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 1 + gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (currentConfig.PicoOpt&0x004)?"ON":"OFF"); // 2 + gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 3 + gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 4 + gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 5 + gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 6 gp2x_text_out8(tl_x, (y+=10), "needs restart:"); - gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (tmp_opts.EmuOpt &0x100)?"ON":"OFF"); // 8 - gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (tmp_opts.EmuOpt &0x010)?"ON":"OFF"); // 9 + gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 8 + gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9 gp2x_text_out8(tl_x, (y+=10), "Done"); // draw cursor @@ -701,14 +689,14 @@ static void amenu_loop_options(void) if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 0: tmp_opts.PicoOpt^=0x100; break; - case 2: tmp_opts.PicoOpt^=0x004; break; - case 3: tmp_opts.PicoOpt^=0x001; break; - case 4: tmp_opts.PicoOpt^=0x002; break; - case 5: tmp_opts.EmuOpt ^=0x008; break; - case 6: tmp_opts.EmuOpt ^=0x020; break; - case 8: tmp_opts.EmuOpt ^=0x100; break; - case 9: tmp_opts.EmuOpt ^=0x010; break; + case 0: currentConfig.PicoOpt^=0x100; break; + case 2: currentConfig.PicoOpt^=0x004; break; + case 3: currentConfig.PicoOpt^=0x001; break; + case 4: currentConfig.PicoOpt^=0x002; break; + case 5: currentConfig.EmuOpt ^=0x008; break; + case 6: currentConfig.EmuOpt ^=0x020; break; + case 8: currentConfig.EmuOpt ^=0x100; break; + case 9: currentConfig.EmuOpt ^=0x010; break; case 10: return; } } @@ -717,9 +705,9 @@ static void amenu_loop_options(void) switch (menu_sel) { case 1: while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) { - tmp_gamma += (inp & GP2X_LEFT) ? -1 : 1; - if (tmp_gamma < 1) tmp_gamma = 1; - if (tmp_gamma > 300) tmp_gamma = 300; + currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1; + if (currentConfig.gamma < 1) currentConfig.gamma = 1; + if (currentConfig.gamma > 300) currentConfig.gamma = 300; draw_amenu_options(menu_sel); usleep(18*1000); } @@ -731,14 +719,26 @@ static void amenu_loop_options(void) // -------------- options -------------- -static char *region_name(unsigned int code) +static const char *region_name(unsigned int code) { - char *names[] = { "Auto", "Japan NTSC", "Japan PAL", "USA", "Europe" }; - int i = 0; - code <<= 1; - while((code >>=1)) i++; - if (i > 4) return "unknown"; - return names[i]; + static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" }; + static const char *names_short[] = { "", " JP", " JP", " US", " EU" }; + int u, i = 0; + if (code) { + code <<= 1; + while((code >>= 1)) i++; + if (i > 4) return "unknown"; + return names[i]; + } else { + static char name[24]; + strcpy(name, "Auto:"); + for (u = 0; u < 3; u++) { + i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1; + while((code >>= 1)) i++; + strcat(name, names_short[i]); + } + return name; + } } static void draw_menu_options(int menu_sel) @@ -746,13 +746,13 @@ static void draw_menu_options(int menu_sel) int tl_x = 25, tl_y = 40, y; char monostereo[8], strframeskip[8], *strrend; - strcpy(monostereo, (tmp_opts.PicoOpt&0x08)?"stereo":"mono"); - if (tmp_opts.Frameskip < 0) + strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono"); + if (currentConfig.Frameskip < 0) strcpy(strframeskip, "Auto"); - else sprintf(strframeskip, "%i", tmp_opts.Frameskip); - if (tmp_opts.PicoOpt&0x10) { + else sprintf(strframeskip, "%i", currentConfig.Frameskip); + if (currentConfig.PicoOpt&0x10) { strrend = " 8bit fast"; - } else if (tmp_opts.EmuOpt&0x80) { + } else if (currentConfig.EmuOpt&0x80) { strrend = "16bit accurate"; } else { strrend = " 8bit accurate"; @@ -761,19 +761,19 @@ static void draw_menu_options(int menu_sel) y = tl_y; memset(gp2x_screen, 0, 320*240); gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0 - gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (tmp_opts.PicoOpt&0x040)?"ON":"OFF"); // 1 - gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (tmp_opts.PicoOpt&0x080)?"ON":"OFF"); // 2 - gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (tmp_opts.EmuOpt &0x002)?"ON":"OFF"); // 3 + gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 1 + gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 2 + gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 3 gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip); - gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (tmp_opts.EmuOpt &0x004)?"ON":"OFF"); // 5 - gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", tmp_opts.PsndRate, monostereo); - gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (tmp_opts.PicoOpt&0x200)?"ON":"OFF"); // 7 - gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (tmp_opts.PicoOpt&0x020)?"ON":"OFF"); // 8 - gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(tmp_opts.PicoRegion)); - gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10 - gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (tmp_opts.EmuOpt &0x200)?"ON":"OFF"); // 11 + gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 5 + gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", currentConfig.PsndRate, monostereo); + gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 7 + gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 8 + gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(currentConfig.PicoRegion)); + gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 10 + gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (currentConfig.EmuOpt &0x200)?"ON":"OFF"); // 11 gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12 - gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", tmp_opts.CPUclock); + gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", currentConfig.CPUclock); gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]"); gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15 gp2x_text_out8(tl_x, (y+=10), "Save cfg as default"); @@ -799,10 +799,32 @@ static int sndrate_prevnext(int rate, int dir) return rates[i]; } +static void region_prevnext(int right) +{ + // jp_ntsc=1, jp_pal=2, usa=4, eu=8 + static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 }; + int i; + if (right) { + if (!currentConfig.PicoRegion) { + for (i = 0; i < 6; i++) + if (rgn_orders[i] == PicoAutoRgnOrder) break; + if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1]; + else currentConfig.PicoRegion=1; + } + else currentConfig.PicoRegion<<=1; + if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8; + } else { + if (!currentConfig.PicoRegion) { + for (i = 0; i < 6; i++) + if (rgn_orders[i] == PicoAutoRgnOrder) break; + if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1]; + } + else currentConfig.PicoRegion>>=1; + } +} + static void menu_options_save(void) { - memcpy(¤tConfig.EmuOpt, &tmp_opts.EmuOpt, sizeof(tmp_opts)); - currentConfig.gamma = tmp_gamma; PicoOpt = currentConfig.PicoOpt; PsndRate = currentConfig.PsndRate; PicoRegionOverride = currentConfig.PicoRegion; @@ -820,11 +842,9 @@ static int menu_loop_options(void) unsigned long inp = 0; if (rom_data) menu_sel_max++; - memcpy(&tmp_opts.EmuOpt, ¤tConfig.EmuOpt, sizeof(tmp_opts)); - tmp_gamma = currentConfig.gamma; - tmp_opts.PicoOpt = PicoOpt; - tmp_opts.PsndRate = PsndRate; - tmp_opts.PicoRegion = PicoRegionOverride; + currentConfig.PicoOpt = PicoOpt; + currentConfig.PsndRate = PsndRate; + currentConfig.PicoRegion = PicoRegionOverride; for(;;) { @@ -834,14 +854,14 @@ static int menu_loop_options(void) if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 1: tmp_opts.PicoOpt^=0x040; break; - case 2: tmp_opts.PicoOpt^=0x080; break; - case 3: tmp_opts.EmuOpt ^=0x002; break; - case 5: tmp_opts.EmuOpt ^=0x004; break; - case 7: tmp_opts.PicoOpt^=0x200; break; - case 8: tmp_opts.PicoOpt^=0x020; break; - case 10: tmp_opts.EmuOpt ^=0x001; break; - case 11: tmp_opts.EmuOpt ^=0x200; break; + case 1: currentConfig.PicoOpt^=0x040; break; + case 2: currentConfig.PicoOpt^=0x080; break; + case 3: currentConfig.EmuOpt ^=0x002; break; + case 5: currentConfig.EmuOpt ^=0x004; break; + case 7: currentConfig.PicoOpt^=0x200; break; + case 8: currentConfig.PicoOpt^=0x020; break; + case 10: currentConfig.EmuOpt ^=0x001; break; + case 11: currentConfig.EmuOpt ^=0x200; break; case 14: cd_menu_loop_options(); if (engineState == PGS_ReloadRom) return 0; // test BIOS @@ -859,8 +879,7 @@ static int menu_loop_options(void) return 1; } } - if(inp & GP2X_X) return 0; // done (no update or write) - if(inp & GP2X_A) { + if(inp & (GP2X_X|GP2X_A)) { menu_options_save(); return 0; // done (update, no write) } @@ -868,32 +887,29 @@ static int menu_loop_options(void) switch (menu_sel) { case 0: if (inp & GP2X_LEFT) { - if ( tmp_opts.PicoOpt&0x10) tmp_opts.PicoOpt&= ~0x10; - else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.EmuOpt |= 0x80; - else if ( tmp_opts.EmuOpt &0x80) break; + if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10; + else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80; + else if ( currentConfig.EmuOpt &0x80) break; } else { - if ( tmp_opts.PicoOpt&0x10) break; - else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.PicoOpt|= 0x10; - else if ( tmp_opts.EmuOpt &0x80) tmp_opts.EmuOpt &= ~0x80; + if ( currentConfig.PicoOpt&0x10) break; + else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10; + else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80; } break; case 4: - tmp_opts.Frameskip += (inp & GP2X_LEFT) ? -1 : 1; - if (tmp_opts.Frameskip < 0) tmp_opts.Frameskip = -1; - if (tmp_opts.Frameskip > 32) tmp_opts.Frameskip = 32; + currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1; + if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1; + if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32; break; case 6: - if ((inp & GP2X_RIGHT) && tmp_opts.PsndRate == 44100 && !(tmp_opts.PicoOpt&0x08)) { - tmp_opts.PsndRate = 8000; tmp_opts.PicoOpt|= 0x08; - } else if ((inp & GP2X_LEFT) && tmp_opts.PsndRate == 8000 && (tmp_opts.PicoOpt&0x08)) { - tmp_opts.PsndRate = 44100; tmp_opts.PicoOpt&=~0x08; - } else tmp_opts.PsndRate = sndrate_prevnext(tmp_opts.PsndRate, inp & GP2X_RIGHT); + if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) { + currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08; + } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) { + currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08; + } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT); break; case 9: - if (inp & GP2X_RIGHT) { - if (tmp_opts.PicoRegion) tmp_opts.PicoRegion<<=1; else tmp_opts.PicoRegion=1; - if (tmp_opts.PicoRegion > 8) tmp_opts.PicoRegion = 8; - } else tmp_opts.PicoRegion>>=1; + region_prevnext(inp & GP2X_RIGHT); break; case 12: if (inp & GP2X_RIGHT) { @@ -903,8 +919,8 @@ static int menu_loop_options(void) break; case 13: while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) { - tmp_opts.CPUclock += (inp & GP2X_LEFT) ? -1 : 1; - if (tmp_opts.CPUclock < 1) tmp_opts.CPUclock = 1; + currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1; + if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1; draw_menu_options(menu_sel); usleep(50*1000); } diff --git a/platform/linux/940ctl_ym2612.c b/platform/linux/940ctl_ym2612.c index b5263dc..4458a2f 100644 --- a/platform/linux/940ctl_ym2612.c +++ b/platform/linux/940ctl_ym2612.c @@ -23,9 +23,9 @@ YM2612 *ym2612_940 = &ym2612; int mix_buffer_[44100/50*2]; /* this is where the YM2612 samples will be mixed to */ int *mix_buffer = mix_buffer_; -static _940_data_t shared_data_; +// static _940_data_t shared_data_; static _940_ctl_t shared_ctl_; -static _940_data_t *shared_data = &shared_data_; +// static _940_data_t *shared_data = &shared_data_; static _940_ctl_t *shared_ctl = &shared_ctl_; unsigned char *mp3_mem = 0; diff --git a/platform/linux/Makefile b/platform/linux/Makefile index 6cce539..e8d740e 100644 --- a/platform/linux/Makefile +++ b/platform/linux/Makefile @@ -30,7 +30,8 @@ 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_file.o ../../Pico/cd/gfx_cd.o + ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \ + ../../Pico/cd/Area.o ../../Pico/cd/Misc.o # Pico - sound OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o # zlib -- 2.39.2