From: kub Date: Sun, 29 Jan 2023 19:37:03 +0000 (+0000) Subject: Merge remote-tracking branch 'notaz/master' X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b58e15633b54621f9508cb673da61a6b0844955;hp=7167e5f3376f0d0692ae102ed2df1ef5d2cc199a;p=libpicofe.git Merge remote-tracking branch 'notaz/master' --- diff --git a/config_file.c b/config_file.c index a1e67ae..248025d 100644 --- a/config_file.c +++ b/config_file.c @@ -92,6 +92,22 @@ void config_write_keys(FILE *f) } } + kbinds = binds[IN_BIND_OFFS(k, IN_BINDTYPE_PLAYER34)]; + for (i = 0; kbinds && me_ctrl_actions[i].name != NULL; i++) { + mask = me_ctrl_actions[i].mask; + if (mask & kbinds) { + strncpy(act, me_ctrl_actions[i].name, 31); + fprintf(f, "bind %s = player3 %s\n", name, mystrip(act)); + kbinds &= ~mask; + } + mask = me_ctrl_actions[i].mask << 16; + if (mask & kbinds) { + strncpy(act, me_ctrl_actions[i].name, 31); + fprintf(f, "bind %s = player4 %s\n", name, mystrip(act)); + kbinds &= ~mask; + } + } + kbinds = binds[IN_BIND_OFFS(k, IN_BINDTYPE_EMU)]; for (i = 0; kbinds && emuctrl_actions[i].name != NULL; i++) { mask = emuctrl_actions[i].mask; @@ -126,12 +142,12 @@ static int parse_bind_val(const char *val, int *type) int player, shift = 0; player = atoi(val + 6) - 1; - if ((unsigned int)player > 1) + if ((unsigned int)player > 3) return -1; - if (player == 1) + if (player & 1) shift = 16; - *type = IN_BINDTYPE_PLAYER12; + *type = IN_BINDTYPE_PLAYER12 + (player >> 1); for (i = 0; me_ctrl_actions[i].name != NULL; i++) { if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0) return me_ctrl_actions[i].mask << shift; diff --git a/gl.c b/gl.c index 0e18c45..3f72c77 100644 --- a/gl.c +++ b/gl.c @@ -10,10 +10,15 @@ static EGLDisplay edpy; static EGLSurface esfc; static EGLContext ectxt; +static GLuint texture_name; + /* for external flips */ void *gl_es_display; void *gl_es_surface; +static int tex_w, tex_h; +static void *tex_mem; + static int gl_have_error(const char *name) { GLenum e = glGetError(); @@ -34,11 +39,9 @@ static int gles_have_error(const char *name) return 0; } -int gl_init(void *display, void *window, int *quirks) +int gl_init(void *display, void *window, int *quirks, int w, int h) { EGLConfig ecfg = NULL; - GLuint texture_name = 0; - void *tmp_texture_mem = NULL; EGLint num_config; int retval = -1; int ret; @@ -53,8 +56,10 @@ int gl_init(void *display, void *window, int *quirks) goto out; } - tmp_texture_mem = calloc(1, 1024 * 512 * 2); - if (tmp_texture_mem == NULL) { + for (tex_w = 1; tex_w < w; tex_w *= 2); + for (tex_h = 1; tex_h < h; tex_h *= 2); + tex_mem = realloc(tex_mem, tex_w * tex_h * 2); + if (tex_mem == NULL) { fprintf(stderr, "OOM\n"); goto out; } @@ -99,12 +104,15 @@ int gl_init(void *display, void *window, int *quirks) glEnable(GL_TEXTURE_2D); + if (texture_name) + glDeleteTextures(1, &texture_name); + glGenTextures(1, &texture_name); glBindTexture(GL_TEXTURE_2D, texture_name); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 512, 0, GL_RGB, - GL_UNSIGNED_SHORT_5_6_5, tmp_texture_mem); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_w, tex_h, 0, GL_RGB, + GL_UNSIGNED_SHORT_5_6_5, tex_mem); if (gl_have_error("glTexImage2D")) goto out; @@ -127,7 +135,6 @@ int gl_init(void *display, void *window, int *quirks) gl_es_surface = (void *)esfc; retval = 0; out: - free(tmp_texture_mem); return retval; } @@ -156,8 +163,8 @@ int gl_flip(const void *fb, int w, int h) if (fb != NULL) { if (w != old_w || h != old_h) { - float f_w = (float)w / 1024.0f; - float f_h = (float)h / 512.0f; + float f_w = (float)w / tex_w; + float f_h = (float)h / tex_h; texture[1*2 + 0] = f_w; texture[2*2 + 1] = f_h; texture[3*2 + 0] = f_w; @@ -199,5 +206,8 @@ void gl_finish(void) gl_es_display = (void *)edpy; gl_es_surface = (void *)esfc; + if (tex_mem) free(tex_mem); + tex_mem = NULL; + gl_platform_finish(); } diff --git a/gl.h b/gl.h index ed1f977..bddacdc 100644 --- a/gl.h +++ b/gl.h @@ -3,7 +3,7 @@ #ifdef HAVE_GLES -int gl_init(void *display, void *window, int *quirks); +int gl_init(void *display, void *window, int *quirks, int w, int h); void gl_announce(void); int gl_flip(const void *fb, int w, int h); void gl_finish(void); @@ -14,7 +14,7 @@ extern void *gl_es_surface; #else -static __inline int gl_init(void *display, void *window, int *quirks) +static __inline int gl_init(void *display, void *window, int *quirks, int w, int h) { return -1; } diff --git a/in_sdl.c b/in_sdl.c index a84c781..d8f5ed5 100644 --- a/in_sdl.c +++ b/in_sdl.c @@ -24,6 +24,9 @@ struct in_sdl_state { SDL_Joystick *joy; int joy_id; int axis_keydown[2]; +#ifdef SDL_REDRAW_EVT + int rdraw; +#endif keybits_t keystate[SDLK_LAST / KEYBITS_WORD_BITS + 1]; // emulator keys should always be processed immediately lest one is lost keybits_t emu_keys[SDLK_LAST / KEYBITS_WORD_BITS + 1]; @@ -274,7 +277,7 @@ static int handle_event(struct in_sdl_state *state, SDL_Event *event, *kc_out = event->key.keysym.sym; if (down_out != NULL) *down_out = event->type == SDL_KEYDOWN; - if (emu_out != 0) + if (emu_out != NULL) *emu_out = emu; return 1; @@ -354,11 +357,21 @@ static int collect_events(struct in_sdl_state *state, int *one_kc, int *one_down { SDL_Event events[4]; Uint32 mask = state->joy ? JOY_EVENTS : (SDL_ALLEVENTS & ~JOY_EVENTS); - int count, maxcount, is_emukey; + int count, maxcount, is_emukey = 0; int i, ret, retval = 0; int num_events, num_peeped_events; SDL_Event *event; +#ifdef SDL_REDRAW_EVT + if (state->rdraw) { + if (one_kc != NULL) + *one_kc = SDLK_UNKNOWN; + if (one_down != NULL) + *one_down = 0; + state->rdraw = 0; + return 1; + } +#endif maxcount = (one_kc != NULL) ? 1 : sizeof(events) / sizeof(events[0]); SDL_PumpEvents(); @@ -388,11 +401,21 @@ static int collect_events(struct in_sdl_state *state, int *one_kc, int *one_down ext_event_handler(event); break; } - continue; +#ifdef SDL_REDRAW_EVT + if (ret != -2 && event->type == SDL_VIDEORESIZE) { + if (one_kc != NULL) + *one_kc = SDLK_UNKNOWN; + if (one_down != NULL) + *one_down = 1; + state->rdraw = 1; + is_emukey = 1, ret = 1; + } else + continue; +#endif } retval |= ret; - if ((is_emukey || one_kc != NULL) && ret) + if ((is_emukey || one_kc != NULL) && retval) { // don't lose events other devices might want to handle if (++i < count) @@ -475,6 +498,11 @@ static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode) } else { +#ifdef SDL_REDRAW_EVT + if (keycode == SDLK_UNKNOWN) + ret = PBTN_RDRAW; + else +#endif for (i = 0; i < map_len; i++) { if (map[i].key == keycode) { ret = map[i].pbtn; diff --git a/input.c b/input.c index aa1f155..b2168fc 100644 --- a/input.c +++ b/input.c @@ -462,6 +462,9 @@ int in_menu_wait(int interesting, char *charcode, int autorep_delay_ms) wait = autorep_delay_ms; /* wait until either key repeat or a new key has been pressed */ +#ifdef SDL_REDRAW_EVT + interesting |= PBTN_RDRAW; +#endif do { ret = in_menu_wait_any(charcode, wait); if (ret == 0 || ret != menu_key_prev) diff --git a/input.h b/input.h index 360b65b..ba6c15f 100644 --- a/input.h +++ b/input.h @@ -21,6 +21,7 @@ #define PBTN_MENU (1 << 10) #define PBTN_CHAR (1 << 11) /* character (text input) */ +#define PBTN_RDRAW (1 << 12) /* redraw event */ // TODO: move to pico #if 0 @@ -70,6 +71,7 @@ enum { IN_BINDTYPE_NONE = -1, IN_BINDTYPE_EMU = 0, IN_BINDTYPE_PLAYER12, + IN_BINDTYPE_PLAYER34, IN_BINDTYPE_COUNT }; diff --git a/linux/host_dasm.c b/linux/host_dasm.c index 24af1b8..a5e66c9 100644 --- a/linux/host_dasm.c +++ b/linux/host_dasm.c @@ -21,6 +21,7 @@ extern char **g_argv; static struct disassemble_info di; +static disassembler_ftype print_insn_func; #if defined __arm__ #define print_insn_func print_insn_little_arm @@ -35,10 +36,10 @@ static struct disassemble_info di; #elif defined __mips__ #define print_insn_func print_insn_little_mips #define BFD_ARCH bfd_arch_mips -#define BFD_MACH bfd_mach_mipsisa32 +#define BFD_MACH bfd_mach_mipsisa64r2 #define DASM_OPTS NULL #elif defined __riscv -#define print_insn_func print_insn_riscv +//#define print_insn_func print_insn_riscv #define BFD_ARCH bfd_arch_riscv #define BFD_MACH bfd_mach_riscv64 #define DASM_OPTS NULL @@ -160,7 +161,7 @@ static int dis_asm_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int len, struct disassemble_info *info) { - memcpy(myaddr, (void *)(long)memaddr, len); + memcpy(myaddr, (void *)memaddr, len); return 0; } @@ -195,10 +196,20 @@ static int insn_printf(void *f, const char *format, ...) return n; } +static int print_insn_hex(bfd_vma addr, struct disassemble_info *info) +{ + unsigned op; + + dis_asm_read_memory(addr, (bfd_byte *)&op, 4, info); + printf("%p %08lx",(void *)addr, (long)op); + return 4; +} + static void host_dasm_init(void) { bfd_init(); - slurp_symtab(g_argv[0]); + if (g_argv && g_argv[0]) + slurp_symtab(g_argv[0]); init_disassemble_info(&di, NULL, insn_printf); di.flavour = bfd_target_unknown_flavour; @@ -211,12 +222,16 @@ static void host_dasm_init(void) di.endian = BFD_ENDIAN_LITTLE; di.disassembler_options = DASM_OPTS; disassemble_init_for_target(&di); +#ifndef print_insn_func + print_insn_func = disassembler(BFD_ARCH, 0, BFD_MACH, NULL); + if (!print_insn_func) print_insn_func = print_insn_hex; +#endif init_done = 1; } void host_dasm(void *addr, int len) { - bfd_vma vma_end, vma = (bfd_vma)(long)addr; + bfd_vma vma_end, vma = (bfd_vma)addr; const char *name; if (!init_done) diff --git a/linux/plat.c b/linux/plat.c index 9109a32..707d5f7 100644 --- a/linux/plat.c +++ b/linux/plat.c @@ -75,7 +75,7 @@ int plat_get_skin_dir(char *dst, int len) { int ret = plat_get_exe_dir(dst, len); if (ret < 0) - return ret; + ret = 0; memcpy(dst + ret, "skin/", sizeof "skin/"); return ret + sizeof("skin/") - 1; diff --git a/menu.c b/menu.c index 50138f3..96b1ea2 100644 --- a/menu.c +++ b/menu.c @@ -981,10 +981,9 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c) { int i; - sel++; for (i = sel + 1; ; i++) { if (i >= len) - i = 1; + i = 0; if (i == sel) break; @@ -992,7 +991,7 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c) break; } - return i - 1; + return i; } static const char *menu_loop_romsel(char *curr_path, int len, @@ -1109,14 +1108,14 @@ rescan: namelist[sel]->d_name); goto rescan; } - if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-1; } - if (inp & PBTN_DOWN) { sel++; if (sel > n-1) sel = 0; } - if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } - if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } - if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = n-1; } - if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = n-1; } - - if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2)) + if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-1; } + else if (inp & PBTN_DOWN) { sel++; if (sel > n-1) sel = 0; } + else if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } + else if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-1) sel = n-1; } + else if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; } + else if (inp & PBTN_R) { sel+=24; if (sel > n-1) sel = n-1; } + + else if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2)) { if (namelist[sel]->d_type == DT_REG) { @@ -1319,10 +1318,10 @@ static char *action_binds(int player_idx, int action_mask, int dev_id) type = IN_BINDTYPE_EMU; if (player_idx >= 0) { can_combo = 0; - type = IN_BINDTYPE_PLAYER12; + type = IN_BINDTYPE_PLAYER12 + (player_idx >> 1); + if (player_idx & 1) + action_mask <<= 16; } - if (player_idx == 1) - action_mask <<= 16; if (dev_id >= 0) dev = dev_last = dev_id; @@ -1459,9 +1458,12 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_ dev_id = -1; // show all mask_shift = 0; - if (player_idx == 1) - mask_shift = 16; - bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU; + if (player_idx >= 0) { + if (player_idx & 1) + mask_shift = 16; + bindtype = IN_BINDTYPE_PLAYER12 + (player_idx >> 1); + } else + bindtype = IN_BINDTYPE_EMU; for (;;) { diff --git a/plat_sdl.c b/plat_sdl.c index 530a9d7..2d537f0 100644 --- a/plat_sdl.c +++ b/plat_sdl.c @@ -28,9 +28,10 @@ void (*plat_sdl_resize_cb)(int w, int h); void (*plat_sdl_quit_cb)(void); static char vid_drv_name[32]; -static int window_w, window_h; +static int window_w, window_h, window_b; static int fs_w, fs_h; static int old_fullscreen; +static int screen_flags; static int vout_mode_overlay = -1, vout_mode_overlay2x = -1, vout_mode_gl = -1; static void *display, *window; static int gl_quirks; @@ -40,6 +41,14 @@ int plat_sdl_change_video_mode(int w, int h, int force) { static int prev_w, prev_h; + // skip GL recreation if window doesn't change - avoids flicker + if (plat_target.vout_method == vout_mode_gl && plat_sdl_gl_active + && plat_target.vout_fullscreen == old_fullscreen + && w == prev_w && h == prev_h && !force) + { + return 0; + } + if (w == 0) w = prev_w; else @@ -59,13 +68,6 @@ int plat_sdl_change_video_mode(int w, int h, int force) plat_target.vout_method = 0; } - // skip GL recreation if window doesn't change - avoids flicker - if (plat_target.vout_method == vout_mode_gl && plat_sdl_gl_active - && plat_target.vout_fullscreen == old_fullscreen && !force) - { - return 0; - } - if (plat_sdl_overlay != NULL) { SDL_FreeYUVOverlay(plat_sdl_overlay); plat_sdl_overlay = NULL; @@ -90,7 +92,10 @@ int plat_sdl_change_video_mode(int w, int h, int force) // (seen on r-pi) SDL_PumpEvents(); - plat_sdl_screen = SDL_SetVideoMode(win_w, win_h, 0, flags); + if (!plat_sdl_screen || screen_flags != flags || + plat_sdl_screen->w != win_w || plat_sdl_screen->h != win_h) + plat_sdl_screen = SDL_SetVideoMode(win_w, win_h, 0, flags); + screen_flags = flags; if (plat_sdl_screen == NULL) { fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError()); plat_target.vout_method = 0; @@ -99,7 +104,7 @@ int plat_sdl_change_video_mode(int w, int h, int force) if (plat_target.vout_method == vout_mode_overlay || plat_target.vout_method == vout_mode_overlay2x) { - int W = plat_target.vout_method == vout_mode_overlay2x && w == 320 ? 2*w : w; + int W = plat_target.vout_method == vout_mode_overlay2x && w < 640 ? 2*w : w; plat_sdl_overlay = SDL_CreateYUVOverlay(W, h, SDL_UYVY_OVERLAY, plat_sdl_screen); if (plat_sdl_overlay != NULL && SDL_LockYUVOverlay(plat_sdl_overlay) == 0) { if ((long)plat_sdl_overlay->pixels[0] & 3) @@ -115,7 +120,8 @@ int plat_sdl_change_video_mode(int w, int h, int force) } } else if (plat_target.vout_method == vout_mode_gl) { - plat_sdl_gl_active = (gl_init(display, window, &gl_quirks) == 0); + int sw = plat_sdl_screen->w, sh = plat_sdl_screen->h; + plat_sdl_gl_active = (gl_init(display, window, &gl_quirks, sw, sh) == 0); if (!plat_sdl_gl_active) { fprintf(stderr, "warning: could not init GL.\n"); plat_target.vout_method = 0; @@ -123,15 +129,29 @@ int plat_sdl_change_video_mode(int w, int h, int force) } if (plat_target.vout_method == 0) { - SDL_PumpEvents(); + Uint32 flags; + int win_w = w; + int win_h = h; #if defined SDL_SURFACE_SW - plat_sdl_screen = SDL_SetVideoMode(w, h, 16, SDL_SWSURFACE); + flags = SDL_SWSURFACE; #elif defined(SDL_TRIPLEBUF) && defined(SDL_BUFFER_3X) - plat_sdl_screen = SDL_SetVideoMode(w, h, 16, SDL_HWSURFACE | SDL_TRIPLEBUF); + flags = SDL_HWSURFACE | SDL_TRIPLEBUF; #else - plat_sdl_screen = SDL_SetVideoMode(w, h, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); + flags = SDL_HWSURFACE | SDL_DOUBLEBUF; #endif + if (plat_target.vout_fullscreen && fs_w && fs_h) { + flags |= SDL_FULLSCREEN; + win_w = fs_w; + win_h = fs_h; + } + + SDL_PumpEvents(); + + if (!plat_sdl_screen || screen_flags != flags || + plat_sdl_screen->w != win_w || plat_sdl_screen->h != win_h) + plat_sdl_screen = SDL_SetVideoMode(win_w, win_h, 16, flags); + screen_flags = flags; if (plat_sdl_screen == NULL) { fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError()); return -1; @@ -156,8 +176,8 @@ void plat_sdl_event_handler(void *event_) if (plat_target.vout_method != 0 && !plat_target.vout_fullscreen && !old_fullscreen) { - window_w = event->resize.w; - window_h = event->resize.h; + window_w = event->resize.w & ~3; + window_h = event->resize.h & ~3; plat_sdl_change_video_mode(0, 0, 1); } break; @@ -169,8 +189,9 @@ void plat_sdl_event_handler(void *event_) } else if (plat_sdl_gl_active) { if (gl_quirks & GL_QUIRK_ACTIVATE_RECREATE) { + int sw = plat_sdl_screen->w, sh = plat_sdl_screen->h; gl_finish(); - plat_sdl_gl_active = (gl_init(display, window, &gl_quirks) == 0); + plat_sdl_gl_active = (gl_init(display, window, &gl_quirks, sw, sh) == 0); } gl_flip(NULL, 0, 0); } @@ -206,6 +227,8 @@ int plat_sdl_init(void) if (info != NULL) { fs_w = info->current_w; fs_h = info->current_h; + if (info->wm_available) + window_b = WM_DECORATION_H; printf("plat_sdl: using %dx%d as fullscreen resolution\n", fs_w, fs_h); } @@ -215,14 +238,14 @@ int plat_sdl_init(void) g_menuscreen_h = 480; if (fs_h != 0) { h = fs_h; - if (info && info->wm_available && h > WM_DECORATION_H) - h -= WM_DECORATION_H; + if (window_b && h > window_b) + h -= window_b; if (g_menuscreen_h > h) g_menuscreen_h = h; } - ret = plat_sdl_change_video_mode(g_menuscreen_w, g_menuscreen_h, 1); - if (ret != 0) { + plat_sdl_screen = SDL_SetVideoMode(g_menuscreen_w, g_menuscreen_h, 16, SDL_HWSURFACE); + if (plat_sdl_screen == NULL) { plat_sdl_screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE); if (plat_sdl_screen == NULL) { fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError()); @@ -293,7 +316,7 @@ int plat_sdl_init(void) if (env) try_gl = atoi(env); if (try_gl) - ret = gl_init(display, window, &gl_quirks); + ret = gl_init(display, window, &gl_quirks, g_menuscreen_w, g_menuscreen_h); if (ret == 0) { gl_announce(); gl_works = 1; @@ -347,10 +370,10 @@ void plat_sdl_overlay_clear(void) int *dst = (int *)plat_sdl_overlay->pixels[0]; int v = 0x10801080; - for (; pixels > 0; dst += 4, pixels -= 2 * 4) + for (; pixels > 7; dst += 4, pixels -= 2 * 4) dst[0] = dst[1] = dst[2] = dst[3] = v; - for (; pixels > 0; dst++, pixels -= 2) + for (; pixels > 1; dst++, pixels -= 2) *dst = v; } diff --git a/posix.h b/posix.h index 257c27f..44b6984 100644 --- a/posix.h +++ b/posix.h @@ -23,12 +23,14 @@ #include #include +#ifndef DT_DIR /* map PSP names to posix. needs special scandir() function to mask rwx bits */ #define d_type d_stat.st_attr #define DT_LNK FIO_SO_IFLNK #define DT_DIR FIO_SO_IFDIR #define DT_REG FIO_SO_IFREG #define DT_UNKNOWN 0 +#endif #else