Anisse<p>Sonic 2 wasn't starting at all in my <a href="https://social.treehouse.systems/tags/GameGear" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>GameGear</span></a> <a href="https://social.treehouse.systems/tags/emulator" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>emulator</span></a>. It seemed like there was some kind of infinite loop. I looked at how the game behaved in <a href="https://social.treehouse.systems/tags/Emulicious" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Emulicious</span></a>, another (closed-source) emulator with great debugging capability.</p><p>I noticed something weird on my emulation: after a HALT, the VDP interrupt would wake-up the CPU, it would be handled and return. But when returning it jumped straight into the previous HALT instruction (!), meaning it looped and never moved forward. I fixed this by implementing the missing PC increment, and it fixed the startup of <a href="https://social.treehouse.systems/tags/Sonic2" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Sonic2</span></a>!</p><p>Later, I went looking at another game that didn't start: Global Gladiators. I figured it might be something related with an infinite loop. I went to the frame that looped, and noticed something similar: a loop reading from the VDP V Counter (or line counter), waiting for it to be 0xC0. But it never happened ! Because at 0xC0, the VDP raised an interrupt and by the time the interrupt was handled, the VDP already had processed a few other lines. So the code looped, waiting for an event that never happened. Emulicious seemed to send the interrupt at 0xC1, contrary to what the official Game Gear manual said would happen; but Charles McDonald's VDP documentation from 2002 said it *should* happen 0xC1. So I simply fixed it by using this same value. But something tells me there might be other timing-related bugs hiding here. At least I can now play on of the greatest games of the platform 😉 </p><p>In the end, this untested interrupt code is the source of multiple bugs... I need to find a way to write simple test for these.</p><p><a href="https://social.treehouse.systems/tags/gears" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>gears</span></a> <a href="https://social.treehouse.systems/tags/EmulatorDevelopment" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>EmulatorDevelopment</span></a> <a href="https://social.treehouse.systems/tags/GlobalGladiators" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>GlobalGladiators</span></a> <a href="https://social.treehouse.systems/tags/McDonalds" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>McDonalds</span></a> <a href="https://social.treehouse.systems/tags/projects" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>projects</span></a></p>