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 
                     
drawn.
                     
                     
                     
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:
                     
                     
                     
current_setting=XBIOS(33,-1)
                     
                     
                     
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)
                     
RESERVE -666
                     
                     
                     
free memory for the file
                     
~RSRC_FREE()
                     
                     
                     
load the file
                     
a&=RSRC_LOAD("prnt_set.rsc")
                     
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
                     
set_vars
                     
                     
                     
get the address of our resource structure
                     
~RSRC_GADDR(0,prntset|,tree%)
                     
                     
                     
get the current printer setting and mask off the unwanted bits
                     
mask=63                                                  
                     
current_setting&=XBIOS(33,W:-1) AND mask
                     
                     
                     
set the buttons in the form to the current printer setup
                     
set_form(current_setting&)
                     
                     
                     
calculate where the picture is to go (in the middle of the screen)
                     
~FORM_CENTER(tree%,x&,y&,w&,h&)
                     
                     
                     
save the screen under where the form is to be put
                     
GET x&,y&,x&+w&,y&+h&,temp$
                     
                     
                     
and draw the form
                     
~OBJC_DRAW(tree%,0,7,x&,y&,w&,h&)
                     
                     
                     
wait for the user to click on 'OK'
                     
result|=FORM_DO(tree%,0)
                     
                     
                     
reset the 'OK' button back to noraml - otherwise next time you  draw 
                     
the form, the 'OK' button will be selected.
                     
OB_STATE(tree%,result|)=BCLR(OB_STATE(tree%,result|),0)
                     
'
                     
                     
                     
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 
                     
ELSE
                     
new_setting&=BSET(new_setting&,n)   otherwise that bit is set
                     
ENDIF
                     
ADD button,3   the  way the resource is drawn,  the buttons  are  in steps of 3
                     
NEXT n
                     
                     
                     
tell the ST to accept the new settings
                     
~XBIOS(33,W:new_setting&)
                     
'
                     
put the screen back to normal
                     
PUT x&,y&,temp$
                     
                     
                     
free up memory taken by the resource
                     
~RSRC_FREE()
                     
                     
                     
return memory to Basic
                     
RESERVE
                     
                     
                     
all done!!
                     
END
                     
'
                     
                     
                     
the  following procedure sets the buttons in the form  according  to 
                     
the printer settings
                     
PROCEDURE set_form(set_&)
                     
  button=3
                     
  FOR n=0 TO 5
                     
    IF BTST(set_&,n)  ! bit is set
                     
if the button on the left needs to be clear 
                     
     OB_STATE(tree%,button)=BCLR(OB_STATE(tree%,button),0)
                     
      OB_STATE(tree%,button+1)=BSET(OB_STATE(tree%,button+1),0)
                     
    ELSE
                     
make the button on the right, clear
                     
      OB_STATE(tree%,button)=BSET(OB_STATE(tree%,button),0)
                     
      OB_STATE(tree%,button+1)=BCLR(OB_STATE(tree%,button+1),0)
                     
    ENDIF
                     
    ADD button,3
                     
  NEXT n
                     
RETURN
                     
'
                     
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
                     
RETURN
                     
                     
                     
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
                     
                     
                     
                     

Takaisin

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