Authors
Publication
Pub Details
Date
Pages
In the past year we have mentioned SuperBASIC which is the language which comes built-in on the Sinclair QL. Starting this month we will si\tart looking at this programming language and how it is an improvement over BASIC as we have come to know it.
Upon powerup of the QL, you have three active windows. Window #0 is the default input window, window #1 is the default program listing area, while window #2 is the data output screen. Depending on whether you choose F1 (monitor) or F2 (television) you will either see two or three of those windows. In television mode, windows #1 and #2 are superimposed upon each other, while in monitor mode they are side by side. In each case, window #0 is at the bottom of your screen. These defaults may be left as they are altered and redefined in a number of ways. The QL has the ability to define and use up to a total of 255 windows. Each of these windows act independently of each other and can either be part of a single program, or used by a number of different programs thanks to the QL’s ability to multi-task.
Three keywords can be used to define a new window. The simplest is, logically enough, Window. It is used in conjunction with four parameters; window width, window depth, and the pixel coordinates of the top left hand corner. You will also have to link the window to a channel which will be used in the event that you are defining or using more than one window. (If you are only using a single window this is not necessary.) The format is: WINDOW x-width, y-width, x-coord, y-coord
Once defined, each window may be further defined as to Border, Paper and Ink. In addition, Strip, Pan, Scroll and Cursor may be used within any selected window.
In order to properly place your window, you will need to be familiar with the pixel system on the QL. (Don’t confuse this with the graphics coordinate system which starts in the bottom left hand corner and can be scaled-but more on this at a future point in time.) The upper left hand corner in the pixel system is designated 0,0. For purposes of defining windows, the screen goes from 0 to 512 from left to right (the x axis) and from 0 to 256 (they axis) from top to bottom. Attention does not have to be strictly paid to whether you are in medium or high resolution mode.
Therefore, to define a window which will take up the entire screen, try this:
100 WINDOW 512,256,0,0
110 PAPER 4
120 CLS
As you see when you RUN this, whether you were in medium or high resolution mode, you now have a screen which is a solid color covering the entire useable area of your display. Try typing in CLS; CLS #0; CLS #1 and CLS #2. What happened? Can you explain it? What you are seeing is the fact that although you have defined a large window, you have not lost other default windows, and when you CLS that screen they reassert their existence.
Windows defined in this manner may be used to output data from a program, or to INPUT required data. Using the INPUT command and adding the necessary channel designation to that command, you are able to request and enter data in the usual manner. If there are a number of channels open with the ability to INPUT data, a flashing cursor will be present at the position where it will accept the INPUT. To alternate between available channels press CTRL-C. The flashing cursor will move from window to window as it selects the channel from which it expects data INPUT.
As with the previous WINDOW command, you will need a few parameters to OPEN a Console. To open such a device to channel 7 the for- mat would be as follows:
OPEN #7, con _ width x depth a xcoord x ycoord
This can be read as “OPEN to channel 7 a console device of width by depth at the point defined by xcoord and ycoord.” Note the “x” between the width and depth specifications as well as the coordinate locations. The “a” between the two sets of parameters must also be included.
Another parameter can be added at the end of this configuration which specifies the size of the print ahead keyboard buffer.
There is another command which is used in the same manner as con_ except that it cannot be used as INPUT. By replacing con_ with scr_ you can open such a window.
Another feature of SuperBASIC is its ability to write Procedures which can be called by name either from within a program or in the immediate mode. Using these procedures can, in almost all cases, eliminate the need for subroutines. A procedure is defined by name, followed by the routine and finally an end-marker. The following procedure is a simple one which only asks for some INPUT. I have named this procedure “ask,” but you can give it any designation you wish.
1000 DEFine PROCedure ask 1010 CSIZE 2,0 1020 INPUT “Enter any number you like: ” ; num 1030 END DEFine ask
(A note here about SuperBASIC keyword abbreviations is in order. The one stroke keywords which we have come to know on Sinclair computers do not exist on the QL, but you have the ability to enter-letter by letter-shortened forms of certain keywords. You can identify these keywords by the fact that portions of the command is in capitals while the remaining portions are in lower case letters-regardless of whether you typed them in upper or lower case. You have the option of only entering the shortened version or the entire keyword. It will appear in its entirety in the program listing in either case.)
Now add this short procedure for printing your number. We will call this procedure “show.”
2000 DEFine PROCedure show 2010 CSIZE 3,1 2020 PRINT num 2030 END DEFine show
If you RUN this program as it stands, you will find that absolutely nothing at all happens! In order to use these procedures, we will add a short program.
100 REPeat demo 110 ask 120 IF num = 999 130 PRINT “BYE-BYE” 140 STOP 150 ELSE 160 show 170 END IF 180 END REPeat demo
We have set this up so that it will continue to run until you enter the number 999 when requested. (Can you now rewrite this program to take advantage of more than one window? Try it and send your best effort to me in care of Computer Shopper and I will share the best demonstration of these techniques.)
Notice, as well, that we have used a number of other SuperBASIC features in this small program. First we will look at the command CSIZE which appears in lines 2010 and 1010.
CSIZE (which stands for character size) allows the programmer to define the size (height and width) of the characters shown on the screen. It requires a designation for both parameters and may include an optional channel number if you are defining the size in a window other than window #1. The format for this is:
CSIZE [optional channel,] width, height
The width may be specified by a number in the range 0-3. Width defines the horizontal size of the character space. A 0 = 6 pixels; 1 = 8 pixels; 2 = 12 pixels and 3 = 16 pixels. Height defines the vertical size of the character space – 0 = 10 pixels and 1=20 pixels. Once the character space is defined by this command, the character will automatically adjust to fill the space available.
The default character size in high resolution mode is 0,0 and the corresponding default for medium resolution mode is 2,0. Using this command you can adjust the size of the character to match a particular window size or just to attract attention. It is also used for title screens or page headings.
You will also notice the REPeat loop used in lines 100-180. In previous versions of Sinclair BASIC, you could form a loop in two ways- using a GOTO statement or an IF…THEN routine. SuperBASIC adds an additional type of looping procedure… the REPeat loop. This is used by defining both the start and end of the loop in a manner similar to that used in defining a procedure. One thing to keep in mind when using this command (or any loop for that matter) is to create a way out for yourself. In this case our “escape valve” is shown in lines 120-140. We have arbitrarily selected the value of 999 to terminate the execution of this program. The use of the IF.. ELSE construction is shown here.
The REPeat loop starts off by calling the “ask” procedure we have created in which the user is asked to INPUT a value. Once the procedure is completed, the program continues at the statement after which “ask” was called. In this case it is the beginning of the IF…ELSE routine. The variable “num” is checked to see if the value is 999. IF it is indeed 999, the words “BYE- BYE” are printed and the program execution is halted. If the value is anything other than 999 the ELSE part of this construction comes into play and the value is printed to the screen by calling the procedure which we have called “show.” Once that is done and the END REPeat statement is en- countered the program loops back to the beginning as defined by the REPeat statement. Although not immediately noticeable, the QL does contain a realtime clock which is running all the time the QL is powered. Due to the fact that there is no constant power source to the clock chip, the time and date must be set each time you turn the QL on if you are going to use this information.
The SuperBASIC command to set the clock is SDATE. The format is:
SDATE year, month, day, hours, minutes, seconds
Accordingly, the way you would set 2:35 P.M. on December 10, 1986 would be: SDATE 1986,12,10,14,35,0
Notice that 2:00 P.M. is entered as 14 using the 24 hour clock. Once this is set, the QL will automatically know what day of the week is correct and you will not have to set it although you may request that information along with the rest of what you have just entered.
To retrive this information from SuperBASIC you would use the function DATE$. This will return a string in the form: YEAR MONTH DATE HOUR MINUTE (S) SECOND(S) As with any other string you may slice portions of it to suit your needs, such as placing some of this information in a separately created window onscreen which constantly displays the current information. (Next month I will show you how to accomplish this.) Using the function DATE (no $) will return the date as a floating point number which you may use to store dates and times in a more compact form.
To get the day of the week you would use the function DAY$ which will use the date information to compute and present the current day of the week. When using ARCHIVE (database) you may want to create a form such as an invoice, purchase order, or any other form or report on which you require the time and date of its printing. Although ARCHIVE uses its own set of commands for this, you still must set the QL’s clock upon powerup in this fashion before you load ACHIVE.
A final command relating to the clock functions is ADATE. ADATE is used to adjust the clock without going through the SDATE function. ADATE followed by a number of seconds (may be positive to set the clock ahead, or negative to set the clock back) will make fine adjustments. For example-ADATE 3600 will advance the clock by one hour while ADATE-60 will move the clock back one minute. This is just our first look at the power of SuperBASIC which will continue on an ongoing basis. If you have a short program which can be used as a demonstration of some feature of the QL, QDOS, SuperBASIC or any other aspect of the computer’s operation, send it to me in care of Computer Shopper and I will share the best ones.