-// (c) Copyright 2006 notaz, All rights reserved.\r
+// (c) Copyright 2006-2007 notaz, All rights reserved.\r
// Free for non-commercial use.\r
\r
// For commercial use, separate licencing terms must be obtained.\r
\r
/* checks if romFileName points to valid MegaCD image\r
* if so, checks for suitable BIOS */\r
-static int cd_check(char **bios_file)\r
+int emu_cd_check(char **bios_file)\r
{\r
unsigned char buf[32];\r
pm_file *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
+ /* it seems we have a CD image here. Try to detect region now.. */\r
pm_seek(cd_f, (type == 1) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
pm_read(buf, 1, cd_f);\r
pm_close(cd_f);\r
printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
}\r
\r
- if(find_bios(region, bios_file))\r
+ if (bios_file == NULL) return type;\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
get_ext(romFileName, ext);\r
}\r
\r
+ if ((PicoMCD & 1) && Pico_mcd != NULL)\r
+ Stop_CD();\r
+\r
// check for MegaCD image\r
- cd_state = cd_check(&used_rom_name);\r
+ cd_state = emu_cd_check(&used_rom_name);\r
if (cd_state > 0) {\r
PicoMCD |= 1;\r
get_ext(used_rom_name, ext);\r
\r
// detect wrong files (Pico crashes on very small files), also see if ROM EP is good\r
if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||\r
- ((*(unsigned short *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {\r
+ ((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {\r
if (rom_data) free(rom_data);\r
rom_data = 0;\r
sprintf(menuErrorMsg, "Not a ROM selected.");\r
\r
\r
static void emu_msg_cb(const char *msg);\r
+static void emu_msg_tray_open(void);\r
\r
void emu_Init(void)\r
{\r
\r
PicoInit();\r
PicoMessage = emu_msg_cb;\r
-\r
-// logf = fopen("log.txt", "w");\r
+ PicoMCDopenTray = emu_msg_tray_open;\r
+ PicoMCDcloseTray = menu_loop_tray;\r
}\r
\r
\r
// set default config\r
memset(¤tConfig, 0, sizeof(currentConfig));\r
currentConfig.lastRomFile[0] = 0;\r
- currentConfig.EmuOpt = 0x1f | 0x400; // | cd_leds\r
- currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940 | cd_pcm | cd_cdda\r
+ currentConfig.EmuOpt = 0x1f | 0x600; // | confirm_save, cd_leds\r
+ currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda\r
currentConfig.PsndRate = 22050; // 44100;\r
currentConfig.PicoRegion = 0; // auto\r
currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
}\r
scaling_update();\r
// some sanity checks\r
- if (currentConfig.CPUclock < 1 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
+ if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
if (currentConfig.gamma < 10 || currentConfig.gamma > 300) currentConfig.gamma = 100;\r
+ if (currentConfig.volume < 0 || currentConfig.volume > 99) currentConfig.volume = 50;\r
// if volume keys are unbound, bind them to volume control\r
if (!currentConfig.KeyBinds[23] && !currentConfig.KeyBinds[22]) {\r
currentConfig.KeyBinds[23] = 1<<29; // vol up\r
free(framebuff);\r
\r
PicoExit();\r
-// fclose(logf);\r
\r
// restore gamma\r
if (gp2x_old_gamma != 100)\r
blit("", str);\r
}\r
\r
+static void emu_msg_tray_open(void)\r
+{\r
+ strcpy(noticeMsg, "CD tray opened");\r
+ gettimeofday(¬iceMsgTime, 0);\r
+}\r
+\r
static void RunEvents(unsigned int which)\r
{\r
if(which & 0x1800) { // save or load (but not both)\r
int do_it = 1;\r
- if (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200) && emu_check_save_file(state_slot)) {\r
+ if ( emu_check_save_file(state_slot) &&\r
+ (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
+ (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
unsigned long keys;\r
- blit("", "OVERWRITE SAVE? (Y=yes, X=no)");\r
+ blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)");\r
while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) )\r
usleep(50*1024);\r
if (keys & GP2X_X) do_it = 0;\r
if(events & 0x6000) {\r
int vol = currentConfig.volume;\r
if (events & 0x2000) {\r
- if (vol < 90) vol++;\r
+ if (vol < 99) vol++;\r
} else {\r
if (vol > 0) vol--;\r
}\r
if (frames_shown > frames_done) frames_shown = frames_done;\r
}\r
}\r
-#if 1\r
+#if 0\r
sprintf(fpsbuff, "%05i", Pico.m.frame_count);\r
#endif\r
lim_time = (frames_done+1) * target_frametime;\r
\r
// save SRAM\r
if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
- osd_text(4, 232, "Writing SRAM/BRAM..");\r
+ emu_state_cb("Writing SRAM/BRAM..");\r
emu_SaveLoadGame(0, 1);\r
SRam.changed = 0;\r
}\r
FILE *sramFile;\r
int sram_size;\r
unsigned char *sram_data;\r
+ int truncate = 1;\r
if (PicoMCD&1) {\r
- sram_size = 0x2000;\r
- sram_data = Pico_mcd->bram;\r
+ if (PicoOpt&0x8000) { // MCD RAM cart?\r
+ sram_size = 0x12000;\r
+ sram_data = SRam.data;\r
+ if (sram_data)\r
+ memcpy32((int *)sram_data, (int *)Pico_mcd->bram, 0x2000/4);\r
+ } else {\r
+ sram_size = 0x2000;\r
+ sram_data = Pico_mcd->bram;\r
+ truncate = 0; // the .brm may contain RAM cart data after normal brm\r
+ }\r
} else {\r
sram_size = SRam.end-SRam.start+1;\r
if(SRam.reg_back & 4) sram_size=0x2000;\r
sram_data = SRam.data;\r
}\r
- if(!sram_data) return 0; // SRam forcefully disabled for this game\r
+ if (!sram_data) return 0; // SRam forcefully disabled for this game\r
\r
- if(load) {\r
+ if (load) {\r
sramFile = fopen(saveFname, "rb");\r
if(!sramFile) return -1;\r
fread(sram_data, 1, sram_size, sramFile);\r
fclose(sramFile);\r
+ if ((PicoMCD&1) && (PicoOpt&0x8000))\r
+ memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4);\r
} else {\r
// sram save needs some special processing\r
// see if we have anything to save\r
- for(; sram_size > 0; sram_size--)\r
- if(sram_data[sram_size-1]) break;\r
+ for (; sram_size > 0; sram_size--)\r
+ if (sram_data[sram_size-1]) break;\r
\r
- if(sram_size) {\r
- sramFile = fopen(saveFname, "wb");\r
+ if (sram_size) {\r
+ sramFile = fopen(saveFname, truncate ? "wb" : "r+b");\r
+ if (!sramFile) sramFile = fopen(saveFname, "wb"); // retry\r
+ if (!sramFile) return -1;\r
ret = fwrite(sram_data, 1, sram_size, sramFile);\r
ret = (ret != sram_size) ? -1 : 0;\r
fclose(sramFile);\r