Subversion Repositories Kolibri OS

Rev

Rev 133 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 133 Rev 384
Line 29... Line 29...
29
    jmp   reserve_flp
29
    jmp   reserve_flp
Line 30... Line 30...
30
 
30
 
Line 31... Line 31...
31
  reserve_flp_ok:
31
  reserve_flp_ok:
32
 
32
 
33
    push  eax
33
    push  eax
34
    mov   eax,[0x3000]
34
    mov   eax,[CURRENT_TASK]
35
    shl   eax,5
35
    shl   eax,5
36
    mov   eax,[eax+0x3000+TASKDATA.pid]
36
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
37
    mov   [flp_status],eax
37
    mov   [flp_status],eax
38
    pop   eax
38
    pop   eax
Line 102... Line 102...
102
    cmp    [FDC_Status],0
102
    cmp    [FDC_Status],0
103
    jne    fdc_status_error_1
103
    jne    fdc_status_error_1
104
    mov    edi,edx
104
    mov    edi,edx
105
    dec    ebx
105
    dec    ebx
106
    shl    ebx,9
106
    shl    ebx,9
107
    mov    esi,0x8000
107
    mov    esi,FLOPPY_BUFF
108
    add    esi,ebx
108
    add    esi,ebx
109
    shl    ecx,9
109
    shl    ecx,9
110
    cld
110
    cld
111
    rep    movsb
111
    rep    movsb
112
    mov    eax,0 ; ok read
112
    mov    eax,0 ; ok read
Line 145... Line 145...
145
l.20_1:
145
l.20_1:
146
    call    ReadSectWithRetr
146
    call    ReadSectWithRetr
147
    cmp    [FDC_Status],0
147
    cmp    [FDC_Status],0
148
    jne    fdc_status_error_3_1
148
    jne    fdc_status_error_3_1
149
    mov     dl,16
149
    mov     dl,16
150
    mov     edi,0xD000
150
    mov     edi,FDD_BUFF
151
    inc     [FDD_Sector]
151
    inc     [FDD_Sector]
152
l.21_1:
152
l.21_1:
153
    mov    esi,eax            ;Name of file we want
153
    mov    esi,eax            ;Name of file we want
154
    mov    ecx,11
154
    mov    ecx,11
155
    cld
155
    cld
Line 217... Line 217...
217
frfl7_1:
217
frfl7_1:
218
    dec    dword [esp+16]
218
    dec    dword [esp+16]
219
frfl8_1:
219
frfl8_1:
220
    mov    edi,[n_sector]
220
    mov    edi,[n_sector]
221
    shl    edi,1            ;find next cluster from FAT
221
    shl    edi,1            ;find next cluster from FAT
222
    add    edi,0x282000
222
    add    edi,FLOPPY_FAT
223
    mov    eax,[edi]
223
    mov    eax,[edi]
224
    and    eax,4095
224
    and    eax,4095
225
    mov    edi,eax
225
    mov    edi,eax
226
    mov    [n_sector],edi
226
    mov    [n_sector],edi
227
    cmp    edi,4095         ;eof  - cluster
227
    cmp    edi,4095         ;eof  - cluster
Line 272... Line 272...
272
    cmp   [root_read],1
272
    cmp   [root_read],1
273
    je    unnecessary_root_read
273
    je    unnecessary_root_read
274
    mov    [FDD_Track],0      ; Öèëèíäð
274
    mov    [FDD_Track],0      ; Öèëèíäð
275
    mov    [FDD_Head],1      ; Ñòîðîíà
275
    mov    [FDD_Head],1      ; Ñòîðîíà
276
    mov    [FDD_Sector],2      ; Ñåêòîð
276
    mov    [FDD_Sector],2      ; Ñåêòîð
277
    mov    edi,0x8000
277
    mov    edi,FLOPPY_BUFF
278
    call   SeekTrack
278
    call   SeekTrack
279
read_flp_root_1:
279
read_flp_root_1:
280
    call   ReadSectWithRetr
280
    call   ReadSectWithRetr
281
    cmp    [FDC_Status],0
281
    cmp    [FDC_Status],0
282
    jne    unnecessary_root_read
282
    jne    unnecessary_root_read
Line 301... Line 301...
301
    cmp   [flp_fat],1
301
    cmp   [flp_fat],1
302
    je    unnecessary_flp_fat
302
    je    unnecessary_flp_fat
303
    mov    [FDD_Track],0      ; Öèëèíäð
303
    mov    [FDD_Track],0      ; Öèëèíäð
304
    mov    [FDD_Head],0      ; Ñòîðîíà
304
    mov    [FDD_Head],0      ; Ñòîðîíà
305
    mov    [FDD_Sector],2      ; Ñåêòîð
305
    mov    [FDD_Sector],2      ; Ñåêòîð
306
    mov    edi,0x8000
306
    mov    edi,FLOPPY_BUFF
307
    call   SeekTrack
307
    call   SeekTrack
308
read_flp_fat_1:
308
read_flp_fat_1:
309
    call   ReadSectWithRetr
309
    call   ReadSectWithRetr
310
    cmp    [FDC_Status],0
310
    cmp    [FDC_Status],0
311
    jne    unnecessary_flp_fat
311
    jne    unnecessary_flp_fat
Line 330... Line 330...
330
    ret
330
    ret
Line 331... Line 331...
331
 
331
 
332
calculatefatchain_flp:
332
calculatefatchain_flp:
Line 333... Line 333...
333
   pushad
333
   pushad
334
 
334
 
Line 335... Line 335...
335
   mov  esi,0x8000
335
   mov  esi,FLOPPY_BUFF
336
   mov  edi,0x282000
336
   mov  edi,FLOPPY_FAT
337
 
337
 
338
 fcnew_1:
338
 fcnew_1:
Line 359... Line 359...
359
   add  edi,4
359
   add  edi,4
360
   mov dword [edi],edx
360
   mov dword [edi],edx
361
   add  edi,4
361
   add  edi,4
362
   add  esi,12
362
   add  esi,12
Line 363... Line 363...
363
 
363
 
364
   cmp  edi,0x282000+2856*2   ;2849 clusters
364
   cmp  edi,FLOPPY_FAT+2856*2   ;2849 clusters
Line 365... Line 365...
365
   jnz  fcnew_1
365
   jnz  fcnew_1
366
 
366
 
Line 382... Line 382...
382
    jne    fdc_status_error
382
    jne    fdc_status_error
383
    call   ReadSectWithRetr
383
    call   ReadSectWithRetr
384
    cmp    [FDC_Status],0
384
    cmp    [FDC_Status],0
385
    jne    fdc_status_error
385
    jne    fdc_status_error
386
    mov    esi,flp_label
386
    mov    esi,flp_label
387
    mov    edi,0xD000+39
387
    mov    edi,FDD_BUFF+39
388
    mov    ecx,15
388
    mov    ecx,15
389
    cld
389
    cld
390
    rep    cmpsb
390
    rep    cmpsb
391
    je     same_label
391
    je     same_label
392
    mov    [root_read],0
392
    mov    [root_read],0
393
    mov    [flp_fat],0
393
    mov    [flp_fat],0
394
same_label:
394
same_label:
395
    mov    esi,0xD000+39
395
    mov    esi,FDD_BUFF+39
396
    mov    edi,flp_label
396
    mov    edi,flp_label
397
    mov    ecx,15
397
    mov    ecx,15
398
    cld
398
    cld
399
    rep    movsb
399
    rep    movsb
400
    popad
400
    popad
Line 411... Line 411...
411
    cmp   [root_read],0
411
    cmp   [root_read],0
412
    je    unnecessary_root_save
412
    je    unnecessary_root_save
413
    mov    [FDD_Track],0      ; Öèëèíäð
