Rev 2288 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2455 | mario79 | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
2288 | clevermous | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; FAT12.INC ;; |
||
7 | ;; (C) 2005 Mario79, License: GPL ;; |
||
8 | ;; ;; |
||
9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
10 | |||
11 | $Revision: 2455 $ |
||
12 | |||
13 | |||
14 | n_sector dd 0 ; temporary save for sector value |
||
15 | flp_status dd 0 |
||
16 | clust_tmp_flp dd 0 ; used by analyze_directory and analyze_directory_to_write |
||
17 | path_pointer_flp dd 0 |
||
18 | pointer_file_name_flp dd 0 |
||
19 | save_root_flag db 0 |
||
20 | save_flag db 0 |
||
21 | root_read db 0 ; 0-necessary to load root, 1-not to load root |
||
22 | flp_fat db 0 ; 0-necessary to load fat, 1-not to load fat |
||
23 | flp_number db 0 ; 1- Floppy A, 2-Floppy B |
||
24 | old_track db 0 ; old value track |
||
25 | flp_label rb 15 ; Label and ID of inserted floppy disk |
||
26 | |||
27 | reserve_flp: |
||
28 | |||
29 | cli |
||
30 | cmp [flp_status], 0 |
||
31 | je reserve_flp_ok |
||
32 | |||
33 | sti |
||
34 | call change_task |
||
35 | jmp reserve_flp |
||
36 | |||
37 | reserve_flp_ok: |
||
38 | |||
39 | push eax |
||
40 | mov eax, [CURRENT_TASK] |
||
41 | shl eax, 5 |
||
42 | mov eax, [eax+CURRENT_TASK+TASKDATA.pid] |
||
43 | mov [flp_status], eax |
||
44 | pop eax |
||
45 | sti |
||
46 | ret |
||
47 | |||
48 | |||
49 | floppy_fileread: |
||
50 | ;---------------------------------------------------------------- |
||
51 | ; |
||
52 | ; fileread - sys floppy |
||
53 | ; |
||
54 | ; eax points to filename 11 chars - for root directory |
||
55 | ; ebx first wanted block ; 1+ ; if 0 then set to 1 |
||
56 | ; ecx number of blocks to read ; 1+ ; if 0 then set to 1 |
||
57 | ; edx mem location to return data |
||
58 | ; esi length of filename 12*X |
||
59 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
||
60 | ; |
||
61 | ; ret ebx = size or 0xffffffff file not found |
||
62 | ; eax = 0 ok read or other = errormsg |
||
63 | ; 10 = access denied |
||
64 | ;-------------------------------------------------------------- |
||
65 | |||
66 | mov [save_flag], 0 |
||
67 | mov [path_pointer_flp], edi |
||
68 | test esi, esi ; return ramdisk root |
||
69 | jnz fr_noroot_1 |
||
70 | cmp ebx, 224/16 |
||
71 | jbe fr_do_1 |
||
72 | mov eax, 5 |
||
73 | xor ebx, ebx |
||
74 | mov [flp_status], ebx |
||
75 | ret |
||
76 | |||
77 | fr_do_1: |
||
78 | push ebx ecx edx |
||
79 | call read_flp_root |
||
80 | pop edx ecx ebx |
||
81 | cmp [FDC_Status], 0 |
||
82 | jne fdc_status_error_1 |
||
83 | mov edi, edx |
||
84 | dec ebx |
||
85 | shl ebx, 9 |
||
86 | mov esi, FLOPPY_BUFF |
||
87 | add esi, ebx |
||
88 | shl ecx, 9 |
||
89 | cld |
||
90 | rep movsb |
||
91 | xor eax, eax |
||
92 | xor ebx, ebx |
||
93 | ; mov eax,0 ; ok read |
||
94 | ; mov ebx,0 |
||
95 | mov [flp_status], eax |
||
96 | ret |
||
97 | fdc_status_error_1: |
||
98 | xor eax, eax |
||
99 | mov [flp_status], eax |
||
100 | mov eax, 10 |
||
101 | or ebx, -1 |
||
102 | ret |
||
103 | |||
104 | fr_noroot_1: |
||
105 | sub esp, 32 |
||
106 | call expand_filename |
||
107 | frfloppy_1: |
||
108 | test ebx, ebx |
||
109 | jnz frfl5_1 |
||
110 | mov ebx, 1 |
||
111 | frfl5_1: |
||
112 | test ecx, ecx |
||
113 | jnz frfl6_1 |
||
114 | mov ecx, 1 |
||
115 | frfl6_1: |
||
116 | dec ebx |
||
117 | push eax |
||
118 | push eax ebx ecx edx esi edi |
||
119 | call read_flp_fat |
||
120 | cmp [FDC_Status], 0 |
||
121 | jne fdc_status_error_3_1 |
||
122 | mov [FDD_Track], 0; Цилиндр |
||
123 | mov [FDD_Head], 1; Сторона |
||
124 | mov [FDD_Sector], 2; Сектор |
||
125 | call SeekTrack |
||
126 | mov dh, 14 |
||
127 | l.20_1: |
||
128 | call ReadSectWithRetr |
||
129 | cmp [FDC_Status], 0 |
||
130 | jne fdc_status_error_3_1 |
||
131 | mov dl, 16 |
||
132 | mov edi, FDD_BUFF |
||
133 | inc [FDD_Sector] |
||
134 | l.21_1: |
||
135 | mov esi, eax ;Name of file we want |
||
136 | mov ecx, 11 |
||
137 | cld |
||
138 | rep cmpsb ;Found the file? |
||
139 | je fifound_1 ;Yes |
||
140 | add ecx, 21 |
||
141 | add edi, ecx ;Advance to next entry |
||
142 | dec dl |
||
143 | test dl, dl |
||
144 | jnz l.21_1 |
||
145 | dec dh |
||
146 | test dh, dh |
||
147 | jnz l.20_1 |
||
148 | fdc_status_error_3: |
||
149 | mov eax, 5 ; file not found ? |
||
150 | or ebx, -1 |
||
151 | add esp, 32+28 |
||
152 | mov [flp_status], 0 |
||
153 | ret |
||
154 | fdc_status_error_3_2: |
||
155 | cmp [FDC_Status], 0 |
||
156 | je fdc_status_error_3 |
||
157 | fdc_status_error_3_1: |
||
158 | add esp, 32+28 |
||
159 | jmp fdc_status_error_1 |
||
160 | |||
161 | fifound_1: |
||
162 | mov eax, [path_pointer_flp] |
||
163 | cmp [eax+36], byte 0 |
||
164 | je fifound_2 |
||
165 | add edi, 0xf |
||
166 | mov eax, [edi] |
||
167 | and eax, 65535 |
||
168 | mov ebx, [path_pointer_flp] |
||
169 | add ebx, 36 |
||
170 | call get_cluster_of_a_path_flp |
||
171 | jc fdc_status_error_3_2 |
||
172 | mov ebx, [ebx-11+28] ;file size |
||
173 | mov [esp+20], ebx |
||
174 | mov [esp+24], ebx |
||
175 | jmp fifound_3 |
||
176 | fifound_2: |
||
177 | mov ebx, [edi-11+28] ;file size |
||
178 | mov [esp+20], ebx |
||
179 | mov [esp+24], ebx |
||
180 | add edi, 0xf |
||
181 | mov eax, [edi] |
||
182 | fifound_3: |
||
183 | and eax, 65535 |
||
184 | mov [n_sector], eax ;eax=cluster |
||
185 | frnew_1: |
||
186 | add eax, 31 ;bootsector+2*fat+filenames |
||
187 | cmp [esp+16], dword 0; wanted cluster ? |
||
188 | jne frfl7_1 |
||
189 | call read_chs_sector |
||
190 | cmp [FDC_Status], 0 |
||
191 | jne fdc_status_error_5 |
||
192 | mov edi, [esp+8] |
||
193 | call give_back_application_data_1 |
||
194 | add [esp+8], dword 512 |
||
195 | dec dword [esp+12] ; last wanted cluster ? |
||
196 | cmp [esp+12], dword 0 |
||
197 | je frnoread_1 |
||
198 | jmp frfl8_1 |
||
199 | frfl7_1: |
||
200 | dec dword [esp+16] |
||
201 | frfl8_1: |
||
202 | mov edi, [n_sector] |
||
203 | shl edi, 1 ;find next cluster from FAT |
||
204 | add edi, FLOPPY_FAT |
||
205 | mov eax, [edi] |
||
206 | and eax, 4095 |
||
207 | mov edi, eax |
||
208 | mov [n_sector], edi |
||
209 | cmp edi, 4095 ;eof - cluster |
||
210 | jz frnoread2_1 |
||
211 | cmp [esp+24], dword 512;eof - size |
||
212 | jb frnoread_1 |
||
213 | sub [esp+24], dword 512 |
||
214 | jmp frnew_1 |
||
215 | |||
216 | read_chs_sector: |
||
217 | call calculate_chs |
||
218 | call ReadSectWithRetr |
||
219 | ret |
||
220 | |||
221 | frnoread2_1: |
||
222 | cmp [esp+16], dword 0; eof without read ? |
||
223 | je frnoread_1 |
||
224 | mov [fdc_irq_func], fdc_null |
||
225 | pop edi esi edx ecx |
||
226 | add esp, 4 |
||
227 | pop ebx; ebx <- eax : size of file |
||
228 | add esp, 36 |
||
229 | mov eax, 6; end of file |
||
230 | mov [flp_status], 0 |
||
231 | ret |
||
232 | |||
233 | frnoread_1: |
||
234 | pop edi esi edx ecx |
||
235 | add esp, 4 |
||
236 | pop ebx; ebx <- eax : size of file |
||
237 | add esp, 36 |
||
238 | xor eax, eax |
||
239 | mov [flp_status], eax |
||
240 | ret |
||
241 | |||
242 | fdc_status_error_5: |
||
243 | pop edi esi edx ecx |
||
244 | add esp, 4 |
||
245 | pop ebx; ebx <- eax : size of file |
||
246 | add esp, 36 |
||
247 | jmp fdc_status_error_1 |
||
248 | |||
249 | read_flp_root: |
||
250 | pusha |
||
251 | call check_label |
||
252 | cmp [FDC_Status], 0 |
||
253 | jne unnecessary_root_read |
||
254 | cmp [root_read], 1 |
||
255 | je unnecessary_root_read |
||
256 | mov [FDD_Track], 0; Цилиндр |
||
257 | mov [FDD_Head], 1; Сторона |
||
258 | mov [FDD_Sector], 2; Сектор |
||
259 | mov edi, FLOPPY_BUFF |
||
260 | call SeekTrack |
||
261 | read_flp_root_1: |
||
262 | call ReadSectWithRetr |
||
263 | cmp [FDC_Status], 0 |
||
264 | jne unnecessary_root_read |
||
265 | push edi |
||
266 | call give_back_application_data_1 |
||
267 | pop edi |
||
268 | add edi, 512 |
||