region detection, cd states wip, fixes, stuff

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@25 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-01-28 22:51:16 +00:00
parent cb0316e4c5
commit 51a902ae25
26 changed files with 520 additions and 291 deletions

View file

@ -24,6 +24,7 @@ struct PicoArea { void *data; int len; char *name; };
arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for arearw *areaRead = (arearw *) 0; // fread; // read and write function pointers for
arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability arearw *areaWrite = (arearw *) 0; // fwrite; // gzip save state ability
areaeof *areaEof = (areaeof *) 0;
// Scan one variable and callback // 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); #define SCANP(x) ScanVar(&Pico.x,sizeof(Pico.x),#x,PmovFile,PmovAction);
// Pack the cpu into a common format: // 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; unsigned int pc=0;
@ -52,29 +53,27 @@ static int PackCpu(unsigned char *cpu)
#endif #endif
#ifdef EMU_C68K #ifdef EMU_C68K
memcpy(cpu,PicoCpu.d,0x40); struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu;
pc=PicoCpu.pc-PicoCpu.membase; memcpy(cpu,context->d,0x40);
*(unsigned int *)(cpu+0x44)=CycloneGetSr(&PicoCpu); pc=context->pc-context->membase;
*(unsigned int *)(cpu+0x48)=PicoCpu.osp; *(unsigned int *)(cpu+0x44)=CycloneGetSr(context);
*(unsigned int *)(cpu+0x48)=context->osp;
#endif #endif
#ifdef EMU_M68K #ifdef EMU_M68K
memcpy(cpu,m68ki_cpu.dar,0x40); m68ki_cpu_core *context = is_sub ? &PicoS68kCPU : &PicoM68kCPU;
pc=m68ki_cpu.pc; memcpy(cpu,context->dar,0x40);
pc=context->pc;
*(unsigned int *)(cpu+0x44)=m68k_get_reg(NULL, M68K_REG_SR); *(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 #endif
*(unsigned int *)(cpu+0x40)=pc; *(unsigned int *)(cpu+0x40)=pc;
return 0; 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 #ifdef EMU_A68K
memcpy(M68000_regs.d,cpu,0x40); memcpy(M68000_regs.d,cpu,0x40);
M68000_regs.pc=pc; M68000_regs.pc=pc;
@ -84,18 +83,20 @@ static int UnpackCpu(unsigned char *cpu)
#endif #endif
#ifdef EMU_C68K #ifdef EMU_C68K
CycloneSetSr(&PicoCpu, *(unsigned int *)(cpu+0x44)); struct Cyclone *context = is_sub ? &PicoCpuS68k : &PicoCpu;
PicoCpu.osp=*(unsigned int *)(cpu+0x48); CycloneSetSr(context, *(unsigned int *)(cpu+0x44));
memcpy(PicoCpu.d,cpu,0x40); context->osp=*(unsigned int *)(cpu+0x48);
PicoCpu.membase=0; memcpy(context->d,cpu,0x40);
PicoCpu.pc =PicoCpu.checkpc(pc); // Base pc context->membase=0;
context->pc = context->checkpc(*(unsigned int *)(cpu+0x40)); // Base pc
#endif #endif
#ifdef EMU_M68K #ifdef EMU_M68K
memcpy(m68ki_cpu.dar,cpu,0x40); m68ki_cpu_core *context = is_sub ? &PicoS68kCPU : &PicoM68kCPU;
m68ki_cpu.pc=pc; memcpy(context->dar,cpu,0x40);
context->pc=*(unsigned int *)(cpu+0x40);
m68k_set_reg(M68K_REG_SR, *(unsigned int *)(cpu+0x44)); 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 #endif
return 0; return 0;
} }
@ -121,22 +122,15 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile)
SCANP(ram) SCANP(vram) SCANP(zram) SCANP(cram) SCANP(vsram) SCANP(ram) SCANP(vram) SCANP(zram) SCANP(cram) SCANP(vsram)
// Pack, scan and unpack the cpu data: // 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? //SekInit(); // notaz: do we really have to do this here?
//PicoMemInit(); //PicoMemInit();
SCAN_VAR(cpu,"cpu") 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.m ,"misc")
SCAN_VAR(Pico.video,"video") 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) // notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway)
if(PicoOpt&7) { if(PicoOpt&7) {
if((PmovAction&3)==1) z80_pack(cpu_z80); if((PmovAction&3)==1) z80_pack(cpu_z80);
@ -167,6 +161,12 @@ int PmovState(int PmovAction, void *PmovFile)
int minimum=0; int minimum=0;
unsigned char head[32]; unsigned char head[32];
// testing
{
if (PmovAction&1) return PicoCdSaveState(PmovFile);
if (PmovAction&2) return PicoCdLoadState(PmovFile);
}
memset(head,0,sizeof(head)); memset(head,0,sizeof(head));
// Find out minimal compatible version: // Find out minimal compatible version:

View file

@ -16,6 +16,7 @@ struct Pico Pico;
int PicoOpt=0; // disable everything by default int PicoOpt=0; // disable everything by default
int PicoSkipFrame=0; // skip rendering frame? 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 PicoRegionOverride = 0; // override the region detection 0: Auto, 1: Japan NTSC, 2: Japan PAL, 4: US, 8: Europe
int PicoAutoRgnOrder = 0;
int emustatus = 0; int emustatus = 0;
void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to send sound buffer (PsndOut) to hardware
@ -109,6 +110,9 @@ int PicoReset(int hard)
if (c=='J') support|=1; if (c=='J') support|=1;
else if (c=='U') support|=4; else if (c=='U') support|=4;
else if (c=='E') support|=8; 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 else
{ {
// New style code: // 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: // Try to pick the best hardware value for English/50hz:
if (support&8) { hw=0xc0; pal=1; } // Europe if (support&8) { hw=0xc0; pal=1; } // Europe
else if (support&4) hw=0x80; // USA else if (support&4) hw=0x80; // USA

View file

@ -33,6 +33,7 @@ extern int PicoOpt;
extern int PicoVer; extern int PicoVer;
extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff 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 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); int PicoInit(void);
void PicoExit(void); void PicoExit(void);
int PicoReset(int hard); int PicoReset(int hard);
@ -45,10 +46,12 @@ int PicoFrameMCD(void);
// Area.c // Area.c
typedef size_t (arearw)(void *p, size_t _size, size_t _n, void *file); 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: // Save or load the state from PmovFile:
int PmovState(int PmovAction, void *PmovFile); // &1=for reading &2=for writing &4=volatile &8=non-volatile 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 *areaRead; // external read and write function pointers for
extern arearw *areaWrite; // gzip save state ability extern arearw *areaWrite; // gzip save state ability
extern areaeof *areaEof;
// Cart.c // Cart.c
int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize); int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize);

View file

@ -168,7 +168,9 @@ struct mcd_misc
{ {
unsigned short hint_vector; unsigned short hint_vector;
unsigned char busreq; 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) #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 // Draw.c
int PicoLine(int scan); int PicoLine(int scan);

151
Pico/cd/Area.c Normal file
View file

@ -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;
}

View file

@ -15,8 +15,6 @@
#define CDC_DMA_SPEED 256 #define CDC_DMA_SPEED 256
int CDC_Decode_Reg_Read; // 2 context?
static void CDD_Reset(void) static void CDD_Reset(void)
{ {
@ -55,7 +53,7 @@ static void CDC_Reset(void)
Pico_mcd->cdc.IFCTRL = 0; Pico_mcd->cdc.IFCTRL = 0;
Pico_mcd->cdc.CTRL.N = 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; Pico_mcd->scd.Status_CDC &= ~0x08;
} }
@ -259,7 +257,7 @@ unsigned char CDC_Read_Reg(void)
case 0x1: // IFSTAT case 0x1: // IFSTAT
cdprintf("CDC read reg 01 = %.2X", Pico_mcd->cdc.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; Pico_mcd->s68k_regs[5] = 0x2;
return Pico_mcd->cdc.IFSTAT; return Pico_mcd->cdc.IFSTAT;
@ -278,42 +276,42 @@ unsigned char CDC_Read_Reg(void)
case 0x4: // HEAD0 case 0x4: // HEAD0
cdprintf("CDC read reg 04 = %.2X", Pico_mcd->cdc.HEAD.B.B0); 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; Pico_mcd->s68k_regs[5] = 0x5;
return Pico_mcd->cdc.HEAD.B.B0; return Pico_mcd->cdc.HEAD.B.B0;
case 0x5: // HEAD1 case 0x5: // HEAD1
cdprintf("CDC read reg 05 = %.2X", Pico_mcd->cdc.HEAD.B.B1); 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; Pico_mcd->s68k_regs[5] = 0x6;
return Pico_mcd->cdc.HEAD.B.B1; return Pico_mcd->cdc.HEAD.B.B1;
case 0x6: // HEAD2 case 0x6: // HEAD2
cdprintf("CDC read reg 06 = %.2X", Pico_mcd->cdc.HEAD.B.B2); 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; Pico_mcd->s68k_regs[5] = 0x7;
return Pico_mcd->cdc.HEAD.B.B2; return Pico_mcd->cdc.HEAD.B.B2;
case 0x7: // HEAD3 case 0x7: // HEAD3
cdprintf("CDC read reg 07 = %.2X", Pico_mcd->cdc.HEAD.B.B3); 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; Pico_mcd->s68k_regs[5] = 0x8;
return Pico_mcd->cdc.HEAD.B.B3; return Pico_mcd->cdc.HEAD.B.B3;
case 0x8: // PTL case 0x8: // PTL
cdprintf("CDC read reg 08 = %.2X", Pico_mcd->cdc.PT.B.L); 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; Pico_mcd->s68k_regs[5] = 0x9;
return Pico_mcd->cdc.PT.B.L; return Pico_mcd->cdc.PT.B.L;
case 0x9: // PTH case 0x9: // PTH
cdprintf("CDC read reg 09 = %.2X", Pico_mcd->cdc.PT.B.H); 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; Pico_mcd->s68k_regs[5] = 0xA;
return Pico_mcd->cdc.PT.B.H; return Pico_mcd->cdc.PT.B.H;
@ -332,21 +330,21 @@ unsigned char CDC_Read_Reg(void)
case 0xC: // STAT0 case 0xC: // STAT0
cdprintf("CDC read reg 12 = %.2X", Pico_mcd->cdc.STAT.B.B0); 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; Pico_mcd->s68k_regs[5] = 0xD;
return Pico_mcd->cdc.STAT.B.B0; return Pico_mcd->cdc.STAT.B.B0;
case 0xD: // STAT1 case 0xD: // STAT1
cdprintf("CDC read reg 13 = %.2X", Pico_mcd->cdc.STAT.B.B1); 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; Pico_mcd->s68k_regs[5] = 0xE;
return Pico_mcd->cdc.STAT.B.B1; return Pico_mcd->cdc.STAT.B.B1;
case 0xE: // STAT2 case 0xE: // STAT2
cdprintf("CDC read reg 14 = %.2X", Pico_mcd->cdc.STAT.B.B2); 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; Pico_mcd->s68k_regs[5] = 0xF;
return Pico_mcd->cdc.STAT.B.B2; 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 Pico_mcd->cdc.IFSTAT |= 0x20; // decoding interrupt flag cleared
if ((Pico_mcd->cdc.CTRL.B.B0 & 0x80) && (Pico_mcd->cdc.IFCTRL & 0x20)) 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; Pico_mcd->cdc.STAT.B.B3 = 0x80;
} }
return ret; return ret;

