Classic Computer Magazine Archive START VOL. 5 NO. 3 / NOVEMBER 1990

WINDOWS ON YOUR ATARI

Program Your Own Graphic User Interface

BY JEFFREY SUMMERS, MD


The fast machine language routines in this neat little demo make it easy and practical for intermediate (and advanced beginner) Atari BASIC programmers to use windows in their own 8-bit programs.

The latest fashion in "user interfaces" (how you work with your computer) is the Graphic User Interface, or GUI (pronounced gooey). Computers such as the Apple Macintosh, Atari ST, and Commodore Amiga have had this type of interface for years, using windows, icons and drop-down menus to make computing easier. Recently, IBM users have been climbing onto the bandwagon with programs such as Microsoft Windows and Digital Research's GEM. The 8-bit Atari recently gained access to such a system with the Diamond operating system from Reeve Software. However, there hasn't been much that a beginning- to- intermediate BASIC programmer could do to get this kind of fancy display.

Atari Windows makes it fairly simple for users to create windows. Text under the window is saved when the window is opened, and restored when the window is closed. Text written to the window will be erased when the window is closed. Windows can also be cleaned (their contents erased) without clearing the entire screen. The routines here work well only with regular "Graphics 0" text screens, but windows are usually used in applications programs where this should not be a problem.


Getting Started

Type in Listing 1, WINDDEMO.BAS, check it with TYPO II, and SAVE a copy to disk before you RUN it. If you have trouble typing the special characters in lines 10020 through 10100, don't type these lines. Instead, type in Listing 2. When RUN, this program creates these hard-to-type lines and stores them in a file called LINES.LST. To merge the two programs, type NEW, then LOAD "D:WIND DEMO. BAS" and then ENTER "D:LINES. LST". Be sure to SAVE the completed version of the program.

You can simply RUN "D:WINDDEMO.BAS" to see Atari Windows in action, but to really appreciate how it works you should have a text-filled screen for a background. One way to do this is to LOAD "D:WINDDEMO.BAS", LIST the program on the screen, and then RUN it. A series of five windows will open on the screen, each with its own little message. Then the windows will close again, one at a time, revealing the windows and text underneath them still intact! (Note that the cursor will be in the middle of the screen, where the last PRINT statement left it.)

In fact, the screen data "behind" each window is stored in memory, and only restored just as the window closes. There is no limit to the number of windows that can be open at one time, but there is a practical limit to the amount of screen information the array used for storage can hold. Currently, this is set to 5000 bytes, which is enough to hold the entire screen being windowed five times - much more than you are likely to use. If you actually need more, simply increase the size of WINDOW$ in line 10010.


Window Routines

Four routines handle the windows: WINDOI, WINDOO, WINDOC, and WINDEX. WINDOI sets everything up for the other routines to use. WINDOO opens windows, WINDOC closes them, and WINDEX cleans them (of course!).

Before trying to do anything with windows, your program should perform a GOSUB 10000. The routine at 10000 takes care of all the setup and calls WINDOI, so you should never actually have to use WINDOI.

WINDOO opens a window. The routine has four parameters: the left column, upper row, right column, and lower row of the window you wish to open. So, the following line:

100 D = USR(WINDOO,4,5,2 5,10)

opens a window that runs from columns 4 to 25 in rows five through 10. A border is drawn around the window, so be sure to make the windows large enough for the text you want.

The window doesn't really change the way you work with the screen. So, if you want to print something at a particular place within a window you would use the POSITION statement just as you would normally. To print "Hello" in the window you just created:

110 POSITION 6,7:PRINT "Hello"

Closing a window erases that window's contents and restores whatever was under the window before it opened. The WINDOC routines closes the windows, and it takes no parameters:

120 D = USR(WINDOC)

Finally, WINDEX erases the contents of the current or top window. This can be useful for asking a series of questions within a window, for example. You can keep your window open while erasing the previous question and response, and then ask another question. This is a bit neater than closing the window and re-opening it with the same dimensions, which would cause the screen contents "underneath" to flash briefly on the screen.

If the windows in the demo move too quickly or slowly for you, change the value of WAIT in line 35. Smaller values shorten the time between window changes, and larger values increase it.

Listing on page 113

A physician from Rochester, NY, Jeffrey Summers NY is a frequent contributor to ANTIC. His soundwave-drawing program Antic Sound Creator appeared in the December 1989 issue of ANTIC.