RESTRICTION: The FP15 and XVM features of the PDP-15 are only partially debugged. Do NOT enable these features for normal operations. 1. New Features in 3.1-0 1.1 SCP and libraries - Added simulated Ethernet support for VMS, FreeBSD, Mac OS/X. - Added status return to tmxr_putc_ln. - Added sim_putchar_s to handle possible output stalls. 1.2 All DECtapes - Added "DECtape off reel" error stop. 1.3 All Asynchronous Consoles - Added support for output congestion stall if using a Telnet connection. 1.4 PDP-1 - Added Type 23 parallel drum support. 1.5 PDP-8 - Added instruction history. - Added TSC8-75 option support for ETOS. - Added TD8E DECtape support. 1.6 PDP-18b - Added instruction history. - Changed PDP-9, PDP-15 API default to enabled. 1.7 PDP-11 - Added support for 18b only Qbus devices. - Formalized bus and addressing definitions. - Added control to enable/disable autoconfiguration. - Added stub support for second Unibus Ethernet controller. 1.7 Interdata 32b - Added instruction history. 1.8 Eclipse - Added floating point support. - Added programmable interval timer support. 1.9 H316 - Added DMA/DMC support. - Added fixed head disk support. - Added moving head disk support. - Added magtape support. 1.10 IBM 1130 (Brian Knittel) - Added support for physical card reader, using the Cardread interface (www.ibm1130.org/sim/downloads). - Added support for physical printer (flushes output buffer after each line). 2. Bugs Fixed in 3.1-0 2.1 SCP and libraries - Fixed numerous bugs in Ethernet library. 2.2 All DECtapes - Fixed reverse checksum value in 'read all' mode. - Simplified (and sped up) timing. 2.3 PDP-8 - Fixed bug in RX28 read status (found by Charles Dickman). - Fixed RX28 double density write. 2.4 PDP-18b - Fixed autoincrement bug in PDP-4, PDP-7, PDP-9. 2.5 PDP-11/VAX - Revised RQ MB->LBN conversion for greater accuracy. - Fixed bug in IO configuration (found by David Hittner). - Fixed bug with multiple RQ RAUSER drives. - Fixed bug in second Qbus Ethernet controller interrupts. 2.6 Nova/Eclipse - Fixed bugs in DKP flag clear, map setup, map usage (Charles Owen). - Fixed bug in MT, reset completes despite I/O reset (Charles Owen). - Fixed bug in MT, space operations return word count (Charles Owen). 2.7 IBM 1130 (Brian Knittel) - Fixed bug in setting carry bit in subtract and subtract double. - Fixed timing problem in console printer simulation. 2.8 1620 - Fixed bug in branch digit (found by Dave Babcock). 3. New Features in 3.0 vs prior releases 3.1 SCP and Libraries - Added ASSIGN/DEASSIGN (logical name) commands. - Changed RESTORE to unconditionally detach files. - Added E11 and TPC format support to magtape library. - Fixed bug in SHOW CONNECTIONS. - Added USE_ADDR64 support. 3.2 All magtapes - Magtapes support SIMH format, E11 format, and TPC format (read only). - SET <tape_unit> FORMAT=format sets the specified tape unit's format. - SHOW <tape_unit> FORMAT displays the specified tape unit's format. - Tape format can also be set as part of the ATTACH command, using the -F switch. 3.3 VAX - VAX can be compiled without USE_INT64. - If compiled with USE_INT64 and USE_ADDR64, RQ and TQ controllers support files > 2GB. - VAX ROM has speed control (SET ROM DELAY/NODELAY). 3.4 PDP-1 - Added block loader format support to LOAD. - Changed BOOT PTR to allow loading of all of the first bank of memory. - The LOAD command takes an optional argument specifying the memory field to be loaded. - The PTR BOOT command takes its starting memory field from the TA (address switch) register. 3.5 PDP-18b Family - Added PDP-4 EAE support. - Added PDP-15 FP15 support. - Added PDP-15 XVM support. - Added PDP-15 "re-entrancy ECO". - Added PDP-7, PDP-9, PDP-15 hardware RIM loader support in BOOT PTR. 4. Bugs Fixed in 3.0 vs prior releases 4.1 SCP and Libraries - Fixed end of file problem in dep, idep. - Fixed handling of trailing spaces in dep, idep. 4.2 VAX - Fixed CVTfi bug: integer overflow not set if exponent out of range - Fixed EMODx bugs: o First and second operands reversed o Separated fraction received wrong exponent o Overflow calculation on separated integer incorrect o Fraction not set to zero if exponent out of range - Fixed interval timer and ROM access to pass power-up self-test even on very fast host processors (fixes from Mark Pizzolato). - Fixed bug in user disk size (found by Chaskiel M Grundman). 4.3 1401 - Fixed mnemonic, instruction lengths, and reverse scan length check bug for MCS. - Fixed MCE bug, BS off by 1 if zero suppress. - Fixed chaining bug, D lost if return to SCP. - Fixed H branch, branch occurs after continue. - Added check for invalid 8 character MCW, LCA. - Fixed magtape load-mode end of record response. - Revised fetch to model hardware more closely. - Fixed tape read end-of-record handling based on real 1401. - Added diagnostic read (space forward). 4.4 Nova - Fixed DSK variable size interaction with restore. - Fixed bug in DSK set size routine. 4.5 PDP-1 - Fixed DT variable size interaction with restore. - Updated CPU, line printer, standard devices to detect indefinite I/O wait. - Fixed incorrect logical, missing activate, break in drum simulator. - Fixed bugs in instruction decoding, overprinting for line printer. - Fixed system hang if continue after PTR error. - Fixed PTR to start/stop on successive rpa instructions. 4.6 PDP-11 - Fixed DT variable size interaction with restore. - Fixed bug in MMR1 update (found by Tim Stark). - Added XQ features and fixed bugs: o Corrected XQ interrupts on IE state transition (code by Tom Evans). o Added XQ interrupt clear on soft reset. o Removed XQ interrupt when setting XL or RL (multiple people). o Added SET/SHOW XQ STATS. o Added SHOW XQ FILTERS. o Added ability to split received packet into multiple buffers. o Added explicit runt and giant packet processing. - Fixed bug in user disk size (found by Chaskiel M Grundman). 4.7 PDP-18B - Fixed DT, RF variable size interaction with restore. - Fixed MT bug in MTTR. - Fixed bug in PDP-4 line printer overprinting. - Fixed bug in PDP-15 memory protect/skip interaction. - Fixed bug in RF set size routine. - Increased PTP TIME for PDP-15 operating systems. - Fixed priorities in PDP-15 API (differs from PDP-9). - Fixed sign handling in PDP-15 EAE unsigned mul/div (differs from PDP-9). - Fixed bug in CAF, clears API subsystem. 4.8 PDP-8 - Fixed DT, DF, RF, RX variable size interaction with restore. - Fixed MT bug in SKTR. - Fixed bug in DF, RF set size routine. 4.9 HP2100 - Fixed bug in DP (13210A controller only), DQ read status. - Fixed bug in DP, DQ seek complete. - Fixed DR drum sizes. - Fixed DR variable capacity interaction with SAVE/RESTORE. 4.10 GRI - Fixed bug in SC queue pointer management. 4.11 PDP-10 - Fixed bug in RP read header. 4.12 Ibm1130 - Fixed bugs found by APL 1130. 4.13 Altairz80 - Fixed bug in real-time clock on Windows host. 4.14 1620 - Fixed bug in immediate index add (found by Michael Short).
601 lines
21 KiB
C
601 lines
21 KiB
C
/* nova_mta.c: NOVA magnetic tape simulator
|
||
|
||
Copyright (c) 1993-2003, 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.
|
||
|
||
mta magnetic tape
|
||
|
||
22-Nov-03 CEO DIB returns # records skipped after space fwd
|
||
22-Nov-03 CEO Removed cancel of tape events in IORST
|
||
25-Apr-03 RMS Revised for extended file support
|
||
28-Mar-03 RMS Added multiformat support
|
||
28-Feb-03 RMS Revised for magtape library
|
||
30-Oct-02 RMS Fixed BOT handling, added error record handling
|
||
08-Oct-02 RMS Added DIB
|
||
30-Sep-02 RMS Revamped error handling
|
||
28-Aug-02 RMS Added end of medium support
|
||
30-May-02 RMS Widened POS to 32b
|
||
22-Apr-02 RMS Added maximum record length test
|
||
06-Jan-02 RMS Revised enable/disable support
|
||
30-Nov-01 RMS Added read only unit, extended SET/SHOW support
|
||
24-Nov-01 RMS Changed POS, USTAT, FLG to an array
|
||
26-Apr-01 RMS Added device enable/disable support
|
||
18-Apr-01 RMS Changed to rewind tape before boot
|
||
10-Dec-00 RMS Added Eclipse support from Charles Owen
|
||
15-Oct-00 RMS Editorial changes
|
||
11-Nov-98 CEO Removed clear of mta_ma on iopC
|
||
04-Oct-98 RMS V2.4 magtape format
|
||
18-Jan-97 RMS V2.3 magtape format
|
||
29-Jun-96 RMS Added unit enable/disable support
|
||
|
||
Magnetic tapes are represented as a series of variable records
|
||
of the form:
|
||
|
||
32b byte count byte count is little endian
|
||
byte 0
|
||
byte 1
|
||
:
|
||
byte n-2
|
||
byte n-1
|
||
32b byte count
|
||
|
||
If the byte count is odd, the record is padded with an extra byte
|
||
of junk. File marks are represented by a byte count of 0 and are
|
||
not duplicated; end of tape by end of file.
|
||
*/
|
||
|
||
#include "nova_defs.h"
|
||
#include "sim_tape.h"
|
||
|
||
#define MTA_NUMDR 8 /* #drives */
|
||
#define USTAT u3 /* unit status */
|
||
#define MTA_MAXFR (1 << 16) /* max record lnt */
|
||
#define WC_SIZE (1 << 14) /* max word count */
|
||
#define WC_MASK (WC_SIZE - 1)
|
||
|
||
/* Command/unit */
|
||
|
||
#define CU_CI 0100000 /* clear interrupt */
|
||
#define CU_EP 0002000 /* poll enable */
|
||
#define CU_DE 0001000 /* disable erase */
|
||
#define CU_DA 0000400 /* disable autoretry */
|
||
#define CU_PE 0000400 /* PE mode */
|
||
#define CU_V_CMD 3 /* command */
|
||
#define CU_M_CMD 027
|
||
#define CU_READ 000
|
||
#define CU_REWIND 001
|
||
#define CU_CMODE 002
|
||
#define CU_SPACEF 003
|
||
#define CU_SPACER 004
|
||
#define CU_WRITE 005
|
||
#define CU_WREOF 006
|
||
#define CU_ERASE 007
|
||
#define CU_READNS 020
|
||
#define CU_UNLOAD 021
|
||
#define CU_DMODE 022
|
||
#define CU_V_UNIT 0 /* unit */
|
||
#define CU_M_UNIT 07
|
||
#define GET_CMD(x) (((x) >> CU_V_CMD) & CU_M_CMD)
|
||
#define GET_UNIT(x) (((x) >> CU_V_UNIT) & CU_M_UNIT)
|
||
|
||
/* Status 1 - stored in mta_sta<31:16> or (*) uptr->USTAT<31:16> */
|
||
|
||
#define STA_ERR1 (0100000u << 16) /* error */
|
||
#define STA_DLT (0040000 << 16) /* data late */
|
||
#define STA_REW (0020000 << 16) /* *rewinding */
|
||
#define STA_ILL (0010000 << 16) /* illegal */
|
||
#define STA_HDN (0004000 << 16) /* high density */
|
||
#define STA_DAE (0002000 << 16) /* data error */
|
||
#define STA_EOT (0001000 << 16) /* *end of tape */
|
||
#define STA_EOF (0000400 << 16) /* *end of file */
|
||
#define STA_BOT (0000200 << 16) /* *start of tape */
|
||
#define STA_9TK (0000100 << 16) /* nine track */
|
||
#define STA_BAT (0000040 << 16) /* bad tape */
|
||
#define STA_CHG (0000010 << 16) /* status change */
|
||
#define STA_WLK (0000004 << 16) /* *write lock */
|
||
#define STA_ODD (0000002 << 16) /* odd character */
|
||
#define STA_RDY (0000001 << 16) /* *drive ready */
|
||
|
||
/* Status 2 - stored in mta_sta<15:0> or (*) uptr->USTAT<15:0> */
|
||
|
||
#define STA_ERR2 0100000 /* error */
|
||
#define STA_RWY 0040000 /* runaway tape */
|
||
#define STA_FGP 0020000 /* false gap */
|
||
#define STA_CDL 0004000 /* corrected dlt */
|
||
#define STA_V_UNIT 8
|
||
#define STA_M_UNIT 07 /* unit */
|
||
#define STA_WCO 0000200 /* word count ovflo */
|
||
#define STA_BDS 0000100 /* bad signal */
|
||
#define STA_OVS 0000040 /* overskew */
|
||
#define STA_CRC 0000020 /* check error */
|
||
#define STA_STE 0000010 /* single trk error */
|
||
#define STA_FPR 0000004 /* false preamble */
|
||
#define STA_FMT 0000002 /* format error */
|
||
#define STA_PEM 0000001 /* *PE mode */
|
||
|
||
#define STA_EFLGS1 (STA_DLT | STA_ILL | STA_DAE | STA_EOT | \
|
||
STA_EOF | STA_BOT | STA_BAT | STA_ODD)
|
||
#define STA_EFLGS2 (STA_FGP | STA_CDL | STA_BDS | STA_OVS | \
|
||
STA_CRC | STA_FPR | STA_FPR) /* set error 2 */
|
||
#define STA_CLR ((020 << 16) | 0010000) /* always clear */
|
||
#define STA_SET (STA_HDN | STA_9TK) /* always set */
|
||
#define STA_DYN (STA_REW | STA_EOT | STA_EOF | STA_BOT | \
|
||
STA_WLK | STA_RDY | STA_PEM) /* kept in USTAT */
|
||
#define STA_MON (STA_REW | STA_BOT | STA_WLK | STA_RDY | \
|
||
STA_PEM) /* set status chg */
|
||
|
||
extern uint16 M[];
|
||
extern UNIT cpu_unit;
|
||
extern int32 int_req, dev_busy, dev_done, dev_disable;
|
||
|
||
int32 mta_ma = 0; /* memory address */
|
||
int32 mta_wc = 0; /* word count */
|
||
int32 mta_cu = 0; /* command/unit */
|
||
int32 mta_sta = 0; /* status register */
|
||
int32 mta_ep = 0; /* enable polling */
|
||
int32 mta_cwait = 100; /* command latency */
|
||
int32 mta_rwait = 100; /* record latency */
|
||
uint8 *mtxb = NULL; /* transfer buffer */
|
||
|
||
DEVICE mta_dev;
|
||
int32 mta (int32 pulse, int32 code, int32 AC);
|
||
t_stat mta_svc (UNIT *uptr);
|
||
t_stat mta_reset (DEVICE *dptr);
|
||
t_stat mta_boot (int32 unitno, DEVICE *dptr);
|
||
t_stat mta_attach (UNIT *uptr, char *cptr);
|
||
t_stat mta_detach (UNIT *uptr);
|
||
int32 mta_updcsta (UNIT *uptr);
|
||
void mta_upddsta (UNIT *uptr, int32 newsta);
|
||
t_stat mta_map_err (UNIT *uptr, t_stat st);
|
||
t_stat mta_vlock (UNIT *uptr, int32 val, char *cptr, void *desc);
|
||
|
||
static const int ctype[32] = { /* c vs r timing */
|
||
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
|
||
0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 };
|
||
|
||
/* MTA data structures
|
||
|
||
mta_dev MTA device descriptor
|
||
mta_unit MTA unit list
|
||
mta_reg MTA register list
|
||
mta_mod MTA modifier list
|
||
*/
|
||
|
||
DIB mta_dib = { DEV_MTA, INT_MTA, PI_MTA, &mta };
|
||
|
||
UNIT mta_unit[] = {
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) },
|
||
{ UDATA (&mta_svc, UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE, 0) } };
|
||
|
||
REG mta_reg[] = {
|
||
{ ORDATA (CU, mta_cu, 16) },
|
||
{ ORDATA (MA, mta_ma, 16) },
|
||
{ ORDATA (WC, mta_wc, 16) },
|
||
{ GRDATA (STA1, mta_sta, 8, 16, 16) },
|
||
{ ORDATA (STA2, mta_sta, 16) },
|
||
{ FLDATA (EP, mta_ep, 0) },
|
||
{ FLDATA (BUSY, dev_busy, INT_V_MTA) },
|
||
{ FLDATA (DONE, dev_done, INT_V_MTA) },
|
||
{ FLDATA (DISABLE, dev_disable, INT_V_MTA) },
|
||
{ FLDATA (INT, int_req, INT_V_MTA) },
|
||
{ DRDATA (CTIME, mta_cwait, 24), PV_LEFT },
|
||
{ DRDATA (RTIME, mta_rwait, 24), PV_LEFT },
|
||
{ URDATA (UST, mta_unit[0].USTAT, 8, 32, 0, MTA_NUMDR, 0) },
|
||
{ URDATA (POS, mta_unit[0].pos, 8, T_ADDR_W, 0,
|
||
MTA_NUMDR, REG_RO | PV_LEFT) },
|
||
{ NULL } };
|
||
|
||
MTAB mta_mod[] = {
|
||
{ MTUF_WLK, 0, "write enabled", "WRITEENABLED", &mta_vlock },
|
||
{ MTUF_WLK, MTUF_WLK, "write locked", "LOCKED", &mta_vlock },
|
||
{ MTAB_XTD|MTAB_VUN, 0, "FORMAT", "FORMAT",
|
||
&sim_tape_set_fmt, &sim_tape_show_fmt, NULL },
|
||
{ 0 } };
|
||
|
||
DEVICE mta_dev = {
|
||
"MT", mta_unit, mta_reg, mta_mod,
|
||
MTA_NUMDR, 10, 31, 1, 8, 8,
|
||
NULL, NULL, &mta_reset,
|
||
&mta_boot, &mta_attach, &mta_detach,
|
||
&mta_dib, DEV_DISABLE };
|
||
|
||
/* IOT routine */
|
||
|
||
int32 mta (int32 pulse, int32 code, int32 AC)
|
||
{
|
||
UNIT *uptr;
|
||
int32 u, c, rval;
|
||
|
||
rval = 0;
|
||
uptr = mta_dev.units + GET_UNIT(mta_cu); /* get unit */
|
||
switch (code) { /* decode IR<5:7> */
|
||
case ioDIA: /* DIA */
|
||
rval = (mta_updcsta (uptr) >> 16) & DMASK; /* return status 1 */
|
||
break;
|
||
case ioDOA: /* DOA */
|
||
/* if (AC & CU_CI) ... clear ep int */
|
||
mta_cu = AC; /* save cmd/unit */
|
||
uptr = mta_dev.units + GET_UNIT(mta_cu); /* get unit */
|
||
mta_updcsta (uptr); /* update status */
|
||
break;
|
||
case ioDIB: /* DIB */
|
||
rval = mta_ma & AMASK; /* return ma */
|
||
break;
|
||
case ioDOB: /* DOB */
|
||
mta_ma = AC & AMASK; /* save ma */
|
||
break;
|
||
case ioDIC: /* DIC */
|
||
rval = mta_updcsta (uptr) & DMASK; /* return status 2 */
|
||
break;
|
||
case ioDOC: /* DOC */
|
||
mta_wc = ((AC & 040000) << 1) | (AC & 077777); /* save wc */
|
||
break; } /* end switch code */
|
||
|
||
/* IOT, continued */
|
||
|
||
switch (pulse) { /* decode IR<8:9> */
|
||
case iopS: /* start */
|
||
c = GET_CMD (mta_cu); /* get command */
|
||
if (dev_busy & INT_MTA) break; /* ignore if busy */
|
||
if ((uptr->USTAT & STA_RDY) == 0) { /* drive not ready? */
|
||
mta_sta = mta_sta | STA_ILL; /* illegal op */
|
||
dev_busy = dev_busy & ~INT_MTA; /* clear busy */
|
||
dev_done = dev_done | INT_MTA; /* set done */
|
||
int_req = (int_req & ~INT_DEV) | (dev_done & ~dev_disable); }
|
||
else if ((c == CU_REWIND) || (c == CU_UNLOAD)) { /* rewind, unload? */
|
||
mta_upddsta (uptr, (uptr->USTAT & /* update status */
|
||
~(STA_BOT | STA_EOF | STA_EOT | STA_RDY)) | STA_REW);
|
||
sim_activate (uptr, mta_rwait); /* start IO */
|
||
if (c == CU_UNLOAD) detach_unit (uptr); }
|
||
else {
|
||
mta_sta = 0; /* clear errors */
|
||
dev_busy = dev_busy | INT_MTA; /* set busy */
|
||
dev_done = dev_done & ~INT_MTA; /* clear done */
|
||
int_req = int_req & ~INT_MTA; /* clear int */
|
||
if (ctype[c]) sim_activate (uptr, mta_cwait);
|
||
else {
|
||
mta_upddsta (uptr, uptr->USTAT &
|
||
~(STA_BOT | STA_EOF | STA_EOT | STA_RDY));
|
||
sim_activate (uptr, mta_rwait); } }
|
||
mta_updcsta (uptr); /* update status */
|
||
break;
|
||
case iopC: /* clear */
|
||
for (u = 0; u < MTA_NUMDR; u++) { /* loop thru units */
|
||
uptr = mta_dev.units + u; /* cancel IO */
|
||
if (sim_is_active (uptr) && !(uptr->USTAT & STA_REW)) {
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
sim_cancel (uptr); } }
|
||
dev_busy = dev_busy & ~INT_MTA; /* clear busy */
|
||
dev_done = dev_done & ~INT_MTA; /* clear done */
|
||
int_req = int_req & ~INT_MTA; /* clear int */
|
||
mta_sta = mta_cu = 0; /* clear registers */
|
||
mta_updcsta (&mta_unit[0]); /* update status */
|
||
break; } /* end case pulse */
|
||
return rval;
|
||
}
|
||
|
||
/* Unit service
|
||
|
||
If rewind done, reposition to start of tape, set status
|
||
else, do operation, clear busy, set done, interrupt
|
||
*/
|
||
|
||
t_stat mta_svc (UNIT *uptr)
|
||
{
|
||
int32 c, p, pa, u;
|
||
t_mtrlnt i, cbc, tbc, wc;
|
||
uint16 c1, c2;
|
||
t_stat st, r = SCPE_OK;
|
||
|
||
u = uptr - mta_dev.units; /* get unit number */
|
||
c = GET_CMD (mta_cu); /* command */
|
||
wc = WC_SIZE - (mta_wc & WC_MASK); /* io wc */
|
||
|
||
if (uptr->USTAT & STA_REW) { /* rewind? */
|
||
sim_tape_rewind (uptr); /* update tape */
|
||
mta_upddsta (uptr, (uptr->USTAT & ~STA_REW) | STA_BOT | STA_RDY);
|
||
if (u == GET_UNIT (mta_cu)) mta_updcsta (uptr);
|
||
return SCPE_OK; }
|
||
|
||
if ((uptr->flags & UNIT_ATT) == 0) { /* not attached? */
|
||
mta_upddsta (uptr, 0); /* unit off line */
|
||
mta_sta = mta_sta | STA_ILL; } /* illegal operation */
|
||
else switch (c) { /* case on command */
|
||
|
||
case CU_CMODE: /* controller mode */
|
||
mta_ep = mta_cu & CU_EP;
|
||
break;
|
||
case CU_DMODE: /* drive mode */
|
||
if (!sim_tape_bot (uptr)) mta_sta = mta_sta | STA_ILL; /* must be BOT */
|
||
else mta_upddsta (uptr, (mta_cu & CU_PE)? /* update drv status */
|
||
uptr->USTAT | STA_PEM: uptr->USTAT & ~ STA_PEM);
|
||
break;
|
||
|
||
/* Unit service, continued */
|
||
|
||
case CU_READ: /* read */
|
||
case CU_READNS: /* read non-stop */
|
||
st = sim_tape_rdrecf (uptr, mtxb, &tbc, MTA_MAXFR); /* read rec */
|
||
if (st == MTSE_RECE) mta_sta = mta_sta | STA_DAE; /* rec in err? */
|
||
else if (st != MTSE_OK) { /* other error? */
|
||
r = mta_map_err (uptr, st); /* map error */
|
||
break; }
|
||
cbc = wc * 2; /* expected bc */
|
||
if (tbc & 1) mta_sta = mta_sta | STA_ODD; /* odd byte count? */
|
||
if (tbc > cbc) mta_sta = mta_sta | STA_WCO; /* too big? */
|
||
else {
|
||
cbc = tbc; /* no, use it */
|
||
wc = (cbc + 1) / 2; } /* adjust wc */
|
||
for (i = p = 0; i < wc; i++) { /* copy buf to mem */
|
||
c1 = mtxb[p++];
|
||
c2 = mtxb[p++];
|
||
pa = MapAddr (0, mta_ma); /* map address */
|
||
if (MEM_ADDR_OK (pa)) M[pa] = (c1 << 8) | c2;
|
||
mta_ma = (mta_ma + 1) & AMASK; }
|
||
mta_wc = (mta_wc + wc) & DMASK;
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
break;
|
||
|
||
case CU_WRITE: /* write */
|
||
tbc = wc * 2; /* io byte count */
|
||
for (i = p = 0; i < wc; i++) { /* copy to buffer */
|
||
pa = MapAddr (0, mta_ma); /* map address */
|
||
mtxb[p++] = (M[pa] >> 8) & 0377;
|
||
mtxb[p++] = M[pa] & 0377;
|
||
mta_ma = (mta_ma + 1) & AMASK; }
|
||
if (st = sim_tape_wrrecf (uptr, mtxb, tbc)) { /* write rec, err? */
|
||
r = mta_map_err (uptr, st); /* map error */
|
||
mta_ma = (mta_ma - wc) & AMASK; } /* restore wc */
|
||
else mta_wc = 0; /* clear wc */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
break;
|
||
|
||
/* Unit service, continued */
|
||
|
||
case CU_WREOF: /* write eof */
|
||
if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */
|
||
r = mta_map_err (uptr, st); /* map error */
|
||
else mta_upddsta (uptr, uptr->USTAT | STA_EOF | STA_RDY);
|
||
break;
|
||
|
||
case CU_ERASE: /* erase */
|
||
if (sim_tape_wrp (uptr)) /* write protected? */
|
||
r = mta_map_err (uptr, MTSE_WRP); /* map error */
|
||
else mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
break;
|
||
|
||
case CU_SPACEF: /* space forward */
|
||
do {
|
||
mta_wc = (mta_wc + 1) & DMASK; /* incr wc */
|
||
if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */
|
||
r = mta_map_err (uptr, st); /* map error */
|
||
break; }
|
||
}
|
||
while (mta_wc != 0);
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
mta_ma = mta_wc; /* Word count = # records */
|
||
break;
|
||
|
||
case CU_SPACER: /* space reverse */
|
||
do {
|
||
mta_wc = (mta_wc + 1) & DMASK; /* incr wc */
|
||
if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */
|
||
r = mta_map_err (uptr, st); /* map error */
|
||
break; }
|
||
}
|
||
while (mta_wc != 0);
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
mta_ma = mta_wc; /* Word count = # records */
|
||
break;
|
||
|
||
default: /* reserved */
|
||
mta_sta = mta_sta | STA_ILL;
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY);
|
||
break; } /* end case */
|
||
|
||
mta_updcsta (uptr); /* update status */
|
||
dev_busy = dev_busy & ~INT_MTA; /* clear busy */
|
||
dev_done = dev_done | INT_MTA; /* set done */
|
||
int_req = (int_req & ~INT_DEV) | (dev_done & ~dev_disable);
|
||
return r;
|
||
}
|
||
|
||
/* Update controller status */
|
||
|
||
int32 mta_updcsta (UNIT *uptr) /* update ctrl */
|
||
{
|
||
mta_sta = (mta_sta & ~(STA_DYN | STA_CLR | STA_ERR1 | STA_ERR2)) |
|
||
(uptr->USTAT & STA_DYN) | STA_SET;
|
||
if (mta_sta & STA_EFLGS1) mta_sta = mta_sta | STA_ERR1;
|
||
if (mta_sta & STA_EFLGS2) mta_sta = mta_sta | STA_ERR2;
|
||
return mta_sta;
|
||
}
|
||
|
||
/* Update drive status */
|
||
|
||
void mta_upddsta (UNIT *uptr, int32 newsta) /* drive status */
|
||
{
|
||
int32 change;
|
||
|
||
if ((uptr->flags & UNIT_ATT) == 0) newsta = 0; /* offline? */
|
||
change = (uptr->USTAT ^ newsta) & STA_MON; /* changes? */
|
||
uptr->USTAT = newsta & STA_DYN; /* update status */
|
||
if (change) {
|
||
/* if (mta_ep) { /* if polling */
|
||
/* u = uptr - mta_dev.units; /* unit num */
|
||
/* mta_sta = (mta_sta & ~STA_UNIT) | (u << STA_V_UNIT);
|
||
/* set polling interupt... } */
|
||
mta_sta = mta_sta | STA_CHG; } /* flag change */
|
||
return;
|
||
}
|
||
|
||
/* Map tape error status */
|
||
|
||
t_stat mta_map_err (UNIT *uptr, t_stat st)
|
||
{
|
||
switch (st) {
|
||
case MTSE_FMT: /* illegal fmt */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_WLK | STA_RDY);
|
||
case MTSE_UNATT: /* unattached */
|
||
mta_sta = mta_sta | STA_ILL;
|
||
case MTSE_OK: /* no error */
|
||
return SCPE_IERR; /* never get here! */
|
||
case MTSE_TMK: /* end of file */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY | STA_EOF);
|
||
break;
|
||
case MTSE_IOERR: /* IO error */
|
||
mta_sta = mta_sta | STA_DAE; /* data error */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY); /* ready */
|
||
return SCPE_IOERR;
|
||
case MTSE_INVRL: /* invalid rec lnt */
|
||
mta_sta = mta_sta | STA_DAE; /* data error */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY); /* ready */
|
||
return SCPE_MTRLNT;
|
||
case MTSE_RECE: /* record in error */
|
||
mta_sta = mta_sta | STA_DAE; /* data error */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY); /* ready */
|
||
break;
|
||
case MTSE_EOM: /* end of medium */
|
||
mta_sta = mta_sta | STA_BAT; /* bad tape */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY); /* ready */
|
||
break;
|
||
case MTSE_BOT: /* reverse into BOT */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_RDY | STA_BOT);
|
||
break;
|
||
case MTSE_WRP: /* write protect */
|
||
mta_upddsta (uptr, uptr->USTAT | STA_WLK | STA_RDY);
|
||
mta_sta = mta_sta | STA_ILL; /* illegal operation */
|
||
break; }
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* Reset routine */
|
||
|
||
t_stat mta_reset (DEVICE *dptr)
|
||
{
|
||
int32 u;
|
||
UNIT *uptr;
|
||
|
||
dev_busy = dev_busy & ~INT_MTA; /* clear busy */
|
||
dev_done = dev_done & ~INT_MTA; /* clear done, int */
|
||
int_req = int_req & ~INT_MTA;
|
||
mta_cu = mta_wc = mta_ma = mta_sta = 0; /* clear registers */
|
||
mta_ep = 0;
|
||
|
||
/* AOS Installer does an IORST after a tape rewind command but before it can
|
||
be serviced, yet expects the tape to have been rewound */
|
||
|
||
for (u = 0; u < MTA_NUMDR; u++) { /* loop thru units */
|
||
uptr = mta_dev.units + u;
|
||
if (sim_is_active (uptr) && /* active and */
|
||
(uptr->flags & STA_REW)) /* rewinding? */
|
||
sim_tape_rewind (uptr); /* update tape */
|
||
sim_tape_reset (uptr); /* clear pos flag */
|
||
sim_cancel (uptr); /* cancel activity */
|
||
if (uptr->flags & UNIT_ATT) uptr->USTAT = STA_RDY |
|
||
(uptr->USTAT & STA_PEM) |
|
||
(sim_tape_wrp (uptr)? STA_WLK: 0) |
|
||
(sim_tape_bot (uptr)? STA_BOT: 0);
|
||
else uptr->USTAT = 0; }
|
||
mta_updcsta (&mta_unit[0]); /* update status */
|
||
if (mtxb == NULL) mtxb = calloc (MTA_MAXFR, sizeof (uint8));
|
||
if (mtxb == NULL) return SCPE_MEM;
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* Attach routine */
|
||
|
||
t_stat mta_attach (UNIT *uptr, char *cptr)
|
||
{
|
||
t_stat r;
|
||
|
||
r = sim_tape_attach (uptr, cptr);
|
||
if (r != SCPE_OK) return r;
|
||
if (!sim_is_active (uptr)) mta_upddsta (uptr, STA_RDY | STA_BOT | STA_PEM |
|
||
(sim_tape_wrp (uptr)? STA_WLK: 0));
|
||
return r;
|
||
}
|
||
|
||
/* Detach routine */
|
||
|
||
t_stat mta_detach (UNIT* uptr)
|
||
{
|
||
if (!sim_is_active (uptr)) mta_upddsta (uptr, 0);
|
||
return sim_tape_detach (uptr);
|
||
}
|
||
|
||
/* Write lock/unlock validate routine */
|
||
|
||
t_stat mta_vlock (UNIT *uptr, int32 val, char *cptr, void *desc)
|
||
{
|
||
if ((uptr->flags & UNIT_ATT) && (val || sim_tape_wrp (uptr)))
|
||
mta_upddsta (uptr, uptr->USTAT | STA_WLK);
|
||
else mta_upddsta (uptr, uptr->USTAT & ~STA_WLK);
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* Bootstrap routine */
|
||
|
||
#define BOOT_START 02000
|
||
#define BOOT_UNIT 02020
|
||
#define BOOT_LEN (sizeof (boot_rom) / sizeof (int))
|
||
|
||
static const int32 boot_rom[] = {
|
||
0060222, /* NIOC 0,MTA ; clear disk */
|
||
0020417, /* LDA 0,UNIT ; unit */
|
||
0024417, /* LDA 1,REWIND ; cmd */
|
||
0107000, /* ADD 0,1 ; cmd + unit */
|
||
0065122, /* DOAS 1,MTA ; start rewind */
|
||
0070422, /* DIA 2,MTA ; get status */
|
||
0151213, /* MOVR# 2,2,SNC ; skip if done */
|
||
0000776, /* JMP .-2 */
|
||
0126400, /* SUB 1,1 ; ma, wc = 0 */
|
||
0066022, /* DOB 1,MTA */
|
||
0067022, /* DOC 1,MTA */
|
||
0061122, /* DOAS 0,MTA ; start read */
|
||
0070422, /* DIA 2,MTA ; get status */
|
||
0151213, /* MOVR# 2,2,SNC ; skip if done */
|
||
0000776, /* JMP .-2 */
|
||
0000377, /* JMP 377 */
|
||
0000000, /* UNIT: */
|
||
0000010 /* REWIND: 10 */
|
||
};
|
||
|
||
t_stat mta_boot (int32 unitno, DEVICE *dptr)
|
||
{
|
||
int32 i;
|
||
extern int32 saved_PC, SR;
|
||
|
||
sim_tape_rewind (&mta_unit[unitno]);
|
||
for (i = 0; i < BOOT_LEN; i++) M[BOOT_START + i] = boot_rom[i];
|
||
M[BOOT_UNIT] = (unitno & CU_M_UNIT) << CU_V_UNIT;
|
||
saved_PC = BOOT_START;
|
||
SR = 0100000 + DEV_MTA;
|
||
return SCPE_OK;
|
||
}
|