Part  4 on Resource programming in GFA Basic.  
This is  the  last article in this series - I hope that they have 
been of some  use, and that you have learnt something about 
This  program and resource is for LOW resolution ST's.  It  is  a 
control panel to change the colour palette.  I would have made it 
STE compatible, but I don't have an STE!
The main part of the control consists of sliders. This concept is 
easy  in resource terms:- a slider consists of  two  'bars',  one 
which  is filled with a pattern,  and on top of that  is  another 
bar,  which  is just an opaque box.  The small box slides up  and 
down on top of the larger box, thus forming a slider. In terms of 
objects,  the larger box is the parent of the small box. To allow 
the  small box to slide within the larger box,  use  the  command 
GRAF_SLIDEBOX;  this  allows  for one object to be  moved  within 
another, this movement can be either horizontal or vertical. This 
command  returns  a value between 0 and 1000,  where  this  value 
represents  how far up (or down) the slider object is within  the 
parent object.
     The  colourful bit
The ST has 512 colours available, but only 16 of them can be show 
on screen at once.  To get the other colours to be displayed, you 
use the SETCOLOR command.  On the STE there are 4096 colours, but 
again, only 16 can be displayed at once. The colour is made up of 
the main colours:  RED,  GREEN and BLUE.  To make up a new colour 
you mix these main RGB values: SETCOLOR 4,7,7,7 would make colour 
register  4 white (all colours are full on).  Note on an  ST  the 
maximum value for each of the colour constituents is  7,  whereas 
for an STE it is 15.  (To confuse things a bit more on an STE the 
colour  constituents don't go in the order they do on an  ST  ie. 
0,1,2,3....; they go 0,8,1,9,2,10,3,11,4,12......).
Due to a mix up in the operating system, the COLOR numbers do not 
correspond  to  the SETCOLOR numbers,  the  following  shows  the 
COLOR     0,1,2,3,4,5,6,7,8,9 ,10,11,12,13,14,15
SETCOLOR  0,2,3,6,4,7,5,8,9,10,11,14,12,15,13,1
To find out what colour mix makes up a particular colour, use the 
XBIOS 7 command,  and pass to it the colour register to look  up. 
Say you want to know what the RED GREEN and BLUE for COLOR 0 is:
  col%=XBIOS(7,c|,L:-1) AND &H777 (or &HFFF for an STE)
  g&=SHR(col% AND &X11110000,4)
  b&=col% AND &X1111
where:  c| is the color, this returns r&, g& and b& as red, green 
and blue.
     The program
The  program  starts off by finding the RGB values  for  all  the 
colours,  then fills boxes with that colour, then allows the user 
to  select which colour to change,  and change that colour  using 
either sliders,  or up and down arrows.  It sits in a loop  until 
'OK' or 'CANCEL' are selected.
The colour to work on is indicated by a tick in the relevant box, 
and the colour changes as you work the sliders or the arrows.
The difficult part was to put a tick in the box,  and also to set 
the  colour  of these boxes.  These boxes are  G_BOXCHAR  objects 
within  the resource file,  the problem is that the  text  within 
this type of object is held in the top 8 bits as ASCII code,  the 
colour of the object in bits 0 to 3, and the fill pattern in bits 
4 to 6.  So to set a tick in a new object,  and change its colour 
involves quite a bit of code! 
Version  2 Basic users will notice I have used a bit  of  machine 
code,  this  simulates the V3 command 'SHR' which shifts right  a 
number, this is used to find out what ASCII code is within one of 
the boxes.
This description is intentionally short, because of the length of 
the  programs.  If you want further help and advice  on  resource 
file  programming,  contact  GFA  User Magazine  at  186  Holland 
Street, Crewe (0270 256429), as a series of articles has appeared 
in that publication.
John Peters


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