From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: LOAD
Abbreviation: L Shift+O
Type: Command
Token code: 147/$93
Handling routine
List of all BASIC keywords

Remark: This article describes the BASIC command LOAD in BASIC V2 at the Commodore 64.

Type: Command
General programming syntax: LOAD ["<filename>"] [,<device number>] [,<secondary number>]

The BASIC command LOAD is used for loading program files (PRG) like BASIC or machine language programs from datasette or disk drive into RAM. This must happen before a stored program can be edited or started and executed with the BASIC command RUN.

The device number instructs the computer which storage device to access, using the following scheme:

  • datasette - device number 1
  • disk drives - device numbers 8-15, optional first disk drive 8, second disk drive 9, etc

If no device number is given, the computer defaults to device 1, i.e. datasette.

The filename parameter can be used to load a specific file. In this context certain characters (e.g. *, ? or $) have special meanings. Examples:

LOAD "*",8 loads the first file
LOAD "A*",8 loads the first file whose name begins with A
LOAD "A*C",8 loads the first file whose name begins with A and ends with C, with any or no included characters.
LOAD "A?C",8 loads the first file whose name consist of the three letters, where the first letter is A and the last is C. The ? is a wildcard which matches any single char 
LOAD "$",8 loads the disk directory

The "secondary number" specifies how the data should be loaded:

,0 The program will be loaded to the start of BASIC memory (2049/$0801)
,1 The program will be loaded absolute, i.e. to its stored location defined by the first two bytes in the binary file. Needed for machine language programs.

If this is not specified, the default value 0 is used.

As the command LOAD is entered directly, all open files will be closed and the BASIC-Command CLR will be executed in the background. If LOAD is called from a BASIC program the stack is not deleted - after loading the file, the BASIC-command RUN will be executed in the background.

A user can easily load from a datasette by holding SHIFT  while pushing RUN/STOP . After that he can be push the PLAY  button on the datasette and the first file will be searched. After a few seconds the name of the located file will be printed on screen with the message "FOUND filename", before being loaded into RAM after some delay. The delay can be skipped by pushing the C=  key although the SPACE  key is more frequently used. While loading a file from datasette the screen will be switched off so the VIC will not interfere with the data transfer which is processed directly by the CPU. The screen remains switched on while loading from other storage devices since transfers are handled by the CIA chips.

If the BASIC error message "?FILE NOT FOUND" appears then the filename didn't exist or isn't a program file.

[edit] Examples

(loads a program from the first disk-drive 8)
(loads a program absolute from the second disk drive 9)
(loads a program with file name stored in the string FILE$ absolute from datasette)

20 IF A=0 THEN A=A+1: LOAD "MUSIC",8,1
30 IF A=1 THEN A=A+1: LOAD "SPRITES",8,1
40 IF A=2 THEN A=A+1: LOAD "GRAPHIC",8,1
50 IF A=3 THEN A=A+1: LOAD "LEVEL1",8
Personal tools
In other languages