/[projet1]/public/pc/tools/osdk/main/makedisk/Floppy.h
Defence Force logotype

Contents of /public/pc/tools/osdk/main/makedisk/Floppy.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1072 - (show annotations)
Wed Jan 8 21:07:43 2014 UTC (6 years ago) by dbug
File MIME type: text/plain
File size: 4267 byte(s)
FloppyBuilder 0.13
- Added a new parameter to make it possible to bootstrap the floppy building process: With 'init' a description fill be generated even if data is missing,
this makes it possible to do a multi-pass build process which will not fail because it depends on things not yet generated :)

1 #ifndef FLOPPY_H_
2 #define FLOPPY_H_
3
4 #include <vector>
5 #include <map>
6 #include <set>
7 #include <sstream>
8 #include <iostream>
9
10
11 enum CompressionMode
12 {
13 e_CompressionNone,
14 e_CompressionFilepack
15 };
16
17 // This class is meant to be mapped on memory area supposed to be of MFM disk format.
18 // The header is 256 bytes long, so this class memory usage should be similar in size and structure.
19 class FloppyHeader
20 {
21 public:
22 FloppyHeader();
23 ~FloppyHeader();
24
25 void Clear();
26
27 bool IsValidHeader() const;
28
29 void SetSignature(char signature[8]);
30
31 void SetSideNumber(int sideNumber);
32 int GetSideNumber() const;
33
34 void SetTrackNumber(int trackNumber);
35 int GetTrackNumber() const;
36
37 void SetGeometry(int geometry);
38 int GetGeometry() const;
39
40 int FindNumberOfSectors(int& firstSectorOffset,int& sectorInterleave) const; ///< Note: This function will expect valid data to exist past the padding because it needs to scan the data...
41
42 private:
43 char m_Signature[8]; // (MFM_DISK)
44 unsigned char m_Sides[4]; // : 4 bytes (2)
45 unsigned char m_Tracks[4]; // : 4 bytes (42/$2A)
46 unsigned char m_Geometry[4]; // : 4 bytes (1)
47 unsigned char m_Padding[236]; // : 236 bytes (000000...00000 )
48 };
49
50
51 class FileEntry
52 {
53 public:
54 FileEntry();
55 ~FileEntry();
56
57 public:
58 int m_FloppyNumber; // 0 for a single floppy program
59 int m_StartSide; // 0 or 1
60 int m_StartTrack; // 0 to 42 (80...)
61 int m_StartSector; // 1 to 17 (or 16 or 18...)
62 int m_SectorCount;
63 int m_FinalFileSize;
64 int m_StoredFileSize;
65 CompressionMode m_CompressionMode;
66 int m_LoadAddress;
67 std::string m_FilePath;
68 std::map<std::string,std::string> m_Metadata;
69 };
70
71
72 class Floppy
73 {
74 public:
75
76 public:
77 Floppy();
78 ~Floppy();
79
80 bool CreateDisk(int numberOfSides,int numberOfTracks,int numberOfSectors);
81 bool LoadDisk(const char* fileName);
82 bool SaveDisk(const char* fileName) const;
83 bool SaveDescription(const char* fileName) const;
84
85 bool WriteSector(const char *fileName);
86 bool WriteFile(const char *fileName,int loadAddress,bool removeHeaderIfPresent,const std::map<std::string,std::string>& metadata);
87 bool WriteTapeFile(const char *fileName);
88
89 bool AddDefine(std::string defineName,std::string defineValue);
90
91 void SetCompressionMode(CompressionMode compressionMode)
92 {
93 m_CompressionMode=compressionMode;
94 }
95
96 void AllowMissingFiles(bool allowMissingFiles)
97 {
98 m_AllowMissingFiles=allowMissingFiles;
99 }
100
101 unsigned int SetPosition(int track,int sector)
102 {
103 m_CurrentSector=sector;
104 m_CurrentTrack =track;
105 return GetDskImageOffset();
106 }
107
108 void MoveToNextSector()
109 {
110 m_CurrentSector++;
111
112 if (m_CurrentSector==m_SectorNumber+1) // We reached the end of the track!
113 {
114 m_CurrentSector=1;
115 m_CurrentTrack++;
116 if (m_CurrentTrack==m_TrackNumber)
117 {
118 // Next side is following on the floppy in the DSK format, so technically we should have nothing to do
119 // All the hard work is in the loader
120 }
121 }
122 }
123
124 void MarkCurrentSectorUsed();
125
126 private:
127 unsigned int GetDskImageOffset();
128
129 private:
130 void* m_Buffer;
131 size_t m_BufferSize;
132 int m_TrackNumber; // 42
133 int m_SectorNumber; // 17
134 int m_SideNumber; // 2
135 int m_OffsetFirstSector; // 156 (Location of the first byte of data of the first sector)
136 int m_InterSectorSpacing; // 358 (Number of bytes to skip to go to the next sector: 256+59+43)
137
138 int m_CurrentTrack;
139 int m_CurrentSector;
140
141 std::set<int> m_SectorUsageMap;
142
143 CompressionMode m_CompressionMode;
144 bool m_AllFilesAreResolved;
145 bool m_AllowMissingFiles;
146
147 std::vector<FileEntry> m_FileEntries;
148 std::vector<std::pair<std::string,std::string>> m_DefineList;
149
150 std::set<std::string> m_MetadataCategories;
151 };
152
153 #endif

  ViewVC Help
Powered by ViewVC 1.1.26