View file

@ -88,6 +88,7 @@ typedef struct
} B; } B;
unsigned int N; unsigned int N;
} CTRL; } CTRL;
unsigned int CDC_Decode_Reg_Read;
} CDC; } CDC;
typedef struct typedef struct
@ -105,9 +106,6 @@ typedef struct
} CDD; } CDD;
extern int CDC_Decode_Reg_Read;
void LC89510_Reset(void); void LC89510_Reset(void);
unsigned short Read_CDC_Host(int is_sub); unsigned short Read_CDC_Host(int is_sub);
void Update_CDC_TRansfer(int which); void Update_CDC_TRansfer(int which);

View file

@ -31,8 +31,6 @@ typedef unsigned int u32;
// extern m68ki_cpu_core m68ki_cpu; // extern m68ki_cpu_core m68ki_cpu;
extern int counter75hz;
static u32 m68k_reg_read16(u32 a) static u32 m68k_reg_read16(u32 a)
{ {
@ -91,12 +89,12 @@ static void m68k_reg_write8(u32 a, u32 d)
return; return;
case 1: case 1:
d &= 3; 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&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 ( (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 SekResetS68k(); // S68k comes out of RESET or BRQ state
PicoMCD&=~2; Pico_mcd->m.state_flags&=~1;
dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft); dprintf("m68k: resetting s68k, cycles=%i", SekCyclesLeft);
} }
Pico_mcd->m.busreq = d; Pico_mcd->m.busreq = d;
@ -225,7 +223,6 @@ static void s68k_reg_write8(u32 a, u32 d)
dprintf("s68k irq mask: %02x", d); dprintf("s68k irq mask: %02x", d);
if ((d&(1<<4)) && (Pico_mcd->s68k_regs[0x37]&4) && !(Pico_mcd->s68k_regs[0x33]&(1<<4))) { if ((d&(1<<4)) && (Pico_mcd->s68k_regs[0x37]&4) && !(Pico_mcd->s68k_regs[0x33]&(1<<4))) {
CDD_Export_Status(); CDD_Export_Status();
// counter75hz = 0; // ???
} }
break; break;
case 0x34: // fader case 0x34: // fader
@ -238,7 +235,6 @@ static void s68k_reg_write8(u32 a, u32 d)
Pico_mcd->s68k_regs[0x37] = d&7; Pico_mcd->s68k_regs[0x37] = d&7;
if ((d&4) && !(d_old&4)) { if ((d&4) && !(d_old&4)) {
CDD_Export_Status(); CDD_Export_Status();
// counter75hz = 0; // ???
} }
return; return;
} }

