| 1 | // (c) Copyright 2006,2007 notaz, All rights reserved.\r |
| 2 | // Free for non-commercial use.\r |
| 3 | \r |
| 4 | // For commercial use, separate licencing terms must be obtained.\r |
| 5 | \r |
| 6 | // don't like to use loads of #ifdefs, so duplicating GP2X code\r |
| 7 | // horribly instead\r |
| 8 | \r |
| 9 | #include <stdio.h>\r |
| 10 | #include <string.h>\r |
| 11 | #include <stdlib.h>\r |
| 12 | #include <unistd.h> // for getcwd cegcc implementation\r |
| 13 | #include <windows.h>\r |
| 14 | \r |
| 15 | #include "giz.h"\r |
| 16 | #include "emu.h"\r |
| 17 | #include "menu.h"\r |
| 18 | #include "../common/arm_utils.h"\r |
| 19 | #include "../common/menu.h"\r |
| 20 | #include "../common/readpng.h"\r |
| 21 | #include "version.h"\r |
| 22 | #include "kgsdk/Framework.h"\r |
| 23 | #include "kgsdk/Framework2D.h"\r |
| 24 | \r |
| 25 | #include <Pico/PicoInt.h>\r |
| 26 | #include <Pico/Patch.h>\r |
| 27 | #include <zlib/zlib.h>\r |
| 28 | \r |
| 29 | extern char romFileName[MAX_PATH];\r |
| 30 | extern char *rom_data;\r |
| 31 | extern int state_slot;\r |
| 32 | extern int config_slot, config_slot_current;\r |
| 33 | \r |
| 34 | #define gizKeyUnkn "???"\r |
| 35 | static const char * const gizKeyNames[] = {\r |
| 36 | "LEFT", "RIGHT", "UP", "DOWN", "STOP", "PLAY", "FORWARD", "REWIND",\r |
| 37 | "LEFT_SHOULDER", "RIGHT_SHOULDER", "HOME", "VOLUME", "BRIGHTNESS", "ALARM", "POWER", gizKeyUnkn,\r |
| 38 | gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,\r |
| 39 | gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn, gizKeyUnkn,\r |
| 40 | };\r |
| 41 | \r |
| 42 | static unsigned char bg_buffer[321*240*2];\r |
| 43 | char menuErrorMsg[40] = {0, };\r |
| 44 | \r |
| 45 | static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);\r |
| 46 | static void menu_prepare_bg(int use_game_bg);\r |
| 47 | \r |
| 48 | static unsigned int inp_prev = 0;\r |
| 49 | static int inp_prevjoy = 0;\r |
| 50 | \r |
| 51 | static unsigned long wait_for_input(unsigned int interesting)\r |
| 52 | {\r |
| 53 | unsigned int ret;\r |
| 54 | static int repeats = 0, wait = 50;\r |
| 55 | int release = 0, i;\r |
| 56 | \r |
| 57 | if (repeats == 2 || repeats == 4) wait /= 2;\r |
| 58 | if (repeats == 6) wait = 15;\r |
| 59 | \r |
| 60 | for (i = 0; i < 6 && inp_prev == Framework_PollGetButtons(); i++) {\r |
| 61 | if (i == 0) repeats++;\r |
| 62 | Sleep(wait);\r |
| 63 | }\r |
| 64 | \r |
| 65 | while ( !((ret = Framework_PollGetButtons()) & interesting) ) {\r |
| 66 | Sleep(50);\r |
| 67 | release = 1;\r |
| 68 | }\r |
| 69 | \r |
| 70 | if (release || ret != inp_prev) {\r |
| 71 | repeats = 0;\r |
| 72 | wait = 50;\r |
| 73 | }\r |
| 74 | inp_prev = ret;\r |
| 75 | inp_prevjoy = 0;\r |
| 76 | \r |
| 77 | // we don't need diagonals in menus\r |
| 78 | if ((ret&BTN_UP) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT;\r |
| 79 | if ((ret&BTN_UP) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;\r |
| 80 | if ((ret&BTN_DOWN) && (ret&BTN_LEFT)) ret &= ~BTN_LEFT;\r |
| 81 | if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;\r |
| 82 | \r |
| 83 | return ret;\r |
| 84 | }\r |
| 85 | \r |
| 86 | \r |
| 87 | static void menu_draw_begin(int use_bgbuff)\r |
| 88 | {\r |
| 89 | if (giz_screen == NULL)\r |
| 90 | {\r |
| 91 | Framework2D_WaitVSync();\r |
| 92 | giz_screen = Framework2D_LockBuffer();\r |
| 93 | }\r |
| 94 | else\r |
| 95 | {\r |
| 96 | lprintf("%s: screen was not NULL\n", __FUNCTION__);\r |
| 97 | }\r |
| 98 | memcpy32(giz_screen, (int *)bg_buffer, 321*240*2/4);\r |
| 99 | }\r |
| 100 | \r |
| 101 | \r |
| 102 | static void menu_draw_end(void)\r |
| 103 | {\r |
| 104 | Framework2D_UnlockBuffer();\r |
| 105 | giz_screen = NULL;\r |
| 106 | }\r |
| 107 | \r |
| 108 | \r |
| 109 | // --------- loading ROM screen ----------\r |
| 110 | \r |
| 111 | static void load_progress_cb(int percent)\r |
| 112 | {\r |
| 113 | int ln, len = percent * 320 / 100;\r |
| 114 | unsigned short *dst;\r |
| 115 | \r |
| 116 | menu_draw_begin(0);\r |
| 117 | dst = (unsigned short *)giz_screen + 321*20;\r |
| 118 | \r |
| 119 | if (len > 320) len = 320;\r |
| 120 | for (ln = 10; ln > 0; ln--, dst += 320)\r |
| 121 | memset(dst, 0xff, len*2);\r |
| 122 | menu_draw_end();\r |
| 123 | }\r |
| 124 | \r |
| 125 | void menu_romload_prepare(const char *rom_name)\r |
| 126 | {\r |
| 127 | const char *p = rom_name + strlen(rom_name);\r |
| 128 | while (p > rom_name && *p != '/') p--;\r |
| 129 | \r |
| 130 | if (rom_data == NULL)\r |
| 131 | memset(giz_screen, 0, 321*240*2);\r |
| 132 | menu_draw_begin(1);\r |
| 133 | \r |
| 134 | smalltext_out16(1, 1, "Loading", 0xffff);\r |
| 135 | smalltext_out16_lim(1, 10, p, 0xffff, 53);\r |
| 136 | menu_draw_end();\r |
| 137 | PicoCartLoadProgressCB = load_progress_cb;\r |
| 138 | }\r |
| 139 | \r |
| 140 | void menu_romload_end(void)\r |
| 141 | {\r |
| 142 | PicoCartLoadProgressCB = NULL;\r |
| 143 | menu_draw_begin(0);\r |
| 144 | smalltext_out16(1, 30, "Starting emulation...", 0xffff);\r |
| 145 | menu_draw_end();\r |
| 146 | }\r |
| 147 | \r |
| 148 | // -------------- ROM selector --------------\r |
| 149 | \r |
| 150 | // rrrr rggg gggb bbbb\r |
| 151 | #if 0\r |
| 152 | static unsigned short file2color(const char *fname)\r |
| 153 | {\r |
| 154 | const char *ext = fname + strlen(fname) - 3;\r |
| 155 | static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso" };\r |
| 156 | static const char *other_exts[] = { "gmv", "pat" };\r |
| 157 | int i;\r |
| 158 | \r |
| 159 | if (ext < fname) ext = fname;\r |
| 160 | for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)\r |
| 161 | if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;\r |
| 162 | for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)\r |
| 163 | if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;\r |
| 164 | return 0xffff;\r |
| 165 | }\r |
| 166 | \r |
| 167 | static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r |
| 168 | {\r |
| 169 | int start, i, pos;\r |
| 170 | \r |
| 171 | start = 12 - sel;\r |
| 172 | n--; // exclude current dir (".")\r |
| 173 | \r |
| 174 | menu_draw_begin(1);\r |
| 175 | \r |
| 176 | if (rom_data == NULL) {\r |
| 177 | menu_darken_bg(giz_screen, giz_screen, 321*240, 0);\r |
| 178 | }\r |
| 179 | \r |
| 180 | menu_darken_bg((char *)giz_screen + 321*120*2, (char *)giz_screen + 321*120*2, 321*8, 0);\r |
| 181 | \r |
| 182 | if(start - 2 >= 0)\r |
| 183 | smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);\r |
| 184 | for (i = 0; i < n; i++) {\r |
| 185 | pos = start + i;\r |
| 186 | if (pos < 0) continue;\r |
| 187 | if (pos > 23) break;\r |
| 188 | if (namelist[i+1]->d_type == DT_DIR) {\r |
| 189 | smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1);\r |
| 190 | smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);\r |
| 191 | } else {\r |
| 192 | unsigned short color = file2color(namelist[i+1]->d_name);\r |
| 193 | smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);\r |
| 194 | }\r |
| 195 | }\r |
| 196 | text_out16(5, 120, ">");\r |
| 197 | menu_draw_end();\r |
| 198 | }\r |
| 199 | \r |
| 200 | static int scandir_cmp(const void *p1, const void *p2)\r |
| 201 | {\r |
| 202 | struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r |
| 203 | if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r |
| 204 | if ((*d1)->d_type == DT_DIR) return -1; // put before\r |
| 205 | if ((*d2)->d_type == DT_DIR) return 1;\r |
| 206 | return alphasort(d1, d2);\r |
| 207 | }\r |
| 208 | \r |
| 209 | static char *filter_exts[] = {\r |
| 210 | ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",\r |
| 211 | ".jpg", ".gpe", ".cue"\r |
| 212 | };\r |
| 213 | \r |
| 214 | static int scandir_filter(const struct dirent *ent)\r |
| 215 | {\r |
| 216 | const char *p;\r |
| 217 | int i;\r |
| 218 | \r |
| 219 | if (ent == NULL || ent->d_name == NULL) return 0;\r |
| 220 | if (strlen(ent->d_name) < 5) return 1;\r |
| 221 | \r |
| 222 | p = ent->d_name + strlen(ent->d_name) - 4;\r |
| 223 | \r |
| 224 | for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)\r |
| 225 | {\r |
| 226 | if (strcmp(p, filter_exts[i]) == 0) return 0;\r |
| 227 | }\r |
| 228 | \r |
| 229 | return 1;\r |
| 230 | }\r |
| 231 | \r |
| 232 | static char *romsel_loop(char *curr_path)\r |
| 233 | {\r |
| 234 | struct dirent **namelist;\r |
| 235 | DIR *dir;\r |
| 236 | int n, sel = 0;\r |
| 237 | unsigned long inp = 0;\r |
| 238 | char *ret = NULL, *fname = NULL;\r |
| 239 | \r |
| 240 | // is this a dir or a full path?\r |
| 241 | if ((dir = opendir(curr_path))) {\r |
| 242 | closedir(dir);\r |
| 243 | } else {\r |
| 244 | char *p;\r |
| 245 | for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);\r |
| 246 | *p = 0;\r |
| 247 | fname = p+1;\r |
| 248 | }\r |
| 249 | \r |
| 250 | n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r |
| 251 | if (n < 0) {\r |
| 252 | // try root\r |
| 253 | n = scandir("/", &namelist, scandir_filter, scandir_cmp);\r |
| 254 | if (n < 0) {\r |
| 255 | // oops, we failed\r |
| 256 | lprintf("dir: "); lprintf(curr_path); lprintf("\n");\r |
| 257 | perror("scandir");\r |
| 258 | return NULL;\r |
| 259 | }\r |
| 260 | }\r |
| 261 | \r |
| 262 | // try to find sel\r |
| 263 | if (fname != NULL) {\r |
| 264 | int i;\r |
| 265 | for (i = 1; i < n; i++) {\r |
| 266 | if (strcmp(namelist[i]->d_name, fname) == 0) {\r |
| 267 | sel = i - 1;\r |
| 268 | break;\r |
| 269 | }\r |
| 270 | }\r |
| 271 | }\r |
| 272 | \r |
| 273 | for (;;)\r |
| 274 | {\r |
| 275 | draw_dirlist(curr_path, namelist, n, sel);\r |
| 276 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);\r |
| 277 | if(inp & BTN_UP ) { sel--; if (sel < 0) sel = n-2; }\r |
| 278 | if(inp & BTN_DOWN) { sel++; if (sel > n-2) sel = 0; }\r |
| 279 | if(inp & BTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r |
| 280 | if(inp & BTN_L) { sel-=24; if (sel < 0) sel = 0; }\r |
| 281 | if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r |
| 282 | if(inp & BTN_R) { sel+=24; if (sel > n-2) sel = n-2; }\r |
| 283 | if(inp & BTN_PLAY) { // enter dir/select\r |
| 284 | again:\r |
| 285 | if (namelist[sel+1]->d_type == DT_REG) {\r |
| 286 | strcpy(romFileName, curr_path);\r |
| 287 | strcat(romFileName, "/");\r |
| 288 | strcat(romFileName, namelist[sel+1]->d_name);\r |
| 289 | ret = romFileName;\r |
| 290 | break;\r |
| 291 | } else if (namelist[sel+1]->d_type == DT_DIR) {\r |
| 292 | int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r |
| 293 | char *p, *newdir = malloc(newlen);\r |
| 294 | if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r |
| 295 | char *start = curr_path;\r |
| 296 | p = start + strlen(start) - 1;\r |
| 297 | while (*p == '/' && p > start) p--;\r |
| 298 | while (*p != '/' && p > start) p--;\r |
| 299 | if (p <= start) strcpy(newdir, "/");\r |
| 300 | else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r |
| 301 | } else {\r |
| 302 | strcpy(newdir, curr_path);\r |
| 303 | p = newdir + strlen(newdir) - 1;\r |
| 304 | while (*p == '/' && p >= newdir) *p-- = 0;\r |
| 305 | strcat(newdir, "/");\r |
| 306 | strcat(newdir, namelist[sel+1]->d_name);\r |
| 307 | }\r |
| 308 | ret = romsel_loop(newdir);\r |
| 309 | free(newdir);\r |
| 310 | break;\r |
| 311 | } else {\r |
| 312 | // unknown file type, happens on NTFS mounts. Try to guess.\r |
| 313 | FILE *tstf; int tmp;\r |
| 314 | strcpy(romFileName, curr_path);\r |
| 315 | strcat(romFileName, "/");\r |
| 316 | strcat(romFileName, namelist[sel+1]->d_name);\r |
| 317 | tstf = fopen(romFileName, "rb");\r |
| 318 | if (tstf != NULL)\r |
| 319 | {\r |
| 320 | if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r |
| 321 | namelist[sel+1]->d_type = DT_REG;\r |
| 322 | else namelist[sel+1]->d_type = DT_DIR;\r |
| 323 | fclose(tstf);\r |
| 324 | goto again;\r |
| 325 | }\r |
| 326 | }\r |
| 327 | }\r |
| 328 | if(inp & BTN_STOP) break; // cancel\r |
| 329 | }\r |
| 330 | \r |
| 331 | if (n > 0) {\r |
| 332 | while(n--) free(namelist[n]);\r |
| 333 | free(namelist);\r |
| 334 | }\r |
| 335 | \r |
| 336 | return ret;\r |
| 337 | }\r |
| 338 | #endif\r |
| 339 | static char *romsel_loop(char *curr_path)\r |
| 340 | {\r |
| 341 | return NULL;\r |
| 342 | }\r |
| 343 | \r |
| 344 | // ------------ patch/gg menu ------------\r |
| 345 | \r |
| 346 | static void draw_patchlist(int sel)\r |
| 347 | {\r |
| 348 | int start, i, pos, active;\r |
| 349 | \r |
| 350 | start = 12 - sel;\r |
| 351 | \r |
| 352 | menu_draw_begin(1);\r |
| 353 | \r |
| 354 | for (i = 0; i < PicoPatchCount; i++) {\r |
| 355 | pos = start + i;\r |
| 356 | if (pos < 0) continue;\r |
| 357 | if (pos > 23) break;\r |
| 358 | active = PicoPatches[i].active;\r |
| 359 | smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);\r |
| 360 | smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);\r |
| 361 | }\r |
| 362 | pos = start + i;\r |
| 363 | if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);\r |
| 364 | \r |
| 365 | text_out16(5, 120, ">");\r |
| 366 | menu_draw_end();\r |
| 367 | }\r |
| 368 | \r |
| 369 | \r |
| 370 | static void patches_menu_loop(void)\r |
| 371 | {\r |
| 372 | int menu_sel = 0;\r |
| 373 | unsigned long inp = 0;\r |
| 374 | \r |
| 375 | for(;;)\r |
| 376 | {\r |
| 377 | draw_patchlist(menu_sel);\r |
| 378 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);\r |
| 379 | if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r |
| 380 | if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r |
| 381 | if(inp &(BTN_LEFT|BTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r |
| 382 | if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r |
| 383 | if(inp & BTN_PLAY) { // action\r |
| 384 | if (menu_sel < PicoPatchCount)\r |
| 385 | PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r |
| 386 | else return;\r |
| 387 | }\r |
| 388 | if(inp & BTN_STOP) return;\r |
| 389 | }\r |
| 390 | \r |
| 391 | }\r |
| 392 | \r |
| 393 | // ------------ savestate loader ------------\r |
| 394 | \r |
| 395 | static int state_slot_flags = 0;\r |
| 396 | \r |
| 397 | static void state_check_slots(void)\r |
| 398 | {\r |
| 399 | int slot;\r |
| 400 | \r |
| 401 | state_slot_flags = 0;\r |
| 402 | \r |
| 403 | for (slot = 0; slot < 10; slot++)\r |
| 404 | {\r |
| 405 | if (emu_check_save_file(slot))\r |
| 406 | {\r |
| 407 | state_slot_flags |= 1 << slot;\r |
| 408 | }\r |
| 409 | }\r |
| 410 | }\r |
| 411 | \r |
| 412 | static void draw_savestate_bg(int slot)\r |
| 413 | {\r |
| 414 | struct PicoVideo tmp_pv;\r |
| 415 | unsigned short tmp_cram[0x40];\r |
| 416 | unsigned short tmp_vsram[0x40];\r |
| 417 | void *tmp_vram, *file;\r |
| 418 | char *fname;\r |
| 419 | \r |
| 420 | fname = emu_GetSaveFName(1, 0, slot);\r |
| 421 | if (!fname) return;\r |
| 422 | \r |
| 423 | tmp_vram = malloc(sizeof(Pico.vram));\r |
| 424 | if (tmp_vram == NULL) return;\r |
| 425 | \r |
| 426 | memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));\r |
| 427 | memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));\r |
| 428 | memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));\r |
| 429 | memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));\r |
| 430 | \r |
| 431 | if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r |
| 432 | file = gzopen(fname, "rb");\r |
| 433 | emu_set_save_cbs(1);\r |
| 434 | } else {\r |
| 435 | file = fopen(fname, "rb");\r |
| 436 | emu_set_save_cbs(0);\r |
| 437 | }\r |
| 438 | \r |
| 439 | if (file) {\r |
| 440 | if (PicoMCD & 1) {\r |
| 441 | PicoCdLoadStateGfx(file);\r |
| 442 | } else {\r |
| 443 | areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file\r |
| 444 | areaRead(Pico.vram, 1, sizeof(Pico.vram), file);\r |
| 445 | areaSeek(file, 0x2000, SEEK_CUR);\r |
| 446 | areaRead(Pico.cram, 1, sizeof(Pico.cram), file);\r |
| 447 | areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);\r |
| 448 | areaSeek(file, 0x221a0, SEEK_SET);\r |
| 449 | areaRead(&Pico.video, 1, sizeof(Pico.video), file);\r |
| 450 | }\r |
| 451 | areaClose(file);\r |
| 452 | }\r |
| 453 | \r |
| 454 | emu_forced_frame();\r |
| 455 | menu_prepare_bg(1);\r |
| 456 | \r |
| 457 | memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r |
| 458 | memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));\r |
| 459 | memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));\r |
| 460 | memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));\r |
| 461 | free(tmp_vram);\r |
| 462 | }\r |
| 463 | \r |
| 464 | static void draw_savestate_menu(int menu_sel, int is_loading)\r |
| 465 | {\r |
| 466 | int tl_x = 25, tl_y = 60, y, i;\r |
| 467 | \r |
| 468 | if (state_slot_flags & (1 << menu_sel))\r |
| 469 | draw_savestate_bg(menu_sel);\r |
| 470 | menu_draw_begin(1);\r |
| 471 | \r |
| 472 | text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");\r |
| 473 | \r |
| 474 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);\r |
| 475 | \r |
| 476 | /* draw all 10 slots */\r |
| 477 | y = tl_y;\r |
| 478 | for (i = 0; i < 10; i++, y+=10)\r |
| 479 | {\r |
| 480 | text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r |
| 481 | }\r |
| 482 | text_out16(tl_x, y, "back");\r |
| 483 | \r |
| 484 | menu_draw_end();\r |
| 485 | }\r |
| 486 | \r |
| 487 | static int savestate_menu_loop(int is_loading)\r |
| 488 | {\r |
| 489 | static int menu_sel = 10;\r |
| 490 | int menu_sel_max = 10;\r |
| 491 | unsigned long inp = 0;\r |
| 492 | \r |
| 493 | state_check_slots();\r |
| 494 | \r |
| 495 | for(;;)\r |
| 496 | {\r |
| 497 | draw_savestate_menu(menu_sel, is_loading);\r |
| 498 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);\r |
| 499 | if(inp & BTN_UP ) {\r |
| 500 | do {\r |
| 501 | menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;\r |
| 502 | } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r |
| 503 | }\r |
| 504 | if(inp & BTN_DOWN) {\r |
| 505 | do {\r |
| 506 | menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;\r |
| 507 | } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r |
| 508 | }\r |
| 509 | if(inp & BTN_PLAY) { // save/load\r |
| 510 | if (menu_sel < 10) {\r |
| 511 | state_slot = menu_sel;\r |
| 512 | if (emu_SaveLoadGame(is_loading, 0)) {\r |
| 513 | strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");\r |
| 514 | return 1;\r |
| 515 | }\r |
| 516 | return 0;\r |
| 517 | } else return 1;\r |
| 518 | }\r |
| 519 | if(inp & BTN_STOP) return 1;\r |
| 520 | }\r |
| 521 | }\r |
| 522 | \r |
| 523 | // -------------- key config --------------\r |
| 524 | \r |
| 525 | static char *action_binds(int player_idx, int action_mask)\r |
| 526 | {\r |
| 527 | static char strkeys[32*5];\r |
| 528 | int i;\r |
| 529 | \r |
| 530 | strkeys[0] = 0;\r |
| 531 | for (i = 0; i < 32; i++) // i is key index\r |
| 532 | {\r |
| 533 | if (currentConfig.KeyBinds[i] & action_mask)\r |
| 534 | {\r |
| 535 | if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;\r |
| 536 | if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gizKeyNames[i]); break; }\r |
| 537 | else strcpy(strkeys, gizKeyNames[i]);\r |
| 538 | }\r |
| 539 | }\r |
| 540 | \r |
| 541 | return strkeys;\r |
| 542 | }\r |
| 543 | \r |
| 544 | static void unbind_action(int action)\r |
| 545 | {\r |
| 546 | int i;\r |
| 547 | \r |
| 548 | for (i = 0; i < 32; i++)\r |
| 549 | currentConfig.KeyBinds[i] &= ~action;\r |
| 550 | }\r |
| 551 | \r |
| 552 | static int count_bound_keys(int action)\r |
| 553 | {\r |
| 554 | int i, keys = 0;\r |
| 555 | \r |
| 556 | for (i = 0; i < 32; i++)\r |
| 557 | if (currentConfig.KeyBinds[i] & action) keys++;\r |
| 558 | \r |
| 559 | return keys;\r |
| 560 | }\r |
| 561 | \r |
| 562 | typedef struct { char *name; int mask; } bind_action_t;\r |
| 563 | \r |
| 564 | static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel)\r |
| 565 | {\r |
| 566 | int x, y, tl_y = 40, i;\r |
| 567 | \r |
| 568 | menu_draw_begin(1);\r |
| 569 | if (player_idx >= 0) {\r |
| 570 | text_out16(80, 20, "Player %i controls", player_idx + 1);\r |
| 571 | x = 100;\r |
| 572 | } else {\r |
| 573 | text_out16(80, 20, "Emulator controls");\r |
| 574 | x = 40;\r |
| 575 | }\r |
| 576 | \r |
| 577 | menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);\r |
| 578 | \r |
| 579 | y = tl_y;\r |
| 580 | for (i = 0; i < opt_cnt; i++, y+=10)\r |
| 581 | text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));\r |
| 582 | \r |
| 583 | text_out16(x, y, "Done");\r |
| 584 | \r |
| 585 | if (sel < opt_cnt) {\r |
| 586 | text_out16(30, 180, "Press a button to bind/unbind");\r |
| 587 | text_out16(30, 190, "Use SELECT to clear");\r |
| 588 | text_out16(30, 200, "To bind UP/DOWN, hold SELECT");\r |
| 589 | text_out16(30, 210, "Select \"Done\" to exit");\r |
| 590 | } else {\r |
| 591 | text_out16(30, 190, "Use Options -> Save cfg");\r |
| 592 | text_out16(30, 200, "to save controls");\r |
| 593 | text_out16(30, 210, "Press B or X to exit");\r |
| 594 | }\r |
| 595 | menu_draw_end();\r |
| 596 | }\r |
| 597 | \r |
| 598 | static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)\r |
| 599 | {\r |
| 600 | int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;\r |
| 601 | unsigned long inp = 0;\r |
| 602 | \r |
| 603 | for (;;)\r |
| 604 | {\r |
| 605 | draw_key_config(opts, opt_cnt, player_idx, sel);\r |
| 606 | inp = wait_for_input(CONFIGURABLE_KEYS);\r |
| 607 | if (!(inp & BTN_HOME)) {\r |
| 608 | prev_select = 0;\r |
| 609 | if(inp & BTN_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r |
| 610 | if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }\r |
| 611 | }\r |
| 612 | if (sel >= opt_cnt) {\r |
| 613 | if (inp & (BTN_PLAY|BTN_STOP)) break;\r |
| 614 | else continue;\r |
| 615 | }\r |
| 616 | // if we are here, we want to bind/unbind something\r |
| 617 | if ((inp & BTN_HOME) && !prev_select)\r |
| 618 | unbind_action(opts[sel].mask);\r |
| 619 | prev_select = inp & BTN_HOME;\r |
| 620 | inp &= CONFIGURABLE_KEYS;\r |
| 621 | inp &= ~BTN_HOME;\r |
| 622 | for (i = 0; i < 32; i++)\r |
| 623 | if (inp & (1 << i)) {\r |
| 624 | if (count_bound_keys(opts[sel].mask) >= 2)\r |
| 625 | currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only\r |
| 626 | else currentConfig.KeyBinds[i] ^= opts[sel].mask;\r |
| 627 | if (player_idx >= 0) {\r |
| 628 | currentConfig.KeyBinds[i] &= ~(3 << 16);\r |
| 629 | currentConfig.KeyBinds[i] |= player_idx << 16;\r |
| 630 | }\r |
| 631 | }\r |
| 632 | }\r |
| 633 | }\r |
| 634 | \r |
| 635 | static void draw_kc_sel(int menu_sel)\r |
| 636 | {\r |
| 637 | int tl_x = 25+40, tl_y = 60, y;\r |
| 638 | \r |
| 639 | y = tl_y;\r |
| 640 | menu_draw_begin(1);\r |
| 641 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);\r |
| 642 | \r |
| 643 | text_out16(tl_x, y, "Player 1");\r |
| 644 | text_out16(tl_x, (y+=10), "Player 2");\r |
| 645 | text_out16(tl_x, (y+=10), "Emulator controls");\r |
| 646 | text_out16(tl_x, (y+=10), "Done");\r |
| 647 | \r |
| 648 | menu_draw_end();\r |
| 649 | }\r |
| 650 | \r |
| 651 | \r |
| 652 | // PicoPad[] format: MXYZ SACB RLDU\r |
| 653 | static bind_action_t ctrl_actions[] =\r |
| 654 | {\r |
| 655 | { "UP ", 0x001 },\r |
| 656 | { "DOWN ", 0x002 },\r |
| 657 | { "LEFT ", 0x004 },\r |
| 658 | { "RIGHT ", 0x008 },\r |
| 659 | { "A ", 0x040 },\r |
| 660 | { "B ", 0x010 },\r |
| 661 | { "C ", 0x020 },\r |
| 662 | { "START ", 0x080 },\r |
| 663 | { "MODE ", 0x800 },\r |
| 664 | { "X ", 0x400 },\r |
| 665 | { "Y ", 0x200 },\r |
| 666 | { "Z ", 0x100 },\r |
| 667 | };\r |
| 668 | \r |
| 669 | // player2_flag, ?, ?, ?, ?, ?, ?, menu\r |
| 670 | // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r |
| 671 | // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r |
| 672 | static bind_action_t emuctrl_actions[] =\r |
| 673 | {\r |
| 674 | { "Load State ", 1<<28 },\r |
| 675 | { "Save State ", 1<<27 },\r |
| 676 | { "Prev Save Slot ", 1<<25 },\r |
| 677 | { "Next Save Slot ", 1<<24 },\r |
| 678 | { "Switch Renderer", 1<<26 },\r |
| 679 | { "Volume Down ", 1<<30 },\r |
| 680 | { "Volume Up ", 1<<29 },\r |
| 681 | { "Enter Menu ", 1<<23 },\r |
| 682 | };\r |
| 683 | \r |
| 684 | static void kc_sel_loop(void)\r |
| 685 | {\r |
| 686 | int menu_sel = 3, menu_sel_max = 3;\r |
| 687 | unsigned long inp = 0;\r |
| 688 | int is_6button = currentConfig.PicoOpt & 0x020;\r |
| 689 | \r |
| 690 | while (1)\r |
| 691 | {\r |
| 692 | draw_kc_sel(menu_sel);\r |
| 693 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);\r |
| 694 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
| 695 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
| 696 | if (inp & BTN_PLAY) {\r |
| 697 | switch (menu_sel) {\r |
| 698 | case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return;\r |
| 699 | case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return;\r |
| 700 | case 2: key_config_loop(emuctrl_actions,\r |
| 701 | sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;\r |
| 702 | case 3: if (rom_data == NULL) emu_WriteConfig(0); return;\r |
| 703 | default: return;\r |
| 704 | }\r |
| 705 | }\r |
| 706 | if (inp & BTN_STOP) return;\r |
| 707 | }\r |
| 708 | }\r |
| 709 | \r |
| 710 | \r |
| 711 | // --------- sega/mega cd options ----------\r |
| 712 | \r |
| 713 | menu_entry cdopt_entries[] =\r |
| 714 | {\r |
| 715 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 },\r |
| 716 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 },\r |
| 717 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 },\r |
| 718 | { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 },\r |
| 719 | { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 },\r |
| 720 | { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 },\r |
| 721 | { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 },\r |
| 722 | { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 },\r |
| 723 | { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 },\r |
| 724 | { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 },\r |
| 725 | { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 },\r |
| 726 | };\r |
| 727 | \r |
| 728 | #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))\r |
| 729 | \r |
| 730 | \r |
| 731 | struct bios_names_t\r |
| 732 | {\r |
| 733 | char us[32], eu[32], jp[32];\r |
| 734 | };\r |
| 735 | \r |
| 736 | static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r |
| 737 | {\r |
| 738 | struct bios_names_t *bios_names = param;\r |
| 739 | char ra_buff[16];\r |
| 740 | \r |
| 741 | switch (entry->id)\r |
| 742 | {\r |
| 743 | case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break;\r |
| 744 | case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break;\r |
| 745 | case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break;\r |
| 746 | case MA_CDOPT_READAHEAD:\r |
| 747 | if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r |
| 748 | else strcpy(ra_buff, " OFF");\r |
| 749 | text_out16(x, y, "ReadAhead buffer %s", ra_buff);\r |
| 750 | break;\r |
| 751 | default:break;\r |
| 752 | }\r |
| 753 | }\r |
| 754 | \r |
| 755 | static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)\r |
| 756 | {\r |
| 757 | int tl_x = 25, tl_y = 60;\r |
| 758 | menu_id selected_id;\r |
| 759 | char ra_buff[16];\r |
| 760 | \r |
| 761 | if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r |
| 762 | else strcpy(ra_buff, " OFF");\r |
| 763 | \r |
| 764 | menu_draw_begin(1);\r |
| 765 | \r |
| 766 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);\r |
| 767 | \r |
| 768 | me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);\r |
| 769 | \r |
| 770 | selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r |
| 771 | if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||\r |
| 772 | (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||\r |
| 773 | (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))\r |
| 774 | text_out16(tl_x, 210, "Press start to test selected BIOS");\r |
| 775 | \r |
| 776 | menu_draw_end();\r |
| 777 | }\r |
| 778 | \r |
| 779 | static void cd_menu_loop_options(void)\r |
| 780 | {\r |
| 781 | static int menu_sel = 0;\r |
| 782 | int menu_sel_max = 10;\r |
| 783 | unsigned long inp = 0;\r |
| 784 | struct bios_names_t bios_names;\r |
| 785 | menu_id selected_id;\r |
| 786 | char *bios, *p;\r |
| 787 | \r |
| 788 | if (find_bios(4, &bios)) { // US\r |
| 789 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r |
| 790 | strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;\r |
| 791 | } else strcpy(bios_names.us, "NOT FOUND");\r |
| 792 | \r |
| 793 | if (find_bios(8, &bios)) { // EU\r |
| 794 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r |
| 795 | strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;\r |
| 796 | } else strcpy(bios_names.eu, "NOT FOUND");\r |
| 797 | \r |
| 798 | if (find_bios(1, &bios)) { // JP\r |
| 799 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r |
| 800 | strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;\r |
| 801 | } else strcpy(bios_names.jp, "NOT FOUND");\r |
| 802 | \r |
| 803 | for(;;)\r |
| 804 | {\r |
| 805 | draw_cd_menu_options(menu_sel, &bios_names);\r |
| 806 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);\r |
| 807 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
| 808 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
| 809 | selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r |
| 810 | if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r |
| 811 | if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&\r |
| 812 | selected_id == MA_CDOPT_READAHEAD) {\r |
| 813 | if (inp & BTN_LEFT) {\r |
| 814 | PicoCDBuffers >>= 1;\r |
| 815 | if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r |
| 816 | } else {\r |
| 817 | if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r |
| 818 | else PicoCDBuffers <<= 1;\r |
| 819 | if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M\r |
| 820 | }\r |
| 821 | }\r |
| 822 | }\r |
| 823 | if (inp & BTN_PLAY) { // toggleable options\r |
| 824 | if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&\r |
| 825 | selected_id == MA_CDOPT_DONE) {\r |
| 826 | return;\r |
| 827 | }\r |
| 828 | switch (selected_id) { // BIOS testers\r |
| 829 | case MA_CDOPT_TESTBIOS_USA:\r |
| 830 | if (find_bios(4, &bios)) { // test US\r |
| 831 | strcpy(romFileName, bios);\r |
| 832 | engineState = PGS_ReloadRom;\r |
| 833 | return;\r |
| 834 | }\r |
| 835 | break;\r |
| 836 | case MA_CDOPT_TESTBIOS_EUR:\r |
| 837 | if (find_bios(8, &bios)) { // test EU\r |
| 838 | strcpy(romFileName, bios);\r |
| 839 | engineState = PGS_ReloadRom;\r |
| 840 | return;\r |
| 841 | }\r |
| 842 | break;\r |
| 843 | case MA_CDOPT_TESTBIOS_JAP:\r |
| 844 | if (find_bios(1, &bios)) { // test JP\r |
| 845 | strcpy(romFileName, bios);\r |
| 846 | engineState = PGS_ReloadRom;\r |
| 847 | return;\r |
| 848 | }\r |
| 849 | break;\r |
| 850 | default:\r |
| 851 | break;\r |
| 852 | }\r |
| 853 | }\r |
| 854 | if (inp & (BTN_STOP|BTN_REW)) return;\r |
| 855 | }\r |
| 856 | }\r |
| 857 | \r |
| 858 | \r |
| 859 | // --------- advanced options ----------\r |
| 860 | \r |
| 861 | menu_entry opt2_entries[] =\r |
| 862 | {\r |
| 863 | { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 },\r |
| 864 | { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 },\r |
| 865 | { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 },\r |
| 866 | { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 },\r |
| 867 | { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 },\r |
| 868 | { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 },\r |
| 869 | };\r |
| 870 | \r |
| 871 | #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))\r |
| 872 | \r |
| 873 | \r |
| 874 | static void draw_amenu_options(int menu_sel)\r |
| 875 | {\r |
| 876 | int tl_x = 25, tl_y = 50;\r |
| 877 | \r |
| 878 | menu_draw_begin(1);\r |
| 879 | \r |
| 880 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);\r |
| 881 | \r |
| 882 | me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);\r |
| 883 | \r |
| 884 | menu_draw_end();\r |
| 885 | }\r |
| 886 | \r |
| 887 | static void amenu_loop_options(void)\r |
| 888 | {\r |
| 889 | static int menu_sel = 0;\r |
| 890 | int menu_sel_max;\r |
| 891 | unsigned long inp = 0;\r |
| 892 | menu_id selected_id;\r |
| 893 | \r |
| 894 | menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;\r |
| 895 | \r |
| 896 | for(;;)\r |
| 897 | {\r |
| 898 | draw_amenu_options(menu_sel);\r |
| 899 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);\r |
| 900 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
| 901 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
| 902 | selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);\r |
| 903 | if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r |
| 904 | if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0) &&\r |
| 905 | selected_id == MA_OPT2_GAMMA) {\r |
| 906 | while ((inp = Framework_PollGetButtons(1)) & (BTN_LEFT|BTN_RIGHT)) {\r |
| 907 | currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1;\r |
| 908 | if (currentConfig.gamma < 1) currentConfig.gamma = 1;\r |
| 909 | if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r |
| 910 | draw_amenu_options(menu_sel);\r |
| 911 | Sleep(18);\r |
| 912 | }\r |
| 913 | }\r |
| 914 | }\r |
| 915 | if (inp & BTN_PLAY) { // toggleable options\r |
| 916 | if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&\r |
| 917 | selected_id == MA_OPT2_DONE) {\r |
| 918 | return;\r |
| 919 | }\r |
| 920 | }\r |
| 921 | if (inp & (BTN_STOP|BTN_REW)) return;\r |
| 922 | }\r |
| 923 | }\r |
| 924 | \r |
| 925 | // -------------- options --------------\r |
| 926 | \r |
| 927 | \r |
| 928 | menu_entry opt_entries[] =\r |
| 929 | {\r |
| 930 | { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 },\r |
| 931 | { "Scale low res mode", MB_ONOFF, MA_OPT_SCALING, ¤tConfig.scaling, 0x001, 0, 3, 1 },\r |
| 932 | { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, ¤tConfig.PicoOpt, 0x040, 0, 0, 1 },\r |
| 933 | { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, ¤tConfig.PicoOpt, 0x080, 0, 0, 1 },\r |
| 934 | { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x002, 0, 0, 1 },\r |
| 935 | { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 },\r |
| 936 | { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x004, 0, 0, 1 },\r |
| 937 | { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },\r |
| 938 | { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, ¤tConfig.PicoOpt, 0x020, 0, 0, 1 },\r |
| 939 | { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 },\r |
| 940 | { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x001, 0, 0, 1 },\r |
| 941 | { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },\r |
| 942 | { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 },\r |
| 943 | { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 },\r |
| 944 | { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 },\r |
| 945 | { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 },\r |
| 946 | { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 },\r |
| 947 | { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 },\r |
| 948 | };\r |
| 949 | \r |
| 950 | #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))\r |
| 951 | \r |
| 952 | \r |
| 953 | static const char *region_name(unsigned int code)\r |
| 954 | {\r |
| 955 | static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r |
| 956 | static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r |
| 957 | int u, i = 0;\r |
| 958 | if (code) {\r |
| 959 | code <<= 1;\r |
| 960 | while((code >>= 1)) i++;\r |
| 961 | if (i > 4) return "unknown";\r |
| 962 | return names[i];\r |
| 963 | } else {\r |
| 964 | static char name[24];\r |
| 965 | strcpy(name, "Auto:");\r |
| 966 | for (u = 0; u < 3; u++) {\r |
| 967 | i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;\r |
| 968 | while((code >>= 1)) i++;\r |
| 969 | strcat(name, names_short[i]);\r |
| 970 | }\r |
| 971 | return name;\r |
| 972 | }\r |
| 973 | }\r |
| 974 | \r |
| 975 | \r |
| 976 | static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r |
| 977 | {\r |
| 978 | char *str, str24[24];\r |
| 979 | \r |
| 980 | switch (entry->id)\r |
| 981 | {\r |
| 982 | case MA_OPT_RENDERER:\r |
| 983 | if (currentConfig.PicoOpt&0x10)\r |
| 984 | str = " 8bit fast";\r |
| 985 | else if (currentConfig.EmuOpt&0x80)\r |
| 986 | str = "16bit accurate";\r |
| 987 | else\r |
| 988 | str = " 8bit accurate";\r |
| 989 | text_out16(x, y, "Renderer: %s", str);\r |
| 990 | break;\r |
| 991 | case MA_OPT_FRAMESKIP:\r |
| 992 | if (currentConfig.Frameskip < 0)\r |
| 993 | strcpy(str24, "Auto");\r |
| 994 | else sprintf(str24, "%i", currentConfig.Frameskip);\r |
| 995 | text_out16(x, y, "Frameskip %s", str24);\r |
| 996 | break;\r |
| 997 | case MA_OPT_SOUND_QUALITY:\r |
| 998 | str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";\r |
| 999 | text_out16(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str);\r |
| 1000 | break;\r |
| 1001 | case MA_OPT_REGION:\r |
| 1002 | text_out16(x, y, "Region: %s", region_name(currentConfig.PicoRegion));\r |
| 1003 | break;\r |
| 1004 | case MA_OPT_CONFIRM_STATES:\r |
| 1005 | switch ((currentConfig.EmuOpt >> 9) & 5) {\r |
| 1006 | default: str = "OFF"; break;\r |
| 1007 | case 1: str = "writes"; break;\r |
| 1008 | case 4: str = "loads"; break;\r |
| 1009 | case 5: str = "both"; break;\r |
| 1010 | }\r |
| 1011 | text_out16(x, y, "Confirm savestate %s", str);\r |
| 1012 | break;\r |
| 1013 | case MA_OPT_SAVECFG:\r |
| 1014 | str24[0] = 0;\r |
| 1015 | if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);\r |
| 1016 | text_out16(x, y, "Save cfg as default%s", str24);\r |
| 1017 | break;\r |
| 1018 | case MA_OPT_LOADCFG:\r |
| 1019 | text_out16(x, y, "Load cfg from profile %i", config_slot);\r |
| 1020 | break;\r |
| 1021 | default:\r |
| 1022 | lprintf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);\r |
| 1023 | break;\r |
| 1024 | }\r |
| 1025 | }\r |
| 1026 | \r |
| 1027 | \r |
| 1028 | \r |
| 1029 | static void draw_menu_options(int menu_sel)\r |
| 1030 | {\r |
| 1031 | int tl_x = 25, tl_y = 24;\r |
| 1032 | \r |
| 1033 | menu_draw_begin(1);\r |
| 1034 | \r |
| 1035 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);\r |
| 1036 | \r |
| 1037 | me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);\r |
| 1038 | \r |
| 1039 | menu_draw_end();\r |
| 1040 | }\r |
| 1041 | \r |
| 1042 | static int sndrate_prevnext(int rate, int dir)\r |
| 1043 | {\r |
| 1044 | int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };\r |
| 1045 | \r |
| 1046 | for (i = 0; i < 5; i++)\r |
| 1047 | if (rates[i] == rate) break;\r |
| 1048 | \r |
| 1049 | i += dir ? 1 : -1;\r |
| 1050 | if (i > 4) return dir ? 44100 : 22050;\r |
| 1051 | if (i < 0) return dir ? 11025 : 8000;\r |
| 1052 | return rates[i];\r |
| 1053 | }\r |
| 1054 | \r |
| 1055 | static void region_prevnext(int right)\r |
| 1056 | {\r |
| 1057 | // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r |
| 1058 | static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r |
| 1059 | int i;\r |
| 1060 | if (right) {\r |
| 1061 | if (!currentConfig.PicoRegion) {\r |
| 1062 | for (i = 0; i < 6; i++)\r |
| 1063 | if (rgn_orders[i] == PicoAutoRgnOrder) break;\r |
| 1064 | if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r |
| 1065 | else currentConfig.PicoRegion=1;\r |
| 1066 | }\r |
| 1067 | else currentConfig.PicoRegion<<=1;\r |
| 1068 | if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;\r |
| 1069 | } else {\r |
| 1070 | if (!currentConfig.PicoRegion) {\r |
| 1071 | for (i = 0; i < 6; i++)\r |
| 1072 | if (rgn_orders[i] == PicoAutoRgnOrder) break;\r |
| 1073 | if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r |
| 1074 | }\r |
| 1075 | else currentConfig.PicoRegion>>=1;\r |
| 1076 | }\r |
| 1077 | }\r |
| 1078 | \r |
| 1079 | static void menu_options_save(void)\r |
| 1080 | {\r |
| 1081 | PicoOpt = currentConfig.PicoOpt;\r |
| 1082 | PsndRate = currentConfig.PsndRate;\r |
| 1083 | PicoRegionOverride = currentConfig.PicoRegion;\r |
| 1084 | if (!(PicoOpt & 0x20)) {\r |
| 1085 | // unbind XYZ MODE, just in case\r |
| 1086 | unbind_action(0xf00);\r |
| 1087 | }\r |
| 1088 | scaling_update();\r |
| 1089 | }\r |
| 1090 | \r |
| 1091 | static int menu_loop_options(void)\r |
| 1092 | {\r |
| 1093 | static int menu_sel = 0;\r |
| 1094 | int menu_sel_max, ret;\r |
| 1095 | unsigned long inp = 0;\r |
| 1096 | menu_id selected_id;\r |
| 1097 | \r |
| 1098 | currentConfig.PicoOpt = PicoOpt;\r |
| 1099 | currentConfig.PsndRate = PsndRate;\r |
| 1100 | currentConfig.PicoRegion = PicoRegionOverride;\r |
| 1101 | \r |
| 1102 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL);\r |
| 1103 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r |
| 1104 | menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r |
| 1105 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r |
| 1106 | \r |
| 1107 | while (1)\r |
| 1108 | {\r |
| 1109 | draw_menu_options(menu_sel);\r |
| 1110 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);\r |
| 1111 | if (inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
| 1112 | if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
| 1113 | selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);\r |
| 1114 | if (inp & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r |
| 1115 | if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) {\r |
| 1116 | switch (selected_id) {\r |
| 1117 | case MA_OPT_RENDERER:\r |
| 1118 | if (inp & BTN_LEFT) {\r |
| 1119 | if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r |
| 1120 | else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;\r |
| 1121 | else if ( currentConfig.EmuOpt &0x80) break;\r |
| 1122 | } else {\r |
| 1123 | if ( currentConfig.PicoOpt&0x10) break;\r |
| 1124 | else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;\r |
| 1125 | else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r |
| 1126 | }\r |
| 1127 | break;\r |
| 1128 | case MA_OPT_SOUND_QUALITY:\r |
| 1129 | if ((inp & BTN_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r |
| 1130 | currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;\r |
| 1131 | } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r |
| 1132 | currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r |
| 1133 | } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & BTN_RIGHT);\r |
| 1134 | break;\r |
| 1135 | case MA_OPT_REGION:\r |
| 1136 | region_prevnext(inp & BTN_RIGHT);\r |
| 1137 | break;\r |
| 1138 | case MA_OPT_CONFIRM_STATES: {\r |
| 1139 | int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r |
| 1140 | n += (inp & BTN_LEFT) ? -1 : 1;\r |
| 1141 | if (n < 0) n = 0; else if (n > 3) n = 3;\r |
| 1142 | n |= n << 1; n &= ~2;\r |
| 1143 | currentConfig.EmuOpt &= ~0xa00;\r |
| 1144 | currentConfig.EmuOpt |= n << 9;\r |
| 1145 | break;\r |
| 1146 | }\r |
| 1147 | case MA_OPT_SAVE_SLOT:\r |
| 1148 | if (inp & BTN_RIGHT) {\r |
| 1149 | state_slot++; if (state_slot > 9) state_slot = 0;\r |
| 1150 | } else {state_slot--; if (state_slot < 0) state_slot = 9;\r |
| 1151 | }\r |
| 1152 | break;\r |
| 1153 | case MA_OPT_SAVECFG:\r |
| 1154 | case MA_OPT_SAVECFG_GAME:\r |
| 1155 | case MA_OPT_LOADCFG:\r |
| 1156 | config_slot += (inp&BTN_RIGHT) ? 1 : -1;\r |
| 1157 | if (config_slot > 9) config_slot = 0;\r |
| 1158 | if (config_slot < 0) config_slot = 9;\r |
| 1159 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r |
| 1160 | menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r |
| 1161 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r |
| 1162 | break;\r |
| 1163 | default:\r |
| 1164 | //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);\r |
| 1165 | break;\r |
| 1166 | }\r |
| 1167 | }\r |
| 1168 | }\r |
| 1169 | if (inp & BTN_PLAY) {\r |
| 1170 | if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))\r |
| 1171 | {\r |
| 1172 | switch (selected_id)\r |
| 1173 | {\r |
| 1174 | case MA_OPT_SCD_OPTS:\r |
| 1175 | cd_menu_loop_options();\r |
| 1176 | if (engineState == PGS_ReloadRom)\r |
| 1177 | return 0; // test BIOS\r |
| 1178 | break;\r |
| 1179 | case MA_OPT_ADV_OPTS:\r |
| 1180 | amenu_loop_options();\r |
| 1181 | break;\r |
| 1182 | case MA_OPT_SAVECFG: // done (update and write)\r |
| 1183 | menu_options_save();\r |
| 1184 | if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r |
| 1185 | else strcpy(menuErrorMsg, "failed to write config");\r |
| 1186 | return 1;\r |
| 1187 | case MA_OPT_SAVECFG_GAME: // done (update and write for current game)\r |
| 1188 | menu_options_save();\r |
| 1189 | if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r |
| 1190 | else strcpy(menuErrorMsg, "failed to write config");\r |
| 1191 | return 1;\r |
| 1192 | case MA_OPT_LOADCFG:\r |
| 1193 | ret = emu_ReadConfig(1, 1);\r |
| 1194 | if (!ret) ret = emu_ReadConfig(0, 1);\r |
| 1195 | if (ret) strcpy(menuErrorMsg, "config loaded");\r |
| 1196 | else strcpy(menuErrorMsg, "failed to load config");\r |
| 1197 | return 1;\r |
| 1198 | default:\r |
| 1199 | //lprintf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);\r |
| 1200 | break;\r |
| 1201 | }\r |
| 1202 | }\r |
| 1203 | }\r |
| 1204 | if(inp & (BTN_STOP|BTN_REW)) {\r |
| 1205 | menu_options_save();\r |
| 1206 | return 0; // done (update, no write)\r |
| 1207 | }\r |
| 1208 | }\r |
| 1209 | }\r |
| 1210 | \r |
| 1211 | // -------------- credits --------------\r |
| 1212 | \r |
| 1213 | static void draw_menu_credits(void)\r |
| 1214 | {\r |
| 1215 | int tl_x = 15, tl_y = 64, y;\r |
| 1216 | menu_draw_begin(1);\r |
| 1217 | \r |
| 1218 | text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r |
| 1219 | y = tl_y;\r |
| 1220 | text_out16(tl_x, y, "Credits:");\r |
| 1221 | text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r |
| 1222 | text_out16(tl_x, (y+=10), " base code of PicoDrive");\r |
| 1223 | text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r |
| 1224 | text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r |
| 1225 | text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r |
| 1226 | text_out16(tl_x, (y+=10), "Stephane Dallongeville:");\r |
| 1227 | text_out16(tl_x, (y+=10), " opensource Gens");\r |
| 1228 | text_out16(tl_x, (y+=10), "Haze: Genesis hw info");\r |
| 1229 | text_out16(tl_x, (y+=10), "Reesy: TODO");\r |
| 1230 | text_out16(tl_x, (y+=10), "TODO: gizmondo hardware");\r |
| 1231 | text_out16(tl_x, (y+=10), "ketchupgun: skin design");\r |
| 1232 | \r |
| 1233 | menu_draw_end();\r |
| 1234 | }\r |
| 1235 | \r |
| 1236 | \r |
| 1237 | // -------------- root menu --------------\r |
| 1238 | \r |
| 1239 | menu_entry main_entries[] =\r |
| 1240 | {\r |
| 1241 | { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 },\r |
| 1242 | { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 },\r |
| 1243 | { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 },\r |
| 1244 | { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 },\r |
| 1245 | { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 },\r |
| 1246 | { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 },\r |
| 1247 | { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 },\r |
| 1248 | { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 },\r |
| 1249 | { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 },\r |
| 1250 | { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 }\r |
| 1251 | };\r |
| 1252 | \r |
| 1253 | #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))\r |
| 1254 | \r |
| 1255 | static void draw_menu_root(int menu_sel)\r |
| 1256 | {\r |
| 1257 | const int tl_x = 70, tl_y = 70;\r |
| 1258 | \r |
| 1259 | menu_draw_begin(1);\r |
| 1260 | \r |
| 1261 | text_out16(tl_x, 20, "PicoDrive v" VERSION);\r |
| 1262 | \r |
| 1263 | menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);\r |
| 1264 | \r |
| 1265 | me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);\r |
| 1266 | \r |
| 1267 | // error\r |
| 1268 | if (menuErrorMsg[0]) {\r |
| 1269 | memset((char *)giz_screen + 321*224*2, 0, 321*16*2);\r |
| 1270 | text_out16(5, 226, menuErrorMsg);\r |
| 1271 | }\r |
| 1272 | menu_draw_end();\r |
| 1273 | }\r |
| 1274 | \r |
| 1275 | \r |
| 1276 | static void menu_loop_root(void)\r |
| 1277 | {\r |
| 1278 | static int menu_sel = 0;\r |
| 1279 | int ret, menu_sel_max;\r |
| 1280 | unsigned long inp = 0;\r |
| 1281 | \r |
| 1282 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL);\r |
| 1283 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_data != NULL);\r |
| 1284 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_data != NULL);\r |
| 1285 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_data != NULL);\r |
| 1286 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);\r |
| 1287 | \r |
| 1288 | menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;\r |
| 1289 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r |
| 1290 | \r |
| 1291 | /* make sure action buttons are not pressed on entering menu */\r |
| 1292 | draw_menu_root(menu_sel);\r |
| 1293 | while (Framework_PollGetButtons(1) & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50);\r |
| 1294 | \r |
| 1295 | for (;;)\r |
| 1296 | {\r |
| 1297 | draw_menu_root(menu_sel);\r |
| 1298 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R);\r |
| 1299 | if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
| 1300 | if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
| 1301 | if(inp &(BTN_HOME|BTN_STOP)){\r |
| 1302 | if (rom_data) {\r |
| 1303 | while (Framework_PollGetButtons(1) & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until select is released\r |
| 1304 | engineState = PGS_Running;\r |
| 1305 | break;\r |
| 1306 | }\r |
| 1307 | }\r |
| 1308 | if(inp & BTN_PLAY) {\r |
| 1309 | switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))\r |
| 1310 | {\r |
| 1311 | case MA_MAIN_RESUME_GAME:\r |
| 1312 | if (rom_data) {\r |
| 1313 | while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50);\r |
| 1314 | engineState = PGS_Running;\r |
| 1315 | return;\r |
| 1316 | }\r |
| 1317 | break;\r |
| 1318 | case MA_MAIN_SAVE_STATE:\r |
| 1319 | if (rom_data) {\r |
| 1320 | if(savestate_menu_loop(0))\r |
| 1321 | continue;\r |
| 1322 | engineState = PGS_Running;\r |
| 1323 | return;\r |
| 1324 | }\r |
| 1325 | break;\r |
| 1326 | case MA_MAIN_LOAD_STATE:\r |
| 1327 | if (rom_data) {\r |
| 1328 | if(savestate_menu_loop(1))\r |
| 1329 | continue;\r |
| 1330 | engineState = PGS_Running;\r |
| 1331 | return;\r |
| 1332 | }\r |
| 1333 | break;\r |
| 1334 | case MA_MAIN_RESET_GAME:\r |
| 1335 | if (rom_data) {\r |
| 1336 | emu_ResetGame();\r |
| 1337 | engineState = PGS_Running;\r |
| 1338 | return;\r |
| 1339 | }\r |
| 1340 | break;\r |
| 1341 | case MA_MAIN_LOAD_ROM:\r |
| 1342 | {\r |
| 1343 | char curr_path[MAX_PATH], *selfname;\r |
| 1344 | FILE *tstf;\r |
| 1345 | if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r |
| 1346 | {\r |
| 1347 | fclose(tstf);\r |
| 1348 | strcpy(curr_path, currentConfig.lastRomFile);\r |
| 1349 | }\r |
| 1350 | else\r |
| 1351 | getcwd(curr_path, MAX_PATH);\r |
| 1352 | selfname = romsel_loop(curr_path);\r |
| 1353 | if (selfname) {\r |
| 1354 | lprintf("selected file: %s\n", selfname);\r |
| 1355 | engineState = PGS_ReloadRom;\r |
| 1356 | return;\r |
| 1357 | }\r |
| 1358 | break;\r |
| 1359 | }\r |
| 1360 | case MA_MAIN_OPTIONS:\r |
| 1361 | ret = menu_loop_options();\r |
| 1362 | if (ret == 1) continue; // status update\r |
| 1363 | if (engineState == PGS_ReloadRom)\r |
| 1364 | return; // BIOS test\r |
| 1365 | break;\r |
| 1366 | case MA_MAIN_CONTROLS:\r |
| 1367 | kc_sel_loop();\r |
| 1368 | break;\r |
| 1369 | case MA_MAIN_CREDITS:\r |
| 1370 | draw_menu_credits();\r |
| 1371 | Sleep(500);\r |
| 1372 | inp = wait_for_input(BTN_PLAY|BTN_STOP);\r |
| 1373 | break;\r |
| 1374 | case MA_MAIN_EXIT:\r |
| 1375 | engineState = PGS_Quit;\r |
| 1376 | return;\r |
| 1377 | case MA_MAIN_PATCHES:\r |
| 1378 | if (rom_data && PicoPatches) {\r |
| 1379 | patches_menu_loop();\r |
| 1380 | PicoPatchApply();\r |
| 1381 | strcpy(menuErrorMsg, "Patches applied");\r |
| 1382 | continue;\r |
| 1383 | }\r |
| 1384 | break;\r |
| 1385 | default:\r |
| 1386 | lprintf("%s: something unknown selected\n", __FUNCTION__);\r |
| 1387 | break;\r |
| 1388 | }\r |
| 1389 | }\r |
| 1390 | menuErrorMsg[0] = 0; // clear error msg\r |
| 1391 | }\r |
| 1392 | }\r |
| 1393 | \r |
| 1394 | // warning: alignment\r |
| 1395 | static void menu_darken_bg(void *dst, const void *src, int pixels, int darker)\r |
| 1396 | {\r |
| 1397 | unsigned int *dest = dst;\r |
| 1398 | const unsigned int *srce = src;\r |
| 1399 | pixels /= 2;\r |
| 1400 | if (darker)\r |
| 1401 | {\r |
| 1402 | while (pixels--)\r |
| 1403 | {\r |
| 1404 | unsigned int p = *srce++;\r |
| 1405 | *dest++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);\r |
| 1406 | }\r |
| 1407 | }\r |
| 1408 | else\r |
| 1409 | {\r |
| 1410 | while (pixels--)\r |
| 1411 | {\r |
| 1412 | unsigned int p = *srce++;\r |
| 1413 | *dest++ = (p&0xf79ef79e)>>1;\r |
| 1414 | }\r |
| 1415 | }\r |
| 1416 | }\r |
| 1417 | \r |
| 1418 | static void menu_prepare_bg(int use_game_bg)\r |
| 1419 | {\r |
| 1420 | if (use_game_bg)\r |
| 1421 | {\r |
| 1422 | // darken the active framebuffer\r |
| 1423 | memset(bg_buffer, 0, 321*8*2);\r |
| 1424 | menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1);\r |
| 1425 | memset(bg_buffer + 321*232*2, 0, 321*8*2);\r |
| 1426 | }\r |
| 1427 | else\r |
| 1428 | {\r |
| 1429 | // should really only happen once, on startup..\r |
| 1430 | readpng(bg_buffer, "skin/background.png", READPNG_BG);\r |
| 1431 | }\r |
| 1432 | }\r |
| 1433 | \r |
| 1434 | static void menu_gfx_prepare(void)\r |
| 1435 | {\r |
| 1436 | menu_prepare_bg(rom_data != NULL);\r |
| 1437 | \r |
| 1438 | menu_draw_begin(1);\r |
| 1439 | menu_draw_end();\r |
| 1440 | }\r |
| 1441 | \r |
| 1442 | \r |
| 1443 | void menu_loop(void)\r |
| 1444 | {\r |
| 1445 | menu_gfx_prepare();\r |
| 1446 | \r |
| 1447 | menu_loop_root();\r |
| 1448 | \r |
| 1449 | menuErrorMsg[0] = 0;\r |
| 1450 | }\r |
| 1451 | \r |
| 1452 | \r |
| 1453 | // --------- CD tray close menu ----------\r |
| 1454 | \r |
| 1455 | static void draw_menu_tray(int menu_sel)\r |
| 1456 | {\r |
| 1457 | int tl_x = 70, tl_y = 90, y;\r |
| 1458 | \r |
| 1459 | menu_draw_begin(1);\r |
| 1460 | \r |
| 1461 | text_out16(tl_x, 20, "The unit is about to");\r |
| 1462 | text_out16(tl_x, 30, "close the CD tray.");\r |
| 1463 | \r |
| 1464 | y = tl_y;\r |
| 1465 | text_out16(tl_x, y, "Load new CD image");\r |
| 1466 | text_out16(tl_x, (y+=10), "Insert nothing");\r |
| 1467 | \r |
| 1468 | // draw cursor\r |
| 1469 | text_out16(tl_x - 16, tl_y + menu_sel*10, ">");\r |
| 1470 | // error\r |
| 1471 | if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);\r |
| 1472 | menu_draw_end();\r |
| 1473 | }\r |
| 1474 | \r |
| 1475 | \r |
| 1476 | int menu_loop_tray(void)\r |
| 1477 | {\r |
| 1478 | int menu_sel = 0, menu_sel_max = 1;\r |
| 1479 | unsigned long inp = 0;\r |
| 1480 | char curr_path[MAX_PATH], *selfname;\r |
| 1481 | FILE *tstf;\r |
| 1482 | \r |
| 1483 | menu_gfx_prepare();\r |
| 1484 | \r |
| 1485 | if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r |
| 1486 | {\r |
| 1487 | fclose(tstf);\r |
| 1488 | strcpy(curr_path, currentConfig.lastRomFile);\r |
| 1489 | }\r |
| 1490 | else\r |
| 1491 | {\r |
| 1492 | getcwd(curr_path, MAX_PATH);\r |
| 1493 | }\r |
| 1494 | \r |
| 1495 | /* make sure action buttons are not pressed on entering menu */\r |
| 1496 | draw_menu_tray(menu_sel);\r |
| 1497 | while (Framework_PollGetButtons(1) & BTN_PLAY) Sleep(50);\r |
| 1498 | \r |
| 1499 | for (;;)\r |
| 1500 | {\r |
| 1501 | draw_menu_tray(menu_sel);\r |
| 1502 | inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY);\r |
| 1503 | if(inp & BTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
| 1504 | if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
| 1505 | if(inp & BTN_PLAY ) {\r |
| 1506 | switch (menu_sel) {\r |
| 1507 | case 0: // select image\r |
| 1508 | selfname = romsel_loop(curr_path);\r |
| 1509 | if (selfname) {\r |
| 1510 | int ret = -1, cd_type;\r |
| 1511 | cd_type = emu_cd_check(NULL);\r |
| 1512 | if (cd_type > 0)\r |
| 1513 | ret = Insert_CD(romFileName, cd_type == 2);\r |
| 1514 | if (ret != 0) {\r |
| 1515 | sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r |
| 1516 | lprintf("%s\n", menuErrorMsg);\r |
| 1517 | continue;\r |
| 1518 | }\r |
| 1519 | engineState = PGS_RestartRun;\r |
| 1520 | return 1;\r |
| 1521 | }\r |
| 1522 | break;\r |
| 1523 | case 1: // insert nothing\r |
| 1524 | engineState = PGS_RestartRun;\r |
| 1525 | return 0;\r |
| 1526 | }\r |
| 1527 | }\r |
| 1528 | menuErrorMsg[0] = 0; // clear error msg\r |
| 1529 | }\r |
| 1530 | }\r |
| 1531 | \r |
| 1532 | \r |