diskParametertable       dd 0
_FATbuffer_SectorNumber  dd 0
_FATBuffer               dd 0
RootDirSector            dd 0
ReservedBeforeDataSector dd 0
NXBIO_ClusterAddr        dw 0
NXDOS_ClusterAddr        dw 0

DBT                      dd 0

lastread dw 0
dirty    db 0
fatdrive db 0
sectorpercluster db 0
reserved db 0
rootentries db 0
sectors     db 0

fatbuf   db 512 dup(0)
fatbuf2  db 512 dup(0)

; =================================================================
mount proc far 
; DL = Drive
; Mount a volume. if volume mounts then a CF=Z and al=0 else CF=NZ
; =================================================================
     mov  fatdrive, dl
     mov  ax, 0
     mov  dirty, al  
     mov  ax, -1  
     mov  lastread, ax

     ; get harddrive parameters
     mov  ah, 8
     mov  dl, 0               ; C:
     add  dl, 80h
     clc
     int  13h
     jc   mounterr
          mov  hd_cyls, cx
          mov  nd_head, dh
          mov  word ptr DBT, di
          mov  word ptr DBT+2, es
     ;
     push cs
     pop  ax
     mov  es, ax
     mov  bx, offset fatbuf
     mov  cx, 0001h
     mov  dx, 0100h
     mov  ax, 0201h
     int  13h         ; read
     ; where root directory is stored
     xor  si, si
     mov  ax, word ptr es:[NXBIO_ClusterAddr][si]
     mov  dx, word ptr es:[NXDOS_ClusterAddr][si]
     ; ??? 
     mov  word ptr es:[NXBIO_ClusterAddr], ax
     mov  word ptr es:[NXDOS_ClusterAddr], dx

      ; readsector(fatdrive, 0, fatbuf) ; read bootsector
      ; check FATID for "FAT16"
      ; if no fat16 then abort 
      mov  al, byte ptr fatbuf+0dh
      mov  sectorpercluster, al
      ; check for valid sectorspercluster abort if not valid
      mov  al, byte ptr fatbuf+0eh
      mov  reserved, al
      mov  al, fatbuf+10h  ; fat count
      cmp  al, 2
      jne  mounterr
           mov  al, fatbuf+11h
           mov  rootentries, al
           mov  al, fatbuf+13h
           mov  sectors, al
           cmp  al, 0
           jne  sectok
                mov  al, fatbuf+20h
                mov  sectors, al
sectok:
           mov  al, fatbuf+16h
           mov  sectorsperfat, al
           mov  ax, fatbuf+1feh    ; check for bad fat signature
           cmp  ax, 0aa55h
           jne  mounterr
                ;
                ; calculate regions 
                ;
                fat1 := start + reserved
                rootdir := (fat1 + 2 * sectorsperfat) << SECTORSHIFT
                rootdirend := rootdir + (rootentries << DIRSHIFT)
                dataregion := 1 + ((rootdirend - 1) >> SECTORSHIFT) - 2 
                              * sectorspercluster
   totclusters := ((sectors - dataregion + start) >> clustershift)
                if (totclusters > $fff0) abort ; too many clusters  
mountok:
      clc
      xor  ax, ax
      ret
mounterr:
      stc
      ret
mount endp

