model.inc
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 6k
Category:

Windows Develop

Development Platform:

Visual C++

  1. ; ========================================================
  2. ;
  3. ; MODEL.INC
  4. ;
  5. ; Copyright (c) 1991 - Microsoft Corp.
  6. ; All rights reserved.
  7. ; Microsoft Confidential
  8. ;
  9. ;
  10. ; Include file which allows globally controlling the memory
  11. ; model of a library of assembly modules. Also contains
  12. ; macros for writing MASM 6.0 code which will compile
  13. ; under DOS 5.1.
  14. ;
  15. ;
  16. ; johnhe - 01-24-92
  17. ;
  18. ; ========================================================================
  19. ; Default to small memory model and C calling conventions if none
  20. ; were declared.
  21. ;
  22. ; ========================================================================
  23. ; Convert old build switches to new type
  24. IFDEF MODEL_LARGE
  25.   MEM_MODEL EQU <LARGE>
  26. ELSEIFDEF MODEL_MEDIUM
  27.   MEM_MODEL EQU <MEDIUM> 
  28. ELSEIFDEF MODEL_COMPACT
  29.   MEM_MODEL EQU <COMPACT>
  30. ELSEIFDEF MODEL_SMALL
  31.   MEM_MODEL EQU <SMALL>
  32. ENDIF
  33. IFNDEF MEM_MODEL
  34.   MEM_MODEL EQU <SMALL>
  35. ENDIF
  36. IFNDEF CALL_TYPE
  37. CALL_TYPE EQU <C>
  38. ENDIF
  39. ; ========================================================================
  40. ; The following defines the memory model based on one of four constants
  41. ; being defined. If none of the constants have been defined the model
  42. ; will default to MODEL_SMALL
  43. ; ========================================================================
  44. DOSSEG
  45. .MODEL MEM_MODEL,CALL_TYPE
  46. ; ========================================================================
  47. ; This macro allows writing code which will assemble with MASM 5.1 or
  48. ; 6.0. MASM 6.0 requires an assume statement before using a register
  49. ; as the base pointer of a structure.
  50. ;
  51. ; RegPtr Register:STRUC, Register:STRUC, ...
  52. ;
  53. ; EXAMPLE:
  54. ;
  55. ; RegPtr DI:MyStruc
  56. ;
  57. ; ========================================================================
  58. RegPtr MACRO  arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
  59.   IFB <arg1>
  60.     %out <Assume Macro --> Requires at least 1 argument.>
  61.   ENDIF
  62.   IF @Version GE 600
  63.     IRP X, <arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9>
  64.       IFNB <x>
  65.         ASSUME  x
  66.       ENDIF
  67.     ENDM
  68.   ENDIF
  69. ENDM
  70. ; ========================================================================
  71. ; Macro which exsplicitly calls a far or near procedure based on the
  72. ; current memory model.
  73. ;
  74. ; call_M PROCEDURE_NAME
  75. ;
  76. ; ========================================================================
  77. call_M MACRO Function
  78. IF  @codesize ; Call adjusted for memory model
  79. call FAR PTR Function ; FAR call if LARGE, MED, or HUGE
  80. ELSE
  81. call NEAR PTR Function ; Else NEAR call
  82. ENDIF
  83. ENDM
  84. ; ========================================================================
  85. ; DS_IF_DATASIZE
  86. ;
  87. ; Equate to allow DS to be pushed on entry to a function if ptrs are
  88. ; far. This macro should be used in conjunction with LoadPtr DS,x,x
  89. ; to ensure DS will be saved if its destroyed by a far ptr load.
  90. ;
  91. ; EXAMPLE:
  92. ;
  93. ; Function PROC USES DI SI ES FPTR_DS, Buffer:PTR, EndBuf:PTR
  94. ;
  95. ; LoadPtr ES,DI,EndBuf
  96. ; LoadPTr DS,SI,BUffer
  97. ; ...
  98. ; Function ENDP
  99. ;
  100. ; Function PROC USES_FPTR_DS, Buffer:PTR, EndBuf:PTR
  101. ;
  102. ; LoadPtr ES,DI,EndBuf
  103. ; LoadPTr DS,SI,BUffer
  104. ; ...
  105. ; Function ENDP
  106. ;
  107. ; ========================================================================
  108. IF @DATASIZE
  109. FPTR_DS EQU <DS>
  110. USES_FPTR_DS EQU <USES DS>
  111. DS_IF_DATASIZE EQU <DS>
  112. ELSE
  113. FPTR_DS EQU  <>
  114. USES_FPTR_DS EQU <>
  115. DS_IF_DATASIZE EQU <>
  116. ENDIF
  117. ; ========================================================================
  118. ; LoadPtr
  119. ;
  120. ; Macro to load a pointer based on the memory model that is in use.
  121. ; Argument checking is included in the macro and the appropriate
  122. ; error message will be displayed.
  123. ;
  124. ; LoadPtr MACRO vSegReg, vReg, vPtr
  125. ;
  126. ; vSegReg - Segment register (normally DS or ES but may be any)
  127. ; vReg - Any general purpose register (AX,BX,CX,DX,SI,DI)
  128. ; vPtr - Pointer to a memory location.
  129. ;   The value will be treated as a dword ptr in
  130. ;   LARGE/COMPACT model and word ptr in MEDIUM/SMALL.
  131. ;
  132. ; ========================================================================
  133. LoadPtr MACRO vSegReg, vReg, vPtr
  134.   SEG_OK = 0 ;; Variables to specify different errors
  135.   REG_OK = 0
  136.   PTR_OK = 0
  137. ;; Error checking on segment register
  138.   IFNB <vSegReg>
  139.     IRP x, <ES,DS,AX,BX,CX,DX,SI,DI>
  140.       IFIDNI <x>,<vSegReg>
  141.         SEG_OK = 1
  142.       ENDIF
  143.     ENDM 
  144.   ENDIF
  145. ;; Error checking on index register
  146.   IFNB <vReg>
  147.     IRP y, <AX,BX,CX,DX,SI,DI>
  148.       IFIDNI <y>,<vReg>
  149.         REG_OK = 1
  150.       ENDIF
  151.     ENDM 
  152.   ENDIF
  153. ;; Error checking on memory pointer
  154.   IFNB <vPtr>
  155.     PTR_OK = 1
  156.   ENDIF
  157. ;; If errs found display appropriate message
  158.   IF (SEG_OK + REG_OK + PTR_OK) NE 3
  159.     IF SEG_OK EQ 0
  160.       %out <LoadPtr Macro --> Invalid segment register vSegReg was specified.>
  161.     ENDIF
  162.     IF REG_OK EQ 0
  163.       %out <LoadPtr Macro --> Invalid register vReg was specified.>
  164.     ENDIF
  165.     IF PTR_OK EQ 0
  166.       %out <LoadPtr Macro --> No memory pointer was specified.>
  167.     ENDIF
  168.     .ERR
  169.   ELSE ;; Start of code in the macro since no errs found
  170.     IF @DataSize ;; For LARGE & COMPACT models use LDS or LES  opcodes
  171.       IFIDNI <vSegReg>,<DS>
  172.         lds vReg, vPtr
  173.       ELSEIFIDNI <vSegReg>,<ES>
  174.         les vReg, vPtr
  175.       ELSE
  176.         mov vSegReg, WORD PTR vPtr[2]
  177.         mov vReg, WORD PTR vPtr
  178.       ENDIF
  179.     ELSE
  180. ;; If vSegReg == ES we have to set ES to DATA SEG
  181.       IFIDNI <vSegReg>,<ES>
  182.         push DS
  183.         pop ES
  184.       ENDIF
  185. ;; Load pointer into specified register
  186.       mov  vReg, vPtr
  187.     ENDIF
  188.   ENDIF
  189. ENDM