From e65f977bd6551b80a48abe00812ae3dfdcdf73fd Mon Sep 17 00:00:00 2001 From: sulokutdcmago Date: Tue, 30 Dec 2008 14:36:30 +0000 Subject: [PATCH] Recovered broken GC support due to writting off the screen in drawstatusbar. Added propper file info showing. Added support for the permision key atribute, but restoring won't work, always restores as xCP (disabled) Makefiles modified to have its own build dirs. --- Makefile.gc | 2 +- Makefile.wii | 2 +- source/freetype.c | 86 ++++++++++++++++++++++++++++++++--------------- source/gci.h | 4 +-- source/main.c | 5 +++ source/mcard.c | 74 +++++++++++++++++++++++++++++++++------- source/sdsupp.c | 17 ++++++++-- 7 files changed, 143 insertions(+), 47 deletions(-) diff --git a/Makefile.gc b/Makefile.gc index 9662c4b..9ed2a7e 100644 --- a/Makefile.gc +++ b/Makefile.gc @@ -17,7 +17,7 @@ include $(DEVKITPPC)/gamecube_rules #--------------------------------------------------------------------------------- #TARGET := $(notdir $(CURDIR)) TARGET := gcmm_GC -BUILD := build +BUILD := build_GC SOURCES := source DATA := data INCLUDES := diff --git a/Makefile.wii b/Makefile.wii index 05abcaa..1b8cf6d 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -17,7 +17,7 @@ include $(DEVKITPPC)/wii_rules #--------------------------------------------------------------------------------- #TARGET := $(notdir $(CURDIR)) TARGET := gcmm_WII -BUILD := build +BUILD := build_WII SOURCES := source DATA := data INCLUDES := diff --git a/source/freetype.c b/source/freetype.c index e6eb6c5..6233956 100644 --- a/source/freetype.c +++ b/source/freetype.c @@ -46,9 +46,11 @@ extern GXRModeObj *vmode; extern card_dir CardList[]; extern u8 filelist[1024][1024]; extern u32 maxfile; -extern GCI gci; -#define MAXFILEBUFFER (1024 * 2048) -extern u8 FileBuffer[MAXFILEBUFFER] ATTRIBUTE_ALIGN (32); +extern GCI gci; +#define MAXFILEBUFFER (1024 * 2048) +extern u8 FileBuffer[MAXFILEBUFFER] ATTRIBUTE_ALIGN (32); +extern u8 CommentBuffer[64] ATTRIBUTE_ALIGN (32); + #define PAGESIZE 18 @@ -430,26 +432,25 @@ void showSaveInfo(int sel) { int bgcolor = getcolour(84,174,211); DrawBoxFilled(375, 175, 605, 410, bgcolor); - // memcpy(company, CardList[sel].company, 2); - // memcpy(gamecode, CardList[sel].gamecode, 4); - //company[2] = gamecode[4] = 0; - // read file, display some more info - // TODO: only read the necessary header + comment for sd + // TODO: only read the necessary header + comment, display banner and icon files if (mode == RESTORE_MODE){ j = SDLoadMCImageHeader(filelist[sel]); - memcpy(&gci, FileBuffer, 64); - ExtractGCIHeader(); - GCIMakeHeader(); + // struct gci now contains header info + memcpy(company, gci.company, 2); + memcpy(gamecode, gci.gamecode, 4); + company[2] = gamecode[4] = 0; - }else if( mode == RESTORE_MODE || mode == DELETE_MODE){ + }else if( (mode == BACKUP_MODE) | (mode == DELETE_MODE) ){ + memcpy(company, CardList[sel].company, 2); + memcpy(gamecode, CardList[sel].gamecode, 4); + company[2] = gamecode[4] = 0; j = CardReadFileHeader(CARD_SLOTB, sel); - } - // struct gci now contains header info + // struct gci now contains header info + + } + - memcpy(company, gci.company, 2); - memcpy(gamecode, gci.gamecode, 4); - company[2] = gamecode[4] = 0; sprintf(txt, "#%d %s/%s", sel, gamecode, company); DrawText(x, y, txt); y += 20; @@ -497,15 +498,39 @@ void showSaveInfo(int sel) { y += 20; sprintf(txt, "Blocks: %d", gci.filesize8); DrawText(x, y, txt); - y += 20; + y += 20; + //M-> Cant' move the file //C->can't copy the file //P->public file //Most frecuent: xxP sprintf(txt, "Perm: %s%s%s", (gci.unknown1 & 16) ? "M " : "x", (gci.unknown1 & 8) ? "C " : "x", (gci.unknown1 & 4) ? "P" : "x"); DrawText(x, y, txt); - y += 20; - // Comment at MCDATAOFFSET+(comment addr) - char *comment = (char*) (FileBuffer+MCDATAOFFSET+gci.comment_addr); + y += 20; + + //Bad way to display the file comment, should reposition to just show the full 32 char lines instead of spliting. + char comment1[32]; + /*DrawText(x, y, "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF"); + y += 20; + */ + strncpy(comment1, CommentBuffer, 25); + DrawText(x, y, comment1); + y += 20; + memset(comment1, 0, sizeof(comment1)); + strncpy(comment1, CommentBuffer+25, 7); + DrawText(x, y, comment1); + y += 20; + memset(comment1, 0, sizeof(comment1)); + strncpy(comment1, CommentBuffer+32, 25); + DrawText(x, y, comment1); + y += 20; + memset(comment1, 0, sizeof(comment1)); + strncpy(comment1, CommentBuffer+57, 7); + DrawText(x, y, comment1); + y += 20; + memset(comment1, 0, sizeof(comment1)); + + /* // Comment at MCDATAOFFSET+(comment addr) + //char *comment = (char*) (FileBuffer+MCDATAOFFSET+gci.comment_addr); j = 0; int x2, z = 0; int offset = 0; @@ -534,7 +559,7 @@ void showSaveInfo(int sel) { //txt[z] = 0; DrawText(x, y, txt); y += 20; - } + }*/ } @@ -703,9 +728,12 @@ int ShowSelector (){ } void writeStatusBar(char *line1, char *line2) { - int bgcolor = getcolour(0xff,0xff,0xff); - //DrawBoxFilled(10, 404, 510, 455, bgcolor); - DrawBoxFilled(10, 430, 510, 485, bgcolor); + int bgcolor = getcolour(0xff,0xff,0xff); +#ifdef HW_RVL + DrawBoxFilled(10, 430, 510, 485, bgcolor); +#else + DrawBoxFilled(10, 404, 510, 455, bgcolor); +#endif //setfontcolour(84,174,211); setfontcolour(28,28,28); DrawText(40, 450, line1); @@ -718,8 +746,12 @@ void clearLeftPane() { } void clearRightPane() { - int bgcolor = getcolour(84,174,211); - DrawBoxFilled(375, 140, 605, 410, bgcolor); + int bgcolor = getcolour(84,174,211); +#ifdef HW_RVL + DrawBoxFilled(375, 140, 605, 410, bgcolor); +#else + DrawBoxFilled(375, 110, 605, 380, bgcolor); +#endif } void DrawHLine (int x1, int x2, int y, int color) diff --git a/source/gci.h b/source/gci.h index 2d56708..d2f3629 100644 --- a/source/gci.h +++ b/source/gci.h @@ -18,8 +18,8 @@ typedef struct { u32 icon_addr; u16 icon_fmt; u16 icon_speed; - u8 unknown1; /*** Permission key? ***/ - u8 unknown2; /*** Again, unknown ***/ + u8 unknown1; /*** Permission key ***/ + u8 unknown2; /*** Copy Counter ***/ u16 index; /*** Ignore - and throw away ***/ u16 filesize8; /*** File size / 8192 ***/ u16 reserved02; /*** Always 0xffff ***/ diff --git a/source/main.c b/source/main.c index 35c05eb..51e43af 100644 --- a/source/main.c +++ b/source/main.c @@ -295,6 +295,11 @@ else }*/ +/* Reboot the system */ +/*void Reboot() { + *((volatile u32*)0xCC003024) = 0x00000000; +} +*/ /**************************************************************************** * Main ****************************************************************************/ diff --git a/source/mcard.c b/source/mcard.c index d571cf2..dc0e170 100644 --- a/source/mcard.c +++ b/source/mcard.c @@ -25,6 +25,7 @@ static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); /*** Memory File Buffer ***/ #define MAXFILEBUFFER (1024 * 2048) /*** 2MB Buffer ***/ u8 FileBuffer[MAXFILEBUFFER] ATTRIBUTE_ALIGN (32); +u8 CommentBuffer[64] ATTRIBUTE_ALIGN (32); u8 filelist[1024][1024]; int maxfile; extern int cancel; @@ -34,6 +35,7 @@ static card_dir CardDir; static card_file CardFile; static card_stat CardStatus; static int cardcount = 0; +static u8 permission; GCI gci; @@ -89,9 +91,11 @@ void GCIMakeHeader() gci.icon_addr = CardStatus.icon_addr; gci.icon_fmt = CardStatus.icon_fmt; gci.icon_speed = CardStatus.icon_speed; - - /*** In the games I've checked, these are always 0 ***/ - gci.unknown1 = gci.unknown2 = 0; + + /*** Permission key has to be gotten separately. Make it 0 for normal privileges ***/ + gci.unknown1 = permission; + /*** Who cares about copy counter ***/ + gci.unknown2 = 0; /*** Block index does not matter, it won't be restored at the same spot ***/ gci.index = 32; @@ -122,6 +126,7 @@ void ExtractGCIHeader() CardStatus.icon_addr = gci.icon_addr; CardStatus.icon_fmt = gci.icon_fmt; CardStatus.icon_speed = gci.icon_speed; + permission = gci.unknown1; CardStatus.len = gci.filesize8 * 8192; CardStatus.comment_addr = gci.comment_addr; } @@ -147,7 +152,7 @@ int CardGetDirectory (int slot){ /*** Try to mount the card ***/ err = MountCard(slot); if (err){ - WaitCardError("CardMount",CARD_GetErrorCode(slot)); + WaitCardError("CardMount", err); return 0; /*** Unable to mount the card ***/ } @@ -195,10 +200,14 @@ void CardListFiles (){ * * Retrieve a file header from the previously populated list. ****************************************************************************/ +//TODO: get icon and banner settings int CardReadFileHeader (int slot, int id){ + int bytesdone = 0; int err; + u32 SectorSize; char company[4]; char gamecode[6]; + int filesize; if (id >= cardcount){ WaitPrompt("Bad id"); @@ -206,6 +215,7 @@ int CardReadFileHeader (int slot, int id){ } /*** Clear the work buffers ***/ + memset (FileBuffer, 0, MAXFILEBUFFER); memset (SysArea, 0, CARD_WORKAREA); company[2] = 0; gamecode[4] = 0; @@ -219,19 +229,47 @@ int CardReadFileHeader (int slot, int id){ /*** Mount the card ***/ err = MountCard (slot); if (err){ - WaitCardError("CardMount",CARD_GetErrorCode(slot)); + WaitCardError("CardMount", err); return 0; } + /*** Retrieve sector size ***/ + CARD_GetSectorSize (slot, &SectorSize); + + /*** Open the file ***/ + err = CARD_Open (slot, (char *) &CardList[id].filename, &CardFile); + if (err) + { + CARD_Unmount (slot); + WaitCardError("CardOpen", err); + return 0; + } + /*** Get card status info ***/ CARD_GetStatus (slot, CardFile.filenum, &CardStatus); + CARD_GetAttributes(slot,CardFile.filenum, &permission); GCIMakeHeader(); + /*** Copy the file contents to the buffer ***/ + filesize = CardFile.len; + + while (bytesdone < filesize) + { + CARD_Read (&CardFile, FileBuffer + MCDATAOFFSET + bytesdone, SectorSize, + bytesdone); + bytesdone += SectorSize; + } + //get the comment (two 32 byte strings) into buffer + memcpy(CommentBuffer, FileBuffer + MCDATAOFFSET + CardStatus.comment_addr, 64); + + /*** Close the file ***/ + CARD_Close (&CardFile); + /*** Unmount the card ***/ CARD_Unmount (slot); - return 1; + return filesize + MCDATAOFFSET; } @@ -269,7 +307,7 @@ int CardReadFile (int slot, int id){ /*** Mount the card ***/ err = MountCard (slot); if (err){ - WaitCardError("CardMount",CARD_GetErrorCode(slot)); + WaitCardError("CardMount", err); return 0; } @@ -281,12 +319,13 @@ int CardReadFile (int slot, int id){ if (err) { CARD_Unmount (slot); - WaitCardError("CardOpen",CARD_GetErrorCode(slot)); + WaitCardError("CardOpen", err); return 0; } /*** Get card status info ***/ CARD_GetStatus (slot, CardFile.filenum, &CardStatus); + CARD_GetAttributes(slot,CardFile.filenum, &permission); GCIMakeHeader(); @@ -341,7 +380,7 @@ int CardWriteFile (int slot) { err = MountCard(slot); if (err){ - WaitCardError("CardMount",CARD_GetErrorCode(slot)); + WaitCardError("CardMount", err); return 0; } @@ -353,20 +392,24 @@ int CardWriteFile (int slot) { if (strcmp ((char *) CardDir.filename, (char *)filename) == 0){ /*** Found the file - abort ***/ CARD_Unmount (slot); - WaitCardError("File already exists",CARD_GetErrorCode(slot)); + WaitCardError("File already exists", err); return 0; } err = CARD_FindNext (&CardDir); } +//This is needed for propper restoring CARD_SetCompany(company); CARD_SetGamecode(gamecode); /*** Now restore the file from backup ***/ err = CARD_Create (slot, (char *) filename, filelen, &CardFile); if (err){ + //Return To show all so we don't have errors + CARD_SetCompany(NULL); + CARD_SetGamecode(NULL); CARD_Unmount (slot); - WaitCardError("CardCreate",CARD_GetErrorCode(slot)); + WaitCardError("CardCreate", err); return 0; } @@ -385,7 +428,12 @@ int CardWriteFile (int slot) { /*** Finally, update the status ***/ CARD_SetStatus (slot, CardFile.filenum, &CardStatus); - + //For some reason this sets the file to Move->allowed, Copy->not allowed, Public file instead of the actual permission value + //CARD_SetAttributes(slot, CardFile.filenum, &permission); + + //Return To show all so we don't have errors + CARD_SetCompany(NULL); + CARD_SetGamecode(NULL); CARD_Close (&CardFile); CARD_Unmount (slot); @@ -449,7 +497,7 @@ void WaitCardError(char *src, int error) { sprintf(err, "Unknown"); break; } - sprintf(msg, "MemCard Error: %s - %s", src, err); + sprintf(msg, "MemCard Error: %s - %d %s", src,error, err); WaitPrompt(msg); diff --git a/source/sdsupp.c b/source/sdsupp.c index c4c55ab..bf99fcd 100644 --- a/source/sdsupp.c +++ b/source/sdsupp.c @@ -14,14 +14,18 @@ #include "sdsupp.h" #include "freetype.h" #include "gci.h" +#include "mcard.h" #define PAGESIZE 20 #define PADCAL 80 /*** Memory Card FileBuffer ***/ -extern u8 FileBuffer[]; +#define MAXFILEBUFFER (1024 * 2048) /*** 2MB Buffer ***/ +extern u8 FileBuffer[MAXFILEBUFFER] ATTRIBUTE_ALIGN (32); +extern u8 CommentBuffer[64] ATTRIBUTE_ALIGN (32); extern u8 filelist[1024][1024]; extern u32 maxfile; +extern GCI gci; int SDSaveMCImage (){ @@ -151,7 +155,6 @@ int SDLoadMCImageHeader(char *sdfilename){ //int offset = 0; //int bytesToRead = 0; long bytesToRead = 0; - int header_size = 64; /*** Make fullpath filename ***/ sprintf (filename, "fatX:/%s/%s", MCSAVES, sdfilename); @@ -182,7 +185,15 @@ filename[3]=48+PI_SDGECKO_A; } /*** Read the file header ***/ - fread (FileBuffer,1,header_size,handle); + fread (FileBuffer,1,sizeof(GCI),handle); + + ExtractGCIHeader(); + GCIMakeHeader(); + + //Get the comment + fseek(handle, MCDATAOFFSET + gci.comment_addr, SEEK_SET); + fread (CommentBuffer, 1, MCDATAOFFSET, handle); + /*** Close the file ***/ fclose (handle);