/*\r
* PicoDrive\r
* (C) notaz, 2007-2010\r
+ * (C) irixxxx, 2019-2024\r
*\r
* This work is licensed under the terms of MAME license.\r
* See COPYING file in the top-level directory.\r
#include "../libpicofe/fonts.h"\r
#include "../libpicofe/sndout.h"\r
#include "../libpicofe/lprintf.h"\r
+#include "../libpicofe/readpng.h"\r
#include "../libpicofe/plat.h"\r
#include "emu.h"\r
#include "input_pico.h"\r
#include <pico/pico_int.h>\r
#include <pico/patch.h>\r
\r
+#if defined(__GNUC__) && __GNUC__ >= 7\r
+#pragma GCC diagnostic ignored "-Wformat-truncation"\r
+#endif\r
+\r
#ifndef _WIN32\r
#define PATH_SEP "/"\r
#define PATH_SEP_C '/'\r
\r
int g_screen_width = 320;\r
int g_screen_height = 240;\r
+int g_screen_ppitch = 320; // pitch in pixels\r
\r
const char *PicoConfigFile = "config2.cfg";\r
currentConfig_t currentConfig, defaultConfig;\r
int flip_after_sync;\r
int engineState = PGS_Menu;\r
\r
-static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
+static short __attribute__((aligned(4))) sndBuffer[2*54000/50];\r
\r
/* tmp buff to reduce stack usage for plats with small stack */\r
static char static_buff[512];\r
strncpy(dst + prefix_len, p, dstlen - prefix_len - 1);\r
\r
dst[dstlen - 8] = 0;\r
- if (dst[strlen(dst) - 4] == '.')\r
- dst[strlen(dst) - 4] = 0;\r
+ if ((p = strrchr(dst, '.')) != NULL)\r
+ dst[p-dst] = 0;\r
if (ext)\r
strcat(dst, ext);\r
}\r
(*region == 8 ? "EU" : "JAP") : "USA");\r
}\r
\r
+ // look for MSU.MD rom file. XXX another extension list? ugh...\r
+ static const char *md_exts[] = { "gen", "smd", "md", "32x" };\r
+ char *ext = strrchr(cd_fname, '.');\r
+ int extpos = ext ? ext-cd_fname : strlen(cd_fname);\r
+ strcpy(static_buff, cd_fname);\r
+ static_buff[extpos++] = '.';\r
+ for (i = 0; i < ARRAY_SIZE(md_exts); i++) {\r
+ strcpy(static_buff+extpos, md_exts[i]);\r
+ if (access(static_buff, R_OK) == 0) {\r
+ printf("found MSU rom: %s\n",static_buff);\r
+ return static_buff;\r
+ }\r
+ }\r
+\r
+ // locate BIOS file\r
if (*region == 4) { // US\r
files = biosfiles_us;\r
count = sizeof(biosfiles_us) / sizeof(char *);\r
strcat(static_buff, ".zip");\r
f = fopen(static_buff, "rb");\r
if (f) break;\r
+\r
+ strcpy(static_buff, files[i]);\r
+ strcat(static_buff, ".bin");\r
+ f = fopen(static_buff, "rb");\r
+ if (f) break;\r
+\r
+ static_buff[strlen(static_buff) - 4] = 0;\r
+ strcat(static_buff, ".zip");\r
+ f = fopen(static_buff, "rb");\r
+ if (f) break;\r
}\r
\r
if (f) {\r
\r
if (PicoIn.AHW & PAHW_SMS) {\r
sys_name = "Master System";\r
+ if (PicoIn.AHW & PAHW_GG)\r
+ sys_name = "Game Gear";\r
+ else if (PicoIn.AHW & PAHW_SG)\r
+ sys_name = "SG-1000";\r
+ else if (PicoIn.AHW & PAHW_SC)\r
+ sys_name = "SC-3000";\r
+ else if (Pico.m.hardware & PMS_HW_JAP)\r
+ sys_name = "Mark III";\r
#ifdef NO_SMS\r
extra = " [no support]";\r
#endif\r
} else if (PicoIn.AHW & PAHW_32X) {\r
sys_name = "32X";\r
} else {\r
- sys_name = "MegaDrive";\r
+ sys_name = "Mega Drive";\r
if ((Pico.m.hardware & 0xc0) == 0x80)\r
sys_name = "Genesis";\r
}\r
movie_data = 0;\r
}\r
\r
- if (!strcmp(ext, ".gmv"))\r
+ if (!strcasecmp(ext, ".gmv"))\r
{\r
// check for both gmv and rom\r
int dummy;\r
get_ext(rom_fname, ext);\r
lprintf("gmv loaded for %s\n", rom_fname);\r
}\r
- else if (!strcmp(ext, ".pat"))\r
+ else if (!strcasecmp(ext, ".pat"))\r
{\r
int dummy;\r
PicoPatchLoad(rom_fname);\r
\r
emu_make_path(carthw_path, "carthw.cfg", sizeof(carthw_path));\r
\r
- media_type = PicoLoadMedia(rom_fname, carthw_path,\r
+ media_type = PicoLoadMedia(rom_fname, NULL, 0, carthw_path,\r
find_bios, do_region_override);\r
\r
switch (media_type) {\r
}\r
else\r
{\r
+ PicoSetInputDevice(0, currentConfig.input_dev0);\r
+ PicoSetInputDevice(1, currentConfig.input_dev1);\r
+\r
system_announce();\r
PicoIn.opt &= ~POPT_DIS_VDP_FIFO;\r
}\r
\r
int emu_swap_cd(const char *fname)\r
{\r
- enum cd_img_type cd_type;\r
+ enum cd_track_type cd_type;\r
int ret = -1;\r
\r
cd_type = PicoCdCheck(fname, NULL);\r
- if (cd_type != CIT_NOT_CD)\r
+ if (cd_type != CT_UNKNOWN)\r
ret = cdd_load(fname, cd_type);\r
if (ret != 0) {\r
menu_update_msg("Load failed, invalid CD image?");\r
void emu_prep_defconfig(void)\r
{\r
memset(&defaultConfig, 0, sizeof(defaultConfig));\r
- defaultConfig.EmuOpt = 0x9d | EOPT_EN_CD_LEDS;\r
- defaultConfig.s_PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 |\r
+ defaultConfig.EmuOpt = EOPT_EN_SRAM | EOPT_EN_SOUND | EOPT_16BPP |\r
+ EOPT_EN_CD_LEDS | EOPT_GZIP_SAVES | EOPT_PICO_PEN;\r
+ defaultConfig.s_PicoOpt = POPT_EN_SNDFILTER|POPT_EN_GG_LCD|POPT_EN_YM2413 |\r
+ POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 |\r
POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX |\r
POPT_EN_DRC|POPT_ACC_SPRITES |\r
POPT_EN_32X|POPT_EN_PWM;\r
defaultConfig.s_PsndRate = 44100;\r
defaultConfig.s_PicoRegion = 0; // auto\r
defaultConfig.s_PicoAutoRgnOrder = 0x184; // US, EU, JP\r
+ defaultConfig.s_hwSelect = PHWS_AUTO;\r
defaultConfig.s_PicoCDBuffers = 0;\r
+ defaultConfig.s_PicoSndFilterAlpha = 0x10000 * 60 / 100;\r
defaultConfig.confirm_save = EOPT_CONFIRM_SAVE;\r
defaultConfig.Frameskip = -1; // auto\r
defaultConfig.input_dev0 = PICO_INPUT_PAD_3BTN;\r
defaultConfig.turbo_rate = 15;\r
defaultConfig.msh2_khz = PICO_MSH2_HZ / 1000;\r
defaultConfig.ssh2_khz = PICO_SSH2_HZ / 1000;\r
+ defaultConfig.max_skip = 4;\r
\r
// platform specific overrides\r
pemu_prep_defconfig();\r
{\r
memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig));\r
PicoIn.opt = currentConfig.s_PicoOpt;\r
- PsndRate = currentConfig.s_PsndRate;\r
+ PicoIn.sndRate = currentConfig.s_PsndRate;\r
PicoIn.regionOverride = currentConfig.s_PicoRegion;\r
PicoIn.autoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
+ PicoIn.hwSelect = currentConfig.s_hwSelect;\r
+ PicoIn.sndFilterAlpha = currentConfig.s_PicoSndFilterAlpha;\r
}\r
\r
int emu_read_config(const char *rom_fname, int no_defaults)\r
}\r
\r
pemu_validate_config();\r
+ PicoIn.overclockM68k = currentConfig.overclock_68k;\r
\r
// some sanity checks\r
-#ifdef PSP\r
- /* TODO: mv to plat_validate_config() */\r
- if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
- if (currentConfig.gamma < -4 || currentConfig.gamma > 16) currentConfig.gamma = 0;\r
- if (currentConfig.gamma2 < 0 || currentConfig.gamma2 > 2) currentConfig.gamma2 = 0;\r
-#endif\r
if (currentConfig.volume < 0 || currentConfig.volume > 99)\r
currentConfig.volume = 50;\r
\r
} \\r
}\r
\r
-mk_text_out(emu_text_out8, unsigned char, 0xf0, g_screen_ptr, 1, g_screen_width)\r
-mk_text_out(emu_text_out16, unsigned short, 0xffff, g_screen_ptr, 1, g_screen_width)\r
+mk_text_out(emu_text_out8, unsigned char, 0xf0, g_screen_ptr, 1, g_screen_ppitch)\r
+mk_text_out(emu_text_out16, unsigned short, 0xffff, g_screen_ptr, 1, g_screen_ppitch)\r
mk_text_out(emu_text_out8_rot, unsigned char, 0xf0,\r
- (char *)g_screen_ptr + (g_screen_width - 1) * g_screen_height, -g_screen_height, 1)\r
+ (char *)g_screen_ptr + (g_screen_ppitch - 1) * g_screen_height, -g_screen_height, 1)\r
mk_text_out(emu_text_out16_rot, unsigned short, 0xffff,\r
- (short *)g_screen_ptr + (g_screen_width - 1) * g_screen_height, -g_screen_height, 1)\r
+ (short *)g_screen_ptr + (g_screen_ppitch - 1) * g_screen_height, -g_screen_height, 1)\r
\r
#undef mk_text_out\r
\r
for (h = 0; h < 8; h++) {\r
unsigned short *p;\r
p = (unsigned short *)g_screen_ptr\r
- + x + g_screen_width * (y + h);\r
+ + x + g_screen_ppitch * (y + h);\r
for (i = len; i > 0; i--, p++)\r
*p = (*p >> 2) & 0x39e7;\r
}\r
static int set_Frameskip, set_EmuOpt, is_on = 0;\r
\r
if (set_on && !is_on) {\r
- set_PsndOut = PsndOut;\r
+ set_PsndOut = PicoIn.sndOut;\r
set_Frameskip = currentConfig.Frameskip;\r
set_EmuOpt = currentConfig.EmuOpt;\r
- PsndOut = NULL;\r
+ PicoIn.sndOut = NULL;\r
currentConfig.Frameskip = 8;\r
- currentConfig.EmuOpt &= ~4;\r
- currentConfig.EmuOpt |= 0x40000;\r
+ currentConfig.EmuOpt &= ~EOPT_EN_SOUND;\r
+ currentConfig.EmuOpt |= EOPT_NO_FRMLIMIT;\r
is_on = 1;\r
emu_status_msg("FAST FORWARD");\r
}\r
else if (!set_on && is_on) {\r
- PsndOut = set_PsndOut;\r
+ PicoIn.sndOut = set_PsndOut;\r
currentConfig.Frameskip = set_Frameskip;\r
currentConfig.EmuOpt = set_EmuOpt;\r
PsndRerate(1);\r
is_on = 0;\r
- // mainly to unbreak pcm\r
- if (PicoIn.AHW & PAHW_MCD)\r
- pcd_state_loaded();\r
}\r
}\r
\r
reset_timing = 1;\r
}\r
\r
-void run_events_pico(unsigned int events)\r
-{\r
- int lim_x;\r
+static int pico_page;\r
+static int pico_w, pico_h;\r
+static u16 *pico_overlay;\r
\r
- if (events & PEV_PICO_SWINP) {\r
- pico_inp_mode++;\r
- if (pico_inp_mode > 2)\r
- pico_inp_mode = 0;\r
- switch (pico_inp_mode) {\r
- case 2: emu_status_msg("Input: Pen on Pad"); break;\r
- case 1: emu_status_msg("Input: Pen on Storyware"); break;\r
- case 0: emu_status_msg("Input: Joystick");\r
- PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
- break;\r
+static u16 *load_pico_overlay(int page, int w, int h)\r
+{\r
+ static const char *pic_exts[] = { "png", "PNG" };\r
+ char *ext, *fname = NULL;\r
+ int extpos, i;\r
+\r
+ if (pico_page == page && pico_w == w && pico_h == h)\r
+ return pico_overlay;\r
+ pico_page = page;\r
+ pico_w = w, pico_h = h;\r
+\r
+ ext = strrchr(rom_fname_loaded, '.');\r
+ extpos = ext ? ext-rom_fname_loaded : strlen(rom_fname_loaded);\r
+ strcpy(static_buff, rom_fname_loaded);\r
+ static_buff[extpos++] = '_';\r
+ if (page < 0) {\r
+ static_buff[extpos++] = 'p';\r
+ static_buff[extpos++] = 'a';\r
+ static_buff[extpos++] = 'd';\r
+ } else\r
+ static_buff[extpos++] = '0'+PicoPicohw.page;\r
+ static_buff[extpos++] = '.';\r
+\r
+ for (i = 0; i < ARRAY_SIZE(pic_exts); i++) {\r
+ strcpy(static_buff+extpos, pic_exts[i]);\r
+ if (access(static_buff, R_OK) == 0) {\r
+ printf("found Pico file: %s\n", static_buff);\r
+ fname = static_buff;\r
+ break;\r
}\r
}\r
+\r
+ pico_overlay = realloc(pico_overlay, w*h*2);\r
+ memset(pico_overlay, 0, w*h*2);\r
+ if (!fname || !pico_overlay || readpng(pico_overlay, fname, READPNG_SCALE, w, h)) {\r
+ if (pico_overlay)\r
+ free(pico_overlay);\r
+ pico_overlay = NULL;\r
+ }\r
+\r
+ return pico_overlay;\r
+}\r
+\r
+void emu_pico_overlay(u16 *pd, int w, int h, int pitch)\r
+{\r
+ u16 *overlay = NULL;\r
+ int y, oh = h;\r
+\r
+ // get overlay\r
+ if (pico_inp_mode == 1) {\r
+ oh = (w/2 < h ? w/2 : h); // storyware has squished h\r
+ overlay = load_pico_overlay(PicoPicohw.page, w, oh);\r
+ } else if (pico_inp_mode == 2)\r
+ overlay = load_pico_overlay(-1, w, oh);\r
+\r
+ // copy overlay onto buffer\r
+ if (overlay) {\r
+ for (y = 0; y < oh; y++)\r
+ memcpy(pd + y*pitch, overlay + y*w, w*2);\r
+ if (y < h)\r
+ memset(pd + y*pitch, 0, w*2);\r
+ }\r
+}\r
+\r
+void run_events_pico(unsigned int events)\r
+{\r
if (events & PEV_PICO_PPREV) {\r
PicoPicohw.page--;\r
if (PicoPicohw.page < 0)\r
PicoPicohw.page = 6;\r
emu_status_msg("Page %i", PicoPicohw.page);\r
}\r
+ if (events & PEV_PICO_STORY) {\r
+ if (pico_inp_mode == 1) {\r
+ pico_inp_mode = 0;\r
+ emu_status_msg("Input: D-Pad");\r
+ } else {\r
+ pico_inp_mode = 1;\r
+ emu_status_msg("Input: Pen on Storyware");\r
+ }\r
+ }\r
+ if (events & PEV_PICO_PAD) {\r
+ if (pico_inp_mode == 2) {\r
+ pico_inp_mode = 0;\r
+ emu_status_msg("Input: D-Pad");\r
+ } else {\r
+ pico_inp_mode = 2;\r
+ emu_status_msg("Input: Pen on Pad");\r
+ }\r
+ }\r
+ if (events & PEV_PICO_PENST) {\r
+ PicoPicohw.pen_pos[0] ^= 0x8000;\r
+ PicoPicohw.pen_pos[1] ^= 0x8000;\r
+ emu_status_msg("Pen %s", PicoPicohw.pen_pos[0] & 0x8000 ? "Up" : "Down");\r
+ }\r
\r
+ if ((currentConfig.EmuOpt & EOPT_PICO_PEN) &&\r
+ (PicoIn.pad[0]&0x20) && pico_inp_mode && pico_overlay) {\r
+ pico_inp_mode = 0;\r
+ emu_status_msg("Input: D-Pad");\r
+ }\r
if (pico_inp_mode == 0)\r
return;\r
\r
if (PicoIn.pad[0] & 8) pico_pen_x++;\r
PicoIn.pad[0] &= ~0x0f; // release UDLR\r
\r
- lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
- if (pico_pen_y < 8)\r
- pico_pen_y = 8;\r
- if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)\r
- pico_pen_y = 224 - PICO_PEN_ADJUST_Y;\r
- if (pico_pen_x < 0)\r
- pico_pen_x = 0;\r
- if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)\r
- 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))\r
- 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
+ /* cursor position, cursor drawing must not cross screen borders */\r
+ if (pico_pen_y < PICO_PEN_ADJUST_Y)\r
+ pico_pen_y = PICO_PEN_ADJUST_Y;\r
+ if (pico_pen_y > 223-1 - PICO_PEN_ADJUST_Y)\r
+ pico_pen_y = 223-1 - PICO_PEN_ADJUST_Y;\r
+ if (pico_pen_x < PICO_PEN_ADJUST_X)\r
+ pico_pen_x = PICO_PEN_ADJUST_X;\r
+ if (pico_pen_x > 319-1 - PICO_PEN_ADJUST_X)\r
+ pico_pen_x = 319-1 - PICO_PEN_ADJUST_X;\r
+\r
+ PicoPicohw.pen_pos[0] &= 0x8000;\r
+ PicoPicohw.pen_pos[1] &= 0x8000;\r
+ PicoPicohw.pen_pos[0] |= 0x03c + pico_pen_x;\r
+ PicoPicohw.pen_pos[1] |= (pico_inp_mode == 1 ? 0x2f8 : 0x1fc) + pico_pen_y;\r
}\r
\r
static void do_turbo(unsigned short *pad, int acts)\r
while (in_menu_wait_any(NULL, 50) & (PBTN_MOK | PBTN_MBACK))\r
;\r
in_set_config_int(0, IN_CFG_BLOCKING, 0);\r
+ plat_status_msg_clear();\r
}\r
if (do_it) {\r
plat_status_msg_busy_first((which & PEV_STATE_LOAD) ? "LOADING STATE" : "SAVING STATE");\r
{\r
static int prev_events = 0;\r
int actions[IN_BINDTYPE_COUNT] = { 0, };\r
- int pl_actions[2];\r
+ int pl_actions[4];\r
int events;\r
\r
in_update(actions);\r
\r
pl_actions[0] = actions[IN_BINDTYPE_PLAYER12];\r
pl_actions[1] = actions[IN_BINDTYPE_PLAYER12] >> 16;\r
+ pl_actions[2] = actions[IN_BINDTYPE_PLAYER34];\r
+ pl_actions[3] = actions[IN_BINDTYPE_PLAYER34] >> 16;\r
\r
PicoIn.pad[0] = pl_actions[0] & 0xfff;\r
PicoIn.pad[1] = pl_actions[1] & 0xfff;\r
+ PicoIn.pad[2] = pl_actions[2] & 0xfff;\r
+ PicoIn.pad[3] = pl_actions[3] & 0xfff;\r
\r
if (pl_actions[0] & 0x7000)\r
do_turbo(&PicoIn.pad[0], pl_actions[0]);\r
if (pl_actions[1] & 0x7000)\r
do_turbo(&PicoIn.pad[1], pl_actions[1]);\r
+ if (pl_actions[2] & 0x7000)\r
+ do_turbo(&PicoIn.pad[2], pl_actions[2]);\r
+ if (pl_actions[3] & 0x7000)\r
+ do_turbo(&PicoIn.pad[3], pl_actions[3]);\r
\r
events = actions[IN_BINDTYPE_EMU] & PEV_MASK;\r
\r
strcpy(path_with_reserve + pos, name);\r
if (plat_is_dir(path_with_reserve))\r
return;\r
- if (mkdir(path_with_reserve, 0777) < 0)\r
+ if (mkdir(path_with_reserve, 0755) < 0)\r
lprintf("failed to create: %s\n", path_with_reserve);\r
}\r
\r
-void emu_cmn_forced_frame(int no_scale, int do_emu)\r
+void emu_cmn_forced_frame(int no_scale, int do_emu, void *buf)\r
{\r
int po_old = PicoIn.opt;\r
+ int y;\r
\r
- memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r
+ for (y = 0; y < g_screen_height; y++)\r
+ memset32((short *)g_screen_ptr + g_screen_ppitch * y, 0,\r
+ g_screen_width * 2 / 4);\r
\r
- PicoIn.opt &= ~POPT_ALT_RENDERER;\r
+ PicoIn.opt &= ~(POPT_ALT_RENDERER|POPT_EN_SOFTSCALE);\r
PicoIn.opt |= POPT_ACC_SPRITES;\r
- if (!no_scale)\r
+ if (!no_scale && currentConfig.scaling)\r
PicoIn.opt |= POPT_EN_SOFTSCALE;\r
\r
PicoDrawSetOutFormat(PDF_RGB555, 1);\r
+ PicoDrawSetOutBuf(buf, g_screen_ppitch * 2);\r
Pico.m.dirtyPal = 1;\r
if (do_emu)\r
PicoFrame();\r
config_readlrom(path);\r
\r
PicoInit();\r
- PicoMessage = plat_status_msg_busy_next;\r
- PicoMCDopenTray = emu_tray_open;\r
- PicoMCDcloseTray = emu_tray_close;\r
+ PicoIn.osdMessage = plat_status_msg_busy_next;\r
+ PicoIn.mcdTrayOpen = emu_tray_open;\r
+ PicoIn.mcdTrayClose = emu_tray_close;\r
\r
sndout_init();\r
}\r
\r
static void snd_write_nonblocking(int len)\r
{\r
- sndout_write_nb(PsndOut, len);\r
+ sndout_write_nb(PicoIn.sndOut, len);\r
}\r
\r
void emu_sound_start(void)\r
{\r
- PsndOut = NULL;\r
+ PicoIn.sndOut = NULL;\r
\r
+ // auto-select rate?\r
+ if (PicoIn.sndRate > 52000 && PicoIn.sndRate < 54000)\r
+ PicoIn.sndRate = YM2612_NATIVE_RATE();\r
if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
{\r
int is_stereo = (PicoIn.opt & POPT_EN_STEREO) ? 1 : 0;\r
\r
+ memset(sndBuffer, 0, sizeof(sndBuffer));\r
+ PicoIn.sndOut = sndBuffer;\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
+ PicoIn.sndRate, Pico.snd.len, is_stereo, Pico.m.pal);\r
+\r
+ sndout_start(PicoIn.sndRate, is_stereo);\r
+ PicoIn.writeSound = snd_write_nonblocking;\r
plat_update_volume(0, 0);\r
- memset(sndBuffer, 0, sizeof(sndBuffer));\r
- PsndOut = sndBuffer;\r
}\r
}\r
\r
}\r
\r
/* our tick here is 1 us right now */\r
-#define ms_to_ticks(x) (unsigned int)(x * 1000)\r
-#define get_ticks() plat_get_ticks_us()\r
+#define ms_to_ticks(x) (int)(x * 1000)\r
+#define get_ticks() plat_get_ticks_us()\r
+#define vsync_delay ms_to_ticks(1)\r
\r
void emu_loop(void)\r
{\r
int frames_done, frames_shown; /* actual frames for fps counter */\r
- int target_frametime_x3;\r
- unsigned int timestamp_x3 = 0;\r
- unsigned int timestamp_aim_x3 = 0;\r
- unsigned int timestamp_fps_x3 = 0;\r
+ int target_frametime;\r
+ unsigned int timestamp = 0;\r
+ unsigned int timestamp_aim = 0;\r
+ unsigned int timestamp_fps = 0;\r
char *notice_msg = NULL;\r
char fpsbuff[24];\r
int fskip_cnt = 0;\r
\r
/* number of ticks per frame */\r
if (Pico.m.pal)\r
- target_frametime_x3 = 3 * ms_to_ticks(1000) / 50;\r
+ target_frametime = ms_to_ticks(1000) / 50;\r
else\r
- target_frametime_x3 = 3 * ms_to_ticks(1000) / 60;\r
+ target_frametime = ms_to_ticks(1000) / 60;\r
\r
reset_timing = 1;\r
frames_done = frames_shown = 0;\r
if (reset_timing) {\r
reset_timing = 0;\r
plat_video_wait_vsync();\r
- timestamp_aim_x3 = get_ticks() * 3;\r
- timestamp_fps_x3 = timestamp_aim_x3;\r
+ timestamp_aim = get_ticks();\r
+ timestamp_fps = timestamp_aim;\r
fskip_cnt = 0;\r
}\r
else if (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) {\r
- timestamp_aim_x3 = get_ticks() * 3;\r
+ timestamp_aim = get_ticks();\r
}\r
\r
- timestamp_x3 = get_ticks() * 3;\r
+ timestamp = get_ticks();\r
\r
// show notice_msg message?\r
if (notice_msg_time != 0)\r
{\r
static int noticeMsgSum;\r
- if (timestamp_x3 - ms_to_ticks(notice_msg_time) * 3\r
- > ms_to_ticks(STATUS_MSG_TIMEOUT) * 3)\r
+ if (timestamp - ms_to_ticks(notice_msg_time)\r
+ > ms_to_ticks(STATUS_MSG_TIMEOUT))\r
{\r
notice_msg_time = 0;\r
- plat_status_msg_clear();\r
- plat_video_flip();\r
- plat_status_msg_clear(); /* Do it again in case of double buffering */\r
notice_msg = NULL;\r
+ plat_status_msg_clear();\r
}\r
else {\r
int sum = noticeMsg[0] + noticeMsg[1] + noticeMsg[2];\r
}\r
\r
// second changed?\r
- if (timestamp_x3 - timestamp_fps_x3 >= ms_to_ticks(1000) * 3)\r
+ if (timestamp - timestamp_fps >= ms_to_ticks(1000))\r
{\r
#ifdef BENCHMARK\r
static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];\r
snprintf(fpsbuff, 8, "%02i/%02i ", frames_shown, frames_done);\r
#endif\r
frames_shown = frames_done = 0;\r
- timestamp_fps_x3 += ms_to_ticks(1000) * 3;\r
+ timestamp_fps += ms_to_ticks(1000);\r
}\r
#ifdef PFRAMES\r
sprintf(fpsbuff, "%i", Pico.m.frame_count);\r
#endif\r
\r
- diff = timestamp_aim_x3 - timestamp_x3;\r
+ diff = timestamp_aim - timestamp;\r
\r
if (currentConfig.Frameskip >= 0) // frameskip enabled (or 0)\r
{\r
fskip_cnt = 0;\r
}\r
}\r
- else if (diff < -target_frametime_x3)\r
+ else if (diff < -target_frametime)\r
{\r
/* no time left for this frame - skip */\r
- /* limit auto frameskip to 8 */\r
- if (frames_done / 8 <= frames_shown)\r
+ /* limit auto frameskip to max_skip */\r
+ if (fskip_cnt < currentConfig.max_skip) {\r
+ fskip_cnt++;\r
skip = 1;\r
- }\r
+ }\r
+ else {\r
+ fskip_cnt = 0;\r
+ }\r
+ } else\r
+ fskip_cnt = 0;\r
\r
// don't go in debt too much\r
- while (diff < -target_frametime_x3 * 3) {\r
- timestamp_aim_x3 += target_frametime_x3;\r
- diff = timestamp_aim_x3 - timestamp_x3;\r
+ while (diff < -target_frametime * 3) {\r
+ timestamp_aim += target_frametime;\r
+ diff = timestamp_aim - timestamp;\r
}\r
\r
emu_update_input();\r
if (skip) {\r
- int do_audio = diff > -target_frametime_x3 * 2;\r
+ int do_audio = diff > -target_frametime * 2;\r
PicoIn.skipFrame = do_audio ? 1 : 2;\r
PicoFrame();\r
PicoIn.skipFrame = 0;\r
frames_shown++;\r
}\r
frames_done++;\r
- timestamp_aim_x3 += target_frametime_x3;\r
+ timestamp_aim += target_frametime;\r
\r
if (!skip && !flip_after_sync)\r
plat_video_flip();\r
&& !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT)))\r
{\r
unsigned int timestamp = get_ticks();\r
- diff = timestamp_aim_x3 - timestamp * 3;\r
+ diff = timestamp_aim - timestamp;\r
\r
// sleep or vsync if we are still too fast\r
- if (diff > target_frametime_x3 && (currentConfig.EmuOpt & EOPT_VSYNC)) {\r
+ if (diff > target_frametime + vsync_delay && (currentConfig.EmuOpt & EOPT_VSYNC)) {\r
// we are too fast\r
plat_video_wait_vsync();\r
timestamp = get_ticks();\r
- diff = timestamp * 3 - timestamp_aim_x3;\r
+ diff = timestamp_aim - timestamp;\r
}\r
- if (diff > target_frametime_x3) {\r
+ if (diff > target_frametime + vsync_delay) {\r
// still too fast\r
- plat_wait_till_us(timestamp + (diff - target_frametime_x3) / 3);\r
+ plat_wait_till_us(timestamp + (diff - target_frametime));\r
}\r
}\r
\r