BASIC Programming (part 5)

See all articles from Sinc-Link v2 n5
Author(s): Stan Piotrowski
Publication: Sinc-Link
Pub Details: Sinc-Link v2 n5 (Volume 2, Issue 5)
Pages: 1-4

Well here we are again ready to do some more Basic Programming. In this issue, we will use some Hints & Techniques in order to enhance or make your Basic programming better.

Let’s start off with the number of lines you are able to print onto your screen. The manual tells you that you can only print 22 lines (0 to 21) yet it tells you that the display file or the screen size is 32 across by 24 lines down (0 to 23). We actually do have access to this but there are 2 restrictions: we cannot print to 24 lines if there is an INPUT command or a SCROLL command. Otherwise, you can. The ZX-81 have several addresses in your RAM pack that it uses for itself and if you’re not careful in POKEing these addresses, the computer can lock up or go into that wonderful display of a “blizzard in the middle of winter”.

The address that keeps track of the number of lines on your screen is 16418. It normally contains “2” counting from the bottom line up which means that you cannot print on the bottom two lines. To print to the bottom 2 lines; POKE 16418,0. Now you can PRINT AT 23,0;”HELLO THERE”….BUT!!! you can’t stop ther program there; it must continue on. If it stops, you know that you get error codes in the bottom left corner. All error codes are printed on line 23 so it would wipe out your PRINT statement. Therefore, if you enter something like the following lines:

10 CLS
20 POKE 16418,0
30 PRINT AT 10,0;"ENTER A NUMBER"
40 IF INKEY$ = "" THEN GOTO 40
50 LET A$=INKEY$
60 PRINT AT 23,10;"YOUR NUMBER IS: ";A$
70 GOTO 30

Now, you can add more printing data if you should want more on the screen. If you need to use a SCROLL or an INPUT, don’t forget to POKE 16418,2 before these commands. Of course you can do the opposite which can be effective.

Enter the following program and you can see that the printing will stay on the bottom of the screen while you can scroll and input anything:

10 CLS
20 PRINT AT 21,0;"PRESS ANY KEY TO STOP"
30 POKE 16418,10
40 FOR I=0 TO 255
45 SCROLL
50 PRINT CHR$ I
60 IF INKEY$="" THEN GOTO 80
70 GOTO 100
80 NEXT I
90 IF I=255 THEN GOTO 40
100 POKE 16418,2
110 FAST
120 CLS
130 SLOW
140 STOP

Have you ever noticed in some programs (especially game programs with machine code) that the first line is always “0”. You know that if you entered a line number with a zero, then nothing would happen; the ZX-81 refuses to accept it. Fear not; we can also change this too. Simply POKE 16510,0. Now list the program and your first line number will be a “0”. Also notice that you cannot delete this line number. For programmers, they sometimes put in their copyright notice since most novice programmers cannot delete or edit it. By simply reversing the process, you can insert a line number that you can delete or edit; POKE 16510,1 or the same line number as the following line number in your program.

Whenever a program had the command PAUSE, did you notice how jerky it seems such as PAUSE 300. The reason is that it is “Bit” counting the frames on the TV screen. A much smoother effect for waiting a period of time is the FOR/NEXT loop such as:

100 FOR I = 1 TO 300
200 NEXT I

And finally, here’s a short program that displays the calendar month for any year you choose. For those of you learning to program, go through line by line and try to determine exactly what and why the program is doing something. For example, in line #240, the numbers that represent some of the months is determined to have 31 days. It laso checks whether there was a leap year in the year you chose.

  1 SLOW
2 CLS
3 PRINT AT 8,2;"1. HARDCOPY","2. SCREENCOPY"
4 IF INKEY$<>"1" AND INKEY$<>"2" THEN GOTO 4
5 LET P$="0"
6 IF INKEY$="1" THEN LET P$="1"
7 PRINT,,
10 PRINT "ENTER MONTH (1 TO 12)"
20 INPUT M
30 PRINT "ENTER YEAR"
40 INPUT Y
45 FAST
50 LET D=1
60 LET MON=M
70 LET YEAR=Y
80 DIM A$(12,9)
100 LET A$(1)="JANUARY "
110 LET A$(2)="FEBRUARY "
120 LET A$(3)="MARCH "
130 LET A$(4)="APRIL "
140 LET A$(5)="MAY "
150 LET A$(6)="JUNE "
160 LET A$(7)="JULY "
170 LET A$(8)="AUGUST "
180 LET A$(9)="SEPTEMBER"
190 LET A$(10)="OCTOBER "
200 LET A$(11)="NOVEMBER "
210 LET A$(12)="DECEMBER "
220 DIM A(42)
230 LET END=30
240 IF M=1 OR M=3 OR M=5 OR M=7 OR M=8 OR M=10 OR M=12 THEN LET END=31
250 IF M=2 THEN LET END =28
260 LET LEAP=0
270 IFY/4=INT (Y/4) AND Y/100<>INT (Y/100) THEN LET LEAP=1
280 IF Y/400=INT (Y/400) THEN LET LEAP=1
300 IF M=2 AND LEAP=1 THEN LET END=29
310 IF M=1 OR M=2 THEN LET M=M+12
320 IF M=13 OR M=14 THEN LET Y=Y-1
330 LET R=D+2*M+2+INT ((3*M+3)/5)+INT (Y/4)+Y-INT (Y/100)+INT (Y/400)
340 LET NUM =(R/7-INT (R/7))*7
350 LET NUM =INT (NUM+ .5)
360 LET START = NUM
370 IF NUM=0 THEN LET START=7
380 LET DAY =1
390 FOR P=START TO 42
400 LET A(P)=DAY
410 LET DAY=DAY+1
420 NEXT P
430 CLS
440 PRINT TAB 10;A$(MON);" ";YEAR
450 PRINT,," SUN MON TUE WED THU FRI SAT"
470 FOR R=0TO5
480 FOR C=1+R*7 TO 7+R*7
490 LET CC=C-R*7
500 IF A(C)=0 THEN PRINT TAB (4*CC);" ";
510 IF A(C)=0 THEN GOTO 550
520 IF A(C) > END THEN PRINT TAB (4*CC);" ";
530 IF A(C) > END THAN GOTO 550
540 PRINT TAB (4*CC);A(C);
550 NEXT C
560 NEXT R
570 IF P$="1" THEN COPY
580 IF P$="1" THEN GOTO 1
590 SLOW
600 PRINT AT 21,0;"PRESS ANY KEY FOR ANOTHER MONTH"
610 IF INKEY$="" THEN GOTO 610
620 GOTO 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.