Final Fantasy Hacktics

Modding => Help! => Topic started by: cadence on May 23, 2019, 02:16:38 am

Title: How do SCUS addresses for files work, and can they be changed/added to?
Post by: cadence on May 23, 2019, 02:16:38 am
So what I've gathered so far from the wiki is that files are loaded from the ISO through addresses in SCUS 942.21. For example, all the SMD files are listed this way. (http://ffhacktics.com/wiki/Music) I'm not entirely sure what the SCUS file is even after scanning through its massive wiki page, but since it holds the PSX kernel and is also apparently used for file loading, my guess is that it's the entry point for the game and its contents are always in RAM, sort of a "Main" file.

I don't know what magic links the SCUS addresses to the SMD files themselves. I can see here (http://ffhacktics.com/wiki/SOUND/) that all the SMD files are in contiguous sectors in the same folder, which seems significant, but... maybe it isn't? If I were to, say, add a new SMD file to one of the giant free spaces listed in the CD Index (http://ffhacktics.com/wiki/CD_Index), could I somehow add a pointer to that song in SCUS and play it like any other SMD file? Even if the answer is "no" (which I'm guessing it is) it'd be helpful to know which parts of my conceptual understanding are correct and which are off.
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: Xifanie on May 23, 2019, 04:15:52 am
Usually, to add more of something, you just expand the table. Though in this case I'm sure you'd have to move it.
It's fairly straightforward in that those file tables are usually just the file sector offset and the file size.

Though you kinda have to edit the ISO to add files to the index to make important new files easier rather than import them directly to sectors.

The SCUS is the main PSX executable, it's specified in the ISO itself at a precise location along with its file size. It's loaded once and can't really be unloaded.
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: cadence on May 23, 2019, 05:21:48 am
Glad I wasn't too far off. The consistent byte sizes and contiguous addresses probably should've tipped me off to it being a table--I'm still getting used to reading hex. I'm guessing that 00028acc - 00040970 in SCUS is mostly dedicated to misc tables, then, since that's the huge unlabelled block that also contains the music file table. Hard to tell what uses that space at a glance since it doesn't link to anything.

Followup questions:


Sorry, that... looks like a lot more, written out. I really appreciate your help so far!
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: Xifanie on May 23, 2019, 08:15:05 am
Headers? Some table with variable row length have pointer tables. Text is particularly infamous for this. World and Event Conditionals also have varying lengths and use pointer tables. This is not something that would ever be the case with tables for file access though.

The bad news is that the SCUS has very limited free space.
The good news is that, AFAIK, BATTLE.BIN and WORLD.BIN are always loaded... you can create a routine to check the new table on either file (in kanji space) based on which one is loaded, making it necessary to store the table in both files. I've done this for many of my hacks in the past... it's just the title screen that worries me, the song COULD be loaded before WORLD.BIN.

There's probably only one routine that looks at that table to load the files, so that would be pretty uninvolved. Quite a bit more to move it on two files as I suggested.

And for that last one I'm talking about files shown by your file explorer in Windows/Mac/whatever. That's a CD-ROM file index. The PSX doesn't need it at all (you can wipe it all, and your OS will think the disc is empty and the game will work just fine), but the programs we use, but with CD Mage/cdprog, they make it easier to import files into the correct sectors.
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: cadence on May 23, 2019, 03:42:16 pm
OK! So having thought about this a little further, the file table having a set number of entries isn't a deal-breaker, as long as higher sector numbers don't somehow go outside the address space; the maximum number of tracks would stay the same, but if the entries in the file table are changed then the songs can be different lengths, in different spots on the disc, and so on. That's a pretty manageable restriction compared to some of the other tables I'm looking at, haha (looking at you, Item Attributes...).

One more question assuming I'm correct so far: are songs streamed from SMDs as they play or is a song loaded into RAM all at once? If the latter, do you know how much space is allocated for it (i.e. is there an effective limit for SMD file sizes)?
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: Xifanie on May 23, 2019, 03:54:20 pm
The files are so small they'd have to be loaded all at once. The PSX loads by sectors, so in groups of 2048 bytes at a time into RAM. Dynamic loading is more for XA / CD audio tracks.

Sorry, I have no idea what the space allocation is for songs. It's same to assume it's at least the size of biggest song filesize, rounded up by 2048. Of course your biggest hurdle would actually be creating a new song; everything else sounds pretty trivial to me. To keep things simple, I'd vote for you to just overwrite one of the Sound Novel songs; I don't personally enjoy any of them tbh.
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: cadence on May 23, 2019, 04:31:19 pm
Aw, I like some of them... but yeah, I can make choices about what to cut.

Thanks so much! Excited to see what we can manage using the known SMD instruction set. ^^
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: Nyzer on May 23, 2019, 05:05:52 pm
For bonus points, the Sound Novel songs aren't used in the main game either. Anyone playing the English versions won't notice their loss.
Title: Re: How do SCUS addresses for files work, and can they be changed/added to?
Post by: 3lric on May 24, 2019, 05:31:48 am
Quote from: Nyzer on May 23, 2019, 05:05:52 pm
For bonus points, the Sound Novel songs aren't used in the main game either. Anyone playing the English versions won't notice their loss.


One is used in game. One of the ones from Diary of Nanai