Improved MemCard mounting. B at main menu goes back to game. 7z files on DVD can now be browsed

This commit is contained in:
dsbomb 2008-04-06 23:49:30 +00:00
parent 24d567e889
commit 759b9ac159
4 changed files with 31 additions and 52 deletions

View File

@ -726,7 +726,6 @@ int LoadDVDFile( unsigned char *buffer )
****************************************************************************/
static int havedir = 0;
int OpenDVD() {
int i, j;
haveSDdir = 0;
havedir = offset = selection = 0;

View File

@ -1082,6 +1082,9 @@ int ConfigScreen()
}
}
if (j & PAD_BUTTON_B ) {
quit = 1;
}
if ( menu == configmenucount )
menu = 0;

View File

@ -320,7 +320,8 @@ int MountTheCard()
*(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, NULL); /*** Don't need or want a callback ***/
CardError = CARD_Mount(CARDSLOT, SysArea, CardRemoved);
if ( CardError == 0 )
return 0;
else {
@ -329,7 +330,7 @@ int MountTheCard()
tries++;
}
return 1;
return -1;
}
/****************************************************************************
@ -338,9 +339,7 @@ int MountTheCard()
* This is based on the code from libogc
****************************************************************************/
void MCManage(int mode, int slot)
{
void MCManage(int mode, int slot) {
char mcFilename[80];
int CardError;
card_dir CardDir;
@ -360,7 +359,7 @@ void MCManage(int mode, int slot)
CARD_Init("FCEU", "00");
/*** Try for memory card in slot A ***/
CardError = CARD_Mount(CARDSLOT, SysArea, CardRemoved );
CardError = MountTheCard();
if ( CardError >= 0 )
{
@ -418,7 +417,7 @@ void MCManage(int mode, int slot)
CardError = CARD_Close(&CardFile);
sprintf(debug, "Saved %d bytes successfully!", savedBytes);
WaitPrompt(debug);
ShowAction(debug);
}
else WaitPrompt("Save Failed!");
@ -430,20 +429,16 @@ void MCManage(int mode, int slot)
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 )
{
while ( CardError != CARD_ERROR_NOFILE ) {
CardError = CARD_FindNext(&CardDir);
if ( strcmp(CardDir.filename, mcFilename) == 0 )
found = 1;
}
if ( found == 0 )
{
if ( found == 0 ) {
WaitPrompt("No Save Game Found");
CARD_Unmount(CARDSLOT);
return;
@ -459,8 +454,7 @@ void MCManage(int mode, int slot)
int sbo = SectorSize;
actualSize -= SectorSize;
while( actualSize > 0 )
{
while( actualSize > 0 ) {
CARD_Read(&CardFile, &statebuffer[sbo], SectorSize, sbo);
actualSize -= SectorSize;
sbo += SectorSize;
@ -472,7 +466,7 @@ void MCManage(int mode, int slot)
CARD_Unmount(CARDSLOT);
sprintf(debug, "Loaded %d bytes successfully!", savedBytes);
WaitPrompt(debug);
ShowAction(debug);
}
break; /*** End load ***/
@ -493,13 +487,12 @@ void SD_Manage(int mode, int slot){
int filesize = 0;
int len = 0;
//sprintf (filepath, "dev%d:\\%s\\%08x.fcs", slot, SAVEDIR, iNESGameCRC32);
sprintf (path, "dev%d:\\%08x.fcs", slot, iNESGameCRC32);
sprintf (path, "dev%d:\\%s\\%08x.fcs", slot, SAVEDIR, iNESGameCRC32);
if (mode == 0) ShowAction ("Saving STATE to SD...");
else ShowAction ("Loading STATE from SD...");
handle = (mode == 0) ? SDCARD_OpenFile (path, "wb") : SDCARD_OpenFile (path, "rb");
handle = SDCARD_OpenFile(path, (mode == 0) ? "wb" : "rb");
if (handle == NULL){
sprintf(msg, "Couldn't open %s", path);
@ -529,7 +522,7 @@ void SD_Manage(int mode, int slot){
SDCARD_CloseFile (handle);
sprintf (msg, "Loaded %d bytes successfully", offset);
WaitPrompt(msg);
ShowAction(msg);
GCFCEUSS_Load();
return ;

View File

@ -53,38 +53,31 @@ 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 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)
{
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)
{
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)
{
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
{
} 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
@ -105,8 +98,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
bufferOffset = 0;
// fix first issue (offset is not a multiply of 32)
if(offset % DVD_OFFSET_MULTIPLY)
{
if(offset % DVD_OFFSET_MULTIPLY) {
// calcualte offset of the prior 32 byte position
i = currentOffset - (currentOffset % DVD_OFFSET_MULTIPLY);
@ -117,8 +109,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
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)
{
if(k > len) {
k = len;
}
@ -133,14 +124,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
}
// fix second issue (more than 2048 bytes are needed)
if(bytesToRead > DVD_MAX_READ_LENGTH)
{
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++)
{
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
@ -152,8 +141,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset)
}
// fix third issue (length is not a multiply of 32)
if(bytesToRead)
{
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
}
@ -204,20 +192,17 @@ SZ_RESULT SzDvdFileSeekImp(void *object, CFileSize pos)
return SZ_OK;
}
SZ_RESULT SzDvdIsArchive(u64 dvd_offset)
{
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);
int res = dvd_safe_read (&Candidate, 6, dvd_offset);
size_t i;
for(i = 0; i < 6; i++)
{
if(Candidate[i] != Signature[i])
{
for(i = 0; i < 6; i++) {
if(Candidate[i] != Signature[i]) {
return SZE_FAIL;
}
}
@ -234,8 +219,7 @@ void SzDisplayError(SZ_RESULT res)
static u64 rootdir;
static int rootdirlength;
void SzParse(void)
{
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;