return 0;\r
}\r
\r
+static unsigned char *cd_realloc(void *old, int filesize)\r
+{\r
+ unsigned char *rom;\r
+ dprintf("sizeof(mcd_state): %i", sizeof(mcd_state));\r
+ rom=realloc(old, sizeof(mcd_state));\r
+ if (rom) memset(rom+0x20000, 0, sizeof(mcd_state)-0x20000);\r
+ return rom;\r
+}\r
+\r
static unsigned char *PicoCartAlloc(int filesize)\r
{\r
int alloc_size;\r
unsigned char *rom;\r
\r
- if (PicoMCD & 1) {\r
- dprintf("sizeof(mcd_state): %i", sizeof(mcd_state));\r
- if (filesize > 0x20000) return NULL; // invalid BIOS\r
- rom=(unsigned char *)malloc(sizeof(mcd_state));\r
- if (rom) memset(rom, 0, sizeof(mcd_state));\r
- return rom;\r
- }\r
+ if (PicoMCD & 1) return cd_realloc(NULL, filesize);\r
\r
alloc_size=filesize+0x7ffff;\r
if((filesize&0x3fff)==0x200) alloc_size-=0x200;\r
\r
fseek(f,0,SEEK_END); size=ftell(f); fseek(f,0,SEEK_SET);\r
if (size <= 0) return 1;\r
- if (PicoMCD & 1) {\r
- if (size > 0x20000) return 1; // invalid BIOS\r
- size = 0xe0000;\r
- } else {\r
- size=(size+3)&~3; // Round up to a multiple of 4\r
- }\r
+ size=(size+3)&~3; // Round up to a multiple of 4\r
\r
// Allocate space for the rom plus padding\r
rom=PicoCartAlloc(size);\r
if (rom==NULL) return 1; // { fclose(f); return 1; }\r
\r
fread(rom,1,size,f); // Load up the rom\r
- // fclose(f); // this is confusing. From now on, caller should close it, because it opened this.\r
+\r
+ // maybe we are loading MegaCD BIOS?\r
+ if (!(PicoMCD&1) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) {\r
+ PicoMCD |= 1;\r
+ rom = cd_realloc(rom, size);\r
+ }\r
\r
// Check for SMD:\r
if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD\r
\r
closezip(zipfile);\r
\r
+ // maybe we are loading MegaCD BIOS?\r
+ if (!(PicoMCD&1) && size == 0x20000 &&\r
+ (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) {\r
+ PicoMCD |= 1;\r
+ rom = cd_realloc(rom, size);\r
+ }\r
+\r
// Check for SMD:\r
if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD\r
else Byteswap(rom,size); // Just byteswap\r
struct PicoSRAM SRam;\r
int z80startCycle = 0, z80stopCycle = 0; // in 68k cycles\r
//int z80ExtraCycles = 0;\r
-int PicoPad[2]; // Joypads, format is SACB RLDU\r
-int PicoMCD = 1; // mega CD status: scd_started\r
+int PicoPad[2]; // Joypads, format is SACB RLDU\r
+int PicoMCD = 0; // mega CD status: scd_started, reset_pending\r
\r
// to be called once on emu init\r
int PicoInit(void)\r
if(Pico.m.rotate++&8) d|=0x0100; else d|=0x0200; // Toggle fifo full empty (who uses that stuff?)\r
if(!(Pico.video.reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled\r
if(SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs)\r
- dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone());\r
+ // dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone());\r
\r
Pico.video.pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald)\r
\r
-#if 0\r
-#include <stdio.h>\r
-#include <windows.h>\r
-#include "misc.h"\r
-#include "lc89510.h"\r
-#include "cd_aspi.h"\r
-#include "Star_68k.h"\r
-#include "mem_S68k.h"\r
-#include "pcm.h"\r
-#endif\r
+/***********************************************************\r
+ * *\r
+ * This source is taken from the Gens project *\r
+ * Written by Stéphane Dallongeville *\r
+ * Copyright (c) 2002 by Stéphane Dallongeville *\r
+ * Modified/adapted for Picodrive by notaz, 2007 *\r
+ * *\r
+ ***********************************************************/\r
\r
#include "../PicoInt.h"\r
\r
#define CDC_DMA_SPEED 256\r
\r
int CDC_Decode_Reg_Read;\r
-static int Status_CDC; // internal status\r
+static int Status_CDC; // internal status (TODO: 2 context?)\r
\r
\r
static void CDD_Reset(void)\r
Pico_mcd->cdc.Stop_Watch = 0;\r
}\r
\r
-#if 0 // TODO\r
-void Update_CDC_TRansfer(void)\r
-{\r
- unsigned int i, dep, lenght, add_dest;\r
- unsigned char *dest;\r
-\r
- if ((Status_CDC & 0x08) == 0) return;\r
-\r
- switch(Pico_mcd->s68k_regs[4] & 7)\r
- {\r
- case 0x0200: // MAIN CPU\r
- case 0x0300: // SUB CPU\r
- Pico_mcd->s68k_regs[4] |= 0x40; // Data ready in host port\r
- return;\r
-\r
- case 0x0400: // PCM RAM\r
- dest = (unsigned char *) Ram_PCM;\r
- dep = ((Pico_mcd->cdc.DMA_Adr & 0x03FF) << 2) + PCM_Chip.Bank;\r
- add_dest = 2;\r
- break;\r
-\r
- case 0x0500: // PRG RAM\r
- dest = (unsigned char *) Ram_Prg;\r
- dep = (Pico_mcd->cdc.DMA_Adr & 0xFFFF) << 3;\r
- add_dest = 2;\r
-// cdprintf("DMA transfer PRG RAM : adr = %.8X ", dep);\r
- break;\r
\r
- case 0x0700: // WORD RAM\r
- if (Ram_Word_State >= 2)\r
- {\r
- dest = (unsigned char *) Ram_Word_1M;\r
- add_dest = 2;\r
- if (Ram_Word_State & 1) dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 3);\r
- else dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 3) + 0x20000;\r
- }\r
- else\r
- {\r
- dest = (unsigned char *) Ram_Word_2M;\r
- dep = ((Pico_mcd->cdc.DMA_Adr & 0x7FFF) << 3);\r
- add_dest = 2;\r
- }\r
- break;\r
-\r
- default:\r
- return;\r
- }\r
+void Update_CDC_TRansfer(int which)\r
+{\r
+ unsigned int dep, length, len;\r
+ unsigned short *dest;\r
+ unsigned char *src;\r
\r
if (Pico_mcd->cdc.DBC.N <= (CDC_DMA_SPEED * 2))\r
{\r
- lenght = (Pico_mcd->cdc.DBC.N + 1) >> 1;\r
- Status_CDC &= ~0x08; // Last transfer\r
- Pico_mcd->s68k_regs[4] |= 0x80; // End data transfer\r
- Pico_mcd->s68k_regs[4] &= ~0x40; // no more data ready\r
- Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress\r
+ length = (Pico_mcd->cdc.DBC.N + 1) >> 1;\r
+ Status_CDC &= ~0x08; // Last transfer\r
+ Pico_mcd->s68k_regs[4] |= 0x80; // End data transfer\r
+ Pico_mcd->s68k_regs[4] &= ~0x40; // no more data ready\r
+ Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress\r
\r
- if (Pico_mcd->cdc.IFCTRL & 0x40) // DTEIEN = Data Trasnfer End Interrupt Enable ?\r
+ if (Pico_mcd->cdc.IFCTRL & 0x40) // DTEIEN = Data Trasnfer End Interrupt Enable ?\r
{\r
Pico_mcd->cdc.IFSTAT &= ~0x40;\r
\r
- if (Int_Mask_S68K & 0x20) sub68k_interrupt(5, -1);\r
-\r
- cdprintf("CDC - DTE interrupt\n");\r
+ if (Pico_mcd->s68k_regs[0x33] & (1<<5))\r
+ {\r
+ dprintf("cdc DTE irq 5");\r
+ SekInterruptS68k(5);\r
+ }\r
}\r
}\r
- else lenght = CDC_DMA_SPEED;\r
+ else length = CDC_DMA_SPEED;\r
+\r
\r
-// cdprintf("DMA lenght = %.4X\n", lenght);\r
+ // TODO: dst bounds checking? DAC.N alignment?\r
+ src = Pico_mcd->cdc.Buffer + Pico_mcd->cdc.DAC.N;\r
\r
\r
- if ((Pico_mcd->s68k_regs[4] & 7) == 4) // PCM DMA\r
+ if (which == 7) // WORD RAM\r
{\r
- __asm\r
+ if (Pico_mcd->s68k_regs[3] & 4)\r
{\r
- mov ecx, lenght\r
- mov edi, dest\r
- lea esi, Pico_mcd->cdc.Buffer\r
- add edi, dep\r
- add esi, Pico_mcd->cdc.DAC.N\r
- mov ebx, add_dest\r
-\r
- Loop_DMA_PCM:\r
- mov ax, [esi]\r
- add esi, 2\r
- mov [edi], ax\r
- add edi, ebx\r
- dec ecx\r
- jnz Loop_DMA_PCM\r
+ dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 3);\r
+ cdprintf("CD DMA # %04x -> word_ram1M # %06x, len=%i",\r
+ Pico_mcd->cdc.DAC.N, dep, length);\r
+\r
+ dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 4);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) dep += 2;\r
+ dest = (unsigned short *) (Pico_mcd->word_ram + dep);\r
+\r
+ for (len = length; len > 0; len--, src+=2, dest+=2)\r
+ *dest = (src[0]<<8) | src[1];\r
}\r
+ else\r
+ {\r
+ dep = ((Pico_mcd->cdc.DMA_Adr & 0x7FFF) << 3);\r
+ cdprintf("CD DMA # %04x -> word_ram2M # %06x, len=%i",\r
+ Pico_mcd->cdc.DAC.N, dep, length);\r
+ dest = (unsigned short *) (Pico_mcd->word_ram + dep);\r
\r
- lenght <<= 1;\r
- Pico_mcd->cdc.DMA_Adr += lenght >> 2;\r
+ for (len = length; len > 0; len--, src+=2, dest++)\r
+ *dest = (src[0]<<8) | src[1];\r
+ }\r
}\r
- else // OTHER DMA\r
+ else if (which == 4) // PCM RAM\r
{\r
- __asm\r
- {\r
- mov ecx, lenght\r
- mov edi, dest\r
- lea esi, Pico_mcd->cdc.Buffer\r
- add edi, dep\r
- add esi, Pico_mcd->cdc.DAC.N\r
- mov ebx, add_dest\r
-\r
- Loop_DMA:\r
- mov ax, [esi]\r
- add esi, 2\r
- rol ax, 8\r
- mov [edi], ax\r
- add edi, ebx\r
- dec ecx\r
- jnz Loop_DMA\r
- }\r
+#if 0\r
+ dest = (unsigned char *) Ram_PCM;\r
+ dep = ((Pico_mcd->cdc.DMA_Adr & 0x03FF) << 2) + PCM_Chip.Bank;\r
+#else\r
+ cdprintf("TODO: PCM Dma");\r
+#endif\r
+ }\r
+ else if (which == 5) // PRG RAM\r
+ {\r
+ dep = (Pico_mcd->cdc.DMA_Adr & 0xFFFF) << 3;\r
+ dest = (unsigned short *) (Pico_mcd->prg_ram + dep);\r
+ cdprintf("CD DMA # %04x -> prg_ram # %06x, len=%i",\r
+ Pico_mcd->cdc.DAC.N, dep, length);\r
\r
- lenght <<= 1;\r
- Pico_mcd->cdc.DMA_Adr += lenght >> 3;\r
+ for (len = length; len > 0; len--, src+=2, dest++)\r
+ *dest = (src[0]<<8) | src[1];\r
}\r
\r
- Pico_mcd->cdc.DAC.N = (Pico_mcd->cdc.DAC.N + lenght) & 0xFFFF;\r
- if (Status_CDC & 0x08) Pico_mcd->cdc.DBC.N -= lenght;\r
+ length <<= 1;\r
+ Pico_mcd->cdc.DAC.N = (Pico_mcd->cdc.DAC.N + length) & 0xFFFF;\r
+ if (Status_CDC & 0x08) Pico_mcd->cdc.DBC.N -= length;\r
else Pico_mcd->cdc.DBC.N = 0;\r
}\r
-#endif\r
\r
\r
unsigned short Read_CDC_Host(int is_sub)\r
Get_Current_Track_CDD_c22();\r
break;\r
\r
- case 0x3: // get total lenght (MSF format)\r
+ case 0x3: // get total length (MSF format)\r
Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 3;\r
Get_Total_Lenght_CDD_c23();\r
break;\r
\r
typedef struct\r
{\r
+ unsigned char Buffer[(32 * 1024 * 2) + 2352];\r
unsigned int Host_Data;\r
unsigned int DMA_Adr;\r
unsigned int Stop_Watch;\r
} B;\r
unsigned int N;\r
} CTRL;\r
- unsigned char Buffer[(32 * 1024 * 2) + 2352];\r
} CDC;\r
\r
typedef struct\r
\r
void LC89510_Reset(void);\r
unsigned short Read_CDC_Host(int is_sub);\r
-void Update_CDC_TRansfer(void);\r
+void Update_CDC_TRansfer(int which);\r
void CDC_Update_Header(void);\r
\r
unsigned char CDC_Read_Reg(void);\r
void CDD_Export_Status(void);\r
void CDD_Import_Command(void);\r
\r
-unsigned char SCD_Read_Byte(unsigned int Adr);\r
-unsigned short SCD_Read_Word(unsigned int Adr);\r
-\r
#ifdef __cplusplus\r
};\r
#endif\r
goto end;\r
case 2:\r
d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0xc7);\r
+ dprintf("m68k_regs r3: %02x @%06x", (u8)d, SekPc);\r
goto end;\r
case 8:\r
dprintf("m68k host data read");\r
Pico_mcd->s68k_regs[2] = d; // really use s68k side register\r
return;\r
case 3:\r
+ dprintf("m68k_regs w3: %02x @%06x", (u8)d, SekPc);\r
d &= 0xc2;\r
if ((Pico_mcd->s68k_regs[3]>>6) != ((d>>6)&3))\r
dprintf("m68k: prg bank: %i -> %i", (Pico_mcd->s68k_regs[a]>>6), ((d>>6)&3));\r
d = 1; goto end; // ver = 0, not in reset state\r
case 2:\r
d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0x1f);\r
+ dprintf("s68k_regs r3: %02x @%06x", (u8)d, SekPc);\r
goto end;\r
case 6:\r
d = CDC_Read_Reg();\r
case 2:\r
return; // only m68k can change WP\r
case 3:\r
+ dprintf("s68k_regs w3: %02x @%06x", (u8)d, SekPc);\r
d &= 0x1d;\r
if (d&4) {\r
d |= Pico_mcd->s68k_regs[3]&0xc2;\r
if ((a&0xfc0000)==0x200000) {\r
dprintf("m68k_wram r8: [%06x] @%06x", a, SekPc);\r
if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?\r
- // TODO\r
+ if (a >= 0x220000) {\r
+ dprintf("cell");\r
+ } else {\r
+ a=((a&0x1fffe)<<1)|(a&1);\r
+ if (Pico_mcd->s68k_regs[3]&1) a+=2;\r
+ d = Pico_mcd->word_ram[a^1];\r
+ }\r
} else {\r
// allow access in any mode, like Gens does\r
d = Pico_mcd->word_ram[(a^1)&0x3ffff];\r
\r
if ((a&0xff4000)==0xa00000) { d=z80Read8(a); goto end; } // Z80 Ram\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("m68k_regs r8: [%02x] @%06x", a&0x3f, SekPc);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("m68k_regs r8: [%02x] @%06x", a&0x3f, SekPc);\r
\r
d=OtherRead16(a&~1, 8|(a&1)); if ((a&1)==0) d>>=8;\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("ret = %02x", (u8)d);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("ret = %02x", (u8)d);\r
\r
end:\r
\r
if ((a&0xfc0000)==0x200000) {\r
dprintf("m68k_wram r16: [%06x] @%06x", a, SekPc);\r
if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?\r
- // TODO\r
+ if (a >= 0x220000) {\r
+ dprintf("cell");\r
+ } else {\r
+ a=((a&0x1fffe)<<1);\r
+ if (Pico_mcd->s68k_regs[3]&1) a+=2;\r
+ d = *(u16 *)(Pico_mcd->word_ram+a);\r
+ }\r
} else {\r
// allow access in any mode, like Gens does\r
d = *(u16 *)(Pico_mcd->word_ram+(a&0x3fffe));\r
goto end;\r
}\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("m68k_regs r16: [%02x] @%06x", a&0x3f, SekPc);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("m68k_regs r16: [%02x] @%06x", a&0x3f, SekPc);\r
\r
d = (u16)OtherRead16(a, 16);\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("ret = %04x", d);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("ret = %04x", d);\r
\r
end:\r
\r
if ((a&0xfc0000)==0x200000) {\r
dprintf("m68k_wram r32: [%06x] @%06x", a, SekPc);\r
if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?\r
- // TODO\r
+ if (a >= 0x220000) {\r
+ dprintf("cell");\r
+ } else {\r
+ u16 *pm;\r
+ a=((a&0x1fffe)<<1);\r
+ if (Pico_mcd->s68k_regs[3]&1) a+=2;\r
+ pm=(u16 *)(Pico_mcd->word_ram+a);\r
+ d = (pm[0]<<16)|pm[1];\r
+ }\r
} else {\r
// allow access in any mode, like Gens does\r
u16 *pm=(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); d = (pm[0]<<16)|pm[1];\r
goto end;\r
}\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("m68k_regs r32: [%02x] @%06x", a&0x3f, SekPc);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("m68k_regs r32: [%02x] @%06x", a&0x3f, SekPc);\r
\r
d = (OtherRead16(a, 32)<<16)|OtherRead16(a+2, 32);\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("ret = %08x", d);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("ret = %08x", d);\r
\r
end:\r
#ifdef __debug_io\r
// prg RAM\r
if ((a&0xfe0000)==0x020000) {\r
u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6];\r
- u8 *pm=(u8 *)(prg_bank+((a^1)&0x1ffff));\r
- *pm=d;\r
+ *(u8 *)(prg_bank+((a^1)&0x1ffff))=d;\r
return;\r
}\r
\r
if ((a&0xfc0000)==0x200000) {\r
dprintf("m68k_wram w8: [%06x] %02x @%06x", a, d, SekPc);\r
if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?\r
- // TODO\r
+ if (a >= 0x220000) {\r
+ dprintf("cell");\r
+ } else {\r
+ a=((a&0x1fffe)<<1)|(a&1);\r
+ if (Pico_mcd->s68k_regs[3]&1) a+=2;\r
+ *(u8 *)(Pico_mcd->word_ram+(a^1))=d;\r
+ }\r
} else {\r
// allow access in any mode, like Gens does\r
- u8 *pm=(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff));\r
- *pm=d;\r
+ *(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff))=d;\r
}\r
return;\r
}\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc);\r
\r
OtherWrite8(a,d,8);\r
}\r
#ifdef __debug_io\r
dprintf("w16: %06x, %04x", a&0xffffff, d);\r
#endif\r
- //if ((a&0xe0ffff)==0xe0AF0E+0x69c||(a&0xe0ffff)==0xe0A9A8+0x69c||(a&0xe0ffff)==0xe0A9AA+0x69c||(a&0xe0ffff)==0xe0A9AC+0x69c)\r
// dprintf("w16: %06x, %04x @%06x", a&0xffffff, d, SekPc);\r
\r
if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram\r
if ((a&0xfc0000)==0x200000) {\r
dprintf("m68k_wram w16: [%06x] %04x @%06x", a, d, SekPc);\r
if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?\r
- // TODO\r
+ if (a >= 0x220000) {\r
+ dprintf("cell");\r
+ } else {\r
+ a=((a&0x1fffe)<<1);\r
+ if (Pico_mcd->s68k_regs[3]&1) a+=2;\r
+ *(u16 *)(Pico_mcd->word_ram+a)=d;\r
+ }\r
} else {\r
// allow access in any mode, like Gens does\r
*(u16 *)(Pico_mcd->word_ram+(a&0x3fffe))=d;\r
return;\r
}\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc);\r
\r
OtherWrite16(a,d);\r
}\r
if (d != 0) // don't log clears\r
dprintf("m68k_wram w32: [%06x] %08x @%06x", a, d, SekPc);\r
if (Pico_mcd->s68k_regs[3]&4) { // 1M mode?\r
- // TODO\r
+ if (a >= 0x220000) {\r
+ dprintf("cell");\r
+ } else {\r
+ u16 *pm;\r
+ a=((a&0x1fffe)<<1);\r
+ if (Pico_mcd->s68k_regs[3]&1) a+=2;\r
+ pm=(u16 *)(Pico_mcd->word_ram+a);\r
+ pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
+ }\r
} else {\r
// allow access in any mode, like Gens does\r
u16 *pm=(u16 *)(Pico_mcd->word_ram+(a&0x3fffe));\r
return;\r
}\r
\r
- if ((a&0xffffc0)==0xa12000)\r
- dprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc);\r
+ //if ((a&0xffffc0)==0xa12000)\r
+ // dprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc);\r
\r
OtherWrite16(a, (u16)(d>>16));\r
OtherWrite16(a+2,(u16)d);\r
\r
// regs\r
if ((a&0xfffe00) == 0xff8000) {\r
- dprintf("s68k_regs r8: [%02x] @ %06x", a&0x1ff, SekPcS68k);\r
+ //dprintf("s68k_regs r8: [%02x] @ %06x", a&0x1ff, SekPcS68k);\r
d = s68k_reg_read16(a&~1, 8|(a&1)); if ((a&1)==0) d>>=8;\r
- dprintf("ret = %02x", (u8)d);\r
+ //dprintf("ret = %02x", (u8)d);\r
goto end;\r
}\r
\r
// word RAM (1M area)\r
if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff\r
dprintf("s68k_wram1M r8: [%06x] @%06x", a, SekPc);\r
- // TODO\r
+ a=((a&0x1fffe)<<1)|(a&1);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) a+=2;\r
+ d = Pico_mcd->word_ram[a^1];\r
+ dprintf("ret = %02x", (u8)d);\r
goto end;\r
}\r
\r
\r
// regs\r
if ((a&0xfffe00) == 0xff8000) {\r
- dprintf("s68k_regs r16: [%02x] @ %06x", a&0x1fe, SekPcS68k);\r
+ //dprintf("s68k_regs r16: [%02x] @ %06x", a&0x1fe, SekPcS68k);\r
d = s68k_reg_read16(a, 16);\r
- dprintf("ret = %04x", d);\r
+ //dprintf("ret = %04x", d);\r
goto end;\r
}\r
\r
// word RAM (1M area)\r
if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff\r
dprintf("s68k_wram1M r16: [%06x] @%06x", a, SekPc);\r
- // TODO\r
+ a=((a&0x1fffe)<<1);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) a+=2;\r
+ d = *(u16 *)(Pico_mcd->word_ram+a);\r
+ dprintf("ret = %04x", (u8)d);\r
goto end;\r
}\r
\r
\r
// regs\r
if ((a&0xfffe00) == 0xff8000) {\r
- dprintf("s68k_regs r32: [%02x] @ %06x", a&0x1fe, SekPcS68k);\r
+ //dprintf("s68k_regs r32: [%02x] @ %06x", a&0x1fe, SekPcS68k);\r
d = (s68k_reg_read16(a, 32)<<16)|s68k_reg_read16(a+2, 32);\r
- dprintf("ret = %08x", d);\r
+ //dprintf("ret = %08x", d);\r
goto end;\r
}\r
\r
\r
// word RAM (1M area)\r
if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff\r
+ u16 *pm;\r
dprintf("s68k_wram1M 32: [%06x] @%06x", a, SekPc);\r
- // TODO\r
+ a=((a&0x1fffe)<<1);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) a+=2;\r
+ pm=(u16 *)(Pico_mcd->word_ram+a);\r
+ d = (pm[0]<<16)|pm[1];\r
+ dprintf("ret = %08x", (u8)d);\r
goto end;\r
}\r
\r
\r
// regs\r
if ((a&0xfffe00) == 0xff8000) {\r
- dprintf("s68k_regs w8: [%02x] %02x @ %06x", a&0x1ff, d, SekPcS68k);\r
+ //dprintf("s68k_regs w8: [%02x] %02x @ %06x", a&0x1ff, d, SekPcS68k);\r
s68k_reg_write8(a,d,8);\r
return;\r
}\r
dprintf("(decode)");\r
} else {\r
// allow access in any mode, like Gens does\r
- u8 *pm=(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff));\r
- *pm=d;\r
+ *(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff))=d;\r
}\r
return;\r
}\r
if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff\r
if (d)\r
dprintf("s68k_wram1M w8: [%06x] %02x @%06x", a, d, SekPc);\r
- // TODO\r
+ a=((a&0x1fffe)<<1)|(a&1);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) a+=2;\r
+ *(u8 *)(Pico_mcd->word_ram+(a^1))=d;\r
return;\r
}\r
\r
\r
// regs\r
if ((a&0xfffe00) == 0xff8000) {\r
- dprintf("s68k_regs w16: [%02x] %04x @ %06x", a&0x1ff, d, SekPcS68k);\r
+ //dprintf("s68k_regs w16: [%02x] %04x @ %06x", a&0x1ff, d, SekPcS68k);\r
s68k_reg_write8(a, d>>8, 16);\r
s68k_reg_write8(a+1,d&0xff, 16);\r
return;\r
if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff\r
if (d)\r
dprintf("s68k_wram1M w16: [%06x] %04x @%06x", a, d, SekPc);\r
- // TODO\r
+ a=((a&0x1fffe)<<1);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) a+=2;\r
+ *(u16 *)(Pico_mcd->word_ram+a)=d;\r
return;\r
}\r
\r
\r
// regs\r
if ((a&0xfffe00) == 0xff8000) {\r
- dprintf("s68k_regs w32: [%02x] %08x @ %06x", a&0x1ff, d, SekPcS68k);\r
+ //dprintf("s68k_regs w32: [%02x] %08x @ %06x", a&0x1ff, d, SekPcS68k);\r
s68k_reg_write8(a, d>>24, 32);\r
s68k_reg_write8(a+1,(d>>16)&0xff, 32);\r
s68k_reg_write8(a+2,(d>>8) &0xff, 32);\r
\r
// word RAM (1M area)\r
if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff\r
+ u16 *pm;\r
if (d)\r
dprintf("s68k_wram1M w32: [%06x] %08x @%06x", a, d, SekPc);\r
- // TODO\r
+ a=((a&0x1fffe)<<1);\r
+ if (!(Pico_mcd->s68k_regs[3]&1)) a+=2;\r
+ pm=(u16 *)(Pico_mcd->word_ram+a);\r
+ pm[0]=(u16)(d>>16); pm[1]=(u16)d;\r
return;\r
}\r
dprintf("s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k);\r
#endif
}
-// TODO: tidy
-extern unsigned char m68k_regs[0x40];
-extern unsigned char s68k_regs[0x200];
+static int Status_CDC;
+
+static __inline void check_cd_dma(void)
+{
+ int ddx;
+
+ if (!(Status_CDC & 0x08)) return;
+
+ ddx = Pico_mcd->s68k_regs[4] & 7;
+ if (ddx < 2) return; // invalid
+ if (ddx < 4) Pico_mcd->s68k_regs[4] |= 0x40; // Data set ready in host port
+ if (ddx == 6) return; // invalid
+
+ Update_CDC_TRansfer(ddx); // now go and do the actual transfer
+}
+
// Accurate but slower frame which does hints
static int PicoFrameHintsMCD(void)
if(Pico.m.padDelay[1]++ > 25) Pico.m.padTHPhase[1]=0;
}
+ check_cd_dma();
+
// H-Interrupts:
if(y <= lines_vis && --hint < 0) // y <= lines_vis: Comix Zone, Golden Axe
{
--- /dev/null
+/*
+#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"
+
+#include "../PicoInt.h"
+
+#define cdprintf printf
+//#define cdprintf(x...)
+
+struct _file_track Tracks[100];
+char Track_Played;
+
+
+int FILE_Init(void)
+{
+// MP3_Init(); // TODO
+ Unload_ISO();
+
+ return 0;
+}
+
+
+void FILE_End(void)
+{
+ Unload_ISO();
+}
+
+
+int Load_ISO(const char *iso_name, int is_bin)
+{
+ struct stat file_stat;
+ int i, j, num_track, Cur_LBA, index, ret;
+ _scd_track *SCD_TOC_Tracks = Pico_mcd->scd.TOC.Tracks;
+ FILE *tmp_file;
+ char tmp_name[1024], tmp_ext[10];
+ static char *exts[] = {
+ "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3",
+ "%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3",
+ /* "%02d.wav", " %02d.wav", "-%02d.wav", "_%02d.wav", " - %02d.wav",
+ "%d.wav", " %d.wav", "-%d.wav", "_%d.wav", " - %2d.wav" */
+ };
+
+ Unload_ISO();
+
+ Tracks[0].Type = is_bin ? TYPE_BIN : TYPE_ISO;
+
+ ret = stat(iso_name, &file_stat);
+ if (ret != 0) return -1;
+
+ Tracks[0].Lenght = file_stat.st_size;
+
+ if (Tracks[0].Type == TYPE_ISO) Tracks[0].Lenght >>= 11; // size in sectors
+ else Tracks[0].Lenght /= 2352; // size in sectors
+
+
+ Tracks[0].F = fopen(iso_name, "rb");
+ if (Tracks[0].F == NULL)
+ {
+ Tracks[0].Type = 0;
+ Tracks[0].Lenght = 0;
+ return -1;
+ }
+
+ if (Tracks[0].Type == TYPE_ISO) fseek(Tracks[0].F, 0x100, SEEK_SET);
+ else fseek(Tracks[0].F, 0x110, SEEK_SET);
+
+ // fread(buf, 1, 0x200, Tracks[0].F);
+ fseek(Tracks[0].F, 0, SEEK_SET);
+
+ Pico_mcd->scd.TOC.First_Track = 1;
+
+ SCD_TOC_Tracks[0].Num = 1;
+ SCD_TOC_Tracks[0].Type = 1; // DATA
+
+ SCD_TOC_Tracks[0].MSF.M = 0;
+ SCD_TOC_Tracks[0].MSF.S = 2;
+ SCD_TOC_Tracks[0].MSF.F = 0;
+
+ cdprintf("\nTrack 0 - %02d:%02d:%02d %s\n", SCD_TOC_Tracks[0].MSF.M, SCD_TOC_Tracks[0].MSF.S, SCD_TOC_Tracks[0].MSF.F,
+ SCD_TOC_Tracks[0].Type ? "DATA" : "AUDIO");
+
+ Cur_LBA = Tracks[0].Lenght; // Size in sectors
+
+ strcpy(tmp_name, iso_name);
+
+ 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++)
+ {
+ tmp_name[strlen(iso_name) - 4] = 0;
+ sprintf(tmp_ext, exts[j], i);
+ strcat(tmp_name, tmp_ext);
+
+ tmp_file = fopen(tmp_name, "rb");
+
+ if (tmp_file)
+ {
+ float fs;
+ index = num_track - Pico_mcd->scd.TOC.First_Track;
+
+ stat(tmp_name, &file_stat);
+
+ fs = (float) file_stat.st_size; // used to calculate lenght
+
+ Tracks[index].F = tmp_file;
+
+ SCD_TOC_Tracks[index].Num = num_track;
+ SCD_TOC_Tracks[index].Type = 0; // AUDIO
+
+ LBA_to_MSF(Cur_LBA, &(SCD_TOC_Tracks[index].MSF));
+
+ cdprintf("\nTrack %i - %02d:%02d:%02d %s\n", index, SCD_TOC_Tracks[index].MSF.M,
+ SCD_TOC_Tracks[index].MSF.S, SCD_TOC_Tracks[index].MSF.F,
+ SCD_TOC_Tracks[index].Type ? "DATA" : "AUDIO");
+
+ // MP3 File
+ Tracks[index].Type = TYPE_MP3;
+ fs /= (128>>3); // (float) (MP3_Get_Bitrate(Tracks[num_track - 1].F) >> 3);
+ fs *= 75;
+ Tracks[index].Lenght = (int) fs;
+ Cur_LBA += Tracks[index].Lenght;
+
+ num_track++;
+ break;
+ }
+ }
+ }
+
+ Pico_mcd->scd.TOC.Last_Track = num_track - 1;
+
+ index = num_track - Pico_mcd->scd.TOC.First_Track;
+ SCD_TOC_Tracks[index].Num = num_track;
+ SCD_TOC_Tracks[index].Type = 0;
+
+ LBA_to_MSF(Cur_LBA, &(SCD_TOC_Tracks[index].MSF));
+
+ cdprintf("End CD - %02d:%02d:%02d\n\n", SCD_TOC_Tracks[index].MSF.M,
+ SCD_TOC_Tracks[index].MSF.S, SCD_TOC_Tracks[index].MSF.F);
+
+ return 0;
+}
+
+
+void Unload_ISO(void)
+{
+ int i;
+
+ Track_Played = 99;
+
+ for(i = 0; i < 100; i++)
+ {
+ if (Tracks[i].F) fclose(Tracks[i].F);
+ Tracks[i].F = NULL;
+ Tracks[i].Lenght = 0;
+ Tracks[i].Type = 0;
+ }
+}
+
+
+int FILE_Read_One_LBA_CDC(void)
+{
+ int where_read;
+ static char cp_buf[2560];
+
+ if (Pico_mcd->s68k_regs[0x36] & 1) // DATA
+ {
+ if (Tracks[0].F == NULL) return -1;
+
+ if (Pico_mcd->scd.Cur_LBA < 0) where_read = 0;
+ else if (Pico_mcd->scd.Cur_LBA >= Tracks[0].Lenght) where_read = Tracks[0].Lenght - 1;
+ else where_read = Pico_mcd->scd.Cur_LBA;
+
+ if (Tracks[0].Type == TYPE_ISO) where_read <<= 11;
+ else where_read = (where_read * 2352 + 16);
+
+ fseek(Tracks[0].F, where_read, SEEK_SET);
+ fread(cp_buf, 1, 2048, Tracks[0].F);
+
+ cdprintf("\n\nRead file CDC 1 data sector :\n");
+ }
+ else // AUDIO
+ {
+ // int rate, channel;
+
+ if (Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type == TYPE_MP3)
+ {
+ // TODO
+ // MP3_Update(cp_buf, &rate, &channel, 0);
+ // Write_CD_Audio((short *) cp_buf, rate, channel, 588);
+ }
+
+ cdprintf("\n\nRead file CDC 1 audio sector :\n");
+ }
+
+ // Update CDC stuff
+
+ CDC_Update_Header();
+
+ if (Pico_mcd->s68k_regs[0x36] & 1) // DATA track
+ {
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x80) // DECEN = decoding enable
+ {
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x04) // WRRQ : this bit enable write to buffer
+ {
+ // CAUTION : lookahead bit not implemented
+
+ Pico_mcd->scd.Cur_LBA++;
+
+ Pico_mcd->cdc.WA.N = (Pico_mcd->cdc.WA.N + 2352) & 0x7FFF; // add one sector to WA
+ Pico_mcd->cdc.PT.N = (Pico_mcd->cdc.PT.N + 2352) & 0x7FFF;
+
+ memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N + 4], cp_buf, 2048);
+ memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N], &Pico_mcd->cdc.HEAD, 4);
+
+#ifdef DEBUG_CD
+ cdprintf("\nRead -> WA = %d Buffer[%d] =\n", Pico_mcd->cdc.WA.N, Pico_mcd->cdc.PT.N & 0x3FFF);
+ cdprintf("Header 1 = %.2X %.2X %.2X %.2X\n", Pico_mcd->cdc.HEAD.B.B0,
+ Pico_mcd->cdc.HEAD.B.B1, Pico_mcd->cdc.HEAD.B.B2, Pico_mcd->cdc.HEAD.B.B3);
+ cdprintf("Header 2 = %.2X %.2X %.2X %.2X --- %.2X %.2X\n\n",
+ Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 0) & 0x3FFF],
+ Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 1) & 0x3FFF],
+ Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 2) & 0x3FFF],
+ Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 3) & 0x3FFF],
+ Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 4) & 0x3FFF],
+ Pico_mcd->cdc.Buffer[(Pico_mcd->cdc.PT.N + 5) & 0x3FFF]);
+#endif
+ }
+
+ }
+ }
+ else // music track
+ {
+ Pico_mcd->scd.Cur_LBA++;
+
+ Pico_mcd->cdc.WA.N = (Pico_mcd->cdc.WA.N + 2352) & 0x7FFF; // add one sector to WA
+ Pico_mcd->cdc.PT.N = (Pico_mcd->cdc.PT.N + 2352) & 0x7FFF;
+
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x80) // DECEN = decoding enable
+ {
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x04) // WRRQ : this bit enable write to buffer
+ {
+ // CAUTION : lookahead bit not implemented
+
+ memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N], cp_buf, 2352);
+ }
+ }
+ }
+
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x80) // DECEN = decoding enable
+ {
+ Pico_mcd->cdc.STAT.B.B0 = 0x80;
+
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x10) // determine form bit form sub header ?
+ {
+ Pico_mcd->cdc.STAT.B.B2 = Pico_mcd->cdc.CTRL.B.B1 & 0x08;
+ }
+ else
+ {
+ Pico_mcd->cdc.STAT.B.B2 = Pico_mcd->cdc.CTRL.B.B1 & 0x0C;
+ }
+
+ if (Pico_mcd->cdc.CTRL.B.B0 & 0x02) Pico_mcd->cdc.STAT.B.B3 = 0x20; // ECC done
+ else Pico_mcd->cdc.STAT.B.B3 = 0x00; // ECC not done
+
+ if (Pico_mcd->cdc.IFCTRL & 0x20)
+ {
+ if (Pico_mcd->s68k_regs[0x33] & (1<<5))
+ {
+ dprintf("cdc dec irq 5");
+ SekInterruptS68k(5);
+ }
+
+ Pico_mcd->cdc.IFSTAT &= ~0x20; // DEC interrupt happen
+ CDC_Decode_Reg_Read = 0; // Reset read after DEC int
+ }
+ }
+
+
+ return 0;
+}
+
+
+int FILE_Play_CD_LBA(void)
+{
+ int index = Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track;
+
+ cdprintf("Play FILE Comp\n");
+
+ if (Tracks[index].F == NULL)
+ {
+ return 1;
+ }
+
+ if (Tracks[index].Type == TYPE_MP3)
+ {
+ int Track_LBA_Pos = Pico_mcd->scd.Cur_LBA - Track_to_LBA(Pico_mcd->scd.Cur_Track);
+ if (Track_LBA_Pos < 0) Track_LBA_Pos = 0;
+
+ // MP3_Play(index, Track_LBA_Pos); // TODO
+ }
+ else
+ {
+ return 3;
+ }
+
+ return 0;
+}
+
--- /dev/null
+#ifndef _CD_FILE_H
+#define _CD_FILE_H
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TYPE_ISO 1
+#define TYPE_BIN 2
+#define TYPE_MP3 3
+//#define TYPE_WAV 4
+
+
+struct _file_track {
+ FILE *F;
+ int Lenght;
+ int Type;
+};
+
+extern struct _file_track Tracks[100];
+extern char Track_Played;
+
+
+int FILE_Init(void);
+void FILE_End(void);
+int Load_ISO(const char *iso_name, int is_bin);
+void Unload_ISO(void);
+int FILE_Read_One_LBA_CDC(void);
+int FILE_Play_CD_LBA(void);
+
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif
#include <stdio.h>\r
#include "cd_sys.h"\r
-//#include "cd_file.h"\r
+#include "cd_file.h"\r
\r
#include "../PicoInt.h"\r
\r
#define FAST_REV 0x10300 // FAST REVERSE track CDD status\r
#define PLAYING 0x0100 // PLAYING audio track CDD status\r
\r
-/*\r
-#include "gens.h"\r
-#include "G_dsound.h"\r
-#include "cdda_mp3.h"\r
-#include "lc89510.h"\r
-#include "Star_68k.h"\r
-#include "Mem_M68K.h"\r
-#include "Mem_S68K.h"\r
-#include "save.h"\r
-#include "misc.h"\r
-*/\r
-\r
\r
/*\r
int CDDA_Enable;\r
\r
static int File_Add_Delay = 0;\r
\r
-//_scd SCD;\r
-\r
\r
\r
#define CHECK_TRAY_OPEN \\r
\r
if (File_Add_Delay == 0)\r
{\r
-#if 0 // TODO\r
FILE_Read_One_LBA_CDC();\r
-#endif\r
}\r
else File_Add_Delay--;\r
}\r
\r
int Init_CD_Driver(void)\r
{\r
-#if 0 // TODO\r
FILE_Init();\r
-#endif\r
\r
return 0;\r
}\r
\r
void End_CD_Driver(void)\r
{\r
-#if 0 // TODO\r
FILE_End();\r
-#endif\r
}\r
\r
\r
}\r
\r
\r
-int Insert_CD(char *buf, char *iso_name)\r
+int Insert_CD(char *iso_name, int is_bin)\r
{\r
+ int ret = 0;\r
+\r
// memset(CD_Audio_Buffer_L, 0, 4096 * 4);\r
// memset(CD_Audio_Buffer_R, 0, 4096 * 4);\r
\r
- if (iso_name == NULL)\r
- {\r
- CD_Present = 0;\r
- }\r
- else\r
+ CD_Present = 0;\r
+\r
+ if (iso_name != NULL)\r
{\r
-#if 0 // TODO\r
- Load_ISO(buf, iso_name);\r
- CD_Present = 1;\r
-#endif\r
- return 0;\r
+ ret = Load_ISO(iso_name, is_bin);\r
+ if (ret == 0)\r
+ CD_Present = 1;\r
}\r
\r
- return 0;\r
+ return ret;\r
}\r
\r
\r
void Stop_CD(void)\r
{\r
-#if 0 // TODO\r
Unload_ISO();\r
-#endif\r
CD_Present = 0;\r
}\r
\r
Pico_mcd->cdd.Ext = 0;\r
\r
// FIXME: remove\r
-Pico_mcd->cdd.Seconde = 2;\r
+//Pico_mcd->cdd.Seconde = 2;\r
\r
CDD_Complete = 1;\r
\r
Pico_mcd->cdd.Ext = 0;\r
\r
// FIXME: remove\r
-Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1;\r
+//Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1;\r
\r
CDD_Complete = 1;\r
\r
{\r
Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
//CD_Audio_Starting = 1;\r
-#if 0 // TODO\r
FILE_Play_CD_LBA();\r
-#endif\r
}\r
\r
if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02;\r
{\r
Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO\r
//CD_Audio_Starting = 1;\r
-#if 0 // TODO\r
FILE_Play_CD_LBA();\r
-#endif\r
}\r
\r
if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02;\r
}\r
\r
\r
-int Fast_Foward_CDD_c8(void)\r
+int Fast_Foward_CDD_c8(void)\r
{\r
CHECK_TRAY_OPEN\r
CHECK_CD_PRESENT\r
}\r
\r
\r
-int Fast_Rewind_CDD_c9(void)\r
+int Fast_Rewind_CDD_c9(void)\r
{\r
CHECK_TRAY_OPEN\r
CHECK_CD_PRESENT\r
\r
Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read\r
\r
-#if 0 // TODO\r
Unload_ISO();\r
-#endif\r
CD_Present = 0;\r
\r
Pico_mcd->scd.Status_CDD = TRAY_OPEN;\r
\r
int Init_CD_Driver(void);\r
void End_CD_Driver(void);\r
-int Insert_CD(char *buf, char *iso_name);\r
+int Insert_CD(char *iso_name, int is_bin);\r
void Stop_CD(void);\r
void Change_CD(void);\r
void Reset_CD(void);\r
return 0;\r
}\r
\r
-static void get_ext(char *ext)\r
+static void get_ext(char *file, char *ext)\r
{\r
char *p;\r
\r
- p = romFileName + strlen(romFileName) - 4;\r
- if (p < romFileName) p = romFileName;\r
+ p = file + strlen(file) - 4;\r
+ if (p < file) p = file;\r
strncpy(ext, p, 4);\r
ext[4] = 0;\r
strlwr(ext);\r
}\r
\r
+char *biosfiles_us[] = { "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210" };\r
+char *biosfiles_eu[] = { "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210" };\r
+char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
+\r
+extern char **g_argv;\r
+\r
+int find_bios(int region, char **bios_file)\r
+{\r
+ static char bios_path[1024];\r
+ int i, j, count;\r
+ char **files;\r
+ FILE *f = NULL;\r
+\r
+ if (region == 4) { // US\r
+ files = biosfiles_us;\r
+ count = sizeof(biosfiles_us) / sizeof(char *);\r
+ } else if (region == 8) { // EU\r
+ files = biosfiles_eu;\r
+ count = sizeof(biosfiles_eu) / sizeof(char *);\r
+ } else if (region == 1 || region == 2) {\r
+ files = biosfiles_jp;\r
+ count = sizeof(biosfiles_jp) / sizeof(char *);\r
+ } else {\r
+ return 0;\r
+ }\r
+\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ strncpy(bios_path, g_argv[0], 1023);\r
+ bios_path[1024-32] = 0;\r
+ for (j = strlen(bios_path); j > 0; j--)\r
+ if (bios_path[j] == '/') { bios_path[j+1] = 0; break; }\r
+ strcat(bios_path, files[i]);\r
+ strcat(bios_path, ".bin");\r
+ f = fopen(bios_path, "rb");\r
+ if (f) break;\r
+\r
+ bios_path[strlen(bios_path) - 4] = 0;\r
+ strcat(bios_path, ".zip");\r
+ f = fopen(bios_path, "rb");\r
+ if (f) break;\r
+ }\r
+\r
+ if (f) {\r
+ printf("using bios: %s\n", bios_path);\r
+ fclose(f);\r
+ if (bios_file) *bios_file = bios_path;\r
+ return 1;\r
+ } else {\r
+ sprintf(menuErrorMsg, "no %s BIOS files found, read docs",\r
+ region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+ printf("%s\n", menuErrorMsg);\r
+ return 0;\r
+ }\r
+}\r
+\r
+/* checks if romFileName points to valid MegaCD image\r
+ * if so, checks for suitable BIOS */\r
+static int cd_check(char *ext, char **bios_file)\r
+{\r
+ unsigned char buf[32];\r
+ FILE *cd_f;\r
+ int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe\r
+\r
+ cd_f = fopen(romFileName, "rb");\r
+ if (!cd_f) return 0; // let the upper level handle this\r
+\r
+ if (fread(buf, 1, 32, cd_f) != 32) {\r
+ fclose(cd_f);\r
+ return 0;\r
+ }\r
+\r
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO)\r
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN)\r
+ if (type == 0) {\r
+ fclose(cd_f);\r
+ return 0;\r
+ }\r
+\r
+ /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */\r
+ fseek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET);\r
+ fread(buf, 1, 1, cd_f);\r
+ fclose(cd_f);\r
+\r
+ if (buf[0] == 0x64) region = 4; // EU\r
+ if (buf[0] == 0xa1) region = 1; // JAP\r
+\r
+ printf("detected %s Sega/Mega CD image with %s region\n",\r
+ type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+\r
+ if (PicoRegionOverride) {\r
+ region = PicoRegionOverride;\r
+ printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+ }\r
+\r
+ if(find_bios(region, bios_file))\r
+ return type; // CD and BIOS detected\r
+\r
+ return -1; // CD detected but load failed\r
+}\r
+\r
int emu_ReloadRom(void)\r
{\r
unsigned int rom_size = 0;\r
+ char *used_rom_name = romFileName;\r
char ext[5];\r
FILE *rom;\r
- int ret;\r
+ int ret, cd_state;\r
\r
printf("emu_ReloadRom(%s)\n", romFileName);\r
\r
- // detect wrong extensions\r
- get_ext(ext);\r
+ get_ext(romFileName, ext);\r
\r
+ // detect wrong extensions\r
if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz\r
sprintf(menuErrorMsg, "Not a ROM selected.");\r
return 0;\r
sprintf(menuErrorMsg, "Could't find a ROM for movie.");\r
return 0;\r
}\r
- get_ext(ext);\r
+ get_ext(romFileName, ext);\r
}\r
\r
- rom = fopen(romFileName, "rb");\r
+ // check for MegaCD image\r
+ cd_state = cd_check(ext, &used_rom_name);\r
+ if (cd_state > 0) {\r
+ PicoMCD |= 1;\r
+ get_ext(used_rom_name, ext);\r
+ } else if (cd_state == -1) {\r
+ // bios_help() ?\r
+ return 0;\r
+ } else {\r
+ PicoMCD &= ~1;\r
+ }\r
+\r
+ rom = fopen(used_rom_name, "rb");\r
if(!rom) {\r
sprintf(menuErrorMsg, "Failed to open rom.");\r
return 0;\r
// zipfile support\r
if(!strcasecmp(ext, ".zip")) {\r
fclose(rom);\r
- ret = CartLoadZip(romFileName, &rom_data, &rom_size);\r
+ ret = CartLoadZip(used_rom_name, &rom_data, &rom_size);\r
if(ret) {\r
- if (ret == 4) strcpy(menuErrorMsg, "No ROMs in zip found.");\r
+ if (ret == 4) strcpy(menuErrorMsg, "No ROMs found in zip.");\r
else sprintf(menuErrorMsg, "Unzip failed with code %i", ret);\r
printf("%s\n", menuErrorMsg);\r
return 0;\r
return 0;\r
}\r
\r
+ // load config for this ROM (do this before insert to get correct region)\r
+ ret = emu_ReadConfig(1);\r
+ if (!ret)\r
+ emu_ReadConfig(0);\r
+\r
printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
if(PicoCartInsert(rom_data, rom_size)) {\r
sprintf(menuErrorMsg, "Failed to load ROM.");\r
return 0;\r
}\r
\r
- // load config for this ROM\r
- ret = emu_ReadConfig(1);\r
- if (!ret)\r
- emu_ReadConfig(0);\r
+ Pico.m.frame_count = 0;\r
+\r
+ // insert CD if it was detected\r
+ if (cd_state > 0) {\r
+ ret = Insert_CD(romFileName, cd_state == 2);\r
+ if (ret != 0) {\r
+ sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
+ printf("%s\n", menuErrorMsg);\r
+ return 0;\r
+ }\r
+ }\r
\r
// emu_ReadConfig() might have messed currentConfig.lastRomFile\r
strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
if(currentConfig.EmuOpt & 1)\r
emu_SaveLoadGame(1, 1);\r
\r
- Pico.m.frame_count = 0;\r
-\r
return 1;\r
}\r
\r
int len = strlen(text)*8;\r
\r
if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
- int *p, i, h, black, white;\r
- if (PicoOpt&0x10) {\r
- black = 0x40404040; white = 0x41;\r
- } else {\r
- black = 0xe0e0e0e0; white = 0xf0;\r
- }\r
+ int *p, i, h;\r
x &= ~3; // align x\r
len = (len+3) >> 2;\r
for (h = 0; h < 8; h++) {\r
p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h));\r
- for (i = len; i; i--, p++) *p = black;\r
+ for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
}\r
- gp2x_text_out8_2(x, y, text, white);\r
+ gp2x_text_out8_2(x, y, text, 0xf0);\r
} else {\r
int *p, i, h;\r
x &= ~1; // align x\r
}\r
}\r
\r
+static void cd_leds(void)\r
+{\r
+ static int old_reg = 0;\r
+ if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change\r
+ old_reg = Pico_mcd->s68k_regs[0];\r
+\r
+ if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+ // 8-bit modes\r
+ unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
+ unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
+ *(unsigned int *)((char *)gp2x_screen + 320*2+306) =\r
+ *(unsigned int *)((char *)gp2x_screen + 320*3+306) =\r
+ *(unsigned int *)((char *)gp2x_screen + 320*4+306) = col_g;\r
+ *(unsigned int *)((char *)gp2x_screen + 320*2+312) =\r
+ *(unsigned int *)((char *)gp2x_screen + 320*3+312) =\r
+ *(unsigned int *)((char *)gp2x_screen + 320*4+312) = col_r;\r
+ } else {\r
+ // 16-bit modes\r
+ unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+306);\r
+ unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
+ unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
+ *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+ *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+ *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+ }\r
+}\r
+\r
static int EmuScan16(unsigned int num, void *sdata)\r
{\r
if (!(Pico.video.reg[1]&8)) num += 8;\r
\r
static void blit(char *fps, char *notice)\r
{\r
+ int emu_opt = currentConfig.EmuOpt;\r
+\r
if (PicoOpt&0x10) {\r
// 8bit fast renderer\r
if (Pico.m.dirtyPal) {\r
gp2x_video_setpalette(localPal, 0x40);\r
}\r
vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
- } else if (!(currentConfig.EmuOpt&0x80)) {\r
+ } else if (!(emu_opt&0x80)) {\r
// 8bit accurate renderer\r
if (Pico.m.dirtyPal) {\r
Pico.m.dirtyPal = 0;\r
vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
blockcpy(localPal+0xc0, localPal+0x40, 0x40*4);\r
+ localPal[0xc0] = 0x0000c000;\r
+ localPal[0xd0] = 0x00c00000;\r
localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
localPal[0xf0] = 0x00ffffff;\r
gp2x_video_setpalette(localPal, 0x100);\r
}\r
\r
if (notice) osd_text(4, 232, notice);\r
- if (currentConfig.EmuOpt & 2)\r
+ if (emu_opt & 2)\r
osd_text(osd_fps_x, 232, fps);\r
+ if ((emu_opt & 0x400) && (PicoMCD & 1))\r
+ cd_leds();\r
\r
//gp2x_video_wait_vsync();\r
gp2x_video_flip();\r
// clears whole screen or just the notice area (in all buffers)\r
static void clearArea(int full)\r
{\r
- if (PicoOpt&0x10) {\r
- // 8bit fast renderer\r
- if (full) gp2x_memset_all_buffers(0, 0x40, 320*240);\r
- else gp2x_memset_all_buffers(320*232, 0x40, 320*8);\r
- } else if (currentConfig.EmuOpt&0x80) {\r
+ if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+ // 8-bit renderers\r
+ if (full) gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
+ else gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
+ } else {\r
// 16bit accurate renderer\r
if (full) gp2x_memset_all_buffers(0, 0, 320*240*2);\r
else gp2x_memset_all_buffers(320*232*2, 0, 320*8*2);\r
- } else {\r
- // 8bit accurate renderer\r
- if (full) gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
- else gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
}\r
}\r
\r
static void vidResetMode(void)\r
{\r
if (PicoOpt&0x10) {\r
- localPal[0x40] = 0;\r
- localPal[0x41] = 0x00ffffff;\r
gp2x_video_changemode(8);\r
- gp2x_video_setpalette(localPal, 0x42);\r
- gp2x_memset_all_buffers(0, 0x40, 320*240);\r
- gp2x_video_flip();\r
} else if (currentConfig.EmuOpt&0x80) {\r
gp2x_video_changemode(15);\r
PicoDrawSetColorFormat(1);\r
PicoScan = EmuScan16;\r
PicoScan(0, 0);\r
} else {\r
+ gp2x_video_changemode(8);\r
+ PicoDrawSetColorFormat(2);\r
+ PicoScan = EmuScan8;\r
+ PicoScan(0, 0);\r
+ }\r
+ if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+ // setup pal for 8-bit modes\r
+ localPal[0xc0] = 0x0000c000; // MCD LEDs\r
+ localPal[0xd0] = 0x00c00000;\r
localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
localPal[0xf0] = 0x00ffffff;\r
- gp2x_video_changemode(8);\r
gp2x_video_setpalette(localPal, 0x100);\r
gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
gp2x_video_flip();\r
- PicoDrawSetColorFormat(2);\r
- PicoScan = EmuScan8;\r
- PicoScan(0, 0);\r
}\r
Pico.m.dirtyPal = 1;\r
// reset scaling\r
char lastRomFile[512];\r
int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,\r
// squidgehack, save_cfg_on_exit, <unused>, 16_bit_mode\r
- // craigix_ram, confirm_save\r
+ // craigix_ram, confirm_save, show_cd_leds, enable_cdda\r
+ // enable_pcm\r
int PicoOpt; // used for config saving only, see Pico.h\r
int PsndRate; // ditto\r
int PicoRegion; // ditto\r
void emu_ResetGame(void);\r
int emu_ReadConfig(int game);\r
int emu_WriteConfig(int game);\r
+int find_bios(int region, char **bios_file);\r
+\r
\r
\r
\r
-\r
-// --------- advanced options ----------\r
-\r
// order must match that of currentConfig_t\r
+\r
struct {\r
int EmuOpt;\r
int PicoOpt;\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
+{\r
+ int tl_x = 25, tl_y = 60, y;\r
+\r
+ y = tl_y;\r
+ memset(gp2x_screen, 0, 320*240);\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), "Done");\r
+\r
+ // draw cursor\r
+ gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+\r
+ if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) ||\r
+ (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) ||\r
+ (menu_sel == 2 && strcmp(b_jp, "NOT FOUND")))\r
+ gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r
+\r
+ gp2x_video_flip();\r
+}\r
+\r
+static void cd_menu_loop_options(void)\r
+{\r
+ int menu_sel = 0, menu_sel_max = 5;\r
+ unsigned long inp = 0;\r
+ char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;\r
+\r
+ if (find_bios(4, &bios)) { // US\r
+ for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
+ strncpy(bios_us, p, 31); bios_us[31] = 0;\r
+ } else strcpy(bios_us, "NOT FOUND");\r
+\r
+ if (find_bios(8, &bios)) { // EU\r
+ for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
+ strncpy(bios_eu, p, 31); bios_eu[31] = 0;\r
+ } else strcpy(bios_eu, "NOT FOUND");\r
+\r
+ if (find_bios(1, &bios)) { // JP\r
+ for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
+ strncpy(bios_jp, p, 31); bios_jp[31] = 0;\r
+ } else strcpy(bios_jp, "NOT FOUND");\r
+\r
+ for(;;)\r
+ {\r
+ draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);\r
+ inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r
+ if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\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: return;\r
+ }\r
+ }\r
+ if(inp & (GP2X_X|GP2X_A)) return;\r
+ if(inp & GP2X_START) { // BIOS testers\r
+ switch (menu_sel) {\r
+ case 0: if (find_bios(4, &bios)) { // test US\r
+ strcpy(romFileName, bios);\r
+ engineState = PGS_ReloadRom;\r
+ return;\r
+ }\r
+ break;\r
+ case 1: if (find_bios(8, &bios)) { // test EU\r
+ strcpy(romFileName, bios);\r
+ engineState = PGS_ReloadRom;\r
+ return;\r
+ }\r
+ break;\r
+ case 2: if (find_bios(1, &bios)) { // test JP\r
+ strcpy(romFileName, bios);\r
+ engineState = PGS_ReloadRom;\r
+ return;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+\r
+// --------- advanced options ----------\r
+\r
static void draw_amenu_options(int menu_sel)\r
{\r
int tl_x = 25, tl_y = 60, y;\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 savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10\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), "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), "[advanced options]");\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
if (rom_data)\r
gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");\r
}\r
}\r
\r
-static void menu_loop_options(void)\r
+static int menu_loop_options(void)\r
{\r
- int menu_sel = 0, menu_sel_max = 15;\r
+ int menu_sel = 0, menu_sel_max = 16;\r
unsigned long inp = 0;\r
\r
if (rom_data) menu_sel_max++;\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 14: amenu_loop_options(); break;\r
- case 15: // done (save)\r
+ case 14: cd_menu_loop_options();\r
+ if (engineState == PGS_ReloadRom)\r
+ return 0; // test BIOS\r
+ break;\r
+ case 15: amenu_loop_options(); break;\r
+ case 16: // done (update and write)\r
menu_options_save();\r
- emu_WriteConfig(0);\r
- return;\r
- case 16: // done (save for current game)\r
+ if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r
+ else strcpy(menuErrorMsg, "failed to write config");\r
+ return 1;\r
+ case 17: // done (update and write for current game)\r
menu_options_save();\r
- emu_WriteConfig(1);\r
- return;\r
+ if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r
+ else strcpy(menuErrorMsg, "failed to write config");\r
+ return 1;\r
}\r
}\r
- if(inp & GP2X_X) return; // done (no save)\r
+ if(inp & GP2X_X) return 0; // done (no update or write)\r
if(inp & GP2X_A) {\r
menu_options_save();\r
- return; // done (save)\r
+ return 0; // done (update, no write)\r
}\r
if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
switch (menu_sel) {\r
\r
static void menu_loop_root(void)\r
{\r
- int menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;\r
+ int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;\r
unsigned long inp = 0;\r
char curr_path[PATH_MAX], *selfname;\r
FILE *tstf;\r
selfname = romsel_loop(curr_path);\r
if (selfname) {\r
printf("selected file: %s\n", selfname);\r
- strncpy(currentConfig.lastRomFile, selfname, sizeof(currentConfig.lastRomFile)-1);\r
- currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
engineState = PGS_ReloadRom;\r
}\r
return;\r
case 5: // options\r
- menu_loop_options();\r
+ ret = menu_loop_options();\r
+ if (ret == 1) continue; // status update\r
+ if (engineState == PGS_ReloadRom)\r
+ return; // BIOS test\r
break;\r
case 6: // controls\r
kc_sel_loop();\r
../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
# Pico - CD
OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \
- ../../Pico/cd/cd_sys.o
+ ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o
# Pico - sound
OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o
# zlib