Merge branch 'next-release'

This commit is contained in:
Jeff Parsons 2016-08-14 10:53:54 -07:00
commit 780fb5ee01
11 changed files with 6067 additions and 5866 deletions

View file

@ -169,13 +169,29 @@ ChipSet.SI1978 = {
/*
* One of the many chips in the VT100 is an 8224, which operates at 24.8832MHz. That frequency is divided by 9
* to yield a 361.69ns clock period for the 8080 CPU, which means the CPU is running at 2.76Mhz (cycles per second).
* Hence the CPU component in the VT100's machine.xml is defined as:
* to yield a 361.69ns clock period for the 8080 CPU, which means (in theory) that the CPU is running at 2.76Mhz.
*
* Hence the CPU component in the VT100's machine.xml SHOULD be defined as:
*
* <cpu id="cpu8080" model="8080" cycles="2764800"/>
*
* where 2764800 = 24883200 / 9. You need to know this because we rely on the CPU frequency for simulating some
* of the other VT100 circuits.
* where 2764800 = 24883200 / 9. Unfortunately, the VT100 ROM decrements a countdown value in memory to determine
* cursor blink rate, and if we use 2764800 cycles per second, the cursor blinks MUCH too fast. It's surprising that
* the VT100 doesn't rely on vertical retrace interrupts for blink rate. Perhaps the designers were concerned about
* consistency across 60Hz and 50Hz display modes, although that seems like a minor concern, considering that the
* alternative means the ROM is now tied to a specific CPU operating frequency. However, short of rewriting portions
* of the ROM, we have to deal with it.
*
* And we deal with it by lowering cycles per second to 1000000 (1Mhz). I'm guessing that in a real VT100, the 8080
* gets bogged down by other factors (eg, the Video Processor's DMA requests), but we don't simulate the hardware to
* that level of detail, so the easiest solution is to lower the effective clock speed.
*
* NOTE: If you've noticed that the VT100 cursor blinks unevenly, you're right, and it's by design: the ROM uses a
* countdown value for the cursor's "on" state that is twice as large as that for the cursor's "off" state, so it's
* "on" twice as long as it's "off".
*
* WARNING: The choice of clock speed has an effect on other simulated VT100 circuits; see the DC011 Timing Chip
* discussion below, along with the getVT100LBA() function.
*
* For reference, here is a list of all the VT100 I/O ports, from /devices/pc8080/machine/vt100/debugger/README.md,
* which in turn comes from p. 4-17 of the VT100 Technical Manual (July 1982):
@ -386,6 +402,7 @@ ChipSet.prototype.initBus = function(cmp, bus, cpu, dbg)
this.cpu = cpu;
this.dbg = dbg;
this.cmp = cmp;
this.kbd = cmp.getMachineComponent("Keyboard");
bus.addPortInputTable(this, this.config.portsInput);
bus.addPortOutputTable(this, this.config.portsOutput);
};
@ -728,7 +745,7 @@ ChipSet.prototype.outSIWatchdog = function(port, b, addrFrom)
};
/**
* getVT100LBA(nBit)
* getVT100LBA(iBit)
*
* Returns the state of the requested (simulated) LBA bit.
*
@ -737,12 +754,12 @@ ChipSet.prototype.outSIWatchdog = function(port, b, addrFrom)
* period than if we divided the cycle count by 88, but a shorter LBA7 period is probably helpful in terms of
* overall performance.
*
* @param {number} nBit
* @param {number} iBit
* @return {number}
*/
ChipSet.prototype.getVT100LBA = function(nBit)
ChipSet.prototype.getVT100LBA = function(iBit)
{
return (this.cpu.getCycles() & (1 << (nBit - 1))) << 1;
return (this.cpu.getCycles() & (1 << (iBit - 1))) << 1;
};
/**
@ -852,6 +869,10 @@ ChipSet.prototype.inVT100FlagsBuffer = function(port, addrFrom)
if (this.bNVROut) {
b |= ChipSet.VT100.FLAGS_BUFFER.NVR_DATA;
}
b &= ~ChipSet.VT100.FLAGS_BUFFER.KBD_XMIT;
if (this.kbd && !this.kbd.checkBusy()) {
b |= ChipSet.VT100.FLAGS_BUFFER.KBD_XMIT;
}
this.bFlagsBuffer = b;
this.printMessageIO(port, null, addrFrom, "FLAGS.BUFFER", b);
return b;
@ -888,6 +909,10 @@ ChipSet.prototype.outVT100NVRLatch = function(port, b, addrFrom)
/**
* outVT100DC012(port, b, addrFrom)
*
* TODO: Consider whether we should disable any interrupts (eg, vertical retrace) until the
* this port is initialized at runtime. We initialize it ourselves at start-up, but our initial
* value is just a guess.
*
* @this {ChipSet}
* @param {number} port (0xA2)
* @param {number} b

View file

@ -939,6 +939,7 @@ CPUState.prototype.checkINTR = function()
{
if ((this.intFlags & CPUDef.INTFLAG.INTR) && this.getIF()) {
var bRST = CPUDef.OPCODE.RST0 | ((this.intFlags & CPUDef.INTFLAG.INTL) << 3);
this.intFlags &= ~CPUDef.INTFLAG.HALT;
this.clearINTR();
this.clearIF();
this.aOps[bRST].call(this);
@ -1096,16 +1097,30 @@ CPUState.prototype.stepCPU = function(nMinCycles)
do {
if (this.intFlags) {
if (this.checkINTR()) {
if (!nMinCycles) {
this.assert(DEBUGGER); // nMinCycles of zero should be generated ONLY by the Debugger
if (DEBUGGER) {
this.println("interrupt dispatched");
break;
}
}
/*
* We no longer call checkINTR() if the Debugger is single-stepping; you'll have to let the
* CPU run with a "g" (or a "p" on a call instruction) if you want interrupts to be processed.
*/
if (nMinCycles) {
/*
* NOTE: If checkINTR() returns true, it also clears INTFLAG.HALT, so we don't have to worry
* about the INTFLAG.HALT code below triggering.
*/
this.checkINTR();
/*
* If the Debugger is running, consider some new notification mechanism(s) regarding interrupt
* dispatches; the following code no longer applies, due to changes above.
*
* if (!nMinCycles && this.checkINTR()) {
* this.assert(DEBUGGER); // nMinCycles of zero should be generated ONLY by the Debugger
* if (DEBUGGER) {
* this.println("interrupt dispatched");
* break;
* }
* }
*/
}
else if (this.intFlags & CPUDef.INTFLAG.HALT) {
if (this.intFlags & CPUDef.INTFLAG.HALT) {
/*
* As discussed in opHLT(), the CPU is never REALLY halted by a HLT instruction; instead,
* opHLT() sets CPUDef.INTFLAG.HALT, signalling to us that we're free to end the current burst

View file

@ -109,7 +109,7 @@ Keyboard.ASCII = {
Keyboard.KEYCODE = {
/* 0x08 */ BS: 8,
/* 0x09 */ TAB: 9,
/* 0x0A */ LF: 10,
/* 0x0A */ LF: 10, // TODO: Determine if any key actually generates this (I suspect there is none)
/* 0x0D */ CR: 13,
/* 0x10 */ SHIFT: 16,
/* 0x11 */ CTRL: 17,
@ -249,7 +249,7 @@ Keyboard.STUPID_KEYCODES[Keyboard.KEYCODE.FF_DASH] = Keyboard.ASCII['-'];
Keyboard.MINPRESSTIME = 100; // 100ms
/**
* Alternate keyCode mappings (to support the popular WASD directional mappings)
* Alternate keyCode mappings (to support popular "WASD"-style directional-key mappings)
*
* TODO: ES6 computed property name support may now be in all mainstream browsers, allowing us to use
* a simple object literal for this and all other object initializations.
@ -286,10 +286,11 @@ Keyboard.VT100 = {
*
* Every time a keyboard scan is initiated (by setting the START bit of the status byte),
* an internal address index is reset to zero, and an interrupt is generated for each entry
* in the aKeysPressed array, along with a final interrupt for KEYLAST.
* in the aKeysActive array, along with a final interrupt for KEYLAST.
*/
ADDRESS: {
PORT: 0x82
PORT: 0x82,
INIT: 0x7F
},
/*
* Writing port 0x82 updates the VT100's keyboard status byte via the keyboard's UART data input.
@ -329,39 +330,56 @@ Keyboard.VT100.KEYMAP[Keyboard.ASCII.W] = 0x09;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.Q] = 0x0A;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.RIGHT] = 0x10;
Keyboard.VT100.KEYMAP[Keyboard.ASCII[']']] = 0x14;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['}']] = 0x94;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['[']] = 0x15;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['{']] = 0x95;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.I] = 0x16;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.U] = 0x17;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.R] = 0x18;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.E] = 0x19;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['1']] = 0x1A;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['!']] = 0x9A;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.LEFT] = 0x20;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.DOWN] = 0x22;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F6] = 0x23; // aka BREAK
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.PAUSE] = 0x23; // aka BREAK
Keyboard.VT100.KEYMAP[Keyboard.ASCII['`']] = 0x24;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['~']] = 0xA4;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['-']] = 0x25;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['_']] = 0xA5;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['9']] = 0x26;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['(']] = 0xA6;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['7']] = 0x27;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['&']] = 0xA7;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['4']] = 0x28;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['$']] = 0xA8;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['3']] = 0x29;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['#']] = 0xA9;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.ESC] = 0x2A;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.UP] = 0x30;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F3] = 0x31; // aka PF3
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F1] = 0x32; // aka PF1
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.BS] = 0x33;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['=']] = 0x34;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['+']] = 0xB4;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['0']] = 0x35;
Keyboard.VT100.KEYMAP[Keyboard.ASCII[')']] = 0xB5;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['8']] = 0x36;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['*']] = 0xB6;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['6']] = 0x37;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['^']] = 0xB7;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['5']] = 0x38;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['%']] = 0xB8;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['2']] = 0x39;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['@']] = 0xB9;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.TAB] = 0x3A;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_7] = 0x40;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F4] = 0x41; // aka PF4
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F2] = 0x42; // aka PF2
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_0] = 0x43;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.LF] = 0x44;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F7] = 0x44; // aka LINE FEED
Keyboard.VT100.KEYMAP[Keyboard.ASCII['\\']] = 0x45;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['|']] = 0xC5;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.L] = 0x46;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.K] = 0x47;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.G] = 0x48;
@ -372,33 +390,38 @@ Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_CR] = 0x51;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_2] = 0x52;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_1] = 0x53;
Keyboard.VT100.KEYMAP[Keyboard.ASCII["'"]] = 0x55;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['"']] = 0xD5;
Keyboard.VT100.KEYMAP[Keyboard.ASCII[';']] = 0x56;
Keyboard.VT100.KEYMAP[Keyboard.ASCII[':']] = 0xD6;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.J] = 0x57;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.H] = 0x58;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.D] = 0x59;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.S] = 0x5A;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_DEL] = 0x60; // keypad period
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F8] = 0x61; // aka keypad comma
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F5] = 0x61; // aka KEYPAD COMMA
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_5] = 0x62;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_4] = 0x63;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.CR] = 0x64; // TODO: Figure out why the Technical Manual lists CR at both 0x04 and 0x64
Keyboard.VT100.KEYMAP[Keyboard.ASCII['.']] = 0x65;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['>']] = 0xE5;
Keyboard.VT100.KEYMAP[Keyboard.ASCII[',']] = 0x66;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['<']] = 0xE6;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.N] = 0x67;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.B] = 0x68;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.X] = 0x69;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F9] = 0x6A; // aka NO SCROLL
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F8] = 0x6A; // aka NO SCROLL
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_9] = 0x70;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_3] = 0x71;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_6] = 0x72;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_SUB] = 0x73;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.NUM_SUB] = 0x73; // aka KEYPAD MINUS
Keyboard.VT100.KEYMAP[Keyboard.ASCII['/']] = 0x75;
Keyboard.VT100.KEYMAP[Keyboard.ASCII['?']] = 0xF5;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.M] = 0x76;
Keyboard.VT100.KEYMAP[Keyboard.ASCII[' ']] = 0x77;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.V] = 0x78;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.C] = 0x79;
Keyboard.VT100.KEYMAP[Keyboard.ASCII.Z] = 0x7A;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F10] = 0x7B; // aka SET-UP
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.F9] = 0x7B; // aka SET-UP
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.CTRL] = 0x7C;
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.SHIFT] = 0x7D; // either shift key (doesn't matter)
Keyboard.VT100.KEYMAP[Keyboard.KEYCODE.CAPSLOCK]= 0x7E;
@ -560,8 +583,9 @@ Keyboard.prototype.powerDown = function(fSave, fShutdown)
Keyboard.VT100.INIT = [
[
Keyboard.VT100.STATUS.INIT,
0 // iKeyNext
Keyboard.VT100.STATUS.INIT, // bVT100Status
Keyboard.VT100.ADDRESS.INIT, // bVT100Address
-1 // iKeyNext
]
];
@ -574,7 +598,7 @@ Keyboard.prototype.reset = function()
{
/*
* As keyDown events are encountered, a corresponding "softCode" is looked up. If one is found,
* then an entry for the key is added to the aKeysPressed array. Each entry contains:
* then an entry for the key is added to the aKeysActive array. Each "key" entry in aKeysActive contains:
*
* softCode: number or string representing the key pressed
* msDown: timestamp of the most recent "down" event
@ -582,7 +606,7 @@ Keyboard.prototype.reset = function()
*
* When the key is finally released (or auto-released), its entry is removed from the array.
*/
this.aKeysPressed = [];
this.aKeysActive = [];
if (this.config.INIT && !this.restore(this.config.INIT)) {
this.notice("reset error");
@ -604,7 +628,7 @@ Keyboard.prototype.save = function()
case Keyboard.SI1978.MODEL:
break;
case Keyboard.VT100.MODEL:
state.set(0, [this.bVT100Status]);
state.set(0, [this.bVT100Status, this.bVT100Address, -1]);
break;
}
return state.data();
@ -630,7 +654,8 @@ Keyboard.prototype.restore = function(data)
case Keyboard.VT100.MODEL:
this.bVT100Status = a[0];
this.updateLEDs(this.bVT100Status & Keyboard.VT100.STATUS.LEDS);
this.iKeyNext = a[1];
this.bVT100Address = a[1];
this.iKeyNext = a[2];
return true;
}
}
@ -717,7 +742,7 @@ Keyboard.prototype.onKeyDown = function(event, fDown)
}
if (!COMPILED && this.messageEnabled(Messages.KEYS)) {
this.printMessage("onKey" + (fDown? "Down" : "Up") + "(" + keyCode + "): " + (fPass? "true" : "false"), true);
this.printMessage("onKey" + (fDown? "Down" : "Up") + "(" + keyCode + "): softCode=" + softCode + ", pass=" + (fPass? "true" : "false"), true);
}
return fPass;
@ -728,13 +753,13 @@ Keyboard.prototype.onKeyDown = function(event, fDown)
*
* @this {Keyboard}
* @param {number|string} softCode
* @return {number} index of softCode in aKeysPressed, or -1 if not found
* @return {number} index of softCode in aKeysActive, or -1 if not found
*/
Keyboard.prototype.indexOfSoftKey = function(softCode)
{
var i;
for (i = 0; i < this.aKeysPressed.length; i++) {
if (this.aKeysPressed[i].softCode == softCode) return i;
for (i = 0; i < this.aKeysActive.length; i++) {
if (this.aKeysActive[i].softCode == softCode) return i;
}
return -1;
};
@ -753,30 +778,30 @@ Keyboard.prototype.onSoftKeyDown = function(softCode, fDown)
if (fDown) {
// this.println(softCode + " down");
if (i < 0) {
this.aKeysPressed.push({
this.aKeysActive.push({
softCode: softCode,
msDown: Date.now(),
fAutoRelease: false
});
} else {
this.aKeysPressed[i].msDown = Date.now();
this.aKeysPressed[i].fAutoRelease = false;
this.aKeysActive[i].msDown = Date.now();
this.aKeysActive[i].fAutoRelease = false;
}
} else if (i >= 0) {
// this.println(softCode + " up");
if (!this.aKeysPressed[i].fAutoRelease) {
var msDown = this.aKeysPressed[i].msDown;
if (!this.aKeysActive[i].fAutoRelease) {
var msDown = this.aKeysActive[i].msDown;
if (msDown) {
var msElapsed = Date.now() - msDown;
if (msElapsed < Keyboard.MINPRESSTIME) {
// this.println(softCode + " released after only " + msElapsed + "ms");
this.aKeysPressed[i].fAutoRelease = true;
this.aKeysActive[i].fAutoRelease = true;
this.checkSoftKeysToRelease();
return true;
}
}
}
this.aKeysPressed.splice(i, 1);
this.aKeysActive.splice(i, 1);
} else {
// this.println(softCode + " up with no down?");
}
@ -820,10 +845,10 @@ Keyboard.prototype.checkSoftKeysToRelease = function()
{
var i = 0;
var msDelayMin = -1;
while (i < this.aKeysPressed.length) {
if (this.aKeysPressed[i].fAutoRelease) {
var softCode = this.aKeysPressed[i].softCode;
var msDown = this.aKeysPressed[i].msDown;
while (i < this.aKeysActive.length) {
if (this.aKeysActive[i].fAutoRelease) {
var softCode = this.aKeysActive[i].softCode;
var msDown = this.aKeysActive[i].msDown;
var msElapsed = Date.now() - msDown;
var msDelay = Keyboard.MINPRESSTIME - msElapsed;
if (msDelay > 0) {
@ -849,9 +874,28 @@ Keyboard.prototype.checkSoftKeysToRelease = function()
}
};
/**
* checkBusy()
*
* Called whenever a ChipSet circuit needs the keyboard's UART status.
* Currently, we have no busy conditions (our virtual keyboard is infinitely fast).
*
* @this {Keyboard}
* @return {boolean}
*/
Keyboard.prototype.checkBusy = function()
{
return false;
};
/**
* inVT100UARTAddress(port, addrFrom)
*
* We take our cue from iKeyNext. If it's -1 (default), we simply return the last value latched
* in bVT100Address. Otherwise, if iKeyNext is a valid index into aKeysActive, we look up the key
* in the VT100.KEYMAP, latch it, and increment iKeyNext, else we latch Keyboard.VT100.KEYLAST
* and set iKeyNext to -1 again.
*
* @this {Keyboard}
* @param {number} port (0x82)
* @param {number} [addrFrom] (not defined if the Debugger is trying to write the specified port)
@ -859,12 +903,24 @@ Keyboard.prototype.checkSoftKeysToRelease = function()
*/
Keyboard.prototype.inVT100UARTAddress = function(port, addrFrom)
{
var b = 0;
if (this.iKeyNext >= 0 && this.iKeyNext < this.aKeysPressed.length - 1) {
var softCode = this.aKeysPressed[this.iKeyNext++];
b = Keyboard.VT100.KEYMAP[softCode];
var b = this.bVT100Address;
if (this.iKeyNext >= 0) {
if (this.iKeyNext < this.aKeysActive.length) {
var key = this.aKeysActive[this.iKeyNext++];
b = Keyboard.VT100.KEYMAP[key.softCode];
if (b & 0x80) {
/*
* TODO: This code is supposed to be accompanied by a SHIFT key; make sure that it is.
*/
b &= 0x7F;
}
} else {
this.iKeyNext = -1;
b = Keyboard.VT100.KEYLAST;
}
this.bVT100Address = b;
this.cpu.requestINTR(1);
}
if (!b) b = Keyboard.VT100.KEYLAST;
this.printMessageIO(port, null, addrFrom, "KBDUART.ADDRESS", b);
return b;
};

View file

@ -320,7 +320,10 @@ Video.prototype.initBuffers = function()
* for each font and draw characters by drawing from the font canvas to the target canvas.
*/
if (this.cxCell > 1) {
this.initCellCache(this.nColsBuffer * this.nRowsBuffer);
/*
* We add an extra column per row to store the visible line length at the start of every row.
*/
this.initCellCache((this.nColsBuffer + 1) * this.nRowsBuffer);
} else {
this.imageBuffer = this.contextScreen.createImageData(cxBuffer, cyBuffer);
this.nPixelsPerCell = (16 / this.nBitsPerPixel)|0;
@ -959,11 +962,12 @@ Video.prototype.updateChar = function(idFont, col, row, data, context)
};
/**
* updateVT100()
* updateVT100(fForced)
*
* @this {Video}
* @param {boolean} [fForced]
*/
Video.prototype.updateVT100 = function()
Video.prototype.updateVT100 = function(fForced)
{
var addrNext = this.addrBuffer, fontNext = -1;
@ -979,6 +983,8 @@ Video.prototype.updateVT100 = function()
var nCols = 0;
var addr = addrNext;
var font = fontNext;
var nColsVisible = this.nColsBuffer;
if (font != Video.VT100.FONT.NORML) nColsVisible >>= 1;
while (true) {
var data = this.bus.getByteDirect(addr++);
if ((data & Video.VT100.LINETERM) == Video.VT100.LINETERM) {
@ -988,7 +994,7 @@ Video.prototype.updateVT100 = function()
addrNext += (b & Video.VT100.LINEATTR.ADDRBIAS)? Video.VT100.ADDRBIAS_LO : Video.VT100.ADDRBIAS_HI;
break;
}
if (nCols < this.abLineBuffer.length) {
if (nCols < nColsVisible) {
this.abLineBuffer[nCols++] = data;
} else {
break; // ideally, we would wait for a LINETERM byte, but it's not safe to loop without limit
@ -1011,13 +1017,21 @@ Video.prototype.updateVT100 = function()
}
/*
* Display the line buffer; ordinarily, the font number would always be valid after processing the "fill lines",
* but if the buffer isn't initialized yet, the usual LINETERM might be missing, so the font number might not be set.
* Display the line buffer; ordinarily, the font number would be valid after processing the "fill lines",
* but if the buffer isn't initialized yet, those lines might be missing, so the font number might not be set.
*/
if (font >= 0) {
/*
* Cell cache logic is complicated by the fact that a line may be single-width one frame and double-width
* the next. So we store the visible line length at the start of each row in the cache, which must match if
* the cache is considered valid for the current line.
*/
var fLineCacheValid = this.fCellCacheValid && (this.aCellCache[iCell] == nColsVisible);
this.aCellCache[iCell++] = nColsVisible;
for (var iCol = 0; iCol < nCols; iCol++) {
data = this.abLineBuffer[iCol];
if (!this.fCellCacheValid || data !== this.aCellCache[iCell]) {
if (!fLineCacheValid || data !== this.aCellCache[iCell]) {
this.aCellCache[iCell] = data;
this.updateChar(font, iCol, nRows, data, this.contextBuffer);
cUpdated++;
}
@ -1027,6 +1041,18 @@ Video.prototype.updateVT100 = function()
nRows++;
}
this.assert(font < 0 || iCell === this.nCellCache);
if (MAXDEBUG && !fForced) {
var nSeconds = Date.now() / 1000;
if ((nSeconds|0) != (this.nUpdateSeconds|0)) {
this.nUpdateNumber = 0;
}
this.nUpdateNumber++;
this.nUpdateSeconds = nSeconds;
this.printMessage("updateVT100(): update #" + this.nUpdateNumber + " at " +this.nUpdateSeconds + " corner=" + str.toHexByte(this.aCellCache[1]) + " cycles=" + this.nCyclesPrev + " delta=" + this.nCyclesDelta);
}
this.fCellCacheValid = true;
if (cUpdated && this.contextBuffer) {
@ -1056,9 +1082,10 @@ Video.prototype.updateScreen = function(n)
{
var fClean;
var fUpdate = true;
var fForced = true;
if (n >= 0) {
fForced = false;
if (this.rateInterrupt) {
/*
* TODO: Incorporate these hard-coded interrupt vector numbers into configuration blocks.
@ -1093,11 +1120,11 @@ Video.prototype.updateScreen = function(n)
}
}
if (DEBUG) {
if (DEBUG && !fForced) {
var nCycles = this.cpu.getCycles();
var nCyclesDelta = nCycles - this.nCyclesPrev;
this.nCyclesDelta = nCycles - this.nCyclesPrev;
this.nCyclesPrev = nCycles;
this.printMessage("updateScreen(" + n + "): clean=" + fClean + ", update=" + fUpdate + ", cycles=" + nCycles + ", delta=" + nCyclesDelta);
if (MAXDEBUG) this.printMessage("updateScreen(" + n + "): clean=" + fClean + ", update=" + fUpdate + ", cycles=" + this.nCyclesPrev + ", delta=" + this.nCyclesDelta);
}
if (!fUpdate) {
@ -1105,32 +1132,34 @@ Video.prototype.updateScreen = function(n)
}
if (this.cxCell > 1) {
this.updateScreenText();
this.updateScreenText(fForced);
} else {
this.updateScreenGraphics();
this.updateScreenGraphics(fForced);
}
};
/**
* updateScreenText()
* updateScreenText(fForced)
*
* @this {Video}
* @param {boolean} [fForced]
*/
Video.prototype.updateScreenText = function()
Video.prototype.updateScreenText = function(fForced)
{
switch(this.nFormat) {
case Video.FORMAT.VT100:
this.updateVT100();
this.updateVT100(fForced);
break;
}
};
/**
* updateScreenGraphics()
* updateScreenGraphics(fForced)
*
* @this {Video}
* @param {boolean} [fForced]
*/
Video.prototype.updateScreenGraphics = function()
Video.prototype.updateScreenGraphics = function(fForced)
{
var addr = this.addrBuffer;
var addrLimit = addr + this.sizeBuffer;