]> wirehaze git hosting - MS-DOS.git/blob - v2.0/source/DOSMAC.ASM

wirehaze git hosting

Add Turkish translation for README
[MS-DOS.git] / v2.0 / source / DOSMAC.ASM
1 ;
2 ; Macro file for MSDOS.
3 ;
4
5 SUBTTL BREAK a listing into pages and give new subtitles
6 PAGE
7 BREAK MACRO subtitle
8 SUBTTL subtitle
9 PAGE
10 ENDM
11
12 BREAK <I_NEED: declare a variable external, if necessary, and allocate a size>
13
14 ;
15 ; declare a variable external and allocate a size
16 ;
17 I_NEED MACRO sym,len
18 CODE ENDS
19 DATA SEGMENT BYTE PUBLIC 'DATA'
20
21 IFIDN <len>,<WORD>
22 EXTRN &sym:WORD
23 ELSE
24 IFIDN <len>,<DWORD>
25 EXTRN &sym:DWORD
26 ELSE
27 EXTRN &sym:BYTE
28 ENDIF
29 ENDIF
30
31 DATA ENDS
32 CODE SEGMENT BYTE PUBLIC 'CODE'
33 ENDM
34
35 ;
36 ; call a procedure that may be external. The call will be short.
37 ;
38 invoke MACRO name
39 &.xcref
40 add_ext name,near
41 &.cref
42 CALL name
43 ENDM
44
45 PAGE
46 ;
47 ; jump to a label that may be external. The call will be near.
48 ;
49 transfer MACRO name
50 &.xcref
51 add_ext name,near
52 &.cref
53 JUMP name
54 ENDM
55
56 ;
57 ; get a short address in a word
58 ;
59 short_addr MACRO name
60 IFDIF <name>,<?>
61 &.xcref
62 add_ext name,near
63 &.cref
64 DW OFFSET DOSGROUP:name
65 ELSE
66 DW ?
67 ENDIF
68 ENDM
69
70 ;
71 ; get a long address in a dword
72 ;
73 long_addr MACRO name
74 &.xcref
75 add_ext name,far
76 &.cref
77 DD name
78 ENDM
79
80 ;
81 ; declare a PROC near or far but PUBLIC nonetheless
82 ;
83 procedure MACRO name,distance
84 PUBLIC name
85 name PROC distance
86 ENDM
87
88 PAGE
89 ;
90 ; define a data item to be public and of an appropriate size/type
91 ;
92 I_AM MACRO name,size
93 PUBLIC name
94
95 IFIDN <size>,<WORD>
96 name DW ?
97 ELSE
98 IFIDN <size>,<DWORD>
99 name DD ?
100 ELSE
101 IFIDN <size>,<BYTE>
102 name DB ?
103 ELSE
104 name DB size DUP (?)
105 ENDIF
106 ENDIF
107 ENDIF
108 ENDM
109
110 PAGE
111 ;
112 ; play games with a possible external. Create a new
113 ; macro for the symbol and text, and string it together
114 ; with a central invoker
115 ;
116
117 .xcref
118 .xcref ?i
119 .xcref def_mac
120 .xcref ?z0
121 .xcref add_ext
122 .cref
123
124 IF1
125 ?i=0
126 ENDIF
127
128 ?z0 macro
129 endm
130
131 ;
132 ; add an external declaration to s with type t if it is not defined
133 ;
134 add_ext macro s,t
135 &.xcref
136 &.xcref ?&s
137 &.cref
138 IFNDEF ?&s
139 ?i = ?i + 1
140 def_mac ?z&%?i,?z&%(?i-1),s,t
141 ENDIF
142 endm
143
144 ;
145 ; define a macro called that possibly externals s:t and then calls macro n
146 ;
147 def_mac macro m,n,s,t
148 &.xcref
149 &.xcref ?&s
150 &.xcref m
151 &.cref
152 m macro
153 ifndef s
154 extrn s:&t
155 endif
156 purge m
157 purge ?&s
158 n
159 endm
160 ?&s macro
161 &endm
162 endm
163
164 ;
165 ; call the macro chain
166 ;
167 do_ext macro
168 &.xcref
169 expand_mac ?z%?i
170 &.cref
171 endm
172
173 PAGE
174 expand_mac macro m
175 m
176 endm
177
178 ;
179 ; define an entry in a procedure
180 ;
181 entry macro name
182 PUBLIC name
183 name:
184 endm
185
186 BREAK <ERROR - print a message and then jump to a label>
187
188 error macro code
189 local a
190 .xcref
191 MOV AL,code
192 transfer SYS_RET_ERR
193 .cref
194 ENDM
195
196 BREAK <JUMP - real jump that links up shortwise>
197 ;
198 ; given a label <lbl> either 2 byte jump to another label <lbl>_J
199 ; if it is near enough or 3 byte jump to <lbl>
200 ;
201
202 jump macro lbl
203 local a
204 .xcref
205 a:
206 ifndef lbl&_J ; is this the first invocation
207 JMP lbl
208 ELSE
209 IF lbl&_J GE $
210 JMP lbl
211 ELSE
212 IF ($-lbl&_J) GT 126 ; is the jump too far away?
213 JMP lbl
214 ELSE ; do the short one...
215 JMP lbl&_J
216 ENDIF
217 ENDIF
218 ENDIF
219 endm
220
221 BREAK <RETURN - return from a function>
222
223 return macro
224 local a
225 .xcref
226 a:
227 RET
228 ret_l = a
229 endm
230
231 BREAK <CONDRET - conditional return>
232
233 makelab macro l,cc,ncc
234 j&ncc a ; j<NCC> a:
235 return ; return
236 a: ; a:
237 ret_&cc = ret_l ; define ret_<CC> to be ret_l
238 endm
239
240 condret macro cc,ncc
241 local a,b
242 ifdef ret_l ; if ret_l is defined
243 if (($ - ret_l) le 126) and ($ gt ret_l)
244 ; if ret_l is near enough then
245 a: j&cc ret_l ; a: j<CC> to ret_l
246 ret_&cc = a ; define ret_<CC> to be a:
247 else
248 makelab a,cc,ncc
249 endif
250 else
251 ifdef ret_&cc ; if ret_<CC> defined
252 if (($ - ret_&cc) le 126) and ($ gt ret_&cc)
253 ; if ret_<CC> is near enough
254 a: j&cc ret_&cc ; a: j<CC> to ret_<CC>
255 ret_&cc = a ; define ret_<CC> to be a:
256 else
257 makelab a,cc,ncc
258 endif
259 else
260 makelab a,cc,ncc
261 endif
262 endif
263 endm
264 ;condret macro cc,ncc
265 ; local a,b
266 ; ifdef ret_l ; if ret_l is defined
267 ; if (($ - ret_l) le 126) and ($ gt ret_l)
268 ; ; if ret_l is near enough then
269 ; a: j&cc ret_l ; a: j<CC> to ret_l
270 ; ret_&cc = a ; define ret_<CC> to be a:
271 ; exitm
272 ; endif
273 ; endif
274 ; ifdef ret_&cc ; if ret_<CC> defined
275 ; if (($ - ret_&cc) le 126) and ($ gt ret_&cc)
276 ; ; if ret_<CC> is near enough
277 ; a: j&cc ret_&cc ; a: j<CC> to ret_<CC>
278 ; ret_&cc = a ; define ret_<CC> to be a:
279 ; exitm
280 ; endif
281 ; endif
282 ; j&ncc a ; j<NCC> a:
283 ; return ; return
284 ; a: ; a:
285 ; ret_&cc = ret_l ; define ret_<CC> to be ret_l
286 ;endm
287
288 BREAK <RETZ - return if zero, links up shortwise if necessary>
289
290 retz macro
291 condret z,nz
292 endm
293
294 BREAK <RETNZ - return if not zero, links up shortwise if necessary>
295
296 retnz macro
297 condret nz,z
298 endm
299
300 BREAK <RETC - return if carry set, links up shortwise if necessary>
301
302 retc macro
303 condret c,nc
304 endm
305
306 BREAK <RETNC - return if not carry, links up shortwise if necessary>
307
308 retnc macro
309 condret nc,c
310 endm
311