413
    mov    [FDD_Track],0      ; Öèëèíäð
414
    mov    [FDD_Head],1      ; Ñòîðîíà
414
    mov    [FDD_Head],1      ; Ñòîðîíà
415
    mov    [FDD_Sector],2      ; Ñåêòîð
415
    mov    [FDD_Sector],2      ; Ñåêòîð
416
    mov    esi,0x8000
416
    mov    esi,FLOPPY_BUFF
417
    call   SeekTrack
417
    call   SeekTrack
418
save_flp_root_1:
418
save_flp_root_1:
419
    push   esi
419
    push   esi
420
    call   take_data_from_application_1
420
    call   take_data_from_application_1
421
    pop    esi
421
    pop    esi
Line 440... Line 440...
440
    je    unnecessary_flp_fat_save
440
    je    unnecessary_flp_fat_save
441
    call   restorefatchain_flp
441
    call   restorefatchain_flp
442
    mov    [FDD_Track],0      ; Öèëèíäð
442
    mov    [FDD_Track],0      ; Öèëèíäð
443
    mov    [FDD_Head],0      ; Ñòîðîíà
443
    mov    [FDD_Head],0      ; Ñòîðîíà
444
    mov    [FDD_Sector],2      ; Ñåêòîð
444
    mov    [FDD_Sector],2      ; Ñåêòîð
445
    mov    esi,0x8000
445
    mov    esi,FLOPPY_BUFF
446
    call   SeekTrack
446
    call   SeekTrack
447
save_flp_fat_1:
447
save_flp_fat_1:
448
    push   esi
448
    push   esi
449
    call   take_data_from_application_1
449
    call   take_data_from_application_1
450
    pop    esi
450
    pop    esi
Line 469... Line 469...
469
 
469
 
470
 
470
 
Line 471... Line 471...
471
restorefatchain_flp:   ; restore fat chain
471
restorefatchain_flp:   ; restore fat chain
472
   pushad
472
   pushad
Line 473... Line 473...
473
 
473
 
474
   mov  esi,0x282000
474
   mov  esi,FLOPPY_FAT
475
   mov  edi,0x8000
475
   mov  edi,FLOPPY_BUFF
476
 
476
 
Line 487... Line 487...
487
   add  edi,4
487
   add  edi,4
488
   mov word [edi],bx
488
   mov word [edi],bx
489
   add  edi,2
489
   add  edi,2
490
   add  esi,8
490
   add  esi,8
Line 491... Line 491...
491
 
491
 
492
   cmp  edi,0x8000+0x1200     ;4274 bytes - all used FAT
492
   cmp  edi,FLOPPY_BUFF+0x1200     ;4274 bytes - all used FAT
Line 493... Line 493...
493
   jb   fcnew2_1
493
   jb   fcnew2_1
494
 
494
 
495
   mov  esi,0x8000           ; duplicate fat chain
495
   mov  esi,FLOPPY_BUFF           ; duplicate fat chain
496
   mov  edi,0x8000+0x1200
496
   mov  edi,FLOPPY_BUFF+0x1200
497
   mov  ecx,0x1200/4
497
   mov  ecx,0x1200/4
Line 498... Line 498...
498
   cld
498
   cld
Line 532... Line 532...
532
l.20_2:
532
l.20_2:
533
    call    ReadSectWithRetr
533
    call    ReadSectWithRetr
534
    cmp    [FDC_Status],0
534
    cmp    [FDC_Status],0
535
    jne    fdc_status_error_4
535
    jne    fdc_status_error_4
536
    mov     dl,16
536
    mov     dl,16
537
    mov     edi,0xD000
537
    mov     edi,FDD_BUFF
538
    inc     [FDD_Sector]
538
    inc     [FDD_Sector]
539
l.21_2:
539
l.21_2:
540
    mov    esi,eax            ;Name of file we want
540
    mov    esi,eax            ;Name of file we want
541
    mov    ecx,11
541
    mov    ecx,11
542
    cld
542
    cld
Line 572... Line 572...
572
fifoundd_2_1:
572
fifoundd_2_1:
573
    mov    [edi-11],byte 0xE5    ;mark filename deleted
573
    mov    [edi-11],byte 0xE5    ;mark filename deleted
574
        movzx   edi, word [edi+0xf] ;edi = cluster
574
        movzx   edi, word [edi+0xf] ;edi = cluster
575
frnewd_1:
575
frnewd_1:
576
    shl    edi,1            ;find next cluster from FAT
576
    shl    edi,1            ;find next cluster from FAT
577
    add    edi,0x282000
577
    add    edi,FLOPPY_FAT
578
    mov    eax,[edi]
578
    mov    eax,[edi]
579
    mov    [edi],word 0x0        ;clear fat chain cluster
579
    mov    [edi],word 0x0        ;clear fat chain cluster
580
    and    eax,4095
580
    and    eax,4095
581
    mov    edi,eax
581
    mov    edi,eax
582
    cmp    edi,dword 4095        ;last cluster ?
582
    cmp    edi,dword 4095        ;last cluster ?
Line 660... Line 660...
660
    pop    eax
660
    pop    eax
661
    mov    [save_root_flag],1
661
    mov    [save_root_flag],1
662
    call   read_flp_root
662
    call   read_flp_root
663
    cmp    [FDC_Status],0
663
    cmp    [FDC_Status],0
664
    jne    fdc_status_error_7
664
    jne    fdc_status_error_7
665
    mov    edi,0x8000   ;Point at directory
665
    mov    edi,FLOPPY_BUFF   ;Point at directory
666
    mov    edx,224 +1
666
    mov    edx,224 +1
667
    ; find an empty spot for filename in the root dir
667
    ; find an empty spot for filename in the root dir
668
l20ds_1:
668
l20ds_1:
669
    sub    edx,1
669
    sub    edx,1
670
    jz     frnoreadds_1
670
    jz     frnoreadds_1
Line 687... Line 687...
687
l.20_3:
687
l.20_3:
688
    call    ReadSectWithRetr
688
    call    ReadSectWithRetr
689
    cmp    [FDC_Status],0
689
    cmp    [FDC_Status],0
690
    jne    fdc_status_error_7
690
    jne    fdc_status_error_7
691
    mov    dl,16
691
    mov    dl,16
692
    mov    edi,0xD000
692
    mov    edi,FDD_BUFF
693
    inc     [FDD_Sector]
693
    inc     [FDD_Sector]
694
l.21_3:
694
l.21_3:
695
    mov    esi,eax            ;Name of file we want
695
    mov    esi,eax            ;Name of file we want
696
    mov    ecx,11
696
    mov    ecx,11
697
    cld
697
    cld
Line 781... Line 781...
781
 
781
 
782
frnewds_2:
782
frnewds_2:
783
    add    ebx,1
783
    add    ebx,1
784
    mov    edi,ebx            ; find free cluster in FAT
784
    mov    edi,ebx            ; find free cluster in FAT
785
    shl    edi,1
785
    shl    edi,1
786
    add    edi,0x282000
786
    add    edi,FLOPPY_FAT
787
    mov    eax,[edi]
787
    mov    eax,[edi]
788
    and    eax,4095
788
    and    eax,4095
789
    jnz    frnewds_2
789
    jnz    frnewds_2
790
    mov    [edx],bx         ; save next cluster pos. to prev cl.
790
    mov    [edx],bx         ; save next cluster pos. to prev cl.
Line 918... Line 918...
918
   popa
918
   popa
919
   cmp    [FDC_Status],0
919
   cmp    [FDC_Status],0
920
   jne    not_found_file_analyze_flp
920
   jne    not_found_file_analyze_flp
Line 921... Line 921...
921
 
921
 
922
   mov ecx,512/32
922
   mov ecx,512/32
