/[projet1]/public/pc/tools/osdk/main/MemMap/sources/memmap.cpp
Defence Force logotype

Contents of /public/pc/tools/osdk/main/MemMap/sources/memmap.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 70 - (show annotations)
Sun May 24 19:53:20 2009 UTC (10 years, 6 months ago) by dbug
File size: 6655 byte(s)
Added the complete source code of the OSDK.
Projects files are available for Visual Studio 6 and .net, plus a Code::Blocks setup (everything works except PictConv that relies on FreeImage - which does not build correctly on mingw)
1 /*==============================================================================
2
3 MemMap
4
5 ==[Description]=================================================================
6
7 Generate an html file representing the memory map of provided files.
8
9 ==[History]=====================================================================
10
11 ==[ToDo]========================================================================
12
13 ==============================================================================*/
14
15 #pragma warning( disable : 4706)
16 #pragma warning( disable : 4786)
17
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <memory.h>
22 #include <io.h>
23 #include <fcntl.h>
24 #include <sys/stat.h>
25
26 #include <string>
27 #include <map>
28
29 #include "infos.h"
30
31 #include "common.h"
32
33
34 const char gHtmlHeader[]=
35 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\r\n"
36 "<HTML lang=fr dir=ltr>\r\n"
37 " <HEAD>\r\n"
38 " <meta name=\"robots\" content=\"noindex\">\r\n"
39 " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\">\r\n"
40 " <title>{PageTitle}</title>\r\n"
41 " <link href=\"{CssLink}\" rel=\"stylesheet\" type=\"text/css\">\r\n"
42 " </HEAD>\r\n"
43 " <BODY>\r\n";
44
45
46 const char gHtmlFooter[]=
47 " </BODY>\r\n"
48 "</HTML>\r\n";
49
50
51
52
53 class Section
54 {
55 public:
56 Section() :
57 m_adress_size(4),
58 m_begin_adress(0),
59 m_end_adress(65535)
60 {
61 }
62
63 void Generate(std::string &ref_html);
64
65 std::map<int,std::string> &GetMap()
66 {
67 return m_map_data;
68 }
69
70 public:
71 std::string m_anchor_name;
72 std::string m_section_name;
73 int m_adress_size;
74 int m_begin_adress;
75 int m_end_adress;
76
77 std::map<int,std::string> m_map_data;
78 };
79
80
81 void Section::Generate(std::string &html)
82 {
83 html+="<a name=\""+m_anchor_name+"\"></a>\r\n";
84
85 html+="<h1>"+m_section_name+"</h1>\r\n";
86
87 html+="<table border>\r\n";
88 html+="<tr>\r\n";
89 html+="<th>Adress</th><th>Size</th><th>Name</th>\r\n";
90 html+="</tr>\r\n";
91
92 std::map<int,std::string>::iterator it=m_map_data.begin();
93 while (it!=m_map_data.end())
94 {
95 int value =(*it).first;
96 const std::string& name=(*it).second;
97 ++it;
98
99 char buffer_adress[512];
100 if (value&255)
101 {
102 sprintf(buffer_adress,"$%02x",value);
103 }
104 else
105 {
106 sprintf(buffer_adress,"<b>$%02x</b>",value);
107 }
108
109 char buffer_size[512];
110 if (it!=m_map_data.end())
111 {
112 sprintf(buffer_size,"%d",(*it).first-value);
113 }
114 else
115 {
116 sprintf(buffer_size,"%d",m_end_adress-value);
117 //sprintf(buffer_size,"???");
118 }
119
120 html+="<tr>\r\n";
121 html+=(std::string)"<td>"+buffer_adress+"</td><td>"+buffer_size+"</td><td>"+name+"</td>";
122 html+="</tr>\r\n";
123 }
124 html+="</table>\r\n";
125 }
126
127
128
129
130
131 #define NB_ARG 4
132
133 int main(int argc,char *argv[])
134 {
135 //
136 // Some initialization for the common library
137 //
138 SetApplicationParameters(
139 "MemMap",
140 TOOL_VERSION_MAJOR,
141 TOOL_VERSION_MINOR,
142 "{ApplicationName} - Version {ApplicationVersion} - This program is a part of the OSDK\r\n"
143 "\r\n"
144 "Author:\r\n"
145 " Pointier Mickael\r\n"
146 "\r\n"
147 );
148
149
150 ArgumentParser cArgumentParser(argc,argv);
151
152 while (cArgumentParser.ProcessNextArgument())
153 {
154 }
155
156
157 if (cArgumentParser.GetParameterCount()!=NB_ARG)
158 {
159 ShowError(0);
160 }
161
162
163 //
164 // Copy last parameters
165 //
166 std::string source_name(cArgumentParser.GetParameter(0));
167 std::string dest_name(cArgumentParser.GetParameter(1));
168 std::string project_name(cArgumentParser.GetParameter(2));
169 std::string css_name(cArgumentParser.GetParameter(3));
170
171 /*
172 printf("\n0=%s\n",source_name.c_str());
173 printf("\n1=%s\n",dest_name.c_str());
174 printf("\n2=%s\n",project_name.c_str());
175 printf("\n3=%s\n",css_name.c_str());
176 */
177
178 void* ptr_buffer_void;
179 size_t size_buffer_src;
180
181 //
182 // Load the file
183 //
184 if (!LoadFile(source_name.c_str(),ptr_buffer_void,size_buffer_src))
185 {
186 printf("\nUnable to load file '%s'",source_name.c_str());
187 printf("\n");
188 exit(1);
189 }
190
191 unsigned char *ptr_buffer=(unsigned char*)ptr_buffer_void;
192
193 //
194 // Parse the file, and generate the list of values
195 //
196 Section section_zeropage;
197
198 section_zeropage.m_anchor_name ="Zero";
199 section_zeropage.m_section_name ="Zero page";
200 section_zeropage.m_adress_size =2;
201 section_zeropage.m_begin_adress =0x0;
202 section_zeropage.m_end_adress =0xFF;
203
204 Section section_normal;
205 section_normal.m_anchor_name ="Normal";
206 section_normal.m_section_name ="Normal memory";
207 section_normal.m_adress_size =4;
208 section_normal.m_begin_adress =0x400;
209 section_normal.m_end_adress =0xBFFF;
210
211 Section section_overlay;
212 section_overlay.m_anchor_name ="Overlay";
213 section_overlay.m_section_name ="Overlay memory";
214 section_overlay.m_adress_size =4;
215 section_overlay.m_begin_adress =0xC000;
216 section_overlay.m_end_adress =0xFFFF;
217
218 char *ptr_tok=strtok((char*)ptr_buffer," \r\n");
219 while (ptr_tok)
220 {
221 // Address
222 int value=strtol(ptr_tok,0,16);
223 ptr_tok=strtok(0," \r\n");
224
225 // Name
226 if (value<256)
227 {
228 // Zero page
229 section_zeropage.GetMap()[value]=ptr_tok;
230 }
231 else
232 if (value>=0xc000)
233 {
234 // Overlay memory
235 section_overlay.GetMap()[value]=ptr_tok;
236 }
237 else
238 {
239 section_normal.GetMap()[value]=ptr_tok;
240 }
241 ptr_tok=strtok(0," \r\n");
242 }
243
244
245 //
246 // Generate the html file
247 //
248 std::string html(gHtmlHeader);
249
250 StringReplace(html,"{PageTitle}" ,project_name);
251 StringReplace(html,"{CssLink}" ,css_name);
252
253 /*
254 html+="<A href=\"#Zero\">Zero page</A><br>";
255 html+="<A href=\"#Normal\">Normal memory</A><br>";
256 html+="<A href=\"#Overlay\">Overlay memory</A><br>";
257 */
258
259 html+="<table>\r\n";
260 html+="<tr>\r\n";
261
262 html+="<td valign=top>\r\n";
263 section_zeropage.Generate(html);
264 html+="</td>\r\n";
265
266 html+="<td valign=top>\r\n";
267 section_normal.Generate(html);
268 html+="</td>\r\n";
269
270 html+="<td valign=top>\r\n";
271 section_overlay.Generate(html);
272 html+="</td>\r\n";
273
274 html+="</tr>\r\n";
275 html+="</table>\r\n";
276
277 html=html+gHtmlFooter;
278
279 unsigned char *ptr_buffer_dst=new unsigned char[size_buffer_src+8];
280 int size_buffer_dst=size_buffer_src/2;
281
282 unsigned char *ptr_src=ptr_buffer;
283 unsigned char *ptr_dst=ptr_buffer_dst;
284 int i;
285 for (i=0;i<size_buffer_dst;i++)
286 {
287 unsigned char b0=*ptr_src++;
288 unsigned char b1=*ptr_src++;
289 unsigned char b=(b1&0xF0)|(b0>>4);
290 *ptr_dst++=b;
291 }
292
293 if (!SaveFile(dest_name.c_str(),html.c_str(),html.size()))
294 {
295 printf("\nUnable to save file '%s'",source_name.c_str());
296 printf("\n");
297 exit(1);
298 }
299
300 //
301 // Make some cleaning
302 //
303 delete[] ptr_buffer;
304 delete[] ptr_buffer_dst;
305
306 return 0;
307 }
308
309

  ViewVC Help
Powered by ViewVC 1.1.26