Skip to content

Commit 780eeea

Browse files
committed
.EXB core image format.
1 parent bc80ef0 commit 780eeea

File tree

7 files changed

+3791
-1
lines changed

7 files changed

+3791
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CFLAGS = -g -W -Wall
33

44
FILES = sblk-file.o pdump-file.o dmp-file.o raw-file.o shr-file.o \
55
mdl-file.o rim10-file.o fasl-file.o palx-file.o lda-file.o \
6-
cross-file.o hex-file.o atari-file.o iml-file.o
6+
cross-file.o hex-file.o atari-file.o iml-file.o exb-file.o
77

88
WORDS = aa-word.o bin-word.o cadr-word.o core-word.o data8-word.o \
99
dta-word.o its-word.o oct-word.o pt-word.o sail-word.o tape-word.o \

check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ test_dis10 its.rp06 "-mks10_its"
7272
test_dis10 system.dmp "-Fdmp -Woct -mka10sail -Sall"
7373
test_dis10 dired.dmp "-6 -mka10sail -Wascii -Sddt"
7474
test_dis10 two.tapes "-r -Wtape"
75+
test_dis10 boot.exb "-Fexb -Wascii"
7576

7677
test_itsarc arc.code
7778
test_ipak stink.-ipak-

dis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern struct file_format *output_file_format;
6666
extern struct file_format atari_file_format;
6767
extern struct file_format cross_file_format;
6868
extern struct file_format dmp_file_format;
69+
extern struct file_format exb_file_format;
6970
extern struct file_format fasl_file_format;
7071
extern struct file_format hex_file_format;
7172
extern struct file_format iml_file_format;

exb-file.c

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
/* Copyright (C) 2022 Lars Brinkhoff <lars@nocrew.org>
2+
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
15+
16+
/* This file format will read in a paper tape with a hardware read-in
17+
loader. To do this, it will read in the loader and run it by
18+
emulating a tiny subset of PDP-10 instructions. The subset is enough to
19+
support the ITS RIM10 and DEC RIM10B loaders. */
20+
21+
#include <stdio.h>
22+
#include <stdlib.h>
23+
24+
#include "dis.h"
25+
#include "memory.h"
26+
27+
static int
28+
read_8 (FILE *f)
29+
{
30+
static int i = 0;
31+
static word_t word;
32+
33+
if (i == 0)
34+
{
35+
word = get_word (f);
36+
if (word == -1)
37+
return -1;
38+
i = 4;
39+
}
40+
41+
i--;
42+
switch (i)
43+
{
44+
case 0: return (word >> 8) & 0377;
45+
case 1: return (word >> 0) & 0377;
46+
case 2: return (word >> 26) & 0377;
47+
case 3: return (word >> 18) & 0377;
48+
}
49+
50+
return -1;
51+
}
52+
53+
static int
54+
read_16 (FILE *f)
55+
{
56+
int x1, x2;
57+
x1 = read_8 (f);
58+
if (x1 == -1)
59+
return 0;
60+
x2 = read_8 (f);
61+
if (x2 == -1)
62+
x2 = 0;
63+
return x1 | (x2 << 8);
64+
}
65+
66+
static word_t
67+
read_32 (FILE *f)
68+
{
69+
word_t x1, x2;
70+
x1 = read_16 (f);
71+
if (feof (f))
72+
return 0;
73+
x2 = read_16 (f);
74+
if (feof (f))
75+
x2 = 0;
76+
return x1 | (x2 << 16);
77+
}
78+
79+
static word_t
80+
read_36 (FILE *f)
81+
{
82+
word_t x1, x2;
83+
x1 = read_32 (f);
84+
if (feof (f))
85+
return 0;
86+
x2 = read_8 (f);
87+
if (feof (f))
88+
x2 = 0;
89+
return x1 | (x2 << 32);
90+
}
91+
92+
static void
93+
read_exb (FILE *f, struct pdp10_memory *memory, int cpu_model)
94+
{
95+
int i, address, length;
96+
word_t *core;
97+
word_t word;
98+
99+
(void)cpu_model;
100+
101+
fprintf (output_file, "EXB format\n");
102+
103+
for (;;)
104+
{
105+
length = read_16 (f);
106+
address = read_32 (f);
107+
108+
if (feof (f) || length < 4)
109+
{
110+
fprintf (stderr, "Unexpected end of file.\n");
111+
exit (1);
112+
}
113+
114+
if (length == 4)
115+
{
116+
fprintf (output_file, "Start address: %06o\n", address);
117+
start_instruction = JRST + address;
118+
return;
119+
}
120+
121+
length -= 4;
122+
length /= 5;
123+
124+
core = malloc (length * sizeof (word_t));
125+
if (core == NULL)
126+
{
127+
fprintf (stderr, "Out of memory.\n");
128+
exit (1);
129+
}
130+
131+
for (i = 0; i < length; i++)
132+
{
133+
word = read_36 (f);
134+
if (feof (f))
135+
{
136+
fprintf (stderr, "Unexpected end of file.\n");
137+
exit (1);
138+
}
139+
core[i] = word;
140+
}
141+
142+
if (length & 1)
143+
read_8 (f);
144+
145+
add_memory (memory, address, length, core);
146+
}
147+
}
148+
149+
static void
150+
write_8 (FILE *f, int data)
151+
{
152+
static word_t word = 0;
153+
static int i = 0;
154+
155+
data &= 0377;
156+
switch (i)
157+
{
158+
case 0: word |= data << 18; break;
159+
case 1: word |= data << 26; break;
160+
case 2: word |= data << 0; break;
161+
case 3: word |= data << 8; break;
162+
}
163+
164+
i++;
165+
if (i == 4)
166+
{
167+
write_word (f, word);
168+
word = 0;
169+
i = 0;
170+
}
171+
}
172+
173+
static void
174+
write_16 (FILE *f, int data)
175+
{
176+
write_8 (f, data);
177+
write_8 (f, data >> 8);
178+
}
179+
180+
static void
181+
write_32 (FILE *f, int data)
182+
{
183+
write_16 (f, data);
184+
write_16 (f, data >> 16);
185+
}
186+
187+
static void
188+
write_36 (FILE *f, word_t data)
189+
{
190+
write_32 (f, data);
191+
write_8 (f, data >> 32);
192+
}
193+
194+
static void
195+
write_block (FILE *f, struct pdp10_memory *memory, int address, int length)
196+
{
197+
int i;
198+
199+
write_16 (f, 5*length + 4);
200+
write_32 (f, address);
201+
202+
for (i = address; i < address + length; i++)
203+
write_36 (f, get_word_at (memory, i));
204+
205+
if (length & 1)
206+
write_8 (f, 0);
207+
}
208+
209+
static void
210+
write_exb (FILE *f, struct pdp10_memory *memory)
211+
{
212+
int start, length;
213+
int i;
214+
215+
for (i = 0; i < memory->areas; i++)
216+
{
217+
start = memory->area[i].start;
218+
length = memory->area[i].end - start;
219+
write_block (f, memory, start, length);
220+
}
221+
222+
start = start_instruction & 0777777;
223+
if (start)
224+
write_block (f, memory, start, 0);
225+
}
226+
227+
struct file_format exb_file_format = {
228+
"exb",
229+
read_exb,
230+
write_exb
231+
};

file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static struct file_format *file_formats[] = {
2626
&atari_file_format,
2727
&cross_file_format,
2828
&dmp_file_format,
29+
&exb_file_format,
2930
&fasl_file_format,
3031
&hex_file_format,
3132
&iml_file_format,

samples/boot.exb

22.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)