PE Evolution - FAUX Functions

mrburnette

Senior Member
Extension of my thoughts on how to best use code snippets: Converting-BCD-byte-values-to-decimal

Run-able Example 08M2 Code: FAUX-Function-demonstration-code

There really should be more Code Snippets like this !
thanks hippy
YES - there should be more (complete code snippets, that is...)
I suspect that a reason that there is not is because the PICAXE BASIC does not support libraries or scoped memory - which is to say that (as an example) the 08M2 has B0 through B27 named variables (Public) but 3 times more memory exists on an 08M2+ that is not named. To use the extra memory is not difficult, but is awkward.

My thoughts on using the unnamed memory:
I should be able to #INCLUDE a code block and instruct the compiler to "create/name" the included file as a function. The specific implementation would allow a memory map between public (named) variables that are referenced and those extended memory variables that are not directly addressable. No firmware changes would be required but the user would achieve the benefit of a quasi-function capability, with limited private variables (specifically, B0 in the main program would be the same B0 in the INCLUDED function BUT the variable can take on a different value and different Symbol in the Function without changing the main program value after returning! The swap would be made by macro-expansion within the compiler and would be invisible to the programmer.

Example syntax:

#INCLUDE "filename.bas" <, varlist>
In use, if the extension <, varlist> does not appear the Directive works as today, however
IF <, varlist> appears, as B0 or W0 formats, then they are mapped to subsequently higher memory banks. For this discussion, I will use my bank-switching routine as a reference: RAM-bank-switching. BANK0 is named variables and BANK1/2/3 would be allocated by the compiler for up to three (3) of the extended #INCLUDES.

This approach is not ideal, but it would allow the compiler to accept new syntax that provides a simulated, but faux, FUNCTION(x) capability. Up to three Functions would appear to have private memory space with a full, clean repertoire of SYMBOL capability, etc. ONLY named variables OR aliases from Symbol definitions would be re-mapped upon return of the function.

Code:
#INCLUDE "F2C.bas" , W0, W1   ; compiler sees thus automatically as a function
Symbol Fahrenheit = W0             ; optional synonym 
Symbol Celsius = W1                   ; optional synonym
...
W0 = 212
Function F2C (W0, W1)                ; cheat as compiler just 'remaps' any variable in the list with its equivalent +28 / +56 / +84
;Function F2C(Fahrenheit, Celsius) ; Should work too as compiler has the Symbol table
 ...
Sertxd (#Farenheit, " F= ", #Celsius, " C")
And only PE changes and no firmware changes.

- Ray
 

Attachments

Top