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

📄 dos.inc

📁 mas for 8086 microprocessor
💻 INC
📖 第 1 页 / 共 3 页
字号:
;
;  Summary:   Displays one or more characters to screen
;
;  Argument:  <char>     8-bit ASCII code
;
;  Returns:   No return value
;
;  Modifies:  AX, DL
;
;  Uses:      Interrupt 21h Function 02h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ShowChar MACRO chr:VARARG
    mov     ah, 02h
    FOR arg, <chr>
        IFDIFI  <arg>, <dl>
            mov     dl, arg
        ENDIF
        int     21h
    ENDM
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @PrtChar char [,char]...
;
;  Summary:   Prints one or more characters to LPT1
;
;  Argument:  <char>     8-bit ASCII code
;
;  Returns:   No return value
;
;  Modifies:  AX, DL
;
;  Uses:      Interrupt 21h Function 05h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@PrtChar MACRO chr:VARARG
    mov     ah, 05h
    FOR arg, <chr>
        IFDIFI  <arg>, <dl>
            mov     dl, arg
        ENDIF
        int     21h
    ENDM
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @ShowStr address [,segment]
;
;  Summary:   Displays a $-terminated string
;
;  Arguments: <address>     Address of string terminated by "$" (24h).
;                           Must be an offset address.
;
;             <segment>     Segment of address string; DS if not given.
;
;  Returns:   No return value
;
;  Modifies:  AX, DX; DS if segment changed
;
;  Uses:      Interrupt 21h Function 09h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ShowStr MACRO ofset:REQ, segmnt
    LOCAL  msg, sseg
    IF @InStr( 1, ofset, <!"> ) EQ 1
        sseg    TEXTEQU @CurSeg
        .DATA
        msg     BYTE    ofset, "$"
    @CurSeg ENDS
        sseg    SEGMENT
        mov     dx, OFFSET msg
    ELSE
        __LdAdr dx, ofset
        IFNB    <segmnt>
            __LdSeg ds, <segmnt>
        ENDIF
    ENDIF
    mov     ah, 9
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @Read buffer, length [,[handle] [,segment]]
;
;  Summary:   Reads data from a file or device
;
;  Arguments: <buffer>      Offset of buffer where data will be stored.
;                           Must be an offset address.
;
;             <length>      Length of data in bytes.
;
;             <handle>      File or device handle; if none given,
;                           keyboard (handle 0) is assumed.
;
;             <segment>     Segment of address string; DS if not given.
;
;  Returns:   If carry: clear, bytes read in AX
;
;  Modifies:  AX, DX, BX, CX; DS if segment changed
;
;  Uses:      Interrupt 21h Function 3Fh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@Read MACRO ofset:REQ, bytes:REQ, handle:=<0>, segmnt
    IFDIF   <handle>, <0>
        mov     bx, handle
    ELSE
        sub     bx, bx
    ENDIF
    mov     cx, bytes
    __LdAdr dx, <ofset>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    mov     ah, 3Fh
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @Write buffer, length [,[handle] [,segment]]
;
;  Summary:   Writes data to a file or device
;
;  Arguments: <buffer>      Offset of buffer where data is stored. Must
;                           be an offset address.
;
;             <length>      Length of data in bytes.
;
;             <handle>      File or device handle; if none given, screen
;                           (handle 1) is assumed.
;
;             <segment>     Segment of address string; DS if not given.
;
;  Returns:   If carry: clear, bytes written in AX
;
;  Modifies:  AX, DX, BX, CX; DS if segment changed
;
;  Uses:      Interrupt 21h Function 40h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@Write MACRO ofset:REQ, bytes:REQ, handle:=<1>, segmnt
    mov     bx, handle
    mov     cx, bytes
    __LdAdr dx, <ofset>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    mov     ah, 40h
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @MakeFile path [,[attrib] [,[segment] [,kind]]]
;
;  Summary:   Creates a file
;
;  Arguments: <path>        ASCIIZ string of file. Must be an offset
;                           address.
;
;             <attrib>      File attribute; 0 is default if none given.
;
;             <segment>     Segment of address string; DS if not given.
;
;             <kind>        If none given, a file is created even if one
;                           already exists. Under DOS 3.x, "tmp" can be
;                           given to create a unique file or "new" to
;                           create a file only if one doesn't already
;                           exist.
;
;  Returns:   If carry: clear, file handle in AX
;
;  Modifies:  AX, DX, CX; DS if segment changed
;
;  Uses:      Interrupt 21h Function 3Ch, 5Ah, 5Bh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@MakeFile MACRO path:REQ, atrib:=<0>, segmnt, kind
    IFDIF   <atrib>, <0>
        mov     cx, atrib
    ELSE
        sub     cx, cx
    ENDIF
    __LdAdr dx, <path>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    IFIDNI  <kind>, <tmp>
        mov     ah, 5Ah
    ELSEIFIDNI <kind>, <new>
        mov    ah, 5Bh
    ELSE
        mov    ah, 3Ch
    ENDIF
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @OpenFile path, access [,segment]
;
;  Summary:   Opens a file for input or output
;
;  Arguments: <path>        ASCIIZ string of file. Must be an offset
;                           address.
;
;             <access>      File access code. Must be a constant. The
;                           default value is 0 (normal read/write file).
;
;             <segment>     Segment of address string; DS if not given.
;
;  Returns:   If carry: set, error code in AX
;             If carry: clear, file handle in AX
;
;  Modifies:  AX, DX; DS if segment changed
;
;  Uses:      Interrupt 21h Function 3Dh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@OpenFile MACRO path:REQ, access:=<0>, segmnt
    __LdAdr dx, <path>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    mov     ax, 3D00h + (access AND 0FFh)
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @CloseFile handle
;
;  Summary:   Closes an open file handle
;
;  Argument:  <handle>     Previously opened file handle
;
;  Returns:   If carry: set, error code in AX
;
;  Modifies:  AX, BX
;
;  Uses:      Interrupt 21h Function 3Eh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@CloseFile MACRO handle:REQ
    mov     bx, handle
    mov     ah, 3Eh
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @DelFile path [,segment]
;
;  Summary:   Deletes a specified file
;
;  Arguments: <path>        Offset of ASCIIZ file specification. Must
;                           be an offset address.
;
;             <segment>     Segment of path; DS if none given.
;
;  Returns:   If carry: set, error code in AX
;
;  Modifies:  AX, DX; DS if segment changed
;
;  Uses:      Interrupt 21h Function 41h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@DelFile MACRO path:REQ, segmnt
    __LdAdr dx, <path>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    mov     ah, 41h
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @MoveFile old, new [,[segold] [,segnew]]
;
;  Summary:   Moves or renames a file by changing its path specification
;
;  Arguments: <old>        Offset of file specification to be renamed.
;                          Must be an offset address.
;
;             <new>        Offset of new file specification. Must be an
;                          offset address.
;
;             <segold>     Segment of old name; DS if none given.
;
;             <segnew>     Segment of new name; ES if none given.
;
;  Returns:   If carry: set, error code in AX
;
;  Modifies:  AX, DX, DI; DS, ES if corresponding segments changed
;
;  Uses:      Interrupt 21h Function 56h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@MoveFile MACRO old:REQ, new:REQ, segold, segnew
    __LdAdr dx, <old>
    __LdAdr di, <new>
    IFNB    <segold>
        __LdSeg ds, <segold>
    ENDIF
    IFNB    <segnew>
        __LdSeg es, <segnew>
    ENDIF
    mov     ah, 56h
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetFirst path [,[attribute] [,segment]]
;             @GetNext
;
;  Summary:   Converts file specifications (optionally including wild
;             cards) into filenames. These macros are usually used with
;             @GetDTA and @SetDTA. Use @SetDTA to set the address where
;             the data for each file will be stored.
;
;  Arguments: <path>          Offset address of fully specified ASCIIZ
;                             file name; can have wild cards. Must be an
;                             offset address.
;
;             <attribute>     File attribute to search for; 0 for normal
;                             if none given.
;
;             <segment>       Segment of path; uses DS if none given.
;
;  Returns:   If carry: set, error code in AX
;
;  Modifies:  For @GetFirst, AX, CX, DX; DS if segment changed;
;             for @GetNext, AX only
;
;  Uses:      Interrupt 21h Function 4Eh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@GetFirst MACRO path:REQ, atrib, segmnt
    IFNB    <atrib>
        mov     cx, atrib
    ELSE
        sub     cx, cx
    ENDIF
    __LdAdr dx, <path>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    mov     ah, 4Eh
    int     21h
ENDM


; 4Fh
@GetNext MACRO
    mov     ah, 4Fh
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetDTA
;
;             @SetDTA buffer [,segment]
;
;  Summary:   Gets or sets the Disk Transfer Address (DTA). These
;             macros are usually used to set the address for file
;             information data used by @GetFirst and @GetNext.
;
;  Arguments: <buffer>      Offset of new DTA buffer. Must be an offset
;                           address.
;
;             <segment>     Segment of new DTA buffer; DS if none given.
;
;  Returns:   @GetDTA: ES:BX points to DTA
;             @SetDTA: No return value
;
;  Modifies:  AX for both; ES, BX for @GetDTA; DS, DX for @SetDTA
;
;  Uses:      Interrupt 21h Function 2Fh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@GetDTA MACRO
    mov     ah, 2Fh
    int     21h
ENDM

; 1Ah
@SetDTA MACRO buffer:REQ, segmnt
    __LdAdr dx, <buffer>
    IFNB    <segmnt>
        __LdSeg ds, <segmnt>
    ENDIF
    mov     ah, 1Ah
    int     21h
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetFileSize handle
;
;  Summary:   Gets the file size by moving the file pointer to
;             end-of-file
;
;             NOTE: The file pointer is reset to zero. Thus this
;                   macro should not be called during operations that move
;                   the pointer.
;
;  Argument:  <handle>     Previously opened file handle.
;
;  Returns:   If carry: clear, file length in DX:AX
;
;  Modifies:  AX, BX, CX, DX
;
;  Uses:      Interrupt 21h Function 42h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@GetFileSize MACRO handle:REQ
    mov     bx, handle
    sub     cx, cx
    sub     dx, dx
    mov     ax, 4202h
    int     21h
    push    dx
    push    ax
    sub     dx, dx
    mov     ax, 4200h
    int     21h
    pop     ax
    pop     dx
ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @MovePtrAbs handle [,distance]
;
;             @MovePtrRel handle [,distance]
;
;  Summary:   Moves the file pointer in an open file. The pointer can be
;             moved to an absolute position, or relative to its current
;             position.
;
;  Arguments: <handle>       Previously opened file handle.
;
;             <distance>     Distance to move pointer (16-bit) constant
;                            or a 16- or 32-bit variable; or leave
;                            blank and set distance in CX:DX before
;                            macro call.
;
;  Returns:   If carry: clear, file pointer position in DX:AX
;
;  Modifies:  AX, BX, CX, DX
;
;  Uses:      Interrupt 21h Function 42h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@MovePtrAbs MACRO handle:REQ, distance
    IFNB    <distance>
        __LdDub <distance>
    ENDIF
    mov     bx, handle
    mov     ax, 4200h
    int     21h

⌨️ 快捷键说明

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