Subversion Repositories Kolibri OS

Rev

Rev 3500 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
593 mikedld 2
;;                                                              ;;
2465 Serge 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;                                                              ;;
593 mikedld 7
;; System service for filesystem call                           ;;
8
;; (C) 2004 Ville Turjanmaa, License: GPL                       ;;
9
;; 29.04.2006 Elimination of hangup after the                   ;;
10
;;            expiration hd_wait_timeout (for LBA) -  Mario79   ;;
431 serge 11
;; 15.01.2005 get file size/attr/date,                          ;;
12
;;            file_append (only for hd) - ATV                   ;;
593 mikedld 13
;; 23.11.2004 test if hd/partition is set - ATV                 ;;
14
;; 18.11.2004 get_disk_info and more error codes - ATV          ;;
15
;; 08.11.2004 expand_pathz and rename (only for hd) - ATV       ;;
16
;; 20.10.2004 Makedir/Removedir (only for hd) - ATV             ;;
17
;;                                                              ;;
431 serge 18
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 19
 
593 mikedld 20
$Revision: 3555 $
21
 
22
 
1 ha 23
iglobal
3500 Serge 24
 
25
if lang eq sp
26
include 'fs/fs-sp.inc'
27
else
2434 Serge 28
dir0:
29
             db  'HARDDISK   '
1 ha 30
             db  'RAMDISK    '
31
             db  'FLOPPYDISK '
32
             db  0
33
 
2434 Serge 34
dir1:
35
             db  'FIRST      '
1 ha 36
             db  'SECOND     '
37
             db  'THIRD      '
38
             db  'FOURTH     '
39
             db  0
3500 Serge 40
end if
1 ha 41
 
42
not_select_IDE db 0
43
 
2434 Serge 44
hd_address_table:
45
                   dd  0x1f0,0x00,0x1f0,0x10
1 ha 46
                   dd  0x170,0x00,0x170,0x10
47
endg
48
 
74 mario79 49
file_system:
50
 
1 ha 51
; IN:
52
;
133 diamond 53
; eax = 0  ; read file          /RamDisk/First  6
1 ha 54
; eax = 8  ; lba read
55
; eax = 15 ; get_disk_info
56
;
57
; OUT:
58
;
59
; eax = 0  : read ok
61 halyavin 60
; eax = 1  : no hd base and/or partition defined
71 diamond 61
; eax = 2  : function is unsupported for this FS
1 ha 62
; eax = 3  : unknown FS
63
; eax = 4  : partition not defined at hd
64
; eax = 5  : file not found
65
; eax = 6  : end of file
66
; eax = 7  : memory pointer not in application area
67
; eax = 8  : disk full
68
; eax = 9  : fat table corrupted
69
; eax = 10 : access denied
83 diamond 70
; eax = 11 : disk error
1 ha 71
;
72
; ebx = size
73
 
61 halyavin 74
; \begin{diamond}[18.03.2006]
75
; for subfunction 16 (start application) error codes must be negative
64 mario79 76
;    because positive values are valid PIDs
61 halyavin 77
; so possible return values are:
78
; eax > 0 : process created, eax=PID
79
 
80
; -0x10 <= eax < 0 : -eax is filesystem error code:
81
; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
82
; eax = -3  = 0xFFFFFFFD : unknown FS
83
; eax = -5  = 0xFFFFFFFB : file not found
84
; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
85
; eax = -9  = 0xFFFFFFF7 : fat table corrupted
86
; eax = -10 = 0xFFFFFFF6 : access denied
87
 
88
; -0x20 <= eax < -0x10: eax is process creation error code:
89
; eax = -0x20 = 0xFFFFFFE0 : too many processes
90
; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
91
; eax = -0x1E = 0xFFFFFFE2 : no memory
92
 
93
; ebx is not changed
94
 
95
; \end{diamond}[18.03.2006]
96
 
1 ha 97
    ; Extract parameters
465 serge 98
 ;   add    eax, std_application_base_address    ; abs start of info block
1 ha 99
 
2434 Serge 100
        cmp     dword [eax+0], 15; GET_DISK_INFO
101
        je      fs_info
1 ha 102
 
2434 Serge 103
        cmp     dword [CURRENT_TASK], 1; no memory checks for kernel requests
