/[projet1]/public/pc/tools/osdk/main/makedisk/FloppyBuilder.cpp
Defence Force logotype

Annotation of /public/pc/tools/osdk/main/makedisk/FloppyBuilder.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1035 - (hide annotations)
Sun Dec 15 15:35:39 2013 UTC (5 years, 11 months ago) by dbug
File size: 8521 byte(s)
FloppyBuilder 0.9
- Added the 'SetCompressionMode' command. Possible parameters are 'None' (default value) and 'FilePack'
The lzpack.cpp file moved out from FilePack and is now in Common, this means it will be usable in other projects (Like PictConv)
1 dbug 975
2     #include <stdlib.h>
3     #include <stdio.h>
4     #include <string.h>
5 dbug 1002 #include <sstream>
6     #include <iostream>
7     #include <vector>
8 dbug 975
9 dbug 1002 #include "infos.h"
10     #include "common.h"
11     #include "Floppy.h"
12 dbug 975
13    
14    
15    
16 dbug 1002 void main(int argc, char *argv[])
17 dbug 975 {
18 dbug 1002 //
19     // Some initialization for the common library
20     //
21     SetApplicationParameters(
22 dbug 1013 "FloppyBuilder",
23 dbug 1002 TOOL_VERSION_MAJOR,
24     TOOL_VERSION_MINOR,
25     "{ApplicationName} - Version {ApplicationVersion} - This program is a part of the OSDK\r\n"
26     "\r\n"
27     "Author:\r\n"
28     " (c) 2002 Debrune Jerome for the initial version \r\n"
29     " (c) 2013 Pointier Mickael for the subsequent changes \r\n"
30     "\r\n"
31     "Purpose:\r\n"
32     " Generating bootable floppies for the Oric computer.\r\n"
33 dbug 1018 "\r\n"
34     "Usage:\r\n"
35     " {ApplicationName} <description file path>\r\n"
36     "\r\n"
37 dbug 1002 );
38 dbug 975
39 dbug 1002 // makedisk filetobuild.txt default.dsk ..\build\%OSDKDISK%
40 dbug 975
41     long param=1;
42    
43     if (argc>1)
44     {
45     for (;;)
46     {
47 dbug 1002 long nb_arg=argc;
48 dbug 975 const char *ptr_arg=argv[param];
49    
50     if (nb_arg==argc) break;
51     }
52     }
53    
54    
55 dbug 1018 if (argc!=2)
56 dbug 975 {
57 dbug 1002 ShowError(nullptr);
58 dbug 975 }
59    
60    
61     //
62     // Open the description file
63     //
64 dbug 1018 const char* description_name(argv[param]);
65 dbug 1002 std::vector<std::string> script;
66     if (!LoadText(description_name,script))
67 dbug 975 {
68 dbug 1013 ShowError("Can't load script file '%s'\n",description_name);
69 dbug 975 }
70    
71     //
72     // Copy the floppy disk
73     //
74 dbug 1002 Floppy floppy;
75 dbug 975
76 dbug 1009 std::string outputLayoutFileName;
77 dbug 1018 std::string targetFloppyDiskName;
78 dbug 975
79 dbug 1002 int lineNumber=0;
80     for (auto it(script.begin());it!=script.end();++it)
81 dbug 975 {
82 dbug 1002 ++lineNumber;
83 dbug 975
84 dbug 1013 std::string currentLine(*it);
85 dbug 1002
86 dbug 1013 std::size_t found = currentLine.find(";");
87     if (found!=std::string::npos)
88     {
89     // Comments, just skip them
90     currentLine=currentLine.substr(0,found);
91     }
92    
93 dbug 1002 std::istringstream iss(currentLine);
94    
95     std::string item;
96     std::vector<std::string> tokens;
97 dbug 1013 while (std::getline(iss,item,' '))
98 dbug 975 {
99 dbug 1025 // Remove eventual superfluous spaces and tabs
100     item=StringTrim(item);
101 dbug 1002 if (!item.empty())
102     {
103     tokens.push_back(item);
104     }
105 dbug 975 }
106 dbug 1002
107     if (!tokens.empty())
108     {
109 dbug 1018 if (tokens[0]=="LoadDiskTemplate")
110     {
111     if (tokens.size()==2)
112     {
113     const std::string& templateFisk(tokens[1]);
114     if (!floppy.LoadDisk(templateFisk.c_str()))
115     {
116     ShowError("Can't load '%s'\n",templateFisk.c_str());
117     }
118    
119     }
120     else
121     {
122     ShowError("Syntax error line (%d), syntax is 'LoadDiskTemplate FilePath' \n",lineNumber);
123     }
124     }
125     else
126     if (tokens[0]=="DefineDisk")
127     {
128     if (tokens.size()==4)
129     {
130     int numberOfSides =std::atoi(tokens[1].c_str());
131     int numberOfTracks =std::atoi(tokens[2].c_str());
132     int numberOfSectors =std::atoi(tokens[3].c_str());
133    
134     if ( numberOfSides!=2 )
135     {
136     ShowError("Syntax error line (%d), numberOfSides has to be 2 (so far)\n",lineNumber);
137     }
138    
139     if ( numberOfTracks!=42 )
140     {
141     ShowError("Syntax error line (%d), numberOfTracks has to be 42 (so far)\n",lineNumber);
142     }
143    
144     if ( numberOfSectors!=17 )
145     {
146     ShowError("Syntax error line (%d), numberOfSectors has to be 17 (so far)\n",lineNumber);
147     }
148    
149     if (!floppy.CreateDisk(numberOfSides,numberOfTracks,numberOfSectors))
150     {
151     ShowError("Can't create disk\n");
152     }
153    
154     }
155     else
156     {
157     ShowError("Syntax error line (%d), syntax is 'DefineDisk numberOfSides numberOfTracks numberOfSectors' \n",lineNumber);
158     }
159     }
160     else
161 dbug 1013 if (tokens[0]=="OutputLayoutFile")
162 dbug 975 {
163 dbug 1013 if (tokens.size()==2)
164     {
165     outputLayoutFileName=tokens[1];
166     }
167     else
168     {
169     ShowError("Syntax error line (%d), syntax is 'OutputLayoutFile FilePath' \n",lineNumber);
170     }
171 dbug 1002 }
172     else
173 dbug 1013 if (tokens[0]=="OutputFloppyFile")
174 dbug 1009 {
175     if (tokens.size()==2)
176     {
177 dbug 1013 targetFloppyDiskName=tokens[1];
178 dbug 1009 }
179     else
180     {
181 dbug 1013 ShowError("Syntax error line (%d), syntax is 'targetFloppyDiskName FilePath' \n",lineNumber);
182 dbug 1009 }
183     }
184     else
185 dbug 1002 if (tokens[0]=="SetPosition")
186     {
187     if (tokens.size()==3)
188 dbug 975 {
189 dbug 1014 int currentTrack =std::atoi(tokens[1].c_str());
190 dbug 1013 if ( (currentTrack<0) || (currentTrack>41) )
191     {
192     ShowError("Syntax error line (%d), TrackNumber has to be between 0 and 41' \n",lineNumber);
193     }
194 dbug 1014 int currentSector=std::atoi(tokens[2].c_str());
195 dbug 1013 if ( (currentSector<0) || (currentSector>41) )
196     {
197     ShowError("Syntax error line (%d), SectorNumber has to be between 1 and 17' \n",lineNumber);
198     }
199 dbug 1014 floppy.SetPosition(currentTrack,currentSector);
200 dbug 975 }
201 dbug 1002 else
202     {
203 dbug 1013 ShowError("Syntax error line (%d), syntax is 'SetPosition TrackNumber SectorNumber' \n",lineNumber);
204 dbug 1002 }
205 dbug 975 }
206     else
207 dbug 1014 if (tokens[0]=="WriteSector")
208 dbug 1002 {
209 dbug 1014 if (tokens.size()==2)
210 dbug 975 {
211 dbug 1014 std::string fileName=tokens[1];
212 dbug 1018 if (!floppy.WriteSector(fileName.c_str()))
213     {
214     ShowError("Error line (%d), could not write file '%s' to disk. Make sure you have a valid floppy format declared. \n",lineNumber,fileName.c_str());
215     }
216 dbug 975 }
217     else
218     {
219 dbug 1025 ShowError("Syntax error line (%d), syntax is 'WriteSector FilePath' \n",lineNumber);
220 dbug 1002 }
221     }
222     else
223     if (tokens[0]=="AddFile")
224     {
225     if (tokens.size()==3)
226     {
227     std::string fileName=tokens[1];
228     int loadAddress=ConvertAdress(tokens[2].c_str());
229 dbug 1018 if (!floppy.WriteFile(fileName.c_str(),loadAddress,false))
230     {
231     ShowError("Error line (%d), could not write file '%s' to disk. Make sure you have a valid floppy format declared. \n",lineNumber,fileName.c_str());
232     }
233 dbug 1002 }
234     else
235     {
236 dbug 1013 ShowError("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
237 dbug 1002 }
238     }
239     else
240 dbug 1018 if (tokens[0]=="AddTapFile")
241     {
242     if (tokens.size()==2)
243     {
244     std::string fileName=tokens[1];
245     if (!floppy.WriteFile(fileName.c_str(),-1,true))
246     {
247     ShowError("Error line (%d), could not write file '%s' to disk. Make sure you have a valid floppy format declared. \n",lineNumber,fileName.c_str());
248     }
249     }
250     else
251     {
252     ShowError("Syntax error line (%d), syntax is 'AddTapFile FilePath' \n",lineNumber);
253     }
254     }
255     else
256 dbug 1009 if (tokens[0]=="AddDefine")
257 dbug 1002 {
258 dbug 1009 if (tokens.size()==3)
259     {
260     floppy.AddDefine(tokens[1],tokens[2]);
261     }
262     else
263     {
264 dbug 1013 ShowError("Syntax error line (%d), syntax is 'AddDefine DefineName DefineValue' \n",lineNumber);
265 dbug 1009 }
266     }
267     else
268 dbug 1035 if (tokens[0]=="SetCompressionMode")
269 dbug 1009 {
270 dbug 1035 if (tokens.size()==2)
271     {
272     if (tokens[1]=="None")
273     {
274     floppy.SetCompressionMode(e_CompressionNone);
275     }
276     else
277     if (tokens[1]=="FilePack")
278     {
279     floppy.SetCompressionMode(e_CompressionFilepack);
280     }
281     else
282     {
283     ShowError("Syntax error line (%d), '%s' is not a valid compression mode, it should be either 'None' or 'FilePack' \n",lineNumber,tokens[1].c_str());
284     }
285     }
286     else
287     {
288     ShowError("Syntax error line (%d), syntax is 'SetCompressionMode [None|FilePack]' \n",lineNumber);
289     }
290     }
291     else
292     {
293 dbug 1013 ShowError("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
294 dbug 1002 }
295     }
296     }
297 dbug 975
298    
299    
300 dbug 1009 if (!floppy.SaveDescription(outputLayoutFileName.c_str()))
301 dbug 1002 {
302 dbug 1013 ShowError("Failed saving description '%s'\n",outputLayoutFileName.c_str());
303 dbug 1002 }
304 dbug 975
305 dbug 1013 if (!floppy.SaveDisk(targetFloppyDiskName.c_str()))
306 dbug 1002 {
307 dbug 1013 ShowError("Failed saving disk '%s'\n",targetFloppyDiskName.c_str());
308 dbug 1002 }
309     else
310     {
311 dbug 1013 printf("Successfully created '%s'\n",targetFloppyDiskName.c_str());
312 dbug 1002 }
313 dbug 975 }

  ViewVC Help
Powered by ViewVC 1.1.26