[Gambas-devel] EXTERN Calls

Christopher Brian Jack brian at ...418...
Tue Mar 21 04:52:20 CET 2006


On Mon, 20 Mar 2006, Rob Kudla wrote:

Doh... didn't even start writing in my thoughts... not my day...
anyways...

> > Then, to get the string, you use StrPtr(), that will return
> > the string located at pBuf. The name 'StrPtr' is maybe not
> > very well chosen. If somebody has a better idea...
>
> GetString()?

GetStringAt(addr as Pointer)

Would be my suggestion.

I'm wondering if perhaps allocated memory should have some more internal
support (block copying, contents examining in the case that the C function
needs to return structs rather than strings, and other stuff you might
want to do with chunks of memory like use it with the SDL audio library as
sample data)

Another BASIC available during Amiga times called AMOS had the concept of
memory banks.  Though I'm not suggesting duplicating the bank structure of
AMOS (although the fact that you could keep banks with your project in
AMOS meant it was a great place to stash things like resources, images,
audio, etc) it would be good to have some of the rudimentary functions
that worked with banks as they allow basic examination and manipulation of
allocated memory.

AMOS had operations peek, deek and leek (byte, short, long 'peek's)
Lots of things have been discovered since then like the phenomenon of
endian-order so there may be a few extras needed.

The basic pattern would be:
LPeek8, LPeek16, LPeek32, LPeek64, L is for little-endian result
BPeek8, BPeek16, BPeek32, BPeek64, B is for big-endian result

And similar for storing:
LPoke8, LPoke16, LPoke32, LPoke64
BPoke8, BPoke16, BPoke32, BPoke64

Again the L and B indicate whether what is being poke'ed is to be stored
in little-endian (L) or big-endian (B) order.  Gambas running on LE
machines would have to swap for the BE versions and gambas running on BE
machines would have to swap for the LE versions.

The syntax of LPeekXX/BPeekXX is
LPeek8  (hPtr AS Pointer, offset AS Integer) AS Integer
LPeek16 (hPtr AS Pointer, offset AS Integer) AS Integer
LPeek32 (hPtr AS Pointer, offset AS Integer) AS Integer
LPeek64 (hPtr AS Pointer, offset AS Integer) AS Integer
BPeek8  (hPtr AS Pointer, offset AS Integer) AS Integer
BPeek16 (hPtr AS Pointer, offset AS Integer) AS Integer
BPeek32 (hPtr AS Pointer, offset AS Integer) AS Integer
BPeek64 (hPtr AS Pointer, offset AS Integer) AS Integer

The syntax of LPokeXX/BPokeXX is
LPoke8  (hPtr AS Pointer, offset AS Integer, value AS Integer)
LPoke16 (hPtr AS Pointer, offset AS Integer, value AS Integer)
LPoke32 (hPtr AS Pointer, offset AS Integer, value AS Integer)
LPoke64 (hPtr AS Pointer, offset AS Integer, value AS Integer)
BPoke8  (hPtr AS Pointer, offset AS Integer, value AS Integer)
BPoke16 (hPtr AS Pointer, offset AS Integer, value AS Integer)
BPoke32 (hPtr AS Pointer, offset AS Integer, value AS Integer)
BPoke64 (hPtr AS Pointer, offset AS Integer, value AS Integer)

Others:
SwapMemory(srcPtr1, offset, length, destPtr2, offset)
CopyMemory(srcPtr1, offset, length, destPtr2, offset)

These functions being careful to properly handle overlapping memory
regions.

Naturally all the above functions should do bounds checking.

.=================================================.
|  Christopher BRIAN Jack aka "Gau of the Veldt"  |
+================================================='
| brian _AT_ brians-anime _DOT_ com
`=================================================-
Hi Spambots, my email address is sputnik at ...418...




More information about the Devel mailing list