This page deals with the text windows in Keen. These are a subset of Patch:Text patches, involving windows that appear in-game (Usually in-level) with text (and in Galaxy, images) in them.
In essence the execution is quite simple. Some event (flag) will trigger the window. The window will appear (In Keen Galaxy\Dreams instantly, in Vorticons via a step-by-step expansion as the window rapidly grows to full size and displays text.) with text in it. The player can often exit the window by pressing a key (or by waiting a set period of time.) at which point the window will vanish and other events may occur.
There is some difference between Keen Vorticons and Keen Galaxy\Dreams windows due to the different engines being used.
In Keen the window is made up of 8x8 unmasked tiles. Keen Vorticons is rather unique in also storing its font in this manner, making the entire window a grid of 8x8 squares. The windows use 8 tiles from the tileset (Four corners, four sides, which tiles can be patched, though there is little point to this.)
The main attribute of a window is its size\location. (The two are interchangeable to some extent.) There are in general two ways to patch this. The first defines the location of all four corners of a window. As this is complicated, it is not often used. (For example in the Keen Vorticons ending sequences, where windows of different sizes in different locations are needed.) For these there will be four patches such as follows:
|Patch: Keen 1 Map ending textbox|
%patch $821E $0F $00
The second method is to simply specify the window's height and width, the window will be 'centered' somewhere on the screen (usually the center, but not always.)
|Patch: Keen 1 Yorp messages textbox|
%patch $2508 $0A $00
In both these cases the screen is divided into 8x8 blocks, with the top left of the screen being 2,2.
Most windows will contain text, rather similar in format to Patch:Text patches. All windows will need to call their text from the text segment in the executable, as detailed on that page. Text that is too large for the window to contain will write right through the window (Vorticons) or give a 'string exceeds width' error (Galaxy)
Vorticons text is 8x8 tiles, meaning it is easy to calculate what will fit in a window. Galaxy and Dreams use a standard monochrome font where each letter has a differing width, which makes this more difficult.
There are some text characters that cannot be patched as characters, but must be patched as hex values. These are double quotation marks ($22), end of line ($0A) and end of text ($00) as well as any characters that will be altered by the program being used to edit the patchfile.
Bitmaps, music and sound
The biggest difference is that Galaxy Windows (And only Galaxy windows, not Dreams.) can display bitmap images and play sounds, as well as switch music. Because of memory constraints, these are not cached when the level is loaded, taking up valuable memory space. These are instead loaded when the window is opened, meaning if there is not enough free memory, the game can crash. Also, because of how the windows operate, bitmaps for a windows sequence must be cached before the first window is opened. An example is from Keen 6's Grabbiter window:
|Patch: Keen 6 Grabbiter window|
%patch $F54E $23 $00
The bitmap is cached before the first window is opened and can be displayed in any further windows. The bitmap's value is also interesting, the game refers to graphics by chunk number, while modkeen exports differently, meaning a patcher must add a certain value to the bitmap they want to use to get the chunk number the game uses. For Keen 6 this is, oddly enough, +6.
Differences between Galaxy and Vorticons windows
- Vorticons windows use 8x8 tiles for letters and can display 'images' in the window in this manner, Galaxy\Dreams use a monochrome font where letters have differing widths and are drawn over the window
- Galaxy windows can play music, sounds and display images
- Galaxy windows are always centered, almost always on the center of the screen
- It is impossible to have text longer than the window in Galaxy without crashing the game
- Galaxy windows use only one line of text per window. If the text changes a new window must be opened
Example window code
This section shows an example of text window code; a patch that contains the complete code to draw a window in various games.
Keen 4: can't swim window
This is the complete 'can't swim' window code. This window is displayed on the map when Keen tries to enter water-type tiles and doesn't have the Wetsuit. It is a standalone window containing a single bitmap image and a message.
On the first line chunk 111 is cached for display. On the second line the window's height and width are set. On the third line chunk 111 is displayed in the window. The fourth line contains the 'image width variable' used to position the text in the window along with the image.
The text itself is called at the end of line 5. At the start of line 7 is a pause where the window can't be dismissed. (Vital to stop the player accidentally skipping it.)
|Patch: Complete Can't swim window code|
Keen 5: simple fuse window
This is a simplified version of the Fuse window. This window is displayed when Keen breaks a fuse in levels It is a standalone window containing a single bitmap image and a message. It has been simplified from the original window that displayed one of two messages and two bitmaps, requiring two keypresses to dismiss.
On the second line chunk 90 is cached for display. On the third and fourth lines the window's height and width are set. On the fifth line chunk 90 is displayed in the window.
The text itself is called at the end of line 6. At the start of line 7 is a pause where the window can't be dismissed. (Vital to stop the player accidentally skipping it.)
|Patch: Simplified Fuse window code|
Keen 6: Rocket Passcard Obtained window
This is the complete window code for the window that appears when the Rocket Passcard is obtained. The first line plays sound $2D, the second line caches Keen's head bitmap ($0023W) which is then displayed on line 4. Notice that bitmaps are referred to by their 'chunk number', that is, what graphic chunk they are in EGAGRAPH.CK6; this is the bitmap number (When exported via ModKeen, Keengraph numbers the bitmaps 'correctly') plus six. The window's size is set on line 3 as being $08x$1A
The image is aligned right by $0030W pixels. By default this is the same as the image's width so that the displayed bitmap is 'right aligned'. Paired with this is a second, equal variable that moves the text in the opposite direction so that it is not centered in the window (and thus overwriting the bitmap.) These variables can be 'reversed' by making them negative. (Changing $0030W to $FFD0W and $30 to $D0 for example.)
Finally the text call on line 6 which determines where the window's text is called from. (See Patch:Text patches.) The value $001EW is the 'pause' before the player can dismiss the window by pressing a key. Finally after the window has been displayed the rocket passcard variable is set to 1 on the last line. (The card is given.)
|Patch: Keen 6|