Subversion Repositories Kolibri OS

Rev

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

Rev 78 Rev 83
Line 543... Line 543...
543
    rep    cmpsb            ;Found the file?
543
    rep    cmpsb            ;Found the file?
544
    je     fifoundd_1          ;Yes
544
    je     fifoundd_1          ;Yes
545
    add    ecx,21
545
    add    ecx,21
546
    add    edi, ecx         ;Advance to next entry
546
    add    edi, ecx         ;Advance to next entry
547
    dec    dl
547
    dec    dl
548
    cmp    dl,0
-
 
549
    jne    l.21_2
548
    jne    l.21_2
550
    dec    dh
549
    dec    dh
551
    cmp    dh,0
-
 
552
    jne    l.20_2
550
    jne    l.20_2
553
    jmp    frnoreadd_1
551
    jmp    frnoreadd_1
Line 554... Line 552...
554
 
552
 
555
fdc_status_error_4:
553
fdc_status_error_4:
Line 559... Line 557...
559
 
557
 
560
fifoundd_1:
558
fifoundd_1:
561
    mov    eax,[path_pointer_flp]
559
    mov    eax,[path_pointer_flp]
562
    cmp    [eax+36],byte 0
560
    cmp    [eax+36],byte 0
563
    je    fifoundd_2
-
 
564
    add    edi,0xf
561
    je    fifoundd_2
565
    mov    eax,[edi]
-
 
566
    and    eax,65535
562
    movzx  eax, word [edi+0xf]
567
    mov    ebx,[path_pointer_flp]
563
    mov    ebx,[path_pointer_flp]
568
    add    ebx,36
564
    add    ebx,36
569
    call   get_cluster_of_a_path_flp
565
    call   get_cluster_of_a_path_flp
570
    jc     frnoreadd_1_1    
566
    jc     frnoreadd_1_1    
Line 573... Line 569...
573
    jmp    fifoundd_2_1
569
    jmp    fifoundd_2_1
574
fifoundd_2:
570
fifoundd_2:
575
    dec    [FDD_Sector]
571
    dec    [FDD_Sector]
576
fifoundd_2_1:
572
fifoundd_2_1:
577
    mov    [edi-11],byte 0xE5    ;mark filename deleted
573
    mov    [edi-11],byte 0xE5    ;mark filename deleted
578
    add    edi,0xf
-
 
579
    mov    eax,[edi]
-
 
580
    and    eax,65535
-
 
581
    mov    edi,eax            ;edi = cluster
574
        movzx   edi, word [edi+0xf] ;edi = cluster
582
frnewd_1:
575
frnewd_1:
583
    shl    edi,1            ;find next cluster from FAT
576
    shl    edi,1            ;find next cluster from FAT
584
    add    edi,0x282000
577
    add    edi,0x282000
585
    mov    eax,[edi]
578
    mov    eax,[edi]
586
    mov    [edi],word 0x0        ;clear fat chain cluster
579
    mov    [edi],word 0x0        ;clear fat chain cluster
Line 672... Line 665...
672
    mov    edi,0x8000   ;Point at directory
665
    mov    edi,0x8000   ;Point at directory
673
    mov    edx,224 +1
666
    mov    edx,224 +1
674
    ; find an empty spot for filename in the root dir
667
    ; find an empty spot for filename in the root dir
675
l20ds_1:
668
l20ds_1:
676
    sub    edx,1
669
    sub    edx,1
677
    cmp    edx,0
-
 
678
    jnz    l21ds_1
-
 
679
    jmp    frnoreadds_1
670
    jz     frnoreadds_1
680
l21ds_1:
671
l21ds_1:
681
    cmp    [edi],byte 0xE5
672
    cmp    [edi],byte 0xE5
682
    jz     fifoundds_1
673
    jz     fifoundds_1
683
    cmp    [edi],byte 0x0
674
    cmp    [edi],byte 0x0
684
    jz     fifoundds_1
675
    jz     fifoundds_1
Line 707... Line 698...
707
    rep    cmpsb            ;Found the file?
698
    rep    cmpsb            ;Found the file?
708
    je     fifoundds_3          ;Yes
699
    je     fifoundds_3          ;Yes
709
    add    ecx,21
700
    add    ecx,21
710
    add    edi, ecx         ;Advance to next entry
701
    add    edi, ecx         ;Advance to next entry
711
    dec    dl
702
    dec    dl
712
    cmp    dl,0
-
 
713
    jne    l.21_3
703
    jne    l.21_3
