The content of this website is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Australia (CC BY-NC-SA 3.0)

Porting MMBasic

MMBasic is designed to facilitate porting to a new platform and allows the easy addition of features to support special requirements. 

Obviously the best way to understand the requirements for this is to request the source and look through it and its documentation. These notes are intended to provide a high level view of what is required.

Requirements

MMBasic requires a CPU with 32 bit integers and pointers supported by an ANSI or C89 C compiler.

In its minimal version MMBasic typically compiles to about 94K of flash and requires just over 5K of RAM plus a minimum of 4K for the stack (9K total). More memory is required to store programs, variables, etc so the interpreter will require at least 16K of RAM to run a small BASIC program.   Generally 32K RAM or more is preferred as that will allow for larger programs and arrays.

Keep in mind that adding extra functionality (SD card support, file I/O, etc) will add to these requirements.

Customisation

The language itself is hardware independent.   Supporting the language are two main files that will need customisation to suit a particular platform:

Adding Functionality

MMBasic has a simple mechanism for adding functionality that is both elegant and efficient. This allows the easy addition of new commands, functions and operators.

For example, let us say that you want to implement a function that returns a special value generated by your hardware.

In one file you would define the C function to perform the operation:

      void fun_myfun(void) {
          fret = (float)special_data_to_return;
      }

And in another file you insert the definition of your function into the function table.  This links the function name in BASIC ("MyFunction") with the C function (fun_myfun):

      { "MyFunction",    T_FNA | T_NBR,    0,   fun_myfun },

MMBasic will do the rest and in your BASIC program you can use the function like any other:

      PRINT MyFunction/100

This mechanism also applies to commands and even to arithmetic and string operators (ie, +, -, /, etc).