Patch:Keen (Keen 4)

From KeenWiki
Jump to: navigation, search

This page contains patches relating to Keen as a sprite in Keen 4. That is, such things as the sprites used, the speeds and sounds. It does not cover patches relating to gameplay such as those that make levels scroll or change keys. Those can be found at Patch:Gameplay (Keen Galaxy). It is divided into sections relating to the various sprite properties the patches involved. Being fluent with various sprite patch pages will help when working with these patches.

As little is known about Keen, there is less information here than for most sprites.


Keen behaviors with their own pages

The following pages have been created for specific Keen actions that have a significant number of patches, necessitating them being kept separate for clarity: This page contains patches relating to Keen as a sprite in Keen 4. That is, such things as the sprites used, the speeds and sounds. It does not cover patches relating to gameplay such as those that make levels scroll or change keys. Those can be found at Patch:Gameplay (Keen Galaxy). It is divided into sections relating to the various sprite properties the patches involved. Being fluent with various sprite patch pages will help when working with these patches.

As little is known about Keen, there is less information here than for most sprites.


Keen behaviors with their own pages

The following pages have been created for specific Keen actions that have a significant number of patches, necessitating them being kept separate for clarity:


Sprite Actions

This is a complete list of Keen's actions, both in-level and on the map. t provides links to some pages that discuss specific actions in further detail but a discussion of all of Keen's actions is too complex to host on this page.

Actions:
$098CW #Keen standing
$09AAW #Keen looks up (Bored)
$09C8W #Keen shrugs 1(Bored more)
$09E6W #Keen shrugs 2
$0A04W #Keen shrugs 3
$0A22W #Keen shrugs 4
$0A40W #Keen shrugs 5
$0A5EW #Keen shrugs 6
$0A7CW #Keen moons 1
$0A9AW #Keen moons 2
$0AB8W #Keen moons 3
$0AD6W #Keen starts reading book 1
$0AF4W #Keen starts reading book 2
$0B12W #Keen starts reading book 3
$0B30W #Keen starts reading book 4
$0B4EW #Keen reads book 1
$0B6CW #Keen reads book 2
$0B8AW #Keen reads book 3
$0BA8W #Keen stops reading book 1
$0BC6W #Keen stops reading book 2
$0BE4W #Keen stops reading book 3
$0C02W #Keen looking up
$0C20W #Keen looking up
$0C3EW #Keen looks down
$0C5CW #Keen looks down
$0C7AW #Keen looks down
$0C98W #Keen looking down
$0CB6W #Keen looking down
$0CD4W #Defunct dead action
$0CF2W #Keen dies sprawled (Exits level if offscreen.)
$0D10W #Keen dies clutched (Exits level if offscreen.)
$0D2EW #Keen die swimming sprawled (Exits level if offscreen.)
$0D4CW #Keen die swimming clutched (Exits level if offscreen.)
$0D6AW #Keen shooting horizontally 1
$0D88W #Keen shooting horizontally 2
$0DA6W #Keen shooting up 1
$0DC4W #Keen shooting up 2
$0DE2W #Keen finishes flicking switches
$0E00W #Keen finishes flicking switches
$0E1EW #Keen places gem, door opens
$0E3CW #Keen turns away from screen
$0E5AW #Keen walks into doors
$0E78W #Keen walks into doors
$0E96W #Keen walks into doors
$0EB4W #Keen walks into doors
$0ED2W #Keen walks into doors
$0EF0W #Keen going still on a pole
$0F0EW #Keen going up a pole
$0F2CW #Keen going up a pole
$0F4AW #Keen going up a pole
$0F68W #Keen going down a pole
$0F86W #Keen going down a pole
$0FA4W #Keen going down a pole
$0FC2W #Keen going down a pole
$0FE0W #Keen shooting horizontally on a pole 1
$0FFEW #Keen shooting horizontally on a pole 2
$101CW #Keen shoots up on pole 1
$103AW #Keen shoots up on pole 2
$1058W #Keen shooting down on a pole 1
$1076W #Keen shooting down on a pole 2
$1094W #Keen standing (Walking action)
$10B2W #Keen walking
$10D0W #Keen walking
$10EEW #Keen walking
$110CW #Keen start pogoing
$112AW #Keen pogoing
$1148W #Keen pogoing
$1166W #Keen jumping 1
$1184W #Keen jumping 2
$11A2W #Keen falling 1
$11C0W #Keen falling 2
$11DEW #Keen start shooting horizontally in air
$11FCW #Keen shoot horizontally in air 1
$121AW #Keen shoot horizontally in air 2
$1238W #Keen start shooting upwards in air
$1256W #Keen shooting up in air 1
$1274W #Keen shooting up in air 2
$1292W #Keen start shooting downwards in air 
$12B0W #Keen shoot down in air 1
$12CEW #Keen shoot down in air 2
$12ECW #Keen gripping ledge 1
$130AW #Keen gripping ledge 2
$1328W #Keen pulls himself up from ledgegripping 1
$1346W #Keen pulls himself up from ledgegripping 2
$1364W #Keen pulls himself up from ledgegripping 3
$1382W #Keen pulls himself up from ledgegripping 4
$13A0W #Keen standing on air (After pulling himself up. Doesn't fall)
$1492W #Map Keen riding foot
$14B0W #Map Keen riding foot
$14CEW #Map Keen swimming
$14ECW #Map Keen standing still
$150AW #Map Keen waving when bored
$1528W #Map Keen waving when bored
$1546W #Map Keen waving when bored
$1564W #Map Keen waving when bored
$1582W #Map Keen waving when bored
$15A0W #Map Keen moving


Sprite Collision

Keen has several sprite collisions used in a variety of circumstances. As such this section does not list the collision values of Keen's actions but instead deals with the more general collision codes.

For patches that affect what collision a specific action uses, see that action's page. (For example Patch:Keen on poles.)


Collision 1 code

This collision, often known as KeenSpriteCollision is used under a variety of circumstances. Keen uses this collision when doing such things as being bored, looking up or down and mooning the player. The collision is exceedingly complex and is notable for using a pointer list that is utterly pointless.

The first section deals with 'exceptional' sprite types. On the first line the Foot's sprite type is checked for followed by a jump to $CCD9 if the sprite type is greater than the Foot's. (An unusual step) If not then the following checks are made: Items, Council Members and Bounders, These checks cause the game to jump to $CE10 (Foot), $CCF5, $CD84, and $CDE8 respectively. (Which are covered later.)

The second part (lines 4 and 5) of the first section deals with further sprite checks; Platforms, Princess Lindsey and stunned sprites. These checks jump to $CDCB, $CDF9 and $CDC5 respectively. (Again these will be treated later.)

The second section starts at $CCF5 and deals with the item sprite type (Type 4) This section first calls the pointless list at the end of the code. The list is 12 items long located at $9DC0 + $161A = $CE1A. All items do the same thing (At $CD07) regardless of what item kind they are which renders the list pointless.

What is done to all item sprites is covered right after the list setup (Line 3 and onwards). First a 'got item' sound is played based on the list located at $2EE70 + $13DC = $3024C. Then the sprite's sprite type is set to 1, the 'misc sprite' type. Then its foreground variable is set to 3 so it appears in front of all tiles. (So the player can see all the items they get.) After this the sprite's animation changes based on the 'got item animation list' at $2EE70 + $140C = $3027C and the player's score increases by an amount given in the list located at $2EE70 + $13F4 = $30264. This is the same basic code for all items.

After this code more specific to various types of items is run. On line 6 a check is made for the keygems which adds a gem to the player's gem counter (The first counter is shown, depending on gem this or the next three counters will be affected.) After this a check is made for the 1UP item type which increases the player's life counter by 1. Following that is the ammo type check which increases the player's ammo counter ($7A58W) by an amount that depends on the difficulty ($7A6CW). Finally the sprite's action is changed to that of the got item, $1F28W.

The third and final section starting at $CD84 deals with all of the 'exceptional' sprite types and is called by the first section of the collision. It is a collection of short segments of code that deal with individual special sprite types Keen can interact with.

The first is the Council Member code. First the game checks to see if Keen is standing on a floor. If not, nothing happens, otherwise the Council Member code executes. (This means Keen cannot interact with a Council Member unless standing on a floor.) Next the level Keen is in is checked. If it is level 14 then the Oracle Janitor code is run. Otherwise the Council Member code is run. Most of this is in calls but notably sound $1F plays and the level state is set to 3.

Next are stunned sprites and Platforms. The difference relates almost entirely to the Bounder. For stunned sprites a check is performed to see if the sprite was a Bounder (If it was its old type $0F is stored when it is stunned.) If and only if that is the case then more code is run. Both stunned sprites and Platforms check an unknown variable and if it is zero then Keen can stand on the sprite.

