Classic Computer Magazine Archive COMPUTE! ISSUE 78 / NOVEMBER 1986 / PAGE 85

ST Outlook

Philip I. Nelson, Assistant Editor

BASIC Slide Show For NEOchrome And DEGAS

Nearly every ST owner has used NEOchrome, the graphics program supplied with the computer, or DEGAS, the excellent drawing program written by Tom Hudson. Both programs allow you to create stunning graphics, but how can you incorporate such pictures in a BASIC program of your own? This month's program demonstrates one way to display NEOchrome and DEGAS pictures in any screen resolution, on color or monochrome 520ST or 1040ST systems. It adjusts automatically for the differences between DEGAS and NEOchrome pictures. However, you must set the correct screen resolution with Set Preferences before you run the slide show. (No harm is done if you display a picture in the wrong resolution, but the picture will be jumbled because the screen's bitplanes don't match up correctly.)

The program begins by asking for the filename of the picture you want to display. Enter the full drive-path and filename, including the extension. For instance, to display the NEOchrome file MYPIC.NEO located on the disk in drive A:, type the filename A:\MYPIC.NEO and press RETURN. To display a DEGAS file named MYPIC.PI2 from the subdirectory BASIC in drive B:, use B: \ BASIC \MYPIC.PI2. Don't confuse the backslash ( \) character with a normal slash (/) when typing filenames. The backslash indicates a subdirectory and is not interchangeable with a slash. After you've entered the filename, the program displays the picture and waits for you to press either mouse button. When you press the button, the screen clears, the original palette colors are restored, and you're invited to enter another filename. To exit, press RETURN at the prompt.

Behind The Scenes

Since column space is limited, this program includes only the bare essentials needed to get a filename and display a picture. If you want to transport these techniques to a program of your own, you'll probably want to refine the input routine and perform some checks for disk errors. Here's a nutshell description of how the program works. Lines 150–170 save the original palette colors in the array SAV%. Lines 180–190 call a VDI routine that hides the mouse pointer (so it won't spoil the picture). Lines 200–300 get the filename, adjust for the file type, and set the color palette for the new picture. The routine called in line 310 clears the entire screen surface with a VDI system routine. Lines 320–330 BLOAD the file into screen memory, and line 340 calls a routine that waits for a button to be pressed. Line 350 restores the previous palette so you can see what you're typing. Line 360 clears the last picture from the screen and goes back for another filename.

When you exit the program, lines 440–460 make the mouse pointer visible again. Notice that BASIC'S menu titles don't reappear, although the menus still work as usual. ST BASIC is intelligent enough to redraw its windows when needed—unless you're rash enough to close all the windows at once—but it never refreshes the menu bar. The assumption seems to be that nobody would ever want to display full-screen graphics from BASIC.

Handling Picture Files

Regardless of screen resolution, NEOchrome and DEGAS files always contain 32,000 bytes of actual screen data preceded by a short header. The header records the picture's resolution and color palette; it's 34 bytes long for DEGAS and 128 bytes long for NEOchrome. The palette data occupies 32 bytes. NEOchiome files also contain extra data for color cycling (this program doesn't do color cycling; it uses the palette that was in effect when you saved the picture).

To reconstruct a picture, the slide-show program reads the palette portion of the file into the string COL$, then directs the computer to use the bytes in COL$ as the new palette. Then it BLOADs the file into the ST's screen memory, using an offset to prevent the header portion of the file from going into the screen.

Location &H44E is a pointer that tells you where screen memory begins. Location &H45A, which ordinarily contains a zero, is a flag that lets you switch to a new palette. The ST scans this location as a background task during every VBI (vertical blank interrupt) interval. When you POKE a nonzero value into &H45A, the computer uses that value as the address of the new color palette. The program discovers the current palette by PEEKing the video display registers at 16745024. If the new version of ST BASIC includes ASK RGB and RGB (see last month's column) you should be able to read and change the palette with BASIC commands instead of fiddling with hardware registers.

System Variables

Locations &H44E and &H45A are "official" system variables that Atari has promised not to change in future system updates. Another interesting variable is location &H45E, a screen pointer flag that's scanned during the VBI like the palette flag. When you put a nonzero value there, the ST uses the value as the new address for screen memory, making it possible to page-flip between alternate screens.

If you incorporate these methods in a program of your own, be sure to use double-precision variables when dealing with system addresses. The DEFDBL A statement in this program defines all variables starting with A as double-precision, which in turn causes BASIC to use longword (four-byte) values when you PEEK or POKE with those variables. POKEing a byte-length or word-length (two-byte) value into a place like &H45A usually causes a crash known as a bus error when the processor tries to address a nonexistent memory location.

BASIC Slide Show

100 rem Display Degas/Neochrome pics.
110 rem Set resolution BEFORE you run.
120 fullw 2:clearw 2
130 col$=string$(32, 32)
140 defdbl a:dim sav%(15)
150 psave=16745024: k=0
160 for j=0 to 15
170 sav%(j)=peek (psave+k) :k=k+2:next
180 poke contr 1, 123:poke contrl+2,0
190 poke contr+6, 0:vdisys(0)
200 input "Enter filename";picname$
210 if len(picname$)=0 then 440
220 flag$=left$(right$(picname$,3),1)
230 offset=128:junk=4:rem Neochrome file
240 if flag$="N" or flag$="n" then 260
250 offset=34: junk=2: rem Degas file
260 close 1:open "I", #1, picname$
270 x$=input$(junk, 1)
280 col$=input$ (32,1)
290 close 1: anu=varptr (col$)
300 apal=&H45A:poke apal, anu
310 gosub 370
320 ascr=&H44e:aa=peek (ascr)
330 bload picname$, aa-offset
340 gosub 400
350 poke apal, varptr (sav%(0))
360 gosub 370:goto 200
370 poke contrl,3:poke contrl+2,0
380 poke contrl+6,0:vdisys(0)
390 return
400 poke contrl,124:poke contrl+2,0
410 poke contrl+6,0:vdisys(0)
420 if peek (intout)=0 then 400
430 return
440 poke contrl, 122:poke contrl+2,0
450 poke contrl+6, 1:poke intin,0
460 vdisys(0)