lst2imem.cxx
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <fstream.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
char linebuf[1024];
void usage( void )
{
cerr << "usage: lst2imem listfilename..." << endl;
exit( 1 );
}
int main( int argc, char ** argv )
{
ifstream in;
int words = 0;
unsigned long savedAddr;
char savedValue[12];
if ( argc < 2 )
usage();
--argc;
while ( argc-- )
{
in.open( argv[1] );
if ( in.fail() )
{
cerr << "Can't open " << argv[1] << endl;
++argv; // point to next
continue;
}
while ( in.getline( linebuf, 1024 ) )
{
char *address, *value, *dummy;
if ( !strlen( linebuf ) )
continue;
address = strtok( linebuf, " " );
if ( strncmp( address, "0x", 2 ) )
continue;
dummy = strtok( NULL, " " );
value = strtok( NULL, " " );
if ( words & 1 ) /* write both */
cout << "@" << hex << ((savedAddr / 8) & 0x1ff) << " "
<< savedValue << "_" << &value[2] << endl;
else
{
savedAddr = strtoul( address, NULL, 16 );
strcpy( savedValue, &value[2] );
}
++words;
}
if ( words & 1 ) // got a leftover
cout << "@" << hex << ((savedAddr / 8) & 0x1ff) << " "
<< savedValue << "_" << "00000000" << endl;
in.close();
++argv; // point to next file
}
return 0;
}