Patch:Executable segments

From KeenWiki
Jump to navigation Jump to search

This is a page about executable segments. It mainly applies to the Galaxy and Dreams games. A related page giving the locations of various pieces of code is Patch:Executable Maps.

Keen executables are divided into a number of segments or sections. For Keen Vorticons this is quite simple, there is a code segment, a second segment containing the tile refresh code and a text segment. (See Patch:Text patches) Galaxy executables are more complex, divided into nearly a hundred segments each.

Like with text patches, pointers to data in a segment treat the start of the segment as 0. However, unlike text patches, the segment itself must be specified. A pointer to data in a segment is thus four bytes long. A typical pointer looks like so:


$11CF05B7RL or $05B7W $11CFRW


The pointer here points to the location $11CF0 + $05B7 = $122A7. This is similar to a postal address, instead of simply saying 'go to the xth house' it may say 'go to the xth house in this city, which is part of this country...' When patching the 'R' is important, it works only with the newest version of CKPatch and means 'relative'; the values in dumped executables are different every time, and the values that are to be used in patches must be taken from the unpatched executable code. As such they too must be altered every time CKPatch is run and the 'RW' or 'RL' tells CKPatch to do this.

In patching such pointers are used with Patch:Sprite behavior, Patch:Sprite collision and Patch:Sprite tile check, as well as in other situations.


Making a custom far call using executable segments

The greatest use of this page will be when making a 'call' to new code using executable segments. As an example, consider new collision code at $7A42 in Keen 4; how is this called? The first step is to check the section below for the last executable segment before the code.

Searching Keen 4's list the segment at $6BD0 occurs before $7A42. (The next segment is $915A.) If the segment doesn't end in 0, round down. (Thus $915A becomes $9150. This is because of how segments work.) The next step is to remove this value from our code location, in this case $7A42 - $6BD0 = $E72. This is the 'offset'. We now have the two components needed for our call.

The call is made by slightly rearranging the two values, segment and offset. Both of these will become two byte values that are stuck together. First divide the segment by $10, so $6BD0 becomes $06BD (This is why we rounded down in the previous paragraph.) Next place the offset after it and add the special 'RL'. Thus $06BD and $0E72 become $06BD0E72RL

This can work in reverse too, to find the code a call references, and it is somewhat easier. $06BD0E72RL is just $6BD0 + $0E72 = $7A42


Segments in Keen games

The following is a list of the segments in the Keen games that are currently known; Keen Galaxy segments are 100% complete, other games are less so.