104
        jz      no_checks_for_kernel
105
        mov     edx, eax
106
        cmp     dword [eax+0], 1
107
        jnz     .usual_check
108
        mov     ebx, [eax+12]
465 serge 109
 ;   add   ebx,std_application_base_address
2434 Serge 110
        mov     ecx, [eax+8]
111
        call    check_region
112
        test    eax, eax
113
        jnz     area_in_app_mem
379 serge 114
 
1 ha 115
.error_output:
2434 Serge 116
        mov     esi, buffer_failed
117
        call    sys_msg_board_str
61 halyavin 118
;    mov   eax,7
2434 Serge 119
        mov     dword [esp+36], 7
120
        ret
1 ha 121
iglobal
61 halyavin 122
  buffer_failed db 'K : Buffer check failed',13,10,0
379 serge 123
endg
1 ha 124
.usual_check:
2434 Serge 125
        cmp     dword [eax+0], 0
126
        mov     ecx, 512
127
        jnz     .small_size
128
        mov     ecx, [eax+8]
129
        shl     ecx, 9
1 ha 130
.small_size:
2434 Serge 131
        mov     ebx, [eax+12]
465 serge 132
 ;   add   ebx,std_application_base_address
2434 Serge 133
        call    check_region
134
        test    eax, eax
135
        jz      .error_output
1 ha 136
  area_in_app_mem:
2434 Serge 137
        mov     eax, edx
1 ha 138
  no_checks_for_kernel:
139
 
140
  fs_read:
141
 
2434 Serge 142
        mov     ebx, [eax+20]   ; program wants root directory ?
143
        test    bl, bl
144
        je      fs_getroot
145
        test    bh, bh
146
        jne     fs_noroot
1 ha 147
  fs_getroot:
61 halyavin 148
; \begin{diamond}[18.03.2006]
149
; root - only read is allowed
150
; other operations return "access denied", eax=10
151
; (execute operation returns eax=-10)
2434 Serge 152
        cmp     dword [eax], 0
153
        jz      .read_root
154
        mov     dword [esp+36], 10
155
        ret
61 halyavin 156
.read_root:
157
; \end{diamond}[18.03.2006]
2434 Serge 158
        mov     esi, dir0
159
        mov     edi, [eax+12]
465 serge 160
 ;   add   edi,std_application_base_address
2434 Serge 161
        mov     ecx, 11
162
        push    ecx
64 mario79 163
;    cld    ; already is
2434 Serge 164
        rep movsb
165
        mov     al, 0x10
166
        stosb
167
        add     edi, 32-11-1
168
        pop     ecx
169
        rep movsb
170
        stosb
171
        and     dword [esp+36], 0; ok read
172
        mov     dword [esp+24], 32*2; size of root
173
        ret
1 ha 174
 
175
  fs_info:                      ;start of code - Mihasik
2434 Serge 176
        push    eax
177
        cmp     [eax+21], byte 'r'
178
        je      fs_info_r
179
        cmp     [eax+21], byte 'R'
180
        je      fs_info_r
181
        mov     eax, 3          ;if unknown disk
182
        xor     ebx, ebx
183
        xor     ecx, ecx
184
        xor     edx, edx
185
        jmp     fs_info1
1 ha 186
  fs_info_r:
2434 Serge 187
        call    ramdisk_free_space;if ramdisk
188
        mov     ecx, edi        ;free space in ecx
189
        shr     ecx, 9          ;free clusters
190
        mov     ebx, 2847       ;total clusters
191
        mov     edx, 512        ;cluster size
192
        xor     eax, eax        ;always 0
1 ha 193
  fs_info1:
2434 Serge 194
        pop     edi
195
        mov     [esp+36], eax
196
        mov     [esp+24], ebx    ; total clusters on disk
197
        mov     [esp+32], ecx    ; free clusters on disk
198
        mov     [edi], edx       ; cluster size in bytes
199
        ret                      ;end of code - Mihasik
1 ha 200
 
201
  fs_noroot:
202
 
2434 Serge 203
        push    dword [eax+0]   ; read/write/delete/.../makedir/rename/lba/run
204
        push    dword [eax+4]   ; 512 block number to read
