s32 WDVD_FindPartition( u64 *outbuf ) { //gprintf( "%s %i\n", __FILE__, __LINE__ ); u64 offset = 0, table_offset = 0; u32 cnt, nb_partitions; s32 ret; //u32 *buffer = NULL; //gprintf( "%s %i\n", __FILE__, __LINE__ ); //buffer = (u32 *)memalign(32, 0x20); //if (!buffer) // return -1; //gprintf( "%s %i\n", __FILE__, __LINE__ ); ret = WDVD_UnencryptedRead( wdvd_buffer, 0x20, PTABLE_OFFSET ); if (ret < 0) { //free( buffer ); return ret; } nb_partitions = wdvd_buffer[0]; table_offset = wdvd_buffer[1] << 2; //gprintf( "%s %i\n", __FILE__, __LINE__ ); ret = WDVD_UnencryptedRead( wdvd_buffer, 0x20, table_offset ); if (ret < 0) { // free( buffer ); return ret; } //gprintf( "%s %i\n", __FILE__, __LINE__ ); for (cnt = 0; cnt < nb_partitions; cnt++) { u32 type = wdvd_buffer[cnt * 2 + 1]; if (!type) { offset = wdvd_buffer[cnt * 2] << 2; break; } } //gprintf( "%s %i\n", __FILE__, __LINE__ ); //free( buffer ); if (!offset) return -1; //gprintf( "%s %i\n", __FILE__, __LINE__ ); *outbuf = offset; return 0; }
s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf) { void *buffer = NULL; u64 offset; u32 mod, size; s32 ret; /* Calculate offset */ offset = ((u64)lba) << 2; /* Calcualte sizes */ mod = len % 32; size = len - mod; /* Read aligned data */ if (size) { ret = WDVD_UnencryptedRead(iobuf, size, offset); if (ret < 0) goto out; } /* Read non-aligned data */ if (mod) { /* Allocate memory */ buffer = memalign(32, 0x20); if (!buffer) return -1; /* Read data */ ret = WDVD_UnencryptedRead(buffer, 0x20, offset + size); if (ret < 0) goto out; /* Copy data */ memcpy(iobuf + size, buffer, mod); } /* Success */ ret = 0; out: /* Free memory */ if (buffer) free(buffer); return ret; }
s32 Multidisc_GetEntries(struct wiigame **outbuf, u32 *outlen) { struct wiigame *gameBuffer = NULL; u32 cnt; s32 ret; /* Read disc header */ ret = WDVD_UnencryptedRead(buffer, sizeof(buffer), 0); if (ret < 0) return ret; /* Check disc ID */ if (buffer[0] != MAGIC_WORD) return -1; /* Number of entries */ cnt = buffer[1]; /* Entries found */ if (cnt) { u32 len = sizeof(struct wiigame) * cnt; /* Allocate memory */ gameBuffer = (struct wiigame *)memalign(32, len); if (!gameBuffer) return -2; /* Read entries */ ret = WDVD_UnencryptedRead(gameBuffer, len, 8); if (ret < 0) goto err; } else return -3; /* Set values */ *outbuf = gameBuffer; *outlen = cnt; return 0; err: /* Free memory */ if (gameBuffer) free(gameBuffer); return ret; }
s32 __Disc_FindPartition(u64 *outbuf) { u64 offset = 0, table_offset = 0; u32 cnt, nb_partitions; s32 ret; /* Read partition info */ ret = WDVD_UnencryptedRead(buffer, 0x20, PTABLE_OFFSET); if (ret < 0) { return ret; } /* Get data */ nb_partitions = buffer[0]; table_offset = buffer[1] << 2; if (nb_partitions > 8) { return -1; } /* Read partition table */ ret = WDVD_UnencryptedRead(buffer, 0x20, table_offset); if (ret < 0) { return ret; } /* Find game partition */ for (cnt = 0; cnt < nb_partitions; cnt++) { u32 type = buffer[cnt * 2 + 1]; /* Game partition */ if(!type) offset = buffer[cnt * 2] << 2; } /* No game partition found */ if (!offset) { gprintf("No game offset partition found\n"); return -1; } /* Set output buffer */ *outbuf = offset; WDVD_Seek(offset); return 0; }
s32 Disc_ReadGCHeader(void *outbuf) { /* Read GC disc header */ return WDVD_UnencryptedRead(outbuf, sizeof(struct gc_discHdr), 0); }