Support for RX11 diskette drives has been added, but is still untested

This commit is contained in:
Jeff Parsons 2017-02-02 15:14:13 -08:00 committed by Jeff Parsons
commit cacc2f7dad
32 changed files with 1531 additions and 660 deletions

View file

@ -513,6 +513,8 @@ var PDP11 = {
RLMP: 0o174406, // RL11 Multi-Purpose Register
RLBE: 0o174410, // RL11 Bus (Address) Extension Register (RLV12 controller only)
DL11: 0o176500, // DL11 Additional Register Range (ends at 0o176676)
RXCS: 0o177170, // RX11 Command and Status Register
RXDB: 0o177172, // RX11 Data Buffer Register
RKDS: 0o177400, // RK11 Drive Status Register
RKER: 0o177402, // RK11 Error Register
RKCS: 0o177404, // RK11 Control Status Register
@ -738,7 +740,7 @@ var PDP11 = {
SCP: 0x2000, // (020000) Search Complete (R/O)
HE: 0x4000, // (040000) Hard Error (R/O)
ERR: 0x8000, // (100000) Composite Error (R/O) (set when any RKER bit is set)
UNUSED: 0x1200, // (120000) unused
UNUSED: 0x1200, // (011000) unused
RMASK: 0xEFFE, // (167776) bits readable
WMASK: 0x0F7F, // (007577) bits writable
SHIFT: {
@ -772,6 +774,7 @@ var PDP11 = {
PRI: 5,
VEC: 0o160,
DRIVES: 4, // maximum of 4 drives
PREFIX: "DY",
RLCS: { // 174400: Control Status Register
DRDY: 0x0001, // Drive Ready (R/O)
FUNC: 0x000E, // Function Code (F2,F1,F0) (R/W)
@ -865,6 +868,76 @@ var PDP11 = {
RDNC: 0b1110 // Read Data without Header Check
}
},
RX11: { // RX11 Disk Controller
PRI: 5,
VEC: 0o264,
DRIVES: 2, // maximum of 2 drives
PREFIX: "DX",
RXCS: { // 177170: Command and Status Register
GO: 0x0001, // (000001) Go (W/O)
FUNC: 0x000E, // (000016) Function Code (F2,F1,F0) (W/O)
UNIT: 0x0010, // (000020) Unit Select (W/O)
DONE: 0x0020, // (000040) Done (R/O)
IE: 0x0040, // (000100) Interrupt Enable (R/W, cleared on INIT)
TR: 0x0080, // (000400) Transfer Request (R/O)
RXINIT: 0x4000, // (040000) RX11 Initialize (W/O)
ERR: 0x8000, // (100000) Error (R/O, cleared on INIT or command)
UNUSED: 0x3F00, // (037400) unused
RMASK: 0x80E0, // (100340) bits readable
WMASK: 0x405F // (040137) bits writable
},
RXDB: { // 177172: Data Buffer Register
},
RXTA: {
MASK: 0x007F
},
RXSA: {
MASK: 0x001F
},
RXES: {
/*
* The DRDY bit is only valid when retrieved via a Read Status function or at completion of Initialize when it indicates
* status of drive O. It is asserted if the unit currently selected exists, is properly supplied with power, has a diskette
* installed correctly, has its door closed, and has a diskette up to speed.
*
* If the Error bit was set in the RXCS but Error bits are not set in the RXES, then specific error conditions can be accessed via
* a Read Error Register function.
*/
CRC: 0x0001, // CRC error (RXES is moved to the RXDB, and Error and Done are asserted)
PARITY: 0x0002, // parity error (RXES is moved to the RXDB, and Error and Done are asserted)
ID: 0x0004, // Initialize Done (following a programmable or UNIBUS initialization, or a power failure)
DEL: 0x0040, // Deleted Data Detected
DRDY: 0x0080 // Drive Ready
},
FUNC: { // NOTE: These function codes are pre-shifted to read/write directly from/to RXCS.FUNC
FILL: 0b0000, // Fill Buffer
EMPTY: 0b0010, // Empty Buffer
WRITE: 0b0100, // Write Sector
READ: 0b0110, // Read Sector
UNUSED: 0b1000, // UNUSED
RDSTAT: 0b1010, // Read Status
WRDEL: 0b1100, // Write Deleted Data Sector
RDERR: 0b1110 // Read Error Register
},
ERROR: {
HOME0: 0o0010, // Drive 0 failed to see home on Initialize
HOME1: 0o0020, // Drive 1 failed to see home on Initialize
BAD_HOME: 0o0030, // Found home when stepping out 10 tracks for INIT
NO_TRACK: 0o0040, // Tried to access a track greater than 77
FOUND_HOME: 0o0050, // Home was found before desired track was reached
SELF_DIAG: 0o0060, // Self-diagnostic error
NO_SECTOR: 0o0070, // Desired sector could not be found after looking at 52 headers (2 revolutions)
NO_SEP: 0o0110, // More than 40us and no SEP clock seen
NO_PREAM: 0o0120, // A preamble could not be found
NO_IOMARK: 0o0130, // Preamble found but no I/O mark found within allowable time span
CRC_HEADER: 0o0140, // CRC error on what we thought was a header
BAD_TRACK: 0o0150, // The header track address of a good header does not compare with the desired track
NO_ID: 0o0160, // Too many tries for an IDAM (identifies header)
NO_DATA: 0o0170, // Data AM not found in allotted time
CRC_DATA: 0o0200, // CRC error on reading the sector from the disk (No code appears in the ERREG).
BAD_PARITY: 0o0210 // All parity errors
}
},
VECTORS: {
0o060: "DL11R",
0o064: "DL11X",
@ -872,12 +945,14 @@ var PDP11 = {
0o074: "PC11X",
0o100: "KW11",
0o160: "RL11",
0o220: "RK11"
0o220: "RK11",
0o264: "RX11"
}
};
PDP11.RK11.RK05 = [203, 2, 12, 512, PDP11.RK11.RKDS.RK05 | PDP11.RK11.RKDS.SOK | PDP11.RK11.RKDS.RRDY];
PDP11.RL11.RL02K = [512, 2, 40, 256, PDP11.RL11.RLMP.GS_ST.LOCKON | PDP11.RL11.RLMP.GS_BH | PDP11.RL11.RLMP.GS_HO];
PDP11.RX11.RX01 = ["DX", 77, 1, 26, 128, 0];
PDP11.RK11.RK05 = ["RK", 203, 2, 12, 512, PDP11.RK11.RKDS.RK05 | PDP11.RK11.RKDS.SOK | PDP11.RK11.RKDS.RRDY];
PDP11.RL11.RL02K = ["RL", 512, 2, 40, 256, PDP11.RL11.RLMP.GS_ST.LOCKON | PDP11.RL11.RLMP.GS_BH | PDP11.RL11.RLMP.GS_HO];
PDP11.ACCESS.READ_WORD = PDP11.ACCESS.WORD | PDP11.ACCESS.READ; // formerly READ_MODE (2)
PDP11.ACCESS.READ_BYTE = PDP11.ACCESS.BYTE | PDP11.ACCESS.READ; // formerly READ_MODE (2) | BYTE_MODE (1)

View file

@ -44,6 +44,7 @@ if (NODE) {
var PC11 = require("./pc11");
var RL11 = require("./rl11");
var RK11 = require("./rk11");
var RX11 = require("./rx11");
}
class DevicePDP11 extends Component {
@ -1204,6 +1205,10 @@ class DevicePDP11 extends Component {
device = new RK11(parmsDevice);
Component.bindComponentControls(device, eDevice, PDP11.APPCLASS);
break;
case 'rx11':
device = new RX11(parmsDevice);
Component.bindComponentControls(device, eDevice, PDP11.APPCLASS);
break;
}
}
}

View file

@ -376,7 +376,8 @@ class DriveController extends Component {
*/
getDriveName(iDrive)
{
return this.type.substr(0, 2) + iDrive;
var drive = this.aDrives[iDrive];
return drive.sName || "---";
}
/**
@ -554,11 +555,12 @@ class DriveController extends Component {
* NOTE: We initialize the following drive properties to their MAXIMUMs; disks may have
* these or SMALLER values (subject to the limits of what the controller supports, of course).
*/
drive.nCylinders = configDrive[0];
drive.nHeads = configDrive[1];
drive.nSectors = configDrive[2];
drive.cbSector = configDrive[3];
drive.status = configDrive[4];
drive.sName = configDrive[0] + iDrive;
drive.nCylinders = configDrive[1];
drive.nHeads = configDrive[2];
drive.nSectors = configDrive[3];
drive.cbSector = configDrive[4];
drive.status = configDrive[5];
/*
* The next group of properties are set by various controller command sequences.
@ -720,9 +722,9 @@ class DriveController extends Component {
{
if (!fRemount) this.cAutoMount = 0;
for (var sDrive in this.configMount) {
var configDrive = this.configMount[sDrive];
var sDiskPath = configDrive['path'] || "";
var sDiskName = configDrive['name'] || this.findDisk(sDiskPath);
var configDisk = this.configMount[sDrive];
var sDiskPath = configDisk['path'] || "";
var sDiskName = configDisk['name'] || this.findDisk(sDiskPath);
if (sDiskPath && sDiskName) {
var iDrive = this.getDriveNumber(sDrive);
if (iDrive >= 0 && iDrive < this.aDrives.length) {
@ -732,7 +734,7 @@ class DriveController extends Component {
continue;
}
}
this.notice("Incorrect auto-mount settings for drive " + sDrive + " (" + JSON.stringify(configDrive) + ")");
this.notice("Incorrect auto-mount settings for drive " + sDrive + " (" + JSON.stringify(configDisk) + ")");
}
return !!this.cAutoMount;
}
@ -1220,7 +1222,7 @@ class DriveController extends Component {
/**
* readData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
*
* Placeholder for subclasses.
* Placeholder for subclasses. Implementation is optional, but the automatic BOOT feature will be unavailable.
*
* @this {DriveController}
* @param {Object} drive
@ -1236,13 +1238,13 @@ class DriveController extends Component {
*/
readData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
return false;
return -1;
}
/**
* writeData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
*
* Placeholder for subclasses.
* Placeholder for subclasses. Implementation is optional.
*
* @this {DriveController}
* @param {Object} drive
@ -1258,7 +1260,7 @@ class DriveController extends Component {
*/
writeData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
return false;
return -1;
}
}

View file

@ -48,10 +48,11 @@ var MessagesPDP11 = {
WRITE: 0x00008000,
RK11: 0x00010000,
RL11: 0x00020000,
DL11: 0x00040000,
SERIAL: 0x00040000,
KW11: 0x00080000,
TIMER: 0x00080000,
RX11: 0x00040000,
DL11: 0x00100000,
SERIAL: 0x00100000,
KW11: 0x00200000,
TIMER: 0x00200000,
SPEAKER: 0x01000000,
COMPUTER: 0x02000000,
LOG: 0x10000000,
@ -94,6 +95,7 @@ MessagesPDP11.CATEGORIES = {
"write": MessagesPDP11.WRITE,
"rk11": MessagesPDP11.RK11,
"rl11": MessagesPDP11.RL11,
"rx11": MessagesPDP11.RX11,
"dl11": MessagesPDP11.DL11,
"serial": MessagesPDP11.SERIAL,
"kw11": MessagesPDP11.KW11,

View file

@ -230,12 +230,12 @@ class RK11 extends DriveController {
*/
readData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
var err = 0;
var nError = 0;
var disk = drive.disk;
var sector = null, ibSector;
if (!disk) {
err = RK11.RKER.NXD;
nError = RK11.RKER.NXD;
nWords = 0;
}
@ -243,12 +243,12 @@ class RK11 extends DriveController {
while (nWords) {
if (!sector) {
if (iCylinder >= disk.nCylinders) {
err = RK11.RKER.NXC;
nError = RK11.RKER.NXC;
break;
}
sector = disk.seek(iCylinder, iHead, iSector + 1);
if (!sector) {
err = RK11.RKER.SKE;
nError = RK11.RKER.SKE;
break;
}
ibSector = 0;
@ -262,7 +262,7 @@ class RK11 extends DriveController {
}
var b0, b1;
if ((b0 = disk.read(sector, ibSector++)) < 0 || (b1 = disk.read(sector, ibSector++)) < 0) {
err = RK11.RKER.NXS;
nError = RK11.RKER.NXS;
break;
}
if (!fCheck) {
@ -277,7 +277,7 @@ class RK11 extends DriveController {
}
}
if (this.bus.checkFault()) {
err = RK11.RKER.NXM;
nError = RK11.RKER.NXM;
break;
}
}
@ -285,7 +285,7 @@ class RK11 extends DriveController {
addr += inc;
nWords--;
}
return done? done(err, iCylinder, iHead, iSector, nWords, addr) : err;
return done? done(nError, iCylinder, iHead, iSector, nWords, addr) : nError;
}
/**
@ -305,29 +305,29 @@ class RK11 extends DriveController {
*/
writeData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
var err = 0;
var nError = 0;
var disk = drive.disk;
var sector = null, ibSector;
if (!disk) {
err = RK11.RKER.NXD;
nError = RK11.RKER.NXD;
nWords = 0;
}
while (nWords) {
var data = this.bus.getWordDirect(this.cpu.mapUnibus(addr));
if (this.bus.checkFault()) {
err = RK11.RKER.NXM;
nError = RK11.RKER.NXM;
break;
}
if (!sector) {
if (iCylinder >= disk.nCylinders) {
err = RK11.RKER.NXC;
nError = RK11.RKER.NXC;
break;
}
sector = disk.seek(iCylinder, iHead, iSector + 1, true);
if (!sector) {
err = RK11.RKER.SKE;
nError = RK11.RKER.SKE;
break;
}
ibSector = 0;
@ -342,7 +342,7 @@ class RK11 extends DriveController {
if (fCheck) {
var b0, b1;
if ((b0 = disk.read(sector, ibSector++)) < 0 || (b1 = disk.read(sector, ibSector++)) < 0) {
err = RK11.RKER.NXS;
nError = RK11.RKER.NXS;
break;
}
/*
@ -356,12 +356,12 @@ class RK11 extends DriveController {
* trigger the RKCS HE (Hard Error) bit. This is all taken care of in updateErrors() now.
*/
if (data != (b0 | (b1 << 8))) {
err = RK11.RKER.WCE;
nError = RK11.RKER.WCE;
break;
}
} else {
if (!disk.write(sector, ibSector++, data & 0xff) || !disk.write(sector, ibSector++, data >> 8)) {
err = RK11.RKER.NXS;
nError = RK11.RKER.NXS;
break;
}
}
@ -369,14 +369,14 @@ class RK11 extends DriveController {
addr += inc;
nWords--;
}
return done? done(err, iCylinder, iHead, iSector, nWords, addr) : err;
return done? done(nError, iCylinder, iHead, iSector, nWords, addr) : nError;
}
/**
* doneReadWrite(err, iCylinder, iHead, iSector, nWords, addr)
* doneReadWrite(nError, iCylinder, iHead, iSector, nWords, addr)
*
* @this {RK11}
* @param {number} err
* @param {number} nError
* @param {number} iCylinder
* @param {number} iHead
* @param {number} iSector
@ -384,13 +384,13 @@ class RK11 extends DriveController {
* @param {number} addr
* @return {boolean}
*/
doneReadWrite(err, iCylinder, iHead, iSector, nWords, addr)
doneReadWrite(nError, iCylinder, iHead, iSector, nWords, addr)
{
this.regRKBA = addr & 0xffff;
this.regRKCS = (this.regRKCS & ~RK11.RKCS.MEX) | ((addr >> (16 - RK11.RKCS.SHIFT.MEX)) & RK11.RKCS.MEX);
this.regRKWC = (0x10000 - nWords) & 0xffff;
this.regRKDA = (this.regRKDA & ~RK11.RKDA.SA) | (iSector & RK11.RKDA.SA);
this.regRKER |= err;
this.regRKER |= nError;
this.updateErrors();
return true;
}

View file

@ -227,13 +227,13 @@ class RL11 extends DriveController {
*/
readData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
var err = 0;
var nError = 0;
var checksum = 0;
var disk = drive.disk;
var sector = null, ibSector;
if (!disk) {
err = RL11.ERRC.HNF; // TODO: Review
nError = RL11.ERRC.HNF; // TODO: Review
nWords = 0;
}
@ -242,14 +242,14 @@ class RL11 extends DriveController {
if (!sector) {
sector = disk.seek(iCylinder, iHead, iSector + 1);
if (!sector) {
err = RL11.ERRC.HNF;
nError = RL11.ERRC.HNF;
break;
}
ibSector = 0;
}
var b0, b1, data;
if ((b0 = disk.read(sector, ibSector++)) < 0 || (b1 = disk.read(sector, ibSector++)) < 0) {
err = RL11.ERRC.HNF;
nError = RL11.ERRC.HNF;
break;
}
/*
@ -267,7 +267,7 @@ class RL11 extends DriveController {
}
}
if (this.bus.checkFault()) {
err = RL11.ERRC.NXM;
nError = RL11.ERRC.NXM;
break;
}
addr += 2;
@ -280,7 +280,7 @@ class RL11 extends DriveController {
if (++iHead >= disk.nHeads) {
iHead = 0;
if (++iCylinder >= disk.nCylinders) {
err = RL11.ERRC.HNF;
nError = RL11.ERRC.HNF;
break;
}
}
@ -292,7 +292,7 @@ class RL11 extends DriveController {
console.log("checksum: " + (checksum|0));
}
return done? done(err, iCylinder, iHead, iSector, nWords, addr) : err;
return done? done(nError, iCylinder, iHead, iSector, nWords, addr) : nError;
}
/**
@ -312,13 +312,13 @@ class RL11 extends DriveController {
*/
writeData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
var err = 0;
var nError = 0;
var checksum = 0;
var disk = drive.disk;
var sector = null, ibSector;
if (!disk) {
err = RL11.ERRC.HNF; // TODO: Review
nError = RL11.ERRC.HNF; // TODO: Review
nWords = 0;
}
@ -331,7 +331,7 @@ class RL11 extends DriveController {
*/
var data = this.bus.getWordDirect(this.cpu.mapUnibus(addr));
if (this.bus.checkFault()) {
err = RL11.ERRC.NXM;
nError = RL11.ERRC.NXM;
break;
}
if (DEBUG && this.messageEnabled(MessagesPDP11.WRITE)) {
@ -348,13 +348,13 @@ class RL11 extends DriveController {
if (!sector) {
sector = disk.seek(iCylinder, iHead, iSector + 1, true);
if (!sector) {
err = RL11.ERRC.HNF;
nError = RL11.ERRC.HNF;
break;
}
ibSector = 0;
}
if (!disk.write(sector, ibSector++, data & 0xff) || !disk.write(sector, ibSector++, data >> 8)) {
err = RL11.ERRC.HNF;
nError = RL11.ERRC.HNF;
break;
}
if (ibSector >= disk.cbSector) {
@ -364,7 +364,7 @@ class RL11 extends DriveController {
if (++iHead >= disk.nHeads) {
iHead = 0;
if (++iCylinder >= disk.nCylinders) {
err = RL11.ERRC.HNF;
nError = RL11.ERRC.HNF;
break;
}
}
@ -376,14 +376,14 @@ class RL11 extends DriveController {
console.log("checksum: " + (checksum|0));
}
return done? done(err, iCylinder, iHead, iSector, nWords, addr) : err;
return done? done(nError, iCylinder, iHead, iSector, nWords, addr) : nError;
}
/**
* doneReadWrite(err, iCylinder, iHead, iSector, nWords, addr)
* doneReadWrite(nError, iCylinder, iHead, iSector, nWords, addr)
*
* @this {RL11}
* @param {number} err
* @param {number} nError
* @param {number} iCylinder
* @param {number} iHead
* @param {number} iSector
@ -391,7 +391,7 @@ class RL11 extends DriveController {
* @param {number} addr
* @return {boolean}
*/
doneReadWrite(err, iCylinder, iHead, iSector, nWords, addr)
doneReadWrite(nError, iCylinder, iHead, iSector, nWords, addr)
{
this.regRLBA = addr & 0xffff;
this.regRLCS = (this.regRLCS & ~RL11.RLCS.BAE) | ((addr >> (16 - RL11.RLCS.SHIFT.BAE)) & RL11.RLCS.BAE);
@ -399,8 +399,8 @@ class RL11 extends DriveController {
this.regRLDA = (iCylinder << RL11.RLDA.SHIFT.RW_CA) | (iHead? RL11.RLDA.RW_HS : 0) | (iSector & RL11.RLDA.RW_SA);
this.tmpRLDA = this.regRLDA;
this.regRLMP = (0x10000 - nWords) & 0xffff;
if (err) {
this.regRLCS |= err | RL11.RLCS.ERR;
if (nError) {
this.regRLCS |= nError | RL11.RLCS.ERR;
}
return true;
}

506
modules/pdp11/lib/rx11.js Normal file
View file

@ -0,0 +1,506 @@
/**
* @fileoverview Implements the RX11 Disk Controller (for RX01 Diskettes)
* @author <a href="mailto:Jeff@pcjs.org">Jeff Parsons</a>
* @copyright © Jeff Parsons 2012-2017
*
* This file is part of PCjs, a computer emulation software project at <http://pcjs.org/>.
*
* It has been adapted from the JavaScript PDP 11/70 Emulator written by Paul Nankervis
* (paulnank@hotmail.com) at <http://skn.noip.me/pdp11/pdp11.html>. This code may be used
* freely provided the original authors are acknowledged in any modified source code.
*
* PCjs is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* PCjs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCjs. If not,
* see <http://www.gnu.org/licenses/gpl.html>.
*
* You are required to include the above copyright notice in every modified copy of this work
* and to display that copyright notice when the software starts running; see COPYRIGHT in
* <http://pcjs.org/modules/shared/lib/defines.js>.
*
* Some PCjs files also attempt to load external resource files, such as character-image files,
* ROM files, and disk image files. Those external resource files are not considered part of PCjs
* for purposes of the GNU General Public License, and the author does not claim any copyright
* as to their contents.
*/
"use strict";
if (NODE) {
var Str = require("../../shared/lib/strlib");
var PDP11 = require("./defines");
var MessagesPDP11 = require("./messages");
var DriveController = require("./drive");
}
class RX11 extends DriveController {
/**
* RX11(parms)
*
* The RX11 component has the following component-specific (parms) properties:
*
* autoMount: one or more JSON-encoded objects, each containing 'name' and 'path' properties
*
* The RX11 Disk Controller controls up to two RX01 disk drives, which in turn read/write
* disk cartridges. See [RX11 Disk Controller Configuration Files](/devices/pdp11/rx11/).
*
* RX01 diskettes are single-sided, with 77 tracks per side, 26 sectors per track, and a sector size
* of 128 bytes, for a total capacity of 250Kb (256,256 bytes). See [RX01 Disk Images](/disks/dec/rx01/).
*
* @param {Object} parms
*/
constructor(parms)
{
super("RX11", parms, MessagesPDP11.RX11, PDP11.RX11, PDP11.RX11.RX01, RX11.UNIBUS_IOTABLE);
/*
* Define all the registers required for this controller.
*/
this.regRXCS = this.regRXDB = 0;
this.regRXTA = this.regRXSA = this.regRXES = this.regError = 0;
/*
* Whenever a command is issued, we record the function code internally here, and when the command
* is completed, we set the internal function code back to UNUSED.
*/
this.funCode = RX11.FUNC.UNUSED;
this.iBuffer = 0;
/*
* We use the new ES6 fill() method to ensure that the buffer returns something reasonable if, for some
* strange reason, the first command we receive is an Empty Buffer command.
*/
this.abBuffer = new Array(128).fill(0);
}
/**
* initController(aRegs)
*
* @this {RX11}
* @param {Array} [aRegs]
* @return {boolean} true if successful, false if failure
*/
initController(aRegs)
{
if (!aRegs) {
aRegs = [0, 0];
}
/*
* ES6 ALERT: A handy destructuring assignment, which makes it easy to perform the inverse
* of what saveController() does when it collects a bunch of object properties into an array.
*/
[
this.regRXCS,
this.regRXDB,
this.regRXTA,
this.regRXSA,
this.regRXES,
this.regError,
this.iBuffer,
this.abBuffer
] = aRegs;
return true;
}
/**
* saveController()
*
* Basically, the inverse of initController().
*
* @this {RX11}
* @return {Array}
*/
saveController()
{
return [
this.regRXCS,
this.regRXDB,
this.regRXTA,
this.regRXSA,
this.regRXES,
this.regError,
this.iBuffer,
this.abBuffer
];
}
/**
* processCommand()
*
* @this {RX11}
*/
processCommand()
{
this.funCode = this.regRXCS & RX11.RXCS.FUNC;
this.regRXCS &= ~(RX11.RXCS.GO | RX11.RXCS.TR | RX11.RXCS.DONE | RX11.RXCS.ERR);
switch(this.funCode) {
case RX11.FUNC.FILL:
case RX11.FUNC.EMPTY:
case RX11.FUNC.READ:
case RX11.FUNC.WRITE:
case RX11.FUNC.WRDEL:
this.initCommand();
break;
case RX11.FUNC.RDSTAT:
this.readStatus();
break;
case RX11.FUNC.RDERR:
this.readError();
break;
default:
if (this.messageEnabled()) this.printMessage(this.type + ": UNSUPPORTED(" + this.funCode + ")");
this.funCode = RX11.FUNC.UNUSED;
break;
}
}
/**
* initCommand()
*
* @this {RX11}
*/
initCommand()
{
this.iBuffer = 0;
}
/**
* doneCommand(nError)
*
* @this {RX11}
* @param {number} [nError]
*/
doneCommand(nError)
{
if (nError) {
this.regError = nError;
this.regRXDB = this.regRXES;
this.regRXCS |= RX11.RXCS.ERR;
}
this.funCode = RX11.FUNC.UNUSED;
this.regRXCS |= RX11.RXCS.DONE;
if (this.regRXCS & RX11.RXCS.IE) this.cpu.setIRQ(this.irq);
}
/**
* readData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
*
* This function is required ONLY if we want to support DriveController's bootSelectedDisk() function (and we do).
*
* @this {RX11}
* @param {Object} drive
* @param {number} iCylinder
* @param {number} iHead
* @param {number} iSector
* @param {number} nWords
* @param {number} addr
* @param {number} inc (normally 2, unless inhibited, in which case it's 0)
* @param {boolean} [fCheck]
* @param {function(...)} [done]
* @return {boolean|number} true if complete, false if queued (or if no done() is supplied, the error code, if any)
*/
readData(drive, iCylinder, iHead, iSector, nWords, addr, inc, fCheck, done)
{
var nError = 0;
var disk = drive.disk;
var sector = null, ibSector;
if (!disk) {
nError = drive.iDrive? RX11.ERROR.HOME1 : RX11.ERROR.HOME0;
nWords = 0;
}
var sWords = "";
while (nWords) {
if (!sector) {
if (iCylinder >= disk.nCylinders) {
nError = RX11.ERROR.NO_TRACK;
break;
}
sector = disk.seek(iCylinder, iHead, iSector);
if (!sector) {
nError = RX11.ERROR.NO_SECTOR;
break;
}
ibSector = 0;
if (++iSector >= disk.nSectors) {
iSector = 0;
if (++iHead >= disk.nHeads) {
iHead = 0;
++iCylinder;
}
}
}
var b0, b1;
if ((b0 = disk.read(sector, ibSector++)) < 0 || (b1 = disk.read(sector, ibSector++)) < 0) {
nError = RX11.ERROR.NO_DATA;
break;
}
var data = b0 | (b1 << 8);
this.bus.setWordDirect(this.cpu.mapUnibus(addr), data);
if (DEBUG && this.messageEnabled(MessagesPDP11.READ)) {
if (!sWords) sWords = Str.toOct(addr) + ": ";
sWords += Str.toOct(data) + ' ';
if (sWords.length >= 64) {
console.log(sWords);
sWords = "";
}
}
if (ibSector >= disk.cbSector) sector = null;
addr += inc;
nWords--;
}
return done? done(nError, iCylinder, iHead, iSector, nWords, addr) : nError;
}
/**
* readSector()
*
* @this {RX11}
*/
readSector()
{
var nError = 0;
var iDrive = (this.regRXCS & RX11.RXCS.UNIT)? 1 : 0;
var drive = this.aDrives[iDrive];
var disk = drive.disk;
var iCylinder = this.regRXTA & RX11.RXTA.MASK, iHead = 0, iSector = this.regRXSA & RX11.RXSA.MASK;
this.regRXES &= ~(RX11.RXES.CRC | RX11.RXES.PARITY | RX11.RXES.DEL | RX11.RXES.DRDY);
if (disk) {
this.regRXES |= RX11.RXES.DRDY;
this.assert(!iSector); // RX sector numbers (unlike RK and RL) are supposed to be 1-based
var sector = disk.seek(iCylinder, iHead, iSector, true);
if (sector) {
var i = 0, nBytes = this.abBuffer.length;
while (i < nBytes) {
var b = disk.read(sector, i);
if (b < 0) {
nError = RX11.ERROR.NO_DATA;
break;
}
this.abBuffer[i++] = b;
}
if (sector.deleted) this.regRXES |= RX11.RXES.DEL;
} else {
nError = RX11.ERROR.NO_SECTOR;
}
} else {
nError = iDrive? RX11.ERROR.HOME1 : RX11.ERROR.HOME0;
}
this.doneCommand(nError);
}
/**
* writeSector(fDeleted)
*
* @this {RX11}
* @param {boolean} fDeleted
*/
writeSector(fDeleted)
{
var nError = 0;
var iDrive = (this.regRXCS & RX11.RXCS.UNIT)? 1 : 0;
var drive = this.aDrives[iDrive];
var disk = drive.disk;
var iCylinder = this.regRXTA & RX11.RXTA.MASK, iHead = 0, iSector = this.regRXSA & RX11.RXSA.MASK;
this.regRXES &= ~(RX11.RXES.CRC | RX11.RXES.PARITY | RX11.RXES.DEL | RX11.RXES.DRDY);
if (disk) {
this.regRXES |= RX11.RXES.DRDY;
this.assert(!iSector); // RX sector numbers (unlike RK and RL) are supposed to be 1-based
var sector = disk.seek(iCylinder, iHead, iSector, true);
if (sector) {
if (fDeleted) sector.deleted = true;
var i = 0, nBytes = this.abBuffer.length;
while (i < nBytes) {
var data = this.abBuffer[i];
if (!disk.write(sector, i, data & 0xff)) {
nError = RX11.ERROR.NO_DATA;
break;
}
i++;
}
} else {
nError = RX11.ERROR.NO_SECTOR;
}
} else {
nError = iDrive? RX11.ERROR.HOME1 : RX11.ERROR.HOME0;
}
this.doneCommand(nError);
}
/**
* readStatus()
*
* @this {RX11}
*/
readStatus()
{
var iDrive = (this.regRXCS & RX11.RXCS.UNIT)? 1 : 0;
var drive = this.aDrives[iDrive];
this.regRXES &= ~RX11.RXES.DRDY;
if (drive && drive.disk) this.regRXES |= RX11.RXES.DRDY;
this.regRXDB = this.regRXES;
this.doneCommand();
}
/**
* readError()
*
* @this {RX11}
*/
readError()
{
this.regRXDB = this.regError;
this.doneCommand();
}
/**
* readRXCS(addr)
*
* @this {RX11}
* @param {number} addr (eg, PDP11.UNIBUS.RXCS or 177170)
* @return {number}
*/
readRXCS(addr)
{
var w = this.regRXCS & RX11.RXCS.RMASK;
switch(this.funCode) {
case RX11.FUNC.FILL:
if (this.iBuffer < this.abBuffer.length) {
this.regRXCS |= RX11.RXCS.TR;
}
break;
}
return w;
}
/**
* writeRXCS(data, addr)
*
* @this {RX11}
* @param {number} data
* @param {number} addr (eg, PDP11.UNIBUS.RXCS or 177170)
*/
writeRXCS(data, addr)
{
this.regRXCS = (this.regRXCS & ~RX11.RXCS.WMASK) | (data & RX11.RXCS.WMASK);
if (this.regRXCS & RX11.RXCS.GO) this.processCommand();
}
/**
* readRXDB(addr)
*
* @this {RX11}
* @param {number} addr (eg, PDP11.UNIBUS.RXDB or 177172)
* @return {number}
*/
readRXDB(addr)
{
switch(this.funCode) {
case RX11.FUNC.EMPTY:
if (this.regRXCS & RX11.RXCS.TR) {
this.regRXCS &= ~RX11.RXCS.TR;
this.assert(this.iBuffer < this.abBuffer.length);
this.regRXDB = this.abBuffer[this.iBuffer++] & 0xff;
if (this.iBuffer >= this.abBuffer.length) {
this.doneCommand();
}
}
break;
}
return this.regRXDB;
}
/**
* writeRXDB(data, addr)
*
* @this {RX11}
* @param {number} data
* @param {number} addr (eg, PDP11.UNIBUS.RXDB or 177172)
*/
writeRXDB(data, addr)
{
switch(this.funCode) {
case RX11.FUNC.FILL:
if (this.regRXCS & RX11.RXCS.TR) {
this.regRXCS &= ~RX11.RXCS.TR;
this.assert(this.iBuffer < this.abBuffer.length);
this.abBuffer[this.iBuffer++] = data & 0xff;
if (this.iBuffer >= this.abBuffer.length) {
this.doneCommand();
}
}
break;
case RX11.FUNC.READ:
case RX11.FUNC.WRITE:
case RX11.FUNC.WRDEL:
if (this.regRXCS & RX11.RXCS.TR) {
this.regRXCS &= ~RX11.RXCS.TR;
switch(this.iBuffer++) {
case 0:
this.regRXSA = data;
break;
case 1:
this.regRXTA = data;
if (this.funCode == RX11.FUNC.READ) {
this.readSector();
} else {
this.writeSector(this.funCode == RX11.FUNC.WRDEL);
}
break;
default:
this.assert(false);
break;
}
}
break;
}
this.regRXDB = data;
}
}
/*
* Alias RX11 definitions as class constants
*/
RX11.RXCS = PDP11.RX11.RXCS; // 177170: Command and Status Register
RX11.RXDB = PDP11.RX11.RXDB; // 177172: Data Buffer Register
RX11.RXTA = PDP11.RX11.RXTA;
RX11.RXSA = PDP11.RX11.RXSA;
RX11.RXES = PDP11.RX11.RXES;
RX11.FUNC = PDP11.RX11.FUNC;
RX11.ERROR = PDP11.RX11.ERROR;
/*
* ES6 ALERT: As you can see below, I've finally started using computed property names.
*/
RX11.UNIBUS_IOTABLE = {
[PDP11.UNIBUS.RXCS]: /* 177170 */ [null, null, RX11.prototype.readRXCS, RX11.prototype.writeRXCS, "RXCS"],
[PDP11.UNIBUS.RXDB]: /* 177172 */ [null, null, RX11.prototype.readRXDB, RX11.prototype.writeRXDB, "RXDB"]
};
if (NODE) module.exports = RX11;