205
        push    dword [eax+8]   ; bytes to write/append or 512 blocks to read
206
        mov     ebx, [eax+12]
465 serge 207
 ;   add   ebx,std_application_base_address
2434 Serge 208
        push    ebx             ; abs start of return/save area
1 ha 209
 
2434 Serge 210
        lea     esi, [eax+20]   ; abs start of dir + filename
211
        mov     edi, [eax+16]
465 serge 212
 ;   add   edi,std_application_base_address    ; abs start of work area
1 ha 213
 
2434 Serge 214
        call    expand_pathz
1 ha 215
 
2434 Serge 216
        push    edi             ; dir start
217
        push    ebx             ; name of file start
1 ha 218
 
2434 Serge 219
        mov     eax, [edi+1]
220
        cmp     eax, 'RD  '
221
        je      fs_yesramdisk
222
        cmp     eax, 'RAMD'
223
        jne     fs_noramdisk
1 ha 224
 
225
  fs_yesramdisk:
226
 
2434 Serge 227
        cmp     byte [edi+1+11], 0
228
        je      fs_give_dir1
1 ha 229
 
2434 Serge 230
        mov     eax, [edi+1+12]
231
        cmp     eax, '1   '
232
        je      fs_yesramdisk_first
233
        cmp     eax, 'FIRS'
234
        jne     fs_noramdisk
1 ha 235
 
236
  fs_yesramdisk_first:
237
 
2434 Serge 238
        cmp     dword [esp+20], 8; LBA read ramdisk
239
        jne     fs_no_LBA_read_ramdisk
1 ha 240
 
2434 Serge 241
        mov     eax, [esp+16]   ; LBA block to read
242
        mov     ecx, [esp+8]    ; abs pointer to return area
1 ha 243
 
2434 Serge 244
        call    LBA_read_ramdisk
245
        jmp     file_system_return
1 ha 246
 
247
 
248
  fs_no_LBA_read_ramdisk:
249
 
2434 Serge 250
        cmp     dword [esp+20], 0; READ
251
        jne     fs_noramdisk_read
1 ha 252
 
2434 Serge 253
        mov     eax, [esp+4]    ; fname
254
        add     eax, 2*12+1
255
        mov     ebx, [esp+16]   ; block start
256
        inc     ebx
257
        mov     ecx, [esp+12]   ; block count
258
        mov     edx, [esp+8]    ; return
259
        mov     esi, [esp+0]
260
        sub     esi, eax
261
        add     esi, 12+1       ; file name length
262
        call    fileread
1 ha 263
 
2434 Serge 264
        jmp     file_system_return
1 ha 265
 
266
 
267
  fs_noramdisk_read:
268
  fs_noramdisk:
379 serge 269
 
1 ha 270
  ;********************************************************************
2434 Serge 271
        mov     eax, [edi+1]
272
        cmp     eax, 'FD  '
273
        je      fs_yesflpdisk
274
        cmp     eax, 'FLOP'
275
        jne     fs_noflpdisk
1 ha 276
 
277
  fs_yesflpdisk:
2434 Serge 278
        call    reserve_flp
1 ha 279
 
2434 Serge 280
        cmp     byte [edi+1+11], 0
281
        je      fs_give_dir1
1 ha 282
 
2434 Serge 283
        mov     eax, [edi+1+12]
284
        cmp     eax, '1   '
285
        je      fs_yesflpdisk_first
286
        cmp     eax, 'FIRS'
287
        je      fs_yesflpdisk_first
288
        cmp     eax, '2   '
289
        je      fs_yesflpdisk_second
290
        cmp     eax, 'SECO'
291
        jne     fs_noflpdisk
292
        jmp     fs_yesflpdisk_second
1 ha 293
 
294
  fs_yesflpdisk_first:
2434 Serge 295
        mov     [flp_number], 1
296
        jmp     fs_yesflpdisk_start
1 ha 297
  fs_yesflpdisk_second:
2434 Serge 298
        mov     [flp_number], 2
1 ha 299
  fs_yesflpdisk_start:
2434 Serge 300
        cmp     dword [esp+20], 0; READ
301
        jne     fs_noflpdisk_read
1 ha 302
 
