fix DVD/7z

This commit is contained in:
dborth 2008-10-15 18:29:01 +00:00
parent 2f85a83ef9
commit 264df6f727
3 changed files with 24 additions and 18 deletions

View File

@ -15,6 +15,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#ifdef WII_DVD #ifdef WII_DVD
extern "C" { extern "C" {
@ -38,17 +39,15 @@ bool isWii = false;
volatile unsigned long *dvd = (volatile unsigned long *) 0xCC006000; volatile unsigned long *dvd = (volatile unsigned long *) 0xCC006000;
#endif #endif
/** Due to lack of memory, we'll use this little 2k keyhole for all DVD operations **/
unsigned char DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32);
unsigned char dvdbuffer[2048];
/**************************************************************************** /****************************************************************************
* dvd_read * dvd_read
* *
* The only DVD function we need - you gotta luv gc-linux self-boots! * Main DVD function, everything else uses this!
* returns: 1 - ok ; 0 - error * returns: 1 - ok ; 0 - error
***************************************************************************/ ***************************************************************************/
#define ALIGN_FORWARD(x,align) ((typeof(x))((((uint32_t)(x)) + (align) - 1) & (~(align-1))))
#define ALIGN_BACKWARD(x,align) ((typeof(x))(((uint32_t)(x)) & (~(align-1))))
int int
dvd_read (void *dst, unsigned int len, u64 offset) dvd_read (void *dst, unsigned int len, u64 offset)
{ {
@ -58,7 +57,9 @@ dvd_read (void *dst, unsigned int len, u64 offset)
// don't read past the end of the DVD (1.5 GB for GC DVD, 4.7 GB for DVD) // don't read past the end of the DVD (1.5 GB for GC DVD, 4.7 GB for DVD)
if((offset < 0x57057C00) || (isWii && (offset < 0x118244F00LL))) if((offset < 0x57057C00) || (isWii && (offset < 0x118244F00LL)))
{ {
unsigned char *buffer = (unsigned char *) (unsigned int) DVDreadbuffer; u8 * buffer = (u8 *)memalign(32, 0x8000);
u32 off_size = 0;
DCInvalidateRange ((void *) buffer, len); DCInvalidateRange ((void *) buffer, len);
#ifdef HW_DOL #ifdef HW_DOL
@ -78,11 +79,17 @@ dvd_read (void *dst, unsigned int len, u64 offset)
if (dvd[0] & 0x4) if (dvd[0] & 0x4)
return 0; return 0;
#else #else
if (DI_ReadDVD(buffer, len >> 11, (u32)(offset >> 11))) off_size = offset - ALIGN_BACKWARD(offset,0x800);
if (DI_ReadDVD(
buffer,
(ALIGN_FORWARD(offset + len,0x800) - ALIGN_BACKWARD(offset,0x800)) >> 11,
(u32)(ALIGN_BACKWARD(offset, 0x800) >> 11)
))
return 0; return 0;
#endif #endif
memcpy (dst, buffer, len); memcpy (dst, buffer+off_size, len);
free(buffer);
return 1; return 1;
} }
@ -241,6 +248,7 @@ getpvd ()
{ {
int sector = 16; int sector = 16;
u32 rootdir32; u32 rootdir32;
unsigned char dvdbuffer[2048];
dvddir = dvddirlength = 0; dvddir = dvddirlength = 0;
IsJoliet = -1; IsJoliet = -1;
@ -325,7 +333,7 @@ bool TestDVD()
***************************************************************************/ ***************************************************************************/
static int diroffset = 0; static int diroffset = 0;
static int static int
getentry (int entrycount) getentry (int entrycount, unsigned char dvdbuffer[])
{ {
char fname[512]; /* Huge, but experience has determined this */ char fname[512]; /* Huge, but experience has determined this */
char *ptr; char *ptr;
@ -445,6 +453,7 @@ ParseDVDdirectory ()
u64 rdoffset; u64 rdoffset;
int len = 0; int len = 0;
int filecount = 0; int filecount = 0;
unsigned char dvdbuffer[2048];
// initialize selection // initialize selection
selection = offset = 0; selection = offset = 0;
@ -464,7 +473,7 @@ ParseDVDdirectory ()
diroffset = 0; diroffset = 0;
while (getentry (filecount)) while (getentry (filecount, dvdbuffer))
{ {
if(strlen(filelist[filecount].filename) > 0 && filecount < MAXFILES) if(strlen(filelist[filecount].filename) > 0 && filecount < MAXFILES)
filecount++; filecount++;

View File

@ -393,6 +393,7 @@ int FileSelector (int method)
{ {
if(method == METHOD_DVD) if(method == METHOD_DVD)
{ {
// go to directory the 7z was in
dvddir = filelist[0].offset; dvddir = filelist[0].offset;
dvddirlength = filelist[0].length; dvddirlength = filelist[0].length;
} }

View File

@ -445,18 +445,14 @@ int SzParse(char * filepath, int method)
{ {
// Parses the 7z into a full file listing // Parses the 7z into a full file listing
// store the current 7z data
unsigned int oldLength = filelist[selection].length;
u64 oldOffset = filelist[selection].offset;
// erase all previous entries // erase all previous entries
memset(&filelist, 0, sizeof(FILEENTRIES) * MAXFILES); memset(&filelist, 0, sizeof(FILEENTRIES) * MAXFILES);
// add '..' folder // add '..' folder in case the user wants exit the 7z
strncpy(filelist[0].displayname, "..", 2); strncpy(filelist[0].displayname, "..", 2);
filelist[0].flags = 1; filelist[0].flags = 1;
filelist[0].length = oldLength; filelist[0].offset = dvddir;
filelist[0].offset = oldOffset; // in case the user wants exit 7z filelist[0].length = dvddirlength;
// get contents and parse them into file list structure // get contents and parse them into file list structure
unsigned int SzI, SzJ; unsigned int SzI, SzJ;