summaryrefslogtreecommitdiff
path: root/other/Kermit/src/writesym.cpp
blob: 13d521e71d5ec5319f786c6afc670bc05b6f69b9 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * readsym.cpp:
 * written by palmers / teso
 */
#include <Kermit>
#include <iostream>
#include <fstream>

#define PROGRAM	"writesym"
#define VERSION	"0.1"
#define AUTHOR	"palmers / teso"


void
usage (char *a)
{
  cout << PROGRAM << VERSION << " by " << AUTHOR << endl;
  cout << endl;
  cout << "Usage: " << a << " [options] <d|p> <offset> <length>" << endl;
  cout << "Options:" << endl;
  cout << "\t-x:\t where x is 1, 2, 3: ... " << endl;
  cout << endl;
  exit (0);
}


int
main (int argc, char **argv)
{
  rwKernel		*rw = NULL;
  char			*inBuf = NULL;
  unsigned long		y = 0,
			length = 0,
			out_offset = 0,
			offset = CONF_1GB;
  int			x = 0;

  if (argc < 4)
    usage (argv[0]);

  while (x < argc)
    {
      if (argv[x][0] == '-')
	{
	  switch (argv[x][1])
	    {
            case '1':
              offset = CONF_1GB;
              break;
            case '2':
              offset = CONF_2GB;
              break;
            case '3':
              offset = CONF_3GB;
              break;
	    case 'h':
	      usage (argv[0]);
	      break;
	    default:
	      usage (argv[0]);
	      break;
	    }
	}
      x++;
    }

  if (argv[argc - 3][0] == 'd')
    rw = new rwKernel (DEVMEM, offset);
  else if (argv[argc - 3][0] == 'p')
    rw = new rwKernel (PROCKCORE, offset);

  out_offset = stoi16 (string (argv[argc - 2]));
  length = stoi16 (string (argv[argc - 1]));

  if (length == 0)
    {
      cerr << "HaHa" << endl;
      abort ();
    }

  inBuf = new char[length + 1];

  cin.setf (ios::hex, ios::basefield);
  while (!cin.eof ())
    {
      cin >> x;
      if (y < length)
	inBuf[y++] = (x & 0xff);
    }
  cin.setf (ios::dec, ios::basefield);

  rw->write (inBuf, length, out_offset);
  delete inBuf;
  return 0;
}