PLOT, CLS and SCROLL on the TS2068

See all articles from Sinc-Link v4 n1
Author(s): Cameron Hayne
Publication: Sinc-Link
Pub Details: Sinc-Link v4 n1 (Volume 4, Issue 1)
Date: January/February 1986
Pages: 10

Cameron Hayne
[address omitted]
U.K.

In a previous article, I discussed how to use the ROM routines for printing from machine code. In this article I will explain a bit more about some of the other display routines in the ROM. Some of this will have easy application from BASIC and so I will give addresses in decimal as well as in hexidecimal. The corresponding addresses for the SPECTRUM will be given in parentheses.

To PLOT a point on the screen is very easy from machine code and vastly faster than from basic. First you must load the BC register pair with the pixel coordinates of the point to be plotted: B=y coordinate, C=x coordinate. Then you call the ROM routine and voila! The ROM routine is at hex 263E, decimal 9790 (hex 22E5, decimal 8933). For example:

LD BC,#00FF (the # indicates hex)
CALL #263E will plot a point at the right hand bottom of screen

The ROM routine uses the “temporary” attributes when plotting a point and these can be set using RST #10 as I explained in the previous article. Note that the BASIC PLOT command automatically sets the attributes to FLASH 8 ; BRIGHT 8 ;PAPER 8 and it may be be necessary to do this when PLOTing from machine code in order to not disturb what is already on the screen.

As you know from BASIC, the screen is split into two parts : the main screen (rows 0-21), and the lower screen where the reports are printed. The size of the lower screen is determined by the system variable DF_SZ at address hex 5C6B, decimal 23659. (Since IY is supposed to be hex 5C3A, this can also be referred to as IY+49 decimal or IY+31 hex.) Usually (DF_SZ)=2 but the lower screen can be expanded to more than two rows or contracted to zero by poking DF_SZ. (But make sure it is at least 2 before returning to BASIC!) The attributes for the lower screen are contained in BORDCR. You can print on the lower screen from BASIC using PRINT #1; etc. and the AT coordinates are taken as relative to the top of the Lower screen. (Thus 0,0 is the first position in the lower screen.) When you do this, the lower screen expands as necessary. The same can be done from machine code by first changing the stream with: LD A, 01 ; CALL #1230 (SPECTRUM #1601). Whereas the whole screen can be cleared by CALL #08A6, decimal 2214 (#0D6B, decimal 3435), the lower screen alone can be cleared by CALL #08A9, decimal 2217 (#0D6E, decimal 3438). On the other hand, if you wanted to clear a certain number of rows at the bottom of the screen (disregarding the boundary between the lower and main screens), you could do this by loading the B register with that number and calling the ROM routine at hex 097F, decimal 2431 (hex 0E44, decimal 3652). For example: LD B, #0C ; CALL #097F would clear the bottom half of the screen.

My final topic is scrolling. The BASIC PRINT routines are the RST #10 routine will issue a “Scroll?” query when they have reached the end of the main screen (when (DF_SZ)=2 as usual). Automatic scrolling of the whole screen can be achiened by poking the system variable SCR_CT with a number bigger than one. To scroll a certain number of rows at the bottom of the screen (disregarding the boundary between the lower and upper screens) up one row, you load the B register with the number of rows, then call the ROM routine at hex 039B, decimal 2363 (hex 0E00, decimal 3584). For example: LD B, #0B ; CALL #093B would scroll the bottom half of the screen up one row.

Here is a short demonstration program:

  1 GOTO 100
10 DEF FN H(x)= INT(x/256): DEF FN L(x)=X-256*FN H(x)
20 RESTORE
30 READ byte : IF byte <> PI THEN POKE address, byte : LET address = address + 1 : GOTO 30
40 RETURN
50 DATA 6, n, 205, FN L (romaddr), FN H (romaddr), 201, PI
100 LET address = 60000 : LET n = 12
110 LET clsbottom = address : LET romaddr = 2431 : GOSUB 20
120 LET scroll = address : LET romaddr = 2363 : LET n=n-1 : GOSUB 20
200 FOR r = 0 TO 21 : PRINT "row ";r: NEXT r
210 FOR r = 0 TO 1 : PRINT # 1; AT r, 0; "lower row ";r: NEXT r
220 PAUSE 200
230 PRINT AT 12, 10; "POOF !" : PAUSE 20: RANDOMIZE USR clsbottom
240 PRINT #1; AT 1, 0; RND
250 PAUSE 20 : IF USR scroll THEN GOTO 240

Now that I am in England and my public library has about 100 books on the Spectrum (but 90 % out on loan) I am discovering some good sources of information. Most people will already know of “The Complete Spectrum ROM Disassembly” by Drs. Ian Logan and Frank O’Hara (Melbourne House, 1983). Their annotations are excellent and the book is invaluable to me. A new discovery is “The Spectrum Operating System” by Steve Kramer (MicroPress, 1984). He explains how to use many of the ROM routines, including the floating point calculator, the microdrive routines and how to use the Interrupts. I thought it worth the £6.00 asking price and now own a copy. An excellent general reference book on the Z80 machine code is “Z80 Assembly Language Subroutines” by Leventhal & Saville (Osbourne/McGraw-Hill, 1983)