Implementing GBS playback in an emulator

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Implementing GBS playback in an emulator
by on (#178289)
So I already have an emulator that can emulate GB/GBC games fully, but I would like to add the ability to play GBS files.

I've had a look around documentation of the format and source code of already existing players, but I'm left confused.
Most notably the GBS spec document confuses me the most, as it is very vague in where I should start reading GB instructions (Is it at 0x70 or at the load address? The example in ROM-bank switching didn't clear anything up)
The only thing I've gotten working is offsetting the RST positions to the load address but even then I don't know if I'm doing it correctly because I'm overwriting instructions that are already there and that doesn't seem right (right at the very start of the file).

So, to make this easier on myself, from the perspective of an existing emulator, what do I need to add/modify to get it playing GBS files?
Re: Implementing GBS playback in an emulator
by on (#179771)
I set things up like this:

Code:
    musicFile.read((char*)&mFileHeader, 0x70);

    numBanks = ((fileSize + mFileHeader.loadAddress - 0x70) + 0x3fff) >> 14;

    rom = new unsigned char[(uint32_t)numBanks << 14];

    memset(rom, 0, (uint32_t)numBanks << 14);
    musicFile.read((char*)rom + mFileHeader.loadAddress, fileSize-0x70);