Commodore 2001-8 User Manual page 94

Table of Contents

Advertisement

program. ObviOUSly, this technique does not work at all, if the program is to be loaded Into the cassette
buffers. Another technique is to assemble the program, into the BASIC program, by means of putting the
machine language program into data statements. The data statements can then be read at the beginning
of the execution of the BASIC program and POKEd into the appropriate memory locations.
SYS COMMAND
When it is necessary to transfer control to the machine language program, there are two ways to do it.
The preferred approach is the SYS command which transfers control totally from BASIC until control is
returned by means of a routine from subroutine instruction. It can be used to transfer control to any other
program such as a machine language monitor or future languages when they become available. If the
following code is encountered
10 SYS (634)
at Line 10, BASIC will hand control of the computer to the program located at 634. The general format
for the SYS command is
SYS (start address)
The start address can be a computed value, in either case, it must result in a positive number not greater
than 65535. NOTE: Execution of machine language code, removes almost all protection that the ROMs
has built into it to allow the BASIC interpreter to continue functioning without regard to user error. As
soon as you transfer control from BASIC to your own program, any mistakes which occur in your program
may cause the machine to cease to function.
In order to help solve this type of problem, you should use
the machine language monitor to develop anything other than the most trivial amount of code. In any
case, when control of system is lost, it can be regained by repowering the system on.
In order to return from the SYS command, the last instruction in the program, which is executed, should
be a RTS instruction. BASIC will then start interpreting the next statement after the SYS command. In
order to pass the variables of data back and forth between the user program and BASIC using the SYS
command, data has to be POKEd into temporarily undisturbed memory locations during the execution of
the BASIC routine. The results of the SYS operation would have to be PEEKed back into the program that
follows the call to SYS.
USR FUNCTION
There are some programs, particularly mathematical ones, in which it is easier to pass parameters
tolfrom BASIC using the USR function and to get the results directly processed in BASIC. USR is
specified
wi~h
a parameter. BASIC evaluates the expression for its parameter and leaves the results of
the evaluation in a floating accumulator which BASIC uses for all of its functions. It is noted that if no
parameter is passed, the floating accumulator is not initializeable by the user or by any other techniques
as it is used by BASIC in a variety of ways prior to executing the USR function.
USR calls a routine, Which executes a machine language program. A result in the floating accumulator to
be analyzed by the BASIC expression. Because USR is a function, it is possible to include the function
called user as part of a BASIC instruction as in: IF USR (A) = 1, THEN etc. In this case the parameter A
will be passed to the USR function in the floating accumulator. The resulting floating accumulator, when
the user returns to BASIC, would be compared to 1 and the logical function would be executed.
The SYS command is more useful for transferring control for machine language processing in which
variables are not being acted on. USR is more useful when one is trying to implement a new BASIC
command. This is an important consideration in using USR. USA uses preassigned variable locations:
locations 1 and 2. These locations must be initialized with the hexadecimal value of the starting address
in which the machine language program is stored. This can be done anyWhere throughout the program
92

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents