home *** CD-ROM | disk | FTP | other *** search
- .SFCOND
- ;.XLIST
- ;
- ; Currently, this file does not support large DATA model.
- ;
- ; Changes must be made to some parts in order to accomodate
- ; this model.
- ;
-
- INCLUDE FAR.FLG
- ;
- ; The FAR.FLG file contains conditional flags which determine how
- ; the assembly module should be compiled. These flags are expected
- ; to be in upper case. If you plan to use the '/mx' or '/ml' switch
- ; when assembling your file, they MUST be in upper case.
- ;
-
- TRUE EQU 1
- FALSE EQU 0
- NULL EQU 0FFFFH
-
- IFNDEF DOSENV
- DOSENV EQU TRUE
- ENDIF
-
- IFNDEF FARPROC
- FARPROC EQU FALSE
- ENDIF
-
- IFNDEF MSC
- MSC EQU FALSE
- ENDIF
-
- IFNDEF FARDATA
- FARDATA EQU FALSE
- ENDIF
-
- IFNDEF VAP
- VAP EQU FALSE
- ENDIF
-
- IFNDEF OPSYSHERE
- OPSYSHERE EQU FALSE
- ENDIF
-
- IFNDEF SYSCALLS
- SYSCALLS EQU FALSE
- ENDIF
- if1
- outif MACRO name,defval,onmsg,offmsg
- ifndef name
- ifb <defval>
- name=0
- else
- name=defval
- endif
- endif
- if name
- name=1
- ifnb <onmsg>
- %out ! onmsg
- endif
- else
- ifnb <offmsg>
- %out ! offmsg
- endif
- endif
- endm
-
- outif DOSENV,1,<DOS Environment>,<OS/2 Environment>
- outif FARPROC,1,<Large code>,<Small code>
- outif FARDATA,1,<Large data>,<Small data>
- outif MSC,1,<Microsoft calling conventions>,<Non-Microsoft calling conventions>
- outif VAP,1,<VAP environment>,<Non-VAP environment>
- endif
-
- ; if not compiling for the DOS environment
- ; (In other words --- compiling for OS/2)
- ; we can assume we will be in protected mode (286 or 386)
-
- IFE DOSENV
- .286P
- ENDIF
-
- ;
- ; Set up the address (from BP saved) where
- ; the first parameter is.
- ;
- IF FARPROC
- parms equ 12
- ELSE
- parms equ 10
- ENDIF
-
- ;
- ; The following equates assume that each parameter is
- ; a word (2 bytes). If you are sending parameters that
- ; are not 2 bytes (far pointers) you must adjust the
- ; location accessed.
- ;
- ; You can define some additional equates which access
- ; double word addresses on the stack.
- ;
- parm1 equ parms
- parm2 equ parm1 + 2
- parm3 equ parm2 + 2
- parm4 equ parm3 + 2
- parm5 equ parm4 + 2
- parm6 equ parm5 + 2
- parm7 equ parm6 + 2
-
- ;
- ; Macro Name : DataGroup
- ;
- ; Parameters : None
- ;
- ; Define the default data segment for the
- ; module being assembled.
- ;
- ; Lattice uses DATA
- ; MicroSoft uses _DATA
- ;
- DataGroup MACRO
- IF MSC
- _DATA segment word public 'DATA'
- ELSE
- DATA segment word public 'DATA'
- ENDIF
- ENDM
-
- ;
- ; Macro Name : EndData
- ;
- ; Parameters : None
- ;
- ; Define the end of the default data segment
- ;
- ; Lattice uses DATA
- ; MicroSoft uses _DATA
- ;
- EndData MACRO
- IF MSC
- _DATA ends
- ELSE
- DATA ends
- ENDIF
- ENDM
-
- gVar MACRO VARNAME,VARSIZE,INITVAL
- IF MSC
- public _&VARNAME
- _&VARNAME VARSIZE INITVAL
- VARNAME equ _&VARNAME
- ELSE
- public VARNAME
- VARNAME VARSIZE INITVAL
- ENDIF
- ENDM
-
- ;
- ; Macro Name : globalB mWord,lWord,initval
- ;
- ; Parameters : mByte = complete variable name
- ; lByte = 8 character name for variable
- ; initval = initial value
- ;
- ; Definition : Define a public 1 BYTE variable with the
- ; initial value of initval
- ;
- ; Lattice only allows 8 character variable names
- ; so lByte will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; mByte will be used.
- ;
- ; You should access the variable in your assembly file
- ; as mByte, not as lByte
- ;
- globalB MACRO mByte,lByte,initval
- gVar mByte,db,initval
- ENDM
-
- ;
- ; Macro Name : globalW mWord,lWord,initval
- ;
- ; Parameters : mWord = complete variable name
- ; lWord = 8 character name for variable
- ; initval = initial value
- ;
- ; Definition : Define a public 2 BYTE WORD variable with the
- ; initial value of initval
- ;
- ; Lattice only allows 8 character variable names
- ; so lWord will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; mWord will be used.
- ;
- ; You should access the variable in your assembly file
- ; as mWord, not as lWord
- ;
- globalW MACRO mWord,lWord,initval
- gVar mWord,dw,initval
- ENDM
-
- ;
- ; Macro Name : globalD mWord,lWord,initval
- ;
- ; Parameters : mWord = complete variable name
- ; lWord = 8 character name for variable
- ; initval = initial value
- ;
- ; Definition : Define a public 4 BYTE WORD variable with the
- ; initial value of initval
- ;
- ; Lattice only allows 8 character variable names
- ; so lWord will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; mWord will be used.
- ;
- ; You should access the variable in your assembly file
- ; as mWord, not as lWord
- ;
- globalD MACRO mWord,lWord,initval
- gVar mWord,dd,initval
- ENDM
-
- ;
- ; Macro Name : globalQ mWord,lWord,initval
- ;
- ; Parameters : mWord = complete variable name
- ; lWord = 8 character name for variable
- ; initval = initial value
- ;
- ; Definition : Define a public 8 BYTE WORD variable with the
- ; initial value of initval
- ;
- ; Lattice only allows 8 character variable names
- ; so lWord will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; mWord will be used.
- ;
- ; You should access the variable in your assembly file
- ; as mWord, not as lWord
- ;
- globalQ MACRO mWord,lWord,initval
- gVar mWord,dq,initval
- ENDM
-
- xVar MACRO VARNAME,VARSIZE
- IF MSC
- extrn _&VARNAME&:&VARSIZE
- VARNAME EQU _&VARNAME
- ELSE
- extrn VARNAME&:&VARSIZE
- ENDIF
- ENDM
-
- ;
- ; Macro Name : extB extvar,extvar8
- ;
- ; Parameters : extvar = complete variable name
- ; extvar8 = 8 character name for variable
- ;
- ; Definition : Define an external 1 BYTE variable
- ;
- ; Lattice only allows 8 character variable names
- ; so extvar8 will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; extvar will be used.
- ;
- ; You should access the variable in your assembly file
- ; as extvar, not as extvar8
- ;
- extB MACRO extvar,extvar8
- xVar extvar,byte
- ENDM
-
- ;
- ; Macro Name : extW extvar,extvar8
- ;
- ; Parameters : extvar = complete variable name
- ; extvar8 = 8 character name for variable
- ;
- ; Definition : Define an external 2 BYTE WORD variable
- ;
- ; Lattice only allows 8 character variable names
- ; so extvar8 will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; extvar will be used.
- ;
- ; You should access the variable in your assembly file
- ; as extvar, not as extvar8
- ;
- extW MACRO extvar,extvar8
- xVar extvar,word
- ENDM
-
- ;
- ; Macro Name : extD extvar,extvar8
- ;
- ; Parameters : extvar = complete variable name
- ; extvar8 = 8 character name for variable
- ;
- ; Definition : Define an external 4 BYTE WORD variable
- ;
- ; Lattice only allows 8 character variable names
- ; so extvar8 will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; extvar will be used.
- ;
- ; You should access the variable in your assembly file
- ; as extvar, not as extvar8
- ;
- extD MACRO extvar,extvar8
- xVar extvar,dword
- ENDM
-
- ;
- ; Macro Name : extQ extvar,extvar8
- ;
- ; Parameters : extvar = complete variable name
- ; extvar8 = 8 character name for variable
- ;
- ; Definition : Define an external 8 BYTE WORD variable
- ;
- ; Lattice only allows 8 character variable names
- ; so extvar8 will be used as the external name.
- ;
- ; MicroSoft accepts more a complete name so
- ; extvar will be used.
- ;
- ; You should access the variable in your assembly file
- ; as extvar, not as extvar8
- ;
- extQ MACRO extvar,extvar8
- xVar extvar,qword
- ENDM
-
- ;
- ; Macro Name : globalBuff mBuff,lBuff,type,length,initval
- ;
- ; Parameters : mBuff = complete variable name
- ; lBuff = 8 character name for variable
- ; type = DB,DW,DQ, etc.
- ; length = number of repetitions of the initial value
- ; initval = inital value for each element of the buffer
- ;
- ; Definition : Define a global buffer of data
- ;
- ; The actual size of the buffer will be
- ;
- ; length * sizeof(type)
- ;
- ; Lattice only allows 8 character variable names
- ; so lBuff will be used as the global name.
- ;
- ; MicroSoft accepts more a complete name so mBuff
- ; will be used.
- ;
- ; You should access the variable in your assembly file
- ; as mBuff, not as lBuff
- ;
- globalBuff MACRO mBuff,lBuff,type,length,initval
- IF MSC
- public _&mBuff
- _&mBuff type length dup (initval)
- mBuff equ _&mBuff
- ELSE
- public mBuff
- mBuff type length dup (initval)
- ENDIF
- ENDM
-
- ;
- ; Macro Name : SUBFN FNAME,FNAME8
- ;
- ; Parameters : FNAME = Function Name (Microsoft)
- ; FNAME8 = 8 Character Function Name (Lattice)
- ;
- ; Definition : Define a function which is global (public).
- ; The macro does not save any registers, it
- ; just defines the function as public
- ;
- ; Use FNAME in you module when accessing the function.
- ; this Name is used by Microsoft, and will be
- ; preceded by an underscore in the object file.
- ;
- SUBFN MACRO FNAME,FNAME8
- IF MSC
- public _&FNAME
- ELSE
- public FNAME
- ENDIF
-
- IF FARPROC
- IF MSC
- _&FNAME proc far
- FNAME equ _&FNAME
- ELSE
- FNAME proc far
- ENDIF
- ELSE
- IF MSC
- _&FNAME proc near
- FNAME equ _&FNAME
- ELSE
- FNAME proc near
- ENDIF
- ENDIF
- ENDM
-
- ;
- ; Macro Name : STARTFN FNAME,FNAME8
- ;
- ; Parameters : FNAME = Function Name (Microsoft)
- ; FNAME8 = 8 Character Function Name (Lattice)
- ;
- ; Definition : Define a function which is global (public).
- ; The macro saves the BP, ES, SI, DI registers, in
- ; that order, and then sets the BP register to
- ; point to the current stack address. It also
- ; defines the function as public
- ;
- ; Use FNAME in you module when accessing the function.
- ; this Name is used by Microsoft, and will be
- ; preceded by an underscore in the object file.
- ;
- STARTFN MACRO FNAME,FNAME8
- SUBFN FNAME,FNAME8
- push bp ;save caller's base pointer
- push es ;and Extra segment register
- push si
- push di
- mov bp,sp ;and set up our base pointer
- ENDM
-
- ;
- ; Macro Name : TERMFN
- ;
- ; Parameters : None
- ;
- ; Definition : Restore all the registers that were saved on the
- ; invocation of STARTFN. The macro does not end
- ; the definition of the function, it justs returns
- ; from the function.
- ;
- TERMFN MACRO
- mov sp,bp
- pop di
- pop si
- pop es
- pop bp
- ret
- ENDM
-
- ;
- ; Macro Name : ENDSUBFN FNAME,FNAME8
- ;
- ; Parameters : FNAME = Function Name (Microsoft)
- ; FNAME8 = 8 Character Function Name (Lattice)
- ;
- ; Definition : End the definition of a function. The macro
- ; just defines the end of a function, it does not
- ; restore any registers that may have been saved.
- ;
- ; If you used SUBFN to define the function, then
- ; use ENDSUBFN to end it.
- ;
- ; If you used STARTFN to define the function, then
- ; use ENDFN to end it.
- ;
- ; Use FNAME in your module when calling the function.
- ; this Name is used by Microsoft, and will be
- ; preceded by an underscore in the object file.
- ;
- ENDSUBFN MACRO FNAME,FNAME8
- IF MSC
- _&FNAME endp
- ELSE
- FNAME endp
- ENDIF
- ENDM
-
- ;
- ; Macro Name : ENDFN FNAME,FNAME8
- ;
- ; Parameters : FNAME = Function Name (Microsoft)
- ; FNAME8 = 8 Character Function Name (Lattice)
- ;
- ; Definition : End the definition of a function. The macro
- ; defines the end of a function, and restores
- ; the registers that were saved by the macro STARTFN.
- ;
- ; If you used SUBFN to define the function, then
- ; use ENDSUBFN to end it.
- ;
- ; If you used STARTFN to define the function, then
- ; use ENDFN to end it.
- ;
- ; Use FNAME in your module when calling the function.
- ; this Name is used by Microsoft, and will be
- ; preceded by an underscore in the object file.
- ;
- ENDFN MACRO FNAME,FNAME8
- TERMFN
- ENDSUBFN FNAME,FNAME8
- ENDM
-
- ;
- ; Macro Name : EXTPROC PROCNAME,PNAME8
- ;
- ; Parameters : PROCNAME = Function Name (Microsoft)
- ; PNAME8 = 8 Character Function Name (Lattice)
- ;
- ; Definition : Define a function as external
- ;
- EXTPROC MACRO PROCNAME,PNAME8
- IF FARPROC
- IF MSC
- EXTRN _&PROCNAME:far
- PROCNAME equ _&PROCNAME
- ELSE
- EXTRN PROCNAME:far
- ENDIF
- ELSE
- IF MSC
- EXTRN _&PROCNAME:near
- PROCNAME equ _&PROCNAME
- ELSE
- EXTRN PROCNAME:near
- ENDIF
- ENDIF
- ENDM
-
- ;
- ; Macro Name : STARTCODE FILENAME
- ;
- ; Parameters : FILENAME = Name of function module
- ;
- ; Definition : Define the name of a function module, and also
- ; defines the code segment.
- ;
- ; Microsoft:
- ; The code segment is FILENAME_TEXT (if medium
- ; model, _TEXT if small) and is placed on a
- ; word boundary, is defined as public and class
- ; CODE.
- ;
- ; Lattice:
- ; The code segment is FILENAME_CODE (if medium
- ; model, prog if small) and is placed on a
- ; word boundary, is defined as public and class
- ; CODE.
- ;
- STARTCODE MACRO FILENAME
- IF VAP
- _TEXT segment word public 'CODE'
- ELSE
- IF FARPROC
- IF MSC
- _TEXT segment word public 'CODE'
- ELSE
- _CODE segment word public 'CODE'
- ENDIF
- ELSE
- IF MSC
- _TEXT segment word public 'CODE'
- ELSE
- prog segment word public 'PROG'
- ENDIF
- ENDIF
- ENDIF
- ENDM
-
- ;
- ; Macro Name : ENDCODE FILENAME
- ;
- ; Parameters : FILENAME = Name of function module
- ;
- ; Definition : Define the end of the code segment for a function
- ; module.
- ;
- ; Microsoft:
- ; The code segment is FILENAME_TEXT (if medium
- ; model, _TEXT if small) and is placed on a
- ; word boundary, is defined as public and class
- ; CODE.
- ;
- ; Lattice:
- ; The code segment is FILENAME_CODE (if medium
- ; model, prog if small) and is placed on a
- ; word boundary, is defined as public and class
- ; CODE.
- ;
- ENDCODE MACRO FILENAME
- IF VAP
- _TEXT ends
- ELSE
- IF FARPROC
- IF MSC
- _TEXT ends
- ELSE
- _CODE ends
- ENDIF
- ELSE
- IF MSC
- _TEXT ends
- ELSE
- prog ends
- ENDIF
- ENDIF
- ENDIF
- ENDM
-
- ;
- ; Macro Name : STARTFILE FILENAME
- ;
- ; Parameters : FILENAME = Name of function module
- ;
- ; Definition : Define the name of a function module, and also
- ; defines the code and data segments. The code
- ; is left open (no ENDCODE macro call). You must
- ; place an ENDCODE call at the end of your code
- ; section.
- ;
- ; Microsoft:
- ; The code segment is FILENAME_TEXT (if medium
- ; model, _TEXT if small) and is placed on a
- ; word boundary, is defined as public and class
- ; CODE. The data segment is _DATA.
- ;
- ; Lattice:
- ; The code segment is FILENAME_CODE (if medium
- ; model, prog if small) and is placed on a
- ; word boundary, is defined as public and class
- ; CODE. The data segment is DATA.
- ;
- ; The data segment is placed in dgroup.
- ;
- STARTFILE MACRO FILENAME
- name FILENAME
-
- STARTCODE FILENAME
- ENDCODE FILENAME
- ;
- DataGroup
- EndData
- ;
- STARTCODE FILENAME
-
- IF VAP
- assume cs:_TEXT
- ELSE
- IF FARPROC
- IF MSC
- assume cs:_TEXT
- ELSE
- assume cs:_CODE
- ENDIF
- ELSE
- IF MSC
- assume cs:_TEXT
- ELSE
- pgroup group prog
- assume cs:pgroup
- ENDIF
- ENDIF
- ENDIF
-
- IF MSC
- dgroup group _data
- ELSE
- dgroup group data
- ENDIF
-
- assume ds:dgroup
- assume es:dgroup
- ENDM
-
- ;IF VAP
- ; extrn NetWareShellServices:dword
- ;ENDIF
-
- IFE DOSENV ; if not DOS
- ; environment, and
- IFE OPSYSHERE ; SysRoutine not
- ; defined in module
- ; being assembled
- IF SYSCALLS ; and System calls
- ; are made (as
- ; opposed to
- ; interrupts)
- EXTPROC SysRoutine,SysRouti ; then define external
- ; SysRoutine
- ENDIF
- ENDIF
- ENDIF
-
- callkbd MACRO ;keyboard macro
- IF DOSENV ; in DOS environment, does int 16h
- int 16h
- ELSE ; in protected mode (OS/2),
- push 16h ; calls SysRoutine (which calls KbdSysCall)
- call SysRoutine
- add sp,2
- ENDIF
- ENDM
-
- callvio MACRO ;video macro
- IF DOSENV ; in DOS environment, does int 10h
- int 10h
- ELSE ; in protected mode (OS/2),
- push 10h ; calls SysRoutine (which calls VioSysCall)
- call SysRoutine
- add sp,2
- ENDIF
- ENDM
-
- callos MACRO ;DOS int 21h macro
- ;IF VAP
- ; call dword ptr cs:NetWareShellServices
- ;ELSE
- IF DOSENV ; in DOS environment, does int 21h
- int 21h
- ELSE ; in protected mode (OS/2),
- push 21h ; calls SysRoutine (which calls
- ; SystemCall)
- call SysRoutine
- pop bx ; this register will be popped
- ; later (just disgarded here)
- ; cannot "add sp,2" because it will
- ; ; change flags
- ENDIF
- ;ENDIF
- ENDM
-
- GETDATASEG MACRO REG ;get the default data segment address
- IF MSC ;into the register REG.
- mov REG,seg _DATA
- ELSE
- mov REG,seg DATA
- ENDIF
- ENDM
-
- jmps macro jmp_addr ;perform a short jump. Justs eliminates
- jmp short jmp_addr ;the need for the word short in your code.
- endm
- .LIST