-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcsave-file.c
116 lines (95 loc) · 2.59 KB
/
csave-file.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
/* Copyright (C) 2022 Lars Brinkhoff <[email protected]>
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 <stdlib.h>
#include "dis.h"
#include "memory.h"
#include "symbols.h"
static void
read_csave (FILE *f, struct pdp10_memory *memory, int cpu_model)
{
int address, length;
word_t word;
int i;
fprintf (output_file, "Nonsharable/compressed SAVE format\n");
while ((word = get_word (f)) & SIGNBIT)
{
word_t *data, *ptr;
length = 01000000 - ((word >> 18) & 0777777);
address = (word & 0777777) + 1;
data = malloc (length * sizeof (word_t));
if (data == NULL)
{
fprintf (stderr, "out of memory\n");
exit (1);
}
ptr = data;
for (i = 0; i < length; i++)
*ptr++ = get_word (f);
add_memory (memory, address, length, data);
}
length = (word >> 18) & 0777777;
address = word & 0777777;
fprintf (output_file, "\n");
dec_info (memory, length, address, cpu_model);
}
void
write_dec_symbols (struct pdp10_memory *memory)
{
}
static void
write_block (FILE *f, struct pdp10_memory *memory, int address, int length)
{
word_t word;
word = -length << 18;
word |= address - 1;
word &= WORDMASK;
write_word (f, word);
while (length-- > 0)
write_word (f, get_word_at (memory, address++));
}
static void
write_core (FILE *f, struct pdp10_memory *memory)
{
int start, length;
int i, n;
for (i = 0; i < memory->areas; i++)
{
start = memory->area[i].start;
length = memory->area[i].end - start;
while (length > 0)
{
n = length > 512 ? 512 : length;
write_block (f, memory, start, n);
start += n;
length -= n;
}
}
}
static void
write_csave (FILE *f, struct pdp10_memory *memory)
{
write_dec_symbols (memory);
write_core (f, memory);
write_word (f, JRST + (start_instruction & 0777777));
}
struct file_format csave_file_format = {
"csave",
read_csave,
write_csave
};
/* Alias for csave. */
struct file_format osave_file_format = {
"osave",
read_csave,
write_csave
};