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 Find out which physical level to play next
482 print game screen
484 Start gameplay

500-530	Subroutine: Calculate LT (maximum time for time bonus)
540-590	Subroutine: Initialize program
600-618	Subroutine: Print and set up new level
700-702	Subroutine: Wait for player to press space
740-750 Subroutine: Figure out which physical level is to be played next
770-840	Death + restart
850-855	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
9000-9009	DATA statements for speed settings 
30100-33699	Level printing routines (i.e. level 15 is on line 31500-31599)

Variables (not all are documented)

A		Address where next apple is placed
B		100
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
DN		Device number
E		Apples left to eat to complete the level
ED		Erase Difficulty (Difficulty level of the previous highscore marker)
EP		Erase Position (Position of the previous highscore marker)
F		Apples left to place on the current level
F1$		Contains the Petscii string for the F1 key 
F3$		Contains the Petscii string for the F3 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
GC		Game speed setting
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
GX		Game maximum 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
LD		Last Difficulty (Difficulty level of the highscore marker for the last game played)
LE		Level end time
LI		Level end time limit to get time bonus
LP		Last Position (Position of the highscore marker for the last game played)
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
SN$()	Speed setting name
SM		Speed multiplier
SP		Next position to change color in time bonus bar
SS()	Speed setting low-high
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		Heartbeat sound flag ( = 1 every other game tick)
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 a series of PRINT statements. The starting line numbers 
of the levels are defined on line 601-604. Before calling the level-specific 
printing routine, the routine at line 600- is responsible for clearing the
screen, placing the cursor in the top left corner, and setting the character
color. The level specific printing routine is responsible for setting and 
clearing reverse mode.