714
    dec    dh
704
    dec    dh
715
    cmp    dh,0
-
 
716
    jne    l.20_3
705
    jne    l.20_3
717
fdc_status_error_8:
706
fdc_status_error_8:
718
    pop     edi esi edx ecx ebx eax
707
    pop     edi esi edx ecx ebx eax
719
    mov    eax,5            ; file not found ?
708
    mov    eax,5            ; file not found ?
720
    mov    ebx,-1
709
    mov    ebx,-1
Line 795... Line 784...
795
    mov    edi,ebx            ; find free cluster in FAT
784
    mov    edi,ebx            ; find free cluster in FAT
796
    shl    edi,1
785
    shl    edi,1
797
    add    edi,0x282000
786
    add    edi,0x282000
798
    mov    eax,[edi]
787
    mov    eax,[edi]
799
    and    eax,4095
788
    and    eax,4095
800
    cmp    eax,0x0
-
 
801
    jnz    frnewds_2
789
    jnz    frnewds_2
802
    mov    [edx],bx         ; save next cluster pos. to prev cl.
790
    mov    [edx],bx         ; save next cluster pos. to prev cl.
803
    mov    edx,edi            ; next save pos abs mem add
791
    mov    edx,edi            ; next save pos abs mem add
804
    ret
792
    ret
Line 1081... Line 1069...
1081
 
1069
 
1082
   pop ebx
1070
   pop ebx
Line 1083... Line 1071...
1083
   ret
1071
   ret
1084
 
1072
 
1085
; \begin{diamond}
1073
; \begin{diamond}
-
 
1074
fat_find_lfn:
-
 
1075
; in: esi->name
-
 
1076
;     [esp+4] = next
1086
fd_find_lfn:
1077
;     [esp+8] = first
1087
; in: esi->name
1078
;     [esp+C]... - possibly parameters for first and next
1088
; out: CF=1 - file not found
1079
; out: CF=1 - file not found
-
 
1080
;      else CF=0, esi->next name component, edi->direntry
-
 
1081
        pusha
-
 
1082
        lea     eax, [esp+0Ch+20h]
1089
;      else CF=0 and edi->direntry
1083
        call    dword [eax-4]
1090
        pusha
1084
        jc      .reterr
1091
        sub     esp, 262*2      ; reserve place for LFN
1085
        sub     esp, 262*2      ; reserve place for LFN
1092
        mov     ebp, esp
-
 
1093
        push    0               ; for fat_get_name: read ASCII name
-
 
1094
        call    read_flp_fat
-
 
1095
        cmp     [FDC_Status], 0
-
 
1096
        jnz     .error
-
 
1097
        mov     eax, 19
-
 
1098
        mov     dh, 14
1086
        mov     ebp, esp
1099
.main_loop:
-
 
1100
.20_1:
-
 
1101
        pusha
-
 
1102
        call    read_chs_sector
-
 
1103
        popa
-
 
1104
        cmp     [FDC_Status], 0
-
 
1105
        jnz     .error
-
 
1106
        mov     edi, 0xD000
-
 
1107
        inc     [FDD_Sector]
-
 
1108
        push    eax
1087
        push    0               ; for fat_get_name: read ASCII name
1109
.21_1:
1088
.l1:
1110
        call    fat_get_name
1089
        call    fat_get_name
1111
        jc      @f
1090
        jc      .l2
1112
        call    fat_compare_name
1091
        call    fat_compare_name
1113
        jz      .found
-
 
1114
@@:
1092
        jz      .found
1115
        add     edi, 0x20
-
 
1116
        cmp     edi, 0xD200
-
 
1117
        jb      .21_1
1093
.l2:
1118
        pop     eax
-
 
1119
        inc     eax
-
 
1120
        dec     dh
1094
        lea     eax, [esp+0Ch+20h+262*2+4]
1121
        js      @f
-
 
1122
        jnz     .20_1
1095
        call    dword [eax-8]
1123
.error:
1096
        jnc     .l1
1124
        add     esp, 262*2+4
1097
        add     esp, 262*2+4
-
 
1098
.reterr:
1125
        popa
1099
        stc
1126
        stc
-
 
1127
        ret
-
 
1128
@@:
-
 
1129
; read next sector from FAT
-
 
1130
        mov     eax, [(eax-31-1)*2+0x282000]
-
 
1131
        and     eax, 0xFFF
-
 
1132
        cmp     eax, 0xFF8
-
 
1133
        jae     .error
-
 
