BBC BASIC for Windows
« Modularising programs »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:57pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Modularising programs  (Read 496 times)
PaoloR
New Member
Image


member is offline

Avatar




PM


Posts: 4
xx Modularising programs
« Thread started 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Modularising programs
« Reply #1 on: Oct 2nd, 2012, 09:02am »

on Oct 2nd, 2012, 12:44am, PaoloR wrote:
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.
User IP Logged

PaoloR
New Member
Image


member is offline

Avatar




PM


Posts: 4
xx Re: Modularising programs
« Reply #2 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Modularising programs
« Reply #3 on: Oct 3rd, 2012, 3:40pm »

on Oct 3rd, 2012, 03:02am, PaoloR wrote:
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.
User IP Logged

PaoloR
New Member
Image


member is offline

Avatar




PM


Posts: 4
xx Re: Modularising programs
« Reply #4 on: Oct 3rd, 2012, 9:02pm »

Richard: thanks for the clarification.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls