fceugx/source/fceuload.cpp

150 lines
2.9 KiB
C++
Raw Normal View History

2008-09-02 03:57:21 +02:00
/****************************************************************************
2009-07-22 04:05:49 +02:00
* FCE Ultra
2008-09-02 03:57:21 +02:00
* Nintendo Wii/Gamecube Port
*
2021-01-06 21:13:49 +01:00
* Tantric 2008-2021
2008-09-02 03:57:21 +02:00
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
2009-02-07 01:57:39 +01:00
#include <malloc.h>
2010-08-29 23:15:42 +02:00
#include <gctypes.h>
2008-09-02 03:57:21 +02:00
2010-03-22 00:49:24 +01:00
#include "fceultra/file.h"
2009-12-14 07:56:29 +01:00
#include "fceugx.h"
#include "gcaudio.h"
2009-07-17 19:27:04 +02:00
#include "fceusupport.h"
2008-09-02 03:57:21 +02:00
#include "pad.h"
2009-03-28 18:23:08 +01:00
#include "menu.h"
#include "fileop.h"
2009-03-28 18:23:08 +01:00
#include "filebrowser.h"
2009-07-22 03:58:45 +02:00
#include "cheatmgr.h"
2008-09-02 03:57:21 +02:00
bool romLoaded = false;
2009-10-02 00:21:25 +02:00
int GCMemROM(int size)
{
2009-10-04 01:08:40 +02:00
bool biosError = false;
2009-03-28 18:23:08 +01:00
ResetGameLoaded();
2008-09-02 03:57:21 +02:00
2009-07-17 19:27:04 +02:00
CloseGame();
GameInfo = new FCEUGI();
memset(GameInfo, 0, sizeof(FCEUGI));
2008-09-02 03:57:21 +02:00
2009-07-17 19:27:04 +02:00
GameInfo->filename = strdup(romFilename);
GameInfo->archiveCount = 0;
2008-09-02 03:57:21 +02:00
2009-03-28 18:23:08 +01:00
/*** Set some default values ***/
2009-07-17 19:27:04 +02:00
GameInfo->name=0;
GameInfo->type=GIT_CART;
2020-11-09 00:36:36 +01:00
GameInfo->vidsys=(EGIV)GetFCEUTiming();
UpdateDendy();
2009-07-17 19:27:04 +02:00
GameInfo->input[0]=GameInfo->input[1]=SI_UNSET;
GameInfo->inputfc=SIFC_UNSET;
GameInfo->cspecial=SIS_NONE;
2008-09-02 03:57:21 +02:00
2009-03-28 18:23:08 +01:00
/*** Set internal sound information ***/
SetSampleRate();
2009-03-28 18:23:08 +01:00
FCEUI_SetSoundVolume(100); // 0-100
FCEUI_SetLowPass(0);
2008-09-02 03:57:21 +02:00
2009-07-18 08:19:04 +02:00
FCEUFILE * fceufp = new FCEUFILE();
fceufp->size = size;
fceufp->filename = romFilename;
2009-12-14 07:56:29 +01:00
fceufp->mode = FCEUFILE::READ; // read only
2010-08-29 23:15:42 +02:00
EMUFILE_MEMFILE *fceumem = new EMUFILE_MEMFILE(nesrom, size);
2009-07-20 10:05:44 +02:00
fceufp->stream = fceumem;
2009-12-14 07:56:29 +01:00
2009-07-20 10:05:44 +02:00
romLoaded = iNESLoad(romFilename, fceufp, 1);
if(!romLoaded)
{
romLoaded = UNIFLoad(romFilename, fceufp);
}
if(!romLoaded)
{
2009-09-15 10:20:48 +02:00
romLoaded = NSFLoad(romFilename, fceufp);
2009-07-20 10:05:44 +02:00
}
if(!romLoaded)
{
// read FDS BIOS into FDSBIOS - should be 8192 bytes
2009-03-28 18:23:08 +01:00
if (FDSBIOS[1] == 0)
{
2009-10-04 01:08:40 +02:00
size_t biosSize = 0;
char filepath[1024];
AllocSaveBuffer ();
sprintf (filepath, "%s%s/disksys.rom", pathPrefix[GCSettings.LoadMethod], APPFOLDER);
biosSize = LoadFile(filepath, SILENT);
if(biosSize == 0 && strlen(appPath) > 0)
{
sprintf (filepath, "%s/disksys.rom", appPath);
biosSize = LoadFile(filepath, SILENT);
}
2009-03-28 18:23:08 +01:00
if (biosSize == 8192)
{
memcpy(FDSBIOS, savebuffer, 8192);
}
else
{
2009-10-04 01:08:40 +02:00
biosError = true;
2009-03-28 18:23:08 +01:00
if (biosSize > 0)
ErrorPrompt("FDS BIOS file is invalid!");
else
ErrorPrompt("FDS BIOS file not found!");
}
FreeSaveBuffer ();
}
2009-07-20 09:26:39 +02:00
if (FDSBIOS[1] != 0)
{
2009-07-20 10:05:44 +02:00
romLoaded = FDSLoad(romFilename, fceufp);
2009-07-20 09:26:39 +02:00
}
}
delete fceufp;
2009-07-18 08:19:04 +02:00
if (romLoaded)
2009-03-28 18:23:08 +01:00
{
FCEU_ResetVidSys();
2009-07-17 19:27:04 +02:00
if(GameInfo->type!=GIT_NSF)
if(FSettings.GameGenie)
OpenGameGenie();
2009-03-28 18:23:08 +01:00
PowerNES();
2009-07-17 19:27:04 +02:00
//if(GameInfo->type!=GIT_NSF)
// FCEU_LoadGamePalette();
2009-07-17 19:27:04 +02:00
2009-03-28 18:23:08 +01:00
FCEU_ResetPalette();
2009-07-17 19:27:04 +02:00
FCEU_ResetMessages(); // Save state, status messages, etc.
2009-07-22 03:58:45 +02:00
SetupCheats();
2009-03-28 18:23:08 +01:00
ResetAudio();
return 1;
}
else
{
2009-07-17 19:27:04 +02:00
delete GameInfo;
GameInfo = 0;
2009-10-04 01:08:40 +02:00
if(!biosError)
ErrorPrompt("Invalid game file!");
2009-03-28 18:23:08 +01:00
romLoaded = false;
return 0;
}
2008-09-02 03:57:21 +02:00
}