1 ; THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
2 ; SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
3 ; END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
4 ; ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
5 ; IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
6 ; SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
7 ; FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
8 ; CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
9 ; AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
10 ; COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
11 ;Shortcuts for casting
17 ;The macros @ArgCount() & @ArgRev() are from the file MACROS.INC, provided
18 ;with MASM. I have included them here because MACROS.INC has bugs, so I
19 ;couldn't just include it.
21 ; Utility Macros - Version 1.0 - for Microsoft Macro Assembler 6.0
22 ; (C) Copyright Microsoft Corporation, 1987,1988,1989,1990
24 ;* @ArgCount - Macro function returns the number of arguments in a
27 ;* Params: arglist - arguments to be counted
29 @ArgCount MACRO arglist:VARARG
38 ;* @ArgRev - Macro function returns a reversed order version of a
41 ;* Shows: Operators - <> ! %
42 ;* String directive - SUBSTR
43 ;* Predefined function - @SizeStr
45 ;* Params: arglist - arguments to be reversed
47 @ArgRev MACRO arglist:vararg
51 txt CATSTR <arg>, <!,>, txt
54 txt SUBSTR txt, 1, @SizeStr( %txt ) - 1
55 txt CATSTR <!<>, txt, <!>>
59 ;These macros are used for decalaring external vars and functions
61 ;this macro is used to declare several symbols of the same type
62 ;usage is: extdef type,sym0,sym1,...
63 extdef macro type,syms:vararg
69 ;this macro is used to generate ext<type> macros
71 ext&id macro syms:vararg
76 ;macros for common types, such as word (extw), byte (extb), & near (extn)
84 ;compute the absolute value of eax. afterwards, edx=sign (0 or -1)
91 ;PUSHM & POPM are used for multiple registers. Note that POPM pops in the
92 ;reverse order from PUSHM, so the list of regs shouls be the same for both.
93 ;You can also define a constant which is a register list, and use it as the
94 ;argument to both macros.
96 ;push multiple registers
97 pushm macro args:vararg
104 ;pop multiple registers
105 popm macro args:vararg
107 % for arg,@ArgRev(args)
112 ;PUSHLONG pushes a long, zero extending the argument if necessary
113 ;it trashes no registers
117 if s EQ 0 ;constant, I think
129 ;PUSHML is pushm using pushlong
130 pushml macro args:vararg
138 ;DBSTR stores a string with occurances of \n converted to newlines
139 ;this macro expects quotes around the string
141 ;note the 'fudge' variable. This fixes an odd problem with the way
142 ;the string macros deal with backslashes - @InStr() treats them like
143 ;any other character, but @SubStr() ignores them
145 local pos,oldpos,len,fudge
147 oldpos = 2 ;skip initial quote
151 pos = @InStr(oldpos,str,<\n>)
156 %db '&@SubStr(<&str>,&oldpos-&fudge,&pos-&oldpos)'
162 pos = @InStr(oldpos,<str>,<\n>)
167 ;;; %db '&@SubStr(&str,&oldpos-&fudge,&len-&oldpos-1)'
168 %db '&@SubStr(&str,&oldpos-&fudge,&len-&oldpos)'
174 ;MPRINTF is a macro interface to the mprintf funcion. It puts the format
175 ;string in the code segment at the current location, pushes the args, and
176 ;calls mprintf. If window is not specified, zero is assumed
177 mprintf macro window:=<0>,format:req,args:vararg
188 % pushml @ArgRev(args)
190 pushml offset string,window
192 add esp,(@ArgCount(args)+2)*4 ;fix stack
198 ;MPRINTF_AT - version of mprintf with coordinates
199 mprintf_at macro window:=<0>,row,col,format:req,args:vararg
210 % pushml @ArgRev(args)
212 pushml offset string,col,row,window
214 add esp,(@ArgCount(args)+4)*4 ;fix stack
220 ;DEBUG calls mprintf with window 0, preserving all registers and flags
221 ;is is conditionall assembled based on the DEBUG_ON flags
222 debug macro format:req,args:vararg
225 push eax ;mprintf trashes eax
232 ;DEBUG_AT - version of debug with coordinates
233 debug_at macro row,col,format:req,args:vararg
236 push eax ;mprintf trashes eax
237 mprintf_at ,row,col,format,args
243 ;Debugging breakpoint macros
245 ;print a message, and do an int3 to pop into the debugger
253 break_if macro cc,str
258 yes_break: debug_brk str
263 ;returns the bit number of the highest bit
279 ;returns the bit number of the lowest bit
297 ;"multiply" the given register by a constant, using whatever method is
298 ;best for the given constant
310 lea reg,[reg*2+reg] ;*3
324 echo Warning: Using imul, to perform multiply by &c