1134
        add     eax, 31
1100
        popa
1135
        jmp     .main_loop
1101
        ret
1136
.found:
1102
.found:
1137
        pop     eax
1103
        add     esp, 262*2+4
-
 
1104
; if this is LFN entry, advance to true entry
-
 
1105
        cmp     byte [edi+11], 0xF
-
 
1106
        jnz     @f
1138
; if LFN entry, advance to corresponding short entry
1107
        lea     eax, [esp+0Ch+20h]
-
 
1108
        call    dword [eax-8]
-
 
1109
        jc      .reterr
-
 
1110
@@:
-
 
1111
        add     esp, 8          ; CF=0
-
 
1112
        push    esi
-
 
1113
        push    edi
-
 
1114
        popa
-
 
1115
        ret
-
 
1116
 
-
 
1117
flp_root_next:
1139
        cmp     byte [edi+11], 0xF
1118
        cmp     edi, 0xD200-0x20
1140
        jnz     .entryfound
1119
        jae     @f
-
 
1120
        add     edi, 0x20
-
 
1121
        ret     ; CF=0
1141
        add     edi, 0x20
1122
@@:
1142
        cmp     edi, 0xD200
1123
; read next sector
-
 
1124
        inc     dword [eax]
-
 
1125
        cmp     dword [eax], 14
1143
        jb      .entryfound
1126
        jae     flp_root_first.readerr
-
 
1127
flp_root_first:
1144
        dec     dh
1128
        mov     eax, [eax]
1145
        jz      .error
1129
        pusha
-
 
1130
        add     eax, 19
1146
        inc     eax
1131
        call    read_chs_sector
1147
        call    read_chs_sector
1132
        popa
1148
        cmp     [FDC_Status], 0
1133
        cmp     [FDC_Status], 0
-
 
1134
        jnz     .readerr
1149
        jnz     .error
1135
        mov     edi, 0xD000
-
 
1136
        ret     ; CF=0
-
 
1137
.readerr:
-
 
1138
        stc
-
 
1139
        ret
-
 
1140
 
-
 
1141
flp_rootmem_first:
-
 
1142
        mov     edi, 0x8000
-
 
1143
        clc
-
 
1144
        ret
-
 
1145
flp_rootmem_next:
-
 
1146
        add     edi, 0x20
-
 
1147
        cmp     edi, 0x8000+14*0x200
-
 
1148
        cmc
-
 
1149
flp_rootmem_next_write:
-
 
1150
flp_rootmem_begin_write:
-
 
1151
flp_rootmem_end_write:
-
 
1152
        ret
-
 
1153
flp_rootmem_extend_dir:
-
 
1154
        stc
-
 
1155
        ret
1150
        mov     edi, 0xD000
1156
 
-
 
1157
flp_notroot_next:
-
 
1158
        cmp     edi, 0xD200-0x20
1151
.entryfound:
1159
        jae     flp_notroot_next_sector
-
 
1160
        add     edi, 0x20
-
 
1161
        ret     ; CF=0
-
 
1162
flp_notroot_next_sector:
-
 
1163
        push    ecx
-
 
1164
        mov     ecx, [eax]
-
 
1165
        mov     ecx, [ecx*2+0x282000]
1152
        cmp     byte [esi], 0
1166
        and     ecx, 0xFFF
-
 
1167
        cmp     ecx, 2849
-
 
1168
        jae     flp_notroot_first.err2
-
 
1169
        mov     [eax], ecx
-
 
1170
        pop     ecx
-
 
1171
flp_notroot_first:
1153
        jz      .done
1172
        mov     eax, [eax]
1154
        test    byte [edi+11], 10h	; is a directory?
1173
        cmp     eax, 2
-
 
1174
        jb      .err
-
 
1175
        cmp     eax, 2849
1155
        jz      .error
1176
        jae     .err
-
 
1177
        pusha
-
 
1178
        add     eax, 31
1156
        movzx   eax, word [edi+26]
1179
        call    read_chs_sector
-
 
1180
        popa
1157
        add     eax, 31
1181
        mov     edi, 0xD000
-
 
1182
        cmp     [FDC_Status], 0
1158
        mov     dh, 0
1183
        jnz     .err
-
 
1184
        ret     ; CF=0
-
 
1185
.err2:
-
 
1186
        pop     ecx
-
 
1187
.err:
-
 
1188
        stc
-
 
1189
        ret
-
 
1190
flp_notroot_begin_write:
-
 
1191
        pusha
-
 
