flat assembler
Message board for the users of flat assembler.

Index > DOS > MASM DOS port macro for FASM

Author
Thread Post new topic Reply to topic
Dima1205



Joined: 02 Jul 2023
Posts: 24
Location: Russian, Moscow
Dima1205 11 Jul 2023, 02:11
СPU directive for this macros:
Code:
@CPU equ 8086; Режим по умолчанию ms-dos (i8086 это по умолчанию).

;cpu_8087   equ 8087
macro .8087 
{ 
  @CPU equ 8087
}
;cpu_8086   equ 8086
macro .8086 
{ 
  @CPU equ 8086
}
;cpu_80186  equ 80186
;Процессор 286:
macro .80186 
{ 
  @CPU equ 80186
}
;cpu_80286  equ 8028601
macro .80286 
{ 
  @CPU equ 8028601
}
;cpu_80286C equ 8028602
macro .80286C 
{ 
  @CPU equ 8028602
}
;cpu_80286P equ 8028603
macro .80286P 
{ 
  @CPU equ 8028603
}
;Сопроцессор 287:
;cpu_80287  equ 8028701
macro .80287 
{ 
  @CPU equ 8028701
}
;Процессор 386:
;cpu_80386  equ 8038601
macro .80386 
{ 
  @CPU equ 8038601
}
;cpu_80386C equ 8038602
macro .80386C 
{ 
  @CPU equ 8038602
}
;cpu_80386P equ 8038603
macro .80386P 
{ 
  @CPU equ 8038603
}
;Сопроцессор 387:
;cpu_80387  equ 8038701
macro .80387 
{ 
  @CPU equ 8038701
}
;Процессор 486:
;cpu_80486  equ 8048601
macro .80486 
{ 
  @CPU equ 8048601
}
;cpu_80486C equ 8048602
macro .80486C 
{ 
  @CPU equ 8048602
}
;cpu_80486P equ 8048603
macro .80486P 
{ 
  @CPU equ 8048603
}
;Процессор 586:
;cpu_80586  equ 8058601
macro .80586 
{ 
  @CPU equ 8058601
}
;cpu_80586p equ 8058603
macro .80586P 
{ 
  @CPU equ 8058603
}
    

Source macros file:
Code:
;
;
; MACRO FROM MASM PACKAGE:
;
;


; BIOS Interface Macros - Version 1.2 - for Microsoft Macro Assembler 6.1
; (C) Copyright Microsoft Corporation, 1987,1988,1989,1990

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Used with: Interrupt 21h Function 440Dh Minor Code 61h
;             Interrupt 21h Function 440Dh Minor Code 41h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Internal

