in BASIC ROM:
|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 normally used for loading program files (PRG) like BASIC, machine language programs, but actually any kind of data from datasette or disk drive into RAM. This is the common task needed before a previously stored program can be edited and run with the BASIC command RUN.
The device number instructs the computer which storage device is to be accessed 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, usually the datasette.
The filename parameter can be used to load a specific file. In this context certain characters have special meanings, e.g. wildcard characters "*", "?" or the directory load character "$"). Examples:
LOAD "*",8 loads the first file if LOAD is called the first time or the last loaded file. LOAD "A*",8 loads the first file whose name begins with A. But note: all characters appearing after the first "*" are ignored. LOAD "A?C",8 loads the first file whose name consists of the three letters, where the first letter is "A" and the last is "C". The "?" character denotes a wildcard which matches any single character. 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 address of BASIC memory (2049/$0801). ,1 The program will be loaded absolute, namely it is stored to the location defined by the first two bytes in the PRG file image. Typically needed for machine language programs to get properly located into the memory.
If this is not specified it defaults to 0.
If the command LOAD is entered directly, all open files will be closed and the BASIC command CLR will be implicitly executed, and interpretation of the current line will end. If LOAD is called from a BASIC program it behaves like chain loader. After the load the program execution is forced to start over from the beginning (in expectation that the running program could have been overwritten), but unlike RUN, variables and arrays are maintained and may hold state information throughout successive loads.
LOAD executed in direct mode always changes the SOV (start-of-variables) pointer. If a ML program is loaded without relocation, SOV will point directly below it which will usually results in a BASIC area pointer mismatch, sometimes leading to a "?OUT OF MEMORY ERROR". To prevent this, a NEW command should be executed after LOAD (beside of some trickery with POKEing pointers).
A user can easily load from a datasette by holding SHIFT while pushing RUN/STOP . After that the PLAY button on the datasette should be pushed and the first file will be searched. After some time the name of the first encountered file will be printed on screen with the message "FOUND filename" for short while and followed by the process of being loaded into RAM. This 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 blanked so the VIC will not interfere the timing for the data transfer directly processed by the CPU. The screen remains on while loading from other storage devices where handshake protocols (like on IEC/serial bus) are able to cope with VIC's behavior.
In case the filename given doesn't match an existing one or is not of type program (PRG) BASIC emits the error message "?FILE NOT FOUND ERROR".
Examples[edit | edit source]
(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)
- Simple loader (from the 1980's)
10 REM JUMP&RUN GAME LOADER 20 A=A+1 30 IF A=1 THEN LOAD "MUSIC",8,1 40 IF A=2 THEN LOAD "SPRITES",8,1 50 IF A=3 THEN LOAD "GRAPHICS",8,1 60 IF A=4 THEN LOAD "LEVEL1",8
This loader program successively loads the machine code or data parts (MUSIC, SPRITES, GRAPHICS) needed for the main program LEVEL1 from disk drive with device number 8 into RAM. As the last step the part "LEVEL1" is loaded as BASIC program, overwriting the loader program and implicitly starting it.
- Advanced loader with progress indicator
0 REM JUMP&RUN GAME LOADER 10 A=A+1 20 D=8: S=4: DATA "MUSIC", "SPRITES", "GRAPHIC", "LEVEL1" 30 READ F$ 40 IF A=0 THEN PRINT CHR$(147)"LOADING PLEASE WAIT..." 50 IF A=S THEN PRINT INT(100*A/S)"%": LOAD F$,D : REM LOAD & START LAST PART 60 PRINT INT(100*A/S)"%": LOAD F$,D,1 : REM LOAD A PART
The file names are taken from the DATA statement on line 20.
Variable D represents the device number.
Variable S contains the number of files to be loaded. Right before a part is loaded the progress in percent (accomplished after the part is finished) will be displayed.
The last part is loaded like a "normal" BASIC program using LOAD without a 3rd argument. This overwrites the loader program and the program "LEVEL1" gets finally started!
ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT