News: 11 March 2016 - Forum Rules

Author Topic: Converting VBA savestate to BGB savestate (Gameboy)  (Read 2968 times)

Spikeman

  • Hero Member
  • *****
  • Posts: 1063
  • *unce unce unce*
    • View Profile
    • None at the moment, check out my Last.fm page instead?
Converting VBA savestate to BGB savestate (Gameboy)
« 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.
« Last Edit: November 20, 2012, 05:33:32 am by Spikeman »
Open Source Hacking Projects: Guru Logic Champ, Telefang 2, (Want more? Check out my GitHub!)

Jorpho

  • Hero Member
  • *****
  • Posts: 5051
  • The cat screams with the voice of a man.
    • View Profile
Re: Converting VBA savestate to BGB savestate (Gameboy)
« Reply #1 on: November 23, 2012, 12:12:53 am »
Now you've got me wondering what this glitch is.
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

Spikeman

  • Hero Member
  • *****
  • Posts: 1063
  • *unce unce unce*
    • View Profile
    • None at the moment, check out my Last.fm page instead?
Re: Converting VBA savestate to BGB savestate (Gameboy)
« Reply #2 on: November 26, 2012, 11:34:59 pm »
It's called the Pause Glitch. Video of it here: http://www.youtube.com/watch?v=7eWBPPoAQTo

I figured out how the glitch works and wrote a post about it here: http://tasvideos.org/forum/viewtopic.php?p=332393#332393

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.
Open Source Hacking Projects: Guru Logic Champ, Telefang 2, (Want more? Check out my GitHub!)