REM Free/total disk space in PDS 7.1
' Note: greater approx. 2 GB not reported.

' declare register structure
TYPE RegtypeX
  AX AS INTEGER
  BX AS INTEGER
  CX AS INTEGER
  DX AS INTEGER
  BP AS INTEGER
  SI AS INTEGER
  DI AS INTEGER
  Flags AS INTEGER
END TYPE
DECLARE SUB InterruptX (N AS INTEGER, I AS RegtypeX, O AS RegtypeX)
DIM InregsX AS RegtypeX, OutregsX AS RegtypeX

'--------D-2136-------------------------------
'INT 21 - DOS 2+ - GET FREE DISK SPACE
'        AH = 36h
'        DL = drive number (00h = default, 01h = A:, etc)
'Return: AX = FFFFh if invalid drive, Else:
'            AX = sectors per cluster
'            BX = number of free clusters
'            CX = bytes per sector
'            DX = total clusters on drive
'Notes:  Free space on drive in bytes is AX * BX * CX
'        Total space on drive in bytes is AX * CX * DX
'Errors: (FAT32 drive)
'        The reported total and free space are limited to 2GB-64KB should
'        they exceed that value when using FAT16 reporting in plain Dos.
'        In windows Dos box the maximum value reported is 2GB-32KB*10 using
'        FAT16 reporting. Free disk space appears to be 16KB less than
'        reported by FAT32 functions.

' get drive letter
IF Command$ <> "" THEN
   D$ = LEFT$(Command$, 1)
ELSE
   LINE INPUT "Disk drive letter? ", D$
   D$ = UCASE$(D$)
END IF

' check control break
DEF SEG = &H40
IF PEEK(&H71) THEN
   Flag = -1
END IF
POKE &H71, &H0
DEF SEG
IF Flag THEN
   END
END IF

' check drive
InregsX.AX = &H3600
InregsX.DX = ASC(UCASE$(D$)) - 64
CALL InterruptX(&H21, InregsX, OutregsX)
IF OutregsX.AX = &HFFFF THEN
   PRINT "Invalid drive."
   END
END IF

' store drive space
If OutregsX.AX<0 Then
   SectorsPerCluster#=Cdbl(OutregsX.AX+65536)
Else
   SectorsPerCluster#=Cdbl(OutregsX.AX)
Endif
If OutregsX.BX<0 Then
   FreeClusters#=Cdbl(OutregsX.BX+65536)
Else
   FreeClusters#=Cdbl(OutregsX.BX)
Endif
If OutregsX.CX<0 Then
   BytesPerSector#=Cdbl(OutregsX.CX+65536)
Else
   BytesPerSector#=Cdbl(OutregsX.CX)
Endif
If OutregsX.DX<0 Then
   TotalClusters#=Cdbl(OutregsX.DX+65536)
Else
   TotalClusters#=Cdbl(OutregsX.DX)
Endif

' calculate drive space
DiskSpace# = BytesPerSector# * SectorsPerCluster# * FreeClusters#
PRINT "Free disk space"; DiskSpace#; "bytes."
TotalSpace# = BytesPerSector# * SectorsPerCluster# * TotalClusters#
PRINT "Total disk space"; TotalSpace#; "bytes."
END
