1 ; SCCSID = @(#)dosmac.asm 1.1 85/04/10
2 ; SCCSID = @(#)dosmac.asm 1.1 85/04/10
4 ; Macro file for MSDOS.
10 SUBTTL BREAK a listing into pages and give new subtitles
18 BREAK <ASMVAR - handle assembly variables once and for all>
32 BREAK <I_NEED: declare a variable external, if necessary, and allocate a size>
35 ; declare a variable external and allocate a size
40 DATA SEGMENT WORD PUBLIC 'DATA'
56 ; call a procedure that may be external. The call will be short.
72 ; jump to a label that may be external. The jump will be near.
87 ; get a short address in a word
98 DW OFFSET DOSGROUP:name
106 ; get a long address in a dword
121 ; declare a PROC near or far but PUBLIC nonetheless
128 ?aframe = 0 ; initial
129 ?stackdepth = 0 ; initial stack size
130 ?initstack = 0 ; initial stack size
132 procedure MACRO name,distance
134 ?aframe = 2 ;; remember the pushed BP
143 ?initstack = ?stackdepth ;; beginning of procedure
148 ; end a procedure and check that stack depth is preserved
150 EndProc MACRO name, chk
151 IFDIF <chk>,<NoCheck> ;; check the stack size
153 IF ?initstack NE ?stackdepth ;; is it different?
154 %OUT ***** Possible stack size error in name *****
163 ; define a data item to be public and of an appropriate size/type
166 I_AM MACRO name,size,init
167 ;; declare the object public
169 ;; declare the type of the object
191 ;; if no initialize then allocate blank storage
193 DB I_AM_SIZE*I_AM_LEN DUP (?)
202 I_AM_SIZE = I_AM_SIZE - 1
205 %out ***** initialization of name not complete *****
208 DB I_AM_SIZE*I_AM_LEN DUP (?)
221 ; define an entry in a procedure
229 BREAK <ERROR - store an error code then jump to a label>
239 BREAK <JUMP - real jump that links up shortwise>
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>
249 ifndef lbl&_J ;; is this the first invocation
252 IF (lbl&_J GE $) OR ($-lbl&_J GT 126)
253 a: JMP lbl ;; is the jump too far away?
255 a: JMP lbl&_J ;; do the short one...
263 BREAK <RETURN - return from a function>
275 BREAK <CONDRET - conditional return>
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:
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:
301 ret_&cc = ret_l ;; define ret_<CC> to be ret_l
305 BREAK <RETZ - return if zero, links up shortwise if necessary>
312 BREAK <RETNZ - return if not zero, links up shortwise if necessary>
319 BREAK <RETC - return if carry set, links up shortwise if necessary>
326 BREAK <RETNC - return if not carry, links up shortwise if necessary>
333 BREAK <CONTEXT - set the DOS context to a particular register>
342 BREAK <SaveReg - save a set of registers>
344 SaveReg MACRO reglist ;; push those registers
346 ?stackdepth = ?stackdepth + 1
352 BREAK <RestoreReg - unsave some registers>
354 RestoreReg MACRO reglist ;; pop those registers
356 ?stackdepth = ?stackdepth - 1
362 BREAK <Critical section macros>
364 EnterCrit MACRO section
368 LeaveCrit MACRO section
372 Break <message - display a message>
374 AsmVars <ShareF,Cargs,Redirector>
377 fmt MACRO typ,lev,fmts,args
389 If (not sharef) and (not redirector)
393 MOV AX,OFFSET DOSGROUP:a
398 b: mov ax,offset share:a
400 b: mov ax,offset netwrk:a
426 Break <DOSAssume - validate assumes>
431 DOSAssume Macro reg,reglist,message
439 %out ***** Invalid DOS register reg in DOSAssume *****
449 %out ***** Invalid register reg in DOSAssume *****
459 MOV AX,OFFSET DOSGroup:a
478 DOSAssume Macro reg,reglist,message
485 BREAK <ASSERT - make assertions about registers>
488 Assert MACRO kind, objs, message
509 MOV AX,OFFSET DOSGroup:b
539 Break <CallInstall - hook to installable pieces>
541 CallInstall MACRO name,mpx,fn,save,restore
546 MOV AX,(mpx SHL 8) + fn
556 Break <Stack frame manipulators>
558 localvar macro name,length
560 ifidn <length>,<BYTE>
563 name EQU BYTE PTR [BP-a]
565 ifidn <length>,<WORD>
568 name EQU WORD PTR [BP-a]
570 ifidn <length>,<DWORD>
573 name EQU DWORD PTR [BP-a]
574 name&l EQU WORD PTR [BP-a]
575 name&h EQU WORD PTR [BP-a+2]
577 ?frame = ?frame + length
579 name EQU BYTE PTR [BP-a]
596 Argvar macro name,length
598 ifidn <length>,<BYTE>
600 ?aframe = ?aframe + 1
601 name EQU BYTE PTR [BP+a]
603 ifidn <length>,<WORD>
605 ?aframe = ?aframe + 2
606 name EQU WORD PTR [BP+a]
608 ifidn <length>,<DWORD>
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]
616 ?aframe = ?aframe + length
617 name EQU BYTE PTR [BP+a]
623 BREAK <errnz - generate compilation errors>
627 %out ***** FATAL error: x <> 0