-
Notifications
You must be signed in to change notification settings - Fork 8
/
PROLOGUE.MAC
300 lines (261 loc) · 5.38 KB
/
PROLOGUE.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
;; A header macro file that defines a lot of common useful macros when
;; programming in assembly. Supports conditional assembly for taking
;; advantage of 80286 opcodes.
IS286 equ 0 ;; True if taking advantage of 80286 opcodes.
Macro SETUPSEGMENT
SEGMENT _TEXT PARA PUBLIC 'CODE'
ASSUME CS:_TEXT
Endm
Struc SEG_OFF
POFF dw ?
PSEG dw ?
Ends
UNION FARPTR
DPTR dd ?
XPTR SEG_OFF <>
ENDS
macro ShiftR REG,TIMES
;; 2 - shift a register right a number of times.
IF IS286
shr REG,TIMES
ELSE
REPT TIMES
shr REG,1
ENDM
ENDIF
endm
macro ShiftL REG,TIMES
;; 3 - shift a register left a number of times
IF IS286
shl REG,TIMES
ELSE
REPT TIMES
shl REG,1
ENDM
ENDIF
endm
macro LSMUL
;; 4 - performs a long signed multiply AX,DX * BX,CX
LOCAL @@HOP1,@@HOP2
;; Long signed multiply
;; Long #1: AX,DX
;; Long #2: BX,CX
push si
xchg si,ax
xchg dx,ax
or ax,ax
jz @@HOP1
mul bx
@@HOP1: xchg cx,ax
or ax,ax
jz @@HOP2
mul si
add cx,ax
@@HOP2: xchg si,ax
mul bx
add dx,cx
pop si
endm
macro LongShiftL TIMES
;; 5 - Shift left AX,DX times.
REPT TIMES
shl ax,1
rcl dx,1
ENDM
endm
macro LongShiftR TIMES
;; 6 - Shifr right AX,DX times
REPT TIMES
sar dx,1
rcr ax,1
ENDM
endm
macro ShiftAL REG,TIMES
;; 7 - shift arithmetic left register, times
IF IS286
sal REG,TIMES
ELSE
REPT TIMES
sal REG,1
ENDM
ENDIF
endm
macro ShiftAR REG,TIMES
;; 8 - Shifr arithmatic right register, times
IF IS286
sar REG,TIMES
ELSE
REPT TIMES
sar REG,1
ENDM
ENDIF
endm
macro PushI VALUE
;; 9 - Push an immediat onto the stack.
;; Push Immediate
IF IS286
push VALUE
ELSE
mov ax,VALUE
push ax
ENDIF
endm
macro PushEA DATA
;; 10 - Push an effective address onto the stack.
;; Push Effective address
IF IS286
push offset DATA
ELSE
mov ax,offset DATA
push ax
ENDIF
endm
macro PushFar DATA
;; 11 - Push far address (relative to DS) onto the stack.
push ds ; push the segment
PushEA DATA ; push the offset
endm
macro PushAll
;; 12 - Push ALL registers onto the stack.
;; Save all registers
IF IS286
pusha ;; if a 286 machine use the pusha opcode
push ds ;; save segment DS
push es ;; save segment ES
ELSE
push ax ;; if not 286 machine use normal method
push bx
push cx
push dx
push si
push di
push bp
push ds
push es
ENDIF
endm
macro PopAll
;; 13 - Pop all registers off of the stack.
;;; Restore all registers from a push all
IF IS286
pop es
pop ds
popa
ELSE
pop es
pop ds
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ENDIF
endm
macro DOSTerminate
;; 14 - Terminate back to DOS
mov ah,4Ch
int 21h
endm
macro DosTSR LOC
;; 15 - Terminate and stay resident back to DOS
lea dx,[LOC+100h] ; (End of program plus PSP)
int 27h ; Terminate and stay resident.
endm
macro Message data
;; 16 - Print a '$' terminated string to the console
push ax
mov ah,9 ; Function 9 write string
lea dx,[data] ; Get the address of the message
int 21h ; Send the message to the screen.
pop ax
endm
macro PENTER STORAGE
;; 17 - Enter a procedue with storage space
;; Procedure enter, uses the 286/386 ENTER opcode
IF IS286
enter STORAGE,0 ; nexting level, always zero.
ELSE
push bp
mov bp,sp
IF STORAGE
sub sp,STORAGE
ENDIF
ENDIF
endm
macro PLEAVE
;; 18 - Exit a procedure with stack correction.
IF IS286
leave
ELSE
mov sp,bp
pop bp
ENDIF
endm
macro PushCREGS
;; 19 - Save registers for C
push es
push ds ;The Kernel is responsible for maintaining DS
push si
push di
cld
endm
macro PopCREGS
;; 20 - Restore registers for C
pop di
pop si
pop ds ;The Kernel is responsible for maintaining DS
pop es
endm
;; Macro used to insert breakpoints in code to invoke the debugger. Using
;; the macro allows for easier searches to be done on debug invokations.
Macro DoDebug
int 3
endm
Macro SwapSegs
push es
push ds
pop es
pop ds
endm
Macro CALLF procedure
;; This macro fakes a far call to a procedure which is near and dear to
;; us but defined as far. This is done to avoid fixups and so that
;; kernel objects are COMable. It is used when a kernel service, which
;; is defined as a far procedure, needs to be called locally.
push cs
call near ptr procedure
endm
Macro NibbleOut
LOCAL @@OK
push ax
and ax,0Fh
add ax,'0'
cmp ax,'9'
jle @@OK
sub ax,'9'+1
add ax,'A'
@@OK: mov [es:di],al
sub di,2
pop ax
shr ax,4 ; down one nibble
endm
Macro HEXPRINT reg,xloc,yloc
push es
push di
push ax
mov ax,reg
push ax
mov ax,0b800h
mov es,ax
mov di,yloc*160+xloc*2+4*2
pop ax
NibbleOut
NibbleOut
NibbleOut
NibbleOut
pop ax
pop di
pop es
endm