1. New Features in 2.10-2 The build procedures have changed. There is only one UNIX makefile. To compile without Ethernet support, simply type gmake {target|all} To compile with Ethernet support, type gmake USE_NETWORK=1 {target|all} The Mingw batch files require Mingw release 2 and invoke the Unix makefile. There are still separate batch files for compilation with or without Ethernet support. 1.1 SCP and Libraries - The EVAL command will evaluate a symbolic type-in and display it in numeric form. - The ! command (with no arguments) will launch the host operating system command shell. The ! command (with an argument) executes the argument as a host operating system command. (Code from Mark Pizzolato) - Telnet sessions now recognize BREAK. How a BREAK is transmitted dependent on the particular Telnet client. (Code from Mark Pizzolato) - The sockets library includes code for active connections as well as listening connections. - The RESTORE command will restore saved memory size, if the simulator supports dynamic memory resizing. 1.2 PDP-1 - The PDP-1 supports the Type 24 serial drum (based on recently discovered documents). 1.3 18b PDP's - The PDP-4 supports the Type 24 serial drum (based on recently discovered documents). 1.4 PDP-11 - The PDP-11 implements a stub DEUNA/DELUA (XU). The real XU module will be included in a later release. 1.5 PDP-10 - The PDP-10 implements a stub DEUNA/DELUA (XU). The real XU module will be included in a later release. 1.6 HP 2100 - The IOP microinstruction set is supported for the 21MX as well as the 2100. - The HP2100 supports the Access Interprocessor Link (IPL). 1.7 VAX - If the VAX console is attached to a Telnet session, BREAK is interpreted as console halt. - The SET/SHOW HISTORY commands enable and display a history of the most recently executed instructions. (Code from Mark Pizzolato) 1.8 Terminals Multiplexors - BREAK detection was added to the HP, DEC, and Interdata terminal multiplexors. 1.9 Interdata 16b and 32b - First release. UNIX is not yet working. 1.10 SDS 940 - First release. 2. Bugs Fixed in 2.10-2 - PDP-11 console must default to 7b for early UNIX compatibility. - PDP-11/VAX TMSCP emulator was using the wrong packet length for read/write end packets. - Telnet IAC+IAC processing was fixed, both for input and output (found by Mark Pizzolato). - PDP-11/VAX Ethernet setting flag bits wrong for chained descriptors (found by Mark Pizzolato). 3. New Features in 2.10 vs prior releases 3.1 SCP and Libraries - The VT emulation package has been replaced by the capability to remote the console to a Telnet session. Telnet clients typically have more complete and robust VT100 emulation. - Simulated devices may now have statically allocated buffers, in addition to dynamically allocated buffers or disk-based data stores. - The DO command now takes substitutable arguments (max 9). In command files, %n represents substitutable argument n. - The initial command line is now interpreted as the command name and substitutable arguments for a DO command. This is backward compatible to prior versions. - The initial command line parses switches. -Q is interpreted as quiet mode; informational messages are suppressed. - The HELP command now takes an optional argument. HELP <cmd> types help on the specified command. - Hooks have been added for implementing GUI-based consoles, as well as simulator-specific command extensions. A few internal data structures and definitions have changed. - Two new routines (tmxr_open_master, tmxr_close_master) have been added to sim_tmxr.c. The calling sequence for sim_accept_conn has been changed in sim_sock.c. - The calling sequence for the VM boot routine has been modified to add an additional parameter. - SAVE now saves, and GET now restores, controller and unit flags. - Library sim_ether.c has been added for Ethernet support. 3.2 VAX - Non-volatile RAM (NVR) can behave either like a memory or like a disk-based peripheral. If unattached, it behaves like memory and is saved and restored by SAVE and RESTORE, respectively. If attached, its contents are loaded from disk by ATTACH and written back to disk at DETACH and EXIT. - SHOW <device> VECTOR displays the device's interrupt vector. A few devices allow the vector to be changed with SET <device> VECTOR=nnn. - SHOW CPU IOSPACE displays the I/O space address map. - The TK50 (TMSCP tape) has been added. - The DEQNA/DELQA (Qbus Ethernet controllers) have been added. - Autoconfiguration support has been added. - The paper tape reader has been removed from vax_stddev.c and now references a common implementation file, dec_pt.h. - Examine and deposit switches now work on all devices, not just the CPU. - Device address conflicts are not detected until simulation starts. 3.3 PDP-11 - SHOW <device> VECTOR displays the device's interrupt vector. Most devices allow the vector to be changed with SET <device> VECTOR=nnn. - SHOW CPU IOSPACE displays the I/O space address map. - The TK50 (TMSCP tape), RK611/RK06/RK07 (cartridge disk), RX211 (double density floppy), and KW11P programmable clock have been added. - The DEQNA/DELQA (Qbus Ethernet controllers) have been added. - Autoconfiguration support has been added. - The paper tape reader has been removed from pdp11_stddev.c and now references a common implementation file, dec_pt.h. - Device bootstraps now use the actual CSR specified by the SET ADDRESS command, rather than just the default CSR. Note that PDP-11 operating systems may NOT support booting with non-standard addresses. - Specifying more than 256KB of memory, or changing the bus configuration, causes all peripherals that are not compatible with the current bus configuration to be disabled. - Device address conflicts are not detected until simulation starts. 3.4 PDP-10 - SHOW <device> VECTOR displays the device's interrupt vector. A few devices allow the vector to be changed with SET <device> VECTOR=nnn. - SHOW CPU IOSPACE displays the I/O space address map. - The RX211 (double density floppy) has been added; it is off by default. - The paper tape now references a common implementation file, dec_pt.h. - Device address conflicts are not detected until simulation starts. 3.5 PDP-1 - DECtape (then known as MicroTape) support has been added. - The line printer and DECtape can be disabled and enabled. 3.6 PDP-8 - The RX28 (double density floppy) has been added as an option to the existing RX8E controller. - SHOW <device> DEVNO displays the device's device number. Most devices allow the device number to be changed with SET <device> DEVNO=nnn. - Device number conflicts are not detected until simulation starts. 3.7 IBM 1620 - The IBM 1620 simulator has been released. 3.8 AltairZ80 - A hard drive has been added for increased storage. - Several bugs have been fixed. 3.9 HP 2100 - The 12845A has been added and made the default line printer (LPT). The 12653A has been renamed LPS and is off by default. It also supports the diagnostic functions needed to run the DCPC and DMS diagnostics. - The 12557A/13210A disk defaults to the 13210A (7900/7901). - The 12559A magtape is off by default. - New CPU options (EAU/NOEAU) enable/disable the extended arithmetic instructions for the 2116. These instructions are standard on the 2100 and 21MX. - New CPU options (MPR/NOMPR) enable/disable memory protect for the 2100 and 21MX. - New CPU options (DMS/NODMS) enable/disable the dynamic mapping instructions for the 21MX. - The 12539 timebase generator autocalibrates. 3.10 Simulated Magtapes - Simulated magtapes recognize end of file and the marker 0xFFFFFFFF as end of medium. Only the TMSCP tape simulator can generate an end of medium marker. - The error handling in simulated magtapes was overhauled to be consistent through all simulators. 3.11 Simulated DECtapes - Added support for RT11 image file format (256 x 16b) to DECtapes. 4. Bugs Fixed in 2.10 vs prior releases - TS11/TSV05 was not simulating the XS0_MOT bit, causing failures under VMS. In addition, two of the CTL options were coded interchanged. - IBM 1401 tape was not setting a word mark under group mark for load mode reads. This caused the diagnostics to crash. - SCP bugs in ssh_break and set_logon were fixed (found by Dave Hittner). - Numerous bugs in the HP 2100 extended arithmetic, floating point, 21MX, DMS, and IOP instructions were fixed. Bugs were also fixed in the memory protect and DMS functions. The moving head disks (DP, DQ) were revised to simulate the hardware more accurately. Missing functions in DQ (address skip, read address) were added. - PDP-10 tape wouldn't boot, and then wouldn't read (reported by Michael Thompson and Harris Newman, respectively) - PDP-1 typewriter is half duplex, with only one shift state for both input and output (found by Derek Peschel) 5. General Notes WARNING: V2.10 has reorganized and renamed some of the definition files for the PDP-10, PDP-11, and VAX. Be sure to delete all previous source files before you unpack the Zip archive, or unpack it into a new directory structure. WARNING: V2.10 has a new, more comprehensive save file format. Restoring save files from previous releases will cause 'invalid register' errors and loss of CPU option flags, device enable/ disable flags, unit online/offline flags, and unit writelock flags. WARNING: If you are using Visual Studio .NET through the IDE, be sure to turn off the /Wp64 flag in the project settings, or dozens of spurious errors will be generated. WARNING: Compiling Ethernet support under Windows requires extra steps; see the Ethernet readme file. Ethernet support is currently available only for Windows, Linux, NetBSD, and OpenBSD.
489 lines
16 KiB
C
489 lines
16 KiB
C
/* sds_mt.c: SDS 940 magnetic tape simulator
|
||
|
||
Copyright (c) 2001-2002, 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
|
||
|
||
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"
|
||
#define MT_MAXFR (32768 * 4)
|
||
#define MT_NUMDR 8 /* number drives */
|
||
#define MT_UNIT 07
|
||
#define UNIT_V_WLK (UNIT_V_UF + 0) /* write locked */
|
||
#define UNIT_WLK (1 << UNIT_V_WLK)
|
||
#define botf u3 /* bot tape flag */
|
||
#define eotf u4 /* eot tape flag */
|
||
#define UNIT_WPRT (UNIT_WLK | UNIT_RO) /* write protect */
|
||
|
||
#define MTR_BOT 0xFFFFFFFE /* BOT pseudo mark */
|
||
|
||
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_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + UNIT_DISABLE, 0) },
|
||
{ UDATA (&mt_svc, UNIT_ATTABLE + 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, 32, 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[] = {
|
||
{ UNIT_WLK, 0, "write enabled", "WRITEENABLED", NULL },
|
||
{ UNIT_WLK, UNIT_WLK, "write locked", "LOCKED", 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) return SCPE_IERR; /* wrong chan? */
|
||
if (mt_gap) { /* in gap? */
|
||
mt_gap = 0; /* clr gap flg */
|
||
sim_cancel (uptr); } /* cancel timer */
|
||
else if (sim_is_active (uptr)) CRETIOP; /* busy? */
|
||
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)) return STOP_INVIOP; /* rw & rev? */
|
||
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) CRETIOP; /* wrong chan? */
|
||
t = inst & 07670; /* get command */
|
||
if ((t == 04010) && !sim_is_active (uptr)) { /* rewind? */
|
||
uptr->pos = uptr->eotf = 0; /* clr pos, 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)) return r; } /* end record */
|
||
break;
|
||
|
||
case IO_WREOR: /* write eor */
|
||
chan_set_flag (mt_dib.chan, CHF_EOR); /* set eor flg */
|
||
if (r = mt_wrend (inst)) return r; /* end record */
|
||
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) return SCPE_IERR; /* wrong chan? */
|
||
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 (!(uptr->flags & UNIT_WPRT)) *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)) return r; } /* err, inv reclnt? */
|
||
uptr->botf = 0; /* off BOT */
|
||
if (mt_inst & CHC_REV) chr = mtxb[--mt_bptr] & 077; /* get next rev */
|
||
else chr = mtxb[mt_bptr++] & 077; /* get next fwd */
|
||
if (!(mt_inst & CHC_BIN)) chr = bcd_to_sds[chr]; /* bcd? */
|
||
*dat = chr & 077; /* give to chan */
|
||
if ((mt_inst & CHC_REV)? (mt_bptr <= 0): /* rev or fwd, */
|
||
(mt_bptr >= mt_blnt)) mt_readend (uptr); /* recd done? */
|
||
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)) chr = sds_to_bcd[chr]; /* bcd? */
|
||
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) mt_readend (uptr); /* skip record */
|
||
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 abc, tbc;
|
||
|
||
if ((uptr->flags & UNIT_ATT) == 0) { /* attached? */
|
||
mt_set_err (uptr); /* no, err, disc */
|
||
return SCPE_UNATT; }
|
||
tbc = mt_readbc (uptr); /* get bc */
|
||
if (tbc == MTR_EOM) { /* end of med? */
|
||
uptr->eotf = 1; /* end of tape */
|
||
mt_set_err (uptr); /* err, disc */
|
||
return SCPE_OK; }
|
||
if (tbc == MTR_BOT) { /* BOT? */
|
||
mt_set_err (uptr); /* err, disc */
|
||
return SCPE_OK; }
|
||
if (tbc == MTR_TMK) { /* tape mark? */
|
||
mt_eof = 1; /* set eof flag */
|
||
mtxb[0] = mtxb[1] = 017; /* EOR char */
|
||
mt_blnt = 2; /* store 2 */
|
||
uptr->pos += sizeof (t_mtrlnt); /* update position */
|
||
return SCPE_OK; }
|
||
mt_blnt = tbc; /* set buf lnt */
|
||
if (tbc > MT_MAXFR) return SCPE_MTRLNT; /* record too long? */
|
||
if (mt_inst & CHC_REV) { /* reverse? */
|
||
fseek (uptr->fileref, uptr->pos - ((tbc + 1) & ~1) - sizeof (t_mtrlnt), SEEK_SET);
|
||
mt_bptr = mt_blnt; }
|
||
abc = fxread (mtxb, sizeof (uint8), tbc, uptr->fileref);/* read record */
|
||
for (; abc < tbc; abc++) mtxb[abc] = 0; /* zero fill */
|
||
if (ferror (uptr->fileref)) { /* I/O error */
|
||
mt_set_err (uptr); /* no, err, disc */
|
||
perror ("MT I/O error");
|
||
clearerr (uptr->fileref);
|
||
return SCPE_IOERR; }
|
||
if (mt_inst & CHC_REV) /* update pos */
|
||
uptr->pos -= (((tbc + 1) & ~1) + (2 * sizeof (t_mtrlnt)));
|
||
else uptr->pos += (((tbc + 1) & ~1) + (2 * sizeof (t_mtrlnt)));
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* Read record byte count */
|
||
|
||
t_mtrlnt mt_readbc (UNIT *uptr)
|
||
{
|
||
t_mtrlnt tbc;
|
||
|
||
if (mt_inst & CHC_REV) {
|
||
if (uptr->pos < sizeof (t_mtrlnt)) {
|
||
uptr->botf = 1;
|
||
return MTR_BOT; }
|
||
fseek (uptr->fileref, uptr->pos - sizeof (t_mtrlnt), SEEK_SET); }
|
||
else fseek (uptr->fileref, uptr->pos, SEEK_SET);
|
||
fxread (&tbc, sizeof (t_mtrlnt), 1, uptr->fileref);
|
||
if (ferror (uptr->fileref) || feof (uptr->fileref) || /* err, eof, eom? */
|
||
(tbc == MTR_EOM)) return MTR_EOM; /* return EOM */
|
||
if (MTRF (tbc)) chan_set_flag (mt_dib.chan, CHF_ERR); /* rec err? set flag */
|
||
return MTRL (tbc);
|
||
}
|
||
|
||
/* 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) chan_disc (mt_dib.chan); /* EOF? */
|
||
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)
|
||
{
|
||
static t_mtrlnt bceom = MTR_EOM;
|
||
static t_mtrlnt bceof = MTR_TMK;
|
||
UNIT *uptr = mt_dev.units + (dev & MT_UNIT);
|
||
t_addr old_pos = uptr->pos;
|
||
t_mtrlnt tbc;
|
||
|
||
sim_cancel (uptr); /* no more xfr's */
|
||
if (mt_bptr == 0) return SCPE_OK; /* buf empty? */
|
||
if (!(uptr->flags & UNIT_ATT)) { /* attached? */
|
||
mt_set_err (uptr); /* no, err, disc */
|
||
return SCPE_UNATT; }
|
||
if (uptr->flags & UNIT_WPRT) { /* write lock? */
|
||
mt_set_err (uptr); /* yes, err, disc */
|
||
return SCPE_OK; }
|
||
if (dev & DEV_MTS) { /* erase? */
|
||
if (mt_inst & CHC_REV) { /* reverse? */
|
||
tbc = mt_readbc (uptr); /* get bc */
|
||
if ((tbc == MTR_TMK) || (tbc == MTR_EOM)) /* tmk, eom? */
|
||
fseek (uptr->fileref, uptr->pos -= sizeof (t_mtrlnt), SEEK_SET);
|
||
else if (tbc != MTR_BOT) { /* not BOT? */
|
||
tbc = MTRL (tbc); /* clear error */
|
||
fseek (uptr->fileref, uptr->pos -=
|
||
(((tbc + 1) & ~1) - sizeof (t_mtrlnt)), SEEK_SET); } }
|
||
fxwrite (&bceom, sizeof (t_mtrlnt), 1, uptr->fileref);
|
||
}
|
||
else {
|
||
fseek (uptr->fileref, uptr->pos, SEEK_SET); /* set position */
|
||
if ((mt_bptr == 1) && (mtxb[0] == 017) && /* wr eof? */
|
||
((mt_inst & 01670) == 00050)) {
|
||
fxwrite (&bceof, sizeof (t_mtrlnt), 1, uptr->fileref);
|
||
uptr->pos += sizeof (t_mtrlnt); }
|
||
else { /* normal wr */
|
||
fxwrite (&mt_bptr, sizeof (t_mtrlnt), 1, uptr->fileref);
|
||
fxwrite (mtxb, sizeof (uint8), (mt_bptr + 1) & ~1, uptr->fileref);
|
||
fxwrite (&mt_bptr, sizeof (t_mtrlnt), 1, uptr->fileref);
|
||
uptr->pos += ((mt_bptr + 1) & ~1) + (2 * sizeof (t_mtrlnt));
|
||
}
|
||
}
|
||
mt_bptr = 0;
|
||
if (ferror (uptr->fileref)) { /* I/O error */
|
||
uptr->pos = old_pos; /* restore pos */
|
||
mt_set_err (uptr); /* no, err, disc */
|
||
perror ("MT I/O error");
|
||
clearerr (uptr->fileref);
|
||
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]);
|
||
mt_unit[i].eotf = 0; }
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* Attach and detach routines */
|
||
|
||
t_stat mt_attach (UNIT *uptr, char *cptr)
|
||
{
|
||
t_stat r;
|
||
|
||
r = attach_unit (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 detach_unit (uptr);
|
||
}
|
||
|
||
/* Boot routine - simulate FILL console command */
|
||
|
||
t_stat mt_boot (int32 unitno, DEVICE *dptr)
|
||
{
|
||
extern uint32 P, M[];
|
||
|
||
if (unitno) return SCPE_ARG; /* only unit 0 */
|
||
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;
|
||
}
|