/[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 1002 - (show annotations)
Sun Dec 8 10:50:26 2013 UTC (6 years, 3 months ago) by dbug
File size: 8550 byte(s)
Resynchronized my own changes to the OSDK with what was in the depot.
From now on I will continue the changes directly with the depot version, and try to update more regularly.
The reason I had this big change is that I had two computers with local changes done in demo parties when working on demos, where I did the fixes to handle Euphoric and Oricutron, plus new tools, modified tools, etc... giant mess.
I do not guarantee that what is on the depot is bug free, but it's the version I'm using right now (My OSDK var points to the public\pc\tools\osdk\main\Osdk\_final_ folder.
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 "MakeDisk",
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!=4)
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 char dest_name[_MAX_PATH];
66 param++;
67 strcpy(source_name,argv[param]);
68 param++;
69 strcpy(dest_name,argv[param]);
70
71 //char ligne[900];
72 int start=0;
73
74 std::stringstream code_drive;
75 std::stringstream code_sector;
76 std::stringstream code_track;
77 std::stringstream code_nombre_secteur;
78 std::stringstream code_adress_low;
79 std::stringstream code_adress_high;
80
81 code_drive << "datas_lecteur\n.byt ";
82 code_sector << "datas_secteur\n.byt ";
83 code_track << "datas_piste\n.byt ";
84 code_nombre_secteur << "nombre_secteur\n.byt ";
85 code_adress_low << "adresse_chargement_low\n.byt ";
86 code_adress_high << "adresse_chargement_high\n.byt ";
87
88 //
89 // Open the description file
90 //
91 std::vector<std::string> script;
92 if (!LoadText(description_name,script))
93 {
94 printf("Can't load script file '%s'\n",description_name);
95 exit(1);
96 }
97
98 //
99 // Copy the floppy disk
100 //
101 Floppy floppy;
102 if (!floppy.Load(source_name))
103 {
104 printf("FloppyBuilder: Can't load '%s'\n",source_name);
105 exit(1);
106 }
107
108 // Example of file:
109 /*
110 1 13
111 #load it at 1000
112 demo\part_hires_picture.o
113 #load it at 0500
114 demo\part_hires_picture.o
115 #load it at 0500
116 demo\part_motherboard_scroller.o
117 #new position on disk
118 0 5
119 #load it at fc00
120 demo\loader.o
121 #bootsector
122 demo\bootsector.o
123 */
124
125
126 //
127 // Set some semi sane
128 //
129 int currentTrack =1;
130 int currentSector=1;
131 floppy.SetOffset(currentTrack,currentSector);
132
133 int lineNumber=0;
134 int fileCount=0;
135 for (auto it(script.begin());it!=script.end();++it)
136 {
137 ++lineNumber;
138
139 const std::string currentLine(*it);
140
141 std::istringstream iss(currentLine);
142
143 std::string item;
144 std::vector<std::string> tokens;
145 while (std::getline(iss, item,' '))
146 {
147 if (!item.empty())
148 {
149 tokens.push_back(item);
150 }
151 }
152
153 if (!tokens.empty())
154 {
155 if (tokens[0][0]==';')
156 {
157 // Comments, just skip them
158 }
159 else
160 if (tokens[0]=="SetPosition")
161 {
162 if (tokens.size()==3)
163 {
164 currentTrack =std::atoi(tokens[1].c_str());
165 currentSector=std::atoi(tokens[2].c_str());
166 floppy.SetOffset(currentTrack,currentSector);
167 }
168 else
169 {
170 printf("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 printf("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 printf("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 if (fileCount)
213 {
214 code_adress_low << ",";
215 code_adress_high << ",";
216
217 code_drive << ",";
218 code_sector << ",";
219 code_track << ",";
220 code_nombre_secteur << ",";
221 }
222 code_adress_low << "<" << tokens[2];
223 code_adress_high << ">" << tokens[2];
224
225 if (currentTrack>41) // face 2
226 {
227 code_track << currentTrack-42+128;
228 }
229 else
230 {
231 code_track << currentTrack;
232 }
233 code_sector << currentSector;
234
235 code_drive << "0";
236
237 int nb_sectors_by_files=floppy.writeFile(fileName.c_str(),currentTrack,currentSector);
238 code_nombre_secteur << nb_sectors_by_files;
239
240 //floppy.SetOffset(currentTrack,currentSector);
241 ++fileCount;
242 }
243 else
244 {
245 printf("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
246 }
247 }
248 else
249 {
250 printf("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
251 exit(1);
252 }
253
254 }
255
256 }
257
258 //fscanf(handle_description,"%d %d",&currentTrack,&currentSector);
259
260 /*
261 // On saute grosse bidouille
262 fgets(ligne,900,handle_description);
263 while (fgets(ligne,900,handle_description)!=NULL)
264 {
265 if (detecte_chaine_renvoi_suite("#bootsector",ligne,sortie)==1)
266 {
267 fgets(ligne,900,handle_description); // On lit le fichier à installer dans le boot sector
268 floppy.install_boot_sector(ligne);
269 }
270 else
271 if (detecte_chaine_renvoi_suite("#new position on disk",ligne,sortie)==1)
272 {
273 fscanf(handle_description,"%d %d",&currentTrack,&currentSector);
274 fgets(ligne,900,handle_description);
275 fgets(ligne,900,handle_description);
276 }
277 else
278 if (detecte_chaine_renvoi_suite("#load it at ",ligne,sortie)==1)
279 {
280 //printf("%s\n",ligne);
281 if (start==1)
282 {
283 code_adress_low << ",";
284 code_adress_high << ",";
285 }
286 code_adress_high << "$" << sortie[0] << sortie[1];
287 code_adress_low << "$" << sortie[2] << sortie[3];
288 }
289 else
290 {
291 if (ligne[strlen(ligne)-1]=='\n') ligne[strlen(ligne)-1]='\0';
292 if (currentSector==taille_piste+1)
293 {
294 currentSector=1;
295 currentTrack++;
296 }
297
298 if (start==1)
299 {
300 code_drive << ",";
301 code_sector << ",";
302 code_track << ",";
303 code_nombre_secteur << ",";
304 }
305
306 if (currentTrack>41) // face 2
307 {
308 code_track << currentTrack-42+128;
309 }
310 else
311 {
312 code_track << currentTrack;
313 }
314 code_sector << currentSector;
315
316 code_drive << "0";
317
318 int nb_sectors_by_files=floppy.writeFile(ligne,currentTrack,currentSector);
319 code_nombre_secteur << nb_sectors_by_files;
320
321 start=1;
322 }
323 }
324 */
325
326 std::stringstream layoutInfo;
327 layoutInfo << code_drive.str() << "\n";
328 layoutInfo << "nb_prgm\n";
329 layoutInfo << code_sector.str() << "\n";
330 layoutInfo << code_track.str() << "\n";
331 layoutInfo << code_nombre_secteur.str() << "\n";
332 layoutInfo << code_adress_low.str() << "\n";
333 layoutInfo << code_adress_high.str() << "\n";
334
335 if (!SaveFile("loader.cod",layoutInfo.str().c_str(),layoutInfo.str().length()))
336 {
337 printf("FloppyBuilder: Can't save '%s'\n","loader.cod");
338 exit(1);
339 }
340
341 if (!floppy.Save(dest_name))
342 {
343 printf("Failed saving '%s'\n",dest_name);
344 exit(1);
345 }
346 else
347 {
348 printf("Successfully created '%s'\n",dest_name);
349 }
350 printf("FloppyBuilder: handle_dsk.dsk built successfully\n");
351 }

  ViewVC Help
Powered by ViewVC 1.1.26