Notes on the C64 Basic game Jake the Snake

Code

0 Jump to initialization, setup and intro code

1-10 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
420-423	Subroutine: Initialize program
430-436 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)
600-618	Subroutine: Print and set up new level
740-747 Subroutine: Read data for next level
770-830	Death + restart
850-870	Level completed
4000-4070	Subroutine: Read highscores from disk
4100-4130	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	Eat an apple on mini-level
 5800-5840	Format highscore list for display
9000-9999	Level data

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$
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
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
GE		Effective game speed
GL		Game speed limit
GM		Game minimum speed
GS		Game speed
GT		Game target minimum speed
H		Position of snake head in T()
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
P		Position of snake head in screen memory (1024-1983)
PL		Physical level (map#)
PR		Print row
PS		Player score
Q		Screen code for character in front of snake
R		Address in screen RAM
RH		Redraw highscore list
S$		Status message
SD		Drawing direction ("step size") (when drawing a level)
SH		Starting highscore entry (to show on intro screen)
SL()	Time limits for when to change color for each position in time bonus bar
SP		Next position to change color in time bonus bar
SS		Step count (when drawing a level)
SY		The symbol to replace the snake head when it moves
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
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)


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/
