80-Bus News

  

Summer 1985 · Volume 4 · Issue 2

Page 16 of 31
COMMON A,B(1),C%,D$,F(2)
DIM B(10),E%(2,3,4),F(10)

Creating and using library programs

In CBASIC one has the ability to include programs — such as graphics or screen handling routines which one may have written or acquired. In this sense, CBASIC operates in much the same way as the better versions of Pascal or Fortran. Any library programs may be incorporated by means of the %INCLUDE statement; it is important to make sure that the Included program (or program segment) does not include a STOP or END statement — for obvious reasons. Up to 6 levels of %INCLUDE nesting are permitted which should be enough for most people!

Other statements, functions and directives

CBASIC is full of other goodies to excite the keen programmer or to depress the less able! Some useful ones are listed briefly.

Statements

CALL — summons a machine code routine, and has the syntax:

CALL <integer expression> – the expression may be in hex

INPUT … LINE — reads an entire entry from the display and assigns it to a special string variable.

INPUT"Message"; LINE SILLY.ANSWERS$

OUT — puts out an 8 bit integer value to an I/O port.

OUT <integer expression,​integer expression> sends a low order byte of the second expression to the output port addressed by the low order byte of the first expression.

RANDOMIZE — seeds the random number generator called by the RND function; the seeding depends upon the operator’s response time to a request from a previously executed INPUT statement.

INPUT"Do you need to use a random number"; A$
RANDOMIZE

READ # … LINE — reads one record from the selected file and assigns it to a string variable.

READ #2; LINE X$ — reads one record from file no. 2 and places it in X$

Savemem — reserves space for a file which will be loaded when Savemem is executed; normally, the file will be a machine code type.

Functions

CONCHAR% — waits for and accepts one character from the keyboard.

CONSTAT% — returns a −1 (true) if a key has been pressed or 0 (false) if not.

INP — returns a byte from a selected I/O port

INP(port.no.)

Compiler directives

There are six of these; two, %INCLUDE and %CHAIN have already been covered and the rest deal with the format of the listing produced by the compiler. Directives do not interfere with the running of the program and they must always be at the beginning of the line.

%LIST and %NOLIST — turn the program listing on or off which could be handy if you only want to see part of a program: they affect both console and printer listings and also operate on disk files.

%EJECT — as its name suggests, operates on the printer when it is enabled and performs a control-L function to start printing at the top of the next page.

%PAGE — sets up the number of printed lines per page on the printer. It defaults to 64 and must be altered if another page length is needed. Thus PAGE(60) specifies 60 lines per page of print.

Apart from compiler directives, there are six “toggles” which may be included as required in the command line. The toggles are preceded by a $ sign.

B —suppresses source file listing at the console, but allows compilation statistics to appear.
C —suppresses the creation of an .INT file which helps in initial error checking for a new program since compilation is a lot faster.
D —suppresses the conversion of lower to upper case letters when these are used in variable names.
E —a useful debugging facility which pinpoints source lines in the .INT file in which an error occurred. It must also be used if you wish to employ the TRACE facility.
F —produces a listing of the program on the printer as well as the console.
G —produces a listing on a disk file as well as the console.

A typical CBASIC compilation command line would be:

>CBASIC TESTPROG first run of the
                  revised version $EF

A typical CBASIC compilation command line would be:

>CBASIC TESTPROG first run of the
                  revised version $EF
Page 16 of 31