Rev 48 | Rev 75 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 48 | Rev 71 | ||
---|---|---|---|
Line 256... | Line 256... | ||
256 | cmp [esp+16],dword 0 ; wanted cluster ? |
256 | cmp [esp+16],dword 0 ; wanted cluster ? |
257 | jne frfl7 |
257 | jne frfl7 |
258 | call memmove |
258 | call memmove |
259 | add [esp+8],dword 512 |
259 | add [esp+8],dword 512 |
260 | dec dword [esp+12] ; last wanted cluster ? |
260 | dec dword [esp+12] ; last wanted cluster ? |
261 | cmp [esp+12],dword 0 |
- | |
262 | je frnoread |
261 | je frnoread |
263 | jmp frfl8 |
262 | jmp frfl8 |
264 | frfl7: |
263 | frfl7: |
265 | dec dword [esp+16] |
264 | dec dword [esp+16] |
266 | frfl8: |
265 | frfl8: |
267 | shl edi,1 ;find next cluster from FAT |
266 | movzx eax,word [edi*2+0x280000] ; find next cluster from FAT |
268 | add edi,0x280000 |
- | |
269 | movzx eax,word [edi] |
- | |
270 | mov edi,eax |
267 | mov edi,eax |
271 | cmp edi,4095 ;eof - cluster |
268 | cmp edi,4095 ;eof - cluster |
272 | jz frnoread2 |
269 | jz frnoread2 |
Line 273... | Line 270... | ||
273 | 270 | ||
Line 518... | Line 515... | ||
518 | mov ebx,dword [edi+17] ;get size |
515 | mov ebx,dword [edi+17] ;get size |
519 | rd_getfileinfo_end: |
516 | rd_getfileinfo_end: |
520 | xor eax,eax |
517 | xor eax,eax |
521 | add esp,32 |
518 | add esp,32 |
522 | ret->->-> |
519 | ret |
- | 520 | ||
- | 521 | ; \begin{diamond} |
|
- | 522 | ||
- | 523 | uni2ansi_str: |
|
- | 524 | ; convert UNICODE zero-terminated string to ASCII-string (codepage 866) |
|
- | 525 | ; in: esi->source, edi->buffer (may be esi=edi) |
|
- | 526 | ; destroys: eax,esi,edi |
|
- | 527 | lodsw |
|
- | 528 | test ax, ax |
|
- | 529 | jz .done |
|
- | 530 | cmp ax, 0x80 |
|
- | 531 | jb .ascii |
|
- | 532 | cmp ax, 0x401 |
|
- | 533 | jz .yo1 |
|
- | 534 | cmp ax, 0x451 |
|
- | 535 | jz .yo2 |
|
- | 536 | cmp ax, 0x410 |
|
- | 537 | jb .unk |
|
- | 538 | cmp ax, 0x440 |
|
- | 539 | jb .rus1 |
|
- | 540 | cmp ax, 0x450 |
|
- | 541 | jb .rus2 |
|
- | 542 | .unk: |
|
- | 543 | mov al, '_' |
|
- | 544 | jmp .doit |
|
- | 545 | .yo1: |
|
- | 546 | mov al, 'ð' |
|
- | 547 | jmp .doit |
|
- | 548 | .yo2: |
|
- | 549 | mov al, 'ñ' |
|
- | 550 | jmp .doit |
|
- | 551 | .rus1: |
|
- | 552 | ; 0x410-0x43F -> 0x80-0xAF |
|
- | 553 | add al, 0x70 |
|
- | 554 | jmp .doit |
|
- | 555 | .rus2: |
|
- | 556 | ; 0x440-0x450 -> 0xE0-0xEF |
|
- | 557 | add al, 0xA0 |
|
- | 558 | .ascii: |
|
- | 559 | .doit: |
|
- | 560 | stosb |
|
- | 561 | jmp uni2ansi_str |
|
- | 562 | .done: |
|
- | 563 | mov byte [edi], 0 |
|
- | 564 | ret |
|
- | 565 | ||
- | 566 | char_toupper: |
|
- | 567 | ; convert character to uppercase, using cp866 encoding |
|
- | 568 | ; in: al=symbol |
|
- | 569 | ; out: al=converted symbol |
|
- | 570 | cmp al, 'a' |
|
- | 571 | jb .ret |
|
- | 572 | cmp al, 'z' |
|
- | 573 | jbe .az |
|
- | 574 | cmp al, ' ' |
|
- | 575 | jb .ret |
|
- | 576 | cmp al, 'à' |
|
- | 577 | jb .rus1 |
|
- | 578 | cmp al, 'ï' |
|
- | 579 | ja .ret |
|
- | 580 | ; 0xE0-0xEF -> 0x90-0x9F |
|
- | 581 | sub al, 'à'-'' |
|
- | 582 | .ret: |
|
- | 583 | ret |
|
- | 584 | .rus1: |
|
- | 585 | ; 0xA0-0xAF -> 0x80-0x8F |
|
- | 586 | .az: |
|
- | 587 | and al, not 0x20 |
|
- | 588 | ret |
|
- | 589 | ||
- | 590 | fat_get_name: |
|
- | 591 | ; in: edi->FAT entry |
|
- | 592 | ; out: CF=1 - no valid entry |
|
- | 593 | ; else CF=0 and ebp->ASCIIZ-name |
|
- | 594 | ; (maximum length of filename is 255 (wide) symbols without trailing 0, |
|
- | 595 | ; but implementation requires buffer 261 words) |
|
- | 596 | ; destroys eax |
|
- | 597 | cmp byte [edi], 0 |
|
- | 598 | jz .no |
|
- | 599 | cmp byte [edi], 0xE5 |
|
- | 600 | jnz @f |
|
- | 601 | .no: |
|
- | 602 | stc |
|
- | 603 | ret |
|
- | 604 | @@: |
|
- | 605 | cmp byte [edi+11], 0xF |
|
- | 606 | jz .longname |
|
- | 607 | push ecx |
|
- | 608 | mov ecx, 8 |
|
- | 609 | push edi ebp ecx |
|
- | 610 | @@: |
|
- | 611 | mov al, [edi] |
|
- | 612 | inc edi |
|
- | 613 | mov [ebp], al |
|
- | 614 | inc ebp |
|
- | 615 | loop @b |
|
- | 616 | pop ecx |
|
- | 617 | @@: |
|
- | 618 | cmp byte [ebp-1], ' ' |
|
- | 619 | jnz @f |
|
- | 620 | dec ebp |
|
- | 621 | loop @b |
|
- | 622 | @@: |
|
- | 623 | mov byte [ebp], '.' |
|
- | 624 | inc ebp |
|
- | 625 | mov ecx, 3 |
|
- | 626 | push ecx |
|
- | 627 | @@: |
|
- | 628 | mov al, [edi] |
|
- | 629 | inc edi |
|
- | 630 | mov [ebp], al |
|
- | 631 | inc ebp |
|
- | 632 | loop @b |
|
- | 633 | pop ecx |
|
- | 634 | @@: |
|
- | 635 | cmp byte [ebp-1], ' ' |
|
- | 636 | jnz @f |
|
- | 637 | dec ebp |
|
- | 638 | loop @b |
|
- | 639 | dec ebp |
|
- | 640 | @@: |
|
- | 641 | and byte [ebp], 0 ; CF=0 |
|
- | 642 | pop ebp edi ecx |
|
- | 643 | ret |
|
- | 644 | .longname: |
|
- | 645 | ; LFN |
|
- | 646 | mov al, byte [edi] |
|
- | 647 | and eax, 0x3F |
|
- | 648 | dec eax |
|
- | 649 | cmp al, 20 |
|
- | 650 | jae .no ; ignore invalid entries |
|
- | 651 | mov word [ebp+260*2], 0 ; force null-terminating for orphans |
|
- | 652 | imul eax, 13*2 |
|
- | 653 | add ebp, eax |
|
- | 654 | test byte [edi], 0x40 |
|
- | 655 | jz @f |
|
- | 656 | mov word [ebp+13*2], 0 |
|
- | 657 | @@: |
|
- | 658 | push eax |
|
- | 659 | ; now copy name from edi to ebp ... |
|
- | 660 | mov eax, [edi+1] |
|
- | 661 | mov [ebp], eax ; symbols 1,2 |
|
- | 662 | mov eax, [edi+5] |
|
- | 663 | mov [ebp+4], eax ; 3,4 |
|
- | 664 | mov eax, [edi+9] |
|
- | 665 | mov [ebp+8], ax ; 5 |
|
- | 666 | mov eax, [edi+14] |
|
- | 667 | mov [ebp+10], eax ; 6,7 |
|
- | 668 | mov eax, [edi+18] |
|
- | 669 | mov [ebp+14], eax ; 8,9 |
|
- | 670 | mov eax, [edi+22] |
|
- | 671 | mov [ebp+18], eax ; 10,11 |
|
- | 672 | mov eax, [edi+28] |
|
- | 673 | mov [ebp+22], eax ; 12,13 |
|
- | 674 | ; ... done |
|
- | 675 | pop eax |
|
- | 676 | sub ebp, eax |
|
- | 677 | test eax, eax |
|
- | 678 | jz @f |
|
- | 679 | ; if this is not first entry, more processing required |
|
- | 680 | stc |
|
- | 681 | ret |
|
- | 682 | @@: |
|
- | 683 | ; if this is first entry: |
|
- | 684 | ; buffer at ebp contains UNICODE name, convert it to ANSI |
|
- | 685 | push esi edi |
|
- | 686 | mov esi, ebp |
|
- | 687 | mov edi, ebp |
|
- | 688 | call uni2ansi_str |
|
- | 689 | pop edi esi |
|
- | 690 | clc |
|
- | 691 | ret |
|
- | 692 | ||
- | 693 | fat_compare_name: |
|
- | 694 | ; compares ASCIIZ-names, case-insensitive (cp866 encoding) |
|
- | 695 | ; in: esi->name, ebp->name |
|
- | 696 | ; out: if names match: ZF=1 and esi->next component of name |
|
- | 697 | ; else: ZF=0, esi is not changed |
|
- | 698 | ; destroys eax |
|
- | 699 | push ebp esi |
|
- | 700 | .loop: |
|
- | 701 | mov al, [ebp] |
|
- | 702 | inc ebp |
|
- | 703 | call char_toupper |
|
- | 704 | push eax |
|
- | 705 | lodsb |
|
- | 706 | call char_toupper |
|
- | 707 | cmp al, [esp] |
|
- | 708 | jnz .done |
|
- | 709 | pop eax |
|
- | 710 | test al, al |
|
- | 711 | jnz .loop |
|
- | 712 | dec esi |
|
- | 713 | pop eax |
|
- | 714 | pop ebp |
|
- | 715 | xor eax, eax ; set ZF flag |
|
- | 716 | ret |
|
- | 717 | .done: |
|
- | 718 | cmp al, '/' |
|
- | 719 | jnz @f |
|
- | 720 | cmp byte [esp], 0 |
|
- | 721 | jnz @f |
|
- | 722 | mov [esp+4], esi |
|
- | 723 | @@: |
|
- | 724 | pop eax |
|
- | 725 | pop esi ebp |
|
- | 726 | ret |
|
- | 727 | ||
- | 728 | rd_find_lfn: |
|
- | 729 | ; in: esi->name |
|
- | 730 | ; out: CF=1 - file not found |
|
- | 731 | ; else CF=0 and edi->direntry |
|
- | 732 | push esi ebp edi |
|
- | 733 | sub esp, 262*2 ; allocate space for LFN |
|
- | 734 | mov ebp, esp ; ebp points to buffer |
|
- | 735 | mov edi, 0x100000+512*19 ; to root dir |
|
- | 736 | .l1: |
|
- | 737 | call fat_get_name |
|
- | 738 | jc .l2 |
|
- | 739 | call fat_compare_name |
|
- | 740 | jz .found |
|
- | 741 | .l2: |
|
- | 742 | add edi, 0x20 |
|
- | 743 | cmp edi, 0x100000+512*33 |
|
- | 744 | jb .l1 |
|
- | 745 | .notfound: |
|
- | 746 | add esp, 262*2 |
|
- | 747 | pop edi ebp esi |
|
- | 748 | stc |
|
- | 749 | ret |
|
- | 750 | .found: |
|
- | 751 | ; found |
|
- | 752 | ; if this is LFN entry, advance to true entry |
|
- | 753 | cmp byte [edi+11], 0xF |
|
- | 754 | jnz @f |
|
- | 755 | add edi, 0x20 |
|
- | 756 | @@: |
|
- | 757 | ; folders are not supported |
|
- | 758 | cmp byte [esi], 0 |
|
- | 759 | jnz .notfound |
|
- | 760 | add esp, 262*2+4 ; CF=0 |
|
- | 761 | pop ebp esi |
|
- | 762 | ret |
|
- | 763 | ||
- | 764 | ;---------------------------------------------------------------- |
|
- | 765 | ; |
|
- | 766 | ; fs_RamdiskRead - LFN variant for reading sys floppy |
|
- | 767 | ; |
|
- | 768 | ; esi points to filename |
|
- | 769 | ; ebx pointer to 64-bit number = first wanted byte, 0+ |
|
- | 770 | ; may be ebx=0 - start from first byte |
|
- | 771 | ; ecx number of bytes to read, 0+ |
|
- | 772 | ; edx mem location to return data |
|
- | 773 | ; |
|
- | 774 | ; ret ebx = size or 0xffffffff file not found |
|
- | 775 | ; eax = 0 ok read or other = errormsg |
|
- | 776 | ; |
|
- | 777 | ;-------------------------------------------------------------- |
|
- | 778 | fs_RamdiskRead: |
|
- | 779 | cmp byte [esi], 0 |
|
- | 780 | jnz @f |
|
- | 781 | or ebx, -1 |
|
- | 782 | mov eax, 10 ; access denied |
|
- | 783 | ret |
|
- | 784 | @@: |
|
- | 785 | push edi |
|
- | 786 | call rd_find_lfn |
|
- | 787 | jnc .found |
|
- | 788 | pop edi |
|
- | 789 | or ebx, -1 |
|
- | 790 | mov eax, 5 ; file not found |
|
- | 791 | ret |
|
- | 792 | .found: |
|
- | 793 | test ebx, ebx |
|
- | 794 | jz .l1 |
|
- | 795 | cmp dword [ebx+4], 0 |
|
- | 796 | jz @f |
|
- | 797 | mov ebx, [edi+28] |
|
- | 798 | .reteof: |
|
- | 799 | mov eax, 6 ; EOF |
|
- | 800 | pop edi |
|
- | 801 | ret |
|
- | 802 | @@: |
|
- | 803 | mov ebx, [ebx] |
|
- | 804 | .l1: |
|
- | 805 | push dword [edi+28] ; file size |
|
- | 806 | push dword [edi+28] |
|
- | 807 | movzx edi, word [edi+26] ; cluster |
|
- | 808 | push ecx edx |
|
- | 809 | .new: |
|
- | 810 | jecxz .done |
|
- | 811 | test edi, edi |
|
- | 812 | jz .eof |
|
- | 813 | cmp edi, 0xFF8 |
|
- | 814 | jae .eof |
|
- | 815 | lea eax, [edi+31] ; bootsector+2*fat+filenames |
|
- | 816 | shl eax, 9 ; *512 |
|
- | 817 | add eax, 0x100000 ; image base |
|
- | 818 | ; now eax points to data of cluster |
|
- | 819 | sub ebx, 512 |
|
- | 820 | jae .skip |
|
- | 821 | lea eax, [eax+ebx+512] |
|
- | 822 | neg ebx |
|
- | 823 | push ecx |
|
- | 824 | cmp ecx, ebx |
|
- | 825 | jbe @f |
|
- | 826 | mov ecx, ebx |
|
- | 827 | @@: |
|
- | 828 | cmp ecx, [esp+12] |
|
- | 829 | jbe @f |
|
- | 830 | mov ecx, [esp+12] |
|
- | 831 | @@: |
|
- | 832 | mov ebx, edx |
|
- | 833 | call memmove |
|
- | 834 | add edx, ecx |
|
- | 835 | sub [esp], ecx |
|
- | 836 | sub [esp+12], ecx |
|
- | 837 | pop ecx |
|
- | 838 | xor ebx, ebx |
|
- | 839 | cmp [esp+8], ebx |
|
- | 840 | jnz .skip |
|
- | 841 | jecxz .done |
|
- | 842 | jmp .eof |
|
- | 843 | .skip: |
|
- | 844 | movzx edi, word [edi*2+0x280000] ; find next cluster from FAT |
|
- | 845 | jmp .new |
|
- | 846 | .eof: |
|
- | 847 | pop edx ecx ebx ebx |
|
- | 848 | jmp .reteof |
|
- | 849 | .done: |
|
- | 850 | pop edx ecx ebx ebx edi |
|
- | 851 | xor eax, eax |
|
- | 852 | ret |
|
- | 853 | ||
- | 854 | ; \end{diamond}->->-> |
|
523 | 855 |