CHARACTER GRAPHICS MADE EASY
By BOB COCKROFT
By BOB COCKROFT
One who does not know character graphics does not know the full capabilities of the Atari computer. By using a modified character set, graphics can be made more interesting. Backgrounds or moving players can, with the help of a character editor, be made with surprising speed. Because of the high resolution of the lines used in creating characters, detailed graphics is possible. Anyone who does not understand character graphics is depriving himself of one of the most exciting aspects of advanced programming.
Character graphics is simply the modification of any or all of the characters the Atari computer provides. A character can be converted from its original form into anything the programmer wishes. For example, the character "W" can be changed into a space ship or even a planet. The only practical limit is your imagination and the use made of the 8 by 8 byte box the character is allowed.(more about this latter) These modified characters are printed on the screen to produce the desired effect. Imagine a screen full of text; letters numbers and punctuation of various types. Suddenly, each one of the characters on the screen shapes its self in such a way as to produce the background for a new game. This changing of shape is character graphics.
A character is a block of memory that is 8 bits wide and 8 bytes high. The values contained in the bytes work the same as missile graphics data. The numbers in the bytes control which or any of the horizontal bits of information which are to be turned on. Each bit is represented by a predetermined power of two.(see below). By poking the value representing the bit you want turned on into the correct location in the character set a new horizontal line can be created. If you want two or more bits turned on you add the value of the desired bits.
The first that one needs to do before modifying a character set is to reserve an area in the memory to store the new set. In most situations it is best to allow 1024 bytes for this purpose. Memory can be reserved by the following
10 POKE 106,PEEK(106)-4
By poking in a lower number into RAMTOP,(location 106) the computer can be fooled into leaving, in this case 4 pages (4*256=1024 bytes) of memory undisturbed.
The next thing that needs to be done is to locate the original character set which is located in the ROM(Read Only Memory). The Character Base Register (756 dec)($2F4 hex) gives us the clue we need. The initial value in this location will be only one of two numbers; either the value 224 which represents uppercase characters or 226 for lowercase characters. By poking either of the preceding numbers into this location the 'case' of the characters can be changed. The fact that makes this location interesting to us is that it gives the starting address for either the upper or lowercase character sets, because the value in this location represents the Most Significant Byte of the start of the (ROM)character sets. In other words, when one multiplies the value in the Character Base Register(dec 756) by 256, the product will be the base address for either the upper or lower case character sets. If you are confused look below.
If the value in CBR(dec 756) is '244'
Then: 224*256= (57344) the starting address of upper case character set
If the value in CBR(dec 756) is '226'
Then: 226*256= (57856) the starting address of lower case character set
Now that you have reserved space for a new altered character set and have located the original set in the ROM, the next step will be to move the original set to the new location. This can be easily done using a FOR NEXT loop.
100 FOR L=1 TO 1024
110 POKE NEWSET+L-1,PEEK(ROMSET+L-1)
120 NEXT L
The next step would be to locate the character you wish to modify in the 1024 bytes of information you have just moved. Each character is assigned a specific number to locate its position. This character location number represents the order in which a character appears in the set. For example the letter 'A' appears as the 33th character in the set; therefore the location number for this character would be 33.(for character location numbers refer to table 1) Each individual character uses 8 bytes of information as can, be seen below.
Therefore multiplying the location number by 8, one can get the position of any character in the set. The base value for the new character set must be added to this value to get its position in the memory. An example for the letter 'A' is given below.
Character location number=33
New character set base=CHARBASE
Character location = CHARLOC
A table for the character location numbers is given below. The characters appear on the right and the location numbers on the left.
The last step would be to tell the Antic ship where to find the new character set. This can be done by poking the new address into the Character Base Register. It is important to know the CBR computes addresses in terms of pages. Therefore, take the address of the new character set and divide it by 256 before poking it into this location.
130 POKE 756,NEWSET/256
Location Numbers For Characters
It is possible to create as many character sets as your memory can hold. One can switch back and forth between a customized character set and the original ROM set by poking the address of the desired set into location 756. Therefore, a program can contain both extensive character graphics and a quick access to normal sets.
Graphic commands like GRAPHICS 1 AND RESET restore the character set pointer to the original locations. The Character Base Register must be readjusted in this situation if a modified character set is to be used.
The first program is a simple application of what I have said. Many of the lines in it have been already discussed in much detail above. If you are still confused it may be helpful to reread the article while following the first program.
The second program hopefully will be a long term benefit for you. It is a simple character editor that can be used to speed up the creation of your modified set. By doing all the time consuming calculations and adjustments, this program will make character creation faster and more interesting. The program will first ask you what the location number of the character you wish to modify is. If you are not sure of the answer refer to table 1. Draw your character using the joystick pressing the trigger to erase. After your editing session press the start button to exit. Then press 'y' if you wish to see the new character. A line of numbers will appear on the screen. You must poke this data into the character location in order to modify it. Finally press the keyboard character which has been modified. If you have done everything correctly you will see a small copy of what had been drawn with the joystick earlier.
Program Listing 1.
90 REM *
92 REM * PROGRAM 1 *
99 REM *CHARACTER BASE FOR THE ROM SET
105 REM * SET BASE VALUE OF THE NEWSET
125 REM * RESERVE MEMORY SPACE *
130 POKE 106,PEEK(106)-5
140 GRAPHICS 0
142 ? :? :? :? "Please Wait"
150 FOR L=1 TO 1024
155 POKE NSET+L-1,PEEK(ROMSET+L-1)
160 NEXT L
165 REM * SET CHARACTER BASE REGISTER TO NEW SET LOCATION *
170 POKE 756,NSET/256
175 REM * POKE IN VALUES FOR MODIFIED CHARACTERS *
180 FOR L1=1 TO 2
190 READ LOC
210 FOR L2=0 TO 7:READ D
220 POKE SET+L2,D
230 NEXT L2
240 NEXT L1
250 DATA 33,126,195,129,165,129,153,195,126
260 DATA 34,28,28,8,255,8,28,20,54
Program Listing 2.
10 REM *
20 REM * PROGRAM 2
30 REM *
32 REM * SIMPLE CHARACTER EDITOR
34 REM *
35 DIM CHD(8),YN$(5),YN1$(5)
40 GRAPHICS 0
50 ? "Enter the character location number for the character you wish to modify "
60 INPUT NUM
65 REM ** FIND THE BASE ADDRESS FOR THE ROM CHARACTER SET **
95 POKE 106,PEEK(106)-5
100 GRAPHICS 0
105 POSITION 11,10:? "one moment please"
108 REM * MOVE ROM SET TO NEWSET LOCATION
110 FOR L=1 TO 1024:POKE NSET+L-1,PEEK(CHBASE+L-1)
120 NEXT L
125 REM * SET CHARACTER BASE REGISTER TO NEW SET LOCATION
152 FOR X=1 TO 8:CHD(X)=0:NEXT X
155 REM * EDIT SECTION
160 GRAPHICS 4
170 COLOR 1
180 SETCOLOR 2,16,1
186 ? " Use joystick to draw"
187 ? " Press button to erase"
188 ? " Press start button when completed"
230 IF ST=14 AND YPLOT>13 THEN YPLOT=YPLOT-1
240 IF ST=13 AND YPLOT<20 THEN YPLOT=YPLOT+1
250 IF ST=7 AND XPLOT<47 THEN XPLOT=XPLOT+1
260 IF ST=11 AND XPLOT>40 THEN XPLOT=XPLOT-1
270 IF STRIG(0)=1 THEN COLOR 1:FOR X=1 TO 5:NEXT X:GOTO 280
272 COLOR 1:FOR X=1 TO 5:PLOT XPLOT,YPLOT:NEXT X
275 COLOR 0
280 PLOT XPLOT,YPLOT
290 IF PEEK(53279)=6 THEN 350
300 GOTO 200
370 FOR X=0 TO 7
390 NEXT X
400 GRAPHICS 0
499 REM * PRINT OUT RESULTS
510 FOR L2=0 TO 7
520 POKE SET+L2,CHD(L2+1)
530 NEXT L2
540 GRAPHICS 0:POSITION 2,5:? "Press the character you have modified"
545 ? :? " Character data below"
550 ? :POSITION 6,10:FOR X=1 TO 8
555 IF X=8 THEN ? CHD(X):GOTO 575
560 ? CHD(X);",";
565 NEXT X
575 POKE 756,NSET/256:7
576 ? "Press the RESET button before rerunning the editor or you will get bad data"
599 REM * RESTART