source refactor

This commit is contained in:
dborth 2008-09-02 01:55:12 +00:00
parent 8cdf9df10c
commit 47fb364fc0
292 changed files with 16237 additions and 43974 deletions

View File

@ -1,108 +0,0 @@
/****************************************************************************
* audio.c
*
* Gamecube audio driver
****************************************************************************/
#include <gccore.h>
#define SAMPLERATE 48000
static unsigned char audiobuffer[2][64 * 1024] __attribute__((__aligned__(32)));
/*** Allow for up to 1 full second ***/
/****************************************************************************
* AudioSwitchBuffers
*
* Manages which buffer is played next
****************************************************************************/
static int isWriting = 0; /*** Bool for buffer writes ***/
static int buffSize[2]; /*** Hold size of current buffer ***/
static int whichab = 0; /*** Which Audio Buffer is in use ***/
static int isPlaying; /*** Is Playing ***/
static void AudioSwitchBuffers()
{
if ( buffSize[whichab] ) {
AUDIO_StopDMA();
AUDIO_InitDMA((u32)audiobuffer[whichab], buffSize[whichab]);
DCFlushRange(&audiobuffer[whichab], buffSize[whichab]);
AUDIO_StartDMA();
isPlaying = 0;
}
whichab ^= 1;
buffSize[whichab] = 0;
}
void InitialiseSound()
{
AUDIO_Init(NULL); /*** Start audio subsystem ***/
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
AUDIO_RegisterDMACallback( AudioSwitchBuffers );
buffSize[0] = buffSize[1] = 0;
}
void StartAudio()
{
AUDIO_StartDMA();
}
void StopAudio()
{
AUDIO_StopDMA();
}
static inline unsigned short FLIP16(unsigned short b)
{
return((b<<8)|((b>>8)&0xFF));
}
static inline u32 FLIP32(u32 b)
{
return( (b<<24) | ((b>>8)&0xFF00) | ((b<<8)&0xFF0000) | ((b>>24)&0xFF) );
}
/****************************************************************************
* Audio incoming is monaural
*
* PlaySound will simply mix to get it right
****************************************************************************/
#define AUDIOBUFFER ((50 * SAMPLERATE) / 1000 ) << 4
static int isPlaying = 0;
static short MBuffer[ 8 * 96000 / 50 ];
void PlaySound( unsigned int *Buffer, int count )
{
int P;
unsigned short *s = (unsigned short *)&MBuffer[0];
unsigned int *d = (unsigned int *)&audiobuffer[whichab][buffSize[whichab]];
unsigned int c;
int ms;
isWriting = 1;
for ( P = 0; P < count; P++ ) {
MBuffer[P] = Buffer[P];
}
/*** Now do Mono - Stereo Conversion ***/
ms = count;
do
{
c = 0xffff & *s++;
*d++ = (c | (c<<16));
} while(--ms);
buffSize[whichab] += ( count << 2 );
/*** This is the kicker for the entire audio loop ***/
if ( isPlaying == 0 )
{
if ( buffSize[whichab] > AUDIOBUFFER )
{
isPlaying = 1;
AudioSwitchBuffers();
}
}
isWriting = 0;
}

View File

@ -1,30 +0,0 @@
/****************************************************************************
* Common module
****************************************************************************/
#include "../../driver.h"
#include "../common/config.h"
/* Message logging(non-netplay messages, usually) for all. */
extern int NoWaiting;
extern FCEUGI *GI;
void DSMFix(unsigned int msg);
void StopSound(void);
extern int eoptions;
#define EO_BGRUN 1
#define EO_CPALETTE 4
#define EO_NOSPRLIM 8
#define EO_FSAFTERLOAD 32
#define EO_FOAFTERSTART 64
#define EO_NOTHROTTLE 128
#define EO_CLIPSIDES 256
#define EO_SNAPNAME 512
#define EO_HIDEMENU 2048
#define EO_HIGHPRIO 4096
#define EO_FORCEASPECT 8192
#define EO_FORCEISCALE 16384
#define EO_NOFOURSCORE 32768

View File

@ -1,243 +0,0 @@
/****************************************************************************
* Drive Code Sending
*
* These codes are courtesy of Ninjamod
* and are used with permission.
*
* http://www.ninjamod.com
****************************************************************************/
#include <gccore.h>
volatile long *dvdio=(volatile long *)0xCC006000;
unsigned int Drive04[] = {
0x40D000,
12,0xf4e1a538,0xcfdc0080,0xf4712aea,
12,0x08806ef4,0xe1135fcf,0xdc6e80a0,
12,0xf9b801f4,0xe1295fcf,0xf47447d0,
12,0x40f7204c,0x80f474d6,0x9c08f720,
12,0xd6fcf474,0x28ae08f7,0x20d2fc80,
12,0x04c4dafc,0xf4747ed4,0x08f000c8,
12,0xdafcf500,0x01e803fc,0xe200a0f4,
12,0x7400ec40,0xf51002f5,0x1003f510,
12,0x04f51005,0xf51006f5,0x1007f510,
12,0x08f51009,0xf5100af5,0x100bf510,
12,0x0cf5100d,0xc8dafcf5,0x0002e803,
12,0xfc3d01f4,0x74f9ec40,0x8002f020,
12,0xc88480c0,0x9c81dcb4,0x80f53000,
12,0xf444f9d1,0x40f8aa00,0x10f4d0f4,
12,0xd140f001,0xdcb480f5,0x3000f748,
12,0xaa00e907,0xf4c4f9d1,0x4010fed8,
12,0x32e81df7,0x48a800e8,0x26f748ab,
12,0x00e820f7,0x48e100e8,0x1af748ee,
12,0x00e83bd8,0x55e82ffe,0x7104fd20,
12,0x00f45100,0xd240a0f5,0x1000fef2,
12,0xf9f4d200,0xd2407104,0xfd0a00f2,
12,0x49fd0500,0x5104f236,0xfef721bc,
12,0xfff731bc,0xfffeccb5,0x80fd5300,
12,0xea0cccb5,0x80c4b081,0xccb680c4,
12,0x9481dcb4,0x80f8e000,0x10a0f510,
12,0x01f51002,0xf51003fe,0xccdafcf7,
12,0x00feffc4,0xdafccc44,0xfcf700fe,
12,0xffc444fc,0xf27cd004,0xcc5b80d8,
12,0x01e9027c,0x04f47585,0xd1405120,
12,0x7134f47d,0xc18508e9,0x1b8000cd,
12,0xdafcd800,0xe906f701,0xf7ffea03,
12,0xf50908c5,0xdafcf475,0xf8d14014,
12,0xfe8001ea,0xe2f710ff,0xf721f749,
12,0x0806e905,0x8502f511,0x0121f479,
12,0x00f000e9,0x0e8000f4,0xc9f8d140,
12,0xd900e803,0xf5100921,0xd906e90f,
12,0x6106f4c8,0xf8d140d8,0x00e802d5,
12,0x064106f4,0xe06fdccf,0xccdafcf7,
12,0x00fdffc4,0xdafccc44,0xfcf700fe,
12,0xffc444fc,0xf27cd004,0xcc5b80d8,
12,0x01e9027c,0x04f475ed,0xd1405120,
12,0xfef4e05c,0xcbcf0000,0x740a0800,
12,0x01000000,0x00000000,0x00000080,
12,0x00000000,0x00000000,0x00000000,
00,0x00804c,
03,0x00D04000,
99 };
unsigned int Drive06[] = {
0x40D000,
12,0xf4e1a538,0xc7dc0080,0xf471c8e9,
12,0x08806ef4,0xe11a5fc7,0xdc6e80a0,
12,0xf9ac01f4,0xe1305fc7,0xf47447d0,
12,0x40f7204c,0x80f47442,0x9d08f720,
12,0xd6fcf474,0x45b108f7,0x20d2fc80,
12,0x04c4dafc,0xf4741ed4,0x08f000c8,
12,0xdafcf500,0x01e803fc,0xe200a0f4,
12,0x7400ec40,0xf51002f5,0x1003f510,
12,0x04f51005,0xf51006f5,0x1007f510,
12,0x08f51009,0xf5100af5,0x100bf510,
12,0x0cf5100d,0xc8dafcf5,0x0002e803,
12,0xfc3d01f4,0x7402ed40,0x8002f020,
12,0xc87880c0,0x9081dca8,0x80f53000,
12,0xf444f9d1,0x40f8aa00,0x10f4d0f4,
12,0xd140f001,0xdca880f5,0x3000f748,
12,0xaa00e907,0xf4c4f9d1,0x4010fed8,
12,0x32e81df7,0x48a800e8,0x26f748ab,
12,0x00e820f7,0x48e100e8,0x1af748ee,
12,0x00e83bd8,0x55e82ffe,0x7104fd20,
12,0x00f45100,0xd240a0f5,0x1000fef2,
12,0xf9f4d200,0xd2407104,0xfd0a00f2,
12,0x49fd0500,0x5104f236,0xfef721bc,
12,0xfff731bc,0xfffecca9,0x80fd5300,
12,0xea0ccca9,0x80c4a481,0xccaa80c4,
12,0x8881dca8,0x80f8e000,0x10a0f510,
12,0x01f51002,0xf51003fe,0xccdafcf7,
12,0x00feffc4,0xdafccc44,0xfcf700fe,
12,0xffc444fc,0xf27cd004,0xcc5b80d8,
12,0x01e9027c,0x04f47585,0xd1405120,
12,0x7134f47d,0xb98508e9,0x1b8000cd,
12,0xdafcd800,0xe906f701,0xf7ffea03,
12,0xf50908c5,0xdafcf475,0xf8d14014,
12,0xfe8001ea,0xe2f710ff,0xf721f749,
12,0x0806e905,0x8502f511,0x0121f479,
12,0x00f000e9,0x0e8000f4,0xc9f8d140,
12,0xd900e803,0xf5100921,0xd906e90f,
12,0x6106f4c8,0xf8d140d8,0x00e802d5,
12,0x064106f4,0xe08cdfc7,0xccdafcf7,
12,0x00fdffc4,0xdafccc44,0xfcf700fe,
12,0xffc444fc,0xf27cd004,0xcc5b80d8,
12,0x01e9027c,0x04f475ed,0xd1405120,
12,0xfef4e0de,0xcbc70000,0x740a0800,
12,0x01000000,0x00000000,0x00000080,
12,0x00000000,0x00000000,0x00000000,
00,0x00804c,
03,0x00D04000,
99 };
unsigned int Drive08[] = {
0x40D000,
12,0xf4e1a538,0xcfdc0080,0xf4717cea,
12,0x08806ef4,0xe1135fcf,0xdc6e80a0,
12,0xf9b601f4,0xe1295fcf,0xf47447d0,
12,0x40f7204c,0x80f47432,0x9d08f720,
12,0xd6fcf474,0x75ae08f7,0x20d2fc80,
12,0x04c4dafc,0xf474d9d4,0x08f000c8,
12,0xdafcf500,0x01e803fc,0xe200a0f4,
12,0x7400ec40,0xf51002f5,0x1003f510,
12,0x04f51005,0xf51006f5,0x1007f510,
12,0x08f51009,0xf5100af5,0x100bf510,
12,0x0cf5100d,0xc8dafcf5,0x0002e803,
12,0xfc3d01f4,0x74f5ec40,0x8002f020,
12,0xc88080c0,0x9881dcb0,0x80f53000,
12,0xf444f9d1,0x40f8aa00,0x10f4d0f4,
12,0xd140f001,0xdcb080f5,0x3000f748,
12,0xaa00e907,0xf4c4f9d1,0x4010fed8,
12,0x32e81df7,0x48a800e8,0x26f748ab,
12,0x00e820f7,0x48e100e8,0x1af748ee,
12,0x00e83bd8,0x55e82ffe,0x7104fd20,
12,0x00f45100,0xd240a0f5,0x1000fef2,
12,0xf9f4d200,0xd2407104,0xfd0a00f2,
12,0x49fd0500,0x5104f236,0xfef721bc,
12,0xfff731bc,0xfffeccb1,0x80fd5300,
12,0xea0cccb1,0x80c4ac81,0xccb280c4,
12,0x9081dcb0,0x80f8e000,0x10a0f510,
12,0x01f51002,0xf51003fe,0xccdafcf7,
12,0x00feffc4,0xdafccc44,0xfcf700fe,
12,0xffc444fc,0xf27cd004,0xcc5b80d8,
12,0x01e9027c,0x04f47585,0xd1405120,
12,0x7134f47d,0xc18508e9,0x1b8000cd,
12,0xdafcd800,0xe906f701,0xf7ffea03,
12,0xf50908c5,0xdafcf475,0xf8d14014,
12,0xfe8001ea,0xe2f710ff,0xf721f749,
12,0x0806e905,0x8502f511,0x0121f479,
12,0x00f000e9,0x0e8000f4,0xc9f8d140,
12,0xd900e803,0xf5100921,0xd906e90f,
12,0x6106f4c8,0xf8d140d8,0x00e802d5,
12,0x064106f4,0xe0bcdccf,0xccdafcf7,
12,0x00fdffc4,0xdafccc44,0xfcf700fe,
12,0xffc444fc,0xf27cd004,0xcc5b80d8,
12,0x01e9027c,0x04f475ed,0xd1405120,
12,0xfef4e0b5,0xcbcf0000,0x740a0800,
12,0x01000000,0x00000000,0x00000080,
12,0x00000000,0x00000000,0x00000000,
00,0x00804c,
03,0x00D04000,
99 };
/****************************************************************************
* Drivecode
*
* Dumb C Implementation of Anaconda Send Code
****************************************************************************/
void SendDriveCode( int model )
{
int i = 0;
int length;
unsigned int cmd = 0xfe010100;
unsigned int loadaddress;
unsigned int *DriveCode;
unsigned char debug[100];
switch( model )
{ case 4: DriveCode = (unsigned int *)Drive04; break;
case 6: DriveCode = (unsigned int *)Drive06; break;
case 8: DriveCode = (unsigned int *)Drive08; break;
default: return;
}
loadaddress = DriveCode[i++];
length = DriveCode[i++];
while ( length == 12 )
{
/*** Address Select ***/
dvdio[0] |= 0x14;
dvdio[1] = 0;
dvdio[2] = cmd;
dvdio[3] = loadaddress;
dvdio[4] = (length << 16);
dvdio[5] = 0;
dvdio[6] = 0;
dvdio[7] = 3;
while ( dvdio[7] & 1 );
dvdio[0] |= 0x14;
dvdio[1] = 0;
dvdio[2] = DriveCode[i++];
dvdio[3] = DriveCode[i++];
dvdio[4] = DriveCode[i++];
dvdio[5] = 0;
dvdio[6] = 0;
dvdio[7] = 1;
while ( dvdio[7] & 1 );
loadaddress += length;
length = DriveCode[i++];
}
loadaddress = DriveCode[i++];
length = DriveCode[i++];
/*** Do SendDriveCommand End ***/
dvdio[0] |= 0x14;
dvdio[1] = 0;
dvdio[2] = cmd;
dvdio[3] = loadaddress;
dvdio[4] = (length << 16);
dvdio[5] = 0;
dvdio[6] = 0;
dvdio[7] = 3;
while ( dvdio[7] & 1 );
dvdio[0] |= 0x14;
dvdio[1] = 0;
dvdio[2] = DriveCode[i++];
dvdio[3] = 0;
dvdio[4] = 0;
dvdio[5] = 0;
dvdio[6] = 0;
dvdio[7] = 1;
while ( dvdio[7] & 1 );
}

View File