2434 Serge 303
        mov     eax, [esp+4]    ; fname
304
        add     eax, 2*12+1
305
        mov     ebx, [esp+16]   ; block start
306
        inc     ebx
307
        mov     ecx, [esp+12]   ; block count
308
        mov     edx, [esp+8]    ; return
309
        mov     esi, [esp+0]
310
        sub     esi, eax
311
        add     esi, 12+1       ; file name length
312
        call    floppy_fileread
1 ha 313
 
2434 Serge 314
        jmp     file_system_return
1 ha 315
 
316
 
317
  fs_noflpdisk_read:
318
  fs_noflpdisk:
319
  ;*****************************************************************
379 serge 320
 
2434 Serge 321
        mov     eax, [edi+1]
322
        cmp     eax, 'HD0 '
323
        je      fs_yesharddisk_IDE0
324
        cmp     eax, 'HD1 '
325
        je      fs_yesharddisk_IDE1
326
        cmp     eax, 'HD2 '
327
        je      fs_yesharddisk_IDE2
328
        cmp     eax, 'HD3 '
329
        je      fs_yesharddisk_IDE3
330
        jmp     old_path_harddisk
1 ha 331
fs_yesharddisk_IDE0:
2434 Serge 332
        call    reserve_hd1
333
        mov     [hdbase], 0x1f0
334
        mov     [hdid], 0x0
335
        mov     [hdpos], 1
336
        jmp     fs_yesharddisk_partition
1 ha 337
fs_yesharddisk_IDE1:
2434 Serge 338
        call    reserve_hd1
339
        mov     [hdbase], 0x1f0
340
        mov     [hdid], 0x10
341
        mov     [hdpos], 2
342
        jmp     fs_yesharddisk_partition
1 ha 343
fs_yesharddisk_IDE2:
2434 Serge 344
        call    reserve_hd1
345
        mov     [hdbase], 0x170
346
        mov     [hdid], 0x0
347
        mov     [hdpos], 3
348
        jmp     fs_yesharddisk_partition
1 ha 349
fs_yesharddisk_IDE3:
2434 Serge 350
        call    reserve_hd1
351
        mov     [hdbase], 0x170
352
        mov     [hdid], 0x10
353
        mov     [hdpos], 4
1 ha 354
fs_yesharddisk_partition:
321 diamond 355
        call    reserve_hd_channel
379 serge 356
;    call  choice_necessity_partition
357
;    jmp   fs_yesharddisk_all
2434 Serge 358
        jmp     fs_for_new_semantic
1 ha 359
 
360
choice_necessity_partition:
2434 Serge 361
        mov     eax, [edi+1+12]
362
        call    StringToNumber
363
        mov     [fat32part], eax
1 ha 364
choice_necessity_partition_1:
2434 Serge 365
        mov     ecx, [hdpos]
366
        xor     eax, eax
367
        mov     [hd_entries], eax; entries in hd cache
368
        mov     edx, DRIVE_DATA+2
369
        cmp     ecx, 0x80
370
        jb      search_partition_array
371
        mov     ecx, 4
1 ha 372
 search_partition_array:
2434 Serge 373
        mov     bl, [edx]
374
        movzx   ebx, bl
375
        add     eax, ebx
376
        inc     edx
377
        loop    search_partition_array
378
        mov     ecx, [hdpos]
379
        mov     edx, BiosDiskPartitions
380
        sub     ecx, 0x80
381
        jb      .s
382
        je      .f
709 diamond 383
 @@:
2434 Serge 384
        mov     ebx, [edx]
385
        add     edx, 4
386
        add     eax, ebx
387
        loop    @b
388
        jmp     .f
709 diamond 389
 .s:
2434 Serge 390
        sub     eax, ebx
709 diamond 391
 .f:
2434 Serge 392
        add     eax, [known_part];   add   eax,[fat32part]
393
        dec     eax
394
        xor     edx, edx
395
        imul    eax, 100
396
        add     eax, DRIVE_DATA+0xa
397
        mov     [transfer_adress], eax
398
        call    partition_data_transfer_1
399
        ret
1 ha 400
 
401
 old_path_harddisk:
2434 Serge 402
        mov     eax, [edi+1]
403
        cmp     eax, 'HD  '