16
Pico/cd/Misc.c Normal file
View file

@ -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
};

View file

@ -11,7 +11,7 @@
#include "../sound/sound.h" #include "../sound/sound.h"
static int counter75hz = 0; // TODO: move 2 context extern unsigned char formatted_bram[8*0x10];
int PicoInitMCD(void) int PicoInitMCD(void)
@ -30,15 +30,22 @@ void PicoExitMCD(void)
int PicoResetMCD(int hard) int PicoResetMCD(int hard)
{ {
// clear everything except BIOS memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram));
memset(Pico_mcd->prg_ram, 0, sizeof(mcd_state) - sizeof(Pico_mcd->bios)); 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) *(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 Pico_mcd->s68k_regs[3] = 1; // 2M word RAM mode with m68k access after reset
counter75hz = 0; Pico_mcd->m.counter75hz = 0;
LC89510_Reset(); LC89510_Reset();
Reset_CD(); Reset_CD();
gfx_cd_reset();
return 0; return 0;
} }
@ -235,8 +242,8 @@ static int PicoFrameHintsMCD(void)
total_z80+=z80_run(z80CycleAim-total_z80); total_z80+=z80_run(z80CycleAim-total_z80);
} }
if ((counter75hz+=10) >= counter75hz_lim) { if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) {
counter75hz -= counter75hz_lim; Pico_mcd->m.counter75hz -= counter75hz_lim;
Check_CD_Command(); Check_CD_Command();
} }

View file

