-
Notifications
You must be signed in to change notification settings - Fork 0
/
exegrab.asm
2201 lines (1855 loc) · 49.2 KB
/
exegrab.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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
;
; +------------------------+
; | BC/FRIENDS'95 PRESENTS |
; |------------------------|
; | ASM Sources of EXEGRAB |
; | TSR Grafix Image Saver |
; |------------------------|
; |- Pogramming example of |
; |- VCPI/RM PIC mapping |
; |- RM IDT redirection |
; |- Turbo Switch detection|
; |- 386 Debug Regs usage |
; |- "ideal" mode ASM |
; +------------------------+
;
;
;
; Graphic Screen Grabber for MS-DOS
; Copyright (C) 1995 Friends Software
; Written by Max Masyutin (Maxim Masiutin)
;
;
; To get the author, mail a message to Max Masyutin (2:469/84@fidonet)
;
; P.S Sorry for the shortage of comments
;
segment CODE use16
assume cs:CODE,ds:CODE
org 100h
; --================[ EQU AREA ]================--
lSEND equ 'SEND'
lGRAB equ 'GRAB'
mHIRQ equ 0
mMouse equ 1
mNMI equ 2
mDR equ 3
mIDT equ 4
mTurbo equ 5
mError equ 255
Num8 equ 12h
Num16 equ 1234h
Num32 equ 12345678h
FirstMS equ 4 ; First Screen Mode Supported
LastMS equ 13h ; Last Screen Mode Supported
PalSize equ 768
Pal16Size equ 96
Pal16Para equ 6
SC equ 3C4h ; Sequence Controller Index
GC equ 3CEh ; Graphics Controller Index
CRTC equ 3D4h ; CRT Controller Index
CRTC_lo equ 0D4h ; CRT Controller Index (Lo port addr)
MISC equ 3C2h ; Miscellaneous Output Register
MISC_INP_lo equ 0CCh ; Miscellaneous Input Register (Lo)
PEL_WRITE equ 3C8h ; PEL Address Write Register
PEL_READ equ 3C7h ; PEL Address Read Mode
PEL_DATA equ 3C9h ; PEL Data Register
PEL_DATA_lo equ 0C9h ; PEL Data Register (Lo port addr)
IRQ8NormPhase equ 150
IRQ8TestPhase equ 5
; --================[ MACRO AREA ]================--
macro a16
align 16
endm
macro Imd16 Var
org $-2
Var dw Num16
endm
macro Imd32 Var
org $-4
Var dd Num32
endm
macro OutPal rCX,rSI
local L
mov dx,PEL_WRITE
mov al,0
out dx,al
mov cx,rCX
inc dx
mov si,rSI
L: outsb
loop L
endm
macro OutPalI rCX
local L
mov dx,PEL_WRITE
mov al,0
out dx,al
mov cx,rCX
inc dx
L: outsb
loop L
endm
macro DrwBeg VideoMode
mov ax,VideoMode
int 10h
push cs
pop ds
push 0A000h
pop es
xor di,di
cld
endm
macro DrwEnd
mov ah,0
int 16h
mov ax,3
int 10h
mov ax,4C00h
int 21h
endm
macro CopyPan Pan
mov cx,bx
mov al,Pan
out dx,al
rep movsd
endm
macro Copy4P
CopyPan 1
xor di,di
CopyPan 2
xor di,di
CopyPan 4
xor di,di
CopyPan 8
endm
macro OutPal16 PB
local L
WaitRetrace
mov cx,17*2+1
mov dl,0C0h
mov si,PB
L: outsb
loop L
OutPalI 17*3
endm
macro WaitRetrace
local L3,L4
mov dx,3DAh
L3:in al,dx
test al,8
jne L3
L4:in al,dx
test al,8
je L4
endm
macro PushV V
mov bx,V*4
push [dword ptr fs:bx]
push bx
endm
macro PopV
pop bx
pop [dword ptr fs:bx]
endm
macro ClrIRQ8
mov al,0Ch
out 70h,al
in al,71h
mov al,20h
out 0A0h,al
out 020h,al
endm
macro InitIRQ8
mov al,0Ch
out 70h,al
in al,71h
mov al,0Bh
out 70h,al
in al,71h
or al,40h
mov ah,al
mov al,0Bh
out 70h,al
mov al,ah
out 71h,al
in al,0A1h
and al,0FEh
out 0A1h,al
endm
macro ClearIRQ8
mov al,0Bh
out 70h,al
in al,71h
and al,0BFh
mov ah,al
mov al,0Bh
out 70h,al
mov al,ah
out 71h,al
mov al,0Ch
out 70h,al
in al,71h
in al,0A1h
or al,1
out 0A1h,al
endm
Start:
; --================[ PALETTE AREA ]================--
jmp Begin
org 300h ; End of palette area
; --================[ INTERNAL SATCK ]================--
db lSEND
org 4FEh ; 200h bytes stack
OldSS dw ?
; --================[ EXE HEADER ]================--
EXEHdr db 'MZ'
ehLastPg dw 0 ; length of partial page at end
ehPageCnt dw ? ; length of image in 512-byte pages, including the header
dw 0 ; number of items in relocation table
dw 2 ; size of header in 16-byte paragraphs
dw 30h ; minimum memory needed above end of program (paragraphs)
dw -1 ; maximum memory needed above end of program (paragraphs)
ehReloSS dw ? ; segment offset of stack segment (for setting SS)
dw 200h ; value for SP register (stack pointer) when started
dw 0 ; file checksum (negative sum of all words in file)
dw 0 ; value for IP register (instruction pointer) when started
dw 0 ; segment offset of code segment (for setting CS)
dw 0 ; file-offset of first relocation item
dw 0 ; overlay number (0 for base module)
db lGRAB
; --================[ DWORD DATA AREA ]================--
OldF1h dd ?
Old01a dd ?
Old02a dd ?
Old33a dd ?
Old70a dd ?
Timer1024 dd ?
LastTurboTest dd ?
; --================[ WORD DATA AREA ]================--
VModes dw VM04,VM05,VM06,VMNS
dw VMNS,VMNS,VMNS,VMNS,VMNS,VM0D,VM0E,VM0F
dw VM10,VM11,VM12,VM13
; --================[ BYTE DATA AREA ]================--
Nums16 db 0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,11h,16,20h
VideoMode db ?
Grabbing db 0
Int21Active db 0
Grab21 db 0
IRQ1Only db ?
Method db ?
IRQ8Left db ?
IRQ8Testing db 0
; --================[ STRINGS DATA AREA ]================--
FName db 'GRAB_'
CutNoHi db '0'
CutNoLo db '0'
db '.EXE',0
; --================[ SCREEN DRAWERS ]================--
CGA_S = CGA_E-CGA_B
CGA_B:
mov ax,Num16
org $-2
CGA_Mode db ?
db 0
int 10h
push cs
pop ds
push 0B800h
pop es
xor di,di
cld
mov si,CGA_S
mov cx,7D0h
rep movsd
mov di,2000h
mov cx,7D0h
rep movsd
DrwEnd
a16
CGA_E:
M0D_S = M0D_E-M0D_B
M0D_B:
DrwBeg 0Dh
OutPal16 M0D_S
mov ax,0102h
mov bx,07D0h
mov dx,3C4h
mov si,Pal16Size+M0D_S
rept 3
out dx,ax
mov cx,bx
rep movsd
shl ah,1
xor di,di
endm
out dx,ax
mov cx,bx
rep movsd
DrwEnd
a16
M0D_E:
M10_S = M10_E-M10_B
M10_B:
DrwBeg 10h
OutPal16 M10_S
mov ax,0102h
mov bx,640*350/16
mov dx,3C4h
mov bp,cs
add bp,Pal16Para+M10_S/16
mov ds,bp
rept 3
xor si,si
out dx,ax
mov cx,bx
rep movsd
shl ah,1
xor di,di
add bp,640*350/(8*16)
mov ds,bp
endm
xor si,si
out dx,ax
mov cx,bx
rep movsd
DrwEnd
a16
M10_E:
M12_S = M12_E-M12_B
M12_B:
DrwBeg 12h
OutPal16 M12_S
mov ax,0102h
mov bx,640*480/16
mov dx,3C4h
mov bp,cs
add bp,Pal16Para+M12_S/16
mov ds,bp
rept 3
xor si,si
out dx,ax
mov cx,bx
rep movsd
shl ah,1
xor di,di
add bp,640*480/(8*16)
mov ds,bp
endm
xor si,si
out dx,ax
mov cx,bx
rep movsd
DrwEnd
a16
M12_E:
M13_S = M13_E-M13_B
M13_B:
DrwBeg 13h
OutPal PalSize,M13_S
mov si,M13_S+PalSize
mov cx,3E80h
rep movsd
DrwEnd
a16
M13_E:
MX32x20_S=MX32x20_E-MX32x20_B
MX32x20_B:
DrwBeg 13h
mov dx,SC
mov ax,0604h
out dx,ax
mov dx,CRTC
mov ax,14h
out dx,ax
mov ax,0E317h
out dx,ax
OutPal PalSize,MX32x20_S
mov si,MX32x20_S+PalSize
mov bx,0FA0h
mov dx,SC
mov al,2
out dx,al
inc dx
Copy4P
DrwEnd
a16
MX32x20_E:
MX32x40_S=MX32x40_E-MX32x40_B
MX32x40_B:
DrwBeg 13h
mov dx,SC
mov ax,0604h
out dx,ax
mov dx,CRTC
mov ax,4009h
out dx,ax
mov ax,14h
out dx,ax
mov ax,0E317h
out dx,ax
OutPal PalSize,MX32x40_S
mov bx,320*400/4
mov dx,SC
mov al,2
out dx,al
inc dx
mov bp,cs
add bp,(MX32x40_S+PalSize)/16
mov ds,bp
xor si,si
CopyPan 1
Count = 2
rept 3
xor si,si
xor di,di
add bp,320*400/(4*16)
mov ds,bp
CopyPan Count
Count = Count shl 1
endm
DrwEnd
a16
MX32x40_E:
MX32x24_S=MX32x24_E-MX32x24_B
MX32x24_B:
DrwBeg 13h
mov dx,3D4h
mov ax,11h
out dx,ax
mov dx,3C4h
mov al,4
out dx,al
inc dx
in al,dx
and al,0F6h
out dx,al
mov dx,3D4h
mov al,14h
out dx,al
inc dx
in al,dx
and al,0BFh
out dx,al
mov dx,3D4h
mov ax,0E317h
out dx,ax
mov dx,3CCh
in al,dx
mov dx,3C2h
or al,0C0h
out dx,al
mov dx,3D4h
mov al,11
out dx,al
inc dx
in al,dx
and al,7Fh
out dx,al
dec dx
mov si,MX32x24set-MX32X24_B ; point to CRT parameter table
mov cx,10 ; # of table entries
rep outsw
OutPal PalSize,MX32x24_S
mov bx,360*240/4
mov dx,SC
mov al,2
out dx,al
inc dx
mov bp,cs
add bp,(MX32x24_S+PalSize)/16
mov ds,bp
xor si,si
CopyPan 1
Count = 2
rept 3
xor si,si
xor di,di
add bp,320*240/(4*16)
mov ds,bp
CopyPan Count
Count = Count shl 1
endm
DrwEnd
MX32x24set dw 00D06h ; Vertical total
dw 03E07h ; Overflow (bit 8 of vertical counts)
dw 0C009h ; Cell height (2 to double-scan)
dw 0EA10h ; V sync start
dw 00C11h ; V sync end and protect cr0-cr7
dw 0DF12h ; Vertical displayed
dw 00014h ; Turn off dword mode
dw 0EA15h ; V blank start
dw 00616h ; V blank end
dw 0E317h ; Turn on byte mode
a16
MX32x24_E:
MX32x48_S=MX32x48_E-MX32x48_B
MX32x48_B:
DrwBeg 13h
mov dx,3D4h
mov ax,11h
out dx,ax
mov dx,3C4h
mov al,4
out dx,al
inc dx
in al,dx
and al,0F6h
out dx,al
mov dx,3D4h
mov al,14h
out dx,al
inc dx
in al,dx
and al,0BFh
out dx,al
mov dx,3D4h
mov ax,0E317h
out dx,ax
mov dx,3CCh
in al,dx
mov dx,3C2h
or al,0C0h
out dx,al
mov dx,3D4h
mov al,11
out dx,al
inc dx
in al,dx
and al,7Fh
out dx,al
dec dx
mov si,MX32x48set-MX32x48_B ; point to CRT parameter table
mov cx,10 ; # of table entries
rep outsw
OutPal PalSize,MX32x48_S
mov bx,320*480/4
mov dx,SC
mov al,2
out dx,al
inc dx
mov bp,cs
add bp,(MX32x48_S+PalSize)/16
mov ds,bp
xor si,si
CopyPan 1
Count = 2
rept 3
xor si,si
xor di,di
add bp,320*480/(4*16)
mov ds,bp
CopyPan Count
Count = Count shl 1
endm
DrwEnd
MX32x48set dw 00D06h ; Vertical total
dw 03E07h ; Overflow (bit 8 of vertical counts)
dw 00009h ; Cell height (2 to double-scan)
dw 0EA10h ; V sync start
dw 00C11h ; V sync end and protect cr0-cr7
dw 0DF12h ; Vertical displayed
dw 00014h ; Turn off dword mode
dw 0EA15h ; V blank start
dw 00616h ; V blank end
dw 0E317h ; Turn on byte mode
a16
MX32x48_E:
MX36x24_S=MX36x24_E-MX36x24_B
MX36x24_B:
DrwBeg 13h
mov dx,SC
mov ax,0604h
out dx,ax
mov ax,0100h
out dx,ax
mov dx,MISC
mov al,0e7h
out dx,al
mov dx,SC
mov ax,0300h
out dx,ax
mov dx,GC
mov ax,4005h
out dx,ax
mov ax,0506h
out dx,ax
mov dx,CRTC
mov si,MX36x24set-MX36X24_B
mov cx,18
rep outsw
OutPal PalSize,MX36x24_S
mov bx,360*240/4
mov dx,SC
mov al,2
out dx,al
inc dx
mov bp,cs
add bp,(MX36x24_S+PalSize)/16
mov ds,bp
xor si,si
CopyPan 1
Count = 2
rept 3
xor si,si
xor di,di
add bp,360*240/(4*16)
mov ds,bp
CopyPan Count
Count = Count shl 1
endm
DrwEnd
MX36x24set dw 0C11h,6b00h,5901h,5a02h,8e03h,5e04h,8a05h,0D06h,3e07h
dw 4109h,0ea10h,08c11h,0df12h,2d13h,14h,0e715h,616h,0e317h
a16
MX36x24_E:
; --================[ INTERRUPT HANDLERS ]================--
Null24:
mov al,3
iret
Int10:
cmp ah,0
jz SVM
cmp ah,0Fh
jne Old10
cmp ebx,lGRAB
jne NotDet
push ax
mov ax,fs
cmp ax,bx
pop ax
jnz NotDet
push cs
pop es
mov eax,lSEND
iret
NotDet:
pushf
call [cs:Old10a]
mov [cs:VideoMode],al
iret
SVM:
mov [cs:VideoMode],al
Old10: db 0EAh
Old10a dd ?
Int21:
mov [cs:Int21Active],1
push [word ptr ss:esp+4]
popf
pushf
db 09Ah
Old21a dd ?
mov [cs:Int21Active],0
pushf
cmp [cs:Grab21],0
jz Not21Grb
cmp [cs:Grabbing],0
jnz GrbNAllowed
push ax
cli
call Grab
pop ax
GrbNAllowed:
mov [cs:Grab21],0
Not21Grb:
pop [word ptr ss:esp+4]
iret
IRQ1End:
in al,61h
or al,80h
out 61h,al
and al,7Fh
out 61h,al
mov al,20h
out 20h,al
ret
; --================[ GRABBER ]================--
Grab:
cmp [cs:Grabbing],0
jnz GrabNotAllowed
cmp [cs:Int21Active],0
jz GrabAllowed
mov [cs:Grab21],1
jmp GrabNotAllowed
GrabAllowed:
call IntrGrab
GrabNotAllowed:
ret
IntrGrab:
mov [cs:OldSS],ss
mov [cs:OldSP],sp
mov ax,cs
mov ss,ax
lea sp,[OldSS]
push ds es
mov ds,ax
mov es,ax
mov [Grabbing],1
movzx eax,[VideoMode]
cmp al,LastMS
ja VMNS
cmp al,FirstMS
jb VMNS
push fs
pushad
push 0
pop fs
PushV 13h
mov [dword ptr fs:bx],Num32
org $-4
Real13v dd ?
PushV 21h
mov [dword ptr fs:bx],Num32
org $-4
Real21v dd ?
PushV 24h
mov [dword ptr fs:bx],Num32
org $-4
dw Null24
CS24 dw ?
call [word ptr eax*2+VModes-2*FirstMS]
PopV
PopV
PopV
popad
pop fs
VMNS:
mov [Grabbing],0
pop es ds ss
mov sp,Num16
Imd16 OldSP
ret
; --================[ VIDEO MODES HANDLERS ]================--
VM04: mov [CGA_Mode],4
jmp CGA_Write
VM05: mov [CGA_Mode],5
jmp CGA_Write
VM06: mov [CGA_Mode],6
CGA_Write:
mov eax,32+CGA_S+320*200/4
lea bx,[CGA_B]
mov cx,CGA_S
call InitFile
mov ax,0B800h
mov cx,8000
call SegWrite
mov dx,2000h
call BlockWrite
call CloseFile
ret
VM0D:
mov dx,CRTC
call GetScrOfs
push ax
mov eax,32+M0D_S+320*200/2+Pal16Size
lea bx,[M0D_B]
mov cx,M0D_S
call InitFile
call Write16Pal
pop bx
mov cx,320*200/8
Count = 0
rept 4
mov dx,GC
mov ax,Count*256+4
Count=Count+1
out dx,ax
mov dx,bx
mov ax,0A000h
call BlockWrite
endm
call CloseFile
ret
VM0E: ret
VM0F: ret
VM10:
mov dx,CRTC
call GetScrOfs
push ax
mov eax,32+M10_S+640*350/2+Pal16Size
lea bx,[M10_B]
mov cx,M10_S
call InitFile
call Write16Pal
pop bx
mov cx,640*350/8
Count = 0
rept 4
mov dx,GC
mov ax,Count*256+4
Count=Count+1
out dx,ax
mov dx,bx
mov ax,0A000h
call BlockWrite
endm
call CloseFile
ret
VM11: ret
VM12:
mov dx,CRTC
call GetScrOfs
push ax
mov eax,32+M12_S+640*480/2+Pal16Size
lea bx,[M12_B]
mov cx,M12_S
call InitFile
call Write16Pal
pop bx
mov cx,640*480/8
Count = 0
rept 4
mov dx,GC
mov ax,Count*256+4
Count=Count+1
out dx,ax
mov dx,bx
mov ax,0A000h
call BlockWrite
endm
call CloseFile
ret
VM13:
mov dx,SC
mov al,4
out dx,al
inc dx
in al,dx
dec dx
and al,8
mov al,2
out dx,al
jnz Std13
mov dl,CRTC_lo
call GetScrOfs
push ax
dec dx
mov al,1
out dx,al
inc dx
in al,dx
mov bl,al
dec dx
mov al,9
out dx,al
inc dx
in al,dx
and al,9Fh
btr ax,7
adc al,0
mov bh,al
mov dl,MISC_INP_lo
in al,dx
or al,al
js MXxx24
; --===[ ???x200*? ]===--
cmp bl,4Fh
je MX32x20
; --===[ 360x200*? ]===--
pop bx
call UnknownMX
ret
; --===[ 320x200*? ]===--
MX32x20:
or bh,bh
jz MX32x40