Charles Pegge
23-06-2008, 21:43
This is an idea for establishing direct 3 way linkage between Asmosphere, thinBasic and thinBasic Modules. By using pointers both functions and data can be shared between the three parties without any mediating code, achieving very high performance wherever it is needed. The virtual table function, mtable is easy to add to any module (both PB and FB examples included in the zip below.)
First a thinBasic script:
'
Uses "Oxygen"
Uses "MyPBModule"
dim tbl as long = mm_table
dim result as long
dim src as string = "
;build interface
;---------------
def mymodule (mov edx,[#tbl]
)
def func1 proc [edx+04]
def func2 proc [edx+08]
def func3 proc [edx+12]
def result [#result]
;try func1
;---------
result=mymodule func1 6
ret
"
'run the code
'------------
o2_asmo src
o2_exec
msgbox 0,result
'msgbox 0,o2_error()+o2_view (src)
This is a PowerBasic skeleton module showing the virtual table interface with function pointers. Other variables can also be placed in the same table.
'Skeleton Module "thinBasic_MyPBModule.bas"
#compile dll
'#include once "win32api.inc"
'#include "thinCore.inc"
function func1(byval a as long) as long
function=a*7
end function
function func2() as long
function=0
end function
function func3() as long
function=0
end function
function mtable() as long
dim tbl(10) as static long
tbl(1)=codeptr(func1)
tbl(2)=codeptr(func2)
tbl(3)=codeptr(func3)
function=varptr(tbl(0))
end function
DECLARE FUNCTION thinBasic_LoadSymbol _
LIB "thinCore.DLL" _
ALIAS "thinBasic_LoadSymbol" _
( _
BYVAL SymbolName AS STRING, _
BYVAL ReturnCode AS LONG, _
BYVAL FunctionOrSubPointer AS DWORD, _
OPTIONAL BYVAL ForceOverWrite AS LONG _
) AS LONG
'----------------------------------------------------------------------------
%thinBasic_ReturnCodeLong= 5
%thinBasic_ForceOverWrite= 1
'
function LoadLocalSymbols Cdecl ALIAS "LoadLocalSymbols" (BYVAL sPath AS STRING) export AS Long
thinBasic_LoadSymbol "mm_table", %thinBasic_ReturnCodeLong, codeptr(mtable), %thinBasic_ForceOverWrite
function=0
end function
Function UnLoadLocalSymbols Cdecl ALIAS "UnLoadLocalSymbols" (BYVAL sPath AS STRING) export AS Long
function=0
end function
First a thinBasic script:
'
Uses "Oxygen"
Uses "MyPBModule"
dim tbl as long = mm_table
dim result as long
dim src as string = "
;build interface
;---------------
def mymodule (mov edx,[#tbl]
)
def func1 proc [edx+04]
def func2 proc [edx+08]
def func3 proc [edx+12]
def result [#result]
;try func1
;---------
result=mymodule func1 6
ret
"
'run the code
'------------
o2_asmo src
o2_exec
msgbox 0,result
'msgbox 0,o2_error()+o2_view (src)
This is a PowerBasic skeleton module showing the virtual table interface with function pointers. Other variables can also be placed in the same table.
'Skeleton Module "thinBasic_MyPBModule.bas"
#compile dll
'#include once "win32api.inc"
'#include "thinCore.inc"
function func1(byval a as long) as long
function=a*7
end function
function func2() as long
function=0
end function
function func3() as long
function=0
end function
function mtable() as long
dim tbl(10) as static long
tbl(1)=codeptr(func1)
tbl(2)=codeptr(func2)
tbl(3)=codeptr(func3)
function=varptr(tbl(0))
end function
DECLARE FUNCTION thinBasic_LoadSymbol _
LIB "thinCore.DLL" _
ALIAS "thinBasic_LoadSymbol" _
( _
BYVAL SymbolName AS STRING, _
BYVAL ReturnCode AS LONG, _
BYVAL FunctionOrSubPointer AS DWORD, _
OPTIONAL BYVAL ForceOverWrite AS LONG _
) AS LONG
'----------------------------------------------------------------------------
%thinBasic_ReturnCodeLong= 5
%thinBasic_ForceOverWrite= 1
'
function LoadLocalSymbols Cdecl ALIAS "LoadLocalSymbols" (BYVAL sPath AS STRING) export AS Long
thinBasic_LoadSymbol "mm_table", %thinBasic_ReturnCodeLong, codeptr(mtable), %thinBasic_ForceOverWrite
function=0
end function
Function UnLoadLocalSymbols Cdecl ALIAS "UnLoadLocalSymbols" (BYVAL sPath AS STRING) export AS Long
function=0
end function