CHARACTER GRAPHICS-PART III
CHARACTER GRAPHICS-PART III
By GEOFF CORRY
In part 3 of this series, I will show how the computer stores the character set, try out a fundamental way to form characters, and jumping ahead, type in and display a special message program.
First, lets look at another device that works with characters:- the typewriter. the familiar typewriter stores its characters on the end of long fingers that swing up and hit the inked ribbon onto the paper. If you have acess to a typewriter, gently press the "A" key and look at the tip of the metal finger that has lifted. At the end, you will see the "A" and below will be the lower case "a". The rest of the characters are stored on similar arms, one set of two for each key. Newer and more expensive typewriters , such as the I.B.M. Selectric or the Olympia store their character sets on a "type ball" or on a "daisy wheel" respectively. This feature of removable type sets, allows one to choose various styles of print, "pica", "elite", or "cursive", being some of the more common. A group of characters of the same style is known as a FONT, a word that is used frequently when describing modified character sets on the computer.
The ATARI computer stores its characters in a special area known as Read Only Memory or ROM (how about that!). This area is mainly above the memory space that stores your favorite game or basic program. Each character description takes eight consecutive memory locations. In the same package with your Basic Computing Language cartridge, is the Basic Reference Manual. On page 55, or thereabout, you will find TABLE 9.6- INTERNAL CHARACTER SET. This table shows the sequence in which all characters are stored in memory. Lets see if we can look at letter "A" as we did on the typewriter. On TABLE 9.6, column 2, we find that the "A" has a number 33. Now each of the previous characters each took up 8 memory locations for a total of 256. Therefore our letter "A" has its description in the next 8 memory cells, which count 257 to 264 cells from the character set origin (CHORG). In the last program, we defined CHORG as memory location 57344. Let's see if this works out. Type in this one liner in immediate mode (no line number):
A=57344+(33*8):FOR I=A TO A+7:PRINT PEEK(I);" ";:NEXT I
When you type this in, make sure there is only one space between PRINT and PEEK. After you hit RETURN, you should see a row of 8 numbers.
Now to get these 8 numbers to look like a letter 'A'. Each character on most computers is formed by dots on an 8 by 8 grid, where each number informs the computer what to put on each of the 8 rows. The next is tricky but important:- Each number, when broken down as a 'BINARY CODED DIGIT', tells the computer where it should put the dots along the row. The binary coded numbering system uses only the digits '0' and '1' to express any number up to the limit of the computer. This system is the essence of all digital computers. Inside any computer, it is either switching something on (digit 1), switching something off (digit 0), or comparing two digits (both 1's? or both 0's?).
We will now break our 8 numbers, printed by the 'one liner' above, into the pattern on an 8 by 8 grid that shows the 'A' as the ATARI does it. Here is the grid and the numbers for each row and column:
1 2 3 4 5 6 7 8
1:0:0:0:0:0:0:0:0: = 0 |
2:0:0:0:1:1:0:0:0: = 24 |L
3: : : : : : : : : = 60 |T
4: : : : : : : : : =102 |E
ROW :-:-:-:-:-:-:-:-: |R
5: : : : : : : : : =102 |
6: : : : : : : : : =126 |
7: : : : : : : : : =102 |
8:0:0:0:0:0:0:0:0: = 0 |
2 6 3 1
8 4 2 6 8 4 2 1
The first number is '0', so there are all zeros in row 1. The second number is 24. The computer looks at this number and sees that it is less than 128 (column 1), less than 64 (column 2), less than 32 (column 3), so it puts zeros in row 2, columns 1 to 3. There is a 16 in 24, so it puts a '1' in the 4th column. 16 from 24 leaves 8, (sounds like primary school - no offence, all you primary school readers) and 8 is what is required for column 5, so a '1' goes in. This uses up our number 24, so zeros go in columns 6 to 8.
Now I'm going to put you to work, primary school here we come! Fill in the rows 3 to 8. Oh, I'll give you row 8, it's all zeros. (Don't cheat and read on.)
If this worked out alright, you should have 1's in columns 3 to 6 of row 3, and of course 0's in the rest. Next 1's go in columns 2 & 3 and in 6 & 7 of rows 4,5, and 7. Row 6 will have 1's in columns 2 to 7 to make up the bar in the 'A'. By the way, the reason that rows 1 and 8 are blank is to give separation between letters in different rows on the screen. (Some lower case letters like g, j, p, q, and y use row 8 for the decenders.) To see other letters or symbols, substitute the 33 in our 'one liner' with the appropriate number in Table 9.6. Draw up your 8 by 8 grids or use a pad of engineering paper (1/4 in. squares) available from most stationers.
Now this is a fair amount of work to do manually, so lets see if you can make up a small program that converts a decimal number into a series of binary numbers. For this exercise, we will assume that decimal numbers don't exceed 255. When you get it working properly, send us a copy. The first three programs with your names will be printed in our next issue. Let us know what your computer interests are, and what you feel would be helpful in future articles in BEGINNER'S LINE.
Now that we have an idea of how ATARI makes up its character sets, lets try modifying some of them. To do this we have to copy the original set down into a memory area where we can make changes. For those that have been following past issues of this series, delete lines 12,14,42,and 44. For those who are new here, type in the following and save it, we will be changing and adding to it later.
20 GRAPHICS 0
50 FOR CH=0 TO 1023
60 POKE START+CH,PEEK(CHORG+CH)
70 NEXT CH
80 POKE CHBAS,RAMNEW
Now everyone, add the following lines:
200 FOR I=0 TO 31:READ A
220 NEXT I
230 POS. 19,10:? "ab"
240 POS. 19,11:? "cd"
500 DATA 0,7,31,63,127,127,255,255
510 DATA 0,208,228,228,220,204,172,128
520 DATA 255,255,127,127,63,31,7,0
530 DATA 128,172,204,220,228,228,228,0
Lines 10 to 80 copy the character set down into RAM. Line 200 reads the 32 data statements that will modify the characters. Line 210 puts the new character statements in memory where the old descriptions of letters 'a','b','c', and 'd' were. Line 220 loops back to line 200. Lines 230 and 240 group our newly defined characters in the middle of the screen. Lines 500 to 530 give new shapes to our four letters. Note that the 97 in line 210 is the number for 'a' in Table 9.6. O.K. Run the program. Voila! An old friend.
Try one yourself. Make up a grid with 16 by 16 squares. (Four 8 by 8's in a cluster.) Trace out a shape, say a happy face, star, flower, etc. Now fill in the squares inside the shape with 1's. When you have finished, look at the top left group of 8 by 8 squares and row by row, work out the eight numbers that the 1's represent. Substitute those 8 numbers in line 500. Repeat this procedure for the top right group of squares, and modify line 510. Do the same for the bottom left group into line 520, and the last group into line 530.
Complicated shapes require more squares and eat up more of the character set. But for greater definition and realism, its worth it. A horse, dog, cat, etc. will need a cluster of at least 6 by 4 modified characters to show a recognizable animal. Highrise buildings can be shown with a 4 by 10 cluster, where the top two layers show the roof in perspective, the middle 6 could be the same pattern for each floor, and the bottom two layers could show the entrances and some landscaping.
After you have done a few shapes, you will wonder if there isn't an easier way. Well there is! A font editing program will take most of the drudgery out of designing each square by displaying what it looks like, and then showing the data for your program. Here is a list of some font editing programs that are available.
Fontedit in "IRIDIS 2" by the CODE WORKS
GRAPHIC GENERATOR by Mark Riley from Datasoft Inc.
INSTEDIT from Atari Program eXchange
SUPERFONT in "The First Book of Atari Graphics" by COMPUTE! Books.
THE NEXT STEP by Sierra OnLine
T.T.#8, CHARACTER GRAPHICS by Educational Software
Also there are some recent articles on font editing as follows:
ATARI PRINTFONT by Jerry White in ANTIC, April 1983
ATARI PROGRAMMABLE CHARACTER EDITOR by Tom Marshall in MICRO #66, Nov.83
Create Your Own Custom Character/Graphics by Tony Messina in A.N.A.L.O.G. #5.
COMPUTER ANIMATION by M. Waite and D. Fox, a series started in the Spring'83 Edition and continuing.
Custom Characters On Atari by Charles Delp in COMPUTE!,June 1983
REDEFINE CHARACTERS by Kathy and Phil Bergh in ANTIC, Aug. 1983
As was mentioned previously, this was only a partial list and to those producers of font editing utilities that were missed, my apologies.
For those who wish to type in a font editor, see the article in this issue, CHARACTER GRAPHICS MADE EASY by Bob Cockroft.
Now finally, here is the special message progam. In this program which I have redefined the first 16 lower case letters "a" to "p" (characters 97 to 112 in Table 9.6). To avoid having to count long spaces between characters, I have used lots of POSITION statements, but still be careful with all those 'o's and 'p's (they can be hilarious at times). Also take care with those data statements in lines 500 to 650 that redefine the characters. They are in the same order as the characters, so there is a clue if you have problems with some of the shapes. The lines from 230 to 450 correspond to lines 1 to 23 on your screen. You may want to modify lines 460 and 470 for your own personal message. Line 20 has been modified with a POKE statement to supress the cursor. Line 45 is added to save time when rerunning the program, and line 100 adds a little color to our Graphics 0 display. Next time we will talk about several ways to get color into your graphic displays. Until then, the message in this program says it all.
20 GR. 0:POKE 752,1
45 IF PEEK(START+1022)=16 THEN 80
50 FOR CH=0 TO 1023
60 POKE START+CH,PEEK(CHORG+CH)
70 NEXT CH
80 POKE CHBAS,RAMNEW
100 SE. 1,0,0:SE. 2,0,10
200 RESTORE :FOR I=0 TO 127:READ A
210 POKE (START+(97*8)+I),A
220 NEXT I
230 POS. 21,1:? "op":POS. 31,1:? "abc"
240 POS. 19,2:? "opop":POS. 29,2:? "djnfg"
250 POS. 16,3:? "oopopop":POS. 29,3:? "hjnfi"
260 POS. 13,4:? "oopop opop":POS, 28,4:? "djnfi"
270 POS. 1,5:? "op":POS. 6,5:? "oop oopop op ooop":POS. 29,5:? "klm"
280 POS. 2,Q:? "opoopopopopop op":POS. 21,6:? "op":POS. 37,6:? "oop"
290 POS. 3,7:? "opopopoop op":POS. 21,7:? "op":POS. 36,7:? "op"
300 POS. 3,8:? "opopop oop":POS. 25,8:? "op":POS. 37,8:? "oop"
310 POS. 3,9:? "opopoop":POS. 32,9:? "oop op"
320 POS. 3,10:? "opop":POS. 28,10:? "op opop ooop"
330 POS. 3,11:? "op":POS. 20,11:? "oop":POS. 26,11:? "ooop opoop"
340 POS. 19,12:? "oop oooopop ooop"
350 POS. 17,13:? "oopop opopoop"
360 POS. 14,14:? "opop op opop"
370 POS. 7,15:? "op":POS. 17,15:? "oopopopop"
380 POS. 3,16:? "oop op":POS. 14,16:? "op opoop"
390 POS. 2,17:? "op opopopoopopooop"
400 POS. 1,18:? "op ooopop op"
410 POS. 1,19:? "op opopop op"
420 POS. 1,20:? "op opopop":POS. 22,20:? "TO:- "
430 POS. 1,21:? "op op"
440 POS. 2,22:? "op op":POS. 14,22:? "FROM:- "
450 POS. 3,23:? "oop"
460 POS. 27,20:? "OUR READERS"
470 POS. 21,22:? "R.O.M."
490 GOTO 490
500 DATA 0,0,0,0,0,0,8,42
510 DATA 199,254,124,120,112,225,195,135
520 DATA 0,0,63,255,252,30,31,7
530 DATA 2,2,2,2,2,10,10,10
540 DATA 2,138,170,170,170,170,170,170
550 DATA 128,20,85,85,85,85,20,128
560 DATA 128,128,128,160,160,168,168,170
570 DATA 10,42,170,42,42,42,170,170
580 DATA 170,168,168,160,160,128,128,128
590 DATA 168,161,165,165,165,165,161,168
600 DATA 42,10,10,8,0,0,0,0
610 DATA 170,170,130,0,0,0,0,0
620 DATA 170,168,168,160,32,32,0,0
630 DATA 10,66,82,82,82,82,66,10
640 DATA 8,8,8,42,42,170,12,12
650 DATA 0,0,0,0,0,128,0,0
That's all folks!
All the best.