void Func_ShowRomInfo() { char RomInfo[256] = ""; char buffer [50]; char buffer2 [50]; sprintf(buffer,"Rom name: %s\n",ROM_SETTINGS.goodname); strcat(RomInfo,buffer); sprintf(buffer,"Rom size: %d Mb\n",rom_length/1024/1024); strcat(RomInfo,buffer); if(ROM_HEADER.Manufacturer_ID == 'N') sprintf(buffer,"Manufacturer: Nintendo\n"); else sprintf(buffer,"Manufacturer: %x\n", ROM_HEADER.Manufacturer_ID); strcat(RomInfo,buffer); countrycodestring(ROM_HEADER.Country_code&0xFF, buffer2); sprintf(buffer,"Country: %s\n",buffer2); strcat(RomInfo,buffer); menu::MessageBox::getInstance().setMessage(RomInfo); }
m64p_error open_rom(const unsigned char* romimage, unsigned int size) { md5_state_t state; md5_byte_t digest[16]; romdatabase_entry* entry; char buffer[256]; unsigned char imagetype; int i; /* check input requirements */ if (g_rom != NULL) { DebugMessage(M64MSG_ERROR, "open_rom(): previous ROM image was not freed"); return M64ERR_INTERNAL; } if (romimage == NULL || !is_valid_rom(romimage)) { DebugMessage(M64MSG_ERROR, "open_rom(): not a valid ROM image"); return M64ERR_INPUT_INVALID; } /* Clear Byte-swapped flag, since ROM is now deleted. */ g_MemHasBeenBSwapped = 0; /* allocate new buffer for ROM and copy into this buffer */ g_rom_size = size; g_rom = (unsigned char *) malloc(size); if (g_rom == NULL) return M64ERR_NO_MEMORY; swap_copy_rom(g_rom, romimage, size, &imagetype); memcpy(&ROM_HEADER, g_rom, sizeof(m64p_rom_header)); /* Calculate MD5 hash */ md5_init(&state); md5_append(&state, (const md5_byte_t*)g_rom, g_rom_size); md5_finish(&state, digest); for ( i = 0; i < 16; ++i ) sprintf(buffer+i*2, "%02X", digest[i]); buffer[32] = '\0'; strcpy(ROM_SETTINGS.MD5, buffer); /* add some useful properties to ROM_PARAMS */ ROM_PARAMS.systemtype = rom_country_code_to_system_type(ROM_HEADER.Country_code); ROM_PARAMS.countperop = COUNT_PER_OP_DEFAULT; ROM_PARAMS.vitiming = ALTERNATE_VI_TIMING_DEFAULT; ROM_PARAMS.countperscanline = DEFAULT_COUNT_PER_SCANLINE; ROM_PARAMS.cheats = NULL; memcpy(ROM_PARAMS.headername, ROM_HEADER.Name, 20); ROM_PARAMS.headername[20] = '\0'; trim(ROM_PARAMS.headername); /* Remove trailing whitespace from ROM name. */ /* Look up this ROM in the .ini file and fill in goodname, etc */ if ((entry=ini_search_by_md5(digest)) != NULL || (entry=ini_search_by_crc(sl(ROM_HEADER.CRC1),sl(ROM_HEADER.CRC2))) != NULL) { strncpy(ROM_SETTINGS.goodname, entry->goodname, 255); ROM_SETTINGS.goodname[255] = '\0'; ROM_SETTINGS.savetype = entry->savetype; ROM_SETTINGS.status = entry->status; ROM_SETTINGS.players = entry->players; ROM_SETTINGS.rumble = entry->rumble; ROM_PARAMS.countperop = entry->countperop; ROM_PARAMS.vitiming = entry->alternate_vi_timing; ROM_PARAMS.countperscanline = entry->count_per_scanline; ROM_PARAMS.cheats = entry->cheats; } else { strcpy(ROM_SETTINGS.goodname, ROM_PARAMS.headername); strcat(ROM_SETTINGS.goodname, " (unknown rom)"); ROM_SETTINGS.savetype = NONE; ROM_SETTINGS.status = 0; ROM_SETTINGS.players = 0; ROM_SETTINGS.rumble = 0; ROM_PARAMS.countperop = COUNT_PER_OP_DEFAULT; ROM_PARAMS.vitiming = ALTERNATE_VI_TIMING_DEFAULT; ROM_PARAMS.countperscanline = DEFAULT_COUNT_PER_SCANLINE; ROM_PARAMS.cheats = NULL; } /* print out a bunch of info about the ROM */ DebugMessage(M64MSG_INFO, "Goodname: %s", ROM_SETTINGS.goodname); DebugMessage(M64MSG_INFO, "Name: %s", ROM_HEADER.Name); imagestring(imagetype, buffer); DebugMessage(M64MSG_INFO, "MD5: %s", ROM_SETTINGS.MD5); DebugMessage(M64MSG_INFO, "CRC: %08" PRIX32 " %08" PRIX32, sl(ROM_HEADER.CRC1), sl(ROM_HEADER.CRC2)); DebugMessage(M64MSG_INFO, "Imagetype: %s", buffer); DebugMessage(M64MSG_INFO, "Rom size: %d bytes (or %d Mb or %d Megabits)", g_rom_size, g_rom_size/1024/1024, g_rom_size/1024/1024*8); DebugMessage(M64MSG_VERBOSE, "ClockRate = %" PRIX32, sl(ROM_HEADER.ClockRate)); DebugMessage(M64MSG_INFO, "Version: %" PRIX32, sl(ROM_HEADER.Release)); if(sl(ROM_HEADER.Manufacturer_ID) == 'N') DebugMessage(M64MSG_INFO, "Manufacturer: Nintendo"); else DebugMessage(M64MSG_INFO, "Manufacturer: %" PRIX32, sl(ROM_HEADER.Manufacturer_ID)); DebugMessage(M64MSG_VERBOSE, "Cartridge_ID: %" PRIX16, ROM_HEADER.Cartridge_ID); countrycodestring(ROM_HEADER.Country_code, buffer); DebugMessage(M64MSG_INFO, "Country: %s", buffer); DebugMessage(M64MSG_VERBOSE, "PC = %" PRIX32, sl(ROM_HEADER.PC)); DebugMessage(M64MSG_VERBOSE, "Save type: %d", ROM_SETTINGS.savetype); //Prepare Hack for GOLDENEYE isGoldeneyeRom = 0; if(strcmp(ROM_PARAMS.headername, "GOLDENEYE") == 0) isGoldeneyeRom = 1; return M64ERR_SUCCESS; }
/* Load a GtkTreeModel after re-scanning directories. */ void rombrowser_refresh(unsigned int roms, unsigned short clear) { int arrayroms; GtkTreeModel* model; /* If clear flag is set, clear the models. */ if(clear) { model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList)); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romFullList)); gtk_tree_selection_select_all(selection); gtk_list_store_clear(GTK_LIST_STORE(model)); model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay)); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romDisplay)); gtk_tree_selection_select_all(selection); gtk_list_store_clear(GTK_LIST_STORE(model)); } model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList)); arrayroms = gtk_tree_model_iter_n_children(model, NULL); /* If there are currently more ROMs in cache than in the rombrowser, add them. */ if(roms>arrayroms) { gboolean fullpaths; GtkTreeIter* iter = (GtkTreeIter*)malloc(sizeof(GtkTreeIter)); char *country, *goodname, *usercomments, *md5hash, *crc1, *crc2, *internalname, *savetype, *players, *size, *compressiontype, *imagetype, *cicchip, *rumble; char* filename = NULL; /* Needs to be NULLed if fullpaths and zero roms are updated, for free. */ GdkPixbuf* flag; GdkPixbuf* status[5]; unsigned int romcounter; int counter; country = (char*)calloc(32, sizeof(char)); md5hash = (char*)calloc(33, sizeof(char)); crc1 = (char*)calloc(9, sizeof(char)); crc2 = (char*)calloc(9, sizeof(char)); savetype = (char*)calloc(16, sizeof(char)); players = (char*)calloc(16, sizeof(char)); size = (char*)calloc(16, sizeof(char)); compressiontype = (char*)calloc(16, sizeof(char)); imagetype = (char*)calloc(32, sizeof(char)); cicchip = (char*)calloc(16, sizeof(char)); rumble = (char*)calloc(8, sizeof(char)); if(iter==NULL||country==NULL||md5hash==NULL||crc1==NULL||crc2==NULL||size==NULL||compressiontype==NULL||imagetype==NULL||cicchip==NULL) { fprintf(stderr, "%s, %d: Out of memory!\n", __FILE__, __LINE__); return; } fullpaths = config_get_bool("RomBrowserShowFullPaths", FALSE); cache_entry* entry; entry = g_romcache.top; /* Advance cache pointer. */ for(romcounter=0; romcounter < arrayroms; ++romcounter) { entry = entry->next; if(entry==NULL) return; } for(romcounter=0; (romcounter < roms) && (entry != NULL); ++romcounter) { countrycodestring(entry->countrycode, country); countrycodeflag(entry->countrycode, &flag); goodname = entry->inientry->goodname; for(counter = 0; counter < 5; ++counter) { if(entry->inientry->status>counter) status[counter] = star; else status[counter] = staroff; } usercomments = entry->usercomments; if(fullpaths) filename = entry->filename; else filename = filefrompath(entry->filename); for(counter = 0; counter < 16; ++counter) sprintf(md5hash+counter*2, "%02X", entry->md5[counter]); sprintf(crc1, "%08X", entry->crc1); sprintf(crc2, "%08X", entry->crc2); internalname=entry->internalname; savestring(entry->inientry->savetype, savetype); playersstring(entry->inientry->players, players); sprintf(size, "%.1f MBits", (float)(entry->romsize / (float)0x20000)); compressionstring(entry->compressiontype, compressiontype); imagestring(entry->imagetype, imagetype); cicstring(entry->cic, cicchip); rumblestring(entry->inientry->rumble, rumble); /* Actually add entries to models. */ model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList)); gtk_list_store_append(GTK_LIST_STORE(model), iter); gtk_list_store_set(GTK_LIST_STORE(model), iter, 0, country, 1, goodname, 2, NULL, 3, usercomments, 4, filename, 5, md5hash, 6, crc1, 7, crc2, 8, internalname, 9, savetype, 10, players, 11, size, 12, compressiontype, 13, imagetype, 14, cicchip, 15, rumble, 16, status[0], 17, status[1], 18, status[2], 19, status[3], 20, status[4], 21, flag, 22, entry, -1); model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay)); gtk_list_store_append(GTK_LIST_STORE(model), iter); gtk_list_store_set(GTK_LIST_STORE(model), iter, 0, country, 1, goodname, 2, NULL, 3, usercomments, 4, filename, 5, md5hash, 6, crc1, 7, crc2, 8, internalname, 9, savetype, 10, players, 11, size, 12, compressiontype, 13, imagetype, 14, cicchip, 15, rumble, 16, status[0], 17, status[1], 18, status[2], 19, status[3], 20, status[4], 21, flag, 22, entry, -1); /*printf("Added: %s\n", goodname);*/ entry = entry->next; } free(country); free(md5hash); free(crc1); free(crc2); free(savetype); free(players); free(size); free(compressiontype); free(imagetype); free(cicchip); free(rumble); if(!fullpaths) { if(filename!=NULL) free(filename); } free(iter); /* Do an initial sort. */ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), g_MainWindow.romSortColumn, rombrowser_compare, (gpointer)NULL, (gpointer)NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), g_MainWindow.romSortColumn, g_MainWindow.romSortType); gtk_tree_view_set_model(GTK_TREE_VIEW(g_MainWindow.romDisplay), model); } }
void fileBrowserFrame_LoadFile(int i) { if(dir_entries[i].attr & FILE_BROWSER_ATTR_DIR){ // Here we are 'recursing' into a subdirectory // We have to do a little dance here to avoid a dangling pointer fileBrowser_file* dir = (fileBrowser_file*)malloc( sizeof(fileBrowser_file) ); memcpy(dir, dir_entries+i, sizeof(fileBrowser_file)); fileBrowserFrame_OpenDirectory(dir); free(dir); menu::Focus::getInstance().clearPrimaryFocus(); } else { // We must select this file int ret = loadROM( &dir_entries[i] ); if(!ret){ // If the read succeeded. strcpy(feedback_string, "Loaded "); strncat(feedback_string, filenameFromAbsPath(dir_entries[i].name), 36-7); char RomInfo[512] = ""; char buffer [50]; char buffer2 [50]; strcat(RomInfo,feedback_string); sprintf(buffer,"\n\nRom name: %s\n",ROM_SETTINGS.goodname); strcat(RomInfo,buffer); sprintf(buffer,"Rom size: %d Mb\n",rom_length/1024/1024); strcat(RomInfo,buffer); if(ROM_HEADER->Manufacturer_ID == 'N') sprintf(buffer,"Manufacturer: Nintendo\n"); else sprintf(buffer,"Manufacturer: %x\n", (unsigned int)(ROM_HEADER->Manufacturer_ID)); strcat(RomInfo,buffer); countrycodestring(ROM_HEADER->Country_code&0xFF, buffer2); sprintf(buffer,"Country: %s\n",buffer2); strcat(RomInfo,buffer); switch (autoSaveLoaded) { case NATIVESAVEDEVICE_NONE: break; case NATIVESAVEDEVICE_SD: strcat(RomInfo,"\nFound & loaded save from SD card\n"); break; case NATIVESAVEDEVICE_USB: strcat(RomInfo,"\nFound & loaded save from USB device\n"); break; case NATIVESAVEDEVICE_CARDA: strcat(RomInfo,"\nFound & loaded save from memcard in slot A\n"); break; case NATIVESAVEDEVICE_CARDB: strcat(RomInfo,"\nFound & loaded save from memcard in slot B\n"); break; } autoSaveLoaded = NATIVESAVEDEVICE_NONE; menu::MessageBox::getInstance().setMessage(RomInfo); } else // If not. { switch(ret) { case ROM_CACHE_ERROR_READ: strcpy(feedback_string,"A read error occured"); break; case ROM_CACHE_INVALID_ROM: strcpy(feedback_string,"Invalid ROM type"); break; default: strcpy(feedback_string,"An error has occured"); break; } menu::MessageBox::getInstance().setMessage(feedback_string); } /* //disable all buttons for (int i = 0; i < NUM_FRAME_BUTTONS; i++) FRAME_BUTTONS[i].button->setActive(false); //set first entry to report 'success'/'error' and return to main menu FRAME_BUTTONS[2].buttonString = feedback_string; FRAME_BUTTONS[2].button->setClicked(Func_ReturnFromFileBrowserFrame); FRAME_BUTTONS[2].button->setActive(true); FRAME_BUTTONS[2].button->setNextFocus(menu::Focus::DIRECTION_UP, NULL); FRAME_BUTTONS[2].button->setNextFocus(menu::Focus::DIRECTION_DOWN, NULL); for (int i = 1; i<NUM_FILE_SLOTS; i++) FRAME_BUTTONS[i+2].buttonString = FRAME_STRINGS[2]; pMenuContext->getFrame(MenuContext::FRAME_FILEBROWSER)->setDefaultFocus(FRAME_BUTTONS[2].button); menu::Focus::getInstance().clearPrimaryFocus();*/ pMenuContext->setActiveFrame(MenuContext::FRAME_MAIN); if(hasLoadedROM) Func_SetPlayGame(); } }
m64p_error open_rom(const unsigned char* romimage, unsigned int size) { md5_state_t state; md5_byte_t digest[16]; romdatabase_entry* entry; char buffer[256]; unsigned char imagetype; int i; m64p_handle CoreSection = NULL; /* check input requirements */ if (rom != NULL) { DebugMessage(M64MSG_ERROR, "open_rom(): previous ROM image was not freed"); return M64ERR_INTERNAL; } if (romimage == NULL || !is_valid_rom(romimage)) { DebugMessage(M64MSG_ERROR, "open_rom(): not a valid ROM image"); return M64ERR_INPUT_INVALID; } /* Clear Byte-swapped flag, since ROM is now deleted. */ g_MemHasBeenBSwapped = 0; /* allocate new buffer for ROM and copy into this buffer */ rom_size = size; rom = (unsigned char *) malloc(size); if (rom == NULL) return M64ERR_NO_MEMORY; memcpy(rom, romimage, size); swap_rom(rom, &imagetype, rom_size); memcpy(&ROM_HEADER, rom, sizeof(m64p_rom_header)); /* Calculate MD5 hash */ md5_init(&state); md5_append(&state, (const md5_byte_t*)rom, rom_size); md5_finish(&state, digest); for ( i = 0; i < 16; ++i ) sprintf(buffer+i*2, "%02X", digest[i]); buffer[32] = '\0'; strcpy(ROM_SETTINGS.MD5, buffer); /* add some useful properties to ROM_PARAMS */ ROM_PARAMS.systemtype = rom_country_code_to_system_type(ROM_HEADER.Country_code); ROM_PARAMS.vilimit = rom_system_type_to_vi_limit(ROM_PARAMS.systemtype); ROM_PARAMS.aidacrate = rom_system_type_to_ai_dac_rate(ROM_PARAMS.systemtype); memcpy(ROM_PARAMS.headername, ROM_HEADER.Name, 20); ROM_PARAMS.headername[20] = '\0'; trim(ROM_PARAMS.headername); /* Remove trailing whitespace from ROM name. */ /* Look up this ROM in the .ini file and fill in goodname, etc */ /* if ((entry=ini_search_by_md5(digest)) != NULL || (entry=ini_search_by_crc(sl(ROM_HEADER.CRC1),sl(ROM_HEADER.CRC2))) != NULL) { strncpy(ROM_SETTINGS.goodname, entry->goodname, 255); ROM_SETTINGS.goodname[255] = '\0'; ROM_SETTINGS.savetype = entry->savetype; ROM_SETTINGS.status = entry->status; ROM_SETTINGS.players = entry->players; ROM_SETTINGS.rumble = entry->rumble; } else { strcpy(ROM_SETTINGS.goodname, ROM_PARAMS.headername); strcat(ROM_SETTINGS.goodname, " (unknown rom)"); ROM_SETTINGS.savetype = NONE; ROM_SETTINGS.status = 0; ROM_SETTINGS.players = 0; ROM_SETTINGS.rumble = 0; } */ strcpy(ROM_SETTINGS.goodname, ROM_PARAMS.headername); strcat(ROM_SETTINGS.goodname, " (unknown rom)"); ROM_SETTINGS.savetype = 0; if (ConfigOpenSection("Core", &CoreSection) == M64ERR_SUCCESS) { ConfigSetDefaultInt(CoreSection, "SaveType", NONE, "The savetype for the game"); ROM_SETTINGS.savetype = ConfigGetParamInt(CoreSection, "SaveType"); } ROM_SETTINGS.status = 0; ROM_SETTINGS.players = 0; ROM_SETTINGS.rumble = 0; /* print out a bunch of info about the ROM */ DebugMessage(M64MSG_INFO, "Goodname: %s", ROM_SETTINGS.goodname); DebugMessage(M64MSG_INFO, "Name: %s", ROM_HEADER.Name); imagestring(imagetype, buffer); DebugMessage(M64MSG_INFO, "MD5: %s", ROM_SETTINGS.MD5); DebugMessage(M64MSG_INFO, "CRC: %x %x", sl(ROM_HEADER.CRC1), sl(ROM_HEADER.CRC2)); DebugMessage(M64MSG_INFO, "Imagetype: %s", buffer); DebugMessage(M64MSG_INFO, "Rom size: %d bytes (or %d Mb or %d Megabits)", rom_size, rom_size/1024/1024, rom_size/1024/1024*8); DebugMessage(M64MSG_VERBOSE, "ClockRate = %x", sl(ROM_HEADER.ClockRate)); DebugMessage(M64MSG_INFO, "Version: %x", sl(ROM_HEADER.Release)); if(sl(ROM_HEADER.Manufacturer_ID) == 'N') DebugMessage(M64MSG_INFO, "Manufacturer: Nintendo"); else DebugMessage(M64MSG_INFO, "Manufacturer: %x", sl(ROM_HEADER.Manufacturer_ID)); DebugMessage(M64MSG_VERBOSE, "Cartridge_ID: %x", ROM_HEADER.Cartridge_ID); countrycodestring(ROM_HEADER.Country_code, buffer); DebugMessage(M64MSG_INFO, "Country: %s", buffer); DebugMessage(M64MSG_VERBOSE, "PC = %x", sl((unsigned int)ROM_HEADER.PC)); DebugMessage(M64MSG_VERBOSE, "Save type: %d", ROM_SETTINGS.savetype); //Prepare Hack for GOLDENEYE isGoldeneyeRom = 0; if(strcmp(ROM_PARAMS.headername, "GOLDENEYE") == 0) isGoldeneyeRom = 1; return M64ERR_SUCCESS; }