
Good morning Class! How are you today? Will someone nudge that fellow in the back seat and wake him up? Thank you.
Today’s discussion will be on graphics. As most of you know, the ZX-81 and T/S-1000 computers come with graphics characters to be entered directly from the keys. This is not true of most other microcomputers.
Key-entered graphics represent an easy method for the user to realize the desired effect he or she wishes to achieve. These same graphic characters can be generated on the screen by another method, however. Does anyone know what that might be?
Yes, the gentleman in the rear has his hand up?
I don’t think the class heard his reply so I’ll repeat it.
He says we can write a program that will peak the ROM memory locations and and have it transfer the character data held in these locations, to areas of the screen designated by another routine that would map the screen co-ordinates.
A suprising and in depth answer, I might say, especially from one who was sound asleep only two minutes ago. As usual, it is not the answer I was looking for, although, in essence, the correct method does exactly that.
The answer is to use the character string or CHR$ function. If all of you would turn to the character set section of the user’s manual on page 137, you will see the Sinclair character codes for the ZX-81 and T/S-1000 which are numbered from 0 to 255.
After looking over this list, we might enter this simple program into our computer:
5 PRINT TAB 3;"CHARACTER CODE
GENERATOR"
10 PRINT AT 20,0;"WHICH
CHARACTER WOULD YOU LIKE",
"TO SEE?"
20 INPUT A
30 PRINT AT 10,10;A;" - ";
CHR$ A;"
40 GOTO 10
Upon RUNning this program we find that we can generate any of the listed characters by entering the corresponding code.
You will notice that lines 10 and 30 PRINT the information at specified co-ordinates on the screen. These locations can be identified from the chart on page 89 of the ZX manual and 67 of the T/S manual.
In other BASICs, the capability of generating lines of multiple characters exists through the STRING$ function. The format STRING$(n,c) would be used where (n) is the number of characters you want to appear in a row and (c) is the CODE of the character itself. This function is useful in producing graphic displays both for the screen and for print-outs.
Unfortunately it doesn’t exist for the ZX-81 and the T/S-1000. It can be simulated in 4 program lines, however.
Let us say that we wanted a string of the character (*), code number 151 to appear on the screen in two layers or lines. We could accomplish this with the following line number:
10 PRINT "(inverse *)(inverse *) ...
(64 times)"
or –
10 PRINT CHR$ 151 + CHR$ 151 ... (64
TIMES)
If we wanted to fill the screen with these characters we would have to enter these characters 704 times – a very tedious procedure indeed.
Enter the following program:
10 LET A$ =""
20 FOR N = 1 TO 64
30 LET A$ = A$ + "(inverse *)"
or
30 LET A$ = A$ + CHR$ 151
40 NEXT N
100 PRINT A$
The first four lines simulate the STRING$ function exactly. Line 100 PRINTs the string of characters. We can print this string as many times as we want or as the screen will allow by entering the following lines:
90 FOR N = 1 TO 10
110 NEXT N
On a 2K and 16K machine the screen will have 20 lines of inverse asterisks. On a 1K machine there will be somewhat less.
MOVING GRAPHICS
In some programs, particularly games, we may have noticed graphic characters or sets of characters that move across the screen either up or down, sideways or at angles. Let us write a routine that takes a 16 character string by changing the 64 in line 20 to 16 and moves it in snake-like fashion from the top of the screen to the bottom.
Delete lines 90, 100 and 110 and add the following lines:
50 LET A = 0
100 FOR N = 0 TO 31
110 PRINT AT A,N; A$
120 PRINT AT A,N; " "
130 IF N = 31 THEN LET A =
A + 1
140 NEXT N
150 GOTO 100
Has anyone seen anything similar to this effect in any of the Synchro-Sette subscription cassette programs? Yes, the gentleman in the back again?
That’s right! The Marquee and the Bulletin Board programs use this effect.
But perhaps you would like to see something more intricate – something with a little more pizazz – something that shows movement in more directions than just one.
Enter the following program:
10 LET A$ = "(inverse *)"
100 FOR A = 5 TO 15
110 FOR N = 1 TO 10
120 GOSUB 1000
130 NEXT N
140 NEXT A
150 FOR A = 5 TO 15
160 FOR N = 30 TO 21 STEP -1
170 GOSUB 1000
180 NEXT N
190 NEXT A
200 FOR N = 11 TO 20
210 FOR A = 1 TO 5
220 GOSUB 2000
230 NEXT A
240 NEXT N
250 FOR N = 11 TO 22
260 FOR A = 20 TO 15 STEP -1
270 GOSUB 2000
280 NEXT A
290 NEXT N
300 LET A$ = "SINCLAIR"
310 LET A = 9
320 LET B = 8
330 FOR N = 19 TO 12 STEP -1
340 PRINT AT A,N; A(B)
350 LET B = B - 1
360 NEXT N
370 LET A$ = "COMPUTER"
380 LET A = 11
385 LET B = 1
390 FOR N = 12 TO 19
400 PRINT AT A,N; A$(B)
410 LET B = B + 1
420 NEXT N
430 LET A = 7
440 LET N = 19
450 GOSUB 3000
460 LET A = 13
470 GOSUB 3000
480 LET N = 12
490 GOSUB 3000
500 LET A = 7
510 GOSUB 3000
999 GOTO 430
1000 PRINT AT A,N; A$
1010 PRINT AT A,N-1; " ";
AT A,N+1; " "
1020 RETURN
2000 PRINT AT A,N; A$
2010 PRINT AT A-1,N; " ";
AT A+1,N; " "
2020 RETURN
3000 PRINT AT A,N;CHR$(( INT
(11 * RND) + 128 ))
3010 RETURN
SYNTACTIC SUM = 56493
This program will RUN comfortably in 2K. The routines to provide movement are covered in the up, down and sideways directions.
Lines 100 to 140 provide left to right motion. Lines 150 to 190 provide right to left motion. Lines 200 to 240 provide up to down motion and lines 250 to 290 provide down to up motion. Subroutine 1000 provides the coordinates for the graphic characters to appear and erases the old graphics characters to give the appearance of movement.
The routines starting at lines 300 and 370 allow the message words to appear on the screen one character at a time and the routine starting at line 430 along with subroutine 3000 provides the changing graphics characters.
Words are printed onto the screen from two different directions and random graphics characters are displayed from four different positions.
Parameters are set in each routine to limit the distance each graphic character will travel.
There is another method of generating a different form of graphics to the screen. Does anyone have an idea what this might be?
Who else! Go ahead, Sir.
Wrong again as usual.
The gentleman in the rear stated that we can POKE graphics directly onto the screen. Although the Sinclair machines have this capability in a limited fashion as evidenced in the LABYRINTH program, it is usually beyond the scope of normal BASIC programming methods to accomplish it.
Does anyone else have an idea? Yes, the lady in the front?
Yes, that’s right – by using the PLOT and UNPLOT commands.
Enter the following program and the RUN it:
100 LET X = 1
110 LET Y = 1
120 IF Y = 42 THEN GOTO 200
130 GOSUB 1000
140 LET X = X + 1
150 LET Y = Y + 1
160 GOTO 120
200 IF X = 62 THEN GOTO 300
210 GOSUB 1000
220 LET X = X + 1
230 LET Y = Y - 1
240 GOTO 200
300 IF Y = 1 THEN GOTO 400
310 GOSUB 1000
320 LET X = X - 1
330 LET Y = Y - 1
340 GOTO 300
400 IF X = 1 THEN GOTO 120
410 GOSUB 1000
420 LET X = X - 1
430 LET Y = Y + 1
440 GOTO 400
1000 PLOT X,Y
1010 UNPLOT X + 1,Y + 1
1020 UNPLOT X - 1,Y + 1
1030 UNPLOT X + 1,Y - 1
1040 UNPLOT X - 1,Y - 1
1050 RETURN
SYNTACTIC SUM = 30794
Kinda reminds you of those old Pong games that were so popular a few years ago, doesn’t it?
As you can now see, we have angular motion in all directions. This program will also RUN in 2K and will cycle about 6 times before the coordinates it is told to PLOT and UNPLOT are of illegal values. An excellent exercise for you students is to try to rewrite this program so that the coordinates that are generated are always in the legal area of the screen.
The secret to achieving moving graphics is to place a graphics character at a certain position on the screen and then erase it and place another right next to it in the direction you want the character to appear to move. FOR/NEXT loops are the most common way of accomplishing this.
If one were to combine these techniques with the ones used for generating a screen memory map as we discussed in the MAY/82 lesson, we could write a program like BOUNCING-BOMBS.
I would like to have each of you write a short program utilizing both of these methods and have it ready for the next class.
HEY, WHERE ARE YOU ALL GOING? CLASS ISN’T DISMISSED YET.
HEY – COME BACK – I WAS ONLY KIDDING ………………
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.