1. Interfacing with BBC Basic.
The aim of this very short tutorial is to show how a BBC Basic program can be run from WimpBasic (WB) but also show how you can pass data between the two languages. There are undoubtedly more complex ways via the Wimps messages or memory blocks. However if you are using WB you may well not want to be involved with the nuts and bolts of the Wimp.
Why would you want to. Well you may have written a single tasking application and want to put the user choices in a windowed environment. A good example is Quake, or Abuse (although these user higher languages).
The demo produced !Basic is very simple but shows all of the principles needed to make your own programs function. The Wimp front end does not have an info window, but then you will know how to create one of these for yourself.
The download, consists of the fully compiled application with all data/basic files included. It also contains for those interested the standard uncompiled WB file. There is also a program listing for those without WB.
The parameter passing utilizes text files,because WB and BBC store strings and variables in different formats. WB can read BBC data files but not the other way. The handling of text files is not very difficult and anyway the basics are shown in the example. So just copy!!
The article assumes that you have produced at least the Hello World example as supplied by Clares. If not go and do it now.
Create the window as shown below in the window editor. The Window should be called choices,as the name in the main window and also as the windows title in the window data editor. Set the window sizes as small as possible.
The icon holding the word name can be called whatever you want (I've called it text1$). The Writable field should however be called writable$. The set button should be set as close$.
For the purpose of this demo you need to create a variable group global. Within the group create a variable opt%. This will keep tabs on the value controlled by the radio buttons.
4. Some code
We now need to create some code that will link all of the previously created elements together. Whenever I start a new project I always create the code that will be called to exit the program. Usually because I like to get the skeleton program up and working.
So here it is :
For the next code items go into the window editor and select the first radio button, and from the menu click amend selected. Midway down the window, is three drop down menus. Click in the grey box next to procedure. The code editor window will open with an empty procedure called ProcMouseClick. After the REM statement enter a new line :-
(Hint you can save typing by using the menu enter/variable).
Press f3 to save the procedure. You need to do the same for the other two radio buttons. Just remember to give global:opt% the values two and three. If you use the same method the code editor will report the error 'not a unique procedure/function name. Simply add a two or three to the end of the procedure name and save again.
Next create a procedure Procwind.
Go to the window editor again and select event handlers. From the drop down menu next to close window event select procwind. This means that when the user clicks on the close window icon WimpBasic will hide the window and not close it. This will mean that the variables will not be lost.
Create a new procedure updatech
So what is this doing. When the data file is first read in by the program, you will want the radio buttons to display the correct value. The Setselect icon will set the relevant icon if the value is true. Because the radio buttons are in the same ESG Group the others will be unset.
Next go to the main WimpBasic window and click on the startup procedure name.
You will have the code editor open with a blank procedure DefprocstartupProcedure
Create a new procedure defprocreadfiles and enter the following:-
So what does this all do. First of all we set up some local variables to be used within the function. The next line simple creates the path to the data file with our information in.
Create a further procedure Defprocwritefiles with the following :-
The first four lines are self explanatory. We are simply creating and assigning values to various variables. Normally I would not assign choices:writeable$ to a$, for a file write operation, but by putting Bput#X%,choices:writeable$ I couldn't get the program to run without crashing. This is also why T% is set to the value of &FFF
That is more or less the end of the Wimp front end. One more procedure to go. Before we write it we will link the various bits and pieces together.
First of all go to the window editor and open the choices window. Select the set button and click on amend selected. From the drop down menu in Procedure choose Procwritefiles and click ok.
Next go to the menu editor and open the iconbar menu. Following across from the submenu/window choose choices, and in procedure select procupdatech.
In the main window choose a sprite for the iconbar. If you're really keen create your own icon and add it to the sprite section of WimpBasic (a mode 27/28 sprite needs to be no bigger than 34 x 34 pixels)
The final act is to create the procedure that will run the Basic V program.
Return to WBs main window and click in the grey box next to select in procedure.
There is not much to say about this. The OSCLI command calls BBC Basic, runs the program and then quits basic at the end.
Save the procedure. You can now compile the program, but DO NOT run it, as the data file and the Basic 5 program need to be written first.
Once you have successfully compiled the program, open the application (Shift Double click)
In your text Editor (Edit,Stronged,Zap) create a text file with the lines
WimpBasic from Clares
Make sure you press return after the 1, to mark the end of the text. Save the file as 'file' in the application directory.
The final stage is to create the Basic V file.
Using your favourite Basic editor create a BASIC file with the following lines :
Save this file within the application as basicv.
Defprocstart is very similar to that in the WimpBasic program, in that it reads in the variables from the text file and assigns them to variables. As someone more famous has said 'that's all there is to it.'
In reality you would in fact be using the Wimp front end to set up keys, set screen modes or sound levels. Whatever you want to put a front end onto the principles remain the same. If you are a C programmer you may be able to use other data structures, but that is beyond the scope of this simple how to article.
It should also be remembered that my techniques may not be the best, the aim of the article is to offer ideas for the use of Wimp Basic.
The principles outlined above could be expanded so that you load in save game data from the Wimp, write temporary files, from the single task application so that you can return to the Wimp environment and return to the basic 5 program later. Be careful though if you attempt this as every variable used by your program would have to be written to file.
If you have comments or other ideas why not mail me and I will include them on this page.