Patch:Incompatible patches

From KeenWiki
Jump to: navigation, search

This page lists and organizes patches that are incompatible with other, unrelated patches, usually due to sharing the same code space. In order to be included on this page a give pair of patches must not both be able to be included in the same patch file without causing problems. Their conflict must also not be 'trivial'; that is, the patches must do different things. Thus a patch that alters the title screen's location will be incompatible with one that stops it being displayed entirely, but the conflict is trivial and obvious and it is (hoped) a patcher would not confuse the two. However some patches are incompatible and unrelated, meaning that a patcher may easily add both to their patch file having no idea they would be in conflict.

When adding a patch to this page it should be categorized under the appropriate episode and code location, so that it can be grouped with patches that suffer similar issues. If at all possible all other patches it is incompatible with should be listed with it and the reasons for incompatibility explained. Patches themselves are not listed, but links to their precise locations on their relevant pages should be included.


Incompatible patches sorted by episode and location

This section of the page is for listing and organizing incompatible patches to identify potential issues and solutions. Patches are sorted by episode, and within that episode by patch location. Patches are placed in the section that corresponds to the smallest location in the patch that causes conflict. If the conflict is not related to sharing code space a patch is located in its own section marked with the location of its lowest location value.


Keen 1

$0AF2 - $0C50

These patches utilize the spare code space formerly used to make EGA data screenshots in the game. This has no side effects by itself since the code is entirely unused.


Fixing compatibility issues

This section provides a brief tutorial on methods that can be used to fix incompatibility between patches. There are two basic kinds of incompatibility; the first is space-related, two patches sharing the same code space, one overwriting the other. The second is function-related, where two patches try and make the game do two different things at the same time. The first is easier to fix than the second.


'Goto-return' example

The following two patches are incompatible, sharing the same code space:

Patch: Keen 1 incompatible patches
#Keen has ammo limit of 100
#If ammo tile, go to new ammo code
%patch $44A0 $E9 $C650W
#New ammo code
%patch $0AF2 $C3 $83 $3E $AAC8W $64 $7D $05 $83 $06 $AAC8W $05 $E9 $39A3W
#Teleporting wins level 13
%patch $801D $E9 $8AD2W
#Mark level as done, call teleporter
%patch $0AF2 $C7 $87 $AAB8W $0001W $E8 $7E1EW $E9 $7522W


Both work by making the game 'detour' to the new patch, execute code then return. They both sue the same location for extra code space, a common situation. In function they are similar to a BASIC 'GOTO' statement. In order to render both compatible one patch needs to be shifted to a new location and its 'gotos' altered to use that location.

First the relevant 'gotos' must be identified; each patch contains two; all starting with $E9. The first makes up the entirety of the first section and the second is at the end of the patch in both patches. (E.g. the first jump in the ammo limit patch is $E9 $C650W and the last $E9 $39A3W.)

A potential pitfall is the presence of $E8 $7E1EW in the second patch, this is a different kind of jump, but it too must be counted.

The next thing to do is to calculate the space the first patch takes up. In this case we count the number of '$' after $0AF2 in the first patch. (remembering that $xxxxW counts double.) The ammo limit patch is thus 16 ($10) bytes long. The next step is to move the second patch so it uses different code space. In this case it will be moved to $0AF2 + $0010 = $0B02.

Finally the affected patch's jumps must be altered. Since the patch is being moved forward in the executable both jumps must be decreased by 16 ($10). So the first jump, $E9 $8AD2W becomes $E9 $8AC2W. The final pair of now-compatible patches are as follows:

Patch: Keen 1 incompatible patches
#Keen has ammo limit of 100
#If ammo tile, go to new ammo code
%patch $44A0 $E9 $C650W
#New ammo code
%patch $0AF2 $C3 $83 $3E $AAC8W $64 $7D $05 $83 $06 $AAC8W $05 $E9 $39A3W
#Teleporting wins level 13 - altered to be compatible with ammo limit patch
%patch $801D $E9 $8AC2W
#Mark level as done, call teleporter
%patch $0B02 $C7 $87 $AAB8W $0001W $E8 $7E0EW $E9 $7512W