404
        je      fs_yesharddisk
405
        cmp     eax, 'HARD'
406
        jne     fs_noharddisk
1 ha 407
 
408
  fs_yesharddisk:
2434 Serge 409
        cmp     dword [esp+20], 8; LBA read
410
        jne     fs_no_LBA_read
411
        mov     eax, [esp+16]   ; LBA block to read
412
        lea     ebx, [edi+1+12] ; pointer to FIRST/SECOND/THIRD/FOURTH
413
        mov     ecx, [esp+8]    ; abs pointer to return area
414
        call    LBA_read
415
        jmp     file_system_return
1 ha 416
 
417
  fs_no_LBA_read:
418
 
2434 Serge 419
        cmp     byte [edi+1+11], 0; directory read
420
        je      fs_give_dir1
421
        call    reserve_hd1
1 ha 422
 fs_for_new_semantic:
2434 Serge 423
        call    choice_necessity_partition
1 ha 424
 
425
  fs_yesharddisk_all:
2434 Serge 426
        mov     eax, 1
427
        mov     ebx, [esp+24+24]
428
        cmp     [hdpos], 0      ; is hd base set?
429
        jz      hd_err_return
430
        cmp     [fat32part], 0  ; is partition set?
431
        jnz     @f
63 halyavin 432
hd_err_return:
2434 Serge 433
        call    free_hd_channel
434
        and     [hd1_status], 0
435
        jmp     file_system_return
63 halyavin 436
@@:
1 ha 437
 
2434 Serge 438
        call    free_hd_channel
439
        and     [hd1_status], 0
1 ha 440
 
441
  fs_noharddisk:
61 halyavin 442
; \begin{diamond}[18.03.2006]
2434 Serge 443
        mov     eax, 5   ; file not found
3555 Serge 444
; а может быть, возвращать другой код ошибки?
2434 Serge 445
        mov     ebx, [esp+24+24]; do not change ebx in application
61 halyavin 446
; \end{diamond}[18.03.2006]
1 ha 447
 
448
  file_system_return:
449
 
2434 Serge 450
        add     esp, 24
1 ha 451
 
2434 Serge 452
        mov     [esp+36], eax
453
        mov     [esp+24], ebx
454
        ret
1 ha 455
 
456
 
457
  fs_give_dir1:
458
 
61 halyavin 459
; \begin{diamond}[18.03.2006]
460
; /RD,/FD,/HD - only read is allowed
461
; other operations return "access denied", eax=10
462
; (execute operation returns eax=-10)
2434 Serge 463
        cmp     dword [esp+20], 0
464
        jz      .read
465
        add     esp, 20
466
        pop     ecx
467
        mov     dword [esp+36], 10
468
        ret
61 halyavin 469
.read:
470
; \end{diamond}[18.03.2006]
2434 Serge 471
        mov     al, 0x10
472
        mov     ebx, 1
473
        mov     edi, [esp+8]
474
        mov     esi, dir1
1 ha 475
  fs_d1_new:
2434 Serge 476
        mov     ecx, 11
61 halyavin 477
;    cld
2434 Serge 478
        rep movsb
479
        stosb
480
        add     edi, 32-11-1
481
        dec     ebx
482
        jne     fs_d1_new
1 ha 483
 
2434 Serge 484
        add     esp, 24
1 ha 485
 
2434 Serge 486
        and     dword [esp+36], 0; ok read
487
        mov     dword [esp+24], 32*1; dir/data size
488
        ret
1 ha 489
 
490
 
491
 
492
LBA_read_ramdisk:
493
 
2434 Serge 494
        cmp     [lba_read_enabled], 1
495
        je      lbarrl1
1 ha 496
 
2434 Serge 497
        xor     ebx, ebx
498
        mov     eax, 2
499
        ret
1 ha 500
 
501
  lbarrl1:
502
 
2434 Serge 503
        cmp     eax, 18*2*80
504
        jb      lbarrl2
505
        xor     ebx, ebx
506
        mov     eax, 3
507
        ret
1 ha 508
 
509
  lbarrl2:
510
 
2434 Serge 511
        pushad
1 ha 512
 
2434 Serge 513
        call    restorefatchain
1 ha 514
 
