-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLMACROS.H
215 lines (199 loc) · 3.2 KB
/
LMACROS.H
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
;
; Here is the lmacros header file of Aztec Assembler used by some of the
; assembly-functions to pick their arguments from the stack with procdef
; macro and so on.
;
nlist
; Copyright (C) 1985 by Manx Software Systems, Inc.
; :ts=8
ifndef MODEL
MODEL equ 0
endif
if MODEL and 1
largecode
FARPROC equ 1
FPTRSIZE equ 4
else
FPTRSIZE equ 2
endif
if MODEL and 2
LONGPTR equ 1
endif
;this macro to be used on returning
;restores bp and registers
pret macro
if havbp
pop bp
endif
ret
endm
internal macro pname
public pname
pname proc
endm
intrdef macro pname
public pname
ifdef FARPROC
pname label far
else
pname label near
endif
endm
procdef macro pname, args
public pname&_
ifdef FARPROC
_arg = 6
pname&_ proc far
else
_arg = 4
pname&_ proc near
endif
ifnb <args>
push bp
mov bp,sp
havbp = 1
decll <args>
else
havbp = 0
endif
endm
entrdef macro pname, args
public pname&_
ifdef FARPROC
_arg = 6
pname&_:
else
_arg = 4
pname&_:
endif
ifnb <args>
if havbp
push bp
mov bp,sp
else
error must declare main proc with args, if entry has args
endif
decll <args>
endif
endm
;this macro equates 'aname' to arg on stack
decl macro aname, type
;;'byte' or anything else
havtyp = 0
ifidn <type>,<byte>
aname equ byte ptr _arg[bp]
_arg = _arg + 2
havtyp = 1
endif
ifidn <type>,<dword>
aname equ dword ptr _arg[bp]
_arg = _arg + 4
havtyp = 1
endif
ifidn <type>,<cdouble>
aname equ qword ptr _arg[bp]
_arg = _arg + 8
havtyp = 1
endif
ifidn <type>, <ptr>
ifdef LONGPTR
aname equ dword ptr _arg[bp]
_arg = _arg + 4
else
aname equ word ptr _arg[bp]
_arg = _arg + 2
endif
havtyp = 1
endif
ifidn <type>, <fptr>
ifdef FARPROC
aname equ dword ptr _arg[bp]
_arg = _arg + 4
else
aname equ word ptr _arg[bp]
_arg = _arg + 2
endif
havtyp = 1
endif
ifidn <type>, <word>
aname equ word ptr _arg[bp]
_arg = _arg + 2
havtyp = 1
endif
ife havtyp
error -- type is unknown.
endif
endm
;this macro loads an arg pointer into DEST, with optional SEGment
ldptr macro dest, argname, seg
ifdef LONGPTR
ifnb <seg> ;;get segment if specified
ifidn <seg>,<es>
les dest,argname
else
ifidn <seg>,<ds>
lds dest,argname
else
mov dest, word ptr argname
mov seg, word ptr argname[2]
endif
endif
else
ifidn <dest>,<si> ;;si gets seg in ds
lds si, argname
else
ifidn <dest>,<di> ;;or, es:di
les di, argname
else
garbage error: no seg for long pointer
endif
endif
endif
else
mov dest, word ptr argname ;;get the pointer
ENDIF
ENDM
decll macro list
IRP i,<list>
decl i
ENDM
ENDM
pend macro pname
pname&_ endp
endm
retptrm macro src,seg
mov ax, word ptr src
ifdef LONGPTR
mov dx, word ptr src+2
endif
endm
retptrr macro src,seg
mov ax,src
ifdef LONGPTR
ifnb <seg>
mov dx, seg
endif
endif
endm
retnull macro
ifdef LONGPTR
sub dx,dx
endif
sub ax,ax
endm
pushds macro
ifdef LONGPTR
push ds
endif
endm
popds macro
ifdef LONGPTR
pop ds
endif
endm
finish macro
codeseg ends
endm
list
codeseg segment byte public 'code'
assume cs:codeseg