@ -23,20 +23,21 @@ struct Cyclone PicoCpuS68k;
m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU
#endif #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 #ifdef EMU_M68K
static int SekIntAckS68k(int level) static int SekIntAckS68k(int level)
{ {
int level_new = 0; int level_new = new_irq_level(level);
irqs &= ~(1 << level);
irqs &= Pico_mcd->s68k_regs[0x33];
if (irqs) {
level_new = 6;
while (level_new > 0) { if (irqs & (1 << level_new)) break; level_new--; }
}
dprintf("s68kACK %i -> %i", level, level_new); dprintf("s68kACK %i -> %i", level, level_new);
CPU_INT_LEVEL = level_new << 8; CPU_INT_LEVEL = level_new << 8;
return M68K_INT_ACK_AUTOVECTOR; return M68K_INT_ACK_AUTOVECTOR;
@ -45,15 +46,9 @@ static int SekIntAckS68k(int level)
#ifdef EMU_C68K #ifdef EMU_C68K
// interrupt acknowledgment // interrupt acknowledgment
static void SekIntAck(int level) static void SekIntAckS68k(int level)
{ {
int level_new = 0; int level_new = new_irq_level(level);
irqs &= ~(1 << level);
irqs &= Pico_mcd->s68k_regs[0x33];
if (irqs) {
level_new = 6;
while (level_new > 0) { if (irqs & (1 << level_new)) break; level_new--; }
}
dprintf("s68kACK %i -> %i", level, level_new); dprintf("s68kACK %i -> %i", level, level_new);
PicoCpuS68k.irq = level_new; PicoCpuS68k.irq = level_new;
@ -82,7 +77,7 @@ int SekInitS68k()
#ifdef EMU_C68K #ifdef EMU_C68K
// CycloneInit(); // CycloneInit();
memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k)); memset(&PicoCpuS68k,0,sizeof(PicoCpuS68k));
PicoCpuS68k.IrqCallback=SekIntAck; PicoCpuS68k.IrqCallback=SekIntAckS68k;
PicoCpuS68k.ResetCallback=SekResetAck; PicoCpuS68k.ResetCallback=SekResetAck;
PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode; PicoCpuS68k.UnrecognizedCallback=SekUnrecognizedOpcode;
#endif #endif
@ -132,14 +127,18 @@ int SekResetS68k()
int SekInterruptS68k(int irq) 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 #ifdef EMU_C68K
PicoCpuS68k.irq=irq; PicoCpuS68k.irq=real_irq;
#endif #endif
#ifdef EMU_M68K #ifdef EMU_M68K
void *oldcontext = m68ki_cpu_p; void *oldcontext = m68ki_cpu_p;
m68k_set_context(&PicoS68kCPU); 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); m68k_set_context(oldcontext);
#endif #endif
return 0; return 0;

View file

@ -1,20 +1,3 @@
/*
#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 <sys/stat.h>
#include "cd_file.h" #include "cd_file.h"
@ -24,6 +7,7 @@
//#define cdprintf(x...) //#define cdprintf(x...)
#define DEBUG_CD #define DEBUG_CD
// TODO: check refs, move 2 context
struct _file_track Tracks[100]; struct _file_track Tracks[100];
char Track_Played; char Track_Played;
@ -53,6 +37,7 @@ int Load_ISO(const char *iso_name, int is_bin)
static char *exts[] = { static char *exts[] = {
"%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3", "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3",
"%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.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", /* "%02d.wav", " %02d.wav", "-%02d.wav", "_%02d.wav", " - %02d.wav",
"%d.wav", " %d.wav", "-%d.wav", "_%d.wav", " - %2d.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++) 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++) for(j = 0; j < sizeof(exts)/sizeof(char *); j++)
{ {
int ext_len; int ext_len;

View file

@ -28,11 +28,7 @@ int CD_Audio_Starting;
*/ */
static int CD_Present = 0; static int CD_Present = 0;
int CD_Timer_Counter = 0; // TODO: check refs // int CD_Timer_Counter = 0; // TODO: check refs
static int CDD_Complete;
static int File_Add_Delay = 0;
@ -46,7 +42,7 @@ if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) \
Pico_mcd->cdd.Frame = 0; \ Pico_mcd->cdd.Frame = 0; \
Pico_mcd->cdd.Ext = 0; \ Pico_mcd->cdd.Ext = 0; \
\ \
CDD_Complete = 1; \ Pico_mcd->scd.CDD_Complete = 1; \
\ \
return 2; \ return 2; \
} }
@ -63,7 +59,7 @@ if (!CD_Present) \
Pico_mcd->cdd.Frame = 0; \ Pico_mcd->cdd.Frame = 0; \
Pico_mcd->cdd.Ext = 0; \ Pico_mcd->cdd.Ext = 0; \
\ \
CDD_Complete = 1; \ Pico_mcd->scd.CDD_Complete = 1; \
\ \
return 3; \ return 3; \
} }
@ -158,9 +154,9 @@ void Check_CD_Command(void)
// Check CDD // Check CDD
if (CDD_Complete) if (Pico_mcd->scd.CDD_Complete)
{ {
CDD_Complete = 0; Pico_mcd->scd.CDD_Complete = 0;
CDD_Export_Status(); CDD_Export_Status();
} }
@ -176,11 +172,11 @@ void Check_CD_Command(void)
Pico_mcd->s68k_regs[0x36] |= 0x01; Pico_mcd->s68k_regs[0x36] |= 0x01;
else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO 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(); FILE_Read_One_LBA_CDC();
} }
else File_Add_Delay--; else Pico_mcd->scd.File_Add_Delay--;
} }
if (Pico_mcd->scd.Status_CDD == FAST_FOW) 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_Track = 0;
Pico_mcd->scd.Cur_LBA = -150; Pico_mcd->scd.Cur_LBA = -150;
Pico_mcd->scd.Status_CDD = READY; 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) else if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0E00)
Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF); 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; return 0;
} }
@ -290,7 +286,7 @@ int Stop_CDD_c1(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -322,7 +318,7 @@ int Get_Pos_CDD_c20(void)
Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F); Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F);
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; 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.Frame = INT_TO_BCDW(MSF.F);
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -385,7 +381,7 @@ int Get_Current_Track_CDD_c22(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -415,7 +411,7 @@ int Get_Total_Lenght_CDD_c23(void)
// FIXME: remove // FIXME: remove
//Pico_mcd->cdd.Seconde = 2; //Pico_mcd->cdd.Seconde = 2;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -441,7 +437,7 @@ int Get_First_Last_Track_CDD_c24(void)
// FIXME: remove // FIXME: remove
//Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1; //Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; 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; 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; return 0;
} }
@ -513,7 +509,7 @@ int Play_CDD_c3(void)
Pico_mcd->cdd.Status = 0x0102; Pico_mcd->cdd.Status = 0x0102;
// Pico_mcd->cdd.Status = COMM_OK; // 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) 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 Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -571,7 +567,7 @@ int Seek_CDD_c4(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -594,7 +590,7 @@ int Pause_CDD_c6(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -637,7 +633,7 @@ int Resume_CDD_c7(void)
Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -657,7 +653,7 @@ int Fast_Foward_CDD_c8(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -678,7 +674,7 @@ int Fast_Rewind_CDD_c9(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -712,7 +708,7 @@ int Close_Tray_CDD_cC(void)
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
} }
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -735,7 +731,7 @@ int Open_Tray_CDD_cD(void)
Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Frame = 0;
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }
@ -756,7 +752,7 @@ int CDD_cA(void)
Pico_mcd->cdd.Frame = INT_TO_BCDW(1); Pico_mcd->cdd.Frame = INT_TO_BCDW(1);
Pico_mcd->cdd.Ext = 0; Pico_mcd->cdd.Ext = 0;
CDD_Complete = 1; Pico_mcd->scd.CDD_Complete = 1;
return 0; return 0;
} }

