Hi John,
I've now got the module interface working. I found Assembler was the easiest way to do it. This is my workbench code for testing various data types.
Because it is not using the macros and a C compiler, we have to trust in the stability of the data structures and function tables across different builds.
Do you normally recompile all the extension modules when the core SB is recompiled?
'extension module for ScriptBasic:
'23:02 11/05/2011
'23:31 13/05/2011
'
'Charles Pegge
#file "mdlt.dll"
'----------------------------------------------------------------------------------
function versmodu cdecl (sys Version, pszVariation, ppModuleInternal) as sys export
'==================================================================================
'print "Version: " hex version
return Version
end function
'-------------------------------------------------------------------------------------------
function bootmodu cdecl (sys pSt, ppModuleInternal, pParameters, pReturnValue) as sys export
'===========================================================================================
'print "Boot!"
end function
'------------------------------------------------------------------------------------
function finimodu cdecl (sys pSt, ppModuleInternal, pParameters, pReturnValue) as sys export
'====================================================================================
'print "Finish!"
end function
'----------------------------------------------------------------------------------------
function trial cdecl (sys pSt, ppModuleInternal, pParameters, pReturnValue) as sys export
'========================================================================================
sys p,t,v,w,pm,pn
string s
'
if pParameters=0 then
print "no params"
else
'
'HOW MANY ARGUMENTS GIVEN
'------------------------
'
mov ecx,pparameters
mov eax,[ecx+8] : shr eax,2 : mov w,eax
'mov eax,[ecx+12] : mov t,al
'
'print "No of Arguments given: " w
'
'SELECT PARAM pn
'---------------
'
'pParameters->Value.aValue[(X)-1]
'
pn=1
'
mov ecx,pparameters
mov ecx,[ecx] 'array of param pointers
mov eax,pn : dec eax : shl eax,2
mov ecx,[ecx+eax] 'array offset to get pparam
'
mov pm,ecx
'
'CONVERSION TO STRING
'--------------------
'
'to string f4 / to long f8 / to double fc
'pSt->Convert2String(pSt->pEo,(x),pSt->pEo->pGlobalMortalList)
'
mov ecx,pSt : mov eax,[ecx] : push [eax+0x8c] : push pm : push eax : call [ecx+0xf4]
mov ecx,eax
mov p,ecx
zstring* z : &z=*p
'
'print "As String: " z
'
mov ecx,pSt : mov eax,[ecx] : push [eax+0x8c] : push pm : push eax : call [ecx+0xf8]
mov ecx,[eax]
mov p,ecx
'
'print "As Long: " p
'
mov ecx,pSt : mov eax,[ecx] : push [eax+0x8c] : push pm : push eax : call [ecx+0xfc]
mov ecx,eax
mov p,ecx
double*d : &d=p
'
print "As Double: " d
'
'GET VALUE / STRING POINTER
'--------------------------
'
'mov eax,[ecx] : mov p,eax 'value / pointer
'mov eax,[ecx+8] : mov w,eax 'size
'mov eax,[ecx+12] : and eax,-1 : mov t,eax
'
'type codes 0 undef 1 double 2 long 3 zstring* 4 zchar ff ptr
'
end if
'
'
'============
'RETURN VALUE
'============
'
'
'check stack:
'mov w,esp
'
'
' 00c string 010 long 018 double
'---------------------------------
'
'
'RETURN LONG
'-----------
'
'long v=456
'
'mov ecx,pst : mov eax,[ecx] : push [eax+0x8c] : push [eax+0x94] : call [ecx+0x10]
'mov ecx,pReturnValue : mov [ecx],eax : mov edx,v : mov [eax],edx
'
'
'RETURN DOUBLE
'-------------
'
'double d=1234.5678
'
'mov ecx,pst : mov eax,[ecx] : push [eax+0x8c] : push [eax+0x94] : call [ecx+0x18]
'mov ecx,pReturnValue : mov [ecx],eax : fld qword d : fstp qword [eax]
'
'
'RETURN STRING
'-------------
'
long ls=8 'length excluding null terminators
zstring z at p
'
mov ecx,pst : mov eax,[ecx] : push [eax+0x8c] : push ls : push [eax+0x94] : call [ecx+0x0c]
mov ecx,pReturnValue : mov [ecx],eax : mov eax,[eax] : mov p,eax
z="ABCDEFGH" 'direct input
'
'
'NB: beware cdecl cleanup.
'-------------------------
'
'sub w,esp
'print "check stack: " hex w
'
end function
Charles