Chapter 9 – Further Programs (Spectrum World Map)Posted: April 20, 2013
The Messier List, check out the fake comets
Telescope, the facts about telescopes, binoculars, cameras and astronomy
Star Tester, a quiz
Ellipses, various ellipses
Spectrum World Map, a map of the world in CHR$ CODE.
Spectrum World Map
One of the problems of producing a picture on the TV screen from a program listing is trying to comprehend what graphics the author intended to be used. The Spectrum is capable of over 44,000 pixel positions (256*175) and it would be quite unreasonable to create a full screen image defining the x and y coordinates of all the pixels to be displayed. It is however quite reasonable to create a simple ‘lo-res’ screen image using the Spectrum chunky graphic set from CHR$ 128 to CHR$ 143 inclusive. This effectively gives a screen resolution of 64*44 pixels (c for chunky!) or 2816 in total.
Fortunately, by selecting the correct graphic characters for each four adjacent pixels a complete screen can be defined in 32*22 character spaces, 704 in total. Now it becomes manageable.
Coding the characters
The simplest way to produce such a screen image is to list 22 consecutive PRINT statements, each containing up to 32 chunky graphic characters, and RUN them. Easy for the programmer but almost impossible for subsequent users to understand. The intended characters must be coded in a legible form that can be keyed in with certainty.
The following program does just that and uses a world map as a demonstration screen display. Once the data has been entered, in a mixture of numbers and upper and lower case letters, the program automatically produces the finished picture via an intermediate coded form. This proves quite interesting to watch.
Key in the program and RUN it. Then enter the lines of coded data line by line from Figure 9.10a. The program is reasonably error-trapped, giving a full opportunity to correct any entry, and is well prompted. Once all 20 lines are completed (two lines are omitted for titling, etc) the program converts the codes into the world map and displays the result recalled by PRINT T$
Figure 9.10: Picture Drawing in Code Form
a) These codes are entered into the program as prompted. The numerics refer to the number of consecutive solid squares — CHR$ 143. The lower case letters refer to the number of blank squares — CHR$ 128.
b) The computer converts the numeric and lower case codes from a) to upper case letters, Tilling each character square.
c) The computer converts the upper case letters in b) to the Spectrum chunky graphic set (CHR$ 128 to CHR$ 143 inclusive). The whole picture is stored in T$ for instant recall.
Saving the DATA
The actual picture is now stored in the DIMensioned T$ array ready to be SAVEd as prompted by the program, the DATA as SAVEd can be MERGEd into other programs as follows:
LOAD “world” DATA T$() ENTER
The picture is still called T$ so beware that this array name is not repeated in the new program: and, of course, the program must be started with GOTO (line number) and not RUN.
This particular program has now done its job and can in theory be discarded. But, before doing so, SAVE the complete program on to tape with GOTO 9990 for use with your own coded pictures.
Making your own coded pictures
The procedure to produce these coded pictures is tedious and is only worthwhile if they are to appear in published form. Page 92 of the Spectrum Manual lists the 16 chunky graphic set characters and these should be marked A through to P, starting at CHR$ 128 as A and finishing at CHR$ 143 as P. The artwork is now prepared on squared paper using page 102 of the Manual for guidance by overlaying tracing paper using the best shapes from the chunky graphic set. These are then converted into letters A to P inclusive as appropriate.
As the bulk of a simple picture is usually either blank or solid black (or any other INK colour) the long strings of AAAAAAAA or PPPPPPP can be compressed in each horizontal line to lower case letters or numerals respectively. Use Figure 9.10a for guidance. For example, the final line:
gGx means AAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAA
where g equals the 7th letter of the alphabet and x the 24th.
Those with programming experience can get the Spectrum to do the conversion of chunky graphics to alphanumeric codes and so ease the task.
50 DIM e$(20,32)
60 DIM z$(20,32)
70 PRINT “WM coder – enter line”
80 FOR n=1 TO 20
90 PRINT AT 0,22;n
100 INPUT “Codes”‘ LINE e$(n)
110 PRINT AT n,0;e$(n)
120 INPUT “OK (y or n)? “; LINE q$: IF q$=”n” THEN GO TO 100
130 NEXT n
140 PRINT PAPER 5;AT 0,0;”*World Map recoded* ”
150 FOR n=1 TO 20: LET h$=””
160 FOR f=1 TO 32: LET x$=””
170 IF e$(n,f)>CHR$ 80 THEN GO TO 220
180 IF e$(n,f)<CHR$ 65 THEN GO TO 250
190 LET h$=h$+e$(n,f)
200 NEXT f: PRINT PAPER 6;h$: LET z$(n)=h$: NEXT n: GO TO 310
220 FOR x=1 TO CODE e$(n,f)-96
230 LET x$=x$+"A": GO TO 280
250 FOR x=1 TO CODE e$(n,f)-48
260 LET x$=x$+"P": GO TO 280
280 NEXT x: LET h$=h$+x$
290 GO TO 200
310 PRINT PAPER 6;AT 0,0;"**World Map** "
320 BORDER 5: LET w$=""
330 FOR n=1 TO 20
340 FOR f=1 TO 32
350 LET t=CODE z$(n,f)+63
360 PRINT INK 2; PAPER 5;CHR$ t;: LET w$=w$+CHR$ t
370 NEXT f: NEXT n: DIM t$(640): LET t$=w$
380 PRINT "T$=World Map – press 's' to save": PAUSE 0
400 SAVE "world" DATA t$()
405 BEEP 1,1
410 PRINT #0;"Rewind/play to verify": VERIFY "world" DATA t$()
430 BEEP 1,1: PRINT FLASH 1;"data saved OK": STOP