Line 923... Line 923...
923
   mov ebx,0xD000
923
   mov ebx,FDD_BUFF
924
 
924
 
925
adr1_analyze_flp:
925
adr1_analyze_flp:
926
   mov esi,edx   ;[esp+16]
926
   mov esi,edx   ;[esp+16]
Line 935... Line 935...
935
   add ebx,32
935
   add ebx,32
936
   loop adr1_analyze_flp
936
   loop adr1_analyze_flp
Line 937... Line 937...
937
 
937
 
938
    mov eax,[clust_tmp_flp]
938
    mov eax,[clust_tmp_flp]
939
    shl    eax,1            ;find next cluster from FAT
939
    shl    eax,1            ;find next cluster from FAT
940
    add    eax,0x282000
940
    add    eax,FLOPPY_FAT
941
    mov    eax,[eax]
941
    mov    eax,[eax]
942
    and    eax,4095
942
    and    eax,4095
943
    cmp eax,0x0ff8
943
    cmp eax,0x0ff8
944
    jb  adr56_flp
944
    jb  adr56_flp
Line 983... Line 983...
983
   popa
983
   popa
984
   cmp    [FDC_Status],0
984
   cmp    [FDC_Status],0
985
   jne    error_found_file_analyze1
985
   jne    error_found_file_analyze1
Line 986... Line 986...
986
 
986
 
987
   mov ecx,512/32
987
   mov ecx,512/32
Line 988... Line 988...
988
   mov ebx,0xD000
988
   mov ebx,FDD_BUFF
989
 
989
 
990
adr1_analyze1:
990
adr1_analyze1:
991
   cmp byte [ebx],0x00
991
   cmp byte [ebx],0x00
Line 997... Line 997...
997
   add ebx,32
997
   add ebx,32
998
   loop adr1_analyze1
998
   loop adr1_analyze1
Line 999... Line 999...
999
 
999
 
1000
   mov eax,[clust_tmp_flp]
1000
   mov eax,[clust_tmp_flp]
1001
   shl    eax,1            ;find next cluster from FAT
1001
   shl    eax,1            ;find next cluster from FAT
1002
   add    eax,0x282000
1002
   add    eax,FLOPPY_FAT
1003
   mov    eax,[eax]
1003
   mov    eax,[eax]
1004
   and    eax,4095
1004
   and    eax,4095
1005
   cmp eax,0x0ff8
1005
   cmp eax,0x0ff8
Line 1011... Line 1011...
1011
 
1011
 
Line 1012... Line 1012...
1012
   mov [edi],word 0x0fff
1012
   mov [edi],word 0x0fff
1013
 
1013
 
1014
   mov eax,[clust_tmp_flp]
1014
   mov eax,[clust_tmp_flp]
1015
   shl    eax,1            ;find next cluster from FAT
1015
   shl    eax,1            ;find next cluster from FAT
1016
   add    eax,0x282000
1016
   add    eax,FLOPPY_FAT
Line 1017... Line 1017...
1017
   sub    edi,0x282000
1017
   sub    edi,FLOPPY_FAT
1018
   mov    [eax],di
1018
   mov    [eax],di
1019
 
1019
 
1020
   pusha
1020
   pusha
1021
   mov ecx,512/4
1021
   mov ecx,512/4
1022
   xor eax,eax
1022
   xor eax,eax
1023
   mov edi,0xD000
1023
   mov edi,FDD_BUFF
Line 1024... Line 1024...
1024
   cld
1024
   cld
Line 1030... Line 1030...
1030
   pusha
1030
   pusha
1031
   call   save_chs_sector
1031
   call   save_chs_sector
1032
   popa
1032
   popa
1033
   cmp    [FDC_Status],0
1033
   cmp    [FDC_Status],0
1034
   jne    error_found_file_analyze1
1034
   jne    error_found_file_analyze1
1035
   mov    ebx,0xD000
1035
   mov    ebx,FDD_BUFF
Line 1036... Line 1036...
1036
 
1036
 
Line 1037... Line 1037...
1037
found_file_analyze1:
1037
found_file_analyze1:
1038
 
1038
 
Line 1059... Line 1059...
1059
    mov    ebx,1
1059
    mov    ebx,1
1060
check_new_flp:
1060
check_new_flp:
1061
    add    ebx,1
1061
    add    ebx,1
1062
    mov    edi,ebx            ; find free cluster in FAT
1062
    mov    edi,ebx            ; find free cluster in FAT
1063
    shl    edi,1
1063
    shl    edi,1
1064
    add    edi,0x282000
1064
    add    edi,FLOPPY_FAT
1065
    mov    eax,[edi]
1065
    mov    eax,[edi]
1066
    and    eax,4095
1066
    and    eax,4095
1067
    cmp    eax,0x0
1067
    cmp    eax,0x0
1068
    jnz    check_new_flp
1068
    jnz    check_new_flp
Line 1112... Line 1112...
1112
        push    esi
1112
        push    esi
1113
        push    edi
1113
        push    edi
1114
        popa
1114
        popa
1115
        ret
1115
        ret
Line -... Line 1116...
-
 
1116
 
-
 
1117
uglobal
-
 
1118
; this is for delete support
-
 
1119
fd_prev_sector          dd      ?
-
 
1120
fd_prev_prev_sector     dd      ?
-
 
1121
endg
1116
 
1122
 
1117
flp_root_next:
1123
flp_root_next:
1118
        cmp     edi, 0xD200-0x20
1124
        cmp     edi, 0xD200-0x20
1119
        jae     @f
1125
        jae     @f
1120
        add     edi, 0x20
1126
        add     edi, 0x20
1121
        ret     ; CF=0
1127
        ret     ; CF=0
1122
@@:
1128
@@:
1123
; read next sector
1129
; read next sector
1124
        inc     dword [eax]
1130
        inc     dword [eax]
1125
        cmp     dword [eax], 14
1131
        cmp     dword [eax], 14
-
 
1132
        jae     flp_root_first.readerr
-
 
1133
        push    [fd_prev_sector]
-
 
1134
        pop     [fd_prev_prev_sector]
-
 
1135
        push    eax
-
 
1136
        mov     eax, [eax]
-
 
1137
        add     eax, 19-1
-
 
1138
        mov     [fd_prev_sector], eax
1126
        jae     flp_root_first.readerr
1139
        pop     eax
1127
flp_root_first:
1140
flp_root_first:
1128
        mov     eax, [eax]
1141
        mov     eax, [eax]
1129
        pusha
1142
        pusha
1130
        add     eax, 19
1143
        add     eax, 19
1131
        call    read_chs_sector
1144
        call    read_chs_sector
1132
        popa
1145
        popa
1133
        cmp     [FDC_Status], 0
1146
        cmp     [FDC_Status], 0
1134
        jnz     .readerr
1147
        jnz     .readerr
1135
        mov     edi, 0xD000
1148
        mov     edi, FDD_BUFF
1136
        ret     ; CF=0
1149
        ret     ; CF=0
1137
.readerr:
1150
.readerr:
1138
        stc
1151
        stc
Line 1139... Line 1152...
1139
        ret
1152
        ret
1140
 
1153
 
1141
flp_rootmem_first:
1154
flp_rootmem_first:
1142
        mov     edi, 0x8000
1155
        mov     edi, FLOPPY_BUFF
1143
        clc
1156
        clc
1144
        ret
1157
        ret
1145
flp_rootmem_next:
1158
flp_rootmem_next:
1146
        add     edi, 0x20
1159
        add     edi, 0x20
1147
        cmp     edi, 0x8000+14*0x200
1160
        cmp     edi, FLOPPY_BUFF+14*0x200
1148
        cmc
1161
        cmc
