Previous 15994 Revisions Next

r12780 Saturday 3rd September, 2011 at 13:10:01 UTC by Olivier Galibert
st_dsk: Add the easy ST formats [O. Galibert]
[src/lib/formats]flopimg.h st_dsk.c st_dsk.h
[src/mess/tools/floptool]main.c

src/lib/formats/flopimg.h
r12779r12780
387387
388388   UINT16 tracks;
389389   UINT8  sides;
390   UINT16 rpm;
391390
392391   UINT32 *cell_data[MAX_FLOPPY_SIDES * MAX_FLOPPY_TRACKS];
393392   UINT32 track_size[MAX_FLOPPY_SIDES * MAX_FLOPPY_TRACKS];
src/lib/formats/st_dsk.c
r12779r12780
88
99#include "formats/st_dsk.h"
1010
11st_gen_format::st_gen_format() : floppy_image_format_t()
11st_gen_format::st_gen_format()
1212{
1313}
1414
r12779r12780
602602   desc_fcp_11_9,
603603   desc_fcp_11_10,
604604};
605
606void 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
630st_format::st_format()
631{
632}
633
634const char *st_format::name() const
635{
636   return "st";
637}
638
639const char *st_format::description() const
640{
641   return "Atari ST floppy disk image";
642}
643
644const char *st_format::extensions() const
645{
646   return "st";
647}
648
649bool st_format::supports_save() const
650{
651   return false;
652}
653
654void st_format::find_size(floppy_image *image, int &track_count, int &head_count, int &sector_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
665int 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
675bool 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
693msa_format::msa_format()
694{
695}
696
697const char *msa_format::name() const
698{
699   return "msa";
700}
701
702const char *msa_format::description() const
703{
704   return "Atari MSA floppy disk image";
705}
706
707const char *msa_format::extensions() const
708{
709   return "msa";
710}
711
712bool msa_format::supports_save() const
713{
714   return false;
715}
716
717void msa_format::read_header(floppy_image *image, UINT16 &sign, UINT16 &sect, 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
728bool 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
752int 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
766bool 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
796const floppy_format_type FLOPPY_ST_FORMAT = &floppy_image_format_creator<st_format>;
797const floppy_format_type FLOPPY_MSA_FORMAT = &floppy_image_format_creator<msa_format>;
src/lib/formats/st_dsk.h
r12779r12780
4242   static const desc_e desc_fcp_11_9[];
4343   static const desc_e desc_fcp_11_10[];
4444   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);
4547};
4648
49class st_format : public st_gen_format
50{
51public:
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
62private:
63   void find_size(floppy_image *image, int &track_count, int &head_count, int &sector_count);
64};
65
66class msa_format : public st_gen_format
67{
68public:
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
79private:
80   bool uncompress(UINT8 *buffer, int csize, int usize);
81   void read_header(floppy_image *image, UINT16 &sign, UINT16 &sect, UINT16 &head, UINT16 &strack, UINT16 &etrack);
82};
83
84extern const floppy_format_type FLOPPY_ST_FORMAT;
85extern const floppy_format_type FLOPPY_MSA_FORMAT;
86
4787#endif /*ST_DSK_H_*/
src/mess/tools/floptool/main.c
r12779r12780
2020#include "formats/mfi_dsk.h"
2121#include "formats/hxcmfm_dsk.h"
2222#include "formats/ami_dsk.h"
23#include "formats/st_dsk.h"
2324
2425static floppy_format_type floppy_formats[] = {
2526   FLOPPY_MFI_FORMAT,
27
2628   FLOPPY_MFM_FORMAT,
2729   FLOPPY_ADF_FORMAT,
30
31   FLOPPY_ST_FORMAT,
32   FLOPPY_MSA_FORMAT,
33
2834   NULL
2935};
3036

Previous 15994 Revisions Next


© 1998-2018 The MESS Team