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 501 502 503
|
/* sds_mt.c: SDS 940 magnetic tape simulator
Copyright (c) 2001-2008, Robert M. Supnik
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Robert M Supnik shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Robert M Supnik.
mt 7 track magnetic tape
16-Feb-06 RMS Added tape capacity checking
07-Dec-04 RMS Added read-only file support
25-Apr-03 RMS Revised for extended file support
28-Mar-03 RMS Added multiformat support
28-Feb-03 RMS Revised for magtape library
Magnetic tapes are represented as a series of variable 8b records
of the form:
32b record length in bytes - exact number
byte 0
byte 1
:
byte n-2
byte n-1
32b record length in bytes - exact number
If the byte count is odd, the record is padded with an extra byte
of junk. File marks are represented by a single record length of 0.
End of tape is two consecutive end of file marks.
*/
#include "sds_defs.h"
#include "sim_tape.h"
#define MT_MAXFR (32768 * 4)
#define MT_NUMDR 8 /* number drives */
#define MT_UNIT 07
#define botf u3 /* bot tape flag */
#define eotf u4 /* eot tape flag */
extern uint32 xfr_req;
extern int32 stop_invins, stop_invdev, stop_inviop;
int32 mt_inst = 0; /* saved instr */
int32 mt_eof = 0; /* end of file */
int32 mt_gap = 0; /* in gap */
int32 mt_skip = 0; /* skip rec */
int32 mt_bptr = 0; /* buf ptr */
int32 mt_blnt = 0; /* buf length */
int32 mt_ctime = 10; /* char time */
int32 mt_gtime = 1000; /* gap time */
int32 mt_stopioe = 1; /* stop on err */
uint8 mtxb[MT_MAXFR]; /* record buffer */
DSPT mt_tplt[] = { /* template */
{ MT_NUMDR, 0 },
{ MT_NUMDR, DEV_MTS },
{ MT_NUMDR, DEV_OUT },
{ MT_NUMDR, DEV_MTS+DEV_OUT },
{ 0, 0 }
};
DEVICE mt_dev;
t_stat mt_svc (UNIT *uptr);
t_stat mt_reset (DEVICE *dptr);
t_stat mt_boot (int32 unitno, DEVICE *dptr);
t_stat mt_attach (UNIT *uptr, char *cptr);
t_stat mt_detach (UNIT *uptr);
t_stat mt_readrec (UNIT *uptr);
t_mtrlnt mt_readbc (UNIT *uptr);
void mt_readend (UNIT *uptr);
t_stat mt_wrend (uint32 dev);
void mt_set_err (UNIT *uptr);
t_stat mt (uint32 fnc, uint32 inst, uint32 *dat);
static const char sds_to_bcd[64] = {
012, 001, 002, 003, 004, 005, 006, 007,
010, 011, 012, 013, 014, 015, 016, 017,
060, 061, 062, 063, 064, 065, 066, 067,
070, 071, 072, 073, 074, 075, 076, 077,
040, 041, 042, 043, 044, 045, 046, 047,
050, 051, 052, 053, 054, 055, 056, 057,
020, 021, 022, 023, 024, 025, 026, 027,
030, 031, 032, 033, 034, 035, 036, 037
};
static const char bcd_to_sds[64] = {
000, 001, 002, 003, 004, 005, 006, 007,
010, 011, 000, 013, 014, 015, 016, 017,
060, 061, 062, 063, 064, 065, 066, 067,
070, 071, 072, 073, 074, 075, 076, 077,
040, 041, 042, 043, 044, 045, 046, 047,
050, 051, 052, 053, 054, 055, 056, 057,
020, 021, 022, 023, 024, 025, 026, 027,
030, 031, 032, 033, 034, 035, 036, 037
};
/* MT data structures
mt_dev MT device descriptor
mt_unit MT unit descriptor
mt_reg MT register list
*/
DIB mt_dib = { CHAN_W, DEV_MT, XFR_MT0, mt_tplt, &mt };
UNIT mt_unit[] = {
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) },
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_ROABLE + UNIT_DISABLE, 0) }
};
REG mt_reg[] = {
{ BRDATA (BUF, mtxb, 8, 8, MT_MAXFR) },
{ DRDATA (BPTR, mt_bptr, 18), PV_LEFT },
{ DRDATA (BLNT, mt_blnt, 18), PV_LEFT },
{ FLDATA (XFR, xfr_req, XFR_V_MT0) },
{ ORDATA (INST, mt_inst, 24) },
{ FLDATA (EOF, mt_eof, 0) },
{ FLDATA (GAP, mt_gap, 0) },
{ FLDATA (SKIP, mt_skip, 0) },
{ DRDATA (CTIME, mt_ctime, 24), REG_NZ + PV_LEFT },
{ DRDATA (GTIME, mt_gtime, 24), REG_NZ + PV_LEFT },
{ URDATA (POS, mt_unit[0].pos, 10, T_ADDR_W, 0,
MT_NUMDR, PV_LEFT | REG_RO) },
{ URDATA (BOT, mt_unit[0].botf, 10, 1, 0, MT_NUMDR, REG_RO) },
{ URDATA (EOT, mt_unit[0].eotf, 10, 1, 0, MT_NUMDR, REG_RO) },
{ FLDATA (STOP_IOE, mt_stopioe, 0) },
{ NULL }
};
MTAB mt_mod[] = {
{ MTUF_WLK, 0, "write enabled", "WRITEENABLED", NULL },
{ MTUF_WLK, MTUF_WLK, "write locked", "LOCKED", NULL },
{ MTAB_XTD|MTAB_VUN, 0, "FORMAT", "FORMAT",
&sim_tape_set_fmt, &sim_tape_show_fmt, NULL },
{ MTAB_XTD|MTAB_VUN, 0, "CAPACITY", "CAPACITY",
&sim_tape_set_capac, &sim_tape_show_capac, NULL },
{ MTAB_XTD|MTAB_VDV, 0, "CHANNEL", "CHANNEL",
&set_chan, &show_chan, NULL },
{ 0 }
};
DEVICE mt_dev = {
"MT", mt_unit, mt_reg, mt_mod,
MT_NUMDR, 10, 31, 1, 8, 8,
NULL, NULL, &mt_reset,
&mt_boot, &mt_attach, NULL,
&mt_dib, DEV_DISABLE
};
/* Mag tape routine
conn - inst = EOM0, dat = NULL
eom1 - inst = EOM1, dat = NULL
sks - inst = SKS, dat = ptr to result
disc - inst = device number, dat = NULL
wreor - inst = device number, dat = NULL
read - inst = device number, dat = ptr to data
write - inst = device number, dat = ptr to result
*/
t_stat mt (uint32 fnc, uint32 inst, uint32 *dat)
{
int32 u = inst & MT_UNIT; /* get unit */
UNIT *uptr = mt_dev.units + u; /* get unit ptr */
int32 t, new_ch;
uint8 chr;
t_stat r;
switch (fnc) { /* case function */
case IO_CONN: /* connect */
new_ch = I_GETEOCH (inst); /* get new chan */
if (new_ch != mt_dib.chan) /* wrong chan? */
return SCPE_IERR;
if (mt_gap) { /* in gap? */
mt_gap = 0; /* clr gap flg */
sim_cancel (uptr); /* cancel timer */
}
else if (sim_is_active (uptr)) /* busy? */
CRETIOP;
uptr->eotf = 0; /* clr eot flag */
mt_eof = 0; /* clr eof flag */
mt_skip = 0; /* clr skp flag */
mt_bptr = mt_blnt = 0; /* init buffer */
if ((inst & DEV_MTS)? (CHC_GETCPW (inst) < 2): /* scn & cpw<3? */
(inst & CHC_REV)) /* rw & rev? */
return STOP_INVIOP;
mt_inst = inst; /* save inst */
if ((inst & DEV_MTS) && !(inst && DEV_OUT)) /* scanning? */
chan_set_flag (mt_dib.chan, CHF_SCAN); /* set chan flg */
xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */
sim_activate (uptr, mt_gtime); /* start timer */
break;
case IO_EOM1: /* EOM mode 1 */
new_ch = I_GETEOCH (inst); /* get new chan */
if (new_ch != mt_dib.chan) /* wrong chan? */
CRETIOP;
t = inst & 07670; /* get command */
if ((t == 04010) && !sim_is_active (uptr)) { /* rewind? */
sim_tape_rewind (uptr); /* rewind unit */
uptr->eotf = 0; /* clr eot */
uptr->botf = 1; /* set bot */
}
else if ((t == 03610) && sim_is_active (uptr) &&/* skip rec? */
((mt_inst & DEV_OUT) == 0))
mt_skip = 1; /* set flag */
else CRETINS;
break;
case IO_DISC: /* disconnect */
sim_cancel (uptr); /* no more xfr's */
if (inst & DEV_OUT) { /* write? */
if (r = mt_wrend (inst)) /* end record */
return r;
}
break;
case IO_WREOR: /* write eor */
chan_set_flag (mt_dib.chan, CHF_EOR); /* set eor flg */
if (r = mt_wrend (inst)) /* end record */
return r;
mt_gap = 1; /* in gap */
sim_activate (uptr, mt_gtime); /* start timer */
break;
case IO_SKS: /* SKS */
new_ch = I_GETSKCH (inst); /* get chan # */
if (new_ch != mt_dib.chan) /* wrong chan? */
return SCPE_IERR;
if ((inst & (DEV_OUT | DEV_MTS)) == 0) { /* not sks 1n? */
t = I_GETSKCND (inst); /* get skip cond */
switch (t) { /* case sks cond */
case 001: /* sks 1021n */
*dat = 1; /* not magpak */
break;
case 002: /* sks 1041n */
if (!(uptr->flags & UNIT_ATT) || /* not ready */
sim_is_active (uptr)) *dat = 1;
break;
case 004: /* sks 1101n */
if (!uptr->eotf) *dat = 1; /* not EOT */
break;
case 010: /* sks 1201n */
if (!uptr->botf) *dat = 1; /* not BOT */
break;
case 013: /* sks 12610 */
if (!mt_gap) *dat = 1; /* not in gap */
break;
case 017: /* sks 13610 */
if (!mt_eof) *dat = 1; /* not EOF */
break;
case 020: /* sks 1401n */
if (!sim_tape_wrp (uptr)) *dat = 1; /* not wrp */
break;
case 031: /* sks 1621n */
case 033: /* sks 1661n */
*dat = 1; /* not 556bpi */
case 035: /* sks 1721n */
break; /* not 800bpi */
}
} /* end if */
break;
case IO_READ: /* read */
xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */
if (mt_blnt == 0) { /* first read? */
r = mt_readrec (uptr); /* get data */
if ((r != SCPE_OK) || (mt_blnt == 0)) /* err, inv reclnt? */
return r;
}
uptr->botf = 0; /* off BOT */
if (mt_inst & CHC_REV) /* get next rev */
chr = mtxb[--mt_bptr] & 077;
else chr = mtxb[mt_bptr++] & 077; /* get next fwd */
if (!(mt_inst & CHC_BIN)) /* bcd? */
chr = bcd_to_sds[chr];
*dat = chr & 077; /* give to chan */
if ((mt_inst & CHC_REV)? (mt_bptr <= 0): /* rev or fwd, */
(mt_bptr >= mt_blnt)) /* recd done? */
mt_readend (uptr);
break;
case IO_WRITE: /* write */
uptr->botf = 0; /* off BOT */
chr = (*dat) & 077;
xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */
if (!(mt_inst & CHC_BIN)) /* bcd? */
chr = sds_to_bcd[chr];
if (mt_bptr < MT_MAXFR) mtxb[mt_bptr++] = chr; /* insert in buf */
break;
default:
CRETINS;
}
return SCPE_OK;
}
/* Unit service */
t_stat mt_svc (UNIT *uptr)
{
if (mt_gap) { /* gap timeout */
mt_gap = 0; /* clr gap flg */
chan_disc (mt_dib.chan); /* disc chan */
}
else if (mt_skip) /* skip record */
mt_readend (uptr);
else { /* normal xfr */
xfr_req = xfr_req | XFR_MT0; /* set xfr req */
sim_activate (uptr, mt_ctime); /* reactivate */
}
return SCPE_OK;
}
/* Read start (get new record) */
t_stat mt_readrec (UNIT *uptr)
{
t_mtrlnt tbc;
t_stat st;
if ((uptr->flags & UNIT_ATT) == 0) { /* attached? */
mt_set_err (uptr); /* no, err, disc */
return SCPE_UNATT;
}
if (mt_inst & CHC_REV) /* reverse? */
st = sim_tape_rdrecr (uptr, mtxb, &tbc, MT_MAXFR); /* read rec rev */
else { /* no, fwd */
t_bool passed_eot = sim_tape_eot (uptr); /* passed EOT? */
st = sim_tape_rdrecf (uptr, mtxb, &tbc, MT_MAXFR);
if (!passed_eot && sim_tape_eot (uptr)) /* just passed eot? */
uptr->eotf = 1;
}
if (st == MTSE_TMK) { /* tape mark? */
mt_eof = 1; /* set eof flag */
mtxb[0] = mtxb[1] = 017; /* EOR char */
mt_blnt = 2; /* store 2 */
return SCPE_OK;
}
if (st != MTSE_OK) { /* other error? */
mt_set_err (uptr); /* err, disc */
if (st == MTSE_IOERR) /* IO error? */
return SCPE_IOERR;
if (st == MTSE_INVRL) /* inv rec lnt? */
return SCPE_MTRLNT;
if (st == MTSE_EOM) /* eom? set eot */
uptr->eotf = 1;
return SCPE_OK;
}
mt_blnt = tbc; /* set buf lnt */
return SCPE_OK;
}
/* Read done (eof, end of record) */
void mt_readend (UNIT *uptr)
{
sim_cancel (uptr); /* stop timer */
mt_skip = 0; /* clr skp flg */
chan_set_flag (mt_dib.chan, CHF_EOR); /* end record */
if (mt_eof) /* EOF? */
chan_disc (mt_dib.chan);
else {
mt_gap = 1; /* no, in gap */
sim_activate (uptr, mt_gtime); /* start timer */
}
return;
}
/* Write complete (end of record or disconnect) */
t_stat mt_wrend (uint32 dev)
{
UNIT *uptr = mt_dev.units + (dev & MT_UNIT);
t_mtrlnt tbc;
t_stat st;
sim_cancel (uptr); /* no more xfr's */
if (mt_bptr == 0) /* buf empty? */
return SCPE_OK;
if (!(uptr->flags & UNIT_ATT)) { /* attached? */
mt_set_err (uptr); /* no, err, disc */
return SCPE_UNATT;
}
if (sim_tape_wrp (uptr)) { /* write lock? */
mt_set_err (uptr); /* yes, err, disc */
return SCPE_OK;
}
if (dev & DEV_MTS) { /* erase? */
if (mt_inst & CHC_REV) /* reverse? */
sim_tape_sprecr (uptr, &tbc); /* backspace */
st = sim_tape_wreom (uptr); /* write eom */
}
else {
t_bool passed_eot = sim_tape_eot (uptr); /* passed EOT? */
if ((mt_bptr == 1) && (mtxb[0] == 017) && /* wr eof? */
((mt_inst & 01670) == 00050))
st = sim_tape_wrtmk (uptr); /* write tape mark */
else st = sim_tape_wrrecf (uptr, mtxb, mt_bptr); /* write record */
if (!passed_eot && sim_tape_eot (uptr)) /* just passed EOT? */
uptr->eotf = 1;
}
mt_bptr = 0;
if (st != MTSE_OK) /* error? */
mt_set_err (uptr);
if (st == MTSE_IOERR)
return SCPE_IOERR;
return SCPE_OK;
}
/* Fatal error */
void mt_set_err (UNIT *uptr)
{
chan_set_flag (mt_dib.chan, CHF_EOR | CHF_ERR); /* eor, error */
chan_disc (mt_dib.chan); /* disconnect */
xfr_req = xfr_req & ~XFR_MT0; /* clear xfr */
sim_cancel (uptr); /* stop */
mt_bptr = 0; /* buf empty */
return;
}
/* Reset routine */
t_stat mt_reset (DEVICE *dptr)
{
int32 i;
chan_disc (mt_dib.chan); /* disconnect */
mt_eof = 0; /* clear state */
mt_gap = 0;
mt_skip = 0;
mt_inst = 0;
mt_bptr = mt_blnt = 0;
xfr_req = xfr_req & ~XFR_MT0; /* clr xfr flag */
for (i = 0; i < MT_NUMDR; i++) { /* deactivate */
sim_cancel (&mt_unit[i]);
sim_tape_reset (&mt_unit[i]);
mt_unit[i].eotf = 0;
}
return SCPE_OK;
}
/* Attach and detach routines */
t_stat mt_attach (UNIT *uptr, char *cptr)
{
t_stat r;
r = sim_tape_attach (uptr, cptr);
if (r != SCPE_OK)
return r;
uptr->botf = 1;
uptr->eotf = 0;
return SCPE_OK;
}
t_stat mt_detach (UNIT *uptr)
{
uptr->botf = uptr->eotf = 0;
return sim_tape_detach (uptr);
}
/* Boot routine - simulate FILL console command */
t_stat mt_boot (int32 unitno, DEVICE *dptr)
{
extern uint32 P, M[];
if (unitno) /* only unit 0 */
return SCPE_ARG;
M[0] = 077777771; /* -7B */
M[1] = 007100000; /* LDX 0 */
M[2] = 000203610; /* EOM 3610B */
M[3] = 003200002; /* WIM 2 */
M[4] = 000100002; /* BRU 2 */
P = 1; /* start at 1 */
return SCPE_OK;
}
|