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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1018 - (show annotations)
Sat Dec 14 14:02:00 2013 UTC (5 years, 9 months 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
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <sstream>
6 #include <iostream>
7 #include <vector>
8
9 #include "infos.h"
10 #include "common.h"
11 #include "Floppy.h"
12
13
14
15
16 void main(int argc, char *argv[])
17 {
18 //
19 // Some initialization for the common library
20 //
21 SetApplicationParameters(
22 "FloppyBuilder",
23 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 "\r\n"
34 "Usage:\r\n"
35 " {ApplicationName} <description file path>\r\n"
36 "\r\n"
37 );
38
39 // makedisk filetobuild.txt default.dsk ..\build\%OSDKDISK%
40
41 long param=1;
42
43 if (argc>1)
44 {
45 for (;;)
46 {
47 long nb_arg=argc;
48 const char *ptr_arg=argv[param];
49
50 if (nb_arg==argc) break;
51 }
52 }
53
54
55 if (argc!=2)
56 {
57 ShowError(nullptr);
58 }
59
60
61 //
62 // Open the description file
63 //
64 const char* description_name(argv[param]);
65 std::vector<std::string> script;
66 if (!LoadText(description_name,script))
67 {
68 ShowError("Can't load script file '%s'\n",description_name);
69 }
70
71 //
72 // Copy the floppy disk
73 //
74 Floppy floppy;
75
76 std::string outputLayoutFileName;
77 std::string targetFloppyDiskName;
78
79 int lineNumber=0;
80 for (auto it(script.begin());it!=script.end();++it)
81 {
82 ++lineNumber;
83
84 std::string currentLine(*it);
85
86 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 std::istringstream iss(currentLine);
94
95 std::string item;
96 std::vector<std::string> tokens;
97 while (std::getline(iss,item,' '))
98 {
99 if (!item.empty())
100 {
101 tokens.push_back(item);
102 }
103 }
104
105 if (!tokens.empty())
106 {
107 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 if (tokens[0]=="OutputLayoutFile")
160 {
161 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 }
170 else
171 if (tokens[0]=="OutputFloppyFile")
172 {
173 if (tokens.size()==2)
174 {
175 targetFloppyDiskName=tokens[1];
176 }
177 else
178 {
179 ShowError("Syntax error line (%d), syntax is 'targetFloppyDiskName FilePath' \n",lineNumber);
180 }
181 }
182 else
183 if (tokens[0]=="SetPosition")
184 {
185 if (tokens.size()==3)
186 {
187 int currentTrack =std::atoi(tokens[1].c_str());
188 if ( (currentTrack<0) || (currentTrack>41) )
189 {
190 ShowError("Syntax error line (%d), TrackNumber has to be between 0 and 41' \n",lineNumber);
191 }
192 int currentSector=std::atoi(tokens[2].c_str());
193 if ( (currentSector<0) || (currentSector>41) )
194 {
195 ShowError("Syntax error line (%d), SectorNumber has to be between 1 and 17' \n",lineNumber);
196 }
197 floppy.SetPosition(currentTrack,currentSector);
198 }
199 else
200 {
201 ShowError("Syntax error line (%d), syntax is 'SetPosition TrackNumber SectorNumber' \n",lineNumber);
202 }
203 }
204 else
205 if (tokens[0]=="WriteSector")
206 {
207 if (tokens.size()==2)
208 {
209 std::string fileName=tokens[1];
210 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 }
215 else
216 {
217 ShowError("Syntax error line (%d), syntax is 'SetBootSector FilePath' \n",lineNumber);
218 }
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 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 }
232 else
233 {
234 ShowError("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
235 }
236 }
237 else
238 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 if (tokens[0]=="AddDefine")
255 {
256 if (tokens.size()==3)
257 {
258 floppy.AddDefine(tokens[1],tokens[2]);
259 }
260 else
261 {
262 ShowError("Syntax error line (%d), syntax is 'AddDefine DefineName DefineValue' \n",lineNumber);
263 }
264 }
265 else
266 {
267 ShowError("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
268 }
269 }
270 }
271
272
273
274 if (!floppy.SaveDescription(outputLayoutFileName.c_str()))
275 {
276 ShowError("Failed saving description '%s'\n",outputLayoutFileName.c_str());
277 }
278
279 if (!floppy.SaveDisk(targetFloppyDiskName.c_str()))
280 {
281 ShowError("Failed saving disk '%s'\n",targetFloppyDiskName.c_str());
282 }
283 else
284 {
285 printf("Successfully created '%s'\n",targetFloppyDiskName.c_str());
286 }
287 }

  ViewVC Help
Powered by ViewVC 1.1.26