-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.c
138 lines (119 loc) · 3.07 KB
/
main.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Copyright (C) 2013 Lars Brinkhoff <lars@nocrew.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "dis.h"
#include "opcode/pdp10.h"
#include "memory.h"
static void
tape_special (int code)
{
switch ((code >> 24) & 0xFF)
{
case 0x80:
fprintf (output_file, "Tape error %06x.\n", code & 0xFFFFFF);
break;
case 0xFF:
fprintf (output_file, "Tape gap (%06x).\n", code & 0xFFFFFF);
break;
default:
fprintf (output_file, "Tape special (%08x).\n", code);
break;
}
}
static void
usage (char **argv)
{
fprintf (stderr, "Usage: %s [-6] [-r] [-F<file format>] [-S<symbol mode>] [-W<word format>] [-D<DDT address>] <file>\n\n", argv[0]);
usage_file_format ();
usage_word_format ();
usage_symbols_mode ();
usage_machine ();
exit (1);
}
int
main (int argc, char **argv)
{
int cpu_model = PDP10_KA10_ITS;
struct pdp10_memory memory;
FILE *file;
word_t word, data;
int opt;
int ddt = 0;
int extra;
output_file = stdout;
while ((opt = getopt (argc, argv, "6rF:S:W:m:D:")) != -1)
{
switch (opt)
{
case '6':
input_file_format = &dmp_file_format;
break;
case 'r':
input_file_format = &raw_file_format;
break;
case 'F':
if (parse_input_file_format (optarg))
usage (argv);
break;
case 'm':
if (parse_machine (optarg, &cpu_model))
usage (argv);
break;
case 'S':
if (parse_symbols_mode (optarg))
usage (argv);
break;
case 'W':
if (parse_input_word_format (optarg))
usage (argv);
break;
case 'D':
ddt = strtol (optarg, NULL, 8);
break;
default:
usage (argv);
}
}
if (optind != argc - 1)
usage (argv);
file = fopen (argv[optind], "rb");
if (file == NULL)
{
fprintf (stderr, "%s: Error opening %s: %s\n",
argv[0], argv[optind], strerror (errno));
return 1;
}
init_memory (&memory);
tape_hook = tape_special;
if (!input_file_format)
guess_input_file_format (file);
input_file_format->read (file, &memory, cpu_model);
extra = 0;
while ((word = get_word (file)) != -1)
{
data = word;
extra++;
}
if (extra == 1)
printf ("(After parsed data, there was one more word: %012llo)\n",
data);
else if (extra > 1)
printf ("(After parsed data, there were %d more words.)\n", extra);
if (ddt)
ntsddt_info (&memory, ddt);
printf ("\nDisassembly:\n\n");
dis (&memory, cpu_model);
return 0;
}