1

Graphics in Mode 0

titlebar.gif

Stephen Levy

The Atari character set makes available numerous graphic characters. Some ways to exploit this feature are explored here.

Atari, long known for its superior graphics, has one graphics mode which is rarely used for graphics. Graphics mode 0 is generally used only for text and text-oriented programs. Well, why not use graphics in mode 0?


Plenty to Choose from

Unlike modes 3 through 11, graphics mode 0 has its own set of characters built-in which can be used to create some very nice designs. The short program below will show most of the graphic characters that are available in mode 0.

10 POKE 82,9:POKE 83,25
20 GRAPHICS 0:CHAR=0:LINE=0:PRINT
30 PRINT CHR$(CHAR);CHR$(32);
40 CHAR=CHAR+1:LINE=LINE+1
50 IF LINE=8 THEN LINE=0:PRINT :PRINT
60 IF (CHAR>26 AND CHAR<32) OR (CHAR>155) THEN PRINT CHR$(27);
70 IF CHAR=32 THEN CHAR=128: PRINT
80 IF CHAR=155 THEN GOTO 40
90 IF CHAR=160 THEN PRINT :GOTO 110
100 GOTO 30
110 POKE 82,2:POKE 83,39:END

What is seen on the screen when this program is RUN are the ATASCII characters from 0 to 31 and 128 to 159. (A complete list of the character set can be found in Appendix C of the Atari 400/800 BASIC Reference Manual.)Characters 128 to 159 are the inverse characters.


Centering the Display

The display has been centered for two reasons: it looks nicer that way, and it illustrates a way to place characters on the screen other than at the left margin.

Actually, the first character on each line is at the left margin. Look at line 10. Memory location 82 stores information the computer needs to find the correct column for the left margin. When you turn on the computer, a 2 is stored in this location. Likewise, memory location 83 stores the column of the right margin. All that has been done here is to change the margins to 9 and 25. On line 110 the margins are restored to 2 and 39.

There are a number of other ways to place characters on the screen at a specific place, including the POSITION, PLOT, and DRAWTO statements. More information about these statements will be provided a little later.


Printing the Graphic Characters

There are two ways to print each character in the character set. Printing the letter A can be done with either

PRINT "A"
or
PRINT CHR$(65)

Both methods produce the same results. The second method can be very inefficient for printing text to the screen, but it's very efficient for printing characters with consecutive ATASCII numbers and graphic characters.

As an example, enter this line and press RETURN:

FOR I = 65 TO 90:PRINT CHR$(I),:NEXT I


Special Characters

Characters 27 to 31, 125 to 127, 156 to 159, and 253 to 255 need special instructions in order to be printed. Note that line 60 checks for some of those characters. When it finds one, it prints character 27 (the ESCape character) before printing the character.

An alternative method can be used to print these characters. Make these changes in the program: delete line 60, add line 15,

15 POKE 766,2

and change line 110 to read

110 POKE 82,2:POKE 83,39:POKE 766,0:END

Try typing in the following program. It can be difficult to enter correctly if you are not experienced at entering these characters. When the program is RUN, the results should be four short lines printed on the screen. The first line should have the ESCape symbol. The second and third lines should show backward curved arrows (one will be inverse video); the last two lines should be the delete symbol and four arrows.

If you do not get the correct results, the proper keystrokes are given after the listing.

10 PRINT "{2 ESC}"
20 PRINT "{ESC}{CLEAR}"
30 PRINT "{ESC}{BELL}"
40 PRINT "{ESC}{DELETE}"
50 PRINT "{ESC}{UP}{ESC}{DOWN}{ESC}{LEFT}{ESC}{RIGHT}"

To enter this program, type each line number, the word PRINT, a quote symbol ("), and the following keys:

ESC, ESC, ESC, ESC, RETURN for line 10;
ESC, ESC, ESC, CTRL-CLEAR, RETURN for line 20;
ESC, ESC, ESC, CTRL-2, RETURN for line 30;
ESC, ESC, ESC, CTRL-DELETE/BACK S, RETURN for line 40;
ESC, ESC, ESC, CTRL-UP arrow, ESC, ESC, ESC, CTRL-DOWN arrow, ESC, ESC, ESC, CTRL-LEFT arrow, ESC, ESC, ESC, CTRL-RIGHT arrow, RETURN for line 50.


The Easy Way

The program below prints the same characters as the previous program. By POKEing a 2 into memory location 766, you no longer need to press the ESC key three times for each character, but just once.

5 POKE 766,2 
10 PRINT "{ESC}"
20 PRINT "{CLEAR}"
30 PRINT "{BELL}"
40 PRINT "{DELETE}"
50 PRINT "{UP}{DOWN}{LEFT}{RIGHT}"
60 POKE 766,0


PLOT and DRAWTO

Any character can be used with the PLOT and DRAWTO command. The following program is self-explanatory and should give some idea of how to use these two commands in graphics mode 0.

10 GRAPHICS 0: POKE 752,1:REM SET GRAPHICS MODE AND TURN OFF CURSOR
20 PRINT "{DOWN}": COLOR 148:REM ATASCII FOR CHARACTER TO PLOT
30 PLOT 2,4:DRAWTO 36,4
40 DRAWTO 36,18:DRAWTO 2,18
50 DRAWTO 2,3:REM NOTICE WE DRAW ONE POSITION PAST OUR STARTING POINT
60 POSITION 5,7:PRINT "PRINT YOUR MESSAGE HERE. BE"
70 POSITION 5,9:PRINT "SURE NOT TO PUT TOO MANY"
80 POSITION 5,11:PRINT "CHARACTERS ON A LINE."
90 POSITION 2,20:REM MOVE CURSOR OUT OF THE WAY
100 POKE 752,0:REM TURN CURSOR BACK ON


POSITIONing Characters

Any character can be placed on the screen at any location chosen. The POSITION statement is easy to use if you follow certain rules:

The next program also uses the POSITION statement, but this time a loop is used to change the locations.

100 DIM TRIANGLE$(34)
110 GRAPHICS 0:POKE 752 91:SETCOLOR 2,7,14:SETCOLOR 1,7,4
120 C=18:R=1
130 TRIANGLE$="{H}{J}"
140 POSITION C,R:PRINT TRIANGLE$
150 FOR B=2 TO 32 STEP 2
160 FOR A=2 TO B
170 TRIANGLE$(A,A)="(inverse blank)"
180 NEXT A
190 TRIANGLE$(A,A+1)="(inverse blank){J}"
200 C=C-1:R=R+1
210 POSITION C,R:PRINT TRIANGLE$
220 NEXT B
230 POKE 752,0

Now add these few lines to the previous program and watch what happens to the triangle:

250 FOR C=1 TO 25
260 A=1:B=2:GOSUB 300
270 A=2:B=1:GOSUB 300
280 NEXT C
290 END
300 SETCOLOR B,7,4:SETCOLOR A,7,14
310 FOR D=1 TO 50:NEXT D:RETURN


Drawing a Picture

The next two listings draw a simple picture. Both listings do exactly the same thing. Both versions of the drawing are included here as an illustration of two methods to print to the screen. When you're creating the picture, the first method is often easier because the picture can be seen while it is LISTed. The second method is supplied for purposes of comparison.


Program 1. Drawing with Characters

Download P007L1.BAS (Saved BASIC)
Download / View P007L1.LST (Listed BASIC)

Program 2. Drawing with CHR$

Download P007L2.BAS (Saved BASIC)
Download / View P007L2.LST (Listed BASIC)

Return to Table of Contents | Previous Section | Next Section