⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rxdosfat.asm

📁 dos source
💻 ASM
📖 第 1 页 / 共 4 页
字号:
        jnz releaseClusterChain_08                      ; no -->

releaseClusterChain_16:
        restoreAllRegisters
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Find All Free Space                                          ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   ax     drive                                                ;
        ;                                                               ;
        ;  Output:                                                      ;
        ;   ax     drive                                                ;
        ;   cx     # free clusters                                      ;
        ;   es:bx  pointer to DPB                                       ;
        ;...............................................................;

AmountFreeSpace:

        Entry
        def  _drive, ax
        def  _freespace
        def  _currcluster
        def  _maxclusters
        def  _entriesPerSector

        ddef _dpb
        ddef _sector
        ddef _buffer
    
        call getDPB                                     ; (es:bx) Device Parameter Block
        stordarg _dpb, es, bx                           ; save address of dpb 
        jc amountFree_Return_Exit                       ; exit if invalid -->

        mov cx, word ptr es:[ _dpbFreeCount ][ bx ]     ; get free cluster count
        cmp cx, -1                                      ; is free space valid ?
        jz amountFree_checkDevice                       ; no, check device physically -->

amountFree_Return:
        getarg ax, _drive
        getdarg es, bx, _dpb
        mov word ptr es:[ _dpbFreeCount ][ bx ], cx     ; save valid number

amountFree_Return_Exit:
        Return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  check device physically
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

amountFree_checkDevice:

        xor dx, dx                                      ; starting cluster
        mov word ptr [ _freespace   ][ bp ], dx
        mov word ptr [ _currcluster ][ bp ], dx

        mov ax, word ptr es:[ _dpbMaxClusterNumber ][ bx ]
        add ax, 2                                       ; adj for first two used entries
        mov word ptr [ _maxclusters ][ bp ], ax

        test word ptr es:[ _dpbMaxClusterNumber ][ bx ], 0F000h
        jnz amountFree16BitFAT                          ; if 16-bit FAT -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  12 Bit FAT 
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

amountFree12BitFAT:
        push dx
        getarg ax, _drive                               ; restore drive
        getdarg es, bx, _dpb                            ; restore dpb
        call _get_12Bit_ClusterValue                    ; optimized get value

        or dx, dx                                       ; cluster free ?
        jnz amountFree12BitFAT_18                       ; no -->
        inc word ptr [ _freespace ][ bp ]

amountFree12BitFAT_18:
        pop dx
        inc dx
        cmp dx, word ptr [ _maxclusters ][ bp ]
        jc amountFree12BitFAT

        getarg cx, _freespace
        jmp amountFree_Return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  16 Bit FAT 
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

amountFree16BitFAT:
        mov cx, word ptr es:[ _dpbBytesPerSector ][ bx ]
        shr cx, 1                                       ; entries per sector
        storarg _entriesPerSector, cx

        xor cx, cx
        mov dx, word ptr es:[ _dpbFirstFAT ][ bx ]      ; where is first FAT table ?
        stordarg _sector, cx, dx

        mov ax, word ptr [ _drive ][ bp ]               ; get drive
        call readBuffer                                 ; read FAT Table
        stordarg _buffer, es, di                        ; save buffer address
        or byte ptr es:[ ccbStatus ][ di ], ( ccb_isFAT )

amountFree16BitFAT_08:
        xor ax, ax
        getarg cx, _entriesPerSector
        mov di, word ptr [ _buffer. _pointer ][ bp ]
        lea di, offset ccbData [ di ]                   ; start of buffer

amountFree16BitFAT_12:
        repnz scasw                                     ; search for null word
        jnz amountFree16BitFAT_16                       ; count is zero -->
        inc word ptr [ _freespace ][ bp ]               ; increment free space
        or cx, cx                                       ; more clusters this sector ?
        jnz amountFree16BitFAT_12                       ; yes -->

amountFree16BitFAT_16:
        mov ax, word ptr [ _entriesPerSector ][ bp ]
        add ax, word ptr [ _currcluster      ][ bp ]
        mov word ptr [ _currcluster  ][ bp ], ax

        mov cx, word ptr [ _maxclusters ][ bp ]
        sub cx, ax                                      ; clusters remaining
        jc amountFree16BitFAT_24                        ; if at end -->
        je amountFree16BitFAT_24                        ; if at end -->

        cmp cx, word ptr [ _entriesPerSector ][ bp ]
        jnc amountFree16BitFAT_20
        mov word ptr [ _entriesPerSector ][ bp ], cx    ; max to read last sector

amountFree16BitFAT_20:
        getarg ax, _drive                               ; get drive
        getdarg es, di, _buffer                         ; no longer scan through ccb
        inc word ptr [ _sector ][ bp ]
        getdarg cx, dx, _sector                         ; get next sector
        call readSelBuffer                              ; else read buffer
        jmp amountFree16BitFAT_08
        
