X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=common%2Femu.c;h=1c7d1b7cc60d6472921b3cec1e33583973c109d6;hb=0aa509f90d056abafd8a9114f11a9ae3df0bfefb;hp=c5686fddf41947d1996223787dd966620df7a709;hpb=8e77275edade55d89b0723a60ab4ef1e2ec288de;p=libpicofe.git diff --git a/common/emu.c b/common/emu.c index c5686fd..1c7d1b7 100644 --- a/common/emu.c +++ b/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,21 +532,32 @@ 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) +void emu_set_defconfig(void) { memcpy(¤tConfig, &defaultConfig, sizeof(currentConfig)); PicoOpt = currentConfig.s_PicoOpt; @@ -565,7 +575,7 @@ int emu_read_config(int game, int no_defaults) if (!game) { if (!no_defaults) - emu_setDefaultConfig(); + emu_set_defconfig(); make_config_cfg(cfg); ret = config_readsect(cfg, NULL); } @@ -583,7 +593,7 @@ int emu_read_config(int game, int no_defaults) { // read user's config int vol = currentConfig.volume; - emu_setDefaultConfig(); + emu_set_defconfig(); ret = config_readsect(cfg, sect); currentConfig.volume = vol; // make vol global (bah) } @@ -650,44 +660,38 @@ 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) \ +#define mk_text_out(name, type, val, topleft, step_x, step_y) \ void name(int x, int y, const char *text) \ { \ int i, l, len = strlen(text); \ - type *screen = (type *)g_screen_ptr + x + y * g_screen_width; \ + type *screen = (type *)(topleft) + x * step_x + y * step_y; \ \ - for (i = 0; i < len; i++, screen += 8) \ + for (i = 0; i < len; i++, screen += 8 * step_x) \ { \ for (l = 0; l < 8; l++) \ { \ unsigned char fd = fontdata8x8[text[i] * 8 + l];\ - type *s = screen + l * g_screen_width; \ - if (fd&0x80) s[0] = val; \ - if (fd&0x40) s[1] = val; \ - if (fd&0x20) s[2] = val; \ - if (fd&0x10) s[3] = val; \ - if (fd&0x08) s[4] = val; \ - if (fd&0x04) s[5] = val; \ - if (fd&0x02) s[6] = val; \ - if (fd&0x01) s[7] = val; \ + type *s = screen + l * step_y; \ + if (fd&0x80) s[step_x * 0] = val; \ + if (fd&0x40) s[step_x * 1] = val; \ + if (fd&0x20) s[step_x * 2] = val; \ + if (fd&0x10) s[step_x * 3] = val; \ + if (fd&0x08) s[step_x * 4] = val; \ + if (fd&0x04) s[step_x * 5] = val; \ + if (fd&0x02) s[step_x * 6] = val; \ + if (fd&0x01) s[step_x * 7] = val; \ } \ } \ } -mk_text_out(emu_textOut8, unsigned char, 0xf0) -mk_text_out(emu_textOut16, unsigned short, 0xffff) +mk_text_out(emu_text_out8, unsigned char, 0xf0, g_screen_ptr, 1, g_screen_width) +mk_text_out(emu_text_out16, unsigned short, 0xffff, g_screen_ptr, 1, g_screen_width) +mk_text_out(emu_text_out8_rot, unsigned char, 0xf0, + (char *)g_screen_ptr + (g_screen_width - 1) * g_screen_height, -g_screen_height, 1) +mk_text_out(emu_text_out16_rot, unsigned short, 0xffff, + (short *)g_screen_ptr + (g_screen_width - 1) * g_screen_height, -g_screen_height, 1) #undef mk_text_out @@ -1076,7 +1080,7 @@ static void run_events_ui(unsigned int which) } if (which & PEV_SWITCH_RND) { - plat_video_toggle_renderer(); + plat_video_toggle_renderer(1, 0); } if (which & (PEV_SSLOT_PREV|PEV_SSLOT_NEXT)) { @@ -1152,14 +1156,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; @@ -1175,8 +1182,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(); }