X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=platform%2Fgp2x%2Fmenu.c;h=40eee48b29bd31b02294f49b2894889082ee9b43;hb=83bd0b76aba19ff62368cfee76089e15579e3b7c;hp=9ffbd40c567ae9e0aa03c8bf6c9bbcf234ce7321;hpb=76276b0bc0b532394d1ba067bf2b17a27b0b3be6;p=picodrive.git diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 9ffbd40..40eee48 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -17,7 +17,9 @@ #include "usbjoy.h" #include "version.h" -#include "Pico/PicoInt.h" +#include +#include +#include #ifndef _DIRENT_HAVE_D_TYPE #error "need d_type for file browser @@ -390,6 +392,187 @@ static char *romsel_loop(char *curr_path) return ret; } +// ------------ patch/gg menu ------------ + +static void draw_patchlist(int sel) +{ + int start, i, pos; + + start = 12 - sel; + + gp2x_pd_clone_buffer2(); + + for (i = 0; i < PicoPatchCount; i++) { + pos = start + i; + if (pos < 0) continue; + if (pos > 23) break; + gp2x_smalltext8_lim(14, pos*10, PicoPatches[i].active ? "ON " : "OFF", 3); + gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6); + } + pos = start + i; + if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4); + + gp2x_text_out8(5, 120, ">"); + gp2x_video_flip2(); +} + + +void patches_menu_loop(void) +{ + int menu_sel = 0; + unsigned long inp = 0; + + for(;;) + { + draw_patchlist(menu_sel); + inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X); + if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; } + if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; } + if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; } + if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; } + if(inp & GP2X_B) { // action + if (menu_sel < PicoPatchCount) + PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active; + else return; + } + if(inp & GP2X_X) return; + } + +} + +// ------------ savestate loader ------------ + +static void menu_prepare_bg(void); + +static int state_slot_flags = 0; + +static void state_check_slots(void) +{ + int slot; + + state_slot_flags = 0; + + for (slot = 0; slot < 10; slot++) + { + if (emu_check_save_file(slot)) + { + state_slot_flags |= 1 << slot; + } + } +} + +static void draw_savestate_bg(int slot) +{ + struct PicoVideo tmp_pv; + unsigned short tmp_cram[0x40]; + unsigned short tmp_vsram[0x40]; + void *tmp_vram, *file; + char *fname; + + fname = emu_GetSaveFName(1, 0, slot); + if (!fname) return; + + tmp_vram = malloc(sizeof(Pico.vram)); + if (tmp_vram == NULL) return; + + memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram)); + memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram)); + memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram)); + memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video)); + + if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) { + file = gzopen(fname, "rb"); + emu_set_save_cbs(1); + } else { + file = fopen(fname, "rb"); + emu_set_save_cbs(0); + } + + if (file) { + if (PicoMCD & 1) { + PicoCdLoadStateGfx(file); + } else { + areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file + areaRead(Pico.vram, 1, sizeof(Pico.vram), file); + areaSeek(file, 0x2000, SEEK_CUR); + areaRead(Pico.cram, 1, sizeof(Pico.cram), file); + areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file); + areaSeek(file, 0x221a0, SEEK_SET); + areaRead(&Pico.video, 1, sizeof(Pico.video), file); + } + areaClose(file); + } + + emu_forced_frame(); + gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2); + menu_prepare_bg(); + + memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram)); + memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram)); + memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram)); + memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video)); + free(tmp_vram); +} + +static void draw_savestate_menu(int menu_sel, int is_loading) +{ + int tl_x = 25, tl_y = 60, y, i; + + if (state_slot_flags & (1 << menu_sel)) + draw_savestate_bg(menu_sel); + gp2x_pd_clone_buffer2(); + + gp2x_text_out8(tl_x, 30, is_loading ? "Load state" : "Save state"); + + /* draw all 10 slots */ + y = tl_y; + for (i = 0; i < 10; i++, y+=10) + { + gp2x_text_out8(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free"); + } + gp2x_text_out8(tl_x, y, "back"); + + // draw cursor + gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">"); + + gp2x_video_flip2(); +} + +static int savestate_menu_loop(int is_loading) +{ + int menu_sel = 10, menu_sel_max = 10; + unsigned long inp = 0; + + state_check_slots(); + + for(;;) + { + draw_savestate_menu(menu_sel, is_loading); + inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X); + if(inp & GP2X_UP ) { + do { + menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; + } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading); + } + if(inp & GP2X_DOWN) { + do { + 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 & GP2X_B) { // save/load + if (menu_sel < 10) { + state_slot = menu_sel; + if (emu_SaveLoadGame(is_loading, 0)) { + strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed"); + return 1; + } + return 0; + } else return 1; + } + if(inp & GP2X_X) return 1; + } +} + // -------------- key config -------------- static char *usb_joy_key_name(int joy, int num) @@ -554,9 +737,10 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0 gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1 gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2 - gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x400)?"ON":"OFF"); // 3 - gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x800)?"ON":"OFF"); // 4 - gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x400)?"ON":"OFF"); // 5 + gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3 + gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4 + gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5 + gp2x_text_out8(tl_x, (y+=10), "Better sync (very slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6 gp2x_text_out8(tl_x, (y+=10), "Done"); // draw cursor @@ -572,7 +756,7 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j static void cd_menu_loop_options(void) { - int menu_sel = 0, menu_sel_max = 6; + int menu_sel = 0, menu_sel_max = 7; unsigned long inp = 0; char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p; @@ -599,10 +783,11 @@ static void cd_menu_loop_options(void) if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 3: currentConfig.EmuOpt ^=0x400; break; - case 4: currentConfig.PicoOpt^=0x800; break; - case 5: currentConfig.PicoOpt^=0x400; break; - case 6: return; + case 3: currentConfig.EmuOpt ^=0x0400; break; + case 4: currentConfig.PicoOpt^=0x0800; break; + case 5: currentConfig.PicoOpt^=0x0400; break; + case 6: currentConfig.PicoOpt^=0x2000; break; + case 7: return; } } if(inp & (GP2X_X|GP2X_A)) return; @@ -970,6 +1155,8 @@ static void draw_menu_root(int menu_sel) gp2x_text_out8(tl_x, (y+=10), "Configure controls"); gp2x_text_out8(tl_x, (y+=10), "Credits"); gp2x_text_out8(tl_x, (y+=10), "Exit"); + if (PicoPatches) + gp2x_text_out8(tl_x, (y+=10), "Patches / GameGenie"); // draw cursor gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">"); @@ -997,6 +1184,7 @@ static void menu_loop_root(void) } if (rom_data) menu_sel = menu_sel_min = 0; + if (PicoPatches) menu_sel_max = 9; for(;;) { @@ -1018,20 +1206,16 @@ static void menu_loop_root(void) break; case 1: // save state if (rom_data) { - if(emu_SaveLoadGame(0, 0)) { - strcpy(menuErrorMsg, "save failed"); + if(savestate_menu_loop(0)) continue; - } engineState = PGS_Running; return; } break; case 2: // load state if (rom_data) { - if(emu_SaveLoadGame(1, 0)) { - strcpy(menuErrorMsg, "load failed"); + if(savestate_menu_loop(1)) continue; - } engineState = PGS_Running; return; } @@ -1067,6 +1251,14 @@ static void menu_loop_root(void) case 8: // exit engineState = PGS_Quit; return; + case 9: // patches/gg + if (rom_data && PicoPatches) { + patches_menu_loop(); + PicoPatchApply(); + strcpy(menuErrorMsg, "Patches applied"); + continue; + } + break; } } menuErrorMsg[0] = 0; // clear error msg @@ -1074,21 +1266,29 @@ static void menu_loop_root(void) } -static void menu_gfx_prepare(void) +static void menu_prepare_bg(void) { extern int localPal[0x100]; - int i; + int c, i; // don't clear old palette just for fun (but make it dark) - for (i = 0x100-1; i >= 0; i--) - localPal[i] = (localPal[i] >> 2) & 0x003f3f3f; + for (i = 0x100-1; i >= 0; i--) { + c = localPal[i]; + localPal[i] = ((c >> 1) & 0x007f7f7f) - ((c >> 3) & 0x001f1f1f); + } localPal[0xe0] = 0x00000000; // reserved pixels for OSD localPal[0xf0] = 0x00ffffff; + gp2x_video_setpalette(localPal, 0x100); +} + +static void menu_gfx_prepare(void) +{ + menu_prepare_bg(); + // switch to 8bpp gp2x_video_changemode2(8); gp2x_video_RGB_setscaling(320, 240); - gp2x_video_setpalette(localPal, 0x100); gp2x_video_flip2(); }