Programming in BASIC
by A. L. Hubbard
Add colorful graphics and title screens to your GFA BASIC programs with PUTMAKER.ARC on your START disk.
This issue's BASIC column brings GFA programmers a simple utility that will dramatically improve the professional look of your programs. It's much easier to use a commercial graphics program like DEGAS or NEOchrome for your artwork than to try to do it in BASIC. Then, with Putmaker, you can clip and save a portion of a medium or low resolution DEGAS or NEO picture and use it in your GFA BASIC programs with a simple PUT command. The graphics file PUTMAKER.PUT used to jazz up Putmaker's title screen is a perfect example.
screen. A colorful
makes any program
look more interest-
ing and professional
and with Putmaker,
it only requires
three lines of code!
How It Works
There are two related GFA BASIC commends that let you manipulate a block of graphic screen data and store it as a bit pattern in a string variable. GET X0,Y0,X1,Y1,A$ reads a rectangle from the screen and stores it in A$. X0 and Y0 are the coordinates of the upper left hand corner; X1 and Y1 are the lower right hand coordinates. PUT X0,Y0,A$[,mode] puts the bit pattern back on the screen, with the upper left-hand corner of the block's location specified with X0 and Y0. The optional mode specifies the graphics mode, typically used to specify how the block interacts with the background. (See your GFA BASIC manual for specifics.)
Putmaker will load uncompressed DEGAS images, NEOchrome images, GFA BASIC PUT and SCREEN files. You can define a rectangular area of an image using the GEM-style rubberband box and save it back to disk as a GFA BASIC PUT file for use in your own programs. Finally, you can save a picture back to disk in any of these formats, making Putmaker a graphics file converter as well!
Running The Program
To run Putmaker, copy the file PUTMAKER.ARC and ARCX.TTP to a blank disk and un-ARC the file, following the Disk Instructions elsewhere in this issue. Double-click on PUTMAKER.PRG, set the screen resolution to that of the picture you wish to clip and load the picture file into the workscreen. Simply "rubber-box" a section of the picture and then save it to disk as a PUT file.
To load the PUT file into your own program, simply BLOAD the file into a string and then PUT the bit pattern wherever you want it. For an example of this, this is how Putmaker loads in its own title screen:
'Load main screen put file to
' ... and Put on main screen.
Here's a quick run-down of Putmaker's menu options. Putmaker is definitely user-friendly and needs few directions.
- About This Program--Copyright and version information.
- Introduction--A simple reminder of program capabilities.
- QUIT--Exits the program.
- PUT File--Loads a GFA PUT format file.
- NEO File--Loads a NEOchrome format file.
- DEGAS File--Loads a DEGAS format file.
- SCREEN File--Loads a GFA SCREEN format file.
- PUT File--Saves the selected block in GFA PUT format.
- NEO File--Saves a NEOchrome format file.
- DEGAS File--Saves a DEGAS format file.
- SCREEN File--Saves a GFA SCREEN format file.
- PUT Area--Lets the user select an area of the workscreen for a PUT file.
- RESOLUTION--Prompts the user to set the resolution of the workscreen.
- Selected PUT--Displays the PUT area previously selected.
- WORKSCREEN--Displays the workscreen.
The following discussions describe Putmaker's main procedures. To examine or print out the source code, doubleclick on PUTMAKER.LST from the Desktop. To load it into GFA BASIC, run the GFA BASIC Interpreter, click on Merge and then select PUTMAKER.LST
Loading a PUT file from disk starts with clearing any previous PUT information in memory. A call to XBIOS(5,L:-1,L:1,W:0) sets the correct resolution for the workscreen. The first two parameters (passed as long words) affect the screen addresses and inform TOS not to modify these functions. The next parameter, a word, is 0 for low resolution; a 1 would change it to medium. PUT_LOAD then reserves space for the longest possible PUT string and loads the file from disk with the command BLOAD. It then PUTs the file on the workscreen and stores the complete screen as the string WORKSCREEN$. After a mouse click, it sets the program colors for the main menu screen and adjusts the resolution.
A screen file contains no resolution or color information and unlike a PUT file, a screen file always takes up a full screen. This makes things very easy; SCR_LOAD simply BLOADs the file to the screen address XBIOS(2).
NEOchrome and DEGAS files include color palette information along with picture information in the file. The procedure first opens a channel using the command OPEN "I",#1, PATH_FLENAME$. It then moves to the fifth byte of the file using SEEK #1,4; this is where the color information starts. Each color value is stored as a word so it must be read in two bytes at a time, interpreted, and stored in the proper location. The command is XBIOS(7,N,Z). XBIOS(7) is the GEM routine, N is the color number and Z is the color value, found by multiplying the high byte by 256 and adding the low byte to the result.
NEOchrome picture information starts at byte 128. To load it at the proper memory location, NEO_LOAD loads it to the screen address minus 128, then closes the channel, stores the workscreen with SGET and exits.
DEGAS pictures may be either low or medium resolution. EXTS="PI"+ STR$(RES) forces the extension to match the workscreen resolution. DEGAS color information begins at byte 3 so DEG_LOAD uses the command SEEK #1,2. The procedure then BLOADs the picture information to the screen address minus 34 to display it properly.
Saving information to a disk file is the reverse of the previous processes. The PUT_SAVE procedure forces a conventional extension and then saves the PUT data using BSAVE.
Saving the work screen string to disk is essentially the same as saving a PUT file; as before, the procedure calls BSAVE and passes it the file name, address and length of the file to save.
NEOchrome pictures require a specific file format. After opening the disk file, NEO_SAVE must print four nulls (CHR$(0)) and the color palette information to it. Next, it saves the rest of the 128-byte header (PRINT#1;STRING$ (92,0);) and then the picture data (PRINT#1,WORKSCREEN$).
The procedure uses the first two bytes to denote the resolution (PRINT#1; CHR$(0);PRINT#1; CHR$(RES-1);) followed by the color information and picture data in the same manner as NEOchrome files.
This is the core of the program. After giving a message to the user, the procedure calls PART_SELECT. This procedure displays the work screen and draws a rubber-band box around an area as long as the left mouse button is held down. It then displays the selected coordinates and gives the user a chance to try again, save the defined PUT block or cancel.
A. L. Hubbard is a 41-year-old-father of three who tries to find time for a computer hobby which is fast becoming a passion. He is employed as a Technical Supervisor in the television broadcast business in Toronto, Canada.
GFA BASIC Ver. 2.0, $79.95. MichTron, 576 Telegraph, Pontiac, MI 48503, (313) 334-5700.