// taking an address of fread or fwrite causes "application could't be started" error\r
// on startup randomly depending on binary layout of executable file.\r
\r
-arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for\r
-arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability\r
+arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for\r
+arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability\r
+areaeof *areaEof = (areaeof *) 0;\r
\r
\r
// Scan one variable and callback\r
#define SCANP(x) ScanVar(&Pico.x,sizeof(Pico.x),#x,PmovFile,PmovAction);\r
\r
// Pack the cpu into a common format:\r
-static int PackCpu(unsigned char *cpu)\r
+int PicoAreaPackCpu(unsigned char *cpu, int is_sub)\r
{\r
unsigned int pc=0;\r
\r
#endif\r
\r
#ifdef EMU_C68K\r
- memcpy(cpu,PicoCpu.d,0x40);\r
- pc=PicoCpu.pc-PicoCpu.membase;\r
- *(unsigned int *)(cpu+0x44)=CycloneGetSr(&PicoCpu);\r
- *(unsigned int *)(cpu+0x48)=PicoCpu.osp;\r
+ struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu;\r
+ memcpy(cpu,context->d,0x40);\r
+ pc=context->pc-context->membase;\r
+ *(unsigned int *)(cpu+0x44)=CycloneGetSr(context);\r
+ *(unsigned int *)(cpu+0x48)=context->osp;\r
#endif\r
\r
#ifdef EMU_M68K\r
- memcpy(cpu,m68ki_cpu.dar,0x40);\r
- pc=m68ki_cpu.pc;\r
+ m68ki_cpu_core *context = is_sub ? &PicoS68kCPU : &PicoM68kCPU;\r
+ memcpy(cpu,context->dar,0x40);\r
+ pc=context->pc;\r
*(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR);\r
- *(unsigned int *)(cpu+0x48)=m68ki_cpu.sp[0];\r
+ *(unsigned int *)(cpu+0x48)=context->sp[0];\r
#endif\r
\r
*(unsigned int *)(cpu+0x40)=pc;\r
return 0;\r
}\r
\r
-static int UnpackCpu(unsigned char *cpu)\r
+int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub)\r
{\r
- unsigned int pc=0;\r
-\r
- pc=*(unsigned int *)(cpu+0x40);\r
-\r
#ifdef EMU_A68K\r
memcpy(M68000_regs.d,cpu,0x40);\r
M68000_regs.pc=pc;\r
#endif\r
\r
#ifdef EMU_C68K\r
- CycloneSetSr(&PicoCpu, *(unsigned int *)(cpu+0x44));\r
- PicoCpu.osp=*(unsigned int *)(cpu+0x48);\r
- memcpy(PicoCpu.d,cpu,0x40);\r
- PicoCpu.membase=0;\r
- PicoCpu.pc =PicoCpu.checkpc(pc); // Base pc\r
+ struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu;\r
+ CycloneSetSr(context, *(unsigned int *)(cpu+0x44));\r
+ context->osp=*(unsigned int *)(cpu+0x48);\r
+ memcpy(context->d,cpu,0x40);\r
+ context->membase=0;\r
+ context->pc = context->checkpc(*(unsigned int *)(cpu+0x40)); // Base pc\r
#endif\r
\r
#ifdef EMU_M68K\r
- memcpy(m68ki_cpu.dar,cpu,0x40);\r
- m68ki_cpu.pc=pc;\r
+ m68ki_cpu_core *context = is_sub ? &PicoS68kCPU : &PicoM68kCPU;\r
+ memcpy(context->dar,cpu,0x40);\r
+ context->pc=*(unsigned int *)(cpu+0x40);\r
m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44));\r
- m68ki_cpu.sp[0]=*(unsigned int *)(cpu+0x48);\r
+ context->sp[0]=*(unsigned int *)(cpu+0x48);\r
#endif\r
return 0;\r
}\r
{\r
Pico.m.scanline=0;\r
\r
- // Scan all the memory areas:\r
+ // Scan all the memory areas:\r
SCANP(ram) SCANP(vram) SCANP(zram) SCANP(cram) SCANP(vsram)\r
\r
// Pack, scan and unpack the cpu data:\r
- if((PmovAction&3)==1) PackCpu(cpu);\r
+ if((PmovAction&3)==1) PicoAreaPackCpu(cpu, 0);\r
//SekInit(); // notaz: do we really have to do this here?\r
//PicoMemInit();\r
SCAN_VAR(cpu,"cpu")\r
- if((PmovAction&3)==2) UnpackCpu(cpu);\r
+ if((PmovAction&3)==2) PicoAreaUnpackCpu(cpu, 0);\r
\r
SCAN_VAR(Pico.m ,"misc")\r
SCAN_VAR(Pico.video,"video")\r
\r
-\r
- if(ver == 0x0030) { // zram was being saved incorrectly in 0x0030 (byteswaped?)\r
- Byteswap(Pico.zram, 0x2000);\r
- return 0; // do not try to load sound stuff\r
- }\r
-\r
- //SCAN_VAR(Pico.s ,"sound")\r
- // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway)\r
- if(PicoOpt&7) {\r
- if((PmovAction&3)==1) z80_pack(cpu_z80);\r
+ // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway)\r
+ if(PicoOpt&7) {\r
+ if((PmovAction&3)==1) z80_pack(cpu_z80);\r
ret = SCAN_VAR(cpu_z80,"cpu_z80")\r
- // do not unpack if we fail to load z80 state\r
- if((PmovAction&3)==2) {\r
+ // do not unpack if we fail to load z80 state\r
+ if((PmovAction&3)==2) {\r
if(ret) z80_reset();\r
else z80_unpack(cpu_z80);\r
}\r
- }\r
- if(PicoOpt&3)\r
+ }\r
+ if(PicoOpt&3)\r
ScanVar(sn76496_regs,28*4,"SN76496state", PmovFile, PmovAction); // regs and other stuff\r
- if(PicoOpt&1) {\r
+ if(PicoOpt&1) {\r
ScanVar(ym2612_regs, 0x200+4, "YM2612state", PmovFile, PmovAction); // regs + addr line\r
- if((PmovAction&3)==2) YM2612PicoStateLoad(); // reload YM2612 state from it's regs\r
- }\r
+ if((PmovAction&3)==2) YM2612PicoStateLoad(); // reload YM2612 state from it's regs\r
+ }\r
}\r
\r
return 0;\r
int minimum=0;\r
unsigned char head[32];\r
\r
+ // testing\r
+ {\r
+ if (PmovAction&1) return PicoCdSaveState(PmovFile);\r
+ if (PmovAction&2) return PicoCdLoadState(PmovFile);\r
+ }\r
+\r
memset(head,0,sizeof(head));\r
\r
// Find out minimal compatible version:\r
int PicoOpt=0; // disable everything by default\r
int PicoSkipFrame=0; // skip rendering frame?\r
int PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
+int PicoAutoRgnOrder = 0;\r
int emustatus = 0;\r
void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware\r
\r
c=region>>(i<<3); c&=0xff;\r
if (c<=' ') continue;\r
\r
- if (c=='J') support|=1;\r
- else if (c=='U') support|=4;\r
- else if (c=='E') support|=8;\r
+ if (c=='J') support|=1;\r
+ else if (c=='U') support|=4;\r
+ else if (c=='E') support|=8;\r
+ else if (c=='j') {support|=1; break; }\r
+ else if (c=='u') {support|=4; break; }\r
+ else if (c=='e') {support|=8; break; }\r
else\r
{\r
// New style code:\r
}\r
}\r
\r
+ // auto detection order override\r
+ if (PicoAutoRgnOrder) {\r
+ if (((PicoAutoRgnOrder>>0)&0xf) & support) support = (PicoAutoRgnOrder>>0)&0xf;\r
+ else if (((PicoAutoRgnOrder>>4)&0xf) & support) support = (PicoAutoRgnOrder>>4)&0xf;\r
+ else if (((PicoAutoRgnOrder>>8)&0xf) & support) support = (PicoAutoRgnOrder>>8)&0xf;\r
+ }\r
+\r
// Try to pick the best hardware value for English/50hz:\r
if (support&8) { hw=0xc0; pal=1; } // Europe\r
else if (support&4) hw=0x80; // USA\r
extern int PicoVer;\r
extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff\r
extern int PicoRegionOverride; // override the region detection 0: auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe\r
+extern int PicoAutoRgnOrder; // packed priority list of regions, for example 0x148 means this detection order: EUR, USA, JAP\r
int PicoInit(void);\r
void PicoExit(void);\r
int PicoReset(int hard);\r
\r
// Area.c\r
typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file);\r
+typedef size_t (areaeof)(void *file);\r
// Save or load the state from PmovFile:\r
int PmovState(int PmovAction, void *PmovFile); // &1=for reading &2=for writing &4=volatile &8=non-volatile\r
-extern arearw *areaRead; // read and write function pointers for\r
-extern arearw *areaWrite; // gzip save state ability\r
+extern arearw *areaRead; // external read and write function pointers for\r
+extern arearw *areaWrite; // gzip save state ability\r
+extern areaeof *areaEof;\r
\r
// Cart.c\r
int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize);\r
{\r
unsigned short hint_vector;\r
unsigned char busreq;\r
- unsigned char pad0;\r
+ unsigned char s68k_pend_ints;\r
+ unsigned int state_flags; // emu state: reset_pending,\r
+ unsigned int counter75hz;\r
\r
};\r
\r
\r
#define Pico_mcd ((mcd_state *)Pico.rom)\r
\r
+// Area.c\r
+int PicoAreaPackCpu(unsigned char *cpu, int is_sub);\r
+int PicoAreaUnpackCpu(unsigned char *cpu, int is_sub);\r
+\r
+// cd/Area.c\r
+int PicoCdSaveState(void *file);\r
+int PicoCdLoadState(void *file);\r
\r
// Draw.c\r
int PicoLine(int scan);\r
--- /dev/null
+// 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;
+}
+
\r
#define CDC_DMA_SPEED 256\r
\r
-int CDC_Decode_Reg_Read; // 2 context?\r
-\r
\r
static void CDD_Reset(void)\r
{\r
Pico_mcd->cdc.IFCTRL = 0;\r
Pico_mcd->cdc.CTRL.N = 0;\r
\r
- CDC_Decode_Reg_Read = 0;\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read = 0;\r
Pico_mcd->scd.Status_CDC &= ~0x08;\r
}\r
\r
case 0x1: // IFSTAT\r
cdprintf("CDC read reg 01 = %.2X", Pico_mcd->cdc.IFSTAT);\r
\r
- CDC_Decode_Reg_Read |= (1 << 1); // Reg 1 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 1); // Reg 1 (decoding)\r
Pico_mcd->s68k_regs[5] = 0x2;\r
return Pico_mcd->cdc.IFSTAT;\r
\r
case 0x4: // HEAD0\r
cdprintf("CDC read reg 04 = %.2X", Pico_mcd->cdc.HEAD.B.B0);\r
\r
- CDC_Decode_Reg_Read |= (1 << 4); // Reg 4 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 4); // Reg 4 (decoding)\r
Pico_mcd->s68k_regs[5] = 0x5;\r
return Pico_mcd->cdc.HEAD.B.B0;\r
\r
case 0x5: // HEAD1\r
cdprintf("CDC read reg 05 = %.2X", Pico_mcd->cdc.HEAD.B.B1);\r
\r
- CDC_Decode_Reg_Read |= (1 << 5); // Reg 5 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 5); // Reg 5 (decoding)\r
Pico_mcd->s68k_regs[5] = 0x6;\r
return Pico_mcd->cdc.HEAD.B.B1;\r
\r
case 0x6: // HEAD2\r
cdprintf("CDC read reg 06 = %.2X", Pico_mcd->cdc.HEAD.B.B2);\r
\r
- CDC_Decode_Reg_Read |= (1 << 6); // Reg 6 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 6); // Reg 6 (decoding)\r
Pico_mcd->s68k_regs[5] = 0x7;\r
return Pico_mcd->cdc.HEAD.B.B2;\r
\r
case 0x7: // HEAD3\r
cdprintf("CDC read reg 07 = %.2X", Pico_mcd->cdc.HEAD.B.B3);\r
\r
- CDC_Decode_Reg_Read |= (1 << 7); // Reg 7 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 7); // Reg 7 (decoding)\r
Pico_mcd->s68k_regs[5] = 0x8;\r
return Pico_mcd->cdc.HEAD.B.B3;\r
\r
case 0x8: // PTL\r
cdprintf("CDC read reg 08 = %.2X", Pico_mcd->cdc.PT.B.L);\r
\r
- CDC_Decode_Reg_Read |= (1 << 8); // Reg 8 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 8); // Reg 8 (decoding)\r
Pico_mcd->s68k_regs[5] = 0x9;\r
return Pico_mcd->cdc.PT.B.L;\r
\r
case 0x9: // PTH\r
cdprintf("CDC read reg 09 = %.2X", Pico_mcd->cdc.PT.B.H);\r
\r
- CDC_Decode_Reg_Read |= (1 << 9); // Reg 9 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 9); // Reg 9 (decoding)\r
Pico_mcd->s68k_regs[5] = 0xA;\r
return Pico_mcd->cdc.PT.B.H;\r
\r
case 0xC: // STAT0\r
cdprintf("CDC read reg 12 = %.2X", Pico_mcd->cdc.STAT.B.B0);\r
\r
- CDC_Decode_Reg_Read |= (1 << 12); // Reg 12 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 12); // Reg 12 (decoding)\r
Pico_mcd->s68k_regs[5] = 0xD;\r
return Pico_mcd->cdc.STAT.B.B0;\r
\r
case 0xD: // STAT1\r
cdprintf("CDC read reg 13 = %.2X", Pico_mcd->cdc.STAT.B.B1);\r
\r
- CDC_Decode_Reg_Read |= (1 << 13); // Reg 13 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 13); // Reg 13 (decoding)\r
Pico_mcd->s68k_regs[5] = 0xE;\r
return Pico_mcd->cdc.STAT.B.B1;\r
\r
case 0xE: // STAT2\r
cdprintf("CDC read reg 14 = %.2X", Pico_mcd->cdc.STAT.B.B2);\r
\r
- CDC_Decode_Reg_Read |= (1 << 14); // Reg 14 (decoding)\r
+ Pico_mcd->cdd.CDC_Decode_Reg_Read |= (1 << 14); // Reg 14 (decoding)\r
Pico_mcd->s68k_regs[5] = 0xF;\r
return Pico_mcd->cdc.STAT.B.B2;\r
\r
Pico_mcd->cdc.IFSTAT |= 0x20; // decoding interrupt flag cleared\r
if ((Pico_mcd->cdc.CTRL.B.B0 & 0x80) && (Pico_mcd->cdc.IFCTRL & 0x20))\r
{\r
- if ((CDC_Decode_Reg_Read & 0x73F2) == 0x73F2)\r
+ if ((Pico_mcd->cdd.CDC_Decode_Reg_Read & 0x73F2) == 0x73F2)\r
Pico_mcd->cdc.STAT.B.B3 = 0x80;\r
}\r
return ret;\r
} B;\r
unsigned int N;\r
} CTRL;\r
+ unsigned int CDC_Decode_Reg_Read;\r
} CDC;\r
\r
typedef struct\r
} CDD;\r
\r
\r
-extern int CDC_Decode_Reg_Read;\r
-\r
-\r
void LC89510_Reset(void);\r
unsigned short Read_CDC_Host(int is_sub);\r
void Update_CDC_TRansfer(int which);\r
\r
// extern m68ki_cpu_core m68ki_cpu;\r
\r
-extern int counter75hz;\r
-\r
\r
static u32 m68k_reg_read16(u32 a)\r
{\r
return;\r
case 1:\r
d &= 3;\r
- if (!(d&1)) PicoMCD |= 2; // reset pending, needed to be sure we fetch the right vectors on reset\r
+ if (!(d&1)) Pico_mcd->m.state_flags |= 1; // reset pending, needed to be sure we fetch the right vectors on reset\r
if ( (Pico_mcd->m.busreq&1) != (d&1)) dprintf("m68k: s68k reset %i", !(d&1));\r
if ( (Pico_mcd->m.busreq&2) != (d&2)) dprintf("m68k: s68k brq %i", (d&2)>>1);\r
- if ((PicoMCD&2) && (d&3)==1) {\r
+ if ((Pico_mcd->m.state_flags&1) && (d&3)==1) {\r
SekResetS68k(); // S68k comes out of RESET or BRQ state\r
- PicoMCD&=~2;\r
+ Pico_mcd->m.state_flags&=~1;\r
dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft);\r
}\r
Pico_mcd->m.busreq = d;\r
dprintf("s68k irq mask: %02x", d);\r
if ((d&(1<<4)) && (Pico_mcd->s68k_regs[0x37]&4) && !(Pico_mcd->s68k_regs[0x33]&(1<<4))) {\r
CDD_Export_Status();\r
- // counter75hz = 0; // ???\r
}\r
break;\r
case 0x34: // fader\r
Pico_mcd->s68k_regs[0x37] = d&7;\r
if ((d&4) && !(d_old&4)) {\r
CDD_Export_Status();\r
- // counter75hz = 0; // ???\r
}\r
return;\r
}\r
--- /dev/null
+
+
+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
+};
+
+
#include "../sound/sound.h"
-static int counter75hz = 0; // TODO: move 2 context
+extern unsigned char formatted_bram[8*0x10];
int PicoInitMCD(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;
}
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();
}
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;
#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;
#ifdef EMU_C68K
// CycloneInit();
memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k));
- PicoCpuS68k.IrqCallback=SekIntAck;
+ PicoCpuS68k.IrqCallback=SekIntAckS68k;
PicoCpuS68k.ResetCallback=SekResetAck;
PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode;
#endif
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;
-/*
-#include <stdio.h>
-#include <string.h>
-#if defined(__WIN__)
-#include <windows.h>
-#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 <sys/stat.h>
#include "cd_file.h"
//#define cdprintf(x...)
#define DEBUG_CD
+// TODO: check refs, move 2 context
struct _file_track Tracks[100];
char Track_Played;
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" */
};
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;
*/\r
\r
static int CD_Present = 0;\r
-int CD_Timer_Counter = 0; // TODO: check refs\r
-\r
-static int CDD_Complete;\r
-\r
-static int File_Add_Delay = 0;\r
+// int CD_Timer_Counter = 0; // TODO: check refs\r
\r
\r
\r
Pico_mcd->cdd.Frame = 0; \\r
Pico_mcd->cdd.Ext = 0; \\r
\\r
- CDD_Complete = 1; \\r
+ Pico_mcd->scd.CDD_Complete = 1; \\r
\\r
return 2; \\r
}\r
Pico_mcd->cdd.Frame = 0; \\r
Pico_mcd->cdd.Ext = 0; \\r
\\r
- CDD_Complete = 1; \\r
+ Pico_mcd->scd.CDD_Complete = 1; \\r
\\r
return 3; \\r
}\r
\r
// Check CDD\r
\r
- if (CDD_Complete)\r
+ if (Pico_mcd->scd.CDD_Complete)\r
{\r
- CDD_Complete = 0;\r
+ Pico_mcd->scd.CDD_Complete = 0;\r
\r
CDD_Export_Status();\r
}\r
Pico_mcd->s68k_regs[0x36] |= 0x01;\r
else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
\r
- if (File_Add_Delay == 0)\r
+ if (Pico_mcd->scd.File_Add_Delay == 0)\r
{\r
FILE_Read_One_LBA_CDC();\r
}\r
- else File_Add_Delay--;\r
+ else Pico_mcd->scd.File_Add_Delay--;\r
}\r
\r
if (Pico_mcd->scd.Status_CDD == FAST_FOW)\r
Pico_mcd->scd.Cur_Track = 0;\r
Pico_mcd->scd.Cur_LBA = -150;\r
Pico_mcd->scd.Status_CDD = READY;\r
- CDD_Complete = 0;\r
+ Pico_mcd->scd.CDD_Complete = 0;\r
}\r
\r
\r
else if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0E00)\r
Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF);\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F);\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F);\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
// FIXME: remove\r
//Pico_mcd->cdd.Seconde = 2;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
// FIXME: remove\r
//Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
\r
if (Pico_mcd->scd.TOC.Tracks[track_number - Pico_mcd->scd.TOC.First_Track].Type) Pico_mcd->cdd.Frame |= 0x0800;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
return 0;\r
}\r
\r
Pico_mcd->cdd.Status = 0x0102;\r
// Pico_mcd->cdd.Status = COMM_OK;\r
\r
- if (File_Add_Delay == 0) File_Add_Delay = delay;\r
+ if (Pico_mcd->scd.File_Add_Delay == 0) Pico_mcd->scd.File_Add_Delay = delay;\r
\r
if (Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type)\r
{\r
\r
Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
return 0;\r
}\r
\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
\r
Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
return 0;\r
}\r
\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Ext = 0;\r
}\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = 0;\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
Pico_mcd->cdd.Frame = INT_TO_BCDW(1);\r
Pico_mcd->cdd.Ext = 0;\r
\r
- CDD_Complete = 1;\r
+ Pico_mcd->scd.CDD_Complete = 1;\r
\r
return 0;\r
}\r
_scd_toc TOC;\r
int Cur_LBA;\r
unsigned int Cur_Track;\r
+ int File_Add_Delay;\r
+ char CDD_Complete;\r
} _scd;\r
\r
\r
-extern int CD_Timer_Counter;\r
-\r
-\r
void LBA_to_MSF(int lba, _msf *MSF);\r
int Track_to_LBA(int track);\r
\r
// TODO...
+// #include <string.h>
#include "../PicoInt.h"
#define rot_comp Pico_mcd->rot_comp
}
+void gfx_cd_reset(void)
+{
+ memset(&rot_comp.Reg_58, 0, 0/*sizeof(Pico_mcd->rot_comp)*/);
+}
+
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
\r
int crashed_940 = 0;\r
\r
+static FILE *loaded_mp3 = 0;\r
\r
/***********************************************************/\r
\r
\r
internal_reset();\r
\r
+ loaded_mp3 = 0;\r
+\r
/* now cause 940 to init it's ym2612 stuff */\r
shared_ctl->baseclock = baseclock;\r
shared_ctl->rate = rate;\r
\r
// here we assume that length is different between games, but constant in one game\r
\r
-static FILE *loaded_mp3 = 0;\r
+static int mp3_samples_ready = 0, mp3_buffer_offs = 0;\r
+static int mp3_play_bufsel = 0;\r
\r
void YM2612UpdateOne_940(short *buffer, int length, int stereo)\r
{\r
int cdda_on, *ym_buffer = shared_data->mix_buffer, mp3_job = 0;\r
- static int mp3_samples_ready = 0, mp3_buffer_offs = 0;\r
- static int mp3_play_bufsel = 1;\r
\r
//printf("YM2612UpdateOne_940()\n");\r
if (shared_ctl->busy) wait_busy_940();\r
printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);\r
\r
shared_ctl->mp3_offs = byte_offs;\r
+\r
+ // reset buffer pointers..\r
+ mp3_samples_ready = mp3_buffer_offs = mp3_play_bufsel = 0;\r
+ shared_ctl->mp3_buffsel = 1; // will change to 0 on first decode\r
}\r
\r
\r
../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o\r
# Pico - CD\r
OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \\r
- ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o\r
+ ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \\r
+ ../../Pico/cd/Area.o ../../Pico/cd/Misc.o\r
# asm stuff\r
ifeq "$(asm_render)" "1"\r
DEFINC += -D_ASM_DRAW_C\r
void spend_cycles(int c);\r
void cache_clean(void);\r
void cache_clean_flush(void);\r
+// this should help to resolve race confition where shared var\r
+// is changed by other core just before we update it\r
+void set_if_not_changed(int *val, int oldval, int newval);\r
\r
// asm volatile ("mov r0, #0" ::: "r0");\r
// asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */\r
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */\r
\r
+\r
+static void mp3_decode(void)\r
+{\r
+ int mp3_offs = shared_ctl->mp3_offs;\r
+ unsigned char *readPtr = mp3_data + mp3_offs;\r
+ int bytesLeft = shared_ctl->mp3_len - mp3_offs;\r
+ int offset; // frame offset from readPtr\r
+ int err;\r
+\r
+ if (bytesLeft <= 0) return; // EOF, nothing to do\r
+\r
+ offset = MP3FindSyncWord(readPtr, bytesLeft);\r
+ if (offset < 0) {\r
+ set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);\r
+ return; // EOF\r
+ }\r
+ readPtr += offset;\r
+ bytesLeft -= offset;\r
+\r
+ err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,\r
+ shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);\r
+ if (err) {\r
+ if (err == ERR_MP3_INDATA_UNDERFLOW) {\r
+ shared_ctl->mp3_offs = shared_ctl->mp3_len; // EOF\r
+ set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);\r
+ return;\r
+ } else if (err <= -6 && err >= -12) {\r
+ // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*\r
+ // just try to skip the offending frame..\r
+ readPtr++;\r
+ }\r
+ shared_ctl->mp3_errors++;\r
+ shared_ctl->mp3_lasterr = err;\r
+ }\r
+ set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data);\r
+}\r
+\r
+\r
void Main940(int startvector)\r
{\r
ym2612_940 = &shared_data->ym2612;\r
break;\r
}\r
\r
- case JOB940_MP3DECODE: {\r
- int mp3_offs = shared_ctl->mp3_offs;\r
- unsigned char *readPtr = mp3_data + mp3_offs;\r
- int bytesLeft = shared_ctl->mp3_len - mp3_offs;\r
- int offset; // frame offset from readPtr\r
- int err;\r
-\r
- if (bytesLeft <= 0) break; // EOF, nothing to do\r
-\r
- offset = MP3FindSyncWord(readPtr, bytesLeft);\r
- if (offset < 0) {\r
- shared_ctl->mp3_offs = shared_ctl->mp3_len;\r
- break; // EOF\r
- }\r
- readPtr += offset;\r
- bytesLeft -= offset;\r
-\r
- err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,\r
- shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);\r
- if (err) {\r
- if (err == ERR_MP3_INDATA_UNDERFLOW) {\r
- shared_ctl->mp3_offs = shared_ctl->mp3_len; // EOF\r
- break;\r
- } else if (err <= -6 && err >= -12) {\r
- // ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*\r
- // just try to skip the offending frame..\r
- readPtr++;\r
- }\r
- shared_ctl->mp3_errors++;\r
- shared_ctl->mp3_lasterr = err;\r
- }\r
- shared_ctl->mp3_offs = readPtr - mp3_data;\r
+ case JOB940_MP3DECODE:\r
+ mp3_decode();\r
break;\r
- }\r
}\r
}\r
\r
\r
.pool\r
\r
+\r
+.global set_if_not_changed @ int *val, int oldval, int newval\r
+\r
+set_if_not_changed:\r
+ swp r3, r2, [r0]\r
+ cmp r1, r3\r
+ bxeq lr\r
+ strne r3, [r0] @ restore value which was changed there by other core\r
+ bx lr\r
+\r
@ vim:filetype=armasm:\r
@make -C ../helix/\r
\r
\r
+up:\r
+ @cp -v code940.bin /mnt/gp2x/mnt/sd/games/PicoDrive/\r
+\r
+\r
# cleanup\r
clean: tidy\r
@$(RM) code940.bin\r
currentConfig.PicoOpt = 0x0f | 0x200; // | use_940\r
currentConfig.PsndRate = 44100;\r
currentConfig.PicoRegion = 0; // auto\r
+ currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
currentConfig.Frameskip = -1; // auto\r
currentConfig.CPUclock = 200;\r
currentConfig.volume = 50;\r
PicoOpt = currentConfig.PicoOpt;\r
PsndRate = currentConfig.PsndRate;\r
PicoRegionOverride = currentConfig.PicoRegion;\r
+ PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;\r
if (PicoOpt & 0x20) {\r
actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
actionNames[10] = "X"; actionNames[11] = "MODE";\r
currentConfig.PicoOpt = PicoOpt;\r
currentConfig.PsndRate = PsndRate;\r
currentConfig.PicoRegion = PicoRegionOverride;\r
+ currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder;\r
bwrite = fwrite(¤tConfig, 1, sizeof(currentConfig), f);\r
fflush(f);\r
fclose(f);\r
\r
// save SRAM\r
if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
+ blit("", "Writing SRAM/BRAM..");\r
emu_SaveLoadGame(0, 1);\r
SRam.changed = 0;\r
}\r
if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {\r
areaRead = gzRead2;\r
areaWrite = gzWrite2;\r
+ areaEof = (areaeof *) gzeof;\r
if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);\r
} else\r
saveFname[strlen(saveFname)-3] = 0;\r
}\r
if(!PmovFile) { // gzip failed or was disabled\r
if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {\r
- areaRead = (STATE_SL_FUNC) fread;\r
- areaWrite = (STATE_SL_FUNC) fwrite;\r
+ areaRead = (arearw *) fread;\r
+ areaWrite = (arearw *) fwrite;\r
+ areaEof = (areaeof *) feof;\r
}\r
}\r
if(PmovFile) {\r
int volume;\r
int gamma;\r
int JoyBinds[4][32];\r
+ int PicoAutoRgnOrder;\r
} currentConfig_t;\r
\r
extern char romFileName[];\r
\r
\r
\r
-// order must match that of currentConfig_t\r
-\r
-struct {\r
- int EmuOpt;\r
- int PicoOpt;\r
- int PsndRate;\r
- int PicoRegion;\r
- int Frameskip;\r
- int CPUclock;\r
-} tmp_opts;\r
-int tmp_gamma;\r
-\r
// --------- sega/mega cd options ----------\r
\r
static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp)\r
gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0\r
gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1\r
gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2\r
- gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (tmp_opts.EmuOpt &0x400)?"ON":"OFF"); // 3\r
- gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (tmp_opts.EmuOpt &0x800)?"ON":"OFF"); // 4\r
+ gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x400)?"ON":"OFF"); // 3\r
+ gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.EmuOpt &0x800)?"ON":"OFF"); // 4\r
gp2x_text_out8(tl_x, (y+=10), "Done");\r
\r
// draw cursor\r
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
switch (menu_sel) {\r
- case 3: tmp_opts.EmuOpt ^=0x400; break;\r
- case 4: tmp_opts.EmuOpt ^=0x800; break;\r
+ case 3: currentConfig.EmuOpt ^=0x400; break;\r
+ case 4: currentConfig.EmuOpt ^=0x800; break;\r
case 5: return;\r
}\r
}\r
\r
y = tl_y;\r
memset(gp2x_screen, 0, 320*240);\r
- gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (tmp_opts.PicoOpt&0x100)?"ON":"OFF"); // 0\r
- gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", tmp_gamma / 100, tmp_gamma%100); // 1\r
- gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (tmp_opts.PicoOpt&0x004)?"ON":"OFF"); // 2\r
- gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (tmp_opts.PicoOpt&0x001)?"ON":"OFF"); // 3\r
- gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (tmp_opts.PicoOpt&0x002)?"ON":"OFF"); // 4\r
- gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (tmp_opts.EmuOpt &0x008)?"ON":"OFF"); // 5\r
- gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (tmp_opts.EmuOpt &0x020)?"ON":"OFF"); // 6\r
+ gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (currentConfig.PicoOpt&0x100)?"ON":"OFF"); // 0\r
+ gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 1\r
+ gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (currentConfig.PicoOpt&0x004)?"ON":"OFF"); // 2\r
+ gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 3\r
+ gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 4\r
+ gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 5\r
+ gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 6\r
gp2x_text_out8(tl_x, (y+=10), "needs restart:");\r
- gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (tmp_opts.EmuOpt &0x100)?"ON":"OFF"); // 8\r
- gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (tmp_opts.EmuOpt &0x010)?"ON":"OFF"); // 9\r
+ gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 8\r
+ gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9\r
gp2x_text_out8(tl_x, (y+=10), "Done");\r
\r
// draw cursor\r
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
switch (menu_sel) {\r
- case 0: tmp_opts.PicoOpt^=0x100; break;\r
- case 2: tmp_opts.PicoOpt^=0x004; break;\r
- case 3: tmp_opts.PicoOpt^=0x001; break;\r
- case 4: tmp_opts.PicoOpt^=0x002; break;\r
- case 5: tmp_opts.EmuOpt ^=0x008; break;\r
- case 6: tmp_opts.EmuOpt ^=0x020; break;\r
- case 8: tmp_opts.EmuOpt ^=0x100; break;\r
- case 9: tmp_opts.EmuOpt ^=0x010; break;\r
+ case 0: currentConfig.PicoOpt^=0x100; break;\r
+ case 2: currentConfig.PicoOpt^=0x004; break;\r
+ case 3: currentConfig.PicoOpt^=0x001; break;\r
+ case 4: currentConfig.PicoOpt^=0x002; break;\r
+ case 5: currentConfig.EmuOpt ^=0x008; break;\r
+ case 6: currentConfig.EmuOpt ^=0x020; break;\r
+ case 8: currentConfig.EmuOpt ^=0x100; break;\r
+ case 9: currentConfig.EmuOpt ^=0x010; break;\r
case 10: return;\r
}\r
}\r
switch (menu_sel) {\r
case 1:\r
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
- tmp_gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
- if (tmp_gamma < 1) tmp_gamma = 1;\r
- if (tmp_gamma > 300) tmp_gamma = 300;\r
+ currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
+ if (currentConfig.gamma < 1) currentConfig.gamma = 1;\r
+ if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
draw_amenu_options(menu_sel);\r
usleep(18*1000);\r
}\r
\r
// -------------- options --------------\r
\r
-static char *region_name(unsigned int code)\r
+static const char *region_name(unsigned int code)\r
{\r
- char *names[] = { "Auto", "Japan NTSC", "Japan PAL", "USA", "Europe" };\r
- int i = 0;\r
- code <<= 1;\r
- while((code >>=1)) i++;\r
- if (i > 4) return "unknown";\r
- return names[i];\r
+ static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r
+ static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
+ int u, i = 0;\r
+ if (code) {\r
+ code <<= 1;\r
+ while((code >>= 1)) i++;\r
+ if (i > 4) return "unknown";\r
+ return names[i];\r
+ } else {\r
+ static char name[24];\r
+ strcpy(name, "Auto:");\r
+ for (u = 0; u < 3; u++) {\r
+ i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;\r
+ while((code >>= 1)) i++;\r
+ strcat(name, names_short[i]);\r
+ }\r
+ return name;\r
+ }\r
}\r
\r
static void draw_menu_options(int menu_sel)\r
int tl_x = 25, tl_y = 40, y;\r
char monostereo[8], strframeskip[8], *strrend;\r
\r
- strcpy(monostereo, (tmp_opts.PicoOpt&0x08)?"stereo":"mono");\r
- if (tmp_opts.Frameskip < 0)\r
+ strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");\r
+ if (currentConfig.Frameskip < 0)\r
strcpy(strframeskip, "Auto");\r
- else sprintf(strframeskip, "%i", tmp_opts.Frameskip);\r
- if (tmp_opts.PicoOpt&0x10) {\r
+ else sprintf(strframeskip, "%i", currentConfig.Frameskip);\r
+ if (currentConfig.PicoOpt&0x10) {\r
strrend = " 8bit fast";\r
- } else if (tmp_opts.EmuOpt&0x80) {\r
+ } else if (currentConfig.EmuOpt&0x80) {\r
strrend = "16bit accurate";\r
} else {\r
strrend = " 8bit accurate";\r
y = tl_y;\r
memset(gp2x_screen, 0, 320*240);\r
gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0\r
- gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (tmp_opts.PicoOpt&0x040)?"ON":"OFF"); // 1\r
- gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (tmp_opts.PicoOpt&0x080)?"ON":"OFF"); // 2\r
- gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (tmp_opts.EmuOpt &0x002)?"ON":"OFF"); // 3\r
+ gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 1\r
+ gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 2\r
+ gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 3\r
gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);\r
- gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (tmp_opts.EmuOpt &0x004)?"ON":"OFF"); // 5\r
- gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", tmp_opts.PsndRate, monostereo);\r
- gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (tmp_opts.PicoOpt&0x200)?"ON":"OFF"); // 7\r
- gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (tmp_opts.PicoOpt&0x020)?"ON":"OFF"); // 8\r
- gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(tmp_opts.PicoRegion));\r
- gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10\r
- gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (tmp_opts.EmuOpt &0x200)?"ON":"OFF"); // 11\r
+ gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 5\r
+ gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", currentConfig.PsndRate, monostereo);\r
+ gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 7\r
+ gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 8\r
+ gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(currentConfig.PicoRegion));\r
+ gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 10\r
+ gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (currentConfig.EmuOpt &0x200)?"ON":"OFF"); // 11\r
gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12\r
- gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", tmp_opts.CPUclock);\r
+ gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", currentConfig.CPUclock);\r
gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");\r
gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15\r
gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");\r
return rates[i];\r
}\r
\r
+static void region_prevnext(int right)\r
+{\r
+ // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r
+ static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r
+ int i;\r
+ if (right) {\r
+ if (!currentConfig.PicoRegion) {\r
+ for (i = 0; i < 6; i++)\r
+ if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
+ if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r
+ else currentConfig.PicoRegion=1;\r
+ }\r
+ else currentConfig.PicoRegion<<=1;\r
+ if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;\r
+ } else {\r
+ if (!currentConfig.PicoRegion) {\r
+ for (i = 0; i < 6; i++)\r
+ if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
+ if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r
+ }\r
+ else currentConfig.PicoRegion>>=1;\r
+ }\r
+}\r
+\r
static void menu_options_save(void)\r
{\r
- memcpy(¤tConfig.EmuOpt, &tmp_opts.EmuOpt, sizeof(tmp_opts));\r
- currentConfig.gamma = tmp_gamma;\r
PicoOpt = currentConfig.PicoOpt;\r
PsndRate = currentConfig.PsndRate;\r
PicoRegionOverride = currentConfig.PicoRegion;\r
unsigned long inp = 0;\r
\r
if (rom_data) menu_sel_max++;\r
- memcpy(&tmp_opts.EmuOpt, ¤tConfig.EmuOpt, sizeof(tmp_opts));\r
- tmp_gamma = currentConfig.gamma;\r
- tmp_opts.PicoOpt = PicoOpt;\r
- tmp_opts.PsndRate = PsndRate;\r
- tmp_opts.PicoRegion = PicoRegionOverride;\r
+ currentConfig.PicoOpt = PicoOpt;\r
+ currentConfig.PsndRate = PsndRate;\r
+ currentConfig.PicoRegion = PicoRegionOverride;\r
\r
for(;;)\r
{\r
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
switch (menu_sel) {\r
- case 1: tmp_opts.PicoOpt^=0x040; break;\r
- case 2: tmp_opts.PicoOpt^=0x080; break;\r
- case 3: tmp_opts.EmuOpt ^=0x002; break;\r
- case 5: tmp_opts.EmuOpt ^=0x004; break;\r
- case 7: tmp_opts.PicoOpt^=0x200; break;\r
- case 8: tmp_opts.PicoOpt^=0x020; break;\r
- case 10: tmp_opts.EmuOpt ^=0x001; break;\r
- case 11: tmp_opts.EmuOpt ^=0x200; break;\r
+ case 1: currentConfig.PicoOpt^=0x040; break;\r
+ case 2: currentConfig.PicoOpt^=0x080; break;\r
+ case 3: currentConfig.EmuOpt ^=0x002; break;\r
+ case 5: currentConfig.EmuOpt ^=0x004; break;\r
+ case 7: currentConfig.PicoOpt^=0x200; break;\r
+ case 8: currentConfig.PicoOpt^=0x020; break;\r
+ case 10: currentConfig.EmuOpt ^=0x001; break;\r
+ case 11: currentConfig.EmuOpt ^=0x200; break;\r
case 14: cd_menu_loop_options();\r
if (engineState == PGS_ReloadRom)\r
return 0; // test BIOS\r
return 1;\r
}\r
}\r
- if(inp & GP2X_X) return 0; // done (no update or write)\r
- if(inp & GP2X_A) {\r
+ if(inp & (GP2X_X|GP2X_A)) {\r
menu_options_save();\r
return 0; // done (update, no write)\r
}\r
switch (menu_sel) {\r
case 0:\r
if (inp & GP2X_LEFT) {\r
- if ( tmp_opts.PicoOpt&0x10) tmp_opts.PicoOpt&= ~0x10;\r
- else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.EmuOpt |= 0x80;\r
- else if ( tmp_opts.EmuOpt &0x80) break;\r
+ if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r
+ else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;\r
+ else if ( currentConfig.EmuOpt &0x80) break;\r
} else {\r
- if ( tmp_opts.PicoOpt&0x10) break;\r
- else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.PicoOpt|= 0x10;\r
- else if ( tmp_opts.EmuOpt &0x80) tmp_opts.EmuOpt &= ~0x80;\r
+ if ( currentConfig.PicoOpt&0x10) break;\r
+ else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;\r
+ else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
}\r
break;\r
case 4:\r
- tmp_opts.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;\r
- if (tmp_opts.Frameskip < 0) tmp_opts.Frameskip = -1;\r
- if (tmp_opts.Frameskip > 32) tmp_opts.Frameskip = 32;\r
+ currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;\r
+ if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1;\r
+ if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;\r
break;\r
case 6:\r
- if ((inp & GP2X_RIGHT) && tmp_opts.PsndRate == 44100 && !(tmp_opts.PicoOpt&0x08)) {\r
- tmp_opts.PsndRate = 8000; tmp_opts.PicoOpt|= 0x08;\r
- } else if ((inp & GP2X_LEFT) && tmp_opts.PsndRate == 8000 && (tmp_opts.PicoOpt&0x08)) {\r
- tmp_opts.PsndRate = 44100; tmp_opts.PicoOpt&=~0x08;\r
- } else tmp_opts.PsndRate = sndrate_prevnext(tmp_opts.PsndRate, inp & GP2X_RIGHT);\r
+ if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r
+ currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;\r
+ } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r
+ currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r
+ } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);\r
break;\r
case 9:\r
- if (inp & GP2X_RIGHT) {\r
- if (tmp_opts.PicoRegion) tmp_opts.PicoRegion<<=1; else tmp_opts.PicoRegion=1;\r
- if (tmp_opts.PicoRegion > 8) tmp_opts.PicoRegion = 8;\r
- } else tmp_opts.PicoRegion>>=1;\r
+ region_prevnext(inp & GP2X_RIGHT);\r
break;\r
case 12:\r
if (inp & GP2X_RIGHT) {\r
break;\r
case 13:\r
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
- tmp_opts.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
- if (tmp_opts.CPUclock < 1) tmp_opts.CPUclock = 1;\r
+ currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
+ if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r
draw_menu_options(menu_sel);\r
usleep(50*1000);\r
}\r
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;
../../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