1192
        mov     eax, [eax]
-
 
1193
        add     eax, 31
-
 
1194
        call    read_chs_sector
-
 
1195
        popa
-
 
1196
        ret
-
 
1197
flp_notroot_end_write:
-
 
1198
        pusha
-
 
1199
        mov     eax, [eax]
-
 
1200
        add     eax, 31
-
 
1201
        call    save_chs_sector
-
 
1202
        popa
-
 
1203
        ret
-
 
1204
flp_notroot_next_write:
-
 
1205
        cmp     edi, 0xD200
-
 
1206
        jae     @f
-
 
1207
        ret
-
 
1208
@@:
-
 
1209
        call    flp_notroot_end_write
-
 
1210
        jmp     flp_notroot_next_sector
-
 
1211
flp_notroot_extend_dir:
-
 
1212
; find free cluster in FAT
-
 
1213
        pusha
-
 
1214
        xor     eax, eax
-
 
1215
        mov     edi, 0x282000
-
 
1216
        mov     ecx, 2849
-
 
1217
        repnz   scasw
1159
        jmp     .main_loop
1218
        jnz     .notfound
-
 
1219
        mov     word [edi-2], 0xFFF     ; mark as last cluster
1160
.done:
1220
        sub     edi, 0x282000
-
 
1221
        shr     edi, 1
-
 
1222
        dec     edi
-
 
1223
        mov     eax, [esp+28]
-
 
1224
        mov     ecx, [eax]
-
 
1225
        mov     [0x282000+ecx*2], di
-
 
1226
        mov     [eax], edi
-
 
1227
        xor     eax, eax
-
 
1228
        mov     edi, 0xD000
-
 
1229
        mov     ecx, 128
-
 
1230
        rep     stosd
-
 
1231
        popa
-
 
1232
        call    flp_notroot_end_write
-
 
1233
        mov     edi, 0xD000
-
 
1234
        clc
1161
        add     esp, 262*2+4+4
1235
        ret
-
 
1236
.notfound:
-
 
1237
        popa
-
 
1238
        stc
-
 
1239
        ret
-
 
1240
 
-
 
1241
fd_find_lfn:
-
 
1242
; in: esi->name
-
 
1243
; out: CF=1 - file not found
-
 
1244
;      else CF=0 and edi->direntry
-
 
1245
        push    esi edi
-
 
1246
        push    0
-
 
1247
        push    flp_root_first
-
 
1248
        push    flp_root_next
-
 
1249
.loop:
-
 
1250
        call    fat_find_lfn
-
 
1251
        jc      .notfound
-
 
1252
        cmp     byte [esi], 0
-
 
1253
        jz      .found
-
 
1254
        test    byte [edi+11], 10h
-
 
1255
        jz      .notfound
-
 
1256
        movzx   eax, word [edi+26]      ; cluster
-
 
1257
        mov     [esp+8], eax
-
 
1258
        mov     dword [esp+4], flp_notroot_first
-
 
1259
        mov     dword [esp], flp_notroot_next
-
 
1260
        jmp     .loop
-
 
1261
.notfound:
-
 
1262
        add     esp, 12
-
 
1263
        pop     edi esi
-
 
1264
        stc
-
 
1265
        ret
-
 
1266
.found:
1162
        push    edi
1267
        add     esp, 16         ; CF=0
Line 1163... Line 1268...
1163
        popad
1268
        pop     esi
1164
        ret
1269
        ret
1165
 
1270
 
Line 1257... Line 1362...
1257
        jmp     .reteof
1362
        jmp     .reteof
1258
.err:
1363
.err:
1259
        mov     ebx, edx
1364
        mov     ebx, edx
1260
        pop     eax edx ecx edi
1365
        pop     eax edx ecx edi
1261
        sub     ebx, edx
1366
        sub     ebx, edx
1262
        mov     al, 5  ; may be other error code?
1367
        mov     al, 11
1263
        ret
1368
        ret
Line 1264... Line 1369...
1264
 
1369
 
1265
;----------------------------------------------------------------
1370
;----------------------------------------------------------------
1266
;
1371
;
Line 1396... Line 1501...
1396
        mov     al, ERROR_END_OF_FILE
1501
        mov     al, ERROR_END_OF_FILE
1397
@@:
1502
@@:
1398
        pop     ecx edi edi
1503
        pop     ecx edi edi
1399
        ret
1504
        ret
Line -... Line 1505...
-
 
1505
 
-
 
1506
;----------------------------------------------------------------
-
 
