;                 Debug
;                 AddSym
                  ExeObj
                  ObjFile 'SYS:AvailRAM'
                  ErrFile 'RAM:Assem.ERRORS'

;---------------------------------------------------------------------------;
;                 AvailRAM V1.00                 By - Jason Marianoff       ;
;                                                     4/161 Riding Road     ;
;                 Last update 16/5/1991               BALMORAL QLD 4171     ;
;                                                     Ph. (07) 899 2212     ;
;---------------------------------------------------------------------------;

_AbsExecBase      EQU     4                      ;Exec Library base address
_LVOOpenLibrary   EQU     -$228                  ;Exec functions
_LVOAvailMem      EQU     -$D8
_LVOGetMsg        EQU     -$174
_LVODelay         EQU     -$C6                   ;DOS function
_LVOOpenWindow    EQU     -$CC                   ;Intuition functions
_LVOPrintIText    EQU     -$D8
_LVOWindowToFront EQU     -$138
_LVOCloseWindow   EQU     -$48
MEMF_PUBLIC       EQU     1                      ;Any available RAM

                  MOVEA.L _AbsExecBase,A6
                  LEA.L   DOSName(PC),A1
                  CLR.L   D0
                  JSR     _LVOOpenLibrary(A6)
                  MOVEA.L D0,A5                  ;A5 - DOS Base
                  LEA.L   INTName(PC),A1
                  MOVE.L  #$1D,D0
                  JSR     _LVOOpenLibrary(A6)
                  MOVEA.L D0,A4                  ;A4 - Intuition Base
                  LEA.L   WindowStruct(PC),A0
                  MOVEA.L A4,A6
                  JSR     _LVOOpenWindow(A6)
                  MOVE.L  D0,D7                  ;D7 - Window Handle
                  BEQ     Abort
                  MOVEA.L D0,A3
                  MOVE.L  86(A3),D6              ;D6 - User Port Pointer
                  MOVEA.L 50(A3),A3              ;A3 - RastPort Address
Loop              MOVE.L  #180,D1
                  MOVEA.L A5,A6
                  JSR     _LVODelay(A6)          ;Wait approx 3 seconds
                  MOVEQ.L #MEMF_PUBLIC,D1
                  MOVEA.L _AbsExecBase,A6
                  JSR     _LVOAvailMem(A6)       ;Get Available RAM
                  CMPI.L  #$10000,D0
                  BCS.S   Finish                 ;Finish if RAM<65536 bytes
                  LEA.L   DecimalTable(PC),A0
                  LEA.L   Buffer(PC),A1
PadStart          MOVE.L  (A0)+,D1               ;Put spaces at start of
                  MOVE.B  #' ',(A1)+             ;number to be displayed
                  CMP.L   D1,D0
                  BCS.S   PadStart
NextDigit         MOVE.B  #10,D2                 ;Convert to decimal
GetDigit          SUBQ.B  #1,D2                  ;and store number
                  SUB.L   D1,D0
                  BCC.S   GetDigit
                  ADD.L   D1,D0
                  MOVE.B  #'9',D1
                  SUB.B   D2,D1
                  MOVE.B  D1,(A1)+
                  MOVE.L  (A0)+,D1
                  BNE.S   NextDigit
                  ADD.B   #'0',D0
                  MOVE.B  D0,(A1)
                  MOVEA.L A3,A0
                  LEA.L   TextStruct(PC),A1
                  MOVE.L  #$20,D0
                  CLR.L   D1
                  MOVEA.L A4,A6
                  JSR     _LVOPrintIText(A6)     ;Print the RAM available
                  MOVEA.L D7,A0
                  JSR     _LVOWindowToFront(A6)  ;Push this window forward
                  MOVEA.L D6,A0
                  MOVEA.L _AbsExecBase,A6
                  JSR     _LVOGetMsg(A6)         ;Check if our event has
                  TST.L   D0                     ;occured (Close gadget)
                  BEQ.S   Loop
Finish            MOVEA.L D7,A0                  ;Close window and return
                  MOVEA.L A4,A6
                  JSR     _LVOCloseWindow(A6)
Abort             CLR.L   D0
                  RTS

DOSName           DC.B    'dos.library',0
INTName           DC.B    'intuition.library',0
DecimalTable      DC.L    1000000,100000,10000,1000,100,10,0
WindowName        DC.B    '  AvailRAM  ',0
                  CNOP    0,2                    ;Align this block
WindowStruct      DC.W    327,0                  ;X,Y Top Left
                  DC.W    129,10                 ;Width,Height
                  DC.B    3,2                    ;Colours
                  DC.L    $200                   ;IDCMP Flags (Close only)
                  DC.L    $2084A                 ;Window Type
                  DC.L    0
                  DC.L    0
                  DC.L    WindowName             ;Pointer to Window name
                  DC.L    0
                  DC.L    0
                  DC.W    129,10                 ;Smallest Width,Height
                  DC.W    129,10                 ;Maximum Width,Height
                  DC.W    1                      ;Screen Type
TextStruct        DC.B    3,2                    ;Colours
                  DC.B    1                      ;Character Mode
                  CNOP    0,2                    ;Align this block
                  DC.W    0,1                    ;X,Y Position
                  DC.L    0                      ;Standard Character Set
                  DC.L    Text                   ;Pointer to Text
                  DC.L    0                      ;No More Text
Text              DC.B    'RAM:'
Buffer            DC.B    '        ',0

END
