From 16e89bed918ec39b1e43956b903f7986af86a6b2 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 10 Nov 2007 15:48:32 +0000 Subject: [PATCH] UI adjustments, nub support git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@291 be3aeb3a-fb24-0410-a615-afba39da0efa --- common/emu.h | 2 +- common/lprintf.h | 2 +- common/menu.h | 1 + psp/Makefile | 6 +-- psp/emu.c | 31 ++++++----- psp/main.c | 2 + psp/menu.c | 135 ++++++++++++++++++++++++++--------------------- psp/menu.h | 3 +- psp/psp.c | 49 ++++++++++++++--- psp/psp.h | 8 +++ 10 files changed, 152 insertions(+), 87 deletions(-) diff --git a/common/emu.h b/common/emu.h index 42a1bfb..b4f3c26 100644 --- a/common/emu.h +++ b/common/emu.h @@ -9,7 +9,7 @@ typedef struct { // squidgehack, no_save_cfg_on_exit, , 16_bit_mode // craigix_ram, confirm_save, show_cd_leds, confirm_load // A_SNs_gamma, perfect_vsync, giz_scanlines, giz_dblbuff - // vsync_mode + // vsync_mode, show_clock int PicoOpt; // used for config saving only, see Pico.h int PsndRate; // ditto int PicoRegion; // ditto diff --git a/common/lprintf.h b/common/lprintf.h index dc49c65..a8d9ee1 100644 --- a/common/lprintf.h +++ b/common/lprintf.h @@ -2,7 +2,7 @@ #include #define lprintf printf #elif defined(PSP) - #if 1 + #ifdef LPRINTF_STDIO #include #define lprintf printf #else diff --git a/common/menu.h b/common/menu.h index 2635967..df990d3 100644 --- a/common/menu.h +++ b/common/menu.h @@ -63,6 +63,7 @@ typedef enum MA_OPT2_NO_LAST_ROM, MA_OPT2_RAMTIMINGS, /* gp2x */ MA_OPT2_SQUIDGEHACK, /* gp2x */ + MA_OPT2_STATUS_LINE, /* psp */ MA_OPT2_DONE, MA_OPT3_SCALE, /* psp (all OPT3) */ MA_OPT3_HSCALE32, diff --git a/psp/Makefile b/psp/Makefile index 49f9f7b..d60078e 100644 --- a/psp/Makefile +++ b/psp/Makefile @@ -10,7 +10,7 @@ amalgamate = 0 #up = 1 -CFLAGS += -I../.. -I. -DNO_SYNC +CFLAGS += -I../.. -I. -DNO_SYNC -DLPRINTF_STDIO CFLAGS += -Wall -Winline -G0 ifeq ($(DEBUG),) CFLAGS += -O2 -ftracer -fstrength-reduce -ffast-math @@ -76,12 +76,12 @@ endif OBJS += data/bg32.o data/bg40.o -LIBS += -lpng -lm -lpspgu -lpsppower -Wl,-Map=PicoDrive.map -lpspaudio +LIBS += -lpng -lm -lpspgu -lpsppower -lpspaudio -lpsprtc -Wl,-Map=PicoDrive.map # target TARGET = PicoDrive EXTRA_TARGETS = EBOOT.PBP -PSP_EBOOT_TITLE = PICODRIVE +PSP_EBOOT_TITLE = PicoDrive PSP_EBOOT_ICON = data/icon.png #PSP_EBOOT_PIC1 = .png diff --git a/psp/emu.c b/psp/emu.c index e72ea7d..6ac086d 100644 --- a/psp/emu.c +++ b/psp/emu.c @@ -145,9 +145,15 @@ void emu_setDefaultConfig(void) currentConfig.KeyBinds[12] = 1<<26; // switch rnd currentConfig.KeyBinds[ 8] = 1<<27; // save state currentConfig.KeyBinds[ 9] = 1<<28; // load state + currentConfig.KeyBinds[28] = 1<<0; // num "buttons" + currentConfig.KeyBinds[30] = 1<<1; + currentConfig.KeyBinds[31] = 1<<2; + currentConfig.KeyBinds[29] = 1<<3; currentConfig.PicoCDBuffers = 0; - currentConfig.scaling = 1; // bilinear filtering for psp - currentConfig.scale = currentConfig.hscale32 = currentConfig.hscale40 = 1.0; + currentConfig.scaling = 1; // bilinear filtering for psp + currentConfig.scale = 1.20; // fullscreen + currentConfig.hscale40 = 1.25; + currentConfig.hscale32 = 1.56; } @@ -353,15 +359,13 @@ static void blitscreen_clut(void) static void cd_leds(void) { - static int old_reg = 0; - unsigned int col_g, col_r, *p; + unsigned int reg, col_g, col_r, *p; - if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change - old_reg = Pico_mcd->s68k_regs[0]; + reg = Pico_mcd->s68k_regs[0]; p = (unsigned int *)((short *)psp_screen + 512*2+4+2); - col_g = (old_reg & 2) ? 0x06000600 : 0; - col_r = (old_reg & 1) ? 0x00180018 : 0; + col_g = (reg & 2) ? 0x06000600 : 0; + col_r = (reg & 1) ? 0x00180018 : 0; *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2; *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2; *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; @@ -798,23 +802,22 @@ static void find_combos(void) if (act == 16 || act == 17) continue; // player2 flag if (act > 17) { - for (u = 0; u < 32; u++) + for (u = 0; u < 28; u++) // 28 because nub can't produce combos if (currentConfig.KeyBinds[u] & (1 << act)) keyc++; } else { - for (u = 0; u < 32; u++) + for (u = 0; u < 28; u++) if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1 (currentConfig.KeyBinds[u] & (1 << act))) keyc++; - for (u = 0; u < 32; u++) + for (u = 0; u < 28; u++) if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2 (currentConfig.KeyBinds[u] & (1 << act))) keyc2++; - if (keyc2 > keyc) keyc = keyc2; } - if (keyc > 1) + if (keyc > 1 || keyc2 > 1) { // loop again and mark those keys and actions as combo - for (u = 0; u < 32; u++) + for (u = 0; u < 28; u++) { if (currentConfig.KeyBinds[u] & (1 << act)) { combo_keys |= 1 << u; diff --git a/psp/main.c b/psp/main.c index 606ca02..0d12196 100644 --- a/psp/main.c +++ b/psp/main.c @@ -4,9 +4,11 @@ #include "../common/menu.h" #include "../common/emu.h" #include "../common/lprintf.h" +#include "version.h" int main() { + lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n"); psp_init(); emu_ReadConfig(0, 0); diff --git a/psp/menu.c b/psp/menu.c index cdcf1e6..ccb472b 100644 --- a/psp/menu.c +++ b/psp/menu.c @@ -33,10 +33,10 @@ #define pspKeyUnkn "???" static const char * const pspKeyNames[] = { - "SELECT", pspKeyUnkn, pspKeyUnkn, "START", "UP", "RIGHT", "DOWN", "LEFT", - "L", "R", pspKeyUnkn, pspKeyUnkn, "TRIANGLE", "CIRCLE", "X", "SQUARE", - "HOME", "HOLD", "WLAN_UP", "REMOTE", "VOLUP", "VOLDOWN", "SCREEN", "NOTE", - pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn + "SELECT", pspKeyUnkn, pspKeyUnkn, "START", "UP", "RIGHT", "DOWN", "LEFT", + "L", "R", pspKeyUnkn, pspKeyUnkn, "TRIANGLE", "CIRCLE", "X", "SQUARE", + "HOME", "HOLD", "WLAN_UP", "REMOTE", "VOLUP", "VOLDOWN", "SCREEN", "NOTE", + pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, pspKeyUnkn, "NUB UP", "NUB RIGHT", "NUB DOWN", "NUB LEFT" // fake }; static unsigned short bg_buffer[480*272] __attribute__((aligned(16))); @@ -48,11 +48,14 @@ static void menu_prepare_bg(int use_game_bg, int use_fg); static unsigned int inp_prev = 0; -static unsigned long wait_for_input(unsigned int interesting) +static unsigned long wait_for_input(unsigned int interesting, int is_key_config) { unsigned int ret; static int repeats = 0, wait = 50; - int release = 0, i; + int release = 0, count, i; + + if (!is_key_config) + interesting |= (interesting & 0xf0) << 24; // also use analog if (repeats == 2 || repeats == 4) wait /= 2; if (repeats == 6) wait = 15; @@ -62,7 +65,7 @@ static unsigned long wait_for_input(unsigned int interesting) psp_msleep(wait); } - while ( !((ret = psp_pad_read(1)) & interesting) ) { + for (count = 0; !((ret = psp_pad_read(1)) & interesting) && count < 100; count++) { psp_msleep(50); release = 1; } @@ -73,6 +76,9 @@ static unsigned long wait_for_input(unsigned int interesting) } inp_prev = ret; + if (!is_key_config) + ret |= (ret & 0xf0000000) >> 24; // use analog as d-pad + // we don't need diagonals in menus if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT; if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT; @@ -350,14 +356,14 @@ static char *romsel_loop(char *curr_path) for (;;) { draw_dirlist(curr_path, namelist, n, sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_X|BTN_CIRCLE, 0); if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; } if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; } if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; } if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; } if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; } if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; } - if(inp & BTN_X) { // enter dir/select + if(inp & BTN_CIRCLE) { // enter dir/select if (namelist[sel+1]->d_type & DT_REG) { strcpy(romFileName, curr_path); strcat(romFileName, "/"); @@ -386,7 +392,7 @@ static char *romsel_loop(char *curr_path) break; } } - if(inp & BTN_CIRCLE) break; // cancel + if(inp & BTN_X) break; // cancel } if (n > 0) { @@ -424,7 +430,7 @@ static void draw_debug(void) static void debug_menu_loop(void) { draw_debug(); - wait_for_input(BTN_X|BTN_CIRCLE); + wait_for_input(BTN_X|BTN_CIRCLE, 0); } // ------------ patch/gg menu ------------ @@ -461,17 +467,17 @@ static void patches_menu_loop(void) for(;;) { draw_patchlist(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_X|BTN_CIRCLE, 0); if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; } if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; } if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; } if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; } - if(inp & BTN_X) { // action + if(inp & BTN_CIRCLE) { // action if (menu_sel < PicoPatchCount) PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active; else return; } - if(inp & BTN_CIRCLE) return; + if(inp & BTN_X) return; } } @@ -591,7 +597,7 @@ static int savestate_menu_loop(int is_loading) for(;;) { draw_savestate_menu(menu_sel, is_loading); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE, 0); if(inp & BTN_UP ) { do { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; @@ -602,7 +608,7 @@ static int savestate_menu_loop(int is_loading) menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); } - if(inp & BTN_X) { // save/load + if(inp & BTN_CIRCLE) { // save/load if (menu_sel < 10) { state_slot = menu_sel; PicoStateProgressCB = emu_msg_cb; /* also suitable for menu */ @@ -613,7 +619,7 @@ static int savestate_menu_loop(int is_loading) return 0; } else return 1; } - if(inp & BTN_CIRCLE) return 1; + if(inp & BTN_X) return 1; } } @@ -630,7 +636,11 @@ static char *action_binds(int player_idx, int action_mask) if (currentConfig.KeyBinds[i] & action_mask) { if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue; - if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, pspKeyNames[i]); break; } + if (strkeys[0]) { + strcat(strkeys, i >= 28 ? ", " : " + "); // nub "buttons" don't create combos + strcat(strkeys, pspKeyNames[i]); + break; + } else strcpy(strkeys, pspKeyNames[i]); } } @@ -683,14 +693,14 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i text_out16(x, y, "Done"); if (sel < opt_cnt) { - text_out16(80+30, 180, "Press a button to bind/unbind"); - text_out16(80+30, 190, "Use SELECT to clear"); - text_out16(80+30, 200, "To bind UP/DOWN, hold SELECT"); - text_out16(80+30, 210, "Select \"Done\" to exit"); + text_out16(80+30, 220, "Press a button to bind/unbind"); + text_out16(80+30, 230, "Use SELECT to clear"); + text_out16(80+30, 240, "To bind UP/DOWN, hold SELECT"); + text_out16(80+30, 250, "Select \"Done\" to exit"); } else { - text_out16(80+30, 190, "Use Options -> Save cfg"); - text_out16(80+30, 200, "to save controls"); - text_out16(80+30, 210, "Press X or O to exit"); + text_out16(80+30, 230, "Use Options -> Save cfg"); + text_out16(80+30, 240, "to save controls"); + text_out16(80+30, 250, "Press X or O to exit"); } menu_draw_end(); } @@ -703,7 +713,7 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i for (;;) { draw_key_config(opts, opt_cnt, player_idx, sel); - inp = wait_for_input(CONFIGURABLE_KEYS|BTN_SELECT); + inp = wait_for_input(CONFIGURABLE_KEYS|BTN_SELECT, 1); if (!(inp & BTN_SELECT)) { prev_select = 0; if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; } @@ -776,8 +786,6 @@ static bind_action_t emuctrl_actions[] = { "Prev Save Slot ", 1<<25 }, { "Next Save Slot ", 1<<24 }, { "Switch Renderer", 1<<26 }, - { "Volume Down ", 1<<30 }, - { "Volume Up ", 1<<29 }, }; static void kc_sel_loop(void) @@ -789,10 +797,10 @@ static void kc_sel_loop(void) while (1) { draw_kc_sel(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE, 0); if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } - if (inp & BTN_X) { + if (inp & BTN_CIRCLE) { switch (menu_sel) { case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return; case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return; @@ -802,7 +810,7 @@ static void kc_sel_loop(void) default: return; } } - if (inp & BTN_CIRCLE) return; + if (inp & BTN_X) return; } } @@ -870,7 +878,7 @@ static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names) if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) || (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) || (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND"))) - text_out16(tl_x, 210, "Press start to test selected BIOS"); + text_out16(tl_x, 250, "Press start to test selected BIOS"); menu_draw_end(); } @@ -902,7 +910,7 @@ static void cd_menu_loop_options(void) for(;;) { draw_cd_menu_options(menu_sel, &bios_names); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel); @@ -919,7 +927,7 @@ static void cd_menu_loop_options(void) } } } - if (inp & BTN_X) { // toggleable options + if (inp & BTN_CIRCLE) { // toggleable options if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) && selected_id == MA_CDOPT_DONE) { return; @@ -950,7 +958,7 @@ static void cd_menu_loop_options(void) break; } } - if (inp & BTN_CIRCLE) return; + if (inp & BTN_X) return; } } @@ -1054,7 +1062,7 @@ static void dispmenu_loop_options(void) for (;;) { draw_dispmenu_options(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(opt3_entries, OPT3_ENTRY_COUNT, menu_sel); @@ -1087,7 +1095,7 @@ static void dispmenu_loop_options(void) } } } - if (inp & BTN_X) { // toggleable options + if (inp & BTN_CIRCLE) { // toggleable options me_process(opt3_entries, OPT3_ENTRY_COUNT, selected_id, 1); switch (selected_id) { case MA_OPT3_DONE: @@ -1108,7 +1116,7 @@ static void dispmenu_loop_options(void) default: break; } } - if (inp & BTN_CIRCLE) return; + if (inp & BTN_X) return; } } @@ -1117,11 +1125,12 @@ static void dispmenu_loop_options(void) menu_entry opt2_entries[] = { - { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 }, - { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 }, - { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 }, - { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 }, - { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 }, + { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x00004, 0, 0, 1 }, + { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x00001, 0, 0, 1 }, + { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x00002, 0, 0, 1 }, + { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x00008, 0, 0, 1 }, + { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x00020, 0, 0, 1 }, + { "Status line in main menu", MB_ONOFF, MA_OPT2_STATUS_LINE, ¤tConfig.EmuOpt, 0x20000, 0, 0, 1 }, { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 }, }; @@ -1153,7 +1162,7 @@ static void amenu_loop_options(void) for(;;) { draw_amenu_options(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel); @@ -1163,13 +1172,13 @@ static void amenu_loop_options(void) // TODO? } } - if (inp & BTN_X) { // toggleable options + if (inp & BTN_CIRCLE) { // toggleable options if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) && selected_id == MA_OPT2_DONE) { return; } } - if (inp & BTN_CIRCLE) return; + if (inp & BTN_X) return; } } @@ -1360,7 +1369,7 @@ static int menu_loop_options(void) while (1) { draw_menu_options(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_X|BTN_CIRCLE, 0); if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel); @@ -1421,7 +1430,7 @@ static int menu_loop_options(void) } } } - if (inp & BTN_X) { + if (inp & BTN_CIRCLE) { if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1)) { switch (selected_id) @@ -1459,7 +1468,7 @@ static int menu_loop_options(void) } } } - if(inp & BTN_CIRCLE) { + if(inp & BTN_X) { menu_options_save(); return 0; // done (update, no write) } @@ -1512,11 +1521,15 @@ menu_entry main_entries[] = static void draw_menu_root(int menu_sel) { - const int tl_x = 80+70, tl_y = 16+70; + const int tl_x = 86+70, tl_y = 16+70; + char *stat = NULL; menu_draw_begin(); - text_out16(tl_x, 16+20, "PicoDrive v" VERSION); + if ((currentConfig.EmuOpt&0x20000) && (stat = psp_get_status_line())) + text_out16(287, 12, "%s", stat); + + text_out16(tl_x, 48, "PicoDrive v" VERSION); menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146); @@ -1552,23 +1565,23 @@ static void menu_loop_root(void) for (;;) { draw_menu_root(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE|BTN_SELECT|BTN_L|BTN_R); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X|BTN_CIRCLE|BTN_SELECT|BTN_L|BTN_R, 0); if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp & (BTN_L|BTN_R)) == (BTN_L|BTN_R)) debug_menu_loop(); - if( inp & (BTN_SELECT|BTN_CIRCLE)) { + if( inp & (BTN_SELECT|BTN_X)) { if (rom_data) { - while (psp_pad_read(1) & (BTN_SELECT|BTN_CIRCLE)) psp_msleep(50); // wait until released + while (psp_pad_read(1) & (BTN_SELECT|BTN_X)) psp_msleep(50); // wait until released engineState = PGS_Running; break; } } - if(inp & BTN_X) { + if(inp & BTN_CIRCLE) { switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel)) { case MA_MAIN_RESUME_GAME: if (rom_data) { - while (psp_pad_read(1) & BTN_X) psp_msleep(50); + while (psp_pad_read(1) & BTN_CIRCLE) psp_msleep(50); engineState = PGS_Running; return; } @@ -1627,7 +1640,9 @@ static void menu_loop_root(void) case MA_MAIN_CREDITS: draw_menu_credits(); psp_msleep(500); - inp = wait_for_input(BTN_X|BTN_CIRCLE); + inp = 0; + while (!(inp & (BTN_X|BTN_CIRCLE))) + inp = wait_for_input(BTN_X|BTN_CIRCLE, 0); break; case MA_MAIN_EXIT: engineState = PGS_Quit; @@ -1757,15 +1772,15 @@ int menu_loop_tray(void) /* make sure action buttons are not pressed on entering menu */ draw_menu_tray(menu_sel); - while (psp_pad_read(1) & BTN_X) psp_msleep(50); + while (psp_pad_read(1) & BTN_CIRCLE) psp_msleep(50); for (;;) { draw_menu_tray(menu_sel); - inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X); + inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_X, 0); if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } - if(inp & BTN_X ) { + if(inp & BTN_CIRCLE) { switch (menu_sel) { case 0: // select image selfname = romsel_loop(curr_path); diff --git a/psp/menu.h b/psp/menu.h index fa6c90c..a36b2a4 100644 --- a/psp/menu.h +++ b/psp/menu.h @@ -9,5 +9,6 @@ void menu_romload_prepare(const char *rom_name); void menu_romload_end(void); -#define CONFIGURABLE_KEYS (BTN_UP|BTN_LEFT|BTN_RIGHT|BTN_DOWN|BTN_L|BTN_R|BTN_TRIANGLE|BTN_CIRCLE|BTN_X|BTN_SQUARE|BTN_START|BTN_NOTE) +#define CONFIGURABLE_KEYS (BTN_UP|BTN_LEFT|BTN_RIGHT|BTN_DOWN|BTN_L|BTN_R|BTN_TRIANGLE|BTN_CIRCLE|BTN_X|BTN_SQUARE|BTN_START| \ + BTN_NUB_UP|BTN_NUB_RIGHT|BTN_NUB_DOWN|BTN_NUB_LEFT|BTN_NOTE) diff --git a/psp/psp.c b/psp/psp.c index b2d0d72..a21507f 100644 --- a/psp/psp.c +++ b/psp/psp.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "psp.h" @@ -18,7 +19,7 @@ unsigned int __attribute__((aligned(16))) guCmdList[GU_CMDLIST_SIZE]; void *psp_screen = VRAM_FB0; static int current_screen = 0; /* front bufer */ -static SceUID logfd = -1; +#define ANALOG_DEADZONE 80 /* Exit callback */ static int exit_callback(int arg1, int arg2, void *common) @@ -47,6 +48,7 @@ void psp_init(void) { SceUID thid; + lprintf("running in %08x kernel\n", sceKernelDevkitVersion()), lprintf("entered psp_init, threadId %i, priority %i\n", sceKernelGetThreadId(), sceKernelGetThreadCurrentPriority()); @@ -93,7 +95,7 @@ void psp_init(void) /* input */ sceCtrlSetSamplingCycle(0); - sceCtrlSetSamplingMode(0); + sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); } void psp_finish(void) @@ -132,12 +134,21 @@ void psp_msleep(int ms) unsigned int psp_pad_read(int blocking) { + unsigned int buttons; SceCtrlData pad; if (blocking) sceCtrlReadBufferPositive(&pad, 1); else sceCtrlPeekBufferPositive(&pad, 1); + buttons = pad.Buttons; + + // analog.. + buttons &= ~(BTN_NUB_UP|BTN_NUB_DOWN|BTN_NUB_LEFT|BTN_NUB_RIGHT); + if (pad.Lx < 128 - ANALOG_DEADZONE) buttons |= BTN_NUB_LEFT; + if (pad.Lx > 128 + ANALOG_DEADZONE) buttons |= BTN_NUB_RIGHT; + if (pad.Ly < 128 - ANALOG_DEADZONE) buttons |= BTN_NUB_UP; + if (pad.Ly > 128 + ANALOG_DEADZONE) buttons |= BTN_NUB_DOWN; - return pad.Buttons; + return buttons; } int psp_get_cpu_clock(void) @@ -153,19 +164,42 @@ int psp_set_cpu_clock(int clock) return ret; } +char *psp_get_status_line(void) +{ + static char buff[64]; + int ret, bat_percent, bat_time; + pspTime time; + + ret = sceRtcGetCurrentClockLocalTime(&time); + bat_percent = scePowerGetBatteryLifePercent(); + bat_time = scePowerGetBatteryLifeTime(); + if (ret < 0 || bat_percent < 0 || bat_time < 0) return NULL; + + snprintf(buff, sizeof(buff), "%02i:%02i bat: %3i%%", time.hour, time.minutes, bat_percent); + if (!scePowerIsPowerOnline()) + snprintf(buff+strlen(buff), sizeof(buff)-strlen(buff), " (%i:%02i)", bat_time/60, bat_time%60); + return buff; +} + /* alt logging */ #define LOG_FILE "log.log" +static SceUID logfd = -1; + void lprintf_f(const char *fmt, ...) { va_list vl; char buff[256]; + if (logfd == -2) return; // disabled + if (logfd < 0) { logfd = sceIoOpen(LOG_FILE, PSP_O_WRONLY|PSP_O_APPEND, 0777); - if (logfd < 0) + if (logfd < 0) { + logfd = -2; return; + } } va_start(vl, fmt); @@ -173,9 +207,10 @@ void lprintf_f(const char *fmt, ...) va_end(vl); sceIoWrite(logfd, buff, strlen(buff)); -//sceKernelDelayThread(200 * 1000); -sceIoClose(logfd); -logfd = -1; + + // make sure it gets flushed + sceIoClose(logfd); + logfd = -1; } diff --git a/psp/psp.h b/psp/psp.h index 8a2828e..7f2d70d 100644 --- a/psp/psp.h +++ b/psp/psp.h @@ -36,6 +36,8 @@ unsigned int psp_pad_read(int blocking); int psp_get_cpu_clock(void); int psp_set_cpu_clock(int clock); +char *psp_get_status_line(void); + /* shorter btn names */ #define BTN_UP PSP_CTRL_UP #define BTN_LEFT PSP_CTRL_LEFT @@ -51,3 +53,9 @@ int psp_set_cpu_clock(int clock); #define BTN_START PSP_CTRL_START #define BTN_NOTE PSP_CTRL_NOTE // doesn't seem to work? +/* fake 'nub' btns */ +#define BTN_NUB_UP (1 << 28) +#define BTN_NUB_RIGHT (1 << 29) +#define BTN_NUB_DOWN (1 << 30) +#define BTN_NUB_LEFT (1 << 31) + -- 2.39.2