K240 Save Game

Disassembly of K240 v2.000 reveals a series of nine calls to the dos.library Write() function, beginning at position $03414 in the main game executable. It's reasonable to conclude that these form K240's save game function. All but one section are given explicit sizes except PART1, whose size can be surmised knowing the save game filesize of 151,850 bytes.

Section Start (bytes) Size (bytes) Content Referenced
PART0 0 18 Game filename and alien Directly
PART1 18 30 Alien data Directly
PART2 48 55810 ?? Directly
PART3 55858 37800 Ships By pointer
PART4 93658 33600 Buildings By pointer
PART5 127258 18000 Asteroid and colony data By pointer
PART6 145258 1920 ?? By pointer
PART7 147178 2336 ?? By pointer
PART8 149514 2336 ?? By pointer
END 151850 - - -

Save game format

Part 0

Start (bytes) Size (bytes) Content
0 16 Game filename (string)
17 2 Current alien number

The last two bytes are probably the alien number, beginning with Kll-Kp-Qua as 01. An alien number of 00 means the game was saved between games.

Part 1

30 bytes long. It appears to be part of the alien data file a1data4 to a6data4, the thirty bytes after the first four bytes of the file. Disassembly suggests the following format.

Position Type Default value
$20300 Long $20a68 (ptr)
$20304 Word $0001
$20306 Word $003c
$20308 Word $0000
$2030a Word $0046
$2030c Word $00c8
$2030e Word $0019
$20310 Word $0014
$20312 Word $0000
$20314 Word $0000
$20316 Word $0002
$20318 Word $0004
$2031a Word $0006
$2031c Word $0010
$2031e Word $0028
$20320 Byte $08
$20321 Byte $00

Part 2

A complex, 55,810-byte structure containing over a hundred game variables. The default values are stored in the game executable, beginning at position $20a8c. Disassembly using IRA gives 186 labels in the area used for this part of the save game.

This structure is currently poorly understood.

Start (bytes) Size (bytes, decimal) Content
0 80 20 longs ??
80 160 Ore prices
240 112 ??
352 53,856 Asteroid maps
54,208 1,602 ??

There are 24 asteroid maps of 2,244 bytes, or 32 lines of 68 byte width.

Part 3

This 37,800 byte section holds data on 700 ships, storing 54 bytes per ship. This includes alien ships. What happens when more than 700 ships are built is untested.

This data structure is detailed in Ships: Current ship data.

Part 4

A 33,600 byte data structure. It stores the current building data for 24 asteroids, for 100 buildings per asteroid, storing 14 bytes per building.

The data structure is detailed in K240 buildings, "Current building data".

Part 5

A 18,000 byte structure which stores asteroid and colony data for 24 asteroids, storing 750 bytes per asteroid. Includes alien asteroids.

The data structure is only partially decoded so far.

Datatype Start (bytes, decimal) Description
15-17 bytes? 40 Asteroid name
10 words 62 Amount of each ore on asteroid
11 words 100 Number of each missile at asteroid
Word 170 Number of spy satellites in asteroid
Word 684 Current population
3 words 694 Power production, usage, and surplus
3 words 700 Air production, usage, and surplus
3 words 706 Food production, usage, and surplus
3 words 712 Water production, usage, and surplus

Part 6

Unknown 1,920 byte structure. If it stores data on a per-asteroid basis, it stores 80 bytes per asteroid.

Part 7

Unknown 2,336 byte structure.

Part 8

Unknown 2,336 byte structure.

Save game code snippet

This code snippet is taken from a disassembly of K240 v2.00 using IRA, and begins at hexadecimal position $03414.

LAB_010D:
    MOVE.L    0(A0,D0.W),D1    
    MOVE.L    D1,LAB_0B3D    ; file to open
    MOVE.L    #$000003ee,D2  ; mode (write)
    JSR       -30(A6)        ; dos.library Open()
    MOVE.L    D0,SECSTRT_1   ; store file pointer
    BEQ.W     LAB_010F       

    MOVE.L    SECSTRT_1,D1   ; File pointer
    MOVE.L    #LAB_0B59,D2   ; Source buffer
    MOVEQ     #18,D3         ; length (18 bytes)
    JSR       -48(A6)        ; dos.library Write()
    TST.L     D0             ; Check if file write was successful
    BMI.W     LAB_0111       ; If not, close and delete the file

    MOVE.L    SECSTRT_1,D1   ; File pointer
    MOVE.L    #LAB_0C7C,D2   ; Source buffer
    MOVE.L    #LAB_0C8C,D3   ; length (LAB_0C8C bytes)
    SUB.L     D2,D3          
    JSR       -48(A6)        ; dos.library Write()
    TST.L     D0             ; Check if file write was successful
    BMI.W     LAB_0111       ; If not, close and delete the file

    MOVE.L    SECSTRT_1,D1   ; file pointer
    MOVE.L    #LAB_0C99,D2   ; buffer
    MOVE.L    #$0000da02,D3  ; length (55,810 bytes)
    JSR       -48(A6)        ; dos.library write
...
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License