11

Here is a BASIC program for the Commodore 64, which should load the LIB file from the disk, and then stop. Yes?

5 PRINT "LOADING..."
10 LOAD "LIB",8,1
20 STOP

the LIB file is 102 bytes long and is loaded to address $BF00, which is under the BASIC ROM so I don't see how it should affect the running of the system in any way since I don't turn the ROM off.

What I see on the screen:

LOADING...
LOADING...
LOADING...
LOADING...
LOADING...
LOADING...
LOADING...
LOADING...

... ad infinitum. How can this be happening?

2 Answers 2

12

When Commodore BASIC finishes the LOAD command, it automatically runs the BASIC program, which was not overwritten because you loaded a binary outside of BASIC's program space. See page 59 of the C64 Programmer's Reference Guide.

5
  • 1
    It appears that this behaviour of LOAD differs if it's run inside a program or if you simply type LOAD in the BASIC screen... Commented Oct 8, 2017 at 16:54
  • 2
    Yes, a number of commands in BASIC differ in operation depending on whether they are run in immediate mode or not. Some commands only work in one mode or the other.
    – Tim Locke
    Commented Oct 9, 2017 at 12:49
  • 1
    I'm sure that doesn't happen in any other BASICs I've used... Why is this happening? Commented Oct 9, 2017 at 13:27
  • 2
    It's happening because it was designed to do it. They wanted programmers to be able to chain BASIC programs together, loading one from another, and have them automatically run, presumably to give an uninterrupted experience for the end user. I checked the manual for Applesoft and Atari BASICs and they do not seem to support this, so perhaps this is something Commodore added themselves or asked Microsoft to do (which is who they bought their BASIC from).
    – Tim Locke
    Commented Oct 9, 2017 at 18:12
  • 4
    There is an example at the bottom of the following article page showing how to load multiple binaries from Commodore BASIC. LOAD - C64-Wiki
    – Tim Locke
    Commented Oct 9, 2017 at 18:12
11

Here is how you do it in Commodore BASIC:

10 IF A=0 THEN PRINT "LOADING, PLEASE WAIT..."
20 IF A=0 THEN A=1:LOAD"LIB",8,1
30 REM "IF A=1" IS TEMPTING HERE BUT IS UNNECESSARY, SINCE A MUST NOT EQUAL ZERO BY NOW
40 SYS 49152:REM ASSUMING "LIB" IS AT $C000; AMEND AS REQUIRED TO RUN "LIB"

Commodore BASIC always re-runs a program when you LOAD within it, but variables are kept intact. This code takes advantage of that by incrementing a variable so that the code can tell if the LOAD has happened yet or not.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .