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

📄 rxdossft.asm

📁 dos source
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        and ax, sftDrivemask
        call getDPB                                     ; get DPB address

        mov cx, word ptr es:[ _dpbVolumeId. _High ][ bx ]
        mov dx, word ptr es:[ _dpbVolumeId. _Low  ][ bx ]

        getdarg es, di, _sftPointer                     ; sft pointer
        mov word ptr es:[ sftVolumeId. _High ][ di ], cx
        mov word ptr es:[ sftVolumeId. _Low  ][ di ], dx
        clc

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

        pop ds
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Build Access Area from SFT                                   ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   es:di  SFT entry                                            ;
        ;   ss:bx  access block                                         ;
        ;...............................................................;

buildAccessRef:

        Entry
        ddef _fileposAtBegCluster
        def  _clusterSize

        saveRegisters si, cx

        push es
        push di
        push bx

        mov ax, word ptr es:[ sftDevInfo    ][ di ]
        and ax, sftDrivemask
        push ax
        mov dx, word ptr es:[ sftBegCluster ][ di ]
        call initdiskAccess                             ; [ax] is drive, [dx] is cluster

        pop ax                                          ; restore drive
        call getDPB                                     ; gets a guaranteed init drive block

        mov ax, word ptr es:[ _dpbBytesPerSector ][ bx ]
        mov cl, byte ptr es:[ _dpbClusterSizeShift ][ bx ]
        shl ax, cl                                      ; bytes per cluster
        storarg _clusterSize, ax

        pop bx
        pop di
        pop es

        mov cx, word ptr es:[ sftRelCluster ][ di ]
        or cx, cx                                       ; cluster zeroed out ?
        jz buildAccessRef_08                            ; can't use curr cluster -->

        xor dx, dx
        mul cx                                          ; file position at start of cluster
        stordarg _fileposAtBegCluster, dx, ax           ; save

        mov ax, word ptr es:[ sftFilePosition. _low  ][ di ]
        mov dx, word ptr es:[ sftFilePosition. _high ][ di ]
        sub ax, word ptr [ _fileposAtBegCluster. _low  ][ bp ]
        sbb dx, word ptr [ _fileposAtBegCluster. _high ][ bp ]
        jc buildAccessRef_08                            ; can't use curr cluster -->
        or dx, dx                                       ; distance greater than 65k ?
        jnz buildAccessRef_08                           ; can't use curr cluster -->

        cmp ax, word ptr [ _clusterSize ][ bp ]         ; greater than cluster size ?
        jge buildAccessRef_08                           ; can't use curr cluster -->

   ; there's a bug here, so we'll just ignore it for now
   ; by ALWAYS exiting.  This patch could be a problem
   ; for larger files, so it needs to be fixed !

     jmp buildAccessRef_08                           ; can't use curr cluster -->
     

        mov dx, word ptr es:[ sftCurCluster ][ di ]
        mov word ptr ss:[ diskAcCurCluster ][ bx ], dx  ; ok, within cluster 

        getdarg dx, ax, _fileposAtBegCluster            ; offset at start of cluster
        mov word ptr ss:[ diskAcOffAtBegBuffer. _low  ][ bx ], ax
        mov word ptr ss:[ diskAcOffAtBegBuffer. _high ][ bx ], dx
        mov word ptr ss:[ diskAcOffAtBegCluster. _low  ][ bx ], ax
        mov word ptr ss:[ diskAcOffAtBegCluster. _high ][ bx ], dx

buildAccessRef_08:
        restoreRegisters cx, si
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Set Relative Cluster Number From SFT FilePosition            ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   es:di  SFT entry                                            ;
        ;                                                               ;
        ;  Preserved:                                                   ;
        ;   CX, ES, DI                                                  ;
        ;...............................................................;

_computeRelativeCluster:

        push cx
        push es
        push di

        mov ax, word ptr es:[ sftDevInfo    ][ di ]
        and ax, sftDrivemask
        call getAddrDPB                                 ; es:bx

        mov ax, word ptr es:[ _dpbBytesPerSector ][ bx ]
        mov cl, byte ptr es:[ _dpbClusterSizeShift ][ bx ]
        shl ax, cl                                      ; bytes per cluster
        mov cx, ax

        pop di
        pop es
        mov ax, word ptr es:[ sftFilePosition. _low  ][ di ]
        mov dx, word ptr es:[ sftFilePosition. _high ][ di ]
        call _div32

        mov word ptr es:[ sftRelCluster ][ di ], ax
        pop cx
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Open SFT                                                     ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   es:dx  unexpanded filename                                  ;
        ;   ax     open mode                                            ;
        ;                                                               ;
        ;  Output:                                                      ;
        ;   es:di  sft pointer                                          ;
        ;   zr     means end of file or wrong address                   ;
        ;...............................................................;

