2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* FCE Ultra 0.98.12
|
|
|
|
* Nintendo Wii/Gamecube Port
|
|
|
|
*
|
|
|
|
* Tantric September 2008
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2009-01-25 07:53:21 +01:00
|
|
|
extern "C" {
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "types.h"
|
|
|
|
#include "git.h"
|
|
|
|
#include "driver.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "fceu.h"
|
|
|
|
#include "sound.h"
|
2008-10-01 07:25:38 +02:00
|
|
|
#include "file.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-01-25 07:53:21 +01:00
|
|
|
extern int FDSLoad(const char *name, FCEUFILE *fp);
|
|
|
|
extern int iNESLoad(const char *name, FCEUFILE *fp);
|
|
|
|
extern int UNIFLoad(const char *name, FCEUFILE *fp);
|
|
|
|
extern int NSFLoad(FCEUFILE *fp);
|
|
|
|
extern uint8 FDSBIOS[8192];
|
|
|
|
}
|
|
|
|
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2008-10-22 18:46:44 +02:00
|
|
|
#include "gcaudio.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "common.h"
|
|
|
|
#include "pad.h"
|
|
|
|
#include "menudraw.h"
|
2008-10-01 07:25:38 +02:00
|
|
|
#include "fileop.h"
|
|
|
|
#include "filesel.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
bool romLoaded = false;
|
|
|
|
|
|
|
|
extern FCEUGI *FCEUGameInfo;
|
|
|
|
|
|
|
|
#define SAMPLERATE 48000
|
|
|
|
|
2008-10-01 07:25:38 +02:00
|
|
|
FCEUFILE *fceufp = NULL;
|
|
|
|
MEMWRAP *fceumem = NULL;
|
|
|
|
unsigned char * fceuFileData = NULL;
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
static void MakeFCEUFile(char * membuffer, int length)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-10-01 07:25:38 +02:00
|
|
|
if(fceufp != NULL)
|
|
|
|
{
|
|
|
|
free(fceuFileData);
|
|
|
|
free(fceumem);
|
|
|
|
free(fceufp);
|
|
|
|
fceuFileData = NULL;
|
|
|
|
fceumem = NULL;
|
|
|
|
fceufp = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-07 01:57:39 +01:00
|
|
|
fceufp =(FCEUFILE *)memalign(32,sizeof(FCEUFILE));
|
2008-10-01 07:25:38 +02:00
|
|
|
fceufp->type=3;
|
2009-02-07 01:57:39 +01:00
|
|
|
fceumem = (MEMWRAP *)memalign(32,sizeof(MEMWRAP));
|
2008-10-01 07:25:38 +02:00
|
|
|
fceumem->location=0;
|
|
|
|
fceumem->size=length;
|
2009-02-07 01:57:39 +01:00
|
|
|
fceuFileData = (unsigned char *)memalign(32,length);
|
2008-10-01 07:25:38 +02:00
|
|
|
memcpy(fceuFileData, membuffer, length);
|
|
|
|
fceumem->data=fceuFileData;
|
|
|
|
fceufp->fp = fceumem;
|
|
|
|
}
|
|
|
|
|
2008-10-02 07:28:01 +02:00
|
|
|
int GCMemROM(int method, int size)
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
2008-09-02 03:57:21 +02:00
|
|
|
ResetGameLoaded();
|
|
|
|
|
|
|
|
/*** Allocate and clear GameInfo ***/
|
|
|
|
|
2009-02-07 01:57:39 +01:00
|
|
|
FCEUGameInfo = (FCEUGI *)memalign(32,sizeof(FCEUGI));
|
2008-09-02 03:57:21 +02:00
|
|
|
memset(FCEUGameInfo, 0, sizeof(FCEUGI));
|
|
|
|
|
|
|
|
/*** Set some default values ***/
|
|
|
|
FCEUGameInfo->soundchan = 1;
|
|
|
|
FCEUGameInfo->soundrate = SAMPLERATE;
|
|
|
|
FCEUGameInfo->name=0;
|
|
|
|
FCEUGameInfo->type=GIT_CART;
|
|
|
|
FCEUGameInfo->vidsys=GIV_USER;
|
|
|
|
FCEUGameInfo->input[0]=FCEUGameInfo->input[1]=-1;
|
|
|
|
FCEUGameInfo->inputfc=-1;
|
|
|
|
FCEUGameInfo->cspecial=0;
|
|
|
|
|
|
|
|
/*** Set internal sound information ***/
|
|
|
|
FCEUI_Sound(SAMPLERATE);
|
2008-09-06 20:24:52 +02:00
|
|
|
FCEUI_SetSoundVolume(100); // 0-100
|
2008-10-21 09:50:37 +02:00
|
|
|
FCEUI_SetLowPass(0);
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
InitialisePads();
|
|
|
|
|
2008-10-02 07:28:01 +02:00
|
|
|
MakeFCEUFile((char *)nesrom, size);
|
2008-10-01 07:25:38 +02:00
|
|
|
|
|
|
|
nesGameType = 0;
|
|
|
|
|
|
|
|
if(iNESLoad(NULL, fceufp))
|
|
|
|
nesGameType = 1;
|
|
|
|
else if(UNIFLoad(NULL,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;
|
2009-02-07 01:57:39 +01:00
|
|
|
char * tmpbuffer = (char *)memalign(32,64 * 1024);
|
2008-10-01 07:25:38 +02:00
|
|
|
|
|
|
|
char filepath[1024];
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
if(MakeFilePath(filepath, FILE_FDSBIOS, method))
|
2008-10-01 07:25:38 +02:00
|
|
|
{
|
2009-01-25 08:01:50 +01:00
|
|
|
biosSize = LoadFile (tmpbuffer, filepath, 0, method, SILENT);
|
2008-10-01 07:25:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(biosSize == 8192)
|
|
|
|
{
|
|
|
|
memcpy(FDSBIOS, tmpbuffer, 8192);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(biosSize > 0)
|
|
|
|
WaitPrompt("FDS BIOS file is invalid!");
|
2008-10-03 07:24:51 +02:00
|
|
|
|
|
|
|
return 0; // BIOS not loaded, do not load game
|
2008-10-01 07:25:38 +02:00
|
|
|
}
|
|
|
|
free(tmpbuffer);
|
|
|
|
}
|
2008-10-01 23:00:12 +02:00
|
|
|
// load game
|
|
|
|
if(FDSLoad(NULL,fceufp))
|
|
|
|
nesGameType = 4;
|
2008-10-01 07:25:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nesGameType > 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
FCEU_ResetVidSys();
|
|
|
|
PowerNES();
|
|
|
|
FCEU_ResetPalette();
|
|
|
|
FCEU_ResetMessages(); // Save state, status messages, etc.
|
|
|
|
SetSoundVariables();
|
2008-10-22 18:46:44 +02:00
|
|
|
ResetAudio();
|
2008-09-02 03:57:21 +02:00
|
|
|
romLoaded = true;
|
2008-10-01 07:25:38 +02:00
|
|
|
return 1;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaitPrompt("Invalid game file!");
|
|
|
|
romLoaded = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|