amountFree16BitFAT_24:
        getarg cx, _freespace
        jmp amountFree_Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Allocate Next Free Cluster                                   ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   ax     drive                                                ;
        ;   dx     recommended start search address                     ;
        ;                                                               ;
        ;  Output:                                                      ;
        ;   ax     drive                                                ;
        ;   dx     allocated cluster number                             ;
        ;   cy     if end of cluster chain.                             ;
        ;...............................................................;

AllocateCluster:

        Entry
        def _drive, ax
        def _cluster, dx
        def _maxclusters
        ddef _dpb

        call getAddrDPB                                 ; (es:bx) Device Parameter Block
        jc allocateCluster_NoneFree                     ; if device invalid -->

        stordarg _dpb, es, bx                           ; save _dpb address

        mov dx, word ptr es:[ _dpbMaxClusterNumber ][ bx ]
        mov word ptr [ _maxclusters ][ bp ], dx

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  loop through entire FAT table search for free cluster
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        getarg dx, _cluster                             ; starting cluster

allocateCluster_12:
        push dx
        mov ax, word ptr [ _drive ][ bp ]               ; get drive
        call getNextCluster                             ; get value at cluster

        mov cx, dx                                      ; cluster value
        pop dx                                          ; cluster number
        or cx, cx                                       ; is cluster free ?
        jz allocateCluster_18                           ; yes -->

        inc dx
        cmp dx, word ptr [ _cluster ][ bp ]             ; back at recommended cluster ?
        jz allocateCluster_NoneFree                     ; end of search -->

        cmp dx, word ptr [ _maxclusters ][ bp ]
        jc allocateCluster_12

        xor dx, dx                                      ; loop back around to start of disk
        jmp allocateCluster_12

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  if no space available on disk
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

allocateCluster_NoneFree:
        stc
        jmp short allocateCluster_Return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  update allocated buffer
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

allocateCluster_18:
        mov cx, 0FFFFh                                  ; updated value
        call updateClusterValue                         ; update value

        getdarg es, bx, _dpb                            ; get _dpb address
        cmp word ptr es:[ _dpbFreeCount ][ bx ], -1     ; value initialized ?
        jz allocateCluster_Return                       ; no -->
        dec word ptr es:[ _dpbFreeCount ][ bx ]         ; subtract allocated unit
        or dx, dx                                       ; no carry

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

allocateCluster_Return:
        getarg ax, _drive
        getdarg es, bx, _dpb
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Allocate/Init A Cluster.                                     ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Note:                                                        ;
        ;   This function will allocate a cluster and completely fill   ;
        ;   it with zeroes.  Ideal for directories which must have      ;
        ;   initialized entries.                                        ;
        ;                                                               ;
        ;                                                               ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   ax     drive                                                ;
        ;                                                               ;
        ;  Output:                                                      ;
        ;   ax     drive                                                ;
        ;   dx     cluster                                              ;
        ;   es:di  pointer to a ccb buffer                              ;
        ;...............................................................;

AllocateInitCluster:

        Entry
        def _drive, ax
        def _secPerCluster
        def _cluster
        ddef _sector

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  allocate a free cluster / sector
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        saveRegisters si, bx

        call getAddrDPB                                 ; point to dpb

        xor dx, dx
        mov cx, 0001
        add cl, byte ptr es:[ _dpbClusterSizeMask ][ bx ]
        mov word ptr [ _secPerCluster ][ bp ], cx

        call AllocateCluster                            ; allocate a cluster
        mov word ptr [ _cluster ][ bp ], dx
        jc AllocateInitCluster_12

        call computeLogSectorNumber                     ; cluster -> sector number
        stordarg _sector, cx, dx                        ; save sector #

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  allocate a buffer/ init
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        call selBuffer                                  ; allocate a buffer
        push di                                         ; pointer to header
        lea di, offset ccbData [ di ]                   ; point to data buffer
        clearMemory sizeCCBData                         ; clear to zeroes
        pop di                                          ; pointer to header

AllocateInitCluster_08:
        call updateChangedCCB                           ; MUST force write updated buffer

        add word ptr es:[ ccbLBN. _low  ][ di ], 0001
        adc word ptr es:[ ccbLBN. _high ][ di ], 0000
        dec word ptr [ _secPerCluster  ][ bp ]          ; continuous write of directory 
        jnz AllocateInitCluster_08

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        getdarg cx, dx, _sector
        mov word ptr es:[ ccbLBN. _low  ][ di ], dx
        mov word ptr es:[ ccbLBN. _high ][ di ], cx
        or cx, cx                                       ; no carry.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -