-
Notifications
You must be signed in to change notification settings - Fork 1
/
QDEFINES.INC
505 lines (459 loc) · 10.9 KB
/
QDEFINES.INC
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
; Copyright 2016 Jerome Shidel
; Released Under GPL v2.0 License.
; QCrt 9.0 Nasm Defines, Constants and Macros File
; User Configuration Defines
; %idefine Target8086 ; Uncomment to target original PC XT.
; %idefine BiosVideoOnly ; Uncomment to remove Direct Video Support
; %idefine DirectVideoOnly ; Uncomment to remove BIOS Video Support
; %idefine SaveAllRegs ; Uncomment to preserve all but return
; registers in procedure and function calls
; %idefine TurboPascal55 ; Only for TP 5.5 Objs, not for TP 7.0 or
; anything else!!
; %idefine DoubleFonts ; Not yet implemented
; %idefine EnableMouse ; Enable Mouse Support
; %idefine DisableMouse ; Disable Mouse Support (default)
; Now for all the self configuring stuff.
%idefine QDefines
%ifndef TargetOS
%idefine TargetOS DOS
%endif
%ifndef TargetCPU
%idefine TargetCPU 286
%endif
%ifidni TargetCPU, 8086
use16
%endif
%ifidni TargetCPU, 186
use16
%endif
%ifidni TargetCPU, 286
use16
%endif
%ifdef TP55
%idefine TurboPascal55
%endif
%ifdef TP70
%idefine TurboPascal70
%endif
%ifdef TurboPascal70
%undef TurboPascal55
%undef TP55
%endif
%ifndef EnableMouse
%idefine DisableMouse
%endif
%ifdef EnableMouse
%warning "Mouse support is enabled."
%endif
; Configuring One's Self A Little Bit
%ifidni __OUTPUT_FORMAT__, obj
%idefine FarCalls
%else
%undef TP55
%undef TurboPascal55
%undef TP70
%undef TurboPascal70
%warning "Binary COM file creation mode."
%ifdef SaveAllRegs
%warning "All none return value registers are preserved."
%else
%warning "Only the DS, SS, SP and BP registers are preserved!"
%endif
; This really should not be in the defines file. But, oh well
; we will just stick it in here anyway.
%idefine ASMTools
jmp SkipOverQCrt
%endif
%ifidn TargetCPU, 8086
cpu 8086
%warning Attempting to generate 8086 compatible code.
%endif
%ifdef FarCalls
%idefine XCALL CALL FAR
%idefine STACKBP BP + 6
%else
%idefine XCALL CALL
%idefine STACKBP BP + 4
%endif
%idefine DVSupport
%idefine BVSupport
%ifdef DirectVideoOnly
%undef BVSupport
%endif
%ifdef BiosVideoOnly
%undef DVSupport
%endif
%ifdef TurboPascal55
%warning Forcing Turbo Pascal version 5.5 compatibility.
%define Section_DATA DATA
%define Section_SHARED BSS
%define Section_CODE CODE
%else
%define Section_DATA _DATA
%define Section_SHARED _BSS
%define Section_CODE _TEXT
%endif
%ifdef ASMTools
%idefine CRLF 0x0d,0x0a
%endif
; Constants
%idefine FALSE 00h
%idefine TRUE 01h
; Macros
%imacro MemByte 2
push es
push bx
mov bx, %1
mov es, bx
mov bx, %2
mov al, [ES:BX]
pop bx
pop es
%endmacro
%imacro MemWord 2
push es
push bx
mov bx, %1
mov es, bx
mov bx, %2
mov ax, [ES:BX]
pop bx
pop es
%endmacro
%imacro pushy 1-*
%rep %0
%ifidni %1, f
pushf
%else
push %1
%endif
%rotate 1
%endrep
%endmacro
%imacro poppy 1-*
%rep %0
%ifidni %1, f
popf
%else
pop %1
%endif
%rotate 1
%endrep
%endmacro
%imacro pushcall 1-*
%if %0 > 1
%rep %0 - 1
%rotate 1
push word %1
%endrep
%rotate 1
%endif
xcall %1
%endmacro
%imacro ReturnsNothing 0
%ifdef SaveAllRegs
%define export_arg none
pushf
pushy ax, dx, bx, cx, si, di, es
%endif
%endmacro
%imacro ReturnsAX 0
%ifdef SaveAllRegs
%define export_arg word
pushy dx, bx, cx, si, di, es
%endif
%endmacro
%imacro ReturnsDXAX 0
%ifdef SaveAllRegs
%define export_arg dword
pushy bx, cx, si, di, es
%endif
%endmacro
%imacro RestoreRegisters 0
%ifdef SaveAllRegs
poppy es, di, si, cx, bx
%ifidn export_arg, dword
; nothing to do here, move along
%elifidn export_arg, word
pop dx
%elifidn export_arg, none
poppy dx, ax
popf
%endif
%endif
%endmacro
%imacro xfunction 2-*
global %1
%1:
%define export_name %1
%if %0 = 3
%define ret_pop %3
%else
%define ret_pop 0
%endif
; %stacksize large ; not using %arg
push bp
mov bp, sp
; %ifdef FARCALLS ; This would be needed if %arg worked
; add bp, 2 ; inside macros, but it does not so
; %endif ; we don't need it.
%ifidni %2, word
ReturnsAX
%elifidni %2, byte
ReturnsAX
%elifidni %2, boolean
ReturnsAX
%elifidni %2, char
ReturnsAX
%elifidni %2, integer
ReturnsAX
%elifidni %2, dword
ReturnsDXAX
%elifidni %2, long
ReturnsDXAX
%elifidni %2, longint
ReturnsDXAX
%elifidni %2, pointer
ReturnsDXAX
%else
ReturnsNothing
%endif
%endmacro
%imacro xprocedure 1-* 0
global %1
%1:
%define export_name %1
%if %0 = 2
%define ret_pop %2
%else
%define ret_pop 0
%endif
; %stacksize large ; not using %arg
push bp
mov bp, sp
; %ifdef FARCALLS ; This would be needed if %arg worked
; add bp, 2 ; inside macros, but it does not so
; %endif ; we don't need it.
ReturnsNothing
%endmacro
%imacro xret 0-1
%ifdef FarCalls
%idefine xret_type RETF
%else
%idefine xret_type RET
%endif
RestoreRegisters
pop bp
%if %0 = 1
%warning OVERRIDE export_name: ret %1
xret_type %1
%elif ret_pop = 0
xret_type
%else
xret_type ret_pop
%endif
%undef xret_type
%undef ret_pop
%undef export_name
%undef export_arg
%endmacro
; es:si is origin; cx is bytes per line, ax, bx, dx destroyed
%imacro xCalcScreenPtr 0
; cx bytes per line
mov cx, [ScreenMax]
xor ch, ch
inc cl
shl cx, 1
; true XY coordinate
mov dx, [WindMin]
mov bx, [CurrentXY]
add bl, dl ; origin X is BL
add dh, bh ; origin Y is DH
xor bh, bh ; clear BH, now BX is X
shl bx, 1 ; times 2 Char/Attr
xor ah, ah ; make AX, Y
mov al, dh
mul cx ; Times Bytes per row
add bx, ax ; add X offset
les si, [VideoPtr]
%endmacro
%imacro Terminate 0-1 0
xcall DoneCrt
MOV AH, 4Ch
MOV AL, %1
INT 21h
%endmacro
%imacro CommandLineParser 1
cld
xor bx, bx
mov di, si
xor dh, dh
%%Loop:
lodsb
cmp al, 0x0d
je %%Next
cmp al, 0x22
je %%Quote
cmp al, 0x27
je %%Quote
cmp al, 0x60
je %%Quote
cmp al, 0x20
je %%Next
cmp al, "/"
je %%Switch
jmp %%Loop
%%Quote:
mov ah, al
%%QuoteLoop:
inc dh
lodsb
cmp al, 0x0d
je %%Error
cmp al, ah
jne %%QuoteLoop
jmp %%Loop
%%Next:
mov cx, si
sub cx, di
cmp cx, 1
push cx
jle %%Skip
cmp al, 0x0d
jne %%NotEnd
dec si
dec cx
%%NotEnd:
push si
cmp al, 0x20
jne %%NotSpace
dec si
dec cx
%%NotSpace:
cmp bx, 0
jne %%NotDefault
mov bx, [%1 + 2]
xor dl, dl
%%NotDefault:
push ax
cmp dh, 0
je %%NotQuoted
inc di
dec si
sub cx, 2
%%NotQuoted:
call bx
xor dh, dh
pop ax
xor bx, bx
pop si
%%Skip:
pop cx
cmp al, 0x0d
je %%Done
cmp al, 0x20
jne %%ResetBX
cmp cx, 1
push cx
jle %%KeepBX
%%ResetBX:
xor bx, bx
%%KeepBX:
mov di, si
jmp %%Loop
%%Switch:
mov di, si
lodsb
cmp al, SwitchChar
jl %%Error
cmp al, 0x61
jl %%CaseOK
cmp al, 0x7a
jg %%CaseOK
sub al, 0x20
%%CaseOK:
mov bx, %1
%%Lookup:
add bx, 4
mov cx, [bx]
cmp cl, 0
je %%Error
cmp cl, al
jne %%Lookup
mov dx, [bx + 2]
mov bx, dx
cmp ch, 0
jne %%NeedsParam
xor cx, cx
push si
mov dl, al
call bx
xor dh, dh
xor bx,bx
pop si
mov di, si
jmp %%Loop
%%NeedsParam:
xor dh, dh
mov dl, al
mov di, si
jmp %%Loop
%%ErrorMsg:
DB "Error parsing command-line options.",CRLF,0
%%Error:
WriteStr %%ErrorMsg
Terminate 1
%%Done:
cmp bx, 0
jne %%Error
%endmacro
; macro that shows command line switch and data, mostly for debuging the
; command line parser
%imacro CommandLineDebug 0
push cx
push dx
mov al, ' '
WriteChar
pop dx
cmp dl, 0
je %%NoSwitch
push dx
mov al, SwitchChar
WriteChar
pop dx
mov al, dl
WriteChar
pop cx
push cx
cmp cx, 0
jne %%NoSwitch
pop cx
ret
%%NoSwitch:
mov al, '('
WriteChar
pop cx
cmp cx, 0
je %%NoText
%%Repeat:
push cx
mov al, [di]
WriteChar
pop cx
inc di
loop %%Repeat
%%NoText:
mov al, ')'
WriteChar
ret
%endmacro
%ifidni __OUTPUT_FORMAT__, bin
%imacro PrefixSeg 1
push cs
pop %1
%endmacro
%imacro DataSeg 1
push cs
pop %1
%endmacro
%endif