Subversion Repositories Kolibri OS

Rev

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

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