I'm trying to write a lua script that plays optimally through Pokemon Crystal (CGB). Right now I want to write an OnMemoryExecute event that triggers before the joypad polling begins for the Game Freak logo and intro movie skip (kinda important to get this right). Without getting into too many details, I want the routine to toggle the A button at the last frame before the intro routine starts checking whether a button was pressed.
After the copyright information is displayed, the game unloads those graphics and loads in the graphics for the game freak logo. During this time, several frames elapse; the joypad is polled each frame, during vblank. Thus the only time an input will have any real effect is if it's sent the frame before it's used. As soon as the graphics loading routine returns, the game starts checking the buttons. If I register my OnMemoryExecute event there, I lose a frame. To save myself some time trying to figure out the optimal execution breakpoint to send my A input, I have decided to register an OnMemoryExecute event at the start of the graphics loading routine and insert emu.frameadvance calls in the callback to offset the A press.
When I do that, though, I get this error in the lua console:
error running function attached by the event OnMemoryExecute
Error message: A .NET exception occured in user-code
It seems that emu.frameadvance within an OnMemoryExecute event is not allowed. emu.yield raises the same error. Is there another way for me to get the effect I want?