2434 Serge 515
        mov     edi, ecx
516
        mov     esi, eax
1 ha 517
 
2434 Serge 518
        shl     esi, 9
519
        add     esi, RAMDISK
520
        mov     ecx, 512/4
61 halyavin 521
;    cld
2434 Serge 522
        rep movsd
1 ha 523
 
2434 Serge 524
        popad
1 ha 525
 
2434 Serge 526
        xor     ebx, ebx
527
        xor     eax, eax
528
        ret
1 ha 529
 
530
LBA_read:
531
 
532
; IN:
533
;
534
; eax = LBA block to read
535
; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
536
; ecx = abs pointer to return area
537
 
2434 Serge 538
        cmp     [lba_read_enabled], 1
539
        je      lbarl1
540
        mov     eax, 2
541
        ret
1 ha 542
 
543
  lbarl1:
544
 
2434 Serge 545
        call    reserve_hd1
1 ha 546
 
2434 Serge 547
        push    eax
548
        push    ecx
1 ha 549
 
2434 Serge 550
        mov     edi, hd_address_table
551
        mov     esi, dir1
552
        mov     eax, [ebx]
553
        mov     edx, '1   '
554
        mov     ecx, 4
1 ha 555
  blar0:
2434 Serge 556
        cmp     eax, [esi]
557
        je      blar2
558
        cmp     eax, edx
559
        je      blar2
560
        inc     edx
561
        add     edi, 8
562
        add     esi, 11
563
        dec     ecx
564
        jnz     blar0
1 ha 565
 
2434 Serge 566
        mov     eax, 1
567
        mov     ebx, 1
568
        jmp     LBA_read_ret
1 ha 569
 
570
  blar2:
2434 Serge 571
        mov     eax, [edi+0]
572
        mov     ebx, [edi+4]
1 ha 573
 
2434 Serge 574
        mov     [hdbase], eax
575
        mov     [hdid], ebx
64 mario79 576
 
2434 Serge 577
        call    wait_for_hd_idle
578
        cmp     [hd_error], 0
579
        jne     hd_lba_error
1 ha 580
 
581
    ; eax = hd port
582
    ; ebx = set for primary (0x00) or slave (0x10)
583
 
2434 Serge 584
        cli
1 ha 585
 
2434 Serge 586
        mov     edx, eax
587
        inc     edx
588
        xor     eax, eax
589
        out     dx, al
590
        inc     edx
591
        inc     eax
592
        out     dx, al
593
        inc     edx
594
        mov     eax, [esp+4]
595
        out     dx, al
596
        shr     eax, 8
597
        inc     edx
598
        out     dx, al
599
        shr     eax, 8
600
        inc     edx
601
        out     dx, al
602
        shr     eax, 8
603
        inc     edx
604
        and     al, 1+2+4+8
605
        add     al, bl
606
        add     al, 128+64+32
607
        out     dx, al
1 ha 608
 
2434 Serge 609
        inc     edx
610
        mov     al, 20h
611
        out     dx, al
1 ha 612
 
2434 Serge 613
        sti
1 ha 614
 
2434 Serge 615
        call    wait_for_sector_buffer
616
        cmp     [hd_error], 0
617
        jne     hd_lba_error
1 ha 618
 
2434 Serge 619
        cli
1 ha 620
 
2434 Serge 621
        mov     edi, [esp+0]
622
        mov     ecx, 256
623
        sub     edx, 7
624
        cld
625
        rep insw
1 ha 626
 
2434 Serge 627
        sti
1 ha 628
 
2434 Serge 629
        xor     eax, eax
630
        xor     ebx, ebx
1 ha 631
 
632
  LBA_read_ret:
2434 Serge 633
        mov     [hd_error], 0
634
        mov     [hd1_status], 0
635
        add     esp, 2*4
1 ha 636
 
2434 Serge 637
        ret
1 ha 638
 
639
 
640
expand_pathz:
641
; IN:
642
;   esi = asciiz path & file
643
;   edi = buffer for path & file name
644
; OUT:
645
;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
646
;   ebx = /file name - zero terminated
647
;   esi = pointer after source
648
 
2434 Serge 649
        push    eax
650
        push    ecx
651
        push    edi;[esp+0]
