XEX player does not initialize POKEY correctly
Brought to you by:
pfusik
When exporting SAP to XEX with ASAP, the XEX player contains the following initialization sequence.
The sequence does not properly initialize SKCTL and both POKEYs. Before setting it or $03, it must be set to $00 to trigger the initialization sequence. Also the last STA AUDF should be and STA SKCTL.
Play the attached .XEX/ATR on a STEREO POKEY machine in Altirra. The XEX will work (as there is no SIO changing POKEY settings), the ATR will sound wrong,
013A: A2 08 LDX #$08
013C: 9D 10 D2 L013C STA $D210,X
013F: 9D 00 D2 STA AUDF1,X
0142: CA DEX
0143: 10 F7 BPL $013C
0145: A9 03 LDA #$03
0147: 8D 1F D2 STA $D21F
014A: 8D 00 D2 STA AUDF1
Fix merged.
The missing SKCTL setting was a huge issue if one plays with a stereo upgrade. Thanks for catching that!
Triggering POKEY initialization doesn't seem necessary. From my experience, most of Atari games and demos don't do that. It only initializes the polys and /28 and /114 divisors. They are already in a valid state because the OS "reset" routine initialized POKEY. You could argue that you get reproducible POKEY state (including RANDOM), but I don't think that's the case without full time sync with ANTIC. Zeroing IRQEN is a good idea so that a CLI in SAP followed by a keypress doesn't crash. Only the xexd routine did that. Writing STIMER doesn't really help as it's done before zeroing AUDF's.
I chose the route to clear all registers, because I didn't want to cause any changes in the file offsets. From the docs, my understanding was that setting D1/D0=$00 in SKCTL is required to perform the missing initialization. Now reading the docs again I understand that this only refers to the internal timer counters and the problem we have here is that D4=$1 in SKCTRL after SIO operations, creating unwanted behavior of "use timer 4 as input clock and reset timers 3+4 when waiting for start bit or a zero is received".
Nevertheless initializing all registers makes the code less error prone in all cases.
I wanted to sync my fork to you latest commits, but I cannot find a way to do that in SF. Do you have tip? And will you create a new build?
Last edit: Peter Dell 2025-02-04