PDA

View Full Version : FreeBasic SDK: extended data type



ErosOlmi
22-08-2008, 02:22
I'm working on implementing thinBasic SDK for FreeBasic compiler but I'm stuck with EXTENDED data type.
Most of the thinBasic SDK functions handling numbers are designed to work with EXTENDED numbers but EXTENDED are not supported natively by FreeBasic.

So, for example, if a SDK function expect an EXT passed BYREF, how to handle in FreeBasic?

Any help is appreciated.

Thanks a lot
Eros

jack
22-08-2008, 03:05
someone wrote a real10 library and it's included in the examples folder, but I must warn you that the output routine is not 100% solid, I will see if I can work on it on my days off (a week from now)
you have to compile the library yourself from the command line.

ErosOlmi
22-08-2008, 03:18
Thanks a lot.
Do you know how to invoke FBC to compile the library? I can see a make file but no idea how to use it.

jack
22-08-2008, 03:25
actually it's very simple, just launch the freeBasic command prompt, cd to real10\libreal10 and type make :)

ErosOlmi
22-08-2008, 03:34
It doesn't work here. I have a lot of compilers installed and when I invoke MAKE it starts the Borland make utility.
I need to check my path precedences and FreeBasic installation. I usually compile FreeBasic sources from inside FBEdit making a FBEdit project.

Do not worry, I'll find a way.
Thanks
Eros

jack
22-08-2008, 03:45
you may need to have Mingw32 installed, anyway attached is the one I just compiled with the latest FB
I believe my system to be clean but recommend you check for virus.

ErosOlmi
22-08-2008, 03:55
Thanks a lot. Compiled test example and is working fine.

I will now work on thinBasic SDK interface. I do not need to make complex operations. I just need to declare some EXT numbers, pass them to thinBasic SDK functions, return values and convert to Double. All FreeBasic calculations will be performed with doubles.

jack
22-08-2008, 04:03
one thing you need to change is the ext structure, as it is defined in the real10 library it's 16 bytes, posibly for speed reasons.

Charles Pegge
22-08-2008, 07:28
Converting between 64 bit and 80 bit floating point is very simple with a little machine code :)
We know that varptr always returns the variable address in the eax register so, all we have to do is formulate fld and fstp pairs which use the eax register as a simple pointer.


I would suggest managing the conversion entirely on the FreeBasic side:

FreeBasic


type extended
dbl as double
xtn as long ' assuming alignment to 4 bytes
end type

dim myvar as extended
dim p as any ptr

'convert from double to extended
p=varptr(myVar)
asm .byte &hdd, &h00, &hdb,&h38

'convert from extended to double
p=varptr(myVar)
asm .byte &hdb, &h28, &hdd,&h18

ErosOlmi
22-08-2008, 12:22
Thanks to all.

Charles, yes, I will do in FreeBasic all the stuff as you suggested.
My target is not to duplicate thinBasic SDK just to be compatible with EXT and DOUBLE. I want all functions as they are and study some simple transparent way for FreeBasic programmers.

Ciao
Eros

Charles Pegge
22-08-2008, 13:29
Hi Eros,

The only complication is alignment in arrays.Are your arrays of extended numbers contiguous (stride of 10 bytes) or are they DWORD aligned (12 bytes)? PB packs them as 10 bytes.

Extended numbers passed byval on the stack, I would expect to be padded to 12 bytes. as PB does.

ErosOlmi
22-08-2008, 13:50
thinBasic EXT arrays elements are 10 bytes.
I suppose BYVAL EXT are passed pushing 4 bytes * 3 times. As far as I can see, BYVAL is not a problem, problem is BYREF.
Anyhow I still need to make real tests. I've so much things to finish for next thinBasic release. But definitely will do a test run on this.

I'm 100% rewriting SDK help material inside official thinBasic help file describing in details all interface functions (it's a big job). Doing that I'm trying to align as much as possible SDK for PowerBasic with SDK for FreeBasic interfaces. In future versions I will do the same for SDK for C. I feel those 3 languages (PowerBasic, FreeBasic, C) are the one worth to work with (for the moment) for thinBasic module development.

ErosOlmi
22-08-2008, 14:30
you may need to have Mingw32 installed, anyway attached is the one I just compiled with the latest FB
I believe my system to be clean but recommend you check for virus.


Ok, I've installed MinGW32, adjusted some path and I was able to create lib libreal10.a

Thanks
Eros

Charles Pegge
22-08-2008, 14:42
In that case I would adopt the extended type for freebasic as:




type exended ' 10 bytes
dbl as dbl
xtr as word
end type


