void snes_main_loop() { if(!romprops.ramsize_bytes)return; if(initloop) { saveram_crc_old = calc_sram_crc(SRAM_SAVE_ADDR, romprops.ramsize_bytes); initloop=0; } saveram_crc = calc_sram_crc(SRAM_SAVE_ADDR, romprops.ramsize_bytes); sram_valid = sram_reliable(); if(crc_valid && sram_valid) { if(saveram_crc != saveram_crc_old) { if(samecount) { diffcount=1; } else { diffcount++; didnotsave++; } samecount=0; } if(saveram_crc == saveram_crc_old) { samecount++; } if(diffcount>=1 && samecount==5) { printf("SaveRAM CRC: 0x%04lx; saving\n", saveram_crc); writeled(1); save_sram(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR); writeled(0); didnotsave=0; } if(didnotsave>50) { printf("periodic save (sram contents keep changing...)\n"); diffcount=0; writeled(1); save_sram(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR); didnotsave=0; writeled(0); } saveram_crc_old = saveram_crc; } printf("crc=%lx crc_valid=%d sram_valid=%d diffcount=%ld samecount=%ld, didnotsave=%ld\n", saveram_crc, crc_valid, sram_valid, diffcount, samecount, didnotsave); }
static void genesis_leave() { if (gensettings.saves & SAVES_SRAM) { /* save SRAM */ save_sram(sramname); } else{ if(WindowPrompt("Save", "Save SRAM?", "Save", "Don't Save")){ save_sram(sramname); } } if (gensettings.saves & SAVES_STATES) { save_state(statename); } else{ if(WindowPrompt("Save", "Save Save State?", "Save", "Don't Save")){ save_state(statename); } } system_shutdown(); // audio_shutdown(); error_shutdown(); free(cart.rom); }
void prepare_reset() { snes_reset(1); delay_ms(1); if(romprops.ramsize_bytes && fpga_test() == FPGA_TEST_TOKEN) { writeled(1); save_sram(file_lfn, romprops.ramsize_bytes, SRAM_SAVE_ADDR); writeled(0); } rdyled(1); readled(1); writeled(1); snes_reset(0); while(get_snes_reset()); snes_reset(1); fpga_dspx_reset(1); delay_ms(200); }
void save_config(char * path) { char tmp[PATH_MAX]; if(!rom_get_loaded()) { return; } else { if(rom_has_battery()) { save_sram(get_sram(), rom_get_info()->ram_size,SramPath); } } memcpy(setting.custom_palette,m_pal16[PAL_CUSTOM_LOCAL], sizeof(word)*3*4); //__android_log_print(ANDROID_LOG_DEBUG, "org.rin", "path in save_config: %s",path); int i; for(i=0; i<sizeof(SETTING); i++){ if ( *((byte*)&setting+i) != *((byte*)&tmpsetting+i) ) break; } if (i>=sizeof(SETTING)) return; jfile fd = jfopen(env_game_thread, path, JF_MODE_NEW | JF_MODE_OVERWRITE | JF_MODE_WRITE, NULL, 0); if(!fd) { return; } jfwrite(env_game_thread, fd, &setting, sizeof(setting)); jfclose(env_game_thread, fd); tmpsetting = setting; }
int main(int args, char *argv[]) { char *save_file; ines_file *nes_rom; /* Print NOW everything :D */ #ifdef _MSC_VER setvbuf(stdout,NULL,_IONBF,0); setvbuf(stderr,NULL,_IONBF,0); #else setbuf(stdout,NULL); setbuf(stderr,NULL); #endif /* i18n stuff */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); /* Parse command line options */ initialize_configuration(); switch ( parse_options(args, argv) ) { case -1: usage(stderr,argv); exit(EXIT_FAILURE); case 0: exit(EXIT_SUCCESS); default: break; } load_user_configuration(); /* Initialize static data */ initialize_palette(); initialize_instruction_set(); initialize_playback(); initialize_apu(); initialize_cpu(); initialize_ppu(); initialize_clock(); initialize_pads(); /* Read the ines file and get all the ROM/VROM */ config.rom_file = argv[optind]; nes_rom = check_ines_file(config.rom_file); map_rom_memory(nes_rom); save_file = load_sram(config.rom_file); /* Init the graphics engine */ init_screen(); init_gui(); /* Main execution loop */ main_loop(); /* After finishing the emulation, save the SRAM if necessary */ save_sram(save_file); free(save_file); /* Free all the used resources */ mapper->end_mapper(); end_screen(); end_gui(); end_ppu(); end_cpu(); end_apu(); end_playback(); free_ines_file(nes_rom); return 0; }
int main(int _argc, char **_argv) { int framecount=0; int sramcount=0; argc=_argc, argv=_argv; defaultExceptionHandler(); fifoSendValue32(FIFO_USER_06, (u32)ipc_region); DS_init(); //DS init. #ifndef ROM_EMBEDED active_interface = fatInitDefault(); //init file operations to your external card. initNiFi(); #endif EMU_Init(); //emulation init. irqSet(IRQ_VBLANK, vblankinterrupt); irqEnable(IRQ_HBLANK); //fifoSetValue32Handler(FIFO_USER_06, aliveinterrupt, 0); //fifoSetValue32Handler(FIFO_USER_05, reg4015interrupt, 0); IPC_ALIVE = 0; IPC_APUIRQ = 0; IPC_REG4015 = 0; consoleinit(); //init subscreen to show chars. crcinit(); //init the crc table. //pre-alocate memory.... //IPC_FILES = malloc(MAXFILES * 256 + MAXFILES * 4); //IPC_ROM = malloc(ROM_MAX_SIZE); #ifndef ROM_EMBEDED if(!bootext()) { //chdir("/"); do_rommenu(); //show a menu selecting rom files. } #else do_romebd(); #endif //__emuflags |= PALSYNC; while(1) { // main loop to do the emulation framecount++; if(__emuflags & PALTIMING && global_playcount == 0) { framecount--; } if(debuginfo[VBLS]>59) { debuginfo[VBLS]-=60; debuginfo[1] = debuginfo[0]; debuginfo[0] = 0; debuginfo[FPS]=framecount; framecount=0; } scanKeys(); IPC_KEYS = keysCurrent(); //change nsf states if(__emuflags & NSFFILE) { static int oldkey = 0; int keydown = IPC_KEYS & (~oldkey); oldkey = IPC_KEYS; if(keydown & KEY_LEFT) { if(__nsfsongno == 0) { __nsfsongno = nsfheader.TotalSong-1; } else { __nsfsongno--; } } if(keydown & KEY_RIGHT) { if(++__nsfsongno > nsfheader.TotalSong-1) { __nsfsongno = 0; } } if(keydown & KEY_UP) { __nsfplay = 1; __nsfinit = 1; } if(keydown & KEY_DOWN) { __nsfplay = 0; Sound_reset(); } } do_shortcuts(); if((__emuflags & AUTOSRAM)) { if(__emuflags & NEEDSRAM) { sramcount = 1; __emuflags&=~NEEDSRAM; } if(sramcount > 0) sramcount++; if(sramcount > 120) { //need auto save for sram. sramcount = 0; save_sram(); } } touch_update(); // do menu functions. do_menu(); //do control menu. do_multi(); if(nifi_stat == 0 || nifi_stat >= 5) play(); //emulate a frame of the NES game. else swiWaitForVBlank(); } }
int state_save(char* path) { size_t size = gb_save_state(NULL); byte *buf = (byte*)malloc(size); if (!buf) { return 0; } gb_save_state(buf); jfile fd = jfopen(env_game_thread, path, JF_MODE_WRITE | JF_MODE_OVERWRITE | JF_MODE_NEW, NULL, 0); if(fd) { jfwrite(env_game_thread, fd, buf, size); jfclose(env_game_thread, fd); } free(buf); char tmp[PATH_MAX]; if(rom_has_battery()) { sprintf(tmp, "%s.sram.gz", RomPath); save_sram(get_sram(), rom_get_info()->ram_size,tmp); } return size; //char temp[PATH_MAX]; //int ret; /* if (0)//setting.compress) { sprintf(temp,"%s.gz",path); FILE * fd = fopen(temp, "w"); if (fd<0){ free(buf); return 0; } ret = gzCreate(fd, buf, size); fclose(fd); free(buf); if (!ret) { remove(temp); return 0; } } else { FILE * fd = fopen(path, "w"); if (fd<0) { free(buf); return 0; } ret = fwrite(buf, size,1 ,fd); fclose(fd); free(buf); if (ret!=1){ remove(path); return 0; }else{ //strcat(path, ".gz"); //remove_file(path); } return ret; }*/ }
static void cmd_saveraw(void) { uint32_t address = parse_unsigned(0,16777216,16); uint32_t length = parse_unsigned(0,16777216,16); save_sram((uint8_t*)curchar, length, address); }