Skip to content

Commit bdc783d

Browse files
committed
Output memory image as PDP-11 ODT commands.
1 parent fdd0531 commit bdc783d

File tree

8 files changed

+11077
-1
lines changed

8 files changed

+11077
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CFLAGS = -g -W -Wall -Ilibword
44
FILES = sblk-file.o pdump-file.o dmp-file.o raw-file.o exe-file.o \
55
mdl-file.o rim10-file.o fasl-file.o palx-file.o lda-file.o \
66
cross-file.o hex-file.o atari-file.o iml-file.o exb-file.o \
7-
tenex-file.o csave-file.o hiseg-file.o simh-file.o
7+
tenex-file.o csave-file.o hiseg-file.o simh-file.o odt-file.o
88

99
LIBWORD = libword/libword.a
1010

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ In addition, some mini and micro computer program formats are supported:
6363

6464
- PDP-11 PALX binaries.
6565
- PDP-11 absolute loader tapes.
66+
- ODT deposit commands.
6667
- CROSS binaries.
6768
- CROSS "ASCII HEX" files.
6869
- Atari DOS executables.

check.sh

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ test_dump ts.srccom "-Wits -Opdump"
100100
test_dump l.bin "-Fpalx -Xoct -Oraw"
101101
test_dump logo.ptp "-Fhex -Xoct -Oraw"
102102
test_dump supdup.bin "-Wits -Fcross -Xoct -Oraw"
103+
test_dump nswit.bin "-Fpalx -Oodt"
103104

104105
test_linum -a linum-1.txt
105106
test_linum -df linum-1.txt

dis.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern struct file_format iml_file_format;
6262
extern struct file_format lda_file_format;
6363
extern struct file_format mdl_file_format;
6464
extern struct file_format nsave_file_format;
65+
extern struct file_format odt_file_format;
6566
extern struct file_format osave_file_format;
6667
extern struct file_format palx_file_format;
6768
extern struct file_format pdump_file_format;

file.c

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static struct file_format *file_formats[] = {
3636
&lda_file_format,
3737
&mdl_file_format,
3838
&nsave_file_format,
39+
&odt_file_format,
3940
&osave_file_format,
4041
&palx_file_format,
4142
&pdump_file_format,

odt-file.c

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/* Copyright (C) 2025 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+
/*
17+
File format to output ODT deposit commands.
18+
19+
Converts a core image to a series of ODT deposit commands. If there
20+
is a start address, there will also be a G command at the end.
21+
*/
22+
23+
#include <stdio.h>
24+
#include <stdlib.h>
25+
#include <string.h>
26+
27+
#include "dis.h"
28+
#include "memory.h"
29+
30+
#define LF 012
31+
#define CR 015
32+
#define MASK 0177777
33+
#define NO_ADDRESS -2
34+
static int previous_address;
35+
36+
static int quantity, address;
37+
38+
static void
39+
write_location (FILE *f, struct pdp10_memory *memory, int address)
40+
{
41+
word_t data = get_word_at (memory, address);
42+
if (data < 0)
43+
return;
44+
45+
/* First, close the previous location (if there was one). If this
46+
location follows the previous, close with "^J" to open the next
47+
location. Otherwise, close with "^M" and open a new location with
48+
"/". Then enter one word of data, and leave the location open. */
49+
50+
data &= MASK;
51+
if (address == previous_address + 1)
52+
fputc (LF, f);
53+
else if (previous_address != NO_ADDRESS)
54+
fputc (CR, f);
55+
if (address != previous_address + 1)
56+
fprintf (f, "%06o/", address);
57+
fprintf (f, "%06llo", data);
58+
previous_address = address;
59+
}
60+
61+
static void
62+
write_odt (FILE *f, struct pdp10_memory *memory)
63+
{
64+
int i;
65+
66+
previous_address = NO_ADDRESS;
67+
68+
/* Memory contents, as deposit commands. */
69+
for (i = 0; i <= MASK; i++)
70+
write_location (f, memory, i);
71+
72+
/* Make sure to close last location. */
73+
if (previous_address != NO_ADDRESS)
74+
fputc (CR, f);
75+
76+
/* Start. */
77+
if (start_instruction > 0)
78+
fprintf (f, "%06lloG", start_instruction & MASK);
79+
}
80+
81+
static void
82+
deposit (struct pdp10_memory *memory)
83+
{
84+
word_t *data = malloc (sizeof (word_t));
85+
if (data == NULL)
86+
{
87+
fprintf (stderr, "Out of memory\n");
88+
exit (1);
89+
}
90+
*data = quantity;
91+
add_memory (memory, address, 1, data);
92+
}
93+
94+
static void
95+
read_char (char c, struct pdp10_memory *memory)
96+
{
97+
switch (c)
98+
{
99+
case '0': case '1': case '2': case '3':
100+
case '4': case '5': case '6': case '7':
101+
if (quantity < 0)
102+
quantity = 0;
103+
quantity *= 010;
104+
quantity += c - '0';
105+
break;
106+
case LF:
107+
case CR:
108+
if (address == -1)
109+
break;
110+
if (quantity < 0)
111+
quantity = -quantity;
112+
deposit (memory);
113+
quantity = 0;
114+
if (c == LF)
115+
address++;
116+
else
117+
address = -1;
118+
break;
119+
case '/':
120+
address = quantity;
121+
quantity = get_word_at (memory, address);
122+
if (quantity == -1)
123+
quantity = 0;
124+
else
125+
quantity = -quantity;
126+
break;
127+
case 'G':
128+
start_instruction = quantity;
129+
quantity = 0;
130+
break;
131+
}
132+
}
133+
134+
static void
135+
read_odt (FILE *f, struct pdp10_memory *memory, int cpu_model)
136+
{
137+
(void)cpu_model;
138+
139+
fprintf (output_file, ";ODT commands\n\n");
140+
141+
quantity = 0;
142+
address = -1;
143+
144+
for (;;)
145+
{
146+
int c = fgetc (f);
147+
if (c == EOF)
148+
return;
149+
read_char (c, memory);
150+
}
151+
}
152+
153+
struct file_format odt_file_format = {
154+
"odt",
155+
read_odt,
156+
write_odt
157+
};

samples/nswit.bin

69.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)