1149
flp_rootmem_next_write:
1162
flp_rootmem_next_write:
1150
flp_rootmem_begin_write:
1163
flp_rootmem_begin_write:
Line 1160... Line 1173...
1160
        add     edi, 0x20
1173
        add     edi, 0x20
1161
        ret     ; CF=0
1174
        ret     ; CF=0
1162
flp_notroot_next_sector:
1175
flp_notroot_next_sector:
1163
        push    ecx
1176
        push    ecx
1164
        mov     ecx, [eax]
1177
        mov     ecx, [eax]
-
 
1178
        push    [fd_prev_sector]
-
 
1179
        pop     [fd_prev_prev_sector]
-
 
1180
        add     ecx, 31
-
 
1181
        mov     [fd_prev_sector], ecx
1165
        mov     ecx, [ecx*2+0x282000]
1182
        mov     ecx, [(ecx-31)*2+FLOPPY_FAT]
1166
        and     ecx, 0xFFF
1183
        and     ecx, 0xFFF
1167
        cmp     ecx, 2849
1184
        cmp     ecx, 2849
1168
        jae     flp_notroot_first.err2
1185
        jae     flp_notroot_first.err2
1169
        mov     [eax], ecx
1186
        mov     [eax], ecx
1170
        pop     ecx
1187
        pop     ecx
Line 1176... Line 1193...
1176
        jae     .err
1193
        jae     .err
1177
        pusha
1194
        pusha
1178
        add     eax, 31
1195
        add     eax, 31
1179
        call    read_chs_sector
1196
        call    read_chs_sector
1180
        popa
1197
        popa
1181
        mov     edi, 0xD000
1198
        mov     edi, FDD_BUFF
1182
        cmp     [FDC_Status], 0
1199
        cmp     [FDC_Status], 0
1183
        jnz     .err
1200
        jnz     .err
1184
        ret     ; CF=0
1201
        ret     ; CF=0
1185
.err2:
1202
.err2:
1186
        pop     ecx
1203
        pop     ecx
Line 1210... Line 1227...
1210
        jmp     flp_notroot_next_sector
1227
        jmp     flp_notroot_next_sector
1211
flp_notroot_extend_dir:
1228
flp_notroot_extend_dir:
1212
; find free cluster in FAT
1229
; find free cluster in FAT
1213
        pusha
1230
        pusha
1214
        xor     eax, eax
1231
        xor     eax, eax
1215
        mov     edi, 0x282000
1232
        mov     edi, FLOPPY_FAT
1216
        mov     ecx, 2849
1233
        mov     ecx, 2849
1217
        repnz   scasw
1234
        repnz   scasw
1218
        jnz     .notfound
1235
        jnz     .notfound
1219
        mov     word [edi-2], 0xFFF     ; mark as last cluster
1236
        mov     word [edi-2], 0xFFF     ; mark as last cluster
1220
        sub     edi, 0x282000
1237
        sub     edi, FLOPPY_FAT
1221
        shr     edi, 1
1238
        shr     edi, 1
1222
        dec     edi
1239
        dec     edi
1223
        mov     eax, [esp+28]
1240
        mov     eax, [esp+28]
1224
        mov     ecx, [eax]
1241
        mov     ecx, [eax]
1225
        mov     [0x282000+ecx*2], di
1242
        mov     [FLOPPY_FAT+ecx*2], di
1226
        mov     [eax], edi
1243
        mov     [eax], edi
1227
        xor     eax, eax
1244
        xor     eax, eax
1228
        mov     edi, 0xD000
1245
        mov     edi, FDD_BUFF
1229
        mov     ecx, 128
1246
        mov     ecx, 128
1230
        rep     stosd
1247
        rep     stosd
1231
        popa
1248
        popa
1232
        call    flp_notroot_end_write
1249
        call    flp_notroot_end_write
1233
        mov     edi, 0xD000
1250
        mov     edi, FDD_BUFF
1234
        clc
1251
        clc
1235
        ret
1252
        ret
1236
.notfound:
1253
.notfound:
1237
        popa
1254
        popa
1238
        stc
1255
        stc
Line 1339... Line 1356...
1339
        pusha
1356
        pusha
1340
        call    read_chs_sector
1357
        call    read_chs_sector
1341
        popa
1358
        popa
1342
        cmp     [FDC_Status], 0
1359
        cmp     [FDC_Status], 0
1343
        jnz     .err
1360
        jnz     .err
1344
        lea     eax, [0xD000+ebx+512]
1361
        lea     eax, [FDD_BUFF+ebx+512]
1345
        neg     ebx
1362
        neg     ebx
1346
        push    ecx
1363
        push    ecx
1347
        cmp     ecx, ebx
1364
        cmp     ecx, ebx
1348
        jbe     @f
1365
        jbe     @f
1349
        mov     ecx, ebx
1366
        mov     ecx, ebx
Line 1353... Line 1370...
1353
        add     edx, ecx
1370
        add     edx, ecx
1354
        sub     [esp], ecx
1371
        sub     [esp], ecx
1355
        pop     ecx
1372
        pop     ecx
1356
        xor     ebx, ebx
1373
        xor     ebx, ebx
1357
.skip:
1374
.skip:
1358
        movzx   edi, word [edi*2+0x282000]
1375
        movzx   edi, word [edi*2+FLOPPY_FAT]
1359
        jmp     .new
1376
        jmp     .new
1360
.done:
1377
.done:
1361
        mov     ebx, edx
1378
        mov     ebx, edx
1362
        pop     eax edx ecx edi
1379
        pop     eax edx ecx edi
1363
        sub     ebx, edx
1380
        sub     ebx, edx
Line 1433... Line 1450...
1433
        pusha
1450
        pusha
1434
        call    read_chs_sector
1451
        call    read_chs_sector
1435
        popa
1452
        popa
1436
        cmp     [FDC_Status], 0
1453
        cmp     [FDC_Status], 0
1437
        jnz     .error
1454
        jnz     .error
1438
        mov     edi, 0xD000
1455
        mov     edi, FDD_BUFF
1439
        push    eax
1456
        push    eax
1440
.l1:
1457
.l1:
1441
        call    fat_get_name
1458
        call    fat_get_name
1442
        jc      .l2
1459
        jc      .l2
1443
        cmp     byte [edi+11], 0xF
1460
        cmp     byte [edi+11], 0xF
Line 1449... Line 1466...
1449
        inc     eax
1466
        inc     eax
1450
        dec     byte [esp+262*2+12]
1467
        dec     byte [esp+262*2+12]
1451
        jz      .done
1468
        jz      .done
1452
        jns     @f
1469
        jns     @f
1453
; read next sector from FAT
1470
; read next sector from FAT
1454
        mov     eax, [(eax-31-1)*2+0x282000]
1471
        mov     eax, [(eax-31-1)*2+FLOPPY_FAT]
1455
        and     eax, 0xFFF
1472
        and     eax, 0xFFF
1456
        cmp     eax, 0xFF8
1473
        cmp     eax, 0xFF8
1457
        jae     .done
1474
        jae     .done
1458
        add     eax, 31
1475
        add     eax, 31
1459
        mov     byte [esp+262*2+12], 0
1476
        mov     byte [esp+262*2+12], 0
Line 1461... Line 1478...
1461
        pusha
1478
        pusha
1462
        call    read_chs_sector
1479
        call    read_chs_sector
1463
        popa
1480
        popa
1464
        cmp     [FDC_Status], 0
1481
        cmp     [FDC_Status], 0
1465
        jnz     .error
1482
        jnz     .error
1466
        mov     edi, 0xD000
1483
        mov     edi, FDD_BUFF
1467
        push    eax
1484
        push    eax
1468
.do_bdfe:
1485
.do_bdfe:
1469
        inc     dword [edx+8]   ; new file found
