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

📄 file.asm

📁 这是一些例程
💻 ASM
📖 第 1 页 / 共 3 页
字号:
        .ENDIF  ; bx ! cx
        ret

WriteFile ENDP


;* GetDiskSize - Gets size information from specified disk.
;*
;* Shows:   DOS Function - 36h (Get Drive Allocation Information)
;*
;* Params:  Drive - Drive code (0 = default, 1 = A, 2 = B, etc.)
;*          Disk  - Pointer to a structure with 4 short integer members:
;*                      Member 1 - Total clusters on disk
;*                      Member 2 - Number of available clusters
;*                      Member 3 - Sectors/cluster (-1 if invalid drive)
;*                      Member 4 - Bytes/sector
;*
;* Return:  None

GetDiskSize PROC USES di,
        Drive:WORD, Disk:PDISKSTAT

        mov     dx, Drive               ; DL = drive code
        mov     ah, 36h                 ; DOS Function 36h
        int     21h                     ; Get Drive Allocation Information
        LoadPtr es, di, Disk            ; ES:DI = disk structure
        mov     (DISKSTAT PTR es:[di]).\
                total, dx               ; DX = total clusters
        mov     (DISKSTAT PTR es:[di]).\
                avail, bx               ; BX = number of free clusters
        mov     (DISKSTAT PTR es:[di]).\
                sects, ax               ; AX = sectors/cluster
        mov     (DISKSTAT PTR es:[di]).\
                bytes, cx               ; CX = bytes/sector
        ret

GetDiskSize ENDP


;* MakeDir - Creates a specified subdirectory.
;*
;* Shows:   DOS Function - 39h (Create Directory)
;*
;* Params:  Pspec - Pointer to ASCIIZ pathname of new subdirectory
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if create error

MakeDir PROC USES ds,
        Pspec:PBYTE

        LoadPtr ds, dx, Pspec           ; Point DS:DX to path spec
        mov     ah, 39h                 ; DOS Function 39h
        int     21h                     ; Create Directory
        mov     ax, 0                   ; Set error code, keep flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

MakeDir ENDP


;* RemoveDir - Removes a specified subdirectory.
;*
;* Shows:   DOS Function - 3Ah (Delete Directory)
;*
;* Params:  Pspec - Pointer to ASCIIZ pathname of subdirectory
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if delete error or subdirectory not empty

RemoveDir PROC USES ds,
        Pspec:PBYTE

        LoadPtr ds, dx, Pspec           ; Point DS:DX to path spec
        mov     ah, 3Ah                 ; DOS Function 3Ah
        int     21h                     ; Delete Directory
        mov     ax, 0                   ; Set error code, keep flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

RemoveDir ENDP


;* ChangeDir - Changes current (default) directory.
;*
;* Shows:   DOS Function - 3Bh (Set Current Directory)
;*
;* Params:  Pspec - Pointer to ASCIIZ pathname of target subdirectory
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if delete error or subdirectory not empty

ChangeDir PROC USES ds,
        Pspec:PBYTE

        LoadPtr ds, dx, Pspec           ; Point DS:DX to path spec
        mov     ah, 3Bh                 ; DOS Function 3Bh
        int     21h                     ; Set Current Directory
        mov     ax, 0                   ; Set error code, keep flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

ChangeDir ENDP


;* DelFile - Deletes a specified file.
;*
;* Shows:   DOS Function - 41h (Delete File)
;*
;* Params:  Fspec - Pointer to ASCIIZ file specification
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if delete error

DelFile PROC USES ds,
        Fspec:PBYTE

        LoadPtr ds, dx, Fspec           ; Point DS:DX to file spec
        mov     ah, 41h                 ; DOS Function 41h
        int     21h                     ; Delete File
        mov     ax, 0                   ; Set error code, keep flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

DelFile ENDP


;* Rewind - Rewinds an open file specified by handle. See the GetFileSize
;* procedure for an example of using Function 42h to determine file size.
;*
;* Shows:   DOS Function - 42h (Set File Pointer)
;*
;* Params:  Handle - File handle
;*
;* Return:  None

Rewind  PROC,
        Handle:WORD

        mov     bx, Handle              ; BX = file handle
        mov     ax, 4200h               ; AH = function #,
                                        ; AL = move to beginning of
        sub     cx, cx                  ;      file plus offset
        sub     dx, dx                  ; CX:DX = offset (zero)
        int     21h                     ; Set File Pointer
        ret

Rewind  ENDP


;* GetFileSize - Gets the size of an open file specified by handle.
;*
;* Shows:   DOS Function - 42h (Set File Pointer)
;*
;* Params:  Handle - File handle
;*
;* Return:  Long integer with file size in bytes

GetFileSize PROC,
        Handle:WORD

        mov     bx, Handle              ; BX = file handle
        mov     ax, 4202h               ; AH = function #,
                                        ; AL = move to end of
        sub     cx, cx                  ;      file plus offset
        sub     dx, dx                  ; CX:DX = offset (zero)
        int     21h                     ; Set File Pointer
        mov     ax, dx                  ; Set DX:AX = file size in
        mov     dx, cx                  ;   bytes, return long int
        ret

