jsbasic/printer.js
2013-08-16 01:37:54 -07:00

79 lines
2.0 KiB
JavaScript

//
// Applesoft BASIC in Javascript
// Printer (for copying output)
//
// Copyright (C) 2009-2011 Joshua Bell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
function Printer(tty, paper) {
var tty_writeChar = tty.writeChar;
tty.writeChar = function(c) {
tty_writeChar(c);
switch (c.charCodeAt(0)) {
case 0:
case 1:
case 2:
case 3:
case 4: // DOS hook
case 5:
case 6:
case 7: // (BEL) bell
case 8: // (BS) backspace
case 9:
case 11: // (VT) clear EOS
case 12: // (FF) clear
case 14: // (SO) normal
case 15: // (SI) inverse
case 16:
case 17: // (DC1) 40-column
case 18: // (DC2) 80-column
case 19: // (DC3) stop list
case 20:
case 21: // (NAK) quit (disable 80-col card)
case 22: // (SYN) scroll
case 23: // (ETB) scroll up
case 24: // (CAN) disable mousetext
case 25: // (EM) home
case 26: // (SUB) clear line
case 27: // (ESC) enable mousetext
case 28: // (FS) forward space
case 29: // (GS) clear EOL
case 30: // (RS) gotoXY
case 31:
break;
case 10: // (LF) line feed
case 13: // (CR) return
paper.appendChild(document.createTextNode('\n'));
break;
default:
paper.appendChild(document.createTextNode(c));
break;
}
if ('normalize' in paper) {
paper.normalize();
}
paper.scrollTop = paper.scrollHeight;
};
this.close = function() {
tty.writeChar = tty_writeChar;
};
}