void gb_destroy() { if(rom_get_loaded()) { //jfile_free(env_game_thread,rom_image); //rom_image = NULL; rom_init(); } }
void set_gb_type() { if (rom_get_loaded()){ switch(setting.gb_type){ case 0: if(org_gbtype==1){ rom_get_info()->gb_type = 2; lcd_set_mpal(setting.gb_palette); }else if(org_gbtype == 2){ rom_get_info()->gb_type = 2; lcd_set_mpal(PAL_SGB); }else if(org_gbtype == 3){ rom_get_info()->gb_type = 3; lcd_set_mpal(PAL_SGB); } break; case 1: rom_get_info()->gb_type = 1; lcd_set_mpal(PAL_MONOCHROME); break; case 2: rom_get_info()->gb_type = 2; if(sgb_mode) lcd_set_mpal(PAL_SGB); else lcd_set_mpal(setting.gb_palette); break; case 3: rom_get_info()->gb_type = 3; lcd_set_mpal(setting.gb_palette); break; case 4: rom_get_info()->gb_type = 4; lcd_set_mpal(setting.gb_palette); break; } if(rom_get_info()->gb_type>=3 && org_gbtype==3) now_gb_mode = 3; else if(rom_get_info()->gb_type==2 && sgb_mode) now_gb_mode = 2; else now_gb_mode = 1; } }
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 gb_run() { int cmd = 0; if (rom_get_loaded()){ if (g_regs.LCDC&0x80){ // LCDC 起動時 g_regs.LY=(g_regs.LY+1)%154; g_regs.STAT&=0xF8; if (g_regs.LYC==g_regs.LY){ g_regs.STAT|=4; if (g_regs.STAT&0x40) cpu_irq(INT_LCDC); } if (g_regs.LY==0){ // renderer_refresh(); cmd |= 1; /* if (gbSkip){ render_screen(vframe); // now_frame=0; } else now_frame++;*/ lcd_clear_win_count(); // skip=skip_buf; } if (g_regs.LY>=144){ // VBlank 期間中 g_regs.STAT|=1; if (g_regs.LY==144){ cpu_exec(72); cpu_irq(INT_VBLANK); if (g_regs.STAT&0x10) cpu_irq(INT_LCDC); cpu_exec(456-80); } else if (g_regs.LY==153){ cpu_exec(80); g_regs.LY=0; cpu_exec(456-80); // 前のラインのかなり早目から0になるようだ。 g_regs.LY=153; } else cpu_exec(456); } else{ // VBlank 期間外 g_regs.STAT|=2; if (g_regs.STAT&0x20) cpu_irq(INT_LCDC); cpu_exec(80); // state=2 g_regs.STAT|=3; cpu_exec(169); // state=3 if (dma_executing){ // HBlank DMA if (b_dma_first){ dma_dest_bank=vram_bank; if (dma_src<0x4000) dma_src_bank=get_rom(); else if (dma_src<0x8000) dma_src_bank=mbc_get_rom(); else if (dma_src>=0xA000&&dma_src<0xC000) dma_src_bank=mbc_get_sram()-0xA000; else if (dma_src>=0xC000&&dma_src<0xD000) dma_src_bank=ram-0xC000; else if (dma_src>=0xD000&&dma_src<0xE000) dma_src_bank=ram_bank-0xD000; else dma_src_bank=NULL; b_dma_first=false; } memcpy(dma_dest_bank+(dma_dest&0x1ff0),dma_src_bank+dma_src,16); // fprintf(cpu_file,"%03d : dma exec %04X -> %04X rest %d\n",g_regs.LY,cpu_dma_src,cpu_dma_dest,cpu_dma_rest); dma_src+=16; dma_src&=0xfff0; dma_dest+=16; dma_dest&=0xfff0; dma_rest--; if (!dma_rest) dma_executing=false; // cpu_total_clock+=207*(cpu_speed?2:1); // cpu_sys_clock+=207*(cpu_speed?2:1); // cpu_div_clock+=207*(cpu_speed?2:1); // g_regs.STAT|=3; if (!gbSkip && !sgb_mask) lcd_render(vframe,g_regs.LY); g_regs.STAT&=0xfc; cpu_exec(207); // state=3 } else{ /* if (lcd_get_sprite_count()){ if (lcd_get_sprite_count()>=10){ cpu_exec(129); if ((g_regs.STAT&0x08)) cpu_irq(INT_LCDC); g_regs.STAT&=0xfc; if (now_frame>=skip) lcd_render(vframe,g_regs.LY); cpu_exec(78); // state=0 } else{ cpu_exec(129*lcd_get_sprite_count()/10); if ((g_regs.STAT&0x08)) cpu_irq(INT_LCDC); g_regs.STAT&=0xfc; if (now_frame>=skip) lcd_render(vframe,g_regs.LY); cpu_exec(207-(129*lcd_get_sprite_count()/10)); // state=0 } } else{ */ g_regs.STAT&=0xfc; if (!gbSkip && !sgb_mask) lcd_render(vframe,g_regs.LY); if ((g_regs.STAT&0x08)) cpu_irq(INT_LCDC); cpu_exec(207); // state=0 // } } } } else{ // LCDC 停止時 g_regs.LY=0; // g_regs.LY=(g_regs.LY+1)%154; re_render++; if (re_render>=154) { // memset(vframe,0xff,(160+16)*144*2); if (!gbSkip) memset(vframe, 0xff, VFRAME_SIZE); // renderer_refresh(); cmd |= 1; /* if (!gbSkip) { // render_screen(vframe); now_frame=0; } else now_frame++;*/ lcd_clear_win_count(); re_render=0; } g_regs.STAT&=0xF8; cpu_exec(456); } // if (!menuConfig.sound.perfectSynchro) // sound_update_gb(line); } return cmd; }
//force: 1 to always write, 0 to only if changed int machine_manage_sram(int mode, int force) { char name[MAX_PATH]; VIRTUAL_FILE *fd; int ramsize = 0; if(menuConfig.file.filename[0] == '\0') return; pspGetStateName(name, STATE_SRAM); switch(mode) { case SRAM_SAVE: if (gblMachineType == EM_SMS) { //Find out if something was written to the SRAM (which is zero initialized) /* int i, modified = 0; for (i=0;i<0x8000;i++) { if (((u8*)cart.sram)[i] != 0) modified = 1; } if (!modified) break;*/ //Determine if something has changed (using the CRC) uLong crc = crc32(0L, Z_NULL, 0); crc = crc32(crc, cart.sram, 0x8000); if (sram_crc == crc) break; sram_crc = crc; } else if (gblMachineType == EM_GBC) { if (!(rom_get_loaded() && rom_has_battery())) break; //Determine if something has changed (using the CRC) const int sram_tbl[]={1,1,1,4,16,8}; int sram_size = 0x2000 * sram_tbl[rom_get_info()->ram_size]; if (rom_get_info()->cart_type>=0x0f && rom_get_info()->cart_type<=0x13) { int tmp = renderer_get_timer_state(); memcpy(get_sram() + sram_size, &tmp, sizeof(int)); sram_size += sizeof(int); } uLong crc = crc32(0L, Z_NULL, 0); crc = crc32(crc, get_sram(), sram_size); if (sram_crc == crc) break; sram_crc = crc; } if (BatteryWarning("Your battery is low!\nDo you want to save the SRAM contents?\n(This might corrupt your Memory Stick if your PSP stops during this operation.)")) { fd = VirtualFileOpen(name, 0, VF_GZFILE, VF_O_WRITE); if (fd) { if (gblMachineType == EM_SMS) VirtualFileWrite(cart.sram, 0x8000, 1, fd); else if (gblMachineType == EM_GBC) gb_save_sram(fd, get_sram(), rom_get_info()->ram_size); VirtualFileClose(fd); } } break; case SRAM_LOAD: fd = VirtualFileOpen(name, 0, VF_GZFILE, VF_O_READ); if (gblMachineType == EM_SMS) { if(fd) { sms.save = 1; VirtualFileRead(cart.sram, 0x8000, 1, fd); ramsize = 0x8000; } else /* No SRAM file, so initialize memory */ memset(cart.sram, 0x00, 0x8000); sram_crc = crc32(0L, Z_NULL, 0); sram_crc = crc32(sram_crc, cart.sram, 0x8000); } else if (gblMachineType == EM_GBC) { if (fd) ramsize = gb_load_sram(fd, sram_space, sizeof(sram_space)); sram_crc = crc32(0L, Z_NULL, 0); sram_crc = crc32(sram_crc, sram_space, ramsize); } if (fd) VirtualFileClose(fd); break; } return ramsize; }