2 Customizing The Graphics Modes

Mixing Graphics Modes 0 And 8

Douglas Crockford


Normally, GRAPHICS 8 does not allow text to be displayed alongside the graphics. This machine language routine, when added to a BASIC program, provides this useful feature.

Graphics mode 0 is the Atari text mode. It supports uppercase, lowercase, inverse video, and has a position function for placing text anywhere within a 40 by 24 display field. Graphics mode 8 is the Atari high resolution plot mode. It supports the plotting of points and lines in a 320 by 160 (or 192) display field. It would be very nice to use both modes at the same time. The text window is some help, but it confines the plot to the top and the text to the bottom. Modifying the display list provides a partial solution, but it is awkward and doesn't permit the mixing of text and plot on the same line.

A better solution is to use graphics mode 8 and plot the dots that make up the text characters. This can be done very quickly by a 6502 machine language subroutine, which does things in software which are very similar to what the display hardware does 60 times a second.

The subroutine is called with the USR function. It has four arguments:

the horizontal cursor position
the vertical cursor position
the address of the string to be displayed
the length of the string to be displayed.

So, the code

GRAPHICS 0 
POSITION X,Y 
PRINT STRING$;

will produce similar results to

GRAPHICS 8 
A=USR(ADR(PRINT$),X,Y,ADR(STRING$),LEN(STRING$))

PRINT$ is a string containing the subroutine. The STRING$ should not extend past the last column in a row. Any embedded function codes (cursor movement, insert, etc.) will be displayed literally. The position of the PLOT/DRAWTO pointer is not changed, nor is the current COLOR.

An interesting bonus is that adding 40*R to the horizontal argument causes the text to be displayed R plot rows lower than usual. This permits the display of subscripts, mathematical expressions, 1 1/2 line spacing, underlining, and so on.

The subroutine is relocatable because it contains no JPs, JSRs, or data reference to itself. It can run anywhere in memory. It is also under 256 bytes, so it can also run in page six. The program shows the subroutine being loaded into a string called PRINT$, and shows a few of the things it can do.


Figure. Screen Dump of the Demo Program.

chap2n5.jpg

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


Return to Table of Contents | Previous Section | Next Section