home *** CD-ROM | disk | FTP | other *** search
- .386p
- Word_size = 4 ; for the 386; min argument passed.
- asm_386 = 1 ; this is for the 386.
- ebadf = 4
- edeadlock = 5
-
- ; Set pointer size.
- ifdef Large_data
- Ptr_size = 8 ; pass 8 bytes at a time for a 6-byte ptr.
- Ptr_reg equ es ; Use es.
- Stack_reg equ ss ; Use ss.
- else
- Ptr_size = 4
- Ptr_reg equ ds ; Can use ds, since = es.
- Stack_reg equ ds ; Can use ds, since = ss.
- endif
-
- ifdef Small_code
- Pbase = 8 ; Location of first parameter.
- Routine_size= 8 ; link + offset.
- return macro Pop_bytes
- ifb <Pop_bytes>
- db 0c3h
- else
- db 0c2h
- dw Pop_bytes
- endif
- endm
- extrnf macro name
- extrn name:near
- endm
- ;near_far equ near
- else
- Pbase = 12 ; Location of first parameter.
- Routine_size= 12 ; Link + offset + segment.
- return macro Pop_bytes
- ifb <Pop_bytes>
- db 0cbh
- else
- db 0cah
- dw Pop_bytes
- endif
- endm
- extrnf macro name
- extrn name:far
- endm
- ;near_far equ far
- endif
-
- prolog macro
- push ebp
- mov ebp,esp
- push esi
- push edi
- push ebx
- ifdef Large_data ; Save DS whether or not 1 DS, in case we modify it.
- push ds
- endif
- endm
- epilog macro Pop_bytes
- ifdef Large_data
- pop ds
- endif
- pop ebx
- pop edi
- pop esi
- pop ebp
- return Pop_bytes
- endm
-
- ; We would have preferred a procbeg and procend macro, but
- ; the "proc" directive can't go inside a macro -- yet another
- ; of the many bugs in the flaky Microsoft assembler.
- publab macro procname
- public _mw&procname
- _mw&procname:
- endm
- cseg macro segname,status
- name &segname
- ifb <status>
- _mw&segname segment dword 'CODE'
- else
- _mw&segname segment dword 'CODE' public
- endif
- assume cs:_mw&segname
- ifdef Small_code
- CGROUP group _mw&segname
- assume cs:CGROUP
- endif
- endm
- endcseg macro segname
- _mw&segname ends
- endm
- pubnames macro names
- irp name,<names>
- ifdef USING_MASM
- public _mw&&name
- else
- public _mw&name
- endif
- endm
- endm
- pubname macro name
- public _mw&name
- endm
- def macro x,y,z
- _mw&x y z
- endm
- defequ macro x,y,z
- _mw&x y z
- x equ _mw&x
- endm
- extequ macro x,type
- extrn _mw&x:type
- x equ _mw&x
- endm
- ext macro x,type
- extrn _mw&x:type
- endm
- ; Macros for parameter set-up that take care of small vs. large code
- ; and to some extent small vs. large data.
- ; Calling sequence:
- ; parms <<N1,T1>,<N2,T2>,...>
- ; where Ni are the names and Ti the types.
- ; This expands into
- ; Ni equ T1 ptr offset[bp]
- ; where offset starts at the appropriate value for a procedure
- ; (assuming BP has been pushed, and taking into account small vs lg code)
- ; and is incremented as follows:
- ; if Ti = "ptr" then increment by Ptr_size
- ; otherwise increment by 2.
- ; For example:
- ; parms <<Src,word>,<Dest,ptr>,<Cnt,word>>
- ; generates
- ; Src equ word ptr 6[bp]
- ; Dest equ dword ptr 8[bp]
- ; Cnt equ word ptr 12[bp]
- ; assuming parms start at 6.
- parm macro P,Type
- local Offset
- Offset equ Poff+0 ; +0 avoids alias; forces pass1 computation of expn.
- ifidn <Type>,<ptr> ; Type = "ptr"?
- ifdef Small_data
- P equ dword ptr Offset[ebp]
- else
- P equ pword ptr Offset[ebp]
- endif
- Poff = Poff + Ptr_size
- else
- ifidn <Type>,<routine> ; Type = "routine"?
- ifdef Small_code
- P equ word ptr Offset[ebp]
- else
- P equ dword ptr Offset[ebp]
- endif
- Poff = Poff + Routine_size - Word_size ; DOES NOT skip link.
- else
- P equ Type ptr Offset[ebp]
- Poff = Poff + Word_size
- endif
- endif
- endm
- parms macro Parmlist
- Poff = Pbase ; ret addr + pushed bp.
- irp P,<Parmlist>
- parm P
- endm
- endm
- parm386 macro parmlist
- parms <parmlist>
- endm
- parm86 macro parmlist
- endm
-
- ; Load a pointer.
- ifdef Small_data
- loadptr macro Seginstr,Ireg,Operand
- mov Ireg,Operand
- endm
- else
- loadptr macro Seginstr,Ireg,Operand
- seginstr Ireg,dword ptr Operand
- endm
- endif
-
- ; Load a formal routine parameter.
- ifdef Small_code
- loadrout macro Segreg,Ireg,Operand
- mov Ireg,Operand
- push cs
- pop Segreg
- endm
- else
- loadrout macro Segreg,Ireg,Operand
- L&Segreg Ireg,dword ptr Operand
- endm
- endif
-
- ; Call a procedure.
- ifdef Small_code
- pcall macro procname
- ifdef USING_MASM
- call procname ; MASM 5.1 BUG!!
- ; MASM doesn't put out proper LEdata for the call below.
- else
- call CGROUP:(near ptr procname)
- endif
- endm
- else
- pcall macro procname
- call far ptr procname
- endm
- endif
-