P-47 Aces Sound Effects Fix


[Download 2019/12/28 VER2]
(Updated: 28 December 2019 22:17:30 UTC)

Introduction

P-47 Aces uses a queue based sound effect engine, which blindly feeds sound codes into the sound CPU periodically. However, it's possible to quite easily generate enough sound effects to fill up the queue, to the point where sound effects can be delayed by multiple seconds.

Interestingly, this is a case of a rather severe programming error that was obscured by partially working, and the issue being even further obscured by relying on a functionality of the game hardware that's not emulated well by MAME. On Jaleco MegaSystem-32, there is a high-rate timer that fires the highest priority interrupt. P-47 Aces (and Wangan Sensou, which has a related but less severe issue) is designed to primarily rely on this interrupt to deliver the sound codes to the sound CPU. This functionality is duplicated in the vblank interrupt, so it will feed at least one byte of sound data per frame in the worst case (assuming we cannot know what rate the timer fires at, perhaps?).

In MAME currently (will fix upstream later), this timer is always enabled, because several games rely on it working. However, on hardware, this is controlled by a single bit in a control register. P-47 Aces intends to set this bit, and even does briefly, as the variable which holds a copy of the register (to be copied in each frame) is initialized with the bit set. However, there is a memory test functionality which rewrites all of RAM... which comes after that initialization! Oops! So the bit is never actually set, the interrupt never fires, and the sound codes trickle out very slowly.

The fix here is to remove the memory test (if you need it there's another one in the service menu!), and fix a bug in the interrupt handler which would also lose the interrupt enable bit (though it would get restored at the next vblank, so 2 bytes are flowing per frame). That latter issue is the issue that also applies to Wangan Sensou, though I think it's not sufficiently bad in that game to worry about fixing.

Update VER2: Removing the memory test also removes RAM clearing, which mostly works except can cause some crashing. VER2 now clears the RAM as well, but preserves the interrupt bit, so there should be no problems.

Installation

Apply the patch files by using beat. The names of the patches correspond to the names of the ROMs (p47-26.bps is applied to the ROM labeled -26, commonly named as p47-26.26, for example).

File CRC SHA1
p47-26.26 6e95e8e5 34969d87a69702ec1e8db31fc53a5cc04b4c0440
p47-27.27 2af5117e 91921035ea13ab94a9f80b660c4e3b3ed6379104
p47-28.28 f1bad6b7 fcf3d00e93cf7ac179aaa47273a3074326f19d7e
p47-29.29 5fc49dbf ef646749497c4d335ccec2ceee3bdc786b3023f0