-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMACROS.MAC
executable file
·688 lines (599 loc) · 14.2 KB
/
MACROS.MAC
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
page ,132
;-----------------------------Module-Header-----------------------------;
; Module Name: MACROS.MAC
;
; This file contains macros definitions for all display drivers to use.
;
; Created: 06-Jan-1987
; Author: **** ***** [*****]
;
; Copyright (c) 1987 Microsoft Corporation
;
; Exported Functions: none
;
; Public Functions: none
;
; Public Data: none
;
; General Description:
;
; Two text equates are given as short hand for WORD PTR
; and BYTE PTR.
;
; A Macro is defined for performing 16-bit output on machines
; which cannot correctly do so.
;
; The macro which is invoked by CMACROS for private stack
; checking is defined.
;
; Restrictions:
; The use of the ?CHKSTKPROC macro requires it to be defined
; before CMACROS is included. If CMACROS is included before
; the include file, a ?CHKSTKPROC macro should be defined
; with a null macro body. This macro will then redefine the
; earlier macro.
;
; The out16 macro is intended as documentation for anyone
; converting a driver to a machine which cannot do 16-bit
; outputs correctly. There is no guarantee that any code
; will have been tested (only one machine is known to have
; the problem).
;
;-----------------------------------------------------------------------;
; The following two equates are just used as shorthand
; for the "word ptr" and "byte ptr" overrides.
wptr equ word ptr
bptr equ byte ptr
;---------------------------------Macro---------------------------------;
; out16
;
; out16 is a macro used wherever any 16-bit output is performed.
; The macro is intended to serve as documentation for those machines
; which do not perform 16-bit outputs correctly (where correctly is
; defined as the way the IBM AT does it).
;
; usage
;
; out16 d,a
;
; where
;
; d - I/O address register. Included as documentation
; only. Must always be DX (lower case).
;
; a - Register to output. Included as documentation
; only. Must always be AX (lower case).
;
; Entry:
; AX = data to output
; DX = I/O port address
; Returns:
; none
; Error Returns:
; none
; Registers Destroyed:
; FLAGS
; Registers Preserved:
; AX,BX,CX,DX,SI,DI,BP,DS,ES
; Calls:
; none
; History:
; Fri 16-Jan-1987 16:49:03 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
ifndef IO8 ;;If normal 16 bit outputs
out16 equ out
else ;;If 8-bit outputs
out16 macro d,a
ifdif <a>,<ax>
%out out16 - invalid register, must be ax
.err
endif
ifdif <d>,<dx>
%out out16 - invalid register, must be dx
.err
endif
ifdif <is>,<cli> ;; If interrupts not off
cli ;; then turn them off
endif ;;
out dx,al ;; Output LSB portion
inc dx ;; --> next address
xchg al,ah ;; Get MSB of output value
out dx,al ;; Output MSB portion
ifdif <ie>,<cli> ;; If not explicitly told to leave
sti ;; interrupts off, turn them on
endif ;;
ifdif <rd>,<dont_save_DL> ;; If not explicitly told to trash DX,
dec dx ;; restore it.
xchg al,ah
endif
endm
endif
;---------------------------------Macro---------------------------------;
; ?CHKSTKPROC
;
; Private Stack Checking Macro
;
; ?CHKSTKPROC will be invoked by the CMACROS for any procedure
; with local variables if both ?CHKSTK and ?CHKSTKPROC were
; defined prior to including the CMACROS.
;
; The macro has one parameter, which is the number of bytes
; to allocate, which is supplied by the CMACROS.
;
; The usage of this macro is defined by the CMACROS. There is no
; user control over the macro. Register usage will be as defined
; by the routine my_check_stack.
;
; Calls:
; my_check_stack
; History:
; Fri 16-Jan-1987 16:49:03 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
ifdef ?CHKSTK ;;Only define macro if
ifdef ?CHKSTKPROC ;; private stack checking
ifndef ?CHKSTKNAME ;;If user name differs from default
extrn my_check_stack:near ;;Procedure to do the checking
endif
?CHKSTKPROC macro s ;;Actual macro text
mov ax,s ;;my_check_stack takes requested space
ifdef ?CHKSTKNAME
?CHKSTKNAME
else
call my_check_stack ;; in AX
endif
endm
endif
endif
;-----------------------------------------------------------------------;
; odd --- macro for odd alignment, counterpart for masm's "even".
;
; Arguments:
; none
; Returns:
; nothing
; Alters:
; nothing
; Calls:
; nothing
; History:
;
; Sun Mar 01, 1987 07:48:01p -by- ****** *. ***** [*******]
; Wrote it!
;-----------------------------------------------------------------------;
odd macro
ife (offset $) AND 1
nop
endif
endm
;-----------------------------------------------------------------------;
; pushem
; popem
;
; Allows giving a list of registers to push/pop on a single line.
; Also allows easy verificaton that pushes and pops are balanced
; because arguements are given in the same order:
;
; pushem ax,bx,cx goes with
; popem ax,bx,cx
;
; Arguments:
; registers to push/pop
; Returns:
; nothing
; Alters:
; nothing
; Calls:
; nothing
; History:
;
; Mon Mar 09, 1987 06:12:32p -by- ****** *. ***** [*******]
; Wrote it!
;-----------------------------------------------------------------------;
pushem macro r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF,r10,r11,r12
irp x,<r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF,r10,r11,r12>
ifnb <x>
push x
endif
endm
endm
popem macro r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF,r10,r11,r12
irp x,<r12,r11,r10,rF,rE,rD,rC,rB,rA,r9,r8,r7,r6,r5,r4,r3,r2,r1>
ifnb <x>
pop x
endif
endm
endm
;-----------------------------------------------------------------------;
; smov
;
; smove moves the contents of one segment register into another
; segment register.
;
; usage
;
; smov x,y
;
; where
;
; x is the destination register
; y is the source register
;
; Arguments:
; y is source segment register
; Returns:
; x segment register = y segment register
; Alters:
; x segment register
; Calls:
; nothing
; History:
;
; Mon Mar 09, 1987 06:12:32p -by- ****** *. ***** [*******]
; Wrote it!
;-----------------------------------------------------------------------;
smov macro x,y
push y
pop x
endm
;--------------------------------------------------------------------------;
; abs_ax
; takes absolute value of AX
; Entry:
; AX = integer
; Returns:
; AX = abs(AX)
; Error Returns:
; none
; Registers Destroyed:
; DX,FLAGS
; Registers Preserved:
; BX,CX,SI,DI,DS,ES,BP
; Calls:
; none
; History:
; Thu Mar 05, 1987 06:15:46p -by- **** ******** [*****]
; wrote it
;--------------------------------------------------------------------------;
abs_ax macro
cwd
xor ax,dx
sub ax,dx
endm
;--------------------------------------------------------------------------;
; min_ax
; returns min of AX and REG
; Entry:
; AX = integer
; REG = general purpose register containing an integer
; Returns:
; AX = min(AX,REG)
; Error Returns:
; none
; Registers Destroyed:
; DX,FLAGS
; Registers Preserved:
; BX,CX,SI,DI,DS,ES,BP
; Calls:
; none
; History:
; Sat Mar 07, 1987 08:39:04p -by- **** ******** [*****]
; wrote it
;--------------------------------------------------------------------------;
min_ax macro REG
sub ax,REG
cwd
and ax,dx
add ax,REG
endm
;--------------------------------------------------------------------------;
; max_ax
; returns max of AX and REG
; Entry:
; AX = integer
; REG = general purpose register containing an integer
; Returns:
; AX = max(AX, REG)
; Error Returns:
; none
; Registers Destroyed:
; DX,FLAGS
; Registers Preserved:
; BX,CX,SI,DI,DS,ES,BP
; Calls:
; none
; History:
; Sat Mar 07, 1987 08:41:38p -by- **** ******** [*****]
; wrote it
;--------------------------------------------------------------------------;
max_ax macro REG
sub ax,REG
cwd
not dx
and ax,dx
add ax,REG
endm
; The following equates are used for defining the target
; processor to the shift macros.
GENERIC equ 0
CPU equ GENERIC
;CPU equ 88
;CPU equ 86
;CPU equ 186
;CPU equ 286
;CPU equ 386
;--------------------------------------------------------------------------;
; shiftl
;
; shiftl is used to implement the advanced shift left immediate
; (SHL dest,count) functionality of the 286 and 386.
;
; Entry:
; DEST = var to shift
; COUNT = number to shift by
; Returns:
; DEST = DEST shl COUNT
; Error Returns:
; none
; Registers Destroyed:
; none
; Registers Preserved:
; all
; Calls:
; none
; History:
; Sat Mar 07, 1987 08:44:30p -by- **** ******** [*****]
; wrote it
;--------------------------------------------------------------------------;
shiftl macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
shl DEST,COUNT
else
REPT COUNT
shl DEST,1
ENDM
endif
endm
;--------------------------------------------------------------------------;
; shiftr
;
; shiftr is used to implement the advanced shift right immediate
; (SHR dest,count) functionality of the 286 and 386.
;
; Entry:
; DEST = var to shift
; COUNT = number to shift by
; Returns:
; DEST = DEST shr COUNT
; Error Returns:
; none
; Registers Destroyed:
; none
; Registers Preserved:
; all
; Calls:
; none
; History:
; Sat Mar 07, 1987 08:44:52p -by- **** ******** [*****]
; wrote it
;--------------------------------------------------------------------------;
shiftr macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
shr DEST,COUNT
else
REPT COUNT
shr DEST,1
ENDM
endif
endm
;--------------------------------------------------------------------------;
; rotcr, rotcl
; rotr, rotl
;
; Use just like you would rcr (or rcl, rol, ror) immediate in 286 specific
; code. If the processor does not support the immediate count (>1 on 808[68])
; then the macro generates multiple rcr (...) by one statements.
;
; Entry:
; DEST = var to rotate
; COUNT = number to rotate by
; Returns:
; DEST = DEST shr COUNT
; Error Returns:
; none
; Registers Destroyed:
; none
; Registers Preserved:
; all
; Calls:
; none
; History:
;
; Fri Apr 17, 1987 08:39:39p -by- ****** *. ***** [*******]
; added rotl and rotr
;
; Sun Apr 12, 1987 07:34:37p -by- ****** *. ***** [*******]
; wrote it
;--------------------------------------------------------------------------;
rotcr macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
rcr DEST,COUNT
else
REPT COUNT
rcr DEST,1
ENDM
endif
endm
rotcl macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
rcl DEST,COUNT
else
REPT COUNT
rcl DEST,1
ENDM
endif
endm
rotl macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
rol DEST,COUNT
else
REPT COUNT
rol DEST,1
ENDM
endif
endm
rotr macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
ror DEST,COUNT
else
REPT COUNT
ror DEST,1
ENDM
endif
endm
;--------------------------------------------------------------------------;
; ashiftr
;
; ashiftr is used to implement the advanced shift arithmetic right immediate
; (SAR dest,count) functionality of the 286 and 386.
;
; Entry:
; DEST = var to shift
; COUNT = number to shift by
; Returns:
; DEST = DEST sar COUNT
; Error Returns:
; none
; Registers Destroyed:
; none
; Registers Preserved:
; all
; Calls:
; none
; History:
; Sat Mar 07, 1987 08:45:06p -by- **** ******** [*****]
; wrote it
;--------------------------------------------------------------------------;
ashiftr macro DEST,COUNT
if (CPU eq 286) or (CPU eq 386)
sar DEST,COUNT
else
REPT COUNT
sar DEST,1
ENDM
endif
endm
;---------------------------------Macro---------------------------------;
; jmpnext
; jmpnext stop
;
; jmpnext is used in the generation of fall through chains. It
; generates the opcode used to swallow the next two bytes of object
; code (cmp ax,immediate word), and performs error checking to
; ensure that only two bytes of object code exist between any
; use of jmpnext.
;
; The chain is terminated by use of an optional parameter to jmpnext.
; If this optional field is non-blank, the chain is terminated.
;
; usage
;
; dog:
; mov al,34
; jmpnext
;
; foo:
; mov al,0
; jmpnext
;
; bar:
; mov al,1
; jmpnext stop ;End of the chain
;
; Entry:
; none
; Returns:
; none
; Error Returns:
; none
; Registers Destroyed:
; FLAGS
; Registers Preserved:
; AX,BX,CX,DX,SI,DI,BP,DS,ES
; Calls:
; none
; History:
; Fri 13-Mar-1987 12:03:16 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
??ji = 0 ;;Initial index value
jmpnext macro e
jn %??ji,%(??ji+1),e ;;Set next label
endm
jn macro i,j,e
.sall
??ji&i:
.xall
ifb <e> ;;If not the end of the chain
db 03Dh ;;cmp ax, next two bytes
errn$ ??ji&j,+2 ;;next lable must be two bytes away
endif
??ji=j ;;increment counter
endm
;---------------------------------Macro---------------------------------;
; missing_code
;
; missing_code is a macro which will display a message on the screen
; at assembly time. It is used to flag code sequences which have not
; been completed.
;
; usage
;
; missing_code <text>
;
; Entry:
; none
; Returns:
; none
; Error Returns:
; none
; Registers Destroyed:
; none
; Registers Preserved:
; ALL
; Calls:
; none
; History:
; Sun 22-Mar-1987 18:21:34 -by- **** ***** [*****]
; Initial version
;-----------------------------------------------------------------------;
missing_code macro x
if1
??_out <&! Missing Code &! x>
endif
endm
;---------------------------Macro---------------------------------------;
; LMHtoP
;
; Converts a Local Memory Handle to a local pointer.
;
; Entry:
; reg1[,reg2]
; Returns:
; reg1 = pointer
; Error Returns:
;
; Registers Destroyed:
; none
; History:
; Mon Mar 23, 1987 06:54:26a -by- Charles Whitmer [chuckwh]
; Imported from GDI.
;-----------------------------------------------------------------------;
LMHtoP macro r1,r2 ;; Local Movable Handle to pointer
ifnb <r2>
mov r1,[r2]
else
mov r1,[r1]
endif
endm