Notes on the C64 Basic game Jake the Snake

Code

0 Jump to initialization, setup and intro code

1-14	Main game loop
20		Entry point for main game loop	

200-270 Subroutine: Eat an apple, place new apple or exit or nothing
 261	Entry point: Print number of apples left until bonus life 
290-293 Subroutine: Place an apple (only to be used at level start)
300-308 Subroutine: Soundeffect death
310-318 Subroutine: Soundeffect level completed
380-388 Subroutine: Snake dies and dissolves in bangs
400-411 Subroutine: Print status line
 410	Entry point: Print non-standard status line
415		Subroutine: Place the cursor on a certain line
430-438 Subroutine: Prepare for new or restarted level
440-460	Subroutine: Prepare for new game

470 Initialize program
472 Setup for a new game
474 Show intro screen
476-478 Initialize game for new or restarted level
480 Read data for next level
482 print game screen
484 Start gameplay

500-530	Subroutine: Calculate LT (maximum time for time bonus)
540-580	Subroutine: Initialize program
600-618	Subroutine: Print and set up new level
740-750 Subroutine: Read data for next level
770-840	Death + restart
850-870	Level completed
4000-4070	Subroutine: Read highscores from disk
4100-4110	Subroutine: Print error message regarding disk operations
4200-4240	Subroutine: Add current score to highscore list, if high enough
4300-4390	Subroutine: Save highscores to disk
4400-4440	Subroutine: Create default highscore file on disk
4900-4960	Subroutine: Ask which device# to load/save highscores to
5000-5999	Subroutine: Show intro screen
 5000-5016	Print intro screen text
 5100-5120	Setup mini-level on introscreen
 5200		Print highscore list
 5500-5650	Animate mini-level
 5700-5720	Subroutine: Eat an apple on mini-level
 5730-5745	Subroutine: Increase minimum game speed
 5750-5775	Subroutine: Increase difficulty level
 5780-5786	Subroutine: Increase maximum game speed
 5800-5840	Subroutine: Format highscore list for display
 5900-5970	Subroutine: Print intro screen level map
 5980-5985	Subroutine: Extract snake movement data for intro screen map
9010-9999	Level data (Level 15 is on line 9150-9159)

Variables (not all are documented)

A$		Data for level
B$		Partial data for level
BA		Apples left to get extra life
BB		Apples needed to get next extra life
BW		Base level (# of maps to skip when playing at higher difficulty)
C		Column
C1$		Newline character (CHR$(13))
D		Direction of snake
DC$		Direction commands for intro screen
DE		Diskdrive error code
DE$		Diskdrive error message
DP		Current position in DC$
DS		Display speed
DM		Demo mode (used for intro screen)
DN		Device number
E		Apples left to eat to complete the level
F		Apples left to place on the current level
F3$		Contains the Petscii string for the F3 key 
F5$		Contains the Petscii string for the F5 key 
F7$		Contains the Petscii string for the F5 key 
G1		Temporary variable used in calculating time bonus limit: Game speed at level start
G2		Temporary variable used in calculating time bonus limit: Game speed after eating a certain number of apples
G3		Temporary variable used in calculating time bonus limit: Sum of the gamespeeds after eating each apple in a level
G4		Temporary variable used in calculating time bonus limit: Average gamespeed for all apples in a level
GD		Game difficulty level
GD$()	Difficulty setting names
GE		Effective game speed
GF		Growth factor
GL		Game speed limit
GM		Game minimum speed
GS		Game speed
GT		Game target minimum speed
H		Position of snake head in T()
HC()	Index of the first entry that has changed for each highscore list. -1 means no changes.
HF$		Name of highscore file
HN$()	Highscore names
HL()	Highscore levels
HP		Have paused (asked user to press some key to continue)
HS()	Highscore scores
I$		Input string
I		General iteration variable
J		General iteration variable
K		Snake was just killed
L		Snake length
LE		Level end time
LI		Level end time limit to get time bonus
LS		Level start time
M		1024
N		1023
N()		Lookup table to get new value for D (direction)
ND		New device number
O		Start time for an iteration of the game loop (not used except when performing timing tests)
P		Position of snake head in screen memory (1024-1983)
PL		Physical level (map#)
PR		Print row
PS		Player score
Q		32
R		Current address in screen RAM
RH		Redraw highscore list
S$		Status message
S$()	S$(n) is a string consisting of n spaces
SC		Time bonus bar color start address
SH		Starting highscore entry (to show on intro screen)
SL()	Time limits for when to change color for each position in time bonus bar
SM		Speed multiplier
SP		Next position to change color in time bonus bar
SY()	Lookup table containing the symbols to use for the snake body
T		Temporary number
T$		Temporary string
T()		Snake trace
TA		Time allowed per apple (and exit) to get time bonus
TB		Time bonus
TL		Target length of snake
TM		Start address of timing marker in color RAM
U		Number of lives
V		Input key value / User command
W		Current level
XB		SID chip base address
XD		Value of D last turn
XS		Shutoff value for voice 2
XW		Sound waveform
XX		Sound length
Y		(Base address of color RAM) - (Base address of screen RAM)
Z		40

Level data:

A level is defined by DATA statements containing one or more strings. 
Each string consists of n groups of four characters each, plus a
continuation character at the end. Thus, the length of the string should be 
4*n+1 characters. The four characters in a group denote numbers stating where
to draw lines: row (0-22), column(0-39), stepsize (usually 1 or 40), stepcount.
The continuation character should be "+" if the next string should be read and
appended to the level data, or "/" if this is the final string. The drawing
routine has no bounds checking, which means a mistake can lead to the program
code being modified.

The following characters can be used to denote numbers in level data (0-40):
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[£]↑← !"#$%&'(

Thus, to define a level containing a single horizontal line, 5 characters long
and starting at row 2, column 3, enter:

8900 DATA BCAE/

Defining it on a line number < 9000 will make it appear as the very first 
level of the game, on the easiest difficulty setting. Once you're happy with
the level, you can change the line numbers to place it where it fits in better
in the game.

PLEASE NOTE: For performance reasons, there is no bounds checking when a level
is printed. This means that it's quite easy to print something that will extend
beyond screen memory and into Basic memory. If this happens, the program will
be modified in rather random ways. Therefore, make sure you save the program
before trying out a new level.

