diff options
Diffstat (limited to 'other/Kermit/src/readsym.cpp')
| -rw-r--r-- | other/Kermit/src/readsym.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/other/Kermit/src/readsym.cpp b/other/Kermit/src/readsym.cpp new file mode 100644 index 0000000..541d594 --- /dev/null +++ b/other/Kermit/src/readsym.cpp | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | /* | ||
| 2 | * readsym.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <Kermit> | ||
| 6 | #include <iostream> | ||
| 7 | #include <fstream> | ||
| 8 | |||
| 9 | #define PROGRAM "readsym" | ||
| 10 | #define VERSION "0.1" | ||
| 11 | #define AUTHOR "palmers / teso" | ||
| 12 | |||
| 13 | |||
| 14 | void dump_c_array (char *arr, char *b, int x) | ||
| 15 | { | ||
| 16 | int y; | ||
| 17 | cout.setf (ios::hex, ios::basefield); | ||
| 18 | cout << "char " << arr << "[] = {" << endl; | ||
| 19 | for (y = 0; y < x; y++) | ||
| 20 | { | ||
| 21 | cout << "0x" << ((int) b[y] & 0xff); | ||
| 22 | if (y != (x - 1)) | ||
| 23 | cout << ", "; | ||
| 24 | if (!(y % 10)) | ||
| 25 | cout << endl; | ||
| 26 | } | ||
| 27 | cout << endl << "};" << endl; | ||
| 28 | cout.setf (ios::dec, ios::basefield); | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | void dump (char *a, int x) | ||
| 33 | { | ||
| 34 | int y; | ||
| 35 | cout.setf (ios::hex, ios::basefield); | ||
| 36 | |||
| 37 | for (y = 0; y < x; y++) | ||
| 38 | { | ||
| 39 | if ((a[y] & 0xff) < 16) | ||
| 40 | cout << '0'; | ||
| 41 | cout << ((int) a[y] & 0xff) << ' '; | ||
| 42 | } | ||
| 43 | cout.setf (ios::dec, ios::basefield); | ||
| 44 | cout << endl; | ||
| 45 | } | ||
| 46 | |||
| 47 | void usage (char *a) | ||
| 48 | { | ||
| 49 | cout << PROGRAM << VERSION << " by " << AUTHOR << endl; | ||
| 50 | cout << endl; | ||
| 51 | cout << "Usage: " << a << " [options] <d|p> <offset> <length>" << endl; | ||
| 52 | cout << "Options:" << endl; | ||
| 53 | cout << "\t-x:\t where x is 1, 2, 3: the amount of ram in GB the system is ought to run" << endl; | ||
| 54 | cout << "\t-c <name>:\t dump the read data as a c array" << endl; | ||
| 55 | cout << endl; | ||
| 56 | exit (0); | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | int main (int argc, char **argv) | ||
| 61 | { | ||
| 62 | rwKernel *rw = NULL; | ||
| 63 | char *inBuf = NULL, | ||
| 64 | *arr_name = NULL; | ||
| 65 | unsigned long length = 0, | ||
| 66 | offset = CONF_1GB; | ||
| 67 | int x = 0; | ||
| 68 | |||
| 69 | if (argc < 4) | ||
| 70 | usage (argv[0]); | ||
| 71 | |||
| 72 | while (x < argc) | ||
| 73 | { | ||
| 74 | if (argv[x][0] == '-') | ||
| 75 | { | ||
| 76 | switch (argv[x][1]) | ||
| 77 | { | ||
| 78 | case '1': | ||
| 79 | offset = CONF_1GB; | ||
| 80 | break; | ||
| 81 | case '2': | ||
| 82 | offset = CONF_2GB; | ||
| 83 | break; | ||
| 84 | case '3': | ||
| 85 | offset = CONF_3GB; | ||
| 86 | break; | ||
| 87 | case 'c': | ||
| 88 | arr_name = argv[x + 1]; | ||
| 89 | x++; | ||
| 90 | break; | ||
| 91 | case 'h': | ||
| 92 | usage (argv[0]); | ||
| 93 | break; | ||
| 94 | default: | ||
| 95 | usage (argv[0]); | ||
| 96 | break; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | x++; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (argv[argc - 3][0] == 'd') | ||
| 103 | rw = new rwKernel (DEVMEM, offset); | ||
| 104 | else if (argv[argc - 3][0] == 'p') | ||
| 105 | rw = new rwKernel (PROCKCORE, offset); | ||
| 106 | |||
| 107 | offset = stoi16 (string (argv[argc - 2])); | ||
| 108 | length = stoi16 (string (argv[argc - 1])); | ||
| 109 | |||
| 110 | inBuf = new char[length + 1]; | ||
| 111 | rw->read (inBuf, length, offset); | ||
| 112 | |||
| 113 | if (arr_name != NULL) | ||
| 114 | { | ||
| 115 | dump_c_array (arr_name, inBuf, length); | ||
| 116 | delete inBuf; | ||
| 117 | exit (0); | ||
| 118 | } | ||
| 119 | |||
| 120 | dump (inBuf, length); | ||
| 121 | delete inBuf; | ||
| 122 | return 0; | ||
| 123 | } | ||
