diff --git a/cube/patches/base/frag.c b/cube/patches/base/frag.c index ac0adea4..d25d5d8b 100644 --- a/cube/patches/base/frag.c +++ b/cube/patches/base/frag.c @@ -26,7 +26,14 @@ u32 read_frag(void *dst, u32 len, u32 offset) { u32 fragSize = fragList[fragTableIdx+1] & 0x7FFFFFFF; u32 fragSector = fragList[fragTableIdx+2]; u32 fragOffsetEnd = fragOffset + fragSize; - +#ifdef DEBUG_VERBOSE + usb_sendbuffer_safe("READ: dst: ",11); + print_int_hex(dst); + usb_sendbuffer_safe(" len: ",6); + print_int_hex(len); + usb_sendbuffer_safe(" ofs: ",6); + print_int_hex(offset); +#endif // Find where our read starts and read as much as we can in this frag before returning if(offset >= fragOffset && offset < fragOffsetEnd) { // Does our read get cut off early? @@ -37,6 +44,18 @@ u32 read_frag(void *dst, u32 len, u32 offset) { adjustedOffset = offset - fragOffset; } do_read(dst, amountToRead, adjustedOffset, fragSector); +#ifdef DEBUG_VERBOSE + u32 sz = amountToRead; + u8* ptr = (u8*)dst; + u32 hash = 5381; + s32 c; + while (c = *ptr++) + hash = ((hash << 5) + hash) + c; + + usb_sendbuffer_safe(" checksum: ",11); + print_int_hex(hash); + usb_sendbuffer_safe("\r\n",2); +#endif return amountToRead; } } @@ -44,7 +63,7 @@ u32 read_frag(void *dst, u32 len, u32 offset) { } void device_frag_read(void *dst, u32 len, u32 offset) -{ +{ while(len != 0) { u32 amountRead = read_frag(dst, len, offset); len-=amountRead; diff --git a/cube/patches/base/igr.c b/cube/patches/base/igr.c index fda3f4b7..dbfbff20 100644 --- a/cube/patches/base/igr.c +++ b/cube/patches/base/igr.c @@ -31,6 +31,7 @@ typedef struct { unsigned int unused[MAXTEXTSECTION]; } DOLHEADER; +#ifndef DEBUG void *memcpy(void *dest, const void *src, u32 size) { char *d = dest; @@ -115,3 +116,7 @@ void exit_to_pref(void) { } } +#else +void exit_to_pref(void) { +} +#endif diff --git a/cube/patches/sdgecko/sd.c b/cube/patches/sdgecko/sd.c index 318f5bda..528289cd 100644 --- a/cube/patches/sdgecko/sd.c +++ b/cube/patches/sdgecko/sd.c @@ -84,8 +84,23 @@ void send_cmd(u32 cmd, u32 sector) { void rcvr_datablock(void *dest, u32 start_byte, u32 bytes_to_read) { int bytesRead = start_byte+bytes_to_read; - while(rcvr_spi() != 0xFE); +#ifdef DEBUG_VERBOSE + usb_sendbuffer_safe(" dst: ",6); + print_int_hex((u32)dest); + usb_sendbuffer_safe(" start_byte: ",13); + print_int_hex(start_byte); + usb_sendbuffer_safe(" bytes_to_read: ",17); + print_int_hex(bytes_to_read); + usb_sendbuffer_safe(" resume: ",9); + print_int_hex(resume); + usb_sendbuffer_safe(" sectorpos: ",12); + print_int_hex(*(vu16*)VAR_SD_SECTORPOS); + usb_sendbuffer_safe("\r\n",2); + +#endif + while(rcvr_spi() != 0xFE); + // Skip the start if it's a misaligned read while(start_byte>4) { exi_imm_read(4); @@ -109,7 +124,7 @@ void rcvr_datablock(void *dest, u32 start_byte, u32 bytes_to_read) { } // Read out the rest from the SD as we've requested it anyway and can't have it hanging off the bus - int remainder = SECTOR_SIZE-bytesRead; + u32 remainder = SECTOR_SIZE-bytesRead; while(remainder>=4) { exi_imm_read(4); remainder-=4; @@ -118,56 +133,54 @@ void rcvr_datablock(void *dest, u32 start_byte, u32 bytes_to_read) { rcvr_spi(); remainder--; } - exi_imm_read(2); // discard CRC + exi_imm_read(2); // discard CRC } void do_read(void *dst, u32 len, u32 offset, u32 sectorLba) { u32 lba = (offset>>9) + sectorLba; u32 startByte = (offset%SECTOR_SIZE); u32 numBytes = len; - - int lbaShift = 9 * (*(vu32*)VAR_SD_TYPE); // SD Card Type (SDHC=0, SD=1) + u32 lbaShift = *(vu32*)VAR_SD_SHIFT; // SDHC uses sector addressing, SD uses byte lba <<= lbaShift; - - // If we weren't just reading this sector - if(lba != *(vu32*)VAR_TMP1) { - if(*(vu32*)VAR_TMP2) { - // End the read by sending CMD12 + Deselect SD + Burn a cycle after it - send_cmd(CMD12, 0); - exi_deselect(); - rcvr_spi(); - } - // Send multiple block read command and the LBA we want to start reading at - send_cmd(CMD18, lba); - *(vu32*)VAR_TMP2 = 1; - } + // Send multiple block read command and the LBA we want to start reading at + send_cmd(CMD18, lba); // Read block crossing a boundary if(startByte) { // amount to read in first block may vary if our read is small enough to fit in it - int amountInBlock = (len + startByte > SECTOR_SIZE) ? SECTOR_SIZE-startByte : len; + u32 amountInBlock = (len + startByte > SECTOR_SIZE) ? SECTOR_SIZE-startByte : len; rcvr_datablock(dst,startByte, amountInBlock); numBytes-=amountInBlock; dst+=amountInBlock; } // Read any full, aligned blocks - int numFullBlocks = numBytes>>9; + u32 numFullBlocks = numBytes>>9; + numBytes -= numFullBlocks << 9; while(numFullBlocks) { rcvr_datablock(dst, 0,SECTOR_SIZE); dst+=SECTOR_SIZE; - numBytes-=SECTOR_SIZE; numFullBlocks--; } // Read any trailing half block if(numBytes) { rcvr_datablock(dst,0, numBytes); + dst+=numBytes; } - - *(vu32*)VAR_TMP1 = lba + ((len + SECTOR_SIZE-startByte) >> lbaShift); + // End the read by sending CMD12 + Deselect SD + Burn a cycle after it + send_cmd(CMD12, 0); + exi_deselect(); + rcvr_spi(); +#ifdef DEBUG_VERBOSE + usb_sendbuffer_safe(" u32: ",5); + print_int_hex(*(u32*)((u32)dst-len)); + usb_sendbuffer_safe(" u32: ",5); + print_int_hex(*(u32*)(((u32)dst-len)+4)); + usb_sendbuffer_safe("\r\n",2); +#endif } /* End of SD functions */ diff --git a/cube/reservedarea.h b/cube/reservedarea.h index 06813c47..7c8c8c79 100644 --- a/cube/reservedarea.h +++ b/cube/reservedarea.h @@ -41,7 +41,7 @@ .set VAR_DISC_2_LBA, 0x2F04 # is the base file sector for disk 2 .set VAR_CUR_DISC_LBA, 0x2F08 # is the currently selected disk sector .set VAR_EXI_BUS_SPD, 0x2F0C # is the EXI bus speed (192 = 16mhz vs 208 = 32mhz) -.set VAR_SD_TYPE, 0x2F10 # is the Card Type (SDHC=0, SD=1) +.set VAR_SD_SHIFT, 0x2F10 # is the SD Card shift amount when issueing read cmds .set VAR_EXI_FREQ, 0x2F14 # is the EXI frequency (4 = 16mhz, 5 = 32mhz) .set VAR_EXI_SLOT, 0x2F18 # is the EXI slot (0 = slot a, 1 = slot b) .set VAR_TMP1, 0x2F1C # space for a variable if required @@ -124,7 +124,7 @@ #define VAR_DISC_2_LBA (VAR_AREA+0x2F04) // is the base file sector for disk 2 #define VAR_CUR_DISC_LBA (VAR_AREA+0x2F08) // is the currently selected disk sector #define VAR_EXI_BUS_SPD (VAR_AREA+0x2F0C) // is the EXI bus speed (192 = 16mhz vs 208 = 32mhz) -#define VAR_SD_TYPE (VAR_AREA+0x2F10) // is the Card Type (SDHC=0, SD=1) +#define VAR_SD_SHIFT (VAR_AREA+0x2F10) // is the SD Card shift amount when issueing read cmds #define VAR_EXI_FREQ (VAR_AREA+0x2F14) // is the EXI frequency (4 = 16mhz, 5 = 32mhz) #define VAR_EXI_SLOT (VAR_AREA+0x2F18) // is the EXI slot (0 = slot a, 1 = slot b) #define VAR_TMP1 (VAR_AREA+0x2F1C) // space for a variable if required diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index 304fe2f9..ed87fda5 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -468,7 +468,7 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2) { // Copy the current speed *(vu32*)VAR_EXI_BUS_SPD = 192; // Card Type - *(vu32*)VAR_SD_TYPE = sdgecko_getAddressingType(((devices[DEVICE_PATCHES]->location == LOC_MEMCARD_SLOT_A) ? 0:1)); + *(vu32*)VAR_SD_SHIFT = 9 * sdgecko_getAddressingType(((devices[DEVICE_PATCHES]->location == LOC_MEMCARD_SLOT_A) ? 0:1)); // Copy the actual freq *(vu32*)VAR_EXI_FREQ = EXI_SPEED16MHZ; // play it safe // Device slot (0 or 1) // This represents 0xCC0068xx in number of u32's so, slot A = 0xCC006800, B = 0xCC006814 diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index 5770e3cb..12d34450 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -379,7 +379,7 @@ s32 deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2) { // Copy the current speed *(vu32*)VAR_EXI_BUS_SPD = !swissSettings.exiSpeed ? 192:208; // Card Type - *(vu32*)VAR_SD_TYPE = SDHCCard; + *(vu32*)VAR_SD_SHIFT = 9 * SDHCCard; // Copy the actual freq *(vu32*)VAR_EXI_FREQ = !swissSettings.exiSpeed ? EXI_SPEED16MHZ:EXI_SPEED32MHZ; // Device slot (0 or 1) // This represents 0xCC0068xx in number of u32's so, slot A = 0xCC006800, B = 0xCC006814 diff --git a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c index cfe61cc0..42c7d5fc 100644 --- a/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c +++ b/cube/swiss/source/devices/wiikeyfusion/deviceHandler-wiikeyfusion.c @@ -123,7 +123,7 @@ s32 deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2) { // Copy the current speed *(vu32*)VAR_EXI_BUS_SPD = 192; // Card Type - *(vu32*)VAR_SD_TYPE = sdgecko_getAddressingType(((devices[DEVICE_PATCHES]->location == LOC_MEMCARD_SLOT_A) ? 0:1)); + *(vu32*)VAR_SD_SHIFT = 9 * sdgecko_getAddressingType(((devices[DEVICE_PATCHES]->location == LOC_MEMCARD_SLOT_A) ? 0:1)); // Copy the actual freq *(vu32*)VAR_EXI_FREQ = EXI_SPEED16MHZ; // play it safe // Device slot (0 or 1) // This represents 0xCC0068xx in number of u32's so, slot A = 0xCC006800, B = 0xCC006814 diff --git a/cube/swiss/source/patcher.c b/cube/swiss/source/patcher.c index d8444d37..3978204b 100644 --- a/cube/swiss/source/patcher.c +++ b/cube/swiss/source/patcher.c @@ -22,13 +22,6 @@ static u32 top_addr = VAR_PATCHES_BASE; -/*** externs ***/ -extern GXRModeObj *vmode; /*** Graphics Mode Object ***/ -extern u32 *xfb[2]; /*** Framebuffers ***/ -extern u32 SDHCCard; - -extern void animateBox(int x1,int y1, int x2, int y2, int color,char *msg); - // Read FuncPattern ReadDebug = {55, 23, 18, 3, 2, 4, 0, 0, "Read (Debug)", 0}; FuncPattern ReadCommon = {67, 30, 18, 5, 2, 3, 0, 0, "Read (Common)", 0}; @@ -43,10 +36,6 @@ u16 _dvdinterrupthandler_part[3] = { 0x6000, 0x002A, 0x0054 }; -u32 _osdispatch_part_a[2] = { - 0x3C60CC00, 0x83E33000 -}; - int install_code() { void *location = (void*)LO_RESERVE; diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 4f783691..b72ee165 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -842,6 +842,10 @@ unsigned int load_app(int multiDol, ExecutableFile *filesToPatch) wkfWriteOffset(*(vu32*)VAR_DISC_1_LBA); } print_gecko("libogc shutdown and boot game!\r\n"); + if((devices[DEVICE_CUR] == &__device_sd_a) || (devices[DEVICE_CUR] == &__device_sd_b)) { + print_gecko("set size\r\n"); + sdgecko_setPageSize(((devices[DEVICE_CUR]->location == LOC_MEMCARD_SLOT_A)? 0:1), 512); + } DOLtoARAM(main_dol_buffer, 0, NULL); return 0; }