1486
        inc     dword [edx+8]   ; new file found
1470
        dec     ebx
1487
        dec     ebx
1471
        jns     .l2
1488
        jns     .l2
Line 1481... Line 1498...
1481
        inc     eax
1498
        inc     eax
1482
        dec     byte [esp+262*2+12]
1499
        dec     byte [esp+262*2+12]
1483
        jz      .done
1500
        jz      .done
1484
        jns     @f
1501
        jns     @f
1485
; read next sector from FAT
1502
; read next sector from FAT
1486
        mov     eax, [(eax-31-1)*2+0x282000]
1503
        mov     eax, [(eax-31-1)*2+FLOPPY_FAT]
1487
        and     eax, 0xFFF
1504
        and     eax, 0xFFF
1488
        cmp     eax, 0xFF8
1505
        cmp     eax, 0xFF8
1489
        jae     .done
1506
        jae     .done
1490
        add     eax, 31
1507
        add     eax, 31
1491
        mov     byte [esp+262*2+12], 0
1508
        mov     byte [esp+262*2+12], 0
Line 1531... Line 1548...
1531
fsfrfe:
1548
fsfrfe:
1532
        mov     eax, 11
1549
        mov     eax, 11
1533
        xor     ebx, ebx
1550
        xor     ebx, ebx
1534
        ret
1551
        ret
Line -... Line 1552...
-
 
1552
 
-
 
1553
fs_FloppyCreateFolder:
-
 
1554
        mov     al, 1
-
 
1555
        jmp     fs_FloppyRewrite.common
1535
 
1556
 
-
 
1557
fs_FloppyRewrite:
-
 
1558
        xor     eax, eax
1536
fs_FloppyRewrite:
1559
.common:
1537
        cmp     byte [esi], 0
1560
        cmp     byte [esi], 0
1538
        jz      @b
1561
        jz      @b
1539
        call    read_flp_fat
1562
        call    read_flp_fat
1540
        cmp     [FDC_Status], 0
1563
        cmp     [FDC_Status], 0
Line 1565... Line 1588...
1565
        push    ebp
1588
        push    ebp
1566
        push    flp_rootmem_first
1589
        push    flp_rootmem_first
1567
        push    flp_rootmem_next
1590
        push    flp_rootmem_next
1568
        jmp     .common1
1591
        jmp     .common1
1569
.noroot:
1592
.noroot:
-
 
1593
        mov     eax, ERROR_ACCESS_DENIED
-
 
1594
        cmp     byte [ebp+1], 0
-
 
1595
        jz      .ret1
1570
; check existence
1596
; check existence
1571
        mov     byte [ebp], 0
1597
        mov     byte [ebp], 0
1572
        call    fd_find_lfn
1598
        call    fd_find_lfn
1573
        mov     byte [ebp], '/'
1599
        mov     byte [ebp], '/'
1574
        lea     esi, [ebp+1]
1600
        lea     esi, [ebp+1]
Line 1597... Line 1623...
1597
        push    flp_notroot_first
1623
        push    flp_notroot_first
1598
        push    flp_notroot_next
1624
        push    flp_notroot_next
1599
.common1:
1625
.common1:
1600
        call    fat_find_lfn
1626
        call    fat_find_lfn
1601
        jc      .notfound
1627
        jc      .notfound
1602
; found; must not be directory
1628
; found
1603
        test    byte [edi+11], 10h
1629
        test    byte [edi+11], 10h
-
 
1630
        jz      .exists_file
-
 
1631
; found directory; if we are creating directory, return OK,
-
 
1632
;                  if we are creating file, say "access denied"
-
 
1633
        add     esp, 28
-
 
1634
        popad
-
 
1635
        test    al, al
-
 
1636
        mov     eax, ERROR_ACCESS_DENIED
-
 
1637
        jz      @f
-
 
1638
        mov     al, 0
-
 
1639
@@:
-
 
1640
        xor     ebx, ebx
-
 
1641
        ret
-
 
1642
.exists_file:
-
 
1643
; found file; if we are creating directory, return "access denied",
-
 
1644
;             if we are creating file, delete existing file and continue
-
 
1645
        cmp     byte [esp+28+28], 0
1604
        jz      @f
1646
        jz      @f
1605
        add     esp, 28
1647
        add     esp, 28
1606
        popad
1648
        popad
1607
        mov     eax, ERROR_ACCESS_DENIED
1649
        mov     eax, ERROR_ACCESS_DENIED
1608
        xor     ebx, ebx
1650
        xor     ebx, ebx
Line 1616... Line 1658...
1616
        test    eax, eax
1658
        test    eax, eax
1617
        jz      .done1
1659
        jz      .done1
1618
@@:
1660
@@:
1619
        cmp     eax, 0xFF8
1661
        cmp     eax, 0xFF8
1620
        jae     .done1
1662
        jae     .done1
1621
        lea     edi, [0x282000 + eax*2] ; position in FAT
1663
        lea     edi, [FLOPPY_FAT + eax*2] ; position in FAT
1622
        xor     eax, eax
1664
        xor     eax, eax
1623
        xchg    ax, [edi]
1665
        xchg    ax, [edi]
1624
        jmp     @b
1666
        jmp     @b
1625
.done1:
1667
.done1:
1626
        pop     edi
1668
        pop     edi
Line 1821... Line 1863...
1821
        mov     [edi+24], ax            ; last write date
1863
        mov     [edi+24], ax            ; last write date
1822
        mov     [edi+18], ax            ; last access date
1864
        mov     [edi+18], ax            ; last access date
1823
        and     word [edi+20], 0        ; high word of cluster
1865
        and     word [edi+20], 0        ; high word of cluster
1824
        and     word [edi+26], 0        ; low word of cluster - to be filled
1866
        and     word [edi+26], 0        ; low word of cluster - to be filled
1825
        and     dword [edi+28], 0       ; file size - to be filled
1867
        and     dword [edi+28], 0       ; file size - to be filled
-
 
1868
        cmp     byte [esp+28+28], 0
-
 
1869
        jz      .doit
-
 
1870
; create directory
-
 
1871
        mov     byte [edi+11], 10h      ; attributes: folder
-
 
1872
        mov     ecx, 32*2
-
 
1873
        mov     edx, edi
1826
.doit:
1874
.doit:
1827
        lea     eax, [esp+8]
1875
        lea     eax, [esp+8]
1828
        call    dword [eax+12]  ; flush directory
1876
        call    dword [eax+12]  ; flush directory
1829
        push    ecx
1877
        push    ecx
1830
        push    edi
1878
        push    edi
1831
        push    0
1879
        push    0
1832
        mov     esi, edx
1880
        mov     esi, edx
-
 
1881
        test    ecx, ecx
1833
        jecxz   .done
1882
        jz      .done
1834
        mov     ecx, 2849
1883
        mov     ecx, 2849
1835
        mov     edi, 0x282000
1884
        mov     edi, FLOPPY_FAT
1836
        push    0       ; first cluster
1885
        push    0       ; first cluster
1837
.write_loop:
1886
.write_loop:
1838
; allocate new cluster
1887
; allocate new cluster
1839
        xor     eax, eax
1888
        xor     eax, eax
1840
        repnz   scasw
1889
        repnz   scasw
1841
        mov     al, ERROR_DISK_FULL
1890
        mov     al, ERROR_DISK_FULL
1842
        jnz     .ret
1891
        jnz     .ret
1843
        dec     edi
1892
        dec     edi
1844
        dec     edi
1893
        dec     edi
1845
        lea     eax, [edi-0x282000]
1894
        lea     eax, [edi-(FLOPPY_FAT)]
1846
        shr     eax, 1                  ; eax = cluster
1895
        shr     eax, 1                  ; eax = cluster
