Romhacking => Programming => Topic started by: Spikeman on November 20, 2012, 01:36:11 am

Title: Converting VBA savestate to BGB savestate (Gameboy)
Post by: Spikeman on November 20, 2012, 01:36:11 am
Hey all, I'm investigating a glitch in Super Mario Land 2 for GB, and I cannot seem to reproduce it in BGB, since it requires frame exact timing. Luckily, I have a movie file of someone performing the glitch, and I was able to create a savestate at the exact frame the glitch occurs (with the game paused), so I can load the savestate, unpause and the glitch executes. This is in VBA.

I need to get the same state into BGB so I can debug it and find out what's happening. My plan was to copy data from the VBA savestate into a BGB savestate and hope nothing went wrong. I copied over all of the RAM data, which seemed to work great, I appear in the same location with the game paused, but the glitch doesn't execute. I then realized I should copy over the registers (AF, HL, DE, BC, and a bunch of CPU registers like LCDC, STAT, etc.). After I did that, the game draws one frame and then crashes. I did some tracing and it seems what is happening is that another Vblank period is occuring before the previous one is done executing. I did manage to find some info in the BGB savestate that seems to correspond to it's internal representation of when Vblank occurs ("vidtime" and "lcdpos" variables in the savestate) - however I can't seem to find anything in VBA that is similar.

Does anyone know where I can find info on VBA's savestate format? Or a way I can stop the second vblank from happening and resynch the game? Or maybe a better approach? Any advice is greatly appreciated. :)

Edit: Nevermind, I was able to figure out how when VBA was undergoing VBLANK using some hacky Lua scripting. If anyone knows a better way, I'm still interested in knowing.
Title: Re: Converting VBA savestate to BGB savestate (Gameboy)
Post by: Jorpho on November 23, 2012, 12:12:53 am
Now you've got me wondering what this glitch is.
Title: Re: Converting VBA savestate to BGB savestate (Gameboy)
Post by: Spikeman on November 26, 2012, 11:34:59 pm
It's called the Pause Glitch. Video of it here:

I figured out how the glitch works and wrote a post about it here:

I never did figure out how VBA and BGB store when VBlank is going to occur, but I did manage to figure out what I needed through other methods. Also just for future record: simply copying the RAM from the VBA savestate seems to get the modified savestate to work (and take you to the same area of the game) in BGB. I also copied over the registers (stack pointer is probably important since copying the RAM changes the stack) and some of the internal registers (eg. LCDC and STAT), but those didn't seem to be important. And I can't see the VBlank timing mattering in almost every situation - it will only be important in timing based glitches like this one.