1507
;
-
 
1508
;  fs_FloppyRewrite - LFN variant for writing sys floppy
-
 
1509
;
-
 
1510
;  esi  points to filename
-
 
1511
;  ebx  ignored (reserved)
-
 
1512
;  ecx  number of bytes to write, 0+
-
 
1513
;  edx  mem location to data
-
 
1514
;
-
 
1515
;  ret ebx = number of written bytes
-
 
1516
;      eax = 0 ok read or other = errormsg
-
 
1517
;
-
 
1518
;--------------------------------------------------------------
-
 
1519
@@:
-
 
1520
        mov     eax, ERROR_ACCESS_DENIED
-
 
1521
        xor     ebx, ebx
-
 
1522
        ret
-
 
1523
fsfrfe2:
-
 
1524
        popad
-
 
1525
fsfrfe:
-
 
1526
        mov     eax, 11
-
 
1527
        xor     ebx, ebx
-
 
1528
        ret
-
 
1529
 
-
 
1530
fs_FloppyRewrite:
-
 
1531
        cmp     byte [esi], 0
-
 
1532
        jz      @b
-
 
1533
        call    read_flp_fat
-
 
1534
        cmp     [FDC_Status], 0
-
 
1535
        jnz     fsfrfe
-
 
1536
        pushad
-
 
1537
        xor     ebp, ebp
-
 
1538
        push    esi
-
 
1539
@@:
-
 
1540
        lodsb
-
 
1541
        test    al, al
-
 
1542
        jz      @f
-
 
1543
        cmp     al, '/'
-
 
1544
        jnz     @b
-
 
1545
        lea     ebp, [esi-1]
-
 
1546
        jmp     @b
-
 
1547
@@:
-
 
1548
        pop     esi
-
 
1549
        test    ebp, ebp
-
 
1550
        jnz     .noroot
-
 
1551
        call    read_flp_root
-
 
1552
        cmp     [FDC_Status], 0
-
 
1553
        jnz     fsfrfe2
-
 
1554
        push    flp_rootmem_extend_dir
-
 
1555
        push    flp_rootmem_end_write
-
 
1556
        push    flp_rootmem_next_write
-
 
1557
        push    flp_rootmem_begin_write
-
 
1558
        xor     ebp, ebp
-
 
1559
        push    ebp
-
 
1560
        push    flp_rootmem_first
-
 
1561
        push    flp_rootmem_next
-
 
1562
        jmp     .common1
-
 
1563
.noroot:
-
 
1564
; check existence
-
 
1565
        mov     byte [ebp], 0
-
 
1566
        call    fd_find_lfn
-
 
1567
        mov     byte [ebp], '/'
-
 
1568
        lea     esi, [ebp+1]
-
 
1569
        jnc     @f
-
 
1570
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
1571
.ret1:
-
 
1572
        mov     [esp+28], eax
-
 
1573
        popad
-
 
1574
        xor     ebx, ebx
-
 
1575
        ret
-
 
1576
@@:
-
 
1577
        test    byte [edi+11], 0x10     ; must be directory
-
 
1578
        mov     eax, ERROR_ACCESS_DENIED
-
 
1579
        jz      .ret1
-
 
1580
        movzx   ebp, word [edi+26]      ; ebp=cluster
-
 
1581
        mov     eax, ERROR_FAT_TABLE
-
 
1582
        cmp     ebp, 2
-
 
1583
        jb      .ret1
-
 
1584
        cmp     ebp, 2849
-
 
1585
        jae     .ret1
-
 
1586
        push    flp_notroot_extend_dir
-
 
1587
        push    flp_notroot_end_write
-
 
1588
        push    flp_notroot_next_write
-
 
1589
        push    flp_notroot_begin_write
-
 
1590
        push    ebp
-
 
1591
        push    flp_notroot_first
-
 
1592
        push    flp_notroot_next
-
 
1593
.common1:
-
 
1594
        call    fat_find_lfn
-
 
1595
        jc      .notfound
-
 
1596
; found, delete FAT chain
-
 
1597
        push    edi
-
 
1598
        xor     eax, eax
-
 
1599
        mov     dword [edi+28], eax     ; zero size
-
 
1600
        xchg    ax, word [edi+26]       ; start cluster
-
 
1601
        test    eax, eax
-
 
1602
        jz      .done1
-
 
1603
@@:
-
 
1604
        cmp     eax, 0xFF8
-
 
1605
        jae     .done1
-
 
1606
        lea     edi, [0x282000 + eax*2] ; position in FAT
