/[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 1014 - (show annotations)
Thu Dec 12 20:50:14 2013 UTC (6 years, 3 months ago) by dbug
File size: 5435 byte(s)
FloppyBuilder 0.5
- removed some unused variables
- cleaned the offset/track/sector management code
- the 'SetBootSector' command is now 'WriteSector' and automatically move to the next sector after writing data
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 int lineNumber=0;
94 for (auto it(script.begin());it!=script.end();++it)
95 {
96 ++lineNumber;
97
98 std::string currentLine(*it);
99
100 std::size_t found = currentLine.find(";");
101 if (found!=std::string::npos)
102 {
103 // Comments, just skip them
104 currentLine=currentLine.substr(0,found);
105 }
106
107 std::istringstream iss(currentLine);
108
109 std::string item;
110 std::vector<std::string> tokens;
111 while (std::getline(iss,item,' '))
112 {
113 if (!item.empty())
114 {
115 tokens.push_back(item);
116 }
117 }
118
119 if (!tokens.empty())
120 {
121 if (tokens[0]=="OutputLayoutFile")
122 {
123 if (tokens.size()==2)
124 {
125 outputLayoutFileName=tokens[1];
126 }
127 else
128 {
129 ShowError("Syntax error line (%d), syntax is 'OutputLayoutFile FilePath' \n",lineNumber);
130 }
131 }
132 else
133 if (tokens[0]=="OutputFloppyFile")
134 {
135 if (tokens.size()==2)
136 {
137 targetFloppyDiskName=tokens[1];
138 }
139 else
140 {
141 ShowError("Syntax error line (%d), syntax is 'targetFloppyDiskName FilePath' \n",lineNumber);
142 }
143 }
144 else
145 if (tokens[0]=="SetPosition")
146 {
147 if (tokens.size()==3)
148 {
149 int currentTrack =std::atoi(tokens[1].c_str());
150 if ( (currentTrack<0) || (currentTrack>41) )
151 {
152 ShowError("Syntax error line (%d), TrackNumber has to be between 0 and 41' \n",lineNumber);
153 }
154 int currentSector=std::atoi(tokens[2].c_str());
155 if ( (currentSector<0) || (currentSector>41) )
156 {
157 ShowError("Syntax error line (%d), SectorNumber has to be between 1 and 17' \n",lineNumber);
158 }
159 floppy.SetPosition(currentTrack,currentSector);
160 }
161 else
162 {
163 ShowError("Syntax error line (%d), syntax is 'SetPosition TrackNumber SectorNumber' \n",lineNumber);
164 }
165 }
166 else
167 if (tokens[0]=="WriteSector")
168 {
169 if (tokens.size()==2)
170 {
171 std::string fileName=tokens[1];
172 floppy.WriteSector(fileName.c_str());
173 }
174 else
175 {
176 ShowError("Syntax error line (%d), syntax is 'SetBootSector FilePath' \n",lineNumber);
177 }
178 }
179 else
180 if (tokens[0]=="AddFile")
181 {
182 if (tokens.size()==3)
183 {
184 std::string fileName=tokens[1];
185 int loadAddress=ConvertAdress(tokens[2].c_str());
186 int nb_sectors_by_files=floppy.WriteFile(fileName.c_str(),loadAddress);
187 }
188 else
189 {
190 ShowError("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
191 }
192 }
193 else
194 if (tokens[0]=="AddDefine")
195 {
196 if (tokens.size()==3)
197 {
198 floppy.AddDefine(tokens[1],tokens[2]);
199 }
200 else
201 {
202 ShowError("Syntax error line (%d), syntax is 'AddDefine DefineName DefineValue' \n",lineNumber);
203 }
204 }
205 else
206 {
207 ShowError("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
208 }
209 }
210 }
211
212
213
214 if (!floppy.SaveDescription(outputLayoutFileName.c_str()))
215 {
216 ShowError("Failed saving description '%s'\n",outputLayoutFileName.c_str());
217 }
218
219 if (!floppy.SaveDisk(targetFloppyDiskName.c_str()))
220 {
221 ShowError("Failed saving disk '%s'\n",targetFloppyDiskName.c_str());
222 }
223 else
224 {
225 printf("Successfully created '%s'\n",targetFloppyDiskName.c_str());
226 }
227 }

  ViewVC Help
Powered by ViewVC 1.1.26