From bf098bc53228f6b5016cb4a6126f4466bfba4e00 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 8 Jan 2007 21:17:08 +0000 Subject: [PATCH] ISO loading, menus, LEDs git-svn-id: file:///home/notaz/opt/svn/PicoDrive@16 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Cart.c | 38 +++-- Pico/Pico.c | 4 +- Pico/VideoPort.c | 2 +- Pico/cd/LC89510.c | 181 +++++++++------------- Pico/cd/LC89510.h | 7 +- Pico/cd/Memory.c | 151 +++++++++++++------ Pico/cd/Pico.c | 21 ++- Pico/cd/cd_file.c | 326 ++++++++++++++++++++++++++++++++++++++++ Pico/cd/cd_file.h | 38 +++++ Pico/cd/cd_sys.c | 60 ++------ Pico/cd/cd_sys.h | 2 +- platform/gp2x/emu.c | 236 +++++++++++++++++++++++------ platform/gp2x/emu.h | 5 +- platform/gp2x/menu.c | 134 ++++++++++++++--- platform/linux/Makefile | 2 +- 15 files changed, 913 insertions(+), 294 deletions(-) create mode 100644 Pico/cd/cd_file.c create mode 100644 Pico/cd/cd_file.h diff --git a/Pico/Cart.c b/Pico/Cart.c index 18461a2c..d3e77438 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -57,18 +57,21 @@ static int DecodeSmd(unsigned char *data,int len) return 0; } +static unsigned char *cd_realloc(void *old, int filesize) +{ + unsigned char *rom; + dprintf("sizeof(mcd_state): %i", sizeof(mcd_state)); + rom=realloc(old, sizeof(mcd_state)); + if (rom) memset(rom+0x20000, 0, sizeof(mcd_state)-0x20000); + return rom; +} + static unsigned char *PicoCartAlloc(int filesize) { int alloc_size; unsigned char *rom; - if (PicoMCD & 1) { - dprintf("sizeof(mcd_state): %i", sizeof(mcd_state)); - if (filesize > 0x20000) return NULL; // invalid BIOS - rom=(unsigned char *)malloc(sizeof(mcd_state)); - if (rom) memset(rom, 0, sizeof(mcd_state)); - return rom; - } + if (PicoMCD & 1) return cd_realloc(NULL, filesize); alloc_size=filesize+0x7ffff; if((filesize&0x3fff)==0x200) alloc_size-=0x200; @@ -90,19 +93,19 @@ int PicoCartLoad(FILE *f,unsigned char **prom,unsigned int *psize) fseek(f,0,SEEK_END); size=ftell(f); fseek(f,0,SEEK_SET); if (size <= 0) return 1; - if (PicoMCD & 1) { - if (size > 0x20000) return 1; // invalid BIOS - size = 0xe0000; - } else { - size=(size+3)&~3; // Round up to a multiple of 4 - } + size=(size+3)&~3; // Round up to a multiple of 4 // Allocate space for the rom plus padding rom=PicoCartAlloc(size); if (rom==NULL) return 1; // { fclose(f); return 1; } fread(rom,1,size,f); // Load up the rom - // fclose(f); // this is confusing. From now on, caller should close it, because it opened this. + + // maybe we are loading MegaCD BIOS? + if (!(PicoMCD&1) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) { + PicoMCD |= 1; + rom = cd_realloc(rom, size); + } // Check for SMD: if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD @@ -184,6 +187,13 @@ int CartLoadZip(const char *fname, unsigned char **prom, unsigned int *psize) closezip(zipfile); + // maybe we are loading MegaCD BIOS? + if (!(PicoMCD&1) && size == 0x20000 && + (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) { + PicoMCD |= 1; + rom = cd_realloc(rom, size); + } + // Check for SMD: if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD else Byteswap(rom,size); // Just byteswap diff --git a/Pico/Pico.c b/Pico/Pico.c index 90b06d6e..bd21a569 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -22,8 +22,8 @@ void (*PicoWriteSound)(void) = 0; // called once per frame at the best time to s struct PicoSRAM SRam; int z80startCycle = 0, z80stopCycle = 0; // in 68k cycles //int z80ExtraCycles = 0; -int PicoPad[2]; // Joypads, format is SACB RLDU -int PicoMCD = 1; // mega CD status: scd_started +int PicoPad[2]; // Joypads, format is SACB RLDU +int PicoMCD = 0; // mega CD status: scd_started, reset_pending // to be called once on emu init int PicoInit(void) diff --git a/Pico/VideoPort.c b/Pico/VideoPort.c index 527f2f03..537e917a 100644 --- a/Pico/VideoPort.c +++ b/Pico/VideoPort.c @@ -359,7 +359,7 @@ unsigned int PicoVideoRead(unsigned int a) if(Pico.m.rotate++&8) d|=0x0100; else d|=0x0200; // Toggle fifo full empty (who uses that stuff?) if(!(Pico.video.reg[1]&0x40)) d|=0x0008; // set V-Blank if display is disabled if(SekCyclesLeft < 84+4) d|=0x0004; // H-Blank (Sonic3 vs) - dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone()); + // dprintf("sr_read %04x @ %06x [%i|%i]", d, SekPc, Pico.m.scanline, SekCyclesDone()); Pico.video.pending=0; // ctrl port reads clear write-pending flag (Charles MacDonald) diff --git a/Pico/cd/LC89510.c b/Pico/cd/LC89510.c index 96d0966c..91b44442 100644 --- a/Pico/cd/LC89510.c +++ b/Pico/cd/LC89510.c @@ -1,13 +1,11 @@ -#if 0 -#include -#include -#include "misc.h" -#include "lc89510.h" -#include "cd_aspi.h" -#include "Star_68k.h" -#include "mem_S68k.h" -#include "pcm.h" -#endif +/*********************************************************** + * * + * This source is taken from the Gens project * + * Written by Stéphane Dallongeville * + * Copyright (c) 2002 by Stéphane Dallongeville * + * Modified/adapted for Picodrive by notaz, 2007 * + * * + ***********************************************************/ #include "../PicoInt.h" @@ -18,7 +16,7 @@ #define CDC_DMA_SPEED 256 int CDC_Decode_Reg_Read; -static int Status_CDC; // internal status +static int Status_CDC; // internal status (TODO: 2 context?) static void CDD_Reset(void) @@ -73,129 +71,90 @@ void LC89510_Reset(void) Pico_mcd->cdc.Stop_Watch = 0; } -#if 0 // TODO -void Update_CDC_TRansfer(void) -{ - unsigned int i, dep, lenght, add_dest; - unsigned char *dest; - - if ((Status_CDC & 0x08) == 0) return; - - switch(Pico_mcd->s68k_regs[4] & 7) - { - case 0x0200: // MAIN CPU - case 0x0300: // SUB CPU - Pico_mcd->s68k_regs[4] |= 0x40; // Data ready in host port - return; - - case 0x0400: // PCM RAM - dest = (unsigned char *) Ram_PCM; - dep = ((Pico_mcd->cdc.DMA_Adr & 0x03FF) << 2) + PCM_Chip.Bank; - add_dest = 2; - break; - - case 0x0500: // PRG RAM - dest = (unsigned char *) Ram_Prg; - dep = (Pico_mcd->cdc.DMA_Adr & 0xFFFF) << 3; - add_dest = 2; -// cdprintf("DMA transfer PRG RAM : adr = %.8X ", dep); - break; - case 0x0700: // WORD RAM - if (Ram_Word_State >= 2) - { - dest = (unsigned char *) Ram_Word_1M; - add_dest = 2; - if (Ram_Word_State & 1) dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 3); - else dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 3) + 0x20000; - } - else - { - dest = (unsigned char *) Ram_Word_2M; - dep = ((Pico_mcd->cdc.DMA_Adr & 0x7FFF) << 3); - add_dest = 2; - } - break; - - default: - return; - } +void Update_CDC_TRansfer(int which) +{ + unsigned int dep, length, len; + unsigned short *dest; + unsigned char *src; if (Pico_mcd->cdc.DBC.N <= (CDC_DMA_SPEED * 2)) { - lenght = (Pico_mcd->cdc.DBC.N + 1) >> 1; - Status_CDC &= ~0x08; // Last transfer - Pico_mcd->s68k_regs[4] |= 0x80; // End data transfer - Pico_mcd->s68k_regs[4] &= ~0x40; // no more data ready - Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress + length = (Pico_mcd->cdc.DBC.N + 1) >> 1; + Status_CDC &= ~0x08; // Last transfer + Pico_mcd->s68k_regs[4] |= 0x80; // End data transfer + Pico_mcd->s68k_regs[4] &= ~0x40; // no more data ready + Pico_mcd->cdc.IFSTAT |= 0x08; // No more data transfer in progress - if (Pico_mcd->cdc.IFCTRL & 0x40) // DTEIEN = Data Trasnfer End Interrupt Enable ? + if (Pico_mcd->cdc.IFCTRL & 0x40) // DTEIEN = Data Trasnfer End Interrupt Enable ? { Pico_mcd->cdc.IFSTAT &= ~0x40; - if (Int_Mask_S68K & 0x20) sub68k_interrupt(5, -1); - - cdprintf("CDC - DTE interrupt\n"); + if (Pico_mcd->s68k_regs[0x33] & (1<<5)) + { + dprintf("cdc DTE irq 5"); + SekInterruptS68k(5); + } } } - else lenght = CDC_DMA_SPEED; + else length = CDC_DMA_SPEED; + -// cdprintf("DMA lenght = %.4X\n", lenght); + // TODO: dst bounds checking? DAC.N alignment? + src = Pico_mcd->cdc.Buffer + Pico_mcd->cdc.DAC.N; - if ((Pico_mcd->s68k_regs[4] & 7) == 4) // PCM DMA + if (which == 7) // WORD RAM { - __asm + if (Pico_mcd->s68k_regs[3] & 4) { - mov ecx, lenght - mov edi, dest - lea esi, Pico_mcd->cdc.Buffer - add edi, dep - add esi, Pico_mcd->cdc.DAC.N - mov ebx, add_dest - - Loop_DMA_PCM: - mov ax, [esi] - add esi, 2 - mov [edi], ax - add edi, ebx - dec ecx - jnz Loop_DMA_PCM + dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 3); + cdprintf("CD DMA # %04x -> word_ram1M # %06x, len=%i", + Pico_mcd->cdc.DAC.N, dep, length); + + dep = ((Pico_mcd->cdc.DMA_Adr & 0x3FFF) << 4); + if (!(Pico_mcd->s68k_regs[3]&1)) dep += 2; + dest = (unsigned short *) (Pico_mcd->word_ram + dep); + + for (len = length; len > 0; len--, src+=2, dest+=2) + *dest = (src[0]<<8) | src[1]; } + else + { + dep = ((Pico_mcd->cdc.DMA_Adr & 0x7FFF) << 3); + cdprintf("CD DMA # %04x -> word_ram2M # %06x, len=%i", + Pico_mcd->cdc.DAC.N, dep, length); + dest = (unsigned short *) (Pico_mcd->word_ram + dep); - lenght <<= 1; - Pico_mcd->cdc.DMA_Adr += lenght >> 2; + for (len = length; len > 0; len--, src+=2, dest++) + *dest = (src[0]<<8) | src[1]; + } } - else // OTHER DMA + else if (which == 4) // PCM RAM { - __asm - { - mov ecx, lenght - mov edi, dest - lea esi, Pico_mcd->cdc.Buffer - add edi, dep - add esi, Pico_mcd->cdc.DAC.N - mov ebx, add_dest - - Loop_DMA: - mov ax, [esi] - add esi, 2 - rol ax, 8 - mov [edi], ax - add edi, ebx - dec ecx - jnz Loop_DMA - } +#if 0 + dest = (unsigned char *) Ram_PCM; + dep = ((Pico_mcd->cdc.DMA_Adr & 0x03FF) << 2) + PCM_Chip.Bank; +#else + cdprintf("TODO: PCM Dma"); +#endif + } + else if (which == 5) // PRG RAM + { + dep = (Pico_mcd->cdc.DMA_Adr & 0xFFFF) << 3; + dest = (unsigned short *) (Pico_mcd->prg_ram + dep); + cdprintf("CD DMA # %04x -> prg_ram # %06x, len=%i", + Pico_mcd->cdc.DAC.N, dep, length); - lenght <<= 1; - Pico_mcd->cdc.DMA_Adr += lenght >> 3; + for (len = length; len > 0; len--, src+=2, dest++) + *dest = (src[0]<<8) | src[1]; } - Pico_mcd->cdc.DAC.N = (Pico_mcd->cdc.DAC.N + lenght) & 0xFFFF; - if (Status_CDC & 0x08) Pico_mcd->cdc.DBC.N -= lenght; + length <<= 1; + Pico_mcd->cdc.DAC.N = (Pico_mcd->cdc.DAC.N + length) & 0xFFFF; + if (Status_CDC & 0x08) Pico_mcd->cdc.DBC.N -= length; else Pico_mcd->cdc.DBC.N = 0; } -#endif unsigned short Read_CDC_Host(int is_sub) @@ -592,7 +551,7 @@ void CDD_Import_Command(void) Get_Current_Track_CDD_c22(); break; - case 0x3: // get total lenght (MSF format) + case 0x3: // get total length (MSF format) Pico_mcd->cdd.Status = (Pico_mcd->cdd.Status & 0xFF00) | 3; Get_Total_Lenght_CDD_c23(); break; diff --git a/Pico/cd/LC89510.h b/Pico/cd/LC89510.h index 7a0fa5e2..11001491 100644 --- a/Pico/cd/LC89510.h +++ b/Pico/cd/LC89510.h @@ -7,6 +7,7 @@ extern "C" { typedef struct { + unsigned char Buffer[(32 * 1024 * 2) + 2352]; unsigned int Host_Data; unsigned int DMA_Adr; unsigned int Stop_Watch; @@ -87,7 +88,6 @@ typedef struct } B; unsigned int N; } CTRL; - unsigned char Buffer[(32 * 1024 * 2) + 2352]; } CDC; typedef struct @@ -110,7 +110,7 @@ extern int CDC_Decode_Reg_Read; void LC89510_Reset(void); unsigned short Read_CDC_Host(int is_sub); -void Update_CDC_TRansfer(void); +void Update_CDC_TRansfer(int which); void CDC_Update_Header(void); unsigned char CDC_Read_Reg(void); @@ -119,9 +119,6 @@ void CDC_Write_Reg(unsigned char Data); void CDD_Export_Status(void); void CDD_Import_Command(void); -unsigned char SCD_Read_Byte(unsigned int Adr); -unsigned short SCD_Read_Word(unsigned int Adr); - #ifdef __cplusplus }; #endif diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index 49b11136..78602144 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -42,6 +42,7 @@ static u32 m68k_reg_read16(u32 a, int realsize) goto end; case 2: d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0xc7); + dprintf("m68k_regs r3: %02x @%06x", (u8)d, SekPc); goto end; case 8: dprintf("m68k host data read"); @@ -96,6 +97,7 @@ static void m68k_reg_write8(u32 a, u32 d, int realsize) Pico_mcd->s68k_regs[2] = d; // really use s68k side register return; case 3: + dprintf("m68k_regs w3: %02x @%06x", (u8)d, SekPc); d &= 0xc2; if ((Pico_mcd->s68k_regs[3]>>6) != ((d>>6)&3)) dprintf("m68k: prg bank: %i -> %i", (Pico_mcd->s68k_regs[a]>>6), ((d>>6)&3)); @@ -143,6 +145,7 @@ static u32 s68k_reg_read16(u32 a, int realsize) d = 1; goto end; // ver = 0, not in reset state case 2: d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0x1f); + dprintf("s68k_regs r3: %02x @%06x", (u8)d, SekPc); goto end; case 6: d = CDC_Read_Reg(); @@ -178,6 +181,7 @@ static void s68k_reg_write8(u32 a, u32 d, int realsize) case 2: return; // only m68k can change WP case 3: + dprintf("s68k_regs w3: %02x @%06x", (u8)d, SekPc); d &= 0x1d; if (d&4) { d |= Pico_mcd->s68k_regs[3]&0xc2; @@ -457,7 +461,13 @@ u8 PicoReadM68k8(u32 a) if ((a&0xfc0000)==0x200000) { dprintf("m68k_wram r8: [%06x] @%06x", a, SekPc); if (Pico_mcd->s68k_regs[3]&4) { // 1M mode? - // TODO + if (a >= 0x220000) { + dprintf("cell"); + } else { + a=((a&0x1fffe)<<1)|(a&1); + if (Pico_mcd->s68k_regs[3]&1) a+=2; + d = Pico_mcd->word_ram[a^1]; + } } else { // allow access in any mode, like Gens does d = Pico_mcd->word_ram[(a^1)&0x3ffff]; @@ -468,13 +478,13 @@ u8 PicoReadM68k8(u32 a) if ((a&0xff4000)==0xa00000) { d=z80Read8(a); goto end; } // Z80 Ram - if ((a&0xffffc0)==0xa12000) - dprintf("m68k_regs r8: [%02x] @%06x", a&0x3f, SekPc); + //if ((a&0xffffc0)==0xa12000) + // dprintf("m68k_regs r8: [%02x] @%06x", a&0x3f, SekPc); d=OtherRead16(a&~1, 8|(a&1)); if ((a&1)==0) d>>=8; - if ((a&0xffffc0)==0xa12000) - dprintf("ret = %02x", (u8)d); + //if ((a&0xffffc0)==0xa12000) + // dprintf("ret = %02x", (u8)d); end: @@ -505,7 +515,13 @@ u16 PicoReadM68k16(u32 a) if ((a&0xfc0000)==0x200000) { dprintf("m68k_wram r16: [%06x] @%06x", a, SekPc); if (Pico_mcd->s68k_regs[3]&4) { // 1M mode? - // TODO + if (a >= 0x220000) { + dprintf("cell"); + } else { + a=((a&0x1fffe)<<1); + if (Pico_mcd->s68k_regs[3]&1) a+=2; + d = *(u16 *)(Pico_mcd->word_ram+a); + } } else { // allow access in any mode, like Gens does d = *(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); @@ -514,13 +530,13 @@ u16 PicoReadM68k16(u32 a) goto end; } - if ((a&0xffffc0)==0xa12000) - dprintf("m68k_regs r16: [%02x] @%06x", a&0x3f, SekPc); + //if ((a&0xffffc0)==0xa12000) + // dprintf("m68k_regs r16: [%02x] @%06x", a&0x3f, SekPc); d = (u16)OtherRead16(a, 16); - if ((a&0xffffc0)==0xa12000) - dprintf("ret = %04x", d); + //if ((a&0xffffc0)==0xa12000) + // dprintf("ret = %04x", d); end: @@ -552,7 +568,15 @@ u32 PicoReadM68k32(u32 a) if ((a&0xfc0000)==0x200000) { dprintf("m68k_wram r32: [%06x] @%06x", a, SekPc); if (Pico_mcd->s68k_regs[3]&4) { // 1M mode? - // TODO + if (a >= 0x220000) { + dprintf("cell"); + } else { + u16 *pm; + a=((a&0x1fffe)<<1); + if (Pico_mcd->s68k_regs[3]&1) a+=2; + pm=(u16 *)(Pico_mcd->word_ram+a); + d = (pm[0]<<16)|pm[1]; + } } else { // allow access in any mode, like Gens does u16 *pm=(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); d = (pm[0]<<16)|pm[1]; @@ -561,13 +585,13 @@ u32 PicoReadM68k32(u32 a) goto end; } - if ((a&0xffffc0)==0xa12000) - dprintf("m68k_regs r32: [%02x] @%06x", a&0x3f, SekPc); + //if ((a&0xffffc0)==0xa12000) + // dprintf("m68k_regs r32: [%02x] @%06x", a&0x3f, SekPc); d = (OtherRead16(a, 32)<<16)|OtherRead16(a+2, 32); - if ((a&0xffffc0)==0xa12000) - dprintf("ret = %08x", d); + //if ((a&0xffffc0)==0xa12000) + // dprintf("ret = %08x", d); end: #ifdef __debug_io @@ -595,8 +619,7 @@ void PicoWriteM68k8(u32 a,u8 d) // prg RAM if ((a&0xfe0000)==0x020000) { u8 *prg_bank = Pico_mcd->prg_ram_b[Pico_mcd->s68k_regs[3]>>6]; - u8 *pm=(u8 *)(prg_bank+((a^1)&0x1ffff)); - *pm=d; + *(u8 *)(prg_bank+((a^1)&0x1ffff))=d; return; } @@ -604,17 +627,22 @@ void PicoWriteM68k8(u32 a,u8 d) if ((a&0xfc0000)==0x200000) { dprintf("m68k_wram w8: [%06x] %02x @%06x", a, d, SekPc); if (Pico_mcd->s68k_regs[3]&4) { // 1M mode? - // TODO + if (a >= 0x220000) { + dprintf("cell"); + } else { + a=((a&0x1fffe)<<1)|(a&1); + if (Pico_mcd->s68k_regs[3]&1) a+=2; + *(u8 *)(Pico_mcd->word_ram+(a^1))=d; + } } else { // allow access in any mode, like Gens does - u8 *pm=(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff)); - *pm=d; + *(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff))=d; } return; } - if ((a&0xffffc0)==0xa12000) - dprintf("m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc); + //if ((a&0xffffc0)==0xa12000) + // dprintf("m68k_regs w8: [%02x] %02x @%06x", a&0x3f, d, SekPc); OtherWrite8(a,d,8); } @@ -624,7 +652,6 @@ void PicoWriteM68k16(u32 a,u16 d) #ifdef __debug_io dprintf("w16: %06x, %04x", a&0xffffff, d); #endif - //if ((a&0xe0ffff)==0xe0AF0E+0x69c||(a&0xe0ffff)==0xe0A9A8+0x69c||(a&0xe0ffff)==0xe0A9AA+0x69c||(a&0xe0ffff)==0xe0A9AC+0x69c) // dprintf("w16: %06x, %04x @%06x", a&0xffffff, d, SekPc); if ((a&0xe00000)==0xe00000) { *(u16 *)(Pico.ram+(a&0xfffe))=d; return; } // Ram @@ -642,7 +669,13 @@ void PicoWriteM68k16(u32 a,u16 d) if ((a&0xfc0000)==0x200000) { dprintf("m68k_wram w16: [%06x] %04x @%06x", a, d, SekPc); if (Pico_mcd->s68k_regs[3]&4) { // 1M mode? - // TODO + if (a >= 0x220000) { + dprintf("cell"); + } else { + a=((a&0x1fffe)<<1); + if (Pico_mcd->s68k_regs[3]&1) a+=2; + *(u16 *)(Pico_mcd->word_ram+a)=d; + } } else { // allow access in any mode, like Gens does *(u16 *)(Pico_mcd->word_ram+(a&0x3fffe))=d; @@ -650,8 +683,8 @@ void PicoWriteM68k16(u32 a,u16 d) return; } - if ((a&0xffffc0)==0xa12000) - dprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc); + //if ((a&0xffffc0)==0xa12000) + // dprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc); OtherWrite16(a,d); } @@ -685,7 +718,15 @@ void PicoWriteM68k32(u32 a,u32 d) if (d != 0) // don't log clears dprintf("m68k_wram w32: [%06x] %08x @%06x", a, d, SekPc); if (Pico_mcd->s68k_regs[3]&4) { // 1M mode? - // TODO + if (a >= 0x220000) { + dprintf("cell"); + } else { + u16 *pm; + a=((a&0x1fffe)<<1); + if (Pico_mcd->s68k_regs[3]&1) a+=2; + pm=(u16 *)(Pico_mcd->word_ram+a); + pm[0]=(u16)(d>>16); pm[1]=(u16)d; + } } else { // allow access in any mode, like Gens does u16 *pm=(u16 *)(Pico_mcd->word_ram+(a&0x3fffe)); @@ -694,8 +735,8 @@ void PicoWriteM68k32(u32 a,u32 d) return; } - if ((a&0xffffc0)==0xa12000) - dprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc); + //if ((a&0xffffc0)==0xa12000) + // dprintf("m68k_regs w32: [%02x] %08x @%06x", a&0x3f, d, SekPc); OtherWrite16(a, (u16)(d>>16)); OtherWrite16(a+2,(u16)d); @@ -719,9 +760,9 @@ u8 PicoReadS68k8(u32 a) // regs if ((a&0xfffe00) == 0xff8000) { - dprintf("s68k_regs r8: [%02x] @ %06x", a&0x1ff, SekPcS68k); + //dprintf("s68k_regs r8: [%02x] @ %06x", a&0x1ff, SekPcS68k); d = s68k_reg_read16(a&~1, 8|(a&1)); if ((a&1)==0) d>>=8; - dprintf("ret = %02x", (u8)d); + //dprintf("ret = %02x", (u8)d); goto end; } @@ -742,7 +783,10 @@ u8 PicoReadS68k8(u32 a) // word RAM (1M area) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff dprintf("s68k_wram1M r8: [%06x] @%06x", a, SekPc); - // TODO + a=((a&0x1fffe)<<1)|(a&1); + if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; + d = Pico_mcd->word_ram[a^1]; + dprintf("ret = %02x", (u8)d); goto end; } @@ -770,9 +814,9 @@ u16 PicoReadS68k16(u32 a) // regs if ((a&0xfffe00) == 0xff8000) { - dprintf("s68k_regs r16: [%02x] @ %06x", a&0x1fe, SekPcS68k); + //dprintf("s68k_regs r16: [%02x] @ %06x", a&0x1fe, SekPcS68k); d = s68k_reg_read16(a, 16); - dprintf("ret = %04x", d); + //dprintf("ret = %04x", d); goto end; } @@ -793,7 +837,10 @@ u16 PicoReadS68k16(u32 a) // word RAM (1M area) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff dprintf("s68k_wram1M r16: [%06x] @%06x", a, SekPc); - // TODO + a=((a&0x1fffe)<<1); + if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; + d = *(u16 *)(Pico_mcd->word_ram+a); + dprintf("ret = %04x", (u8)d); goto end; } @@ -822,9 +869,9 @@ u32 PicoReadS68k32(u32 a) // regs if ((a&0xfffe00) == 0xff8000) { - dprintf("s68k_regs r32: [%02x] @ %06x", a&0x1fe, SekPcS68k); + //dprintf("s68k_regs r32: [%02x] @ %06x", a&0x1fe, SekPcS68k); d = (s68k_reg_read16(a, 32)<<16)|s68k_reg_read16(a+2, 32); - dprintf("ret = %08x", d); + //dprintf("ret = %08x", d); goto end; } @@ -844,8 +891,13 @@ u32 PicoReadS68k32(u32 a) // word RAM (1M area) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff + u16 *pm; dprintf("s68k_wram1M 32: [%06x] @%06x", a, SekPc); - // TODO + a=((a&0x1fffe)<<1); + if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; + pm=(u16 *)(Pico_mcd->word_ram+a); + d = (pm[0]<<16)|pm[1]; + dprintf("ret = %08x", (u8)d); goto end; } @@ -881,7 +933,7 @@ void PicoWriteS68k8(u32 a,u8 d) // regs if ((a&0xfffe00) == 0xff8000) { - dprintf("s68k_regs w8: [%02x] %02x @ %06x", a&0x1ff, d, SekPcS68k); + //dprintf("s68k_regs w8: [%02x] %02x @ %06x", a&0x1ff, d, SekPcS68k); s68k_reg_write8(a,d,8); return; } @@ -894,8 +946,7 @@ void PicoWriteS68k8(u32 a,u8 d) dprintf("(decode)"); } else { // allow access in any mode, like Gens does - u8 *pm=(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff)); - *pm=d; + *(u8 *)(Pico_mcd->word_ram+((a^1)&0x3ffff))=d; } return; } @@ -904,7 +955,9 @@ void PicoWriteS68k8(u32 a,u8 d) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff if (d) dprintf("s68k_wram1M w8: [%06x] %02x @%06x", a, d, SekPc); - // TODO + a=((a&0x1fffe)<<1)|(a&1); + if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; + *(u8 *)(Pico_mcd->word_ram+(a^1))=d; return; } @@ -927,7 +980,7 @@ void PicoWriteS68k16(u32 a,u16 d) // regs if ((a&0xfffe00) == 0xff8000) { - dprintf("s68k_regs w16: [%02x] %04x @ %06x", a&0x1ff, d, SekPcS68k); + //dprintf("s68k_regs w16: [%02x] %04x @ %06x", a&0x1ff, d, SekPcS68k); s68k_reg_write8(a, d>>8, 16); s68k_reg_write8(a+1,d&0xff, 16); return; @@ -950,7 +1003,9 @@ void PicoWriteS68k16(u32 a,u16 d) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff if (d) dprintf("s68k_wram1M w16: [%06x] %04x @%06x", a, d, SekPc); - // TODO + a=((a&0x1fffe)<<1); + if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; + *(u16 *)(Pico_mcd->word_ram+a)=d; return; } @@ -974,7 +1029,7 @@ void PicoWriteS68k32(u32 a,u32 d) // regs if ((a&0xfffe00) == 0xff8000) { - dprintf("s68k_regs w32: [%02x] %08x @ %06x", a&0x1ff, d, SekPcS68k); + //dprintf("s68k_regs w32: [%02x] %08x @ %06x", a&0x1ff, d, SekPcS68k); s68k_reg_write8(a, d>>24, 32); s68k_reg_write8(a+1,(d>>16)&0xff, 32); s68k_reg_write8(a+2,(d>>8) &0xff, 32); @@ -998,9 +1053,13 @@ void PicoWriteS68k32(u32 a,u32 d) // word RAM (1M area) if ((a&0xfe0000)==0x0c0000 && (Pico_mcd->s68k_regs[3]&4)) { // 0c0000-0dffff + u16 *pm; if (d) dprintf("s68k_wram1M w32: [%06x] %08x @%06x", a, d, SekPc); - // TODO + a=((a&0x1fffe)<<1); + if (!(Pico_mcd->s68k_regs[3]&1)) a+=2; + pm=(u16 *)(Pico_mcd->word_ram+a); + pm[0]=(u16)(d>>16); pm[1]=(u16)d; return; } dprintf("s68k w32: %06x, %08x @%06x", a&0xffffff, d, SekPcS68k); diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index d9879560..013340cc 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -64,9 +64,22 @@ static __inline void SekRunS68k(int cyc) #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) @@ -115,6 +128,8 @@ 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 { diff --git a/Pico/cd/cd_file.c b/Pico/cd/cd_file.c new file mode 100644 index 00000000..1f634744 --- /dev/null +++ b/Pico/cd/cd_file.c @@ -0,0 +1,326 @@ +/* +#include +#include +#if defined(__WIN__) +#include +#else +#include "port.h" +#endif +#include "cd_sys.h" +#include "cd_file.h" +#include "lc89510.h" +#include "cdda_mp3.h" +#include "star_68k.h" +#include "rom.h" +#include "mem_s68k.h" +*/ + +#include +#include "cd_file.h" + +#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; +} + diff --git a/Pico/cd/cd_file.h b/Pico/cd/cd_file.h new file mode 100644 index 00000000..4bf9d19e --- /dev/null +++ b/Pico/cd/cd_file.h @@ -0,0 +1,38 @@ +#ifndef _CD_FILE_H +#define _CD_FILE_H + +#include + +#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 diff --git a/Pico/cd/cd_sys.c b/Pico/cd/cd_sys.c index 72d6c0ed..833680b1 100644 --- a/Pico/cd/cd_sys.c +++ b/Pico/cd/cd_sys.c @@ -1,6 +1,6 @@ #include #include "cd_sys.h" -//#include "cd_file.h" +#include "cd_file.h" #include "../PicoInt.h" @@ -15,18 +15,6 @@ #define FAST_REV 0x10300 // FAST REVERSE track CDD status #define PLAYING 0x0100 // PLAYING audio track CDD status -/* -#include "gens.h" -#include "G_dsound.h" -#include "cdda_mp3.h" -#include "lc89510.h" -#include "Star_68k.h" -#include "Mem_M68K.h" -#include "Mem_S68K.h" -#include "save.h" -#include "misc.h" -*/ - /* int CDDA_Enable; @@ -45,8 +33,6 @@ static int CDD_Complete; static int File_Add_Delay = 0; -//_scd SCD; - #define CHECK_TRAY_OPEN \ @@ -191,9 +177,7 @@ void Check_CD_Command(void) if (File_Add_Delay == 0) { -#if 0 // TODO FILE_Read_One_LBA_CDC(); -#endif } else File_Add_Delay--; } @@ -215,9 +199,7 @@ void Check_CD_Command(void) int Init_CD_Driver(void) { -#if 0 // TODO FILE_Init(); -#endif return 0; } @@ -225,9 +207,7 @@ int Init_CD_Driver(void) void End_CD_Driver(void) { -#if 0 // TODO FILE_End(); -#endif } @@ -240,33 +220,29 @@ void Reset_CD(void) } -int Insert_CD(char *buf, char *iso_name) +int Insert_CD(char *iso_name, int is_bin) { + int ret = 0; + // memset(CD_Audio_Buffer_L, 0, 4096 * 4); // memset(CD_Audio_Buffer_R, 0, 4096 * 4); - if (iso_name == NULL) - { - CD_Present = 0; - } - else + CD_Present = 0; + + if (iso_name != NULL) { -#if 0 // TODO - Load_ISO(buf, iso_name); - CD_Present = 1; -#endif - return 0; + ret = Load_ISO(iso_name, is_bin); + if (ret == 0) + CD_Present = 1; } - return 0; + return ret; } void Stop_CD(void) { -#if 0 // TODO Unload_ISO(); -#endif CD_Present = 0; } @@ -436,7 +412,7 @@ int Get_Total_Lenght_CDD_c23(void) Pico_mcd->cdd.Ext = 0; // FIXME: remove -Pico_mcd->cdd.Seconde = 2; +//Pico_mcd->cdd.Seconde = 2; CDD_Complete = 1; @@ -462,7 +438,7 @@ int Get_First_Last_Track_CDD_c24(void) Pico_mcd->cdd.Ext = 0; // FIXME: remove -Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1; +//Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1; CDD_Complete = 1; @@ -546,9 +522,7 @@ int Play_CDD_c3(void) { Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO //CD_Audio_Starting = 1; -#if 0 // TODO FILE_Play_CD_LBA(); -#endif } if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02; @@ -651,9 +625,7 @@ int Resume_CDD_c7(void) { Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO //CD_Audio_Starting = 1; -#if 0 // TODO FILE_Play_CD_LBA(); -#endif } if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02; @@ -669,7 +641,7 @@ int Resume_CDD_c7(void) } -int Fast_Foward_CDD_c8(void) +int Fast_Foward_CDD_c8(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -690,7 +662,7 @@ int Fast_Foward_CDD_c8(void) } -int Fast_Rewind_CDD_c9(void) +int Fast_Rewind_CDD_c9(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -751,9 +723,7 @@ int Open_Tray_CDD_cD(void) Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read -#if 0 // TODO Unload_ISO(); -#endif CD_Present = 0; Pico_mcd->scd.Status_CDD = TRAY_OPEN; diff --git a/Pico/cd/cd_sys.h b/Pico/cd/cd_sys.h index 34c9126f..7ec9cdaf 100644 --- a/Pico/cd/cd_sys.h +++ b/Pico/cd/cd_sys.h @@ -60,7 +60,7 @@ void Check_CD_Command(void); int Init_CD_Driver(void); void End_CD_Driver(void); -int Insert_CD(char *buf, char *iso_name); +int Insert_CD(char *iso_name, int is_bin); void Stop_CD(void); void Change_CD(void); void Reset_CD(void); diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index a90d8503..666537cb 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -96,29 +96,131 @@ static int try_rfn_cut(void) return 0; } -static void get_ext(char *ext) +static void get_ext(char *file, char *ext) { char *p; - p = romFileName + strlen(romFileName) - 4; - if (p < romFileName) p = romFileName; + p = file + strlen(file) - 4; + if (p < file) p = file; strncpy(ext, p, 4); ext[4] = 0; strlwr(ext); } +char *biosfiles_us[] = { "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210" }; +char *biosfiles_eu[] = { "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210" }; +char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" }; + +extern char **g_argv; + +int find_bios(int region, char **bios_file) +{ + static char bios_path[1024]; + int i, j, count; + char **files; + FILE *f = NULL; + + if (region == 4) { // US + files = biosfiles_us; + count = sizeof(biosfiles_us) / sizeof(char *); + } else if (region == 8) { // EU + files = biosfiles_eu; + count = sizeof(biosfiles_eu) / sizeof(char *); + } else if (region == 1 || region == 2) { + files = biosfiles_jp; + count = sizeof(biosfiles_jp) / sizeof(char *); + } else { + return 0; + } + + for (i = 0; i < count; i++) + { + strncpy(bios_path, g_argv[0], 1023); + bios_path[1024-32] = 0; + for (j = strlen(bios_path); j > 0; j--) + if (bios_path[j] == '/') { bios_path[j+1] = 0; break; } + strcat(bios_path, files[i]); + strcat(bios_path, ".bin"); + f = fopen(bios_path, "rb"); + if (f) break; + + bios_path[strlen(bios_path) - 4] = 0; + strcat(bios_path, ".zip"); + f = fopen(bios_path, "rb"); + if (f) break; + } + + if (f) { + printf("using bios: %s\n", bios_path); + fclose(f); + if (bios_file) *bios_file = bios_path; + return 1; + } else { + sprintf(menuErrorMsg, "no %s BIOS files found, read docs", + region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); + printf("%s\n", menuErrorMsg); + return 0; + } +} + +/* checks if romFileName points to valid MegaCD image + * if so, checks for suitable BIOS */ +static int cd_check(char *ext, char **bios_file) +{ + unsigned char buf[32]; + FILE *cd_f; + int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe + + cd_f = fopen(romFileName, "rb"); + if (!cd_f) return 0; // let the upper level handle this + + if (fread(buf, 1, 32, cd_f) != 32) { + fclose(cd_f); + return 0; + } + + if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1; // Sega CD (ISO) + if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2; // Sega CD (BIN) + if (type == 0) { + fclose(cd_f); + return 0; + } + + /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */ + fseek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET); + fread(buf, 1, 1, cd_f); + fclose(cd_f); + + if (buf[0] == 0x64) region = 4; // EU + if (buf[0] == 0xa1) region = 1; // JAP + + printf("detected %s Sega/Mega CD image with %s region\n", + type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); + + if (PicoRegionOverride) { + region = PicoRegionOverride; + printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); + } + + if(find_bios(region, bios_file)) + return type; // CD and BIOS detected + + return -1; // CD detected but load failed +} + int emu_ReloadRom(void) { unsigned int rom_size = 0; + char *used_rom_name = romFileName; char ext[5]; FILE *rom; - int ret; + int ret, cd_state; printf("emu_ReloadRom(%s)\n", romFileName); - // detect wrong extensions - get_ext(ext); + get_ext(romFileName, ext); + // detect wrong extensions if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz sprintf(menuErrorMsg, "Not a ROM selected."); return 0; @@ -162,10 +264,22 @@ int emu_ReloadRom(void) sprintf(menuErrorMsg, "Could't find a ROM for movie."); return 0; } - get_ext(ext); + get_ext(romFileName, ext); } - rom = fopen(romFileName, "rb"); + // check for MegaCD image + cd_state = cd_check(ext, &used_rom_name); + if (cd_state > 0) { + PicoMCD |= 1; + get_ext(used_rom_name, ext); + } else if (cd_state == -1) { + // bios_help() ? + return 0; + } else { + PicoMCD &= ~1; + } + + rom = fopen(used_rom_name, "rb"); if(!rom) { sprintf(menuErrorMsg, "Failed to open rom."); return 0; @@ -180,9 +294,9 @@ int emu_ReloadRom(void) // zipfile support if(!strcasecmp(ext, ".zip")) { fclose(rom); - ret = CartLoadZip(romFileName, &rom_data, &rom_size); + ret = CartLoadZip(used_rom_name, &rom_data, &rom_size); if(ret) { - if (ret == 4) strcpy(menuErrorMsg, "No ROMs in zip found."); + if (ret == 4) strcpy(menuErrorMsg, "No ROMs found in zip."); else sprintf(menuErrorMsg, "Unzip failed with code %i", ret); printf("%s\n", menuErrorMsg); return 0; @@ -206,16 +320,28 @@ int emu_ReloadRom(void) return 0; } + // load config for this ROM (do this before insert to get correct region) + ret = emu_ReadConfig(1); + if (!ret) + emu_ReadConfig(0); + printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size); if(PicoCartInsert(rom_data, rom_size)) { sprintf(menuErrorMsg, "Failed to load ROM."); return 0; } - // load config for this ROM - ret = emu_ReadConfig(1); - if (!ret) - emu_ReadConfig(0); + Pico.m.frame_count = 0; + + // insert CD if it was detected + if (cd_state > 0) { + ret = Insert_CD(romFileName, cd_state == 2); + if (ret != 0) { + sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?"); + printf("%s\n", menuErrorMsg); + return 0; + } + } // emu_ReadConfig() might have messed currentConfig.lastRomFile strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1); @@ -253,8 +379,6 @@ int emu_ReloadRom(void) if(currentConfig.EmuOpt & 1) emu_SaveLoadGame(1, 1); - Pico.m.frame_count = 0; - return 1; } @@ -440,19 +564,14 @@ void osd_text(int x, int y, char *text) int len = strlen(text)*8; if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { - int *p, i, h, black, white; - if (PicoOpt&0x10) { - black = 0x40404040; white = 0x41; - } else { - black = 0xe0e0e0e0; white = 0xf0; - } + int *p, i, h; x &= ~3; // align x len = (len+3) >> 2; for (h = 0; h < 8; h++) { p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h)); - for (i = len; i; i--, p++) *p = black; + for (i = len; i; i--, p++) *p = 0xe0e0e0e0; } - gp2x_text_out8_2(x, y, text, white); + gp2x_text_out8_2(x, y, text, 0xf0); } else { int *p, i, h; x &= ~1; // align x @@ -465,6 +584,33 @@ void osd_text(int x, int y, char *text) } } +static void cd_leds(void) +{ + static int old_reg = 0; + if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change + old_reg = Pico_mcd->s68k_regs[0]; + + if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + // 8-bit modes + unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; + unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; + *(unsigned int *)((char *)gp2x_screen + 320*2+306) = + *(unsigned int *)((char *)gp2x_screen + 320*3+306) = + *(unsigned int *)((char *)gp2x_screen + 320*4+306) = col_g; + *(unsigned int *)((char *)gp2x_screen + 320*2+312) = + *(unsigned int *)((char *)gp2x_screen + 320*3+312) = + *(unsigned int *)((char *)gp2x_screen + 320*4+312) = col_r; + } else { + // 16-bit modes + unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+306); + unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0; + unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0; + *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; + *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; + *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; + } +} + static int EmuScan16(unsigned int num, void *sdata) { if (!(Pico.video.reg[1]&8)) num += 8; @@ -486,6 +632,8 @@ static void (*vidCpyM2)(void *dest, void *src) = NULL; static void blit(char *fps, char *notice) { + int emu_opt = currentConfig.EmuOpt; + if (PicoOpt&0x10) { // 8bit fast renderer if (Pico.m.dirtyPal) { @@ -495,7 +643,7 @@ static void blit(char *fps, char *notice) gp2x_video_setpalette(localPal, 0x40); } vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); - } else if (!(currentConfig.EmuOpt&0x80)) { + } else if (!(emu_opt&0x80)) { // 8bit accurate renderer if (Pico.m.dirtyPal) { Pico.m.dirtyPal = 0; @@ -504,6 +652,8 @@ static void blit(char *fps, char *notice) vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40); vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40); blockcpy(localPal+0xc0, localPal+0x40, 0x40*4); + localPal[0xc0] = 0x0000c000; + localPal[0xd0] = 0x00c00000; localPal[0xe0] = 0x00000000; // reserved pixels for OSD localPal[0xf0] = 0x00ffffff; gp2x_video_setpalette(localPal, 0x100); @@ -520,8 +670,10 @@ static void blit(char *fps, char *notice) } if (notice) osd_text(4, 232, notice); - if (currentConfig.EmuOpt & 2) + if (emu_opt & 2) osd_text(osd_fps_x, 232, fps); + if ((emu_opt & 0x400) && (PicoMCD & 1)) + cd_leds(); //gp2x_video_wait_vsync(); gp2x_video_flip(); @@ -543,18 +695,14 @@ static void blit(char *fps, char *notice) // clears whole screen or just the notice area (in all buffers) static void clearArea(int full) { - if (PicoOpt&0x10) { - // 8bit fast renderer - if (full) gp2x_memset_all_buffers(0, 0x40, 320*240); - else gp2x_memset_all_buffers(320*232, 0x40, 320*8); - } else if (currentConfig.EmuOpt&0x80) { + if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + // 8-bit renderers + if (full) gp2x_memset_all_buffers(0, 0xe0, 320*240); + else gp2x_memset_all_buffers(320*232, 0xe0, 320*8); + } else { // 16bit accurate renderer if (full) gp2x_memset_all_buffers(0, 0, 320*240*2); else gp2x_memset_all_buffers(320*232*2, 0, 320*8*2); - } else { - // 8bit accurate renderer - if (full) gp2x_memset_all_buffers(0, 0xe0, 320*240); - else gp2x_memset_all_buffers(320*232, 0xe0, 320*8); } } @@ -562,27 +710,27 @@ static void clearArea(int full) static void vidResetMode(void) { if (PicoOpt&0x10) { - localPal[0x40] = 0; - localPal[0x41] = 0x00ffffff; gp2x_video_changemode(8); - gp2x_video_setpalette(localPal, 0x42); - gp2x_memset_all_buffers(0, 0x40, 320*240); - gp2x_video_flip(); } else if (currentConfig.EmuOpt&0x80) { gp2x_video_changemode(15); PicoDrawSetColorFormat(1); PicoScan = EmuScan16; PicoScan(0, 0); } else { + gp2x_video_changemode(8); + PicoDrawSetColorFormat(2); + PicoScan = EmuScan8; + PicoScan(0, 0); + } + if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + // setup pal for 8-bit modes + localPal[0xc0] = 0x0000c000; // MCD LEDs + localPal[0xd0] = 0x00c00000; localPal[0xe0] = 0x00000000; // reserved pixels for OSD localPal[0xf0] = 0x00ffffff; - gp2x_video_changemode(8); gp2x_video_setpalette(localPal, 0x100); gp2x_memset_all_buffers(0, 0xe0, 320*240); gp2x_video_flip(); - PicoDrawSetColorFormat(2); - PicoScan = EmuScan8; - PicoScan(0, 0); } Pico.m.dirtyPal = 1; // reset scaling diff --git a/platform/gp2x/emu.h b/platform/gp2x/emu.h index 33b1ae72..3c90fdcc 100644 --- a/platform/gp2x/emu.h +++ b/platform/gp2x/emu.h @@ -19,7 +19,8 @@ typedef struct { char lastRomFile[512]; int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves, // squidgehack, save_cfg_on_exit, , 16_bit_mode - // craigix_ram, confirm_save + // craigix_ram, confirm_save, show_cd_leds, enable_cdda + // enable_pcm int PicoOpt; // used for config saving only, see Pico.h int PsndRate; // ditto int PicoRegion; // ditto @@ -44,3 +45,5 @@ void emu_Loop(void); void emu_ResetGame(void); int emu_ReadConfig(int game); int emu_WriteConfig(int game); +int find_bios(int region, char **bios_file); + diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 7b18517c..1232e87d 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -562,10 +562,8 @@ static void kc_sel_loop(void) - -// --------- advanced options ---------- - // order must match that of currentConfig_t + struct { int EmuOpt; int PicoOpt; @@ -576,6 +574,94 @@ struct { } tmp_opts; int tmp_gamma; +// --------- sega/mega cd options ---------- + +static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp) +{ + int tl_x = 25, tl_y = 60, y; + + y = tl_y; + memset(gp2x_screen, 0, 320*240); + gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0 + gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1 + gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2 + gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (tmp_opts.EmuOpt &0x400)?"ON":"OFF"); // 3 + gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (tmp_opts.EmuOpt &0x800)?"ON":"OFF"); // 4 + gp2x_text_out8(tl_x, (y+=10), "Done"); + + // draw cursor + gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">"); + + if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) || + (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) || + (menu_sel == 2 && strcmp(b_jp, "NOT FOUND"))) + gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS"); + + gp2x_video_flip(); +} + +static void cd_menu_loop_options(void) +{ + int menu_sel = 0, menu_sel_max = 5; + unsigned long inp = 0; + char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p; + + if (find_bios(4, &bios)) { // US + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + strncpy(bios_us, p, 31); bios_us[31] = 0; + } else strcpy(bios_us, "NOT FOUND"); + + if (find_bios(8, &bios)) { // EU + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + strncpy(bios_eu, p, 31); bios_eu[31] = 0; + } else strcpy(bios_eu, "NOT FOUND"); + + if (find_bios(1, &bios)) { // JP + for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++; + strncpy(bios_jp, p, 31); bios_jp[31] = 0; + } else strcpy(bios_jp, "NOT FOUND"); + + for(;;) + { + draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp); + inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START); + if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } + if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } + if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options + switch (menu_sel) { + case 3: tmp_opts.EmuOpt ^=0x400; break; + case 4: return; + } + } + if(inp & (GP2X_X|GP2X_A)) return; + if(inp & GP2X_START) { // BIOS testers + switch (menu_sel) { + case 0: if (find_bios(4, &bios)) { // test US + strcpy(romFileName, bios); + engineState = PGS_ReloadRom; + return; + } + break; + case 1: if (find_bios(8, &bios)) { // test EU + strcpy(romFileName, bios); + engineState = PGS_ReloadRom; + return; + } + break; + case 2: if (find_bios(1, &bios)) { // test JP + strcpy(romFileName, bios); + engineState = PGS_ReloadRom; + return; + } + break; + } + } + } +} + + +// --------- advanced options ---------- + static void draw_amenu_options(int menu_sel) { int tl_x = 25, tl_y = 60, y; @@ -683,11 +769,12 @@ static void draw_menu_options(int menu_sel) gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (tmp_opts.PicoOpt&0x200)?"ON":"OFF"); // 7 gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (tmp_opts.PicoOpt&0x020)?"ON":"OFF"); // 8 gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(tmp_opts.PicoRegion)); - gp2x_text_out8(tl_x, (y+=10), "Use SRAM savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10 + gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10 gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (tmp_opts.EmuOpt &0x200)?"ON":"OFF"); // 11 gp2x_text_out8(tl_x, (y+=10), "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), "[advanced 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), "Save cfg as default"); if (rom_data) gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only"); @@ -726,9 +813,9 @@ static void menu_options_save(void) } } -static void menu_loop_options(void) +static int menu_loop_options(void) { - int menu_sel = 0, menu_sel_max = 15; + int menu_sel = 0, menu_sel_max = 16; unsigned long inp = 0; if (rom_data) menu_sel_max++; @@ -754,21 +841,27 @@ static void menu_loop_options(void) case 8: tmp_opts.PicoOpt^=0x020; break; case 10: tmp_opts.EmuOpt ^=0x001; break; case 11: tmp_opts.EmuOpt ^=0x200; break; - case 14: amenu_loop_options(); break; - case 15: // done (save) + case 14: cd_menu_loop_options(); + if (engineState == PGS_ReloadRom) + return 0; // test BIOS + break; + case 15: amenu_loop_options(); break; + case 16: // done (update and write) menu_options_save(); - emu_WriteConfig(0); - return; - case 16: // done (save for current game) + if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved"); + else strcpy(menuErrorMsg, "failed to write config"); + return 1; + case 17: // done (update and write for current game) menu_options_save(); - emu_WriteConfig(1); - return; + if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved"); + else strcpy(menuErrorMsg, "failed to write config"); + return 1; } } - if(inp & GP2X_X) return; // done (no save) + if(inp & GP2X_X) return 0; // done (no update or write) if(inp & GP2X_A) { menu_options_save(); - return; // done (save) + return 0; // done (update, no write) } if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise switch (menu_sel) { @@ -882,7 +975,7 @@ static void draw_menu_root(int menu_sel) static void menu_loop_root(void) { - int menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4; + int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4; unsigned long inp = 0; char curr_path[PATH_MAX], *selfname; FILE *tstf; @@ -948,13 +1041,14 @@ static void menu_loop_root(void) selfname = romsel_loop(curr_path); if (selfname) { printf("selected file: %s\n", selfname); - strncpy(currentConfig.lastRomFile, selfname, sizeof(currentConfig.lastRomFile)-1); - currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0; engineState = PGS_ReloadRom; } return; case 5: // options - menu_loop_options(); + ret = menu_loop_options(); + if (ret == 1) continue; // status update + if (engineState == PGS_ReloadRom) + return; // BIOS test break; case 6: // controls kc_sel_loop(); diff --git a/platform/linux/Makefile b/platform/linux/Makefile index fc6b200e..e4d54802 100644 --- a/platform/linux/Makefile +++ b/platform/linux/Makefile @@ -30,7 +30,7 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory ../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o # Pico - CD OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ - ../../Pico/cd/cd_sys.o + ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o # Pico - sound OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o # zlib -- 2.39.5