-
Notifications
You must be signed in to change notification settings - Fork 0
/
t10_sfh.c
500 lines (374 loc) · 15.8 KB
/
t10_sfh.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
// Simple File Handler
// OPEN, ENTER, LOOKUP, RENAME
#include "op.h"
#include "tops10-uuosym.h"
#include "tops10-monctx.h"
// Free a channel
int sfh_freechannel(PCTX *ctx,int chan)
{
if (mCTX->clist[chan])
free(mCTX->clist[chan]);
mCTX->clist[chan] = NULL;
return(0);
}
// Create the channel (0 success, 1 error)
int sfh_createchan(PCTX *ctx,int chan, int mode, BIGV opmod, BIGV opdev, BIGV opbuf, char *ov, int devtype)
{
T10SFH *nsfh;
// Allocate new channel structure
nsfh = (T10SFH *) malloc(T10SFH_SIZE);
if (nsfh==NULL) {
printf("Cannot allocate a T10SFH\n");
exit(100);
}
// Zero the area
memset((void *) nsfh, 0, T10SFH_SIZE);
nsfh->state = SFH_STATE_CLOSED;
nsfh->devtype = devtype;
nsfh->flags = 0;
nsfh->filemode = mode;
nsfh->dOPMOD = opmod;
nsfh->dOPDEV = opdev;
nsfh->dOPBUF = opbuf;
strcpy(nsfh->devnam, ov);
mCTX->clist[chan] = nsfh;
return(0);
}
// Open a device (return 0 on success, 1 on error)
int sfh_opendevice(PCTX *ctx,int chan, int mode, BIGV opmod, BIGV opdev, BIGV opbuf, char *ov)
{
int devtype;
// Check to see if the channel is available
if (mCTX->clist[chan])
switch(mCTX->clist[chan]->state) {
case SFH_STATE_CLOSED:
sfh_freechannel(ctx,chan); // Closed - so free it
break;
case SFH_STATE_OPEN:
case SFH_STATE_FILE:
default:
return(1); // channel in use
}
devtype = SFH_DEVICE_UNKNOWN;
if (strcmp(ov,"TTY ")==0) devtype = SFH_DEVICE_TTY;
/*
TTY permits the following modes:
18-21 IO.ERR Error flags. These are returned by the monitor
after an I/O operation that failed:
Flag Symbol Error
18 IO.IMP Not assigned to a job for image
mode input.
19 IO.DER Ignore interrupts for 0.75 seconds.
20 IO.DTE Echo failure on output.
21 IO.BKT Character lost on input.
If all of these bits are set, the remote node to
which the terminal is connected has failed.
23 IO.ACT Device active.
25 IO.ABS Enable using break mask. (Refer to Section 15.4.)
26 IO.BKA Break on all characters. An IN or INPUT call will
terminate on the first character typed, thus
enabling character input mode.
27 IO.TEC Truth in echoing mode. This causes all control
characters to be output as themselves (for example,
the ESCAPE character is not echoed as $ but as octal
33).
28 IO.SUP Suppress echoing.
29 IO.LEM Enable special editor mode. This causes some
control characters (CTRL/R, CTRL/H, CTRL/U, CTRL/W,
and DELETE) to be passed to the program and ignored
by the monitor, except to echo the control
characters and to act as break characters.
32-35 IO.MOD Data mode:
0 .IOASC ASCII mode.
1 .IOASL ASCII line mode.
2 .IOPIM Packed image mode.
4 .IOAS8 8-bit ASCII mode.
10 .IOIMG Image mode.
*/
if (strcmp(ov,"DSK ")==0) devtype = SFH_DEVICE_DSK;
/*
I/O status bits for disk are as follows:
Bits Symbol Meaning
18-21 IO.ERR Error flags:
Flag Symbol Error
18 IO.IMP Attempt to write on software
write-locked file structure or
software redundancy failure
occurred.
19 IO.DER Error detected by device.
20 IO.DTE Hard data error.
21 IO.BKT Block too large.
22 IO.EOF End of file.
23 IO.ACT Device active.
29 IO.WHD Write disk pack headers.
30 IO.SYN Synchronous I/O.
32-35 IO.MOD Data mode:
Code Symbol Meaning
0 .IOASC ASCII mode.
1 .IOASL ASCII line mode.
10 .IOIMG Image mode.
13 .IOIBN Image binary mode.
14 .IOBIN Binary mode.
16 .IODPR Dump record mode.
17 .IODMP Dump mode.
*/
// if (strcmp(ov,"LPT ")==0) devtype = SFH_DEVICE_LPT;
/*
The I/O status bits for the line printer are as follows:
Bits Symbol Meaning
23 IO.ACT Device active.
25 IO.SVF Suppresses the vertical format unit on a line
printer. This allows LN01 fonts and graphics to
print correctly. Refer to the TOPS-10 Operating
System Commands Manual for information on using LN01
fonts.
29 IO.SFF Suppress formfeeds on OUT, OUTPUT, and CLOSE monitor
calls.
32-35 IO.MOD Data mode:
Code Symbol Meaning
0 .IOASC ASCII mode.
1 .IOASL ASCII line mode.
4 .IOAS8 8-bit ASCII mode, for network line
printers only.
10 .IOIMG Image mode.
*/
// if (strcmp(ov,"MTA ")==0) devtype = SFH_DEVICE_MTA;
/*
The I/O status bits for magtapes are listed below.
Bits Symbol Meaning
18-21 IO.ERR Error flags. If all these bits are set, the error
was detected by the tape label handler; use the
DEVOP. call to determine the extended error code.
Flag Symbol Error
18 IO.IMP Output attempted on a write-locked
unit, or an illegal operation was
attempted.
19 IO.DER Data was missed on the tape or the
tape was bad, or the transport is
hung.
20 IO.DTE Parity error.
21 IO.BKT The record read from the tape is
too long for the buffer.
22 IO.EOF End-of-file mark found. You must clear this bit
using SETSTS before reading further, or CLOSE to
reset the tape status.
23 IO.ACT Device active.
24 IO.BOT Beginning of tape.
25 IO.EOT Physical end of tape was encountered. Physical EOT
is several feet before the actual end of tape. It
is seen when passed over on a write operation as an
error return with this bit set in the file status
word. You must clear this bit and condition (using
the SETSTS call) before another write operation can
be successful. Physical EOT is not seen on read
operations. Physical EOT does not prevent your
program from writing off the end of tape. If your
program does not heed the physical EOT warning, it
is allowed to keep writing. Logical EOT does not
prevent your program from reading past it. Your
program must check for two consecutive EOF marks,
which indicates the logical EOT.
26 IO.PAR Parity:
0 = even (BCD only)
1 = odd
27-28 IO.DEN Density:
0 = standard
1 = 200 BPI
2 = 556 BPI
3 = 800 BPI
Other densities (1600, 6250) must be specified by
setting IO.DEN to 0 on an OPEN, and then using a
TAPOP. to set the desired density.
Odd parity is preferred. The user program should
specify even parity only when creating a tape to be
read in binary coded decimal (BCD) on another type
of computer system.
29 IO.NRC Read without reread check.
32-35 IO.MOD Data mode. Defines method for writing data into
buffers. The modes are:
Code Symbol Meaning
0 .IOASC ASCII mode.
1 .IOASL ASCII line mode.
3 .IOBYT Byte mode.
10 .IOIMG Image mode.
13 .IOIBN Image binary mode.
14 .IOBIN Binary mode.
16 .IODPR Dump record mode.
17 .IODMP Dump mode. */
// if (strcmp(ov,"PTY ")==0) devtype = SFH_DEVICE_PTY;
*/
The I/O status bits for the PTY are:
Bits Symbol Meaning
21 IO.BKT More output sent than was accepted by the PTY.
23 IO.ACT Device active.
24 IO.PTI Job is waiting to receive input.
25 IO.PTO Job is waiting to send output.
26 IO.PTM Subjob is in monitor mode.
32-35 IO.MOD Data mode:
Code Symbol Meaning
0 .IOASC ASCII mode.
1 .IOASL ASCII line mode.
2 .IOPIM Packed image mode (for full-SCNSER
PTYs only).
4 .IOAS8 8-bit ASCII mode.
*/
// if (strcmp(ov,"PLT ")==0) devtype = SFH_DEVICE_PLT;
/*
The I/O status bits for the plotter are as follows:
Bits Symbol Meaning
23 IO.ACT Device active.
32-35 IO.MOD Data mode:
Code Symbol Meaning
0 .IOASC ASCII mode.
1 .IOASL ASCII line mode.
10 .IOIMG Image mode.
13 .IOIBN Image binary mode.
14 .IOBIN Binary mode.
*/
if (sfh_createchan(ctx,chan,mode,opmod,opdev,opbuf,ov,devtype)) return(1);
switch(devtype) {
case SFH_DEVICE_TTY:
mCTX->clist[chan]->flags = SFH_FLAG_STDOUT;
mCTX->clist[chan]->iv = stdin;
mCTX->clist[chan]->ov = stdout;
mCTX->clist[chan]->state = SFH_STATE_DEVICE;
return(0); // TTY is open
case SFH_DEVICE_DSK:
mCTX->clist[chan]->flags = 0;
mCTX->clist[chan]->iv = NULL;
mCTX->clist[chan]->ov = NULL;
mCTX->clist[chan]->state = SFH_STATE_OPEN;
return(0); // DSK is open
default:
return(1); // Unsupported device
}
}
int t10_OPEN(PCTX *ctx)
{
BIGV op_opmod,op_opdev,op_opbuf;
char ov[7];
char *d;
op_opmod = READMEM(jctx, ctx->E + UUO_xOPMOD);
CHKERROR(jctx);
op_opdev = READMEM(jctx, ctx->E + UUO_xOPDEV);
CHKERROR(jctx);
op_opbuf = READMEM(jctx, ctx->E + UUO_xOPBUF);
CHKERROR(jctx);
printf("OPEN Chan = %o, ",SFHCHAN(ctx->AC));
printf("OPMOD %06o %06o, ",
(int) LH(op_opmod),
(int) RH(op_opmod));
switch (op_opmod & UUO_IOxMOD) {
case UUO_xIOASC: d = ".IOASC ASCII mode (for any device except display)."; break;
case UUO_xIOASL: d = ".IOASL ASCII line mode (for any device except display)."; break;
case UUO_xIOPIM: d = ".IOPIM Packed image mode (terminal only)."; break;
case UUO_xIOBYT: d = ".IOBYT Byte mode (magtape device only)."; break;
case UUO_xIOAS8: d = ".IOAS8 8-bit ASCII mode (terminal, pseudo-terminal, and line printers only)."; break;
case UUO_xIOIMG: d = ".IOIMG Image mode (for any except display device)."; break;
case UUO_xIOIBN: d = ".IOIBN Image binary mode (for disk, DECtape, magtape, plotter, card device, or papertape device)."; break;
case UUO_xIOBIN: d = ".IOBIN Binary mode (for same devices as .IOIBN)."; break;
case UUO_xIOIDP: d = ".IOIDP Image dump mode (for display devices only)."; break;
case UUO_xIODPR: d = ".IODPR Dump record mode (for disk, DECtape, or magtape devices)."; break;
case UUO_xIODMP: d = ".IODMP Dump mode (for disk, DECtape, or magtape devices)."; break;
default:
d = "Unknown open mode"; break;
}
unpacksixhw((int)LH(op_opdev), &ov[0]);
unpacksixhw((int)RH(op_opdev), &ov[3]);
ov[6] = '\0';
printf("OPDEV /%s/, ",ov);
printf("OPBUF %06o %06o\n",
(int) LH(op_opbuf),
(int) RH(op_opbuf));
printf("Mode=%s\n",d);
switch (sfh_opendevice(ctx, SFHCHAN(ctx->AC), op_opmod & UUO_IOxMOD,
op_opmod, op_opdev, op_opbuf, ov)) {
case 0: // Success
ctx->PC += 1;
break;
default: // Error
ctx->PC += 0;
break;
}
return(OK_EXIT);
}
// INIT - obsolete form of OPEN
int t10_INIT(PCTX *ctx)
{
BIGV op_opmod,op_opdev,op_opbuf;
char ov[7];
char *d;
op_opmod = ctx->E;
op_opdev = READMEM(jctx, ctx->PC + 1);
CHKERROR(jctx);
op_opbuf = READMEM(jctx, ctx->PC + 2);
CHKERROR(jctx);
printf("Chan = %o, ",SFHCHAN(ctx->AC));
printf("OPMOD %06o %06o, ",
(int) LH(op_opmod),
(int) RH(op_opmod));
switch (op_opmod & UUO_IOxMOD) {
case UUO_xIOASC: d = ".IOASC ASCII mode (for any device except display)."; break;
case UUO_xIOASL: d = ".IOASL ASCII line mode (for any device except display)."; break;
case UUO_xIOPIM: d = ".IOPIM Packed image mode (terminal only)."; break;
case UUO_xIOBYT: d = ".IOBYT Byte mode (magtape device only)."; break;
case UUO_xIOAS8: d = ".IOAS8 8-bit ASCII mode (terminal, pseudo-terminal, and line printers only)."; break;
case UUO_xIOIMG: d = ".IOIMG Image mode (for any except display device)."; break;
case UUO_xIOIBN: d = ".IOIBN Image binary mode (for disk, DECtape, magtape, plotter, card device, or papertape device)."; break;
case UUO_xIOBIN: d = ".IOBIN Binary mode (for same devices as .IOIBN)."; break;
case UUO_xIOIDP: d = ".IOIDP Image dump mode (for display devices only)."; break;
case UUO_xIODPR: d = ".IODPR Dump record mode (for disk, DECtape, or magtape devices)."; break;
case UUO_xIODMP: d = ".IODMP Dump mode (for disk, DECtape, or magtape devices)."; break;
default:
d = "Unknown open mode"; break;
}
unpacksixhw((int)LH(op_opdev), &ov[0]);
unpacksixhw((int)RH(op_opdev), &ov[3]);
ov[6] = '\0';
printf("OPDEV /%s/, ",ov);
printf("OPBUF %06o %06o\n",
(int) LH(op_opbuf),
(int) RH(op_opbuf));
printf("Mode=%s\n",d);
switch (sfh_opendevice(ctx, SFHCHAN(ctx->AC), op_opmod & UUO_IOxMOD,
op_opmod, op_opdev, op_opbuf, ov)) {
case 0: // Success
ctx->PC += 3;
break;
default: // Error
ctx->PC += 2;
break;
}
return(OK_EXIT);
}
// RELEASE close file - single return
int t10_RELEAS(PCTX *ctx)
{
// No action if file already closed
if (mCTX->clist[SFHCHAN(ctx->AC)]==NULL) return(OK_EXIT);
switch(mCTX->clist[SFHCHAN(ctx->AC)]->state) {
case SFH_STATE_CLOSED:
return(OK_EXIT);
case SFH_STATE_OPEN:
case SFH_STATE_FILE:
default:
printf("?T10_SFH - Need to close files with RELEASE - not implemented PC %06o\n",ctx->PC);
cPSTAT = PSTAT_HALTED;
return(OK_PSTAT);
}
return(OK_EXIT);
}
// INBUF set input buffers
int t10_INBUF(PCTX *ctx)
{
if (mCTX->clist[SFHCHAN(ctx->AC)]==NULL) return(OK_EXIT);
mCTX->clist[SFHCHAN(ctx->AC)]->inbufs = ctx->E;
return(OK_EXIT);
}
// OUTBUF set input buffers
int t10_OUTBUF(PCTX *ctx)
{
if (mCTX->clist[SFHCHAN(ctx->AC)]==NULL) return(OK_EXIT);
mCTX->clist[SFHCHAN(ctx->AC)]->outbufs = ctx->E;
return(OK_EXIT);
}