BasConfig is a utility, written by Oliver Fink, that creates config blocks for Qliberator compiled programs. For those that don’t know, config blocks are extras chucks of data added to programs that are changeable by the user, using the program “config”. In other words, if you have a program and you want the user to be able to change the size of the programs window, you can put the variables for the window size in a config block and let the user configure anytime they want. Config blocks are part of the executable and do not interfere with the running of the program. The ‘config’ program knows where in the executable the config block is and knows how to change it.
Another way of looking at the config block is as an object that has some data that is used by your program and is separate from your program. In fact, until your program is compiled, the config block is a separate file from your SuperBasic program. This block is accessible from both your program and the “config” program.
BasConfig creates a file that has the config block and some SuperBasic extensions that allow the program access to the block. These extensions need only be LRESPRed when you are developing your program. They can be compiled into your program and become part of the executable.
Before you use BasConfig, you need to define what type of data you want the user to be able to change. There are 7 different data types that are allowed in config blocks:
String Long Word Word Byte Select Code Char
BasConfig does not support the Long Word or Select data types. I don’t have any documentation on config, so I can’t say exactly what the difference is between the types other than what is obvious.
To access the data in the config block, there is a function for each data type supported by BasConfig:
C_STR$(n) - String C_WORD(n) - Word C_BYTE(n) - Byte C_CODE(n) - Code C_CHAR(n) - Char
The functions return the Nth data type in the config block. If you have two CHAR’s and one STRING data types in the config block and you wanted to get the second CHAR, you would do something like this:
$var = C_CHAR(2)
If your config block does not have a CHAR data type, you should be back some sort of error (I have not tested this).
To learn how all of this works, I created a SuperBasic program that opens a window and displays the contents of the two BYTE data items in a config block. The example code is:
100 REMark $$asmb=ram1_test_cfg,0,10 110 EXT_FN "C_BYTE" 120 OPEN #3,scr_100x100a50x50 130 PAPER #3,0: INK #3,4: CLS #3 140 item1 = C_BYTE(1) 150 item2 = C_BYTE(2) 160 PRINT #3,"Item #1 = ";item1 170 PRINT #3,"Item #2 = ";item2 180 PAUSE 500 190 CLOSE #3
Note the $$asmb directive that links the config block into the program. It is BasConfig that creates this block, which includes the 5 functions to access the config block. The EXT_FN command tells Qliberator that the references to C_BYTE will be resolved at link time.
To create the config block, exec basconfig_obj. The program will ask you for how many different config items you want. For this example, I entered 2. Next you are asked to enter the name of your final program and its version number. This is used by the “config” program to let the user know exactly what program they are configuring. These to items can not be changed by the user.
Now the program will query you for the data types for the first data item. You can scrolll through the data types by hitting the left arrow key. I scrolled over to “Byte” and hit return. Since each data type is different the next few questions will be different for each data type. In the base of the “Byte” data type the items were: Initial value, Minimum value, & Maximum value. The Min and Max values give you control of the changes the user can make, so that a “bad” configuration can’t be made. For this example, I gave the first item a initial value of 10 and the second a value of 20.
Once I answered all of the questions for the second config item, the program asked for a file to store the config block. It looks like the convention for config block file name extensions is _cfg.
Now, the documentation for BasConfig is very sparse. I had to figure out how to get the data out of the config block by reading the source code for BasConfig. So, I have only done just enough to get a fair idea of what is going on and how to get it to work.