BBC BASIC for Windows
Programming >> BBC BASIC language >> Modularising programs http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1349138694 Modularising programs
Post by PaoloR on Oct 2nd, 2012, 12:44am
In most computer languages it is possible to break code up into separate files (usually containing code with similar functionality.)
How do I do that in BBC Basic? Suppose I had a program structure thus:
A | B ------ C ------D ------- E ------ F
where A was a 'control program' and the B-F would be 'called' as required.
Would I create library files and then INSTALL them in A? Or is there another way to do this?
TIA
Re: Modularising programs
Post by admin on Oct 2nd, 2012, 09:02am
Would I create library files and then INSTALL them in A?
Yes, that is the recommended way. The INSTALL statement can be used either for libraries or to support modular programming. In the latter case you don't need to worry about adhering to all the recommendations for writing libraries (to ensure they are portable), for example it is acceptable to share global variables between your main program and a sub-module, whereas it wouldn't be with a 'true' library.
An alternative approach is to use the CALL filename statement. This is similar to INSTALL except that the module is only temporarily loaded into memory, executed, and then discarded. Whereas a module loaded using INSTALL should contain only FNs and PROCs, a module executed using CALL should contain only in-line code and no FNs or PROCs.
Bear in mind that the INSTALLed or CALLed module cannot use line numbers or labels, so a stricter adherence to structured programming techniques may be required.
If you intend to develop modular programs in this way you will probably want to use the Module Viewer add-in utility to display the different modules in separate tabs. Installing Module Viewer from the command line also gives you the option of creating a desktop shortcut which runs BB4W with the tabbed interface automatically initialised.
To edit modules other than the 'main program' double-click on the tab; this will open another instance of the IDE.
Richard. Re: Modularising programs
Post by PaoloR on Oct 3rd, 2012, 03:02am
Richard: thanks for the clarification.
Quote:
Whereas a module loaded using INSTALL should contain only FNs and PROCs, a module executed using CALL should contain only in-line code and no FNs or PROCs.
As I'm new to BBC Basic what exactly is in-line code? I understand the concept of in-line assembler but I presume you are referring to Basic with this comment. Presumably just a series of Basic statements in, ahem, unstructured fashion?
Also, I assume that INSTALLing files loads them into memory at program commencement and leaves them there for the duration of the program run. Would this be a correct assumption?
TIA
Re: Modularising programs
Post by admin on Oct 3rd, 2012, 3:40pm
Presumably just a series of Basic statements in, ahem, unstructured fashion?
Yes, that's what I mean. The sort of thing CALL filename is useful for is executing a file containing constant declarations, or structure declarations, or the like. That way it saves some memory since once the declarations have been made there's no need for the code to be 'resident' any more.
Quote:
Also, I assume that INSTALLing files loads them into memory at program commencement and leaves them there for the duration of the program run. Would this be a correct assumption?
Yes. The libraries are loaded above HIMEM, and if there is (unusually) a requirement to discard them you can do it using this trick:
Code:
HIMEM = HIMEM + 1
HIMEM = HIMEM - 1
CLEAR
Otherwise they remain resident until the program is next run.
Richard.
Re: Modularising programs
Post by PaoloR on Oct 3rd, 2012, 9:02pm