**  Programmer:   John Veldthuis
**                21 Ngatai Street
**                Manaia, Taranaki
**                New Zealand
**    Placed in the Public Domain
**    09 Febuary 1988


   include  "exec/types.i"
   include  "exec/memory.i"

   xref  _LVOOpenLibrary
   xref  _LVOCloseLibrary
   xref  _LVORawDoFmt
   xref  _LVOOutput
   xref  _LVOAvailMem
   xref  _LVOWrite

SysBase  equ   4

Main:
      move.l   SysBase,a6
      lea      DosName,a1
      moveq    #0,d0
      jsr      _LVOOpenLibrary(a6)   ;open Dos Library
      tst.l    d0
      bne.s    DosOK
      moveq.l  #20,d0
      rts
DosOK move.l   d0,DosBase
      move.l   d0,a6
      jsr      _LVOOutput(a6)        ;find standard output device
      move.l   d0,stdout
      move.l   SysBase,a6
      move.l   #MEMF_CHIP,d1
      jsr      _LVOAvailMem(a6)      ;find out how much chip memory avail
      move.l   d0,ChipMem
      move.l   #MEMF_FAST,d1
      jsr      _LVOAvailMem(a6)      ;find out how much fast memory avail
      move.l   d0,FastMem
      lea      FastMess,a0
      jsr      Printf                ;format output message
      jsr      Write                 ;print how much fast memory
      move.l   ChipMem,d0
      lea      ChipMess,a0
      jsr      Printf
      jsr      Write                 ;print out how much chip memory
      move.l   ChipMem,d0
      add.l    FastMem,d0            ;add the two togeather to get total
      lea      TotMess,a0
      jsr      Printf
      jsr      Write                 ;print out total memory
      move.l   SysBase,a6
      move.l   DosBase,a1
      jsr      _LVOCloseLibrary(a6)  ;close Dos library
      rts



Write    lea      Buffer,a0          ;Get formated message buffer
         move.l   a0,d2
Loop     tst.b    (a0)+              ;scan till a zero byte found
         bne.s    Loop
         move.l   a0,d3
         sub.l    d2,d3              ;calculate lenght of message
         sub.l    #1,d3
         move.l   DosBase,a6
         move.l   stdout,d1
         move.l   #Buffer,d2
         jsr      _LVOWrite(a6)      ;write message to standard output
         rts


Printf   move.l   d0,-(sp)           ;number of bytes
         move.l   sp,a1
         lea   Expand,a2
         lea   Buffer,a3
         move.l   SysBase,a6
         jsr      _LVORawDoFmt(a6)   ;format string
         addq.l   #4,sp
         rts



Expand   move.b   d0,(a3)+           ;routine for RawDoFmt
         rts



DosBase  dc.l  0
stdout   dc.l  0
ChipMem  dc.l  0
FastMem  dc.l  0

Buffer   ds.b  60
DosName  dc.b  'dos.library',0
FastMess dc.b  'You have %ld bytes of Fast memory available',10,0
ChipMess dc.b  'You have %ld bytes of Chip memory available',10,0
TotMess  dc.b  'You have %ld bytes of Total memory avaiable',10,0


      end

