2008-09-17 03:54:21 +02:00
|
|
|
/****************************************************************************
|
2008-09-17 04:27:55 +02:00
|
|
|
* Visual Boy Advance GX
|
2008-09-17 03:54:21 +02:00
|
|
|
*
|
|
|
|
* Tantric September 2008
|
|
|
|
*
|
|
|
|
* vbasupport.cpp
|
|
|
|
*
|
|
|
|
* VBA support code
|
|
|
|
***************************************************************************/
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-09-23 01:00:10 +02:00
|
|
|
#include "agb/GBA.h"
|
|
|
|
#include "agb/agbprint.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
#include "Flash.h"
|
|
|
|
#include "Port.h"
|
|
|
|
#include "RTC.h"
|
|
|
|
#include "Sound.h"
|
|
|
|
#include "unzip.h"
|
|
|
|
#include "Util.h"
|
2008-09-23 01:00:10 +02:00
|
|
|
#include "dmg/GB.h"
|
|
|
|
#include "dmg/gbGlobals.h"
|
2008-09-26 08:23:00 +02:00
|
|
|
//#include "dmg/gbSound.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
#include "vba.h"
|
|
|
|
#include "fileop.h"
|
2008-09-29 09:35:26 +02:00
|
|
|
#include "dvd.h"
|
|
|
|
#include "smbop.h"
|
|
|
|
#include "memcardop.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
#include "audio.h"
|
|
|
|
#include "vmmem.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "menudraw.h"
|
2008-09-29 09:35:26 +02:00
|
|
|
#include "gcunzip.h"
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
extern "C"
|
2008-09-17 03:54:21 +02:00
|
|
|
{
|
2008-09-16 07:42:21 +02:00
|
|
|
#include "tbtime.h"
|
2008-09-17 03:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static tb_t start, now;
|
|
|
|
|
|
|
|
u32 loadtimeradjust;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
static u32 autoFrameSkipLastTime = 0;
|
|
|
|
static int frameskipadjust = 0;
|
|
|
|
|
|
|
|
int vAspect = 0;
|
|
|
|
int hAspect = 0;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* VBA Globals
|
|
|
|
***************************************************************************/
|
2008-09-16 07:42:21 +02:00
|
|
|
int RGB_LOW_BITS_MASK=0x821;
|
|
|
|
int systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
|
|
|
|
|
|
|
int systemDebug = 0;
|
|
|
|
int emulating = 0;
|
|
|
|
|
|
|
|
int sensorX = 2047;
|
|
|
|
int sensorY = 2047;
|
|
|
|
|
|
|
|
int systemFrameSkip = 0;
|
|
|
|
bool systemSoundOn = false;
|
|
|
|
int systemVerbose = 0;
|
|
|
|
int cartridgeType = 0;
|
|
|
|
int srcWidth = 0;
|
|
|
|
int srcHeight = 0;
|
|
|
|
int destWidth = 0;
|
|
|
|
int destHeight = 0;
|
|
|
|
int srcPitch = 0;
|
|
|
|
int saveExists = 0;
|
|
|
|
int systemRedShift = 0;
|
|
|
|
int systemBlueShift = 0;
|
|
|
|
int systemGreenShift = 0;
|
|
|
|
int systemColorDepth = 0;
|
|
|
|
u16 systemGbPalette[24];
|
|
|
|
u16 systemColorMap16[0x10000];
|
|
|
|
//u32 systemColorMap32[0x10000];
|
2008-10-02 23:07:38 +02:00
|
|
|
u32 *systemColorMap32 = NULL;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
|
|
|
struct EmulatedSystem emulator =
|
2008-09-17 03:54:21 +02:00
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
false,
|
|
|
|
0
|
|
|
|
};
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* systemGetClock
|
|
|
|
*
|
|
|
|
* Returns number of milliseconds since program start
|
|
|
|
****************************************************************************/
|
|
|
|
u32 systemGetClock( void )
|
|
|
|
{
|
|
|
|
mftb(&now);
|
|
|
|
return tb_diff_msec(&now, &start) - loadtimeradjust;
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
void systemFrame() {}
|
|
|
|
void systemScreenCapture(int a) {}
|
|
|
|
void systemShowSpeed(int speed) {}
|
|
|
|
void systemGbBorderOn() {}
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
bool systemPauseOnFrame()
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
return false;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
2008-09-23 01:00:10 +02:00
|
|
|
/*
|
2008-09-16 07:42:21 +02:00
|
|
|
void GC_Sleep(u32 dwMiliseconds)
|
|
|
|
{
|
|
|
|
int nVBlanks = (dwMiliseconds / 16);
|
|
|
|
while (nVBlanks-- > 0)
|
|
|
|
{
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
|
|
|
}
|
2008-09-23 01:00:10 +02:00
|
|
|
*/
|
2008-09-17 03:54:21 +02:00
|
|
|
void system10Frames(int rate)
|
|
|
|
{
|
|
|
|
if ( cartridgeType == 1 )
|
|
|
|
return;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
u32 time = systemGetClock();
|
|
|
|
u32 diff = time - autoFrameSkipLastTime;
|
|
|
|
int speed = 100;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
if(diff)
|
|
|
|
speed = (1000000/rate)/diff;
|
|
|
|
/* char temp[512];
|
|
|
|
sprintf(temp,"Speed: %i",speed);
|
|
|
|
MENU_DrawString( -1, 450,temp , 1 ); */
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
if(speed >= 98)
|
|
|
|
{
|
|
|
|
frameskipadjust++;
|
|
|
|
|
|
|
|
if(frameskipadjust >= 3)
|
|
|
|
{
|
|
|
|
frameskipadjust=0;
|
|
|
|
if(systemFrameSkip > 0)
|
|
|
|
systemFrameSkip--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(speed < 80)
|
|
|
|
frameskipadjust -= (90 - speed)/5;
|
|
|
|
else if(systemFrameSkip < 9)
|
|
|
|
frameskipadjust--;
|
|
|
|
|
|
|
|
if(frameskipadjust <= -2)
|
|
|
|
{
|
|
|
|
frameskipadjust += 2;
|
|
|
|
if(systemFrameSkip < 9)
|
|
|
|
systemFrameSkip++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
autoFrameSkipLastTime = time;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* System
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void systemGbPrint(u8 *data,int pages,int feed,int palette, int contrast) {}
|
2008-09-23 01:00:10 +02:00
|
|
|
void debuggerOutput(const char *s, u32 addr) {}
|
|
|
|
void (*dbgOutput)(const char *s, u32 addr) = debuggerOutput;
|
2008-09-17 03:54:21 +02:00
|
|
|
void systemMessage(int num, const char *msg, ...) {}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
bool MemCPUReadBatteryFile(char * membuffer, int size)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
if(size == 512 || size == 0x2000)
|
2008-09-17 03:54:21 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
memcpy(eepromData, membuffer, size);
|
2008-09-17 03:54:21 +02:00
|
|
|
}
|
2008-09-29 09:35:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(size == 0x20000)
|
|
|
|
{
|
|
|
|
memcpy(flashSaveMemory, membuffer, 0x20000);
|
|
|
|
flashSetSize(0x20000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(flashSaveMemory, membuffer, 0x10000);
|
|
|
|
flashSetSize(0x10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
extern int gbaSaveType;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
int MemCPUWriteBatteryFile(char * membuffer)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
if(gbaSaveType == 0)
|
2008-09-17 03:54:21 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
if(eepromInUse)
|
|
|
|
gbaSaveType = 3;
|
|
|
|
else
|
|
|
|
switch(saveType)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
gbaSaveType = 1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gbaSaveType = 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-17 03:54:21 +02:00
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
if((gbaSaveType) && (gbaSaveType!=5))
|
2008-09-18 05:12:56 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
// only save if Flash/Sram in use or EEprom in use
|
|
|
|
if(gbaSaveType != 3)
|
|
|
|
{
|
|
|
|
if(gbaSaveType == 2)
|
|
|
|
{
|
|
|
|
memcpy(membuffer, flashSaveMemory, flashSize);
|
|
|
|
result = flashSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy(membuffer, flashSaveMemory, 0x10000);
|
|
|
|
result = 0x10000;
|
|
|
|
}
|
|
|
|
}
|
2008-09-18 05:12:56 +02:00
|
|
|
else
|
2008-09-29 09:35:26 +02:00
|
|
|
{
|
|
|
|
memcpy(membuffer, eepromData, eepromSize);
|
|
|
|
result = eepromSize;
|
|
|
|
}
|
2008-09-18 05:12:56 +02:00
|
|
|
}
|
2008-09-17 03:54:21 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* SetFileBytesWritten
|
|
|
|
* Sets the # of bytes written into a file
|
|
|
|
* Used by GBA.cpp and GB.cpp
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void SetFileBytesWritten(int bytes)
|
|
|
|
{
|
|
|
|
//datasize = bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* LoadBatteryOrState
|
|
|
|
* Load Battery/State file into memory
|
|
|
|
* action = 0 - Load battery
|
|
|
|
* action = 1 - Load state
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool LoadBatteryOrState(int method, int action, bool silent)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
char filepath[1024];
|
|
|
|
bool result = false;
|
2008-09-29 09:35:26 +02:00
|
|
|
int offset = 0;
|
|
|
|
char ext[4];
|
|
|
|
|
|
|
|
if(action == 0)
|
|
|
|
sprintf(ext, "sav");
|
|
|
|
else
|
|
|
|
sprintf(ext, "sgm");
|
2008-09-17 03:54:21 +02:00
|
|
|
|
|
|
|
ShowAction ((char*) "Loading...");
|
|
|
|
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoSaveMethod(); // we use 'Save' because we need R/W
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
AllocSaveBuffer();
|
|
|
|
|
|
|
|
// load the file into savebuffer
|
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
if(method == METHOD_SD || method == METHOD_USB)
|
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
if(ChangeFATInterface(method, NOTSILENT))
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s/%s.%s", ROOTFATDIR, GCSettings.SaveFolder, ROMFilename, ext);
|
|
|
|
offset = LoadBufferFromFAT (filepath, silent);
|
|
|
|
}
|
2008-09-17 03:54:21 +02:00
|
|
|
}
|
2008-09-29 09:35:26 +02:00
|
|
|
else if(method == METHOD_SMB)
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s.%s", GCSettings.SaveFolder, ROMFilename, ext);
|
|
|
|
offset = LoadBufferFromSMB (filepath, silent);
|
|
|
|
}
|
|
|
|
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s.%s", ROMFilename, ext);
|
2008-09-17 03:54:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
if(method == METHOD_MC_SLOTA)
|
|
|
|
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
|
|
|
|
else
|
|
|
|
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
|
|
|
|
}
|
2008-09-17 03:54:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
// load savebuffer into VBA memory
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
|
|
|
if(action == 0)
|
|
|
|
{
|
|
|
|
if(cartridgeType == 1)
|
|
|
|
result = MemgbReadBatteryFile((char *)savebuffer, offset);
|
|
|
|
else
|
|
|
|
result = MemCPUReadBatteryFile((char *)savebuffer, offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = emulator.emuReadMemState((char *)savebuffer, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeSaveBuffer();
|
|
|
|
|
|
|
|
if(!silent && !result)
|
|
|
|
{
|
|
|
|
if(offset == 0)
|
|
|
|
{
|
|
|
|
if(action == 0)
|
|
|
|
WaitPrompt ((char*) "Save file not found");
|
|
|
|
else
|
|
|
|
WaitPrompt ((char*) "State file not found");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(action == 0)
|
|
|
|
WaitPrompt ((char*) "Invalid save file");
|
|
|
|
else
|
|
|
|
WaitPrompt ((char*) "Invalid state file");
|
|
|
|
}
|
|
|
|
}
|
2008-09-17 03:54:21 +02:00
|
|
|
return result;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SaveBatteryOrState
|
|
|
|
* Save Battery/State file into memory
|
|
|
|
* action = 0 - Save battery
|
|
|
|
* action = 1 - Save state
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
bool SaveBatteryOrState(int method, int action, bool silent)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
char filepath[1024];
|
|
|
|
bool result = false;
|
2008-09-29 09:35:26 +02:00
|
|
|
int offset = 0;
|
|
|
|
char ext[4];
|
|
|
|
int datasize = 0; // we need the actual size of the data written
|
|
|
|
|
|
|
|
if(action == 0)
|
|
|
|
sprintf(ext, "sav");
|
|
|
|
else
|
|
|
|
sprintf(ext, "sgm");
|
2008-09-17 03:54:21 +02:00
|
|
|
|
|
|
|
ShowAction ((char*) "Saving...");
|
|
|
|
|
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoSaveMethod(); // we use 'Save' because we need R/W
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
AllocSaveBuffer();
|
|
|
|
|
|
|
|
// put VBA memory into savebuffer, sets datasize to size of memory written
|
|
|
|
if(action == 0)
|
2008-09-17 03:54:21 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
if(cartridgeType == 1)
|
|
|
|
datasize = MemgbWriteBatteryFile((char *)savebuffer);
|
|
|
|
else
|
|
|
|
datasize = MemCPUWriteBatteryFile((char *)savebuffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool written = emulator.emuWriteMemState((char *)savebuffer, SAVEBUFFERSIZE);
|
|
|
|
// we really should set datasize to the exact memory size written
|
|
|
|
// but instead we'll set it at 128K - although much of it will go unused
|
|
|
|
if(written)
|
|
|
|
datasize = (512*256);
|
2008-09-17 03:54:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
// write savebuffer into file
|
|
|
|
if(datasize > 0)
|
2008-09-18 05:12:56 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
if(method == METHOD_SD || method == METHOD_USB)
|
|
|
|
{
|
|
|
|
if(ChangeFATInterface(method, NOTSILENT))
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s/%s.%s", ROOTFATDIR, GCSettings.SaveFolder, ROMFilename, ext);
|
|
|
|
offset = SaveBufferToFAT (filepath, datasize, silent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(method == METHOD_SMB)
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s.%s", GCSettings.SaveFolder, ROMFilename, ext);
|
|
|
|
offset = SaveBufferToSMB (filepath, datasize, silent);
|
|
|
|
}
|
|
|
|
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s.%s", ROMFilename, ext);
|
|
|
|
|
|
|
|
if(method == METHOD_MC_SLOTA)
|
|
|
|
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent);
|
|
|
|
else
|
|
|
|
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(offset > 0)
|
|
|
|
{
|
|
|
|
if(!silent)
|
|
|
|
WaitPrompt ((char*) "Save successful");
|
|
|
|
result = true;
|
|
|
|
}
|
2008-09-18 05:12:56 +02:00
|
|
|
}
|
2008-09-29 09:35:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!silent)
|
|
|
|
WaitPrompt((char *)"No data to save!");
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeSaveBuffer();
|
2008-09-17 03:54:21 +02:00
|
|
|
|
|
|
|
return result;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Sound
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void systemWriteDataToSoundBuffer()
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
MIXER_AddSamples((u8 *)soundFinalWave, (cartridgeType == 1));
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
bool systemSoundInit()
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
return true;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool systemCanChangeSoundQuality()
|
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
return true;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
void systemSoundPause() {}
|
|
|
|
void systemSoundResume() {}
|
|
|
|
void systemSoundReset() {}
|
|
|
|
void systemSoundShutdown() {}
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* systemReadJoypads
|
|
|
|
****************************************************************************/
|
|
|
|
bool systemReadJoypads()
|
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
return true;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 systemReadJoypad(int which)
|
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
return GetJoy();
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* systemDrawScreen
|
|
|
|
****************************************************************************/
|
|
|
|
void systemDrawScreen()
|
|
|
|
{
|
2008-09-17 03:54:21 +02:00
|
|
|
// GB / GBC Have oodles of time - so sync on VSync
|
|
|
|
GX_Render( srcWidth, srcHeight, pix, srcPitch );
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
#ifdef HW_RVL
|
2008-09-16 07:42:21 +02:00
|
|
|
VIDEO_WaitVSync ();
|
2008-09-17 03:54:21 +02:00
|
|
|
#else
|
|
|
|
if ( cartridgeType == 1 )
|
|
|
|
{
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
|
|
|
#endif
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 10:10:36 +02:00
|
|
|
extern bool gbUpdateSizes();
|
2008-09-29 09:35:26 +02:00
|
|
|
bool LoadGBROM(int method)
|
2008-09-26 10:10:36 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
// cleanup GB memory
|
2008-09-26 10:10:36 +02:00
|
|
|
if(gbRom != NULL)
|
|
|
|
gbCleanUp();
|
2008-09-29 09:35:26 +02:00
|
|
|
|
|
|
|
gbRom = (u8 *)malloc(1024*1024*4); // allocate 4 MB to GB ROM
|
2008-09-26 10:10:36 +02:00
|
|
|
|
|
|
|
systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED;
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case METHOD_SD:
|
|
|
|
case METHOD_USB:
|
|
|
|
gbRomSize = LoadFATFile ((char *)gbRom, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case METHOD_DVD:
|
|
|
|
gbRomSize = LoadDVDFile ((unsigned char *)gbRom, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case METHOD_SMB:
|
|
|
|
gbRomSize = LoadSMBFile ((char *)gbRom, 0);
|
|
|
|
break;
|
|
|
|
}
|
2008-09-26 10:10:36 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
if(!gbRom)
|
|
|
|
return false;
|
2008-09-26 10:10:36 +02:00
|
|
|
|
|
|
|
return gbUpdateSizes();
|
|
|
|
}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
bool LoadVBAROM(int method)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
int type = 0;
|
|
|
|
bool loaded = false;
|
2008-09-26 08:23:00 +02:00
|
|
|
|
|
|
|
// image type (checks file extension)
|
2008-09-29 09:35:26 +02:00
|
|
|
if(utilIsGBAImage(filelist[selection].filename))
|
2008-09-26 08:23:00 +02:00
|
|
|
type = 2;
|
2008-09-29 09:35:26 +02:00
|
|
|
else if(utilIsGBImage(filelist[selection].filename))
|
2008-09-26 08:23:00 +02:00
|
|
|
type = 1;
|
2008-09-29 09:35:26 +02:00
|
|
|
else if(utilIsZipFile(filelist[selection].filename))
|
|
|
|
{
|
|
|
|
// we need to check the file extension of the first file in the archive
|
|
|
|
char * zippedFilename = GetFirstZipFilename (method);
|
|
|
|
|
|
|
|
if(strlen(zippedFilename) > 0)
|
|
|
|
{
|
|
|
|
if(utilIsGBAImage(zippedFilename))
|
|
|
|
type = 2;
|
|
|
|
else if(utilIsGBImage(zippedFilename))
|
|
|
|
type = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// leave before we do anything
|
|
|
|
if(type != 1 && type != 2)
|
|
|
|
{
|
|
|
|
WaitPrompt((char *)"Unknown game image!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
cartridgeType = 0;
|
|
|
|
srcWidth = 0;
|
|
|
|
srcHeight = 0;
|
|
|
|
destWidth = 0;
|
|
|
|
destHeight = 0;
|
|
|
|
srcPitch = 0;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
2008-09-26 08:23:00 +02:00
|
|
|
case 2:
|
2008-09-16 07:42:21 +02:00
|
|
|
//WaitPrompt("GameBoy Advance Image");
|
|
|
|
cartridgeType = 2;
|
|
|
|
emulator = GBASystem;
|
|
|
|
srcWidth = 240;
|
|
|
|
srcHeight = 160;
|
2008-09-29 09:35:26 +02:00
|
|
|
loaded = VMCPULoadROM(method);
|
2008-09-17 03:54:21 +02:00
|
|
|
// Actual Visual Aspect is 1.57
|
2008-09-16 07:42:21 +02:00
|
|
|
hAspect = 70;
|
|
|
|
vAspect = 46;
|
|
|
|
srcPitch = 484;
|
|
|
|
soundQuality = 2;
|
|
|
|
soundBufferLen = 1470;
|
|
|
|
cpuSaveType = 0;
|
|
|
|
break;
|
|
|
|
|
2008-09-26 08:23:00 +02:00
|
|
|
case 1:
|
2008-09-16 07:42:21 +02:00
|
|
|
//WaitPrompt("GameBoy Image");
|
|
|
|
cartridgeType = 1;
|
|
|
|
emulator = GBSystem;
|
|
|
|
srcWidth = 160;
|
|
|
|
srcHeight = 144;
|
2008-09-29 09:35:26 +02:00
|
|
|
loaded = LoadGBROM(method);
|
2008-09-17 03:54:21 +02:00
|
|
|
// Actual physical aspect is 1.0
|
2008-09-16 07:42:21 +02:00
|
|
|
hAspect = 60;
|
|
|
|
vAspect = 46;
|
|
|
|
srcPitch = 324;
|
|
|
|
soundQuality = 1;
|
|
|
|
soundBufferLen = 1470 * 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
if(!loaded)
|
2008-09-16 07:42:21 +02:00
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
WaitPrompt((char *)"Error loading game!");
|
|
|
|
return false;
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-29 09:35:26 +02:00
|
|
|
// Set defaults
|
|
|
|
flashSetSize(0x20000); // 128K saves
|
|
|
|
rtcEnable(true);
|
|
|
|
agbPrintEnable(false);
|
|
|
|
soundOffFlag = false;
|
|
|
|
soundLowPass = true;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
// Setup GX
|
|
|
|
GX_Render_Init( srcWidth, srcHeight, hAspect, vAspect );
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
if ( cartridgeType == 1 )
|
|
|
|
{
|
|
|
|
gbSoundReset();
|
|
|
|
gbSoundSetQuality(soundQuality);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
soundSetQuality(soundQuality);
|
|
|
|
CPUInit("/VBA/BIOS/BIOS.GBA", 1);
|
|
|
|
CPUReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
soundVolume = 0;
|
|
|
|
systemSoundOn = true;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
soundInit();
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
emulating = 1;
|
2008-09-23 01:00:10 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
// reset frameskip variables
|
|
|
|
autoFrameSkipLastTime = frameskipadjust = systemFrameSkip = 0;
|
2008-09-16 07:42:21 +02:00
|
|
|
|
2008-09-29 09:35:26 +02:00
|
|
|
// Start system clock
|
|
|
|
mftb(&start);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-09-16 07:42:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-17 03:54:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* EEPROM
|
|
|
|
****************************************************************************/
|
|
|
|
int systemGetSensorX()
|
|
|
|
{
|
|
|
|
return sensorX;
|
|
|
|
}
|
|
|
|
|
|
|
|
int systemGetSensorY()
|
|
|
|
{
|
|
|
|
return sensorY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void systemUpdateMotionSensor() {}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Palette
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-09-16 07:42:21 +02:00
|
|
|
void InitialisePalette()
|
|
|
|
{
|
|
|
|
int i;
|
2008-09-17 03:54:21 +02:00
|
|
|
// Build GBPalette
|
2008-09-16 07:42:21 +02:00
|
|
|
for( i = 0; i < 24; )
|
|
|
|
{
|
|
|
|
systemGbPalette[i++] = (0x1f) | (0x1f << 5) | (0x1f << 10);
|
|
|
|
systemGbPalette[i++] = (0x15) | (0x15 << 5) | (0x15 << 10);
|
|
|
|
systemGbPalette[i++] = (0x0c) | (0x0c << 5) | (0x0c << 10);
|
|
|
|
systemGbPalette[i++] = 0;
|
|
|
|
}
|
2008-09-17 03:54:21 +02:00
|
|
|
// Set palette etc - Fixed to RGB565
|
2008-09-16 07:42:21 +02:00
|
|
|
systemColorDepth = 16;
|
|
|
|
systemRedShift = 11;
|
|
|
|
systemGreenShift = 6;
|
|
|
|
systemBlueShift = 0;
|
|
|
|
for(i = 0; i < 0x10000; i++)
|
|
|
|
{
|
|
|
|
systemColorMap16[i] =
|
|
|
|
((i & 0x1f) << systemRedShift) |
|
|
|
|
(((i & 0x3e0) >> 5) << systemGreenShift) |
|
|
|
|
(((i & 0x7c00) >> 10) << systemBlueShift);
|
|
|
|
}
|
|
|
|
}
|