
So you're interested in how I've ripped legend of legaia (LOL)
or are just curious to know how LOL's music engine works huh?

Well, the driver appears to be a "generic" VAB/SEQ driver,
however IDA Pro does not recognize all function calls, making
an easy rip quite hard. I found it hard to rip this, although
that's probably because of my inexperience.

Anyway, after a lot of disassembling and debugging I finally
found out how the music system in LOL works.

The file system is completely nameless (everything is just
reffered to as numbers). A big file, PROT.DAT, contains lots
of stuff related to sound and music and graphics data. The
first few thousand bytes are like this:

Offset      Length                    Value
0           4                         0
4           4                         Number of records
8           4*Number of records       Records

Each "record" points to the offset*0x800 of the file within
PROT.DAT. So if a record contained 0xCAB5 the offset of that
file within PROT.DAT would be 0x655A800.

For music, the file is actually made up of three chunks: the
VAB header, VAB body and SEQ data. A chunk looks like:
Offset      Length                    Value
0           3                         ChunkLength
3           1                         ChunkType
4           ChunkLength               Data

There are three known ChunkTypes for music:
0 = VAB header
1 = VAB body
2 = SEQ data

As I said before, each music file is made up of three chunks,
with the exception of 068 (which only has two VAB header/body
chunks) and 074 (which as only one SEQ data chunk).

Note: These chunks can come in ANY order (as I found out)!

As for which file numbers correspond to music, I was lucky to
find that out. When I found the "load file" function I noticed
0x41F was getting passed to it in the title screen and 0x41D
in the prologue. I then found an old file named "legend of
legaia debug faq" which had the following lines (for a special
more which allowed you to access a "sound test" that could play
any music in the game):
"63.	The prologue.
64.	The coming of the Mist.
65.	Title Screen"
I also had run search.exe on PROT.DAT previously, and it had
identified a section which had 78 SEQs in it. Guess how many
musics the debug faq said there was? Yep, 78.

(report2.txt contains this report)

In fact, all music in the game corresponds to file numbers
990 + (0 to 77). The numbers from 0 to 77 exactly correspond
to the music mentioned in the debug faq, which is why the names
for tracks are so similar.

With this knowledge I could now contruct a program which ripped
all the music for me. It is included as "lolrip.bas". It will
run on any version of QBASIC. The program uses "template.exe",
which is just a nearly-empty PSX-EXE which the VAB/SEQ data is
to be contained. Its text sections starts at 0x800FF800 and is
0x00080800 bytes long (but that can be extended if you need
more room).

template.exe has the following properties:
The SEQ data MUST be loaded at 0x80100000
The location of the VAB header is specified in 0x800FFFF8
The location of the VAB body is specified in 800FFFFC
(By default the VAB header is located at 0x80120000)
You MUST change the "locations of VAB header/body" to where you
have actually located them

All psfs in the set have SEQ data located at 0x80100000 and VAB
header/body data at 0x80120000... with the exception of 068,
which has its VAB stuff loaded at 0x80110000 (gee, this psf is
really an odd one out). The reason for this is that for some
reason, if the VAB data is loaded at 0x80120000, you get a
clicking noise!

Since the driver was 174KB big, I decided it would be
beneficial to convert the entire set to minipsf. The driver,
lol.psflib, is an ordinary psf with text section starting at
0x80010000 with a length of 0x000E1000.
It appeared that the conversion to minipsf was beneficial. I
made the size of the entire set go from 20mb to 7.5mb :)
(it also made the ripping process 3 times as fast)

Well, that's all for now but if you have any additional
questions you can contact me at: someone42_000@hotmail.com


TOOLS USED:
IDA Pro
PSEmuPro (don't underestimate the usefullness of this when
ripping PSFs. If that program didn't exist this set wouldn't
have existed)
Search V1.1 by Reptile (reptile_psx@hotmail.com)
seq2mid by ????? (its in japanese!)
Legend of Legaia Debug Mode FAQ (FFCCMMG@hotmail.com)