fceugx/source/ngc/fceuload.cpp

156 lines
3.1 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
*
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
#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;
#define SAMPLERATE 48000
2009-10-02 00:21:25 +02:00
int GCMemROM(int size)
{
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;
romLoaded = false;
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;
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)
{
int biosSize = 0;
2009-03-28 18:23:08 +01:00
char * tmpbuffer = (char *) memalign(32, 64 * 1024);
char filepath[1024];
2009-10-02 00:21:25 +02:00
if (MakeFilePath(filepath, FILE_FDSBIOS))
{
2009-10-02 00:21:25 +02:00
biosSize = LoadFile(tmpbuffer, filepath, 0, SILENT);
}
2009-03-28 18:23:08 +01:00
if (biosSize == 8192)
{
memcpy(FDSBIOS, tmpbuffer, 8192);
}
else
{
2009-03-28 18:23:08 +01:00
if (biosSize > 0)
ErrorPrompt("FDS BIOS file is invalid!");
else
ErrorPrompt("FDS BIOS file not found!");
}
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
}
}
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-03-28 18:23:08 +01:00
ErrorPrompt("Invalid game file!");
romLoaded = false;
return 0;
}
2008-09-02 03:57:21 +02:00
}