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
|
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* Tantric 2008-2009
|
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>
|
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
|
|
|
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2008-10-22 18:46:44 +02:00
|
|
|
#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"
|
2008-10-01 07:25:38 +02:00
|
|
|
#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;
|
|
|
|
|
|
|
|
#define SAMPLERATE 48000
|
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
int GCMemROM(int size)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
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->soundchan = 1;
|
|
|
|
GameInfo->soundrate = SAMPLERATE;
|
|
|
|
GameInfo->name=0;
|
|
|
|
GameInfo->type=GIT_CART;
|
2010-04-12 23:15:11 +02:00
|
|
|
GameInfo->vidsys=(EGIV)GCSettings.timing;
|
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 ***/
|
|
|
|
FCEUI_Sound(SAMPLERATE);
|
|
|
|
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
|
|
|
|
memorystream * fceumem = new memorystream((char *) 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)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
|
|
|
// read FDS BIOS into FDSBIOS - should be 8192 bytes
|
2009-03-28 18:23:08 +01:00
|
|
|
if (FDSBIOS[1] == 0)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
2009-10-04 01:08:40 +02:00
|
|
|
size_t biosSize = 0;
|
2009-03-28 18:23:08 +01:00
|
|
|
char * tmpbuffer = (char *) memalign(32, 64 * 1024);
|
2008-10-01 07:25:38 +02:00
|
|
|
|
|
|
|
char filepath[1024];
|
|
|
|
|
2010-01-13 06:53:42 +01:00
|
|
|
sprintf (filepath, "%s%s/disksys.rom", pathPrefix[GCSettings.LoadMethod], APPFOLDER);
|
|
|
|
biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT);
|
|
|
|
if(biosSize == 0 && strlen(appPath) > 0)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
2010-01-13 06:53:42 +01:00
|
|
|
sprintf (filepath, "%s/disksys.rom", appPath);
|
2009-10-02 00:21:25 +02:00
|
|
|
biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT);
|
2008-10-01 07:25:38 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if (biosSize == 8192)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
|
|
|
memcpy(FDSBIOS, tmpbuffer, 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!");
|
2009-07-20 08:18:06 +02:00
|
|
|
else
|
|
|
|
ErrorPrompt("FDS BIOS file not found!");
|
2008-10-01 07:25:38 +02:00
|
|
|
}
|
|
|
|
free(tmpbuffer);
|
|
|
|
}
|
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
|
|
|
}
|
2008-10-01 07:25:38 +02:00
|
|
|
}
|
|
|
|
|
2009-07-20 08:18:06 +02:00
|
|
|
delete fceufp;
|
2009-07-18 08:19:04 +02:00
|
|
|
|
2009-07-20 08:18:06 +02:00
|
|
|
if (romLoaded)
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
|
|
|
FCEU_ResetVidSys();
|
2009-07-17 19:27:04 +02:00
|
|
|
|
2009-07-29 08:33:17 +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
|
|
|
|
2009-07-20 08:18:06 +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
|
|
|
}
|