-
Notifications
You must be signed in to change notification settings - Fork 13
/
magfrm.c
211 lines (173 loc) · 4.66 KB
/
magfrm.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* Copyright (C) 2017 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 <string.h>
#include "dis.h"
word_t mthri[] =
{
0777761000000, /* -17,,0 */
0255000000000, /* JFCL */
0541440000004, /* HRRI 11,4 */
0734740000001, /* CONSO 344,1 */
0254000000003, /* JRST 3 */
0241011777776, /* ROT -2(11) */
0734071000010, /* DATAI 340,@10(11) */
0256011000010, /* XCT 10(11) */
0256011000013, /* XCT 13(11) */
0364440000000, /* SOJA 11,0 */
0312000000017, /* CAME 17 */
0270017000000, /* ADD (17) */
0331740000000, /* SKIPL 17,0 */
0254200000015, /* JRST 4,15 */
0253740000003, /* AOBJN 17,3 */
0254000000002 /* JRST 2 */
};
static void (*write_record) (FILE *f, word_t *buffer, int);
word_t buffer[5 * 1024];
static void
write_header (FILE *f, char *name)
{
char *fn1, *fn2;
/* The MAGDMP header is three words of SIXBIT text:
file name 1, file name 2, and version. Use the input
file name split on "." and version 001 for all files. */
fprintf (stderr, "File %s -> ", name);
fn1 = name;
fn2 = strchr (name, '.');
if (fn2)
*fn2++ = 0;
else
{
fn2 = fn1;
fn1 = "@";
}
fprintf (stderr, "%s %s\n", fn1, fn2);
buffer[0] = ascii_to_sixbit (fn1);
buffer[1] = ascii_to_sixbit (fn2);
buffer[2] = ascii_to_sixbit ("001");
write_record (f, buffer, 3);
write_record (f, buffer, 0);
}
static void
write_file (FILE *f, char *name)
{
FILE *in;
int n;
word_t *x = buffer;
in = fopen (name, "rb");
if (in == NULL)
{
fprintf (stderr, "File not found: %s\n", name);
exit (1);
}
n = 0;
/* One record with the file name, and then a tape mark. */
write_header (f, name);
/* Then file data in 1024 word records, terminated by a tape mark. */
for (;;)
{
word_t word = get_word (in);
if (word != -1)
{
*x++ = word;
n++;
}
if (n == 1024 || word == -1)
{
/* If we have a full record, or no more data in the input
file, write a record. */
if (n > 0)
write_record (f, buffer, n);
x = buffer;
n = 0;
}
if (word == -1)
break;
}
/* Tape mark. */
write_record (f, buffer, 0);
}
static void
write_hri (FILE *f, const char *file)
{
FILE *in = fopen (file, "rb");
word_t word, *p;
/* The hardware read-in record starts with an SBLK loader. */
memcpy (buffer, mthri, sizeof mthri);
/* Look for a JRST 1 in the input file. */
p = buffer + sizeof mthri / sizeof (word_t);
for (;;)
{
word = get_word (in);
if (word == JRST_1)
break;
if (word == -1)
exit (1);
}
/* Next copy the file to tape. */
for (;;)
{
word = get_word (in);
if (word == -1)
break;
*p++ = word;
}
write_record (f, buffer, p - buffer);
write_record (f, buffer, 0);
}
static void
seven_tracks (void)
{
write_record = write_7track_record;
}
static void
nine_tracks (void)
{
write_record = write_9track_record;
}
int
main (int argc, char **argv)
{
int i = 1;
input_word_format = &its_word_format;
output_file = stdout;
/* Default to 9-track tape. */
nine_tracks ();
if (argc < 2)
{
fprintf (stderr, "Usage: %s [-7|-9] <magdmp> <files...>\n\n", argv[0]);
fprintf (stderr, "Writes a MAGDMP bootable tape image file in SIMH format.\n");
fprintf (stderr, "The first argument specifies the MAGDMP program.\n");
fprintf (stderr, "The following arguments specify files put on the tape.\n");
fprintf (stderr, "The inputs must be in ITS evacuate format.\n");
fprintf (stderr, "The output is written to stdout.\n");
exit (1);
}
if (strcmp (argv[i], "-7") == 0)
{
seven_tracks();
i++;
}
else if (strcmp (argv[i], "-9") == 0)
{
nine_tracks();
i++;
}
memset (buffer, 0, sizeof buffer);
/* The first tape record is for hardware read-in, ended by a tape
mark. The first 16 words are an SBLK loader, next comes MAGDMP. */
write_hri (stdout, argv[i]);
i++;
for (; i < argc; i++)
write_file (stdout, argv[i]);
return 0;
}