summaryrefslogtreecommitdiff
path: root/v4.0/src/INC/DOSMAC.INC
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/INC/DOSMAC.INC')
-rw-r--r--v4.0/src/INC/DOSMAC.INC630
1 files changed, 630 insertions, 0 deletions
diff --git a/v4.0/src/INC/DOSMAC.INC b/v4.0/src/INC/DOSMAC.INC
new file mode 100644
index 0000000..ca21f8b
--- /dev/null
+++ b/v4.0/src/INC/DOSMAC.INC
@@ -0,0 +1,630 @@
1; SCCSID = @(#)dosmac.asm 1.1 85/04/10
2; SCCSID = @(#)dosmac.asm 1.1 85/04/10
3;
4; Macro file for MSDOS.
5;
6
7TRUE EQU 0FFFFh
8FALSE EQU 0
9
10SUBTTL BREAK a listing into pages and give new subtitles
11PAGE
12BREAK MACRO subtitle
13 SUBTTL subtitle
14 PAGE
15ENDM
16.xcref break
17
18BREAK <ASMVAR - handle assembly variables once and for all>
19
20AsmVars Macro varlist
21IRP var,<varlist>
22AsmVar var
23ENDM
24ENDM
25
26AsmVar Macro var
27IFNDEF var
28var = FALSE
29ENDIF
30ENDM
31
32BREAK <I_NEED: declare a variable external, if necessary, and allocate a size>
33
34;
35; declare a variable external and allocate a size
36;
37AsmVar InstalledData
38I_NEED MACRO sym,len
39IF NOT InstalledData
40 DATA SEGMENT WORD PUBLIC 'DATA'
41 IFIDN <len>,<WORD>
42 EXTRN &sym:WORD
43 ELSE
44 IFIDN <len>,<DWORD>
45 EXTRN &sym:DWORD
46 ELSE
47 EXTRN &sym:BYTE
48 ENDIF
49 ENDIF
50 DATA ENDS
51ENDIF
52ENDM
53 .xcref I_need
54
55;
56; call a procedure that may be external. The call will be short.
57;
58invoke MACRO name
59.xcref
60 IF2
61 IFNDEF name
62 EXTRN name:NEAR
63 ENDIF
64 ENDIF
65.cref
66 CALL name
67ENDM
68.xcref invoke
69
70PAGE
71;
72; jump to a label that may be external. The jump will be near.
73;
74transfer MACRO name
75.xcref
76 IF2
77 IFNDEF name
78 EXTRN name:NEAR
79 ENDIF
80 ENDIF
81.cref
82 JUMP name
83ENDM
84.xcref transfer
85
86;
87; get a short address in a word
88;
89short_addr MACRO name
90 IFDIF <name>,<?>
91.xcref
92 IF2
93 IFNDEF name
94 EXTRN name:NEAR
95 ENDIF
96 ENDIF
97.cref
98 DW OFFSET DOSGROUP:name
99 ELSE
100 DW ?
101 ENDIF
102ENDM
103.xcref short_addr
104
105;
106; get a long address in a dword
107;
108long_addr MACRO name
109.xcref
110 IF2
111 IFNDEF name
112 EXTRN name:NEAR
113 ENDIF
114 ENDIF
115.cref
116 DD name
117ENDM
118.xcref long_addr
119
120;
121; declare a PROC near or far but PUBLIC nonetheless
122;
123.xcref ?frame
124.xcref ?aframe
125.xcref ?stackdepth
126.xcref ?initstack
127?frame = 0 ; initial
128?aframe = 0 ; initial
129?stackdepth = 0 ; initial stack size
130?initstack = 0 ; initial stack size
131
132procedure MACRO name,distance
133 ?frame = 0
134 ?aframe = 2 ;; remember the pushed BP
135 PUBLIC name
136 IF1
137 %OUT name... pass 1
138 ENDIF
139 IF2
140 %OUT name... pass 2
141 ENDIF
142name PROC distance
143 ?initstack = ?stackdepth ;; beginning of procedure
144ENDM
145.xcref procedure
146
147;
148; end a procedure and check that stack depth is preserved
149;
150EndProc MACRO name, chk
151 IFDIF <chk>,<NoCheck> ;; check the stack size
152 IF2
153 IF ?initstack NE ?stackdepth ;; is it different?
154 %OUT ***** Possible stack size error in name *****
155 ENDIF
156 ENDIF
157 ENDIF
158name ENDP
159ENDM
160.xcref endproc
161PAGE
162;
163; define a data item to be public and of an appropriate size/type
164;
165
166I_AM MACRO name,size,init
167;; declare the object public
168 PUBLIC name
169;; declare the type of the object
170 IFIDN <size>,<WORD>
171name LABEL WORD
172 I_AM_SIZE = 1
173 I_AM_LEN = 2
174 ELSE
175 IFIDN <size>,<DWORD>
176name LABEL DWORD
177 I_AM_SIZE = 2
178 I_AM_LEN = 2
179 ELSE
180 IFIDN <size>,<BYTE>
181name LABEL BYTE
182 I_AM_SIZE = 1
183 I_AM_LEN = 1
184 ELSE
185name LABEL BYTE
186 I_AM_SIZE = size
187 I_AM_LEN = 1
188 ENDIF
189 ENDIF
190 ENDIF
191;; if no initialize then allocate blank storage
192 IFB <init>
193 DB I_AM_SIZE*I_AM_LEN DUP (?)
194 ELSE
195IF NOT InstalledData
196 IRP itm,<init>
197 IF I_AM_LEN EQ 1
198 DB itm
199 ELSE
200 DW itm
201 ENDIF
202 I_AM_SIZE = I_AM_SIZE - 1
203 ENDM
204 IF I_AM_SIZE NE 0
205 %out ***** initialization of name not complete *****
206 ENDIF
207ELSE
208 DB I_AM_SIZE*I_AM_LEN DUP (?)
209ENDIF
210 ENDIF
211ENDM
212.xcref I_AM
213.xcref I_AM_SIZE
214.xcref I_AM_LEN
215I_AM_SIZE = 0
216I_AM_LEN = 0
217
218PAGE
219
220;
221; define an entry in a procedure
222;
223entry macro name
224 PUBLIC name
225name:
226endm
227.xcref entry
228
229BREAK <ERROR - store an error code then jump to a label>
230
231error macro code
232.xcref
233 MOV AL,code
234 transfer SYS_RET_ERR
235.cref
236ENDM
237.xcref error
238
239BREAK <JUMP - real jump that links up shortwise>
240;
241; given a label <lbl> either 2 byte jump to another label <lbl>_J
242; if it is near enough or 3 byte jump to <lbl>
243;
244
245jump macro lbl
246 local a
247.xcref
248
249 ifndef lbl&_J ;; is this the first invocation
250a: JMP lbl
251 ELSE
252 IF (lbl&_J GE $) OR ($-lbl&_J GT 126)
253a: JMP lbl ;; is the jump too far away?
254 ELSE
255a: JMP lbl&_J ;; do the short one...
256 ENDIF
257 ENDIF
258 lbl&_j = a
259.cref
260endm
261.xcref jump
262
263BREAK <RETURN - return from a function>
264
265return macro x
266 local a
267.xcref
268a:
269 RET
270ret_l = a
271.cref
272endm
273.xcref return
274
275BREAK <CONDRET - conditional return>
276
277condret macro cc,ncc
278 local a
279.xcref
280.xcref a
281.cref
282 ifdef ret_l ;; if ret_l is defined
283 if (($ - ret_l) le 126) and ($ gt ret_l)
284 ;; if ret_l is near enough then
285 a: j&cc ret_l ;; a: j<CC> to ret_l
286 ret_&cc = a ;; define ret_<CC> to be a:
287 exitm
288 endif
289 endif
290 ifdef ret_&cc ;; if ret_<CC> defined
291 if (($ - ret_&cc) le 126) and ($ gt ret_&cc)
292 ;; if ret_<CC> is near enough
293 a: j&cc ret_&cc ;; a: j<CC> to ret_<CC>
294 ret_&cc = a ;; define ret_<CC> to be a:
295 exitm
296 endif
297 endif
298 j&ncc a ;; j<NCC> a:
299 return ;; return
300 a: ;; a:
301 ret_&cc = ret_l ;; define ret_<CC> to be ret_l
302endm
303.xcref condret
304
305BREAK <RETZ - return if zero, links up shortwise if necessary>
306
307retz macro
308 condret z,nz
309endm
310.xcref retz
311
312BREAK <RETNZ - return if not zero, links up shortwise if necessary>
313
314retnz macro
315 condret nz,z
316endm
317.xcref retnz
318
319BREAK <RETC - return if carry set, links up shortwise if necessary>
320
321retc macro
322 condret c,nc
323endm
324.xcref retc
325
326BREAK <RETNC - return if not carry, links up shortwise if necessary>
327
328retnc macro
329 condret nc,c
330endm
331.xcref retnc
332
333BREAK <CONTEXT - set the DOS context to a particular register>
334
335context macro r
336 PUSH SS
337 POP r
338 ASSUME r:DOSGROUP
339endm
340.xcref context
341
342BREAK <SaveReg - save a set of registers>
343
344SaveReg MACRO reglist ;; push those registers
345IRP reg,<reglist>
346 ?stackdepth = ?stackdepth + 1
347 PUSH reg
348ENDM
349ENDM
350.xcref SaveReg
351
352BREAK <RestoreReg - unsave some registers>
353
354RestoreReg MACRO reglist ;; pop those registers
355IRP reg,<reglist>
356 ?stackdepth = ?stackdepth - 1
357 POP reg
358ENDM
359ENDM
360.xcref RestoreReg
361
362BREAK <Critical section macros>
363
364EnterCrit MACRO section
365 Invoke E&section
366ENDM
367
368LeaveCrit MACRO section
369 Invoke L&section
370ENDM
371
372Break <message - display a message>
373
374AsmVars <ShareF,Cargs,Redirector>
375
376if debug
377fmt MACRO typ,lev,fmts,args
378local a,b,c
379 PUSHF
380IFNB <typ>
381 TEST BugTyp,typ
382 JZ c
383 CMP BugLev,lev
384 JB c
385ENDIF
386 PUSH AX
387 PUSH BP
388 MOV BP,SP
389If (not sharef) and (not redirector)
390Table segment
391a db fmts,0
392Table ends
393 MOV AX,OFFSET DOSGROUP:a
394else
395 jmp short b
396a db fmts,0
397if sharef
398b: mov ax,offset share:a
399else
400b: mov ax,offset netwrk:a
401endif
402endif
403 PUSH AX
404cargs = 2
405IRP item,<args>
406IFIDN <AX>,<item>
407 MOV AX,[BP+2]
408ELSE
409 MOV AX,item
410ENDIF
411 PUSH AX
412cargs = cargs + 2
413ENDM
414 invoke PFMT
415 ADD SP,Cargs
416 POP BP
417 POP AX
418c:
419 POPF
420ENDM
421else
422fmt macro
423endm
424endif
425
426Break <DOSAssume - validate assumes>
427
428AsmVar Debug,$temp
429
430IF debug
431DOSAssume Macro reg,reglist,message
432local a,b
433 IFIDN <reg>,<CS>
434 $temp = 1
435 ELSE
436 IFIDN <reg>,<SS>
437 $temp = 0
438 ELSE
439 %out ***** Invalid DOS register reg in DOSAssume *****
440 ENDIF
441 ENDIF
442 IRP r,<reglist>
443 IFIDN <r>,<DS>
444 $temp = $temp OR 2
445 ELSE
446 IFIDN <r>,<ES>
447 $temp = $temp OR 4
448 ELSE
449 %out ***** Invalid register reg in DOSAssume *****
450 ENDIF
451 ENDIF
452 ENDM
453 PUSH AX
454 MOV AX,$temp
455 PUSH AX
456IF SHAREF
457 MOV AX,OFFSET a
458ELSE
459 MOV AX,OFFSET DOSGroup:a
460ENDIF
461 PUSH AX
462 Invoke SegCheck
463 POP AX
464IF NOT SHAREF
465Table SEGMENT
466a DB message,0
467Table ends
468ELSE
469 JMP SHORT a
470b DB message,0
471a:
472ENDIF
473IRP r,<reglist>
474 ASSUME r:DOSGroup
475ENDM
476ENDM
477ELSE
478DOSAssume Macro reg,reglist,message
479IRP r,<reglist>
480 ASSUME r:DOSGroup
481ENDM
482ENDM
483ENDIF
484
485BREAK <ASSERT - make assertions about registers>
486
487IF DEBUG
488Assert MACRO kind, objs, message
489 LOCAL a,b
490 IFIDN <kind>,<Z>
491 CMP objs,0
492 JZ a
493 fmt <>,<>,<message>
494a:
495 ELSE
496 IFIDN <kind>,<NZ>
497 CMP objs,0
498 JNZ a
499 fmt <>,<>,<message>
500a:
501 ELSE
502 PUSH AX
503 IRP obj,<objs>
504 PUSH obj
505 ENDM
506 IF SHAREF
507 MOV AX,OFFSET b
508 ELSE
509 MOV AX,OFFSET DOSGroup:b
510 ENDIF
511 PUSH AX
512 IFIDN <kind>,<ISBUF>
513 Invoke BUFCheck
514 ENDIF
515 IFIDN <kind>,<ISSFT>
516 Invoke SFTCheck
517 ENDIF
518 IFIDN <kind>,<ISDPB>
519 Invoke DPBCheck
520 ENDIF
521 POP AX
522 IF SHAREF
523 JMP SHORT a
524b DB Message,0
525a:
526 ELSE
527Table segment
528b db Message,0
529Table ends
530 ENDIF
531 ENDIF
532 ENDIF
533ENDM
534ELSE
535Assert Macro
536ENDM
537ENDIF
538
539Break <CallInstall - hook to installable pieces>
540
541CallInstall MACRO name,mpx,fn,save,restore
542IF Installed
543 IFNB <save>
544 SaveReg <save>
545 ENDIF
546 MOV AX,(mpx SHL 8) + fn
547 INT 2Fh
548 IFNB <restore>
549 RestoreReg <restore>
550 ENDIF
551ELSE
552 Invoke name
553ENDIF
554ENDM
555
556Break <Stack frame manipulators>
557
558localvar macro name,length
559local a
560 ifidn <length>,<BYTE>
561 ?frame = ?frame + 1
562 a = ?frame
563 name EQU BYTE PTR [BP-a]
564 else
565 ifidn <length>,<WORD>
566 ?frame = ?frame + 2
567 a = ?frame
568 name EQU WORD PTR [BP-a]
569 else
570 ifidn <length>,<DWORD>
571 ?frame = ?frame + 4
572 a = ?frame
573 name EQU DWORD PTR [BP-a]
574 name&l EQU WORD PTR [BP-a]
575 name&h EQU WORD PTR [BP-a+2]
576 else
577 ?frame = ?frame + length
578 a = ?frame
579 name EQU BYTE PTR [BP-a]
580 endif
581 endif
582 endif
583endm
584
585enter macro
586 push bp
587 mov bp,sp
588 sub sp,?frame
589endm
590
591leave macro
592 mov sp,bp
593 pop bp
594endm
595
596Argvar macro name,length
597local a
598 ifidn <length>,<BYTE>
599 a = ?aframe
600 ?aframe = ?aframe + 1
601 name EQU BYTE PTR [BP+a]
602 else
603 ifidn <length>,<WORD>
604 a = ?aframe
605 ?aframe = ?aframe + 2
606 name EQU WORD PTR [BP+a]
607 else
608 ifidn <length>,<DWORD>
609 a = ?aframe
610 ?aframe = ?aframe + 4
611 name EQU DWORD PTR [BP+a]
612 name&l EQU WORD PTR [BP+a]
613 name&h EQU WORD PTR [BP+a+2]
614 else
615 a = ?aframe
616 ?aframe = ?aframe + length
617 name EQU BYTE PTR [BP+a]
618 endif
619 endif
620 endif
621endm
622
623BREAK <errnz - generate compilation errors>
624
625errnz macro x
626if x NE 0
627 %out ***** FATAL error: x <> 0
628foobar
629endif
630endm