forked from jratcliff63367/digpak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PROLOGUE.MAC
297 lines (264 loc) · 5.46 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
;; 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.
;IF IS286
;.286
;ENDIF
SETUPSEGMENT macro
SEGMENT _TEXT PARA PUBLIC 'CODE'
ASSUME CS:_TEXT
Endm
SEG_OFF Struc
POFF dw ?
PSEG dw ?
SEG_OFF Ends
FARPTR UNION
DPTR dd ?
XPTR SEG_OFF <>
FARPTR ENDS
ShiftR macro REG,XTIMES
;; 2 - shift a register right a number of times.
IF IS286
shr REG,XTIMES
ELSE
REPT XTIMES
shr REG,1
ENDM
ENDIF
endm
ShiftL macro REG,XTIMES
;; 3 - shift a register left a number of times
IF IS286
shl REG,XTIMES
ELSE
REPT XTIMES
shl REG,1
ENDM
ENDIF
endm
LSMUL macro
;; 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
LongShiftL macro XTIMES
;; 5 - Shift left AX,DX times.
REPT XTIMES
shl ax,1
rcl dx,1
ENDM
endm
LongShiftR macro XTIMES
;; 6 - Shifr right AX,DX times
REPT XTIMES
sar dx,1
rcr ax,1
ENDM
endm
ShiftAL macro REG,XTIMES
;; 7 - shift arithmetic left register, times
IF IS286
sal REG,XTIMES
ELSE
REPT XTIMES
sal REG,1
ENDM
ENDIF
endm
ShiftAR macro REG,XTIMES
;; 8 - Shifr arithmatic right register, times
IF IS286
sar REG,XTIMES
ELSE
REPT XTIMES
sar REG,1
ENDM
ENDIF
endm
PushI macro VALUE
;; 9 - Push an immediat onto the stack.
;; Push Immediate
IF IS286
push VALUE
ELSE
mov ax,VALUE
push ax
ENDIF
endm
PushEA macro MYDATA
;; 10 - Push an effective address onto the stack.
;; Push Effective address
IF IS286
push offset MYDATA
ELSE
mov ax,offset MYDATA
push ax
ENDIF
endm
PushFar macro MYDATA
;; 11 - Push far address (relative to DS) onto the stack.
push ds ; push the segment
PushEA MYDATA ; push the offset
endm
PushAll macro
;; 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
PopAll macro
;; 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
DOSTerminate macro
;; 14 - Terminate back to DOS
mov ah,4Ch
int 21h
endm
DosTSR macro LOC
;; 15 - Terminate and stay resident back to DOS
xlea dx,<LOC+100h> ; (End of program plus PSP)
int 27h ; Terminate and stay resident.
endm
Message macro mydata
;; 16 - Print a '$' terminated string to the console
push ax
mov ah,9 ; Function 9 write string
xlea dx,mydata ; Get the address of the message
int 21h ; Send the message to the screen.
pop ax
endm
PENTER macro 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
PLEAVE macro
;; 18 - Exit a procedure with stack correction.
IF IS286
leave
ELSE
mov sp,bp
pop bp
ENDIF
endm
PushCREGS macro
;; 19 - Save registers for C
push es
push ds ;The Kernel is responsible for maintaining DS
push si
push di
cld
endm
PopCREGS macro
;; 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.
DoDebug macro
int 3
endm
SwapSegs macro
push es
push ds
pop es
pop ds
endm
CALLF macro 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
NibbleOut macro
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
ShiftR ax,4 ; shr ax,4 ; down one nibble
endm
HEXPRINT macro 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