a2-4am / 4cade

100s of games at your fingertips, as long as your fingertips are on an Apple ][
https://archive.org/details/TotalReplay
MIT License
153 stars 21 forks source link

Wings of Fury - strange keyboard handling #564

Closed xotmatrix closed 6 months ago

xotmatrix commented 6 months ago

I was looking into the Wings of Fury keyboard code for pointless reddit reasons and stumbled onto something very strange. The keyboard handling in this version fails to detect keypresses a high percentage of the time because the keyboard strobe is regularly cleared shortly before the keyboard is read. The problem is confirmed to affect real hardware.

I've looked at several other versions and this keyboard strobe clearing code (which is in many places) appears to have been disabled by a patch with seemingly inert code ... or the Total Replay version has patched out writing to TAPEOUT for unknown reasons. Working versions include the Woz-a-Day (so the differences appear to be official), as well as qkumba's wings of fury PRODOS (san inc crack).po and the BB and Mr. Slick cracks. I have not yet seen a version that matches what's in Total Replay.

I do not claim what follows is an exhaustive list of differences. Once the game reached a breakpoint at $8E, I searched for STA $C010 KBDSTRB and STA $C020 TAPEOUT. These instructions overlap at many addresses. The Total Replay version doesn't seem to ever touch TAPEOUT but the other versions often do instead of touching KBDSTRB. I noticed some other differences in keyboard adjacent code starting at 01/ACC4 so it does seem like the differences are more extensive than just changing some addresses. I did not spend a lot of time trying to understand the code.

Problematic:

TOTAL REPLAY

*0/0.ffff s 8d 20 c0                                                            

Searching 00/0000.FFFF for 3-byte pattern: 0 Matches                            <-- STA $C020 TAPEOUT (Main)

*1/0.ffff s 8d 20 c0                                                            

Searching 01/0000.FFFF for 3-byte pattern: 0 Matches                            <-- STA $C020 TAPEOUT (Aux)

*0/0.ffff s 8d 10 c0                                                            

Searching 00/0000.FFFF for 3-byte pattern: 7 Matches                            <-- STA $C010 KBDSTRB (Main)

    0089    00BC    4009    404D    60FC    7662    766A                        

*1/0.ffff s 8d 10 c0                                                            

Searching 01/0000.FFFF for 3-byte pattern: 39 Matches                           <-- STA $C010 KBDSTRB (Aux)

    201B    3373    6303    688D    68D4    9012    9018    901E                
    9024    902A    9030    9036    903C    9042    9048    904E                
    9060    9066    906F    90F2    9104    911C    9128    A4E0                
    A4E6    A4EF    A4F8    A4FE    A507    A510    A516    A51F                
    A525    A52E    A534    ACC4    ACF6    B077    B07C                        

Working:

SAN INC PRODOS CRACK / BB CRACK / MR. SLICK CRACK

*0/0.ffff s 8d 20 c0                                                            

Searching 00/0000.FFFF for 3-byte pattern: 3 Matches                            <-- STA $C020 TAPEOUT (Main)

    0089    00BC    60FC                                                        

*1/0.ffff s 8d 20 c0                                                            

Searching 01/0000.FFFF for 3-byte pattern: 32 Matches                           <-- STA $C020 TAPEOUT (Aux)

    9012    9018    901E    9024    902A    9030    9036    903C                
    9042    9048    904E    9060    9066    906F    90F2    9104                
    911C    9128    A4E0    A4E6    A4EF    A4F8    A4FE    A507                
    A510    A516    A51F    A525    A52E    A534    B077    B07C                

*0/0.ffff s 8d 10 c0                                                            

Searching 00/0000.FFFF for 3-byte pattern: 4 Matches                            <-- STA $C010 KBDSTRB (Main)

    4009    404D    7662    766A                                                

*1/0.ffff s 8d 10 c0                                                            

Searching 01/0000.FFFF for 3-byte pattern: 7 Matches                            <-- STA $C010 KBDSTRB (Aux)

    201B    3373    6303    688D    68D4    ACC4    ACF6                        

I did not perform this exact search on the Woz-a-Day version because my emulator does not yet support this disk format. However, using Crossrunner, I did spot-check all of the STA $C020 matches found in the cracked versions and they were present in the woz.

I don't know what's going on. I feel like I am missing some important information or context so I have not attempted to fix anything.

peterferrie commented 6 months ago

TAPEOUT accesses are patched out because they crash the IIc. I will fix the keyboard issue.

xotmatrix commented 6 months ago

My intuition was that it was done to appease the Apple //c because it has reserved $C02x but I also played Wings of Fury on the //c in my youth, so it wasn't quite adding up. I didn't find any information at first but looking at the //c Plus Preliminary Reference just now, it sounds like ROM may be banked by it. Any additional insight is welcome.

peterferrie commented 6 months ago

Choplifter used it and it definitely crashed on the IIc. I probably assumed that WoF would be affected similarly, and patched it badly.

peterferrie commented 6 months ago

yes, that was exactly what happened. Fixed in a362597c09f5059a69d67b84c9fc9b522ecfed9a