OSDN Git Service

実行ファイルを2つに分けたいけど分けられず
[haribote-os-xe/hariboteXE.git] / files.pas
1 unit files;
2
3 interface
4
5 uses System.SysUtils, System.Types;
6
7 type
8   TFileInfo = record
9     clustno: integer;
10     name: string[8];
11     ext: string[3];
12     tpye: Byte;
13     reserve: string[10];
14     size: UInt32;
15   end;
16
17   TFiles = class
18   private
19     procedure readfat(img: TBytes);
20   public
21     fat: array of DWORD;
22     constructor Create;
23     destructor Destroy; override;
24     procedure loadfile(clustno, size: integer; buf, img: TBytes);
25     function search(name: string; info: array of TFileInfo;
26       max: integer): integer;
27   end;
28
29 implementation
30
31 { TFiles }
32
33 uses bootpack;
34
35 constructor TFiles.Create;
36 begin
37   inherited;
38   //fat := Pointer(0);
39   SetLength(fat, 4 * 2880);
40   readfat(Pointer(ADR_DISKIMG + $00C200));
41 end;
42
43 destructor TFiles.Destroy;
44 begin
45   Finalize(fat);
46   inherited;
47 end;
48
49 procedure TFiles.loadfile(clustno, size: integer; buf, img: TBytes);
50 var
51   i: integer;
52 begin
53   while true do
54   begin
55     if size < 512 then
56     begin
57       for i := 0 to size do
58         buf[i] := img[clustno * 512 + i];
59       break;
60     end;
61     for i := 0 to 512 do
62       buf[i] := img[clustno * 512 + i];
63     dec(size, 512);
64     inc(clustno, 512);
65     clustno := fat[clustno];
66   end;
67 end;
68
69 procedure TFiles.readfat(img: TBytes);
70 var
71   i, j: integer;
72 begin
73   j := 0;
74   for i := 0 to 2880 do
75   begin
76     fat[i] := (img[j] or img[j + 1] shl 8) and $FFF;
77     fat[i + 1] := (img[j + 1] shr 4 or img[j + 2] shl 4) and $FFF;
78     inc(j);
79   end;
80 end;
81
82 function TFiles.search(name: string; info: array of TFileInfo;
83   max: integer): integer;
84 var
85   i, j: integer;
86   s: string;
87 label next;
88 begin
89   s:='';
90   j := 1;
91   for i := 1 to Length(name) do
92   begin
93     if j > 12 then
94     begin
95       result := -1;
96       Exit;
97     end;
98     if (name[i] = '.') and (j <= 8) then
99     begin
100       repeat
101         s:=s+' ';
102         inc(j);
103       until j = 8;
104     end
105     else
106     begin
107       s := s + name[i];
108       inc(j);
109     end;
110   end;
111   s := UpperCase(s);
112   result := -1;
113   for i := 0 to max do
114   begin
115     if info[i].name = '' then
116       break;
117     if info[i].tpye and $18 = 0 then
118     begin
119       for j := 0 to 10 do
120         if info[i].name <> s[j] then
121           goto next;
122       result := i;
123       break;
124     end;
125   next:
126   end;
127 end;
128
129 end.