/[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 1018 - (hide annotations)
Sat Dec 14 14:02:00 2013 UTC (6 years ago) by dbug
File size: 7700 byte(s)
FloppyBuilder 0.6
- Added the 'LoadDiskTemplate' and 'DefineDisk' commands (and removed these parameters from the command line, define disk does not work at the moment)
- Added the 'AddTapFile' command, similar to 'AddFile' but automatically removes the header and extract the start address of the file
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 1002 if (!item.empty())
100     {
101     tokens.push_back(item);
102     }
103 dbug 975 }
104 dbug 1002
105     if (!tokens.empty())
106     {
107 dbug 1018 if (tokens[0]=="LoadDiskTemplate")
108     {
109     if (tokens.size()==2)
110     {
111     const std::string& templateFisk(tokens[1]);
112     if (!floppy.LoadDisk(templateFisk.c_str()))
113     {
114     ShowError("Can't load '%s'\n",templateFisk.c_str());
115     }
116    
117     }
118     else
119     {
120     ShowError("Syntax error line (%d), syntax is 'LoadDiskTemplate FilePath' \n",lineNumber);
121     }
122     }
123     else
124     if (tokens[0]=="DefineDisk")
125     {
126     if (tokens.size()==4)
127     {
128     int numberOfSides =std::atoi(tokens[1].c_str());
129     int numberOfTracks =std::atoi(tokens[2].c_str());
130     int numberOfSectors =std::atoi(tokens[3].c_str());
131    
132     if ( numberOfSides!=2 )
133     {
134     ShowError("Syntax error line (%d), numberOfSides has to be 2 (so far)\n",lineNumber);
135     }
136    
137     if ( numberOfTracks!=42 )
138     {
139     ShowError("Syntax error line (%d), numberOfTracks has to be 42 (so far)\n",lineNumber);
140     }
141    
142     if ( numberOfSectors!=17 )
143     {
144     ShowError("Syntax error line (%d), numberOfSectors has to be 17 (so far)\n",lineNumber);
145     }
146    
147     if (!floppy.CreateDisk(numberOfSides,numberOfTracks,numberOfSectors))
148     {
149     ShowError("Can't create disk\n");
150     }
151    
152     }
153     else
154     {
155     ShowError("Syntax error line (%d), syntax is 'DefineDisk numberOfSides numberOfTracks numberOfSectors' \n",lineNumber);
156     }
157     }
158     else
159 dbug 1013 if (tokens[0]=="OutputLayoutFile")
160 dbug 975 {
161 dbug 1013 if (tokens.size()==2)
162     {
163     outputLayoutFileName=tokens[1];
164     }
165     else
166     {
167     ShowError("Syntax error line (%d), syntax is 'OutputLayoutFile FilePath' \n",lineNumber);
168     }
169 dbug 1002 }
170     else
171 dbug 1013 if (tokens[0]=="OutputFloppyFile")
172 dbug 1009 {
173     if (tokens.size()==2)
174     {
175 dbug 1013 targetFloppyDiskName=tokens[1];
176 dbug 1009 }
177     else
178     {
179 dbug 1013 ShowError("Syntax error line (%d), syntax is 'targetFloppyDiskName FilePath' \n",lineNumber);
180 dbug 1009 }
181     }
182     else
183 dbug 1002 if (tokens[0]=="SetPosition")
184     {
185     if (tokens.size()==3)
186 dbug 975 {
187 dbug 1014 int currentTrack =std::atoi(tokens[1].c_str());
188 dbug 1013 if ( (currentTrack<0) || (currentTrack>41) )
189     {
190     ShowError("Syntax error line (%d), TrackNumber has to be between 0 and 41' \n",lineNumber);
191     }
192 dbug 1014 int currentSector=std::atoi(tokens[2].c_str());
193 dbug 1013 if ( (currentSector<0) || (currentSector>41) )
194     {
195     ShowError("Syntax error line (%d), SectorNumber has to be between 1 and 17' \n",lineNumber);
196     }
197 dbug 1014 floppy.SetPosition(currentTrack,currentSector);
198 dbug 975 }
199 dbug 1002 else
200     {
201 dbug 1013 ShowError("Syntax error line (%d), syntax is 'SetPosition TrackNumber SectorNumber' \n",lineNumber);
202 dbug 1002 }
203 dbug 975 }
204     else
205 dbug 1014 if (tokens[0]=="WriteSector")
206 dbug 1002 {
207 dbug 1014 if (tokens.size()==2)
208 dbug 975 {
209 dbug 1014 std::string fileName=tokens[1];
210 dbug 1018 if (!floppy.WriteSector(fileName.c_str()))
211     {
212     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());
213     }
214 dbug 975 }
215     else
216     {
217 dbug 1014 ShowError("Syntax error line (%d), syntax is 'SetBootSector FilePath' \n",lineNumber);
218 dbug 1002 }
219     }
220     else
221     if (tokens[0]=="AddFile")
222     {
223     if (tokens.size()==3)
224     {
225     std::string fileName=tokens[1];
226     int loadAddress=ConvertAdress(tokens[2].c_str());
227 dbug 1018 if (!floppy.WriteFile(fileName.c_str(),loadAddress,false))
228     {
229     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());
230     }
231 dbug 1002 }
232     else
233     {
234 dbug 1013 ShowError("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
235 dbug 1002 }
236     }
237     else
238 dbug 1018 if (tokens[0]=="AddTapFile")
239     {
240     if (tokens.size()==2)
241     {
242     std::string fileName=tokens[1];
243     if (!floppy.WriteFile(fileName.c_str(),-1,true))
244     {
245     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());
246     }
247     }
248     else
249     {
250     ShowError("Syntax error line (%d), syntax is 'AddTapFile FilePath' \n",lineNumber);
251     }
252     }
253     else
254 dbug 1009 if (tokens[0]=="AddDefine")
255 dbug 1002 {
256 dbug 1009 if (tokens.size()==3)
257     {
258     floppy.AddDefine(tokens[1],tokens[2]);
259     }
260     else
261     {
262 dbug 1013 ShowError("Syntax error line (%d), syntax is 'AddDefine DefineName DefineValue' \n",lineNumber);
263 dbug 1009 }
264     }
265     else
266     {
267 dbug 1013 ShowError("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
268 dbug 1002 }
269     }
270     }
271 dbug 975
272    
273    
274 dbug 1009 if (!floppy.SaveDescription(outputLayoutFileName.c_str()))
275 dbug 1002 {
276 dbug 1013 ShowError("Failed saving description '%s'\n",outputLayoutFileName.c_str());
277 dbug 1002 }
278 dbug 975
279 dbug 1013 if (!floppy.SaveDisk(targetFloppyDiskName.c_str()))
280 dbug 1002 {
281 dbug 1013 ShowError("Failed saving disk '%s'\n",targetFloppyDiskName.c_str());
282 dbug 1002 }
283     else
284     {
285 dbug 1013 printf("Successfully created '%s'\n",targetFloppyDiskName.c_str());
286 dbug 1002 }
287 dbug 975 }

  ViewVC Help
Powered by ViewVC 1.1.26