/**************************************************************************** * FCE Ultra 0.98.12 * Nintendo Wii/Gamecube Port * * Tantric 2008-2009 * * fceload.c * * NES Memory Load Game * * This performs the functions of LoadGame and iNESLoad from a single module * Helper function for GameCube injected ROMS ****************************************************************************/ #include #include #include #include #include "fceugx.h" #include "gcaudio.h" #include "fceusupport.h" #include "pad.h" #include "menu.h" #include "fileop.h" #include "filebrowser.h" bool romLoaded = false; #define SAMPLERATE 48000 static FCEUFILE *fceufp = NULL; static memorystream* fceumem = NULL; static void MakeFCEUFile(char * membuffer, int length) { if(fceufp != NULL) { delete fceufp; fceufp = NULL; } fceumem = new memorystream(membuffer, length); // we never need to delete this...? fceufp = new FCEUFILE(); fceufp->size = length; fceufp->stream = fceumem; fceufp->filename = romFilename; } int GCMemROM(int method, int size) { ResetGameLoaded(); //AutosaveStatus[0] = AutosaveStatus[1] = 0; //AutosaveStatus[2] = AutosaveStatus[3] = 0; CloseGame(); GameInfo = new FCEUGI(); memset(GameInfo, 0, sizeof(FCEUGI)); GameInfo->filename = strdup(romFilename); //if(fceufp->archiveFilename != "") GameInfo->archiveFilename = strdup(fceufp->archiveFilename.c_str()); GameInfo->archiveCount = 0; /*** Set some default values ***/ GameInfo->soundchan = 1; GameInfo->soundrate = SAMPLERATE; GameInfo->name=0; GameInfo->type=GIT_CART; GameInfo->vidsys=GIV_USER; GameInfo->input[0]=GameInfo->input[1]=SI_UNSET; GameInfo->inputfc=SIFC_UNSET; GameInfo->cspecial=SIS_NONE; /*** Set internal sound information ***/ FCEUI_Sound(SAMPLERATE); FCEUI_SetSoundVolume(100); // 0-100 FCEUI_SetLowPass(0); MakeFCEUFile((char *) nesrom, size); nesGameType = 0; if (iNESLoad(romFilename, fceufp, 1)) nesGameType = 1; else if (UNIFLoad(romFilename, fceufp)) nesGameType = 2; else if (NSFLoad(fceufp)) nesGameType = 3; else { // read FDS BIOS into FDSBIOS - should be 8192 bytes if (FDSBIOS[1] == 0) { int biosSize = 0; char * tmpbuffer = (char *) memalign(32, 64 * 1024); char filepath[1024]; if (MakeFilePath(filepath, FILE_FDSBIOS, method)) { biosSize = LoadFile(tmpbuffer, filepath, 0, method, SILENT); } if (biosSize == 8192) { memcpy(FDSBIOS, tmpbuffer, 8192); } else { if (biosSize > 0) ErrorPrompt("FDS BIOS file is invalid!"); return 0; // BIOS not loaded, do not load game } free(tmpbuffer); } // load game if (FDSLoad(NULL, fceufp)) nesGameType = 4; } if (nesGameType > 0) { FCEU_ResetVidSys(); if(GameInfo->type!=GIT_NSF) if(FSettings.GameGenie) OpenGenie(); PowerNES(); if(GameInfo->type!=GIT_NSF) FCEU_LoadGamePalette(); FCEU_ResetPalette(); FCEU_ResetMessages(); // Save state, status messages, etc. if(GameInfo->type!=GIT_NSF) FCEU_LoadGameCheats(0); ResetAudio(); romLoaded = true; return 1; } else { delete GameInfo; GameInfo = 0; ErrorPrompt("Invalid game file!"); romLoaded = false; return 0; } }