Patch:Quantum Explosion Dynamo (Sprite)
The Quantum Explosion Dynamo proper is the final device encountered by Keen in Keen 5, and responsible for the Omegamatic's ability to destroy the galaxy. It consists of a large atom-like entity encased in a hard glass sphere held by two rods between two towers. Unlike the fuses in other parts of the Omegamatic, Keen cannot destroy the Q.E.D. by pogoing on it, or shooting it.
The Q.E.D.\Fuse counter is in fact an invisible sprite, the visible part is constructed entirely of tiles. It is sensitive only to the exploded Shikadi Mine's fragments. A related sprite is the Teleporter sprite. In 'fuse levels' the Q.E.D. does not spawn by default, simply modifying the game memory instead.
The Q.E.D. is thus only partly responsible in part for fuses; Q.E.D. sprites are placed in fuse levels, each one requiring a fuse to be broken before the level is won. As such fuses will also be mentioned on this page but the sprite will be called the 'Q.E.D.' for simplicity.
Sprite Type
The Q.E.D. uses sprite type 25 which is used only by the Q.E.D. It is the most important sprite type in the game; in order for the Shikadi Mine fragment to trigger the game being won, it's sprite must collide with a sprite having the Q.E.D. sprite type. Thus simply changing this makes the game unbeatable.
Keen 5
#Q.E.D.\Fuse. sprite type
%patch $139B2 $19
Sprite Actions
The Q.E.D. has only one action proper, but the fuse and Q.E.D. share six actions. The Q.E.D. is spawned using its own unique action and it remains using this action until destroyed.
When the Q.E.D. is hit by a Shikadi Mine fragment it spawns a 2x2 square of Q.E.D.\Fuse explosions also used by fuses. When Keen smashes a Fuse a single Fuse\Q.E.D. explosion sprite is spawned. The Q.E.D.\Fuse explosion plays for three frames before vanishing entirely.
On destroying the Q.E.D. a win level sprite is spawned. This does nothing but after a time causes the game to be won.
Actions: $1AE6W #QED and fuse explosion 1 $1B04W #QED and fuse explosion 2 $1B22W #QED and fuse explosion 3 $1B40W #Win level sprite $3186W #QED\Fuse counter
Keen 5
#When spawned
%patch $139FC [$3186W]
#What Q.E.D.\fuse does:
%patch $334E2 [$3186W]
#When Keen smashes Q.E.D.\a Fuse spawn this
%patch $FF7D [$1AE6W]
#Fuse\Q.E.D. explosion sequence
%patch $31E42 [$1B04W]
%patch $31E60 [$1B22W]
%patch $31E7E [$0000W]
#Win level sprite spawned
%patch $FFB4 [$1B40W]
#What win level sprite does
%patch $31E9C [$0000W]
Sprite Behavior
There is only one behavior used by the Q.E.D.\Fuses, it is run by the win level sprite and does one of two things, depending on level. If it is the Q.E.D. level then the game is won, otherwise a Fuse message is displayed.
Behaviors: $0F9206A2RL #Win level
Keen 5
#Q.E.D.
%patch $334D6 $00000000L #Nothing
#Q.E.D.\Fuse explosion
%patch $31E36 $00000000L #Nothing
%patch $31E54 $00000000L #Nothing
%patch $31E72 $00000000L #Nothing
#Win level sprite
%patch $31E90 $0F9206A2RL #Win level
Win level behavior
This is the complete code for the 'win level' behavior that is run whenever the 'win level' sprite is spawned. It is quite simple. On the first line it checks the level Keen is in; if that is the Q.E.D. level (Level $0C or 12) then the level state is set to $0F, or win the game. Otherwise it is set to $0E or 'display broken fuse message'
Keen 5
#Win level behavior code
%patch $FFC2 $55 $8B $EC $83 $3E {$9E55W} [$0C] {$75} $08 $C7 $06 {$6F70W} [$000FW]
$5D $CB $C7 $06 {$6F70W} [$000FW] $5D $CB
Speed
The Q.E.D., win level sprite and Q.E.D. explosion do not move. However for some odd reasons the Q.E.D.'s animation motion suggests that it should; it is unknown why this is so.
Animation motion
#Q.E.D.\Fuse explosion
%patch $31E32 [$0000W $0000W]
%patch $31E50 [$0000W $0000W]
%patch $31E6E [$0000W $0000W]
#Win level sprite
%patch $31E8C [$0000W $0000W]
#Q.E.D.
%patch $334D2 [$0080W $0000W]
Sprite Collision
The Q.E.D. has no collision at all, nor does its explosion. In order for the Shikadi Mine fragment to trigger the game being won, it's sprite must collide with a sprite having the Q.E.D.\Fuse sprite type.
Collision values
As noted the Q.E.D. has no collision. It has a value of 0 for all its actions.
Keen 5 collision values
#Q.E.D.
%patch $334DA $00000000L #Nothing
#Q.E.D.\Fuse explosion
%patch $31E3A $00000000L #Nothing
%patch $31E58 $00000000L #Nothing
%patch $31E76 $00000000L #Nothing
#Win level sprite
%patch $31E94 $00000000L #Nothing
Collision codes
Need to destroy multiple Q.E.D.s with health to win game
This patch gives the Q.E.D. a collision, meaning that a Mine Fragment does not need to hit it to win the game. Furthermore several Q.E.D.s need to be destroyed and each Q.E.D. requires multiple shots to destroy. (In this example Keen cannot shoot the Q.E.D. but a simple alteration changes that.)
The first part of this patch sets how many Q.E.D. must be destroyed to win the game. (This means that destroying a Fuse counts as destroying a Q.E.D. To avoid this use another variable.) The second part sets the 'health' of every Q.E.D. when it is spawned. In this patch 5 Q.E.D. (or Fuses) with health 2 need to be destroyed to win the game.
On the first line a check is made for the 'trigger sprite'; in this case sprite type 3 (Keen's shot); if this is found then the game proceeds to the next line.
On line 2 the colliding sprite is transformed into something else. (In this case the smashed Shockshund shot.) and its sprite type is changed to 0. The Q.E.D.'s health is depleted on line 3 and if it is 0 the game continues on to line 4, the Q.E.D. explosion code.
Lines 4 to 6 spawn four Q.E.D. explosions, each has a horizontal and vertical location marked in blue. On line 7 a 3x3 block of tiles in the foreground ($0001W, $0000W is background) is replaced with tile $0020W and the Q.E.D. is removed.
At the end of line 9 a check is made to see if the right number of Q.E.D.s have been destroyed. If so then the level is ended. (Specifically a special 'end level' sprite is spawned.)
After the collision there is a patch that makes the Q.E.D. use the new collision. The collision code overwrites an apparently useless and unused segment of code.
Keen 5
#Number of fuses\Q.E.D.s that need to be destroyed
%patch $F110 {$6F5EW} [$0005W]
#QED Spawn includes health
%patch $139B4 $C7 $47 $40 [$0002W]
#Q.E.D. collision
%patch $9E88 $55 $8B $EC $56 $8B $76 $08 $83 $3C [$04] {$74} $03 $5E $5D $CB $B8
[$2FE0W] $50 $56 $9A $090B1242RL $83 $C4 $04 $C7 $44 $00 [$0000W]
$8B $76 $06 $FF $4C $40 {$74} $03 $5E $5D $CB $FF $74 [$2E] $FF
$74 [$2C] $9A $0F920628RL $83 $C4 $04 $FF $74 [$2E] $FF $74 [$30]
$9A $0F920628RL $83 $C4 $04 $FF $74 [$32] $FF $74 [$2C] $9A $0F920628RL
$83 $C4 $04 $FF $74 [$32] $FF $74 [$30] $9A $0F920628RL
$83 $C4 $04 $68 [$0003W] $68 [$0003W] $FF $74 $2E $FF $74 $2C
$68 [$0001W] $FF $36 $9E51W $68 [$0020W] $9A $174E0F25RL $83
$C4 $0E $56 $9A $06B91E47RL $44 $44 $FF $0E {$6F5EW $74} $03
$5E $5D $CB $9A $0F920677RL $5E $5D $CB
#New QED action uses collision
%patch $334C6 $FFFFW $FFFFW $0000W $0000W $0001W $0008W $0080W $0000W
$00000000L $090B0DD8RL $00000000L $3186W
Animations
While the Q.E.D. and win level sprite are invisible (using a value of -1 for its animations), it and the Fuse's explosion require animations. There is therefore a cache. As a side note, the Q.E.D. 'animates' though it has no need to. (See sprite speed section above.) Note also that the win level sprite's animation speed does not appear to control when the level will be won.
Keen 5
#Cache
%patch $31A52 [$011BW] #Q.E.D.\Fuse cache start
%patch $31AA6 [$011DW] #Cache end
#Q.E.D.\Fuse explosion
%patch $31E26 $011BW $011BW
%patch $31E30 $000AW #Animation speed
%patch $31E44 $011CW $011CW
%patch $31E4E $0014W #Animation speed
%patch $31E62 $011DW $011DW
%patch $31E6C $000AW #Animation speed
#Win level sprite
%patch $31E80 $FFFFW $FFFFW #Invisible
%patch $31E8A $003CW #Pause before winning level?
#Q.E.D.
%patch $334C6 $FFFFW $FFFFW #Invisible
%patch $334D0 $0008W #Animation speed
Sounds
The Q.E.D. makes a sound when it is destroyed. This is the same sound made when a Fuse is destroyed, so altering it will affect fuses as well.
Keen 5
#Q.E.D.\Fuse smashed sound
%patch $FF8A $34
#Don't play Q.E.D.\Fuse smashed sound
%patch $FF89 $EB $0A
Sprite positioning
The Q.E.D. spawns one pixel up and one pixel left of where it is placed. This is unnecessary and it is not known why it is done.
Keen 5
#Spawn height
%patch $139D4 $FFF0W #1 pixel up
%patch $139E1 $FFF0W #1 pixel left
Sprite-tile interaction
The Q.E.D. has no tile interaction of any kind, it ignores tiles completely. (This also means it cannot have any animation unless given a collision.) The Q.E.D.\Fuse explosions use a generic 'draw this sprite' interaction that simply ensures they appear onscreen.
Keen 5
#Q.E.D.\Fuse explosion
%patch $31E3E $090B17B5RL
%patch $31E5C $090B17B5RL
%patch $31E7A $090B17B5RL
#Win level sprite
%patch $31E98 $090B17B5RL
#Q.E.D.
%patch $334DE $00000000L
Action type
All actions relating to the Q.E.D. and Fuse are type 0, since they do not move and simply sit in one place. However the Q.E.D. has an animation speed, something that suggests it should be able to move about. (See sprite speed section above.)
Keen 5
#Q.E.D./Fuse explosion
%patch $31E2A [$0000W]
%patch $31E48 [$0000W]
%patch $31E66 [$0000W]
#Win level sprite
%patch $31E84 [$0000W]
#Q.E.D.
%patch $334CA [$0000W]
Deprotect and stick to ground
The Q.E.D. and Fuse explosions do not use either of these two variables. However the Q.E.D. uses 'stick to ground'; something that suggests it should be able to move about. (See sprite speed section above.)
Keen 5
#Q.E.D. explosion
%patch $31DF0 [$0000W $0000W]
%patch $31E0E [$0000W $0000W]
#Q.E.D.\Fuse explosion
%patch $31E2C [$0000W $0000W]
%patch $31E4A [$0000W $0000W]
%patch $31E68 [$0000W $0000W]
#Win level sprite
%patch $31E86 [$0000W $0000W]
#Q.E.D.
%patch $334CC [$0000W $0001W]
Sprite spawn code
There is only one type of Q.E.D.\Fuse appearing on all difficulties. On the first line of the initiation code the level is checked. If it is level 12 then the Q.E.D. is spawned and an unknown variable is set to 4. If the level is not 12 then this is skipped. (Sprites placed in non-Q.E.D. levels will not spawn at all.) In both cases however the Fuse explosion cache is set in $C7 $06 $C2A5W $0001W.
Replacing $0C $75 with $90 $90 will cause the Q.E.D. sprite to spawn in all levels like a regular sprite does.
The last blue highlighted value is the sprite action the sprite uses as it proceeds to act in-level. $C7 $47 $02 $xxxxW sets the sprite activity, $C7 $07 $xxxxW sets the sprite type, 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, but accomplishes nothing for the Q.E.D. The Q.E.D. also spawns one pixel left of where it is placed. (The second $FFF0W value.)
Keen 5
#Location of initiation code
%patch $F516 [$3B7W] #QED\Fuse (At $F107)
#Q.E.D.\Fuse Initiation code
%patch $F107 $83 $3E [$6F68W] {$0C $75} $12 $C7 $06 {$6F5EW} [$0004W] $57 $56 $9A
{$11C41D56RL} $83 $C4 $04 $EB $04 $FF $06 $5E $6F $C7 $06 $C2A5W
$0001W $E9 $027AW
#Q.E.D. spawn code
%patch $13996 $55 $8B $EC $56 $57 $8B $76 $06 $8B $7E $08 $33 $C0 $50 $9A $06B91DCDRL
$83 $C4 $02 $8B $1E $40 $9E $C7 $07 [$0019W] $C7 $47
$02 [$0001W] $89 $77 $2C $89 $7F $2E $8B $47 $2C $40 $89 $47 $30
$8B $47 $2E $40 $89 $47 $32 $8B $C6 $B1 $08 $D3 $E0 $05 [$FFF0W]
$89 $47 $22 $89 $47 $0A $8B $C7 $D3 $E0 $05 [$FFF0W] $89 $47 $24
$89 $47 $0C $8B $47 $22 $05 $20 $02 $89 $47 $26 $8B $47 $24 $05
$20 $02 $89 $47 $28 $B8 [$3186W] $50 $53 $9A $090B11C4RL $83
$C4 $04 $5F $5E $5D $CB
End level sprite spawn code
What actually ends the game is a special 'end level' sprite which is spawned when Keen destroys the Q.E.D. The code required to call this spawning is simply $9A $0F920677RL. Unlike other spawn codes this does not have any sort of initiation code or caching, it is pure spawning code and quite simple code at that.
The highlighted blue variables set the following properties. First the sprite's activity (Se tto 2, or 'always active'; this means Keen cannot 'escape' winning the level by going offscreen.), secondly the sprite's clipping (Set to 0 so it ignores tiles and doesn't move.) and finally the sprite's action. This controls everything else about it, including its using the behavior that ends the level and wins the game.
Keen 5
#End Level sprite spawn code
%patch $FF97 $55 $8B $EC $33 $C0 $50 $9A $06B91DCDRL $83 $C4 $02 $8B $1E
$40 $9E $C7 $47 $02 [$0002W] $C7 $47 $06 [$0000W] $B8 [$1B40W] $50
$53 $9A $090B11C4RL $83 $C4 $04 $5D $CB
Misc
These patches do not fit into any of the above sections.
Q.E.D. wins game when touched, doesn't explode
This patch gives the Q.E.D. a new collision that makes it respond to Keen by winning the game. As a side effect it will not (and cannot) explode. This works by overwriting some of the Shikadi Mine's collision that normally responds to the Q.E.D. Keen's type is the value in blue; $03 will make the Q.E.D. win the game when shot.
Keen 5
#Q.E.D wins game when touched, doesn't explode
%patch $334DA $11C4047BRL
%patch $120BB $55 $8B $EC $56 $8B $76 $08 $83 $3C [$02] $74 $03 $5E $5D $CB
$9A $0F920677RL $5E $5D $CB
Q.E.D.\Fuse sprite brings up 4 messages to Keen when touched in different levels
This patch uses concepts from this page but is found on the Fuse window page as it mainly deals with modifying the fuse windows.