Resource Programming with GFA Basic     Pt2
Last  month in the introduction to resource file  programming,  some 
basic  principles  were discussed.  This time,  I want to  take  the 
programs  a  little further,  and present a program to set  up  your 
printer. The choice of input is controlled with a resource file.
The  main  way  this new resource is  constructed,  is  with  "radio 
buttons".  These radio buttons behave exactly like the buttons on an 
old style radio, where you may have say 3 buttons, Long wave, Medium 
wave and VHF. If you push in VHF, any other button will pop out, and 
if you now press Medium wave in,  the VHF button will pop out.  This 
allows you one choice out of three buttons:
______  ______  ______  
| A  |  | B  |  | C  |
So in the example above, you can select either A, B or C.
A radio button is selected when you create the resource file with an 
editor,  you may, at the time of editing it, make a button selected; 
that  is: it will be already selected for you when  the  picture  is 
When  you run the program,  you will notice that there is more  than 
one bank of buttons:
______  ______    
| A  |  | B  |  
______  ______    
| C  |  | D  |  
If  you simply put these buttons straight onto the  form,  then  you 
will  only  be able to select one of the four  buttons.  To  have  a 
multiple bank of buttons, where you can select one in each bank, you 
have to put a box around each bank:
| ______  ______ |   
| | A  |  | B  | |  Bank 1
|                |
| ______  ______ |   
| | C  |  | D  | |  Bank 2 
|                |
What this does,  is make the radio buttons into children of the box, 
so each box has its own selection.  The type of box to use is "IBOX" 
(Invisible  Box),  and  when  you have  drawn  it,  make  the  frame 
disappear by making the frame have a width of 0. I have included the 
file  "FIRST_PR.RSC" which shows these IBOXES before they have  been 
hidden, so you can see how its done.
When  you  put the 2 boxes onto the form,  then cover them  with  an 
ibox,  you  will get a message informing you that you are  about  to 
reconstruct  the objects,  this indicates that all is  ok.  What  is 
happening,  is that when you started,  these boxes were children  of 
the main form,  but now you have covered them with another  box,  so 
they are to become children of the new box, and grandchildren of the 
main form.
The program
To  control  the  printer,   the  operating  system  call  XBIOS  33 
(setprt)is used. This call sets (or gets) the printer configuration, 
on  return  from the call,  you will get a  number,  which  has  the 
following meaning:
Bit Number        0                       1
     0       dot matrix printer      daisy wheel
     1       monochrome    "         colour printer
     2       Atari printer           Epson    "
     3       Draft mode              NLQ print mode
     4       Centronics port         RS 232 port
     5       Continuous paper        Single sheet paper
  6-14              reserved
    15              always 0
As you can see,  the only bits we are really interested in are  bits 
0-5,  so when you get a number back from the XBIOS call,  it is best 
to mask off the unwanted bits.  To call this routine, and return the 
current printer configuration:
The  minus  1  means - return current setting.  To get  rid  of  the 
unwanted bits use a mask of 63 (binary 111111). When you turn on the 
ST,  if you don't have "CONTROL.ACC" on the disk you boot from, then 
the  ST  thinks that you have an Atari printer,  and  assumes  other 
things about the printer.  To change these settings,  you can either 
use  CONTROL.ACC  or  do  it yourself with  a  simple  call  to  the 
operating system.  You could do it with a one line command,  if  you 
happen  to know what settings you want.  Suppose you have  an  Espon 
printer,  and  want it to print in NLQ mode,  you would have to  set 
Bits 2 and 3 (=001100 or 12 in decimal) so to actually do the  call, 
you  would write the following line:  Void  XBIOS(33,12).  Now  your 
printer is configured correctly.  However, not everyone can remember 
these bits, or what they do, so it is best to give the user a choice 
of inputs,  and then do the change for him.  This choice of input is 
better  represented by a picture,  thus the use of a resource  file. 
(The beginnings of your own CONTROL.ACC maybe ??).
The flow of the program is simple; it loads a resource file; it then 
gets  the  current  printer setting,  changes  the  buttons  in  the 
resource file to depict those settings, draws the buttons on screen, 
and  waits  for  the user to click on OK.  If there  have  been  any 
changes  to  the settings,  the program  automatically  changes  the 
printer settings. That's it!
The program listing explained.
(Note:  these  explanations  are for the V3  listing,  I  have  also 
included a V2 .BAS file on the disk)
reserve memory for the resource file (just the file size is enough)
free memory for the file
load the file
if  you can't find the resource file then I have included  a  little 
routine to attempt to find it using the fileselector.
set up the variables from the resource file
get the address of our resource structure
get the current printer setting and mask off the unwanted bits
current_setting&=XBIOS(33,W:-1) AND mask
set the buttons in the form to the current printer setup
calculate where the picture is to go (in the middle of the screen)
save the screen under where the form is to be put
GET x&,y&,x&+w&,y&+h&,temp$
and draw the form
wait for the user to click on 'OK'
reset the 'OK' button back to noraml - otherwise next time you  draw 
the form, the 'OK' button will be selected.
now go through the buttons, to find out which ones are selected, and 
which are not:
button=3        (the first button's object number is 3)
FOR n=0 TO 5
IF OB_STATE(tree%,button)           if the button on the left is selected
new_setting&=BCLR(new_setting&,n)   then that bit is 0 
new_setting&=BSET(new_setting&,n)   otherwise that bit is set
ADD button,3   the  way the resource is drawn,  the buttons  are  in steps of 3
tell the ST to accept the new settings
put the screen back to normal
PUT x&,y&,temp$
free up memory taken by the resource
return memory to Basic
all done!!
the  following procedure sets the buttons in the form  according  to 
the printer settings
PROCEDURE set_form(set_&)
  FOR n=0 TO 5
    IF BTST(set_&,n)  ! bit is set
if the button on the left needs to be clear 
make the button on the right, clear
    ADD button,3
  NEXT n
this procedure contains the names of the objects created within  the 
resource file:
PROCEDURE set_vars
  LET prntset|=0  ! DIALOG TREE
  ' the various bits of XBIOS(33) contain information
  ' about your printer
  ' Bit 0
  LET dmp|=3        ! dot matrix
  LET daisy|=4      ! daisy wheel
  ' Bit 1
  LET mono|=6       ! monochrome printer
  LET colour|=7     ! colour printer
  ' Bit 2
  LET atarip|=9     ! Atari printer
  LET epson|=10     ! Epson printer
  ' Bit 3
  LET draft|=12     ! Test mode
  LET nlq|=13       ! NLQ mode
  ' Bit 4
  LET centronc|=15  ! Centronics Port
  LET rs232|=16     ! RS232 Port
  ' Bit 5
  LET continus|=18  ! Continuous paper
  LET single|=19    ! Single Sheet
  LET prtok|=20                       !   Button
I  hope  that  you find the subject easy to  master,  and  that  the 
programs are of some little use.  Next month I want to cover how  to 
get information to and from a dialog box, using input objects.
John Peters


(C) Marko, Suomen Atari-sivut / ArkiSTo 2003