;*; Updated on 06-Dec-91 at 9:16 AM by Michele Tonti; edit time: 0:00:12
;*************************** AMUS Program Label ******************************
; Filename: DSKFRE.M68                                      Date: 12/6/91
; Category: SBR          Hash Code: 561-445-106-040      Version:
; Initials: KUNI/AM      Name: RENE S. HOLLAN
; Company: UDISCO LTD.                             Telephone #: 5144818107
; Related Files: DSKFRE.SBR,DSKFRE.DOC,DSKFRE.BAS,DSKFRE.RUN,DSKFRE.LIT
; Min. Op. Sys.:                               Expertise Level:
; Special:
; Description: Returns the largest contiguous block free and the total number
; of blocks free on a specified device.
;
;*****************************************************************************
;************************************************************************
;                                                                       *
;                               DSKFRE BASIC SUBROUTINE                 *
;                                                                       *
;************************************************************************
;
;                                   NOTICE
;
;All    rights   reserved.  This software is the property of UDISCO LTD.  and
;the material contained herein is  the   proprietary   property   and   trade
;secrets    of    UDISCO  LTD.,  embodying  substantial  creative efforts and
;confidential information, ideas and expressions, no part of  which  may   be
;reproduced   or  transmitted  in  any  form  or  by  any  means, electronic,
;mechanical,  or  otherwise,  including  photocopying  or  input  into    any
;information   storage  or  retrieval  system  without  the  express  written
;permission of UDISCO LTD.
;
;Permission to copy and use is granted to AMUS members for non commercial
;purposes only.
;
;       Author:         Rene S. Hollan
;       Date Written:   June 3, 1989
;
;       COPYRIGHT (C) 1989 - UDISCO LTD.
;
;Edit History
;
;[100]  3 July 89
;       Coding starts. /RSH
;
;       Usage:  XCALL DSKFRE,<device spec.>,<contig>,<total>
;
;       Where   <device spec.> is device specification (i.e. DSK0:),
;
;               <contig> receives size of largest contigous block,
;
;               <total> receives total number of blocks free.
;
;               <contig> and <total> must be mapped as floating point
;       variables, i.e.:
;
;               MAP1 contig,F,6
;               MAP1 total,F,6
;
;               If an error occurs (bad device spec., etc.) contig is set to
;       0 and the file system error code is returned in total.
;
;       Note that the device driver for the specified device must be loaded
; into memory and that there must be sufficient memory available in the
; BASIC impure area to hold a 24 byte result table (from DSKFRE), a DDB,
; and a 512 byte disk buffer.
;

       SEARCH  SYS
       SEARCH  SYSSYM

       OBJNAM  0,0,[SBR]

VMAJOR  =       1                       ; major version
VMINOR  =       0                       ; minor version
VSUB    =       0                       ; sub version
VEDIT   =       100.                    ; edit level
VWHO    =       0                       ; patch level

; On entry A3 points to the following parameter block

OFINI                                   ; BASIC calling parameter area
OFDEF   Bas.No,2                                ;    number of parameters (3)
OFDEF   Bas.T1,2                                ;    type code (string)
OFDEF   Bas.A1,4                                ;    variable address
OFDEF   Bas.L1,4                                ;    variable length
OFDEF   Bas.T2,2                                ;    type code (string)
OFDEF   Bas.A2,4                                ;    variable address
OFDEF   Bas.L2,4                                ;    variable length
OFDEF   Bas.T3,2                                ;    type code (string)
OFDEF   Bas.A3,4                                ;    variable address
OFDEF   Bas.L3,4                                ;    variable length
OFSIZ   Bas.Sz                          ; parameter area size

DSKFRE: PHDR    -1,PV$RSM,PH$REU!PH$REE  ; program header
       MOV     Bas.A1(A3),A2           ; A2 -> device name
       MOV     A4,A5                   ; A5 -> device table
       LEA     A4,DF.SIZ(A4)           ; adjust for device table size
       ORB     #D$BYP+D$ERC,D.FLG(A4)  ; bypass error messages
       FSPEC   @A4                     ; FSPEC the device name into imp. area
       BNE     ERR                     ; error

       MOV     A4,D.BUF(A4)            ; D.BUF --> base of DDB
       ADD     #D.DDB,D.BUF(A4)        ; D.BUF --> buffer area
       MOV     #512.,D.SIZ(A4)         ; set buffer size
       CLR     D.DVR(A4)               ; no driver
       ORB     #D$INI,D.FLG(A4)        ; set buffer inited flag
; WARNING!!! - DEVICE DRIVER MUST BE IN MEMORY OR ALL THIS WILL BLOW UP IN
;              YOUR FACE!
       DSKFRE  @A4,@A5                 ; get free space on device
       BEQ     OK                      ; no error

ERR:    CLR     D1                      ; clear contiguous blocks
       MOV     D1,DF.HOL(A5)           ; ...
       MOVB    D.ERR(A4),D1            ; set error code in total blocks
       MOV     D1,DF.FRE(A5)           ; ...

OK:
       MOV     Bas.A2(A3),A1           ; A1 -> contiguous space result
       FLTOF   DF.HOL(A5),@A1          ; return contiguous space
       MOV     Bas.A3(A3),A1           ; A1 -> total space result
       FLTOF   DF.FRE(A5),@A1          ; return total space

       RTN                             ; and return

       END