Bounder types are next at $CDE8. This simply calls the 'push Keen vertically and horizontally' code meaning the Bounder types can push Keen around.

Second-to-last is Princess Lindsey's type at $CDF9 which simply runs her code. Finally the Foot's type at $CE10 sets the level state to 7. (The actual Foot code is stored elsewhere and triggered by the state change.)

Patch: Keen Collision 1 code
#Keen sprite collision: First section, jumps
%patch $CCA9 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $8B $04 $3D $0011W $75 $03 $E9 $0152W $7F $19 $3D $0004W $74 $30 $3D $0006W $75 $03 $E9 $00B7W $3D $000FW $75 $03 $E9 $0113W $5F $5E $5D $CB $3D $0014W $75 $03 $E9 $00EAW $3D $0018W $75 $03 $E9 $0110W $3D $0021W $75 $03 $E9 $00D4W $5F $5E $5D $CB
#Second section, items
%patch $CCF5 $8B $5C $3E $83 $FB $0B $76 $03 $E9 $0116W $D1 $E3 $2E $FF $A7 $161AW $8B $5C $3E $D1 $E3 $FF $B7 $13DCW $9A $187409F1RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $20 $0003W $8B $5C $3E $D1 $E3 $8B $87 $140CW $89 $44 $1E $8B $5C $3E $D1 $E3 $FF $B7 $13F4W $9A $06BD1EF2RL $83 $C4 $02 $83 $7C $3E $04 $7D $0B $8B $5C $3E $D1 $E3 $FF $87 $7A60W $EB $20 $83 $7C $3E $0A $75 $06 $FF $06 $7A6AW $EB $14 $83 $7C $3E $0B $75 $0E $8B $1E $7A6CW $D1 $E3 $8B $87 $13D4W $01 $06 $7A58W $B8 $1F28W $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB $5F $5E $5D $CB
#Third section, other
%patch $CD84 $83 $7D $36 $00 $75 $03 $E9 $0089W $83 $3E $A7EDW $0E $75 $17 $9A $0E8F07D9RL $9A $16540D59RL $56 $9A $06BD1E8BRL $83 $C4 $02 $5F $5E $5D $CB $B8 $001FW $50 $9A $187409F1RL $83 $C4 $02 $C7 $06 $7A70W $0003W $5F $5E $5D $CB $5F $5E $5D $CB %patch $CDC5 $83 $7C $44 $0F $75 $4B $83 $3E $7A6EW $00 $75 $44 $56 $57 $9A $09DC0D33RL $83 $C4 $04 $5F $5E $5D $CB $5F $5E $5D $CB $5F $5E $5D $CB %patch $CDE8 $33 $C0 $50 $56 $57 $9A $09DC0DA0RL $83 $C4 $06 $5F $5E $5D $CB %patch $CDF9 $9A $0E8F0645RL $56 $9A $06BD1E8BRL $83 $C4 $02 $9A $16540D59RL $5F $5E $5D $CB %patch $CE10 $C7 $06 $7A70W $0007W $5F $5E $5D $CB
#Pointless Keen-item collision list
%patch $CE1A $1507W
#Red Gem (At $CD07)
%patch $CE1C $1507W
#Yellow Gem (At $CD07)
%patch $CE1E $1507W
#Blue Gem (At $CD07)
%patch $CE20 $1507W
#Green Gem (At $CD07)
%patch $CE22 $1507W
#100 points (At $CD07)
%patch $CE24 $1507W
#200 points (At $CD07)
%patch $CE26 $1507W
#500 points (At $CD07)
%patch $CE28 $1507W
#1000 points (At $CD07)
%patch $CE2A $1507W
#2000 points (At $CD07)
%patch $CE2C $1507W
#5000 points (At $CD07)
%patch $CE2E $1507W
#1UP (At $CD07)
%patch $CE30 $1507W
#Ammo (At $CD07)


Compressed collision code

