; Bin package - version 23.12.88

               XDEF    LinkTop
               XDEF    Bin

               include 'package.i'

; Initialisation section
               MOVE.L  D0,A0                  ; Address of package structure
               MOVE.L  #LinkTop,PckTopId(A0)  ; Address of top-link
               CLR.W   D0                     ; No error
               RTS

; Return number as binary string
Bin:           MOVE.L  A5,D2           ; Put address of string in D2
               MOVE.B  #'%',(A5)+
               MOVEQ   #30,D4          ; Digit counter
               MOVE.L  -9(A5),D1       ; Get number
               BRA.S   Bin2            ; .. and branch into loop
Bin1:          ADD.L   D1,D1
Bin2:          DBMI    D4,Bin1         ; Loop until 1. non zero bit
               ADDQ.W  #1,D4
               CLR.B   D5
Bin3:          MOVE.B  #'0',D0
               ADD.L   D1,D1           ; Digit value into carry
               ADDX.B  D5,D0              
               MOVE.B  D0,(A5)+        ; Set next character of string
               DBRA    D4,Bin3
BinEnd:        MOVE.L  A5,D3
               SUB.L   D2,D3           ; Calculate length
               RTS                     ; .. and return

               SECTION BinData,DATA

BinLink:       DC.L    0
               DC.L    BinName
               DC.W    strgcode        ; String function
               DC.W    1               ; One argument
               DC.W    longval         ; Arg type = long int value
               DC.L    Bin             ; Routine address
BinName:       DC.B    'BIN$',0

               CNOP    0,2
LinkTop:       DC.L    BinLink

               END 
