/[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 1013 - (show annotations)
Thu Dec 12 19:35:12 2013 UTC (6 years, 2 months ago) by dbug
File size: 6151 byte(s)
Modified the ShowError command to take optional parameters (makes it possible to display actual information in the error message)
FloppyBuilder 0.3: Fixed parsing of comments, added a 'OutputFloppyFile' command, validated that the number of sectors and tracks is correct in the 'SetPosition' command.
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 );
34
35 // makedisk filetobuild.txt default.dsk ..\build\%OSDKDISK%
36
37 long param=1;
38
39 if (argc>1)
40 {
41 for (;;)
42 {
43 long nb_arg=argc;
44 const char *ptr_arg=argv[param];
45
46 if (nb_arg==argc) break;
47 }
48 }
49
50
51 if (argc!=3)
52 {
53 ShowError(nullptr);
54 }
55
56
57 //
58 // Copy last parameters
59 //
60 char description_name[_MAX_PATH];
61
62 strcpy(description_name,argv[param]);
63
64 char source_name[_MAX_PATH];
65 param++;
66 strcpy(source_name,argv[param]);
67
68 int start=0;
69
70 //std::string templateFloppyDiskName;
71 std::string targetFloppyDiskName;
72
73 //
74 // Open the description file
75 //
76 std::vector<std::string> script;
77 if (!LoadText(description_name,script))
78 {
79 ShowError("Can't load script file '%s'\n",description_name);
80 }
81
82 //
83 // Copy the floppy disk
84 //
85 Floppy floppy;
86 if (!floppy.LoadDisk(source_name))
87 {
88 ShowError("FloppyBuilder: Can't load '%s'\n",source_name);
89 }
90
91 std::string outputLayoutFileName;
92
93 //
94 // Set some semi sane
95 //
96 int currentTrack =1;
97 int currentSector=1;
98 floppy.SetOffset(currentTrack,currentSector);
99
100 int lineNumber=0;
101 for (auto it(script.begin());it!=script.end();++it)
102 {
103 ++lineNumber;
104
105 std::string currentLine(*it);
106
107 std::size_t found = currentLine.find(";");
108 if (found!=std::string::npos)
109 {
110 // Comments, just skip them
111 currentLine=currentLine.substr(0,found);
112 }
113
114 std::istringstream iss(currentLine);
115
116 std::string item;
117 std::vector<std::string> tokens;
118 while (std::getline(iss,item,' '))
119 {
120 if (!item.empty())
121 {
122 tokens.push_back(item);
123 }
124 }
125
126 if (!tokens.empty())
127 {
128 if (tokens[0]=="OutputLayoutFile")
129 {
130 if (tokens.size()==2)
131 {
132 outputLayoutFileName=tokens[1];
133 }
134 else
135 {
136 ShowError("Syntax error line (%d), syntax is 'OutputLayoutFile FilePath' \n",lineNumber);
137 }
138 }
139 else
140 if (tokens[0]=="OutputFloppyFile")
141 {
142 if (tokens.size()==2)
143 {
144 targetFloppyDiskName=tokens[1];
145 }
146 else
147 {
148 ShowError("Syntax error line (%d), syntax is 'targetFloppyDiskName FilePath' \n",lineNumber);
149 }
150 }
151 else
152 if (tokens[0]=="SetPosition")
153 {
154 if (tokens.size()==3)
155 {
156 currentTrack =std::atoi(tokens[1].c_str());
157 if ( (currentTrack<0) || (currentTrack>41) )
158 {
159 ShowError("Syntax error line (%d), TrackNumber has to be between 0 and 41' \n",lineNumber);
160 }
161 currentSector=std::atoi(tokens[2].c_str());
162 if ( (currentSector<0) || (currentSector>41) )
163 {
164 ShowError("Syntax error line (%d), SectorNumber has to be between 1 and 17' \n",lineNumber);
165 }
166 floppy.SetOffset(currentTrack,currentSector);
167 }
168 else
169 {
170 ShowError("Syntax error line (%d), syntax is 'SetPosition TrackNumber SectorNumber' \n",lineNumber);
171 }
172 }
173 else
174 if (tokens[0]=="SetBootSector")
175 {
176 if (tokens.size()==3)
177 {
178 std::string fileName=tokens[2];
179 if (tokens[1]=="Microdisc")
180 {
181 floppy.WriteSector(0,2,fileName.c_str());
182 }
183 else
184 if (tokens[1]=="Jasmin")
185 {
186 floppy.WriteSector(0,1,fileName.c_str());
187 }
188 else
189 {
190 ShowError("Syntax error line (%d), syntax is 'SetBootSector Jasmin|Microdisc FilePath'. '%s' is not a valid type \n",lineNumber,tokens[1].c_str());
191 }
192 }
193 else
194 {
195 ShowError("Syntax error line (%d), syntax is 'SetBootSector Jasmin|Microdisc FilePath' \n",lineNumber);
196 }
197 }
198 else
199 if (tokens[0]=="AddFile")
200 {
201 if (tokens.size()==3)
202 {
203 std::string fileName=tokens[1];
204 int loadAddress=ConvertAdress(tokens[2].c_str());
205
206 if (currentSector==taille_piste+1)
207 {
208 currentSector=1;
209 currentTrack++;
210 }
211
212 int nb_sectors_by_files=floppy.WriteFile(fileName.c_str(),currentTrack,currentSector,loadAddress);
213 }
214 else
215 {
216 ShowError("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
217 }
218 }
219 else
220 if (tokens[0]=="AddDefine")
221 {
222 if (tokens.size()==3)
223 {
224 floppy.AddDefine(tokens[1],tokens[2]);
225 }
226 else
227 {
228 ShowError("Syntax error line (%d), syntax is 'AddDefine DefineName DefineValue' \n",lineNumber);
229 }
230 }
231 else
232 {
233 ShowError("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
234 }
235 }
236 }
237
238
239
240 if (!floppy.SaveDescription(outputLayoutFileName.c_str()))
241 {
242 ShowError("Failed saving description '%s'\n",outputLayoutFileName.c_str());
243 }
244
245 if (!floppy.SaveDisk(targetFloppyDiskName.c_str()))
246 {
247 ShowError("Failed saving disk '%s'\n",targetFloppyDiskName.c_str());
248 }
249 else
250 {
251 printf("Successfully created '%s'\n",targetFloppyDiskName.c_str());
252 }
253 }

  ViewVC Help
Powered by ViewVC 1.1.26