-// (c) Copyright 2006-2009 notaz, All rights reserved.\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
+/*\r
+ * PicoDrive\r
+ * (C) notaz, 2007-2010\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <unistd.h>\r
#endif\r
\r
+#include "../libpicofe/posix.h"\r
+#include "../libpicofe/input.h"\r
+#include "../libpicofe/fonts.h"\r
+#include "../libpicofe/sndout.h"\r
+#include "../libpicofe/lprintf.h"\r
+#include "../libpicofe/plat.h"\r
#include "emu.h"\r
-#include "menu.h"\r
-#include "fonts.h"\r
-#include "lprintf.h"\r
-#include "config.h"\r
-#include "plat.h"\r
-#include "input.h"\r
-#include "posix.h"\r
+#include "input_pico.h"\r
+#include "menu_pico.h"\r
+#include "config_file.h"\r
\r
#include <pico/pico_int.h>\r
#include <pico/patch.h>\r
int pico_inp_mode = 0;\r
int engineState = PGS_Menu;\r
\r
+static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
+\r
/* tmp buff to reduce stack usage for plats with small stack */\r
static char static_buff[512];\r
-/* TODO: len checking */\r
-char rom_fname_reload[512];\r
+const char *rom_fname_reload;\r
char rom_fname_loaded[512];\r
int rom_loaded = 0;\r
int reset_timing = 0;\r
static const char * const biosfiles_eu[] = { "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303" };\r
static const char * const biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
\r
-static int find_bios(int region, char **bios_file)\r
+static int find_bios(int region, const char **bios_file)\r
{\r
int i, count;\r
const char * const *files;\r
} else {\r
sprintf(static_buff, "no %s BIOS files found, read docs",\r
region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
- me_update_msg(static_buff);\r
+ menu_update_msg(static_buff);\r
return 0;\r
}\r
}\r
emu_status_msg("%s %s / %dFPS%s", tv_standard, sys_name, fps, extra);\r
}\r
\r
-// note: this function might mangle rom_fname\r
// XXX: portions of this code should move to pico/\r
-int emu_reload_rom(char *rom_fname)\r
+int emu_reload_rom(const char *rom_fname_in)\r
{\r
unsigned int rom_size = 0;\r
- char *used_rom_name = rom_fname;\r
+ const char *used_rom_name = NULL;\r
+ char *rom_fname = NULL;\r
unsigned char *rom_data = NULL;\r
char ext[5];\r
pm_file *rom = NULL;\r
int cd_state = CIT_NOT_CD;\r
int ret, media_type, cd_region;\r
int cfg_loaded = 0, bad_rom = 0;\r
+ int menu_romload_started = 0;\r
+ int retval = 0;\r
+\r
+ lprintf("emu_ReloadRom(%s)\n", rom_fname_in);\r
\r
- lprintf("emu_ReloadRom(%s)\n", rom_fname);\r
+ rom_fname = strdup(rom_fname_in);\r
+ if (rom_fname == NULL)\r
+ return 0;\r
\r
+ used_rom_name = rom_fname;\r
get_ext(rom_fname, ext);\r
\r
// early cleanup\r
int dummy;\r
FILE *movie_file = fopen(rom_fname, "rb");\r
if (!movie_file) {\r
- me_update_msg("Failed to open movie.");\r
- return 0;\r
+ menu_update_msg("Failed to open movie.");\r
+ goto out;\r
}\r
fseek(movie_file, 0, SEEK_END);\r
movie_size = ftell(movie_file);\r
fseek(movie_file, 0, SEEK_SET);\r
if (movie_size < 64+3) {\r
- me_update_msg("Invalid GMV file.");\r
+ menu_update_msg("Invalid GMV file.");\r
fclose(movie_file);\r
- return 0;\r
+ goto out;\r
}\r
movie_data = malloc(movie_size);\r
if (movie_data == NULL) {\r
- me_update_msg("low memory.");\r
+ menu_update_msg("low memory.");\r
fclose(movie_file);\r
- return 0;\r
+ goto out;\r
}\r
dummy = fread(movie_data, 1, movie_size, movie_file);\r
fclose(movie_file);\r
if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) {\r
- me_update_msg("Invalid GMV file.");\r
- return 0;\r
+ menu_update_msg("Invalid GMV file.");\r
+ goto out;\r
}\r
dummy = try_rfn_cut(rom_fname) || try_rfn_cut(rom_fname);\r
if (!dummy) {\r
- me_update_msg("Could't find a ROM for movie.");\r
- return 0;\r
+ menu_update_msg("Could't find a ROM for movie.");\r
+ goto out;\r
}\r
get_ext(rom_fname, ext);\r
lprintf("gmv loaded for %s\n", rom_fname);\r
PicoPatchLoad(rom_fname);\r
dummy = try_rfn_cut(rom_fname) || try_rfn_cut(rom_fname);\r
if (!dummy) {\r
- me_update_msg("Could't find a ROM to patch.");\r
- return 0;\r
+ menu_update_msg("Could't find a ROM to patch.");\r
+ goto out;\r
}\r
get_ext(rom_fname, ext);\r
}\r
\r
media_type = detect_media(rom_fname);\r
if (media_type == PM_BAD) {\r
- me_update_msg("Not a ROM/CD img selected.");\r
- return 0;\r
+ menu_update_msg("Not a ROM/CD img selected.");\r
+ goto out;\r
}\r
\r
shutdown_MCD();\r
(cd_region == 8 ? "EU" : "JAP") : "USA");\r
}\r
if (!find_bios(cd_region, &used_rom_name))\r
- return 0;\r
+ goto out;\r
\r
get_ext(used_rom_name, ext);\r
PicoAHW |= PAHW_MCD;\r
}\r
else {\r
- me_update_msg("Invalid CD image");\r
- return 0;\r
+ menu_update_msg("Invalid CD image");\r
+ goto out;\r
}\r
}\r
else if (media_type == PM_MARK3) {\r
\r
rom = pm_open(used_rom_name);\r
if (rom == NULL) {\r
- me_update_msg("Failed to open ROM");\r
- return 0;\r
+ menu_update_msg("Failed to open ROM");\r
+ goto out;\r
}\r
\r
menu_romload_prepare(used_rom_name); // also CD load\r
+ menu_romload_started = 1;\r
used_rom_name = NULL; // uses static_buff\r
\r
ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoAHW & PAHW_SMS) ? 1 : 0);\r
pm_close(rom);\r
if (ret != 0) {\r
- if (ret == 2) me_update_msg("Out of memory");\r
- else if (ret == 3) me_update_msg("Read failed");\r
- else me_update_msg("PicoCartLoad() failed.");\r
- goto fail;\r
+ if (ret == 2) menu_update_msg("Out of memory");\r
+ else if (ret == 3) menu_update_msg("Read failed");\r
+ else menu_update_msg("PicoCartLoad() failed.");\r
+ goto out;\r
}\r
\r
// detect wrong files\r
}\r
\r
if (bad_rom) {\r
- me_update_msg("Bad ROM detected.");\r
- goto fail;\r
+ menu_update_msg("Bad ROM detected.");\r
+ goto out;\r
}\r
\r
// load config for this ROM (do this before insert to get correct region)\r
\r
emu_make_path(static_buff, "carthw.cfg", sizeof(static_buff));\r
if (PicoCartInsert(rom_data, rom_size, static_buff)) {\r
- me_update_msg("Failed to load ROM.");\r
- goto fail;\r
+ menu_update_msg("Failed to load ROM.");\r
+ goto out;\r
}\r
\r
// insert CD if it was detected\r
if (ret != 0) {\r
PicoCartUnload();\r
rom_data = NULL; // freed by unload\r
- me_update_msg("Insert_CD() failed, invalid CD image?");\r
- goto fail;\r
+ menu_update_msg("Insert_CD() failed, invalid CD image?");\r
+ goto out;\r
}\r
}\r
\r
menu_romload_end();\r
+ menu_romload_started = 0;\r
\r
if (PicoPatches) {\r
PicoPatchPrepare();\r
if (currentConfig.EmuOpt & EOPT_EN_SRAM)\r
emu_save_load_game(1, 1);\r
\r
- return 1;\r
-\r
-fail:\r
- if (rom_data)\r
+ retval = 1;\r
+out:\r
+ if (retval == 0 && rom_data)\r
free(rom_data);\r
- menu_romload_end();\r
- return 0;\r
+ if (menu_romload_started)\r
+ menu_romload_end();\r
+ free(rom_fname);\r
+ return retval;\r
}\r
\r
int emu_swap_cd(const char *fname)\r
if (cd_type != CIT_NOT_CD)\r
ret = Insert_CD(fname, cd_type);\r
if (ret != 0) {\r
- me_update_msg("Load failed, invalid CD image?");\r
+ menu_update_msg("Load failed, invalid CD image?");\r
return 0;\r
}\r
\r
return NULL;\r
}\r
\r
-int emu_check_save_file(int slot)\r
+int emu_check_save_file(int slot, int *time)\r
{\r
return emu_get_save_fname(1, 0, slot) ? 1 : 0;\r
}\r
if (which & (PEV_STATE_LOAD|PEV_STATE_SAVE))\r
{\r
int do_it = 1;\r
- if ( emu_check_save_file(state_slot) &&\r
+ if ( emu_check_save_file(state_slot, NULL) &&\r
(((which & PEV_STATE_LOAD) && (currentConfig.confirm_save & EOPT_CONFIRM_LOAD)) ||\r
((which & PEV_STATE_SAVE) && (currentConfig.confirm_save & EOPT_CONFIRM_SAVE))) )\r
{\r
plat_status_msg_busy_first(tmp);\r
\r
in_set_config_int(0, IN_CFG_BLOCKING, 1);\r
- while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK))\r
+ while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))\r
;\r
- while ( !((keys = in_menu_wait_any(50)) & (PBTN_MA3|PBTN_MBACK)) )\r
+ while ( !((keys = in_menu_wait_any(NULL, 50)) & (PBTN_MA3|PBTN_MBACK)) )\r
;\r
if (keys & PBTN_MBACK)\r
do_it = 0;\r
- while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK))\r
+ while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))\r
;\r
in_set_config_int(0, IN_CFG_BLOCKING, 0);\r
}\r
}\r
\r
emu_status_msg("SAVE SLOT %i [%s]", state_slot,\r
- emu_check_save_file(state_slot) ? "USED" : "FREE");\r
+ emu_check_save_file(state_slot, NULL) ? "USED" : "FREE");\r
}\r
if (which & PEV_MENU)\r
engineState = PGS_Menu;\r
\r
memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r
\r
+ PicoOpt &= ~POPT_ALT_RENDERER;\r
PicoOpt |= POPT_ACC_SPRITES;\r
if (!no_scale)\r
PicoOpt |= POPT_EN_SOFTSCALE;\r
PicoMessage = plat_status_msg_busy_next;\r
PicoMCDopenTray = emu_tray_open;\r
PicoMCDcloseTray = emu_tray_close;\r
+\r
+ sndout_init();\r
}\r
\r
void emu_finish(void)\r
pprof_finish();\r
\r
PicoExit();\r
+ sndout_exit();\r
+}\r
+\r
+static void snd_write_nonblocking(int len)\r
+{\r
+ sndout_write_nb(PsndOut, len);\r
+}\r
+\r
+void emu_sound_start(void)\r
+{\r
+ PsndOut = NULL;\r
+\r
+ if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
+ {\r
+ int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
+\r
+ PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+\r
+ printf("starting audio: %i len: %i stereo: %i, pal: %i\n",\r
+ PsndRate, PsndLen, is_stereo, Pico.m.pal);\r
+ sndout_start(PsndRate, is_stereo);\r
+ PicoWriteSound = snd_write_nonblocking;\r
+ plat_update_volume(0, 0);\r
+ memset(sndBuffer, 0, sizeof(sndBuffer));\r
+ PsndOut = sndBuffer;\r
+ }\r
+}\r
+\r
+void emu_sound_stop(void)\r
+{\r
+ sndout_stop();\r
+}\r
+\r
+void emu_sound_wait(void)\r
+{\r
+ sndout_wait();\r
}\r
\r
static void skip_frame(int do_audio)\r
if (PicoAHW & PAHW_MCD)\r
PicoCDBufferInit();\r
\r
+ plat_video_loop_prepare();\r
pemu_loop_prep();\r
+ pemu_sound_start();\r
\r
/* number of ticks per frame */\r
if (Pico.m.pal) {\r
}\r
\r
pemu_loop_end();\r
+ emu_sound_stop();\r
\r
// pemu_loop_end() might want to do 1 frame for bg image,\r
// so free CD buffer here\r