When a program starts it is often useful to be able to know
what device the program has loaded from so that it can load
more files from the same place. Quite often, the usual method
is to not bother, and hard-code the source into separate
loader programs. For instance:
Tape loader:
10 CLEAR 32767:LOAD "code"CODE:RANDOMIZE USR 32768
Microdrive loader:
10 CLEAR 32767:LOAD *"m";1;"code"CODE:RANDOMIZE USR 32768
However, it is more useful to be able to have just one loader
program and have it load its resources from where it has just
loaded from so you don't have to have different programs for
different devices.
This can be done comprehensively as part of generalised
device selection code.
However, if all the program needs to do is load some more files and
that's it, for example, loading and entering some machine code, it
can be done a lot simpler.
10 CLEAR 32767:GOSUB 100:RANDOMIZE USR 32768
100 LET d=PEEK 23649+256*PEEK 23650-2
110 LET d=d+1:IF PEEK d<>128 THEN GOTO 110
120 IF PEEK (d+19) THEN GOTO 170
130 LET d=PEEK 23769
140 IF d=CODE"M" THEN LOAD *"m";PEEK 23766;"code"CODE:RETURN
150 IF d=CODE"N" THEN LOAD *"n";PEEK 23766 CODE:RETURN
160 IF d=CODE"B" THEN LOAD *"b"CODE:RETURN
170 LOAD "code"CODE:RETURN
|