Keen 3: (INCOMPLETE!)
Start  Stop   Length Name               Class
00000H 12ABFH 12AC0H seg000             CODE
12AC0H 13A6FH 00FB0H seg001             DOS exit screen
13A70H 179CFH 03F60H seg002             SOUNDS.CK3
179D0H 1819FH 007D0H seg003             HELPTEXT.CK3
181A0H 184DFH 00340H seg004             ENDTEXT.CK3
184E0H 18BCFH 006F0H seg005             PREVIEWS.CK3
18BD0H 1981FH 00C50H seg006             STORYTEXT.CK3
19820H 1D46FH 03C50H dseg               DATA
1D470H 1F07FH 01C10H seg008             STACK
Keen 4:
Start  Stop   Length Name               Class
00000H 037DBH 037DCH seg000             CODE
037DCH 03EDAH 006FFH seg001             CODE
03EDBH 05C45H 01D6BH seg002             CODE
05C46H 06BCFH 00F8AH seg003             CODE
06BD0H 09159H 0258AH seg004             CODE
0915AH 09DC4H 00C6BH seg005             CODE
09DC5H 0B7FFH 01A3BH seg006             CODE
0B800H 0D8F2H 020F3H seg007             CODE
0D8F3H 0E8F2H 01000H seg008             CODE
0E8F3H 0FA7FH 0118DH seg009             CODE; sprite spawning
0FA80H 10805H 00D86H seg010             CODE; sprite behavior
10806H 11A2DH 01228H seg011             CODE; sprite behavior
11A2EH 12A6EH 01041H seg012             CODE; sprite behavior
12A6FH 1460AH 01B9CH seg013             CODE
1460BH 155E0H 00FD6H seg014             CODE
155E1H 1654EH 00F6EH seg015             CODE
1654FH 18269H 01D1BH seg016             CODE
1826AH 1874DH 004E4H seg017             CODE
1874EH 1931DH 00BD0H seg018             CODE
1931EH 1A892H 01575H seg019             CODE
1A893H 1D01FH 0278DH seg020             CODE
1D020H 1D064H 00045H seg021             CODE
1D065H 1E09FH 0103BH seg022             CODE
1E0A0H 1ED2FH 00C90H seg023             CODE
1ED30H 1EE3FH 00110H seg024             UNK
1EE40H 1F03FH 00200H seg025             'Star wars' story
1F040H 1F04FH 00010H seg026             Level 0 name
1F050H 1F05FH 00010H seg027             Level 1 name
1F060H 1F06FH 00010H seg028             Level 2 name
1F070H 1F08FH 00020H seg029             Level 3 name
1F090H 1F0AFH 00020H seg030             Level 4 name
1F0B0H 1F0BFH 00010H seg031             Level 5 name
1F0C0H 1F0CFH 00010H seg032             Level 6 name
1F0D0H 1F0DFH 00010H seg033             Level 7 name
1F0E0H 1F0EFH 00010H seg034             Level 8 name
1F0F0H 1F0FFH 00010H seg035             Level 9 name
1F100H 1F10FH 00010H seg036             Level 10 name
1F110H 1F12FH 00020H seg037             Level 11 name
1F130H 1F14FH 00020H seg038             Level 12 name
1F150H 1F17FH 00030H seg039             Level 13 name
1F180H 1F19FH 00020H seg040             Level 14 name
1F1A0H 1F1AFH 00010H seg041             Level 15 name
1F1B0H 1F1BFH 00010H seg042             Level 16 name
1F1C0H 1F1CFH 00010H seg043             Level 17 name
1F1D0H 1F1EFH 00020H seg044             Level 18 name
1F1F0H 1F20FH 00020H seg045             Level 0 entry text
1F210H 1F23FH 00030H seg046             Level 1 entry text
1F240H 1F25FH 00020H seg047             Level 2 entry text
1F260H 1F28FH 00030H seg048             Level 3 entry text
1F290H 1F2CFH 00040H seg049             Level 4 entry text
1F2D0H 1F2FFH 00030H seg050             Level 5 entry text
1F300H 1F32FH 00030H seg051             Level 6 entry text
1F330H 1F34FH 00020H seg052             Level 7 entry text
1F350H 1F37FH 00030H seg053             Level 8 entry text
1F380H 1F39FH 00020H seg054             Level 9 entry text
1F3A0H 1F3CFH 00030H seg055             Level 10 entry text
1F3D0H 1F3FFH 00030H seg056             Level 11 entry text
1F400H 1F42FH 00030H seg057             Level 12 entry text
1F430H 1F46FH 00040H seg058             Level 13 entry text
1F470H 1F4AFH 00040H seg059             Level 14 entry text
1F4B0H 1F4DFH 00030H seg060             Level 15 entry text
1F4E0H 1F50FH 00030H seg061             Level 16 entry text
1F510H 1F53FH 00030H seg062             Level 17 entry text
1F540H 1F57FH 00040H seg063             Level 18 entry text
1F580H 1F5DFH 00060H seg064             1st Oracle janitor text
1F5E0H 1F62FH 00050H seg065             2nd Oracle janitor text
1F630H 1F64FH 00020H seg066             3rd Oracle janitor text
1F650H 1F67FH 00030H seg067             4th Oracle janitor text
1F680H 1F6FFH 00080H seg068             Lowercase keypress definitions
1F700H 1F77FH 00080H seg069             Uppercase keypress definitions
1F780H 1F7FFH 00080H seg070             Unknown  keypress definitions
1F800H 1F82FH 00030H seg071             Uppercase keypress definitions 2
1F830H 1F86FH 00040H seg072             Debug menu actions
1F870H 1F8DFH 00070H seg073             Sound effects menu actions
1F8E0H 1F92FH 00050H seg074             Music menu actions
1F930H 1F98FH 00060H seg075             New game menu actions
1F990H 1FA9FH 00110H seg076             Load\save menu actions
1FAA0H 1FB0FH 00070H seg077             Options menu actions
1FB10H 1FBCFH 000C0H seg078             Movement setup menu actions
1FBD0H 1FC2FH 00060H seg079             Button setup menu actions
1FC30H 1FCBFH 00090H seg080             Keyboard\Joystick\Gravis menus actions
1FCC0H 1FD7FH 000C0H seg081             Configure menu actions
1FD80H 1FE3FH 000C0H seg082             Main menu actions
1FE40H 20DEFH 00FB0H seg083             DOS exit screen
20DF0H 2107FH 00290H seg084             Audiohead
21080H 2482FH 037B0H seg085             EGAhead
24830H 2A39FH 05B70H seg086             Maphead and tile properties
2A3A0H 2B62FH 01290H seg087             UNK
2B630H 2EE6FH 03840H seg088             UNK
2EE70H 3D6BFH 0E850H dseg               DATA
3D6C0H 3D73FH 00080H seg090             STACK
Keen 5:
Start  Stop   Length Name               Class
00000H 037DBH 037DCH seg000             CODE
037DCH 03ED4H 006F9H seg001             CODE
03ED5H 05C19H 01D45H seg002             CODE
05C1AH 06B8FH 00F76H seg003             CODE
06B90H 090BEH 0252FH seg004             CODE
090BFH 0AAEFH 01A31H seg005             CODE
0AAF0H 0CCB6H 021C7H seg006             CODE
0CCB7H 0E0C1H 0140BH seg007             CODE
0E0C2H 0ED5CH 00C9BH seg008             CODE
0ED5DH 0F922H 00BC6H seg009             CODE
0F923H 11023H 01701H seg010             CODE
11024H 11C40H 00C1DH seg011             CODE
11C41H 13A0BH 01DCBH seg012             CODE
13A0CH 155A7H 01B9CH seg013             CODE
155A8H 1657DH 00FD6H seg014             CODE
1657EH 174E0H 00F63H seg015             CODE
174E1H 19206H 01D26H seg016             CODE
19207H 196EBH 004E5H seg017             CODE
196ECH 1A2BBH 00BD0H seg018             CODE
1A2BCH 1B832H 01577H seg019             CODE
1B833H 1DFBBH 02789H seg020             CODE
1DFBCH 1E000H 00045H seg021             CODE
1E001H 1F03BH 0103BH seg022             CODE
1F03CH 1FCCFH 00C94H seg023             CODE
1FCD0H 1FDDFH 00110H seg024             CODE
1FDE0H 2003FH 00260H seg025             'Star wars' story
20040H 2050FH 004D0H seg026             Level names and entry texts
20510H 2058FH 00080H seg027             Lowercase keypress definitions
20590H 2060FH 00080H seg028             Uppercase keypress definitions
20610H 2068FH 00080H seg029             Unknown  keypress definitions
20690H 206BFH 00030H seg030             Uppercase keypress definitions 2
206C0H 206FFH 00040H seg031             Debug menu actions
20700H 2076FH 00070H seg032             Sound effects menu actions
20770H 207BFH 00050H seg033             Music menu actions
207C0H 2081FH 00060H seg034             New game menu actions
20820H 2092FH 00110H seg035             Load\save menu actions
20930H 2099FH 00070H seg036             Options menu actions
209A0H 20A5FH 000C0H seg037             Movement setup menu actions
20A60H 20ABFH 00060H seg038             Button setup menu actions
20AC0H 20B4FH 00090H seg039             Keyboard\Joystick\Gravis menus actions
20B50H 20C0FH 000C0H seg040             Configure menu actions
20C10H 20CCFH 000C0H seg041             Main menu actions
20CD0H 21C7FH 00FB0H seg042             DOS exit screen
21C80H 21FBFH 00340H seg043             Audiohead
21FC0H 2598FH 039D0H seg044             Egahead
25990H 2B7AFH 05E20H seg045             Maphead and tile properties
2B7B0H 2CAFFH 01350H seg046             UNK
2CB00H 3033FH 03840H seg047             UNK
30340H 3E2EFH 0DFB0H dseg               DATA
3E2F0H 3E36FH 00080H seg049             STACK
Keen 6:
Start  Stop   Length Name               Class
00000H 037BCH 037BDH seg000             CODE
037BDH 03D03H 00547H seg001             CODE
03D04H 05A19H 01D16H seg002             CODE
05A1AH 069A9H 00F90H seg003             CODE
069AAH 08F41H 02598H seg004             CODE
08F42H 0AA23H 01AE2H seg005             CODE
0AA24H 0CA69H 02046H seg006             CODE
0CA6AH 0DBE1H 01178H seg007             CODE
0DBE2H 0E429H 00848H seg008             CODE
0E42AH 0EFC5H 00B9CH seg009             CODE
0EFC6H 10CC4H 01CFFH seg010             CODE
10CC5H 11CFEH 0103AH seg011             CODE
11CFFH 1259FH 008A1H seg012             CODE
125A0H 1413BH 01B9CH seg013             CODE
1413CH 15111H 00FD6H seg014             CODE
15112H 1607FH 00F6EH seg015             CODE
16080H 17ED8H 01E59H seg016             CODE
17ED9H 183BDH 004E5H seg017             CODE
183BEH 18F8DH 00BD0H seg018             CODE
18F8EH 1A504H 01577H seg019             CODE
1A505H 1CF38H 02A34H seg020             CODE
1CF39H 1CF7EH 00046H seg021             CODE
1CF7FH 1DFB9H 0103BH seg022             CODE
1DFBAH 1EC3FH 00C86H seg023             CODE
1EC40H 1ED4FH 00110H seg024             UNK
1ED50H 1EF3FH 001F0H seg025             'Star wars' story
1EF40H 1EF4FH 00010H seg026             Level 0 name
1EF50H 1EF6FH 00020H seg027             Level 1 name
1EF70H 1EF7FH 00010H seg028             Level 2 name
1EF80H 1EF9FH 00020H seg029             Level 3 name
1EFA0H 1EFBFH 00020H seg030             Level 4 name
1EFC0H 1EFCFH 00010H seg031             Level 5 name
1EFD0H 1EFEFH 00020H seg032             Level 6 name
1EFF0H 1EFFFH 00010H seg033             Level 7 name
1F000H 1F01FH 00020H seg034             Level 8 name
1F020H 1F02FH 00010H seg035             Level 9 name
1F030H 1F03FH 00010H seg036             Level 10 name
1F040H 1F04FH 00010H seg037             Level 11 name
1F050H 1F06FH 00020H seg038             Level 12 name
1F070H 1F08FH 00020H seg039             Level 13 name
1F090H 1F0AFH 00020H seg040             Level 14 name
1F0B0H 1F0CFH 00020H seg041             Level 15 name
1F0D0H 1F0DFH 00010H seg042             Level 16 name
1F0E0H 1F0FFH 00020H seg043             Level 17 name
1F100H 1F10FH 00010H seg044             Level 18 name
1F110H 1F12FH 00020H seg045             Level 0 entry text
1F130H 1F15FH 00030H seg046             Level 1 entry text
1F160H 1F18FH 00030H seg047             Level 2 entry text
1F190H 1F1BFH 00030H seg048             Level 3 entry text
1F1C0H 1F1EFH 00030H seg049             Level 4 entry text
1F1F0H 1F21FH 00030H seg050             Level 5 entry text
1F220H 1F24FH 00030H seg051             Level 6 entry text
1F250H 1F26FH 00020H seg052             Level 7 entry text
1F270H 1F29FH 00030H seg053             Level 8 entry text
1F2A0H 1F2CFH 00030H seg054             Level 9 entry text
1F2D0H 1F2FFH 00030H seg055             Level 10 entry text
1F300H 1F34FH 00050H seg056             Level 11 entry text
1F350H 1F37FH 00030H seg057             Level 12 entry text
1F380H 1F3BFH 00040H seg058             Level 13 entry text
1F3C0H 1F3FFH 00040H seg059             Level 14 entry text
1F400H 1F43FH 00040H seg060             Level 15 entry text
1F440H 1F46FH 00030H seg061             Level 16 entry text
1F470H 1F49FH 00030H seg062             BWB entry text
1F4A0H 1F4CFH 00030H seg063             High scores entry text
1F4D0H 1F54FH 00080H seg064             Lowercase keypress definitions
1F550H 1F5CFH 00080H seg065             Uppercase keypress definitions
1F5D0H 1F64FH 00080H seg066             Unknown  keypress definitions
1F650H 1F67FH 00030H seg067             Uppercase keypress definitions 2
1F680H 1F68FH 00010H seg068             UNK
1F690H 1F6CFH 00040H seg069             Debug menu actions
1F6D0H 1F73FH 00070H seg070             Sound effects menu actions
1F740H 1F78FH 00050H seg071             Music menu actions
1F790H 1F7EFH 00060H seg072             New game menu actions
1F7F0H 1F8FFH 00110H seg073             Load\save menu actions
1F900H 1F96FH 00070H seg074             Options menu actions
1F970H 1FA2FH 000C0H seg075             Movement setup menu actions
1FA30H 1FA8FH 00060H seg076             Button setup menu actions
1FA90H 1FB1FH 00090H seg077             Keyboard\Joystick\Gravis menus actions
1FB20H 1FBDFH 000C0H seg078             Configure menu actions
1FBE0H 1FC9FH 000C0H seg079             Main menu actions
1FCA0H 20C4FH 00FB0H seg080             DOS exit screen
20C50H 20F4FH 00300H seg081             Audiohead
20F50H 2507FH 04130H seg082             Egahead
25080H 2BF2FH 06EB0H seg083             Maphead and tile properties
2BF30H 2D4EFH 015C0H seg084             UNK
2D4F0H 30D2FH 03840H seg085             UNK
30D30H 3F8CFH 0EBA0H dseg               DATA
3F8D0H 3F94FH 00080H seg087             STACK
Keen Dreams: (UNCONFIRMED!)
Start  Stop   Length Name               Class
00000H ?????H ?????H ??????             CODE
037B0H ?????H ?????H ??????             CODE
03C00H ?????H ?????H ??????             CODE
044D0H ?????H ?????H ??????             CODE
059A0H ?????H ?????H ??????             CODE
05E80H ?????H ?????H ??????             CODE
07C50H ?????H ?????H ??????             CODE
08680H ?????H ?????H ??????             CODE
09590H ?????H ?????H ??????             CODE
098D0H ?????H ?????H ??????             CODE
09A10H ?????H ?????H ??????             CODE
0A7D0H ?????H ?????H ??????             CODE
0B2D0H ?????H ?????H ??????             CODE
0CA50H ?????H ?????H ??????             CODE
0D8C0H ?????H ?????H ??????             CODE
0E450H ?????H ?????H ??????             CODE
0F8D0H ?????H ?????H ??????             CODE
0FE40H ?????H ?????H ??????             CODE
10BB0H ?????H ?????H ??????             CODE
11FA0H ?????H ?????H ??????             CODE
16C40H ?????H ?????H ??????             CODE
23A70H ?????H ?????H dseg               DATA