@ -1,888 +0,0 @@
/****************************************************************************
* DVD.CPP
*
* This module manages all dvd i/o etc.
* There is also a simple ISO9660 parser included.
****************************************************************************/
#include <gccore.h>
#include <ogcsys.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gctypes.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <unistd.h>
#include "gcdvd.h"
#include "iplfont.h"
#ifdef __gamecube__
#include "sz.h"
#endif
FILE *filehandle = NULL;
#define MAXFILES 1000
// From libfat MAX_FILENAME_LENGTH
#define MAX_PATH_LEN 768
/*typedef struct {
char filename[MAX_PATH_LEN+1];
u64 offset;
unsigned int length;
char flags;
}FILEENTRIES;*/
/*** Simplified Directory Entry Record
I only care about a couple of values ***/
#define RECLEN 0
#define EXTENT 6
#define FILE_LENGTH 14
#define FILE_FLAGS 25
#define FILENAME_LENGTH 32
#define FILENAME 33
#define PAGESIZE 11
#define FCEUDIR "fceu"
#define ROMSDIR "roms"
FILEENTRIES filelist[MAXFILES];
int maxfiles = 0;
int offset = 0;
int selection = 0;
/*** DVD Read Buffer ***/
unsigned char readbuffer[2048] ATTRIBUTE_ALIGN(32);
volatile long *dvd=(volatile long *)0xCC006000;
extern void SendDriveCode( int model );
extern int font_height;
extern bool isZipFile();
extern int unzipDVDFile(unsigned char *outbuffer, unsigned int discoffset, unsigned int length);
//extern void writex(int x, int y, int sx, int sy, char *string, unsigned int selected);
extern unsigned char *nesromptr;
extern int IsXenoGCImage( char *buffer );
int LoadDVDFile( unsigned char *buffer );
void GetSDInfo ();
extern u8 ChosenSlot;
/** true if we the emulator is running on a wii **/
extern bool isWii;
extern int WiiSD_Available;
u8 UseSDCARD = 0;
u8 UseWiiSDCARD = 0;
char rootSDdir[MAX_PATH_LEN];
int haveSDdir = 0;
int sdslot = 0;
/****************************************************************************
* DVD Lowlevel Functions
*
* These are here simply because the same functions in libogc are not
* exposed to the user
****************************************************************************/
void dvd_inquiry() {
dvd[0] = 0x2e;
dvd[1] = 0;
dvd[2] = 0x12000000;
dvd[3] = 0;
dvd[4] = 0x20;
dvd[5] = 0x80000000;
dvd[6] = 0x20;
dvd[7] = 3;
while( dvd[7] & 1 );
DCFlushRange((void *)0x80000000, 32);
/*** Get Drive Type ***/
unsigned char *inquiry=(unsigned char *)0x80000004;
int driveid = (int)inquiry[2];
/*** Make sure it's one I now about ***/
if ( ( driveid != 4 ) && ( driveid != 6 ) && ( driveid != 8 ) ) {
isWii = true; // Wii in GC mode
}
}
void dvd_unlock() {
dvd[0] |= 0x00000014;
dvd[1] = 0x00000000;
dvd[2] = 0xFF014D41;
dvd[3] = 0x54534849;
dvd[4] = 0x54410200;
dvd[7] = 1;
while ((dvd[0] & 0x14) == 0) { }
dvd[0] |= 0x00000014;
dvd[1] = 0x00000000;
dvd[2] = 0xFF004456;
dvd[3] = 0x442D4741;
dvd[4] = 0x4D450300;
dvd[7] = 1;
while ((dvd[0] & 0x14) == 0) { }
}
void dvd_extension()
{
dvd[0] = 0x2E;
dvd[1] = 0;
dvd[2] = 0x55010000;
dvd[3] = 0;
dvd[4] = 0;
dvd[5] = 0;
dvd[6] = 0;
dvd[7] = 1; // enable reading!
while (dvd[7] & 1);
}
#define DEBUG_STOP_DRIVE 0
#define DEBUG_START_DRIVE 0x100
#define DEBUG_ACCEPT_COPY 0x4000
#define DEBUG_DISC_CHECK 0x8000
void dvd_motor_on_extra()
{
dvd[0] = 0x2e;
dvd[1] = 0;
dvd[2] = 0xfe110000 | DEBUG_START_DRIVE | DEBUG_ACCEPT_COPY | DEBUG_DISC_CHECK;
dvd[3] = 0;
dvd[4] = 0;
dvd[5] = 0;
dvd[6] = 0;
dvd[7] = 1;
while ( dvd[7] & 1 );
}
void dvd_motor_off( )
{
dvd[0] = 0x2e;
dvd[1] = 0;
dvd[2] = 0xe3000000;
dvd[3] = 0;
dvd[4] = 0;
dvd[5] = 0;
dvd[6] = 0;
dvd[7] = 1; // Do immediate
while (dvd[7] & 1);
/*** PSO Stops blackscreen at reload ***/
dvd[0] = 0x14;
dvd[1] = 0;
}
void dvd_setstatus()
{
dvd[0] = 0x2E;
dvd[1] = 0;
dvd[2] = 0xee060300;
dvd[3] = 0;
dvd[4] = 0;
dvd[5] = 0;
dvd[6] = 0;
dvd[7] = 1; // enable reading!
while (dvd[7] & 1);
}
unsigned int dvd_read_id(void *dst)
{
if ((((int)dst) & 0xC0000000) == 0x80000000) // cached?
DCInvalidateRange((void *)dst, 0x20);
dvd[0] = 0x2E;
dvd[1] = 0;
dvd[2] = 0xA8000040;
dvd[3] = 0;
dvd[4] = 0x20;
dvd[5] = (unsigned long)dst;
dvd[6] = 0x20;
dvd[7] = 3; // enable reading!
while (dvd[7] & 1);
if (dvd[0] & 0x4)
return 1;
return 0;
}
unsigned int dvd_read(void *dst, unsigned int len, u64 offset) {
unsigned char* buffer = (unsigned char*)(unsigned int)readbuffer;
if (len > 2048)
return 0;
DCInvalidateRange((void *) buffer, len);
// don't read past 8,543,666,176 (DVD9)
if (offset < 0x57057C00 || (isWii == true && offset < 0x1FD3E0000LL)) {
offset >>= 2;
dvd[0] = 0x2E;
dvd[1] = 0;
dvd[2] = 0xA8000000;
dvd[3] = (u32)offset;
dvd[4] = len;
dvd[5] = (unsigned long)buffer;
dvd[6] = len;
dvd[7] = 3; // enable reading!
while (dvd[7] & 1);
memcpy (dst, buffer, len);
} else // Let's not read past end of DVD
return 0;
if (dvd[0] & 0x4) /* Ensure it has completed */
return 0;
return 1;
}
void dvd_reset(void)
{
int i;
*(unsigned long*)0xcc006004 = 2;
unsigned long v = *(unsigned long*)0xcc003024;
*(unsigned long*)0xcc003024 = (v &~4) | 1;
for ( i = 0; i < 10000; i++ );
*(unsigned long*)0xcc003024 = v | 5;
}
/****************************************************************************
* ISO Parsing Functions
****************************************************************************/
#define PVDROOT 0x9c
static int IsJoliet = 0;
static u64 rootdir = 0;
static int rootdirlength = 0;
int IsPVD() {
int sector = 16;
u32 rootdir32;
rootdir = rootdirlength = 0;
IsJoliet = -1;
/*** Read the ISO section looking for a valid
Primary Volume Decriptor.
Spec says first 8 characters are id ***/
// Look for Joliet PVD first
while ( sector < 32 ) {
int res = dvd_read( &readbuffer, 2048, (u64)sector << 11 );
if (res) {
if ( memcmp( &readbuffer, "\2CD001\1", 8 ) == 0 ) {
memcpy(&rootdir32, &readbuffer[PVDROOT + EXTENT], 4);
rootdir = (u64)rootdir32;
rootdir <<= 11;
memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
IsJoliet = 1;
break;
}
} else
return 0;
sector++;
}
if (IsJoliet > 0)
return 1;
sector = 16;
// Look for standard ISO9660 PVD
while ( sector < 32 ) {
int res = dvd_read( &readbuffer, 2048, (u64)sector << 11 );
if (res) {
if ( memcmp( &readbuffer, "\1CD001\1", 8 ) == 0 ) {
memcpy(&rootdir32, &readbuffer[PVDROOT + EXTENT], 4);
rootdir = (u64)rootdir32;
rootdir <<= 11;
memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
IsJoliet = 0;
break;
}
} else
return 0;
sector++;
}
return (IsJoliet == 0);
}
/****************************************************************************
* getfiles
*
* Retrieve the current file directory entry
****************************************************************************/
static int diroffset = 0;
int getfiles( int filecount ) {
char fname[MAX_PATH_LEN+1];
char *ptr;
char *filename;
char *filenamelength;
char *rr;
int j;
u32 offset32;
/*** Do some basic checks ***/
if ( filecount == MAXFILES ) return 0;
if ( diroffset >= 2048 ) return 0;
/*** Now decode this entry ***/
if ( readbuffer[diroffset] != 0 ) {
ptr = (char *)&readbuffer[0];
ptr += diroffset;
filename = ptr + FILENAME;
filenamelength = ptr + FILENAME_LENGTH;
/* Check for wrap round - illegal in ISO spec,
* but certain crap writers do it! */
if ( diroffset + readbuffer[diroffset] > 2048 ) return 0;
if ( *filenamelength ) {
memset(&fname, 0, 128);
/*** Return the values needed ***/
if (!IsJoliet)
strcpy(fname, filename);
else {
for ( j = 0; j < ( *filenamelength >> 1 ); j++ ) {
fname[j] = filename[j*2+1];
}
fname[j] = 0;
if ( strlen(fname) >= MAX_PATH_LEN ) fname[MAX_PATH_LEN] = 0;
if ( strlen(fname) == 0 ) fname[0] = filename[0];
}
if ( strlen(fname) == 0 ) strcpy(fname,"ROOT");
else {
if ( fname[0] == 1 ) strcpy(fname,"..");
else{
//fname[ *filenamelength ] = 0;
/*
* Move *filenamelength to t,
* Only to stop gcc warning for noobs :)
*/
int t = *filenamelength;
fname[t] = 0;
}
}
/** Rockridge Check **/ /*** Remove any trailing ;1 from ISO name ***/
rr = strstr (fname, ";"); //if ( fname[ strlen(fname) - 2 ] == ';' )
if (rr != NULL) *rr = 0; //fname[ strlen(fname) - 2 ] = 0;*/
strcpy(filelist[filecount].filename, fname);
memcpy(&offset32, &readbuffer[diroffset + EXTENT], 4);
filelist[filecount].offset = (u64)offset32;
memcpy(&filelist[filecount].length, &readbuffer[diroffset + FILE_LENGTH], 4);
memcpy(&filelist[filecount].flags, &readbuffer[diroffset + FILE_FLAGS], 1);
filelist[filecount].offset <<= 11;
filelist[filecount].flags = filelist[filecount].flags & 2;
/*** Prepare for next entry ***/
diroffset += readbuffer[diroffset];
return 1;
}
}
return 0;
}
#ifdef __gamecube__
/****************************************************************************
* ParseDirectory
*
* Parse the isodirectory, returning the number of files found
****************************************************************************/
int parsedir() {
int pdlength;
u64 pdoffset;
u64 rdoffset;
int len = 0;
int filecount = 0;
pdoffset = rdoffset = rootdir;
pdlength = rootdirlength;
filecount = 0;
/*** Clear any existing values ***/
memset(&filelist, 0, sizeof(FILEENTRIES) * MAXFILES);
/*** Get as many files as possible ***/
while ( len < pdlength )
{
if (dvd_read (&readbuffer, 2048, pdoffset) == 0)
return 0;
diroffset = 0;
while ( getfiles( filecount ) ) {
if ( filecount < MAXFILES )
filecount++;
}
len += 2048;
pdoffset = rdoffset + len;
}
return filecount;
}
#endif
/***************************************************************************
* FileSortCallback
*
* Quick sort callback to sort file entries with the following order:
* .
* ..
* <dirs>
* <files>
***************************************************************************/
static int FileSortCallback(const void *f1, const void *f2)
{
/* Special case for implicit directories */
if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.')
{
if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; }
if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; }
if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; }
if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; }
}
/* If one is a file and one is a directory the directory is first. */
if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1;
if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1;
return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename);
}
/***************************************************************************
* Update SDCARD curent directory name
***************************************************************************/
int updateSDdirname() {
int size=0;
char *test;
char temp[1024];
/* current directory doesn't change */
if (strcmp(filelist[selection].filename,".") == 0)
return 0;
/* go up to parent directory */
if (strcmp(filelist[selection].filename,"..") == 0) {
/* determine last subdirectory namelength */
sprintf(temp,"%s",rootSDdir);
test = strtok(temp,"/");
while (test != NULL) {
size = strlen(test);
test = strtok(NULL,"/");
}
/* remove last subdirectory name */
size = strlen(rootSDdir) - size - 1;
rootSDdir[size] = 0;
/* handles root name */
//sprintf(tmpCompare, "dev%d:",ChosenSlot);
if (strcmp(rootSDdir, "/") == 0)
sprintf(rootSDdir,"fat:/");
return 1;
} else {
/* test new directory namelength */
if ((strlen(rootSDdir)+1+strlen(filelist[selection].filename)) < MAX_PATH_LEN) {
/* handles root name */
sprintf(temp, "/%s/..", FCEUDIR);
if (strcmp(rootSDdir, temp) == 0)
sprintf(rootSDdir,"fat:/");
/* update current directory name */
sprintf(rootSDdir, "%s/%s",rootSDdir, filelist[selection].filename);
return 1;
} else {
WaitPrompt ("Dirname is too long !");
return -1;
}
}
}
/***************************************************************************
* Browse SDCARD subdirectories
***************************************************************************/
int parseSDdirectory() {
int numstored = 0;
DIR_ITER *sddir = NULL;
char msg[128];
char filename[MAX_PATH_LEN];
struct stat filestat;
/* initialize selection */
selection = offset = 0;
// If rootSDdir doesn't exist, default to the root dir
sddir = diropen(rootSDdir);
if (sddir == NULL) {
strcpy(rootSDdir, "fat:/");
sddir = diropen(rootSDdir);
if (sddir == NULL) {
sprintf(msg, "Error opening %s", rootSDdir);
WaitPrompt(msg);
return 0;
}
}
while (dirnext(sddir, filename, &filestat) == 0) {
if ((strcmp(filename, ".") != 0) && (numstored < MAXFILES)) {
memset(&filelist[numstored], 0, sizeof (FILEENTRIES));
strncpy(filelist[numstored].filename, filename, MAX_PATH_LEN);
filelist[numstored].length = filestat.st_size;
filelist[numstored].flags = (filestat.st_mode & S_IFDIR) ? 1 : 0;
numstored++;
}
}
dirclose(sddir);
/* Sort the file list */
qsort(filelist, numstored, sizeof(FILEENTRIES), FileSortCallback);
return numstored;
}
/****************************************************************************
* ShowFiles
*
* Support function for FileSelector
****************************************************************************/
void ShowFiles( int offset, int selection ) {
int i,j;
char text[80];
ClearScreen();
j = 0;
for ( i = offset; i < ( offset + PAGESIZE ) && ( i < maxfiles ); i++ ) {
if ( filelist[i].flags ) {
strcpy(text,"[");
strncat(text, filelist[i].filename, 78);
strcat(text,"]");
} else
strncpy(text, filelist[i].filename, 80);
text[80]=0;
char dir[1024];
if (UseSDCARD)
strcpy(dir, rootSDdir);
else
dir[0] = 0;
writex(CentreTextPosition(dir), 22, GetTextWidth(dir), font_height, dir, 0);
while (GetTextWidth(text) > 620)
text[strlen(text)-2] = 0;
writex( CentreTextPosition(text), ( j * font_height ) + 110, GetTextWidth(text), font_height, text, j == ( selection - offset ) );
j++;
}
SetScreen();
}
/****************************************************************************
* FileSelector
*
* Let user select another ROM to load
****************************************************************************/
bool inSz = false;
extern u8 PADCAL;
void FileSelector() {
short p;
signed char a;
int haverom = 0;
int redraw = 1;
while ( haverom == 0 ) {
if ( redraw ) ShowFiles( offset, selection );
redraw = 0;
p = PAD_ButtonsDown(0);
a = PAD_StickY(0);
if (p & PAD_BUTTON_B) return;
if ( ( p & PAD_BUTTON_DOWN ) || ( a < -PADCAL ) ) {
selection++;
if (selection == maxfiles) selection = offset = 0;
if ((selection - offset) >= PAGESIZE) offset += PAGESIZE;
redraw = 1;
} // End of down
if ( ( p & PAD_BUTTON_UP ) || ( a > PADCAL ) ) {
selection--;
if ( selection < 0 ){
selection = maxfiles - 1;
offset = selection - PAGESIZE + 1;
}
if (selection < offset) offset -= PAGESIZE;
if ( offset < 0 ) offset = 0;
redraw = 1;
} // End of Up
if ( (p & PAD_BUTTON_LEFT) || (p & PAD_TRIGGER_L) ) {
/*** Go back a page ***/
selection -= PAGESIZE;
if ( selection < 0 ) {
selection = maxfiles - 1;
offset = selection-PAGESIZE + 1;
}
if ( selection < offset ) offset -= PAGESIZE;
if ( offset < 0 ) offset = 0;
redraw = 1;
}
if (( p & PAD_BUTTON_RIGHT ) || (p & PAD_TRIGGER_R)) {
/*** Go forward a page ***/
selection += PAGESIZE;
if ( selection > maxfiles - 1 ) selection = offset = 0;
if ( ( selection - offset ) >= PAGESIZE ) offset += PAGESIZE;
redraw = 1;
}
if ( p & PAD_BUTTON_A ) {
if ( filelist[selection].flags ) { /*** This is directory ***/
if (UseSDCARD) {
/* update current directory and set new entry list if directory has changed */
int status = updateSDdirname();
if (status == 1) {
maxfiles = parseSDdirectory();
if (!maxfiles) {
WaitPrompt ((char*)"Error reading directory !");
haverom = 1; // quit SD menu
haveSDdir = 0; // reset everything at next access
}
} else if (status == -1) {
haverom = 1; // quit SD menu
haveSDdir = 0; // reset everything at next access
}
}
#ifdef __gamecube__
else { // DVD
rootdir = filelist[selection].offset;
rootdirlength = filelist[selection].length;
offset = selection = 0;
maxfiles = parsedir();
}
#endif
}
#ifdef __gamecube__
else if (selection == 0 && inSz == true) {
rootdir = filelist[1].offset;
rootdirlength = filelist[1].length;
offset = 0;
maxfiles = parsedir();
inSz = false;
SzClose();
}
else if (inSz == false && SzDvdIsArchive(filelist[selection].offset) == SZ_OK) {
// parse the 7zip file
ShowAction("Found 7z");
SzParse();
if(SzRes == SZ_OK) {
inSz = true;
offset = selection = 0;
} else {
SzDisplayError(SzRes);
}
}
else if (inSz == true) {
// extract the selected ROM from the 7zip file to the buffer
if(SzExtractROM(filelist[selection].offset, nesromptr) == true) {
haverom = 1;
inSz = false;
// go one directory up
rootdir = filelist[1].offset;
rootdirlength = filelist[1].length;
offset = selection = 0;
maxfiles = parsedir();
}
}
#endif
else {
rootdir = filelist[selection].offset;
rootdirlength = filelist[selection].length;
// Now load the DVD file to it's offset
LoadDVDFile(nesromptr);
haverom = 1;
}
redraw = 1;
}
}
}
/****************************************************************************
* LoadDVDFile
****************************************************************************/
int LoadDVDFile( unsigned char *buffer ) {
u64 offset;
int blocks;
int i;
u64 discoffset;
/*** SDCard Addition ***/
if (UseSDCARD) GetSDInfo();
if (rootdirlength == 0) return 0;
/*** How many 2k blocks to read ***/
blocks = rootdirlength / 2048;
offset = 0;
discoffset = rootdir;
ShowAction("Loading ... Wait");
if (UseSDCARD) fread(&readbuffer, 1, 2048, filehandle);
else dvd_read(&readbuffer, 2048, discoffset);
if (isZipFile() == false) {
if (UseSDCARD) fseek(filehandle, 0, SEEK_SET);
for ( i = 0; i < blocks; i++ ) {
if (UseSDCARD) fread(&readbuffer, 1, 2048, filehandle);
else dvd_read(&readbuffer, 2048, discoffset);
memcpy(&buffer[offset], &readbuffer, 2048);
offset += 2048;
discoffset += 2048;
}
/*** And final cleanup ***/
if( rootdirlength % 2048 ) {
i = rootdirlength % 2048;
if (UseSDCARD) fread(&readbuffer, 1, i, filehandle);
else dvd_read(&readbuffer, 2048, discoffset);
memcpy(&buffer[offset], &readbuffer, i);
}
} else {
return unzipDVDFile( buffer, (u32)discoffset, rootdirlength);
}
if (UseSDCARD) fclose(filehandle);
return rootdirlength;
}
#ifdef __gamecube__
/****************************************************************************
* OpenDVD
*
* This function performs the swap task for softmodders.
* For Viper/Qoob users, sector 0 is read, and if it contains all nulls
* an ISO disc is assumed.
****************************************************************************/
static int haveDVDdir = 0;
int OpenDVD() {
haveSDdir = 0;
haveDVDdir = offset = selection = 0;
// Mount the DVD if necessary
if (!IsPVD()) {
ShowAction((char*)"Mounting DVD");
DVD_Mount();
ShowAction((char*)"Done Mounting");
haveDVDdir = 0;
if (!IsPVD()) {
WaitPrompt((char*)"No vallid ISO9660 DVD");
return 0; // No correct ISO9660 DVD
}
}
/*** At this point I should have an unlocked DVD ... so let's do the ISO ***/
if ( haveDVDdir != 1 ) {
if ( IsPVD() ) {
/*** Have a valid PVD, so start reading directory entries ***/
maxfiles = parsedir();
if ( maxfiles ) {
offset = selection = 0;
FileSelector();
haveDVDdir = 1;
}
} else {
return 0;
}
} else
FileSelector();
return 1;
}
#endif
int OpenSD() {
UseSDCARD = 1;
char msg[128];
if (haveSDdir == 0) {
#ifdef __gamecube__
/* don't mess with DVD entries */
haveDVDdir = 0;
#endif
/* Reset SDCARD root directory */
sprintf(rootSDdir,"/%s/%s", FCEUDIR, ROMSDIR);
/* Parse initial root directory and get entries list */
ShowAction("Reading Directory ...");
maxfiles = parseSDdirectory();
if (maxfiles) {
//sprintf (msg, "Found %d entries", maxfiles);
//WaitPrompt(msg);
/* Select an entry */
FileSelector();
/* memorize last entries list, actual root directory and selection for next access */
haveSDdir = 1;
} else {
/* no entries found */
sprintf (msg, "Error reading %s", rootSDdir);
WaitPrompt (msg);
return 0;
}
}
/* Retrieve previous entries list and made a new selection */
else FileSelector();
return 1;
}
/****************************************************************************
* SDCard Get Info
****************************************************************************/
void GetSDInfo () {
char fname[MAXPATHLEN];
rootdirlength = 0;
/* Check filename length */
if ((strlen(rootSDdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
sprintf(fname, "%s/%s",rootSDdir,filelist[selection].filename);
else
{
WaitPrompt ((char*)"Maximum Filename Length reached !");
haveSDdir = 0; // reset everything before next access
}
filehandle = fopen(fname, "rb");
if (filehandle == NULL)
{
WaitPrompt ((char*)"Unable to open file!");
return;
}
fseek(filehandle, 0, SEEK_END);
rootdirlength = ftell(filehandle);
fseek(filehandle, 0, SEEK_SET);
}

View File

@ -1,13 +0,0 @@
#define MAXJOLIET 256
#define MAXFILES 1000
typedef struct {
char filename[MAXJOLIET];
char sdcardpath[256];
u64 offset;
unsigned int length;
char flags;
}FILEENTRIES;
extern FILEENTRIES filelist[MAXFILES];

View File

@ -1,375 +0,0 @@
/****************************************************************************
* GCVideo
*
* This module contains all GameCube video routines
****************************************************************************/
#include <gccore.h>
#include <ogcsys.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iplfont.h"
#include "nesback.h"
#include "intl.h"
//#define FORCE_PAL50 1
#define TEX_WIDTH 256
#define TEX_HEIGHT 512
#define WIDTH 640
#define DEFAULT_FIFO_SIZE 256 * 1024
unsigned int *xfb[2]; /*** Framebuffer - used throughout ***/
GXRModeObj *vmode;
/*** Backdrop ***/
extern unsigned char backdrop[614400];
/*** Need something to hold the PC palette ***/
struct pcpal {
unsigned char r;
unsigned char g;
unsigned char b;
} pcpalette[256];
unsigned int gcpalette[256]; /*** Much simpler GC palette ***/
unsigned short rgb565[256]; /*** Texture map palette ***/
static unsigned char gp_fifo[DEFAULT_FIFO_SIZE] __attribute__((__aligned__(32)));
static unsigned char texturemem[TEX_WIDTH * TEX_HEIGHT * 2] __attribute__((__aligned__(32)));
GXTexObj texobj;
GXColor background = {0, 0, 0, 0xff};
static Mtx projectionMatrix,modelViewMatrix;
void CheesyScale(unsigned char *XBuf);
int whichfb = 0;
extern int font_height;
int copynow = GX_FALSE;
/****************************************************************************
* GX Chip Copy to XFB
****************************************************************************/
static void copy_to_xfb() {
if (copynow == GX_TRUE) {
GX_CopyDisp(xfb[whichfb],GX_TRUE);
GX_Flush();
copynow = GX_FALSE;
}
}
/****************************************************************************
* Initialise the GX
****************************************************************************/
void StartGX() {
/*** Clear out FIFO area ***/
memset(&gp_fifo, 0, DEFAULT_FIFO_SIZE);
/*** Initialise GX ***/
GX_Init(&gp_fifo, DEFAULT_FIFO_SIZE);
GX_SetCopyClear(background, 0x00ffffff);
/*** Additions from libogc ***/
GX_SetViewport(10,0,vmode->fbWidth,vmode->efbHeight,0,1);
GX_SetDispCopyYScale((f32)vmode->xfbHeight/(f32)vmode->efbHeight);
GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight);
GX_SetDispCopyDst(vmode->fbWidth,vmode->xfbHeight);
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
GX_SetCullMode(GX_CULL_NONE);
GX_SetZMode(GX_FALSE,GX_ALWAYS,GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(xfb[whichfb],GX_TRUE);
/*** Additions from ogc spaceship ***/
GX_SetDispCopyGamma(GX_GM_1_0);
GX_ClearVtxDesc();
GX_SetVtxAttrFmt(GX_VTXFMT0,GX_VA_POS,GX_POS_XYZ,GX_F32,0);
GX_SetVtxAttrFmt(GX_VTXFMT0,GX_VA_TEX0,GX_TEX_ST,GX_F32,0);
GX_SetVtxDesc(GX_VA_POS,GX_DIRECT);
GX_SetVtxDesc(GX_VA_TEX0,GX_DIRECT);
GX_SetNumChans(0); /* default, color = vertex color */
GX_SetNumTexGens(1);
GX_SetTexCoordGen(GX_TEXCOORD0,GX_TG_MTX2x4,GX_TG_TEX0,GX_IDENTITY);
GX_SetTevOrder(GX_TEVSTAGE0,GX_TEXCOORD0,GX_TEXMAP0,GX_COLORNULL);
GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE);
GX_InitTexObj(&texobj,&texturemem,TEX_WIDTH,TEX_HEIGHT,
GX_TF_RGB565,GX_REPEAT,GX_REPEAT,GX_FALSE);
DCFlushRange(&texturemem, TEX_WIDTH * TEX_HEIGHT * 2);
GX_LoadTexObj(&texobj,GX_TEXMAP0);
GX_InvalidateTexAll();
/* load projection matrix */
/*** Setting Height to 648 get's it right ? ***/
guOrtho(projectionMatrix,10,610,640,0,-1,1);
GX_LoadProjectionMtx(projectionMatrix,GX_ORTHOGRAPHIC);
/* load model view matrix */
c_guMtxScale(modelViewMatrix,660,640,1);
GX_LoadPosMtxImm(modelViewMatrix,GX_PNMTX0);
}
/****************************************************************************
* GXDraw
*
* Using the texture map draw with quads
****************************************************************************/
void GXDraw(unsigned char *XBuf) {
float gs = 1.0;
float gt = 1.0;
int width, height,t,xb;
unsigned short *texture;
memset(&texturemem, 0, TEX_WIDTH * TEX_HEIGHT * 2);
texture = (unsigned short *)&texturemem[16 * TEX_WIDTH];
/*** Now draw the texture ***/
t = 0;
for(height = 0; height < 120; height++) {
xb = height * 512;
for(width = 256; width > 0; width -= 4) {
/*** Row one ***/
texture[t++] = rgb565[XBuf[xb + width-1]];
texture[t++] = rgb565[XBuf[xb + width-2]];
texture[t++] = rgb565[XBuf[xb + width-3]];
texture[t++] = rgb565[XBuf[xb + width-4]];
/*** Row three ***/
texture[t++] = rgb565[XBuf[xb + width-1]];
texture[t++] = rgb565[XBuf[xb + width-2]];
texture[t++] = rgb565[XBuf[xb + width-3]];
texture[t++] = rgb565[XBuf[xb + width-4]];
/*** Row one ***/
texture[t++] = rgb565[XBuf[xb + 256 + width-1]];
texture[t++] = rgb565[XBuf[xb + 256 + width-2]];
texture[t++] = rgb565[XBuf[xb + 256 + width-3]];
texture[t++] = rgb565[XBuf[xb + 256 + width-4]];
/*** Row three ***/
texture[t++] = rgb565[XBuf[xb + 256 + width-1]];
texture[t++] = rgb565[XBuf[xb + 256 + width-2]];
texture[t++] = rgb565[XBuf[xb + 256 + width-3]];
texture[t++] = rgb565[XBuf[xb + 256 + width-4]];
}
}
DCFlushRange(&texturemem, TEX_WIDTH * TEX_HEIGHT * 2);
/* setup GX */
GX_InvalidateTexAll();
// ok render the triangles now
GX_Begin(GX_QUADS,GX_VTXFMT0,4);
{
GX_Position3f32(0,0,0);
GX_TexCoord2f32(0,0);
GX_Position3f32(0,1,0);
GX_TexCoord2f32(0,gt);
GX_Position3f32(1,1,0);
GX_TexCoord2f32(gs,gt);
GX_Position3f32(1,0,0);
GX_TexCoord2f32(gs,0);
}
GX_End();
GX_DrawDone();
copynow = GX_TRUE;
}
/****************************************************************************
* initDisplay
*
* It should be noted that this function forces the system to use a
* 640x480 viewport for either NTSC or PAL.
*
* Helps keep the rendering at 2x sweet
****************************************************************************/
void initDisplay() {
/*** Start VIDEO Subsystem ***/
VIDEO_Init();
vmode = VIDEO_GetPreferredMode(NULL);
VIDEO_Configure(vmode);
xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode));
xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode));
/*init_font();*/
VIDEO_SetNextFramebuffer(xfb[0]);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(vmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
VIDEO_SetPostRetraceCallback(PAD_ScanPads);
/*** Setup a console - guard against spurious printf ***/
VIDEO_SetPreRetraceCallback(copy_to_xfb);
VIDEO_SetNextFramebuffer(xfb[0]);
PAD_Init();
StartGX();
}
/****************************************************************************
* RenderFrame
*
* Render a single frame at 2x zoom
****************************************************************************/
#define NESWIDTH 256
#define NESHEIGHT 240
void RenderFrame(char *XBuf, int style) {
int gcdispOffset = 32; /*** Offset to centre on screen ***/
int w,h;
int c,i;
whichfb ^= 1;
switch(style) {
case 0 :
VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK);
/*** Simply go through each row ***/
for(h = 0; h < NESHEIGHT; h++) {
for(w = 0; w < NESWIDTH; w++) {
c = (h << 8) + w;
i = gcdispOffset + w;
/*** Fast Zoom - Repeat each row, use 1 Xbuf == 2 GC
To speed up more, use indexed palette array ***/
xfb[whichfb][i] = gcpalette[(unsigned char)XBuf[c]];
xfb[whichfb][i + 320] = gcpalette[(unsigned char)XBuf[c]];
}
gcdispOffset += 640;
}
break;
case 1:
CheesyScale(XBuf);
break;
case 2:
GXDraw(XBuf);
break;
}
/*** Now resync with VSync ***/
VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush();
VIDEO_WaitVSync();
}
/****************************************************************************
* rgbcolor
*
* Support routine for gcpalette
****************************************************************************/
unsigned int rgbcolor(unsigned char r1, unsigned char g1, unsigned char b1,
unsigned char r2, unsigned char g2, unsigned char b2) {
int y1,cb1,cr1,y2,cb2,cr2,cb,cr;
y1=(299*r1+587*g1+114*b1)/1000;
cb1=(-16874*r1-33126*g1+50000*b1+12800000)/100000;
cr1=(50000*r1-41869*g1-8131*b1+12800000)/100000;
y2=(299*r2+587*g2+114*b2)/1000;
cb2=(-16874*r2-33126*g2+50000*b2+12800000)/100000;
cr2=(50000*r2-41869*g2-8131*b2+12800000)/100000;
cb=(cb1+cb2) >> 1;
cr=(cr1+cr2) >> 1;
return ((y1 << 24) | (cb << 16) | (y2 << 8) | cr);
}
/****************************************************************************
* SetPalette
*
* A shadow copy of the palette is maintained, in case the NES Emu kernel
* requests a copy.
****************************************************************************/
void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g,
unsigned char b) {
/*** Make PC compatible copy ***/
pcpalette[index].r = r;
pcpalette[index].g = g;
pcpalette[index].b = b;
/*** Generate Gamecube palette ***/
gcpalette[index] = rgbcolor(r,g,b,r,g,b);
/*** Generate RGB565 texture palette ***/
rgb565[index] = ((r & 0xf8) << 8) |
((g & 0xfc) << 3) |
((b & 0xf8) >> 3);
}
/****************************************************************************
* GetPalette
****************************************************************************/
void FCEUD_GetPalette(unsigned char i, unsigned char *r, unsigned char *g,
unsigned char *b) {
*r = pcpalette[i].r;
*g = pcpalette[i].g;
*b = pcpalette[i].b;
}
/****************************************************************************
* NES Cheesy Scaler
*
* This scaler simply attempts to correct the 1.25 aspect by
* stretching the initial 256 pixels to 320.
* The standard 2x2 scaler can then be applied
****************************************************************************/
void CheesyScale(unsigned char *XBuf) {
static int newrow[320]; /*** New cheesy row ***/
unsigned int cheesypal[256]; /*** Enhanced Cheesy Palette ***/
int i,j,c,p = 0;
unsigned char p1,p2;
unsigned int ofs, gcdispOffset = 0;
int h, n, nw;
/*** Stretch ***/
for (h = 0; h < NESHEIGHT; h++) {
j = c = p = 0;
for (i = 0; i < NESWIDTH; i++) {
/*** Every fifth pixel is stretched by adding
the mid colour range ***/
n = (h << 8) + i;
newrow[j++] = XBuf[n];
c++;
if (c == 4) { /*** Done 4 pixels, so add the fifth ***/
p1 = XBuf[n];
p2 = XBuf[n+1];
cheesypal[p] = rgbcolor(pcpalette[p1].r, pcpalette[p1].g,
pcpalette[p1].b, pcpalette[p2].r, pcpalette[p2].g,
pcpalette[p2].b);
newrow[j++] = 0x8000 + p;
p++;
c = 0;
}
}
/*** Now update the screen display with the new colours ***/
ofs = gcdispOffset;
for (nw = 0; nw < 320; nw++) {
if (newrow[nw] & 0x8000) {
xfb[whichfb][ofs + nw] = cheesypal[newrow[nw] & 0xff ];
xfb[whichfb][ofs + 320 + nw] = cheesypal[newrow[nw] & 0xff];
} else {
xfb[whichfb][ofs + nw] = gcpalette[newrow[nw]];
xfb[whichfb][ofs + nw + 320] = gcpalette[newrow[nw]];
}
}
gcdispOffset += 640;
}
}

