Skip to content

Commit fdd0531

Browse files
committed
Support SIMH deposit commands as input.
1 parent e010f9f commit fdd0531

File tree

2 files changed

+109
-2
lines changed

2 files changed

+109
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Most tools that work with executable programs support these formats:
5757
- TOPS-10 highseg sharable .SHR and nonsharable .HGH format.
5858
- TOPS-20 and TOPS-10 sharable save .EXE files.
5959
- TENEX sharable save .SAV files.
60-
- SIMH deposit commands; output only.
60+
- SIMH deposit commands.
6161

6262
In addition, some mini and micro computer program formats are supported:
6363

simh-file.c

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,115 @@ write_simh (FILE *f, struct pdp10_memory *memory)
5757
fprintf (f, ";execute %012llo\n", start_instruction);
5858
}
5959

60+
static int
61+
whitespace(char c)
62+
{
63+
switch (c)
64+
{
65+
case ' ':
66+
case '\t':
67+
case '\r':
68+
case '\n':
69+
return 1;
70+
default:
71+
return 0;
72+
}
73+
}
74+
75+
static int
76+
whitespace_or_nul(char c)
77+
{
78+
return whitespace (c) || c == 0;
79+
}
80+
81+
static void
82+
fatal (char *format, char *line)
83+
{
84+
fprintf (stderr, format, line);
85+
exit (1);
86+
}
87+
88+
static void
89+
deposit (char *line, struct pdp10_memory *memory)
90+
{
91+
char *p;
92+
word_t *data;
93+
unsigned long x, address = strtoul (line, &p, 8);
94+
if (!whitespace (*p))
95+
fatal ("Invalid DEPOSIT arguments: \"%s\"\n", line);
96+
97+
while (whitespace(*p))
98+
p++;
99+
if (*p == 0)
100+
fatal ("Invalid DEPOSIT arguments: \"%s\"\n", line);
101+
102+
data = malloc (sizeof (word_t));
103+
if (data == NULL)
104+
{
105+
fprintf (stderr, "Out of memory\n");
106+
exit (1);
107+
}
108+
x = strtoul (p, &p, 8);
109+
if (!whitespace_or_nul (*p))
110+
fatal ("Invalid DEPOSIT arguments: \"%s\"\n", line);
111+
112+
*data = x;
113+
add_memory (memory, address, 1, data);
114+
}
115+
116+
static void
117+
start (char *line)
118+
{
119+
char *p;
120+
unsigned long address = strtoul (line, &p, 8);
121+
if (p == line || !whitespace_or_nul (*p))
122+
fatal ("Invalid GO argument: \"%s\"\n", line);
123+
start_instruction = JRST | address;
124+
}
125+
126+
static void
127+
read_line (char *line, struct pdp10_memory *memory)
128+
{
129+
char *p = line;
130+
size_t n;
131+
132+
while (whitespace(*p))
133+
p++;
134+
if (*p == 0 || *p == ';' || *p == '#')
135+
return;
136+
line = p++;
137+
while (!whitespace_or_nul(*p))
138+
p++;
139+
if (*p == 0)
140+
fatal ("SIMH command has no argument: %s\n", line);
141+
*p++ = 0;
142+
n = strlen(line);
143+
if (strncasecmp (line, "deposit", n) == 0)
144+
deposit (p, memory);
145+
else if (strncasecmp (line, "go", n) == 0)
146+
start (p);
147+
else
148+
fatal ("Unsupported SIMH command: %s\n", line);
149+
}
150+
151+
static void
152+
read_simh (FILE *f, struct pdp10_memory *memory, int cpu_model)
153+
{
154+
static char line[100];
155+
(void)cpu_model;
156+
157+
fprintf (output_file, ";SIMH script\n\n");
158+
159+
for (;;)
160+
{
161+
if (fgets (line, sizeof line, f) == NULL)
162+
return;
163+
read_line (line, memory);
164+
}
165+
}
166+
60167
struct file_format simh_file_format = {
61168
"simh",
62-
NULL,
169+
read_simh,
63170
write_simh
64171
};

0 commit comments

Comments
 (0)