formatting

This commit is contained in:
dsbomb 2008-04-05 14:57:58 +00:00
parent f0b068bfff
commit 3868e2ba51
13 changed files with 42347 additions and 42380 deletions

View File

@ -1,114 +1,114 @@
/****************************************************************************
* 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 ***/
/*** Set default samplerate to 48khz ***/
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
/*** and the DMA Callback ***/
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;
}
/****************************************************************************
* 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 ***/
/*** Set default samplerate to 48khz ***/
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
/*** and the DMA Callback ***/
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 +1,30 @@
/****************************************************************************
* 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
/****************************************************************************
* 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 +1,243 @@
/****************************************************************************
* 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 );
}
/****************************************************************************
* 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 );
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,184 +1,184 @@
/****************************************************************************
* 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>
#include <sdcard.h>
extern sd_file *filehandle;
extern int UseSDCARD;
extern void ShowAction( char *msg );
extern void WaitPrompt( char *msg );
extern unsigned char readbuffer[2048];
extern unsigned int dvd_read(void *dst, unsigned int len, unsigned int offset);
#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 )
SDCARD_ReadFile(filehandle, &readbuffer, 2048);
else
dvd_read(&readbuffer, 2048, discoffset);
} while ( res != Z_STREAM_END );
inflateEnd(&zs);
if ( UseSDCARD )
SDCARD_CloseFile(filehandle);
if ( res == Z_STREAM_END ) {
if ( FLIP32(pkzip.uncompressedSize == (u32)bufferoffset ) )
return bufferoffset;
else
return FLIP32(pkzip.uncompressedSize);
}
return 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>
#include <sdcard.h>
extern sd_file *filehandle;
extern int UseSDCARD;
extern void ShowAction( char *msg );
extern void WaitPrompt( char *msg );
extern unsigned char readbuffer[2048];
extern unsigned int dvd_read(void *dst, unsigned int len, unsigned int offset);
#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 )
SDCARD_ReadFile(filehandle, &readbuffer, 2048);
else
dvd_read(&readbuffer, 2048, discoffset);
} while ( res != Z_STREAM_END );
inflateEnd(&zs);
if ( UseSDCARD )
SDCARD_CloseFile(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,143 +1,143 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.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;
int screenscaler = 2;
uint8 *xbsave=NULL;
int eoptions=EO_BGRUN | EO_FORCEISCALE;
extern int RenderFrame( char *XBuf , int style);
extern int ConfigScreen();
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);
void (*PSOReload) () = (void (*)()) 0x80001800;
static void reset_cb() {
PSOReload();
}
extern int WaitPromptChoice (char *msg, char *bmsg, char *amsg);
int choosenSDSlot = 0;
int main(int argc, char *argv[])
{
initDisplay();
SYS_SetResetCallback (reset_cb);
InitialiseSound();
SDCARD_Init ();
/*** 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();
choosenSDSlot = !WaitPromptChoice("Choose a SLOT to load Roms from SDCARD", "SLOT B", "SLOT A");
ConfigScreen();
while (1)
{
uint8 *gfx;
int32 *sound;
int32 ssize;
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
xbsave = gfx;
FCEUD_Update(gfx, sound, ssize);
}
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)
{
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.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;
int screenscaler = 2;
uint8 *xbsave=NULL;
int eoptions=EO_BGRUN | EO_FORCEISCALE;
extern int RenderFrame( char *XBuf , int style);
extern int ConfigScreen();
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);
void (*PSOReload) () = (void (*)()) 0x80001800;
static void reset_cb() {
PSOReload();
}
extern int WaitPromptChoice (char *msg, char *bmsg, char *amsg);
int choosenSDSlot = 0;
int main(int argc, char *argv[])
{
initDisplay();
SYS_SetResetCallback (reset_cb);
InitialiseSound();
SDCARD_Init ();
/*** 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();
choosenSDSlot = !WaitPromptChoice("Choose a SLOT to load Roms from SDCARD", "SLOT B", "SLOT A");
ConfigScreen();
while (1)
{
uint8 *gfx;
int32 *sound;
int32 ssize;
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
xbsave = gfx;
FCEUD_Update(gfx, sound, ssize);
}
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)
{
}

File diff suppressed because it is too large Load Diff

View File

@ -1,155 +1,155 @@
/****************************************************************************
* 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 ConfigScreen();
/****************************************************************************
* 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
****************************************************************************/
int 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
****************************************************************************/
int 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 = ConfigScreen();
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;
}
/****************************************************************************
* 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 ConfigScreen();
/****************************************************************************
* 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
****************************************************************************/
int 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
****************************************************************************/
int 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 = ConfigScreen();
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 +1,132 @@
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,
};
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,354 +1,354 @@
/****************************************************************************
* 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 "gcdvd.h"
#include "sz.h"
// 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)
{
memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE);
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)
{
int ret = dvd_buffered_read(buffer, len, offset);
memcpy(dst_v, &buffer, len);
return ret;
}
else
{
// 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
dvd_safe_read (&Candidate, 6, dvd_offset);
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...");
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;
}
}
/****************************************************************************
* 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 "gcdvd.h"
#include "sz.h"
// 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)
{
memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE);
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)
{
int ret = dvd_buffered_read(buffer, len, offset);
memcpy(dst_v, &buffer, len);
return ret;
}
else
{
// 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
dvd_safe_read (&Candidate, 6, dvd_offset);
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...");
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;
}
}

View File

@ -1,46 +1,46 @@
/****************************************************************************
* 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 );
/****************************************************************************
* 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 );