X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fcommon%2Femu.c;h=08efdb2cbafaf185b3b82473793dd3f3a79215dd;hb=37807164d4d20e0f4ab33cc842993168641fea33;hp=141356a30153247bb6049252d710e5781a694ecb;hpb=a47dd66367c0d6d4ae2957dfd028125636ca9f65;p=picodrive.git diff --git a/platform/common/emu.c b/platform/common/emu.c index 141356a..08efdb2 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -112,8 +112,7 @@ static int find_bios(int region, char **bios_file) for (i = 0; i < count; i++) { - plat_get_root_dir(bios_path, sizeof(bios_path)); - strcat(bios_path, files[i]); + emu_make_path(bios_path, files[i], sizeof(bios_path) - 4); strcat(bios_path, ".bin"); f = fopen(bios_path, "rb"); if (f) break; @@ -533,18 +532,29 @@ static void romfname_ext(char *dst, const char *prefix, const char *ext) if (ext) strcat(dst, ext); } -static void make_config_cfg(char *cfg) +void emu_make_path(char *buff, const char *end, int size) { - int len; - len = plat_get_root_dir(cfg, 512); - strncpy(cfg + len, PicoConfigFile, 512-6-1-len); + int pos, end_len; + + end_len = strlen(end); + pos = plat_get_root_dir(buff, size); + strncpy(buff + pos, end, size - pos); + buff[size - 1] = 0; + if (pos + end_len > size - 1) + lprintf("Warning: path truncated: %s\n", buff); +} + +static void make_config_cfg(char *cfg_buff_512) +{ + emu_make_path(cfg_buff_512, PicoConfigFile, 512-6); if (config_slot != 0) { - char *p = strrchr(cfg, '.'); - if (p == NULL) p = cfg + strlen(cfg); + char *p = strrchr(cfg_buff_512, '.'); + if (p == NULL) + p = cfg_buff_512 + strlen(cfg_buff_512); sprintf(p, ".%i.cfg", config_slot); } - cfg[511] = 0; + cfg_buff_512[511] = 0; } static void emu_setDefaultConfig(void) @@ -650,16 +660,6 @@ int emu_write_config(int is_game) } -void emu_writelrom(void) -{ - char cfg[512]; - make_config_cfg(cfg); - config_writelrom(cfg); -#ifndef NO_SYNC - sync(); -#endif -} - /* always using built-in font */ #define mk_text_out(name, type, val) \ @@ -1099,31 +1099,37 @@ static void run_events_ui(unsigned int which) void emu_update_input(void) { - unsigned int allActions[2] = { 0, 0 }, events; - static unsigned int prevEvents = 0; + static int prev_events = 0; + int actions[IN_BINDTYPE_COUNT] = { 0, }; + int pl_actions[2]; + int events; - /* FIXME: player2 */ - allActions[0] = in_update(); + in_update(actions); - PicoPad[0] = allActions[0] & 0xfff; - PicoPad[1] = allActions[1] & 0xfff; + pl_actions[0] = actions[IN_BINDTYPE_PLAYER12]; + pl_actions[1] = actions[IN_BINDTYPE_PLAYER12] >> 16; - if (allActions[0] & 0x7000) do_turbo(&PicoPad[0], allActions[0]); - if (allActions[1] & 0x7000) do_turbo(&PicoPad[1], allActions[1]); + PicoPad[0] = pl_actions[0] & 0xfff; + PicoPad[1] = pl_actions[1] & 0xfff; - events = (allActions[0] | allActions[1]) & PEV_MASK; + if (pl_actions[0] & 0x7000) + do_turbo(&PicoPad[0], pl_actions[0]); + if (pl_actions[1] & 0x7000) + do_turbo(&PicoPad[1], pl_actions[1]); + + events = actions[IN_BINDTYPE_EMU] & PEV_MASK; // volume is treated in special way and triggered every frame if (events & (PEV_VOL_DOWN|PEV_VOL_UP)) plat_update_volume(1, events & PEV_VOL_UP); - if ((events ^ prevEvents) & PEV_FF) { + if ((events ^ prev_events) & PEV_FF) { emu_set_fastforward(events & PEV_FF); plat_update_volume(0, 0); reset_timing = 1; } - events &= ~prevEvents; + events &= ~prev_events; if (PicoAHW == PAHW_PICO) run_events_pico(events); @@ -1132,7 +1138,7 @@ void emu_update_input(void) if (movie_data) update_movie(); - prevEvents = (allActions[0] | allActions[1]) & PEV_MASK; + prev_events = actions[IN_BINDTYPE_EMU] & PEV_MASK; } static void mkdir_path(char *path_with_reserve, int pos, const char *name) @@ -1146,14 +1152,17 @@ static void mkdir_path(char *path_with_reserve, int pos, const char *name) void emu_init(void) { - char dir[256]; + char path[512]; int pos; /* make dirs for saves */ - pos = plat_get_root_dir(dir, sizeof(dir) - 4); - mkdir_path(dir, pos, "mds"); - mkdir_path(dir, pos, "srm"); - mkdir_path(dir, pos, "brm"); + pos = plat_get_root_dir(path, sizeof(path) - 4); + mkdir_path(path, pos, "mds"); + mkdir_path(path, pos, "srm"); + mkdir_path(path, pos, "brm"); + + make_config_cfg(path); + config_readlrom(path); PicoInit(); PicoMessage = plat_status_msg_busy_next; @@ -1169,8 +1178,14 @@ void emu_finish(void) SRam.changed = 0; } - if (!(currentConfig.EmuOpt & EOPT_NO_AUTOSVCFG)) - emu_writelrom(); + if (!(currentConfig.EmuOpt & EOPT_NO_AUTOSVCFG)) { + char cfg[512]; + make_config_cfg(cfg); + config_writelrom(cfg); +#ifndef NO_SYNC + sync(); +#endif + } PicoExit(); }