-
 
1607
        xor     eax, eax
-
 
1608
        xchg    ax, [edi]
-
 
1609
        jmp     @b
-
 
1610
.done1:
-
 
1611
        pop     edi
-
 
1612
        call    get_time_for_file
-
 
1613
        mov     [edi+22], ax
-
 
1614
        call    get_date_for_file
-
 
1615
        mov     [edi+24], ax
-
 
1616
        mov     [edi+18], ax
-
 
1617
        or      byte [edi+11], 20h      ; set 'archive' attribute
-
 
1618
        jmp     .doit
-
 
1619
.notfound:
-
 
1620
; file is not found; generate short name
-
 
1621
        call    fat_name_is_legal
-
 
1622
        jc      @f
-
 
1623
        add     esp, 28
-
 
1624
        popad
-
 
1625
        mov     eax, ERROR_FILE_NOT_FOUND
-
 
1626
        xor     ebx, ebx
-
 
1627
        ret
-
 
1628
@@:
-
 
1629
        sub     esp, 12
-
 
1630
        mov     edi, esp
-
 
1631
        call    fat_gen_short_name
-
 
1632
.test_short_name_loop:
-
 
1633
        push    esi edi ecx
-
 
1634
        mov     esi, edi
-
 
1635
        lea     eax, [esp+12+12+8]
-
 
1636
        mov     [eax], ebp
-
 
1637
        call    dword [eax-4]
-
 
1638
        jc      .found
-
 
1639
.test_short_name_entry:
-
 
1640
        cmp     byte [edi+11], 0xF
-
 
1641
        jz      .test_short_name_cont
-
 
1642
        mov     ecx, 11
-
 
1643
        push    esi edi
-
 
1644
        repz    cmpsb
-
 
1645
        pop     edi esi
-
 
1646
        jz      .short_name_found
-
 
1647
.test_short_name_cont:
-
 
1648
        lea     eax, [esp+12+12+8]
-
 
1649
        call    dword [eax-8]
-
 
1650
        jnc     .test_short_name_entry
-
 
1651
        jmp     .found
-
 
1652
.short_name_found:
-
 
1653
        pop     ecx edi esi
-
 
1654
        call    fat_next_short_name
-
 
1655
        jnc     .test_short_name_loop
-
 
1656
.disk_full:
-
 
1657
        add     esp, 12+28
-
 
1658
        popa
-
 
1659
        mov     eax, ERROR_DISK_FULL
-
 
1660
        xor     ebx, ebx
-
 
1661
        ret
-
 
1662
.found:
-
 
1663
        pop     ecx edi esi
-
 
1664
; now find space in directory
-
 
1665
; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~'
-
 
1666
        mov     al, '~'
-
 
1667
        push    ecx edi
-
 
1668
        mov     ecx, 8
-
 
1669
        repnz   scasb
-
 
1670
        push    1
-
 
1671
        pop     eax     ; 1 entry
-
 
1672
        jnz     .notilde
-
 
1673
; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total
-
 
1674
        xor     eax, eax
-
 
1675
@@:
-
 
1676
        cmp     byte [esi], 0
-
 
1677
        jz      @f
-
 
1678
        inc     esi
-
 
1679
        inc     eax
-
 
1680
        jmp     @b
-
 
1681
@@:
-
 
1682
        sub     esi, eax
-
 
1683
        add     eax, 12+13
-
 
1684
        mov     ecx, 13
-
 
1685
        push    edx
-
 
1686
        cdq
-
 
1687
        div     ecx
-
 
1688
        pop     edx
-
 
1689
.notilde:
-
 
1690
        push    -1
-
 
1691
        push    -1
-
 
1692
; find  successive entries in directory
-
 
1693
        xor     ecx, ecx
-
 
1694
        push    eax
-
 
1695
        lea     eax, [esp+12+8+12+8]
-
 
1696
        mov     [eax], ebp
-
 
1697
        call    dword [eax-4]
-
 
1698
        pop     eax
-
 
1699
        jnc     .scan_dir
-
 
1700
.fsfrfe3:
-
 
1701
        add     esp, 8+8+12+28
-
 
1702
        popad
-
 
1703
        mov     eax, 11
-
 
1704
        xor     ebx, ebx
-
 
1705
        ret
-
 
1706
.scan_dir:
-
 
1707
        cmp     byte [edi], 0
-
 
1708
        jz      .free
-
 
1709
        cmp     byte [edi], 0xE5
-
 
