home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / DX86_O / MACROS < prev    next >
Encoding:
Text File  |  1990-05-01  |  4.2 KB  |  222 lines

  1. ; .286c         -- DO NOT ADD THESE; 
  2. ; .286p
  3. ; .287
  4. ; otherwise fwaits will be omitted and it won't work for the 8086/8087.
  5.  
  6.  
  7. eax    equ    ax
  8. ebx    equ    bx
  9. ecx    equ    cx
  10. edx    equ    dx
  11. edi    equ    di
  12. esi    equ    si
  13. esp    equ    sp
  14. ebp    equ    bp
  15. movzx    equ    mov
  16. ebadf = 6
  17. edeadlock = 25
  18. eaccess equ     5
  19. enoent  equ      2
  20. ; Set pointer size.
  21. ifdef    Large_data
  22. Ptr_size    =    4
  23. Ptr_reg     equ    es    ; Use es.
  24. Stack_reg    equ    ss    ; Use ss.
  25. else
  26. Ptr_size    =    2
  27. Ptr_reg     equ    ds    ; Can use ds, since = es.
  28. Stack_reg    equ    ds    ; Can use ds, since = ss.
  29. endif
  30.  
  31. ifdef    Small_code
  32. Pbase    =    4    ; Location of first parameter.
  33. Routine_size=    4    ; link + offset.
  34. return    macro    Pop_bytes
  35.   ifb    <Pop_bytes>
  36.     db    0c3h
  37.   else
  38.     db    0c2h
  39.     dw    Pop_bytes
  40.   endif
  41.     endm
  42.     extrnf    macro    name
  43.     extrn    name:near
  44.     endm
  45. else
  46. Pbase    =    6    ; Location of first parameter.
  47. Routine_size=    6    ; Link + offset + segment.
  48. return    macro    Pop_bytes
  49.   ifb    <Pop_bytes>
  50.     db    0cbh
  51.   else
  52.     db    0cah
  53.     dw    Pop_bytes
  54.   endif
  55.     endm
  56.     extrnf    macro    name
  57.     extrn    name:far
  58.     endm
  59. endif
  60.  
  61. Word_size = 2
  62.  
  63. prolog    macro
  64.     push    bp
  65.     mov    bp,sp
  66. ifdef    Large_data    ; Save DS whether or not 1 DS, in case we modify it.
  67.     push    ds
  68. endif
  69.     endm
  70. epilog    macro    Pop_bytes
  71. ifdef    Large_data
  72.     pop    ds
  73. endif
  74.     pop    bp
  75.     return    Pop_bytes
  76.     endm
  77.  
  78. ; We would have preferred a procbeg and procend macro, but
  79. ; the "proc" directive can't go inside a macro -- yet another
  80. ; of the many bugs in the flaky Microsoft assembler.
  81. publab    macro    procname
  82.     public    _mw&procname
  83. _mw&procname:
  84.     endm
  85.     
  86. cseg    macro    segname,status
  87.     name    &segname
  88.     cseg2    &segname,&status
  89.     endm
  90.     
  91. ; Same as cseg, but without the "name" directive.  It's because you
  92. ; can't override a name directive.    
  93. cseg2    macro    segname,status    
  94. ifb    <status>
  95. _mw&segname    segment word 'code'
  96. else
  97. _mw&segname    segment word 'code' public
  98. endif
  99.     assume    cs:_mw&segname
  100. ifdef    Small_code
  101. cgroup    group    _mw&segname
  102.     assume    cs:cgroup
  103. endif
  104.     endm
  105.     
  106. endcseg macro    segname
  107. _mw&segname    ends
  108.     endm
  109.     
  110. pubnames macro    names
  111.     irp    name,<names>
  112. ifdef   USING_PHARLAP  
  113.     public    _mw&name
  114. else    
  115.     public    _mw&&name
  116. endif   
  117.     endm
  118.     endm
  119. def    macro    x,y,z
  120. _mw&x    y    z
  121.     endm
  122. defequ    macro    x,y,z
  123. _mw&x    y    z
  124. x    equ    _mw&x
  125.     endm
  126. extequ    macro    x,type
  127.     extrn    _mw&x:type
  128. x    equ    _mw&x
  129.     endm
  130. ext    macro    x,type
  131.     extrn    _mw&x:type
  132.     endm
  133. ; Macros for parameter set-up that take care of small vs. large code
  134. ; and to some extent small vs. large data.
  135. ; Callling sequence:
  136. ;    parms    <<N1,T1>,<N2,T2>,...>
  137. ; where Ni are the names and Ti the types.
  138. ; This expands into
  139. ;    Ni equ T1 ptr offset[bp]
  140. ; where offset starts at the appropriate value for a procedure
  141. ; (assuming BP has been pushed, and taking into account small vs lg code)
  142. ; and is incremented as follows:
  143. ;    if Ti = "ptr" then increment by Ptr_size
  144. ;    otherwise increment by 2.
  145. ; For example:
  146. ;    parms    <<Src,word>,<Dest,ptr>,<Cnt,word>>
  147. ; generates
  148. ;    Src equ word ptr 6[bp]
  149. ;    Dest equ dword ptr 8[bp]
  150. ;    Cnt equ word ptr 12[bp]
  151. ; assuming parms start at 6.
  152. parm    macro    P,Type
  153.     local    offset
  154. offset    equ    Poff+0    ; +0 avoids alias; forces pass1 computation of expn.
  155. ifidn    <Type>,<ptr>    ; Type = "ptr"?
  156.   ifdef Small_data
  157. P    equ    word ptr offset[bp]
  158.   else
  159. P    equ    dword ptr offset[bp]
  160.   endif
  161. Poff    =    Poff + Ptr_size
  162. else
  163. ifidn    <Type>,<routine>    ; Type = "routine"?
  164.   ifdef Small_code
  165. P    equ    word ptr offset[bp]
  166.   else
  167. P    equ    dword ptr offset[bp]
  168.   endif
  169. Poff    =    Poff + Routine_size - 2 ; DOES NOT skip link.
  170. else
  171. P    equ    Type ptr offset[bp]
  172. Poff    =    Poff + 2
  173. endif
  174. endif
  175.     endm
  176. parms    macro    Parmlist
  177. Poff    =    Pbase    ; ret addr + pushed bp.
  178.     irp    P,<Parmlist>
  179.     parm    P
  180.     endm
  181.     endm
  182. parm86    macro    parmlist
  183.     parms    <parmlist>
  184.     endm
  185. parm386    macro    parmlist
  186.     endm
  187.  
  188. ; Load a pointer.
  189. ifdef    Small_data
  190. loadptr macro    Seginstr,Ireg,Operand
  191.     mov    Ireg,Operand
  192.     endm
  193. else
  194. loadptr macro    Seginstr,Ireg,Operand
  195.     Seginstr Ireg,Operand
  196.     endm
  197. endif
  198.  
  199. ; Load a formal routine parameter.
  200. ifdef    Small_code
  201. loadrout macro    Segreg,Ireg,Operand
  202.     mov    Ireg,Operand
  203.     push    cs
  204.     pop    Segreg
  205.     endm
  206. else
  207. loadrout macro    Segreg,Ireg,Operand
  208.     L&Segreg Ireg,dword ptr Operand
  209.     endm
  210. endif
  211.  
  212. ; Call a procedure.
  213. ifdef    Small_code
  214. pcall    macro    procname
  215.     call    cgroup:(near ptr procname)
  216.     endm
  217. else
  218. pcall    macro    procname
  219.     call    far ptr procname
  220.     endm
  221. endif
  222.