/* Get a keystroke from the user (or from a macro) and perform the * indicated command. A non-zero return value indicates a request to * change the current puzzle, the actual value being a delta. */ static int doturn(void) { switch (input()) { case ARROW_N: if (!movecursor(NORTH)) ding(); break; case ARROW_E: if (!movecursor(EAST)) ding(); break; case ARROW_S: if (!movecursor(SOUTH)) ding(); break; case ARROW_W: if (!movecursor(WEST)) ding(); break; case 'k': if (!shiftfromcurrblock(NORTH)) ding(); break; case 'l': if (!shiftfromcurrblock(EAST)) ding(); break; case 'j': if (!shiftfromcurrblock(SOUTH)) ding(); break; case 'h': if (!shiftfromcurrblock(WEST)) ding(); break; case 'K': if (!newmove(NORTH)) ding(); break; case 'L': if (!newmove(EAST)) ding(); break; case 'J': if (!newmove(SOUTH)) ding(); break; case 'H': if (!newmove(WEST)) ding(); break; case 'x': if (!undomove()) ding(); break; case 'z': if (!redomove()) ding(); break; case 'X': if (!undostep()) ding(); break; case 'Z': if (!redostep()) ding(); break; case 'R': initgamestate(); break; case 's': savestate(); break; case 'r': if (!restorestate()) ding(); break; case 'S': if (!partialsave()) ding(); break; case 'g': drawgoalscreen(); break; case '?': drawhelpscreen(); break; case '\f': break; case 'P': return -1; case 'N': return +1; case 'q': exit(0); case 'Q': exit(0); } return 0; }
//poll input for gui2 void gui2_poll() { static u32 old_joy1 = 0; u32 new_joy1,joy1 = 0; //hack to make sure key isnt held down if(joykeys[config.gui_keys[0]]) joy1 |= INPUT_MENU; if(joykeys[config.gui_keys[1]]) joy1 |= INPUT_LOADSTATE; if(joykeys[config.gui_keys[2]]) joy1 |= INPUT_SAVESTATE; if(joykeys[config.gui_keys[4]]) joy1 |= INPUT_SCREENSHOT; new_joy1 = joy1 & ~old_joy1; old_joy1 = joy1; //end hack if(new_joy1 & INPUT_MENU) { //dont let user exit gui if rom is not loaded if((pce == 0) || (pce->rom == 0)) return; gui_active ^= 1; memset(gui_draw_getscreen(),GUI_COLOR_OFFSET,gui_draw_getscreenpitch()*gui_draw_getscreenheight()); if(gui_active == 0) sound_play(); else { sound_pause(); video_copyscreen(); } } else if(gui_active) return; else if(new_joy1 & INPUT_LOADSTATE) loadstate(); else if(new_joy1 & INPUT_SAVESTATE) savestate(); #ifdef SCREENSHOTS else if(new_joy1 & INPUT_SCREENSHOT)screenshot(); #endif }
void startoutput(void) { if (! strnull(logfile)) logstr = stropen(logfile, "w!"); // always open file if given else logstr = (streq(strfile, "-") ? NULL : stdout); // don't hog stdout if (logstr != NULL) { fprintf(logstr, "\n%s\n", headline); // print headline, params fprintf(logstr, "\n%9s%9s%9s%9s", "nbody", "dtime", "nstatic", "eps"); #if !defined(QUICKSCAN) fprintf(logstr, "%9s", "theta"); #endif fprintf(logstr, "%9s%9s%9s\n", "usequad", "dtout", "tstop"); fprintf(logstr, "%9d%9.5f%9d%9.4f", nbody, dtime, nstatic, eps); #if !defined(QUICKSCAN) fprintf(logstr, "%9.2f", theta); #endif fprintf(logstr, "%9s%9.5f%9.4f\n", usequad ? "true" : "false", dtout, tstop); if (! strnull(options)) // print options, if any fprintf(logstr, "\n\toptions: %s\n", options); } if (! strnull(savefile)) // was state file given? savestate(savefile); // save initial data forcehead = FALSE; // require header printing fflush(NULL); // empty all output buffers // my code starts }
void savegame(char *name) { if(!m_classicsp) { conoutf("can only save classic sp games"); return; }; sprintf_sd(fn)("savegames/%s.csgz", name); savestate(fn); stop(); conoutf("wrote %s", fn); };
void record(char *name) { if(m_sp) { conoutf("cannot record singleplayer games"); return; }; int cn = getclientnum(); if(cn<0) return; sprintf_sd(fn)("demos/%s.cdgz", name); savestate(fn); gzputi(cn); conoutf("started recording demo to %s", fn); demorecording = true; starttime = lastmillis; ddamage = bdamage = 0; };
void state_save(int n) { int f; char *name; if (n < 0) n = saveslot; if (n < 0) n = 0; name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, n); if ((f = open(name, O_WRONLY|O_CREAT|O_TRUNC))) { savestate(f); close(f); } free(name); }
void state_save(int n) { FILE *f; char *name; if (n < 0) n = saveslot; if (n < 0) n = 0; name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, n); if ((f = fopen(name, "wb"))) { savestate(f); fclose(f); } free(name); }
output() { int nttot, nbavg, ncavg, k, bits; diagnostics(); /* compute std diagnostics */ nttot = n2bcalc + nbccalc; nbavg = (int) ((real) n2bcalc / (real) nfcalc); ncavg = (int) ((real) nbccalc / (real) nfcalc); printf("\n %10s%10s%10s%10s%10s%10s%10s\n", "tnow", "T+U", "T/U", "nttot", "nbavg", "ncavg", "cputime"); printf(" %10.3f%10.4f%10.4f%10d%10d%10d%10.2f\n\n", tnow, etot[0], etot[1]/etot[2], nttot, nbavg, ncavg, cputime()); printf("\t %10s", "cm pos"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[0][k]); printf("\n\t %10s", "cm vel"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[1][k]); printf("\n"); bits = 0; /* collect output bit flags */ if (minor_freqout > 0.0 && (minor_tout - 0.01/freq) <= tnow) { minor_tout += 1.0 / minor_freqout; bits |= TimeBit; } if (freqout > 0.0 && (tout - 0.01/freq) <= tnow) { tout += 1.0 / freqout; bits |= TimeBit | PhaseSpaceBit; if (scanopt(options, "mass") || firstmass) { bits |= MassBit; firstmass = FALSE; } if (scanopt(options, "phi")) bits |= PotentialBit; if (scanopt(options, "acc")) bits |= AccelerationBit; } if (bits != 0 && outstr != NULL) { /* output ready and able? */ put_snap(outstr, &bodytab, &nbody, &tnow, &bits); if (bits & PhaseSpaceBit) printf("\n\tparticle data written\n"); } if (*savefile) /* state file specified? */ savestate(savefile); /* save system data */ }
/* * do_file - load or save game data in the given file * * Returns true on success and false on failure. * * @desc is a brief user-provided description (<20 bytes) of the state. * If no description is provided, set @desc to NULL. * */ static bool do_file(char *path, char *desc, bool is_load) { char buf[200], desc_buf[20]; int fd, file_mode; /* set file mode */ file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT); /* attempt to open file descriptor here */ if ((fd = open(path, file_mode, 0666)) < 0) return false; /* load/save state */ if (is_load) { /* load description */ read(fd, desc_buf, 20); /* load state */ loadstate(fd); /* print out a status message so the user knows the state loaded */ snprintf(buf, 200, "Loaded state from \"%s\"", path); rb->splash(HZ * 1, buf); } else { /* build description buffer */ memset(desc_buf, 0, 20); if (desc) strlcpy(desc_buf, desc, 20); /* save state */ write(fd, desc_buf, 20); savestate(fd); } /* close file descriptor */ close(fd); /* return true (for success) */ return true; }
void output() { int k, bits; diagnostics(); printf("\n %12s%12s%12s%12s\n", "tnow", "T+U", "T/U", "cputime"); printf(" %12.3f%12.6f%12.4f%12.2f\n\n", tnow, etot[0], etot[1]/etot[2], cputime()); printf("\t %10s", "cm pos"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[0][k]); printf("\n\t %10s", "cm vel"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[1][k]); printf("\n"); bits = 0; if (minor_freqout > 0.0 && (minor_tout - 0.01/freq) <= tnow) { minor_tout += 1.0 / minor_freqout; bits |= TimeBit; } if (freqout > 0.0 && (tout - 0.01/freq) <= tnow) { tout += 1.0 / freqout; bits |= TimeBit | PhaseSpaceBit; if (firstmass || scanopt(options, "mass")) bits |= MassBit; firstmass = FALSE; if (scanopt(options, "phi")) bits |= PotentialBit; if (scanopt(options, "acc")) bits |= AccelerationBit; } if (bits != 0 && outstr != NULL) { put_snap(outstr, &bodytab, &nbody, &tnow, &bits); if (bits & PhaseSpaceBit) printf("\n\tparticle data written\n"); } if ((bits & PhaseSpaceBit) != 0 && quadstr != NULL) put_quadfield(quadstr); if (*savefile) /* state file specified? */ savestate(savefile); /* save system data */ }
void state_poll() { static const int savekeys[] = { SDL_SCANCODE_0, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9 }; if (keystate[SDL_SCANCODE_LCTRL]) { for (int i=0;i<10;i++) if (keyreleased[savekeys[i]]) savestate(slotname(i)); } else if (keystate[SDL_SCANCODE_LSHIFT]) { for (int i=0;i<10;i++) if (keyreleased[savekeys[i]]) loadstate(slotname(i)); } }
initoutput() { printf("\n%s\n\n", headline); /* print headline, params */ printf("%12s%12s%12s%12s\n", "nbody", "freq", "eps", "tol"); printf("%12d%12.2f%12.4f%12.4f\n\n", nbody, freq, eps, tol); printf("potential(5) = { %s ; %s ; %s }\n", getparam("potname"), getparam("potpars"), getparam("potfile")); if (nrigid != 0) printf(" // the first %d stars were held rigid\n",nrigid); if (*options) printf("\toptions: %s\n", options); if (*outfile) { /* output file specified? */ outstr = stropen(outfile, "w"); /* setup output stream */ put_history(outstr); /* write file history */ } else outstr = NULL; /* prevent binary output */ if (*savefile) /* state file specified? */ savestate(savefile); /* save inital data */ }
/* * do_file - load or save game data in the given file * * Returns true on success and false on failure. * * @desc is a brief user-provided description (<20 bytes) of the state. * If no description is provided, set @desc to NULL. * */ static bool do_file(char *path/*, char *desc*/, bool is_load) { int fd; //, file_mode; /* load/save state */ if (is_load) { fd = open(path, O_RDONLY ); if(!fd) { printf("Retry...\n"); fd = open(path, O_RDONLY ); if(!fd) return false; else printf("File opened!\n"); } else printf("File opened!\n"); /* load state */ loadstate(fd); printf("Loaded state from \"%s\"\n", path); } else { fd = open(path, O_WRONLY | O_CREAT ); if(!fd) { printf("Retry...\n"); fd = open(path, O_WRONLY | O_CREAT ); if(!fd) return false; else printf("File opened!\n"); } else printf("File opened!\n"); /* save state */ savestate(fd); } /* close file descriptor */ close(fd); /* return true (for success) */ return true; }
int savestate_f(Mach *m, uint slot) { FILE *fp; int ret; if (slot >= nelem(m->state)) return -EINVAL; fp = xfopen("%u.sav", "wb", slot); if (!fp) return -errno; ret = 0; memset(m->state[slot], 0, sizeof(m->state[slot])); savestate(m, m->state[slot]); if (fwrite(m->state[slot], 1, sizeof(m->state[slot]), fp) != sizeof(m->state[slot])) ret = -errno; fclose(fp); return ret; }
void initoutput() { if (! streq(headline, "")) { /* nontrivial headline? */ printf("\n%s\n", headline); /* headline log stream */ set_headline(headline); /* and save with history */ } if (*outfile) { /* output file given? */ outstr = stropen(outfile, "w"); /* setup out. stream */ put_history(outstr); } if (*quadfile) { /* field file given? */ quadstr = stropen(quadfile, "w"); /* setup out. stream */ put_history(quadstr); } printf("\n%12s%12s%12s%12s%12s%12s\n", "nbody", "freq", "eps_r", "eps_t", "mode", "tstop"); printf("%12d%12.4f%12.4f%12.4f%12d%12.2f\n\n", nbody, freq, eps1, eps2, mode, tstop); if (*options) printf("\toptions: %s\n\n", options); minor_tout = tout = tnow; /* schedule 1st outputs */ if (*savefile) /* restart file enabled? */ savestate(savefile); /* save inital state */ }
void end(scene* now, int retcode) { freeall(now); savestate(); pause(now, &s_skip); exit(retcode); }
int gbcSaveState(const char* filename) { savestate(filename); return 1; }
void output(void) { real teff; int n; string outtags[MaxBodyFields]; char namebuf[256]; struct stat buf; stream outstr; string streamtags[] = { MassTag, PosTag, VelTag, PhiTag, AccTag, NULL }; diagnostics(); // compute std diagnostics if (logstr != NULL) { //fprintf(logstr, "\n %8s%8s%8s%8s%8s%8s%8s%8s\n", //"time", "|T+U|", "T", "-U", "-T/U", "|Vcom|", "|Jtot|", "CPUtot"); //fprintf(logstr, " %8.3f%8.4f%8.4f%8.4f%8.5f%8.5f%8.4f%8.2f\n", // tnow, ABS(etot[0]), etot[1], -etot[2], -etot[1]/etot[2], // absv(cmvel), absv(amvec), cputime()); } teff = tnow + dtime/8; // anticipate slightly... if (! strnull(outfile) && teff >= tout) { // time for data output? n = 0; if (scanopt(outputs, PosTag)) // if listed in outputs outtags[n++] = PosTag; // include tag in list if (scanopt(outputs, VelTag)) outtags[n++] = VelTag; if (scanopt(outputs, MassTag) || (nstep == 0)) outtags[n++] = MassTag; if (scanopt(outputs, PhiTag)) outtags[n++] = PhiTag; // select potential data if (scanopt(outputs, AccTag)) outtags[n++] = AccTag; // select acceleration data outtags[n] = NULL; sprintf(namebuf, outfile, nstep); // make up output file name if (stat(namebuf, &buf) != 0) { // no output file exists? outstr = stropen(namebuf, "w"); // create & open for output put_history(outstr); // write out hiatory data } else // else file already exists outstr = stropen(namebuf, "a"); // reopen and append output put_snap(outstr, &bodytab, &nbody, &tnow, outtags); strclose(outstr); // close up output file if (logstr != NULL) fprintf(logstr, "\n\tdata output to file %s at time %f\n", namebuf, tnow); tout += dtout; // schedule next output } if (! strnull(strfile)) { if (! streq(strfile, "-")) { sprintf(namebuf, strfile, nstep); if (stat(namebuf, &buf) != 0) { outstr = stropen(namebuf, "w"); put_history(outstr); } else outstr = stropen(namebuf, "a"); } else outstr = stdout; put_snap(outstr, &bodytab, &nbody, &tnow, streamtags); fflush(outstr); if (! streq(strfile, "-")) strclose(outstr); } if (! strnull(savefile)) // was state file given? savestate(savefile); // save data for restart forcehead = FALSE; // insure headers print fflush(NULL); // empty all output buffers }
void finish(int n) { Rule_t* r; int i; /* * old error intercept */ if (!state.hold && (r = internal.error) && (r->property & (P_target|P_functional)) == P_target) { state.hold = null; if (n && error_info.errors && !state.compileonly && !state.interrupt) { if (r->status == NOTYET) maketop(r, P_dontcare|P_foreground, NiL); state.hold = 0; if (r->status == EXISTS) { r->status = NOTYET; return; } } } /* * children exit without cleanup */ if (getpid() != state.pid) _exit(n); unparse(0); switch (state.finish) { case 0: /* * disable listing and wait for any jobs to finish */ state.finish++; alarm(0); state.list = 0; message((-1, "%s cleanup", state.interrupt ? "interrupt" : n > 0 ? "error" : "normal")); complete(NiL, NiL, NiL, 0); /*FALLTHROUGH*/ case 1: /* * make the done trap */ state.finish++; if (!state.compileonly && (r = getrule(external.done))) maketop(r, P_dontcare, NiL); /*FALLTHROUGH*/ case 2: /* * make the makedone trap */ state.finish++; if (!state.compileonly && (r = getrule(external.makedone))) maketop(r, P_dontcare, NiL); /*FALLTHROUGH*/ case 3: /* * wait for any job(s) to finish */ state.finish++; complete(NiL, NiL, NiL, 0); /*FALLTHROUGH*/ case 4: /* * put all jobs in foreground and save state */ state.finish++; state.jobs = 0; savestate(); /*FALLTHROUGH*/ case 5: /* * clean up temporaries */ state.finish++; remtmp(1); /*FALLTHROUGH*/ case 6: /* * drop the coshell */ state.finish++; drop(); /*FALLTHROUGH*/ case 7: /* * dump */ state.finish++; if (state.test & 0x00002000) { Vmstat_t vs; vmstat(Vmheap, &vs); error(0, "vm region %zu segments %zu busy %zu:%zu free %zu:%zu", vs.extent, vs.n_seg, vs.n_busy, vs.s_busy, vs.n_free, vs.s_free); } dump(sfstdout, error_info.trace <= -14); /*FALLTHROUGH*/ case 8: /* * final output */ state.finish++; if (state.errors && state.keepgoing && !n) n = 1; if (state.mam.out) { if (state.mam.regress) sfprintf(state.mam.out, "%sinfo finish regression\n", state.mam.label); else if (state.mam.dynamic || *state.mam.label) sfprintf(state.mam.out, "%sinfo finish %lu %d\n", state.mam.label, CURTIME, n); } for (i = 0; i < elementsof(state.io); i++) if (state.io[i] != sfstdin && state.io[i] != sfstdout && state.io[i] != sfstderr) sfclose(state.io[i]); if (state.errors && state.keepgoing) error(2, "*** %d action%s failed", state.errors, state.errors == 1 ? null : "s"); message((-1, "%s exit", state.interrupt ? "interrupt" : n ? "error" : "normal")); break; } if (state.interrupt) { n = 3; signal(state.interrupt, SIG_DFL); kill(getpid(), state.interrupt); pause(); } exit(n); }
//run 1 NES frame with FF/REW control void play() { static int framecount=0; static int fcount = 0; int forward = 0; int backward = 0; do_cheat(); global_playcount++; if(global_playcount > 6) global_playcount = 0; if(nifi_stat) __emuflags &= ~(FASTFORWARD | REWIND); //when nifi enabled, disable the fastforward & rewind. forward = __emuflags & FASTFORWARD; backward = __emuflags & REWIND; if(backward) { // for rolling back... a nice function? swiWaitForVBlank(); framecount++; if(framecount>2) { framecount-=3; if(firstsave!=lastsave) { lastsave--; if(lastsave<0) lastsave=maxsaves-1; loadstate(freemem_start+SAVESTATESIZE*lastsave); EMU_Run(); } } } else { if(__emuflags & SOFTRENDER) { if(!(forward) && (fcount >= debuginfo[6] && fcount - debuginfo[6] < 10) ) // disable VBlank to speed up emulation. swiWaitForVBlank(); } else { if(!(forward)) { if(__emuflags & PALSYNC) { if(__emuflags & (SOFTRENDER | PALTIMING)) __emuflags ^= PALSYNC; if(REG_VCOUNT < 190) { swiWaitForVBlank(); } } else { if((!(__emuflags & ALLPIXEL)) || (all_pix_start != 0)) swiWaitForVBlank(); } } } if(!(__emuflags & PALTIMING && global_playcount == 6)) { EMU_Run(); //run a frame framecount++; if(framecount>8) { //save state every 9th frame framecount-=9; savestate(freemem_start+SAVESTATESIZE*lastsave); lastsave++; if(lastsave>=maxsaves) lastsave=0; if(lastsave==firstsave) { firstsave++; if(firstsave>=maxsaves) firstsave=0; } } } else { if((__emuflags & PALTIMING) && (__emuflags & ALLPIXEL) && !(__emuflags & SOFTRENDER)) swiWaitForVBlank(); } } if(__emuflags & SOFTRENDER) { __emuflags &= ~AUTOSRAM; __rendercount++; if(SOFT_FRAMESKIP <= 1 ||__rendercount == 1) { if(__emuflags & ALLPIXEL) render_sub(); render_all(); } if(!(forward) && __rendercount >= SOFT_FRAMESKIP) __rendercount = 0; if((forward) && __rendercount > 16) __rendercount = 0; } else if(__emuflags & ALLPIXEL) { render_sub(); } fcount++; if(fcount > 59) fcount = 0; __emuflags &= ~(FASTFORWARD | REWIND); }
void handle_key(void){ if (NeedsPoll) poll_keyboard(); if (key[syskeys[0]] || key[KEY_ESC]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[0]] || key[KEY_ESC]); key_done=1; } if (key[syskeys[1]]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); mute_audio(); mute_voice(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } } while ((!key[syskeys[1]]) && (!key[KEY_ESC]) && (!key[syskeys[0]])); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); init_sound_stream(); } if (key[syskeys[5]]) { if (savestate(app_data.statefile)==0) { display_msg("Savefile saved.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[5]]); } /* LOAD STATE */ if (key[syskeys[6]]) { int stateError; if ((stateError=loadstate(app_data.statefile))==0) { display_msg("Savefile loaded.",5); } else if (stateError>=199) { if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5); else if (stateError==200+ROM_O2) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5); else if (stateError==200+ROM_G7400) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5); else if (stateError==200+ROM_C52) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5); else if (stateError==200+ROM_JOPAC) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5); else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[6]]); } if (key[syskeys[2]]) key_debug=1; if (key[syskeys[3]]) { init_cpu(); init_roms(); init_vpp(); clearscr(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[3]]); } /* SET HIGHSCORE */ if (key[syskeys[7]]) { set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore); } if (key[syskeys[4]]) { BITMAP *bmp; PALETTE pal; char *p; static char name[1024]; static int scshot_counter = 0; if (strlen(app_data.scshot)>0){ if ((p=strchr(app_data.scshot,'@'))) { *p = 0; sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1); *p = '@'; } else { strcpy(name, app_data.scshot); } get_palette(pal); bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H); save_bitmap(name, bmp, pal); destroy_bitmap(bmp); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[4]]); } } // switch joystick if (key[syskeys[8]]) { joyswitch = joyswitch ? 0 : 1; set_defjoykeys(0,joyswitch); set_defjoykeys(1,joyswitch ? 0 : 1); int tmp = app_data.stick[0]; app_data.stick[0] = app_data.stick[1]; app_data.stick[1] = tmp; do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[8]]); } if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } }
int main(int argc, const char *argv[]) { ez::ezOptionParser opt; opt.overview = "GenEmu -- Sega Genesis Emulator"; opt.syntax = "genemu [OPTIONS] rom"; opt.add("",0,0,0,"Display usage instructions.", "-h", "--help"); opt.add("",0,-1,',',"Apply Game Genie codes [format=ABCD-EFGH]", "--gamegenie", "--gg"); opt.add("",0,1,0,"Force console type [accepted values: PAL or NTSC]", "--mode", "--type"); opt.add("",0,-1,',',"Make screenshots on the specified frames and exit", "--screenshots"); opt.add("",0,1,0,"Load from saved state", "--load"); opt.parse(argc, argv); if (opt.isSet("-h")) { std::string usage; opt.getUsage(usage, 120); std::cout << usage; return 0; } std::vector<std::string*> args; if (opt.firstArgs.size() >= 2) { strcpy(romname, opt.firstArgs[1]->c_str()); } else if (opt.lastArgs.size() >= 1) strcpy(romname, opt.lastArgs[0]->c_str()); else { std::cerr << "ERROR: no ROM specified\n"; return 2; } int romsize; if (strstr(romname, ".smd")) romsize = load_smd(romname); else romsize = load_bin(romname); mem_init(romsize); #if 0 uint16_t checksum = 0; for (int i=0;i<(romsize-512)/2;i++) checksum += m68k_read_memory_16(512+i*2); assert(checksum == m68k_read_memory_16(0x18e)); #endif #if 1 char buf[256]; int pc = 0; strcpy(buf, argv[1]); strcat(buf, ".asm"); FILE *f = fopen(buf, "w"); while (pc < romsize) { int oplen = m68k_disassemble(buf, pc, M68K_CPU_TYPE_68000); fprintf(f, "%06x\t%s\n", pc, buf); pc += oplen; } fclose(f); #endif if (opt.isSet("--mode")) { std::string mode; opt.get("--mode")->getString(mode); if (mode == "PAL") { VERSION_PAL = 1; std::cerr << "Forced mode: PAL\n"; } else if (mode == "NTSC") { VERSION_PAL = 0; std::cerr << "Forced mode: NTSC\n"; } else { std::cerr << "ERROR: invalid mode: " << mode << std::endl; return 2; } } std::vector<int> ss_frames; int ss_idx = 0; hw_init(YM2612_FREQ, VERSION_PAL ? 50 : 60); if (!opt.isSet("--screenshots")) { hw_enable_video(true); hw_enable_audio(true); gfx_enable(true); } else { opt.get("--screenshots")->getInts(ss_frames); } CPU_M68K.init(); CPU_Z80.init(); MASTER_CLOCK = 0; CPU_M68K.reset(); VDP.reset(); if (opt.isSet("--load")) { std::string sn; opt.get("--load")->getString(sn); loadstate(sn.c_str()); } while (hw_poll()) { if (ss_idx < ss_frames.size() && framecounter == ss_frames[ss_idx]) { gfx_enable(true); } int numscanlines = VDP.num_scanlines(); uint8_t *screen; int pitch; hw_beginframe(&screen, &pitch); int16_t *audio; int nsamples; hw_beginaudio(&audio, &nsamples); int audio_index = 0; int audio_step = (nsamples << 16) / numscanlines; for (int sl=0;sl<numscanlines;++sl) { CPU_M68K.run(MASTER_CLOCK + VDP_CYCLES_PER_LINE); CPU_Z80 .run(MASTER_CLOCK + VDP_CYCLES_PER_LINE); vdp_scanline(screen); screen += pitch; int prev_index = audio_index; audio_index += audio_step; YM2612Update(audio + ((prev_index+0x8000)>>16)*2, (audio_index-prev_index+0x8000)>>16); MASTER_CLOCK += VDP_CYCLES_PER_LINE; } hw_endaudio(); hw_endframe(); if (framecounter == 100 && opt.isSet("--gamegenie")) { std::vector<std::string> codes; opt.get("--gamegenie")->getStrings(codes); for (int i=0;i<codes.size();++i) mem_apply_gamegenie(codes[i].c_str()); } if (ss_idx < ss_frames.size() && framecounter == ss_frames[ss_idx]) { static char ssname[2048]; sprintf(ssname, "%s.%d.%s.bmp", romname, framecounter, (VERSION_PAL ? "PAL" : "NTSC")); std::cerr << "Saving screenshot " << ssname << std::endl; hw_save_screenshot(ssname); sprintf(ssname, "%s.%d.%s.gs", romname, framecounter, (VERSION_PAL ? "PAL" : "NTSC")); savestate(ssname); ++ss_idx; if (ss_idx == ss_frames.size()) break; } ++framecounter; state_poll(); } #if 0 checksum = 0; for (int i=0;i<(romsize-512)/2;i++) checksum += m68k_read_memory_16(512+i*2); assert(checksum == m68k_read_memory_16(0x18e)); #endif #if 0 { char buf[256]; int pc = 0xffffee00; FILE *f = fopen(buf, "w"); while (pc <= 0xffffef00) { int oplen = m68k_disassemble(buf, pc, M68K_CPU_TYPE_68000); fprintf(stdout, "%06x\t%s\n", pc, buf); pc += oplen; } fclose(f); } #endif return 0; }
void conv(register FILE *fp, int baseline) { register FILE *gfp = NULL; /* input file pointer */ register int done = 0; /* flag to remember if finished */ register ELT *e; /* current element pointer */ ELT *PICTURE; /* whole picture data base pointer */ double temp; /* temporary calculating area */ /* POINT ptr; */ /* coordinates of a point to pass to `mov' */ /* routine */ int flyback; /* flag `want to end up at the top of the */ /* picture?' */ int compat; /* test character after .GE or .GF */ initpic(); /* set defaults, ranges, etc. */ strcpy(GScommand, inputline); /* save `.GS' line for later */ do { done = !doinput(fp); /* test for EOF */ flyback = (*c3 == 'F'); /* and .GE or .GF */ compat = (compatibility_flag || *c4 == '\n' || *c4 == ' ' || *c4 == '\0'); done |= (*c1 == '.' && *c2 == 'G' && (*c3 == 'E' || flyback) && compat); if (done) { if (setdefault) savestate(); if (!gremlinfile[0]) { if (!setdefault) error("at line %1: no picture filename.\n", baseline); return; } char *path; gfp = macro_path.open_file(gremlinfile, &path); if (!gfp) return; PICTURE = DBRead(gfp); /* read picture file */ fclose(gfp); a_delete path; if (DBNullelt(PICTURE)) return; /* If a request is made to make the */ /* picture fit into a specific area, */ /* set the scale to do that. */ if (stipple == (char *) NULL) /* if user forgot stipple */ if (has_polygon(PICTURE)) /* and picture has a polygon */ stipple = (char *)DEFSTIPPLE; /* then set the default */ if ((temp = bottompoint - toppoint) < 0.1) temp = 0.1; temp = (height != 0.0) ? height / (temp * SCREENtoINCH) : BIG; if ((troffscale = rightpoint - leftpoint) < 0.1) troffscale = 0.1; troffscale = (width != 0.0) ? width / (troffscale * SCREENtoINCH) : BIG; if (temp == BIG && troffscale == BIG) troffscale = xscale; else { if (temp < troffscale) troffscale = temp; } /* here, troffscale is the */ /* picture's scaling factor */ if (pointscale) { register int i; /* do pointscaling here, when */ /* scale is known, before output */ for (i = 0; i < SIZES; i++) tsize[i] = (int) (troffscale * (double) tsize[i] + 0.5); } /* change to device units */ troffscale *= SCREENtoINCH * res; /* from screen units */ ytop = (int) (toppoint * troffscale); /* calculate integer */ ybottom = (int) (bottompoint * troffscale); /* versions of the */ xleft = (int) (leftpoint * troffscale); /* picture limits */ xright = (int) (rightpoint * troffscale); /* save stuff in number registers, */ /* register g1 = picture width and */ /* register g2 = picture height, */ /* set vertical spacing, no fill, */ /* and break (to make sure picture */ /* starts on left), and put out the */ /* user's `.GS' line. */ printf(".br\n" ".nr g1 %du\n" ".nr g2 %du\n" "%s" ".nr g3 \\n(.f\n" ".nr g4 \\n(.s\n" "\\0\n" ".sp -1\n", xright - xleft, ybottom - ytop, GScommand); if (stipple) /* stipple requested for this picture */ printf(".st %s\n", stipple); lastx = xleft; /* note where we are (upper left */ lastyline = lasty = ytop; /* corner of the picture) */ /* Just dump everything in the order it appears. * * If -s command-line option, traverse picture twice: First time, * print only the interiors of filled polygons (as borderless * polygons). Second time, print the outline as series of line * segments. This way, postprocessors that overwrite rather than * merge picture elements (such as Postscript) can still have text and * graphics on a shaded background. */ /* if (sflag) */ if (!sflag) { /* changing the default for filled polygons */ e = PICTURE; polyfill = FILL; while (!DBNullelt(e)) { printf(".mk\n"); if (e->type == POLYGON) HGPrintElt(e, baseline); printf(".rt\n"); lastx = xleft; lastyline = lasty = ytop; e = DBNextElt(e); } } e = PICTURE; /* polyfill = !sflag ? BOTH : OUTLINE; */ polyfill = sflag ? BOTH : OUTLINE; /* changing the default */ while (!DBNullelt(e)) { printf(".mk\n"); HGPrintElt(e, baseline); printf(".rt\n"); lastx = xleft; lastyline = lasty = ytop; e = DBNextElt(e); } /* decide where to end picture */ /* I changed everything here. I always use the combination .mk and */ /* .rt so once finished I just space down the heigth of the picture */ /* that is \n(g2u */ if (flyback) { /* end picture at upper left */ /* ptr.x = leftpoint; ptr.y = toppoint; */ } else { /* end picture at lower left */ /* ptr.x = leftpoint; ptr.y = bottompoint; */ printf(".sp \\n(g2u\n"); } /* tmove(&ptr); */ /* restore default line parameters */ /* restore everything to the way it was before the .GS, then put */ /* out the `.GE' line from user */ /* printf("\\D't %du'\\D's %du'\n", DEFTHICK, DEFSTYLE); */ /* groff doesn't understand the \Ds command */ printf("\\D't %du'\n", DEFTHICK); if (flyback) /* make sure we end up at top of */ printf(".sp -1\n"); /* picture if `flying back' */ if (stipple) /* restore stipple to previous */ printf(".st\n"); printf(".br\n" ".ft \\n(g3\n" ".ps \\n(g4\n" "%s", inputline); } else interpret(inputline); /* take commands from the input file */ } while (!done); }
static void click_savestate() { savestate(); joykeys[config.gui_keys[0]] = 1; }
/* The main function */ int main(int argc, char const *argv[]) { DBusError dbe; struct state_st state; /* Parse the command line. */ if (argv[1] && argv[1][0] == 'd') { /* Debug dump */ assert(loadstate(&state)); dumpop(&state); return 0; } else if (argv[1] && argv[1][0] == 'r') { /* Repair the GA state. */ unsigned i; assert(loadstate(&state)); for (i = 0; i < G_N_ELEMENTS(state.pop); i++) { /* Ensure that genes are bounded. */ struct genome_st *g = &state.pop[i]; if (g->window > TIMEOUT) g->window = TIMEOUT; else if (g->window < 3) g->window = 3; if (g->threshold <= 0) g->threshold = 0.1; else if (g->threshold >= 1) g->threshold = 0.9; } savestate(&state); return 0; } /* Redirect stdio. */ assert((stderr = fopen(FNAME".err", "a")) != NULL); assert((stdout = fopen(FNAME".log", "a")) != NULL); /* Initialize infrastructure for the test. */ Loop = g_main_loop_new(0, 0); DBus = dbus_bus_get(DBUS_BUS_SESSION, NULL); dbus_connection_setup_with_g_main(DBus, g_main_context_default()); dbus_error_init(&dbe); dbus_bus_add_match(DBus, "type='method_call',interface='com.nokia.HildonDesktop.AppMgr',member='LaunchApplication'", &dbe); assert(!dbus_error_is_set(&dbe)); Dpy = XOpenDisplay(NULL); assert(Dpy != NULL); if (!loadstate(&state)) initpop(&state); /* Test */ eval(&state.pop[state.idx++]); if (state.idx >= G_N_ELEMENTS(state.pop)) generation(&state); /* Done and reboot. */ savestate(&state); if (argv[1]) system("echo reboot | sudo gainroot"); return 0; } /* main */
int menu_state(int save){ char **statebody=NULL; char* name; int i, flags,ret, del=0,l; #ifndef OHBOY_FILE_STAT_NOT_AVAILABLE /* Not all platforms implement stat()/fstat() */ struct stat fstat; time_t time; char *tstr; #endif char *savedir; char *savename; char *saveprefix; FILE *f; int sizeof_slots=0; while (slots[sizeof_slots] != NULL) sizeof_slots++; statebody = malloc(sizeof_slots * sizeof(char*)); /* FIXME check for NULL return from malloc */ savedir = rc_getstr("savedir"); savename = rc_getstr("savename"); saveprefix = malloc(strlen(savedir) + strlen(savename) + 2); sprintf(saveprefix, "%s%s%s", savedir, DIRSEP, savename); dialog_begin(save?"Save State":"Load State",rom.name); for(i=0; i<sizeof_slots; i++){ name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, i); #ifndef OHBOY_FILE_STAT_NOT_AVAILABLE /* if the file exists lookup the timestamp */ if(!stat(name,&fstat)){ time = fstat.st_mtime; tstr = ctime(&time); l = strlen(tstr); statebody[i] = malloc(l); strcpy(statebody[i],tstr); statebody[i][l-1]=0; #else /* check if the file exists */ if(f=fopen(name,"rb")){ fclose(f); statebody[i] = (char*)not_emptyslot; #endif /* OHBOY_FILE_STAT_NOT_AVAILABLE */ flags = FIELD_SELECTABLE; } else { statebody[i] = (char*)emptyslot; flags = save ? FIELD_SELECTABLE : 0; } dialog_text(slots[i],statebody[i],flags); free(name); } if(ret=dialog_end()){ name = malloc(strlen(saveprefix) + 5); sprintf(name, "%s.%03d", saveprefix, ret-1); if(save){ if(f=fopen(name,"wb")){ savestate(f); fclose(f); } }else{ if(f=fopen(name,"rb")){ loadstate(f); fclose(f); vram_dirty(); pal_dirty(); sound_dirty(); mem_updatemap(); } } free(name); } for(i=0; i<sizeof_slots; i++) if(statebody[i] != emptyslot && statebody[i] != not_emptyslot) free(statebody[i]); free(saveprefix); return ret; } #define GBPAL_COUNT 27 struct pal_s{ char name[16]; unsigned int dmg_bgp[4]; unsigned int dmg_wndp[4]; unsigned int dmg_obp0[4]; unsigned int dmg_obp1[4]; }gbpal[GBPAL_COUNT] = { { .name = "Default", .dmg_bgp = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}, .dmg_wndp = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}, .dmg_obp0 = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}, .dmg_obp1 = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C} },{//Grey Palette .name = "Grey", .dmg_bgp = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //BG .dmg_wndp = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //WIN .dmg_obp0 = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //OB0 .dmg_obp1 = { 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 } //OB1 },{//Realistic Palette .name = "DMG",