dmsc / fastbasic

FastBasic - Fast BASIC interpreter for the Atari 8-bit computers
GNU General Public License v2.0
139 stars 20 forks source link

Modular loading and unloading of "addons" #51

Open rickcollette opened 3 years ago

rickcollette commented 3 years ago

Some akin to dlopen in C - https://pubs.opengroup.org/onlinepubs/009696799/functions/dlopen.html would be great to have.

The advantage over a RUN "Dx:Filename.ext" is that you would not unload the initial program, keeping any vars you have set. If someone were to write a core application that was small - but contained all of the static vars required; and called modules via a dlopen-like method, it could become quite extendible.

Example of usage (though pretty nitch): BBS where the system is modular and would not require a sort of TSR to be present. Maybe an adventure game where you could add in modules for different games A text interpreter that called in modules to handle things differently

If this already exists; or there is some other way to handle this; I'd love to see it.

rickcollette commented 2 years ago

Is there any more detail I can provide to help this along? Or even a patreon or paypal to donate for the cause?

dmsc commented 2 years ago

Sorry for waiting so long to respond, I'm really busy this days.

I think that what you want is having "overlays", and a way to load those overlays over existing code. This is not easy to implement, you would certainly need a specific linker configuration (to define memory areas with the base code and the overlayed code).

The same support could be used to write banked cartridges, were part of the code could be located in the "main" bank and other parts in secondary banks.

One posibility is add a way to specify the "bank" on which each PROC is placed:

' Load bank 1 somehow
EXEC MY_PROC_1
` Load bank 2 somehow
EXEC MY_PROC_2

PROC MY_PROC_1 [BANK "bank1"]
  ' code here....
ENDPROC

PROC MY_PROC_2 [BANK "bank2"]
  ' code here....
ENDPROC

You should be very careful to call procedures on one bank from another, only call banked procedures from the main code.