-
Notifications
You must be signed in to change notification settings - Fork 0
/
DISKTOOL.PAS
executable file
·941 lines (890 loc) · 26.6 KB
/
DISKTOOL.PAS
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
Unit DiskTool;
(****************************************************************************
* Disk Toolkit Unit v1.03 *
****************************************************************************
* „®áâ㯠ç¥p¥§ INT 13h *
* Drive IDE features *
* ‚áâp®¥ë© Š˜ ( —’…Hˆ…) *
* *
* *«ì讥 ᯠᨡø: *
* þ ” à®®¢ã § ª¨£ã "à ªâ¨ª ¯à®£à ¬¬¨à®¢ ¨ï" ¨ § ¨á室¨ª¨ *
* þ Linux-ã & ¥£® ¨á室¨ª ¬ *
* þ A.R.G.-ã § ¨á室¨ª¨ Linux *
* þ FiDO § talks.asm, ru.hacker, netmail, etc. *
* þ NiGhthAWk-ã § FiDO, Internet, BBS & ¤à. *
* þ €«¥ªá¥î ‡ ©ª® (2:5045/66) § ¯®¨â , § HDD, etc. *
* þ ... *
* *
* ®¦¥« ¨ï 諨⥠: *
* FidoNet: 2:5045/66.45,Nikita Galaiko *
* E-Mail: [email protected] *
****************************************************************************
* Last Update: 30/06/2001 *
****************************************************************************
* (C) NiKe'Soft UnLtd. *
****************************************************************************)
{$A-,B-,D+,E+,F-,G+,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
INTERFACE
{$DEFINE UseIntCache}
Uses Hex;
const
MaxLongName = 255;
DosSectorSize = 512;
Boot_Signature = $AA55;
FSector_Signature = $41615252; {"RRaA"}
FSinfo_Signature = $61417272; {"rrAa"}
faReadOnly = $01;
faHidden = $02;
faSysFile = $04;
faVolumeID = $08;
faDirectory = $10;
faArchive = $20;
faAnyFile = $3F;
faNone = 0;
faUnused = faVolumeID or faArchive or faSysFile or faHidden;
faExt = faReadOnly or faHidden or faSysFile or faVolumeID;
BAD_MsDOS_chars : array[0..8] of char = ('*','+','?','<','>','|','"','/','\');
UnKnownFAT = 0;
FAT12 = 1;
FAT16 = 2;
FAT32 = 3;
NoError = 0;
DiskError : byte = NoError;
(*
00h BYTE 10h (size of packet)
01h BYTE reserved (0)
02h WORD number of blocks to transfer
04h DWORD -> transfer buffer
08h QWORD starting absolute block number
*)
type tTransferBlock = record
Size : word;
Blocks : word;
BufAdr : pointer;
BegLo : longint;
BegHi : longint; {0 if HDD < 1000 GB :)}
end;
type tInt13ExtInfo = record
majVer : byte;
extVer : byte;
Res : byte;
APB : word; {API subset support Bitmap}
end;
type tInt13ExtDriveInfo = record {Format of IBM/MS INT 13 Extensions drive parameters}
IOSize : word; {(call) size of buffer (001Ah for v1.x, 001Eh for v2.0)}
{(ret) size of returned data}
Flags : word; {information flags}
Cyls : longint; {number of cylinders on drive}
Heads : longint; {number of heads on drive}
Sect : longint; {number of sectors per track}
ToSLo : longint; {LO total number of sectors on drive}
ToSHi : longint; {HI total number of sectors on drive}
SecSize : word; {bytes per sector}
EnhInfo : pointer;
end;
tEnhDrvInfo = record {Format of Phoenix Enhanced Disk Drive Spec translated drive parameter table:}
Cyls : word;
Heads : byte;
Sign : byte; {A0h (signature indicating translated table)}
SWrPCyl : word; {starting write precompensation cylinder number}
res : byte;
CtrlBt : byte; {control byte (see #1857 at INT 41)}
PhysCyls : word; {number of physical cylinders}
PhysHeads : byte; {number of physical heads}
LandCyl : word; {cylinder number of landing zone}
LogSect : byte; {number of logical sectors per track}
CRC : byte; {checksum}
end;
Type
PathStr = string[79]; { DOS File pathname string }
DirStr = string[67]; { DOS Drive and directory string }
NameStr = string[8]; { DOS File name string }
ExtStr = string[4]; { DOS File extension string }
tLongName = string[MaxLongName];
Array512 = array[0..511] of char;
tDrvBiosInfo = record
MaxSector : byte;
MaxHead : byte;
MaxTrack : word;
SeHD : longint;
end;
tDirElement = record
case byte of
0:( Name : array[0..7] of char;
Ext : array[0..2] of char;
Attr : byte;
lCase : byte; {Char case of name & ext}
cTime_ms : byte; {Creation time, milliseconds}
cTime : word; {Creation time}
cDate : word; {Creation date}
aDate : word; {Last access date}
Clus_hi : word; {High 16 bits of cluster in FAT32}
Date : longint;
Cluster : word;
Size : longint);
1:( NameExt : array[0..10] of char);
end;
tLFNelement = record
ID : byte;
Name1 : array[0..4] of word;
attr : byte;
res1 : byte;
CRC : byte;
Name2 : array[0..5] of word;
cluster : word;
Name3 : array[0..1] of word;
end;
tFAT16Sec = array [0..255] of word;
tFAT32Sec = array [0..127] of longint;
pPartition = ^tPartition;
tPartition = record
BootF : Byte; {”« £ ªâ¨¢®áâ¨ à §¤¥« }
BegHd : Byte; {‘â®à® ç « à §¤¥« }
BegSC : Word; {‘¥ªâ®à/樫¨¤à ç « }
SysID : Byte; {Š®¤ á¨á⥬ë}
EndHd : Byte; {‘â®à® ª®æ à §¤¥« }
EndSC : Word; {‘¥ªâ®à/樫¨¤à ª®æ }
Secs : LongInt; {Žâ®á¨â¥«ìë© á¥ªâ®à ç « }
Size : LongInt {Ž¡ê¥¬ ¢ ᥪâ®à å}
end; {PartType}
pBoot16 = ^tBoot16;
tBoot16 = record
JmpOp : array[1..3] of byte; {Ž¡ëç®, "jmp short XXX; NOP"}
SysID : array[1..8] of char; {ID ®¯¥à 樮®© ‘¨á⥬ë}
SectSize : Word; {Š®«¨ç¥á⢮ ¡ ©â ¢ ᥪâ®à¥}
ClusSize : Byte; {Š®«¨ç¥á⢮ ᥪâ®à®¢ ¢ ª« áâ¥à¥}
ResSecs : Word; {Š®«¨ç¥á⢮ ᥪâ®à®¢ ¯¥à¥¤ FAT}
FatCnt : Byte; {Š®«¨ç¥á⢮ FAT}
RootSize : Word; {Š®«¨ç¥á⢮ í«¥¬¥â®¢ ª®à¥¢®£® ª â «®£ }
TotSec16 : Word; {Š®«¨ç¥á⢮ ᥪâ®à®¢ ¤¨áª¥}
Media : Byte; {„¥áªà¨¯â®à ®á¨â¥«ï}
FatSize : Word; { §¬¥à FAT12/16 ¢ ᥪâ®à å}
SpTrk : Word; {Š®«¨ç¥á⢮ ᥪâ®à®¢ ¤®à®¦ª¥ ¤«ï à §¤¥«®¢ <32 Œ¡ ©â ¨«¨ 0}
HeadCnt : Word; {Š®«¨ç¥á⢮ £®«®¢®ª}
HidnSecLo : Word; {Š®«¨ç¥á⢮ á¯àïâ ëå ᥪâ®à®¢ ¤«ï à §¤¥«®¢ ¬¥ìè¥ 32 Œ¡ ©â}
HidnSecHi : Word; {‚¬¥á⥠¢ HidnSecLo ¤ ¥â ª®«¨ç¥á⢮}
TotSec32 : LongInt; {Ž¡é¥¥ ª®«¨ç¥á⢮ ᥪâ®à®¢ ¤«ï à §¤¥«®¢ ¡®«ìè¥ 32 Œ¡ ©â}
DrvNum : byte; {®¬¥à 䨧¨ç¥áª®£® ¤¨áª }
res1 : byte; {???}
ExtBootSig : byte; { áè¨à¨ ï ᨣ âãà ¤¨áª }
SerialNum : longint; {‘¥à¨©ë© ®¬¥à}
DLabel : array[1..11] of char; {Œ¥âª ¤¨áª }
FatID : array[1..8] of char; {FAT ID}
BootPrg : array[1..384] of Byte; {Boot Program}
Part : array[1..4] of tPartition; { àâ¨è¨ë}
BootSign : word;
end;
pBoot32 = ^tBoot32;
tBoot32 = record
JmpOp : array[1..3] of byte; {Ž¡ëç®, "jmp short XXX; NOP"}
SysID : array[1..8] of char; {ID ®¯¥à 樮®© ‘¨á⥬ë}
SectSize : word; { §¬¥à ᥪâ®à ¢ ¡ ©â å}
ClusSize : byte; { §¬¥à ª« áâ¥à ¢ ᥪâ®à å}
ResSecs : word; {Š®«¨ç¥á⢮ ‡ १¥à¢¨à®¢ ëå ᥪâ®à®¢ ¯¥à¥¤ FAT}
FATcnt : byte; {Š®«¨ç¥á⢮ ª®¯¨© FAT}
RootSize : word; { §¬¥à ª®à¥£®£® ª â «®£ }
TotSec16 : word; {… ˆ‘Ž‹œ‡“…’‘Ÿ (Š®«¨ç¥á⢮ ᥪâ®à®¢ ¤«ï ¤¨áª <32MB)}
Media : byte; {„¨áªà¨¯â®à ®á¨â¥«ï}
FATsize : word; {‘¥ªâ®à®¢ ¢ FAT12/16}
SpTrk : word; {‘¥ªâ®à®¢ ¤®à®¦ª¥}
HeadCnt : word; {Š®«¨ç¥á⢮ ®¢¥àå®á⥩}
HidnSecLo : word; {Lo(‘¯àïâ ëå ᥪâ®à®¢)}
HidnSecHi : word; {Hi(‘¯àïâ ëå ᥪâ®à®¢)}
TotSec32 : longint; {‚ᥣ® ᥪâ®à®¢}
FAT32size : longint; {‘¥ªâ®à®¢ ¢ FAT32}
Flags : byte; {”« £¨ ¢á直¥ (...,ActiveFat,...)}
SysMajor : byte; {‘â à訩 ¡ ©â á¨á⥬ë}
SysMinor : word; {Œ« ¤è¨© ¡ ©â á¨á⥬ë}
RootClus : longint; {Š« áâ¥à ª®àï}
FSect : word; {Žâ®á¨â¥«ìë© á¥ªâ®à ¨ä®à¬ 樮®£® ᥪâ®à FS}
ResBootSec : word; {Žâ®á¨â¥«ìë© á¥ªâ®à १¥à¢®£® Boot-ᥪâ®à }
res1 : array[1..12] of byte; {???}
DrvNum : byte; {®¬¥à 䨧¨ç¥áª®£® ¤¨áª }
res2 : byte; {???}
ExtBootSig : byte; { áè¨à¨ ï ᨣ âãà ¤¨áª }
SerialNum : longint; {‘¥à¨©ë© ®¬¥à}
DLabel : array[1..11] of char; {Œ¥âª ¤¨áª }
FatID : array[1..8] of char; {FAT ID}
BootPrg : array[1..356] of byte; {Boot Program}
Part : array[1..4] of tPartition; { àâ¨è¨ë}
BootSign : word; { = 5DAAh - ᨣ âãà ®à¬ «ì®£® Boot-ᥪâ®à }
end;
tFSInfoSector = record
Sector_Sign : longint; {0x41615252}
res1 : array[0..481] of byte;
Signature : longint; {0x61417272}
Free_Clusters : longint; {Free cluster count. -1 if unknown}
Next_Free : longint; {Most recently allocated cluster}
res2 : array[0..13] of byte;
end;
type pBIOS_Drive = ^tBIOS_Drive;
tBIOS_Drive = record
Drive : byte;
MaxTrack : word;
MaxHead : word;
MaxSector : byte;
SEHD : word;
SecSiz : word;
DBI : tDrvBiosInfo;
ExtSup : boolean;
ExtInf : tInt13ExtDriveInfo;
{ EnhInf : tEnhDrvInfo;{}
end;
function GetDriveInfo(Drv : byte; var DrvInf : tBIOS_Drive) : byte;
function GetDrvBiosInfo(Drive : byte; var DrvBIOSInf : tDrvBIOSInfo) : boolean;
function Int13ExtIntalled(Drive : byte; var Info : tInt13ExtInfo) : byte;
function GetInt13ExtDriveInfo(Drive : byte; var DrvInfo : tInt13ExtDriveInfo; var EnhInfo) : byte;
procedure UnpackCylSec(CSec: Word; var Cyl : word; var Sec : byte);
function CalcFS(Drive : tBIOS_Drive; track : word; Head, Sector : byte) : longint;
procedure DeCalcFS(Drive : tBIOS_Drive; fs : longint; var track : word; var Head, Sector : byte);
function ErrToStr(Error: byte): string;
procedure Recalibrate(Drive : byte);
function CheckSectors(Drive : tBIOS_Drive; Track: word; Head, Sector, Num: byte): boolean;
function ReadSectors (Drive : tBIOS_Drive; Head: byte; CylSec: word; num : byte; var buf): boolean;
function WriteSectors(Drive : tBIOS_Drive; Head: byte; CylSec: word; num : byte; var buf): boolean;
function ReadDataS(Drive : tBIOS_Drive; Track: word; Head, Sector: Byte; num : byte; var iobuf): boolean;
function WriteDataS(Drive : tBIOS_Drive; Track: word; Head, Sector, num: Byte; var iobuf): boolean;
function Diskette_Changed(Drive : byte) : boolean;
function GetSysSt(sysID : byte) : string;
function DosChar(c : char) : boolean;
function WinChar(c : char) : boolean;
function Flush_Cache : integer;
function ReadAbsSector(drv : byte; s,n : longint; var bf) : boolean;
function WriteAbsSector(drv : byte; s,n : longint; var bf) : boolean;
{$IFDEF UseIntCache}
const Max_Cache_Pages = 128;
type pCache = ^tCache;
tCache = record
Drive : byte;
Data : array[0..DosSectorSize-1] of char;
Track : word;
Head : byte;
Sec : byte;
end;
var _Cache : array[1..Max_Cache_Pages] of pCache;
nCPages : integer;
CachePos : integer;
dap : tTransferBlock;
{$ENDIF}
IMPLEMENTATION
function ReadAbsSector(drv : byte; s,n : longint; var bf) : boolean;
var e : boolean;
begin
dap.size := sizeof(dap);
dap.blocks := 1;
dap.bufadr := @bf;
dap.beghi := 0;
dap.beglo := s-1;
asm
mov AX,4200h
mov DL,80h
lea SI,dap
int 13h
mov e,al
end;
ReadAbsSector := not e;
end;
function WriteAbsSector(drv : byte; s,n : longint; var bf) : boolean;
var e : boolean;
begin
dap.size := sizeof(dap);
dap.blocks := 1;
dap.bufadr := @bf;
dap.beghi := 0;
dap.beglo := s-1;
asm
mov AX,4300h
mov DL,80h
lea SI,dap
int 13h
mov e,al
end;
WriteAbsSector := not e;
end;
function GetDriveInfo(Drv : byte; var DrvInf : tBIOS_Drive) : byte;
var EnhInf : tEnhDrvInfo;
ei : tInt13ExtInfo;
begin
GetDriveInfo := 1; fillchar(DrvInf,sizeof(DrvInf),#0);
if GetDrvBiosInfo(Drv,DrvInf.DBI) then
begin
with DrvInf do
begin
Drive := Drv;
ExtSup := false;
GetDriveInfo := 0;
if Int13ExtIntalled(Drive,ei) = 0 then
begin
if GetInt13ExtDriveInfo(Drive,ExtInf,EnhInf) = 0 then
begin
if ExtInf.Cyls > 1 then
begin
MaxTrack := ExtInf.Cyls-1;
if ExtInf.Heads > 1 then
begin
MaxHead := ExtInf.Heads-1;
if ExtInf.Sect > 0 then MaxSector := ExtInf.Sect;
begin
if ExtInf.SecSize > 0 then
begin
SecSiz := ExtInf.SecSize;
ExtSup := true;
end;
end;
end;
end;
end;
end;
if not ExtSup then
begin
MaxTrack := DBI.MaxTrack;
MaxHead := DBI.MaxHead;
MaxSector := DBI.MaxSector;
SecSiz := DOSSECTORSIZE;
end;
SEHD := (MaxSector)*(MaxHead+1);
end;
end;
end;
(*
INT 13 - IBM/MS INT 13 Extensions - GET DRIVE PARAMETERS
AH = 48h
DL = drive (80h-FFh)
DS:SI -> buffer for drive parameters (see #0179)
Return: CF clear if successful
DS:SI buffer filled
CF set on error
AH = error code (see #0140)
*)
function GetInt13ExtDriveInfo(Drive : byte; var DrvInfo : tInt13ExtDriveInfo; var EnhInfo) : byte;
{assembler;}
var e : byte;
begin
DrvInfo.IOSize := sizeof(DrvInfo);
DrvInfo.EnhInfo := @EnhInfo;
asm
mov ah,48h
mov dl,Drive
lds si,DrvInfo
int 13h
mov e,0
jnc @NoError
mov e,ah
@NoError:
end;
GetInt13ExtDriveInfo := e;
end;
function Int13ExtIntalled(Drive : byte; var Info : tInt13ExtInfo) : byte;
var Inst,a,b,d : byte; c : word;
{assembler;}
begin
asm
mov ah,41h
mov bx,55AAh
mov dl,Drive
int 13h
jc @NotInstalled
mov a,ah
mov b,al
mov c,cx
mov d,dh
mov inst,1 {installed}
jmp @End
@NotInstalled:
mov inst,0 {not installed}
@End:
end;
if inst = 1 then
with Info do
begin
majVer := a;
extVer := d;
Res := b;
APB := c;
Int13ExtIntalled := 0;
end else
begin
fillchar(info,sizeof(info),#0);
Int13ExtIntalled := 1;
end;
end;
{$IFDEF UseIntCache}
function Flush_Cache;
var i : integer;
begin
if nCPages > Max_Cache_Pages then nCPages := Max_Cache_Pages;
for i := 1 to nCPages do if _Cache[i] <> nil then begin dispose(_Cache[i]); _Cache[i] := nil; end;
nCPages := 0;
CachePos := 0;
Flush_Cache := NoError;
end;
{$ELSE}
function Flush_Cache; assembler;
asm
end;
{$ENDIF}
function DosChar(c : char) : boolean;
begin
if (c<' ')
or(c='"')or(c='*')or(c='+')or(c='/')
or((c>=':')and(c<='?'))
or((c>='[')and(c<=']'))
or((c>='[')and(c<=']'))
or(c='|')
then DosChar := false
else DosChar := true;
end;
function WinChar(c : char) : boolean;
begin
if ((c='+')or(c=';')or(c='=')or(c='[')or(c=']')) then WinChar := true
else WinChar := false;
end;
procedure UnpackCylSec;
{„¥ª®¤¨àã¥â 樫¨¤à ¨ ᥪâ®à ¤«ï ¯à¥àë¢ ¨ï $13}
begin
Cyl := (CSec and 192) shl 2 + CSec shr 8;
Sec := CSec and 63
end;
Function PackCylSec(Cyl : word; Sec : byte) : word;
{“¯ ª®¢ë¢ ¥â 樫¨¤à ¨ ᥪâ®à ¢ ®¤® á«®¢® ¤«ï ¯à¥àë¢ ¨ï $13}
begin
PackCylSec := Sec+(Cyl and $300) shr 2 + (Cyl shl 8)
end;
procedure DeCalcFS;
begin
with Drive do
if (fs > 0)and(MaxSector > 0)and(SeHD > 0) then
begin
Track := fs div SeHD;
fs := fs mod SeHD;
if fs = 0 then
begin
fs := SeHD;
dec(Track);
end;
Head := fs div MaxSector;
Sector := fs mod MaxSector;
if Sector = 0 then
begin
Sector := MaxSector;
Dec(Head);
end;
end else
begin
Sector := 0; Track := 0; Head := 0;
end;
end;
function CalcFS;
begin
with Drive do
if (MaxSector > 0)and(SeHD > 0) then
begin
CalcFS := longint(SeHD)*longint(Track) + longint(Head)*longint(MaxSector) + Sector;
end else
begin
CalcFS := 0;
end;
end;
function CheckSectors;
{assembler;}
begin
asm
cli
mov dl, Drive.Drive
mov dh, Head
mov cx, Track
xchg cl, ch
shl cl, 6
add cl, Sector
mov al, num
mov ah, 04h
int 13h
mov DiskError, ah
mov al, 1
jnc @NoError
xor al, al
@NoError:
sti
end;
end;
function ReadSectors;
{$IFDEF UseIntCache}
var f,e : boolean;
i,t : word;
s : byte;
begin
e := false;
if num < 1 then exit;
if num = 1 then
begin
if Drive.Drive < 2 then if Diskette_Changed(Drive.Drive) then Flush_Cache;
UnPackCylSec(cylsec,t,s);
f := false;
for i := 1 to nCPages do if _Cache[i] <> nil then
begin
if _Cache[i]^.Drive = Drive.Drive then
if _Cache[i]^.Track = t then
if _Cache[i]^.Head = Head then
if _Cache[i]^.Sec = s then begin f := true; break; end;
end;
end else f := false;
if f then
begin
e := true;
move(_Cache[i]^.data,buf,DosSectorSize)
end else
begin
{$ELSE}
assembler;
{$ENDIF}
asm
mov dl, Drive.Drive
mov dh, Head
mov cx, CylSec
les bx, buf
mov al, num
mov ah, 02h
int 13h
mov al, 1
jnc @NoError
xor al, al
@NoError:
{$IFDEF UseIntCache}
mov e,al
{$ENDIF}
end;
{$IFDEF UseIntCache}
if (e){and(num = 1)} then
begin
if CachePos < Max_Cache_Pages then inc(CachePos) else CachePos := 1;
if (nCPages < CachePos) then
begin
inc(nCPages);
new(_Cache[nCPages]);
end else if _Cache[CachePos]=nil then new(_Cache[CachePos]);
if _Cache[CachePos]<>nil then
begin
_Cache[CachePos]^.Drive := Drive.Drive;
_Cache[CachePos]^.Head := Head;
_Cache[CachePos]^.Track := T;
_Cache[CachePos]^.Sec := S;
move(buf,_Cache[CachePos]^.data,sizeof(_Cache[1]^.data));
end;
end;
end;
ReadSectors := e;
end;
{$ENDIF}
Function ReadDataS;
var SecBeg : longint;
{$IFDEF UseIntCache}
var f,e : boolean;
i : word;
begin
e := false;
if num < 1 then exit;
if (num = 1) then
begin
if Drive.Drive < 2 then if Diskette_Changed(Drive.Drive) then Flush_Cache;
f := false;
for i := 1 to nCPages do if _Cache[i] <> nil then
begin
if _Cache[i]^.Drive = Drive.Drive then
if _Cache[i]^.Track = Track then
if _Cache[i]^.Head = Head then
if _Cache[i]^.Sec = Sector then begin f := true; break; end;
end else
begin
nCPages := i-1; break;
end;
end else f := false;
if f then
begin
e := true;
move(_Cache[i]^.data,iobuf,DosSectorSize)
end else
begin
{$ELSE}
{assembler;}
begin
{$ENDIF}
if Drive.ExtSup then
begin
SecBeg := CalcFS(Drive,Track,Head,Sector-1);
dap.size := sizeof(dap);
dap.Blocks := num;
dap.bufadr := @iobuf;
dap.BegLo := SecBeg;
dap.BegHi := 0;
asm
mov DL,Drive.Drive
lea si,dap
mov AX,4200h
int 13h
end;
e := true;
end else
asm
cli
mov dl, Drive.Drive
mov dh, Head
mov cx, Track
xchg cl, ch
shl cl, 6
add cl, Sector
les bx, ioBuf
mov al, num
mov ah, 02h
int 13h
mov DiskError,ah
mov al, 1
jnc @NoError
xor al, al
@NoError:
sti
{$IFDEF UseIntCache}
mov e,al
{$ELSE}
end;
{$ENDIF}
end;
{$IFDEF UseIntCache}
if (e){and(num = 1)} then
begin
if CachePos < Max_Cache_Pages then inc(CachePos) else CachePos := 1;
if (nCPages < CachePos) then
begin
inc(nCPages);
new(_Cache[nCPages]);
end else if _Cache[CachePos]=nil then new(_Cache[CachePos]);
if _Cache[CachePos]<>nil then
begin
_Cache[CachePos]^.Drive := Drive.Drive;
_Cache[CachePos]^.Head := Head;
_Cache[CachePos]^.Track := Track;
_Cache[CachePos]^.Sec := Sector;
move(iobuf,_Cache[CachePos]^.data,sizeof(_Cache[1]^.data));
end;
end;
end;
ReadDataS:=e;
end;
{$ENDIF}
Function WriteDataS;
{$IFDEF UseIntCache}
begin
Flush_Cache;
{$ELSE}
assembler;
{$ENDIF}
asm
cli
mov dl, Drive.Drive
mov dh, Head
mov cx, Track
xchg cl, ch
shl cl, 6
add cl, Sector
les bx, ioBuf
mov al, num
mov ah, 03h
int 13h
mov DiskError,ah
mov al, 1
jnc @NoError
xor al, al
@NoError:
sti
{$IFDEF UseIntCache}
end;
{$ENDIF}
end; {WriteDataS}
function WriteSectors;
{$IFDEF UseIntCache}
begin
Flush_Cache;
{$ELSE}
assembler;
{$ENDIF}
asm
mov dl, Drive.Drive
mov dh, Head
mov cx, CylSec
les bx, buf
mov al, num
mov ah, 03h
int 13h
mov al, 1
jnc @NoError
xor al, al
@NoError:
{$IFDEF UseIntCache}
end;
{$ENDIF}
end; {WriteSectorS}
procedure Recalibrate; assembler;
asm
{Recalibrate}
xor ah,ah
mov dl,Drive
int 13h
{Re-Init according 2 Drive table}
mov ah,09h
mov dl,Drive
int 13h
end;
function Diskette_Changed; assembler;
asm
mov ah,16h
mov dl,Drive
int 13h
cmp ah,06h
je @Changed
mov al,0
jmp @Exit
@Changed:
mov al,1
@Exit:
end;
function GetDrvBiosInfo;
var tt : word; hh,sec : byte;
begin
asm
cli
mov ah, 08h
mov dl, Drive
int 13h
mov DiskError, ah
jc @Error
dec dl
mov HH,dh
mov al,cl
and al,3fh
mov Sec,al
xor ax,ax
and cl,0C0h
mov al,cl
shl ax,2
mov al,ch
mov TT,ax
xor al, al
jmp @NoError
@Error:
mov al,1
mov Sec,0
mov HH,0
mov TT,0
@NoError:
sti
end;
with DrvBiosInf do
begin
MaxSector := Sec;
MaxHead := hh;
MaxTrack := tt;
SeHD := (MaxHead+1)*MaxSector;
GetDrvBiosInfo := (SeHD>0);
end;
end;
function GetSysSt;
begin
case sysID of
$00: GetSysSt := 'UnUsed';
$01: GetSysSt := 'DOS FAT12';
$02: GetSysSt := 'XENIX root';
$03: GetSysSt := 'XENIX /usr';
$04: GetSysSt := 'DOS FAT16 < 32mb';
$05: GetSysSt := 'Extended';
$06: GetSysSt := 'DOS FAT16 > 32mb';
$07: GetSysSt := 'NTFS ???';
$08: GetSysSt := 'AIX ???';
$09: GetSysSt := 'AIX';
$09: GetSysSt := 'Coherent FS';
$0A: GetSysSt := 'OS/2 ???';
$0B: GetSysSt := 'M$ Win FAT32';
$0C: GetSysSt := 'M$ Win FAT32x';
$0E: GetSysSt := 'BigDOSx';
$0F: GetSysSt := 'Extended-X';
$10: GetSysSt := 'OPUS';
$11: GetSysSt := 'OS/2 FAT12-h';
$12: GetSysSt := 'Compaq';
$14: GetSysSt := 'OS/2 FAT16-h < 32mb';
$16: GetSysSt := 'OS/2 FAT16-h > 32mb';
$17: GetSysSt := 'OS/2 HPFS-h';
$18: GetSysSt := 'AST Windows swap';
$24: GetSysSt := 'NEC MS-DOS 3.x';
$3C: GetSysSt := 'PQ PM recovery';
$40: GetSysSt := 'VENIX 80286';
$42: GetSysSt := 'SFS';
$50: GetSysSt := 'DM, read-only';
$51: GetSysSt := 'Novell???';
$52: GetSysSt := 'CP/M ???';
$56: GetSysSt := 'GoldenBow VFeature';
$61: GetSysSt := 'SpeedStor';
$63: GetSysSt := 'Unix SysV/386 ???';
$64: GetSysSt := 'Novell NetWare';
$65: GetSysSt := 'Novell NetWare+';
$70: GetSysSt := 'DiskSecure M-Boot';
$75: GetSysSt := 'PC/IX';
$80: GetSysSt := 'Minix';
$81: GetSysSt := 'Linux ???';
$82: GetSysSt := 'Linux Swap';
$83: GetSysSt := 'Linux EXT2fs/xIAfs';
$84: GetSysSt := 'OS/2-renumbered';
$93: GetSysSt := 'Amoeba FS';
$94: GetSysSt := 'Amoeba Bad Block';
$A5: GetSysSt := 'FreeBSD';
$B7: GetSysSt := 'BSDI FS (1 Swap)';
$B8: GetSysSt := 'BSDI Swap (2 FS)';
$C1: GetSysSt := 'DR-DOS FAT12-s';
$C4: GetSysSt := 'DR-DOS FAT16-s';
$C6: GetSysSt := 'DR-DOS Huge-s';
$C7: GetSysSt := 'Cyrnix Boot';
$DB: GetSysSt := 'CP/M ???';
$E1: GetSysSt := 'SpeedStor FAT12';
$F2: GetSysSt := 'DOS sec.';
$E4: GetSysSt := 'SpeedStor FAT16';
$FE: GetSysSt := 'LANstep';
$FF: GetSysSt := 'Xenix bad block';
else GetSysSt := 'UnKnown ('+hexb(sysID)+'h)';
end;
end;
Function ErrToStr;
begin
case Error of
NoError: ErrToStr:='';
$01: ErrToStr:='¥¯à ¢¨«ì ï ª®¬ ¤ ';
$02: ErrToStr:='¥ ©¤¥ ¤à¥á ï ¬¥âª ';
$03: ErrToStr:='„¨áª § é¨é¥ ®â § ¯¨á¨';
$04: ErrToStr:='‘¥ªâ®à ¥ ©¤¥';
$05: ErrToStr:='Žè¨¡ª ४ «¨¡à®¢ª¨';
$06: ErrToStr:='ந§®è« § ¬¥ ¤¨áª¥âë';
$07: ErrToStr:='Žè¨¡ª ¢ ¯ à ¬¥âà å DBT ¤¨áª ';
$08: ErrToStr:='¥à¥¯®«¥¨¥ ª « DMA';
$09: ErrToStr:='‚ë室 § £à ¨æã 64k DMA';
$0a: ErrToStr:='«®å®© ᥪâ®à';
$0b: ErrToStr:='«®å ï ¤®à®¦ª ';
$0c: ErrToStr:='¥¯à ¢¨«ìë© ®¬¥à ¤®à®¦ª¨';
$0d: ErrToStr:='¥¯à ¢¨«ìë© ®¬¥à ᥪâ®à ';
$0e: ErrToStr:='Ž¡ à㦥 ¤à¥á ï ¬¥âª ã¯à ¢«ïîé¨å ¤ ëå';
$0f: ErrToStr:='Žè¨¡ª DMA';
$10: ErrToStr:='Žè¨¡ª ¤ ëå (CRC failed)';
$11: ErrToStr:='„ ë¥ áª®à४â¨à®¢ ë á奬 ¬¨ ª®â஫ï';
else ErrToStr:='¥¨§¢¥áâ ï ®è¨¡ª ';
end;
End;
function DosStr(st : string) : boolean;
var i : integer;
begin
DosStr := true;
for i := 1 to byte(st[0]) do if not DosChar(st[i]) then begin DosStr:=false; break; end;
end;
{$IFDEF UseIntCache}
var i : integer;
BEGIN
for i := 1 to Max_Cache_Pages do _Cache[i] := nil;
nCPages := 0;
CachePos := 0;
{$ENDIF}
END. {of unit}
... and Justice 4 all. (c) MetallicA