View File

@ -1,23 +0,0 @@
/*****************************************************************************
* Gamecube XenoGC Identifier
*
* Functions to determine if the DVD is in fact a XenoGC boot disc
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int IsXenoGCImage( char *buffer )
{
/*** All Xeno GC Homebrew Boot have id GBLPGL ***/
if ( memcmp( buffer, "GBLPGL", 6 ) )
return 0;
if ( memcmp( &buffer[0x20], "GAMECUBE \"EL TORITO\" BOOTLOADER", 31 ) )
return 0;
return 1;
}

View File

@ -1,170 +0,0 @@
/****************************************************************************
* GC Zip Extension
*
* GC DVD Zip File Loader.
*
* The idea here is not to support every zip file on the planet!
* The unzip routine will simply unzip the first file in the zip archive.
*
* For maximum compression, I'd recommend using 7Zip,
* 7za a -tzip -mx=9 rom.zip rom.smc
****************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
extern unsigned int dvd_read(void *dst, unsigned int len, u64 offset);
extern FILE *filehandle;
extern u8 UseSDCARD;
extern void ShowAction( char *msg );
extern void WaitPrompt( char *msg );
extern unsigned char readbuffer[2048];
#define ZIPCHUNK 2048
/*** PKWare Zip Header ***/
#define PKZIPID 0x504b0304
typedef struct {
unsigned int zipid __attribute__ ((__packed__)); // 0x04034b50
unsigned short zipversion __attribute__ ((__packed__));
unsigned short zipflags __attribute__ ((__packed__));
unsigned short compressionMethod __attribute__ ((__packed__));
unsigned short lastmodtime __attribute__ ((__packed__));
unsigned short lastmoddate __attribute__ ((__packed__));
unsigned int crc32 __attribute__ ((__packed__));
unsigned int compressedSize __attribute__ ((__packed__));
unsigned int uncompressedSize __attribute__ ((__packed__));
unsigned short filenameLength __attribute__ ((__packed__));
unsigned short extraDataLength __attribute__ ((__packed__));
} PKZIPHEADER;
static inline u32 FLIP32(u32 b) {
unsigned int c;
c = ( b & 0xff000000 ) >> 24;
c |= ( b & 0xff0000 ) >> 8;
c |= ( b & 0xff00 ) << 8;
c |= ( b & 0xff ) << 24;
return c;
}
static inline u16 FLIP16(u16 b) {
u16 c;
c = ( b & 0xff00 ) >> 8;
c |= ( b &0xff ) << 8;
return c;
}
/****************************************************************************
* isZipFile
*
* This ONLY check the zipid, so any file which starts with the correct
* 4 bytes will be treated as a zip file.
*
* It interrogate the first 4 bytes of the common readbuffer, so make sure
* it is populated before calling.
****************************************************************************/
bool isZipFile() {
u32 check;
memcpy(&check, &readbuffer, 4);
return (check == PKZIPID) ? true : false;
}
/****************************************************************************
* unzipDVDFile
*
* This loads the zip file in small 2k chunks, and decompresses to the
* output buffer.
*
* Unzip terminates on Z_END_STREAM.
***************************************************************************/
int unzipDVDFile(unsigned char *outbuffer, unsigned int discoffset, unsigned int length) {
PKZIPHEADER pkzip;
int zipoffset = 0;
int zipchunk = 0;
char out[ZIPCHUNK];
z_stream zs;
int res;
int bufferoffset = 0;
int have = 0;
char debug[128];
/*** Copy PKZip header to local, used as info ***/
memcpy(&pkzip, &readbuffer, sizeof(PKZIPHEADER));
sprintf(debug, "Unzipping %d bytes ... Wait", FLIP32(pkzip.uncompressedSize));
ShowAction(debug);
/*** Prepare the zip stream ***/
memset(&zs, 0, sizeof(z_stream));
zs.zalloc = Z_NULL;
zs.zfree = Z_NULL;
zs.opaque = Z_NULL;
zs.avail_in = 0;
zs.next_in = Z_NULL;
res = inflateInit2(&zs, -MAX_WBITS);
if ( res != Z_OK )
return 0;
/*** Set ZipChunk for first pass ***/
zipoffset = ( sizeof(PKZIPHEADER) + FLIP16(pkzip.filenameLength) + FLIP16(pkzip.extraDataLength ));
zipchunk = ZIPCHUNK - zipoffset;
/*** No do it! ***/
do {
zs.avail_in = zipchunk;
zs.next_in = (Bytef *)&readbuffer[zipoffset];
/*** Now inflate until input buffer is exhausted ***/
do {
zs.avail_out = ZIPCHUNK;
zs.next_out = (Bytef *)&out;
res = inflate(&zs, Z_NO_FLUSH);
if ( res == Z_MEM_ERROR ) {
inflateEnd(&zs);
return 0;
}
have = ZIPCHUNK - zs.avail_out;
if (have) {
/*** Copy to normal block buffer ***/
memcpy(&outbuffer[bufferoffset], &out, have);
bufferoffset += have;
}
} while ( zs.avail_out == 0 );
/*** Readup the next 2k block ***/
zipoffset = 0;
zipchunk = ZIPCHUNK;
discoffset += 2048;
if (UseSDCARD) fread(&readbuffer, 2048, 1, filehandle);
else dvd_read(&readbuffer, 2048, discoffset);
} while ( res != Z_STREAM_END );
inflateEnd(&zs);
if (UseSDCARD) fclose(filehandle);
if ( res == Z_STREAM_END ) {
if ( FLIP32(pkzip.uncompressedSize == (u32)bufferoffset ) )
return bufferoffset;
else
return FLIP32(pkzip.uncompressedSize);
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +0,0 @@
/*
* This file holds collections of strings to make localization easier.
* Keep the max string length to 30 characters or bad things will happen
*/
#define MENU_STRING_LENGTH 30
#ifdef INTL_SPANISH
//#include "intl/spanish.h"
#elif defined INTL_GERMAN
//#include "intl/german.h"
#elif defined INTL_DUTCH
#include "intl/dutch.h"
#else
#include "intl/english.h"
#endif

View File

@ -1,104 +0,0 @@
/*
* ---------------------------------------------------------------------------
* Dutch by Adr990
* ---------------------------------------------------------------------------
*/
// Some general menu strings
#define MENU_ON "AAN"
#define MENU_OFF "UIT"
#define MENU_EXIT "Terug naar vorige"
#define MENU_PRESS_A "Druk op A om door te gaan"
// Main menu
#define MENU_MAIN_PLAY "Start spel"
#define MENU_MAIN_RESET "Herstart NES"
#define MENU_MAIN_LOAD "Laad nieuw spel"
#define MENU_MAIN_SAVE "Save Manager"
#define MENU_MAIN_INFO "ROM Informatie"
#define MENU_MAIN_JOYPADS "Instellingen Joypads"
#define MENU_MAIN_OPTIONS "Video Opties"
#ifdef HW_RVL
#define MENU_MAIN_RELOAD "TP Herladen"
#define MENU_MAIN_REBOOT "Herstart Wii"
#else
#define MENU_MAIN_RELOAD "PSO herlaad"
#define MENU_MAIN_REBOOT "Herstart Gamecube"
#endif
#define MENU_MAIN_CREDITS "Bekijk Credits"
#define MENU_MAIN_TEXT1 MENU_CREDITS_TITLE
#define MENU_MAIN_TEXT2 "Druk op L + R gewoon om terug te keren naar het menu!"
#define MENU_MAIN_TEXT3 "Druk START + B + X gewoon voor PSO/SD-herlaad"
#define MENU_MAIN_TEXT4 "FCE Ultra GC is een gewijzigte port van de FCE Ultra 0.98.12 Nintendo Entertainment system for x86 (Windows/Linux) PC's. In Hollands you can play NES games op je GameCube bruikbaar met Softmod en/of Modchip van een DVD of via Netwerk connection naar je PC."
#define MENU_MAIN_TEXT5 "Disclaimer - Gebruik op eigen risico!"
#define MENU_MAIN_TEXT6 "Official Startpagina: http://www.tehskeen.net"
// Media menu
#define MENU_MEDIA_TITLE "Laad een spel"
#define MENU_MEDIA_SDCARD "Laad van SDCard"
#define MENU_MEDIA_DVD "Laad van DVD"
#define MENU_MEDIA_STOPDVD "Stop DVD Motor"
#define MENU_MEDIA_STOPPING "Stopt DVD ... Wacht"
#define MENU_MEDIA_STOPPED "DVD Motor Gestopt"
#define MENU_MEDIA_TEXT1 "Waar wacht Je op? Laad een paar spellen!"
#define MENU_MEDIA_TEXT2 "Nog hier?"
#define MENU_MEDIA_TEXT3 "Hoe kun je zo lang wachten?! De spellen wachten op je!!"
// Save menu
#define MENU_SAVE_TITLE "Save Staat Manager"
#define MENU_SAVE_SAVE "Save Staat"
#define MENU_SAVE_LOAD "Load Staat"
#define MENU_SAVE_DEVICE "Apperaat"
#define MENU_SAVE_TEXT1 "Van waar wil je je spel laden/saven?"
#define MENU_SAVE_TEXT2 "Hard time making up your mind?"
// Rom Information
#define MENU_INFO_TITLE "ROM Informatie"
#define MENU_INFO_ROM "ROM Groote"
#define MENU_INFO_VROM "VROM Groote"
#define MENU_INFO_CRC "iNES CRC"
#define MENU_INFO_MAPPER "Mapper"
#define MENU_INFO_MIRROR "Spiegeling"
// Config Joypad menu
#define MENU_CONFIG_TITLE "Controller Instellingen"
#define MENU_CONFIG_A "NES Knop A"
#define MENU_CONFIG_B "NES Knop B"
#define MENU_CONFIG_START "NES Knop START"
#define MENU_CONFIG_SELECT "NES Knop SELECT"
#define MENU_CONFIG_TURBO_A "NES Knop TURBO A"
#define MENU_CONFIG_TURBO_B "NES Knop TURBO B"
#define MENU_CONFIG_FOUR_SCORE "Vier Score"
#define MENU_CONFIG_CLIP "Analog Clip"
#define MENU_CONFIG_SPEED "Turbo Snelheid"
#define MENU_CONFIG_TEXT1 "Stel je Gamepad in"
#define MENU_CONFIG_TEXT2 "Omhoog, omhoog, omlaag, omglaag, links, rechts, links, recht, B, A, start"
// Emulator Options menu
#define MENU_VIDEO_TITLE "Video Opties"
#define MENU_VIDEO_SCALER "Screen Schaal"
#define MENU_VIDEO_PALETTE "Palette"
#define MENU_VIDEO_SPRITE "8 Sprite Maximum"
#define MENU_VIDEO_TIMING "Timing"
#define MENU_VIDEO_SAVE "Save Settings"
#define MENU_VIDEO_LOAD "Load Settings"
#define MENU_VIDEO_DEFAULT "Normaal"
#define MENU_VIDEO_TEXT1 "Wow, deze kleuren en vormen zijn zeker mooi, Brengt terug de herideringen."
#define MENU_VIDEO_TEXT2 "Wees zeker niet met deze instellingen kloten, Je wilt niet deze ervaringen verkloten! :D"
// Credits menu
#ifdef HW_RVL
#define MENU_CREDITS_TITLE "FCE Ultra Wii Edition v1.0.10beta1"
#else
#define MENU_CREDITS_TITLE "FCE Ultra GC Edition v1.0.10beta1"
#endif
#define MENU_CREDITS_BY "bij"
#define MENU_CREDITS_GCPORT "Gamecube Port"
#define MENU_CREDITS_ORIG "Original FCE"
#define MENU_CREDITS_FCEU "FCE Ultra"
#define MENU_CREDITS_DVD "DVD Codes belangerijk van"
#define MENU_CREDITS_MISC "Misc addons"
#define MENU_CREDITS_EXTRAS "Extra opties"
#define MENU_CREDITS_THANK "Bedankt aan"
#define MENU_CREDITS_WII "voor het brengen naar de Wii"

View File

@ -1,104 +0,0 @@
/*
* ---------------------------------------------------------------------------
* English by dsbomb
* ---------------------------------------------------------------------------
*/
// Some general menu strings
#define MENU_ON "ON"
#define MENU_OFF "OFF"
#define MENU_EXIT "Return to Previous"
#define MENU_PRESS_A "Press A to Continue"
// Main menu
#define MENU_MAIN_PLAY "Play Game"
#define MENU_MAIN_RESET "Reset NES"
#define MENU_MAIN_LOAD "Load New Game"
#define MENU_MAIN_SAVE "Save Manager"
#define MENU_MAIN_INFO "ROM Information"
#define MENU_MAIN_JOYPADS "Configure Joypads"
#define MENU_MAIN_OPTIONS "Video Options"
#ifdef HW_RVL
#define MENU_MAIN_RELOAD "TP Reload"
#define MENU_MAIN_REBOOT "Reboot Wii"
#else
#define MENU_MAIN_RELOAD "PSO Reload"
#define MENU_MAIN_REBOOT "Reboot Gamecube"
#endif
#define MENU_MAIN_CREDITS "View Credits"
#define MENU_MAIN_TEXT1 MENU_CREDITS_TITLE
#define MENU_MAIN_TEXT2 "Press L + R anytime to return to this menu!"
#define MENU_MAIN_TEXT3 "Press START + B + X anytime for PSO/SD-reload"
#define MENU_MAIN_TEXT4 "FCE Ultra GC is a modified port of the FCE Ultra 0.98.12 Nintendo Entertainment system for x86 (Windows/Linux) PC's. In English you can play NES games on your GameCube using either a softmod and/or modchip from a DVD or via a networked connection to your PC."
#define MENU_MAIN_TEXT5 "Disclaimer - Use at your own RISK!"
#define MENU_MAIN_TEXT6 "Official Homepage: http://www.tehskeen.net"
// Media menu
#define MENU_MEDIA_TITLE "Load a Game"
#define MENU_MEDIA_SDCARD "Load from SDCard"
#define MENU_MEDIA_DVD "Load from DVD"
#define MENU_MEDIA_STOPDVD "Stop DVD Motor"
#define MENU_MEDIA_STOPPING "Stopping DVD ... Wait"
#define MENU_MEDIA_STOPPED "DVD Motor Stopped"
#define MENU_MEDIA_TEXT1 "What are You waiting for? Load some games!"
#define MENU_MEDIA_TEXT2 "Still here?"
#define MENU_MEDIA_TEXT3 "How can You wait this long?! The games are waiting for You!!"
// Save menu
#define MENU_SAVE_TITLE "Save State Manager"
#define MENU_SAVE_SAVE "Save State"
#define MENU_SAVE_LOAD "Load State"
#define MENU_SAVE_DEVICE "Device"
#define MENU_SAVE_TEXT1 "From where do you wish to load/save your game?"
#define MENU_SAVE_TEXT2 "Hard time making up your mind?"
// Rom Information
#define MENU_INFO_TITLE "ROM Information"
#define MENU_INFO_ROM "ROM Size"
#define MENU_INFO_VROM "VROM Size"
#define MENU_INFO_CRC "iNES CRC"
#define MENU_INFO_MAPPER "Mapper"
#define MENU_INFO_MIRROR "Mirroring"
// Config Joypad menu
#define MENU_CONFIG_TITLE "Controller Configuration"
#define MENU_CONFIG_A "NES Button A"
#define MENU_CONFIG_B "NES Button B"
#define MENU_CONFIG_START "NES Button START"
#define MENU_CONFIG_SELECT "NES Button SELECT"
#define MENU_CONFIG_TURBO_A "NES Button TURBO A"
#define MENU_CONFIG_TURBO_B "NES Button TURBO B"
#define MENU_CONFIG_FOUR_SCORE "Four Score"
#define MENU_CONFIG_CLIP "Analog Clip"
#define MENU_CONFIG_SPEED "Turbo Speed"
#define MENU_CONFIG_TEXT1 "Configure Your Gamepad"
#define MENU_CONFIG_TEXT2 "Up, up, down, down, left, right, left, right, B, A, start"
// Emulator Options menu
#define MENU_VIDEO_TITLE "Video Options"
#define MENU_VIDEO_SCALER "Screen Scaler"
#define MENU_VIDEO_PALETTE "Palette"
#define MENU_VIDEO_SPRITE "8 Sprite Limit"
#define MENU_VIDEO_TIMING "Timing"
#define MENU_VIDEO_SAVE "Save Settings"
#define MENU_VIDEO_LOAD "Load Settings"
#define MENU_VIDEO_DEFAULT "Default"
#define MENU_VIDEO_TEXT1 "Wow, these colors and shapes sure are beautiful, brings back the memories."
#define MENU_VIDEO_TEXT2 "Be sure not to mess these settings up, You don't want to ruin the experience! :D"
// Credits menu
#ifdef HW_RVL
#define MENU_CREDITS_TITLE "FCE Ultra Wii Edition v1.0.10beta1"
#else
#define MENU_CREDITS_TITLE "FCE Ultra GC Edition v1.0.10beta1"
#endif
#define MENU_CREDITS_BY "by"
#define MENU_CREDITS_GCPORT "Gamecube Port"
#define MENU_CREDITS_ORIG "Original FCE"
#define MENU_CREDITS_FCEU "FCE Ultra"
#define MENU_CREDITS_DVD "DVD Codes courtesy of"
#define MENU_CREDITS_MISC "Misc addons"
#define MENU_CREDITS_EXTRAS "Extra features"
#define MENU_CREDITS_THANK "Thank you to"
#define MENU_CREDITS_WII "for bringing it to the Wii"

View File

@ -1,162 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <gctypes.h>
#include <ogc/system.h>
#include <fat.h>
#include "../../types.h"
#include "common.h"
/* Some timing-related variables. */
static int fullscreen=0;
static int genie=0;
static int palyo=0;
static volatile int nofocus=0;
static volatile int userpause=0;
#define SO_FORCE8BIT 1
#define SO_SECONDARY 2
#define SO_GFOCUS 4
#define SO_D16VOL 8
#define GOO_DISABLESS 1 /* Disable screen saver when game is loaded. */
#define GOO_CONFIRMEXIT 2 /* Confirmation before exiting. */
#define GOO_POWERRESET 4 /* Confirm on power/reset. */
static int soundvolume=100;
static int soundquality=0;
static int soundo;
u8 screenscaler = 2;
uint8 *xbsave=NULL;
int eoptions=EO_BGRUN | EO_FORCEISCALE;
extern int RenderFrame( char *XBuf , int style);
extern int MainMenu();
extern void InitialiseSound();
extern void initDisplay();
extern void InitialisePads();
extern int GetJoy();
extern void GCMemROM();
extern void PlaySound( void *Buf, int samples );
long long basetime;
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
extern void ManageSettings(int mode, int slot, int device, int quiet);
extern u8 ChosenSlot;
extern u8 ChosenDevice;
extern void *Reload();
extern void Reboot();
static void reset_cb() {
Reload();
}
/*static int power_hit = 0;
static void power_cb() {
//Reboot();
//SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
power_hit = 1;
}*/
extern int WaitPromptChoice (char *msg, char *bmsg, char *amsg);
bool isWii = false;
static unsigned char *inquiry=(unsigned char *)0x80000004;
int main(int argc, char *argv[]) {
initDisplay();
SYS_SetResetCallback(reset_cb);
//SYS_SetPowerCallback(power_cb);
InitialiseSound();
fatInitDefault();
#ifdef __gamecube__
DVD_Init();
dvd_inquiry();
#endif
/*** Minimal Emulation Loop ***/
if ( !FCEUI_Initialize() ) {
printf("Ooops - unable to initialize system\n");
return 1;
}
palyo=0;
FCEUI_SetVidSystem(palyo);
genie&=1;
FCEUI_SetGameGenie(genie);
fullscreen&=1;
soundo&=1;
FCEUI_SetSoundVolume(soundvolume);
FCEUI_SetSoundQuality(soundquality);
cleanSFMDATA();
GCMemROM();
// Load settings
ManageSettings(1, ChosenSlot, ChosenDevice, 1);
MainMenu();
while (1) {
uint8 *gfx;
int32 *sound;
int32 ssize;
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
xbsave = gfx;
FCEUD_Update(gfx, sound, ssize);
/*if (power_hit)
//SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
Reboot();*/
}
return 0;
}
/****************************************************************************
* FCEU Support Functions to be written
****************************************************************************/
/*** File Control ***/
FILE *FCEUD_UTF8fopen(const char *n, const char *m)
{
return(fopen(n,m));
}
/*** General Logging ***/
void FCEUD_PrintError(char *s)
{
}
void FCEUD_Message(char *text)
{
}
/*** VIDEO ***/
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
{
PlaySound(Buffer, Count);
RenderFrame( XBuf, screenscaler );
GetJoy(); /* Fix by Garglub. Thanks! */
}
/*** Netplay ***/
int FCEUD_SendData(void *data, uint32 len)
{
return 1;
}
int FCEUD_RecvData(void *data, uint32 len)
{
return 0;
}
void FCEUD_NetworkClose(void)
{
}
void FCEUD_NetplayText(uint8 *text)
{
}

View File

@ -1,74 +0,0 @@
/****************************************************************************
* 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>
#include "../../types.h"
/* Switch to asm for faster compilation
*#include "../../roms/nesrom.h"
*/
#include "../../git.h"
#include "../../driver.h"
#include "../../palette.h"
#include "../../fceu.h"
#include "../../sound.h"
unsigned char *nesromptr;
extern FCEUGI *FCEUGameInfo;
extern int iNESMemLoad( char *rom );
extern void InitialisePads();
extern unsigned char nesrom[];
#define SAMPLERATE 48000
int GCMemROM()
{
nesromptr = &nesrom[0];
ResetGameLoaded();
/*** Allocate and clear GameInfo ***/
FCEUGameInfo = malloc(sizeof(FCEUGI));
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);
FCEUI_SetSoundQuality(0);
FCEUI_SetSoundVolume(100);
FCEUI_SetLowPass(0);
InitialisePads();
if ( iNESMemLoad( nesromptr ) )
{
FCEU_ResetVidSys();
PowerNES();
FCEU_ResetPalette();
FCEU_ResetMessages(); // Save state, status messages, etc.
SetSoundVariables();
}
else
{
WaitPrompt("Bad cartridge!");
return -1;
}
return 0;;
}

View File

@ -1,779 +0,0 @@
/****************************************************************************
* Memory Based Load/Save State Manager
*
* These are simply the state routines, brought together as GCxxxxx
* The original file I/O is replaced with Memory Read/Writes to the
* statebuffer below
****************************************************************************/
#include <gccore.h>
#include <string.h>
#include <malloc.h>
#include <fat.h>
#include "../../types.h"
#include "../../state.h"
#include "saveicon.h"
#include "iplfont.h"
#include "intl.h"
#define FCEUDIR "fceu"
#define SAVEDIR "saves"
/*** External functions ***/
extern void FCEUPPU_SaveState(void);
extern void FCEUSND_SaveState(void);
extern void WaitPrompt( char *text );
extern void FlipByteOrder(uint8 *src, uint32 count);
extern void ShowAction( char *text );
extern void FCEUD_SetPalette(unsigned char index, unsigned char r, unsigned char g, unsigned char b);
extern void FCEU_ResetPalette(void);
extern void FCEUI_DisableSpriteLimitation( int a );
/*** External save structures ***/
extern SFORMAT SFCPU[];
extern SFORMAT SFCPUC[];
extern SFORMAT FCEUPPU_STATEINFO[];
extern SFORMAT FCEUCTRL_STATEINFO[];
extern SFORMAT FCEUSND_STATEINFO[];
extern SFORMAT SFMDATA[64];
extern u32 iNESGameCRC32;
int CARDSLOT = CARD_SLOTA;
#define RLSB 0x80000000
#define FILESIZEOFFSET 2116
unsigned char statebuffer[64 * 1024] ATTRIBUTE_ALIGN(32); /*** Never had one this big ! ***/
int sboffset; /*** Used as a basic fileptr ***/
int mcversion = 0x981211;
static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN(32);
extern u8 ChosenSlot;
extern u8 ChosenDevice;
extern u8 screenscaler;
extern u8 currpal;
extern u8 slimit;
extern u8 timing;
extern u8 mpads[6];
extern u8 FSDisable;
extern u8 PADCAL;
extern u8 PADTUR;
extern u8 UseSDCARD;
extern u8 UseWiiSDCARD;
extern struct st_palettes {
char *name, *desc;
unsigned int data[64];
} *palettes;
/****************************************************************************
* Memory based file functions
****************************************************************************/
/*** Open a file ***/
void memopen() {
sboffset = 0;
memset(statebuffer, 0, sizeof(statebuffer));
}
/*** Close a file ***/
void memclose() {
sboffset = 0;
}
/*** Write to the file ***/
void memfwrite( void *buffer, int len ) {
if ( (sboffset + len ) > sizeof(statebuffer))
WaitPrompt("Buffer Exceeded");
if ( len > 0 ) {
memcpy(&statebuffer[sboffset], buffer, len );
sboffset += len;
}
}
/*** Read from a file ***/
void memfread( void *buffer, int len ) {
if ( ( sboffset + len ) > sizeof(statebuffer))
WaitPrompt("Buffer exceeded");
if ( len > 0 ) {
memcpy(buffer, &statebuffer[sboffset], len);
sboffset += len;
}
}
/****************************************************************************
* GCReadChunk
*
* Read the array of SFORMAT structures to memory
****************************************************************************/
int GCReadChunk( int chunkid, SFORMAT *sf ) {
int csize;
static char chunk[6];
int chunklength;
int thischunk;
char info[128];
memfread(&chunk, 4);
memfread(&thischunk, 4);
memfread(&chunklength, 4);
if (strcmp(chunk, "CHNK") == 0) {
if (chunkid == thischunk) {
/*** Now decode the array of chunks to this one ***/
while (sf->v) {
memfread(&chunk, 4);
if ( memcmp(&chunk, "CHKE", 4) == 0 )
return 1;
if (memcmp(&chunk, sf->desc, 4) == 0) {
memfread(&csize, 4);
if (csize == (sf->s & (~RLSB ))) {
memfread( sf->v, csize );
sprintf(info,"%s %d", chunk, csize);
} else {
WaitPrompt("Bad chunk link");
return 0;
}
} else {
sprintf(info, "No Sync %s %s", chunk, sf->desc);
WaitPrompt(info);
return 0;
}
sf++;
}
} else
return 0;
} else
return 0;
return 1;
}
/****************************************************************************
* GCFCEUSS_Load
*
* Reads the SFORMAT arrays
****************************************************************************/
int GCFCEUSS_Load() {
int totalsize = 0;
sboffset = 16 + sizeof(saveicon) + 64; /*** Reset memory file pointer ***/
memcpy(&totalsize, &statebuffer[FILESIZEOFFSET], 4);
/*** Now read the chunks back ***/
if (GCReadChunk(1, SFCPU)) {
if (GCReadChunk(2, SFCPUC)) {
if (GCReadChunk(3, FCEUPPU_STATEINFO)) {
if (GCReadChunk(4, FCEUCTRL_STATEINFO)) {
if (GCReadChunk(5, FCEUSND_STATEINFO)) {
if (GCReadChunk(0x10, SFMDATA))
return 1;
}
}
}
}
}
return 0;
}
/****************************************************************************
* GCSaveChunk
*
* Write the array of SFORMAT structures to the file
****************************************************************************/
int GCSaveChunk(int chunkid, SFORMAT *sf) {
int chnkstart;
int csize = 0;
int chsize = 0;
char chunk[] = "CHNK";
/*** Add chunk marker ***/
memfwrite(&chunk, 4);
memfwrite(&chunkid, 4);
chnkstart = sboffset; /*** Save ptr ***/
sboffset += 4; /*** Space for length ***/
csize += 12;
/*** Now run through this structure ***/
while (sf->v) {
/*** Check that there is a decription ***/
if ( sf->desc == NULL)
break;
/*** Write out the description ***/
memfwrite( sf->desc, 4);
/*** Write the length of this chunk ***/
chsize = ( sf->s & (~RLSB) );
memfwrite( &chsize, 4);
if ( chsize > 0 )
/*** Write the actual data ***/
memfwrite( sf->v, chsize );
csize += 8;
csize += chsize;
sf++;
}
/*** Update CHNK length ***/
memcpy(&statebuffer[chnkstart], &csize, 4);
return csize;
}
/****************************************************************************
* GCFCEUSS_Save
*
* This is a modified version of FCEUSS_Save
* It uses memory for it's I/O and has an added CHNK block.
* The file is terminated with CHNK length of 0.
****************************************************************************/
int GCFCEUSS_Save() {
int totalsize = 0;
static unsigned char header[16] = "FCS\xff";
char chunk[] = "CHKE";
int zero = 0;
char Comment[2][100] = { { MENU_CREDITS_TITLE }, { "A GAME" } };
memopen(); /*** Reset Memory File ***/
/*** Add version ID ***/
memcpy(&header[8], &mcversion, 4);
/*** Do internal Saving ***/
FCEUPPU_SaveState();
FCEUSND_SaveState();
/*** Write Icon ***/
memfwrite(&saveicon, sizeof(saveicon));
totalsize += sizeof(saveicon);
/*** And Comments ***/
sprintf(Comment[1], "NES CRC 0x%08x", iNESGameCRC32);
memfwrite(&Comment[0], 64);
totalsize += 64;
/*** Write header ***/
memfwrite(&header, 16);
totalsize += 16;
totalsize += GCSaveChunk(1, SFCPU);
totalsize += GCSaveChunk(2, SFCPUC);
totalsize += GCSaveChunk(3, FCEUPPU_STATEINFO);
totalsize += GCSaveChunk(4, FCEUCTRL_STATEINFO);
totalsize += GCSaveChunk(5, FCEUSND_STATEINFO);
totalsize += GCSaveChunk(0x10, SFMDATA);
/*** Add terminating CHNK ***/
memfwrite(&chunk,4);
memfwrite(&zero,4);
totalsize += 8;
/*** Update size element ***/
memcpy(&statebuffer[FILESIZEOFFSET], &totalsize, 4);
return totalsize;
}
/****************************************************************************
* Card Removed
*
* Straight copy from MemCard demo
****************************************************************************/
int CardReady = 0;
void CardRemoved(s32 chn,s32 result) {
CARD_Unmount(chn);
CardReady = 0;
}
/****************************************************************************
* Snes9xGX Memcard
****************************************************************************/
void uselessinquiry() {
volatile long *udvd = ( volatile long *)0xCC006000;
udvd[0] = 0;
udvd[1] = 0;
udvd[2] = 0x12000000;
udvd[3] = 0;
udvd[4] = 0x20;
udvd[5] = 0x80000000;
udvd[6] = 0x20;
udvd[7] = 1;
while (udvd[7] & 1);
}
int MountTheCard() {
int tries = 0;
int CardError;
while (tries < 10) {
*(unsigned long*)(0xcc006800) |= 1<<13; /*** Disable Encryption ***/
uselessinquiry();
VIDEO_WaitVSync();
//CardError = CARD_Mount(CARDSLOT, SysArea, NULL); /*** Don't need or want a callback ***/
CardError = CARD_Mount(CARDSLOT, SysArea, CardRemoved);
if (CardError == 0)
return 0;
else {
EXI_ProbeReset();
}
tries++;
}
return -1;
}
/****************************************************************************
* MemCard Save
*
* This is based on the code from libogc
****************************************************************************/
void MC_ManageState(int mode, int slot) {
char mcFilename[80];
int CardError;
card_dir CardDir;
card_file CardFile;
int SectorSize;
int found = 0;
int FileSize;
int actualSize;
int savedBytes=0;
char debug[128];
CARDSLOT = slot;
/*** Build the file name ***/
sprintf(mcFilename, "FCEU-%08x.fcs", iNESGameCRC32);
/*** Mount the Card ***/
CARD_Init("FCEU", "00");
/*** Try for memory card in slot A ***/
CardError = MountTheCard();
if (CardError >= 0) {
/*** Get card sector size ***/
CardError = CARD_GetSectorSize(CARDSLOT, &SectorSize);
switch (mode) {
case 0 : { /*** Save Game ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
found = 0;
card_stat CardStatus;
while (CardError != CARD_ERROR_NOFILE) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
/*** Determine number of sectors required ***/
savedBytes = actualSize = GCFCEUSS_Save();
sprintf(debug, "Saving in MC ...");
ShowAction(debug);
FileSize = ( actualSize / SectorSize ) * SectorSize;
if (actualSize % SectorSize)
FileSize += SectorSize;
/*** Now write the file out ***/
if (!found)
CardError = CARD_Create(CARDSLOT, mcFilename, FileSize, &CardFile);
else
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CARD_GetStatus(CARDSLOT, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0;
CardStatus.icon_fmt = 2;
CardStatus.icon_speed = 1;
CardStatus.comment_addr = sizeof(saveicon);
CARD_SetStatus(CARDSLOT, CardFile.filenum, &CardStatus);
/*** Haha! libogc only write one block at a time! ***/
if (CardError == 0) {
int sbo = 0;
while (actualSize > 0) {
CardError = CARD_Write(&CardFile, &statebuffer[sbo], SectorSize, sbo );
actualSize -= SectorSize;
sbo += SectorSize;
}
CardError = CARD_Close(&CardFile);
sprintf(debug, "Saved %d bytes successfully!", savedBytes);
WaitPrompt(debug);
} else {
WaitPrompt("Save Failed");
}
CARD_Unmount(CARDSLOT);
}
break; /*** End save ***/
case 1: { /*** Load state ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
memopen(); /*** Clear the buffer ***/
found = 0;
while (CardError != CARD_ERROR_NOFILE) {
CardError = CARD_FindNext(&CardDir);
if (strcmp(CardDir.filename, mcFilename) == 0)
found = 1;
}
if (found == 0) {
WaitPrompt("No Save Game Found");
CARD_Unmount(CARDSLOT);
return;
}
/*** Load the file into memory ***/
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CardError = CARD_Read(&CardFile, &statebuffer, SectorSize, 0);
/*** Get actual size of the file ***/
memcpy(&actualSize, &statebuffer[FILESIZEOFFSET], 4);
savedBytes = actualSize;
int sbo = SectorSize;
actualSize -= SectorSize;
while(actualSize > 0) {
CARD_Read(&CardFile, &statebuffer[sbo], SectorSize, sbo);
actualSize -= SectorSize;
sbo += SectorSize;
}
CARD_Close(&CardFile);
/*** Finally, do load ***/
GCFCEUSS_Load();
CARD_Unmount(CARDSLOT);
sprintf(debug, "Loaded %d bytes successfully!", savedBytes);
WaitPrompt(debug);
}
break; /*** End load ***/
default: break;
}
} else {
WaitPrompt("Cannot Mount Memory Card!");
}
}
void SD_ManageState(int mode, int slot) {
char path[1024];
char msg[128];
int filesize = 0;
int len = 0;
int offset = 0;
FILE *handle;
if (mode == 0) ShowAction ("Saving STATE to SD...");
else ShowAction ("Loading STATE from SD...");
sprintf (path, "/%s/%s/%08x.fcs", FCEUDIR, SAVEDIR, iNESGameCRC32);
handle = fopen(path, (mode == 0) ? "wb" : "rb");
if (handle == NULL) {
sprintf(msg, "Couldn't open %s", path);
WaitPrompt(msg);
return;
}
if (mode == 0) { //Save
filesize = GCFCEUSS_Save();
len = fwrite(statebuffer, filesize, 1, handle);
fclose(handle);
/*if (len != filesize){
sprintf (msg, "Error writing %s", path);
WaitPrompt (msg);
return;
}*/
sprintf (msg, "Saved %d bytes successfully", filesize);
WaitPrompt (msg);
} else { //Load
memopen();
while ((len = fread(&statebuffer[offset], 1, 1024, handle)) > 0)
offset += len;
fclose(handle);
sprintf (msg, "Loaded %d bytes successfully", offset);
WaitPrompt(msg);
GCFCEUSS_Load();
return;
}
}
void ManageState(int mode, int slot, int device) {
if (device == 0) {
MC_ManageState(mode, slot);
}
else {
SD_ManageState(mode, slot);
}
}
/* u8 screenscaler
* u8 currpal
* u8 slimit
* u8 timing
* u8 mpads[6]
* int FSDisable (int is u32, 4 bytes)
* u8 PADCAL
* u8 PADTUR
* u8 ChosenSlot
* u8 ChosenDevice
* u8 UseSDCARD
* u8 UseWiiSDCARD
*/
int SaveSettings(u8 *buffer) {
int filesize = 0;
buffer[filesize++] = screenscaler;
buffer[filesize++] = currpal;
buffer[filesize++] = slimit;
buffer[filesize++] = timing;
buffer[filesize++] = mpads[0];
buffer[filesize++] = mpads[1];
buffer[filesize++] = mpads[2];
buffer[filesize++] = mpads[3];
buffer[filesize++] = mpads[4];
buffer[filesize++] = mpads[5];
buffer[filesize++] = FSDisable;
buffer[filesize++] = PADCAL;
buffer[filesize++] = PADTUR;
buffer[filesize++] = ChosenSlot;
buffer[filesize++] = ChosenDevice;
buffer[filesize++] = UseSDCARD;
buffer[filesize++] = UseWiiSDCARD;
return filesize+1;
}
int LoadSettings(u8 *buffer) {
int filesize = 0;
screenscaler = buffer[filesize++];
currpal = buffer[filesize++];
if (currpal == 0)
FCEU_ResetPalette();
else {
u8 r, g, b, i;
/*** Now setup this palette ***/
for ( i = 0; i < 64; i++ ) {
r = palettes[currpal-1].data[i] >> 16;
g = ( palettes[currpal-1].data[i] & 0xff00 ) >> 8;
b = ( palettes[currpal-1].data[i] & 0xff );
FCEUD_SetPalette( i, r, g, b);
FCEUD_SetPalette( i+64, r, g, b);
FCEUD_SetPalette( i+128, r, g, b);
FCEUD_SetPalette( i+192, r, g, b);
}
}
slimit = buffer[filesize++];
FCEUI_DisableSpriteLimitation(slimit);
timing = buffer[filesize++];
FCEUI_SetVidSystem(timing);
mpads[0] = buffer[filesize++];
mpads[1] = buffer[filesize++];
mpads[2] = buffer[filesize++];
mpads[3] = buffer[filesize++];
mpads[4] = buffer[filesize++];
mpads[5] = buffer[filesize++];
FSDisable = buffer[filesize++];
FCEUI_DisableFourScore(FSDisable);
PADCAL = buffer[filesize++];
PADTUR = buffer[filesize++];
ChosenSlot = buffer[filesize++];
ChosenDevice = buffer[filesize++];
UseSDCARD = buffer[filesize++];
UseWiiSDCARD = buffer[filesize++];
return filesize+1;
}
/****************************************************************************
* Save Settings to MemCard
****************************************************************************/
void MC_ManageSettings(int mode, int slot, int quiet) {
char mcFilename[80];
int CardError;
card_dir CardDir;
card_file CardFile;
int SectorSize;
int found = 0;
int FileSize;
int actualSize;
int savedBytes=0;
char msg[128];
/*** Build the file name ***/
strcpy(mcFilename, "FCEU-Settings.fcs");
/*** Mount the Card ***/
CARD_Init("FCEU", "00");
/*** Try for memory card in slot A ***/
CardError = MountTheCard();
if (CardError >= 0) {
/*** Get card sector size ***/
CardError = CARD_GetSectorSize(slot, &SectorSize);
switch (mode) {
case 0 : { /*** Save Game ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(slot, &CardDir, true);
found = 0;
card_stat CardStatus;
while (CardError != CARD_ERROR_NOFILE) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
/*** Determine number of bytes required ***/
u8 buffer[SectorSize];
memset(buffer, 0, SectorSize);
actualSize = SaveSettings(buffer);
savedBytes = actualSize;
sprintf(msg, "Saving Settings to MC ...");
ShowAction(msg);
FileSize = (actualSize / SectorSize) * SectorSize;
if ((actualSize % SectorSize) || (FileSize == 0))
FileSize += SectorSize;
/*** Now write the file out ***/
if (!found)
CardError = CARD_Create(CARDSLOT, mcFilename, FileSize, &CardFile);
else
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CARD_GetStatus(CARDSLOT, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0;
CardStatus.icon_fmt = 2;
CardStatus.icon_speed = 1;
CardStatus.comment_addr = sizeof(saveicon);
CARD_SetStatus(CARDSLOT, CardFile.filenum, &CardStatus);
/*** Haha! libogc only write one block at a time! ***/
if (CardError == 0) {
int sbo = 0;
while (actualSize > 0) {
CardError = CARD_Write(&CardFile, &buffer[sbo], SectorSize, sbo );
actualSize -= SectorSize;
sbo += SectorSize;
}
CardError = CARD_Close(&CardFile);
strcpy(msg, "Saved settings successfully");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
}
else {
strcpy(msg, "Save Settings Failed!");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
}
CARD_Unmount(CARDSLOT);
}
break; /*** End save ***/
case 1: { /*** Load state ***/
/*** Look for this file ***/
CardError = CARD_FindFirst(CARDSLOT, &CardDir, true);
found = 0;
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if (strcmp(CardDir.filename, mcFilename) == 0)
found = 1;
}
if (found == 0) {
strcpy(msg, "No Settings Found");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
CARD_Unmount(CARDSLOT);
return;
}
u8 buffer[SectorSize];
/*** Load the file into memory ***/
CardError = CARD_Open(CARDSLOT, mcFilename, &CardFile);
CardError = CARD_Read(&CardFile, &buffer, SectorSize, 0);
CARD_Close(&CardFile);
/*** Finally, do load ***/
savedBytes = LoadSettings(buffer);
sprintf(msg, "Loaded settings successfully!");
ShowAction(msg);
CARD_Unmount(CARDSLOT);
}
break; /*** End load ***/
default: break;
}
} else {
strcpy(msg, "Cannot mount Memory Card!");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
}
}
void SD_ManageSettings(int mode, int slot, int quiet) {
char path[1024];
char msg[128];
int filesize = 0;
int len = 0;
u8 buffer[128];
if (mode == 0) ShowAction ("Saving Settings to SD...");
else ShowAction ("Loading Settings from SD...");
sprintf(path, "/%s/%s/Settings.fcs", FCEUDIR, SAVEDIR);
FILE *f = fopen(path, (mode == 0) ? "wb" : "rb");
if (f == NULL) {
sprintf(msg, "Couldn't open %s", path);
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
return;
}
if (mode == 0) { // Save
filesize = SaveSettings(buffer);
len = fwrite(buffer, filesize, 1, f);
fclose(f);
sprintf(msg, "Saved settings successfully");
if (quiet) ShowAction(msg);
else WaitPrompt(msg);
} else { // Load
fread(buffer, 128, 1, f);
fclose(f);
/*** Finally, do load ***/
filesize = LoadSettings(buffer);
sprintf (msg, "Loaded settings successfully");
ShowAction(msg);
return;
}
}
void ManageSettings(int mode, int slot, int device, int quiet) {
if (device == 0) {
MC_ManageSettings(mode, slot, quiet);
}
else {
SD_ManageSettings(mode, slot, quiet);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,155 +0,0 @@
/****************************************************************************
* Gamecube Input
*
* Use JOY1 and JOY2
****************************************************************************/
#include <gccore.h>
#include "../../driver.h"
#include "../../fceu.h"
/* PADStatus joypads[4]; */
static uint32 JSReturn = 0;
unsigned short skipa[4] = {0, 0, 0, 0};
unsigned short skipb[4] = {0, 0, 0, 0};
unsigned short op[4] = {0, 0, 0, 0};
extern int MainMenu();
/****************************************************************************
* Initialise Pads
****************************************************************************/
void InitialisePads()
{
int attrib = 0;
void *InputDPR;
FCEUI_DisableFourScore(1);
InputDPR = &JSReturn;
FCEUI_SetInput(0, SI_GAMEPAD, InputDPR, attrib);
FCEUI_SetInput(1, SI_GAMEPAD, InputDPR, attrib);
}
unsigned short gcpadmap[] = { PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_START, PAD_TRIGGER_Z, PAD_BUTTON_X, PAD_BUTTON_Y,
PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT };
unsigned int nespadmap[] = { JOY_A, JOY_B, JOY_START, JOY_SELECT, JOY_A, JOY_B,
JOY_UP, JOY_DOWN, JOY_LEFT, JOY_RIGHT };
/****************************************************************************
* Convert GC Joystick Readings to JOY
****************************************************************************/
u8 PADTUR = 2;
unsigned char DecodeJoy( unsigned short pp )
{
unsigned short p = PAD_ButtonsHeld(pp);
unsigned char J = 0;
int i;
if ((skipa[pp] == 0) || ((op[pp] & gcpadmap[4]) == 0)) {
nespadmap[4] = JOY_A;
skipa[pp] = PADTUR;
}
if ((skipb[pp] == 0) || ((op[pp] & gcpadmap[5]) == 0)) {
nespadmap[5] = JOY_B;
skipb[pp] = PADTUR;
}
for (i = 0; i < 10; i++) {
if (p & gcpadmap[i])
J |= nespadmap[i];
}
if (skipa[pp] > 0){
nespadmap[4] = 0;
skipa[pp]--;
}
if (skipb[pp] > 0){
nespadmap[5] = 0;
skipb[pp]--;
}
op[pp] = p;
return J;
}
/****************************************************************************
* V 1.0.1
*
* Additional check for Analog X/Y
****************************************************************************/
u8 PADCAL = 40;
unsigned char GetAnalog(int Joy)
{
signed char x, y;
unsigned char i = 0;
x = PAD_StickX(Joy);
y = PAD_StickY(Joy);
if (x * x + y * y > PADCAL * PADCAL) {
if (x > 0 && y == 0) return JOY_RIGHT;
if (x < 0 && y == 0) return JOY_LEFT;
if (x == 0 && y > 0) return JOY_UP;
if (x == 0 && y < 0) return JOY_DOWN;
if ((float)y / x >= -2.41421356237 && (float)y / x < 2.41421356237) {
if (x >= 0)
i |= JOY_RIGHT;
else
i |= JOY_LEFT;
}
if ((float)x / y >= -2.41421356237 && (float)x / y < 2.41421356237) {
if (y >= 0)
i |= JOY_UP;
else
i |= JOY_DOWN;
}
}
return i;
}
int GetJoy()
{
unsigned char pad[4];
short i;
int t = 0;
void (*PSOReload)() = (void(*)())0x80001800;
/*** Before checking anything else, look for PSOReload ***/
if ( PAD_ButtonsHeld(0) == ( PAD_BUTTON_B | PAD_BUTTON_X | PAD_BUTTON_START ) )
PSOReload();
/*** Look for config menu ***/
signed char px;
px = PAD_SubStickX (0);
if (((px < -PADCAL)) || (PAD_ButtonsHeld(0) == ( PAD_TRIGGER_L | PAD_TRIGGER_R ))) {
t = MainMenu();
if (t == 1) {
return 1;
}
}
for (i = 0; i < 4; i++)
pad[i] = DecodeJoy(i) | GetAnalog(i);
JSReturn = pad[0] | pad[1] << 8 | pad[2] << 16 | pad[3] << 24;
return 0;
}

View File

@ -1,132 +0,0 @@
unsigned short saveicon[1024] = {
0xDAD6, 0xEF7B, 0xE318, 0xCA52, 0xA94A, 0xCA52, 0xF7BD, 0xF7BD,
0x8C63, 0xA108, 0xCE73, 0xBDEF, 0x8421, 0x8C63, 0x9CE7, 0x8C63,
0xB5AD, 0xAD6B, 0xA94A, 0xCE71, 0xDEF7, 0xCE73, 0xF7BB, 0xFFFF,
0xA94A, 0xC20F, 0xEB58, 0xFBBB, 0x8421, 0xC1EE, 0xE2F5, 0xDED3,
0xDEF5, 0xDED4, 0xDEF4, 0xDED4, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xF7BA, 0xF7BA, 0xFBBA, 0xFBBA, 0xDAD4, 0xDED4, 0xDED4, 0xDED4,
0xDAB3, 0xDAB3, 0xDAB3, 0xD6B3, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFBBA, 0xFBBB, 0xFBBA, 0xFBBA, 0xDED4, 0xDEF4, 0xDED4, 0xCA0E,
0xD692, 0xD692, 0xD692, 0xD272, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFBB, 0xFFBB, 0xFBBA, 0xFBBA, 0xBD8A, 0xDAB2, 0xE2F4, 0xE2F4,
0xD292, 0xD692, 0xD692, 0xD292, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFBBA, 0xF7BA, 0xF798, 0xF799, 0xE2F4, 0xE2F4, 0xDAB2, 0xDAD2,
0xD272, 0xCE71, 0xBDEE, 0xA529, 0xFFFF, 0xFFFF, 0xFFFF, 0xDAD4,
0xFBBA, 0xFBBA, 0xFB99, 0xD270, 0xDED4, 0xDED3, 0xDED3, 0xD670,
0x98C6, 0x8C63, 0x8421, 0x8000, 0x9CE7, 0x8842, 0x8000, 0x8000,
0x9CE5, 0x8000, 0x8000, 0x8000, 0xA0E5, 0x8000, 0x8000, 0x8000,
0x8421, 0x8842, 0x9084, 0x8421, 0x8000, 0x8421, 0x8C63, 0xB9CC,
0x8000, 0x8421, 0xB18B, 0xD6B3, 0x8000, 0x8421, 0xD6B3, 0xE717,
0xA528, 0xCE71, 0xDED4, 0xDAD3, 0xCE71, 0xE736, 0xE315, 0xE2F5,
0xE316, 0xDAD4, 0xDAD4, 0xDAD4, 0xB18B, 0xA528, 0xA528, 0xA128,
0xDAB3, 0xDED3, 0xDED4, 0xDED4, 0xE2F5, 0xE715, 0xE715, 0xE715,
0xDED4, 0xDED4, 0xDED4, 0xDED4, 0xA107, 0xA507, 0xA528, 0xA528,
0xDED4, 0xDED4, 0xDED4, 0xDEB3, 0xE715, 0xE716, 0xE715, 0xE716,
0xDED5, 0xDED4, 0xDED5, 0xDEF5, 0xA528, 0xA528, 0xA528, 0xA528,
0xDA92, 0xDED3, 0xDED3, 0xDAD3, 0xE716, 0xE716, 0xE715, 0xE2F5,
0xDEF5, 0xDEF5, 0xE2F5, 0xE2F5, 0xA528, 0xA528, 0xA528, 0xA528,
0xDED3, 0xDED3, 0xDAB2, 0xDAB3, 0xE715, 0xE715, 0xE2F4, 0xE2F5,
0xE2F5, 0xE2F5, 0xE315, 0xE315, 0xA528, 0xA528, 0xA528, 0xA528,
0xDED3, 0xDED3, 0xDEB2, 0xDA90, 0xE2F5, 0xE315, 0xE2F4, 0xDEB2,
0xE316, 0xE716, 0xEB36, 0xEF37, 0xA928, 0xA528, 0xA928, 0xB5AB,
0xA927, 0x8000, 0x8000, 0x8000, 0xB589, 0xB189, 0x8000, 0x8000,
0xD670, 0xB9AB, 0x98C4, 0x8000, 0xDED3, 0xD26F, 0xA927, 0x8000,
0x8000, 0xAD8B, 0xE738, 0xC210, 0x8000, 0xB9CD, 0xF39B, 0xA109,
0x8000, 0xBE0F, 0xEB5A, 0xA52A, 0x8000, 0xC20F, 0xE739, 0xAD6D,
0x94A4, 0x9084, 0x9084, 0x9084, 0x8442, 0x8842, 0x8842, 0x9083,
0x8843, 0x8C63, 0x8C62, 0x8841, 0x98E8, 0x94A6, 0x8862, 0x8842,
0x9083, 0x9083, 0x9083, 0x9084, 0x94A5, 0x94A5, 0x94A5, 0x94A4,
0x8862, 0x8862, 0x8842, 0x8842, 0x8842, 0x8841, 0x8421, 0x8421,
0x9484, 0x9484, 0x9084, 0x9084, 0x94A4, 0x94A5, 0x94A5, 0x94A5,
0x8862, 0x8862, 0x8C62, 0x8C62, 0x8421, 0x8421, 0x8421, 0x8421,
0x94A4, 0x9084, 0x94A4, 0x94A4, 0x94A5, 0x94A5, 0x94A5, 0x94A5,
0x8C62, 0x8C62, 0x8C62, 0x8C62, 0x8421, 0x8421, 0x8421, 0x8421,
0x94A4, 0x94A4, 0x94A4, 0x94A4, 0x94A5, 0x94A5, 0x94A5, 0x9083,
0x8C62, 0x8C63, 0x8C63, 0x9484, 0x8421, 0x8421, 0x8421, 0x8841,
0x94A4, 0x94A4, 0x94A4, 0x9CE6, 0x8C62, 0x8842, 0x8841, 0x8841,
0x9083, 0x8C62, 0x8C63, 0x8841, 0x8C62, 0x8C62, 0x8C62, 0x8421,
0xB58A, 0xDA91, 0xB58A, 0x8000, 0x94A4, 0xDA91, 0xBDCB, 0x8000,
0x9062, 0xD690, 0xBDCB, 0x8000, 0x8C62, 0xDA91, 0xC5ED, 0x8000,
0x8000, 0xBDEF, 0xEB5A, 0x98C7, 0x8000, 0xB9CD, 0xEB5A, 0x90A5,
0x8000, 0xA549, 0xD294, 0x98E7, 0x8000, 0x8421, 0xC651, 0xA128,
0xA96D, 0x9085, 0x8C63, 0x8C63, 0x94A6, 0x8421, 0x9CE7, 0x8C63,
0x8422, 0x8421, 0xA529, 0x94A4, 0x8421, 0x8421, 0x98C5, 0x9083,
0x8C63, 0x8C63, 0x8C63, 0x8C63, 0x8842, 0x8C62, 0x8C63, 0x9084,
0x8842, 0x8C62, 0x9084, 0x8C63, 0x8C42, 0x8C62, 0x8842, 0x8862,
0x8421, 0x8421, 0x8421, 0x8421, 0x8C63, 0x8421, 0x8421, 0x8421,
0x94A4, 0x8842, 0x8421, 0x8421, 0x9D07, 0x8862, 0x8421, 0x8421,
0x8421, 0x8421, 0x8421, 0x8C63, 0x8421, 0x8421, 0x8421, 0x94A4,
0x8421, 0x8421, 0x8421, 0xA108, 0x8421, 0x8421, 0x8421, 0xAD6B,
0x9084, 0x8421, 0x8421, 0x8441, 0x94A4, 0x8421, 0x8421, 0x8421,
0x94A4, 0x8821, 0x8841, 0x8841, 0x9484, 0x8421, 0x8842, 0x8842,
0x8841, 0x8421, 0x8841, 0x8420, 0x9084, 0x9084, 0x8C62, 0x8421,
0x94A4, 0x9CE7, 0x8842, 0x8421, 0x9084, 0x98C5, 0x8841, 0x8421,
0x8C62, 0xDA91, 0xC5ED, 0x8000, 0x9083, 0xDA92, 0xC1ED, 0x8000,
0x94A4, 0xC1ED, 0xAD69, 0x8000, 0x98A5, 0xB5AB, 0x8000, 0x8000,
0x8000, 0x8421, 0xC230, 0xA94A, 0x8000, 0x8421, 0xBE0F, 0xAD6B,
0x8000, 0x8421, 0xA98B, 0xB5CD, 0x8000, 0x8421, 0x8C63, 0xA149,
0x8421, 0x8421, 0x94A4, 0x90A4, 0x8020, 0x8421, 0x8841, 0x9484,
0x8862, 0x8421, 0x8420, 0x8821, 0xA128, 0xA129, 0xA549, 0x8883,
0x8842, 0x8842, 0x8841, 0x8C63, 0x8C42, 0x8842, 0x8841, 0x9084,
0x8842, 0x8842, 0x8842, 0x8C63, 0x8441, 0x8421, 0x8421, 0x8842,
0x9CE7, 0x8842, 0x8421, 0x8421, 0x9084, 0x8421, 0x8421, 0x8421,
0x8842, 0x8422, 0x8421, 0x8421, 0x8421, 0x8822, 0x8822, 0x8421,
0x8841, 0x8421, 0x8841, 0x98C5, 0x8441, 0x8421, 0x8441, 0x8C63,
0x8421, 0x8421, 0x8441, 0x8421, 0x8421, 0x8421, 0x8421, 0x8421,
0x94A4, 0x8000, 0x8421, 0x8842, 0x9084, 0x8842, 0x8421, 0x8842,
0x8C42, 0x8C62, 0x8822, 0x8842, 0x8421, 0x8821, 0x8821, 0x8841,
0x8842, 0x8C63, 0x8841, 0x8021, 0x8C63, 0x9084, 0x8421, 0x8000,
0x8842, 0x8C43, 0x8421, 0x8000, 0x9484, 0xA0E7, 0x9CC6, 0xB58B,
0x9CC5, 0xB5AB, 0x8000, 0x8000, 0xA527, 0xB18A, 0x8000, 0x8000,
0xB9AB, 0xB18A, 0x8000, 0x8000, 0xDAB3, 0xC1ED, 0xB58A, 0xA106,
0x8000, 0x8421, 0x8C63, 0x8421, 0x8000, 0x8421, 0x8C63, 0x8421,
0x8000, 0x8421, 0x8C63, 0x8421, 0x8000, 0x8421, 0x8C63, 0xAD8C,
0x8000, 0x8000, 0x8000, 0x90C5, 0x8000, 0x8000, 0x90A5, 0xA129,
0x98E7, 0xB5CE, 0xC652, 0xC210, 0xC651, 0xE318, 0xDEF7, 0xCE72,
0x94C6, 0xA529, 0xB9CE, 0xC632, 0xCA52, 0xDAD6, 0xDAD6, 0xD6B6,
0xD6B5, 0xD6B6, 0xD6B6, 0xD6B5, 0xC631, 0xD6B6, 0xD6B6, 0xD6B5,
0xC632, 0xB18D, 0xB16C, 0xA108, 0xEF7C, 0xE73A, 0xD6B6, 0xB5AD,
0xEB5A, 0xEF9C, 0xDEF7, 0xD693, 0xE73A, 0xF39D, 0xDAB5, 0xD271,
0x8401, 0xA108, 0xA528, 0xA508, 0x9083, 0xC20F, 0xCA30, 0xCA30,
0xC60F, 0xD272, 0xD271, 0xD250, 0xD671, 0xCE2F, 0xD270, 0xD670,
0xA929, 0xB16A, 0xBDED, 0xCA2F, 0xD250, 0xCA0E, 0xDA92, 0xDAB2,
0xD24F, 0xD24E, 0xD250, 0xCE2E, 0xD670, 0xD66F, 0xD64F, 0xCE2D,
0xD271, 0xDEB4, 0xDED4, 0xDED4, 0xD670, 0xD24F, 0xDA70, 0xD670,
0xD24E, 0xD24E, 0xD24E, 0xD24F, 0xD22E, 0xD24E, 0xD64E, 0xD64E,
0xDAB2, 0xCE50, 0xCA2E, 0xCA0D, 0xD670, 0xCE2E, 0xC5ED, 0xC5EC,
0xD24F, 0xCE0D, 0xC5EC, 0xC5EC, 0xD24E, 0xCE2D, 0xCA0C, 0xCA0D,
0x8000, 0x8421, 0xD2B4, 0xDAF7, 0x8000, 0x9D08, 0xE75A, 0xEB7B,
0x90C6, 0xB5CE, 0xEF7C, 0xF7BD, 0xBE0F, 0xEB39, 0xE739, 0xF39C,
0xE318, 0xDEF7, 0xDEF7, 0xDEF7, 0xDEF8, 0xE318, 0xDEF8, 0xE2F8,
0xE739, 0xE318, 0xE318, 0xE318, 0xF39C, 0xE739, 0xE739, 0xE739,
0xC630, 0xCA52, 0xDAB6, 0xD6B5, 0xDED6, 0xC20F, 0xD293, 0xD6B5,
0xE319, 0xDAD6, 0xC630, 0xDEF7, 0xE718, 0xE739, 0xDAB5, 0xD294,
0xE739, 0xF39D, 0xE2F7, 0xDAB3, 0xDEF8, 0xF39D, 0xE718, 0xDAD4,
0xDAD6, 0xF39D, 0xE739, 0xDED4, 0xD274, 0xE73A, 0xEB5A, 0xE2F5,
0xD270, 0xD670, 0xD671, 0xD691, 0xD670, 0xDA91, 0xDA91, 0xDA91,
0xDA91, 0xDEB1, 0xDEB2, 0xE2D2, 0xDEB2, 0xE2D3, 0xE2D3, 0xE2D3,
0xDA91, 0xDA91, 0xD66F, 0xD22D, 0xDEB2, 0xDE91, 0xCE2D, 0xD22E,
0xE6D3, 0xE2B2, 0xC9EC, 0xCA0D, 0xE6F3, 0xDA90, 0xCA0D, 0xCA0D,
0xD24E, 0xD24E, 0xD64E, 0xD66F, 0xD24E, 0xD64E, 0xD66F, 0xDA70,
0xD66F, 0xDA70, 0xDA91, 0xDA92, 0xDEB3, 0xDEB3, 0xE2D4, 0xE2D4,
0xD64F, 0xCE2E, 0xCE2E, 0xD24F, 0xD670, 0xCE2E, 0xD24F, 0xD670,
0xDAB2, 0xD250, 0xCE2E, 0xB148, 0xE2D4, 0xDA92, 0xD24F, 0xB969,
0xE739, 0xE317, 0xE318, 0xE739, 0xE318, 0xDEF7, 0xDAD6, 0xDAD6,
0xDEF7, 0xDAD6, 0xD6B5, 0xD6B4, 0xDEF7, 0xDAD6, 0xD6B4, 0xD294,
0xF7BD, 0xEB5A, 0xE739, 0xE738, 0xE318, 0xE739, 0xDAD6, 0xDAD6,
0xD294, 0xDAD6, 0xDAD6, 0xD294, 0xD294, 0xD294, 0xDAD6, 0xD294,
0xE738, 0xE739, 0xEB39, 0xD693, 0xDAD6, 0xDAD6, 0xDED6, 0xDAD5,
0xD294, 0xD294, 0xD294, 0xD694, 0xD273, 0xD293, 0xD273, 0xD273,
0xC630, 0xD6B5, 0xE738, 0xE2F5, 0xC630, 0xC631, 0xD6B5, 0xDAB3,
0xCE72, 0xC1EF, 0xCE72, 0xCA30, 0xD293, 0xC630, 0xC610, 0xD272,
0xDEB2, 0xE2D3, 0xE2D3, 0xDEB2, 0xD270, 0xD250, 0xCE2F, 0xD24F,
0xC60E, 0xCA2F, 0xCE50, 0xD271, 0xCE50, 0xCE51, 0xD251, 0xD271,
0xD670, 0xDEB2, 0xE2D3, 0xD691, 0xD691, 0xDAB2, 0xD692, 0xD693,
0xD271, 0xCE71, 0xD271, 0xD272, 0xD271, 0xD271, 0xD271, 0xD271,
0xE716, 0xE716, 0xE2F5, 0xE716, 0xDAB4, 0xE2F6, 0xDAB4, 0xDEB4,
0xD272, 0xDAB4, 0xDAB3, 0xD271, 0xD672, 0xD692, 0xDAB4, 0xD250,
0xE6F6, 0xDEB3, 0xD670, 0xD24F, 0xDEB3, 0xD691, 0xD670, 0xD670,
0xD270, 0xD270, 0xD250, 0xD671, 0xCE4F, 0xCE4F, 0xCE2F, 0xD24F,
};

View File

@ -1,372 +0,0 @@
/****************************************************************************
* SZ.C
* svpe June 2007
*
* This file manages the 7zip support for this emulator.
* Currently it only provides functions for loading a 7zip file from a DVD.
****************************************************************************/
#ifdef HW_DOL // only do 7zip in Gamecube mode for now...
#include "iplfont.h"
#include "sz.h"
#include "gcdvd.h"
extern u8 UseSDCARD;
extern u8 UseWiiSDCARD;
extern FILE *filehandle;
extern void GetSDInfo();
// 7zip error list
char szerrormsg[][30] = {
"7z: Data error",
"7z: Out of memory",
"7z: CRC Error",
"7z: Not implemented",
"7z: Fail",
"7z: Archive error"
};
SZ_RESULT SzRes;
SzFileInStream SzArchiveStream;
CArchiveDatabaseEx SzDb;
ISzAlloc SzAllocImp;
ISzAlloc SzAllocTempImp;
UInt32 SzBlockIndex = 0xFFFFFFFF;
size_t SzBufferSize;
size_t SzOffset;
size_t SzOutSizeProcessed;
CFileItem *SzF;
char sz_buffer[2048];
// needed because there are no header files -.-
//#include <sdcard.h>
#define MAXFILES 1000
#define MAXJOLIET 256
extern FILEENTRIES filelist[MAXFILES];
extern int selection;
extern int maxfiles;
extern int offset;
// the GC's dvd drive only supports offsets and length which are a multiply of 32 bytes
// additionally the max length of a read is 2048 bytes
// this function removes these limitations
// additionally the 7zip SDK does often read data in 1 byte parts from the DVD even when
// it could read 32 bytes. the dvdsf_buffer has been added to avoid having to read the same sector
// over and over again
unsigned char dvdsf_buffer[DVD_SECTOR_SIZE];
u64 dvdsf_last_offset = 0;
u64 dvdsf_last_length = 0;
int dvd_buffered_read(void *dst, u32 len, u64 offset) {
int ret = 0;
// only read data if the data inside dvdsf_buffer cannot be used
if(offset != dvdsf_last_offset || len > dvdsf_last_length) {
char msg[1024];
sprintf(msg, "buff_read: len=%d, offset=%llX, UseSD=%d", len, offset, UseSDCARD);
//WaitPrompt(msg);
memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE);
if (UseSDCARD) {
if (filehandle == NULL)
GetSDInfo();
fseek(filehandle, offset, SEEK_SET);
fread(&dvdsf_buffer, len, 1, filehandle);
} else if (!UseWiiSDCARD)
ret = dvd_read(&dvdsf_buffer, len, offset);
dvdsf_last_offset = offset;
dvdsf_last_length = len;
}
memcpy(dst, &dvdsf_buffer, len);
return ret;
}
int dvd_safe_read(void *dst_v, u32 len, u64 offset) {
unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector
// if read size and length are a multiply of DVD_(OFFSET,LENGTH)_MULTIPLY and length < DVD_MAX_READ_LENGTH
// we don't need to fix anything
if(len % DVD_LENGTH_MULTIPLY == 0 && offset % DVD_OFFSET_MULTIPLY == 0 && len <= DVD_MAX_READ_LENGTH) {
char msg[1024];
sprintf(msg, "simple_safe_read: len=%d, offset=%llX, UseSD=%d", len, offset, UseSDCARD);
//WaitPrompt(msg);
int ret = dvd_buffered_read(buffer, len, offset);
memcpy(dst_v, &buffer, len);
return ret;
} else {
char msg[1024];
sprintf(msg, "complex_safe_read: len=%d, offset=%llX, UseSD=%d", len, offset, UseSDCARD);
//WaitPrompt(msg);
// no errors yet -> ret = 0
// the return value of dvd_read will be OR'd with ret
// because dvd_read does return 1 on error and 0 on success and
// because 0 | 1 = 1 ret will also contain 1 if at least one error
// occured and 0 otherwise ;)
int ret = 0; // return value of dvd_read
// we might need to fix all 3 issues
unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types
u64 bytesToRead; // the number of bytes we still need to read & copy to the output buffer
u64 currentOffset; // the current dvd offset
u64 bufferOffset; // the current buffer offset
u64 i, j, k; // temporary variables which might be used for different stuff
// unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector
currentOffset = offset;
bytesToRead = len;
bufferOffset = 0;
// fix first issue (offset is not a multiply of 32)
if(offset % DVD_OFFSET_MULTIPLY) {
// calcualte offset of the prior 32 byte position
i = currentOffset - (currentOffset % DVD_OFFSET_MULTIPLY);
// calculate the offset from which the data of the dvd buffer will be copied
j = currentOffset % DVD_OFFSET_MULTIPLY;
// calculate the number of bytes needed to reach the next DVD_OFFSET_MULTIPLY byte mark
k = DVD_OFFSET_MULTIPLY - j;
// maybe we'll only need to copy a few bytes and we therefore don't even reach the next sector
if(k > len) {
k = len;
}
// read 32 bytes from the last 32 byte position
ret |= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i);
// copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead
memcpy(&dst[bufferOffset], &buffer[j], k);
currentOffset += k;
bufferOffset += k;
bytesToRead -= k;
}
// fix second issue (more than 2048 bytes are needed)
if(bytesToRead > DVD_MAX_READ_LENGTH) {
// calculate the number of 2048 bytes sector needed to get all data
i = (bytesToRead - (bytesToRead % DVD_MAX_READ_LENGTH)) / DVD_MAX_READ_LENGTH;
// read data in 2048 byte sector
for(j = 0; j < i; j++) {
ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector
memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer
// update currentOffset, bufferOffset and bytesToRead
currentOffset += DVD_MAX_READ_LENGTH;
bufferOffset += DVD_MAX_READ_LENGTH;
bytesToRead -= DVD_MAX_READ_LENGTH;
}
}
// fix third issue (length is not a multiply of 32)
if(bytesToRead) {
ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd
memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer
}
//free(tmp);
return ret;
}
}
// function used by the 7zip SDK to read data from the DVD (fread)
SZ_RESULT SzDvdFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object;
// calculate dvd sector offset
u64 offset = (u64)(s->offset + s->pos);
if(maxRequiredSize > 2048)
{
maxRequiredSize = 2048;
}
// read data
dvd_safe_read(sz_buffer, maxRequiredSize, offset);
*buffer = sz_buffer;
*processedSize = maxRequiredSize;
s->pos += *processedSize;
return SZ_OK;
}
// function used by the 7zip SDK to change the filepointer (fseek(object, pos, SEEK_SET))
SZ_RESULT SzDvdFileSeekImp(void *object, CFileSize pos)
{
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object;
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
if(pos >= s->len)
{
WaitPrompt("7z Error: The 7z SDK wants to start reading somewhere behind the EOF...");
return SZE_FAIL;
}
// save new position and return
s->pos = pos;
return SZ_OK;
}
SZ_RESULT SzDvdIsArchive(u64 dvd_offset) {
// 7z signautre
static Byte Signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
Byte Candidate[6];
// read the data from the DVD
int res = dvd_safe_read (&Candidate, 6, dvd_offset);
char msg[1024];
/*sprintf(msg, "7zSig: %02X %02X %02X %02X %02X %02X",
Candidate[0],
Candidate[1],
Candidate[2],
Candidate[3],
Candidate[4],
Candidate[5]);
WaitPrompt(msg);*/
size_t i;
for(i = 0; i < 6; i++) {
if(Candidate[i] != Signature[i]) {
return SZE_FAIL;
}
}
return SZ_OK;
}
// display an error message
void SzDisplayError(SZ_RESULT res)
{
WaitPrompt(szerrormsg[(res - 1)]);
}
static u64 rootdir;
static int rootdirlength;
void SzParse(void) {
// save the offset and the length of this file inside the archive stream structure
SzArchiveStream.offset = filelist[selection].offset;
SzArchiveStream.len = filelist[selection].length;
SzArchiveStream.pos = 0;
// set handler functions for reading data from DVD and setting the position
SzArchiveStream.InStream.Read = SzDvdFileReadImp;
SzArchiveStream.InStream.Seek = SzDvdFileSeekImp;
// set default 7Zip SDK handlers for allocation and freeing memory
SzAllocImp.Alloc = SzAlloc;
SzAllocImp.Free = SzFree;
SzAllocTempImp.Alloc = SzAllocTemp;
SzAllocTempImp.Free = SzFreeTemp;
// prepare CRC and 7Zip database structures
InitCrcTable();
SzArDbExInit(&SzDb);
// open the archive
SzRes = SzArchiveOpen(&SzArchiveStream.InStream, &SzDb, &SzAllocImp, &SzAllocTempImp);
if(SzRes != SZ_OK)
{
// free memory used by the 7z SDK
SzArDbExFree(&SzDb, SzAllocImp.Free);
return;
}
else
{
// archive opened successfully
// erase all previous entries
memset(&filelist, 0, sizeof(FILEENTRIES) * MAXFILES);
// add '../' folder
strncpy(filelist[0].filename, "../", 3);
filelist[0].length = rootdirlength; // store rootdir in case the user wants to go one folder up
filelist[0].offset = rootdir; // -''- rootdir length -''-
filelist[0].flags = 0;
// get contents and parse them into the dvd file list structure
unsigned int SzI, SzJ;
SzJ = 1;
for(SzI = 0; SzI < SzDb.Database.NumFiles; SzI++)
{
SzF = SzDb.Database.Files + SzI;
// skip directories
if(SzF->IsDirectory)
{
continue;
}
// do not exceed MAXFILES to avoid possible buffer overflows
if(SzJ == (MAXFILES - 1))
{
break;
}
// parse information about this file to the dvd file list structure
strncpy(filelist[SzJ].filename, SzF->Name, MAXJOLIET); // copy joliet name (useless...)
filelist[SzJ].filename[MAXJOLIET] = 0; // terminate string
filelist[SzJ].length = SzF->Size; // filesize
filelist[SzJ].offset = SzI; // the extraction function identifies the file with this number
filelist[SzJ].flags = 0; // only files will be displayed (-> no flags)
SzJ++;
}
// update maxfiles and select the first entry
maxfiles = SzJ;
offset = selection = 0;
return;
}
}
void SzClose(void)
{
SzArDbExFree(&SzDb, SzAllocImp.Free);
}
bool SzExtractROM(int i, unsigned char *buffer)
{
// prepare some variables
SzBlockIndex = 0xFFFFFFFF;
SzOffset = 0;
// Unzip the file
//ShowAction("Un7zipping file. Please wait...");
WaitPrompt("Un7zipping file. Please wait...");
SzRes = SzExtract2(
&SzArchiveStream.InStream,
&SzDb,
i, /* index of file */
&SzBlockIndex, /* index of solid block */
&buffer,
&SzBufferSize,
&SzOffset, /* offset of stream for required file in *outBuffer */
&SzOutSizeProcessed, /* size of file in *outBuffer */
&SzAllocImp,
&SzAllocTempImp);
// check for errors
if(SzRes != SZ_OK)
{
// display error message
WaitPrompt(szerrormsg[(SzRes - 1)]);
return false;
}
else
{
// close 7Zip archive and free memory
SzArDbExFree(&SzDb, SzAllocImp.Free);
return true;
}
}
#endif

View File

@ -1,46 +0,0 @@
/****************************************************************************
* SZ.C
* svpe June 2007
*
* This file manages the 7zip support for this emulator.
* Currently it only provides functions for loading a 7zip file from a DVD.
****************************************************************************/
#include <gccore.h>
#include <ogcsys.h>
#include <gctypes.h>
#include <stdio.h>
#include <string.h>
#include "7zCrc.h"
#include "7zIn.h"
#include "7zExtract.h"
typedef struct _SzFileInStream
{
ISzInStream InStream;
u64 offset; // offset of the file
unsigned int len; // length of the file
u64 pos; // current position of the file pointer
} SzFileInStream;
extern SZ_RESULT SzRes;
#define DVD_LENGTH_MULTIPLY 32
#define DVD_OFFSET_MULTIPLY 32
#define DVD_MAX_READ_LENGTH 2048
#define DVD_SECTOR_SIZE 2048
int dvd_buffered_read(void *dst, u32 len, u64 offset);
int dvd_safe_read(void *dst_v, u32 len, u64 offset);
SZ_RESULT SzDvdFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize);
SZ_RESULT SzDvdFileSeekImp(void *object, CFileSize pos);
SZ_RESULT SzDvdIsArchive(u64 dvd_offset);
void SzDisplayError(SZ_RESULT res);
void SzParse(void);
void SzClose(void);
bool SzExtractROM(int i, unsigned char *buffer);
// pseudo-header file part for some functions used in the gamecube port
extern unsigned int dvd_read(void *dst, unsigned int len, u64 offset);
extern void WaitPrompt( char *msg );
extern void ShowAction( char *msg );

Some files were not shown because too many files have changed in this diff Show More