1847
        mov     word [edi], 0xFFF       ; mark as last cluster
1896
        mov     word [edi], 0xFFF       ; mark as last cluster
1848
        xchg    edi, [esp+4]
1897
        xchg    edi, [esp+4]
1849
        cmp     dword [esp], 0
1898
        cmp     dword [esp], 0
1850
        jz      .first
1899
        jz      .first
Line 1860... Line 1909...
1860
        mov     ecx, 512
1909
        mov     ecx, 512
1861
        cmp     dword [esp+20], ecx
1910
        cmp     dword [esp+20], ecx
1862
        jae     @f
1911
        jae     @f
1863
        mov     ecx, [esp+20]
1912
        mov     ecx, [esp+20]
1864
@@:
1913
@@:
-
 
1914
        mov     edi, FDD_BUFF
-
 
1915
        cmp     byte [esp+24+28+28], 0
-
 
1916
        jnz     .writedir
1865
        push    ecx
1917
        push    ecx
1866
        mov     edi, 0xD000
-
 
1867
        rep     movsb
1918
        rep     movsb
1868
        pop     ecx
1919
        pop     ecx
-
 
1920
.writedircont:
1869
        push    ecx
1921
        push    ecx
1870
        sub     ecx, 512
1922
        sub     ecx, 512
1871
        neg     ecx
1923
        neg     ecx
1872
        push    eax
1924
        push    eax
1873
        xor     eax, eax
1925
        xor     eax, eax
Line 1916... Line 1968...
1916
.diskerr:
1968
.diskerr:
1917
        sub     esi, ecx
1969
        sub     esi, ecx
1918
        mov     eax, 11
1970
        mov     eax, 11
1919
        pop     edi ecx
1971
        pop     edi ecx
1920
        jmp     .ret
1972
        jmp     .ret
-
 
1973
.writedir:
-
 
1974
        push    ecx
-
 
1975
        mov     ecx, 32/4
-
 
1976
        push    ecx esi
-
 
1977
        rep     movsd
-
 
1978
        pop     esi ecx
-
 
1979
        mov     dword [edi-32], '.   '
-
 
1980
        mov     dword [edi-32+4], '    '
-
 
1981
        mov     dword [edi-32+8], '    '
-
 
1982
        mov     byte [edi-32+11], 10h
-
 
1983
        mov     word [edi-32+26], ax
-
 
1984
        push    esi
-
 
1985
        rep     movsd
-
 
1986
        pop     esi
-
 
1987
        mov     dword [edi-32], '..  '
-
 
1988
        mov     dword [edi-32+4], '    '
-
 
1989
        mov     dword [edi-32+8], '    '
-
 
1990
        mov     byte [edi-32+11], 10h
-
 
1991
        mov     ecx, [esp+28+8]
-
 
1992
        mov     word [edi-32+26], cx
-
 
1993
        pop     ecx
-
 
1994
        jmp     .writedircont
Line 1921... Line 1995...
1921
 
1995
 
1922
;----------------------------------------------------------------
1996
;----------------------------------------------------------------
1923
;
1997
;
1924
;  fs_FloppyWrite - LFN variant for writing to floppy
1998
;  fs_FloppyWrite - LFN variant for writing to floppy
Line 2040... Line 2114...
2040
; now ebx=start pos, ecx=end pos, both lie inside file
2114
; now ebx=start pos, ecx=end pos, both lie inside file
2041
        sub     ecx, ebx
2115
        sub     ecx, ebx
2042
        jz      .ret
2116
        jz      .ret
2043
        call    SetUserInterrupts
2117
        call    SetUserInterrupts
2044
.write_loop:
2118
.write_loop:
-
 
2119
; skip unmodified sectors
-
 
2120
        cmp     dword [esp], 0x200
-
 
2121
        jb      .modify
-
 
2122
        sub     ebx, 0x200
-
 
2123
        jae     .skip
-
 
2124
        add     ebx, 0x200
-
 
2125
.modify:
2045
        lea     eax, [edi+31]   ; current sector
2126
        lea     eax, [edi+31]   ; current sector
2046
; get length of data in current sector
2127
; get length of data in current sector
2047
        push    ecx
2128
        push    ecx
2048
        sub     ebx, 0x200
2129
        sub     ebx, 0x200
2049
        jb      .hasdata
2130
        jb      .hasdata
Line 2077... Line 2158...
2077
        push    eax ecx edi
2158
        push    eax ecx edi
2078
        xor     eax, eax
2159
        xor     eax, eax
2079
        mov     ecx, 0x200
2160
        mov     ecx, 0x200
2080
        sub     ecx, [esp+4+12]
2161
        sub     ecx, [esp+4+12]
2081
        jbe     @f
2162
        jbe     @f
2082
        mov     edi, 0xD000
2163
        mov     edi, FDD_BUFF
2083
        add     edi, [esp+4+12]
2164
        add     edi, [esp+4+12]
2084
        rep     stosb
2165
        rep     stosb
2085
@@:
2166
@@:
2086
; zero uninitialized data in the last sector
2167
; zero uninitialized data in the last sector
2087
        mov     ecx, 0x200
2168
        mov     ecx, 0x200
2088
        sub     ecx, esi
2169
        sub     ecx, esi
2089
        jbe     @f
2170
        jbe     @f
2090
        mov     edi, 0xD000
2171
        mov     edi, FDD_BUFF
2091
        add     edi, esi
2172
        add     edi, esi
2092
        rep     stosb
2173
        rep     stosb
2093
@@:
2174
@@:
2094
        pop     edi ecx eax
2175
        pop     edi ecx eax
2095
; copy new data
2176
; copy new data
2096
        push    eax
2177
        push    eax
2097
        mov     eax, edx
2178
        mov     eax, edx
2098
        neg     ebx
2179
        neg     ebx
2099
        jecxz   @f
2180
        jecxz   @f
2100
        add     ebx, 0xD000+0x200
2181
        add     ebx, FDD_BUFF+0x200
2101
        call    memmove
2182
        call    memmove
2102
        xor     ebx, ebx
2183
        xor     ebx, ebx
2103
@@:
2184
@@:
2104
        pop     eax
2185
        pop     eax
2105
; save sector
2186
; save sector
Line 2110... Line 2191...
2110
        jnz     .device_err2
2191
        jnz     .device_err2
2111
        add     edx, ecx
2192
        add     edx, ecx
2112
        sub     [esp], ecx
2193
        sub     [esp], ecx
2113
        pop     ecx
2194
        pop     ecx
2114
        jz      .done
2195
        jz      .done
-
 
2196
.skip:
2115
.next_cluster:
2197
.next_cluster:
2116
        movzx   edi, word [edi*2+0x282000]
2198
        movzx   edi, word [edi*2+FLOPPY_FAT]
2117
        sub     esi, 0x200
2199
        sub     esi, 0x200
2118
        jae     @f
2200
        jae     @f
2119
        xor     esi, esi
2201
        xor     esi, esi
2120
@@:
2202
@@:
2121
        sub     dword [esp], 0x200
2203
        sub     dword [esp], 0x200
Line 2141... Line 2223...
2141
        mov     ecx, [edi+28]
2223
        mov     ecx, [edi+28]
2142
        jecxz   .zero_size
2224
        jecxz   .zero_size
2143
@@:
2225
@@:
2144
        sub     ecx, 0x200
2226
        sub     ecx, 0x200
2145
        jbe     @f
2227
        jbe     @f
2146
        mov     eax, [eax*2+0x282000]
2228
        mov     eax, [eax*2+FLOPPY_FAT]
2147
        and     eax, 0xFFF
2229
        and     eax, 0xFFF
2148
        jz      .fat_err
2230
        jz      .fat_err
2149
        cmp     eax, 0xFF8
