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
14

Where Text Goes

Introduction

The Turbo course's S23 had ClrScr and GotoXY. HiSoft Pascal has neither - and needs neither, because the Einstein's screen understands a couple of control characters of its own, and WRITE can send them. With a three-line procedure you have GotoXY back.

Clearing The Screen

PAGE clears the screen and puts the cursor at the top left - Turbo's ClrScr.

Moving The Cursor

Write CHR(29), then a column, then a row, and the next thing written goes there:

WRITE(CHR(29),CHR(5),CHR(10),'A')

puts an A in column 5 of row 10. Note two things. The two numbers go in as characters, with CHR. And they count from 0: columns 0 to 39, rows 0 to 23, (0,0) the top left - where Turbo's GotoXY counted from 1. A number past the edge is ignored, and the cursor stays where it was.

CHR(30) on its own sends the cursor to the top left without clearing anything.

GotoXY, Back Again

Wrap it in a procedure that takes Turbo's numbers, and your Turbo habits carry straight over:

PROCEDURE GOTOXY(X,Y:INTEGER);
BEGIN
WRITE(CHR(29),CHR(X-1),CHR(Y-1))
END;

GOTOXY(1,1) is the top left, GOTOXY(40,24) the bottom right. Do not write in that last cell: as in Turbo, it makes the whole screen scroll up a line.

Colour

TCOL(F,B) sets the colours of the text written after it: F for the letters, B for the background behind them, numbers from the manual's table of sixteen. Three useful ones:

TCOLGives
TCOL(15,4)White on blue - the screen's ordinary colours
TCOL(15,6)White on dark red
TCOL(1,11)Black on light yellow

Set it back with TCOL(15,4) when you are done, or everything after - the 0: prompt included - carries on in your colours.

The Code

10 PROGRAM BOX;
20 VAR I:INTEGER;
30 PROCEDURE GOTOXY(X,Y:INTEGER);
40 BEGIN
50 WRITE(CHR(29),CHR(X-1),CHR(Y-1))
60 END;
70 BEGIN
80 PAGE;
90 WRITE('TOP LEFT');
100 FOR I:=10 TO 30 DO
110 BEGIN
120 GOTOXY(I,5); WRITE('#');
130 GOTOXY(I,15); WRITE('#')
140 END;
150 FOR I:=6 TO 14 DO
160 BEGIN
170 GOTOXY(10,I); WRITE('#');
180 GOTOXY(30,I); WRITE('#')
190 END;
200 TCOL(15,6);
210 GOTOXY(16,10); WRITE('EINSTEIN');
220 TCOL(15,4);
230 GOTOXY(1,20)
240 END.

Starting from

BOX.ASC saved from XBAS; HPEIN BOX.

What you should see

The screen clears; TOP LEFT in the corner; a box of # from column 10 to 30 and row 5 to 15; EINSTEIN in white on dark red in the middle of it; and the 0: prompt near the bottom, in the ordinary colours.

Change One Thing

  • In line 50, swap CHR(X-1) and CHR(Y-1). What happens to the box - and why does part of it go missing?
  • Take out line 220. What colour is the 0: prompt afterwards?
  • Change line 230 to GOTOXY(40,24); WRITE(CHR(42)). Where has the box gone?

Exercises

14.1 Write your name in the middle of an otherwise empty screen.

14.2 Count down from 5 to 1 in the same place on the screen, each number replacing the last, and then write GO. (A FOR loop of a few thousand empty passes makes a pause - S5.)

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
Everything is one row down and one column rightThe numbers after CHR(29) count from 0. Take one off Turbo's.
The drawing is turned on its sideColumn and row the wrong way round: column first.
Part of a drawing is missingA row past 23 or a column past 39 - it is ignored.
Everything has moved upSomething was written in the bottom-right cell.
The prompt is in odd colours after a programIt left TCOL set. End with TCOL(15,4).

Summary

PAGE clears the screen. CHR(29), a column and a row - counting from 0 - move the cursor; CHR(30) sends it home. A three-line GOTOXY procedure gives you Turbo's version back. TCOL colours text; TCOL(15,4) puts it back.

Next

S15, Keys Without ENTER - INCH, and why it needs (*$C-*).

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.