HiSoft Pascal Primer cover: a square, a triangle and a circle drawn and filled by a HiSoft Pascal program on the Tatung Einstein
← Back to Courses
module
3

Writing A Program In XBAS

Introduction

In the Turbo course, the editor was part of Turbo Pascal: E, type, CTRL-K CTRL-D, S. HiSoft Pascal has no editor at all. Its manual's answer is to use the one every Einstein already has - XBAS, the Einstein's BASIC. You type your Pascal into it as if it were a BASIC program, a numbered line at a time, and save it as a text file for the compiler to read.

Pascal As Numbered Lines

Start XBAS from the 0: prompt, and type a program with a line number at the front of each line:

10 PROGRAM FIRST;
20 BEGIN
30 WRITELN(20)
40 END.

XBAS does not try to run any of it. A line that starts with a number is simply stored, in number order. LIST shows what is stored:

    10 PROGRAM FIRST;
    20 BEGIN
    30 WRITELN(20)
    40 END.

The numbers are only for XBAS, to keep the lines in order and to let you change them. The compiler skips over them (S4). Count in tens, as BASIC programmers do, so that there is room to put a line in between later.

One Turbo habit does not survive: indenting. XBAS keeps only one space after the line number, however many you type, so every line starts at the left. The listings in this primer are written that way.

If typing the numbers is tedious, type AUTO first. XBAS then puts 10, 20, 30... in front of each line for you. It does not stop by itself, and ESC does not stop it: when you are done, press ENTER on the empty number it offers. XBAS answers Branch Error and Ready - take no notice, your lines are kept.

Changing A Line

There is no cursor to move round the program as there was in Turbo's editor. You change a program a whole line at a time, by its number:

  • To replace a line, type it again with the same number.
  • To delete a line, type its number and nothing else.
  • To put a line in between, give it a number in between: 25 goes after 20.
  • RENUM renumbers the whole program in tens again, when the gaps run out.
  • LIST shows the program as it is now.

Capitals

XBAS starts with CAPS LOCK on, so everything you type comes out in capitals - and Pascal's own words have to be in capitals for HiSoft Pascal: BEGIN, not begin. Even if you press CAPS LOCK, XBAS turns every small letter into a capital when it stores the line - including the ones inside Pascal's quotes. (XBAS spares only text in double quotes, BASIC's kind of string, which Pascal does not use.) So all your programs will look like the ones in this primer, capitals throughout, and every message they print will be in capitals. A small letter in a message has to be written as a character code: CHR(97) is a.

Square Brackets And Comments

Two things from the Turbo course need a different key here.

[ and ] are typed with the LEFT and RIGHT arrow keys, as they were in Turbo. On the screen they show as arrows, and , because that is how the Einstein draws those two characters. In the file they are brackets, and the compiler reads them as brackets.

{ and } cannot be used for comments. XBAS takes them for BASIC words: type { NOTE } and it stores OR NOTE >, which the compiler then refuses. Write comments with (* and *) instead - they pass through untouched.

Five Characters XBAS Changes

XBAS reads those braces as BASIC even inside quotes - and three more characters with them. Wherever you type them, it stores something else:

You typeXBAS stores
?PRINT
{OR
|XOR
}>
~/

The one you will miss is the question mark. WRITE('READY? ') comes out of XBAS as WRITE('READYPRINT '). When a message needs one, write it as a character code - CHR(63) is ?:

WRITELN('READY',CHR(63))

prints READY?. Every other character on the keyboard goes through as typed.

Saving For The Compiler

The compiler cannot see what is in XBAS's memory. It reads a file from the disc, and the file's name must end .ASC:

SAVE "FIRST.ASC"

Save after every change, before you compile - whatever you changed after the last SAVE is not in the file, and the compiler never sees it. Saving over the old file is fine: XBAS replaces it without asking.

To start a fresh program, NEW empties XBAS's memory. To carry on with a program you saved, LOAD "FIRST.ASC" brings it back. DOS leaves XBAS for the 0: prompt - with the program in its memory gone, so save first.

The Code

A program with an array, to try the arrow keys, and a comment. Type it into XBAS:

10 PROGRAM FIRST;
20 (* THREE NUMBERS *)
30 VAR A:ARRAY[1..3] OF INTEGER;
40 BEGIN
50 A[1]:=4; A[2]:=5;
60 A[3]:=A[1]*A[2];
70 WRITELN(A[3])
80 END.

Then:

LIST
SAVE "FIRST.ASC"
NEW
LIST
LOAD "FIRST.ASC"
LIST

Starting from

The primer's disc, XBAS typed at 0:.

What you should see

The first LIST shows the eight lines, numbers moved to the right, and every [ and ] drawn as an arrow:

    10 PROGRAM FIRST;
    20 (* THREE NUMBERS *)
    30 VAR A:ARRAY←1..3→ OF INTEGER;
    40 BEGIN
    50 A←1→:=4; A←2→:=5;
    60 A←3→:=A←1→*A←2→;
    70 WRITELN(A←3→)
    80 END.

SAVE answers Ready. After NEW, LIST shows nothing. After LOAD, the same eight lines are back. S4 compiles it.

Change One Thing

Make each change after the LOAD, then LIST:

  • Type 70 WRITELN(A[1],A[2],A[3]). What happens to the old line 70?
  • Type 20 on its own. Where has the comment gone?
  • Type 55 A[3]:=0;. Where does it appear in the listing?

Then think ahead: if you compiled FIRST.ASC now, without saving again, which version of line 70 would the compiler see?

Exercises

3.1 Use AUTO to type a four-line program that writes your name, and save it as NAME.ASC.

3.2 Load FIRST.ASC, put a new line between every pair of lines (any comment will do), then RENUM it and LIST it. What numbers do the lines have now?

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
A comment comes back as OR ... >It was typed with { }. Use (* *).
PRINT appears in a messageA ? was typed. Use CHR(63).
A line has a number like 601Its Pascal started with a digit, which XBAS read as part of the line number. Put (**) in front of it (S10).
Branch Error after typing a lone numberThere is no line with that number to delete - or you pressed ENTER on an empty AUTO number, which is how you leave AUTO.
The compiled program does not have your last changeIt was made after the last SAVE. Save, then compile.
The program is gone after DOSLeaving XBAS forgets the program. XBAS, then LOAD "NAME.ASC".

Summary

Type Pascal into XBAS as numbered lines, in capitals, with the arrow keys for [ and ], (* *) for comments and CHR(63) for a question mark. Change a line by retyping its number; delete it by typing the number alone; RENUM tidies the numbers. SAVE "NAME.ASC" writes the file the compiler reads - save after every change. NEW empties, LOAD brings back, DOS leaves.

Next

S4, Compiling And Running - handing FIRST.ASC to HiSoft Pascal.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.