Extended variables, including arrays can then be converted on entry and exit from the thinbasic module, without creating new variables.

I look forward to the new SDK documentation. TOMDK was derived from the March 2008 release of the PB SDK - as was my provisional FB SDK. TOMDK found that some of the functions were absent from the current thincore.DLL. So I commented them out. here is the bind list:

TOMDK

bind thincore
(
thinBasic_LoadSymbol thinBasic_LoadSymbol
thinBasic_VariableExists thinBasic_VariableExists
thinBasic_VariableGetInfo thinBasic_VariableGetInfo
thinBasic_VariableGetInfoEX thinBasic_VariableGetInfoEX
thinBasic_VariableIsArray thinBasic_VariableIsArray
thinBasic_VariableRedim thinBasic_VariableRedim
thinBasic_ArrayGetElements thinBasic_ArrayGetElements
thinBasic_ArrayGetPtr thinBasic_ArrayGetPtr
thinBasic_ArrayGetInfo thinBasic_ArrayGetInfo
thinBasic_AddEquate thinBasic_AddEquate
thinBasic_AddVariable thinBasic_AddVariable
thinBasic_ChangeVariableNumber thinBasic_ChangeVariableNumber
thinBasic_ChangeVariableString thinBasic_ChangeVariableString
thinBasic_GetToken thinBasic_GetToken
thinBasic_GetTokenID thinBasic_GetTokenID
thinBasic_TokenGetCurrentID thinBasic_TokenGetCurrentID
thinBasic_PutBack thinBasic_PutBack
thinBasic_FunctionExists thinBasic_FunctionExists
thinBasic_FunctionSimpleCall thinBasic_FunctionSimpleCall
thinBasic_GetKeywordSpeficic thinBasic_GetKeywordSpeficic
thinBasic_VariableParse thinBasic_VariableParse
thinBasic_VariableParsePtr thinBasic_VariableParsePtr
thinBasic_VariablePtrToDirectPtr thinBasic_VariablePtrToDirectPtr
thinBasic_DirectPtrToDataPtr thinBasic_DirectPtrToDataPtr
thinBasic_VariableParseAndGetInfo thinBasic_VariableParseAndGetInfo

thinBasic_ParseVariableInfo thinBasic_ParseVariableInfo
thinBasic_ChangeVariableStringDirect thinBasic_ChangeVariableStringDirect
thinBasic_ChangeVariableNumberDirect thinBasic_ChangeVariableNumberDirect
thinBasic_ParseNumber thinBasic_ParseNumber
thinBasic_ParseLong thinBasic_ParseLong
; thinBasic_Parse1NumberAndParens thinBasic_Parse1NumberAndParens
; thinBasic_Parse2NumberAndParens thinBasic_Parse2NumberAndParens
; thinBasic_Parse3NumberAndParens thinBasic_Parse3NumberAndParens
; thinBasic_Parse4NumberAndParens thinBasic_Parse4NumberAndParens
; thinBasic_Parse5NumberAndParens thinBasic_Parse5NumberAndParens
; thinBasic_Parse6NumberAndParens thinBasic_Parse6NumberAndParens
thinBasic_Parse1Number thinBasic_Parse1Number
; thinBasic_Parse2Number thinBasic_Parse2Number
; thinBasic_Parse3Number thinBasic_Parse3Number
; thinBasic_Parse4Number thinBasic_Parse4Number
; thinBasic_Parse5Number thinBasic_Parse5Number
; thinBasic_Parse6Number thinBasic_Parse6Number
thinBasic_ParseXNumbers thinBasic_ParseXNumbers
thinBasic_Parse1StringXNumbers thinBasic_Parse1StringXNumbers
thinBasic_Parse1String thinBasic_Parse1String
thinBasic_ParseString thinBasic_ParseString
thinBasic_CheckOpenParens thinBasic_CheckOpenParens
thinBasic_CheckOpenParens_Mandatory thinBasic_CheckOpenParens_Mandatory
thinBasic_CheckOpenParens_Optional thinBasic_CheckOpenParens_Optional
thinBasic_CheckCloseParens thinBasic_CheckCloseParens
thinBasic_CheckCloseParens_Mandatory thinBasic_CheckCloseParens_Mandatory
thinBasic_CheckCloseParens_Optional thinBasic_CheckCloseParens_Optional
thinBasic_CheckComma thinBasic_CheckComma
thinBasic_CheckComma_Mandatory thinBasic_CheckComma_Mandatory
thinBasic_CheckComma_Optional thinBasic_CheckComma_Optional
thinBasic_DetermineType thinBasic_DetermineType
thinBasic_GetRunTimeInfo thinBasic_GetRunTimeInfo
thinBasic_GetLastError thinBasic_GetLastError
thinBasic_RunTimeError thinBasic_RunTimeError
)

