Subversion Repositories Kolibri OS

Rev

Rev 3626 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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