;macro __LdSeg  dest,src
;{ 
;mov   ah, 0Fh
   ; int   10h
;   src_i equ \`src
;   if 
;
;}


;__LdSeg MACRO dest:REQ, src:REQ
;    IFIDNI <src>, <es>                 ;; Segment register
;        mov     ax, src
;        mov     dest, ax
;    ELSEIFIDNI <src>, <ss>
;        mov     ax, src
;        mov     dest, ax
;    ELSEIFIDNI <src>, <ds>
;        mov     ax, src
;        mov     dest, ax
;    ELSEIFIDNI <src>, <cs>
;        mov     ax, src
;        mov     dest, ax
;    ELSEIF (OPATTR (src)) AND 00000100y ;; Constant
;        mov     ax, src
;        mov     dest, ax
;    ELSE                                ;; Memory or general register
;        mov     dest, src
;    ENDIF
;ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetMode
;
;  Summary:   Gets the current video mode and page
;
;  Arguments: None
;
;  Returns:   AL     Mode
;             AH     Width in characters
;             BH     Page
;
;  Modifies:  AX, BH
;
;  Uses:      Interrupt 10h Function 0Fh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetMode 
{ 
    mov   ah, 0Fh
    int   10h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetMode mode
;
;  Summary:   Sets the current video mode and page
;
;  Argument:  <mode>     8-bit video mode.
;
;  Returns:   No return value
;
;  Modifies:  AX
;
;  Uses:      Interrupt 10h Function 00h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetMode mode
{ 
    mov   al, mode
    xor   ah, ah
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetColor color
;
;  Summary:   Sets the background color
;
;  Argument:  <color>     8-bit background color (0-15); border
;                         color in text modes
;
;  Returns:   No return value
;
;  Modifies:  AX, BX
;
;  Uses:      Interrupt 10h Function 0Bh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetColor color
{ 
    sub   bh, bh
    mov   bl, color
    mov   ah, 0Bh
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetPalette color
;
;  Summary:   Sets the color palette
;
;  Argument:  <color>     8-bit color palette; 0-1 for modes 5 and 6
;
;  Returns:   No return value
;
;  Modifies:  AX, BX
;
;  Uses:      Interrupt 10h Function 0Bh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetPalette color
{ 
    mov   bh, 1
    mov   bl, color
    mov   ah, 0Bh
    int   10h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetPage page
;
;  Summary:   Sets the video page
;
;  Argument:  <page>     8-bit page number; 0-3 for modes 2 and 3
;
;  Returns:   No return value
;
;  Modifies:  AX
;
;  Uses:      Interrupt 10h Function 05h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetPage pagenum
{ 
    mov   al, pagenum
    mov   ah, 05h
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetCsrSize startline, endline
;
;  Summary:   Sets the cursor size and shape by specifying active scan
;             lines. For color adapters, the lines are 0-7. For the
;             monochrome adapter, the lines are 0-13.
;
;  Arguments: <startline>     8-bit starting scan line (default CGA = 6;
;                             MA = 12)
;
;             <endline>       8-bit ending scan line (default CGA = 7;
;                             MA = 13)
;
;  Returns:   No return value
;
;  Modifies:  AX, CX
;
;  Uses:      Interrupt 10h Function 01h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetCsrSize first, last
{ 
    mov   ch, first
    mov   cl, last
    mov   ah, 01h
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetCharAtr [page]
;
;  Summary:   Gets the character and attribute at the cursor location
;
;  Argument:  <page>     8-bit page to check; if none given, 0 assumed
;
;  Returns:   AH     Attribute
;             AL     ASCII character
;
;  Modifies:  AX, BH
;
;  Uses:      Interrupt 10h Function 08h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetCharAtr pagenum
{     
    match any,pagenum \{  mov   bh, pagenum  \}
    match ,pagenum \{  sub   bh, bh  \}    
    mov   ah, 08h
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @PutCharAtr [character] [,[attrib] [,[page] [,count]]]
;
;             @PutChar [character] [,[page] [,count]]
;
;  Summary:   Puts one or more characters and attributes at the current
;             cursor position. For @PutChar, the current attribute is
;             used in text modes and any specified attribute is ignored.
;
;  Arguments: <character>     8-bit ASCII character to put; if none
;                             given, AL used.
;
;             <attrib>        8-bit attribute to put; if none given,
;                             BL used.
;
;             <page>          8-bit page to put on; if none given, 0
;                             assumed.
;
;             <count>         Number to put; if none given, 1 assumed.
;
;  Returns:   No return value
;
;  Modifies:  AX, BX, CX
;
;  Uses:      Interrupt 10h Function 09h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @PutCharAtr chr, atrib, pagenum, loops
{     
    match any,chr \{  mov   al, chr  \}
    match any,atrib \{  mov   bl, atrib  \}      
    match any,pagenum \{  mov   bh, pagenum  \}
    match ,pagenum \{  sub   bh, bh  \}    
    match any,loops \{  mov   cx, loops  \}
    match ,loops \{  mov   cx, 1  \}    
    mov   ah, 09h
    int   10h
}

; 0Ah
macro @PutChar chr, atrib, pagenum, loops
{     
    match any,chr \{  mov   al, chr  \}
    match any,atrib \{  mov   bl, atrib  \}      
    match any,pagenum \{  mov   bh, pagenum  \}
    match ,pagenum \{  sub   bh, bh  \}    
    match any,loops \{  mov   cx, loops  \}
    match ,loops \{  mov   cx, 1  \}    
    mov   ah, 0Ah
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetCsrPos [column] [,[row] [,page]]
;
;  Summary:   Sets the cursor position
;
;  Arguments: <column>     8-bit column; if none given, DL used.
;
;             <row>        8-bit row; if none given, DH used.
;
;             <page>       8-bit page with cursor; if none given,
;                          0 assumed.
;
;  Returns:   No return value
;
;  Modifies:  AX, DX, BH
;
;  Uses:      Interrupt 10h Function 02h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetCsrPos column, row, pagenum
{     
    match any,column \{   mov   dl, column  \}
    match any,row \{   mov   dh, row  \}
    match any,pagenum \{  mov   bh, pagenum  \}
    match ,pagenum \{  sub   bh, bh  \} 
    mov   ah, 02h
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetCsr [page]
;
;  Summary:   Gets the cursor position and size
;
;  Argument:  <page>     8-bit page with cursor; if none given,
;                        0 assumed
;
;  Returns:   DL     Column
;             DH     Row
;             CL     Starting scan line
;             CH     Ending scan line
;
;  Modifies:  AX, DX, CX, BH
;
;  Uses:      Interrupt 10h Function 03h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetCsr pagenum
{     
    match any,pagenum \{  mov   bh, pagenum  \}
    match ,pagenum \{  xor   bh, bh  \}
    mov   ah, 03h
    int   10h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @Scroll dist [,[attr][,[upcol [,[uprow [,[dncol][,dnrow]]]]]]]
;
;  Summary:   Scrolls a specified window up or down
;
;  Arguments: <dist>      8-bit number of lines to scroll; positive
;                         scrolls down; negative scrolls up; 0 clears.
;
;             <attr>      8-bit attribute for blank lines; if none
;                         given, 07h (white on black).
;
;             <upcol>     Upper left column; if none given, CL used.
;
;             <uprow>     Upper left row; if none given, CH used.
;
;             <dncol>     Lower right column; if none given, DL used.
;
;             <dnrow>     Lower right row; if none given, DH used.
;
;  Returns:   No return value
;
;  Modifies:  AX, CX, DX, BH
;
;  Uses:      Interrupt 10h Function 06h and 07h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @Scroll distance, atrib,upcol, uprow, dncol, dnrow
{     
  match any,upcol \{  mov   cl, upcol  \}
  match any,uprow \{  mov   ch, uprow  \}
  match any,dncol \{  mov   dl, dncol  \}
  match any,dnrow \{  mov   dh, dnrow  \}  
  match any,atrib \{  mov   bh, atrib \}
  match ,atrib \{  mov   bh, 07h \}

  if distance <=0 
     mov   ax, 0600h + (-(distance) AND 0FFh)
  else
     mov   ax, 0700h + (distance AND 0FFh)
  end if
  int   10h  
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @Cls [page]
;
;  Summary:   Clears the screen
;
;  Argument:  <page>     Video page (8-bit); if none given, 0 assumed
;
;  Returns:   No return value
;
;  Modifies:  AX, BX, CX, DX
;
;  Uses:      Interrupt 10h Function 08h, 06h, and 02h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

macro @Cls pagenum
{ 
   const_equ equ
   pagenum_s equ \`pagenum
   match any,pagenum
   \{      
      match ='bh',pagenum_s 
      \\{ 
         sub   bh, bh
         const_equ equ 1
      \\}
     
      match ='BH',pagenum_s 
      \\{ 
         sub   bh, bh
         const_equ equ 1
      \\}
     
      match any,const_equ \\{ mov   bh, pagenum \\}     
   \}
  
    match ,const_equ \{ sub   bh, bh  \}   
    purge const_equ,const_equ
    
    mov   ah, 08h
    int   10h
    mov   bh, ah
    sub   cx, cx
    mov   dx, 324Fh
    mov   ax, 0600h
    int   10h
    mov   bh, bl
    sub   dx, dx
    mov   ah, 02h
    int   10h
}

;* @PushAll and @PopAll - Macros to push and pop all general purpose
;* registers. Registers are pushed in the following order:
;*    AX, CX, DX, BX, SP, BP, SI, DI
;* They are popped in the reverse order. Uses most efficient method
;* available at assembly time (not at run time).
;*
;* Shows:   Instruction - pusha     popa
;*          Operator    - AND
;*
;* Params:  None

macro @PushAll 
{ 
   if @Cpu < 80186
        ;assembling on 8086 и 8087
        push ax
        push cx
        push dx
        push bx
        push sp
        push bp
        push si
        push di
   else 
   
      pusha  ;assembling on 80186/286/386,
   end if
   
}

macro @PopAll 
{ 
   if @Cpu < 80186
        ;assembling on 8086 и 8087
        pop ax
        pop cx
        pop dx
        pop bx
        pop sp
        pop bp
        pop si
        pop di
   else 
   
      popa  ;assembling on 80186/286/386,
   end if   
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetDate
;
;  Summary:   Gets the system date
;
;  Arguments: None
;
;  Returns:   AL     Day of week (0 = Sunday, 1 = Monday, ...)
;             CX     Year (1980-2099)
;             DH     Month (1-12)
;             DL     Day (1-31)
;
;  Modifies:  AX, CX, DX
;
;  Uses:      Interrupt 21h Function 2Ah
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetDate 
{ 
    mov     ah, 2Ah
    int     21h 
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetDate month, day, year
;
;  Summary:   Sets the system date
;
;  Arguments: <month>     8-bit month (1-12)
;
;             <day>       8-bit day (1-31)
;
;             <year>      16-bit year (1980-2099)
;
;  Returns:   AL     If date was valid 0, else -1
;
;  Modifies:  AX, CX, DX
;
;  Uses:      Interrupt 21h Function 2Bh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

macro @SetDate month, day, year
{ 
    mov     cx, year
    mov     dh, month
    mov     dl, day
    mov     ah, 2Bh
    int     21h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetTime
;
;  Summary:   Gets the system time
;
;  Arguments: None
;
;  Returns:   CH     Hour (0-23)
;             CL     Minute (0-59)
;             DH     Second (0-59)
;             DL     Hundredth (0-99)
;
;  Modifies:  AX, CX, DX
;
;  Uses:      Interrupt 21h Function 2Ch
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetTime 
{ 
    mov     ah, 2Ch
    int     21h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @SetTime hour,minute,second,hundredth
;
;  Summary:   Sets the system time
;
;  Arguments: <hour>          8-bit hours (0-23)
;
;             <minute>        8-bit minutes (0-59)
;
;             <second>        8-bit seconds (0-59)
;
;             <hundredth>     8-bit hundredth of seconds (0-99)
;
;  Returns:   AL     If time was valid 0, else -1
;
;  Modifies:  AX, CX, DX
;
;  Uses:      Interrupt 21h Function 2Dh
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @SetTime hour, minutes, seconds, hundredths
{ 
    mov     ch, hour
    mov     cl, minutes
    mov     dh, seconds
    mov     dl, hundredths
    mov     ah, 2Dh
    int     21h
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetVer
;
;  Summary:   Gets the DOS version
;
;  Arguments: None
;
;  Returns:   AL        Major version (0 for versions prior to 2.0)
;             AH        Minor version
;             BH        OEM serial number
;             BL:CX     24-bit user number
;
;  Modifies:  AX, BX, CX
;
;  Uses:      Interrupt 21h Function 30h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetVer 
{ 
    mov     ah, 30h
    int     21h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetBlock paragraphs [, retry]
;
;  Summary:   Allocates a block of memory
;
;  Argument:  <paragraphs>     Paragraphs (16 bytes) of memory wanted
;             <retry>          If nonzero, allocate largest block
;                              available
;
;  Returns:   AX     If carry: clear, the segment of the allocated
;                    memory. If carry: set, an error code
;             BX     Paragraphs actually allocated. If <retry> is not
;                    zero, it may be less than requested.
;
;  Modifies:  AX, BX
;
;  Uses:      Interrupt 21h Function 48h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetBlock  paragraphs,retry
{ 
    local   tryit
    mov     bx, paragraphs
    tryit:  
    mov     ah, 48h
    int     21h
    
    if !=0
       jc  tryit
    end if 
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @ChkDrv [drive]
;
;  Summary:   Gets various data about a disk
;
;  Argument:  <drive>     8-bit drive number (0 = current, A = 1,
;                         B = 2, ...); if none given, current assumed
;
;  Returns:   AX     Sectors per cluster; -1 if drive invalid
;             BX     Available clusters
;             CX     Bytes per sector
;             DX     Clusters per drive
;
;  Modifies:  AX, BX, CX, DX
;
;  Uses:      Interrupt 21h Function 1Ch
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @ChkDrv drive
{  
  match ,drive    \{ sub     dl, dl \}
  match any,drive \{ mov     dl, drive \}
  mov     ah, 1Ch
  int     21h  
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  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
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetFileSize handle
{  
    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
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  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
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @CloseFile handle
{  
    mov     bx, handle
    mov     ah, 3Eh
    int     21h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetDrv
;
;             @SetDrv drive
;
;  Summary:   Gets or sets the current drive
;
;  Argument:  <drive>     8-bit drive number (0 = A, 1 = B, ...)
;
;  Returns:   For @GetDrv, drive number in AL (0 = A, 1 = B, ...);
;             for @SetDrv, number of drives in AL
;
;  Modifies:  AX for both; DL for @SetDrv
;
;  Uses:      Interrupt 21h Function 19h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetDrv 
{  
    mov     ah, 19h
    int     21h
}

; 0Eh
macro @SetDrv drive
{  
    mov     dl, drive
    mov     ah, 0Eh
    int     21h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @Exit [return]
;
;  Summary:   Exits to DOS with return code
;
;  Argument:  <return>     8-bit code to return to DOS; if none given,
;                          AL is used. If given, must be a constant.
;
;  Returns:   No return value
;
;  Modifies:  AX
;
;  Uses:      Interrupt 21h Function 4Ch
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @Exit return
{  
  match ,return    \{ mov     ah, 4Ch \}
  match any,return \{ mov     ax, 4C00h + (return AND 0FFh) \}
  int     21h
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Syntax:    @GetInt interrupt
;
;             @SetInt interrupt, vector [,segment]
;
;  Summary:   Gets or sets the vector for a specified interrupt
;             routine
;
;  Arguments: <interrupt>     8-bit interrupt number. Must be a
;                             constant.
;
;             <vector>        Offset of interrupt routine.
;
;             <segment>       Segment of routine; if none given, DS
;                             assumed for data; segment ignored for
;                             code labels.
;
;  Returns:   For @GetInt, ES:BX points to interrupt routine;
;             for @SetInt, no return value
;
;  Modifies:  AX for both; ES and BX for @GetInt; DS and DX for
;             @SetInt
;
;  Uses:      Interrupt 21h Function 35h
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
macro @GetInt interrupt
{  
    mov     ax, 3500h + (interrupt AND 0FFh)
    int     21h
}
    

_________________
Best regards, Dmitry
Post 11 Jul 2023, 02:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.