Rev 83 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 83 | Rev 86 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; FAT12.INC ;; |
3 | ;; FAT12.INC ;; |
4 | ;; (C) 2005 Mario79, License: GPL ;; |
4 | ;; (C) 2005 Mario79, License: GPL ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | n_sector dd 0 ; temporary save for sector value |
8 | n_sector dd 0 ; temporary save for sector value |
9 | flp_status dd 0 |
9 | flp_status dd 0 |
10 | clust_tmp_flp dd 0 ; used by analyze_directory and analyze_directory_to_write |
10 | clust_tmp_flp dd 0 ; used by analyze_directory and analyze_directory_to_write |
11 | path_pointer_flp dd 0 |
11 | path_pointer_flp dd 0 |
12 | pointer_file_name_flp dd 0 |
12 | pointer_file_name_flp dd 0 |
13 | save_root_flag db 0 |
13 | save_root_flag db 0 |
14 | save_flag db 0 |
14 | save_flag db 0 |
15 | root_read db 0 ; 0-necessary to load root, 1-not to load root |
15 | root_read db 0 ; 0-necessary to load root, 1-not to load root |
16 | flp_fat db 0 ; 0-necessary to load fat, 1-not to load fat |
16 | flp_fat db 0 ; 0-necessary to load fat, 1-not to load fat |
17 | flp_number db 0 ; 1- Floppy A, 2-Floppy B |
17 | flp_number db 0 ; 1- Floppy A, 2-Floppy B |
18 | old_track db 0 ; old value track |
18 | old_track db 0 ; old value track |
19 | flp_label rb 15 ; Label and ID of inserted floppy disk |
19 | flp_label rb 15 ; Label and ID of inserted floppy disk |
20 | 20 | ||
21 | reserve_flp: |
21 | reserve_flp: |
22 | 22 | ||
23 | cli |
23 | cli |
24 | cmp [flp_status],0 |
24 | cmp [flp_status],0 |
25 | je reserve_flp_ok |
25 | je reserve_flp_ok |
26 | 26 | ||
27 | sti |
27 | sti |
28 | call change_task |
28 | call change_task |
29 | jmp reserve_flp |
29 | jmp reserve_flp |
30 | 30 | ||
31 | reserve_flp_ok: |
31 | reserve_flp_ok: |
32 | 32 | ||
33 | push eax |
33 | push eax |
34 | mov eax,[0x3000] |
34 | mov eax,[0x3000] |
35 | shl eax,5 |
35 | shl eax,5 |
36 | mov eax,[eax+0x3000+4] |
36 | mov eax,[eax+0x3000+4] |
37 | mov [flp_status],eax |
37 | mov [flp_status],eax |
38 | pop eax |
38 | pop eax |
39 | sti |
39 | sti |
40 | ret |
40 | ret |
41 | 41 | ||
42 | floppy_free_space: |
42 | floppy_free_space: |
43 | ;--------------------------------------------- |
43 | ;--------------------------------------------- |
44 | ; |
44 | ; |
45 | ; returns free space in edi |
45 | ; returns free space in edi |
46 | ; |
46 | ; |
47 | ;--------------------------------------------- |
47 | ;--------------------------------------------- |
48 | push eax ebx ecx |
48 | push eax ebx ecx |
49 | call read_flp_fat |
49 | call read_flp_fat |
50 | cmp [FDC_Status],0 |
50 | cmp [FDC_Status],0 |
51 | jne fdc_status_error_2 |
51 | jne fdc_status_error_2 |
52 | mov eax,0x282000 |
52 | mov eax,0x282000 |
53 | xor edi,edi |
53 | xor edi,edi |
54 | mov ecx,2847 ;1448000/512 |
54 | mov ecx,2847 ;1448000/512 |
55 | rdfs1_1: |
55 | rdfs1_1: |
56 | mov ebx,[eax] |
56 | mov ebx,[eax] |
57 | and ebx,4095 |
57 | and ebx,4095 |
58 | jne rdfs2_1 |
58 | jne rdfs2_1 |
59 | add edi,512 |
59 | add edi,512 |
60 | rdfs2_1: |
60 | rdfs2_1: |
61 | add eax,2 |
61 | add eax,2 |
62 | loop rdfs1_1 |
62 | loop rdfs1_1 |
63 | fdc_status_error_2: |
63 | fdc_status_error_2: |
64 | pop ecx ebx eax |
64 | pop ecx ebx eax |
65 | ret |
65 | ret |
66 | 66 | ||
67 | 67 | ||
68 | 68 | ||
69 | 69 | ||
70 | floppy_fileread: |
70 | floppy_fileread: |
71 | ;---------------------------------------------------------------- |
71 | ;---------------------------------------------------------------- |
72 | ; |
72 | ; |
73 | ; fileread - sys floppy |
73 | ; fileread - sys floppy |
74 | ; |
74 | ; |
75 | ; eax points to filename 11 chars - for root directory |
75 | ; eax points to filename 11 chars - for root directory |
76 | ; ebx first wanted block ; 1+ ; if 0 then set to 1 |
76 | ; ebx first wanted block ; 1+ ; if 0 then set to 1 |
77 | ; ecx number of blocks to read ; 1+ ; if 0 then set to 1 |
77 | ; ecx number of blocks to read ; 1+ ; if 0 then set to 1 |
78 | ; edx mem location to return data |
78 | ; edx mem location to return data |
79 | ; esi length of filename 12*X |
79 | ; esi length of filename 12*X |
80 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
80 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
81 | ; |
81 | ; |
82 | ; ret ebx = size or 0xffffffff file not found |
82 | ; ret ebx = size or 0xffffffff file not found |
83 | ; eax = 0 ok read or other = errormsg |
83 | ; eax = 0 ok read or other = errormsg |
84 | ; 10 = access denied |
84 | ; 10 = access denied |
85 | ;-------------------------------------------------------------- |
85 | ;-------------------------------------------------------------- |
86 | 86 | ||
87 | mov [save_flag],0 |
87 | mov [save_flag],0 |
88 | mov [path_pointer_flp],edi |
88 | mov [path_pointer_flp],edi |
89 | cmp esi,0 ; return ramdisk root |
89 | cmp esi,0 ; return ramdisk root |
90 | jne fr_noroot_1 |
90 | jne fr_noroot_1 |
91 | cmp ebx,224/16 |
91 | cmp ebx,224/16 |
92 | jbe fr_do_1 |
92 | jbe fr_do_1 |
93 | mov eax,5 |
93 | mov eax,5 |
94 | mov ebx,0 |
94 | mov ebx,0 |
95 | mov [flp_status],0 |
95 | mov [flp_status],0 |
96 | ret |
96 | ret |
97 | 97 | ||
98 | fr_do_1: |
98 | fr_do_1: |
99 | push ebx ecx edx |
99 | push ebx ecx edx |
100 | call read_flp_root |
100 | call read_flp_root |
101 | pop edx ecx ebx |
101 | pop edx ecx ebx |
102 | cmp [FDC_Status],0 |
102 | cmp [FDC_Status],0 |
103 | jne fdc_status_error_1 |
103 | jne fdc_status_error_1 |
104 | mov edi,edx |
104 | mov edi,edx |
105 | dec ebx |
105 | dec ebx |
106 | shl ebx,9 |
106 | shl ebx,9 |
107 | mov esi,0x8000 |
107 | mov esi,0x8000 |
108 | add esi,ebx |
108 | add esi,ebx |
109 | shl ecx,9 |
109 | shl ecx,9 |
110 | cld |
110 | cld |
111 | rep movsb |
111 | rep movsb |
112 | mov eax,0 ; ok read |
112 | mov eax,0 ; ok read |
113 | mov ebx,0 |
113 | mov ebx,0 |
114 | mov [flp_status],0 |
114 | mov [flp_status],0 |
115 | ret |
115 | ret |
116 | fdc_status_error_1: |
116 | fdc_status_error_1: |
117 | mov [flp_status],0 |
117 | mov [flp_status],0 |
118 | mov eax,10 |
118 | mov eax,10 |
119 | mov ebx,-1 |
119 | mov ebx,-1 |
120 | ret |
120 | ret |
121 | 121 | ||
122 | fr_noroot_1: |
122 | fr_noroot_1: |
123 | sub esp,32 |
123 | sub esp,32 |
124 | call expand_filename |
124 | call expand_filename |
125 | frfloppy_1: |
125 | frfloppy_1: |
126 | cmp ebx,0 |
126 | cmp ebx,0 |
127 | jne frfl5_1 |
127 | jne frfl5_1 |
128 | mov ebx,1 |
128 | mov ebx,1 |
129 | frfl5_1: |
129 | frfl5_1: |
130 | cmp ecx,0 |
130 | cmp ecx,0 |
131 | jne frfl6_1 |
131 | jne frfl6_1 |
132 | mov ecx,1 |
132 | mov ecx,1 |
133 | frfl6_1: |
133 | frfl6_1: |
134 | dec ebx |
134 | dec ebx |
135 | push eax |
135 | push eax |
136 | push eax ebx ecx edx esi edi |
136 | push eax ebx ecx edx esi edi |
137 | call read_flp_fat |
137 | call read_flp_fat |
138 | cmp [FDC_Status],0 |
138 | cmp [FDC_Status],0 |
139 | jne fdc_status_error_3_1 |
139 | jne fdc_status_error_3_1 |
140 | mov [FDD_Track],0 ; Öèëèíäð |
140 | mov [FDD_Track],0 ; Öèëèíäð |
141 | mov [FDD_Head],1 ; Ñòîðîíà |
141 | mov [FDD_Head],1 ; Ñòîðîíà |
142 | mov [FDD_Sector],2 ; Ñåêòîð |
142 | mov [FDD_Sector],2 ; Ñåêòîð |
143 | call SeekTrack |
143 | call SeekTrack |
144 | mov dh,14 |
144 | mov dh,14 |
145 | l.20_1: |
145 | l.20_1: |
146 | call ReadSectWithRetr |
146 | call ReadSectWithRetr |
147 | cmp [FDC_Status],0 |
147 | cmp [FDC_Status],0 |
148 | jne fdc_status_error_3_1 |
148 | jne fdc_status_error_3_1 |
149 | mov dl,16 |
149 | mov dl,16 |
150 | mov edi,0xD000 |
150 | mov edi,0xD000 |
151 | inc [FDD_Sector] |
151 | inc [FDD_Sector] |
152 | l.21_1: |
152 | l.21_1: |
153 | mov esi,eax ;Name of file we want |
153 | mov esi,eax ;Name of file we want |
154 | mov ecx,11 |
154 | mov ecx,11 |
155 | cld |
155 | cld |
156 | rep cmpsb ;Found the file? |
156 | rep cmpsb ;Found the file? |
157 | je fifound_1 ;Yes |
157 | je fifound_1 ;Yes |
158 | add ecx,21 |
158 | add ecx,21 |
159 | add edi, ecx ;Advance to next entry |
159 | add edi, ecx ;Advance to next entry |
160 | dec dl |
160 | dec dl |
161 | cmp dl,0 |
161 | cmp dl,0 |
162 | jne l.21_1 |
162 | jne l.21_1 |
163 | dec dh |
163 | dec dh |
164 | cmp dh,0 |
164 | cmp dh,0 |
165 | jne l.20_1 |
165 | jne l.20_1 |
166 | fdc_status_error_3: |
166 | fdc_status_error_3: |
167 | mov eax,5 ; file not found ? |
167 | mov eax,5 ; file not found ? |
168 | mov ebx,-1 |
168 | mov ebx,-1 |
169 | add esp,32+28 |
169 | add esp,32+28 |
170 | mov [flp_status],0 |
170 | mov [flp_status],0 |
171 | ret |
171 | ret |
172 | fdc_status_error_3_2: |
172 | fdc_status_error_3_2: |
173 | cmp [FDC_Status],0 |
173 | cmp [FDC_Status],0 |
174 | je fdc_status_error_3 |
174 | je fdc_status_error_3 |
175 | fdc_status_error_3_1: |
175 | fdc_status_error_3_1: |
176 | add esp,32+28 |
176 | add esp,32+28 |
177 | jmp fdc_status_error_1 |
177 | jmp fdc_status_error_1 |
178 | 178 | ||
179 | fifound_1: |
179 | fifound_1: |
180 | mov eax,[path_pointer_flp] |
180 | mov eax,[path_pointer_flp] |
181 | cmp [eax+36],byte 0 |
181 | cmp [eax+36],byte 0 |
182 | je fifound_2 |
182 | je fifound_2 |
183 | add edi,0xf |
183 | add edi,0xf |
184 | mov eax,[edi] |
184 | mov eax,[edi] |
185 | and eax,65535 |
185 | and eax,65535 |
186 | mov ebx,[path_pointer_flp] |
186 | mov ebx,[path_pointer_flp] |
187 | add ebx,36 |
187 | add ebx,36 |
188 | call get_cluster_of_a_path_flp |
188 | call get_cluster_of_a_path_flp |
189 | jc fdc_status_error_3_2 |
189 | jc fdc_status_error_3_2 |
190 | mov ebx,[ebx-11+28] ;file size |
190 | mov ebx,[ebx-11+28] ;file size |
191 | mov [esp+20],ebx |
191 | mov [esp+20],ebx |
192 | mov [esp+24],ebx |
192 | mov [esp+24],ebx |
193 | jmp fifound_3 |
193 | jmp fifound_3 |
194 | fifound_2: |
194 | fifound_2: |
195 | mov ebx,[edi-11+28] ;file size |
195 | mov ebx,[edi-11+28] ;file size |
196 | mov [esp+20],ebx |
196 | mov [esp+20],ebx |
197 | mov [esp+24],ebx |
197 | mov [esp+24],ebx |
198 | add edi,0xf |
198 | add edi,0xf |
199 | mov eax,[edi] |
199 | mov eax,[edi] |
200 | fifound_3: |
200 | fifound_3: |
201 | and eax,65535 |
201 | and eax,65535 |
202 | mov [n_sector],eax ;eax=cluster |
202 | mov [n_sector],eax ;eax=cluster |
203 | frnew_1: |
203 | frnew_1: |
204 | add eax,31 ;bootsector+2*fat+filenames |
204 | add eax,31 ;bootsector+2*fat+filenames |
205 | cmp [esp+16],dword 0 ; wanted cluster ? |
205 | cmp [esp+16],dword 0 ; wanted cluster ? |
206 | jne frfl7_1 |
206 | jne frfl7_1 |
207 | call read_chs_sector |
207 | call read_chs_sector |
208 | cmp [FDC_Status],0 |
208 | cmp [FDC_Status],0 |
209 | jne fdc_status_error_5 |
209 | jne fdc_status_error_5 |
210 | mov edi,[esp+8] |
210 | mov edi,[esp+8] |
211 | call give_back_application_data_1 |
211 | call give_back_application_data_1 |
212 | add [esp+8],dword 512 |
212 | add [esp+8],dword 512 |
213 | dec dword [esp+12] ; last wanted cluster ? |
213 | dec dword [esp+12] ; last wanted cluster ? |
214 | cmp [esp+12],dword 0 |
214 | cmp [esp+12],dword 0 |
215 | je frnoread_1 |
215 | je frnoread_1 |
216 | jmp frfl8_1 |
216 | jmp frfl8_1 |
217 | frfl7_1: |
217 | frfl7_1: |
218 | dec dword [esp+16] |
218 | dec dword [esp+16] |
219 | frfl8_1: |
219 | frfl8_1: |
220 | mov edi,[n_sector] |
220 | mov edi,[n_sector] |
221 | shl edi,1 ;find next cluster from FAT |
221 | shl edi,1 ;find next cluster from FAT |
222 | add edi,0x282000 |
222 | add edi,0x282000 |
223 | mov eax,[edi] |
223 | mov eax,[edi] |
224 | and eax,4095 |
224 | and eax,4095 |
225 | mov edi,eax |
225 | mov edi,eax |
226 | mov [n_sector],edi |
226 | mov [n_sector],edi |
227 | cmp edi,4095 ;eof - cluster |
227 | cmp edi,4095 ;eof - cluster |
228 | jz frnoread2_1 |
228 | jz frnoread2_1 |
229 | cmp [esp+24],dword 512 ;eof - size |
229 | cmp [esp+24],dword 512 ;eof - size |
230 | jb frnoread_1 |
230 | jb frnoread_1 |
231 | sub [esp+24],dword 512 |
231 | sub [esp+24],dword 512 |
232 | jmp frnew_1 |
232 | jmp frnew_1 |
233 | 233 | ||
234 | read_chs_sector: |
234 | read_chs_sector: |
235 | call calculate_chs |
235 | call calculate_chs |
236 | call ReadSectWithRetr |
236 | call ReadSectWithRetr |
237 | ret |
237 | ret |
238 | 238 | ||
239 | frnoread2_1: |
239 | frnoread2_1: |
240 | cmp [esp+16],dword 0 ; eof without read ? |
240 | cmp [esp+16],dword 0 ; eof without read ? |
241 | je frnoread_1 |
241 | je frnoread_1 |
242 | mov [fdc_irq_func],fdc_null |
242 | mov [fdc_irq_func],fdc_null |
243 | pop edi esi edx ecx |
243 | pop edi esi edx ecx |
244 | add esp,4 |
244 | add esp,4 |
245 | pop ebx ; ebx <- eax : size of file |
245 | pop ebx ; ebx <- eax : size of file |
246 | add esp,36 |
246 | add esp,36 |
247 | mov eax,6 ; end of file |
247 | mov eax,6 ; end of file |
248 | mov [flp_status],0 |
248 | mov [flp_status],0 |
249 | ret |
249 | ret |
250 | 250 | ||
251 | frnoread_1: |
251 | frnoread_1: |
252 | pop edi esi edx ecx |
252 | pop edi esi edx ecx |
253 | add esp,4 |
253 | add esp,4 |
254 | pop ebx ; ebx <- eax : size of file |
254 | pop ebx ; ebx <- eax : size of file |
255 | add esp,36 |
255 | add esp,36 |
256 | mov eax,0 |
256 | mov eax,0 |
257 | mov [flp_status],0 |
257 | mov [flp_status],0 |
258 | ret |
258 | ret |
259 | 259 | ||
260 | fdc_status_error_5: |
260 | fdc_status_error_5: |
261 | pop edi esi edx ecx |
261 | pop edi esi edx ecx |
262 | add esp,4 |
262 | add esp,4 |
263 | pop ebx ; ebx <- eax : size of file |
263 | pop ebx ; ebx <- eax : size of file |
264 | add esp,36 |
264 | add esp,36 |
265 | jmp fdc_status_error_1 |
265 | jmp fdc_status_error_1 |
266 | 266 | ||
267 | read_flp_root: |
267 | read_flp_root: |
268 | pusha |
268 | pusha |
269 | call check_label |
269 | call check_label |
270 | cmp [FDC_Status],0 |
270 | cmp [FDC_Status],0 |
271 | jne unnecessary_root_read |
271 | jne unnecessary_root_read |
272 | cmp [root_read],1 |
272 | cmp [root_read],1 |
273 | je unnecessary_root_read |
273 | je unnecessary_root_read |
274 | mov [FDD_Track],0 ; Öèëèíäð |
274 | mov [FDD_Track],0 ; Öèëèíäð |
275 | mov [FDD_Head],1 ; Ñòîðîíà |
275 | mov [FDD_Head],1 ; Ñòîðîíà |
276 | mov [FDD_Sector],2 ; Ñåêòîð |
276 | mov [FDD_Sector],2 ; Ñåêòîð |
277 | mov edi,0x8000 |
277 | mov edi,0x8000 |
278 | call SeekTrack |
278 | call SeekTrack |
279 | read_flp_root_1: |
279 | read_flp_root_1: |
280 | call ReadSectWithRetr |
280 | call ReadSectWithRetr |
281 | cmp [FDC_Status],0 |
281 | cmp [FDC_Status],0 |
282 | jne unnecessary_root_read |
282 | jne unnecessary_root_read |
283 | push edi |
283 | push edi |
284 | call give_back_application_data_1 |
284 | call give_back_application_data_1 |
285 | pop edi |
285 | pop edi |
286 | add edi,512 |
286 | add edi,512 |
287 | inc [FDD_Sector] |
287 | inc [FDD_Sector] |
288 | cmp [FDD_Sector],16 |
288 | cmp [FDD_Sector],16 |
289 | jne read_flp_root_1 |
289 | jne read_flp_root_1 |
290 | mov [root_read],1 |
290 | mov [root_read],1 |
291 | unnecessary_root_read: |
291 | unnecessary_root_read: |
292 | popa |
292 | popa |
293 | ret |
293 | ret |
294 | 294 | ||
295 | 295 | ||
296 | read_flp_fat: |
296 | read_flp_fat: |
297 | pusha |
297 | pusha |
298 | call check_label |
298 | call check_label |
299 | cmp [FDC_Status],0 |
299 | cmp [FDC_Status],0 |
300 | jne unnecessary_flp_fat |
300 | jne unnecessary_flp_fat |
301 | cmp [flp_fat],1 |
301 | cmp [flp_fat],1 |
302 | je unnecessary_flp_fat |
302 | je unnecessary_flp_fat |
303 | mov [FDD_Track],0 ; Öèëèíäð |
303 | mov [FDD_Track],0 ; Öèëèíäð |
304 | mov [FDD_Head],0 ; Ñòîðîíà |
304 | mov [FDD_Head],0 ; Ñòîðîíà |
305 | mov [FDD_Sector],2 ; Ñåêòîð |
305 | mov [FDD_Sector],2 ; Ñåêòîð |
306 | mov edi,0x8000 |
306 | mov edi,0x8000 |
307 | call SeekTrack |
307 | call SeekTrack |
308 | read_flp_fat_1: |
308 | read_flp_fat_1: |
309 | call ReadSectWithRetr |
309 | call ReadSectWithRetr |
310 | cmp [FDC_Status],0 |
310 | cmp [FDC_Status],0 |
311 | jne unnecessary_flp_fat |
311 | jne unnecessary_flp_fat |
312 | push edi |
312 | push edi |
313 | call give_back_application_data_1 |
313 | call give_back_application_data_1 |
314 | pop edi |
314 | pop edi |
315 | add edi,512 |
315 | add edi,512 |
316 | inc [FDD_Sector] |
316 | inc [FDD_Sector] |
317 | cmp [FDD_Sector],19 |
317 | cmp [FDD_Sector],19 |
318 | jne read_flp_fat_1 |
318 | jne read_flp_fat_1 |
319 | mov [FDD_Sector],1 |
319 | mov [FDD_Sector],1 |
320 | mov [FDD_Head],1 |
320 | mov [FDD_Head],1 |
321 | call ReadSectWithRetr |
321 | call ReadSectWithRetr |
322 | cmp [FDC_Status],0 |
322 | cmp [FDC_Status],0 |
323 | jne unnecessary_flp_fat |
323 | jne unnecessary_flp_fat |
324 | call give_back_application_data_1 |
324 | call give_back_application_data_1 |
325 | call calculatefatchain_flp |
325 | call calculatefatchain_flp |
326 | mov [root_read],0 |
326 | mov [root_read],0 |
327 | mov [flp_fat],1 |
327 | mov [flp_fat],1 |
328 | unnecessary_flp_fat: |
328 | unnecessary_flp_fat: |
329 | popa |
329 | popa |
330 | ret |
330 | ret |
331 | 331 | ||
332 | calculatefatchain_flp: |
332 | calculatefatchain_flp: |
333 | pushad |
333 | pushad |
334 | 334 | ||
335 | mov esi,0x8000 |
335 | mov esi,0x8000 |
336 | mov edi,0x282000 |
336 | mov edi,0x282000 |
337 | 337 | ||
338 | fcnew_1: |
338 | fcnew_1: |
339 | mov eax,dword [esi] |
339 | mov eax,dword [esi] |
340 | mov ebx,dword [esi+4] |
340 | mov ebx,dword [esi+4] |
341 | mov ecx,dword [esi+8] |
341 | mov ecx,dword [esi+8] |
342 | mov edx,ecx |
342 | mov edx,ecx |
343 | shr edx,4 ;8 ok |
343 | shr edx,4 ;8 ok |
344 | shr dx,4 ;7 ok |
344 | shr dx,4 ;7 ok |
345 | xor ch,ch |
345 | xor ch,ch |
346 | shld ecx,ebx,20 ;6 ok |
346 | shld ecx,ebx,20 ;6 ok |
347 | shr cx,4 ;5 ok |
347 | shr cx,4 ;5 ok |
348 | shld ebx,eax,12 |
348 | shld ebx,eax,12 |
349 | and ebx,0x0fffffff ;4 ok |
349 | and ebx,0x0fffffff ;4 ok |
350 | shr bx,4 ;3 ok |
350 | shr bx,4 ;3 ok |
351 | shl eax,4 |
351 | shl eax,4 |
352 | and eax,0x0fffffff ;2 ok |
352 | and eax,0x0fffffff ;2 ok |
353 | shr ax,4 ;1 ok |
353 | shr ax,4 ;1 ok |
354 | mov dword [edi],eax |
354 | mov dword [edi],eax |
355 | add edi,4 |
355 | add edi,4 |
356 | mov dword [edi],ebx |
356 | mov dword [edi],ebx |
357 | add edi,4 |
357 | add edi,4 |
358 | mov dword [edi],ecx |
358 | mov dword [edi],ecx |
359 | add edi,4 |
359 | add edi,4 |
360 | mov dword [edi],edx |
360 | mov dword [edi],edx |
361 | add edi,4 |
361 | add edi,4 |
362 | add esi,12 |
362 | add esi,12 |
363 | 363 | ||
364 | cmp edi,0x282000+2856*2 ;2849 clusters |
364 | cmp edi,0x282000+2856*2 ;2849 clusters |
365 | jnz fcnew_1 |
365 | jnz fcnew_1 |
366 | 366 | ||
367 | popad |
367 | popad |
368 | ret |
368 | ret |
369 | 369 | ||
370 | check_label: |
370 | check_label: |
371 | pushad |
371 | pushad |
372 | mov [FDD_Track],0 ; Öèëèíäð |
372 | mov [FDD_Track],0 ; Öèëèíäð |
373 | mov [FDD_Head],0 ; Ñòîðîíà |
373 | mov [FDD_Head],0 ; Ñòîðîíà |
374 | mov [FDD_Sector],1 ; Ñåêòîð |
374 | mov [FDD_Sector],1 ; Ñåêòîð |
375 | call SetUserInterrupts |
375 | call SetUserInterrupts |
376 | call FDDMotorON |
376 | call FDDMotorON |
377 | call RecalibrateFDD |
377 | call RecalibrateFDD |
378 | cmp [FDC_Status],0 |
378 | cmp [FDC_Status],0 |
379 | jne fdc_status_error |
379 | jne fdc_status_error |
380 | call SeekTrack |
380 | call SeekTrack |
381 | cmp [FDC_Status],0 |
381 | cmp [FDC_Status],0 |
382 | jne fdc_status_error |
382 | jne fdc_status_error |
383 | call ReadSectWithRetr |
383 | call ReadSectWithRetr |
384 | cmp [FDC_Status],0 |
384 | cmp [FDC_Status],0 |
385 | jne fdc_status_error |
385 | jne fdc_status_error |
386 | mov esi,flp_label |
386 | mov esi,flp_label |
387 | mov edi,0xD000+39 |
387 | mov edi,0xD000+39 |
388 | mov ecx,15 |
388 | mov ecx,15 |
389 | cld |
389 | cld |
390 | rep cmpsb |
390 | rep cmpsb |
391 | je same_label |
391 | je same_label |
392 | mov [root_read],0 |
392 | mov [root_read],0 |
393 | mov [flp_fat],0 |
393 | mov [flp_fat],0 |
394 | same_label: |
394 | same_label: |
395 | mov esi,0xD000+39 |
395 | mov esi,0xD000+39 |
396 | mov edi,flp_label |
396 | mov edi,flp_label |
397 | mov ecx,15 |
397 | mov ecx,15 |
398 | cld |
398 | cld |
399 | rep movsb |
399 | rep movsb |
400 | popad |
400 | popad |
401 | ret |
401 | ret |
402 | fdc_status_error: |
402 | fdc_status_error: |
403 | popad |
403 | popad |
404 | ret |
404 | ret |
405 | 405 | ||
406 | save_flp_root: |
406 | save_flp_root: |
407 | pusha |
407 | pusha |
408 | call check_label |
408 | call check_label |
409 | cmp [FDC_Status],0 |
409 | cmp [FDC_Status],0 |
410 | jne unnecessary_root_save |
410 | jne unnecessary_root_save |
411 | cmp [root_read],0 |
411 | cmp [root_read],0 |
412 | je unnecessary_root_save |
412 | je unnecessary_root_save |
413 | mov [FDD_Track],0 ; Öèëèíäð |
413 | mov [FDD_Track],0 ; Öèëèíäð |
414 | mov [FDD_Head],1 ; Ñòîðîíà |
414 | mov [FDD_Head],1 ; Ñòîðîíà |
415 | mov [FDD_Sector],2 ; Ñåêòîð |
415 | mov [FDD_Sector],2 ; Ñåêòîð |
416 | mov esi,0x8000 |
416 | mov esi,0x8000 |
417 | call SeekTrack |
417 | call SeekTrack |
418 | save_flp_root_1: |
418 | save_flp_root_1: |
419 | push esi |
419 | push esi |
420 | call take_data_from_application_1 |
420 | call take_data_from_application_1 |
421 | pop esi |
421 | pop esi |
422 | add esi,512 |
422 | add esi,512 |
423 | call WriteSectWithRetr |
423 | call WriteSectWithRetr |
424 | cmp [FDC_Status],0 |
424 | cmp [FDC_Status],0 |
425 | jne unnecessary_root_save |
425 | jne unnecessary_root_save |
426 | inc [FDD_Sector] |
426 | inc [FDD_Sector] |
427 | cmp [FDD_Sector],16 |
427 | cmp [FDD_Sector],16 |
428 | jne save_flp_root_1 |
428 | jne save_flp_root_1 |
429 | unnecessary_root_save: |
429 | unnecessary_root_save: |
430 | mov [fdc_irq_func],fdc_null |
430 | mov [fdc_irq_func],fdc_null |
431 | popa |
431 | popa |
432 | ret |
432 | ret |
433 | 433 | ||
434 | save_flp_fat: |
434 | save_flp_fat: |
435 | pusha |
435 | pusha |
436 | call check_label |
436 | call check_label |
437 | cmp [FDC_Status],0 |
437 | cmp [FDC_Status],0 |
438 | jne unnecessary_flp_fat_save |
438 | jne unnecessary_flp_fat_save |
439 | cmp [flp_fat],0 |
439 | cmp [flp_fat],0 |
440 | je unnecessary_flp_fat_save |
440 | je unnecessary_flp_fat_save |
441 | call restorefatchain_flp |
441 | call restorefatchain_flp |
442 | mov [FDD_Track],0 ; Öèëèíäð |
442 | mov [FDD_Track],0 ; Öèëèíäð |
443 | mov [FDD_Head],0 ; Ñòîðîíà |
443 | mov [FDD_Head],0 ; Ñòîðîíà |
444 | mov [FDD_Sector],2 ; Ñåêòîð |
444 | mov [FDD_Sector],2 ; Ñåêòîð |
445 | mov esi,0x8000 |
445 | mov esi,0x8000 |
446 | call SeekTrack |
446 | call SeekTrack |
447 | save_flp_fat_1: |
447 | save_flp_fat_1: |
448 | push esi |
448 | push esi |
449 | call take_data_from_application_1 |
449 | call take_data_from_application_1 |
450 | pop esi |
450 | pop esi |
451 | add esi,512 |
451 | add esi,512 |
452 | call WriteSectWithRetr |
452 | call WriteSectWithRetr |
453 | cmp [FDC_Status],0 |
453 | cmp [FDC_Status],0 |
454 | jne unnecessary_flp_fat_save |
454 | jne unnecessary_flp_fat_save |
455 | inc [FDD_Sector] |
455 | inc [FDD_Sector] |
456 | cmp [FDD_Sector],19 |
456 | cmp [FDD_Sector],19 |
457 | jne save_flp_fat_1 |
457 | jne save_flp_fat_1 |
458 | mov [FDD_Sector],1 |
458 | mov [FDD_Sector],1 |
459 | mov [FDD_Head],1 |
459 | mov [FDD_Head],1 |
460 | call take_data_from_application_1 |
460 | call take_data_from_application_1 |
461 | call WriteSectWithRetr |
461 | call WriteSectWithRetr |
462 | cmp [FDC_Status],0 |
462 | cmp [FDC_Status],0 |
463 | jne unnecessary_flp_fat_save |
463 | jne unnecessary_flp_fat_save |
464 | mov [root_read],0 |
464 | mov [root_read],0 |
465 | unnecessary_flp_fat_save: |
465 | unnecessary_flp_fat_save: |
466 | mov [fdc_irq_func],fdc_null |
466 | mov [fdc_irq_func],fdc_null |
467 | popa |
467 | popa |
468 | ret |
468 | ret |
469 | 469 | ||
470 | 470 | ||
471 | restorefatchain_flp: ; restore fat chain |
471 | restorefatchain_flp: ; restore fat chain |
472 | pushad |
472 | pushad |
473 | 473 | ||
474 | mov esi,0x282000 |
474 | mov esi,0x282000 |
475 | mov edi,0x8000 |
475 | mov edi,0x8000 |
476 | 476 | ||
477 | fcnew2_1: |
477 | fcnew2_1: |
478 | mov eax,dword [esi] |
478 | mov eax,dword [esi] |
479 | mov ebx,dword [esi+4] |
479 | mov ebx,dword [esi+4] |
480 | shl ax,4 |
480 | shl ax,4 |
481 | shl eax,4 |
481 | shl eax,4 |
482 | shl bx,4 |
482 | shl bx,4 |
483 | shr ebx,4 |
483 | shr ebx,4 |
484 | shrd eax,ebx,8 |
484 | shrd eax,ebx,8 |
485 | shr ebx,8 |
485 | shr ebx,8 |
486 | mov dword [edi],eax |
486 | mov dword [edi],eax |
487 | add edi,4 |
487 | add edi,4 |
488 | mov word [edi],bx |
488 | mov word [edi],bx |
489 | add edi,2 |
489 | add edi,2 |
490 | add esi,8 |
490 | add esi,8 |
491 | 491 | ||
492 | cmp edi,0x8000+0x1200 ;4274 bytes - all used FAT |
492 | cmp edi,0x8000+0x1200 ;4274 bytes - all used FAT |
493 | jb fcnew2_1 |
493 | jb fcnew2_1 |
494 | 494 | ||
495 | mov esi,0x8000 ; duplicate fat chain |
495 | mov esi,0x8000 ; duplicate fat chain |
496 | mov edi,0x8000+0x1200 |
496 | mov edi,0x8000+0x1200 |
497 | mov ecx,0x1200/4 |
497 | mov ecx,0x1200/4 |
498 | cld |
498 | cld |
499 | rep movsd |
499 | rep movsd |
500 | 500 | ||
501 | popad |
501 | popad |
502 | ret |
502 | ret |
503 | 503 | ||
504 | 504 | ||
505 | floppy_filedelete: |
505 | floppy_filedelete: |
506 | ;-------------------------------------------- |
506 | ;-------------------------------------------- |
507 | ; |
507 | ; |
508 | ; filedelete - sys floppy |
508 | ; filedelete - sys floppy |
509 | ; in: |
509 | ; in: |
510 | ; eax - filename 11 chars - for root directory |
510 | ; eax - filename 11 chars - for root directory |
511 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
511 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
512 | ; |
512 | ; |
513 | ; out: |
513 | ; out: |
514 | ; eax - 0 = successful, 1 = file not found, 10 = access denied |
514 | ; eax - 0 = successful, 1 = file not found, 10 = access denied |
515 | ; |
515 | ; |
516 | ;-------------------------------------------- |
516 | ;-------------------------------------------- |
517 | mov [path_pointer_flp],edi |
517 | mov [path_pointer_flp],edi |
518 | mov [save_flag],0 |
518 | mov [save_flag],0 |
519 | mov ebp,1 ; file not found as default |
519 | mov ebp,1 ; file not found as default |
520 | filedelete_newtry_1: |
520 | filedelete_newtry_1: |
521 | sub esp,32 |
521 | sub esp,32 |
522 | call expand_filename |
522 | call expand_filename |
523 | push eax ebx ecx edx esi edi |
523 | push eax ebx ecx edx esi edi |
524 | call read_flp_fat |
524 | call read_flp_fat |
525 | cmp [FDC_Status],0 |
525 | cmp [FDC_Status],0 |
526 | jne frnoreadd_1 |
526 | jne frnoreadd_1 |
527 | mov [FDD_Track],0 ; Öèëèíäð |
527 | mov [FDD_Track],0 ; Öèëèíäð |
528 | mov [FDD_Head],1 ; Ñòîðîíà |
528 | mov [FDD_Head],1 ; Ñòîðîíà |
529 | mov [FDD_Sector],2 ; Ñåêòîð |
529 | mov [FDD_Sector],2 ; Ñåêòîð |
530 | call SeekTrack |
530 | call SeekTrack |
531 | mov dh,14 |
531 | mov dh,14 |
532 | l.20_2: |
532 | l.20_2: |
533 | call ReadSectWithRetr |
533 | call ReadSectWithRetr |
534 | cmp [FDC_Status],0 |
534 | cmp [FDC_Status],0 |
535 | jne fdc_status_error_4 |
535 | jne fdc_status_error_4 |
536 | mov dl,16 |
536 | mov dl,16 |
537 | mov edi,0xD000 |
537 | mov edi,0xD000 |
538 | inc [FDD_Sector] |
538 | inc [FDD_Sector] |
539 | l.21_2: |
539 | l.21_2: |
540 | mov esi,eax ;Name of file we want |
540 | mov esi,eax ;Name of file we want |
541 | mov ecx,11 |
541 | mov ecx,11 |
542 | cld |
542 | cld |
543 | rep cmpsb ;Found the file? |
543 | rep cmpsb ;Found the file? |
544 | je fifoundd_1 ;Yes |
544 | je fifoundd_1 ;Yes |
545 | add ecx,21 |
545 | add ecx,21 |
546 | add edi, ecx ;Advance to next entry |
546 | add edi, ecx ;Advance to next entry |
547 | dec dl |
547 | dec dl |
548 | jne l.21_2 |
548 | jne l.21_2 |
549 | dec dh |
549 | dec dh |
550 | jne l.20_2 |
550 | jne l.20_2 |
551 | jmp frnoreadd_1 |
551 | jmp frnoreadd_1 |
552 | 552 | ||
553 | fdc_status_error_4: |
553 | fdc_status_error_4: |
554 | pop edi esi edx ecx ebx eax |
554 | pop edi esi edx ecx ebx eax |
555 | add esp,32 |
555 | add esp,32 |
556 | jmp fdc_status_error_1 |
556 | jmp fdc_status_error_1 |
557 | 557 | ||
558 | fifoundd_1: |
558 | fifoundd_1: |
559 | mov eax,[path_pointer_flp] |
559 | mov eax,[path_pointer_flp] |
560 | cmp [eax+36],byte 0 |
560 | cmp [eax+36],byte 0 |
561 | je fifoundd_2 |
561 | je fifoundd_2 |
562 | movzx eax, word [edi+0xf] |
562 | movzx eax, word [edi+0xf] |
563 | mov ebx,[path_pointer_flp] |
563 | mov ebx,[path_pointer_flp] |
564 | add ebx,36 |
564 | add ebx,36 |
565 | call get_cluster_of_a_path_flp |
565 | call get_cluster_of_a_path_flp |
566 | jc frnoreadd_1_1 |
566 | jc frnoreadd_1_1 |
567 | mov edi,ebx |
567 | mov edi,ebx |
568 | add edi,11 |
568 | add edi,11 |
569 | jmp fifoundd_2_1 |
569 | jmp fifoundd_2_1 |
570 | fifoundd_2: |
570 | fifoundd_2: |
571 | dec [FDD_Sector] |
571 | dec [FDD_Sector] |
572 | fifoundd_2_1: |
572 | fifoundd_2_1: |
573 | mov [edi-11],byte 0xE5 ;mark filename deleted |
573 | mov [edi-11],byte 0xE5 ;mark filename deleted |
574 | movzx edi, word [edi+0xf] ;edi = cluster |
574 | movzx edi, word [edi+0xf] ;edi = cluster |
575 | frnewd_1: |
575 | frnewd_1: |
576 | shl edi,1 ;find next cluster from FAT |
576 | shl edi,1 ;find next cluster from FAT |
577 | add edi,0x282000 |
577 | add edi,0x282000 |
578 | mov eax,[edi] |
578 | mov eax,[edi] |
579 | mov [edi],word 0x0 ;clear fat chain cluster |
579 | mov [edi],word 0x0 ;clear fat chain cluster |
580 | and eax,4095 |
580 | and eax,4095 |
581 | mov edi,eax |
581 | mov edi,eax |
582 | cmp edi,dword 4095 ;last cluster ? |
582 | cmp edi,dword 4095 ;last cluster ? |
583 | jz frnoreadd2_1 |
583 | jz frnoreadd2_1 |
584 | jmp frnewd_1 |
584 | jmp frnewd_1 |
585 | 585 | ||
586 | frnoreadd2_1: |
586 | frnoreadd2_1: |
587 | call WriteSectWithRetr |
587 | call WriteSectWithRetr |
588 | cmp [FDC_Status],0 |
588 | cmp [FDC_Status],0 |
589 | jne fdc_status_error_4 |
589 | jne fdc_status_error_4 |
590 | call save_flp_fat |
590 | call save_flp_fat |
591 | cmp [FDC_Status],0 |
591 | cmp [FDC_Status],0 |
592 | jne fdc_status_error_4 |
592 | jne fdc_status_error_4 |
593 | ; pop edi esi edx ecx ebx eax |
593 | ; pop edi esi edx ecx ebx eax |
594 | ; add esp,32 |
594 | ; add esp,32 |
595 | mov ebp,0 ; file found |
595 | mov ebp,0 ; file found |
596 | ; jmp filedelete_newtry_1 |
596 | ; jmp filedelete_newtry_1 |
597 | jmp frnoreadd_1 |
597 | jmp frnoreadd_1 |
598 | 598 | ||
599 | frnoreadd_1_1: |
599 | frnoreadd_1_1: |
600 | cmp [FDC_Status],0 |
600 | cmp [FDC_Status],0 |
601 | jne fdc_status_error_4 |
601 | jne fdc_status_error_4 |
602 | frnoreadd_1: |
602 | frnoreadd_1: |
603 | pop edi esi edx ecx ebx eax |
603 | pop edi esi edx ecx ebx eax |
604 | add esp,32 |
604 | add esp,32 |
605 | mov eax,ebp |
605 | mov eax,ebp |
606 | ret |
606 | ret |
607 | 607 | ||
608 | floppy_filesave: |
608 | floppy_filesave: |
609 | ;---------------------------------------------------------- |
609 | ;---------------------------------------------------------- |
610 | ; |
610 | ; |
611 | ; filesave - sys floppy |
611 | ; filesave - sys floppy |
612 | ; |
612 | ; |
613 | ; eax ; pointer to file name 11 chars - for root directory |
613 | ; eax ; pointer to file name 11 chars - for root directory |
614 | ; ebx ; buffer |
614 | ; ebx ; buffer |
615 | ; ecx ; count to write in bytes |
615 | ; ecx ; count to write in bytes |
616 | ; edx ; 0 create new , 1 append |
616 | ; edx ; 0 create new , 1 append |
617 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
617 | ; edi pointer to path /fd/1/...... - for all files in nested directories |
618 | ; |
618 | ; |
619 | ; output : eax = 0 - ok |
619 | ; output : eax = 0 - ok |
620 | ; 5 - file not found / directory not found |
620 | ; 5 - file not found / directory not found |
621 | ; 8 - disk full |
621 | ; 8 - disk full |
622 | ; 10 - access denied |
622 | ; 10 - access denied |
623 | ;----------------------------------------------------------- |
623 | ;----------------------------------------------------------- |
624 | mov [path_pointer_flp],edi |
624 | mov [path_pointer_flp],edi |
625 | sub esp,32 |
625 | sub esp,32 |
626 | call expand_filename |
626 | call expand_filename |
627 | cmp edx,0 |
627 | cmp edx,0 |
628 | jnz fsdel_1 |
628 | jnz fsdel_1 |
629 | pusha |
629 | pusha |
630 | call floppy_filedelete |
630 | call floppy_filedelete |
631 | cmp [FDC_Status],0 |
631 | cmp [FDC_Status],0 |
632 | jne fdc_status_error_6 |
632 | jne fdc_status_error_6 |
633 | popa |
633 | popa |
634 | mov [save_flag],1 |
634 | mov [save_flag],1 |
635 | fsdel_1: |
635 | fsdel_1: |
636 | call floppy_free_space |
636 | call floppy_free_space |
637 | cmp [FDC_Status],0 |
637 | cmp [FDC_Status],0 |
638 | jne fdc_status_error_6 |
638 | jne fdc_status_error_6 |
639 | cmp ecx,edi |
639 | cmp ecx,edi |
640 | jb rd_do_save_1 |
640 | jb rd_do_save_1 |
641 | add esp,32 |
641 | add esp,32 |
642 | mov eax,8 ; not enough free space |
642 | mov eax,8 ; not enough free space |
643 | mov [flp_status],0 |
643 | mov [flp_status],0 |
644 | ret |
644 | ret |
645 | 645 | ||
646 | fdc_status_error_6: |
646 | fdc_status_error_6: |
647 | popa |
647 | popa |
648 | add esp,32 |
648 | add esp,32 |
649 | jmp fdc_status_error_1 |
649 | jmp fdc_status_error_1 |
650 | 650 | ||
651 | rd_do_save_1: |
651 | rd_do_save_1: |
652 | push eax ebx ecx edx esi edi |
652 | push eax ebx ecx edx esi edi |
653 | call read_flp_fat |
653 | call read_flp_fat |
654 | cmp [FDC_Status],0 |
654 | cmp [FDC_Status],0 |
655 | jne fdc_status_error_7 |
655 | jne fdc_status_error_7 |
656 | push eax |
656 | push eax |
657 | mov eax,[path_pointer_flp] |
657 | mov eax,[path_pointer_flp] |
658 | cmp [eax+36],byte 0 |
658 | cmp [eax+36],byte 0 |
659 | jne fifoundds_2 |
659 | jne fifoundds_2 |
660 | pop eax |
660 | pop eax |
661 | mov [save_root_flag],1 |
661 | mov [save_root_flag],1 |
662 | call read_flp_root |
662 | call read_flp_root |
663 | cmp [FDC_Status],0 |
663 | cmp [FDC_Status],0 |
664 | jne fdc_status_error_7 |
664 | jne fdc_status_error_7 |
665 | mov edi,0x8000 ;Point at directory |
665 | mov edi,0x8000 ;Point at directory |
666 | mov edx,224 +1 |
666 | mov edx,224 +1 |
667 | ; find an empty spot for filename in the root dir |
667 | ; find an empty spot for filename in the root dir |
668 | l20ds_1: |
668 | l20ds_1: |
669 | sub edx,1 |
669 | sub edx,1 |
670 | jz frnoreadds_1 |
670 | jz frnoreadds_1 |
671 | l21ds_1: |
671 | l21ds_1: |
672 | cmp [edi],byte 0xE5 |
672 | cmp [edi],byte 0xE5 |
673 | jz fifoundds_1 |
673 | jz fifoundds_1 |
674 | cmp [edi],byte 0x0 |
674 | cmp [edi],byte 0x0 |
675 | jz fifoundds_1 |
675 | jz fifoundds_1 |
676 | add edi,32 ; Advance to next entry |
676 | add edi,32 ; Advance to next entry |
677 | jmp l20ds_1 |
677 | jmp l20ds_1 |
678 | 678 | ||
679 | fifoundds_2: |
679 | fifoundds_2: |
680 | pop eax |
680 | pop eax |
681 | mov [save_root_flag],0 |
681 | mov [save_root_flag],0 |
682 | mov [FDD_Track],0 ; Öèëèíäð |
682 | mov [FDD_Track],0 ; Öèëèíäð |
683 | mov [FDD_Head],1 ; Ñòîðîíà |
683 | mov [FDD_Head],1 ; Ñòîðîíà |
684 | mov [FDD_Sector],2 ; Ñåêòîð |
684 | mov [FDD_Sector],2 ; Ñåêòîð |
685 | call SeekTrack |
685 | call SeekTrack |
686 | mov dh,14 |
686 | mov dh,14 |
687 | l.20_3: |
687 | l.20_3: |
688 | call ReadSectWithRetr |
688 | call ReadSectWithRetr |
689 | cmp [FDC_Status],0 |
689 | cmp [FDC_Status],0 |
690 | jne fdc_status_error_7 |
690 | jne fdc_status_error_7 |
691 | mov dl,16 |
691 | mov dl,16 |
692 | mov edi,0xD000 |
692 | mov edi,0xD000 |
693 | inc [FDD_Sector] |
693 | inc [FDD_Sector] |
694 | l.21_3: |
694 | l.21_3: |
695 | mov esi,eax ;Name of file we want |
695 | mov esi,eax ;Name of file we want |
696 | mov ecx,11 |
696 | mov ecx,11 |
697 | cld |
697 | cld |
698 | rep cmpsb ;Found the file? |
698 | rep cmpsb ;Found the file? |
699 | je fifoundds_3 ;Yes |
699 | je fifoundds_3 ;Yes |
700 | add ecx,21 |
700 | add ecx,21 |
701 | add edi, ecx ;Advance to next entry |
701 | add edi, ecx ;Advance to next entry |
702 | dec dl |
702 | dec dl |
703 | jne l.21_3 |
703 | jne l.21_3 |
704 | dec dh |
704 | dec dh |
705 | jne l.20_3 |
705 | jne l.20_3 |
706 | fdc_status_error_8: |
706 | fdc_status_error_8: |
707 | pop edi esi edx ecx ebx eax |
707 | pop edi esi edx ecx ebx eax |
708 | mov eax,5 ; file not found ? |
708 | mov eax,5 ; file not found ? |
709 | mov ebx,-1 |
709 | mov ebx,-1 |
710 | add esp,32 |
710 | add esp,32 |
711 | mov [flp_status],0 |
711 | mov [flp_status],0 |
712 | ret |
712 | ret |
713 | 713 | ||
714 | fifoundds_3: |
714 | fifoundds_3: |
715 | add edi,0xf |
715 | add edi,0xf |
716 | mov eax,[edi] |
716 | mov eax,[edi] |
717 | and eax,65535 |
717 | and eax,65535 |
718 | mov ebx,[path_pointer_flp] |
718 | mov ebx,[path_pointer_flp] |
719 | add ebx,36 |
719 | add ebx,36 |
720 | call get_cluster_of_a_path_flp |
720 | call get_cluster_of_a_path_flp |
721 | jc fdc_status_error_7_1 |
721 | jc fdc_status_error_7_1 |
722 | found_directory_for_writing_flp: |
722 | found_directory_for_writing_flp: |
723 | call analyze_directory_to_write_flp |
723 | call analyze_directory_to_write_flp |
724 | jc fdc_status_error_7_1 |
724 | jc fdc_status_error_7_1 |
725 | mov edi,ebx |
725 | mov edi,ebx |
726 | fifoundds_1: |
726 | fifoundds_1: |
727 | push edi ; move the filename to root dir |
727 | push edi ; move the filename to root dir |
728 | mov esi,[esp+4+20] |
728 | mov esi,[esp+4+20] |
729 | cmp [save_root_flag],0 |
729 | cmp [save_root_flag],0 |
730 | jne fifoundds_4 |
730 | jne fifoundds_4 |
731 | mov esi,[pointer_file_name_flp] |
731 | mov esi,[pointer_file_name_flp] |
732 | fifoundds_4: |
732 | fifoundds_4: |
733 | mov ecx,11 |
733 | mov ecx,11 |
734 | cld |
734 | cld |
735 | rep movsb |
735 | rep movsb |
736 | pop edi |
736 | pop edi |
737 | mov edx,edi |
737 | mov edx,edi |
738 | add edx,11+0xf ; edx <- cluster save position |
738 | add edx,11+0xf ; edx <- cluster save position |
739 | mov ebx,[esp+12] ; save file size |
739 | mov ebx,[esp+12] ; save file size |
740 | mov [edi+28],ebx |
740 | mov [edi+28],ebx |
741 | mov [edi+11],byte 0x20 ; attribute |
741 | mov [edi+11],byte 0x20 ; attribute |
742 | call get_date_for_file ; from FAT32.INC |
742 | call get_date_for_file ; from FAT32.INC |
743 | mov [edi+24],ax ; date |
743 | mov [edi+24],ax ; date |
744 | mov [edi+18],ax ; date |
744 | mov [edi+18],ax ; date |
745 | call get_time_for_file ; from FAT32.INC |
745 | call get_time_for_file ; from FAT32.INC |
746 | mov [edi+22],ax ; time |
746 | mov [edi+22],ax ; time |
747 | xor ax,ax |
747 | xor ax,ax |
748 | mov [edi+20],ax |
748 | mov [edi+20],ax |
749 | mov ebx,1 ; first cluster |
749 | mov ebx,1 ; first cluster |
750 | cmp [save_root_flag],0 |
750 | cmp [save_root_flag],0 |
751 | jne frnewds_1 |
751 | jne frnewds_1 |
752 | call frnewds_2 |
752 | call frnewds_2 |
753 | pusha |
753 | pusha |
754 | call WriteSectWithRetr |
754 | call WriteSectWithRetr |
755 | popa |
755 | popa |
756 | cmp [FDC_Status],0 |
756 | cmp [FDC_Status],0 |
757 | jne fdc_status_error_7 |
757 | jne fdc_status_error_7 |
758 | jmp frnewds_3 |
758 | jmp frnewds_3 |
759 | 759 | ||
760 | frnewds_1: |
760 | frnewds_1: |
761 | call frnewds_2 |
761 | call frnewds_2 |
762 | frnewds_3: |
762 | frnewds_3: |
763 | pusha ; move save to floppy cluster |
763 | pusha ; move save to floppy cluster |
764 | add ebx,31 |
764 | add ebx,31 |
765 | mov eax,ebx |
765 | mov eax,ebx |
766 | mov esi,[esp+32+16] |
766 | mov esi,[esp+32+16] |
767 | call take_data_from_application_1 |
767 | call take_data_from_application_1 |
768 | call save_chs_sector |
768 | call save_chs_sector |
769 | cmp [FDC_Status],0 |
769 | cmp [FDC_Status],0 |
770 | jne fdc_status_error_7 |
770 | jne fdc_status_error_7 |
771 | popa |
771 | popa |
772 | mov eax,[esp+12] |
772 | mov eax,[esp+12] |
773 | cmp eax,512 |
773 | cmp eax,512 |
774 | jb flnsa_1 |
774 | jb flnsa_1 |
775 | sub eax,512 |
775 | sub eax,512 |
776 | mov [esp+12],eax |
776 | mov [esp+12],eax |
777 | mov eax,[esp+16] |
777 | mov eax,[esp+16] |
778 | add eax,512 |
778 | add eax,512 |
779 | mov [esp+16],eax |
779 | mov [esp+16],eax |
780 | jmp frnewds_1 |
780 | jmp frnewds_1 |
781 | 781 | ||
782 | frnewds_2: |
782 | frnewds_2: |
783 | add ebx,1 |
783 | add ebx,1 |
784 | mov edi,ebx ; find free cluster in FAT |
784 | mov edi,ebx ; find free cluster in FAT |
785 | shl edi,1 |
785 | shl edi,1 |
786 | add edi,0x282000 |
786 | add edi,0x282000 |
787 | mov eax,[edi] |
787 | mov eax,[edi] |
788 | and eax,4095 |
788 | and eax,4095 |
789 | jnz frnewds_2 |
789 | jnz frnewds_2 |
790 | mov [edx],bx ; save next cluster pos. to prev cl. |
790 | mov [edx],bx ; save next cluster pos. to prev cl. |
791 | mov edx,edi ; next save pos abs mem add |
791 | mov edx,edi ; next save pos abs mem add |
792 | ret |
792 | ret |
793 | 793 | ||
794 | flnsa_1: |
794 | flnsa_1: |
795 | mov [edi],word 4095 ; mark end of file - last cluster |
795 | mov [edi],word 4095 ; mark end of file - last cluster |
796 | cmp [save_root_flag],1 |
796 | cmp [save_root_flag],1 |
797 | jne flnsa_2 |
797 | jne flnsa_2 |
798 | call save_flp_root |
798 | call save_flp_root |
799 | cmp [FDC_Status],0 |
799 | cmp [FDC_Status],0 |
800 | jne fdc_status_error_7 |
800 | jne fdc_status_error_7 |
801 | flnsa_2: |
801 | flnsa_2: |
802 | call save_flp_fat |
802 | call save_flp_fat |
803 | cmp [FDC_Status],0 |
803 | cmp [FDC_Status],0 |
804 | jne fdc_status_error_7 |
804 | jne fdc_status_error_7 |
805 | frnoreadds_1: |
805 | frnoreadds_1: |
806 | pop edi esi edx ecx ebx eax |
806 | pop edi esi edx ecx ebx eax |
807 | add esp,32 |
807 | add esp,32 |
808 | mov eax,0 |
808 | mov eax,0 |
809 | mov [flp_status],0 |
809 | mov [flp_status],0 |
810 | ret |
810 | ret |
811 | 811 | ||
812 | fdc_status_error_7_1: |
812 | fdc_status_error_7_1: |
813 | cmp [FDC_Status],0 |
813 | cmp [FDC_Status],0 |
814 | je fdc_status_error_8 |
814 | je fdc_status_error_8 |
815 | fdc_status_error_7: |
815 | fdc_status_error_7: |
816 | pop edi esi edx ecx ebx eax |
816 | pop edi esi edx ecx ebx eax |
817 | add esp,32 |
817 | add esp,32 |
818 | jmp fdc_status_error_1 |
818 | jmp fdc_status_error_1 |
819 | 819 | ||
820 | save_chs_sector: |
820 | save_chs_sector: |
821 | call calculate_chs |
821 | call calculate_chs |
822 | call WriteSectWithRetr |
822 | call WriteSectWithRetr |
823 | ret |
823 | ret |
824 | 824 | ||
825 | calculate_chs: |
825 | calculate_chs: |
826 | mov bl,[FDD_Track] |
826 | mov bl,[FDD_Track] |
827 | mov [old_track],bl |
827 | mov [old_track],bl |
828 | mov ebx,18 |
828 | mov ebx,18 |
829 | xor edx,edx |
829 | xor edx,edx |
830 | div ebx |
830 | div ebx |
831 | inc edx |
831 | inc edx |
832 | mov [FDD_Sector],dl |
832 | mov [FDD_Sector],dl |
833 | xor edx,edx |
833 | xor edx,edx |
834 | mov ebx,2 |
834 | mov ebx,2 |
835 | div ebx |
835 | div ebx |
836 | mov [FDD_Track],al |
836 | mov [FDD_Track],al |
837 | mov [FDD_Head],0 |
837 | mov [FDD_Head],0 |
838 | cmp edx,0 |
838 | cmp edx,0 |
839 | je no_head_2 |
839 | je no_head_2 |
840 | inc [FDD_Head] |
840 | inc [FDD_Head] |
841 | no_head_2: |
841 | no_head_2: |
842 | mov dl,[old_track] |
842 | mov dl,[old_track] |
843 | cmp dl,[FDD_Track] |
843 | cmp dl,[FDD_Track] |
844 | je no_seek_track_1 |
844 | je no_seek_track_1 |
845 | call SeekTrack |
845 | call SeekTrack |
846 | no_seek_track_1: |
846 | no_seek_track_1: |
847 | ret |
847 | ret |
848 | 848 | ||
849 | 849 | ||
850 | get_cluster_of_a_path_flp: |
850 | get_cluster_of_a_path_flp: |
851 | ;--------------------------------------------------------- |
851 | ;--------------------------------------------------------- |
852 | ; input : EBX = pointer to a path string |
852 | ; input : EBX = pointer to a path string |
853 | ; (example: the path "/files/data/document" become |
853 | ; (example: the path "/files/data/document" become |
854 | ; "files......data.......document...0" |
854 | ; "files......data.......document...0" |
855 | ; '.' = space char |
855 | ; '.' = space char |
856 | ; '0' = char(0) (ASCII=0) !!! ) |
856 | ; '0' = char(0) (ASCII=0) !!! ) |
857 | ; output : if (CARRY=1) -> ERROR in the PATH |
857 | ; output : if (CARRY=1) -> ERROR in the PATH |
858 | ; if (CARRY=0) -> EAX=cluster |
858 | ; if (CARRY=0) -> EAX=cluster |
859 | ;--------------------------------------------------------- |
859 | ;--------------------------------------------------------- |
860 | 860 | ||
861 | push edx |
861 | push edx |
862 | mov edx,ebx |
862 | mov edx,ebx |
863 | 863 | ||
864 | search_end_of_path_flp: |
864 | search_end_of_path_flp: |
865 | cmp [save_flag],0 |
865 | cmp [save_flag],0 |
866 | jne search_end_of_path_flp_1 |
866 | jne search_end_of_path_flp_1 |
867 | cmp byte [edx],0 |
867 | cmp byte [edx],0 |
868 | je found_end_of_path_flp |
868 | je found_end_of_path_flp |
869 | jmp search_end_of_path_flp_2 |
869 | jmp search_end_of_path_flp_2 |
870 | search_end_of_path_flp_1: |
870 | search_end_of_path_flp_1: |
871 | cmp byte [edx+12],0 |
871 | cmp byte [edx+12],0 |
872 | je found_end_of_path_flp |
872 | je found_end_of_path_flp |
873 | search_end_of_path_flp_2: |
873 | search_end_of_path_flp_2: |
874 | inc edx ; '/' |
874 | inc edx ; '/' |
875 | call analyze_directory_flp |
875 | call analyze_directory_flp |
876 | jc directory_not_found_flp |
876 | jc directory_not_found_flp |
877 | 877 | ||
878 | mov eax,[ebx+20-2] ; read the HIGH 16bit cluster field |
878 | mov eax,[ebx+20-2] ; read the HIGH 16bit cluster field |
879 | mov ax,[ebx+26] ; read the LOW 16bit cluster field |
879 | mov ax,[ebx+26] ; read the LOW 16bit cluster field |
880 | and eax,0xfff ;[fatMASK] |
880 | and eax,0xfff ;[fatMASK] |
881 | add edx,11 ; 8+3 (name+extension) |
881 | add edx,11 ; 8+3 (name+extension) |
882 | jmp search_end_of_path_flp |
882 | jmp search_end_of_path_flp |
883 | 883 | ||
884 | found_end_of_path_flp: |
884 | found_end_of_path_flp: |
885 | inc edx |
885 | inc edx |
886 | mov [pointer_file_name_flp],edx |
886 | mov [pointer_file_name_flp],edx |
887 | pop edx |
887 | pop edx |
888 | clc ; no errors |
888 | clc ; no errors |
889 | ret |
889 | ret |
890 | 890 | ||
891 | directory_not_found_flp: |
891 | directory_not_found_flp: |
892 | pop edx |
892 | pop edx |
893 | stc ; errors occour |
893 | stc ; errors occour |
894 | ret |
894 | ret |
895 | 895 | ||
896 | analyze_directory_flp: |
896 | analyze_directory_flp: |
897 | ;-------------------------------- |
897 | ;-------------------------------- |
898 | ; input : EAX = first cluster of the directory |
898 | ; input : EAX = first cluster of the directory |
899 | ; EBX = pointer to filename |
899 | ; EBX = pointer to filename |
900 | ; output : IF CARRY=0 EAX = sector where th file is found |
900 | ; output : IF CARRY=0 EAX = sector where th file is found |
901 | ; EBX = pointer in buffer |
901 | ; EBX = pointer in buffer |
902 | ; [buffer .. buffer+511] |
902 | ; [buffer .. buffer+511] |
903 | ; ECX,EDX,EDI,EDI not changed |
903 | ; ECX,EDX,EDI,EDI not changed |
904 | ; IF CARRY=1 |
904 | ; IF CARRY=1 |
905 | ;-------------------------------- |
905 | ;-------------------------------- |
906 | push ebx ;[esp+16] |
906 | push ebx ;[esp+16] |
907 | push ecx |
907 | push ecx |
908 | push edx |
908 | push edx |
909 | push esi |
909 | push esi |
910 | push edi |
910 | push edi |
911 | 911 | ||
912 | 912 | ||
913 | adr56_flp: |
913 | adr56_flp: |
914 | mov [clust_tmp_flp],eax |
914 | mov [clust_tmp_flp],eax |
915 | add eax,31 |
915 | add eax,31 |
916 | pusha |
916 | pusha |
917 | call read_chs_sector |
917 | call read_chs_sector |
918 | popa |
918 | popa |
919 | cmp [FDC_Status],0 |
919 | cmp [FDC_Status],0 |
920 | jne not_found_file_analyze_flp |
920 | jne not_found_file_analyze_flp |
921 | 921 | ||
922 | mov ecx,512/32 |
922 | mov ecx,512/32 |
923 | mov ebx,0xD000 |
923 | mov ebx,0xD000 |
924 | 924 | ||
925 | adr1_analyze_flp: |
925 | adr1_analyze_flp: |
926 | mov esi,edx ;[esp+16] |
926 | mov esi,edx ;[esp+16] |
927 | mov edi,ebx |
927 | mov edi,ebx |
928 | cld |
928 | cld |
929 | push ecx |
929 | push ecx |
930 | mov ecx,11 |
930 | mov ecx,11 |
931 | rep cmpsb |
931 | rep cmpsb |
932 | pop ecx |
932 | pop ecx |
933 | je found_file_analyze_flp |
933 | je found_file_analyze_flp |
934 | 934 | ||
935 | add ebx,32 |
935 | add ebx,32 |
936 | loop adr1_analyze_flp |
936 | loop adr1_analyze_flp |
937 | 937 | ||
938 | mov eax,[clust_tmp_flp] |
938 | mov eax,[clust_tmp_flp] |
939 | shl eax,1 ;find next cluster from FAT |
939 | shl eax,1 ;find next cluster from FAT |
940 | add eax,0x282000 |
940 | add eax,0x282000 |
941 | mov eax,[eax] |
941 | mov eax,[eax] |
942 | and eax,4095 |
942 | and eax,4095 |
943 | cmp eax,0x0ff8 |
943 | cmp eax,0x0ff8 |
944 | jb adr56_flp |
944 | jb adr56_flp |
945 | not_found_file_analyze_flp: |
945 | not_found_file_analyze_flp: |
946 | pop edi |
946 | pop edi |
947 | pop esi |
947 | pop esi |
948 | pop edx |
948 | pop edx |
949 | pop ecx |
949 | pop ecx |
950 | add esp,4 |
950 | add esp,4 |
951 | stc ;file not found |
951 | stc ;file not found |
952 | ret |
952 | ret |
953 | 953 | ||
954 | found_file_analyze_flp: |
954 | found_file_analyze_flp: |
955 | pop edi |
955 | pop edi |
956 | pop esi |
956 | pop esi |
957 | pop edx |
957 | pop edx |
958 | pop ecx |
958 | pop ecx |
959 | add esp,4 |
959 | add esp,4 |
960 | clc ;file found |
960 | clc ;file found |
961 | ret |
961 | ret |
962 | 962 | ||
963 | 963 | ||
964 | analyze_directory_to_write_flp: |
964 | analyze_directory_to_write_flp: |
965 | ;-------------------------------- |
965 | ;-------------------------------- |
966 | ; input : EAX = first cluster of the directory |
966 | ; input : EAX = first cluster of the directory |
967 | ; output : IF CARRY=0 EAX = sector where the file is found |
967 | ; output : IF CARRY=0 EAX = sector where the file is found |
968 | ; EBX = pointer in buffer |
968 | ; EBX = pointer in buffer |
969 | ; [buffer .. buffer+511] |
969 | ; [buffer .. buffer+511] |
970 | ; ECX,EDX,EDI,EDI not changed |
970 | ; ECX,EDX,EDI,EDI not changed |
971 | ; IF CARRY=1 |
971 | ; IF CARRY=1 |
972 | ;-------------------------------- |
972 | ;-------------------------------- |
973 | 973 | ||
974 | push ecx |
974 | push ecx |
975 | push edx |
975 | push edx |
976 | push esi |
976 | push esi |
977 | 977 | ||
978 | adr561: |
978 | adr561: |
979 | mov [clust_tmp_flp],eax |
979 | mov [clust_tmp_flp],eax |
980 | add eax,31 |
980 | add eax,31 |
981 | pusha |
981 | pusha |
982 | call read_chs_sector |
982 | call read_chs_sector |
983 | popa |
983 | popa |
984 | cmp [FDC_Status],0 |
984 | cmp [FDC_Status],0 |
985 | jne error_found_file_analyze1 |
985 | jne error_found_file_analyze1 |
986 | 986 | ||
987 | mov ecx,512/32 |
987 | mov ecx,512/32 |
988 | mov ebx,0xD000 |
988 | mov ebx,0xD000 |
989 | 989 | ||
990 | adr1_analyze1: |
990 | adr1_analyze1: |
991 | cmp byte [ebx],0x00 |
991 | cmp byte [ebx],0x00 |
992 | je found_file_analyze1 |
992 | je found_file_analyze1 |
993 | cmp byte [ebx],0xe5 |
993 | cmp byte [ebx],0xe5 |
994 | je found_file_analyze1 |
994 | je found_file_analyze1 |
995 | 995 | ||
996 | avanti: |
996 | avanti: |
997 | add ebx,32 |
997 | add ebx,32 |
998 | loop adr1_analyze1 |
998 | loop adr1_analyze1 |
999 | 999 | ||
1000 | mov eax,[clust_tmp_flp] |
1000 | mov eax,[clust_tmp_flp] |
1001 | shl eax,1 ;find next cluster from FAT |
1001 | shl eax,1 ;find next cluster from FAT |
1002 | add eax,0x282000 |
1002 | add eax,0x282000 |
1003 | mov eax,[eax] |
1003 | mov eax,[eax] |
1004 | and eax,4095 |
1004 | and eax,4095 |
1005 | cmp eax,0x0ff8 |
1005 | cmp eax,0x0ff8 |
1006 | jb adr561 |
1006 | jb adr561 |
1007 | 1007 | ||
1008 | call get_free_FAT ;this block of code add a new cluster |
1008 | call get_free_FAT ;this block of code add a new cluster |
1009 | ;for the directory because the directory |
1009 | ;for the directory because the directory |
1010 | ;is full |
1010 | ;is full |
1011 | 1011 | ||
1012 | mov [edi],word 0x0fff |
1012 | mov [edi],word 0x0fff |
1013 | 1013 | ||
1014 | mov eax,[clust_tmp_flp] |
1014 | mov eax,[clust_tmp_flp] |
1015 | shl eax,1 ;find next cluster from FAT |
1015 | shl eax,1 ;find next cluster from FAT |
1016 | add eax,0x282000 |
1016 | add eax,0x282000 |
1017 | sub edi,0x282000 |
1017 | sub edi,0x282000 |
1018 | mov [eax],di |
1018 | mov [eax],di |
1019 | 1019 | ||
1020 | pusha |
1020 | pusha |
1021 | mov ecx,512/4 |
1021 | mov ecx,512/4 |
1022 | xor eax,eax |
1022 | xor eax,eax |
1023 | mov edi,0xD000 |
1023 | mov edi,0xD000 |
1024 | cld |
1024 | cld |
1025 | rep stosd |
1025 | rep stosd |
1026 | popa |
1026 | popa |
1027 | 1027 | ||
1028 | mov eax,edi |
1028 | mov eax,edi |
1029 | add eax,31 |
1029 | add eax,31 |
1030 | pusha |
1030 | pusha |
1031 | call save_chs_sector |
1031 | call save_chs_sector |
1032 | popa |
1032 | popa |
1033 | cmp [FDC_Status],0 |
1033 | cmp [FDC_Status],0 |
1034 | jne error_found_file_analyze1 |
1034 | jne error_found_file_analyze1 |
1035 | mov ebx,0xD000 |
1035 | mov ebx,0xD000 |
1036 | 1036 | ||
1037 | found_file_analyze1: |
1037 | found_file_analyze1: |
1038 | 1038 | ||
1039 | pop esi |
1039 | pop esi |
1040 | pop edx |
1040 | pop edx |
1041 | pop ecx |
1041 | pop ecx |
1042 | clc ;file found |
1042 | clc ;file found |
1043 | ret |
1043 | ret |
1044 | 1044 | ||
1045 | error_found_file_analyze1: |
1045 | error_found_file_analyze1: |
1046 | pop esi |
1046 | pop esi |
1047 | pop edx |
1047 | pop edx |
1048 | pop ecx |
1048 | pop ecx |
1049 | stc |
1049 | stc |
1050 | ret |
1050 | ret |
1051 | 1051 | ||
1052 | get_free_FAT_flp: |
1052 | get_free_FAT_flp: |
1053 | ;------------------------------------------ |
1053 | ;------------------------------------------ |
1054 | ; input : EAX = # cluster for start the searching |
1054 | ; input : EAX = # cluster for start the searching |
1055 | ; output : EAX = # first cluster found free |
1055 | ; output : EAX = # first cluster found free |
1056 | ;------------------------------------------- |
1056 | ;------------------------------------------- |
1057 | push ebx |
1057 | push ebx |
1058 | 1058 | ||
1059 | mov ebx,1 |
1059 | mov ebx,1 |
1060 | check_new_flp: |
1060 | check_new_flp: |
1061 | add ebx,1 |
1061 | add ebx,1 |
1062 | mov edi,ebx ; find free cluster in FAT |
1062 | mov edi,ebx ; find free cluster in FAT |
1063 | shl edi,1 |
1063 | shl edi,1 |
1064 | add edi,0x282000 |
1064 | add edi,0x282000 |
1065 | mov eax,[edi] |
1065 | mov eax,[edi] |
1066 | and eax,4095 |
1066 | and eax,4095 |
1067 | cmp eax,0x0 |
1067 | cmp eax,0x0 |
1068 | jnz check_new_flp |
1068 | jnz check_new_flp |
1069 | 1069 | ||
1070 | pop ebx |
1070 | pop ebx |
1071 | ret |
1071 | ret |
1072 | 1072 | ||
1073 | ; \begin{diamond} |
1073 | ; \begin{diamond} |
1074 | fat_find_lfn: |
1074 | fat_find_lfn: |
1075 | ; in: esi->name |
1075 | ; in: esi->name |
1076 | ; [esp+4] = next |
1076 | ; [esp+4] = next |
1077 | ; [esp+8] = first |
1077 | ; [esp+8] = first |
1078 | ; [esp+C]... - possibly parameters for first and next |
1078 | ; [esp+C]... - possibly parameters for first and next |
1079 | ; out: CF=1 - file not found |
1079 | ; out: CF=1 - file not found |
1080 | ; else CF=0, esi->next name component, edi->direntry |
1080 | ; else CF=0, esi->next name component, edi->direntry |
1081 | pusha |
1081 | pusha |
1082 | lea eax, [esp+0Ch+20h] |
1082 | lea eax, [esp+0Ch+20h] |
1083 | call dword [eax-4] |
1083 | call dword [eax-4] |
1084 | jc .reterr |
1084 | jc .reterr |
1085 | sub esp, 262*2 ; reserve place for LFN |
1085 | sub esp, 262*2 ; reserve place for LFN |
1086 | mov ebp, esp |
1086 | mov ebp, esp |
1087 | push 0 ; for fat_get_name: read ASCII name |
1087 | push 0 ; for fat_get_name: read ASCII name |
1088 | .l1: |
1088 | .l1: |
1089 | call fat_get_name |
1089 | call fat_get_name |
1090 | jc .l2 |
1090 | jc .l2 |
1091 | call fat_compare_name |
1091 | call fat_compare_name |
1092 | jz .found |
1092 | jz .found |
1093 | .l2: |
1093 | .l2: |
1094 | lea eax, [esp+0Ch+20h+262*2+4] |
1094 | lea eax, [esp+0Ch+20h+262*2+4] |
1095 | call dword [eax-8] |
1095 | call dword [eax-8] |
1096 | jnc .l1 |
1096 | jnc .l1 |
1097 | add esp, 262*2+4 |
1097 | add esp, 262*2+4 |
1098 | .reterr: |
1098 | .reterr: |
1099 | stc |
1099 | stc |
1100 | popa |
1100 | popa |
1101 | ret |
1101 | ret |
1102 | .found: |
1102 | .found: |
1103 | add esp, 262*2+4 |
1103 | add esp, 262*2+4 |
1104 | ; if this is LFN entry, advance to true entry |
1104 | ; if this is LFN entry, advance to true entry |
1105 | cmp byte [edi+11], 0xF |
1105 | cmp byte [edi+11], 0xF |
1106 | jnz @f |
1106 | jnz @f |
1107 | lea eax, [esp+0Ch+20h] |
1107 | lea eax, [esp+0Ch+20h] |
1108 | call dword [eax-8] |
1108 | call dword [eax-8] |
1109 | jc .reterr |
1109 | jc .reterr |
1110 | @@: |
1110 | @@: |
1111 | add esp, 8 ; CF=0 |
1111 | add esp, 8 ; CF=0 |
1112 | push esi |
1112 | push esi |
1113 | push edi |
1113 | push edi |
1114 | popa |
1114 | popa |
1115 | ret |
1115 | ret |
1116 | 1116 | ||
1117 | flp_root_next: |
1117 | flp_root_next: |
1118 | cmp edi, 0xD200-0x20 |
1118 | cmp edi, 0xD200-0x20 |
1119 | jae @f |
1119 | jae @f |
1120 | add edi, 0x20 |
1120 | add edi, 0x20 |
1121 | ret ; CF=0 |
1121 | ret ; CF=0 |
1122 | @@: |
1122 | @@: |
1123 | ; read next sector |
1123 | ; read next sector |
1124 | inc dword [eax] |
1124 | inc dword [eax] |
1125 | cmp dword [eax], 14 |
1125 | cmp dword [eax], 14 |
1126 | jae flp_root_first.readerr |
1126 | jae flp_root_first.readerr |
1127 | flp_root_first: |
1127 | flp_root_first: |
1128 | mov eax, [eax] |
1128 | mov eax, [eax] |
1129 | pusha |
1129 | pusha |
1130 | add eax, 19 |
1130 | add eax, 19 |
1131 | call read_chs_sector |
1131 | call read_chs_sector |
1132 | popa |
1132 | popa |
1133 | cmp [FDC_Status], 0 |
1133 | cmp [FDC_Status], 0 |
1134 | jnz .readerr |
1134 | jnz .readerr |
1135 | mov edi, 0xD000 |
1135 | mov edi, 0xD000 |
1136 | ret ; CF=0 |
1136 | ret ; CF=0 |
1137 | .readerr: |
1137 | .readerr: |
1138 | stc |
1138 | stc |
1139 | ret |
1139 | ret |
1140 | 1140 | ||
1141 | flp_rootmem_first: |
1141 | flp_rootmem_first: |
1142 | mov edi, 0x8000 |
1142 | mov edi, 0x8000 |
1143 | clc |
1143 | clc |
1144 | ret |
1144 | ret |
1145 | flp_rootmem_next: |
1145 | flp_rootmem_next: |
1146 | add edi, 0x20 |
1146 | add edi, 0x20 |
1147 | cmp edi, 0x8000+14*0x200 |
1147 | cmp edi, 0x8000+14*0x200 |
1148 | cmc |
1148 | cmc |
1149 | flp_rootmem_next_write: |
1149 | flp_rootmem_next_write: |
1150 | flp_rootmem_begin_write: |
1150 | flp_rootmem_begin_write: |
1151 | flp_rootmem_end_write: |
1151 | flp_rootmem_end_write: |
1152 | ret |
1152 | ret |
1153 | flp_rootmem_extend_dir: |
1153 | flp_rootmem_extend_dir: |
1154 | stc |
1154 | stc |
1155 | ret |
1155 | ret |
1156 | 1156 | ||
1157 | flp_notroot_next: |
1157 | flp_notroot_next: |
1158 | cmp edi, 0xD200-0x20 |
1158 | cmp edi, 0xD200-0x20 |
1159 | jae flp_notroot_next_sector |
1159 | jae flp_notroot_next_sector |
1160 | add edi, 0x20 |
1160 | add edi, 0x20 |
1161 | ret ; CF=0 |
1161 | ret ; CF=0 |
1162 | flp_notroot_next_sector: |
1162 | flp_notroot_next_sector: |
1163 | push ecx |
1163 | push ecx |
1164 | mov ecx, [eax] |
1164 | mov ecx, [eax] |
1165 | mov ecx, [ecx*2+0x282000] |
1165 | mov ecx, [ecx*2+0x282000] |
1166 | and ecx, 0xFFF |
1166 | and ecx, 0xFFF |
1167 | cmp ecx, 2849 |
1167 | cmp ecx, 2849 |
1168 | jae flp_notroot_first.err2 |
1168 | jae flp_notroot_first.err2 |
1169 | mov [eax], ecx |
1169 | mov [eax], ecx |
1170 | pop ecx |
1170 | pop ecx |
1171 | flp_notroot_first: |
1171 | flp_notroot_first: |
1172 | mov eax, [eax] |
1172 | mov eax, [eax] |
1173 | cmp eax, 2 |
1173 | cmp eax, 2 |
1174 | jb .err |
1174 | jb .err |
1175 | cmp eax, 2849 |
1175 | cmp eax, 2849 |
1176 | jae .err |
1176 | jae .err |
1177 | pusha |
1177 | pusha |
1178 | add eax, 31 |
1178 | add eax, 31 |
1179 | call read_chs_sector |
1179 | call read_chs_sector |
1180 | popa |
1180 | popa |
1181 | mov edi, 0xD000 |
1181 | mov edi, 0xD000 |
1182 | cmp [FDC_Status], 0 |
1182 | cmp [FDC_Status], 0 |
1183 | jnz .err |
1183 | jnz .err |
1184 | ret ; CF=0 |
1184 | ret ; CF=0 |
1185 | .err2: |
1185 | .err2: |
1186 | pop ecx |
1186 | pop ecx |
1187 | .err: |
1187 | .err: |
1188 | stc |
1188 | stc |
1189 | ret |
1189 | ret |
1190 | flp_notroot_begin_write: |
1190 | flp_notroot_begin_write: |
1191 | pusha |
1191 | pusha |
1192 | mov eax, [eax] |
1192 | mov eax, [eax] |
1193 | add eax, 31 |
1193 | add eax, 31 |
1194 | call read_chs_sector |
1194 | call read_chs_sector |
1195 | popa |
1195 | popa |
1196 | ret |
1196 | ret |
1197 | flp_notroot_end_write: |
1197 | flp_notroot_end_write: |
1198 | pusha |
1198 | pusha |
1199 | mov eax, [eax] |
1199 | mov eax, [eax] |
1200 | add eax, 31 |
1200 | add eax, 31 |
1201 | call save_chs_sector |
1201 | call save_chs_sector |
1202 | popa |
1202 | popa |
1203 | ret |
1203 | ret |
1204 | flp_notroot_next_write: |
1204 | flp_notroot_next_write: |
1205 | cmp edi, 0xD200 |
1205 | cmp edi, 0xD200 |
1206 | jae @f |
1206 | jae @f |
1207 | ret |
1207 | ret |
1208 | @@: |
1208 | @@: |
1209 | call flp_notroot_end_write |
1209 | call flp_notroot_end_write |
1210 | jmp flp_notroot_next_sector |
1210 | jmp flp_notroot_next_sector |
1211 | flp_notroot_extend_dir: |
1211 | flp_notroot_extend_dir: |
1212 | ; find free cluster in FAT |
1212 | ; find free cluster in FAT |
1213 | pusha |
1213 | pusha |
1214 | xor eax, eax |
1214 | xor eax, eax |
1215 | mov edi, 0x282000 |
1215 | mov edi, 0x282000 |
1216 | mov ecx, 2849 |
1216 | mov ecx, 2849 |
1217 | repnz scasw |
1217 | repnz scasw |
1218 | jnz .notfound |
1218 | jnz .notfound |
1219 | mov word [edi-2], 0xFFF ; mark as last cluster |
1219 | mov word [edi-2], 0xFFF ; mark as last cluster |
1220 | sub edi, 0x282000 |
1220 | sub edi, 0x282000 |
1221 | shr edi, 1 |
1221 | shr edi, 1 |
1222 | dec edi |
1222 | dec edi |
1223 | mov eax, [esp+28] |
1223 | mov eax, [esp+28] |
1224 | mov ecx, [eax] |
1224 | mov ecx, [eax] |
1225 | mov [0x282000+ecx*2], di |
1225 | mov [0x282000+ecx*2], di |
1226 | mov [eax], edi |
1226 | mov [eax], edi |
1227 | xor eax, eax |
1227 | xor eax, eax |
1228 | mov edi, 0xD000 |
1228 | mov edi, 0xD000 |
1229 | mov ecx, 128 |
1229 | mov ecx, 128 |
1230 | rep stosd |
1230 | rep stosd |
1231 | popa |
1231 | popa |
1232 | call flp_notroot_end_write |
1232 | call flp_notroot_end_write |
1233 | mov edi, 0xD000 |
1233 | mov edi, 0xD000 |
1234 | clc |
1234 | clc |
1235 | ret |
1235 | ret |
1236 | .notfound: |
1236 | .notfound: |
1237 | popa |
1237 | popa |
1238 | stc |
1238 | stc |
1239 | ret |
1239 | ret |
1240 | 1240 | ||
1241 | fd_find_lfn: |
1241 | fd_find_lfn: |
1242 | ; in: esi->name |
1242 | ; in: esi->name |
1243 | ; out: CF=1 - file not found |
1243 | ; out: CF=1 - file not found |
1244 | ; else CF=0 and edi->direntry |
1244 | ; else CF=0 and edi->direntry, eax=directory cluster (0 for root) |
1245 | push esi edi |
1245 | push esi edi |
1246 | push 0 |
1246 | push 0 |
1247 | push flp_root_first |
1247 | push flp_root_first |
1248 | push flp_root_next |
1248 | push flp_root_next |
1249 | .loop: |
1249 | .loop: |
1250 | call fat_find_lfn |
1250 | call fat_find_lfn |
1251 | jc .notfound |
1251 | jc .notfound |
1252 | cmp byte [esi], 0 |
1252 | cmp byte [esi], 0 |
1253 | jz .found |
1253 | jz .found |
1254 | test byte [edi+11], 10h |
1254 | test byte [edi+11], 10h |
1255 | jz .notfound |
1255 | jz .notfound |
1256 | movzx eax, word [edi+26] ; cluster |
1256 | movzx eax, word [edi+26] ; cluster |
1257 | mov [esp+8], eax |
1257 | mov [esp+8], eax |
1258 | mov dword [esp+4], flp_notroot_first |
1258 | mov dword [esp+4], flp_notroot_first |
1259 | mov dword [esp], flp_notroot_next |
1259 | mov dword [esp], flp_notroot_next |
1260 | jmp .loop |
1260 | jmp .loop |
1261 | .notfound: |
1261 | .notfound: |
1262 | add esp, 12 |
1262 | add esp, 12 |
1263 | pop edi esi |
1263 | pop edi esi |
1264 | stc |
1264 | stc |
1265 | ret |
1265 | ret |
1266 | .found: |
1266 | .found: |
- | 1267 | mov eax, [esp+8] |
|
1267 | add esp, 16 ; CF=0 |
1268 | add esp, 16 ; CF=0 |
1268 | pop esi |
1269 | pop esi |
1269 | ret |
1270 | ret |
1270 | 1271 | ||
1271 | ;---------------------------------------------------------------- |
1272 | ;---------------------------------------------------------------- |
1272 | ; |
1273 | ; |
1273 | ; fs_FloppyRead - LFN variant for reading floppy |
1274 | ; fs_FloppyRead - LFN variant for reading floppy |
1274 | ; |
1275 | ; |
1275 | ; esi points to filename |
1276 | ; esi points to filename |
1276 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
1277 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
1277 | ; may be ebx=0 - start from first byte |
1278 | ; may be ebx=0 - start from first byte |
1278 | ; ecx number of bytes to read, 0+ |
1279 | ; ecx number of bytes to read, 0+ |
1279 | ; edx mem location to return data |
1280 | ; edx mem location to return data |
1280 | ; |
1281 | ; |
1281 | ; ret ebx = bytes read or 0xffffffff file not found |
1282 | ; ret ebx = bytes read or 0xffffffff file not found |
1282 | ; eax = 0 ok read or other = errormsg |
1283 | ; eax = 0 ok read or other = errormsg |
1283 | ; |
1284 | ; |
1284 | ;-------------------------------------------------------------- |
1285 | ;-------------------------------------------------------------- |
1285 | fs_FloppyRead: |
1286 | fs_FloppyRead: |
1286 | call read_flp_fat |
1287 | call read_flp_fat |
1287 | cmp byte [esi], 0 |
1288 | cmp byte [esi], 0 |
1288 | jnz @f |
1289 | jnz @f |
1289 | or ebx, -1 |
1290 | or ebx, -1 |
1290 | mov eax, 10 ; access denied |
1291 | mov eax, 10 ; access denied |
1291 | ret |
1292 | ret |
1292 | @@: |
1293 | @@: |
1293 | push edi |
1294 | push edi |
1294 | call fd_find_lfn |
1295 | call fd_find_lfn |
1295 | jnc .found |
1296 | jnc .found |
1296 | pop edi |
1297 | pop edi |
1297 | or ebx, -1 |
1298 | or ebx, -1 |
1298 | mov eax, 5 ; file not found |
1299 | mov eax, 5 ; file not found |
1299 | ret |
1300 | ret |
1300 | .found: |
1301 | .found: |
1301 | test ebx, ebx |
1302 | test ebx, ebx |
1302 | jz .l1 |
1303 | jz .l1 |
1303 | cmp dword [ebx+4], 0 |
1304 | cmp dword [ebx+4], 0 |
1304 | jz @f |
1305 | jz @f |
1305 | xor ebx, ebx |
1306 | xor ebx, ebx |
1306 | .reteof: |
1307 | .reteof: |
1307 | mov eax, 6 ; EOF |
1308 | mov eax, 6 ; EOF |
1308 | pop edi |
1309 | pop edi |
1309 | ret |
1310 | ret |
1310 | @@: |
1311 | @@: |
1311 | mov ebx, [ebx] |
1312 | mov ebx, [ebx] |
1312 | .l1: |
1313 | .l1: |
1313 | push ecx edx |
1314 | push ecx edx |
1314 | push 0 |
1315 | push 0 |
1315 | mov eax, [edi+28] |
1316 | mov eax, [edi+28] |
1316 | sub eax, ebx |
1317 | sub eax, ebx |
1317 | jb .eof |
1318 | jb .eof |
1318 | cmp eax, ecx |
1319 | cmp eax, ecx |
1319 | jae @f |
1320 | jae @f |
1320 | mov ecx, eax |
1321 | mov ecx, eax |
1321 | mov byte [esp], 6 ; EOF |
1322 | mov byte [esp], 6 ; EOF |
1322 | @@: |
1323 | @@: |
1323 | movzx edi, word [edi+26] |
1324 | movzx edi, word [edi+26] |
1324 | .new: |
1325 | .new: |
1325 | jecxz .done |
1326 | jecxz .done |
1326 | test edi, edi |
1327 | test edi, edi |
1327 | jz .eof |
1328 | jz .eof |
1328 | cmp edi, 0xFF8 |
1329 | cmp edi, 0xFF8 |
1329 | jae .eof |
1330 | jae .eof |
1330 | lea eax, [edi+31] |
1331 | lea eax, [edi+31] |
1331 | pusha |
1332 | pusha |
1332 | call read_chs_sector |
1333 | call read_chs_sector |
1333 | popa |
1334 | popa |
1334 | cmp [FDC_Status], 0 |
1335 | cmp [FDC_Status], 0 |
1335 | jnz .err |
1336 | jnz .err |
1336 | sub ebx, 512 |
1337 | sub ebx, 512 |
1337 | jae .skip |
1338 | jae .skip |
1338 | lea eax, [0xD000+ebx+512] |
1339 | lea eax, [0xD000+ebx+512] |
1339 | neg ebx |
1340 | neg ebx |
1340 | push ecx |
1341 | push ecx |
1341 | cmp ecx, ebx |
1342 | cmp ecx, ebx |
1342 | jbe @f |
1343 | jbe @f |
1343 | mov ecx, ebx |
1344 | mov ecx, ebx |
1344 | @@: |
1345 | @@: |
1345 | mov ebx, edx |
1346 | mov ebx, edx |
1346 | call memmove |
1347 | call memmove |
1347 | add edx, ecx |
1348 | add edx, ecx |
1348 | sub [esp], ecx |
1349 | sub [esp], ecx |
1349 | pop ecx |
1350 | pop ecx |
1350 | xor ebx, ebx |
1351 | xor ebx, ebx |
1351 | .skip: |
1352 | .skip: |
1352 | movzx edi, word [edi*2+0x282000] |
1353 | movzx edi, word [edi*2+0x282000] |
1353 | jmp .new |
1354 | jmp .new |
1354 | .done: |
1355 | .done: |
1355 | mov ebx, edx |
1356 | mov ebx, edx |
1356 | pop eax edx ecx edi |
1357 | pop eax edx ecx edi |
1357 | sub ebx, edx |
1358 | sub ebx, edx |
1358 | ret |
1359 | ret |
1359 | .eof: |
1360 | .eof: |
1360 | mov ebx, edx |
1361 | mov ebx, edx |
1361 | pop eax edx ecx |
1362 | pop eax edx ecx |
1362 | jmp .reteof |
1363 | jmp .reteof |
1363 | .err: |
1364 | .err: |
1364 | mov ebx, edx |
1365 | mov ebx, edx |
1365 | pop eax edx ecx edi |
1366 | pop eax edx ecx edi |
1366 | sub ebx, edx |
1367 | sub ebx, edx |
1367 | mov al, 11 |
1368 | mov al, 11 |
1368 | ret |
1369 | ret |
1369 | 1370 | ||
1370 | ;---------------------------------------------------------------- |
1371 | ;---------------------------------------------------------------- |
1371 | ; |
1372 | ; |
1372 | ; fs_FloppyReadFolder - LFN variant for reading floppy folders |
1373 | ; fs_FloppyReadFolder - LFN variant for reading floppy folders |
1373 | ; |
1374 | ; |
1374 | ; esi points to filename |
1375 | ; esi points to filename |
1375 | ; ebx pointer to structure: 32-bit number = first wanted block, 0+ |
1376 | ; ebx pointer to structure: 32-bit number = first wanted block, 0+ |
1376 | ; & flags (bitfields) |
1377 | ; & flags (bitfields) |
1377 | ; flags: bit 0: 0=ANSI names, 1=UNICODE names |
1378 | ; flags: bit 0: 0=ANSI names, 1=UNICODE names |
1378 | ; ecx number of blocks to read, 0+ |
1379 | ; ecx number of blocks to read, 0+ |
1379 | ; edx mem location to return data |
1380 | ; edx mem location to return data |
1380 | ; |
1381 | ; |
1381 | ; ret ebx = blocks read or 0xffffffff folder not found |
1382 | ; ret ebx = blocks read or 0xffffffff folder not found |
1382 | ; eax = 0 ok read or other = errormsg |
1383 | ; eax = 0 ok read or other = errormsg |
1383 | ; |
1384 | ; |
1384 | ;-------------------------------------------------------------- |
1385 | ;-------------------------------------------------------------- |
1385 | fs_FloppyReadFolder: |
1386 | fs_FloppyReadFolder: |
1386 | call read_flp_fat |
1387 | call read_flp_fat |
1387 | push edi |
1388 | push edi |
1388 | cmp byte [esi], 0 |
1389 | cmp byte [esi], 0 |
1389 | jz .root |
1390 | jz .root |
1390 | call fd_find_lfn |
1391 | call fd_find_lfn |
1391 | jnc .found |
1392 | jnc .found |
1392 | pop edi |
1393 | pop edi |
1393 | or ebx, -1 |
1394 | or ebx, -1 |
1394 | mov eax, ERROR_FILE_NOT_FOUND |
1395 | mov eax, ERROR_FILE_NOT_FOUND |
1395 | ret |
1396 | ret |
1396 | .found: |
1397 | .found: |
1397 | test byte [edi+11], 0x10 ; do not allow read files |
1398 | test byte [edi+11], 0x10 ; do not allow read files |
1398 | jnz .found_dir |
1399 | jnz .found_dir |
1399 | pop edi |
1400 | pop edi |
1400 | or ebx, -1 |
1401 | or ebx, -1 |
1401 | mov eax, ERROR_ACCESS_DENIED |
1402 | mov eax, ERROR_ACCESS_DENIED |
1402 | ret |
1403 | ret |
1403 | .found_dir: |
1404 | .found_dir: |
1404 | movzx eax, word [edi+26] |
1405 | movzx eax, word [edi+26] |
1405 | add eax, 31 |
1406 | add eax, 31 |
1406 | push 0 |
1407 | push 0 |
1407 | jmp .doit |
1408 | jmp .doit |
1408 | .root: |
1409 | .root: |
1409 | mov eax, 19 |
1410 | mov eax, 19 |
1410 | push 14 |
1411 | push 14 |
1411 | .doit: |
1412 | .doit: |
1412 | push ecx ebp |
1413 | push ecx ebp |
1413 | sub esp, 262*2 ; reserve space for LFN |
1414 | sub esp, 262*2 ; reserve space for LFN |
1414 | mov ebp, esp |
1415 | mov ebp, esp |
1415 | push dword [ebx+4] ; for fat_get_name: read ANSI/UNICODE names |
1416 | push dword [ebx+4] ; for fat_get_name: read ANSI/UNICODE names |
1416 | mov ebx, [ebx] |
1417 | mov ebx, [ebx] |
1417 | ; init header |
1418 | ; init header |
1418 | push eax ecx |
1419 | push eax ecx |
1419 | mov edi, edx |
1420 | mov edi, edx |
1420 | mov ecx, 32/4 |
1421 | mov ecx, 32/4 |
1421 | xor eax, eax |
1422 | xor eax, eax |
1422 | rep stosd |
1423 | rep stosd |
1423 | pop ecx eax |
1424 | pop ecx eax |
1424 | mov byte [edx], 1 ; version |
1425 | mov byte [edx], 1 ; version |
1425 | mov esi, edi ; esi points to BDFE |
1426 | mov esi, edi ; esi points to BDFE |
1426 | .main_loop: |
1427 | .main_loop: |
1427 | pusha |
1428 | pusha |
1428 | call read_chs_sector |
1429 | call read_chs_sector |
1429 | popa |
1430 | popa |
1430 | cmp [FDC_Status], 0 |
1431 | cmp [FDC_Status], 0 |
1431 | jnz .error |
1432 | jnz .error |
1432 | mov edi, 0xD000 |
1433 | mov edi, 0xD000 |
1433 | push eax |
1434 | push eax |
1434 | .l1: |
1435 | .l1: |
1435 | call fat_get_name |
1436 | call fat_get_name |
1436 | jc .l2 |
1437 | jc .l2 |
1437 | cmp byte [edi+11], 0xF |
1438 | cmp byte [edi+11], 0xF |
1438 | jnz .do_bdfe |
1439 | jnz .do_bdfe |
1439 | add edi, 0x20 |
1440 | add edi, 0x20 |
1440 | cmp edi, 0xD200 |
1441 | cmp edi, 0xD200 |
1441 | jb .do_bdfe |
1442 | jb .do_bdfe |
1442 | pop eax |
1443 | pop eax |
1443 | inc eax |
1444 | inc eax |
1444 | dec byte [esp+262*2+12] |
1445 | dec byte [esp+262*2+12] |
1445 | jz .done |
1446 | jz .done |
1446 | jns @f |
1447 | jns @f |
1447 | ; read next sector from FAT |
1448 | ; read next sector from FAT |
1448 | mov eax, [(eax-31-1)*2+0x282000] |
1449 | mov eax, [(eax-31-1)*2+0x282000] |
1449 | and eax, 0xFFF |
1450 | and eax, 0xFFF |
1450 | cmp eax, 0xFF8 |
1451 | cmp eax, 0xFF8 |
1451 | jae .done |
1452 | jae .done |
1452 | add eax, 31 |
1453 | add eax, 31 |
1453 | mov byte [esp+262*2+12], 0 |
1454 | mov byte [esp+262*2+12], 0 |
1454 | @@: |
1455 | @@: |
1455 | pusha |
1456 | pusha |
1456 | call read_chs_sector |
1457 | call read_chs_sector |
1457 | popa |
1458 | popa |
1458 | cmp [FDC_Status], 0 |
1459 | cmp [FDC_Status], 0 |
1459 | jnz .error |
1460 | jnz .error |
1460 | mov edi, 0xD000 |
1461 | mov edi, 0xD000 |
1461 | push eax |
1462 | push eax |
1462 | .do_bdfe: |
1463 | .do_bdfe: |
1463 | inc dword [edx+8] ; new file found |
1464 | inc dword [edx+8] ; new file found |
1464 | dec ebx |
1465 | dec ebx |
1465 | jns .l2 |
1466 | jns .l2 |
1466 | dec ecx |
1467 | dec ecx |
1467 | js .l2 |
1468 | js .l2 |
1468 | inc dword [edx+4] ; new file block copied |
1469 | inc dword [edx+4] ; new file block copied |
1469 | call fat_entry_to_bdfe |
1470 | call fat_entry_to_bdfe |
1470 | .l2: |
1471 | .l2: |
1471 | add edi, 0x20 |
1472 | add edi, 0x20 |
1472 | cmp edi, 0xD200 |
1473 | cmp edi, 0xD200 |
1473 | jb .l1 |
1474 | jb .l1 |
1474 | pop eax |
1475 | pop eax |
1475 | inc eax |
1476 | inc eax |
1476 | dec byte [esp+262*2+12] |
1477 | dec byte [esp+262*2+12] |
1477 | jz .done |
1478 | jz .done |
1478 | jns @f |
1479 | jns @f |
1479 | ; read next sector from FAT |
1480 | ; read next sector from FAT |
1480 | mov eax, [(eax-31-1)*2+0x282000] |
1481 | mov eax, [(eax-31-1)*2+0x282000] |
1481 | and eax, 0xFFF |
1482 | and eax, 0xFFF |
1482 | cmp eax, 0xFF8 |
1483 | cmp eax, 0xFF8 |
1483 | jae .done |
1484 | jae .done |
1484 | add eax, 31 |
1485 | add eax, 31 |
1485 | mov byte [esp+262*2+12], 0 |
1486 | mov byte [esp+262*2+12], 0 |
1486 | @@: |
1487 | @@: |
1487 | jmp .main_loop |
1488 | jmp .main_loop |
1488 | .error: |
1489 | .error: |
1489 | add esp, 262*2+4 |
1490 | add esp, 262*2+4 |
1490 | pop ebp ecx edi edi |
1491 | pop ebp ecx edi edi |
1491 | or ebx, -1 |
1492 | or ebx, -1 |
1492 | mov eax, ERROR_FILE_NOT_FOUND |
1493 | mov eax, ERROR_FILE_NOT_FOUND |
1493 | ret |
1494 | ret |
1494 | .done: |
1495 | .done: |
1495 | add esp, 262*2+4 |
1496 | add esp, 262*2+4 |
1496 | pop ebp |
1497 | pop ebp |
1497 | mov ebx, [edx+4] |
1498 | mov ebx, [edx+4] |
1498 | xor eax, eax |
1499 | xor eax, eax |
1499 | dec ecx |
1500 | dec ecx |
1500 | js @f |
1501 | js @f |
1501 | mov al, ERROR_END_OF_FILE |
1502 | mov al, ERROR_END_OF_FILE |
1502 | @@: |
1503 | @@: |
1503 | pop ecx edi edi |
1504 | pop ecx edi edi |
1504 | ret |
1505 | ret |
1505 | 1506 | ||
1506 | ;---------------------------------------------------------------- |
1507 | ;---------------------------------------------------------------- |
1507 | ; |
1508 | ; |
1508 | ; fs_FloppyRewrite - LFN variant for writing sys floppy |
1509 | ; fs_FloppyRewrite - LFN variant for writing sys floppy |
1509 | ; |
1510 | ; |
1510 | ; esi points to filename |
1511 | ; esi points to filename |
1511 | ; ebx ignored (reserved) |
1512 | ; ebx ignored (reserved) |
1512 | ; ecx number of bytes to write, 0+ |
1513 | ; ecx number of bytes to write, 0+ |
1513 | ; edx mem location to data |
1514 | ; edx mem location to data |
1514 | ; |
1515 | ; |
1515 | ; ret ebx = number of written bytes |
1516 | ; ret ebx = number of written bytes |
1516 | ; eax = 0 ok read or other = errormsg |
1517 | ; eax = 0 ok read or other = errormsg |
1517 | ; |
1518 | ; |
1518 | ;-------------------------------------------------------------- |
1519 | ;-------------------------------------------------------------- |
1519 | @@: |
1520 | @@: |
1520 | mov eax, ERROR_ACCESS_DENIED |
1521 | mov eax, ERROR_ACCESS_DENIED |
1521 | xor ebx, ebx |
1522 | xor ebx, ebx |
1522 | ret |
1523 | ret |
1523 | fsfrfe2: |
1524 | fsfrfe2: |
1524 | popad |
1525 | popad |
1525 | fsfrfe: |
1526 | fsfrfe: |
1526 | mov eax, 11 |
1527 | mov eax, 11 |
1527 | xor ebx, ebx |
1528 | xor ebx, ebx |
1528 | ret |
1529 | ret |
1529 | 1530 | ||
1530 | fs_FloppyRewrite: |
1531 | fs_FloppyRewrite: |
1531 | cmp byte [esi], 0 |
1532 | cmp byte [esi], 0 |
1532 | jz @b |
1533 | jz @b |
1533 | call read_flp_fat |
1534 | call read_flp_fat |
1534 | cmp [FDC_Status], 0 |
1535 | cmp [FDC_Status], 0 |
1535 | jnz fsfrfe |
1536 | jnz fsfrfe |
1536 | pushad |
1537 | pushad |
1537 | xor ebp, ebp |
1538 | xor ebp, ebp |
1538 | push esi |
1539 | push esi |
1539 | @@: |
1540 | @@: |
1540 | lodsb |
1541 | lodsb |
1541 | test al, al |
1542 | test al, al |
1542 | jz @f |
1543 | jz @f |
1543 | cmp al, '/' |
1544 | cmp al, '/' |
1544 | jnz @b |
1545 | jnz @b |
1545 | lea ebp, [esi-1] |
1546 | lea ebp, [esi-1] |
1546 | jmp @b |
1547 | jmp @b |
1547 | @@: |
1548 | @@: |
1548 | pop esi |
1549 | pop esi |
1549 | test ebp, ebp |
1550 | test ebp, ebp |
1550 | jnz .noroot |
1551 | jnz .noroot |
1551 | call read_flp_root |
1552 | call read_flp_root |
1552 | cmp [FDC_Status], 0 |
1553 | cmp [FDC_Status], 0 |
1553 | jnz fsfrfe2 |
1554 | jnz fsfrfe2 |
1554 | push flp_rootmem_extend_dir |
1555 | push flp_rootmem_extend_dir |
1555 | push flp_rootmem_end_write |
1556 | push flp_rootmem_end_write |
1556 | push flp_rootmem_next_write |
1557 | push flp_rootmem_next_write |
1557 | push flp_rootmem_begin_write |
1558 | push flp_rootmem_begin_write |
1558 | xor ebp, ebp |
1559 | xor ebp, ebp |
1559 | push ebp |
1560 | push ebp |
1560 | push flp_rootmem_first |
1561 | push flp_rootmem_first |
1561 | push flp_rootmem_next |
1562 | push flp_rootmem_next |
1562 | jmp .common1 |
1563 | jmp .common1 |
1563 | .noroot: |
1564 | .noroot: |
1564 | ; check existence |
1565 | ; check existence |
1565 | mov byte [ebp], 0 |
1566 | mov byte [ebp], 0 |
1566 | call fd_find_lfn |
1567 | call fd_find_lfn |
1567 | mov byte [ebp], '/' |
1568 | mov byte [ebp], '/' |
1568 | lea esi, [ebp+1] |
1569 | lea esi, [ebp+1] |
1569 | jnc @f |
1570 | jnc @f |
1570 | mov eax, ERROR_FILE_NOT_FOUND |
1571 | mov eax, ERROR_FILE_NOT_FOUND |
1571 | .ret1: |
1572 | .ret1: |
1572 | mov [esp+28], eax |
1573 | mov [esp+28], eax |
1573 | popad |
1574 | popad |
1574 | xor ebx, ebx |
1575 | xor ebx, ebx |
1575 | ret |
1576 | ret |
1576 | @@: |
1577 | @@: |
1577 | test byte [edi+11], 0x10 ; must be directory |
1578 | test byte [edi+11], 0x10 ; must be directory |
1578 | mov eax, ERROR_ACCESS_DENIED |
1579 | mov eax, ERROR_ACCESS_DENIED |
1579 | jz .ret1 |
1580 | jz .ret1 |
1580 | movzx ebp, word [edi+26] ; ebp=cluster |
1581 | movzx ebp, word [edi+26] ; ebp=cluster |
1581 | mov eax, ERROR_FAT_TABLE |
1582 | mov eax, ERROR_FAT_TABLE |
1582 | cmp ebp, 2 |
1583 | cmp ebp, 2 |
1583 | jb .ret1 |
1584 | jb .ret1 |
1584 | cmp ebp, 2849 |
1585 | cmp ebp, 2849 |
1585 | jae .ret1 |
1586 | jae .ret1 |
1586 | push flp_notroot_extend_dir |
1587 | push flp_notroot_extend_dir |
1587 | push flp_notroot_end_write |
1588 | push flp_notroot_end_write |
1588 | push flp_notroot_next_write |
1589 | push flp_notroot_next_write |
1589 | push flp_notroot_begin_write |
1590 | push flp_notroot_begin_write |
1590 | push ebp |
1591 | push ebp |
1591 | push flp_notroot_first |
1592 | push flp_notroot_first |
1592 | push flp_notroot_next |
1593 | push flp_notroot_next |
1593 | .common1: |
1594 | .common1: |
1594 | call fat_find_lfn |
1595 | call fat_find_lfn |
1595 | jc .notfound |
1596 | jc .notfound |
1596 | ; found, delete FAT chain |
1597 | ; found, delete FAT chain |
1597 | push edi |
1598 | push edi |
1598 | xor eax, eax |
1599 | xor eax, eax |
1599 | mov dword [edi+28], eax ; zero size |
1600 | mov dword [edi+28], eax ; zero size |
1600 | xchg ax, word [edi+26] ; start cluster |
1601 | xchg ax, word [edi+26] ; start cluster |
1601 | test eax, eax |
1602 | test eax, eax |
1602 | jz .done1 |
1603 | jz .done1 |
1603 | @@: |
1604 | @@: |
1604 | cmp eax, 0xFF8 |
1605 | cmp eax, 0xFF8 |
1605 | jae .done1 |
1606 | jae .done1 |
1606 | lea edi, [0x282000 + eax*2] ; position in FAT |
1607 | lea edi, [0x282000 + eax*2] ; position in FAT |
1607 | xor eax, eax |
1608 | xor eax, eax |
1608 | xchg ax, [edi] |
1609 | xchg ax, [edi] |
1609 | jmp @b |
1610 | jmp @b |
1610 | .done1: |
1611 | .done1: |
1611 | pop edi |
1612 | pop edi |
1612 | call get_time_for_file |
1613 | call get_time_for_file |
1613 | mov [edi+22], ax |
1614 | mov [edi+22], ax |
1614 | call get_date_for_file |
1615 | call get_date_for_file |
1615 | mov [edi+24], ax |
1616 | mov [edi+24], ax |
1616 | mov [edi+18], ax |
1617 | mov [edi+18], ax |
1617 | or byte [edi+11], 20h ; set 'archive' attribute |
1618 | or byte [edi+11], 20h ; set 'archive' attribute |
1618 | jmp .doit |
1619 | jmp .doit |
1619 | .notfound: |
1620 | .notfound: |
1620 | ; file is not found; generate short name |
1621 | ; file is not found; generate short name |
1621 | call fat_name_is_legal |
1622 | call fat_name_is_legal |
1622 | jc @f |
1623 | jc @f |
1623 | add esp, 28 |
1624 | add esp, 28 |
1624 | popad |
1625 | popad |
1625 | mov eax, ERROR_FILE_NOT_FOUND |
1626 | mov eax, ERROR_FILE_NOT_FOUND |
1626 | xor ebx, ebx |
1627 | xor ebx, ebx |
1627 | ret |
1628 | ret |
1628 | @@: |
1629 | @@: |
1629 | sub esp, 12 |
1630 | sub esp, 12 |
1630 | mov edi, esp |
1631 | mov edi, esp |
1631 | call fat_gen_short_name |
1632 | call fat_gen_short_name |
1632 | .test_short_name_loop: |
1633 | .test_short_name_loop: |
1633 | push esi edi ecx |
1634 | push esi edi ecx |
1634 | mov esi, edi |
1635 | mov esi, edi |
1635 | lea eax, [esp+12+12+8] |
1636 | lea eax, [esp+12+12+8] |
1636 | mov [eax], ebp |
1637 | mov [eax], ebp |
1637 | call dword [eax-4] |
1638 | call dword [eax-4] |
1638 | jc .found |
1639 | jc .found |
1639 | .test_short_name_entry: |
1640 | .test_short_name_entry: |
1640 | cmp byte [edi+11], 0xF |
1641 | cmp byte [edi+11], 0xF |
1641 | jz .test_short_name_cont |
1642 | jz .test_short_name_cont |
1642 | mov ecx, 11 |
1643 | mov ecx, 11 |
1643 | push esi edi |
1644 | push esi edi |
1644 | repz cmpsb |
1645 | repz cmpsb |
1645 | pop edi esi |
1646 | pop edi esi |
1646 | jz .short_name_found |
1647 | jz .short_name_found |
1647 | .test_short_name_cont: |
1648 | .test_short_name_cont: |
1648 | lea eax, [esp+12+12+8] |
1649 | lea eax, [esp+12+12+8] |
1649 | call dword [eax-8] |
1650 | call dword [eax-8] |
1650 | jnc .test_short_name_entry |
1651 | jnc .test_short_name_entry |
1651 | jmp .found |
1652 | jmp .found |
1652 | .short_name_found: |
1653 | .short_name_found: |
1653 | pop ecx edi esi |
1654 | pop ecx edi esi |
1654 | call fat_next_short_name |
1655 | call fat_next_short_name |
1655 | jnc .test_short_name_loop |
1656 | jnc .test_short_name_loop |
1656 | .disk_full: |
1657 | .disk_full: |
1657 | add esp, 12+28 |
1658 | add esp, 12+28 |
1658 | popa |
1659 | popa |
1659 | mov eax, ERROR_DISK_FULL |
1660 | mov eax, ERROR_DISK_FULL |
1660 | xor ebx, ebx |
1661 | xor ebx, ebx |
1661 | ret |
1662 | ret |
1662 | .found: |
1663 | .found: |
1663 | pop ecx edi esi |
1664 | pop ecx edi esi |
1664 | ; now find space in directory |
1665 | ; now find space in directory |
1665 | ; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~' |
1666 | ; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~' |
1666 | mov al, '~' |
1667 | mov al, '~' |
1667 | push ecx edi |
1668 | push ecx edi |
1668 | mov ecx, 8 |
1669 | mov ecx, 8 |
1669 | repnz scasb |
1670 | repnz scasb |
1670 | push 1 |
1671 | push 1 |
1671 | pop eax ; 1 entry |
1672 | pop eax ; 1 entry |
1672 | jnz .notilde |
1673 | jnz .notilde |
1673 | ; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total |
1674 | ; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total |
1674 | xor eax, eax |
1675 | xor eax, eax |
1675 | @@: |
1676 | @@: |
1676 | cmp byte [esi], 0 |
1677 | cmp byte [esi], 0 |
1677 | jz @f |
1678 | jz @f |
1678 | inc esi |
1679 | inc esi |
1679 | inc eax |
1680 | inc eax |
1680 | jmp @b |
1681 | jmp @b |
1681 | @@: |
1682 | @@: |
1682 | sub esi, eax |
1683 | sub esi, eax |
1683 | add eax, 12+13 |
1684 | add eax, 12+13 |
1684 | mov ecx, 13 |
1685 | mov ecx, 13 |
1685 | push edx |
1686 | push edx |
1686 | cdq |
1687 | cdq |
1687 | div ecx |
1688 | div ecx |
1688 | pop edx |
1689 | pop edx |
1689 | .notilde: |
1690 | .notilde: |
1690 | push -1 |
1691 | push -1 |
1691 | push -1 |
1692 | push -1 |
1692 | ; find |
1693 | ; find |
1693 | xor ecx, ecx |
1694 | xor ecx, ecx |
1694 | push eax |
1695 | push eax |
1695 | lea eax, [esp+12+8+12+8] |
1696 | lea eax, [esp+12+8+12+8] |
1696 | mov [eax], ebp |
1697 | mov [eax], ebp |
1697 | call dword [eax-4] |
1698 | call dword [eax-4] |
1698 | pop eax |
1699 | pop eax |
1699 | jnc .scan_dir |
1700 | jnc .scan_dir |
1700 | .fsfrfe3: |
1701 | .fsfrfe3: |
1701 | add esp, 8+8+12+28 |
1702 | add esp, 8+8+12+28 |
1702 | popad |
1703 | popad |
1703 | mov eax, 11 |
1704 | mov eax, 11 |
1704 | xor ebx, ebx |
1705 | xor ebx, ebx |
1705 | ret |
1706 | ret |
1706 | .scan_dir: |
1707 | .scan_dir: |
1707 | cmp byte [edi], 0 |
1708 | cmp byte [edi], 0 |
1708 | jz .free |
1709 | jz .free |
1709 | cmp byte [edi], 0xE5 |
1710 | cmp byte [edi], 0xE5 |
1710 | jz .free |
1711 | jz .free |
1711 | xor ecx, ecx |
1712 | xor ecx, ecx |
1712 | .scan_cont: |
1713 | .scan_cont: |
1713 | push eax |
1714 | push eax |
1714 | lea eax, [esp+12+8+12+8] |
1715 | lea eax, [esp+12+8+12+8] |
1715 | call dword [eax-8] |
1716 | call dword [eax-8] |
1716 | pop eax |
1717 | pop eax |
1717 | jnc .scan_dir |
1718 | jnc .scan_dir |
1718 | cmp [FDC_Status], 0 |
1719 | cmp [FDC_Status], 0 |
1719 | jnz .fsfrfe3 |
1720 | jnz .fsfrfe3 |
1720 | push eax |
1721 | push eax |
1721 | lea eax, [esp+12+8+12+8] |
1722 | lea eax, [esp+12+8+12+8] |
1722 | call dword [eax+16] ; extend directory |
1723 | call dword [eax+16] ; extend directory |
1723 | pop eax |
1724 | pop eax |
1724 | jnc .scan_dir |
1725 | jnc .scan_dir |
1725 | add esp, 8+8+12+28 |
1726 | add esp, 8+8+12+28 |
1726 | popad |
1727 | popad |
1727 | mov eax, ERROR_DISK_FULL |
1728 | mov eax, ERROR_DISK_FULL |
1728 | xor ebx, ebx |
1729 | xor ebx, ebx |
1729 | ret |
1730 | ret |
1730 | .free: |
1731 | .free: |
1731 | test ecx, ecx |
1732 | test ecx, ecx |
1732 | jnz @f |
1733 | jnz @f |
1733 | mov [esp], edi |
1734 | mov [esp], edi |
1734 | mov ecx, [esp+8+8+12+8] |
1735 | mov ecx, [esp+8+8+12+8] |
1735 | mov [esp+4], ecx |
1736 | mov [esp+4], ecx |
1736 | xor ecx, ecx |
1737 | xor ecx, ecx |
1737 | @@: |
1738 | @@: |
1738 | inc ecx |
1739 | inc ecx |
1739 | cmp ecx, eax |
1740 | cmp ecx, eax |
1740 | jb .scan_cont |
1741 | jb .scan_cont |
1741 | ; found! |
1742 | ; found! |
1742 | ; calculate name checksum |
1743 | ; calculate name checksum |
1743 | push esi ecx |
1744 | push esi ecx |
1744 | mov esi, [esp+8+8] |
1745 | mov esi, [esp+8+8] |
1745 | mov ecx, 11 |
1746 | mov ecx, 11 |
1746 | xor eax, eax |
1747 | xor eax, eax |
1747 | @@: |
1748 | @@: |
1748 | ror al, 1 |
1749 | ror al, 1 |
1749 | add al, [esi] |
1750 | add al, [esi] |
1750 | inc esi |
1751 | inc esi |
1751 | loop @b |
1752 | loop @b |
1752 | pop ecx esi |
1753 | pop ecx esi |
1753 | pop edi |
1754 | pop edi |
1754 | pop dword [esp+8+12+8] |
1755 | pop dword [esp+8+12+8] |
1755 | ; edi points to first entry in free chunk |
1756 | ; edi points to first entry in free chunk |
1756 | dec ecx |
1757 | dec ecx |
1757 | jz .nolfn |
1758 | jz .nolfn |
1758 | push esi |
1759 | push esi |
1759 | push eax |
1760 | push eax |
1760 | lea eax, [esp+8+8+12+8] |
1761 | lea eax, [esp+8+8+12+8] |
1761 | call dword [eax+4] ; begin write |
1762 | call dword [eax+4] ; begin write |
1762 | mov al, 40h |
1763 | mov al, 40h |
1763 | .writelfn: |
1764 | .writelfn: |
1764 | or al, cl |
1765 | or al, cl |
1765 | mov esi, [esp+4] |
1766 | mov esi, [esp+4] |
1766 | push ecx |
1767 | push ecx |
1767 | dec ecx |
1768 | dec ecx |
1768 | imul ecx, 13 |
1769 | imul ecx, 13 |
1769 | add esi, ecx |
1770 | add esi, ecx |
1770 | stosb |
1771 | stosb |
1771 | mov cl, 5 |
1772 | mov cl, 5 |
1772 | call fs_RamdiskRewrite.read_symbols |
1773 | call fs_RamdiskRewrite.read_symbols |
1773 | mov ax, 0xF |
1774 | mov ax, 0xF |
1774 | stosw |
1775 | stosw |
1775 | mov al, [esp+4] |
1776 | mov al, [esp+4] |
1776 | stosb |
1777 | stosb |
1777 | mov cl, 6 |
1778 | mov cl, 6 |
1778 | call fs_RamdiskRewrite.read_symbols |
1779 | call fs_RamdiskRewrite.read_symbols |
1779 | xor eax, eax |
1780 | xor eax, eax |
1780 | stosw |
1781 | stosw |
1781 | mov cl, 2 |
1782 | mov cl, 2 |
1782 | call fs_RamdiskRewrite.read_symbols |
1783 | call fs_RamdiskRewrite.read_symbols |
1783 | pop ecx |
1784 | pop ecx |
1784 | lea eax, [esp+8+8+12+8] |
1785 | lea eax, [esp+8+8+12+8] |
1785 | call dword [eax+8] ; next write |
1786 | call dword [eax+8] ; next write |
1786 | xor eax, eax |
1787 | xor eax, eax |
1787 | loop .writelfn |
1788 | loop .writelfn |
1788 | pop eax |
1789 | pop eax |
1789 | pop esi |
1790 | pop esi |
1790 | ; lea eax, [esp+8+12+8] |
1791 | ; lea eax, [esp+8+12+8] |
1791 | ; call dword [eax+12] ; end write |
1792 | ; call dword [eax+12] ; end write |
1792 | .nolfn: |
1793 | .nolfn: |
1793 | xchg esi, [esp] |
1794 | xchg esi, [esp] |
1794 | mov ecx, 11 |
1795 | mov ecx, 11 |
1795 | rep movsb |
1796 | rep movsb |
1796 | mov word [edi], 20h ; attributes |
1797 | mov word [edi], 20h ; attributes |
1797 | sub edi, 11 |
1798 | sub edi, 11 |
1798 | pop esi ecx |
1799 | pop esi ecx |
1799 | add esp, 12 |
1800 | add esp, 12 |
1800 | mov byte [edi+13], 0 ; tenths of a second at file creation time |
1801 | mov byte [edi+13], 0 ; tenths of a second at file creation time |
1801 | call get_time_for_file |
1802 | call get_time_for_file |
1802 | mov [edi+14], ax ; creation time |
1803 | mov [edi+14], ax ; creation time |
1803 | mov [edi+22], ax ; last write time |
1804 | mov [edi+22], ax ; last write time |
1804 | call get_date_for_file |
1805 | call get_date_for_file |
1805 | mov [edi+16], ax ; creation date |
1806 | mov [edi+16], ax ; creation date |
1806 | mov [edi+24], ax ; last write date |
1807 | mov [edi+24], ax ; last write date |
1807 | mov [edi+18], ax ; last access date |
1808 | mov [edi+18], ax ; last access date |
1808 | and word [edi+20], 0 ; high word of cluster |
1809 | and word [edi+20], 0 ; high word of cluster |
1809 | and word [edi+26], 0 ; low word of cluster - to be filled |
1810 | and word [edi+26], 0 ; low word of cluster - to be filled |
1810 | and dword [edi+28], 0 ; file size - to be filled |
1811 | and dword [edi+28], 0 ; file size - to be filled |
1811 | .doit: |
1812 | .doit: |
1812 | lea eax, [esp+8] |
1813 | lea eax, [esp+8] |
1813 | call dword [eax+12] ; flush directory |
1814 | call dword [eax+12] ; flush directory |
1814 | push ecx |
1815 | push ecx |
1815 | push edi |
1816 | push edi |
1816 | add edi, 26 ; edi points to low word of cluster |
1817 | add edi, 26 ; edi points to low word of cluster |
1817 | push edi |
1818 | push edi |
1818 | mov esi, edx |
1819 | mov esi, edx |
1819 | jecxz .done |
1820 | jecxz .done |
1820 | mov ecx, 2849 |
1821 | mov ecx, 2849 |
1821 | mov edi, 0x282000 |
1822 | mov edi, 0x282000 |
1822 | push 0 ; first cluster |
1823 | push 0 ; first cluster |
1823 | .write_loop: |
1824 | .write_loop: |
1824 | ; allocate new cluster |
1825 | ; allocate new cluster |
1825 | xor eax, eax |
1826 | xor eax, eax |
1826 | repnz scasw |
1827 | repnz scasw |
1827 | mov al, ERROR_DISK_FULL |
1828 | mov al, ERROR_DISK_FULL |
1828 | jnz .ret |
1829 | jnz .ret |
1829 | dec edi |
1830 | dec edi |
1830 | dec edi |
1831 | dec edi |
1831 | lea eax, [edi-0x282000] |
1832 | lea eax, [edi-0x282000] |
1832 | shr eax, 1 ; eax = cluster |
1833 | shr eax, 1 ; eax = cluster |
1833 | mov word [edi], 0xFFF ; mark as last cluster |
1834 | mov word [edi], 0xFFF ; mark as last cluster |
1834 | cmp dword [esp], 0 |
1835 | cmp dword [esp], 0 |
1835 | jz .first |
1836 | jz .first |
1836 | xchg edi, [esp+4] |
1837 | xchg edi, [esp+4] |
1837 | stosw |
1838 | stosw |
1838 | mov edi, [esp+4] |
1839 | mov edi, [esp+4] |
1839 | jmp @f |
1840 | jmp @f |
1840 | .first: |
1841 | .first: |
1841 | mov [esp], eax |
1842 | mov [esp], eax |
1842 | @@: |
1843 | @@: |
1843 | inc ecx |
1844 | inc ecx |
1844 | ; write data |
1845 | ; write data |
1845 | push ecx edi |
1846 | push ecx edi |
1846 | mov ecx, 512 |
1847 | mov ecx, 512 |
1847 | cmp dword [esp+20], ecx |
1848 | cmp dword [esp+20], ecx |
1848 | jae @f |
1849 | jae @f |
1849 | mov ecx, [esp+20] |
1850 | mov ecx, [esp+20] |
1850 | @@: |
1851 | @@: |
1851 | push ecx |
1852 | push ecx |
1852 | mov edi, 0xD000 |
1853 | mov edi, 0xD000 |
1853 | rep movsb |
1854 | rep movsb |
1854 | pop ecx |
1855 | pop ecx |
1855 | push ecx |
1856 | push ecx |
1856 | sub ecx, 512 |
1857 | sub ecx, 512 |
1857 | neg ecx |
1858 | neg ecx |
1858 | push eax |
1859 | push eax |
1859 | xor eax, eax |
1860 | xor eax, eax |
1860 | rep stosb |
1861 | rep stosb |
1861 | pop eax |
1862 | pop eax |
1862 | add eax, 31 |
1863 | add eax, 31 |
1863 | pusha |
1864 | pusha |
1864 | call save_chs_sector |
1865 | call save_chs_sector |
1865 | popa |
1866 | popa |
1866 | pop ecx |
1867 | pop ecx |
1867 | cmp [FDC_Status], 0 |
1868 | cmp [FDC_Status], 0 |
1868 | jnz .diskerr |
1869 | jnz .diskerr |
1869 | sub [esp+20], ecx |
1870 | sub [esp+20], ecx |
1870 | pop edi ecx |
1871 | pop edi ecx |
1871 | jnz .write_loop |
1872 | jnz .write_loop |
1872 | .done: |
1873 | .done: |
1873 | xor eax, eax |
1874 | xor eax, eax |
1874 | .ret: |
1875 | .ret: |
1875 | pop ebx edi edi ecx |
1876 | pop ebx edi edi ecx |
1876 | mov [esp+28+28], eax |
1877 | mov [esp+28+28], eax |
1877 | lea eax, [esp+8] |
1878 | lea eax, [esp+8] |
1878 | call dword [eax+4] |
1879 | call dword [eax+4] |
1879 | mov [edi+26], bx |
1880 | mov [edi+26], bx |
1880 | mov ebx, esi |
1881 | mov ebx, esi |
1881 | sub ebx, edx |
1882 | sub ebx, edx |
1882 | mov [edi+28], ebx |
1883 | mov [edi+28], ebx |
1883 | call dword [eax+12] |
1884 | call dword [eax+12] |
1884 | mov [esp+28+16], ebx |
1885 | mov [esp+28+16], ebx |
1885 | test ebp, ebp |
1886 | test ebp, ebp |
1886 | jnz @f |
1887 | jnz @f |
1887 | call save_flp_root |
1888 | call save_flp_root |
1888 | @@: |
1889 | @@: |
1889 | add esp, 28 |
1890 | add esp, 28 |
1890 | cmp [FDC_Status], 0 |
1891 | cmp [FDC_Status], 0 |
1891 | jnz .err3 |
1892 | jnz .err3 |
1892 | call save_flp_fat |
1893 | call save_flp_fat |
1893 | cmp [FDC_Status], 0 |
1894 | cmp [FDC_Status], 0 |
1894 | jnz .err3 |
1895 | jnz .err3 |
1895 | popa |
1896 | popa |
1896 | ret |
1897 | ret |
1897 | .err3: |
1898 | .err3: |
1898 | popa |
1899 | popa |
1899 | mov al, 11 |
1900 | mov al, 11 |
1900 | xor ebx, ebx |
1901 | xor ebx, ebx |
1901 | ret |
1902 | ret |
1902 | .diskerr: |
1903 | .diskerr: |
1903 | sub esi, ecx |
1904 | sub esi, ecx |
1904 | mov eax, 11 |
1905 | mov eax, 11 |
1905 | pop edi ecx |
1906 | pop edi ecx |
1906 | jmp .ret |
1907 | jmp .ret |
- | 1908 | ||
- | 1909 | fs_FloppyGetFileInfo: |
|
- | 1910 | call read_flp_fat |
|
- | 1911 | cmp [FDC_Status], 0 |
|
- | 1912 | jnz ret11 |
|
- | 1913 | cmp byte [esi], 0 |
|
- | 1914 | jnz @f |
|
- | 1915 | mov eax, 2 ; unsupported |
|
- | 1916 | ret |
|
- | 1917 | @@: |
|
- | 1918 | push edi |
|
- | 1919 | call fd_find_lfn |
|
- | 1920 | jmp fs_GetFileInfo_finish |
|
- | 1921 | ||
- | 1922 | ret11: |
|
- | 1923 | mov eax, 11 |
|
- | 1924 | ret |
|
- | 1925 | ||
- | 1926 | fs_FloppySetFileInfo: |
|
- | 1927 | call read_flp_fat |
|
- | 1928 | cmp [FDC_Status], 0 |
|
- | 1929 | jnz ret11 |
|
- | 1930 | cmp byte [esi], 0 |
|
- | 1931 | jnz @f |
|
- | 1932 | mov eax, 2 ; unsupported |
|
- | 1933 | ret |
|
- | 1934 | @@: |
|
- | 1935 | push edi |
|
- | 1936 | call fd_find_lfn |
|
- | 1937 | jnc @f |
|
- | 1938 | pop edi |
|
- | 1939 | mov eax, ERROR_FILE_NOT_FOUND |
|
- | 1940 | ret |
|
- | 1941 | @@: |
|
- | 1942 | push eax |
|
- | 1943 | call bdfe_to_fat_entry |
|
- | 1944 | pop eax |
|
- | 1945 | test eax, eax |
|
- | 1946 | jz .root |
|
- | 1947 | add eax, 31 |
|
- | 1948 | pusha |
|
- | 1949 | call save_chs_sector |
|
- | 1950 | popa |
|
- | 1951 | jmp .cmn |
|
- | 1952 | .root: |
|
- | 1953 | call save_flp_root |
|
- | 1954 | .cmn: |
|
- | 1955 | pop edi |
|
- | 1956 | xor eax, eax |
|
- | 1957 | cmp [FDC_Status], 0 |
|
- | 1958 | jz @f |
|
- | 1959 | mov al, 11 |
|
- | 1960 | @@: |
|
- | 1961 | ret |
|
1907 | 1962 | ||
1908 | ; \end{diamond}=>=>->->->-> |
1963 | ; \end{diamond}=>=>->->->-> |