            opt     l+,o+,ow-
*
*   extgfx.s version 8.1 - © Copyright 1990 Jaba Development
*
*   Author    : Jan van den Baard
*   Assembler : Devpac vesion 2.14
*
            incdir  'sys:devpac_inc/'
            include 'mymacros.i'
            include 'intuition/intuition.i'
            include 'exec/memory.i'
            include 'graphics/graphics_lib.i'
            include 'intuition/intuition_lib.i'
            include 'exec/exec_lib.i'

            XREF    _GfxBase
            XREF    DoBuf
            XREF    StrLen

            XDEF    FormatText

FormatText:     movem.l a2-a6,-(sp)
                move.l  a2,a4               ; arguments to a4
                move.l  a1,a3               ; format string to a3
                move.l  a0,a2               ; rastport to a2
                move.l  (_SysBase).w,a6
                move.l  #512,d0             ; 512 bytes MAXIMUM
                moveq   #MEMF_PUBLIC,d1
                libcall AllocMem            ; allocate buffer
                move.l  d0,a5
                beq.s   NoMem               ; buffer allocation failed
                movem.l a2-a3,-(sp)         ; save registers
                move.l  a3,a0
                move.l  a4,a1
                move.l  #DoBuf,a2
                move.l  a5,a3
                libcall RawDoFmt            ; format the string
                movem.l (sp)+,a2-a3         ; restore registers
                move.l  _GfxBase,a6
                move.l  a5,a0
                bsr     StrLen
                move.l  d0,-(sp)
                move.l  a5,a0               ; string in a0
                move.l  a2,a1               ; rastport in a1
                libcall Text                ; print the string
                move.l  (_SysBase).w,a6
                move.l  a5,a1
                move.l  #512,d0             ; free the buffer
                libcall FreeMem
                move.l  (sp)+,d0
                bra.s   EndFT
NoMem:          cldat   d0
EndFT:          movem.l (sp)+,a2-a6
                rts