2231
        cmp     eax, 0xFF8
2150
        jb      @b
2232
        jb      @b
2151
.fat_err:
2233
.fat_err:
Line 2154... Line 2236...
2154
        pop     eax
2236
        pop     eax
2155
        stc
2237
        stc
2156
        ret
2238
        ret
2157
@@:
2239
@@:
2158
        push    eax
2240
        push    eax
2159
        mov     eax, [eax*2+0x282000]
2241
        mov     eax, [eax*2+FLOPPY_FAT]
2160
        and     eax, 0xFFF
2242
        and     eax, 0xFFF
2161
        cmp     eax, 0xFF8
2243
        cmp     eax, 0xFF8
2162
        pop     eax
2244
        pop     eax
2163
        jb      .fat_err
2245
        jb      .fat_err
2164
; set length to full number of sectors
2246
; set length to full number of sectors
2165
        sub     [edi+28], ecx
2247
        sub     [edi+28], ecx
2166
.start_extend:
2248
.start_extend:
2167
        pop     ecx
2249
        pop     ecx
2168
; now do extend
2250
; now do extend
2169
        push    edx esi
2251
        push    edx esi
2170
        mov     esi, 0x282000+2*2       ; start scan from cluster 2
2252
        mov     esi, FLOPPY_FAT+2*2       ; start scan from cluster 2
2171
        mov     edx, 2847               ; number of clusters to scan
2253
        mov     edx, 2847               ; number of clusters to scan
2172
.extend_loop:
2254
.extend_loop:
2173
        cmp     [edi+28], ecx
2255
        cmp     [edi+28], ecx
2174
        jae     .extend_done
2256
        jae     .extend_done
2175
; add new sector
2257
; add new sector
Line 2185... Line 2267...
2185
        pop     eax
2267
        pop     eax
2186
        jnz     .disk_full
2268
        jnz     .disk_full
2187
        mov     word [edi-2], 0xFFF
2269
        mov     word [edi-2], 0xFFF
2188
        mov     esi, edi
2270
        mov     esi, edi
2189
        mov     edx, ecx
2271
        mov     edx, ecx
2190
        sub     edi, 0x282000
2272
        sub     edi, FLOPPY_FAT
2191
        shr     edi, 1
2273
        shr     edi, 1
2192
        dec     edi     ; now edi=new cluster
2274
        dec     edi     ; now edi=new cluster
2193
        test    eax, eax
2275
        test    eax, eax
2194
        jz      .first_cluster
2276
        jz      .first_cluster
2195
        mov     [0x282000+eax*2], di
2277
        mov     [FLOPPY_FAT+eax*2], di
2196
        jmp     @f
2278
        jmp     @f
2197
.first_cluster:
2279
.first_cluster:
2198
        pop     eax             ; eax->direntry
2280
        pop     eax             ; eax->direntry
2199
        push    eax
2281
        push    eax
2200
        mov     [eax+26], di
2282
        mov     [eax+26], di
Line 2328... Line 2410...
2328
        jnz     .err_next
2410
        jnz     .err_next
2329
.noread:
2411
.noread:
2330
        mov     ecx, [esp+4]
2412
        mov     ecx, [esp+4]
2331
        neg     ecx
2413
        neg     ecx
2332
        push    edi
2414
        push    edi
2333
        mov     edi, 0xD000+0x200
2415
        mov     edi, FDD_BUFF+0x200
2334
        add     edi, [esp+8]
2416
        add     edi, [esp+8]
2335
        xor     eax, eax
2417
        xor     eax, eax
2336
        mov     [esp+8], eax
2418
        mov     [esp+8], eax
2337
        rep     stosb
2419
        rep     stosb
2338
        pop     edi
2420
        pop     edi
Line 2345... Line 2427...
2345
.err_next:
2427
.err_next:
2346
        mov     byte [esp], 11
2428
        mov     byte [esp], 11
2347
.next_cluster:
2429
.next_cluster:
2348
        sub     dword [esp+12], 0x200
2430
        sub     dword [esp+12], 0x200
2349
        jbe     .expand_done
2431
        jbe     .expand_done
2350
        movzx   edi, word [0x282000+edi*2]
2432
        movzx   edi, word [FLOPPY_FAT+edi*2]
2351
        jmp     .zero_loop
2433
        jmp     .zero_loop
2352
.expand_done:
2434
.expand_done:
2353
        pop     eax ecx ecx edi edi
2435
        pop     eax ecx ecx edi edi
2354
        jmp     .doret
2436
        jmp     .doret
2355
.truncate:
2437
.truncate:
Line 2360... Line 2442...
2360
        jz      .zero_size
2442
        jz      .zero_size
2361
; find new last sector
2443
; find new last sector
2362
@@:
2444
@@:
2363
        sub     eax, 0x200
2445
        sub     eax, 0x200
2364
        jbe     @f
2446
        jbe     @f
2365
        movzx   ecx, word [0x282000+ecx*2]
2447
        movzx   ecx, word [FLOPPY_FAT+ecx*2]
2366
        jmp     @b
2448
        jmp     @b
2367
@@:
2449
@@:
2368
; we will zero data at the end of last sector - remember it
2450
; we will zero data at the end of last sector - remember it
2369
        push    ecx
2451
        push    ecx
2370
; terminate FAT chain
2452
; terminate FAT chain
2371
        lea     ecx, [0x282000+ecx+ecx]
2453
        lea     ecx, [FLOPPY_FAT+ecx+ecx]
2372
        push    dword [ecx]
2454
        push    dword [ecx]
2373
        mov     word [ecx], 0xFFF
2455
        mov     word [ecx], 0xFFF
2374
        pop     ecx
2456
        pop     ecx
2375
        and     ecx, 0xFFF
2457
        and     ecx, 0xFFF
2376
        jmp     .delete
2458
        jmp     .delete
Line 2380... Line 2462...
2380
.delete:
2462
.delete:
2381
; delete FAT chain starting with ecx
2463
; delete FAT chain starting with ecx
2382
; mark all clusters as free
2464
; mark all clusters as free
2383
        cmp     ecx, 0xFF8
2465
        cmp     ecx, 0xFF8
2384
        jae     .deleted
2466
        jae     .deleted
2385
        lea     ecx, [0x282000+ecx+ecx]
2467
        lea     ecx, [FLOPPY_FAT+ecx+ecx]
2386
        push    dword [ecx]
2468
        push    dword [ecx]
2387
        and     word [ecx], 0
2469
        and     word [ecx], 0
2388
        pop     ecx
2470
        pop     ecx
2389
        and     ecx, 0xFFF
2471
        and     ecx, 0xFFF
2390
        jmp     .delete
2472
        jmp     .delete
Line 2407... Line 2489...
2407
        jz      .truncate_done
2489
        jz      .truncate_done
2408
        call    SetUserInterrupts
2490
        call    SetUserInterrupts
2409
        pusha
2491
        pusha
2410
        call    read_chs_sector
2492
        call    read_chs_sector
2411
        popa
2493
        popa
2412
        add     edi, 0xD000
2494
        add     edi, FDD_BUFF
2413
        mov     ecx, 0xD000+0x200
2495
        mov     ecx, FDD_BUFF+0x200
2414
        sub     ecx, edi
2496
        sub     ecx, edi
2415
        push    eax
2497
        push    eax
2416
        xor     eax, eax
2498
        xor     eax, eax
2417
        rep     stosb
2499
        rep     stosb
2418
        pop     eax
2500
        pop     eax
Line 2469... Line 2551...
2469
        jz      @f
2551
        jz      @f
2470
        mov     al, 11
2552
        mov     al, 11
2471
@@:
2553
@@:
2472
        ret
2554
        ret
Line -... Line 2555...
-
 
