Hi!
I'm working on a series of game dev tutorials for VFX.
The code relies on a well-known gaming library, Allegro 5.
The (not show-stopping but still significant) challenge is that when using ndp387.fth, we're limited to 8 floats, but the Allegro API has many functions that take 8 or more floats and the FFI doesn't support hfp387.fth.
I talked with Stephen and he guided me to Extern.fth, where I made the following change:
: CopyFLOAT \ ^ai --
\ Compile code to copy FTOS to the frame as a float or double
[ FPSystem 1 = [if] \ external float stack
] [a \ pop float from external float stack into the FPU
mov eax, FSP-OFFSET [esi] \ get FP stack pointer
fld fword 0 [eax] \ push FNOS to FPU
lea eax, FPCELL [eax] \ update stack pointer
mov FSP-OFFSET [esi], eax
a] [a] [
[then] ]
case dup ai.size @
4 of >r [a fstp float a] r> ai.FrameOff @ [a [esp] a] [a] endof
8 of >r [a fstp double a] r> ai.FrameOff @ [a [esp] a] [a] endof
10 of >r [a fstp extended a] r> ai.FrameOff @ [a [esp] a] [a] endof
err_CGsize throw
endcase
;
I've verified that the extra code - copy-pasted directly from the definition of >FPU in hfp387.fth - is generated in calls to foreign functions taking floats. But I'm getting an access violation.
The repository is here -> https://github.com/RogerLevy/vfxland
The modified Extern.fth is included. The test is in test7_tilemap_hfp.f.
Any help is appreciated!
(Btw, an official way to format code might be a good addition to the forums)