1 ha 652
 
653
  pathz_start:
2434 Serge 654
        mov     byte [edi], '/'
655
        inc     edi
656
        mov     al, 32
657
        mov     ecx, 11
658
        cld
659
        rep stosb               ; clear filename area
660
        sub     edi, 11
661
        mov     ebx, edi        ; start of dir/file name
1 ha 662
 
663
  pathz_new_char:
2434 Serge 664
        mov     al, [esi]
665
        inc     esi
666
        cmp     al, 0
667
        je      pathz_end
1 ha 668
 
2434 Serge 669
        cmp     al, '/'
670
        jne     pathz_not_path
671
        cmp     edi, ebx        ; skip first '/'
672
        jz      pathz_new_char
673
        lea     edi, [ebx+11]   ; start of next directory
674
        jmp     pathz_start
1 ha 675
 
676
  pathz_not_path:
2434 Serge 677
        cmp     al, '.'
678
        jne     pathz_not_ext
679
        lea     edi, [ebx+8]    ; start of extension
680
        jmp     pathz_new_char
1 ha 681
 
682
  pathz_not_ext:
2434 Serge 683
        cmp     al, 'a'
684
        jb      pathz_not_low
685
        cmp     al, 'z'
686
        ja      pathz_not_low
687
        sub     al, 0x20        ; char to uppercase
1 ha 688
 
689
  pathz_not_low:
2434 Serge 690
        mov     [edi], al
691
        inc     edi
692
        mov     eax, [esp+0]    ; start_of_dest_path
693
        add     eax, 512        ; keep maximum path under 512 bytes
694
        cmp     edi, eax
695
        jb      pathz_new_char
1 ha 696
 
697
  pathz_end:
2434 Serge 698
        cmp     ebx, edi        ; if path end with '/'
699
        jnz     pathz_put_zero  ; go back 1 level
700
        sub     ebx, 12
1 ha 701
 
702
  pathz_put_zero:
2434 Serge 703
        mov     byte [ebx+11], 0
704
        dec     ebx             ; include '/' char into file name
705
        pop     edi
706
        pop     ecx
707
        pop     eax
708
        ret
1 ha 709
 
710
;*******************************************
711
;* string to number
712
;* input eax - 4 byte string
713
;* output eax - number
714
;*******************************************
715
StringToNumber:
3555 Serge 716
;    ПЕРЕВОД СТРОКОВОГО ЧИСЛА В ЧИСЛОВОЙ ВИД
717
;    Вход:
718
;        EDI - адрес строки с числом. Конец числа отмечен кодом 0Dh
719
;    Выход:
720
;        CF - индикатор ошибок:
721
;            0 - ошибок нет;
722
;            1 - ошибка
723
;        Если CF=0, то AX - число.
1 ha 724
 
2434 Serge 725
        push    bx
726
        push    cx
727
        push    dx
728
        push    edi
729
        mov     [partition_string], eax
730
        mov     edi, partition_string
731
        xor     cx, cx
379 serge 732
i1:
2434 Serge 733
        mov     al, [edi]
734
        cmp     al, 32;13
735
        je      i_exit
1 ha 736
;    cmp    al,'0'
737
;    jb    err
738
;    cmp    al,'9'
739
;    ja    err
2434 Serge 740
        sub     al, 48
741
        shl     cx, 1
742
        jc      error
743
        mov     bx, cx
744
        shl     cx, 1
745
        jc      error
746
        shl     cx, 1
747
        jc      error
748
        add     cx, bx
749
        jc      error
750
        cbw
751
        add     cx, ax
752
        jc      error
1 ha 753
i3:
2434 Serge 754
        inc     edi
755
        jmp     i1
1 ha 756
i_exit:
2434 Serge 757
        mov     ax, cx
758
        clc
1 ha 759
i4:
2434 Serge 760
        movzx   eax, ax
761
        pop     edi
762
        pop     dx
763
        pop     cx
764
        pop     bx
765
        ret
1 ha 766
 
1047 heavyiron 767
error:
2434 Serge 768
        stc
769
        jmp     i4
1 ha 770
 
2434 Serge 771
partition_string:
772
                  dd 0
1379 turbanoff 773
                  db 32