Kason's Tower

Type
Game
Category
Machine-language action game with a self-reading BASIC loader
Author
Jim Rogers
Published in
ANALOG Computing, June 1988; reissued by GIA Software on the Czech disk magazine Flop, issue 5
Year
1988
Language
Atari BASIC loader with machine-language DATA
Requirements
Atari XL/XE (per the REMs) with Atari BASIC; joystick in port 1
Six blue-grey floors stacked up the screen, small figures standing at alternate ends, a green character at bottom right, and MEN 0 LEVEL 0 PRESS START TO BEGIN at the bottom

About the program

Kason's Tower is an all-machine-code game that came to readers as a BASIC type-in. The REMs credit Jim Rogers, "ANALOG 6/88" (the June 1988 issue of ANALOG Computing), and the Czech group GIA Software, which reissued it on the disk magazine Flop 5. Line 80 just says "Game!" and line 90 "Requires joystick!". The screen shows a tower of six floors with figures standing at alternate ends of each floor, your own character at the bottom right, and a status line with MEN (lives) and LEVEL. The magazine article that went with it isn't part of this listing, so the full rules aren't given here. Press START and explore.

What you need

An XL/XE (as the REMs state) with Atari BASIC, and a joystick in port 1.

Typing it in

  • 2,200 numbers. Lines 1001–1104 hold the game itself, 25 values to a line. A few lines (1011, 1023, 1035 … 1095) carry only two values, and the line number after each of them is skipped. That's the layout of the listing, not a fault: the bytes run on without a gap. A disassembly of this copy is consistent all the way through, and every jump lands on an instruction boundary.
  • Every value counts, including the order. A single mistyped number usually shows up as a crash rather than an error message, so SAVE before each RUN.
  • Lines 10 and 30 contain line-drawing characters (CTRL-Q, CTRL-R, CTRL-E, CTRL-Z, CTRL-C) that form a box in the REMs. They're decoration only.

How it works: a loader that reads its own listing

BASIC's READ is slow: converting 2,200 numbers from text one at a time takes a long while. So the program reads only the 210 bytes in lines 5001–5009 with READ (line 200, which also plays a rising tone so you know something is happening) and POKEs them into page 6. Line 4010 then calls that routine with USR(1536).

