/* Loader proper */ t_stat sim_load (FILE *fi, char *cptr, char *fnam, int flag) { int rombase; int c1, c2, i; if (flag == 1) /* don't dump */ return SCPE_ARG; /* this assumes a HDT style ROM, where the first 2 bytes refer to the * actual word start of the ROM, e.g. with PDQ-3 the HDT ROM has 0xf401 * as the first word, so it will load at word address 0xf400, and 0xfc68 * will be preset to 0xf401 */ c1 = fgetc(fi); c2 = fgetc(fi); rombase = c1 + c2 * 256; rom_write(rombase & 0xfffe, rombase); reg_fc68 = rombase; i = 0; while (!feof(fi) && i<0x1ff) { c1 = fgetc(fi); c2 = fgetc(fi); rom_write(rombase+i, (uint16)(c1 + c2*256)); i++; } reg_romsize = i; /* preset the cpu_serial number from ROM, may be overwritten manually for special purposes */ rom_read(rombase+i-1, ®_cpuserial); return SCPE_OK; }
static BYTE REGPARM1 read_super_9(WORD addr) { if (spet_ramen) { return (mem_ram + 0x10000)[(spet_bank << 12) | (addr & 0x0fff)]; } return rom_read(addr); }
int getchar(void) { unsigned char c = '\0'; int i; for (;;) { i = apbus ? apcall_read(1, &c, 1) : rom_read(1, &c, 1); if (i == 1) break; if (i != -2 && i != 0) return -1; } return c; }
static void launch_rom(GtkWidget *widget, gpointer data) { char *name, *name_aux; name_aux = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data)); name = malloc(strlen(name_aux)+1); strcpy(name, name_aux); gtk_widget_destroy(GTK_WIDGET(data)); printf("Emulateur Nintendo64 (mupen64) version : %s\n", VERSION); if (rom_read(name)) { if(rom) { free(rom); rom = NULL; } if(ROM_HEADER) { free(ROM_HEADER); ROM_HEADER = NULL; } free(name); file_selection_launched = 0; return; } // checking 'debugger' option #ifdef DBG if (GTK_TOGGLE_BUTTON(button_debug)->active == 1) { init_debugger(); } #endif // creating emulation thread if (pthread_create(&thread_n64, NULL, main_thread, NULL)) printf("error: problem with thread_n64 creation.\n"); else printf("creation of the emulation thread... PID=%ld\n", thread_n64); }
void bootxx(uint32_t d4, uint32_t d5, uint32_t d6, uint32_t d7) { int fd, blk, bs; int ctlr, unit, part, type; int i; int bootdev = d6; char *addr; char devname[32]; printf("NetBSD/news68k Primary Boot\n"); DPRINTF("\n"); DPRINTF("d4 %x\n", d4); DPRINTF("d5 %x (%s)\n", d5, (char *)d5); DPRINTF("d6 %x\n", d6); DPRINTF("d7 %x\n", d7); DPRINTF("block_size = %d\n", bbinfo.bbi_block_size); DPRINTF("block_count = %d\n", bbinfo.bbi_block_count); DPRINTF("entry_point = %p\n", entry_point); /* sd(ctlr, lun, part, bus?, host) */ ctlr = BOOTDEV_CTLR(bootdev); unit = BOOTDEV_UNIT(bootdev); part = BOOTDEV_PART(bootdev); type = BOOTDEV_TYPE(bootdev); if (devs[type] == NULL) { printf("unknown bootdev (0x%x)\n", bootdev); return; } snprintf(devname, sizeof(devname), "%s(%d,%d,%d)", devs[type], ctlr, unit, part); fd = rom_open(devname, 0); if (fd == -1) { printf("cannot open %s\n", devname); return; } addr = (char *)entry_point; bs = bbinfo.bbi_block_size; DPRINTF("reading block:"); for (i = 0; i < bbinfo.bbi_block_count; i++) { blk = bbinfo.bbi_block_table[i]; DPRINTF(" %d", blk); rom_lseek(fd, blk * 512, 0); rom_read(fd, addr, bs); addr += bs; } DPRINTF(" done\n"); rom_close(fd); (*entry_point)(d4, d5, d6, d7); DPRINTF("bootxx returned?\n"); }
int loadROM(fileBrowser_file* rom){ int ret = 0; savestates_job = 0; //clear all pending save states // First, if there's already a loaded ROM if(hasLoadedROM){ // Unload it, and deinit everything cpu_deinit(); eepromWritten = FALSE; mempakWritten = FALSE; sramWritten = FALSE; flashramWritten = FALSE; romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); closeDLL_RSP(); closeDLL_input(); closeDLL_audio(); closeDLL_gfx(); ROMCache_deinit(); free_memory(); #ifndef HW_RVL ARAM_manager_deinit(); #endif } format_mempacks(); reset_flashram(); init_eeprom(); hasLoadedROM = TRUE; #ifndef HW_RVL ARAM_manager_init(); #endif #ifdef USE_TLB_CACHE TLBCache_init(); #else tlb_mem2_init(); #endif //romFile_init(rom); ret = rom_read(rom); if(ret){ // Something failed while trying to read the ROM. hasLoadedROM = FALSE; return ret; } // Init everything for this ROM init_memory(); gfx_set_fb(xfb[0], xfb[1]); if (screenMode == SCREENMODE_16x9_PILLARBOX) gfx_set_window( 78, 0, 483, 480); else gfx_set_window( 0, 0, 640, 480); gfx_info_init(); audio_info_init(); // control_info_init(); rsp_info_init(); romOpen_gfx(); // gfx_set_fb(xfb[0], xfb[1]); romOpen_audio(); romOpen_input(); cpu_init(); if(autoSave==AUTOSAVE_ENABLE) { switch (nativeSaveDevice) { case NATIVESAVEDEVICE_SD: case NATIVESAVEDEVICE_USB: // Adjust saveFile pointers saveFile_dir = (nativeSaveDevice==NATIVESAVEDEVICE_SD) ? &saveDir_libfat_Default:&saveDir_libfat_USB; saveFile_readFile = fileBrowser_libfat_readFile; saveFile_writeFile = fileBrowser_libfat_writeFile; saveFile_init = fileBrowser_libfat_init; saveFile_deinit = fileBrowser_libfat_deinit; break; case NATIVESAVEDEVICE_CARDA: case NATIVESAVEDEVICE_CARDB: // Adjust saveFile pointers saveFile_dir = (nativeSaveDevice==NATIVESAVEDEVICE_CARDA) ? &saveDir_CARD_SlotA:&saveDir_CARD_SlotB; saveFile_readFile = fileBrowser_CARD_readFile; saveFile_writeFile = fileBrowser_CARD_writeFile; saveFile_init = fileBrowser_CARD_init; saveFile_deinit = fileBrowser_CARD_deinit; break; } // Try loading everything int result = 0; saveFile_init(saveFile_dir); result += loadEeprom(saveFile_dir); result += loadSram(saveFile_dir); result += loadMempak(saveFile_dir); result += loadFlashram(saveFile_dir); saveFile_deinit(saveFile_dir); switch (nativeSaveDevice) { case NATIVESAVEDEVICE_SD: // if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from SD card"); if (result) autoSaveLoaded = NATIVESAVEDEVICE_SD; break; case NATIVESAVEDEVICE_USB: // if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from USB device"); if (result) autoSaveLoaded = NATIVESAVEDEVICE_USB; break; case NATIVESAVEDEVICE_CARDA: // if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from memcard in slot A"); if (result) autoSaveLoaded = NATIVESAVEDEVICE_CARDA; break; case NATIVESAVEDEVICE_CARDB: // if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from memcard in slot B"); if (result) autoSaveLoaded = NATIVESAVEDEVICE_CARDB; break; } } return 0; }
int main (int argc, char *argv[]) { char c; char plugins[100][100], s[20]; char romfile[PATH_MAX]; int old_i, i, i1, i2, i3, i4; int p, p_fullscreen = 0, p_emumode = 0, p_gfx = 0, p_audio = 0, p_input = 0, p_rsp = 0, p_help = 0, p_error = 0; int p_emumode_value=1, fileloaded = 0, p_interactive = 0; int true = 1; char *buffer, *buffer2; #if defined (__linux__) if (signal(SIGTERM, sigterm_handler) == SIG_ERR) printf("Warning: Couldn't register SIGTERM signal handler!\n"); #endif //Set working dir #ifdef WITH_HOME { char temp[PATH_MAX], orig[PATH_MAX]; FILE *src, *dest; struct dirent *entry; DIR *dir; strcpy(g_WorkingDir, getenv("HOME")); strcat(g_WorkingDir, "/.mupen64/"); strcpy(cwd, g_WorkingDir); mkdir(g_WorkingDir, 0700); strcpy(temp, g_WorkingDir); strcat(temp, "mupen64.ini"); dest = fopen(temp, "rb"); if (dest == NULL) { unsigned char byte; dest = fopen(temp, "wb"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/mupen64.ini"); src = fopen(orig, "rb"); while(fread(&byte, 1, 1, src)) fwrite(&byte, 1, 1, dest); fclose(src); fclose(dest); } else fclose(dest); strcpy(temp, g_WorkingDir); strcat(temp, "lang"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/lang"); symlink(orig, temp); /*strcpy(temp, g_WorkingDir); strcat(temp, "plugins"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins"); symlink(orig, temp);*/ strcpy(temp, g_WorkingDir); strcat(temp, "plugins"); mkdir(temp, 0700); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins"); dir = opendir(orig); while((entry = readdir(dir)) != NULL) { if(strcmp(entry->d_name + strlen(entry->d_name) - 3, ".so")) { strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins/"); strcat(orig, entry->d_name); src = fopen(orig, "rb"); if(src == NULL) continue; strcpy(temp, g_WorkingDir); strcat(temp, "plugins/"); strcat(temp, entry->d_name); dest = fopen(temp, "rb"); if(dest == NULL) { unsigned char byte; dest = fopen(temp, "wb"); while(fread(&byte, 1, 1, src)) fwrite(&byte, 1, 1, dest); fclose(src); fclose(dest); } else fclose(dest); } else { strcpy(temp, g_WorkingDir); strcat(temp, "plugins/"); strcat(temp, entry->d_name); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins/"); strcat(orig, entry->d_name); symlink(orig, temp); } } strcpy(temp, g_WorkingDir); strcat(temp, "save/"); mkdir(temp, 0700); chdir(g_WorkingDir); } #else if (argv[0][0] != '/') { getcwd(cwd, 1024); strcat(cwd, "/"); strcat(cwd, argv[0]); } else strcpy(cwd, argv[0]); while(cwd[strlen(cwd)-1] != '/') cwd[strlen(cwd)-1] = '\0'; strcpy(g_WorkingDir, cwd); #endif //read config file, read plugins config_read(); plugin_scan_directory(cwd); //get config file settings buffer = (char*)config_get_string("Gfx Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[100], buffer2); p_gfx = true; } else if(buffer) printf("GFX Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Audio Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[99], buffer2); p_audio = true; } else if(buffer) printf("Audio Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Input Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[98], buffer2); p_input = true; } else if(buffer) printf("Input Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("RSP Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[97], buffer2); p_rsp = true; } else if(buffer) printf("RSP Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Core", ""); if(strcmp(buffer,"")) { p_emumode = true; p_emumode_value = buffer[0]-'0'+1; } buffer = (char*)config_get_string("Fullscreen", ""); if(strcmp(buffer,"")) { if(!strcmp(buffer, "true")) p_fullscreen = true; } buffer = (char*)config_get_string("No Ask", ""); if(strcmp(buffer,"")) { if(!strcmp(buffer, "true")) p_noask = true; } // Command Line Parameter - Parsing for(p=1; p<argc; p++) { if(argv[p][0] == '-') { if(!strcmp(argv[p], "--fullscreen")) p_fullscreen = true; else if(!strcmp(argv[p], "--help")) p_help = true; else if(!strcmp(argv[p], "--noask")) p_noask = true; else if(!strcmp(argv[p], "--interactive")) p_interactive = true; else if(!strcmp(argv[p], "--emumode")) { p++; if(p < argc) { p_emumode_value = argv[p][0]; p_emumode = true; } } else if(!strcmp(argv[p], "--gfx")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[100], buffer); p_gfx = true; } else printf("specified GFX Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--audio")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[99], buffer); p_audio = true; } else printf("specified Audio Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--input")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[98], buffer); p_input = true; } else printf("specified Input Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--rsp")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[97], buffer); p_rsp = true; } else printf("specified RSP Plugin couldn't be loaded!\n"); } } } else { strcpy(romfile, argv[p]); fileloaded = true; } } if(p_interactive) { p_emumode = 0; p_gfx = 0; p_audio = 0; p_input = 0; p_rsp = 0; } printf("\nMupen64 version : %s\n", VERSION); if (argc < 2 || p_help || p_error || fileloaded != true) { printf("\n\n" "syntax: mupen64_nogui [parameter(s)] rom\n" "\n" "Parameters:\n" " --fullscreen : turn fullscreen mode on\n" " --gfx (plugin) : set gfx plugin to (plugin)\n" " --audio (plugin) : set audio plugin to (plugin)\n" " --input (plugin) : set input plugin to (plugin)\n" " --rsp (plugin) : set rsp plugin to (plugin)\n" " --emumode (number) : set emu mode to: 1=interp./2=recomp./3=pure interp\n" " --noask : don't ask to force load on bad dumps\n" " --interactive : ask interactively for all plugins\n" "\n" "You can also use the Config-File from the Gui-Version\n" "but there are aditional Parameters for the NO-GUI Version\n" "\n"); return 0; } if (rom_read(romfile)) { if(rom) free(rom); if(ROM_HEADER) free(ROM_HEADER); return 1; } printf("Goodname:%s\n", ROM_SETTINGS.goodname); printf("16kb eeprom=%d\n", ROM_SETTINGS.eeprom_16kb); printf ("emulation mode:\n" " 1. interpreter\n" " 2. dynamic recompiler (default)\n" " 3. pure interpreter\n"); if(p_emumode) c = p_emumode_value; else c = getchar(); if (c == '1') dynacore=0; else if (c == '3') dynacore=2; else dynacore=1; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(10, 10, 16, 0); SDL_ShowCursor(0); SDL_EnableKeyRepeat(0, 0); SDL_EnableUNICODE(1); init_memory(); // --------------------- loading plugins ---------------------- i=1; i1=1; printf(" Choose your gfx plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_GFX) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } if(p_gfx) i1 = 100; else { if(p_emumode) getchar(); /*c = getchar(); s[0] = c; s[1] = 0;*/ scanf("%10s", s); i1 = atoi(s); } plugin_rewind(); old_i = i; printf(" Choose your audio plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_AUDIO) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); //getchar(); s[0] = c; s[1] = 0;*/ if(p_audio) i2 = 99; else { scanf("%10s", s); i2 = old_i + atoi(s) - 1; } plugin_rewind(); old_i = i; printf(" Choose your input plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_CONTROLLER) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); //getchar(); s[0] = c; s[1] = 0;*/ if(p_input) i3 = 98; else { scanf("%10s", s); i3 = old_i + atoi(s) - 1; } plugin_rewind(); old_i = i; printf(" Choose your RSP plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_RSP) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); getchar(); s[0] = c; s[1] = 0;*/ if(p_rsp) i4 = 97; else { scanf("%10s", s); i4 = old_i + atoi(s) - 1; } printf("\n\nSelected Plugins: %s, %s, %s, %s\n", plugins[i1], plugins[i2], plugins[3], plugins[i4]); plugin_load_plugins(plugins[i1], plugins[i2], plugins[i3], plugins[i4]); romOpen_gfx(); romOpen_audio(); romOpen_input(); // ------------------------------------------------------------ SDL_SetEventFilter(filter); if(p_fullscreen) changeWindow(); go(); romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); closeDLL_RSP(); closeDLL_input(); closeDLL_audio(); closeDLL_gfx(); free(rom); free(ROM_HEADER); free_memory(); return 0; }