void rc_dokey(int key, int st) { if (!keybind[key]) return; if (keybind[key][0] != '+' && !st) return; if (st) rc_command(keybind[key]); else { keybind[key][0] = '-'; rc_command(keybind[key]); keybind[key][0] = '+'; } }
extern "C" DLL_EXPORT void CDECL_CALL EmuMain(char *rom) { int i; char *s; /* If we have special perms, drop them ASAP! */ vid_preinit(); init_exports(); s = strdup("."); sys_sanitize(s); sys_initpath(s); for (i = 0; defaultconfig[i]; i++) rc_command(defaultconfig[i]); /* FIXME - make interface modules responsible for atexit() */ atexit(shutdown); catch_signals(); vid_init(); pcm_init(); rom = strdup(rom); sys_sanitize(rom); loader_init(rom); emu_reset(); emu_run(); }
int rc_sourcefile(char *filename) { FILE *f; char *name; char line[256], *p; name = path_search(filename, "r", rcpath); f = fopen(name, "r"); if (!f) return -1; for (;;) { if (feof(f)) break; fgets(line, sizeof line, f); if ((p = strpbrk(line, "#\r\n"))) *p = 0; rc_command(line); } fclose(f); return 0; }
int main(int argc, char *argv[]) { int i; char *opt, *arg, *cmd, *s, *rom = 0; /* Avoid initializing video if we don't have to */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--help")) help(base(argv[0])); else if (!strcmp(argv[i], "--version")) version(base(argv[0])); else if (!strcmp(argv[i], "--copying")) copying(); else if (!strcmp(argv[i], "--bind")) i += 2; else if (!strcmp(argv[i], "--source")) i++; else if (!strcmp(argv[i], "--showvars")) { show_exports(); exit(0); } else if (argv[i][0] == '-' && argv[i][1] == '-'); else if (argv[i][0] == '-' && argv[i][1]); else rom = argv[i]; } if (!rom) usage(base(argv[0])); /* If we have special perms, drop them ASAP! */ vid_preinit(); init_exports(); s = strdup(argv[0]); sys_sanitize(s); sys_initpath(s); for (i = 0; defaultconfig[i]; i++) rc_command(defaultconfig[i]); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--bind")) { if (i + 2 >= argc) die("missing arguments to bind\n"); cmd = malloc(strlen(argv[i+1]) + strlen(argv[i+2]) + 9); sprintf(cmd, "bind %s \"%s\"", argv[i+1], argv[i+2]); rc_command(cmd); free(cmd); i += 2; } else if (!strcmp(argv[i], "--source")) { if (i + 1 >= argc) die("missing argument to source\n"); cmd = malloc(strlen(argv[i+1]) + 6); sprintf(cmd, "source %s", argv[++i]); rc_command(cmd); free(cmd); } else if (!strncmp(argv[i], "--no-", 5)) { opt = strdup(argv[i]+5); while ((s = strchr(opt, '-'))) *s = '_'; cmd = malloc(strlen(opt) + 7); sprintf(cmd, "set %s 0", opt); rc_command(cmd); free(cmd); free(opt); } else if (argv[i][0] == '-' && argv[i][1] == '-') { opt = strdup(argv[i]+2); if ((s = strchr(opt, '='))) { *s = 0; arg = s+1; } else arg = "1"; while ((s = strchr(opt, '-'))) *s = '_'; while ((s = strchr(arg, ','))) *s = ' '; cmd = malloc(strlen(opt) + strlen(arg) + 6); sprintf(cmd, "set %s %s", opt, arg); rc_command(cmd); free(cmd); free(opt); } /* short options not yet implemented */ else if (argv[i][0] == '-' && argv[i][1]); } /* FIXME - make interface modules responsible for atexit() */ atexit(shutdown); catch_signals(); vid_init(); pcm_init(); rom = strdup(rom); sys_sanitize(rom); loader_init(rom); emu_reset(); emu_run(); /* never reached */ return 0; }
int menu_controls(){ int ret=0, i=0, btna=2, btnb=1, btnx=2, btny=1, btnl=3, btnr=4; FILE *file; btna = rc_getint("button_a"); btnb = rc_getint("button_b"); btnx = rc_getint("button_x"); btny = rc_getint("button_y"); btnl = rc_getint("button_l"); btnr = rc_getint("button_r"); start: dialog_begin("Controls",NULL); #if defined(CAANOO) dialog_text("Caanoo","Gameboy",0); /* 1 */ #endif #if defined(WIZ) dialog_text("Wiz","Gameboy",0); /* 1 */ #endif #if defined(DINGOO_NATIVE) dialog_text("Dingoo","Gameboy",0); /* 1 */ #endif #if defined(GP2X_ONLY) dialog_text("GP2X","Gameboy",0); /* 1 */ #endif dialog_text(NULL,NULL,0); /* 2 */ dialog_option("Button A",lbutton_a,&btna); /* 3 */ dialog_option("Button B",lbutton_b,&btnb); /* 4 */ dialog_option("Button X",lbutton_x,&btnx); /* 5 */ dialog_option("Button Y",lbutton_y,&btny); /* 6 */ dialog_option("Button L",lbutton_l,&btnl); /* 7 */ dialog_option("Button R",lbutton_r,&btnr); /* 8 */ dialog_text(NULL,NULL,0); /* 9 */ dialog_text("Apply",NULL,FIELD_SELECTABLE); /* 10 */ dialog_text("Apply & Save",NULL,FIELD_SELECTABLE); /* 11 */ dialog_text("Cancel",NULL,FIELD_SELECTABLE); /* 12 */ switch(ret=dialog_end()){ case 12: /* Cancel */ return ret; break; case 10: /* Apply */ case 11: /* Apply & Save */ sprintf(config[0],"#KEY BINDINGS#"); sprintf(config[1],"set button_a %i",btna); sprintf(config[2],"set button_b %i",btnb); sprintf(config[3],"set button_x %i",btnx); sprintf(config[4],"set button_y %i",btny); sprintf(config[5],"set button_l %i",btnl); sprintf(config[6],"set button_r %i",btnr); #if defined(CAANOO) if (btna == 0) {sprintf(config[7],"unbind joy0");} if (btnb == 0) {sprintf(config[8],"unbind joy2");} if (btnx == 0) {sprintf(config[9],"unbind joy1");} if (btny == 0) {sprintf(config[10],"unbind joy3");} if (btnl == 0) {sprintf(config[11],"unbind joy4");} if (btnr == 0) {sprintf(config[12],"unbind joy5");} if (btna == 1) {sprintf(config[7],"bind joy0 +a");} if (btnb == 1) {sprintf(config[8],"bind joy2 +a");} if (btnx == 1) {sprintf(config[9],"bind joy1 +a");} if (btny == 1) {sprintf(config[10],"bind joy3 +a");} if (btnl == 1) {sprintf(config[11],"bind joy4 +a");} if (btnr == 1) {sprintf(config[12],"bind joy5 +a");} if (btna == 2) {sprintf(config[7],"bind joy0 +b");} if (btnb == 2) {sprintf(config[8],"bind joy2 +b");} if (btnx == 2) {sprintf(config[9],"bind joy1 +b");} if (btny == 2) {sprintf(config[10],"bind joy3 +b");} if (btnl == 2) {sprintf(config[11],"bind joy4 +b");} if (btnr == 2) {sprintf(config[12],"bind joy5 +b");} if (btna == 3) {sprintf(config[7],"bind joy0 +select");} if (btnb == 3) {sprintf(config[8],"bind joy2 +select");} if (btnx == 3) {sprintf(config[9],"bind joy1 +select");} if (btny == 3) {sprintf(config[10],"bind joy3 +select");} if (btnl == 3) {sprintf(config[11],"bind joy4 +select");} if (btnr == 3) {sprintf(config[12],"bind joy5 +select");} if (btna == 4) {sprintf(config[7],"bind joy0 +start");} if (btnb == 4) {sprintf(config[8],"bind joy2 +start");} if (btnx == 4) {sprintf(config[9],"bind joy1 +start");} if (btny == 4) {sprintf(config[10],"bind joy3 +start");} if (btnl == 4) {sprintf(config[11],"bind joy4 +start");} if (btnr == 4) {sprintf(config[12],"bind joy5 +start");} if (btna == 5) {sprintf(config[7],"bind joy0 reset");} if (btnb == 5) {sprintf(config[8],"bind joy2 reset");} if (btnx == 5) {sprintf(config[9],"bind joy1 reset");} if (btny == 5) {sprintf(config[10],"bind joy3 reset");} if (btnl == 5) {sprintf(config[11],"bind joy4 reset");} if (btnr == 5) {sprintf(config[12],"bind joy5 reset");} if (btna == 6) {sprintf(config[7],"bind joy0 quit");} if (btnb == 6) {sprintf(config[8],"bind joy2 quit");} if (btnx == 6) {sprintf(config[9],"bind joy1 quit");} if (btny == 6) {sprintf(config[10],"bind joy3 quit");} if (btnl == 6) {sprintf(config[11],"bind joy4 quit");} if (btnr == 6) {sprintf(config[12],"bind joy5 quit");} #endif #if defined(DINGOO_NATIVE) if (btna == 0) {sprintf(config[7],"unbind ctrl");} if (btnb == 0) {sprintf(config[8],"unbind alt");} if (btnx == 0) {sprintf(config[9],"unbind space");} if (btny == 0) {sprintf(config[10],"unbind shift");} if (btnl == 0) {sprintf(config[11],"unbind tab");} if (btnr == 0) {sprintf(config[12],"unbind backspace");} if (btna == 1) {sprintf(config[7],"bind ctrl +a");} if (btnb == 1) {sprintf(config[8],"bind alt +a");} if (btnx == 1) {sprintf(config[9],"bind space +a");} if (btny == 1) {sprintf(config[10],"bind shift +a");} if (btnl == 1) {sprintf(config[11],"bind tab +a");} if (btnr == 1) {sprintf(config[12],"bind backspace +a");} if (btna == 2) {sprintf(config[7],"bind ctrl +b");} if (btnb == 2) {sprintf(config[8],"bind alt +b");} if (btnx == 2) {sprintf(config[9],"bind space +b");} if (btny == 2) {sprintf(config[10],"bind shift +b");} if (btnl == 2) {sprintf(config[11],"bind tab +b");} if (btnr == 2) {sprintf(config[12],"bind backspace +b");} if (btna == 3) {sprintf(config[7],"bind ctrl +select");} if (btnb == 3) {sprintf(config[8],"bind alt +select");} if (btnx == 3) {sprintf(config[9],"bind space +select");} if (btny == 3) {sprintf(config[10],"bind shift +select");} if (btnl == 3) {sprintf(config[11],"bind tab +select");} if (btnr == 3) {sprintf(config[12],"bind backspace +select");} if (btna == 4) {sprintf(config[7],"bind ctrl +start");} if (btnb == 4) {sprintf(config[8],"bind alt +start");} if (btnx == 4) {sprintf(config[9],"bind space +start");} if (btny == 4) {sprintf(config[10],"bind shift +start");} if (btnl == 4) {sprintf(config[11],"bind tab +start");} if (btnr == 4) {sprintf(config[12],"bind backspace +start");} if (btna == 5) {sprintf(config[7],"bind ctrl reset");} if (btnb == 5) {sprintf(config[8],"bind alt reset");} if (btnx == 5) {sprintf(config[9],"bind space reset");} if (btny == 5) {sprintf(config[10],"bind shift reset");} if (btnl == 5) {sprintf(config[11],"bind tab reset");} if (btnr == 5) {sprintf(config[12],"bind backspace reset");} if (btna == 6) {sprintf(config[7],"bind ctrl quit");} if (btnb == 6) {sprintf(config[8],"bind alt quit");} if (btnx == 6) {sprintf(config[9],"bind space quit");} if (btny == 6) {sprintf(config[10],"bind shift quit");} if (btnl == 6) {sprintf(config[11],"bind tab quit");} if (btnr == 6) {sprintf(config[12],"bind backspace quit");} #endif #if defined(WIZ) || defined(GP2X_ONLY) if (btna == 0) {sprintf(config[7],"unbind joy12");} if (btnb == 0) {sprintf(config[8],"unbind joy13");} if (btnx == 0) {sprintf(config[9],"unbind joy14");} if (btny == 0) {sprintf(config[10],"unbind joy15");} if (btnl == 0) {sprintf(config[11],"unbind joy10");} if (btnr == 0) {sprintf(config[12],"unbind joy11");} if (btna == 1) {sprintf(config[7],"bind joy12 +a");} if (btnb == 1) {sprintf(config[8],"bind joy13 +a");} if (btnx == 1) {sprintf(config[9],"bind joy14 +a");} if (btny == 1) {sprintf(config[10],"bind joy15 +a");} if (btnl == 1) {sprintf(config[11],"bind joy10 +a");} if (btnr == 1) {sprintf(config[12],"bind joy11 +a");} if (btna == 2) {sprintf(config[7],"bind joy12 +b");} if (btnb == 2) {sprintf(config[8],"bind joy13 +b");} if (btnx == 2) {sprintf(config[9],"bind joy14 +b");} if (btny == 2) {sprintf(config[10],"bind joy15 +b");} if (btnl == 2) {sprintf(config[11],"bind joy10 +b");} if (btnr == 2) {sprintf(config[12],"bind joy11 +b");} if (btna == 3) {sprintf(config[7],"bind joy12 +select");} if (btnb == 3) {sprintf(config[8],"bind joy13 +select");} if (btnx == 3) {sprintf(config[9],"bind joy14 +select");} if (btny == 3) {sprintf(config[10],"bind joy15 +select");} if (btnl == 3) {sprintf(config[11],"bind joy10 +select");} if (btnr == 3) {sprintf(config[12],"bind joy11 +select");} if (btna == 4) {sprintf(config[7],"bind joy12 +start");} if (btnb == 4) {sprintf(config[8],"bind joy13 +start");} if (btnx == 4) {sprintf(config[9],"bind joy14 +start");} if (btny == 4) {sprintf(config[10],"bind joy15 +start");} if (btnl == 4) {sprintf(config[11],"bind joy10 +start");} if (btnr == 4) {sprintf(config[12],"bind joy11 +start");} if (btna == 5) {sprintf(config[7],"bind joy12 reset");} if (btnb == 5) {sprintf(config[8],"bind joy13 reset");} if (btnx == 5) {sprintf(config[9],"bind joy14 reset");} if (btny == 5) {sprintf(config[10],"bind joy15 reset");} if (btnl == 5) {sprintf(config[11],"bind joy10 reset");} if (btnr == 5) {sprintf(config[12],"bind joy11 reset");} if (btna == 6) {sprintf(config[7],"bind joy12 quit");} if (btnb == 6) {sprintf(config[8],"bind joy13 quit");} if (btnx == 6) {sprintf(config[9],"bind joy14 quit");} if (btny == 6) {sprintf(config[10],"bind joy15 quit");} if (btnl == 6) {sprintf(config[11],"bind joy10 quit");} if (btnr == 6) {sprintf(config[12],"bind joy11 quit");} #endif for(i=0; i<13; i++) rc_command(config[i]); pal_dirty(); if (ret == 11){ /* Apply & Save */ file = fopen("bindings.rc","w"); for(i=0; i<13; i++){ fputs(config[i],file); fputs("\n",file); } fclose(file); } break; } return ret; }
int menu_options(){ struct pal_s *palp=0; int pal=0, skip=0, ret=0, cfilter=0, sfps=0, upscale=0, speed=0, i=0; char *tmp=0, *romdir=0; FILE *file; #ifdef DINGOO_NATIVE /* ** 100Mhz once caused Dingoo A320 MIPS to hang, ** when 100Mhz worked BW GB (Adjustris) game was running at 32 fps (versus 60 at 200Mhz). ** 150Mhz has never worked on my Dingoo A320. */ uintptr_t dingoo_clock_speeds[] = { 200000000, 250000000, 300000000, 336000000, 360000000, 400000000 /* , 430000000 Should not be needed */ }; /* ** under-under clock option is for GB games. ** GB games can often be ran under the already ** underclocked Dingoo speed of 336Mhz */ bool dingoo_clock_change_result; uintptr_t tempCore=336000000; /* default Dingoo A320 clock speed */ uintptr_t tempMemory=112000000; /* default Dingoo A320 memory speed */ cpu_clock_get(&tempCore, &tempMemory); #endif /* DINGOO_NATIVE */ pal = findpal(); cfilter = rc_getint("colorfilter"); if(cfilter && !rc_getint("filterdmg")) cfilter = 2; upscale = rc_getint("upscaler"); skip = rc_getint("frameskip")+1; sfps = rc_getint("showfps"); #ifdef DINGOO_NATIVE speed = 0; #else speed = rc_getint("cpuspeed")/50 - 4; #endif /* DINGOO_NATIVE */ if(speed<0) speed = 0; if(speed>11) speed = 11; romdir = rc_getstr("romdir"); romdir = romdir ? strdup(romdir) : strdup("."); start: dialog_begin("Options",NULL); dialog_option("Mono Palette",lpalettes,&pal); /* 1 */ dialog_option("Color Filter",lcolorfilter,&cfilter); /* 2 */ dialog_option("Upscaler",lupscaler,&upscale); /* 3 */ dialog_option("Frameskip",lframeskip,&skip); /* 4 */ dialog_option("Show FPS",lsdl_showfps,&sfps); /* 5 */ #if defined(WIZ) || defined(DINGOO_NATIVE) dialog_option("Clock Speed",lclockspeeds,&speed); /* 6 */ #else dialog_text("Clock Speed","Default",0); /* 6 */ #endif dialog_text("Rom Path",romdir,FIELD_SELECTABLE); /* 7 */ #ifdef GNUBOY_HARDWARE_VOLUME dialog_option("Volume", volume_levels, &volume_hardware); /* 8 */ /* this is not the OSD volume.. */ #else dialog_text("Volume", "Default", 0); /* 8 */ /* this is not the OSD volume.. */ #endif /* GNBOY_HARDWARE_VOLUME */ dialog_text(NULL,NULL,0); /* 9 */ dialog_text("Apply",NULL,FIELD_SELECTABLE); /* 10 */ dialog_text("Apply & Save",NULL,FIELD_SELECTABLE); /* 11 */ dialog_text("Cancel",NULL,FIELD_SELECTABLE); /* 12 */ switch(ret=dialog_end()){ case 7: /* "Rom Path" romdir */ tmp = menu_requestdir("Select Rom Directory",romdir); if(tmp){ free(romdir); romdir = tmp; } goto start; case 12: /* Cancel */ return ret; break; case 10: /* Apply */ case 11: /* Apply & Save */ #ifdef GNUBOY_HARDWARE_VOLUME pcm_volume(volume_hardware * 10); #endif /* GNBOY_HARDWARE_VOLUME */ palp = &gbpal[pal]; if(speed) { #ifdef DINGOO_NATIVE /* ** For now do NOT plug in into settings system, current ** (Wiz) speed system is focused on multiples of 50Mhz. ** Dingoo default clock speed is 336Mhz (CPU certified for ** 360, 433MHz is supposed to be possible). ** Only set clock speed if changed in options each and ** everytime - do not use config file */ --speed; /* check menu response is withing the preset array range/size */ if (speed > (sizeof(dingoo_clock_speeds)/sizeof(uintptr_t) - 1) ) speed = 0; tempCore = dingoo_clock_speeds[speed]; dingoo_clock_change_result = cpu_clock_set(tempCore); tempCore=tempMemory=0; cpu_clock_get(&tempCore, &tempMemory); /* currently unused */ /* TODO display clock speed next to on screen FPS indicator */ #endif /* DINGOO_NATIVE */ speed = speed*50 + 200; } sprintf(config[0],"set dmg_bgp 0x%.6x 0x%.6x 0x%.6x 0x%.6x", palp->dmg_bgp[0], palp->dmg_bgp[1], palp->dmg_bgp[2], palp->dmg_bgp[3]); sprintf(config[1],"set dmg_wndp 0x%.6x 0x%.6x 0x%.6x 0x%.6x",palp->dmg_wndp[0],palp->dmg_wndp[1],palp->dmg_wndp[2],palp->dmg_wndp[3]); sprintf(config[2],"set dmg_obp0 0x%.6x 0x%.6x 0x%.6x 0x%.6x",palp->dmg_obp0[0],palp->dmg_obp0[1],palp->dmg_obp0[2],palp->dmg_obp0[3]); sprintf(config[3],"set dmg_obp1 0x%.6x 0x%.6x 0x%.6x 0x%.6x",palp->dmg_obp1[0],palp->dmg_obp1[1],palp->dmg_obp1[2],palp->dmg_obp1[3]); sprintf(config[4],"set colorfilter %i",cfilter!=0); sprintf(config[5],"set filterdmg %i",cfilter==1); sprintf(config[6],"set upscaler %i",upscale); sprintf(config[7],"set frameskip %i",skip-1); sprintf(config[8],"set showfps %i",sfps); sprintf(config[9],"set cpuspeed %i",speed); #ifdef DINGOO_NATIVE /* FIXME Windows too..... if (DIRSEP_CHAR == '\\').... */ { char tmp_path[PATH_MAX]; char *dest, *src; dest = &tmp_path[0]; src = romdir; /* escape the path seperator (should escape other things too.) */ while(*dest = *src++) { if (*dest == DIRSEP_CHAR) { dest++; *dest = DIRSEP_CHAR; } dest++; } sprintf(config[10], "set romdir \"%s\"", tmp_path); scaler_init(0); } #else sprintf(config[10],"set romdir \"%s\"",romdir); scaler_init(0); #endif /* DINGOO_NATIVE */ for(i=0; i<11; i++) rc_command(config[i]); pal_dirty(); if (ret == 11){ /* Apply & Save */ file = fopen("ohboy.rc","w"); for(i=0; i<11; i++){ fputs(config[i],file); fputs("\n",file); } fclose(file); } break; } free(romdir); return ret; }
int menu(){ char *dir; int mexit=0; static char *loadrom; int old_upscale = 0, new_upscale = 0; old_upscale = rc_getint("upscaler"); gui_begin(); while(!mexit){ dialog_begin(rom.name,"ohBoy"); dialog_text("Back to Game",NULL,FIELD_SELECTABLE); dialog_text("Load State",NULL,FIELD_SELECTABLE); dialog_text("Save State",NULL,FIELD_SELECTABLE); dialog_text("Reset Game",NULL,FIELD_SELECTABLE); dialog_text(NULL,NULL,0); dialog_text("Load ROM",NULL,FIELD_SELECTABLE); dialog_text("Options",NULL,FIELD_SELECTABLE); dialog_text("Controls",NULL,FIELD_SELECTABLE); dialog_text("About",NULL,FIELD_SELECTABLE); dialog_text("Quit","",FIELD_SELECTABLE); #ifdef DINGOO_NATIVE dialog_text(NULL, NULL, 0); /* blank line */ dialog_text("Menu:", NULL, 0); dialog_text(" Slide Power", NULL, 0); #endif /* DINGOO_NATIVE */ switch(dialog_end()){ case 2: if(menu_state(0)) mexit=1; break; case 3: if(menu_state(1)) mexit=1; break; case 4: rc_command("reset"); mexit=1; break; case 6: dir = rc_getstr("romdir"); if(loadrom = menu_requestfile(NULL,"Select Rom",dir,"gb;gbc;zip")) { loader_unload(); ohb_loadrom(loadrom); mexit=1; } break; case 7: if(menu_options()) mexit=1; break; case 8: if(menu_controls()) mexit=1; break; case 9: if(menu_about()) mexit=0; break; case 10: exit(0); break; default: mexit=1; break; } } new_upscale = rc_getint("upscaler"); if (old_upscale != new_upscale) scaler_init(new_upscale); gui_end(); return 0; }