home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / wasm202.zip / MISC.MAC < prev    next >
Text File  |  1986-11-21  |  7KB  |  188 lines

  1.  List-
  2.  
  3. ;============================================================================;
  4. ;                       Miscellaneous Macro Definitions                      ;
  5. ;                                                                            ;
  6. ; The following macros provide various standard (non-i/o, non-operating      ;
  7. ; system dependent) operations.  For specific DOS functions, see the file    ;
  8. ; DOS.MAC.  For lower level i/o functions, see the file BIOS.MAC.            ;
  9. ;                                                                            ;
  10. ; The defined macros are:                                                    ;
  11. ;                                                                            ;
  12. ; STRING_OFFSET         return offset of a string, declare if necessary      ;
  13. ; STRING_OFFSETZ        return offset of a stringz, declare if necessary     ;
  14. ; DECLARE_STRING        declare a string                                     ;
  15. ; DECLARE_STRINGZ       declare a stringz                                    ;
  16. ; INTERRUPT             execute an interrupt                                 ;
  17. ; IF_SAME               conditional "if operands are same"                   ;
  18. ; IF_DIFFERENT          conditional "if operands are different"              ;
  19. ; IF_EXIST              conditional "if operand exists"                      ;
  20. ; IF_NONE               conditional "if operand doesn't exist"               ;
  21. ;                                                                            ;
  22. ; The two formats for strings are "string" and "stringz."  The first format  ;
  23. ; is used for standard string manipulations and consists of a string of any  ;
  24. ; ASCII characters preceded by a byte specifing its length.  The second      ;
  25. ; format is used to pass file names to DOS and consists of a string of any   ;
  26. ; ASCII characters terminated by a byte 00.                                  ;
  27. ;============================================================================;
  28.  
  29. ;===============================================;
  30. ;                 String_Offset                 ;
  31. ;                                               ;
  32. ; Returns the offset of a string whose length   ;
  33. ; is the first byte. If a literal string is     ;
  34. ; passed, it is declared with its length as its ;
  35. ; first byte.                                   ;
  36. ;                                               ;
  37. ; STRING - string or location of string:        ;
  38. ;   literal string or 16 bit register,          ;
  39. ;   immediate data, or memory.                  ;
  40. ; LOCATION - storage for string offset: 16 bit  ;
  41. ;   register.                                   ;
  42. ;===============================================;
  43.  
  44. String_Offset Macro String, Location
  45.  If Type(String) And Type('')
  46.   Jmps B                ;jump over declaration
  47. A Db Byte (Offset B - Offset A - 1), String ;declare
  48. B Mov Location, Offset A ;set offset of string
  49.  Else
  50.   Mov Location, String ;just pass location
  51.  Endif
  52.  Endm
  53.  
  54. ;===============================================;
  55. ;                 String_Offsetz                ;
  56. ;                                               ;
  57. ; Returns the offset of a string terminated by  ;
  58. ; a zero. If a literal string is passed, it is  ;
  59. ; declared with a terminating zero              ;
  60. ;                                               ;
  61. ; STRING - string or location of string:        ;
  62. ;   literal string or 16 bit register,          ;
  63. ;   immediate data, or memory.                  ;
  64. ; LOCATION - storage for string offset: 16 bit  ;
  65. ;   register.                                   ;
  66. ;===============================================;
  67.  
  68. String_Offsetz Macro String, Location
  69.  If Type(String) And Type('')
  70.   Jmps B                ;jump over declaration
  71. A Db String, 0          ;declare
  72. B Mov Location, Offset A ;set offset of string
  73.  Else
  74.   Mov Location, String ;just pass location
  75.  Endif
  76.  Endm
  77.  
  78. ;===============================================;
  79. ;                 Declare_String                ;
  80. ;                                               ;
  81. ; Declare a string with the first byte being    ;
  82. ; its length.                                   ;
  83. ;                                               ;
  84. ; STRING - string to decalare: literal string.  ;
  85. ;===============================================;
  86.  
  87. Declare_String Macro Str1, Str2, Str3, Str4, Str5
  88. A Db Byte (Offset B - Offset A - 1)
  89.  If_Exist Str1
  90.   Db Str1
  91.  Endif
  92.  If_Exist Str2
  93.   Db Str2
  94.  Endif
  95.  If_Exist Str3
  96.   Db Str3
  97.  Endif
  98.  If_Exist Str4
  99.   Db Str4
  100.  Endif
  101.  If_Exist Str5
  102.   Db Str5
  103.  Endif
  104. B
  105.  Endm
  106.  
  107. ;===============================================;
  108. ;                 Declare_Stringz               ;
  109. ;                                               ;
  110. ; Declare a string terminated by a byte 00.     ;
  111. ;                                               ;
  112. ; STRING - string to decalare: literal string.  ;
  113. ;===============================================;
  114.  
  115. Declare_Stringz Macro Str1, Str2, Str3, Str4, Str5
  116.  If_Exist Str1
  117.   Db Str1
  118.  Endif
  119.  If_Exist Str2
  120.   Db Str2
  121.  Endif
  122.  If_Exist Str3
  123.   Db Str3
  124.  Endif
  125.  If_Exist Str4
  126.   Db Str4
  127.  Endif
  128.  If_Exist Str5
  129.   Db Str5
  130.  Endif
  131.  Db 0
  132.  Endm
  133.  
  134. ;===============================================;
  135. ;                   Interrupt                   ;
  136. ;                                               ;
  137. ; Execute an interrupt, function, and a         ;
  138. ; subfunction.                                  ;
  139. ;                                               ;
  140. ; INT_NUM - interrupt: 8 bit immediate data.    ;
  141. ; FUNC_NUM1 - optional main function (AH): 8    ;
  142. ;   bit register or immediate data.             ;
  143. ; FUNC_NUM2 - optional secondary fuction (AL):  ;
  144. ;   8 bit register or immediate data.           ;
  145. ;===============================================;
  146.  
  147. Interrupt Macro Int_Num, Func_Num1, Func_Num2
  148.  Push Ax                ;parameters on stack
  149.  Mov Bp, Sp
  150.  If_Exist Func_Num1
  151.   Mov Byte [Bp+1], Func_Num1 ;set function (AH)
  152.  Endif
  153.  If_Exist Func_Num2
  154.   Mov Byte [Bp], Func_Num2   ;set subfunction (AL)
  155.  Endif
  156.  Pop Ax                 ;restore parameters
  157.  Int Int_Num            ;execute interrupt
  158.  Endm
  159.  
  160. ;===============================================;
  161. ;            Conditional Statements             ;
  162. ;                                               ;
  163. ; Conditional "if" statements to test if two    ;
  164. ; operands are identical (IF_SAME) or different ;
  165. ; (IF_DIFFERENT) or if an operand exists        ;
  166. ; (IF_EXIST) or not (IF_NONE).                  ;
  167. ;                                               ;
  168. ; OP, OP1, and OP2 - the optional operands to   ;
  169. ;   test: may be any operands.                  ;
  170. ;===============================================; 
  171.  
  172. If_Same Macroc Op1, Op2
  173.  If Type(Op1)=Type(Op2) And (Size(Op1)=Size(Op2)) And (Value(Op1)=Value(Op2))
  174.  Endm
  175.  
  176. If_Different Macroc Op1, Op2
  177.  Ifn Type(Op1)=Type(Op2) And (Value(Op1)=Value(Op2)) And (Size(Op1)=Size(Op2))
  178.  Endm
  179.  
  180. If_Exist Macroc Op
  181.  Ifn Type(Op)=Type()
  182.  Endm
  183.  
  184. If_None Macroc Op
  185.  If Type(Op)=Type()
  186.  Endm
  187.  
  188.