Skip to content

Commit 7adc8c1

Browse files
committed
Implement writing for SBLK and RIM10 file formats.
1 parent d87b07d commit 7adc8c1

File tree

4 files changed

+138
-4
lines changed

4 files changed

+138
-4
lines changed

dis.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ extern void read_raw_at (FILE *f, struct pdp10_memory *memory,
111111
int address);
112112
extern void write_raw_at (FILE *f, struct pdp10_memory *memory,
113113
int address);
114+
extern void write_sblk_core (FILE *f, struct pdp10_memory *memory);
115+
extern void write_sblk_symbols (FILE *f);
114116
extern void sblk_info (FILE *f, word_t word0, int cpu_model);
115117
extern void dmp_info (struct pdp10_memory *memory, int cpu_model);
116118
extern void dec_info (struct pdp10_memory *memory,
@@ -124,7 +126,7 @@ extern int parse_machine (const char *string, int *machine);
124126
extern void dis (struct pdp10_memory *memory, int cpu_model);
125127
extern void disassemble_word (struct pdp10_memory *memory, word_t word,
126128
int address, int cpu_model);
127-
extern word_t ascii_to_sixbit (char *ascii);
129+
extern word_t ascii_to_sixbit (const char *ascii);
128130
extern void sixbit_to_ascii (word_t sixbit, char *ascii);
129131
extern void squoze_to_ascii (word_t squoze, char *ascii);
130132
extern void print_date (FILE *, word_t t);

info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
word_t start_instruction;
3838

3939
word_t
40-
ascii_to_sixbit (char *ascii)
40+
ascii_to_sixbit (const char *ascii)
4141
{
4242
int i;
4343
char c;

rim10-file.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@
3838
#define OP_CONO_PTR 071060
3939
#define OP_DATAI_PTR 071044
4040

41+
static word_t midas_rim10[] =
42+
{
43+
/*00*/ 0777761000000LL, /* -17,,0 */
44+
/*01*/ 0710600000060LL, /* CONO PTR,60 */
45+
/*02*/ 0541440000004LL, /* HRRI 11,4 */
46+
/*03*/ 0710740000010LL, /* CONSO PTR,10 */
47+
/*04*/ 0254000000003LL, /* JRST 3 */
48+
/*05*/ 0241011777776LL, /* ROT 0,-2(11) */
49+
/*06*/ 0710471000010LL, /* DATAI PTR,@10(11) */
50+
/*07*/ 0256011000010LL, /* XCT 10(11) */
51+
/*10*/ 0256011000013LL, /* XCT 13(11) */
52+
/*11*/ 0364440000000LL, /* SOJA 11,0 */
53+
/*12*/ 0312000000017LL, /* CAME 0,17 */
54+
/*13*/ 0270017000000LL, /* ADD 0,(17) */
55+
/*14*/ 0331740000000LL, /* SKIPL 17,0 */
56+
/*15*/ 0254200000001LL, /* JRST 4,1 */
57+
/*16*/ 0253740000003LL, /* AOBJN 17,3 */
58+
/*17*/ 0254000000002LL /* JRST 2 */
59+
};
60+
4161
static int
4262
effective_address (word_t insn, struct pdp10_memory *memory)
4363
{
@@ -235,8 +255,20 @@ read_rim10 (FILE *f, struct pdp10_memory *memory, int cpu_model)
235255
printf ("Start address: %o\n", address);
236256
}
237257

258+
static void
259+
write_rim10 (FILE *f, struct pdp10_memory *memory)
260+
{
261+
int i;
262+
263+
for (i = 0; i < sizeof midas_rim10 / sizeof midas_rim10[0]; i++)
264+
write_word (f, midas_rim10[i]);
265+
266+
write_sblk_core (f, memory);
267+
write_word (f, start_instruction);
268+
}
269+
238270
struct file_format rim10_file_format = {
239271
"rim10",
240272
read_rim10,
241-
NULL
273+
write_rim10
242274
};

sblk-file.c

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
#include "dis.h"
2020
#include "memory.h"
21+
#include "symbols.h"
22+
23+
#define SYHKL 0400000000000
24+
#define SYKIL 0200000000000
25+
#define SYLCL 0100000000000
26+
#define SYGBL 0040000000000
2127

2228
static void
2329
read_sblk (FILE *f, struct pdp10_memory *memory, int cpu_model)
@@ -74,8 +80,102 @@ read_sblk (FILE *f, struct pdp10_memory *memory, int cpu_model)
7480
sblk_info (f, word, cpu_model);
7581
}
7682

83+
static void
84+
write_block (FILE *f, struct pdp10_memory *memory, int start, int end)
85+
{
86+
word_t word, cksum;
87+
int i, length;
88+
89+
length = end - start;
90+
word = -length << 18;
91+
word |= start;
92+
word &= WORDMASK;
93+
write_word (f, word);
94+
95+
cksum = word;
96+
for (i = start; i < end; i++)
97+
{
98+
cksum = (cksum << 1) | (cksum >> 35);
99+
word = get_word_at (memory, i);
100+
cksum += word;
101+
cksum &= WORDMASK;
102+
write_word (f, word);
103+
}
104+
105+
write_word (f, cksum);
106+
}
107+
108+
void
109+
write_sblk_core (FILE *f, struct pdp10_memory *memory)
110+
{
111+
int start, length;
112+
int i, n;
113+
114+
for (i = 0; i < memory->areas; i++)
115+
{
116+
start = memory->area[i].start;
117+
length = memory->area[i].end - start;
118+
while (length > 0)
119+
{
120+
n = length > 512 ? 512 : length;
121+
write_block (f, memory, start, start + n);
122+
start += n;
123+
length -= n;
124+
}
125+
}
126+
}
127+
128+
void
129+
write_sblk_symbols (FILE *f)
130+
{
131+
word_t word, cksum;
132+
int i, length;
133+
134+
length = 2 * num_symbols;
135+
word = length;
136+
word = (-word) << 18;
137+
word &= WORDMASK;
138+
write_word (f, word);
139+
140+
cksum = word;
141+
for (i = 0; i < num_symbols; i++)
142+
{
143+
cksum = (cksum << 1) | (cksum >> 35);
144+
word = ascii_to_sixbit (symbols[i].name);
145+
if (symbols[i].flags & SYMBOL_KILLED)
146+
word |= SYKIL;
147+
if (symbols[i].flags & SYMBOL_HALFKILLED)
148+
word |= SYHKL;
149+
if (symbols[i].flags & SYMBOL_GLOBAL)
150+
word |= SYGBL;
151+
else
152+
word |= SYLCL;
153+
cksum += word;
154+
cksum &= WORDMASK;
155+
write_word (f, word);
156+
157+
cksum = (cksum << 1) | (cksum >> 35);
158+
word = symbols[i].value;
159+
cksum += word;
160+
cksum &= WORDMASK;
161+
write_word (f, word);
162+
}
163+
164+
write_word (f, cksum);
165+
}
166+
167+
static void
168+
write_sblk (FILE *f, struct pdp10_memory *memory)
169+
{
170+
write_word (f, JRST_1);
171+
write_sblk_core (f, memory);
172+
write_word (f, start_instruction);
173+
write_sblk_symbols (f);
174+
write_word (f, start_instruction);
175+
}
176+
77177
struct file_format sblk_file_format = {
78178
"sblk",
79179
read_sblk,
80-
NULL
180+
write_sblk
81181
};

0 commit comments

Comments
 (0)