To allocate global memory that will be used by other applications than your own (AV-protocol, BubbleGEM, etc.) you cannot use the standard MALLOC() but should instead implement these routines supplied by Ulli Gruszka of RUN! Software.
Call this function once somewhere in your startup code:
mxmask%=@mxmask
FUNCTION mxmask
$F%
IF GEMDOS(68,L:-1,0)=-32
RETURN 0
ELSE IF GEMDOS(290,-1)=-32
RETURN 3
ELSE
RETURN -1
ENDIF
ENDFUNC
Call this function if you need memory which will be used by other applications (AV-protocol, BubbleGEM)
bubblebuf%=@mxalloc_global(256,3)
FUNCTION mxalloc_global(amount%,mode&)
$F%
' mode& must be one of the following:
' 0 = ST-RAM only
' 1 = TT-RAM only
' 2 = EITHER, ST-RAM prefered
' 3 = EITHER, TT-RAM prefered
'
IF mxmask%<>0
mode&=OR(mode&,&X100000)
RETURN GEMDOS(68,L:amount%,mode& AND mxmask%)
ELSE
RETURN MALLOC(amount%)
ENDIF
ENDFUNC
|
Explanation of the problem, by Thomas Binder (snipped from the same thread in CSAS)
There's a problem on TT and Falcon TOS: Both crash or exhibit other strange behaviour when Mxalloc() is called with memory protection flags. Thus, the code Ulli provided ensures that the memory protection flags are masked off before a call to Mxalloc() is being made when there's no memory protection.
Note that the code doesn't actually test for memory protection, but for the existance of the Sysconf()-call. This is a GEMDOS call present in all versions of MiNT supporting memory protection, but not in TOS or MagiC. Andreas Kromke agreed that - if he implemented memory protection - MagiC would get this call, too. |