/[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 1009 - (show annotations)
Wed Dec 11 20:11:41 2013 UTC (5 years, 11 months ago) by dbug
File size: 5386 byte(s)
More FloppyBuilder changes:
- Add 'OutputLayoutFile' and 'AddDefine' commands
- The generated file has been vastly improved
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
75 //
76 // Open the description file
77 //
78 std::vector<std::string> script;
79 if (!LoadText(description_name,script))
80 {
81 printf("Can't load script file '%s'\n",description_name);
82 exit(1);
83 }
84
85 //
86 // Copy the floppy disk
87 //
88 Floppy floppy;
89 if (!floppy.LoadDisk(source_name))
90 {
91 printf("FloppyBuilder: Can't load '%s'\n",source_name);
92 exit(1);
93 }
94
95 std::string outputLayoutFileName;
96
97 //
98 // Set some semi sane
99 //
100 int currentTrack =1;
101 int currentSector=1;
102 floppy.SetOffset(currentTrack,currentSector);
103
104 int lineNumber=0;
105 for (auto it(script.begin());it!=script.end();++it)
106 {
107 ++lineNumber;
108
109 const std::string currentLine(*it);
110
111 std::istringstream iss(currentLine);
112
113 std::string item;
114 std::vector<std::string> tokens;
115 while (std::getline(iss, item,' '))
116 {
117 if (!item.empty())
118 {
119 tokens.push_back(item);
120 }
121 }
122
123 if (!tokens.empty())
124 {
125 if (tokens[0][0]==';')
126 {
127 // Comments, just skip them
128 }
129 else
130 if (tokens[0]=="OutputLayoutFile")
131 {
132 if (tokens.size()==2)
133 {
134 outputLayoutFileName=tokens[1];
135 }
136 else
137 {
138 printf("Syntax error line (%d), syntax is 'OutputLayoutFile FilePath' \n",lineNumber);
139 }
140 }
141 else
142 if (tokens[0]=="SetPosition")
143 {
144 if (tokens.size()==3)
145 {
146 currentTrack =std::atoi(tokens[1].c_str());
147 currentSector=std::atoi(tokens[2].c_str());
148 floppy.SetOffset(currentTrack,currentSector);
149 }
150 else
151 {
152 printf("Syntax error line (%d), syntax is 'SetPosition TrackNumber SectorNumber' \n",lineNumber);
153 }
154 }
155 else
156 if (tokens[0]=="SetBootSector")
157 {
158 if (tokens.size()==3)
159 {
160 std::string fileName=tokens[2];
161 if (tokens[1]=="Microdisc")
162 {
163 floppy.WriteSector(0,2,fileName.c_str());
164 }
165 else
166 if (tokens[1]=="Jasmin")
167 {
168 floppy.WriteSector(0,1,fileName.c_str());
169 }
170 else
171 {
172 printf("Syntax error line (%d), syntax is 'SetBootSector Jasmin|Microdisc FilePath'. '%s' is not a valid type \n",lineNumber,tokens[1].c_str());
173 }
174 }
175 else
176 {
177 printf("Syntax error line (%d), syntax is 'SetBootSector Jasmin|Microdisc FilePath' \n",lineNumber);
178 }
179 }
180 else
181 if (tokens[0]=="AddFile")
182 {
183 if (tokens.size()==3)
184 {
185 std::string fileName=tokens[1];
186 int loadAddress=ConvertAdress(tokens[2].c_str());
187
188 if (currentSector==taille_piste+1)
189 {
190 currentSector=1;
191 currentTrack++;
192 }
193
194 int nb_sectors_by_files=floppy.WriteFile(fileName.c_str(),currentTrack,currentSector,loadAddress);
195 }
196 else
197 {
198 printf("Syntax error line (%d), syntax is 'AddFile FilePath LoadAddress' \n",lineNumber);
199 }
200 }
201 else
202 if (tokens[0]=="AddDefine")
203 {
204 if (tokens.size()==3)
205 {
206 floppy.AddDefine(tokens[1],tokens[2]);
207 }
208 else
209 {
210 printf("Syntax error line (%d), syntax is 'AddDefine DefineName DefineValue' \n",lineNumber);
211 }
212 }
213 else
214 {
215 printf("Syntax error line (%d), unknown keyword '%s' \n",lineNumber,tokens[0].c_str());
216 exit(1);
217 }
218 }
219 }
220
221
222
223 if (!floppy.SaveDescription(outputLayoutFileName.c_str()))
224 {
225 printf("Failed saving description '%s'\n",outputLayoutFileName.c_str());
226 exit(1);
227 }
228
229 if (!floppy.SaveDisk(dest_name))
230 {
231 printf("Failed saving disk '%s'\n",dest_name);
232 exit(1);
233 }
234 else
235 {
236 printf("Successfully created '%s'\n",dest_name);
237 }
238 }

  ViewVC Help
Powered by ViewVC 1.1.26