forked from historicalsource/pinballfantasies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMACROS1.ASM
691 lines (620 loc) · 9.43 KB
/
MACROS1.ASM
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
689
690
691
;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
;º º
;º The SpacePigs' standard set of macros (1) º
;º º
;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
FALSE EQU 0 ;MUST BE 0!
TRUE EQU 255 ;MUST BE 255!
imul_256 macro
cwd
mov dl,ah
mov ah,al
xor al,al
endm
;************************** STANDARD MAKROS ********************************
PLOPP MACRO REG
POP REG
PUSH REG
ENDM
DATAMOV MACRO DE,SO,LE
PUSH DI SI CX ES
PUSH OFFSET DE
PUSH OFFSET SO
PUSH LE
POP CX
POP SI
POP DI
PUSH DS
POP ES
REP MOVSB
POP ES CX SI DI
ENDM
MOVAL MACRO DE,SO
MOV AL,SO
MOV DE,AL
ENDM
JCXNZ MACRO LABAN
LOCAL NOLABAN
JCXZ NOLABAN
JMP LABAN
NOLABAN:ENDM
NIL MACRO NOLLA
XOR NOLLA,NOLLA
ENDM
MOVE MACRO DEST,SOURCE
PUSH SOURCE
POP DEST
ENDM
MOVA MACRO DEST,SOURCE
MOV AX,SOURCE
MOV DEST,AX
ENDM
ADDA MACRO DEST,SOURCE
MOV AX,SOURCE
ADD DEST,AX
ENDM
ADDAL MACRO DEST,SOURCE
MOV AL,SOURCE
ADD DEST,AL
ENDM
CALLE MACRO PROSEDUR ;CALL IF EQUAL
LOCAL NEHE
JNE NEHE
CALL PROSEDUR
NEHE: ENDM
CALLC MACRO PROSEDUR ;CALL IF CARRY
LOCAL NEHE
JNC NEHE
CALL PROSEDUR
NEHE: ENDM
SET_ES MACRO SEGADR
PUSH SEGADR
POP ES
ENDM
SET_DS MACRO SEGADR
PUSH SEGADR
POP DS
ENDM
PABS MACRO REGI
LOCAL NOTNEG
OR REGI,REGI
JG NOTNEG
NEG REGI
NOTNEG: ENDM
NABS MACRO REGI
LOCAL NOTPOS
OR REGI,REGI
JL NOTPOS
NEG REGI
NOTPOS: ENDM
;************************ MINNES-HANTERANDE MACROS *************************
ALLOCMEM MACRO SIZE ;ALLOCATES THE SPECIFIED NUMBER OF BYTES
PUSH BX ;RETURNS SEG-OFFSET IN AX
MOV BX,SIZE
SHR BX,4
INC BX
MOV AH,48H
INT 21H
POP BX
ENDM
ALLOCMEGAMEM MACRO SIZE ;ALLOCERAR ETT VISST ANTAL PARAGRAFER
;RETURNS SEG ADR IN AX.
PUSH BX
MOV BX,SIZE
MOV AH,48H
INT 21H
POP BX
ENDM
ALLOCMEGAMEM2 MACRO SIZE ;ALLOCERAR ETT VISST ANTAL PARAGRAFER
;RETURNS SEG ADR IN AX.
;RETURNS NO OF BYTES AVAILABLE IF -C- IN BX.
MOV BX,SIZE
MOV AH,48H
INT 21H
ENDM
SETBLOCK MACRO BLOCK,SIZE
PUSH BX
PUSH ES
MOV BX,SIZE
MOV AX,BLOCK
MOV ES,AX
MOV AH,4AH
SHR BX,4
INC BX
INT 21H
POP ES
POP BX
ENDM
DISALLOC MACRO BLOCK
local nullblock
PUSH AX
mov ax,block
cmp ax,0
pop ax
jz nullblock
push ax
PUSH ES
PUSH BLOCK
POP ES
MOV AH,49H
INT 21H
POP ES
POP AX
nullblock:
ENDM
FIRSTFIT MACRO
MOV AX,5801H
XOR BX,BX
INT 21H
ENDM
BESTFIT MACRO
MOV AX,5801H
MOV BX,1
INT 21H
ENDM
LASTFIT MACRO
MOV AX,5801H
MOV BX,2
INT 21H
ENDM
PRINTMESS2 MACRO MESSAGE
PUSHA
MOV DX,OFFSET MESSAGE
MOV AX,900H
INT 21H
POPA
ENDM
PRINTMESS MACRO MESSAGE
LOCAL MESS,GNU
JMP SHORT GNU
MESS DB MESSAGE,'$'
GNU: PUSHA
PUSH DS
MOV AX,CS
MOV DS,AX
MOV DX,OFFSET CS:MESS
MOV AX,900H
INT 21H
POP DS
POPA
ENDM
ERRORBLIP MACRO
LOCAL CONT65
PUSHA
SETMARG 2
MOV CX,4
CONT65: PUSH CX
MOV CX,0FFFFH
LOOP $
POP CX
LOOP CONT65
SETMARG 16
POPA
ENDM
CARRYBLIP MACRO
LOCAL NOTC
JNC NOTC
ERRORBLIP
NOTC:
ENDM
WAITKEY MACRO
PUSHA
XOR AH,AH
INT 16H
POPA
ENDM
WAITOR MACRO WAITS
LOCAL WAITA
PUSH CX
MOV CX,WAITS
WAITA: LOOP WAITA
POP CX
ENDM
MEGAWAIT MACRO WAITS
LOCAL WAITA
PUSH CX
MOV CX,WAITS
WAITA: WAITOR 0
LOOP WAITA
POP CX
ENDM
SYNCWAIT MACRO WAITS
LOCAL WAITA
PUSHA
MOV CX,WAITS
WAITA: SYNC
LOOP WAITA
POPA
ENDM
BEEP MACRO
PUSHF
PUSHA
MOV AH,14
MOV AL,7
INT 10H
POPA
POPF
ENDM
BLIP MACRO
LOCAL CONT
PUSHF
PUSHA
SETMARG 4H
MOV CX,4
CONT: SYNC
LOOP CONT
SETMARG 0H
POPA
POPF
ENDM
;*************************** DISK DRIVE MAKROS *****************************
SLACKDRIVELED MACRO
MOV DX,3F2H
MOV AL,0
OUT DX,AL
ENDM
WRITEFILE MACRO HANDLE,BYTES,SOURCE
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,HANDLE
MOV CX,BYTES
MOV DX,OFFSET SOURCE
MOV AH,40H
INT 21H
POP DX
POP CX
POP BX
POP AX
ENDM
WRITEFILE2 MACRO HANDLE,BYTES,SOURCE
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,HANDLE
MOV CX,BYTES
MOV DX,SOURCE
MOV AH,40H
INT 21H
POP DX
POP CX
POP BX
POP AX
ENDM
OPENFILE MACRO FILENAME ;FILENAME IN DS:FILNAME
PUSH AX ;RETURNS HANDLE IN BX
PUSH DX
MOV DX,OFFSET FILENAME
MOV AX,3D02H
INT 21H
MOV BX,AX
POP DX
POP AX
ENDM
OPENFILE2 MACRO FILENAME ;USE THIS WHEN A REGISTER POINTS TO FILENAME
PUSH AX ;RETURNS HANDLE IN BX
PUSH DX
MOV DX,FILENAME
MOV AX,3D02H
INT 21H
MOV BX,AX
POP DX
POP AX
ENDM
FILEPOINT MACRO HANDLE,HIGH,LOW
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV BX,HANDLE
MOV CX,HIGH
MOV DX,LOW
MOV AX,4200H
INT 21H
POP DX
POP CX
POP BX
POP AX
ENDM
READFILE MACRO HANDLE,BYTES,DEST
PUSH ES
PUSHA
MOV BX,HANDLE
MOV CX,BYTES
MOV DX,OFFSET DEST
MOV AX,3F00H
INT 21H
MOV ES,AX
POPA
MOV AX,ES
POP ES
ENDM
READFILE2 MACRO HANDLE,BYTES,DEST
PUSH ES
PUSHA
MOV BX,HANDLE
MOV CX,BYTES
MOV DX,DEST
MOV AX,3F00H
INT 21H
MOV ES,AX
POPA
MOV AX,ES
POP ES
ENDM
GETFILESIZE MACRO HANDLE ;RETURNS SIZE IN AX
PUSH BX
PUSH CX
MOV BX,HANDLE
MOV AX,4202H
XOR CX,CX
XOR DX,DX
INT 21H
PUSH AX
XOR DX,DX
MOV AX,4200H
INT 21H
POP AX
POP CX
POP BX
ENDM
GETMEGAFILESIZE MACRO HANDLE ;RETURNS SIZE IN DX,AX
PUSH BX
PUSH CX
MOV BX,HANDLE
MOV AX,4202H
XOR CX,CX
XOR DX,DX
INT 21H
PUSH AX
PUSH DX
XOR DX,DX
MOV AX,4200H
INT 21H
POP DX
POP AX
POP CX
POP BX
ENDM
CREATEFILE MACRO FILENAME ;RETURNS HANDLE IN BX
PUSH AX
PUSH CX
PUSH DX
MOV AH,3CH
MOV CX,0000H ;CH=0, CL=FILE ATTRIBUTE BYTE
MOV DX,OFFSET FILENAME
INT 21H
MOV BX,AX
POP DX
POP CX
POP AX
ENDM
CREATEFILE2 MACRO FILENAME
PUSH CX
PUSH DX
MOV AH,3CH
MOV CX,0000H ;CH=0, CL=FILE ATTRIBUTE BYTE
MOV DX,FILENAME
INT 21H
POP DX
POP CX
ENDM
CLOSEFILE MACRO HANDLE
PUSH AX
PUSH BX
MOV BX,HANDLE
MOV AX,3E00H
INT 21H
POP BX
POP AX
ENDM
DELETEFILE MACRO FILENAME
PUSH AX
MOV DX,OFFSET FILENAME
MOV AH,41H
INT 21H
POP AX
ENDM
DELETEFILE2 MACRO FILENAME
PUSH AX
MOV DX,FILENAME
MOV AH,41H
INT 21H
POP AX
ENDM
SETDRIVE MACRO DRIVE
PUSH AX
CLC
MOV DL,DRIVE
MOV AH,0EH
INT 21H
POP AX
ENDM
GETDRIVE MACRO
MOV AH,19H
INT 21H
ENDM
GETDIR MACRO DRIVE,BUF
LOCAL ZEROGNU,YSED,ZFI
PUSH DX
PUSH SI
PUSH OFFSET BUF
MOV DL,DRIVE
POP SI
MOV AH,47H
INT 21H
JC YSED
JMP YSED
MOV SI,OFFSET BUF-2
MOV CX,65
ZEROGNU:INC SI
CMP BYTE PTR DS:[SI],0
LOOPNE ZEROGNU
JCXZ YSED
ZFI: INC SI
MOV BYTE PTR DS:[SI],0
LOOP ZFI
YSED: POP SI
POP DX
ENDM
CD MACRO DIR
PUSH AX
PUSH DX
MOV AH,3BH
MOV DX,OFFSET DIR
INT 21H
POP DX
POP AX
ENDM
CD2 MACRO DIR
PUSH AX
PUSH DX
MOV AH,3BH
MOV DX,DIR
INT 21H
POP DX
POP AX
ENDM
;*************************** GRAFIK MAKROS *********************************
MCGAB_OFF MACRO
MOV DX,3C4H
MOV AL,4
MOV AH,0EH
OUT DX,AX
COMMENT\
MOV DX,3D4H ;DOUBLE WORD MODE
MOV AL,14H
OUT DX,AL
INC DX
IN AL,DX
OR AL,01000000B
OUT DX,AL
\
ENDM
MCGAB_ON MACRO
MOV DX,3C4H
MOV AL,4
MOV AH,06H
OUT DX,AX
MOV DX,3D4H ;COUNT BY FOUR AND NO DOUBLE WORD MODE
COMMENT\
MOV AL,14H
OUT DX,AL
INC DX
IN AL,DX
AND AL,10111111B
OUT DX,AL
MOV DX,3D4H ;MODE CONTROL (STANDARD ADRESSING MODE)
MOV AL,17H
MOV AH,11100011B
OUT DX,AX
;\
ENDM
SETMARG MACRO COLOR
PUSH DX AX
MOV AL,CS:MARG
MOV CS:OLDMARG,AL
; pushf
; cli
MOV DX,3DAH
IN AL,DX
rept 3
jmp $+2
endm
MOV DL,0C0H
MOV AL,11H+20H
OUT DX,AL
rept 3
jmp $+2
endm
MOV AL,COLOR
MOV CS:MARG,AL
OUT DX,AL
; popf
POP AX DX
ENDM
RESTOREMARG MACRO
PUSHA
MOV CL,CS:OLDMARG
SETMARG CL
POPA
ENDM
VIDEOMODE MACRO VM
PUSH AX
MOV AH,0
MOV AL,VM
INT 10H
POP AX
ENDM
SYNC MACRO
LOCAL SYNC1,SYNC2
push es
mov dx,40h
mov es,dx
mov dx,es:[63h]
add dl,6
pop es
sync1: IN AL,DX
TEST AL,8
JNZ SYNC1
SYNC2: IN AL,DX
TEST AL,8
JZ SYNC2
ENDM
SETWRITE MACRO MASK
MOV DX,3C4H ;FIXA KANAL
MOV AH,MASK
MOV AL,2 ;TILL BITPLANS-
OUT DX,AX ;MASKEN
ENDM
SETREAD MACRO PLN
MOV DX,3CEH
MOV AH,PLN
MOV AL,4
OUT DX,AX
ENDM
SETMCGAB MACRO MEMORY_LINELEN,LINELEN_IN_SIGHT
MOV AX,12H
INT 10H
MOV AX,13H
INT 10H
MOV BX,MEMORY_LINELEN ;CALC BX (SET LINE LENGTH)
SHR BX,3
MOV CX,LINELEN_IN_SIGHT ;CALC CX (HORIZ END)
SHR CX,2
DEC CX
MOV DX,3D4H ;SET HORIZ END
MOV AL,01H
MOV AH,CL ;(DET MAN VILL HA GENOM 4)
OUT DX,AX
MOV DX,3D4H ;SET LINE LENGTH (I MINNESUPPBYGGNADEN)
MOV AL,13H
MOV AH,BL
OUT DX,AX
MOV DX,3C4H ;SET MCGAB (NO CHAIN FOUR, USE 256KB)
MOV AL,04H
OUT DX,AL
INC DX
IN AL,DX
AND AL,11110110B
OUT DX,AL
MOV DX,3D4H ;COUNT BY FOUR AND NO DOUBLE WORD MODE
MOV AL,14H
OUT DX,AL
INC DX
IN AL,DX
AND AL,11111111B ;10111111B ;10011111B SVARAR MOT KOMMENTAREN
OUT DX,AL
MOV DX,3D4H ;MODE CONTROL (STANDARD ADRESSING MODE)
MOV AL,17H
MOV AH,11100011B
OUT DX,AX
ENDM
;****************************** VRIGA MACROS *********************************
SETMASK MACRO MASK ;INTERRUPT MASKEN!
MOV AL,MASK
OUT 21H,AL
ENDM