ErosOlmi
22-08-2008, 15:04
Charles,

attached the latest SDK for PowerBasic. I will start from this for creating new FreeBasic one.

thinBasic_Parse2Number, thinBasic_Parse3Number, ... are missing an "s" at the end. They should be thinBasic_Parse2Numbers, thinBasic_Parse3Numbers, ...
Functions ending with ..."AndParens" are now obsolete.

Some functions inside thinCore.inc are new and will be present in next release. I will update all material very soon.

Ciao
Eros

Charles Pegge
22-08-2008, 16:42
Thanks Eros,

I've updated TOMDK and thinBasicOxygen.

Below is the thinCore kit for FreeBasic I have been using - see how it compares with your latest :)


Update posted further down

ErosOlmi
22-08-2008, 17:00
Thank you very much Charles. A much better version than mine.

Charles Pegge
22-08-2008, 17:43
The web pulsates with thinBasic updates this afternoon.

I've just made one correction to thincore.bi and the DEF file parse1number instead of parse1numbers. This is reposted above.

I have also included the machine code conversion EXT - DOUBLE Conversion lines in thincore.bi (commented).

There is also a listing of all the exported function names present in thincore.dll.

At some point we need to devise a standard test suite to exercise all the functions - do you have such a thing for PB that I could adapt for FB?

ErosOlmi
22-08-2008, 17:53
No I do not have a test but I'm preparing complete help material for all exported functions.
Each function will report its meaning, syntax, how to use, where to use and for which language it is avaibale.
I will start with PowerBasic and FreeBasic.

Anyhow, inside \thinBasic\SampleScripts\Exe\ you can adapt ListExeImportExport.tBasic script to test exported function names.

Ciao
Eros

ErosOlmi
22-08-2008, 18:07
I've just made one correction to thincore.bi and the DEF file parse1number instead of parse1numbers. This is reposted above.

I have also included the machine code conversion EXT - DOUBLE Conversion lines in thincore.bi (commented).


I cannot see those changes ???

Charles Pegge
22-08-2008, 18:37
Sorry Eros. Don't know what happened there but its definitely uploaded this time.

I will do FB module test pieces as soon as possible.

ErosOlmi
22-08-2008, 18:53
Sorry Charles but still cannot get the changes you mentioned.
In thinCore.bi there is no EXT/DOUBLE conversion.
Also parse1numbers should be parse1number (singular because just one number), all the others (from 2 to 7) are plural.
I cleaned also my browser cache (just in case)

Ciao
Eros

PS: going out for few hours now, so take your time.

Charles Pegge
22-08-2008, 19:36
Well third time lucky I hope.

ErosOlmi
22-08-2008, 21:22
Thanks. This one is ok.

I just noted a little error in
DECLARE FUNCTION thinBasic_Parse1Number LIB "thinCore.DLL" ALIAS "thinBasic_Parse1Numbers"
ALIAS is still with "s". Should be without "s".

Ciao
Eros

Charles Pegge
22-08-2008, 21:50
You beat me to it! Thanks Eros.

File updated. But I think it is inevitable that testing all the functions will expose a few more gremlins. I am looking at ways of automating tests whenever changes are made to the module package. - Can't rely on fingers and spectacles.

ErosOlmi
22-08-2008, 21:54
Well, when I will finish to align PowerBasic SDK with FreeBasic one, it will be MY DUTY to keep them aligned and documented.
"C" language can wait a bit for the moment.

Thanks a lot for your work Charles!

Charles Pegge
22-08-2008, 22:11
Freebasic uses a utility called SWIG to automatically translate C headers to Freebasic headers. I wonder if we could do something similar - to keep module headers synchronised across several languages. It all depends on how frequently the thincore interface is likely to change, but it might save you a lot of work in the long run.

ErosOlmi
22-08-2008, 22:39
I do not think I will introduce new interfaces in near future. I just need to make a job on sync and documentation in order to simplify module development.

jack
15-09-2008, 20:30
I finally worked on the real10 lib a bit, fixed the output routine and added more
types that are automatically converted to extended when used with an
extended function or variable, also added For Next support for extended type.
I still consider this as an interesting experiment, not solid enough to be taken
seriously.
I bundled the code in one include file so you can compile it in FBide, no need
to compile to lib, it's easier to experiment with the code this way.

Petr Schreiber
15-09-2008, 20:47
Hi Jack,

thanks for nice surprise, I will try it during tomorrow.


Petr

EDIT: Looked at it right now, this is big amount of work done!