-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsat_batches.c
More file actions
310 lines (270 loc) · 9.64 KB
/
sat_batches.c
File metadata and controls
310 lines (270 loc) · 9.64 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include "sat_batches.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cap.h"
#include "transcode.h"
enum sat_source_op {
SAT_SRC_AS_IS = 0,
SAT_SRC_TRIM_TITLE_SUMMARY,
SAT_SRC_SERIAL_LOADER_PLUS_BODY,
};
struct sat_source {
const char *file;
enum sat_source_op op;
};
struct sat_batch_def {
struct sat_batch_info info;
const struct sat_source *sources;
int nsources;
uint16_t image_entry;
};
struct sat_image_patch {
uint16_t addr;
uint8_t value;
};
static const struct sat_source src_cpu_functional[] = {
{ "funktionalcpu.cap", SAT_SRC_AS_IS },
};
static const struct sat_source src_reader_a[] = {
{ "reading-test-chain-01a.cap", SAT_SRC_AS_IS },
};
static const struct sat_source src_printer_mech[] = {
{ "printermechanicaltest.cap", SAT_SRC_AS_IS },
};
/* Printer Mechanic Test startup: the deck issues PER 0x00,0x0126, whose order
* block is {00,40,00,4F,06,70} — a 79-byte "read unchanged" into 0x0670.
* In the real SAT stack that record comes from the required center card. The
* current scatter-image path has no physical center card, so synthesize the
* default raw reader bytes the diagnostic expects:
* col1 integrated, col2 no 2nd transport, col4 normal drum, col5 normal
* ribbon, col6 WITH END OF TEST HLT. The remaining bytes are left zero.
*
* Confidence:
* - 0x0673 / 0x0674 are directly tested by the deck as 0x01 (normal drum /
* ribbon path).
* - 0x0675 follows the manual's center-card column 6. Under the raw-reader
* low-byte model, a 9-punch collapses to 0x00, so WITH END OF TEST HLT is
* represented here as 0x00.
* - columns not yet evidenced by the code remain zero until more manual
* evidence is recovered. */
static const struct sat_image_patch printer_mech_center_card[] = {
{ 0x0670, 0x01 }, /* column 1: integrated subsystem */
{ 0x0671, 0x01 }, /* column 2: 2nd transport absent */
{ 0x0673, 0x01 }, /* column 4: normal drum */
{ 0x0674, 0x01 }, /* column 5: normal ribbon */
{ 0x0675, 0x00 }, /* column 6: with END OF TEST HLT */
};
static const struct sat_source src_control_program[] = {
{ "control-program-cr.cap", SAT_SRC_SERIAL_LOADER_PLUS_BODY },
};
static const struct sat_source src_ls600_controller[] = {
{ "sat-ls600.cap", SAT_SRC_SERIAL_LOADER_PLUS_BODY },
{ "ls600-controller-test.cap", SAT_SRC_TRIM_TITLE_SUMMARY },
};
static const struct sat_source src_ls600_transcoder[] = {
{ "sat-ls600.cap", SAT_SRC_SERIAL_LOADER_PLUS_BODY },
{ "ls600-transcoder-test.cap", SAT_SRC_TRIM_TITLE_SUMMARY },
};
static const struct sat_source src_ls600_doe[] = {
{ "sat-ls600.cap", SAT_SRC_SERIAL_LOADER_PLUS_BODY },
{ "ls600-doe.cap", SAT_SRC_TRIM_TITLE_SUMMARY },
};
static const struct sat_batch_def sat_batches[] = {
{
{ "cpu-functional", "CPU Functional Test",
"SAT step 1: the functional CPU deck staged through the scatter-image path.",
SAT_BATCH_IMAGE },
src_cpu_functional, (int)(sizeof(src_cpu_functional) / sizeof(src_cpu_functional[0])),
0x0000
},
{
{ "card-reader-a", "Reading Test Channel A",
"SAT step 2: the captured card-reader test deck.", SAT_BATCH_IMAGE },
src_reader_a, (int)(sizeof(src_reader_a) / sizeof(src_reader_a[0])),
0x0000
},
{
{ "printer-mechanical", "Printer Mechanical Test",
"SAT step 3: the line-printer deck staged through the scatter-image path, "
"with the required center card synthesized into the startup input buffer.",
SAT_BATCH_IMAGE },
src_printer_mech, (int)(sizeof(src_printer_mech) / sizeof(src_printer_mech[0])),
0x0118
},
{
{ "control-program-cr", "Control Program CR",
"Control-program utility deck with the serial Hollerith loader kept.",
SAT_BATCH_READER },
src_control_program, (int)(sizeof(src_control_program) / sizeof(src_control_program[0])),
0x0000
},
{
{ "ls600-controller-sat", "LS600 Controller SAT Batch",
"Sequencer Program followed by LS600 Controller Test, prepared per the SAT notes.",
SAT_BATCH_READER },
src_ls600_controller, (int)(sizeof(src_ls600_controller) / sizeof(src_ls600_controller[0])),
0x0000
},
{
{ "ls600-transcoder-sat", "LS600 Transcoder SAT Batch",
"Sequencer Program followed by LS600 Transcoder Test, prepared per the SAT notes.",
SAT_BATCH_READER },
src_ls600_transcoder, (int)(sizeof(src_ls600_transcoder) / sizeof(src_ls600_transcoder[0])),
0x0000
},
{
{ "ls600-doe-sat", "LS600 D.O.E. SAT Batch",
"Sequencer Program followed by the LS600 D.O.E. deck, prepared per the SAT notes.",
SAT_BATCH_READER },
src_ls600_doe, (int)(sizeof(src_ls600_doe) / sizeof(src_ls600_doe[0])),
0x0000
},
};
static int row8_loader_card(const struct cap_deck *deck)
{
int ncards = cap_num_cards(deck);
int limit = ncards < 5 ? ncards : 5;
for (int i = 1; i < limit; i++) {
const uint16_t *cols = cap_card_columns(deck, i);
if (cap_card_ncols(deck, i) >= 3 && cols && cols[2] == 0x0100)
return i;
}
return (ncards > 1) ? 1 : 0;
}
static int append_card_range(struct cap_deck *out, const struct cap_deck *src,
int first, int last_inclusive)
{
for (int i = first; i <= last_inclusive; i++) {
int ncols = cap_card_ncols(src, i);
const uint16_t *cols = cap_card_columns(src, i);
if (ncols <= 0 || !cols)
continue;
if (cap_append_card(out, cols, ncols) != 0)
return -1;
}
return 0;
}
static int append_source(struct cap_deck *out, const char *path, enum sat_source_op op)
{
struct cap_deck *src = cap_load(path);
int ncards;
int rc = -1;
if (!src)
return -1;
ncards = cap_num_cards(src);
switch (op) {
case SAT_SRC_AS_IS:
rc = append_card_range(out, src, 0, ncards - 1);
break;
case SAT_SRC_TRIM_TITLE_SUMMARY:
rc = (ncards >= 3) ? append_card_range(out, src, 1, ncards - 2) : -1;
break;
case SAT_SRC_SERIAL_LOADER_PLUS_BODY: {
int loader = row8_loader_card(src);
if (ncards < 7)
rc = -1;
else if (cap_append_card(out, cap_card_columns(src, loader),
cap_card_ncols(src, loader)) != 0)
rc = -1;
else
rc = append_card_range(out, src, 5, ncards - 2);
break;
}
default:
rc = -1;
break;
}
cap_free(src);
return rc;
}
static const struct sat_batch_def *sat_batch_def_find(const char *id)
{
if (!id)
return NULL;
for (size_t i = 0; i < sizeof(sat_batches) / sizeof(sat_batches[0]); i++) {
if (strcmp(sat_batches[i].info.id, id) == 0)
return &sat_batches[i];
}
return NULL;
}
static void sat_apply_image_patches(const struct sat_batch_def *def, unsigned char *image)
{
const struct sat_image_patch *patches = NULL;
size_t npatches = 0;
if (strcmp(def->info.id, "printer-mechanical") == 0) {
patches = printer_mech_center_card;
npatches = sizeof(printer_mech_center_card) / sizeof(printer_mech_center_card[0]);
}
for (size_t i = 0; i < npatches; i++)
image[patches[i].addr] = patches[i].value;
}
static void sat_note(char *note, size_t note_sz, const struct sat_batch_def *def)
{
if (!note || note_sz == 0)
return;
snprintf(note, note_sz, "%s", def->info.summary);
}
int sat_batch_count(void)
{
return (int)(sizeof(sat_batches) / sizeof(sat_batches[0]));
}
const struct sat_batch_info *sat_batch_info_at(int idx)
{
if (idx < 0 || idx >= sat_batch_count())
return NULL;
return &sat_batches[idx].info;
}
const struct sat_batch_info *sat_batch_find(const char *id)
{
const struct sat_batch_def *def = sat_batch_def_find(id);
return def ? &def->info : NULL;
}
int sat_batch_prepare_image(const char *root, const char *id,
unsigned char *image,
unsigned *lo, unsigned *hi, uint16_t *entry,
char *note, size_t note_sz)
{
char path[1024];
const struct sat_batch_def *def = sat_batch_def_find(id);
int rc;
if (!def || def->info.launch != SAT_BATCH_IMAGE ||
!root || !image || !lo || !hi || !entry || def->nsources != 1)
return -1;
snprintf(path, sizeof(path), "%s/%s", root, def->sources[0].file);
memset(image, 0, MEM_SIZE);
rc = cap_load_scattered(path, TC_COLBIN, image, lo, hi);
if (rc < 0)
return -1;
sat_apply_image_patches(def, image);
*entry = def->image_entry ? def->image_entry : (uint16_t)*lo;
sat_note(note, note_sz, def);
return 0;
}
int sat_batch_prepare_deck(const char *root, const char *id,
const char *out_path,
char *note, size_t note_sz)
{
char path[1024];
struct cap_deck *out;
const struct sat_batch_def *def = sat_batch_def_find(id);
if (!def || def->info.launch != SAT_BATCH_READER || !root || !out_path)
return -1;
out = cap_create();
if (!out)
return -1;
for (int i = 0; i < def->nsources; i++) {
snprintf(path, sizeof(path), "%s/%s", root, def->sources[i].file);
if (append_source(out, path, def->sources[i].op) != 0) {
cap_free(out);
return -1;
}
}
if (cap_save(out, out_path) != 0) {
cap_free(out);
return -1;
}
cap_free(out);
sat_note(note, note_sz, def);
return 0;
}