*	MXALLOC is written by Klaus Pedersen (micro@imada.ou.dk).
*
* MXALLOC is a auto-detecting memory allocation function.

MXALLOC         EQU $44
MALLOC          EQU $48
GemDos          EQU 1

                GLOBL Mxalloc
                
; void *Mxalloc(long amount, int type);
;   type : 
;     0 - ST ram needed (DMA sound/ACSI/VIDEO)
;     1 - TT ram needed...
;     2 - ST ram if possible else TT...
;     3 - TT ram if possible else ST (SCSI/LAN)

; TC passes :
;   'amount' in D0.l
;   'type'   in D1.w

                DATA
AllocFunc:      DC.W     MXALLOC      ; To start with - use MXALLOC!
                                      ; if that fails - use MALLOC
                TEXT

Mxalloc:        move.l   A2,-(SP)     ; save A2
                move.w   D1,-(SP)     ; push memory type
                move.l   D0,-(SP)     ; push alloc size.
                move.w   AllocFunc,-(SP)
                trap     #GemDos
                moveq    #-$20,D1     ; Test for "Unknown Gemdos function"
                cmp.l    D1,D0
                bne.b    return
                
; We get here only ones! - because the first function call automatically
; change to a Malloc, if we can't do a Mxalloc
                move.w   #MALLOC,(SP) ; If no Mxalloc then use Malloc
                move.w   (SP),AllocFunc ;
                trap     #GemDos

return:         addq.l   #8,SP        ; Tidy stack
                movea.l  D0,A0        ; Pointers in Address regs.
                movea.l  (SP)+,A2     ; restore A2
                rts

                END
                