Found at 80011CF8
Summary
This function builds a file look up table, then a XA streaming table based on the contents of KKIIDDZZ.HED. For the look up table it converts the relative LBA location of each file up to index 447 into absolute LBA location. For the stream table it updates the start LBA value for each entry off the value in the header file. It the configures the CD to play an audio file (unverified).
Behavior
Call CdSearchFile to get the position and size of KKIIDDZZ.HED and load it to our cdlFileStruct, then convert that position into an absolute LBA value with CdPosToInt. Seek to the LBA address of KKIIDDZZ.HED so we can read the file into memory, then execute the read and wait until its done. The address to where we read the file is where the file look up table will live.
Enter a loop to update the table with the absolute LBA position of each file. This is done for the first 448 entries, The math for how this is done is in the notes section.
The function then starts populating the start LBA in the XA stream table that corresponds to the following files: TALK.STR, STEXP.STR, WEBGET.STR, LAB.STR, GOV1.STR, GOV2.STR. There is an entry for however many tracks are in a file.
Finally Set the cd mode to the following followed by a Demute command:
- Double speed
- Send XA-ADPCM to SPU audio input
- 2048 byte sector size
- Ignore bit to Normal
- Process only XA-ADPCM sectors that match set filter
- Report off
- Autopause off
- CDDA off
Notes
- First three loops are to ensure the command was accepted by the sony cd library.
- The pointer CdSearchFile returns is a pointer that contains the same data that CdSearchFile populated into our desired stack address.
- The look up table entries are just 32 bit values where the lower 20 bits encode the absolute file position as LBA and the upper 12 bits encode the file size in sector count.
- These header entries before calculations are the LBA addresses of each file on the CD relative to the header file, To get the absolute address we do the operation below. The +1 accounts for the size of the header file.
- The math for calculating the file LBA is as follows: (currentHeaderEntry & 0xFFF00000) | (((currentHeaderEntry & 0xFFFFF) + 1 + headerLBA) & 0xFFFFF). This translates to the following:
- AND the current header entry to extract the upper 12 bits. This is the size of the file in sector count.
- AND the current header entry and extract the lower 20 bits. This gives us a relative LBA
- add 1 + 355 to this relative LBA this gives us absolute LBA
- AND the absolute LBA again to keep it inside the 20 bit boundary
- OR the absolute LBA and the sector count to get one value.
- The stream table already exists in memory, we are only populating the start LBA of the STR file.
- Index 448 to the end (467) of the header file contain absolute position, hence why the math is not applied to them and these all point to STR files.
Unknowns
- The size field in the look up table does not seem to correspond to the true size of the file for index 454 to end, I wonder if these are the polygon streamed video and we are only tracking the audio portion?
- I believe we send the set mode and demute commands at the end because the japanese version has audio that plays when the dualshock controller required screen comes up and the two versions share the same code base. Or could be left over from a demo trailer.
Function Signature
Parameters: None
Returns
Always 0