1710
        jz      .free
-
 
1711
        xor     ecx, ecx
-
 
1712
.scan_cont:
-
 
1713
        push    eax
-
 
1714
        lea     eax, [esp+12+8+12+8]
-
 
1715
        call    dword [eax-8]
-
 
1716
        pop     eax
-
 
1717
        jnc     .scan_dir
-
 
1718
        cmp     [FDC_Status], 0
-
 
1719
        jnz     .fsfrfe3
-
 
1720
        push    eax
-
 
1721
        lea     eax, [esp+12+8+12+8]
-
 
1722
        call    dword [eax+16]          ; extend directory
-
 
1723
        pop     eax
-
 
1724
        jnc     .scan_dir
-
 
1725
        add     esp, 8+8+12+28
-
 
1726
        popad
-
 
1727
        mov     eax, ERROR_DISK_FULL
-
 
1728
        xor     ebx, ebx
-
 
1729
        ret
-
 
1730
.free:
-
 
1731
        test    ecx, ecx
-
 
1732
        jnz     @f
-
 
1733
        mov     [esp], edi
-
 
1734
        mov     ecx, [esp+8+8+12+8]
-
 
1735
        mov     [esp+4], ecx
-
 
1736
        xor     ecx, ecx
-
 
1737
@@:
-
 
1738
        inc     ecx
-
 
1739
        cmp     ecx, eax
-
 
1740
        jb      .scan_cont
-
 
1741
; found!
-
 
1742
; calculate name checksum
-
 
1743
        push    esi ecx
-
 
1744
        mov     esi, [esp+8+8]
-
 
1745
        mov     ecx, 11
-
 
1746
        xor     eax, eax
-
 
1747
@@:
-
 
1748
        ror     al, 1
-
 
1749
        add     al, [esi]
-
 
1750
        inc     esi
-
 
1751
        loop    @b
-
 
1752
        pop     ecx esi
-
 
1753
        pop     edi
-
 
1754
        pop     dword [esp+8+12+8]
-
 
1755
; edi points to first entry in free chunk
-
 
1756
        dec     ecx
-
 
1757
        jz      .nolfn
-
 
1758
        push    esi
-
 
1759
        push    eax
-
 
1760
        lea     eax, [esp+8+8+12+8]
-
 
1761
        call    dword [eax+4]         ; begin write
-
 
1762
        mov     al, 40h
-
 
1763
.writelfn:
-
 
1764
        or      al, cl
-
 
1765
        mov     esi, [esp+4]
-
 
1766
        push    ecx
-
 
1767
        dec     ecx
-
 
1768
        imul    ecx, 13
-
 
1769
        add     esi, ecx
-
 
1770
        stosb
-
 
1771
        mov     cl, 5
-
 
1772
        call    fs_RamdiskRewrite.read_symbols
-
 
1773
        mov     ax, 0xF
-
 
1774
        stosw
-
 
1775
        mov     al, [esp+4]
-
 
1776
        stosb
-
 
1777
        mov     cl, 6
-
 
1778
        call    fs_RamdiskRewrite.read_symbols
-
 
1779
        xor     eax, eax
-
 
1780
        stosw
-
 
1781
        mov     cl, 2
-
 
1782
        call    fs_RamdiskRewrite.read_symbols
-
 
1783
        pop     ecx
-
 
1784
        lea     eax, [esp+8+8+12+8]
-
 
1785
        call    dword [eax+8]         ; next write
-
 
1786
        xor     eax, eax
-
 
1787
        loop    .writelfn
-
 
1788
        pop     eax
-
 
1789
        pop     esi
-
 
1790
;        lea     eax, [esp+8+12+8]
-
 
1791
;        call    dword [eax+12]          ; end write
-
 
1792
.nolfn:
-
 
1793
        xchg    esi, [esp]
-
 
1794
        mov     ecx, 11
-
 
1795
        rep     movsb
-
 
1796
        mov     word [edi], 20h         ; attributes
-
 
1797
        sub     edi, 11
-
 
1798
        pop     esi ecx
-
 
1799
        add     esp, 12
-
 
1800
        mov     byte [edi+13], 0        ; tenths of a second at file creation time
-
 
1801
        call    get_time_for_file
-
 
1802
        mov     [edi+14], ax            ; creation time
-
 
1803
        mov     [edi+22], ax            ; last write time
-
 
1804
        call    get_date_for_file
-
 
1805
        mov     [edi+16], ax            ; creation date
-
 