GetFileSize ENDP


;* GetAttribute - Gets the attribute(s) of a specified file.
;*
;* Shows:   DOS Function - 43h (Get or Set File Attributes)
;*
;* Params:  Fspec - Pointer to ASCIIZ file specification
;*
;* Return:  Short integer with file attribute bits set as follows:
;*                bit 0 = read only              bit 3 = volume label
;*                bit 1 = hidden                 bit 4 = subdirectory
;*                bit 2 = system                 bit 5 = archive
;*          0 indicates normal data file
;*          -1 indicates error

GetAttribute PROC USES ds,
        Fspec:PBYTE

        LoadPtr ds, dx, Fspec           ; DS:DX = file specification
        mov     ax, 4300h               ; AH = function #
                                        ; AL = 0 (return attribute)
        int     21h                     ; Get File Attributes
        mov     ax, -1                  ; Set code, keep flags
        .IF     !carry?
        mov     ax, cx                  ; Return with file attribute bits
        .ENDIF
        ret

GetAttribute ENDP


;* SetAttribute - Sets the attribute(s) of a specified file.
;*
;* Shows:   DOS Function - 43h (Get or Set File Attributes)
;*
;* Params:  Attr - Attribute bits set as follows:
;*                        bit 0 = read only      bit 3 = volume label
;*                        bit 1 = hidden         bit 4 = subdirectory
;*                        bit 2 = system         bit 5 = archive
;*                 (Attr = 0 for normal data file)
;*          Fspec - Pointer to ASCIIZ file specification
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if delete error

SetAttribute PROC USES ds,
        Attr:WORD,
        Fspec:PBYTE

        LoadPtr ds, dx, Fspec           ; DS:DX = file specification
        mov     cx, Attr                ; Put attribute code in CX
        mov     ax, 4301h               ; AH = function #
                                        ; AL = 1 (set attribute)
        int     21h                     ; Set File Attributes
        mov     ax, 0                   ; Clear code, keep flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

SetAttribute ENDP


;* GetCurDir - Gets the current directory of default drive.
;*
;* Shows:   DOS Function - 47h (Get Current Directory)
;*
;* Params:  Spec - Pointer to 64-byte buffer to receive directory
;*          path. Path terminates with 0 but does not include
;*          drive and does not begin with backslash.
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if delete error or subdirectory not empty

GetCurDir PROC USES ds si,
        Spec:PBYTE

        LoadPtr ds, si, Spec            ; DS:SI = spec address
        mov     ah, 47h                 ; AH = function number
        sub     dl, dl                  ; DL = current drive (0)
        int     21h                     ; Get Current Directory
        mov     ax, 0                   ; Set error code, keep flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

GetCurDir ENDP


;* FindFirst - Finds first entry in given directory matching specification.
;*
;* Shows:   DOS Function - 4Eh (Find First File)
;*          Instructions - pushf    popf
;*
;* Params:  Attr - Attribute code (see header comments for CreateFile)
;*          Fspec - Pointer to ASCIIZ file specification
;*          Finfo - Pointer to 43-byte buffer to receive
;*                      data from matched entry
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if no match found

        .DATA
OldDta  FPVOID  ?                       ; Storage for old DTA address

        .CODE

FindFirst PROC USES ds,
        Attr:WORD,
        Fspec:PBYTE,
        Finfo:PFILEINFO

        ; Get current DTA address, pass address of pointer to hold value
        INVOKE  GetDTA,
                ADDR OldDta

        mov     cx, Attr                ; Load CX with file attribute

        ; Set DTA address, pass pointer to structure
        INVOKE  SetDTA,
                Finfo

        LoadPtr ds, dx, Fspec           ; Point DS:DX to file spec
        mov     ah, 4Eh                 ; AH = function number
        int     21h                     ; Find First File

        pushf                           ; Preserve flags

        ; Restore DTA address, pass pointer
        INVOKE  SetDTA,
                OldDta

        sub     ax, ax                  ; Set error code
        popf                            ; Recover flags
        .IF     carry?
        inc     ax                      ; Set error code to 1
        .ENDIF
        ret

FindFirst ENDP


;* FindNext - Finds next entry in given directory matching specification.
;* (Should be called only after successfully calling the FindFirst procedure.)
;*
;* Shows:   DOS Function - 4Fh (Find Next File)
;*          Operator - OFFSET
;*
;* Params:  Finfo - Pointer to 43-byte buffer. This must be the same buffer
;*                      (or a duplicate) returned from the FindFirst procedure.
;*
;* Return:  Short integer with error code
;*          0 if successful
;*          1 if no more matches found

FindNext PROC USES ds,
        Finfo:PFILEINFO

        ; Get current DTA address, pass address of pointer to hold value
        INVOKE  GetDTA,
                ADDR OldDta

        ; Set DTA address, pass pointer to structure

⌨️ 快捷键说明

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