
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Standard Definitions.                                ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                       ;
        ;  (C) Copyright, 1991.  Mike Podanoffsky               ;
        ;      All Rights Reserved.                             ;
        ;.......................................................;

zero            equ 0
one             equ 1
two             equ 2
minusOne        equ -1

no              equ 0
yes             equ 1

false           equ 0
true            equ 1

__pointer	equ 0
__segment	equ 2


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  Dos Function Codes
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExitProgram             equ 00h

SetDiskTransferAddr     equ 1Ah
GetDiskTransferAddr     equ 2Fh
SetIntVector            equ 25h
GetIntVector            equ 35h
TerminateProcess        equ 4ch


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  Flag Register Values
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_flags_of               equ 0800h
_flags_df               equ 0400h
_flags_if               equ 0200h
_flags_tf               equ 0100h
_flags_sf               equ 0080h
_flags_zf               equ 0040h
_flags_af               equ 0010h
_flags_pf               equ 0004h
_flags_cf               equ 0001h


        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Entry Macro.                                         ;
        ;.......................................................;

entry   macro label

label   proc far
_ARGP   = 6
_ARGT   = 0
        push bp
        mov bp,sp
        endm
        
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Entry Macro.                                         ;
        ;.......................................................;

alias   macro label

label   proc far
label   endp
        endm
        
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Return Macro.                                        ;
        ;.......................................................;
        
return  macro nbytes
        mov sp,bp
        pop bp
   ifidn <nbytes>,<pascal>
   	ret _ARGP-6
	else
	ret nbytes
	endif
        endm
        
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Define Double Argument.                              ;
        ;.......................................................;
        
darg    macro label

label   = _ARGP                                 ;
_ARGP   = _ARGP+4                               ;long
	chklabel label        
        endm
        
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Define Argument.                                     ;
        ;.......................................................;
        
iarg     macro label
        
label   = _ARGP                                 ;set argument.
_ARGP   = _ARGP+2
	chklabel label        
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Temporary Storage.                                   ;
        ;.......................................................;
        
targ    macro label,reg
        
_ARGT   = _ARGT-2
label   = _ARGT                                 ;set argument.
pushedreg = no

    ifb <reg>
        push ax
        pushedreg = yes
        endif

    ifnb <reg>
     irp treg,<ax,bx,cx,dx,si,di,es,ds,f>
      ifidn <reg>,<treg>
        tpush reg
        pushedreg = yes
        endif
        endm
        endif

     ife pushedreg-no                           ;if not pushed
        push ax
        mov word ptr label [bp],reg             ;really a value.
        endif
	chklabel label        
	endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Temporary Double Arg Storage.                        ;
        ;.......................................................;
        
tdarg   macro label,reg,seg
        
_ARGT   = _ARGT-4
label   = _ARGT                                 ;set argument.
pushedreg = no
pushedseg = no

    ifb <reg>
        push ax
        push ax
        pushedreg = yes
        pushedseg = yes
        endif

    ifnb <reg>
     irp treg,<ax,bx,cx,dx,si,di,es,ds,f>
      ifidn <reg>,<treg>
        tpush reg
        pushedreg = yes
        endif
        endm
        endif

     ife pushedreg-no                           ;if not pushed
        push ax
        push ax
        mov word ptr label [bp],reg             ;really a value.
        mov word ptr label [bp+2],zero          ;32 bits.
        pushedreg = yes
        pushedseg = yes
        endif

    ifnb <seg>
     irp tseg,<es,ds>
      ifidn <seg>,<tseg>
        tpush seg
        pushedseg = yes
        endif
        endm
        endif

     ife pushedseg-no
        push ax
        endif
	chklabel label        
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Check for Bad Label					;
        ;.......................................................;
        
chklabel    macro label

    ifidn <label>,<offset>
    	error "bad label"
	endif

    ifidn <label>,<org>
    	error "bad label"
	endif

    ifidn <label>,<ptr>
    	error "bad label"
	endif

    ifidn <label>,<end>
    	error "bad label"
	endif

    ifidn <label>,<endp>
    	error "bad label"
	endif

    ifidn <label>,<even>
    	error "bad label"
	endif

    ifidn <label>,<segment>
    	error "bad label"
	endif

	endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Define Double Argument.                              ;
        ;.......................................................;
        
