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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1329 - (show annotations)
Sat Oct 24 20:40:51 2015 UTC (3 years, 10 months ago) by dbug
File MIME type: text/plain
File size: 4683 byte(s)
FloppyBuilder 0.18
- Added a 'ReserveSectors' command that can be used to leave room on the disk for save games or stuff like that.
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(const 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 ReserveSectors(int sectorCount,int fillValue,const std::map<std::string,std::string>& metadata);
90
91 bool ExtractFile(const char *fileName,int trackNumber,int sectorNumber,int sectorCount);
92
93 bool AddDefine(std::string defineName,std::string defineValue);
94
95 void SetCompressionMode(CompressionMode compressionMode)
96 {
97 m_CompressionMode=compressionMode;
98 }
99
100 void AllowMissingFiles(bool allowMissingFiles)
101 {
102 m_AllowMissingFiles=allowMissingFiles;
103 }
104
105 unsigned int SetPosition(int track,int sector)
106 {
107 m_CurrentSector=sector;
108 m_CurrentTrack =track;
109 return GetDskImageOffset();
110 }
111
112 bool MoveToNextSector()
113 {
114 m_CurrentSector++;
115
116 if (m_CurrentSector==m_SectorNumber+1) // We reached the end of the track!
117 {
118 m_CurrentSector=1;
119 m_CurrentTrack++;
120 if (m_CurrentTrack==m_TrackNumber)
121 {
122 // Next side is following on the floppy in the DSK format, so technically we should have nothing to do
123 // All the hard work is in the loader
124 }
125 if (m_CurrentTrack==(m_TrackNumber*2))
126 {
127 // We have reached the end of the floppy...
128 return false;
129 }
130 }
131 return true;
132 }
133
134 void MarkCurrentSectorUsed();
135
136 private:
137 unsigned int GetDskImageOffset();
138
139 private:
140 void* m_Buffer;
141 size_t m_BufferSize;
142 int m_TrackNumber; // 42
143 int m_SectorNumber; // 17
144 int m_SideNumber; // 2
145 int m_OffsetFirstSector; // 156 (Location of the first byte of data of the first sector)
146 int m_InterSectorSpacing; // 358 (Number of bytes to skip to go to the next sector: 256+59+43)
147
148 int m_CurrentTrack;
149 int m_CurrentSector;
150
151 std::set<int> m_SectorUsageMap;
152
153 CompressionMode m_CompressionMode;
154 bool m_AllFilesAreResolved;
155 bool m_AllowMissingFiles;
156
157 std::vector<FileEntry> m_FileEntries;
158 std::vector<std::pair<std::string,std::string>> m_DefineList;
159
160 int m_LastFileWithMetadata;
161 std::set<std::string> m_MetadataCategories;
162 };
163
164 #endif

  ViewVC Help
Powered by ViewVC 1.1.26