#include "lprintf.h"\r
#include "config.h"\r
#include "plat.h"\r
+#include "input.h"\r
\r
#include <pico/pico_int.h>\r
#include <pico/patch.h>\r
\r
char *PicoConfigFile = "config.cfg";\r
currentConfig_t currentConfig, defaultConfig;\r
-char noticeMsg[64] = { 0, };\r
int state_slot = 0;\r
int config_slot = 0, config_slot_current = 0;\r
int pico_inp_mode = 0;\r
// TODO: bits 6 & 5\r
}\r
movie_data[0x18+30] = 0;\r
- sprintf(noticeMsg, "MOVIE: %s", (char *) &movie_data[0x18]);\r
+ plat_status_msg("MOVIE: %s", (char *) &movie_data[0x18]);\r
}\r
else\r
{\r
PicoOpt &= ~POPT_DIS_VDP_FIFO;\r
- if (Pico.m.pal) {\r
- strcpy(noticeMsg, "PAL SYSTEM / 50 FPS");\r
- } else {\r
- strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS");\r
- }\r
+ plat_status_msg(Pico.m.pal ? "PAL SYSTEM / 50 FPS" : "NTSC SYSTEM / 60 FPS");\r
}\r
- emu_noticeMsgUpdated();\r
\r
// load SRAM for this ROM\r
if (currentConfig.EmuOpt & EOPT_USE_SRAM)\r
#undef mk_text_out\r
\r
\r
-void emu_updateMovie(void)\r
+void update_movie(void)\r
{\r
int offs = Pico.m.frame_count*3 + 0x40;\r
if (offs+3 > movie_size) {\r
free(movie_data);\r
movie_data = 0;\r
- strcpy(noticeMsg, "END OF MOVIE.");\r
+ plat_status_msg("END OF MOVIE.");\r
lprintf("END OF MOVIE.\n");\r
- emu_noticeMsgUpdated();\r
} else {\r
// MXYZ SACB RLDU\r
PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU\r
// make save filename\r
saveFname = emu_GetSaveFName(load, sram, state_slot);\r
if (saveFname == NULL) {\r
- if (!sram) {\r
- strcpy(noticeMsg, load ? "LOAD FAILED (missing file)" : "SAVE FAILED ");\r
- emu_noticeMsgUpdated();\r
- }\r
+ if (!sram)\r
+ plat_status_msg(load ? "LOAD FAILED (missing file)" : "SAVE FAILED");\r
return -1;\r
}\r
\r
}\r
else ret = -1;\r
if (!ret)\r
- strcpy(noticeMsg, load ? "GAME LOADED " : "GAME SAVED ");\r
+ plat_status_msg(load ? "GAME LOADED" : "GAME SAVED");\r
else\r
{\r
- strcpy(noticeMsg, load ? "LOAD FAILED " : "SAVE FAILED ");\r
+ plat_status_msg(load ? "LOAD FAILED" : "SAVE FAILED");\r
ret = -1;\r
}\r
\r
- emu_noticeMsgUpdated();\r
return ret;\r
}\r
}\r
currentConfig.EmuOpt &= ~4;\r
currentConfig.EmuOpt |= 0x40000;\r
is_on = 1;\r
- strcpy(noticeMsg, "FAST FORWARD ");\r
- emu_noticeMsgUpdated();\r
+ plat_status_msg("FAST FORWARD");\r
}\r
else if (!set_on && is_on) {\r
PsndOut = set_PsndOut;\r
{\r
if (events & (1 << 3)) {\r
pico_inp_mode++;\r
- if (pico_inp_mode > 2) pico_inp_mode = 0;\r
+ if (pico_inp_mode > 2)\r
+ pico_inp_mode = 0;\r
switch (pico_inp_mode) {\r
- case 2: strcpy(noticeMsg, "Input: Pen on Pad "); break;\r
- case 1: strcpy(noticeMsg, "Input: Pen on Storyware"); break;\r
- case 0: strcpy(noticeMsg, "Input: Joytick ");\r
+ case 2: plat_status_msg("Input: Pen on Pad"); break;\r
+ case 1: plat_status_msg("Input: Pen on Storyware"); break;\r
+ case 0: plat_status_msg("Input: Joystick");\r
PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
break;\r
}\r
- emu_noticeMsgUpdated();\r
}\r
if (events & (1 << 4)) {\r
PicoPicohw.page--;\r
- if (PicoPicohw.page < 0) PicoPicohw.page = 0;\r
- sprintf(noticeMsg, "Page %i ", PicoPicohw.page);\r
- emu_noticeMsgUpdated();\r
+ if (PicoPicohw.page < 0)\r
+ PicoPicohw.page = 0;\r
+ plat_status_msg("Page %i", PicoPicohw.page);\r
}\r
if (events & (1 << 5)) {\r
PicoPicohw.page++;\r
- if (PicoPicohw.page > 6) PicoPicohw.page = 6;\r
- sprintf(noticeMsg, "Page %i ", PicoPicohw.page);\r
- emu_noticeMsgUpdated();\r
+ if (PicoPicohw.page > 6)\r
+ PicoPicohw.page = 6;\r
+ plat_status_msg("Page %i", PicoPicohw.page);\r
}\r
}\r
\r
-void emu_DoTurbo(int *pad, int acts)\r
+static void do_turbo(int *pad, int acts)\r
{\r
static int turbo_pad = 0;\r
static unsigned char turbo_cnt[3] = { 0, 0, 0 };\r
*pad |= turbo_pad & (acts >> 8);\r
}\r
\r
+static void run_ui_events(unsigned int which)\r
+{\r
+ if (which & (PEV_STATE_LOAD|PEV_STATE_SAVE))\r
+ {\r
+ int do_it = 1;\r
+ if ( emu_checkSaveFile(state_slot) &&\r
+ (((which & PEV_STATE_LOAD) && (currentConfig.EmuOpt & EOPT_CONFIRM_LOAD)) ||\r
+ ((which & PEV_STATE_SAVE) && (currentConfig.EmuOpt & EOPT_CONFIRM_SAVE))) )\r
+ {\r
+ const char *nm;\r
+ char tmp[64];\r
+ int keys, len;\r
+\r
+ strcpy(tmp, (which & PEV_STATE_LOAD) ? "LOAD STATE?" : "OVERWRITE SAVE?");\r
+ len = strlen(tmp);\r
+ nm = in_get_key_name(-1, -PBTN_MA3);\r
+ snprintf(tmp + len, sizeof(tmp) - len, "(%s=yes, ", nm);\r
+ len = strlen(tmp);\r
+ nm = in_get_key_name(-1, -PBTN_MBACK);\r
+ snprintf(tmp + len, sizeof(tmp) - len, "%s=no)", nm);\r
+\r
+ plat_status_msg_busy_first(tmp);\r
+\r
+ in_set_blocking(1);\r
+ while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK))\r
+ ;\r
+ while ( !((keys = in_menu_wait_any(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
+ ;\r
+ in_set_blocking(0);\r
+ }\r
+ if (do_it) {\r
+ plat_status_msg_busy_first((which & PEV_STATE_LOAD) ? "LOADING GAME" : "SAVING GAME");\r
+ PicoStateProgressCB = plat_status_msg_busy_next;\r
+ emu_SaveLoadGame((which & PEV_STATE_LOAD) ? 1 : 0, 0);\r
+ PicoStateProgressCB = NULL;\r
+ }\r
+ }\r
+ if (which & PEV_SWITCH_RND)\r
+ {\r
+ plat_video_toggle_renderer();\r
+ }\r
+ if (which & (PEV_SSLOT_PREV|PEV_SSLOT_NEXT))\r
+ {\r
+ if (which & PEV_SSLOT_PREV) {\r
+ state_slot -= 1;\r
+ if (state_slot < 0)\r
+ state_slot = 9;\r
+ } else {\r
+ state_slot += 1;\r
+ if (state_slot > 9)\r
+ state_slot = 0;\r
+ }\r
+\r
+ plat_status_msg("SAVE SLOT %i [%s]", state_slot,\r
+ emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
+ }\r
+ if (which & PEV_MENU)\r
+ engineState = PGS_Menu;\r
+}\r
+\r
+void emu_update_input(void)\r
+{\r
+ unsigned int allActions[2] = { 0, 0 }, events;\r
+ static unsigned int prevEvents = 0;\r
+\r
+ /* FIXME: player2 */\r
+ allActions[0] = in_update();\r
+\r
+ PicoPad[0] = allActions[0] & 0xfff;\r
+ PicoPad[1] = allActions[1] & 0xfff;\r
+\r
+ if (allActions[0] & 0x7000) do_turbo(&PicoPad[0], allActions[0]);\r
+ if (allActions[1] & 0x7000) do_turbo(&PicoPad[1], allActions[1]);\r
+\r
+ events = (allActions[0] | allActions[1]) & PEV_MASK;\r
+\r
+ // volume is treated in special way and triggered every frame\r
+ if (events & (PEV_VOL_DOWN|PEV_VOL_UP))\r
+ plat_update_volume(1, events & PEV_VOL_UP);\r
+\r
+ if ((events ^ prevEvents) & PEV_FF) {\r
+ emu_changeFastForward(events & PEV_FF);\r
+ plat_update_volume(0, 0);\r
+// reset_timing = 1;\r
+ }\r
+\r
+ events &= ~prevEvents;\r
+\r
+// TODO if (PicoAHW == PAHW_PICO)\r
+// RunEventsPico(events);\r
+ if (events)\r
+ run_ui_events(events);\r
+ if (movie_data)\r
+ update_movie();\r
+\r
+ prevEvents = (allActions[0] | allActions[1]) & PEV_MASK;\r
+}\r
+\r
#define EOPT_GZIP_SAVES (1<<3)
#define EOPT_MMUHACK (1<<4)
#define EOPT_NO_AUTOSVCFG (1<<5)
+#define EOPT_16BPP (1<<7)
#define EOPT_RAM_TIMINGS (1<<8)
+#define EOPT_CONFIRM_SAVE (1<<9)
+#define EOPT_EN_CD_LEDS (1<<10)
+#define EOPT_CONFIRM_LOAD (1<<11)
#define EOPT_A_SN_GAMMA (1<<12)
#define EOPT_PSYNC (1<<13)
extern currentConfig_t currentConfig, defaultConfig;
extern char *PicoConfigFile;
extern int rom_loaded;
-extern char noticeMsg[64];
extern int state_slot;
extern int config_slot, config_slot_current;
extern unsigned char *movie_data;
int emu_ReloadRom(char *rom_fname);
int emu_SaveLoadGame(int load, int sram);
+
int emu_ReadConfig(int game, int no_defaults);
int emu_WriteConfig(int game);
+void emu_packConfig(void);
+void emu_unpackConfig(void);
void emu_writelrom(void);
+
char *emu_GetSaveFName(int load, int is_sram, int slot);
int emu_checkSaveFile(int slot);
void emu_setSaveStateCbs(int gz);
-void emu_updateMovie(void);
-int emu_cdCheck(int *pregion, char *fname_in);
+
+void emu_update_input(void);
int emu_findBios(int region, char **bios_file);
void emu_textOut8 (int x, int y, const char *text);
void emu_textOut16(int x, int y, const char *text);
void emu_getGameName(char *str150);
void emu_changeFastForward(int set_on);
void emu_RunEventsPico(unsigned int events);
-void emu_DoTurbo(int *pad, int acts);
-void emu_packConfig(void);
-void emu_unpackConfig(void);
void emu_shutdownMCD(void);
+int emu_cdCheck(int *pregion, char *fname_in);
#ifdef __cplusplus
} // extern "C"
#define PBTN_MENU (1 << 10)
+/* ui events */
+#define PEVB_VOL_DOWN 30
+#define PEVB_VOL_UP 29
+#define PEVB_STATE_LOAD 28
+#define PEVB_STATE_SAVE 27
+#define PEVB_SWITCH_RND 26
+#define PEVB_SSLOT_PREV 25
+#define PEVB_SSLOT_NEXT 24
+#define PEVB_MENU 23
+#define PEVB_FF 22
+
+#define PEV_VOL_DOWN (1 << PEVB_VOL_DOWN)
+#define PEV_VOL_UP (1 << PEVB_VOL_UP)
+#define PEV_STATE_LOAD (1 << PEVB_STATE_LOAD)
+#define PEV_STATE_SAVE (1 << PEVB_STATE_SAVE)
+#define PEV_SWITCH_RND (1 << PEVB_SWITCH_RND)
+#define PEV_SSLOT_PREV (1 << PEVB_SSLOT_PREV)
+#define PEV_SSLOT_NEXT (1 << PEVB_SSLOT_NEXT)
+#define PEV_MENU (1 << PEVB_MENU)
+#define PEV_FF (1 << PEVB_FF)
+
+#define PEV_MASK 0x7fc00000
+
+
enum {
IN_DRVID_UNKNOWN = 0,
IN_DRVID_GP2X,
// "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
me_bind_action emuctrl_actions[] =\r
{\r
- { "Load State ", 1<<28 },\r
- { "Save State ", 1<<27 },\r
- { "Prev Save Slot ", 1<<25 },\r
- { "Next Save Slot ", 1<<24 },\r
- { "Switch Renderer ", 1<<26 },\r
- { "Volume Down ", 1<<30 },\r
- { "Volume Up ", 1<<29 },\r
- { "Fast forward ", 1<<22 },\r
- { "Enter Menu ", 1<<23 },\r
- { "Pico Next page ", 1<<21 },\r
- { "Pico Prev page ", 1<<20 },\r
- { "Pico Switch input", 1<<19 },\r
- { NULL, 0 }\r
+ { "Load State ", 1 << PEVB_STATE_LOAD },\r
+ { "Save State ", 1 << PEVB_STATE_SAVE },\r
+ { "Prev Save Slot ", 1 << PEVB_SSLOT_PREV },\r
+ { "Next Save Slot ", 1 << PEVB_SSLOT_NEXT },\r
+ { "Switch Renderer ", 1 << PEVB_SWITCH_RND },\r
+ { "Volume Down ", 1 << PEVB_VOL_DOWN },\r
+ { "Volume Up ", 1 << PEVB_VOL_UP },\r
+ { "Fast forward ", 1 << PEVB_FF },\r
+ { "Enter Menu ", 1 << PEVB_MENU },\r
+ { "Pico Next page ", 1 << 21 }, /* TODO */\r
+ { "Pico Prev page ", 1 << 20 },\r
+ { "Pico Switch input", 1 << 19 },\r
+ { NULL, 0 }\r
};\r
\r
static int key_config_loop_wrap(menu_id id, int keys)\r
void emu_Deinit(void);
void emu_Loop(void);
-void emu_noticeMsgUpdated(void);
int emu_getMainDir(char *dst, int len);
void menu_romload_prepare(const char *rom_name);
void menu_romload_end(void);
void plat_init(void);
void plat_finish(void);
+/* to be used while emulation is starting or running */
+void plat_status_msg(const char *format, ...);
+
+/* used before things blocking for a while (these funcs redraw on return) */
+void plat_status_msg_busy_first(const char *msg);
+void plat_status_msg_busy_next(const char *msg);
+
/* menu: enter (switch bpp, etc), begin/end drawing */
void plat_video_menu_enter(int is_rom_loaded);
void plat_video_menu_begin(void);
void plat_video_menu_end(void);
+void plat_video_toggle_renderer(void);
void plat_validate_config(void);
+void plat_update_volume(int has_changed, int is_up);
int plat_is_dir(const char *path);
int plat_wait_event(int *fds_hnds, int count, int timeout_ms);
#include "../common/fonts.h"\r
#include "../common/emu.h"\r
#include "../common/config.h"\r
-#include "../common/input.h"\r
#include "../linux/sndout_oss.h"\r
#include "version.h"\r
\r
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing\r
static int osd_fps_x;\r
static int gp2x_old_gamma = 100;\r
+static char noticeMsg[40];\r
unsigned char *PicoDraw2FB = NULL; // temporary buffer for alt renderer\r
int reset_timing = 0;\r
\r
#define PICO_PEN_ADJUST_Y 2\r
static int pico_pen_x = 320/2, pico_pen_y = 240/2;\r
\r
-static void emu_msg_cb(const char *msg);\r
static void emu_msg_tray_open(void);\r
\r
\r
-void emu_noticeMsgUpdated(void)\r
+void plat_status_msg(const char *format, ...)\r
{\r
+ va_list vl;\r
+\r
+ va_start(vl, format);\r
+ vsnprintf(noticeMsg, sizeof(noticeMsg), format, vl);\r
+ va_end(vl);\r
+\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
\r
mkdir("cfg", 0777);\r
\r
PicoInit();\r
- PicoMessage = emu_msg_cb;\r
+ PicoMessage = plat_status_msg_busy_next;\r
PicoMCDopenTray = emu_msg_tray_open;\r
PicoMCDcloseTray = menu_loop_tray;\r
}\r
\r
static void draw_cd_leds(void)\r
{\r
-// static\r
int old_reg;\r
-// if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change // mmu hack problems?\r
old_reg = Pico_mcd->s68k_regs[0];\r
\r
- if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+ if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) {\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
{\r
int emu_opt = currentConfig.EmuOpt;\r
\r
- if (PicoOpt&0x10)\r
+ if (PicoOpt & POPT_ALT_RENDERER)\r
{\r
// 8bit fast renderer\r
if (Pico.m.dirtyPal) {\r
// do actual copy\r
vidCpyM2((unsigned char *)g_screen_ptr+320*8, PicoDraw2FB+328*8);\r
}\r
- else if (!(emu_opt&0x80))\r
+ else if (!(emu_opt & EOPT_16BPP))\r
{\r
// 8bit accurate renderer\r
if (Pico.m.dirtyPal)\r
if (PicoAHW & PAHW_PICO)\r
draw_pico_ptr();\r
\r
- //gp2x_video_wait_vsync();\r
gp2x_video_flip();\r
\r
- if (!(PicoOpt&0x10)) {\r
+ if (!(PicoOpt & POPT_ALT_RENDERER)) {\r
if (!(Pico.video.reg[1]&8)) {\r
- if (currentConfig.EmuOpt&0x80) {\r
+ if (currentConfig.EmuOpt & EOPT_16BPP)\r
DrawLineDest = (unsigned short *) g_screen_ptr + 320*8;\r
- } else {\r
+ else\r
DrawLineDest = (unsigned char *) g_screen_ptr + 320*8;\r
- }\r
} else {\r
DrawLineDest = g_screen_ptr;\r
}\r
}\r
}\r
\r
-\r
// clears whole screen or just the notice area (in all buffers)\r
static void clearArea(int full)\r
{\r
}\r
}\r
\r
+void plat_status_msg_busy_next(const char *msg)\r
+{\r
+ clearArea(0);\r
+ blit("", msg);\r
+\r
+ /* assumption: msg_busy_next gets called only when\r
+ * something slow is about to happen */\r
+ reset_timing = 1;\r
+}\r
+\r
+void plat_status_msg_busy_first(const char *msg)\r
+{\r
+ gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240*2);\r
+ plat_status_msg_busy_next(msg);\r
+}\r
\r
static void vidResetMode(void)\r
{\r
- if (PicoOpt&0x10) {\r
+ if (PicoOpt & POPT_ALT_RENDERER) {\r
gp2x_video_changemode(8);\r
- } else if (currentConfig.EmuOpt&0x80) {\r
+ } else if (currentConfig.EmuOpt & EOPT_16BPP) {\r
gp2x_video_changemode(16);\r
PicoDrawSetColorFormat(1);\r
PicoScanBegin = EmuScanBegin16;\r
PicoDrawSetColorFormat(2);\r
PicoScanBegin = EmuScanBegin8;\r
}\r
- if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+ if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) {\r
// setup pal for 8-bit modes\r
localPal[0xc0] = 0x0000c000; // MCD LEDs\r
localPal[0xd0] = 0x00c00000;\r
else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
}\r
\r
-\r
-static void emu_msg_cb(const char *msg)\r
+void plat_video_toggle_renderer(void)\r
{\r
- if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
- // 8-bit renderers\r
- gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
- osd_text(4, 232, msg);\r
- gp2x_memcpy_all_buffers((char *)g_screen_ptr+320*232, 320*232, 320*8);\r
- } else {\r
- // 16bit accurate renderer\r
- gp2x_memset_all_buffers(320*232*2, 0, 320*8*2);\r
- osd_text(4, 232, msg);\r
- gp2x_memcpy_all_buffers((char *)g_screen_ptr+320*232*2, 320*232*2, 320*8*2);\r
- }\r
- gettimeofday(¬iceMsgTime, 0);\r
- noticeMsgTime.tv_sec -= 2;\r
+ if (PicoOpt & POPT_ALT_RENDERER) {\r
+ PicoOpt &= ~POPT_ALT_RENDERER;\r
+ currentConfig.EmuOpt |= EOPT_16BPP;\r
+ } else if (!(currentConfig.EmuOpt & EOPT_16BPP))\r
+ PicoOpt |= POPT_ALT_RENDERER;\r
+ else\r
+ currentConfig.EmuOpt &= ~EOPT_16BPP;\r
\r
- /* assumption: emu_msg_cb gets called only when something slow is about to happen */\r
- reset_timing = 1;\r
-}\r
+ vidResetMode();\r
\r
-static void emu_state_cb(const char *str)\r
-{\r
- clearArea(0);\r
- blit("", str);\r
+ if (PicoOpt & POPT_ALT_RENDERER) {\r
+ plat_status_msg(" 8bit fast renderer");\r
+ } else if (currentConfig.EmuOpt & EOPT_16BPP) {\r
+ plat_status_msg("16bit accurate renderer");\r
+ } else {\r
+ plat_status_msg(" 8bit accurate renderer");\r
+ }\r
}\r
\r
static void emu_msg_tray_open(void)\r
{\r
- strcpy(noticeMsg, "CD tray opened");\r
- gettimeofday(¬iceMsgTime, 0);\r
+ plat_status_msg("CD tray opened");\r
}\r
\r
static void RunEventsPico(unsigned int events)\r
PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
}\r
\r
-static void update_volume(int has_changed, int is_up)\r
+void plat_update_volume(int has_changed, int is_up)\r
{\r
static int prev_frame = 0, wait_frames = 0;\r
int vol = currentConfig.volume;\r
+ int need_low_volume = 0;\r
+ gp2x_soc_t soc;\r
+\r
+ soc = soc_detect();\r
+ if ((PicoOpt & POPT_EN_STEREO) && soc == SOCID_MMSP2)\r
+ need_low_volume = 1;\r
\r
if (has_changed)\r
{\r
- if (vol < 5 && (PicoOpt&8) && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r
+ if (need_low_volume && vol < 5 && prev_frame == Pico.m.frame_count - 1 && wait_frames < 12)\r
wait_frames++;\r
else {\r
if (is_up) {\r
sndout_oss_setvol(vol, vol);\r
currentConfig.volume = vol;\r
}\r
- sprintf(noticeMsg, "VOL: %02i", vol);\r
- gettimeofday(¬iceMsgTime, 0);\r
+ plat_status_msg("VOL: %02i", vol);\r
prev_frame = Pico.m.frame_count;\r
}\r
\r
- // set the right mixer func\r
- if (!(PicoOpt&8)) return; // just use defaults for mono\r
+ if (need_low_volume)\r
+ return;\r
+\r
+ /* set the right mixer func */\r
if (vol >= 5)\r
PsndMix_32_to_16l = mix_32_to_16l_stereo;\r
else {\r
}\r
}\r
\r
-static void RunEvents(unsigned int which)\r
-{\r
- if (which & 0x1800) // save or load (but not both)\r
- {\r
- int do_it = 1;\r
- if ( emu_checkSaveFile(state_slot) &&\r
- (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
- (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save\r
- {\r
- const char *nm;\r
- char tmp[64];\r
- int keys, len;\r
-\r
- strcpy(tmp, (which & 0x1000) ? "LOAD STATE? " : "OVERWRITE SAVE? ");\r
- len = strlen(tmp);\r
- nm = in_get_key_name(-1, -PBTN_MA3);\r
- snprintf(tmp + len, sizeof(tmp) - len, "(%s=yes, ", nm);\r
- len = strlen(tmp);\r
- nm = in_get_key_name(-1, -PBTN_MBACK);\r
- snprintf(tmp + len, sizeof(tmp) - len, "%s=no)", nm);\r
-\r
- blit("", tmp);\r
-\r
- in_set_blocking(1);\r
- while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK)); // wait for release\r
- while ( !((keys = in_menu_wait_any(50)) & (PBTN_MA3|PBTN_MBACK)) ); // .. press\r
- if (keys & PBTN_MBACK)\r
- do_it = 0;\r
- while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK)); // .. release\r
- in_set_blocking(0);\r
-\r
- clearArea(0);\r
- }\r
- if (do_it) {\r
- osd_text(4, 232, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
- PicoStateProgressCB = emu_state_cb;\r
- gp2x_memcpy_all_buffers(g_screen_ptr, 0, 320*240*2);\r
- emu_SaveLoadGame((which & 0x1000) >> 12, 0);\r
- PicoStateProgressCB = NULL;\r
- }\r
-\r
- reset_timing = 1;\r
- }\r
- if (which & 0x0400) // switch renderer\r
- {\r
- if ( PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }\r
- else if (!(currentConfig.EmuOpt&0x80)) PicoOpt|= 0x10;\r
- else currentConfig.EmuOpt &= ~0x80;\r
-\r
- vidResetMode();\r
-\r
- if (PicoOpt&0x10) {\r
- strcpy(noticeMsg, " 8bit fast renderer");\r
- } else if (currentConfig.EmuOpt&0x80) {\r
- strcpy(noticeMsg, "16bit accurate renderer");\r
- } else {\r
- strcpy(noticeMsg, " 8bit accurate renderer");\r
- }\r
-\r
- emu_noticeMsgUpdated();\r
- }\r
- if (which & 0x0300)\r
- {\r
- if(which&0x0200) {\r
- state_slot -= 1;\r
- if(state_slot < 0) state_slot = 9;\r
- } else {\r
- state_slot += 1;\r
- if(state_slot > 9) state_slot = 0;\r
- }\r
- sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
- emu_noticeMsgUpdated();\r
- }\r
- if (which & 0x0080) {\r
- engineState = PGS_Menu;\r
- }\r
-}\r
-\r
-static void updateKeys(void)\r
-{\r
- unsigned int allActions[2] = { 0, 0 }, events;\r
- static unsigned int prevEvents = 0;\r
-\r
- /* FIXME: player2 */\r
- allActions[0] = in_update();\r
-\r
- PicoPad[0] = allActions[0] & 0xfff;\r
- PicoPad[1] = allActions[1] & 0xfff;\r
-\r
- if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);\r
- if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);\r
-\r
- events = (allActions[0] | allActions[1]) >> 16;\r
-\r
- // volume is treated in special way and triggered every frame\r
- if (events & 0x6000)\r
- update_volume(1, events & 0x2000);\r
-\r
- if ((events ^ prevEvents) & 0x40) {\r
- emu_changeFastForward(events & 0x40);\r
- update_volume(0, 0);\r
- reset_timing = 1;\r
- }\r
-\r
- events &= ~prevEvents;\r
-\r
- if (PicoAHW == PAHW_PICO)\r
- RunEventsPico(events);\r
- if (events) RunEvents(events);\r
- if (movie_data) emu_updateMovie();\r
-\r
- prevEvents = (allActions[0] | allActions[1]) >> 16;\r
-}\r
-\r
\r
static void updateSound(int len)\r
{\r
sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);\r
sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
PicoWriteSound = updateSound;\r
- update_volume(0, 0);\r
+ plat_update_volume(0, 0);\r
memset(sndBuffer, 0, sizeof(sndBuffer));\r
PsndOut = sndBuffer;\r
PsndRate_old = PsndRate;\r
} else {\r
// it is quite common for this implementation to leave 1 fame unfinished\r
// when second changes, but we don't want buffer to starve.\r
- if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
- updateKeys();\r
+ if (PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
+ emu_update_input();\r
SkipFrame(1); pframes_done++;\r
}\r
\r
if (currentConfig.Frameskip >= 0) // frameskip enabled\r
{\r
for(i = 0; i < currentConfig.Frameskip; i++) {\r
- updateKeys();\r
+ emu_update_input();\r
SkipFrame(1); pframes_done++; frames_done++;\r
if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
gettimeofday(&tval, 0);\r
reset_timing = 1;\r
continue;\r
}\r
- updateKeys();\r
+ emu_update_input();\r
SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;\r
continue;\r
}\r
\r
- updateKeys();\r
+ emu_update_input();\r
PicoFrame();\r
\r
// check time\r
\r
emu_changeFastForward(0);\r
\r
- if (PicoAHW & PAHW_MCD) PicoCDBufferFree();\r
+ if (PicoAHW & PAHW_MCD)\r
+ PicoCDBufferFree();\r
\r
// save SRAM\r
- if((currentConfig.EmuOpt & 1) && SRam.changed) {\r
- emu_state_cb("Writing SRAM/BRAM..");\r
+ if ((currentConfig.EmuOpt & EOPT_USE_SRAM) && SRam.changed) {\r
+ plat_status_msg_busy_first("Writing SRAM/BRAM...");\r
emu_SaveLoadGame(0, 1);\r
SRam.changed = 0;\r
}\r
\r
// if in 8bit mode, generate 16bit image for menu background\r
- if ((PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80))\r
+ if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP))\r
emu_forcedFrame(POPT_EN_SOFTSCALE);\r
}\r
\r
{ BTN_Y, 6 },
{ KEY_ENTER, 7 },
{ BTN_START, 7 },
- { BTN_TL, 27 }, /* save state */
- { BTN_TR, 28 }, /* load state */
+ { BTN_TL, PEVB_STATE_LOAD },
+ { BTN_TR, PEVB_STATE_SAVE },
};
#define DEF_BIND_COUNT (sizeof(in_evdev_def_binds) / sizeof(in_evdev_def_binds[0]))
static void emu_msg_tray_open(void);\r
\r
\r
-void emu_noticeMsgUpdated(void)\r
+void plat_status_msg(const char *format, ...)\r
{\r
+ va_list vl;\r
+\r
+ va_start(vl, format);\r
+ vsnprintf(noticeMsg, sizeof(noticeMsg), fmt, vl);\r
+ va_end(vl);\r
+\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
\r
gettimeofday(¬iceMsgTime, 0);\r
}\r
\r
-#if 0\r
-static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
-{\r
- int ret, px, py, lim_x;\r
- static int pdown_frames = 0;\r
-\r
- emu_RunEventsPico(events);\r
-\r
- if (pico_inp_mode == 0) return;\r
-\r
- // for F200\r
- ret = gp2x_touchpad_read(&px, &py);\r
- if (ret >= 0)\r
- {\r
- if (ret > 35000)\r
- {\r
- if (pdown_frames++ > 5)\r
- PicoPad[0] |= 0x20;\r
-\r
- pico_pen_x = px;\r
- pico_pen_y = py;\r
- if (!(Pico.video.reg[12]&1)) {\r
- pico_pen_x -= 32;\r
- if (pico_pen_x < 0) pico_pen_x = 0;\r
- if (pico_pen_x > 248) pico_pen_x = 248;\r
- }\r
- if (pico_pen_y > 224) pico_pen_y = 224;\r
- }\r
- else\r
- pdown_frames = 0;\r
-\r
- //if (ret == 0)\r
- // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
- }\r
-\r
- PicoPad[0] &= ~0x0f; // release UDLR\r
- if (gp2x_keys & GP2X_UP) pico_pen_y--;\r
- if (gp2x_keys & GP2X_DOWN) pico_pen_y++;\r
- if (gp2x_keys & GP2X_LEFT) pico_pen_x--;\r
- if (gp2x_keys & GP2X_RIGHT) pico_pen_x++;\r
-\r
- lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
- if (pico_pen_y < 8) pico_pen_y = 8;\r
- if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y;\r
- if (pico_pen_x < 0) pico_pen_x = 0;\r
- if (pico_pen_x > lim_x-PICO_PEN_ADJUST_X) pico_pen_x = lim_x-PICO_PEN_ADJUST_X;\r
-\r
- PicoPicohw.pen_pos[0] = pico_pen_x;\r
- if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
- PicoPicohw.pen_pos[0] += 0x3c;\r
- PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
-}\r
-#endif\r
\r
static void update_volume(int has_changed, int is_up)\r
{\r
}\r
}\r
\r
-static void RunEvents(unsigned int which)\r
-{\r
- if (which & 0x1800) // save or load (but not both)\r
- {\r
- int do_it = 1;\r
- if ( emu_checkSaveFile(state_slot) &&\r
- (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
- (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
-#if 0\r
- unsigned long keys;\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
- while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release\r
- usleep(50*1024);\r
- clearArea(0);\r
-#endif\r
- }\r
- if (do_it) {\r
- osd_text(4, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
- PicoStateProgressCB = emu_state_cb;\r
- //gp2x_memcpy_all_buffers(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
- emu_SaveLoadGame((which & 0x1000) >> 12, 0);\r
- PicoStateProgressCB = NULL;\r
- }\r
-\r
- reset_timing = 1;\r
- }\r
- if (which & 0x0400) // switch renderer\r
- {\r
- if ( PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }\r
- else if (!(currentConfig.EmuOpt&0x80)) PicoOpt|= 0x10;\r
- else currentConfig.EmuOpt &= ~0x80;\r
-\r
- vidResetMode();\r
-\r
- if (PicoOpt&0x10) {\r
- strcpy(noticeMsg, " 8bit fast renderer");\r
- } else if (currentConfig.EmuOpt&0x80) {\r
- strcpy(noticeMsg, "16bit accurate renderer");\r
- } else {\r
- strcpy(noticeMsg, " 8bit accurate renderer");\r
- }\r
-\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- if (which & 0x0300)\r
- {\r
- if(which&0x0200) {\r
- state_slot -= 1;\r
- if(state_slot < 0) state_slot = 9;\r
- } else {\r
- state_slot += 1;\r
- if(state_slot > 9) state_slot = 0;\r
- }\r
- sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- if (which & 0x0080) {\r
- engineState = PGS_Menu;\r
- }\r
-}\r
-\r
-static void updateKeys(void)\r
-{\r
- unsigned int allActions[2] = { 0, 0 }, events;\r
- static unsigned int prevEvents = 0;\r
-\r
- /* FIXME: combos, player2 */\r
- allActions[0] = in_update();\r
-\r
- PicoPad[0] = allActions[0] & 0xfff;\r
- PicoPad[1] = allActions[1] & 0xfff;\r
-\r
- if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);\r
- if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);\r
-\r
- events = (allActions[0] | allActions[1]) >> 16;\r
-\r
- // volume is treated in special way and triggered every frame\r
- if (events & 0x6000)\r
- update_volume(1, events & 0x2000);\r
-\r
- if ((events ^ prevEvents) & 0x40) {\r
- emu_changeFastForward(events & 0x40);\r
- update_volume(0, 0);\r
- reset_timing = 1;\r
- }\r
-\r
- events &= ~prevEvents;\r
-\r
-/*\r
- if (PicoAHW == PAHW_PICO)\r
- RunEventsPico(events, keys);\r
-*/\r
- if (events) RunEvents(events);\r
- if (movie_data) emu_updateMovie();\r
-\r
- prevEvents = (allActions[0] | allActions[1]) >> 16;\r
-}\r
-\r
\r
static void updateSound(int len)\r
{\r
// it is quite common for this implementation to leave 1 fame unfinished\r
// when second changes, but we don't want buffer to starve.\r
if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
- updateKeys();\r
+ emu_update_input();\r
SkipFrame(1); pframes_done++;\r
}\r
\r
if (currentConfig.Frameskip >= 0) // frameskip enabled\r
{\r
for(i = 0; i < currentConfig.Frameskip; i++) {\r
- updateKeys();\r
+ emu_update_input();\r
SkipFrame(1); pframes_done++; frames_done++;\r
if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
gettimeofday(&tval, 0);\r
reset_timing = 1;\r
continue;\r
}\r
- updateKeys();\r
+ emu_update_input();\r
SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;\r
continue;\r
}\r
\r
- updateKeys();\r
+ emu_update_input();\r
PicoFrame();\r
\r
// check time\r
static void blit2(const char *fps, const char *notice, int lagging_behind);
static void clearArea(int full);
-void emu_noticeMsgUpdated(void)
+void plat_status_msg(const char *format, ...)
{
+ va_list vl;
+
+ va_start(vl, format);
+ vsnprintf(noticeMsg, sizeof(noticeMsg), fmt, vl);
+ va_end(vl);
+
noticeMsgTime = sceKernelGetSystemTimeLow();
}
static void emu_msg_tray_open(void)
{
- strcpy(noticeMsg, "CD tray opened");
- noticeMsgTime = sceKernelGetSystemTimeLow();
+ plat_status_msg("CD tray opened");
}
ret = sceAudio_38553111(samples_block/2, PsndRate, 2); // seems to not need that stupid 64byte alignment
if (ret < 0) {
lprintf("sceAudio_38553111() failed: %i\n", ret);
- sprintf(noticeMsg, "sound init failed (%i), snd disabled", ret);
- noticeMsgTime = sceKernelGetSystemTimeLow();
- currentConfig.EmuOpt &= ~4;
+ plat_status_msg("sound init failed (%i), snd disabled", ret);
+ currentConfig.EmuOpt &= ~EOPT_EN_SOUND;
} else {
PicoWriteSound = writeSound;
memset32((int *)(void *)sndBuffer, 0, sizeof(sndBuffer)/4);
vidResetMode();
- if (PicoOpt&0x10)
- strcpy(noticeMsg, "fast renderer");
+ if (PicoOpt & POPT_ALT_RENDERER)
+ plat_status_msg("fast renderer");
else if (currentConfig.EmuOpt&0x80)
- strcpy(noticeMsg, "accurate renderer");
-
- noticeMsgTime = sceKernelGetSystemTimeLow();
+ plat_status_msg("accurate renderer");
}
if (which & 0x0300)
{
state_slot += 1;
if(state_slot > 9) state_slot = 0;
}
- sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");
- noticeMsgTime = sceKernelGetSystemTimeLow();
+ plat_status_msg("SAVE SLOT %i [%s]", state_slot,
+ emu_checkSaveFile(state_slot) ? "USED" : "FREE");
}
}
static unsigned int prevEvents = 0;
int i;
- /* FIXME: port to input fw */
+ /* FIXME: port to input fw, merge with emu.c:emu_update_input() */
keys = psp_pad_read(0);
if (keys & PSP_CTRL_HOME)
sceDisplayWaitVblankStart();