The routine walks through the tokenized program in memory, starting from the statement table pointer at 136/137. For each line it finds the DATA (which Atari BASIC stores as the original ASCII text), converts the digits into byte values itself, and stores them from $1CFC upwards. When it reaches the end, it sets MEMLO (743/744) to $1CFC and jumps there, and the first instruction jumps on into the game at $2049. (If BASIC's program area starts at $0700, as it does without DOS, the routine builds the code there first and then copies it up into place.) That's the same job BASIC's READ would do, but done directly in machine code, which is much faster. GRAPHICS 5 in line 4000 just clears the screen first.

The game itself uses player/missile graphics for the characters and redefined shapes stored in the first part of the DATA, which is why the opening lines of numbers look like bitmaps (60, 124, 124, 252 …) rather than 6502 instructions.

Listing

10 REM {CTRL-Q}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-E}
20 REM | KASON'S TOWER |
30 REM {CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-C}
40 REM (c) by Jim Rogers
50 REM ANALOG 6/88
60 REM for all Atari XL/XE
70 REM (p) by GIA Software
80 REM Game!
90 REM Requires joystick!
100 GRAPHICS 18:POSITION 3,5:? #6;"KASON'S TOWER"
200 RESTORE 5001:FOR A=1536 TO 1745:READ B:POKE A,B:SOUND 0,121+42*(A<1600)+81*(A<1670),10,4:NEXT A
300 SOUND 0,0,0,0
1001 DATA 76,73,32,56,124,124,252,240,240,230,48,0,252,252,92,92,108,108,104,108,56,124,112,230,254
1002 DATA 255,248,124,56,48,56,60,124,108,108,104,0,56,124,124,252,240,240,230,48,0,252,252,60,60
1003 DATA 126,118,224,224,56,124,112,230,254,255,248,124,56,98,50,60,60,124,112,96,0,56,124,124,252
1004 DATA 240,240,230,48,0,112,112,116,62,62,254,246,134,56,124,112,230,254,255,248,124,56,60,12,12
1005 DATA 62,62,126,116,0,56,124,124,252,240,240,230,48,252,240,92,110,204,0,0,0,0,56,124,112
1006 DATA 230,254,255,248,124,48,56,60,110,0,0,0,0,0,28,62,62,63,15,15,103,12,0,63,63
1007 DATA 58,58,54,54,22,54,28,62,14,103,127,255,31,62,28,12,28,60,62,54,54,22,0,28,62
1008 DATA 62,63,15,15,103,12,0,63,63,60,60,126,110,7,7,28,62,14,103,127,255,31,62,28,70
1009 DATA 76,60,60,62,14,6,0,28,62,62,63,15,15,103,12,0,14,14,46,124,124,127,111,97,28
1010 DATA 62,14,103,127,255,31,62,28,60,48,48,124,124,126,46,0,28,62,62,63,15,15,103,12,63
1011 DATA 59,58
1013 DATA 118,51,0,0,0,0,28,62,14,103,127,255,31,62,12,28,60,118,0,0,0,0,0,24,60
1014 DATA 126,24,24,24,60,24,60,24,60,126,35,65,255,65,35,196,130,255,130,196,40,40,37,35,35
1015 DATA 37,40,42,45,47,50,53,57,60,64,68,72,76,81,173,165,174,16,0,0,0,0,0,0,172
1016 DATA 165,182,165,172,16,121,96,72,60,72,96,121,96,96,48,50,37,51,51,0,51,52,33,50,52
1017 DATA 0,52,47,0,34,37,39,41,46,3,5,6,6,7,7,7,6,6,5,3,0,0,1,1,1
1018 DATA 1,1,1,1,1,1,1,0,0,34,0,68,162,144,144,128,121,108,96,91,60,81,121,121,121
1019 DATA 81,60,60,60,81,60,60,60,81,60,47,47,60,47,47,47,47,72,72,81,81,96,96,121,96
1020 DATA 121,144,121,144,121,60,47,60,134,62,254,46,0,0,154,44,0,56,0,79,72,138,72,152,72
1021 DATA 169,1,141,10,212,173,172,6,41,1,201,1,208,30,172,164,6,185,165,6,141,2,208,185,225
1022 DATA 6,141,20,208,238,164,6,173,164,6,201,7,144,5,169,0,141,164,6,172,174,6,185,175,6
1023 DATA 141,3
1025 DATA 208,238,174,6,173,174,6,201,14,144,5,169,0,141,174,6,238,172,6,104,168,104,170,104,64
1026 DATA 72,138,72,152,72,169,0,141,164,6,141,172,6,141,174,6,165,224,24,105,17,133,226,165,225
1027 DATA 105,0,133,227,160,0,162,17,169,0,145,203,145,205,200,202,208,246,173,173,6,133,203,133,205
1028 DATA 160,0,162,17,177,224,145,203,177,226,145,205,200,202,208,244,173,189,6,201,1,208,53,238,190
1029 DATA 6,174,190,6,224,4,144,5,169,0,141,1,210,224,5,144,34,169,0,141,190,6,174,191,6
1030 DATA 189,137,30,141,0,210,169,163,141,1,210,238,191,6,174,191,6,224,38,144,5,169,0,141,191
1031 DATA 6,173,195,6,201,1,208,38,169,42,141,3,210,174,196,6,189,37,30,141,2,210,238,196,6
1032 DATA 173,196,6,201,19,208,14,169,0,141,195,6,141,196,6,141,3,210,141,2,210,173,211,6,201
1033 DATA 1,208,38,169,166,141,5,210,174,212,6,189,129,30,141,4,210,238,212,6,173,212,6,201,8
1034 DATA 208,14,169,0,141,211,6,141,212,6,141,5,210,141,4,210,104,168,104,170,104,76,98,228,173
1035 DATA 197,6
1037 DATA 10,141,194,6,169,12,56,237,194,6,168,169,38,153,175,6,153,176,6,173,197,6,41,1,201
1038 DATA 1,208,8,169,214,153,175,6,153,176,6,160,0,162,6,169,0,153,216,6,200,202,208,247,96
1039 DATA 169,175,162,24,56,237,197,6,202,208,249,96,169,198,141,207,6,141,0,208,141,1,208,169,175
1040 DATA 141,173,6,169,0,133,20,165,20,201,3,144,250,96,56,165,106,56,233,16,141,7,212,141,192
1041 DATA 6,169,62,141,47,2,169,3,141,29,208,173,192,6,24,105,3,133,208,169,0,133,207,162,5
1042 DATA 160,0,169,0,145,207,200,208,249,230,208,202,208,242,173,192,6,24,105,6,133,208,169,36,133
1043 DATA 207,162,7,142,193,6,160,0,162,12,185,15,30,145,207,200,202,208,247,165,207,24,105,24,133
1044 DATA 207,174,193,6,202,208,227,230,208,169,29,133,207,162,7,142,193,6,162,2,142,194,6,160,0
1045 DATA 162,5,185,32,30,145,207,200,202,208,247,165,207,24,105,13,133,207,174,194,6,202,208,227,165
1046 DATA 207,56,233,2,133,207,174,193,6,202,240,47,142,193,6,162,2,142,194,6,160,0,162,5,185
1047 DATA 27,30
1049 DATA 145,207,200,202,208,247,165,207,24,105,13,133,207,174,194,6,202,208,227,165,207,56,233,2,133
1050 DATA 207,174,193,6,202,208,162,173,192,6,24,105,4,133,204,133,206,230,206,162,7,160,0,169,50
1051 DATA 153,165,6,200,202,240,9,169,198,153,165,6,200,202,208,238,169,0,141,8,208,141,9,208,141
1052 DATA 10,208,141,11,208,141,8,210,169,3,141,15,210,160,0,162,7,185,175,30,153,192,2,200,202
1053 DATA 208,246,169,33,141,111,2,169,0,141,172,6,141,195,6,141,196,6,141,197,6,141,203,6,141
1054 DATA 214,6,162,7,160,0,169,38,153,175,6,200,153,175,6,200,202,240,13,169,214,153,175,6,200
1055 DATA 153,175,6,200,202,208,230,162,7,160,0,169,254,153,225,6,200,202,208,247,169,29,133,225,169
1056 DATA 135,133,224,32,46,32,173,48,2,133,207,173,49,2,133,208,160,1,169,240,145,207,160,3,177
1057 DATA 207,24,105,128,145,207,160,8,162,12,169,138,145,207,200,200,200,202,208,246,169,187,141,0,2
1058 DATA 169,30,141,1,2,169,192,141,14,212,160,13,162,31,169,7,32,92,228,173,48,2,24,105,134
1059 DATA 133,207
1061 DATA 173,49,2,105,0,133,208,162,6,142,193,6,160,0,162,20,169,255,145,207,200,202,208,248,165
1062 DATA 207,24,105,120,133,207,165,208,105,0,133,208,174,193,6,202,208,222,173,48,2,24,105,41,133
1063 DATA 207,173,49,2,105,4,133,208,160,0,162,16,185,56,30,145,207,200,202,208,247,160,0,162,3
1064 DATA 173,48,2,24,121,182,30,153,218,0,173,49,2,105,4,153,219,0,200,200,202,208,233,169,5
1065 DATA 141,201,6,169,0,141,199,6,141,189,6,141,0,210,141,1,210,169,20,141,200,6,160,0,162
1066 DATA 20,185,81,30,145,222,200,202,208,247,173,31,208,201,6,208,249,160,0,162,20,169,0,145,222
1067 DATA 200,202,208,248,169,1,141,189,6,160,0,173,201,6,24,105,16,145,218,32,46,32,169,0,141
1068 DATA 197,6,160,0,173,199,6,24,105,16,145,220,32,20,32,169,2,141,30,208,173,14,208,41,3
1069 DATA 201,0,208,3,76,20,35,169,0,141,189,6,169,6,56,237,197,6,168,162,247,169,164,141,1
1070 DATA 210,189,81,29,141,0,210,173,10,210,153,225,6,169,0,133,20,165,20,201,20,144,250,232,208
1071 DATA 226,169
1073 DATA 0,141,0,210,141,1,210,169,254,153,225,6,169,1,141,189,6,32,237,31,238,197,6,173,197
1074 DATA 6,201,7,144,9,238,199,6,206,200,6,76,145,34,32,34,32,141,173,6,32,62,32,173,15
1075 DATA 208,41,3,201,0,240,56,169,1,141,195,6,162,198,173,197,6,41,1,201,1,208,2,162,50
1076 DATA 142,207,6,142,0,208,142,1,208,32,237,31,206,201,6,160,0,173,201,6,24,105,16,145,218
1077 DATA 32,62,32,173,201,6,201,0,208,3,76,74,34,169,2,141,30,208,173,120,2,141,208,6,173
1078 DATA 205,6,201,1,208,3,76,232,35,173,202,6,201,1,240,21,173,132,2,201,0,208,14,173,120
1079 DATA 2,141,204,6,169,1,141,202,6,141,211,6,173,202,6,201,1,208,91,32,34,32,174,203,6
1080 DATA 56,253,101,30,141,173,6,172,204,6,192,11,240,7,172,204,6,192,10,208,10,173,207,6,56
1081 DATA 253,113,30,141,207,6,172,204,6,192,7,240,7,172,204,6,192,6,208,10,173,207,6,24,125
1082 DATA 113,30,141,207,6,173,207,6,141,0,208,141,1,208,238,203,6,173,203,6,201,12,208,8,169
1083 DATA 0,141
1085 DATA 203,6,141,202,6,76,215,36,173,205,6,201,1,240,39,173,208,6,201,13,208,88,169,1,141
1086 DATA 205,6,160,0,177,224,201,56,240,11,169,237,133,224,169,29,133,225,76,22,36,169,101,133,224
1087 DATA 169,29,133,225,173,205,6,201,1,208,49,32,34,32,24,105,4,141,173,6,238,210,6,173,210
1088 DATA 6,201,12,208,27,32,34,32,141,173,6,169,0,141,205,6,141,210,6,165,224,56,233,102,133
1089 DATA 224,165,225,233,0,133,225,76,215,36,173,208,6,201,10,240,14,173,208,6,201,8,240,7,173
1090 DATA 208,6,201,11,208,21,169,135,133,224,169,29,133,225,173,207,6,201,47,240,3,206,207,6,76
1091 DATA 159,36,173,208,6,201,6,240,14,173,208,6,201,5,240,7,173,208,6,201,7,208,74,169,255
1092 DATA 133,224,169,28,133,225,173,207,6,201,200,240,3,238,207,6,173,207,6,141,0,208,141,1,208
1093 DATA 172,214,6,165,224,24,121,125,30,133,224,165,225,105,0,133,225,238,215,6,173,215,6,201,3
1094 DATA 208,20,169,0,141,215,6,238,214,6,173,214,6,201,4,208,5,169,0,141,214,6,160,0,162
1095 DATA 2,142
1097 DATA 193,6,173,197,6,10,141,194,6,152,24,105,12,56,237,194,6,170,185,216,6,201,1,208,89
1098 DATA 185,218,6,201,1,240,18,185,220,6,56,233,1,153,220,6,201,0,208,69,169,1,153,218,6
1099 DATA 173,197,6,41,1,201,1,240,29,254,175,6,254,175,6,189,175,6,201,214,144,13,169,38,157
1100 DATA 175,6,169,0,153,216,6,153,218,6,76,78,37,222,175,6,222,175,6,189,175,6,201,38,176
1101 DATA 13,169,214,157,175,6,169,0,153,216,6,153,218,6,200,174,193,6,202,208,134,173,216,6,201
1102 DATA 1,240,38,173,217,6,201,1,240,31,173,10,210,41,15,24,105,16,141,220,6,141,221,6,173
1103 DATA 10,210,41,1,168,169,1,153,220,6,141,216,6,141,217,6,174,200,6,160,255,169,0,133,77
1104 DATA 136,208,249,202,208,244,76,171,34
4000 GRAPHICS 5
4010 XX=USR(1536)
5001 DATA 104,169,28,133,206,169,252,133,205,165,129,201,7,208,8,169,7,133,206,169,0,133,205,165,136
5002 DATA 133,203,165,137,133,204,162,240,224,3,208,108,160,4,200,177,203,201,48,144,6,177,203,201,155
5003 DATA 208,243,152,72,136,177,203,56,233,48,133,207,169,10,133,209,162,2,134,208,136,177,203,201,48
5004 DATA 240,20,177,203,201,48,144,23,56,233,48,170,165,207,24,101,209,202,208,250,133,207,169,100,133
5005 DATA 209,166,208,202,208,218,160,0,165,207,145,205,230,205,165,205,201,0,208,2,230,206,104,168,177
5006 DATA 203,201,155,208,165,160,2,165,203,24,113,203,133,203,165,204,105,0,133,204,160,4,177,203,201
5007 DATA 1,240,140,224,240,240,229,165,129,201,7,208,34,169,0,133,207,169,7,133,208,169,252,133,205
5008 DATA 169,28,133,206,162,8,160,0,177,207,145,205,200,208,249,230,206,230,208,202,208,240,169,252,141
5009 DATA 231,2,169,28,141,232,2,76,252,28

Credits