2555
 
2473
 
2556
if 0
2474
;----------------------------------------------------------------
2557
;----------------------------------------------------------------
2475
;
2558
;
2476
;  fs_FloppyExecute - LFN variant for executing from floppy
2559
;  fs_FloppyExecute - LFN variant for executing from floppy
2477
;
2560
;
Line 2540... Line 2623...
2540
        add     eax, 31
2623
        add     eax, 31
2541
        call    read_chs_sector
2624
        call    read_chs_sector
2542
        cmp     [FDC_Status], 0
2625
        cmp     [FDC_Status], 0
2543
        jnz     .err
2626
        jnz     .err
2544
        pop     edi
2627
        pop     edi
2545
        mov     esi, 0xD000
2628
        mov     esi, FDD_BUFF
2546
        push    edi
2629
        push    edi
2547
        mov     ecx, 512/4
2630
        mov     ecx, 512/4
2548
        rep     movsd
2631
        rep     movsd
2549
        mov     eax, [esp+28]
2632
        mov     eax, [esp+28]
2550
        mov     ecx, [eax]
2633
        mov     ecx, [eax]
Line 2557... Line 2640...
2557
        rep     stosb
2640
        rep     stosb
2558
        pop     eax
2641
        pop     eax
2559
@@:
2642
@@:
2560
        mov     [eax], ecx
2643
        mov     [eax], ecx
2561
        mov     edx, [eax+4]
2644
        mov     edx, [eax+4]
2562
        mov     dx, [edx*2+0x282000]
2645
        mov     dx, [edx*2+FLOPPY_FAT]
2563
        mov     [eax+4], dx     ; high word is already zero
2646
        mov     [eax+4], dx     ; high word is already zero
2564
        popad
2647
        popad
2565
        xor     eax, eax
2648
        xor     eax, eax
2566
        ret
2649
        ret
2567
.eof:
2650
.eof:
Line 2570... Line 2653...
2570
        ret
2653
        ret
2571
.err:
2654
.err:
2572
        popad
2655
        popad
2573
        mov     eax, 11
2656
        mov     eax, 11
2574
        ret
2657
        ret
-
 
2658
end if
-
 
2659
 
-
 
2660
;----------------------------------------------------------------
-
 
2661
;
-
 
2662
;  fs_FloppyDelete - delete file or empty folder from floppy
-
 
2663
;
-
 
2664
;  esi  points to filename
-
 
2665
;
-
 
2666
;  ret  eax = 0 ok or other = errormsg
-
 
2667
;
-
 
2668
;--------------------------------------------------------------
-
 
2669
fs_FloppyDelete:
-
 
2670
        call    read_flp_fat
-
 
2671
        cmp     [FDC_Status], 0
-
 
2672
        jz      @f
-
 
2673
        push    11
-
 
2674
        jmp     .pop_ret
-
 
2675
@@:
-
 
2676
        cmp     byte [esi], 0
-
 
2677
        jnz     @f
-
 
2678
; cannot delete root!
-
 
2679
.access_denied:
-
 
2680
        push    ERROR_ACCESS_DENIED
-
 
2681
.pop_ret:
-
 
2682
        pop     eax
-
 
2683
        ret
-
 
2684
@@:
-
 
2685
        and     [fd_prev_sector], 0
-
 
2686
        and     [fd_prev_prev_sector], 0
-
 
2687
        push    edi
-
 
2688
        call    fd_find_lfn
-
 
2689
        jnc     .found
-
 
2690
        pop     edi
-
 
2691
        push    ERROR_FILE_NOT_FOUND
-
 
2692
        jmp     .pop_ret
-
 
2693
.found:
-
 
2694
        cmp     dword [edi], '.   '
-
 
2695
        jz      .access_denied2
-
 
2696
        cmp     dword [edi], '..  '
-
 
2697
        jz      .access_denied2
-
 
2698
        test    byte [edi+11], 10h
-
 
2699
        jz      .dodel
-
 
2700
; we can delete only empty folders!
-
 
2701
        push    eax
-
 
2702
        movzx   eax, word [edi+26]
-
 
2703
        push    ebx
-
 
2704
        pusha
-
 
2705
        add     eax, 31
-
 
2706
        call    read_chs_sector
-
 
2707
        popa
-
 
2708
        mov     ebx, FDD_BUFF + 2*0x20
-
 
2709
.checkempty:
-
 
2710
        cmp     byte [ebx], 0
-
 
2711
        jz      .empty
-
 
2712
        cmp     byte [ebx], 0xE5
-
 
2713
        jnz     .notempty
-
 
2714
        add     ebx, 0x20
-
 
2715
        cmp     ebx, FDD_BUFF + 0x200
-
 
2716
        jb      .checkempty
-
 
2717
        movzx   eax, word [FLOPPY_FAT + eax*2]
-
 
2718
        pusha
-
 
2719
        add     eax, 31
-
 
2720
        call    read_chs_sector
-
 
2721
        popa
-
 
2722
        mov     ebx, FDD_BUFF
-
 
2723
        jmp     .checkempty
-
 
2724
.notempty:
-
 
2725
        pop     ebx
-
 
2726
        pop     eax
-
 
2727
.access_denied2:
-
 
2728
        pop     edi
-
 
2729
        jmp     .access_denied
-
 
2730
.empty:
-
 
2731
        pop     ebx
-
 
2732
        pop     eax
-
 
2733
        pusha
-
 
2734
        call    read_chs_sector
-
 
2735
        popa
-
 
2736
.dodel:
-
 
2737
        push    eax
-
 
2738
        movzx   eax, word [edi+26]
-
 
2739
        xchg    eax, [esp]
-
 
2740
; delete folder entry
-
 
2741
        mov     byte [edi], 0xE5
-
 
2742
; delete LFN (if present)
-
 
2743
.lfndel:
-
 
2744
        cmp     edi, FDD_BUFF
-
 
2745
        ja      @f
-
 
2746
        cmp     [fd_prev_sector], 0
-
 
2747
        jz      .lfndone
-
 
2748
        push    [fd_prev_sector]
-
 
2749
        push    [fd_prev_prev_sector]
-
 
2750
        pop     [fd_prev_sector]
-
 
2751
        and     [fd_prev_prev_sector], 0
-
 
2752
        pusha
-
 
2753
        call    save_chs_sector
-
 
2754
        popa
-
 
2755
        pop     eax
-
 
2756
        pusha
-
 
2757
        call    read_chs_sector
-
 
2758
        popa
-
 
2759
        mov     edi, FDD_BUFF+0x200
-
 
2760
@@:
-
 
2761
        sub     edi, 0x20
-
 
2762
        cmp     byte [edi], 0xE5
-
 
2763
        jz      .lfndone
-
 
2764
        cmp     byte [edi+11], 0xF
-
 
2765
        jnz     .lfndone
-
 
2766
        mov     byte [edi], 0xE5
-
 
2767
        jmp     .lfndel
-
 
2768
.lfndone:
-
 
2769
        pusha
-
 
2770
        call    save_chs_sector
-
 
2771
        popa
-
 
2772
; delete FAT chain
-
 
2773
        pop     eax
-
 
2774
        test    eax, eax
-
 
2775
        jz      .done
-
 
2776
@@:
-
 
2777
        lea     eax, [FLOPPY_FAT + eax*2]
-
 
2778
        push    dword [eax]
-
 
2779
        and     word [eax], 0
-
 
2780
        pop     eax
-
 
2781
        and     eax, 0xFFF
-
 
2782
        jnz     @b
-
 
2783
.done:
-
 
2784
        call    save_flp_fat
-
 
2785
        pop     edi
-
 
2786
        xor     eax, eax
-
 
2787
        ret
Line 2575... Line 2788...
2575
 
2788