Subversion Repositories Kolibri OS

Rev

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

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