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
|
|
|
|
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
|
|
|
|
|
2008-10-02 07:28:01 +02:00
|
|
|
int GCMemROM(int method, int size)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
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;
|
|
|
|
GameInfo->vidsys=GIV_USER;
|
|
|
|
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-07-20 10:05:44 +02:00
|
|
|
memorystream * fceumem;
|
2008-10-01 07:25:38 +02:00
|
|
|
|
2009-07-20 08:18:06 +02:00
|
|
|
romLoaded = false;
|
2008-10-01 07:25:38 +02:00
|
|
|
|
2009-07-20 10:05:44 +02:00
|
|
|
// for some reason FCEU_fseek(fp,0,SEEK_SET); fails, so we will do this
|
|
|
|
fceumem = new memorystream((char *) nesrom, size);
|
|
|
|
fceufp->stream = fceumem;
|
|
|
|
romLoaded = iNESLoad(romFilename, fceufp, 1);
|
|
|
|
|
|
|
|
if(!romLoaded)
|
|
|
|
{
|
|
|
|
delete fceumem;
|
|
|
|
fceumem = new memorystream((char *) nesrom, size);
|
|
|
|
fceufp->stream = fceumem;
|
|
|
|
romLoaded = UNIFLoad(romFilename, fceufp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!romLoaded)
|
|
|
|
{
|
|
|
|
delete fceumem;
|
|
|
|
fceumem = new memorystream((char *) nesrom, size);
|
|
|
|
fceufp->stream = fceumem;
|
|
|
|
romLoaded = NSFLoad(fceufp);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int 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];
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if (MakeFilePath(filepath, FILE_FDSBIOS, method))
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
biosSize = LoadFile(tmpbuffer, filepath, 0, method, 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-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)
|
|
|
|
{
|
|
|
|
// load game
|
2009-07-20 10:05:44 +02:00
|
|
|
delete fceumem;
|
|
|
|
fceumem = new memorystream((char *) nesrom, size);
|
|
|
|
fceufp->stream = fceumem;
|
|
|
|
|
|
|
|
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-20 08:18:06 +02:00
|
|
|
//if(GameInfo->type!=GIT_NSF)
|
|
|
|
// if(FSettings.GameGenie)
|
|
|
|
// OpenGenie();
|
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-03-28 18:23:08 +01:00
|
|
|
ErrorPrompt("Invalid game file!");
|
|
|
|
romLoaded = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|