/[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 1095 - (show annotations)
Wed Jan 29 13:46:25 2014 UTC (5 years, 7 months ago) by dbug
File MIME type: text/plain
File size: 4476 byte(s)
FloppyBuilder 0.14
- The MetaData tables will now not contain any information after the last file that declared metadata, this allows to not waste room in the loader for dummy data

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 bool 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 if (m_CurrentTrack==(m_TrackNumber*2))
122 {
123 // We have reached the end of the floppy...
124 return false;
125 }
126 }
127 return true;
128 }
129
130 void MarkCurrentSectorUsed();
131
132 private:
133 unsigned int GetDskImageOffset();
134
135 private:
136 void* m_Buffer;
137 size_t m_BufferSize;
138 int m_TrackNumber; // 42
139 int m_SectorNumber; // 17
140 int m_SideNumber; // 2
141 int m_OffsetFirstSector; // 156 (Location of the first byte of data of the first sector)
142 int m_InterSectorSpacing; // 358 (Number of bytes to skip to go to the next sector: 256+59+43)
143
144 int m_CurrentTrack;
145 int m_CurrentSector;
146
147 std::set<int> m_SectorUsageMap;
148
149 CompressionMode m_CompressionMode;
150 bool m_AllFilesAreResolved;
151 bool m_AllowMissingFiles;
152
153 std::vector<FileEntry> m_FileEntries;
154 std::vector<std::pair<std::string,std::string>> m_DefineList;
155
156 int m_LastFileWithMetadata;
157 std::set<std::string> m_MetadataCategories;
158 };
159
160 #endif

  ViewVC Help
Powered by ViewVC 1.1.26