getdarg  macro seg,reg,label
loadedflag  = no

   ifidn <seg>,<es>
        les reg,dword ptr label [bp]
        loadedflag = yes
        endif

   ifidn <seg>,<ds>
        lds reg,dword ptr label [bp]
        loadedflag = yes
        endif

   ife loadedflag-no
        mov reg,word ptr label [bp]
        mov seg,word ptr label [bp+2]
        endif
        endm
        
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Define Argument.                                     ;
        ;.......................................................;
        
getarg  macro reg,label
        mov reg,word ptr label [bp]
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Store Double Argument.                               ;
        ;.......................................................;
        
stordarg  macro label,reg,seg
        mov word ptr label [bp],reg
        mov word ptr label [bp+2],seg
        endm
        
        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Store Argument.                                      ;
        ;.......................................................;
        
storarg macro label,reg
        mov word ptr label [bp],reg
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Save Registers.                                      ;
        ;.......................................................;
        
SaveRegisters macro 

        push ax
        push bx
        push cx
        push dx
        push si
        push di
        push bp

        push ds
        push es
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Restore Registers.                                   ;
        ;.......................................................;
        
RestoreRegisters macro
        pop es
        pop ds

        pop bp
        pop di
        pop si
        pop dx
        pop cx
        pop bx
        pop ax
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Save Segments.                                       ;
        ;.......................................................;
        
saveSegments macro reg1,reg2,reg3,reg4,reg5,reg6,reg7,reg8,reg9,reg0

        push ds
        push es

   ifnb <reg1>
        tpush reg1
        endif
   ifnb <reg2>
        tpush reg2
        endif
   ifnb <reg3>
        tpush reg3
        endif
   ifnb <reg4>
        tpush reg4
        endif
   ifnb <reg5>
        tpush reg5
        endif
   ifnb <reg6>
        tpush reg6
        endif
   ifnb <reg7>
        tpush reg7
        endif
   ifnb <reg8>
        tpush reg8
        endif
   ifnb <reg9>
        tpush reg9
        endif
   ifnb <reg0>
        tpush reg0
        endif
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Restore Segments.                                    ;
        ;.......................................................;
        
restoreSegments macro reg1,reg2,reg3,reg4,reg5,reg6,reg7,reg8,reg9,reg0

   ifnb <reg1>
        tpop reg1
        endif
   ifnb <reg2>
        tpop reg2
        endif
   ifnb <reg3>
        tpop reg3
        endif
   ifnb <reg4>
        tpop reg4
        endif
   ifnb <reg5>
        tpop reg5
        endif
   ifnb <reg6>
        tpop reg6
        endif
   ifnb <reg7>
        tpop reg7
        endif
   ifnb <reg8>
        tpop reg8
        endif
   ifnb <reg9>
        tpop reg9
        endif
   ifnb <reg0>
        tpop reg0
        endif

        pop es
        pop ds
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  This Segment						;
        ;.......................................................;

thisSegment macro reg1,reg2,reg3,reg4,reg5,reg6,reg7,reg8,reg9,reg0

   ifnb <reg1>
        push cs
	pop reg1
        endif
   ifnb <reg2>
        push cs
	pop reg2
        endif
   ifnb <reg3>
        push cs
	pop reg3
        endif
   ifnb <reg4>
        push cs
	pop reg4
        endif
   ifnb <reg5>
        push cs
	pop reg5
        endif
   ifnb <reg6>
        push cs
	pop reg6
        endif
   ifnb <reg7>
        push cs
	pop reg7
        endif
   ifnb <reg8>
        push cs
	pop reg8
        endif
   ifnb <reg9>
        push cs
	pop reg9
        endif
   ifnb <reg0>
        push cs
	pop reg0
        endif
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Call Dos                                             ;
        ;.......................................................;

callDos macro fctvalue,lowvalue

    ifnb <fctvalue>    
        mov ah,fctvalue
        endif

    ifnb <lowvalue>    
        mov al,lowvalue
        endif

        int 21h
        endm

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Set Interrupt Vector.                                ;
        ;.......................................................;

setIntTrap macro intvector, newvector, savevector

        callDos GetIntVector, intvector
        mov word ptr [savevector + 2 ], es
        mov word ptr [savevector ], bx

        mov dx,seg newvector
        mov ds,dx
        mov dx,offset newvector
        callDos SetIntVector, intvector

        endm
