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. 1. New Features 1.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. 1.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. 1.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. 1.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. 1.5 PDP-1 - DECtape (then known as MicroTape) support has been added. - The line printer and DECtape can be disabled and enabled. 1.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. 1.7 IBM 1620 - The IBM 1620 simulator has been released. 1.8 AltairZ80 - A hard drive has been added for increased storage. - Several bugs have been fixed. 1.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. 1.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. 1.11 Simulated DECtapes - Added support for RT11 image file format (256 x 16b) to DECtapes. 2. Release Notes 2.1 Bugs Fixed - 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. 2.2 HP 2100 Debugging - The HP 2100 CPU nows runs all of the CPU diagnostics. - The peripherals run most of the peripheral diagnostics. There is still a problem in overlapped seek operation on the disks. See the file hp2100_diag.txt for details. 3. In Progress These simulators are not finished and are available in a separate Zip archive distribution. - Interdata 16b/32b: coded, partially tested. See the file id_diag.txt for details. - SDS 940: coded, partially tested.
444 lines
15 KiB
C
444 lines
15 KiB
C
/* pdp18b_rp.c: RP15/RP02 disk pack simulator
|
||
|
||
Copyright (c) 1993-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.
|
||
|
||
rp RP15/RP02 disk pack
|
||
|
||
05-Oct-02 RMS Added DIB, device number support
|
||
06-Jan-02 RMS Revised enable/disable support
|
||
29-Nov-01 RMS Added read only unit support
|
||
25-Nov-01 RMS Revised interrupt structure
|
||
Changed FLG to array
|
||
26-Apr-01 RMS Added device enable/disable support
|
||
14-Apr-99 RMS Changed t_addr to unsigned
|
||
29-Jun-96 RMS Added unit enable/disable support
|
||
*/
|
||
|
||
#include "pdp18b_defs.h"
|
||
|
||
/* Constants */
|
||
|
||
#define RP_NUMWD 256 /* words/sector */
|
||
#define RP_NUMSC 10 /* sectors/surface */
|
||
#define RP_NUMSF 20 /* surfaces/cylinder */
|
||
#define RP_NUMCY 203 /* cylinders/drive */
|
||
#define RP_NUMDR 8 /* drives/controller */
|
||
#define RP_SIZE (RP_NUMCY * RP_NUMSF * RP_NUMSC * RP_NUMWD) /* words/drive */
|
||
|
||
/* Unit specific flags */
|
||
|
||
#define UNIT_V_WLK (UNIT_V_UF + 0) /* hwre write lock */
|
||
#define UNIT_WLK (1u << UNIT_V_WLK)
|
||
#define UNIT_WPRT (UNIT_WLK | UNIT_RO) /* write protect */
|
||
|
||
/* Parameters in the unit descriptor */
|
||
|
||
#define CYL u3 /* current cylinder */
|
||
#define FUNC u4 /* function */
|
||
|
||
/* Status register A */
|
||
|
||
#define STA_V_UNIT 15 /* unit select */
|
||
#define STA_M_UNIT 07
|
||
#define STA_V_FUNC 12 /* function */
|
||
#define STA_M_FUNC 07
|
||
#define FN_IDLE 0
|
||
#define FN_READ 1
|
||
#define FN_WRITE 2
|
||
#define FN_RECAL 3
|
||
#define FN_SEEK 4
|
||
#define FN_RDALL 5
|
||
#define FN_WRALL 6
|
||
#define FN_WRCHK 7
|
||
#define FN_2ND 010 /* second state flag */
|
||
#define STA_IED 0004000 /* int enable done */
|
||
#define STA_IEA 0002000 /* int enable attn */
|
||
#define STA_GO 0001000 /* go */
|
||
#define STA_WPE 0000400 /* write lock error */
|
||
#define STA_NXC 0000200 /* nx cyl error */
|
||
#define STA_NXF 0000100 /* nx surface error */
|
||
#define STA_NXS 0000040 /* nx sector error */
|
||
#define STA_HNF 0000020 /* hdr not found */
|
||
#define STA_SUWP 0000010 /* sel unit wrt lock */
|
||
#define STA_SUSI 0000004 /* sel unit seek inc */
|
||
#define STA_DON 0000002 /* done */
|
||
#define STA_ERR 0000001 /* error */
|
||
|
||
#define STA_RW 0777000 /* read/write */
|
||
#define STA_EFLGS (STA_WPE | STA_NXC | STA_NXF | STA_NXS | \
|
||
STA_HNF | STA_SUSI) /* error flags */
|
||
#define STA_DYN (STA_SUWP | STA_SUSI) /* per unit status */
|
||
#define GET_UNIT(x) (((x) >> STA_V_UNIT) & STA_M_UNIT)
|
||
#define GET_FUNC(x) (((x) >> STA_V_FUNC) & STA_M_FUNC)
|
||
|
||
/* Status register B */
|
||
|
||
#define STB_V_ATT0 17 /* unit 0 attention */
|
||
#define STB_ATTN 0776000 /* attention flags */
|
||
#define STB_SUFU 0001000 /* sel unit unsafe */
|
||
#define STB_PGE 0000400 /* programming error */
|
||
#define STB_EOP 0000200 /* end of pack */
|
||
#define STB_TME 0000100 /* timing error */
|
||
#define STB_FME 0000040 /* format error */
|
||
#define STB_WCE 0000020 /* write check error */
|
||
#define STB_WPE 0000010 /* word parity error */
|
||
#define STB_LON 0000004 /* long parity error */
|
||
#define STB_SUSU 0000002 /* sel unit seeking */
|
||
#define STB_SUNR 0000001 /* sel unit not rdy */
|
||
|
||
#define STB_EFLGS (STB_SUFU | STB_PGE | STB_EOP | STB_TME | STB_FME | \
|
||
STB_WCE | STB_WPE | STB_LON ) /* error flags */
|
||
#define STB_DYN (STB_SUFU | STB_SUSU | STB_SUNR) /* per unit */
|
||
|
||
/* Disk address */
|
||
|
||
#define DA_V_SECT 0 /* sector */
|
||
#define DA_M_SECT 017
|
||
#define DA_V_SURF 5
|
||
#define DA_M_SURF 037
|
||
#define DA_V_CYL 10 /* cylinder */
|
||
#define DA_M_CYL 0377
|
||
#define GET_SECT(x) (((x) >> DA_V_SECT) & DA_M_SECT)
|
||
#define GET_SURF(x) (((x) >> DA_V_SURF) & DA_M_SURF)
|
||
#define GET_CYL(x) (((x) >> DA_V_CYL) & DA_M_CYL)
|
||
#define GET_DA(x) ((((GET_CYL (x) * RP_NUMSF) + GET_SURF (x)) * \
|
||
RP_NUMSC) + GET_SECT (x))
|
||
|
||
#define RP_MIN 2
|
||
#define MAX(x,y) (((x) > (y))? (x): (y))
|
||
|
||
extern int32 M[];
|
||
extern int32 int_hwre[API_HLVL+1], nexm;
|
||
extern UNIT cpu_unit;
|
||
|
||
int32 rp_sta = 0; /* status A */
|
||
int32 rp_stb = 0; /* status B */
|
||
int32 rp_ma = 0; /* memory address */
|
||
int32 rp_da = 0; /* disk address */
|
||
int32 rp_wc = 0; /* word count */
|
||
int32 rp_busy = 0; /* busy */
|
||
int32 rp_stopioe = 1; /* stop on error */
|
||
int32 rp_swait = 10; /* seek time */
|
||
int32 rp_rwait = 10; /* rotate time */
|
||
|
||
DEVICE rp_dev;
|
||
int32 rp63 (int32 pulse, int32 AC);
|
||
int32 rp64 (int32 pulse, int32 AC);
|
||
int32 rp_iors (void);
|
||
t_stat rp_svc (UNIT *uptr);
|
||
void rp_updsta (int32 newa, int32 newb);
|
||
t_stat rp_reset (DEVICE *dptr);
|
||
t_stat rp_attach (UNIT *uptr, char *cptr);
|
||
t_stat rp_detach (UNIT *uptr);
|
||
|
||
/* RP15 data structures
|
||
|
||
rp_dev RP device descriptor
|
||
rp_unit RP unit list
|
||
rp_reg RP register list
|
||
rp_mod RP modifier list
|
||
*/
|
||
|
||
DIB rp_dib = { DEV_RP, 2, &rp_iors, { &rp63, &rp64 } };
|
||
|
||
UNIT rp_unit[] = {
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) },
|
||
{ UDATA (&rp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, RP_SIZE) } };
|
||
|
||
REG rp_reg[] = {
|
||
{ ORDATA (STA, rp_sta, 18) },
|
||
{ ORDATA (STB, rp_stb, 18) },
|
||
{ ORDATA (DA, rp_da, 18) },
|
||
{ ORDATA (MA, rp_ma, 18) },
|
||
{ ORDATA (WC, rp_wc, 18) },
|
||
{ FLDATA (INT, int_hwre[API_RP], INT_V_RP) },
|
||
{ FLDATA (BUSY, rp_busy, 0) },
|
||
{ FLDATA (STOP_IOE, rp_stopioe, 0) },
|
||
{ DRDATA (STIME, rp_swait, 24), PV_LEFT },
|
||
{ DRDATA (RTIME, rp_rwait, 24), PV_LEFT },
|
||
{ ORDATA (DEVNO, rp_dib.dev, 6), REG_HRO },
|
||
{ NULL } };
|
||
|
||
MTAB rp_mod[] = {
|
||
{ UNIT_WLK, 0, "write enabled", "WRITEENABLED", NULL },
|
||
{ UNIT_WLK, UNIT_WLK, "write locked", "LOCKED", NULL },
|
||
{ MTAB_XTD|MTAB_VDV, 0, "DEVNO", "DEVNO", &set_devno, &show_devno },
|
||
{ 0 } };
|
||
|
||
DEVICE rp_dev = {
|
||
"RP", rp_unit, rp_reg, rp_mod,
|
||
RP_NUMDR, 8, 24, 1, 8, 18,
|
||
NULL, NULL, &rp_reset,
|
||
NULL, &rp_attach, &rp_detach,
|
||
&rp_dib, DEV_DISABLE };
|
||
|
||
/* IOT routines */
|
||
|
||
int32 rp63 (int32 pulse, int32 AC)
|
||
{
|
||
rp_updsta (0, 0);
|
||
if (pulse == 001) /* DPSF */
|
||
return ((rp_sta & (STA_DON | STA_ERR)) || (rp_stb & STB_ATTN))?
|
||
IOT_SKP + AC: AC;
|
||
if (pulse == 021) /* DPSA */
|
||
return (rp_stb & STB_ATTN)? IOT_SKP + AC: AC;
|
||
if (pulse == 041) /* DPSJ */
|
||
return (rp_sta & STA_DON)? IOT_SKP + AC: AC;
|
||
if (pulse == 061) /* DPSE */
|
||
return (rp_sta & STA_ERR)? IOT_SKP + AC: AC;
|
||
if (pulse == 002) return rp_sta; /* DPOSA */
|
||
if (pulse == 022) return rp_stb; /* DPOSB */
|
||
if (((pulse & 007) == 004) && rp_busy) { /* busy? */
|
||
rp_updsta (0, STB_PGE);
|
||
return AC; }
|
||
if (pulse == 004) { /* DPLA */
|
||
rp_da = AC;
|
||
if (GET_SECT (rp_da) >= RP_NUMSC) rp_updsta (STA_NXS, 0);
|
||
if (GET_SURF (rp_da) >= RP_NUMSF) rp_updsta (STA_NXF, 0);
|
||
if (GET_CYL (rp_da) >= RP_NUMCY) rp_updsta (STA_NXC, 0); }
|
||
if (pulse == 024) { /* DPCS */
|
||
rp_sta = rp_sta & ~(STA_HNF | STA_DON);
|
||
rp_stb = rp_stb & ~(STB_FME | STB_WPE | STB_LON | STB_WCE |
|
||
STB_TME | STB_PGE | STB_EOP);
|
||
rp_updsta (0, 0); }
|
||
if (pulse == 044) rp_ma = AC; /* DPCA */
|
||
if (pulse == 064) rp_wc = AC; /* DPWC */
|
||
return AC;
|
||
}
|
||
|
||
/* IOT 64 */
|
||
|
||
int32 rp64 (int32 pulse, int32 AC)
|
||
{
|
||
int32 u, f, c;
|
||
UNIT *uptr;
|
||
|
||
if (pulse == 021) return IOT_SKP + AC; /* DPSN */
|
||
if (pulse == 002) return rp_unit[GET_UNIT (rp_sta)].CYL; /* DPOU */
|
||
if (pulse == 022) return rp_da; /* DPOA */
|
||
if (pulse == 042) return rp_ma; /* DPOC */
|
||
if (pulse == 062) return rp_wc; /* DPOW */
|
||
if ((pulse & 007) != 004) return AC;
|
||
if (rp_busy) { /* busy? */
|
||
rp_updsta (0, STB_PGE);
|
||
return AC; }
|
||
if (pulse == 004) rp_sta = rp_sta & ~STA_RW; /* DPCF */
|
||
if (pulse == 024) rp_sta = rp_sta & (AC | ~STA_RW); /* DPLZ */
|
||
if (pulse == 044) rp_sta = rp_sta | (AC & STA_RW); /* DPLO */
|
||
if (pulse == 064) rp_sta = (rp_sta & ~STA_RW) | (AC & STA_RW); /* DPLF */
|
||
if (rp_sta & STA_GO) {
|
||
u = GET_UNIT (rp_sta); /* get unit num */
|
||
uptr = rp_dev.units + u; /* select unit */
|
||
if (sim_is_active (uptr)) return AC; /* can't if busy */
|
||
f = uptr->FUNC = GET_FUNC (rp_sta); /* get function */
|
||
rp_busy = 1; /* set ctrl busy */
|
||
rp_sta = rp_sta & ~(STA_HNF | STA_DON); /* clear flags */
|
||
rp_stb = rp_stb & ~(STB_FME | STB_WPE | STB_LON | STB_WCE |
|
||
STB_TME | STB_PGE | STB_EOP | (1 << (STB_V_ATT0 - u)));
|
||
if (((uptr->flags & UNIT_ATT) == 0) || (f == FN_IDLE) ||
|
||
(f == FN_SEEK) || (f == FN_RECAL))
|
||
sim_activate (uptr, RP_MIN); /* short delay */
|
||
else { c = GET_CYL (rp_da);
|
||
c = abs (c - uptr->CYL) * rp_swait; /* seek time */
|
||
sim_activate (uptr, MAX (RP_MIN, c + rp_rwait)); } }
|
||
rp_updsta (0, 0);
|
||
return AC;
|
||
}
|
||
|
||
/* Unit service
|
||
|
||
If function = idle, clear busy
|
||
If seek or recal initial state, clear attention line, compute seek time,
|
||
put on cylinder, set second state
|
||
If unit not attached, give error
|
||
If seek or recal second state, set attention line, compute errors
|
||
Else complete data transfer command
|
||
|
||
The unit control block contains the function and cylinder for
|
||
the current command.
|
||
*/
|
||
|
||
static int32 fill[RP_NUMWD] = { 0 };
|
||
t_stat rp_svc (UNIT *uptr)
|
||
{
|
||
int32 f, u, comp, cyl, sect, surf;
|
||
int32 err, pa, da, wc, awc, i;
|
||
|
||
u = uptr - rp_dev.units; /* get drv number */
|
||
f = uptr->FUNC; /* get function */
|
||
if (f == FN_IDLE) { /* idle? */
|
||
rp_busy = 0; /* clear busy */
|
||
return SCPE_OK; }
|
||
|
||
if ((f == FN_SEEK) || (f == FN_RECAL)) { /* seek or recal? */
|
||
rp_busy = 0; /* not busy */
|
||
cyl = (f == FN_SEEK)? GET_CYL (rp_da): 0; /* get cylinder */
|
||
sim_activate (uptr, MAX (RP_MIN, abs (cyl - uptr->CYL) * rp_swait));
|
||
uptr->CYL = cyl; /* on cylinder */
|
||
uptr->FUNC = FN_SEEK | FN_2ND; /* set second state */
|
||
rp_updsta (0, 0); /* update status */
|
||
return SCPE_OK; }
|
||
|
||
if (f == (FN_SEEK | FN_2ND)) { /* seek done? */
|
||
rp_updsta (0, rp_stb | (1 << (STB_V_ATT0 - u))); /* set attention */
|
||
return SCPE_OK; }
|
||
|
||
if ((uptr->flags & UNIT_ATT) == 0) { /* not attached? */
|
||
rp_updsta (STA_DON, STB_SUFU); /* done, unsafe */
|
||
return IORETURN (rp_stopioe, SCPE_UNATT); }
|
||
|
||
if ((f == FN_WRITE) && (uptr->flags & UNIT_WPRT)) { /* write locked? */
|
||
rp_updsta (STA_DON | STA_WPE, 0); /* error */
|
||
return SCPE_OK; }
|
||
|
||
if (GET_SECT (rp_da) >= RP_NUMSC) rp_updsta (STA_NXS, 0);
|
||
if (GET_SURF (rp_da) >= RP_NUMSF) rp_updsta (STA_NXF, 0);
|
||
if (GET_CYL (rp_da) >= RP_NUMCY) rp_updsta (STA_NXC, 0);
|
||
if (rp_sta & (STA_NXS | STA_NXF | STA_NXC)) { /* or bad disk addr? */
|
||
rp_updsta (STA_DON, STB_SUFU); /* done, unsafe */
|
||
return SCPE_OK; }
|
||
|
||
pa = rp_ma & ADDRMASK; /* get mem addr */
|
||
da = GET_DA (rp_da) * RP_NUMWD; /* get disk addr */
|
||
wc = 01000000 - rp_wc; /* get true wc */
|
||
if (((t_addr) (pa + wc)) > MEMSIZE) { /* memory overrun? */
|
||
nexm = 1; /* set nexm flag */
|
||
wc = MEMSIZE - pa; } /* limit xfer */
|
||
if ((da + wc) > RP_SIZE) { /* disk overrun? */
|
||
rp_updsta (0, STB_EOP); /* error */
|
||
wc = RP_SIZE - da; } /* limit xfer */
|
||
|
||
err = fseek (uptr->fileref, da * sizeof (int), SEEK_SET);
|
||
|
||
if ((f == FN_READ) && (err == 0)) { /* read? */
|
||
awc = fxread (&M[pa], sizeof (int32), wc, uptr->fileref);
|
||
for ( ; awc < wc; awc++) M[pa + awc] = 0;
|
||
err = ferror (uptr->fileref); }
|
||
|
||
if ((f == FN_WRITE) && (err == 0)) { /* write? */
|
||
fxwrite (&M[pa], sizeof (int32), wc, uptr->fileref);
|
||
err = ferror (uptr->fileref);
|
||
if ((err == 0) && (i = (wc & (RP_NUMWD - 1)))) {
|
||
fxwrite (fill, sizeof (int), i, uptr->fileref);
|
||
err = ferror (uptr->fileref); } }
|
||
|
||
if ((f == FN_WRCHK) && (err == 0)) { /* write check? */
|
||
for (i = 0; (err == 0) && (i < wc); i++) {
|
||
awc = fxread (&comp, sizeof (int32), 1, uptr->fileref);
|
||
if (awc == 0) comp = 0;
|
||
if (comp != M[pa + i]) rp_updsta (0, STB_WCE); }
|
||
err = ferror (uptr->fileref); }
|
||
|
||
rp_wc = (rp_wc + wc) & 0777777; /* final word count */
|
||
rp_ma = (rp_ma + wc) & 0777777; /* final mem addr */
|
||
da = (da + wc + (RP_NUMWD - 1)) / RP_NUMWD; /* final sector num */
|
||
cyl = da / (RP_NUMSC * RP_NUMSF); /* get cyl */
|
||
if (cyl >= RP_NUMCY) cyl = RP_NUMCY - 1;
|
||
surf = (da % (RP_NUMSC * RP_NUMSF)) / RP_NUMSC; /* get surface */
|
||
sect = (da % (RP_NUMSC * RP_NUMSF)) % RP_NUMSC; /* get sector */
|
||
rp_da = (cyl << DA_V_CYL) | (surf << DA_V_SURF) | (sect << DA_V_SECT);
|
||
rp_busy = 0; /* clear busy */
|
||
rp_updsta (STA_DON, 0); /* set done */
|
||
|
||
if (err != 0) { /* error? */
|
||
perror ("RP I/O error");
|
||
clearerr (uptr->fileref);
|
||
return IORETURN (rp_stopioe, SCPE_IOERR); }
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* Update status */
|
||
|
||
void rp_updsta (int32 newa, int32 newb)
|
||
{
|
||
int32 f;
|
||
UNIT *uptr;
|
||
|
||
uptr = rp_dev.units + GET_UNIT (rp_sta);
|
||
rp_sta = (rp_sta & ~(STA_DYN | STA_ERR)) | newa;
|
||
rp_stb = (rp_stb & ~STB_DYN) | newb;
|
||
if (uptr->flags & UNIT_WPRT) rp_sta = rp_sta | STA_SUWP;
|
||
if ((uptr->flags & UNIT_ATT) == 0) rp_stb = rp_stb | STB_SUFU | STB_SUNR;
|
||
else if (sim_is_active (uptr)) {
|
||
f = (uptr->FUNC) & STA_M_FUNC;
|
||
if ((f == FN_SEEK) || (f == FN_RECAL))
|
||
rp_stb = rp_stb | STB_SUSU | STB_SUNR; }
|
||
else if (uptr->CYL >= RP_NUMCY) rp_sta = rp_sta | STA_SUSI;
|
||
if ((rp_sta & STA_EFLGS) || (rp_stb & STB_EFLGS)) rp_sta = rp_sta | STA_ERR;
|
||
if (((rp_sta & (STA_ERR | STA_DON)) && (rp_sta & STA_IED)) ||
|
||
((rp_stb & STB_ATTN) && (rp_sta & STA_IEA))) SET_INT (RP);
|
||
else CLR_INT (RP);
|
||
return;
|
||
}
|
||
|
||
/* Reset routine */
|
||
|
||
t_stat rp_reset (DEVICE *dptr)
|
||
{
|
||
int32 i;
|
||
UNIT *uptr;
|
||
|
||
rp_sta = rp_stb = rp_da = rp_wc = rp_ma = rp_busy = 0;
|
||
CLR_INT (RP);
|
||
for (i = 0; i < RP_NUMDR; i++) {
|
||
uptr = rp_dev.units + i;
|
||
sim_cancel (uptr);
|
||
uptr->CYL = uptr->FUNC = 0; }
|
||
return SCPE_OK;
|
||
}
|
||
|
||
/* IORS routine */
|
||
|
||
int32 rp_iors (void)
|
||
{
|
||
return ((rp_sta & (STA_ERR | STA_DON)) || (rp_stb & STB_ATTN))? IOS_RP: 0;
|
||
}
|
||
|
||
/* Attach unit */
|
||
|
||
t_stat rp_attach (UNIT *uptr, char *cptr)
|
||
{
|
||
t_stat reason;
|
||
|
||
reason = attach_unit (uptr, cptr);
|
||
rp_updsta (0, 0);
|
||
return reason;
|
||
}
|
||
|
||
/* Detach unit */
|
||
|
||
t_stat rp_detach (UNIT *uptr)
|
||
{
|
||
t_stat reason;
|
||
|
||
reason = detach_unit (uptr);
|
||
rp_updsta (0, 0);
|
||
return reason;
|
||
}
|