clownmdemu – Yet More Fixes

BlastBrothers is back at it again with the bug-hunting, so here are some more fixes!

Fix After Burner II‘s Audio

After Burner II is fascinating: it plays PCM samples using the PSG channels, rather than the DAC channel. Because there is only one DAC channel, but multiple PSG channels, this allows the game to play multiple PCM samples at once, which is something that is not possible to do otherwise without mixing samples on one of the CPUs!

However, the game was failing to output any PCM samples in my emulator. Using the debugger, it could be seen that the PSG was indeed being used to play PCM samples, but it just was not audible.

Fortunately, I had a suspicion about what the problem could be: the documentation that I had used when creating my PSG emulator mentioned that, at a low-enough frequency countdown setting, the square wave ceases to alternate. I found this to be questionable, so I did not implement it in my emulator. However, the PSG would be outputting such a high frequency at this setting that it would be not only imperceivable to human hearing, but filtered-out entirely by the audio resampler. So, I did as the documentation said, and stopped the wave from alternating. And, with that, After Burner II‘s samples became audible!

Fix Jim Power‘s Flipped Graphics

While investigating another inaccuracy, I stumbled upon this bizarre bug:

After having made so many improvements to VDP communication lately, I was baffled to see yet another problem with it crop-up. It appeared that each longword of data that was being written to the VDP’s plane maps had its words reversed. After some testing, I concluded that this was not a problem with DMA transfers nor VRAM byte-swapping, so I began tracing longword-sized writes from the 68000 to the VDP’s ports. Upon detecting one, I used the emulator’s disassembler to view the code that performed it, and this is what I found:

00004260: bsr.s   $4268
00004262: swap d3
00004264: tas.b d3
00004266: move.l d2,d1
00004268: swap d3
0000426A: move.l usp,a6
0000426C: move.l d3,(a6)
0000426E: move.l d1,-(a6)
00004270: rts

Upon seeing this, I knew exactly what the problem was: the game was using a pre-decrement longword write, and it expected each word to be written in reverse order. In other words, it expects the latter word to be written to the VDP first, and then the former word afterwards.

While it was a bit of a pain to make my 68000 interpreter recreate this behaviour, I soon had it done, and I could enjoy Jim Power‘s hypnotic parallax scrolling bug-free!

Seriously, try moving to the right in this game – it gets weird.

One thought on “clownmdemu – Yet More Fixes

Leave a comment

Design a site like this with WordPress.com
Get started