View file

@ -46,12 +46,11 @@ typedef struct {
_scd_toc TOC; _scd_toc TOC;
int Cur_LBA; int Cur_LBA;
unsigned int Cur_Track; unsigned int Cur_Track;
int File_Add_Delay;
char CDD_Complete;
} _scd; } _scd;
extern int CD_Timer_Counter;
void LBA_to_MSF(int lba, _msf *MSF); void LBA_to_MSF(int lba, _msf *MSF);
int Track_to_LBA(int track); int Track_to_LBA(int track);

View file

@ -1,5 +1,6 @@
// TODO... // TODO...
// #include <string.h>
#include "../PicoInt.h" #include "../PicoInt.h"
#define rot_comp Pico_mcd->rot_comp #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)*/);
}

View file

@ -36,5 +36,7 @@ void gfx_cd_update(void);
unsigned int gfx_cd_read(unsigned int a); unsigned int gfx_cd_read(unsigned int a);
void gfx_cd_write(unsigned int a, unsigned int d); void gfx_cd_write(unsigned int a, unsigned int d);
void gfx_cd_reset(void);
#endif // _GFX_CD_H #endif // _GFX_CD_H

View file

@ -27,6 +27,7 @@ static unsigned char *mp3_mem = 0;
int crashed_940 = 0; int crashed_940 = 0;
static FILE *loaded_mp3 = 0;
/***********************************************************/ /***********************************************************/
@ -380,6 +381,8 @@ void YM2612Init_940(int baseclock, int rate)
internal_reset(); internal_reset();
loaded_mp3 = 0;
/* now cause 940 to init it's ym2612 stuff */ /* now cause 940 to init it's ym2612 stuff */
shared_ctl->baseclock = baseclock; shared_ctl->baseclock = baseclock;
shared_ctl->rate = rate; 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 // 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) void YM2612UpdateOne_940(short *buffer, int length, int stereo)
{ {
int cdda_on, *ym_buffer = shared_data->mix_buffer, mp3_job = 0; 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"); //printf("YM2612UpdateOne_940()\n");
if (shared_ctl->busy) wait_busy_940(); 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); printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len);
shared_ctl->mp3_offs = byte_offs; 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
} }

View file

@ -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/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
# Pico - CD # Pico - CD
OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ 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 # asm stuff
ifeq "$(asm_render)" "1" ifeq "$(asm_render)" "1"
DEFINC += -D_ASM_DRAW_C DEFINC += -D_ASM_DRAW_C

View file

@ -11,11 +11,52 @@ void wait_irq(void);
void spend_cycles(int c); void spend_cycles(int c);
void cache_clean(void); void cache_clean(void);
void cache_clean_flush(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 ("mov r0, #0" ::: "r0");
// asm volatile ("mcr p15, 0, r0, c7, c6, 0" ::: "r0"); /* flush dcache */ // 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 */ // 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) void Main940(int startvector)
{ {
ym2612_940 = &shared_data->ym2612; ym2612_940 = &shared_data->ym2612;
@ -85,40 +126,9 @@ void Main940(int startvector)
break; break;
} }
case JOB940_MP3DECODE: { case JOB940_MP3DECODE:
int mp3_offs = shared_ctl->mp3_offs; mp3_decode();
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; 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;
break;
}
} }
} }

