; load a file to the specified location
; LBYTES filename hexaddress

        INCLUDE "includes/MACS.ASM"
        INCLUDE "includes/FileMacs.ASM"
        INCLUDE "includes/TTY.ASM"

       INIT_AMIGA

; Number of parameters OK ?

      CMP.B          #2,D0
      BGE.S          Cont_1
      BSR            PRINT
      DC.B           '(C) 07.88 by RAKO',10
      DC.B           'USAGE: LBYTES filename hexaddress',10
      DC.B           'Loads the file to memory at address',10,0
      BRA.S          EXIT_1
Cont_1:
      MOVEM.L        A0/D0,-(A7) ; store string and length for further use
      BSR            SKIP_PARM
      MOVE.L         A0,A3       ; store begin of 2nd parameter
      BSR            HexA0_D0
      MOVE.L         D0,A2       ; store address in A2
      MOVEM.L        (A7)+,A0/D0
      MOVE.L         A3,D0       ; get begin of 2nd parameter
      SUB.L          A0,D0       ; subtract begin of first parameter
skip_spc:
      SUBQ.W         #1,D0    ; length -1
      CMP.B          #32,(A0,D0.W) ; blank ?
      BEQ.S          skip_spc
      MOVE.B         #0,1(A0,D0.W) ; replace blank with NULL

; load file to Memory address
      OPEN_IN        1,A0
      FSIZE          1,D0 ; get length of file
      STO            D0,Length
; now load File
      LOAD           1,A2
; close file
      FCLOSE         1

; type number of bytes used
      BSR            TXTOUT
      DC.B           'Number of bytes: $',0
      RCL            Length,D0
      BSR            HEXO32
      MOVEQ          #10,d0
      BSR            OUTCH
      BSR            PRINTBUF

EXIT_1:
       MOVEQ         #0,D0
       EXIT_AMIGA
Length:  DS.L  1

SKIP_PARM:                ; skip one Parameter in (A0)
         CMP.B    #' ',(A0)+ ; find first non blank character
         BEQ.S    SKIP_PARM
_skip_l1:
         CMP.B    #' ',(A0)+ ; find first Blank after letters
         BGT.S    _skip_l1
         SUBQ.L   #1,A0
         RTS              ; thats it.

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
      END
