Does Keen 2 have customizable variables?

Anything related to Keen Modding.
Post Reply
User avatar
proYorp
Posts: 5
Joined: Sun Oct 21, 2018 12:31 am

Does Keen 2 have customizable variables?

Post by proYorp »

I am a novice at programming. I know some of the theory but haven't succeeded in using it for much. I know that in some languages like JavaScript, there are different types of variables that can only hold certain types of data, for instance boolean, string, integer, and float. Does assembly have this limitation? Specifically, assembly resulting from compiled C/C++ as from how Keen was created?

Keen 2 has eight variables used to determine the status of winning the game, one for each machine level. As far as I understand, they are used as true/false boolean variables: value of 0 if false, value of 1 if true.

So can these variables be used to hold values other than true/false? What is their maximum value? 255? 65535?

If it's possible, then there are eight separate variables that can be patched to keep track of all kinds of things. It would require quite a bit of restructuring the functions that are called in the engine, but more complicated things have been done I think. Maybe just one of the city variables can be patched to simply add +1 to its value every time an important level is won, so it can still be used to trigger the victory sequence once it reaches a certain value, and the rest can be used for other things.

Imagine if this was possible. These variables could be used for anything at all: different states of the worldmap, disappearing walls in the levels, modes of behaviour in enemies, anything that needs an external value to keep track of. Even if the maxium value is 255 that's still so many individual numbers that could be used as a flag for a specific state.

Even if the limit on these variables is 1 and 0, there are still 8 variables that could be used to flag things... is it easily possible to patch Keen 2 to win the game just by detecting the amount of levels won?
User avatar
Fleexy
Site Admin
Posts: 490
Joined: Fri Dec 12, 2008 1:33 am
Location: Bloogton Tower

Re: Does Keen 2 have customizable variables?

Post by Fleexy »

At the assembly/machine code level, there are only memory locations holding numbers. Variable "type" only depends on how the numbers are used. Even which locations are distinct "variables" is determined by usage and can be changed with sufficient effort.

It looks like each machine's state is managed by instructions that operate on two bytes (a word) at once. Even though Keen 2 always sets those words to either 0 or 1, a word is sufficient to store 2^16 distinct values, often used to represent the numbers 0 to 65535 or -32768 to 32767. Someone who is better at patching than me could very likely use one of those words (or even just one byte) for a counter as you suggested, then update the win condition with the new interpretation of that space.

One limitation is that these are global variables, not per-tile or per-sprite storage. Perhaps a more clever patcher than me might be able to scavenge space elsewhere for sophisticated behaviors.
Post Reply