This patch compresses the collision 1 code by removing the item list and rearranging code. As a side effect it takes longer to process than the default code (Though this shouldn't be an issue on modern computers.) It will also crash the game if another kind of item is added to the game, but as this itself is exceedingly difficult it shouldn't be a concern.

The specifics of what this code does can be obtained from the above section.

Patch: Compressed Keen Collision 1 code
#Section 1, other
%patch $CCA9 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $8B $04 $3D $0011W
#Foot
$75 $06 $C7 $06 $7A70W $0007W $3D $0006W $75 $38 $83 $7D $36
#Council
$00 $74 $2E $83 $3E $A7EDW $0E $75 $15 $9A $0E8F07D9RL $9A $16540D59RL $56 $9A $06BD1E8BRL $83 $C4 $02 $EB $12 $B8 $001FW $50 $9A $187409F1RL $83 $C4 $02 $C7 $06 $7A70W $0003W $5F $5E $5D $CB $3D $000FW $75 $0F $33 $C0 $50 $56 $57 $9A
#Bounders
$09DC0DA0RL $83 $C4 $06 $EB $E8 $3D $0021W $75 $06 $83 $7C
#Platforms, stunned
$44 $0F $74 $05 $3D $0014W $75 $13 $83 $3E $7A6EW $00 $75 $D1 $56 $57 $9A $09DC0D33RL $83 $C4 $04 $EB $C5 $3D $0018W $75
#Lindsey
$15 $9A $0E8F0645RL $56 $9A $06BD1E8BRL $83 $C4 $02 $9A
#Items
$16540D59RL $EB $AB $3D $0004W $75 $A6
#Section 2, items
%patch $CD54 $8B $5C $3E $D1 $E3 $FF $B7 $13DCW $9A $187409F1RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $20 $0003W $8B $5C $3E $D1 $E3 $8B $87 $140CW $89 $44 $1E $8B $5C $3E $D1 $E3 $FF $B7 $13F4W $9A $06BD1EF2RL $83 $C4 $02 $83 $7C $3E $04 $7D $0B $8B $5C $3E $D1 $E3 $FF $87 $7A60W $EB $20 $83 $7C $3E $0A $75 $06 $FF $06 $7A6AW $EB $14 $83 $7C $3E $0B $75 $0E $8B $1E $7A6CW $D1 $E3 $8B $87 $13D4W $01 $06 $7A58W $B8 $1F28W $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB


Collision 2 code

This collision, often known as KeenOnPolesSpriteCollision is actually used under a variety of circumstances. Keen uses this collision when looking up or down, climbing poles and gripping ledges. The collision is far simpler than the first sprite collision, ignoring many sprite types. Like Keen's first sprite collision it employs a pointer list.

The first part of the code sets up the pointer list. All sprite types less than 9 are ignored. (First line.) All sprite types greater than $09 + $0B ($14) are likewise ignored. The list for intermediate values is located at $CEB5 ($16B5W in the segment.) Everything following is pointed to by the pointer list.

There are only four basic things the sprite collision does, the first being 'nothing' The next thing it does is kill the player, rather strange since all types that cause this kill the player in their own sprite collisions. The remaining two segments of code 'disturb' the player.

The first disturbance on lines 2-5 occurs when a Platform type sprite hits Keen. This restores his clipping to 1 (It is often 0 when doing things like pole climbing.) and changes his action to $11A2W, or falling. It also runs a 'push Keen vertically' subroutine so Keen will stand and move with the disturbing sprite.

The second disturbance is for Bounder type sprites that can push Keen sideways as well as vertically. This code is nearly the same; it also sets Keen's action to falling and his clipping to 1 but also sets his foreground variable to 1. It then runs a subroutine to push Keen vertically and horizontally. In Keen 4 it is caused only by Bounders.

Patch: Keen Collision 2 code
#Keen on pole sprite collision
%patch $CE32 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $8B $1D $83 $EB $09 $83 $FB $0B $77 $69 $D1 $E3 $2E $FF $A7 $16B5W $C7 $44 $06 $0001W $B8 $11A2W $50 $56 $9A $09DC120ARL $83 $C4 $04 $33 $C0 $89 $44 $18 $89 $44 $16 $A3 $BB $CA $57 $56 $9A $09DC0D33RL $83 $C4 $04 $5F $5E $5D $CB $0E $E8 $FD6CW $5F $5E $5D $CB $C7 $44 $20 $0001W $C7 $44 $06 $0001W $B8 $11A2W $50 $56 $9A $09DC120ARL $83 $C4 $04 $33 $C0 $89 $44 $18 $89 $44 $16 $A3 $BB $CA $33 $C0 $50 $57 $56 $9A $09DC0DA0RL $83 $C4 $06 $5F $5E $5D $CB
#Sprite collision list
%patch $CEB5 $1679W
#Kill Keen (At $CE79)
%patch $CEB7 $1679W
#Kill Keen (At $CE79)
%patch $CEB9 $16B0W
#Nothing (At $CEB0)
%patch $CEBB $16B0W
#Nothing (At $CEB0)
%patch $CEBD $16B0W
#Nothing (At $CEB0)
%patch $CEBF $1679W
#Kill Keen (At $CE79)
%patch $CEC1 $1681W
#Get knocked off of pole by Bounder (At $CE81)
%patch $CEC3 $16B0W
#Nothing (At $CEB0)
%patch $CEC5 $16B0W
#Nothing (At $CEB0)
%patch $CEC7 $16B0W
#Nothing (At $CEB0)
%patch $CEC9 $16B0W
#Nothing (At $CEB0)
%patch $CECB $164EW
#Get knocked off pole by Platform (At $CE4E)


Collision 3 code

This collision, often known as KeenSwimCollision is used only when Keen is swimming. The collision is a simpler version of collision 1 and also uses an item pointer list that is utterly pointless.

The first two lines differentiate between items (Type 4) and the Council Member (Type 6). The Member code skips to the last line of the collision where the level state is set to 3. (Executing the rest of the Council Member code.)

The rest of the collision deals with items. (This means Keen can only interact with two basic things while swimming.) This section first calls the pointless list at the end of the code. The list is 12 items long located at $E8F0 + $1117 = $FA07. All items do the same thing (At $F980) regardless of what item kind they are which renders the list pointless.

What is done to all item sprites is covered right after the list setup (Line 3 and onwards). First a 'got item' sound is played based on the list located at $2EE70 + $13DC = $3024C. Then the sprite's sprite type is set to 1, the 'misc sprite' type. Then its foreground variable is set to 3 so it appears in front of all tiles. (So the player can see all the items they get.) After this the sprite's animation changes based on the 'got item animation list' at $2EE70 + $140C = $3027C and the player's score increases by an amount given in the list located at $2EE70 + $13F4 = $30264. This is the same basic code for all items.

After this code more specific to various types of items is run. On line 7 a check is made for the keygems which adds a gem to the player's gem counter (The first counter is shown, depending on gem this or the next three counters will be affected.) After this a check is made for the 1UP item type which increases the player's life counter by 1. Following that is the ammo type check which increases the player's ammo counter ($7A58W) by an amount that depends on the difficulty ($7A6CW). Finally the sprite's action is changed to that of the got item, $1F28W.

Patch: Keen Collision 3 code
#Keenswim collision
%patch $F951 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $8B $04 $3D $0004W $74 $0B $3D $0006W $75 $03 $E9 $008EW $E9 $0091W $8B $5C $3E $83 $FB $0B $76 $03 $E9 $0086W $D1 $E3 $2E $FF $A7 $1117W $8B $5C $3E $D1 $E3 $FF $B7 $13DCW $9A $187409F1RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $20 $0003W $8B $5C $3E $D1 $E3 $8B $87 $140CW $89 $44 $1E $8B $5C $3E $D1 $E3 $FF $B7 $13F4W $9A $06BD1EF2RL $83 $C4 $02 $83 $7C $3E $04 $7D $0B $8B $5C $3E $D1 $E3 $FF $87 $7A60W $EB $20 $83 $7C $3E $0A $75 $06 $FF $06 $7A6AW $EB $14 $83 $7C $3E $0B $75 $0E $8B $1E $7A6CW $D1 $E3 $8B $87 $13D4W $01 $06 $7A58W $B8 $1F28W $50 $56 $9A $09DC120ARL $83 $C4 $04 $EB $08 $EB $06 $C7 $06 $7A70W $0003W $83 $C7 $4C $5F $5E $5D $CB
#Items list
%patch $FA07 $1090W
#Red Gem (At $F980)
%patch $FA09 $1090W
#Yellow Gem (At $F980)
%patch $FA0B $1090W
#Blue Gem (At $F980)
%patch $FA0D $1090W
#Green Gem (At $F980)
%patch $FA0F $1090W
#100 points (At $F980)
%patch $FA11 $1090W
#200 points (At $F980)
%patch $FA13 $1090W
#500 points (At $F980)
%patch $FA15 $1090W
#1000 points (At $F980)
%patch $FA17 $1090W
#2000 points (At $F980)
%patch $FA19 $1090W
#5000 points (At $F980)
%patch $FA1B $1090W
#1UP (At $F980)
%patch $FA1D $1090W
#Ammo (At $F980)


Bounder types push Keen sideways but can't be stood on

This patch alters the two sprite collisions Keen uses that refer to Bounder-type sprites. This makes anything using the Bounder type push Keen left and right, but not up and down. This means that Keen cannot stand on them. This also frees the code from $AB6D - $ACAD.

Patch: Bounder types push Keen sideways but can't be stood on
#Bounders push Keen sideways but can't be stood on
%patch $CE98 $33 $C0 $89 $44 $18 $89 $44 $16 $A3 $BB $CA $57 $56 $9A $09DC0C9ARL $83 $C4 $04 $5F $5E $5D $CB %patch $CDE8 $56 $57 $9A $09DC0C9ARL $83 $C4 $04 $5F $5E $5D $CB


Sprite-tile interaction

The player's tile interaction, the game tile code is not in fact part of Keen's tile interaction. Instead it is run by the designated player sprite whatever its current tile interaction may be. Keen in fact has several tile interactions depending on what he is doing.


Interaction values

The following is a general guide to the various tile interactions Keen uses. Note also that his interaction with various tile types (Deadly, items, etc.) is in addition to this, as noted above.

Patch: Keen 4
#Standing
%patch $2F814 $0B801AA2RL
#Walking
%patch $2FF1C $0B801B5FRL %patch $2FF3A $0B801B5FRL %patch $2FF58 $0B801B5FRL %patch $2FF76 $0B801B5FRL
#Bored 1
%patch $2F832 $0B801AA2RL
#Bored 2
%patch $2F850 $0B801AA2RL %patch $2F86E $0B801AA2RL %patch $2F88C $0B801AA2RL %patch $2F8AA $0B801AA2RL %patch $2F8C8 $0B801AA2RL %patch $2F8E6 $0B801AA2RL
#Bored 3
%patch $2F95E $0B801AA2RL %patch $2F97C $0B801AA2RL %patch $2F99A $0B801AA2RL %patch $2F9B8 $0B801AA2RL %patch $2F9D6 $0B801AA2RL %patch $2F9F4 $0B801AA2RL %patch $2FA12 $0B801AA2RL %patch $2FA30 $0B801AA2RL %patch $2FA4E $0B801AA2RL %patch $2FA6C $0B801AA2RL
#Mooning
%patch $2F904 $0B801AA2RL %patch $2F922 $0B801AA2RL %patch $2F940 $0B801AA2RL
#Look up
%patch $2FA8A $0B801AA2RL %patch $2FAA8 $0B801AA2RL
#Look down
%patch $2FAC6 $0B801AA2RL %patch $2FAE4 $0B801AA2RL %patch $2FB02 $0B801AA2RL %patch $2FB20 $0B801AA2RL


Pogoing Keen

These patches relate to Keen using the pogo.


Keen cannot pogo before getting an item\winning a level

This patch stops Keen from pogoing until he has fulfilled a certain condition. The patch as given here limits Keen's pogoing until he wins level 4. The condition is highlighted in brown (See Patch:Game stats and Patch:Jump conditions.)

The values $FFD0W is the pogo speed, which controls the pogo bounce height; $0002W is the sound played when the pogo is deployed (It can also be $0007W.).

As a side effect the F10 B Cheat is disabled.

Patch: Keen cannot pogo before getting an item\winning a level
#Keen cannot pogo before getting an item\winning a level
#Disable F10-B and insert New Keen start pogo code
%patch $73B4 $E9 $0095W $55 $8B $EC $56 $8B $76 $06 $C7 $44 $18 $FFD0W $8B $44 $18 $BA $06 $00 $F7 $EA $A3 $21 $C9 $C7 $06 $BB $CA $0018W $B8 $0007W $50 $9A $187409F1RL $83 $C4 $02 $5E $5D $CB
#Change start_pogo behavior
%patch $2FF8C $06BD07E7RL
#No pogo while standing until level 4 is done
%patch $BB14 $83 $3E $7A26W $00 $74 $29 $C7 $06 $C3 $C5 $0001W $B8 $0002W $50 $9A $187409F1RL $83 $C4 $02 $C7 $44 $1C $110CW $C7 $44 $16 $0000W $C7 $44 $18 $FFD0W $5E $5D $CB
#No pogo while walking until level 4 is done
%patch $BF2D $83 $3E $7A26W $00 $74 $30 $C7 $06 $C3 $C5 $0001W $C7 $44 $1C $110CW $B8 $0002W $50 $9A $187409F1RL $83 $C4 $02 $8B $44 $0E $B1 $04 $D3 $E0 $89 $44 $16 $C7 $44 $18 $FFD0W $5E $8B $E5 $5D $CB
#No pogo in air until level 4 is done
%patch $C49B $22 $83 $3E $C3 $C5 $00 $75 $1B $83 $3E $7A26W $00 $74 $14 $C7 $06 $C3 $C5 $0001W $C7 $44 $1C $112AW $C7 $06 $BB $CA $0000W $5E $5D $CB


Disable shooting while pogoing

This patch stops Keen from shooting while pogoing. (See also Patch:Keen shooting (Galaxy).) Keen can still shoot while doing other things.

Patch: Disable shooting while pogoing
#Disable shooting while pogoing
%patch $C5DE $EB


Jumping Keen

These patches relate to Keen jumping.


Disable shooting while jumping

This patch stops Keen from shooting while jumping\falling. (See also Patch:Keen shooting (Galaxy).) Keen can still shoot while doing other things.

Patch: Disable shooting while jumping
#Disable shooting while jumping
%patch $C462 $EB


Jump physics

The variables that control the height and duration of Keen's jumps are spread over several behaviors. There are two important parameters: initial velocity, and duration. The velocity is the initial speed of the jump or pogo, while the duration is the maximum time that this initial velocity can be sustained before Keen feels gravity. That is, the initial velocity is how fast Keen jumps, while the duration is how long.

Since distance is speed * time, increasing either will increase Keen's jump height. However the most 'natural' looking way to increase Keen's jump height is to increase the duration, 'faster' jumps can look choppy. Also, the speed and duration only apply to the start of Keen's jump, when the time runs out, he will still be moving upwards, but will start slowing and then start falling.


Patch: Jumping Physics
#Jump from standstill
%patch $BAF0 $FFD8W
#Starting speed
%patch $BAFC $0012W
#Duration
#Pogo from standstill
%patch $BB33 $FFD0W
#Starting speed
%patch $BB3F $0018W
#Duration
#Jump from walking
%patch $BF0A $FFD8W
#Starting speed
%patch $BF18 $0012W
#Duration
#Pogo from walking
%patch $BF51 $FFD0W
#Starting speed
%patch $BF5D $0018W
#Duration
#Pogo bounce
%patch $C4D3 $FFD0W
#Starting speed
%patch $C4E4 $0018W
#Duration
#Pogo air
%patch $C50E $09
#Duration, after this gravity takes hold
#Jump from a pole
%patch $C6AB $FFECW
#Starting speed
%patch $C6B6 $000AW
#Duration
#Pogo Bounce
%patch $D830 $FFD0W
#Starting speed
%patch $D836 $0018W
#Duration


Details

The duration can be considered a 'timer' that counts down. When it reaches zero Keen will experience gravity. However, if the jump or pogo button is released, then Keen will start to feel gravity even if the timer has not expired. The timer is measured in tics (70 Hz), so a timer of 70 means that Keen can jump upwards for 1 second before feeling gravity. The initial velocity is in map units per tic, which is 256ths of a tile per 70th of a second.


Example problems

Q1.  If Keen is given an initial velocity of -18 ($FFEEW) and a max timer of 70 tics (1 second), what is the tile-height at his jump apex?
A1.  -18 (map units/tic) * 70 tics * 1 (tile/256 map units) = 4 tiles.
Q2.  We have given Keen an initial velocity of 8, and we want his jump apex to be 5 tiles high.  What will his maximum timer need to be set at?
A2.  8 (map units/tic) * 1 (tile / 256 map units) * X tics = 5 tiles  --> rearrange to solve for X --> X = 160 tics.

Note that these problems only consider the linear region of Keen's jump (i.e., when the jump button is depressed and velocity is constant upwards in the y-axis). After this linear region, Keen will still travel upwards as gravity begins to pull him down (i.e., he has reached the parabolic region of his jump). This extra distance is dependent only on velocity at the end of the linear region (i.e., the initial velocity that you patched), and not on the jump timer. Once Keen has reached the parabolic region, he will accelerate downwards at 2 map units / tic^2 (or 1.5 on easy mode).

Q3.  Reread Q1.  In consideration of the extra height that Keen will acquire due to the parabolic region of his jump, what is his TRUE tile-height at his jump apex?
A3.  At the end of the linear region, Keen had traveled 4 tiles and retained a velocity of -18 (map units / tic).  
    Use v^2 = u^2 + 2as to deduce maximum height, at which point v^2 = 0.
    0 = u^2 + 2as --> --> s = -u^2/2a 
    s = [- 324 (mu^2/tic^2) ] / [ 4 (mu/tic^2) ] = -81 mu = ~ -0.3 tiles.

So the calculated height is 4.3 tiles. In actuality, Keen jumps a little over 5 tiles, because the acceleration is not uniform per tic (it is actually applied twice after every second tic) and it is distorted a little bit at the apex. In addition, at the end of the linear region of the pogo, gravity is greatly decreased, and the duration of this decreased gravity effect can be altered. Even after considering the parabolic region, jump height will likely be a little bit higher than calculated, so you'll have to fine tune it by testing.


Keen can jump as high as he wants

This patch allows Keen to jump as if he has the F10 J cheat on all the time. The F10 J cheat will still work, but will not change anything. The second line allows Keen to hit ceilings and not fall. Removing this line makes Keen act like the jump cheat in keen Dreams.

Patch: Keen 5
#Keen has no max jump height
%patch $C3B2 $EB $0A %patch $D49D $EB $30
#And don't hit ceilings


Keen entering doors

Remove 'air-door' glitch

This patch stops Keen re-entering doors he has just emerged from. This stops a particular bug which allows Keen to exit some levels by pressing up as soon as he emerges from a door.

Patch: Keen 4
#Eliminate air-door entry glitch
%patch $2FD5E $0C02W


Sprite spawn code

There are two initiation codes, one for Keen facing left and one for Keen facing right. Both are nearly identical except for Keen's starting direction. Both use the same spawning code. The call $0D8F0003RL is used to mark the sprite as the player.

In the initiation code notice the Keen's cache being set ($C7 $06 $3D $CB $0001W.) Also notice that both initiation codes cache the scoreboard image ($00FDW) separately.

In the spawning code the last blue highlighted value is the sprite action the sprite uses as it proceeds to act in-level. $C7 $02 $xxxxW sets the clipping, $C7 $07 $xxxxW sets the sprite type, $C7 $20 $xxxxW sets the foreground value. Finally $D3 $E0 $05 $xxxx is how far down (Or more usually up) the sprite is spawned from where it is placed. This is necessary for sprites that walk on the ground as they can only be placed in the level at multiples of 16 pixels high while their actual height can be anything.

Keen's horizontal direction depends on his initiation code. (It is the first blue variable.) He always starts the level 'facing down' however, though this is of little importance. $C7 $47 $10 $xxxxW is the vertical direction the sprite starts moving in, either $0001W (Facing down), $FFFFW (Facing up) or $0000W (Neither, never used.) Keen's sprite type is important, if it is not $0002W then he will be invulnerable to enemy sprites since this sprite type is used to identify 'killable players'

Patch: Keen 4
#Location of initiation codes
%patch $EE85 $0064W
#Right Facing Keen (At $E954)
%patch $EE87 $0090W
#Left Facing Keen (At $E980)
#Right facing Keen Initiation code
%patch $E954 $B8 $0001W $50 $FF $76 $FC $57 $9A $0B80000ERL
#Keen's direction is +1
$83 $C4 $06 $9A $0D8F0003RL $C7 $06 $3D $CB $0001W $B8 $2A3ARW $8A $16 $EC $7A $8E $C0 $26 $08 $16 $00FDW $E9 $047DW
#Cache scoreboard too
#Left facing Keen Initiation code
%patch $E980 $B8 $FFFFW $50 $FF $76 $FC $57 $9A $0B80000ERL
#Keen's direction is -1
$83 $C4 $06 $9A $0D8F0003RL $C7 $06 $3D $CB $0001W $B8 $2A3ARW $8A $16 $EC $7A $8E $C0 $26 $08 $16 $00FDW $E9 $0451W
#Cache scoreboard too
#Normal Keen spawning code
%patch $B80E $55 $8B $EC $8B $1E $A7D6W $C7 $07 $0002W $C7 $47 $02 $0002W $C7 $47 $20 $0001W $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05 $FF0FW $89 $47 $0C $8B $46 $0A $89 $47 $0E $C7 $47 $10 $0001W $B8 $098CW $50 $53 $9A $09DC118CRL $83 $C4 $04 $5D $CB


Keen's spawn height and changing Keen's height

This simple patch alters how high Keen spawns above where he is placed in a level. By default this is 16 pixels up,suitable for a Keen sprite 32 pixels high. If Keen's height is changed, this should be changed to reflect that. It is part of the above spawning code patch and shouldn't be used in conjunction with it.

Patch: Keen 4
#Keen's spawn height
%patch $B833 $FF0FW
#16 pixels up



Sprite Actions

This is a complete list of Keen's actions, both in-level and on the map. t provides links to some pages that discuss specific actions in further detail but a discussion of all of Keen's actions is too complex to host on this page.

Actions:
$098CW #Keen standing
$09AAW #Keen looks up (Bored)
$09C8W #Keen shrugs 1(Bored more)
$09E6W #Keen shrugs 2
$0A04W #Keen shrugs 3
$0A22W #Keen shrugs 4
$0A40W #Keen shrugs 5
$0A5EW #Keen shrugs 6
$0A7CW #Keen moons 1
$0A9AW #Keen moons 2
$0AB8W #Keen moons 3
$0AD6W #Keen starts reading book 1
$0AF4W #Keen starts reading book 2
$0B12W #Keen starts reading book 3
$0B30W #Keen starts reading book 4
$0B4EW #Keen reads book 1
$0B6CW #Keen reads book 2
$0B8AW #Keen reads book 3
$0BA8W #Keen stops reading book 1
$0BC6W #Keen stops reading book 2
$0BE4W #Keen stops reading book 3
$0C02W #Keen looking up
$0C20W #Keen looking up
$0C3EW #Keen looks down
$0C5CW #Keen looks down
$0C7AW #Keen looks down
$0C98W #Keen looking down
$0CB6W #Keen looking down
$0CD4W #Defunct dead action
$0CF2W #Keen dies sprawled (Exits level if offscreen.)
$0D10W #Keen dies clutched (Exits level if offscreen.)
$0D2EW #Keen die swimming sprawled (Exits level if offscreen.)
$0D4CW #Keen die swimming clutched (Exits level if offscreen.)
$0D6AW #Keen shooting horizontally 1
$0D88W #Keen shooting horizontally 2
$0DA6W #Keen shooting up 1
$0DC4W #Keen shooting up 2
$0DE2W #Keen finishes flicking switches
$0E00W #Keen finishes flicking switches
$0E1EW #Keen places gem, door opens
$0E3CW #Keen turns away from screen
$0E5AW #Keen walks into doors
$0E78W #Keen walks into doors
$0E96W #Keen walks into doors
$0EB4W #Keen walks into doors
$0ED2W #Keen walks into doors
$0EF0W #Keen going still on a pole
$0F0EW #Keen going up a pole
$0F2CW #Keen going up a pole
$0F4AW #Keen going up a pole
$0F68W #Keen going down a pole
$0F86W #Keen going down a pole
$0FA4W #Keen going down a pole
$0FC2W #Keen going down a pole
$0FE0W #Keen shooting horizontally on a pole 1
$0FFEW #Keen shooting horizontally on a pole 2
$101CW #Keen shoots up on pole 1
$103AW #Keen shoots up on pole 2
$1058W #Keen shooting down on a pole 1
$1076W #Keen shooting down on a pole 2
$1094W #Keen standing (Walking action)
$10B2W #Keen walking
$10D0W #Keen walking
$10EEW #Keen walking
$110CW #Keen start pogoing
$112AW #Keen pogoing
$1148W #Keen pogoing
$1166W #Keen jumping 1
$1184W #Keen jumping 2
$11A2W #Keen falling 1
$11C0W #Keen falling 2
$11DEW #Keen start shooting horizontally in air
$11FCW #Keen shoot horizontally in air 1
$121AW #Keen shoot horizontally in air 2
$1238W #Keen start shooting upwards in air
$1256W #Keen shooting up in air 1
$1274W #Keen shooting up in air 2
$1292W #Keen start shooting downwards in air 
$12B0W #Keen shoot down in air 1
$12CEW #Keen shoot down in air 2
$12ECW #Keen gripping ledge 1
$130AW #Keen gripping ledge 2
$1328W #Keen pulls himself up from ledgegripping 1
$1346W #Keen pulls himself up from ledgegripping 2
$1364W #Keen pulls himself up from ledgegripping 3
$1382W #Keen pulls himself up from ledgegripping 4
$13A0W #Keen standing on air (After pulling himself up. Doesn't fall)
$1492W #Map Keen riding foot
$14B0W #Map Keen riding foot
$14CEW #Map Keen swimming
$14ECW #Map Keen standing still
$150AW #Map Keen waving when bored
$1528W #Map Keen waving when bored
$1546W #Map Keen waving when bored
$1564W #Map Keen waving when bored
$1582W #Map Keen waving when bored
$15A0W #Map Keen moving


Sprite Collision

Keen has several sprite collisions used in a variety of circumstances. As such this section does not list the collision values of Keen's actions but instead deals with the more general collision codes.

For patches that affect what collision a specific action uses, see that action's page. (For example Patch:Keen on poles.)


Collision 1 code

This collision, often known as KeenSpriteCollision is used under a variety of circumstances. Keen uses this collision when doing such things as being bored, looking up or down and mooning the player. The collision is exceedingly complex and is notable for using a pointer list that is utterly pointless.

The first section deals with 'exceptional' sprite types. On the first line the Foot's sprite type is checked for followed by a jump to $CCD9 if the sprite type is greater than the Foot's. (An unusual step) If not then the following checks are made: Items, Council Members and Bounders, These checks cause the game to jump to $CE10 (Foot), $CCF5, $CD84, and $CDE8 respectively. (Which are covered later.)

The second part (lines 4 and 5) of the first section deals with further sprite checks; Platforms, Princess Lindsey and stunned sprites. These checks jump to $CDCB, $CDF9 and $CDC5 respectively. (Again these will be treated later.)

The second section starts at $CCF5 and deals with the item sprite type (Type 4) This section first calls the pointless list at the end of the code. The list is 12 items long located at $9DC0 + $161A = $CE1A. All items do the same thing (At $CD07) regardless of what item kind they are which renders the list pointless.

What is done to all item sprites is covered right after the list setup (Line 3 and onwards). First a 'got item' sound is played based on the list located at $2EE70 + $13DC = $3024C. Then the sprite's sprite type is set to 1, the 'misc sprite' type. Then its foreground variable is set to 3 so it appears in front of all tiles. (So the player can see all the items they get.) After this the sprite's animation changes based on the 'got item animation list' at $2EE70 + $140C = $3027C and the player's score increases by an amount given in the list located at $2EE70 + $13F4 = $30264. This is the same basic code for all items.

After this code more specific to various types of items is run. On line 6 a check is made for the keygems which adds a gem to the player's gem counter (The first counter is shown, depending on gem this or the next three counters will be affected.) After this a check is made for the 1UP item type which increases the player's life counter by 1. Following that is the ammo type check which increases the player's ammo counter ($7A58W) by an amount that depends on the difficulty ($7A6CW). Finally the sprite's action is changed to that of the got item, $1F28W.

The third and final section starting at $CD84 deals with all of the 'exceptional' sprite types and is called by the first section of the collision. It is a collection of short segments of code that deal with individual special sprite types Keen can interact with.

The first is the Council Member code. First the game checks to see if Keen is standing on a floor. If not, nothing happens, otherwise the Council Member code executes. (This means Keen cannot interact with a Council Member unless standing on a floor.) Next the level Keen is in is checked. If it is level 14 then the Oracle Janitor code is run. Otherwise the Council Member code is run. Most of this is in calls but notably sound $1F plays and the level state is set to 3.

Next are stunned sprites and Platforms. The difference relates almost entirely to the Bounder. For stunned sprites a check is performed to see if the sprite was a Bounder (If it was its old type $0F is stored when it is stunned.) If and only if that is the case then more code is run. Both stunned sprites and Platforms check an unknown variable and if it is zero then Keen can stand on the sprite.

Bounder types are next at $CDE8. This simply calls the 'push Keen vertically and horizontally' code meaning the Bounder types can push Keen around.

Second-to-last is Princess Lindsey's type at $CDF9 which simply runs her code. Finally the Foot's type at $CE10 sets the level state to 7. (The actual Foot code is stored elsewhere and triggered by the state change.)

Patch: Keen Collision 1 code
#Keen sprite collision: First section, jumps
%patch $CCA9 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $8B $04 $3D $0011W $75 $03 $E9 $0152W $7F $19 $3D $0004W $74 $30 $3D $0006W $75 $03 $E9 $00B7W $3D $000FW $75 $03 $E9 $0113W $5F $5E $5D $CB $3D $0014W $75 $03 $E9 $00EAW $3D $0018W $75 $03 $E9 $0110W $3D $0021W $75 $03 $E9 $00D4W $5F $5E $5D $CB
#Second section, items
%patch $CCF5 $8B $5C $3E $83 $FB $0B $76 $03 $E9 $0116W $D1 $E3 $2E $FF $A7 $161AW $8B $5C $3E $D1 $E3 $FF $B7 $13DCW $9A $187409F1RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $20 $0003W $8B $5C $3E $D1 $E3 $8B $87 $140CW $89 $44 $1E $8B $5C $3E $D1 $E3 $FF $B7 $13F4W $9A $06BD1EF2RL $83 $C4 $02 $83 $7C $3E $04 $7D $0B $8B $5C $3E $D1 $E3 $FF $87 $7A60W $EB $20 $83 $7C $3E $0A $75 $06 $FF $06 $7A6AW $EB $14 $83 $7C $3E $0B $75 $0E $8B $1E $7A6CW $D1 $E3 $8B $87 $13D4W $01 $06 $7A58W $B8 $1F28W $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB $5F $5E $5D $CB
#Third section, other
%patch $CD84 $83 $7D $36 $00 $75 $03 $E9 $0089W $83 $3E $A7EDW $0E $75 $17 $9A $0E8F07D9RL $9A $16540D59RL $56 $9A $06BD1E8BRL $83 $C4 $02 $5F $5E $5D $CB $B8 $001FW $50 $9A $187409F1RL $83 $C4 $02 $C7 $06 $7A70W $0003W $5F $5E $5D $CB $5F $5E $5D $CB %patch $CDC5 $83 $7C $44 $0F $75 $4B $83 $3E $7A6EW $00 $75 $44 $56 $57 $9A $09DC0D33RL $83 $C4 $04 $5F $5E $5D $CB $5F $5E $5D $CB $5F $5E $5D $CB %patch $CDE8 $33 $C0 $50 $56 $57 $9A $09DC0DA0RL $83 $C4 $06 $5F $5E $5D $CB %patch $CDF9 $9A $0E8F0645RL $56 $9A $06BD1E8BRL $83 $C4 $02 $9A $16540D59RL $5F $5E $5D $CB %patch $CE10 $C7 $06 $7A70W $0007W $5F $5E $5D $CB
#Pointless Keen-item collision list
%patch $CE1A $1507W
#Red Gem (At $CD07)
%patch $CE1C $1507W
#Yellow Gem (At $CD07)
%patch $CE1E $1507W
#Blue Gem (At $CD07)
%patch $CE20 $1507W
#Green Gem (At $CD07)
%patch $CE22 $1507W
#100 points (At $CD07)
%patch $CE24 $1507W
#200 points (At $CD07)
%patch $CE26 $1507W
#500 points (At $CD07)
%patch $CE28 $1507W
#1000 points (At $CD07)
%patch $CE2A $1507W
#2000 points (At $CD07)
%patch $CE2C $1507W
#5000 points (At $CD07)
%patch $CE2E $1507W
#1UP (At $CD07)
%patch $CE30 $1507W
#Ammo (At $CD07)


Compressed collision code

This patch compresses the collision 1 code by removing the item list and rearranging code. As a side effect it takes longer to process than the default code (Though this shouldn't be an issue on modern computers.) It will also crash the game if another kind of item is added to the game, but as this itself is exceedingly difficult it shouldn't be a concern.

The specifics of what this code does can be obtained from the above section.

Patch: Compressed Keen Collision 1 code
#Section 1, other
%patch $CCA9 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $8B $04 $3D $0011W
#Foot
$75 $06 $C7 $06 $7A70W $0007W $3D $0006W $75 $38 $83 $7D $36
#Council
$00 $74 $2E $83 $3E $A7EDW $0E $75 $15 $9A $0E8F07D9RL $9A $16540D59RL $56 $9A $06BD1E8BRL $83 $C4 $02 $EB $12 $B8 $001FW $50 $9A $187409F1RL $83 $C4 $02 $C7 $06 $7A70W $0003W $5F $5E $5D $CB $3D $000FW $75 $0F $33 $C0 $50 $56 $57 $9A
#Bounders
$09DC0DA0RL $83 $C4 $06 $EB $E8 $3D $0021W $75 $06 $83 $7C
#Platforms, stunned
$44 $0F $74 $05 $3D $0014W $75 $13 $83 $3E $7A6EW $00 $75 $D1 $56 $57 $9A $09DC0D33RL $83 $C4 $04 $EB $C5 $3D $0018W $75
#Lindsey
$15 $9A $0E8F0645RL $56 $9A $06BD1E8BRL $83 $C4 $02 $9A
#Items
$16540D59RL $EB $AB $3D $0004W $75 $A6
#Section 2, items
%patch $CD54 $8B $5C $3E $D1 $E3 $FF $B7 $13DCW $9A $187409F1RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $20 $0003W $8B $5C $3E $D1 $E3 $8B $87 $140CW $89 $44 $1E $8B $5C $3E $D1 $E3 $FF $B7 $13F4W $9A $06BD1EF2RL $83 $C4 $02 $83 $7C $3E $04 $7D $0B $8B $5C $3E $D1 $E3 $FF $87 $7A60W $EB $20 $83 $7C $3E $0A $75 $06 $FF $06 $7A6AW $EB $14 $83 $7C $3E $0B $75 $0E $8B $1E $7A6CW $D1 $E3 $8B $87 $13D4W $01 $06 $7A58W $B8 $1F28W $50 $56 $9A $09DC120ARL $83 $C4 $04 $5F $5E $5D $CB


Collision 2 code

This collision, often known as KeenOnPolesSpriteCollision is actually used under a variety of circumstances. Keen uses this collision when looking up or down, climbing poles and gripping ledges. The collision is far simpler than the first sprite collision, ignoring many sprite types. Like Keen's first sprite collision it employs a pointer list.

The first part of the code sets up the pointer list. All sprite types less than 9 are ignored. (First line.) All sprite types greater than $09 + $0B ($14) are likewise ignored. The list for intermediate values is located at $CEB5 ($16B5W in the segment.) Everything following is pointed to by the pointer list.

There are only four basic things the sprite collision does, the first being 'nothing' The next thing it does is kill the player, rather strange since all types that cause this kill the player in their own sprite collisions. The remaining two segments of code 'disturb' the player.

The first disturbance on lines 2-5 occurs when a Platform type sprite hits Keen. This restores his clipping to 1 (It is often 0 when doing things like pole climbing.) and changes his action to $11A2W, or falling. It also runs a 'push Keen vertically' subroutine so Keen will stand and move with the disturbing sprite.

The second disturbance is for Bounder type sprites that can push Keen sideways as well as vertically. This code is nearly the same; it also sets Keen's action to falling and his clipping to 1 but also sets his foreground variable to 1. It then runs a subroutine to push Keen vertically and horizontally. In Keen 4 it is caused only by Bounders.

Patch: Keen Collision 2 code
#Keen on pole sprite collision
%patch $CE32 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $8B $1D $83 $EB $09 $83 $FB $0B $77 $69 $D1 $E3 $2E $FF $A7 $16B5W $C7 $44 $06 $0001W $B8 $11A2W $50 $56 $9A $09DC120ARL $83 $C4 $04 $33 $C0 $89 $44 $18 $89 $44 $16 $A3 $BB $CA $57 $56 $9A $09DC0D33RL $83 $C4 $04 $5F $5E $5D $CB $0E $E8 $FD6CW $5F $5E $5D $CB $C7 $44 $20 $0001W $C7 $44 $06 $0001W $B8 $11A2W $50 $56 $9A $09DC120ARL $83 $C4 $04 $33 $C0 $89 $44 $18 $89 $44 $16 $A3 $BB $CA $33 $C0 $50 $57 $56 $9A $09DC0DA0RL $83 $C4 $06 $5F $5E $5D $CB
#Sprite collision list
%patch $CEB5 $1679W
#Kill Keen (At $CE79)
%patch $CEB7 $1679W
#Kill Keen (At $CE79)
%patch $CEB9 $16B0W
#Nothing (At $CEB0)
%patch $CEBB $16B0W
#Nothing (At $CEB0)
%patch $CEBD $16B0W
#Nothing (At $CEB0)
%patch $CEBF $1679W
#Kill Keen (At $CE79)
%patch $CEC1 $1681W
#Get knocked off of pole by Bounder (At $CE81)
%patch $CEC3 $16B0W
#Nothing (At $CEB0)
%patch $CEC5 $16B0W
#Nothing (At $CEB0)
%patch $CEC7 $16B0W
#Nothing (At $CEB0)
%patch $CEC9 $16B0W
#Nothing (At $CEB0)
%patch $CECB $164EW
#Get knocked off pole by Platform (At $CE4E)


Collision 3 code

This collision, often known as KeenSwimCollision is used only when Keen is swimming. The collision is a simpler version of collision 1 and also uses an item pointer list that is utterly pointless.

The first two lines differentiate between items (Type 4) and the Council Member (Type 6). The Member code skips to the last line of the collision where the level state is set to 3. (Executing the rest of the Council Member code.)

The rest of the collision deals with items. (This means Keen can only interact with two basic things while swimming.) This section first calls the pointless list at the end of the code. The list is 12 items long located at $E8F0 + $1117 = $FA07. All items do the same thing (At $F980) regardless of what item kind they are which renders the list pointless.

What is done to all item sprites is covered right after the list setup (Line 3 and onwards). First a 'got item' sound is played based on the list located at $2EE70 + $13DC = $3024C. Then the sprite's sprite type is set to 1, the 'misc sprite' type. Then its foreground variable is set to 3 so it appears in front of all tiles. (So the player can see all the items they get.) After this the sprite's animation changes based on the 'got item animation list' at $2EE70 + $140C = $3027C and the player's score increases by an amount given in the list located at $2EE70 + $13F4 = $30264. This is the same basic code for all items.

After this code more specific to various types of items is run. On line 7 a check is made for the keygems which adds a gem to the player's gem counter (The first counter is shown, depending on gem this or the next three counters will be affected.) After this a check is made for the 1UP item type which increases the player's life counter by 1. Following that is the ammo type check which increases the player's ammo counter ($7A58W) by an amount that depends on the difficulty ($7A6CW). Finally the sprite's action is changed to that of the got item, $1F28W.

Patch: Keen Collision 3 code
#Keenswim collision
%patch $F951 $55 $8B $EC $56 $57 $8B $7E $06 $8B $76 $08 $8B $04 $3D $0004W $74 $0B $3D $0006W $75 $03 $E9 $008EW $E9 $0091W $8B $5C $3E $83 $FB $0B $76 $03 $E9 $0086W $D1 $E3 $2E $FF $A7 $1117W $8B $5C $3E $D1 $E3 $FF $B7 $13DCW $9A $187409F1RL $83 $C4 $02 $C7 $04 $0001W $C7 $44 $20 $0003W $8B $5C $3E $D1 $E3 $8B $87 $140CW $89 $44 $1E $8B $5C $3E $D1 $E3 $FF $B7 $13F4W $9A $06BD1EF2RL $83 $C4 $02 $83 $7C $3E $04 $7D $0B $8B $5C $3E $D1 $E3 $FF $87 $7A60W $EB $20 $83 $7C $3E $0A $75 $06 $FF $06 $7A6AW $EB $14 $83 $7C $3E $0B $75 $0E $8B $1E $7A6CW $D1 $E3 $8B $87 $13D4W $01 $06 $7A58W $B8 $1F28W $50 $56 $9A $09DC120ARL $83 $C4 $04 $EB $08 $EB $06 $C7 $06 $7A70W $0003W $83 $C7 $4C $5F $5E $5D $CB
#Items list
%patch $FA07 $1090W
#Red Gem (At $F980)
%patch $FA09 $1090W
#Yellow Gem (At $F980)
%patch $FA0B $1090W
#Blue Gem (At $F980)
%patch $FA0D $1090W
#Green Gem (At $F980)
%patch $FA0F $1090W
#100 points (At $F980)
%patch $FA11 $1090W
#200 points (At $F980)
%patch $FA13 $1090W
#500 points (At $F980)
%patch $FA15 $1090W
#1000 points (At $F980)
%patch $FA17 $1090W
#2000 points (At $F980)
%patch $FA19 $1090W
#5000 points (At $F980)
%patch $FA1B $1090W
#1UP (At $F980)
%patch $FA1D $1090W
#Ammo (At $F980)


Bounder types push Keen sideways but can't be stood on

This patch alters the two sprite collisions Keen uses that refer to Bounder-type sprites. This makes anything using the Bounder type push Keen left and right, but not up and down. This means that Keen cannot stand on them. This also frees the code from $AB6D - $ACAD.

Patch: Bounder types push Keen sideways but can't be stood on
#Bounders push Keen sideways but can't be stood on
%patch $CE98 $33 $C0 $89 $44 $18 $89 $44 $16 $A3 $BB $CA $57 $56 $9A $09DC0C9ARL $83 $C4 $04 $5F $5E $5D $CB %patch $CDE8 $56 $57 $9A $09DC0C9ARL $83 $C4 $04 $5F $5E $5D $CB


Sprite-tile interaction

The player's tile interaction, the game tile code is not in fact part of Keen's tile interaction. Instead it is run by the designated player sprite whatever its current tile interaction may be. Keen in fact has several tile interactions depending on what he is doing.


Interaction values

The following is a general guide to the various tile interactions Keen uses. Note also that his interaction with various tile types (Deadly, items, etc.) is in addition to this, as noted above.

Patch: Keen 4
#Standing
%patch $2F814 $0B801AA2RL
#Walking
%patch $2FF1C $0B801B5FRL %patch $2FF3A $0B801B5FRL %patch $2FF58 $0B801B5FRL %patch $2FF76 $0B801B5FRL
#Bored 1
%patch $2F832 $0B801AA2RL
#Bored 2
%patch $2F850 $0B801AA2RL %patch $2F86E $0B801AA2RL %patch $2F88C $0B801AA2RL %patch $2F8AA $0B801AA2RL %patch $2F8C8 $0B801AA2RL %patch $2F8E6 $0B801AA2RL
#Bored 3
%patch $2F95E $0B801AA2RL %patch $2F97C $0B801AA2RL %patch $2F99A $0B801AA2RL %patch $2F9B8 $0B801AA2RL %patch $2F9D6 $0B801AA2RL %patch $2F9F4 $0B801AA2RL %patch $2FA12 $0B801AA2RL %patch $2FA30 $0B801AA2RL %patch $2FA4E $0B801AA2RL %patch $2FA6C $0B801AA2RL
#Mooning
%patch $2F904 $0B801AA2RL %patch $2F922 $0B801AA2RL %patch $2F940 $0B801AA2RL
#Look up
%patch $2FA8A $0B801AA2RL %patch $2FAA8 $0B801AA2RL
#Look down
%patch $2FAC6 $0B801AA2RL %patch $2FAE4 $0B801AA2RL %patch $2FB02 $0B801AA2RL %patch $2FB20 $0B801AA2RL


Pogoing Keen

These patches relate to Keen using the pogo.


Keen cannot pogo before getting an item\winning a level

This patch stops Keen from pogoing until he has fulfilled a certain condition. The patch as given here limits Keen's pogoing until he wins level 4. The condition is highlighted in brown (See Patch:Game stats and Patch:Jump conditions.)

The values $FFD0W is the pogo speed, which controls the pogo bounce height; $0002W is the sound played when the pogo is deployed (It can also be $0007W.).

As a side effect the F10 B Cheat is disabled.

Patch: Keen cannot pogo before getting an item\winning a level
#Keen cannot pogo before getting an item\winning a level
#Disable F10-B and insert New Keen start pogo code
%patch $73B4 $E9 $0095W $55 $8B $EC $56 $8B $76 $06 $C7 $44 $18 $FFD0W $8B $44 $18 $BA $06 $00 $F7 $EA $A3 $21 $C9 $C7 $06 $BB $CA $0018W $B8 $0007W $50 $9A $187409F1RL $83 $C4 $02 $5E $5D $CB
#Change start_pogo behavior
%patch $2FF8C $06BD07E7RL
#No pogo while standing until level 4 is done
%patch $BB14 $83 $3E $7A26W $00 $74 $29 $C7 $06 $C3 $C5 $0001W $B8 $0002W $50 $9A $187409F1RL $83 $C4 $02 $C7 $44 $1C $110CW $C7 $44 $16 $0000W $C7 $44 $18 $FFD0W $5E $5D $CB
#No pogo while walking until level 4 is done
%patch $BF2D $83 $3E $7A26W $00 $74 $30 $C7 $06 $C3 $C5 $0001W $C7 $44 $1C $110CW $B8 $0002W $50 $9A $187409F1RL $83 $C4 $02 $8B $44 $0E $B1 $04 $D3 $E0 $89 $44 $16 $C7 $44 $18 $FFD0W $5E $8B $E5 $5D $CB
#No pogo in air until level 4 is done
%patch $C49B $22 $83 $3E $C3 $C5 $00 $75 $1B $83 $3E $7A26W $00 $74 $14 $C7 $06 $C3 $C5 $0001W $C7 $44 $1C $112AW $C7 $06 $BB $CA $0000W $5E $5D $CB


Disable shooting while pogoing

This patch stops Keen from shooting while pogoing. (See also Patch:Keen shooting (Galaxy).) Keen can still shoot while doing other things.

Patch: Disable shooting while pogoing
#Disable shooting while pogoing
%patch $C5DE $EB


Jumping Keen

These patches relate to Keen jumping.


Disable shooting while jumping

This patch stops Keen from shooting while jumping\falling. (See also Patch:Keen shooting (Galaxy).) Keen can still shoot while doing other things.

Patch: Disable shooting while jumping
#Disable shooting while jumping
%patch $C462 $EB


Jump physics

The variables that control the height and duration of Keen's jumps are spread over several behaviors. There are two important parameters: initial velocity, and duration. The velocity is the initial speed of the jump or pogo, while the duration is the maximum time that this initial velocity can be sustained before Keen feels gravity. That is, the initial velocity is how fast Keen jumps, while the duration is how long.

Since distance is speed * time, increasing either will increase Keen's jump height. However the most 'natural' looking way to increase Keen's jump height is to increase the duration, 'faster' jumps can look choppy. Also, the speed and duration only apply to the start of Keen's jump, when the time runs out, he will still be moving upwards, but will start slowing and then start falling.


Patch: Jumping Physics
#Jump from standstill
%patch $BAF0 $FFD8W
#Starting speed
%patch $BAFC $0012W
#Duration
#Pogo from standstill
%patch $BB33 $FFD0W
#Starting speed
%patch $BB3F $0018W
#Duration
#Jump from walking
%patch $BF0A $FFD8W
#Starting speed
%patch $BF18 $0012W
#Duration
#Pogo from walking
%patch $BF51 $FFD0W
#Starting speed
%patch $BF5D $0018W
#Duration
#Pogo bounce
%patch $C4D3 $FFD0W
#Starting speed
%patch $C4E4 $0018W
#Duration
#Pogo air
%patch $C50E $09
#Duration, after this gravity takes hold
#Jump from a pole
%patch $C6AB $FFECW
#Starting speed
%patch $C6B6 $000AW
#Duration
#Pogo Bounce
%patch $D830 $FFD0W
#Starting speed
%patch $D836 $0018W
#Duration


Details

The duration can be considered a 'timer' that counts down. When it reaches zero Keen will experience gravity. However, if the jump or pogo button is released, then Keen will start to feel gravity even if the timer has not expired. The timer is measured in tics (70 Hz), so a timer of 70 means that Keen can jump upwards for 1 second before feeling gravity. The initial velocity is in map units per tic, which is 256ths of a tile per 70th of a second.


Example problems

Q1.  If Keen is given an initial velocity of -18 ($FFEEW) and a max timer of 70 tics (1 second), what is the tile-height at his jump apex?
A1.  -18 (map units/tic) * 70 tics * 1 (tile/256 map units) = 4 tiles.
Q2.  We have given Keen an initial velocity of 8, and we want his jump apex to be 5 tiles high.  What will his maximum timer need to be set at?
A2.  8 (map units/tic) * 1 (tile / 256 map units) * X tics = 5 tiles  --> rearrange to solve for X --> X = 160 tics.

Note that these problems only consider the linear region of Keen's jump (i.e., when the jump button is depressed and velocity is constant upwards in the y-axis). After this linear region, Keen will still travel upwards as gravity begins to pull him down (i.e., he has reached the parabolic region of his jump). This extra distance is dependent only on velocity at the end of the linear region (i.e., the initial velocity that you patched), and not on the jump timer. Once Keen has reached the parabolic region, he will accelerate downwards at 2 map units / tic^2 (or 1.5 on easy mode).

Q3.  Reread Q1.  In consideration of the extra height that Keen will acquire due to the parabolic region of his jump, what is his TRUE tile-height at his jump apex?
A3.  At the end of the linear region, Keen had traveled 4 tiles and retained a velocity of -18 (map units / tic).  
    Use v^2 = u^2 + 2as to deduce maximum height, at which point v^2 = 0.
    0 = u^2 + 2as --> --> s = -u^2/2a 
    s = [- 324 (mu^2/tic^2) ] / [ 4 (mu/tic^2) ] = -81 mu = ~ -0.3 tiles.

So the calculated height is 4.3 tiles. In actuality, Keen jumps a little over 5 tiles, because the acceleration is not uniform per tic (it is actually applied twice after every second tic) and it is distorted a little bit at the apex. In addition, at the end of the linear region of the pogo, gravity is greatly decreased, and the duration of this decreased gravity effect can be altered. Even after considering the parabolic region, jump height will likely be a little bit higher than calculated, so you'll have to fine tune it by testing.


Keen can jump as high as he wants

This patch allows Keen to jump as if he has the F10 J cheat on all the time. The F10 J cheat will still work, but will not change anything. The second line allows Keen to hit ceilings and not fall. Removing this line makes Keen act like the jump cheat in keen Dreams.

Patch: Keen 5
#Keen has no max jump height
%patch $C3B2 $EB $0A %patch $D49D $EB $30
#And don't hit ceilings


Keen entering doors

Remove 'air-door' glitch

This patch stops Keen re-entering doors he has just emerged from. This stops a particular bug which allows Keen to exit some levels by pressing up as soon as he emerges from a door.

Patch: Keen 4
#Eliminate air-door entry glitch
%patch $2FD5E $0C02W


Sprite spawn code

There are two initiation codes, one for Keen facing left and one for Keen facing right. Both are nearly identical except for Keen's starting direction. Both use the same spawning code. The call $0D8F0003RL is used to mark the sprite as the player.

In the initiation code notice the Keen's cache being set ($C7 $06 $3D $CB $0001W.) Also notice that both initiation codes cache the scoreboard image ($00FDW) separately.

In the spawning code the last blue highlighted value is the sprite action the sprite uses as it proceeds to act in-level. $C7 $02 $xxxxW sets the clipping, $C7 $07 $xxxxW sets the sprite type, $C7 $20 $xxxxW sets the foreground value. Finally $D3 $E0 $05 $xxxx is how far down (Or more usually up) the sprite is spawned from where it is placed. This is necessary for sprites that walk on the ground as they can only be placed in the level at multiples of 16 pixels high while their actual height can be anything.

Keen's horizontal direction depends on his initiation code. (It is the first blue variable.) He always starts the level 'facing down' however, though this is of little importance. $C7 $47 $10 $xxxxW is the vertical direction the sprite starts moving in, either $0001W (Facing down), $FFFFW (Facing up) or $0000W (Neither, never used.) Keen's sprite type is important, if it is not $0002W then he will be invulnerable to enemy sprites since this sprite type is used to identify 'killable players'

Patch: Keen 4
#Location of initiation codes
%patch $EE85 $0064W
#Right Facing Keen (At $E954)
%patch $EE87 $0090W
#Left Facing Keen (At $E980)
#Right facing Keen Initiation code
%patch $E954 $B8 $0001W $50 $FF $76 $FC $57 $9A $0B80000ERL
#Keen's direction is +1
$83 $C4 $06 $9A $0D8F0003RL $C7 $06 $3D $CB $0001W $B8 $2A3ARW $8A $16 $EC $7A $8E $C0 $26 $08 $16 $00FDW $E9 $047DW
#Cache scoreboard too
#Left facing Keen Initiation code
%patch $E980 $B8 $FFFFW $50 $FF $76 $FC $57 $9A $0B80000ERL
#Keen's direction is -1
$83 $C4 $06 $9A $0D8F0003RL $C7 $06 $3D $CB $0001W $B8 $2A3ARW $8A $16 $EC $7A $8E $C0 $26 $08 $16 $00FDW $E9 $0451W
#Cache scoreboard too
#Normal Keen spawning code
%patch $B80E $55 $8B $EC $8B $1E $D6 $A7 $C7 $07 $0002W $C7 $47 $02 $0002W $C7 $47 $20 $0001W $8B $46 $06 $B1 $08 $D3 $E0 $89 $47 $0A $8B $46 $08 $D3 $E0 $05 $FF0FW $89 $47 $0C $8B $46 $0A $89 $47 $0E $C7 $47 $10 $0001W $B8 $098CW $50 $53 $9A $09DC118CRL $83 $C4 $04 $5D $CB


Keen's spawn height and changing Keen's height

This simple patch alters how high Keen spawns above where he is placed in a level. By default this is 16 pixels up,suitable for a Keen sprite 32 pixels high. If Keen's height is changed, this should be changed to reflect that. It is part of the above spawning code patch and shouldn't be used in conjunction with it.

Patch: Keen 4
#Keen's spawn height
%patch $B833 $FF0FW
#16 pixels up