; Free Memory at absolute addresses
; Call Like
; FreeMem $20000 $30000
      INCLUDE "includes/MACS.ASM"

      INIT_AMIGA


        CMPI.B #' ',(A0)  ; check for any characters
        BLT.S Instructions ; print out instructions and exit
        BSR HexA0_D0
        MOVEA.L D0,A1     ; get start address
        CMPI.B #' ',(A0)  ; check for any characters
        BLT.S Instructions ; print out instructions and exit
        BSR HexA0_D0
        SUB.L A1,D0       ; determine length of memory area
        CALLSYS  FreeMem  ; call FreeMem
        TST.L D0          ; deallocation OK ?
        BNE.S Success_exit
        BRA.S Error_Exit  ; print text and signal error
Success_exit:
        BSR    PRINT
        DC.B 'Memory DEallocation successfull',10,0
        CLR.L D0          ; signal no error
        BRA    Exit_prog
Instructions:             ; print out instructions and exit
        BSR    PRINT
 DC.B '(C) 07.88 by RAKO',10
 DC.B 'Usage: FreeMem  30000  50000 DEallocates from $30000 to $50000',10
 DC.B '!!!!!!!!!!! BE VERY CAREFULL WITH THIS COMMAND !!!!!!!!!!!!',10,0
        MOVEQ  #$64,D0    ; signal error
        BRA    Exit_prog  ; and exit
Error_Exit:
        BSR    PRINT
        DC.B 'Could not DEallocate memory!',10,0
        MOVEQ  #$64,D0    ; signal error
        BRA    Exit_prog  ; and exit
HexA0_D0:                 ; get Hex number from text (A0)  -> D0
        CLR.L D0
; Hack leading spaces
Hack_Blank:
         CMP.B    #' ',(A0)+
         BEQ.S    Hack_Blank
         SUBQ.L   #1,A0
LC6642C:
        MOVE.B (A0)+,D1
        CMPI.B #' ',D1    ; space ?
        BEQ.S LC66454
        CMPI.B #10,D1     ; Line Feed ?
        BEQ.S LC66454
        CMPI.B #'A',D1    ; letter 'A' ?
        BLT.S LC66446
        SUBI.B #55,D1
        BRA.S LC6644A
LC66446:
        SUBI.B #$30,D1    ; generate number from 10 to 15
LC6644A:
        ANDI.B #$F,D1     ; only numbers from 10 to 15 are relevant
        LSL.L #4,D0       ; place for next 4 bits
        OR.B D1,D0        ; insert next 4 bits
        BRA.S LC6642C     ; continue until end of Number
LC66454:RTS

Exit_prog:
        EXIT_AMIGA

        END


