-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMacros.inc
More file actions
176 lines (145 loc) · 2.87 KB
/
Macros.inc
File metadata and controls
176 lines (145 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
;--- macros:
;--- CStr()
;--- L()
;--- CStrW()
;--- smalloc, sfree, sreload
;--- return
;--- @mov
;--- MEMBER
ifndef CStr
;--- CStr() define a string in .CONST
;--- or in .CONST$2 if .CONST is the current section
CStr macro text:VARARG
local sym
ifidni @CurSeg,<CONST>
CONST$2 segment dword flat public 'CONST'
else
CONST segment dword flat public 'CONST'
endif
ifidni <text>,<"">
sym db 0
else
sym db text,0
endif
@CurSeg ends
exitm <offset sym>
endm
endif
ifndef L
;---- L() defines a wide string
;---- usage: StringName dw L(stringvalue)
if 0
L macro y:req
local x
x textequ <>
forc chr$,<y>
x CatStr x,<'&chr$'>,<,>
endm
x CatStr x,<0>
exitm <x>
endm
endif ;L()
else
L macro parms:VARARG
local wstr,i,c,tstr
wstr textequ <>
i = 0
for parm,<parms>
c SubStr <parm>,1,1
ifidn c,<">
tstr SubStr <parm>,2,@SizeStr(parm)-2
% forc chr$,<tstr>
if i
wstr CatStr wstr,<,>
endif
wstr CatStr wstr,<'&chr$'>
i = i + 1
endm
else
if i
wstr CatStr wstr,<,>
endif
wstr CatStr wstr,<parm>
endif
endm
exitm <wstr>
endm
endif
;--- CStrW defines a wide string in .CONST
;--- returns a pointer to that string
CStrW macro text:req
local sym
ifidni @CurSeg,<CONST>
CONST$2 segment dword flat public 'CONST'
else
CONST segment dword flat public 'CONST'
endif
align 2
sym dw text,0
@CurSeg ends
exitm <offset sym>
endm
ifndef smalloc
;--- the smalloc + sfree macros are used to alloc space
;--- on the stack.
;--- usage: "smalloc register,numBytes" and "sfree"
smalloc macro reg:req,bytes:req ;alloc space on the stack (local only)
local ?bytes
?bytes = (bytes + 3) and 0fffffffch
sub esp,?bytes
mov reg,esp
push ?bytes+4
endm
sreload macro reg:req,index ;reload address of stack items
ifnb <index>
mov reg,esp
repeat index
add reg,[reg]
endm
add reg,4
else
lea reg,[esp+4]
endif
endm
sfree macro
add esp,[esp]
endm
endif ;smalloc
;--- return: return a value in eax
ifndef return
return macro x
ifnb <x>
if (OPATTR x) and 4 ;;constant?
if x
mov eax,x
else
xor eax,eax
endif
else
mov eax,x
endif
endif
ret
endm
endif ;return
;--- simple macro for a 3 byte move, used i.e.: @mov ecx, 3
@mov macro x, y
push y
pop x
endm
ifndef MEMBER
;--- MEMBER: create member names
;--- requires at least one other definition in program itself.
;--- assume ebx is used to access this_. so define in program
;--- "_this textequ <[ebx].CClassName>"
;--- "MEMBER VarName"
;--- so access to member
;--- "[ebx].CClassName.VarName" simplifies to "m_VarName"
MEMBER macro names:VARARG
local x
for y,<names>
x CatStr <_this.>,<y>
m_&y textequ x
endm
endm
endif ;MEMBER