_SFTOpenFile:

        Entry
        def  _handle, -1
        def  _openMode, ax
        ddef _filename, es, dx                          ; arg passed internally as es:dx
        ddef _sftPointer                                ; sft reserved pointer
        defbytes _dirAccess, sizeDIRACCESS
        
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  does file exist ?
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        mov ax, (FILE_ORDEVICE + FILECANNOT_BEDIRECTORY)
        mov si, dx                                      ; name from caller (es: si )
        lea di, offset _dirAccess [ bp ]                ; work dir access block
        call LocateFile                                 ; if can't locate, then 
        ifc _SFTOpenFile_50                             ; error code already set

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  name is valid. populate sft.
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        call FindAvailableSFTHandle                     ; find an available file handle
        ifc _SFTOpenFile_50                             ; if none available -->

        mov word ptr [ _handle ][ bp ], ax
        stordarg _sftPointer, es, bx                    ; sft reserved pointer
        call InitSFTEntry                               ; clear entry

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  if file opened is a device
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        getdarg dx, ax, _dirAccess.fileAcDevicePtr
        or dx, dx                                       ; _segment
        jz _SFTOpenFile_22                              ; if not a device -->

        or word ptr es:[ sftDevInfo ][ bx ], sftIsDevice
        mov word ptr es:[ sftDCB. _segment ][ bx ], dx
        mov word ptr es:[ sftDCB. _pointer ][ bx ], ax  ; device address

        push ds
        setDS ss
        mov si, word ptr [ _dirAccess.fileAcNameOffset ][ bp ]
        les di, dword ptr [ _sftPointer ][ bp ]         ; get sft pointer
        lea di, offset sftFileName [ di ]
        call convFilenametoFCBString                    ; convert to a match template
        pop ds

        jmp short _SFTOpenFile_42

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  if open is to file
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_SFTOpenFile_22:
        push word ptr [ _dirAccess.fileAcBufferPtr. _segment ][ bp ]
        mov ax, word ptr [ _dirAccess.fileAcBufferPtr. _pointer ][ bp ]
        add ax, word ptr [ _dirAccess.fileAcDirOffset ][ bp ]
        push ax

        push word ptr [ _sftPointer. _segment ][ bp ]
        push word ptr [ _sftPointer. _pointer ][ bp ]
        call initSFTfromDirEntry

        mov al, byte ptr [ _openMode ][ bp ]
        mov byte ptr es:[ sftMode ][ di ], al           ; set mode.

        test al, OPEN_ACCESS_NOINHERIT
        jz _SFTOpenFile_42                              ; if inherit not used -->
        or word ptr es:[ sftDevInfo ][ di ], sftNoInherit

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

_SFTOpenFile_42:
        mov ax, word ptr [ _handle ][ bp ]
        clc

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  if error, release locked sft
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_SFTOpenFile_50:
        getdarg es, di, _sftPointer                     ; sft reserved pointer
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Create SFT File                                              ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   es:dx  unexpanded filename                                  ;
        ;   cx     attributes                                           ;
        ;                                                               ;
        ;  Output:                                                      ;
        ;   es:di  sft pointer                                          ;
        ;   zr     means end of file or wrong address                   ;
        ;...............................................................;

_SFTCreateFile:

        Entry
        def  _attributes, cx                            ; attributes
        defbytes _dirAccess, sizeDIRACCESS

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  see if path is valid
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        mov ax, (FILE_NODEVICENAME + FILEMAY_EXIST + FILECANNOT_BEDIRECTORY)
        mov si, dx                                      ; name from caller
        lea di, offset _dirAccess [ bp ]                ; work dir access block
        call LocateFile
        jc _SFTCreateFile_42                            ; if path invalid -->

        lea di, offset _dirAccess [ bp ]                ; work dir access block
        mov cx, word ptr [ _attributes ][ bp ]          ; get attributes
        call createSFTEntry                             ; create/init SFT entry

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_SFTCreateFile_42:
        Return

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Read From SFT                                                ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Input:                                                       ;
        ;   cx     bytes to read                                        ;
        ;   es:di  sft pointer                                          ;
        ;   stack  buffer address                                       ;
        ;                                                               ;
        ;  Output:                                                      ;
        ;   cx     bytes actually read                                  ;
        ;   zr     means end of file or wrong address                   ;
        ;...............................................................;

⌨️ 快捷键说明

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