1806
        mov     [edi+24], ax            ; last write date
-
 
1807
        mov     [edi+18], ax            ; last access date
-
 
1808
        and     word [edi+20], 0        ; high word of cluster
-
 
1809
        and     word [edi+26], 0        ; low word of cluster - to be filled
-
 
1810
        and     dword [edi+28], 0       ; file size - to be filled
-
 
1811
.doit:
-
 
1812
        lea     eax, [esp+8]
-
 
1813
        call    dword [eax+12]  ; flush directory
-
 
1814
        push    ecx
-
 
1815
        push    edi
-
 
1816
        add     edi, 26         ; edi points to low word of cluster
-
 
1817
        push    edi
-
 
1818
        mov     esi, edx
-
 
1819
        jecxz   .done
-
 
1820
        mov     ecx, 2849
-
 
1821
        mov     edi, 0x282000
-
 
1822
        push    0       ; first cluster
-
 
1823
.write_loop:
-
 
1824
; allocate new cluster
-
 
1825
        xor     eax, eax
-
 
1826
        repnz   scasw
-
 
1827
        mov     al, ERROR_DISK_FULL
-
 
1828
        jnz     .ret
-
 
1829
        dec     edi
-
 
1830
        dec     edi
-
 
1831
        lea     eax, [edi-0x282000]
-
 
1832
        shr     eax, 1                  ; eax = cluster
-
 
1833
        mov     word [edi], 0xFFF       ; mark as last cluster
-
 
1834
        cmp     dword [esp], 0
-
 
1835
        jz      .first
-
 
1836
        xchg    edi, [esp+4]
-
 
1837
        stosw
-
 
1838
        mov     edi, [esp+4]
-
 
1839
        jmp     @f
-
 
1840
.first:
-
 
1841
        mov     [esp], eax
-
 
1842
@@:
-
 
1843
        inc     ecx
-
 
1844
; write data
-
 
1845
        push    ecx edi
-
 
1846
        mov     ecx, 512
-
 
1847
        cmp     dword [esp+20], ecx
-
 
1848
        jae     @f
-
 
1849
        mov     ecx, [esp+20]
-
 
1850
@@:
-
 
1851
        push    ecx
-
 
1852
        mov     edi, 0xD000
-
 
1853
        rep     movsb
-
 
1854
        pop     ecx
-
 
1855
        push    ecx
-
 
1856
        sub     ecx, 512
-
 
1857
        neg     ecx
-
 
1858
        push    eax
-
 
1859
        xor     eax, eax
-
 
1860
        rep     stosb
-
 
1861
        pop     eax
-
 
1862
        add     eax, 31
-
 
1863
        pusha
-
 
1864
        call    save_chs_sector
-
 
1865
        popa
-
 
1866
        pop     ecx
-
 
1867
        cmp     [FDC_Status], 0
-
 
1868
        jnz     .diskerr
-
 
1869
        sub     [esp+20], ecx
-
 
1870
        pop     edi ecx
-
 
1871
        jnz     .write_loop
-
 
1872
.done:
-
 
1873
        xor     eax, eax
-
 
1874
.ret:
-
 
1875
        pop     ebx edi edi ecx
-
 
1876
        mov     [esp+28+28], eax
-
 
1877
        lea     eax, [esp+8]
-
 
1878
        call    dword [eax+4]
-
 
1879
        mov     [edi+26], bx
-
 
1880
        mov     ebx, esi
-
 
1881
        sub     ebx, edx
-
 
1882
        mov     [edi+28], ebx
-
 
1883
        call    dword [eax+12]
-
 
1884
        mov     [esp+28+16], ebx
-
 
1885
        test    ebp, ebp
-
 
1886
        jnz     @f
-
 
1887
        call    save_flp_root
-
 
1888
@@:
-
 
1889
        add     esp, 28
-
 
1890
        cmp     [FDC_Status], 0
-
 
1891
        jnz     .err3
-
 
1892
        call    save_flp_fat
-
 
1893
        cmp     [FDC_Status], 0
-
 
1894
        jnz     .err3
-
 
1895
        popa
-
 
1896
        ret
-
 
1897
.err3:
-
 
1898
        popa
-
 
1899
        mov     al, 11
-
 
1900
        xor     ebx, ebx
-
 
1901
        ret
-
 
1902
.diskerr:
-
 
1903
        sub     esi, ecx
-
 
1904
        mov     eax, 11
-
 
1905
        pop     edi ecx
-
 
1906
        jmp     .ret
1400
 
1907