View file

@ -182,4 +182,14 @@ wait_irq:
.pool .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: @ vim:filetype=armasm:

View file

@ -61,6 +61,10 @@ code940.gpe : $(OBJS940) ../helix/helix_mp3.a
@make -C ../helix/ @make -C ../helix/
up:
@cp -v code940.bin /mnt/gp2x/mnt/sd/games/PicoDrive/
# cleanup # cleanup
clean: tidy clean: tidy
@$(RM) code940.bin @$(RM) code940.bin

View file

@ -456,6 +456,7 @@ int emu_ReadConfig(int game)
currentConfig.PicoOpt = 0x0f | 0x200; // | use_940 currentConfig.PicoOpt = 0x0f | 0x200; // | use_940
currentConfig.PsndRate = 44100; currentConfig.PsndRate = 44100;
currentConfig.PicoRegion = 0; // auto currentConfig.PicoRegion = 0; // auto
currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP
currentConfig.Frameskip = -1; // auto currentConfig.Frameskip = -1; // auto
currentConfig.CPUclock = 200; currentConfig.CPUclock = 200;
currentConfig.volume = 50; currentConfig.volume = 50;
@ -490,6 +491,7 @@ int emu_ReadConfig(int game)
PicoOpt = currentConfig.PicoOpt; PicoOpt = currentConfig.PicoOpt;
PsndRate = currentConfig.PsndRate; PsndRate = currentConfig.PsndRate;
PicoRegionOverride = currentConfig.PicoRegion; PicoRegionOverride = currentConfig.PicoRegion;
PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;
if (PicoOpt & 0x20) { if (PicoOpt & 0x20) {
actionNames[ 8] = "Z"; actionNames[ 9] = "Y"; actionNames[ 8] = "Z"; actionNames[ 9] = "Y";
actionNames[10] = "X"; actionNames[11] = "MODE"; actionNames[10] = "X"; actionNames[11] = "MODE";
@ -527,6 +529,7 @@ int emu_WriteConfig(int game)
currentConfig.PicoOpt = PicoOpt; currentConfig.PicoOpt = PicoOpt;
currentConfig.PsndRate = PsndRate; currentConfig.PsndRate = PsndRate;
currentConfig.PicoRegion = PicoRegionOverride; currentConfig.PicoRegion = PicoRegionOverride;
currentConfig.PicoAutoRgnOrder = PicoAutoRgnOrder;
bwrite = fwrite(&currentConfig, 1, sizeof(currentConfig), f); bwrite = fwrite(&currentConfig, 1, sizeof(currentConfig), f);
fflush(f); fflush(f);
fclose(f); fclose(f);
@ -1231,6 +1234,7 @@ if (Pico.m.frame_count == 31563) {
// save SRAM // save SRAM
if((currentConfig.EmuOpt & 1) && SRam.changed) { if((currentConfig.EmuOpt & 1) && SRam.changed) {
blit("", "Writing SRAM/BRAM..");
emu_SaveLoadGame(0, 1); emu_SaveLoadGame(0, 1);
SRam.changed = 0; SRam.changed = 0;
} }
@ -1321,14 +1325,16 @@ int emu_SaveLoadGame(int load, int sram)
if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) { if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {
areaRead = gzRead2; areaRead = gzRead2;
areaWrite = gzWrite2; areaWrite = gzWrite2;
areaEof = (areaeof *) gzeof;
if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY); if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);
} else } else
saveFname[strlen(saveFname)-3] = 0; saveFname[strlen(saveFname)-3] = 0;
} }
if(!PmovFile) { // gzip failed or was disabled if(!PmovFile) { // gzip failed or was disabled
if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) { if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {
areaRead = (STATE_SL_FUNC) fread; areaRead = (arearw *) fread;
areaWrite = (STATE_SL_FUNC) fwrite; areaWrite = (arearw *) fwrite;
areaEof = (areaeof *) feof;
} }
} }
if(PmovFile) { if(PmovFile) {

View file

@ -30,6 +30,7 @@ typedef struct {
int volume; int volume;
int gamma; int gamma;
int JoyBinds[4][32]; int JoyBinds[4][32];
int PicoAutoRgnOrder;
} currentConfig_t; } currentConfig_t;
extern char romFileName[]; extern char romFileName[];

View file

@ -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 ---------- // --------- sega/mega cd options ----------
static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp) 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, "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), "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), "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), "CD LEDs %s", (currentConfig.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), "CDDA audio (using mp3s) %s", (currentConfig.EmuOpt &0x800)?"ON":"OFF"); // 4
gp2x_text_out8(tl_x, (y+=10), "Done"); gp2x_text_out8(tl_x, (y+=10), "Done");
// draw cursor // 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_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
switch (menu_sel) { switch (menu_sel) {
case 3: tmp_opts.EmuOpt ^=0x400; break; case 3: currentConfig.EmuOpt ^=0x400; break;
case 4: tmp_opts.EmuOpt ^=0x800; break; case 4: currentConfig.EmuOpt ^=0x800; break;
case 5: return; case 5: return;
} }
} }
@ -670,16 +658,16 @@ static void draw_amenu_options(int menu_sel)
y = tl_y; y = tl_y;
memset(gp2x_screen, 0, 320*240); 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, "Scale 32 column mode %s", (currentConfig.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), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.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 Z80 %s", (currentConfig.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 YM2612 (FM) %s", (currentConfig.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), "Emulate SN76496 (PSG) %s", (currentConfig.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), "gzip savestates %s", (currentConfig.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+=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), "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), "craigix's RAM timings %s", (currentConfig.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), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9
gp2x_text_out8(tl_x, (y+=10), "Done"); gp2x_text_out8(tl_x, (y+=10), "Done");
// draw cursor // 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_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
switch (menu_sel) { switch (menu_sel) {
case 0: tmp_opts.PicoOpt^=0x100; break; case 0: currentConfig.PicoOpt^=0x100; break;
case 2: tmp_opts.PicoOpt^=0x004; break; case 2: currentConfig.PicoOpt^=0x004; break;
case 3: tmp_opts.PicoOpt^=0x001; break; case 3: currentConfig.PicoOpt^=0x001; break;
case 4: tmp_opts.PicoOpt^=0x002; break; case 4: currentConfig.PicoOpt^=0x002; break;
case 5: tmp_opts.EmuOpt ^=0x008; break; case 5: currentConfig.EmuOpt ^=0x008; break;
case 6: tmp_opts.EmuOpt ^=0x020; break; case 6: currentConfig.EmuOpt ^=0x020; break;
case 8: tmp_opts.EmuOpt ^=0x100; break; case 8: currentConfig.EmuOpt ^=0x100; break;
case 9: tmp_opts.EmuOpt ^=0x010; break; case 9: currentConfig.EmuOpt ^=0x010; break;
case 10: return; case 10: return;
} }
} }
@ -717,9 +705,9 @@ static void amenu_loop_options(void)
switch (menu_sel) { switch (menu_sel) {
case 1: case 1:
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) { while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
tmp_gamma += (inp & GP2X_LEFT) ? -1 : 1; currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;
if (tmp_gamma < 1) tmp_gamma = 1; if (currentConfig.gamma < 1) currentConfig.gamma = 1;
if (tmp_gamma > 300) tmp_gamma = 300; if (currentConfig.gamma > 300) currentConfig.gamma = 300;
draw_amenu_options(menu_sel); draw_amenu_options(menu_sel);
usleep(18*1000); usleep(18*1000);
} }
@ -731,14 +719,26 @@ static void amenu_loop_options(void)
// -------------- options -------------- // -------------- 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" }; static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
int i = 0; static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
int u, i = 0;
if (code) {
code <<= 1; code <<= 1;
while((code >>=1)) i++; while((code >>= 1)) i++;
if (i > 4) return "unknown"; if (i > 4) return "unknown";
return names[i]; 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) 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; int tl_x = 25, tl_y = 40, y;
char monostereo[8], strframeskip[8], *strrend; char monostereo[8], strframeskip[8], *strrend;
strcpy(monostereo, (tmp_opts.PicoOpt&0x08)?"stereo":"mono"); strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");
if (tmp_opts.Frameskip < 0) if (currentConfig.Frameskip < 0)
strcpy(strframeskip, "Auto"); strcpy(strframeskip, "Auto");
else sprintf(strframeskip, "%i", tmp_opts.Frameskip); else sprintf(strframeskip, "%i", currentConfig.Frameskip);
if (tmp_opts.PicoOpt&0x10) { if (currentConfig.PicoOpt&0x10) {
strrend = " 8bit fast"; strrend = " 8bit fast";
} else if (tmp_opts.EmuOpt&0x80) { } else if (currentConfig.EmuOpt&0x80) {
strrend = "16bit accurate"; strrend = "16bit accurate";
} else { } else {
strrend = " 8bit accurate"; strrend = " 8bit accurate";
@ -761,19 +761,19 @@ static void draw_menu_options(int menu_sel)
y = tl_y; y = tl_y;
memset(gp2x_screen, 0, 320*240); memset(gp2x_screen, 0, 320*240);
gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0 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 timing (slower) %s", (currentConfig.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), "Accurate sprites (slower) %s", (currentConfig.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), "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), "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), "Enable sound %s", (currentConfig.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), "Sound Quality: %5iHz %s", currentConfig.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), "Use ARM940 core for sound %s", (currentConfig.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), "6 button pad %s", (currentConfig.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), "Genesis Region: %s", region_name(currentConfig.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), "Use SRAM/BRAM savestates %s", (currentConfig.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), "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), "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), "[Sega/Mega CD options]");
gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15 gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15
gp2x_text_out8(tl_x, (y+=10), "Save cfg as default"); 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]; 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) static void menu_options_save(void)
{ {
memcpy(&currentConfig.EmuOpt, &tmp_opts.EmuOpt, sizeof(tmp_opts));
currentConfig.gamma = tmp_gamma;
PicoOpt = currentConfig.PicoOpt; PicoOpt = currentConfig.PicoOpt;
PsndRate = currentConfig.PsndRate; PsndRate = currentConfig.PsndRate;
PicoRegionOverride = currentConfig.PicoRegion; PicoRegionOverride = currentConfig.PicoRegion;
@ -820,11 +842,9 @@ static int menu_loop_options(void)
unsigned long inp = 0; unsigned long inp = 0;
if (rom_data) menu_sel_max++; if (rom_data) menu_sel_max++;
memcpy(&tmp_opts.EmuOpt, &currentConfig.EmuOpt, sizeof(tmp_opts)); currentConfig.PicoOpt = PicoOpt;
tmp_gamma = currentConfig.gamma; currentConfig.PsndRate = PsndRate;
tmp_opts.PicoOpt = PicoOpt; currentConfig.PicoRegion = PicoRegionOverride;
tmp_opts.PsndRate = PsndRate;
tmp_opts.PicoRegion = PicoRegionOverride;
for(;;) 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_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
switch (menu_sel) { switch (menu_sel) {
case 1: tmp_opts.PicoOpt^=0x040; break; case 1: currentConfig.PicoOpt^=0x040; break;
case 2: tmp_opts.PicoOpt^=0x080; break; case 2: currentConfig.PicoOpt^=0x080; break;
case 3: tmp_opts.EmuOpt ^=0x002; break; case 3: currentConfig.EmuOpt ^=0x002; break;
case 5: tmp_opts.EmuOpt ^=0x004; break; case 5: currentConfig.EmuOpt ^=0x004; break;
case 7: tmp_opts.PicoOpt^=0x200; break; case 7: currentConfig.PicoOpt^=0x200; break;
case 8: tmp_opts.PicoOpt^=0x020; break; case 8: currentConfig.PicoOpt^=0x020; break;
case 10: tmp_opts.EmuOpt ^=0x001; break; case 10: currentConfig.EmuOpt ^=0x001; break;
case 11: tmp_opts.EmuOpt ^=0x200; break; case 11: currentConfig.EmuOpt ^=0x200; break;
case 14: cd_menu_loop_options(); case 14: cd_menu_loop_options();
if (engineState == PGS_ReloadRom) if (engineState == PGS_ReloadRom)
return 0; // test BIOS return 0; // test BIOS
@ -859,8 +879,7 @@ static int menu_loop_options(void)
return 1; return 1;
} }
} }
if(inp & GP2X_X) return 0; // done (no update or write) if(inp & (GP2X_X|GP2X_A)) {
if(inp & GP2X_A) {
menu_options_save(); menu_options_save();
return 0; // done (update, no write) return 0; // done (update, no write)
} }
@ -868,32 +887,29 @@ static int menu_loop_options(void)
switch (menu_sel) { switch (menu_sel) {
case 0: case 0:
if (inp & GP2X_LEFT) { if (inp & GP2X_LEFT) {
if ( tmp_opts.PicoOpt&0x10) tmp_opts.PicoOpt&= ~0x10; if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;
else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.EmuOpt |= 0x80; else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;
else if ( tmp_opts.EmuOpt &0x80) break; else if ( currentConfig.EmuOpt &0x80) break;
} else { } else {
if ( tmp_opts.PicoOpt&0x10) break; if ( currentConfig.PicoOpt&0x10) break;
else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.PicoOpt|= 0x10; else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;
else if ( tmp_opts.EmuOpt &0x80) tmp_opts.EmuOpt &= ~0x80; else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;
} }
break; break;
case 4: case 4:
tmp_opts.Frameskip += (inp & GP2X_LEFT) ? -1 : 1; currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;
if (tmp_opts.Frameskip < 0) tmp_opts.Frameskip = -1; if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1;
if (tmp_opts.Frameskip > 32) tmp_opts.Frameskip = 32; if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;
break; break;
case 6: case 6:
if ((inp & GP2X_RIGHT) && tmp_opts.PsndRate == 44100 && !(tmp_opts.PicoOpt&0x08)) { if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {
tmp_opts.PsndRate = 8000; tmp_opts.PicoOpt|= 0x08; currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;
} else if ((inp & GP2X_LEFT) && tmp_opts.PsndRate == 8000 && (tmp_opts.PicoOpt&0x08)) { } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {
tmp_opts.PsndRate = 44100; tmp_opts.PicoOpt&=~0x08; currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;
} else tmp_opts.PsndRate = sndrate_prevnext(tmp_opts.PsndRate, inp & GP2X_RIGHT); } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);
break; break;
case 9: case 9:
if (inp & GP2X_RIGHT) { region_prevnext(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;
break; break;
case 12: case 12:
if (inp & GP2X_RIGHT) { if (inp & GP2X_RIGHT) {
@ -903,8 +919,8 @@ static int menu_loop_options(void)
break; break;
case 13: case 13:
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) { while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
tmp_opts.CPUclock += (inp & GP2X_LEFT) ? -1 : 1; currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
if (tmp_opts.CPUclock < 1) tmp_opts.CPUclock = 1; if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;
draw_menu_options(menu_sel); draw_menu_options(menu_sel);
usleep(50*1000); usleep(50*1000);
} }

View file

@ -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_[44100/50*2]; /* this is where the YM2612 samples will be mixed to */
int *mix_buffer = mix_buffer_; 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_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_; static _940_ctl_t *shared_ctl = &shared_ctl_;
unsigned char *mp3_mem = 0; unsigned char *mp3_mem = 0;

View file

@ -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/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
# Pico - CD # Pico - CD
OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ 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 # Pico - sound
OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o
# zlib # zlib