src/lib/formats/st_dsk.c
| r12779 | r12780 | |
| 8 | 8 | |
| 9 | 9 | #include "formats/st_dsk.h" |
| 10 | 10 | |
| 11 | | st_gen_format::st_gen_format() : floppy_image_format_t() |
| 11 | st_gen_format::st_gen_format() |
| 12 | 12 | { |
| 13 | 13 | } |
| 14 | 14 | |
| r12779 | r12780 | |
| 602 | 602 | desc_fcp_11_9, |
| 603 | 603 | desc_fcp_11_10, |
| 604 | 604 | }; |
| 605 | |
| 606 | void st_gen_format::generate(int track, int head, int track_count, int head_count, UINT8 *buffer, int sector_count, floppy_image *image) |
| 607 | { |
| 608 | desc_s sectors[11]; |
| 609 | for(int i=0; i<sector_count; i++) { |
| 610 | sectors[i].data = buffer + 512*i; |
| 611 | sectors[i].size = 512; |
| 612 | } |
| 613 | |
| 614 | const desc_e *desc = 0; |
| 615 | switch(sector_count) { |
| 616 | case 9: |
| 617 | desc = desc_fcp_9; |
| 618 | break; |
| 619 | case 10: |
| 620 | desc = desc_fcp_10[(track*head_count + head) % 10]; |
| 621 | break; |
| 622 | case 11: |
| 623 | desc = desc_fcp_11[(track*head_count + head) % 11]; |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | generate_track(desc, track, head, sectors, sector_count, 100000, image); |
| 628 | } |
| 629 | |
| 630 | st_format::st_format() |
| 631 | { |
| 632 | } |
| 633 | |
| 634 | const char *st_format::name() const |
| 635 | { |
| 636 | return "st"; |
| 637 | } |
| 638 | |
| 639 | const char *st_format::description() const |
| 640 | { |
| 641 | return "Atari ST floppy disk image"; |
| 642 | } |
| 643 | |
| 644 | const char *st_format::extensions() const |
| 645 | { |
| 646 | return "st"; |
| 647 | } |
| 648 | |
| 649 | bool st_format::supports_save() const |
| 650 | { |
| 651 | return false; |
| 652 | } |
| 653 | |
| 654 | void st_format::find_size(floppy_image *image, int &track_count, int &head_count, int §or_count) |
| 655 | { |
| 656 | int size = image->image_size(); |
| 657 | for(track_count=80; track_count <= 82; track_count++) |
| 658 | for(head_count=1; head_count <= 2; head_count++) |
| 659 | for(sector_count=9; sector_count <= 11; sector_count++) |
| 660 | if(size == 512*track_count*head_count*sector_count) |
| 661 | return; |
| 662 | track_count = head_count = sector_count = 0; |
| 663 | } |
| 664 | |
| 665 | int st_format::identify(floppy_image *image) |
| 666 | { |
| 667 | int track_count, head_count, sector_count; |
| 668 | find_size(image, track_count, head_count, sector_count); |
| 669 | |
| 670 | if(track_count) |
| 671 | return 50; |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | bool st_format::load(floppy_image *image) |
| 676 | { |
| 677 | UINT8 sectdata[11*512]; |
| 678 | int track_count, head_count, sector_count; |
| 679 | find_size(image, track_count, head_count, sector_count); |
| 680 | |
| 681 | image->set_meta_data(track_count, head_count); |
| 682 | int track_size = sector_count*512; |
| 683 | for(int track=0; track < track_count; track++) { |
| 684 | for(int side=0; side < head_count; side++) { |
| 685 | image->image_read(sectdata, (track*head_count + side)*track_size, track_size); |
| 686 | generate(track, side, track_count, head_count, sectdata, sector_count, image); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | return TRUE; |
| 691 | } |
| 692 | |
| 693 | msa_format::msa_format() |
| 694 | { |
| 695 | } |
| 696 | |
| 697 | const char *msa_format::name() const |
| 698 | { |
| 699 | return "msa"; |
| 700 | } |
| 701 | |
| 702 | const char *msa_format::description() const |
| 703 | { |
| 704 | return "Atari MSA floppy disk image"; |
| 705 | } |
| 706 | |
| 707 | const char *msa_format::extensions() const |
| 708 | { |
| 709 | return "msa"; |
| 710 | } |
| 711 | |
| 712 | bool msa_format::supports_save() const |
| 713 | { |
| 714 | return false; |
| 715 | } |
| 716 | |
| 717 | void msa_format::read_header(floppy_image *image, UINT16 &sign, UINT16 §, UINT16 &head, UINT16 &strack, UINT16 &etrack) |
| 718 | { |
| 719 | UINT8 h[10]; |
| 720 | image->image_read(h, 0, 10); |
| 721 | sign = (h[0] << 8) | h[1]; |
| 722 | sect = (h[2] << 8) | h[3]; |
| 723 | head = (h[4] << 8) | h[5]; |
| 724 | strack = (h[6] << 8) | h[7]; |
| 725 | etrack = (h[8] << 8) | h[9]; |
| 726 | } |
| 727 | |
| 728 | bool msa_format::uncompress(UINT8 *buffer, int csize, int usize) |
| 729 | { |
| 730 | UINT8 sectdata[11*512]; |
| 731 | int src=0, dst=0; |
| 732 | while(src<csize && dst<usize) { |
| 733 | unsigned char c = buffer[src++]; |
| 734 | if(c == 0xe5) { |
| 735 | if(csize-src < 3) |
| 736 | return false; |
| 737 | c = buffer[src++]; |
| 738 | int count = (buffer[src] << 8) | buffer[src+1]; |
| 739 | if(usize-dst < count) |
| 740 | return false; |
| 741 | for(int i=0; i<count; i++) |
| 742 | sectdata[dst++] = c; |
| 743 | } else |
| 744 | sectdata[dst++] = c; |
| 745 | } |
| 746 | if(src != csize || dst != usize) |
| 747 | return false; |
| 748 | memcpy(buffer, sectdata, usize); |
| 749 | return true; |
| 750 | } |
| 751 | |
| 752 | int msa_format::identify(floppy_image *image) |
| 753 | { |
| 754 | UINT16 sign, sect, head, strack, etrack; |
| 755 | read_header(image, sign, sect, head, strack, etrack); |
| 756 | |
| 757 | if(sign == 0x0e0f && |
| 758 | (sect >=9 && sect <= 11) && |
| 759 | (head == 0 || head == 1) && |
| 760 | strack <= etrack && |
| 761 | etrack < 82) |
| 762 | return 100; |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | bool msa_format::load(floppy_image *image) |
| 767 | { |
| 768 | UINT16 sign, sect, head, strack, etrack; |
| 769 | read_header(image, sign, sect, head, strack, etrack); |
| 770 | image->set_meta_data(etrack+1, head+1); |
| 771 | |
| 772 | UINT8 sectdata[11*512]; |
| 773 | UINT8 th[2]; |
| 774 | |
| 775 | int pos = 10; |
| 776 | int track_size = sect*512; |
| 777 | |
| 778 | for(int track=strack; track <= etrack; track++) { |
| 779 | for(int side=0; side <= head; side++) { |
| 780 | image->image_read(th, pos, 2); |
| 781 | pos += 2; |
| 782 | int tsize = (th[0] << 8) | th[1]; |
| 783 | image->image_read(sectdata, pos, tsize); |
| 784 | pos += tsize; |
| 785 | if(tsize < track_size) { |
| 786 | if(!uncompress(sectdata, tsize, track_size)) |
| 787 | return FALSE; |
| 788 | } |
| 789 | generate(track, side, etrack+1, head+1, sectdata, sect, image); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | return TRUE; |
| 794 | } |
| 795 | |
| 796 | const floppy_format_type FLOPPY_ST_FORMAT = &floppy_image_format_creator<st_format>; |
| 797 | const floppy_format_type FLOPPY_MSA_FORMAT = &floppy_image_format_creator<msa_format>; |
src/lib/formats/st_dsk.h
| r12779 | r12780 | |
| 42 | 42 | static const desc_e desc_fcp_11_9[]; |
| 43 | 43 | static const desc_e desc_fcp_11_10[]; |
| 44 | 44 | static const desc_e *const desc_fcp_11[]; |
| 45 | |
| 46 | void generate(int track, int head, int track_count, int head_count, UINT8 *buffer, int sector_count, floppy_image *image); |
| 45 | 47 | }; |
| 46 | 48 | |
| 49 | class st_format : public st_gen_format |
| 50 | { |
| 51 | public: |
| 52 | st_format(); |
| 53 | |
| 54 | virtual int identify(floppy_image *image); |
| 55 | virtual bool load(floppy_image *image); |
| 56 | |
| 57 | virtual const char *name() const; |
| 58 | virtual const char *description() const; |
| 59 | virtual const char *extensions() const; |
| 60 | virtual bool supports_save() const; |
| 61 | |
| 62 | private: |
| 63 | void find_size(floppy_image *image, int &track_count, int &head_count, int §or_count); |
| 64 | }; |
| 65 | |
| 66 | class msa_format : public st_gen_format |
| 67 | { |
| 68 | public: |
| 69 | msa_format(); |
| 70 | |
| 71 | virtual int identify(floppy_image *image); |
| 72 | virtual bool load(floppy_image *image); |
| 73 | |
| 74 | virtual const char *name() const; |
| 75 | virtual const char *description() const; |
| 76 | virtual const char *extensions() const; |
| 77 | virtual bool supports_save() const; |
| 78 | |
| 79 | private: |
| 80 | bool uncompress(UINT8 *buffer, int csize, int usize); |
| 81 | void read_header(floppy_image *image, UINT16 &sign, UINT16 §, UINT16 &head, UINT16 &strack, UINT16 &etrack); |
| 82 | }; |
| 83 | |
| 84 | extern const floppy_format_type FLOPPY_ST_FORMAT; |
| 85 | extern const floppy_format_type FLOPPY_MSA_FORMAT; |
| 86 | |
| 47 | 87 | #endif /*ST_DSK_H_*/ |