To Typescript

This commit is contained in:
Will Scullin 2021-12-25 13:25:38 -08:00
parent f6b239913a
commit 064dc0801d
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
3 changed files with 81 additions and 85 deletions

View File

@ -1,84 +0,0 @@
/* Copyright 2010-2019 Will Scullin <scullin@scullinsteel.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
import { debug, toHex } from '../util';
import { P7, P8A } from '../roms/cards/serial';
export default function Serial(io, cbs) {
debug('Serial card');
var SWITCHES = [
0, // SW1 Baud bit 0
0, // SW2 Baud bit 1
0, // SW3 Baud bit 2 000 - 19200
1, // SW4 CR Delay 1 - Disabled
1, // SW5 Width bit 0
1, // SW6 Width bit 1 11 - 40 Columns
1, // SW7 Line feed 1 - Disabled
];
var LOC = {
STATUS: 0x80,
DATA_1: 0x81,
DATA_0: 0x82
};
function init() {
debug('Serial Card');
}
function _access(off, val) {
var nextBit = 1;
var result = undefined;
if (val === undefined) {
result = 0;
for (var idx = 0; idx < 7; idx++) {
result >>= 1;
result |= SWITCHES[idx] ? 0x80 : 0;
}
result >>= 1;
result |= nextBit ? 0x80 : 0;
switch (off & 0x83) {
case LOC.STATUS:
break;
case LOC.DATA_1:
debug('xmit 1');
break;
case LOC.DATA_0:
debug('xmit 0');
break;
default:
debug('Serial card unknown soft switch', toHex(off));
}
} else {
debug('Serial card write to', toHex(off), toHex(val));
}
return result;
}
init();
return {
ioSwitch: function (off, val) {
return _access(off, val);
},
read: function(page, off) {
if (page < 0xC8) {
return P7[off];
} else {
return P8A[((page % 2) << 8) | off];
}
},
write: function() {}
};
}

77
js/cards/serial.ts Normal file
View File

@ -0,0 +1,77 @@
import { debug, toHex } from '../util';
import { P7, P8A } from '../roms/cards/serial';
import type { byte, Card } from 'js/types';
const LOC = {
STATUS: 0x80,
DATA_1: 0x81,
DATA_0: 0x82
} as const;
const SWITCHES = [
0, // SW1 Baud bit 0
0, // SW2 Baud bit 1
0, // SW3 Baud bit 2 000 - 19200
1, // SW4 CR Delay 1 - Disabled
1, // SW5 Width bit 0
1, // SW6 Width bit 1 11 - 40 Columns
1, // SW7 Line feed 1 - Disabled
] as const;
export default class Serial implements Card {
constructor() {
debug('Serial Card');
}
private _access(off: byte, val: byte) {
const nextBit = 1;
let result = undefined;
if (val === undefined) {
result = 0;
for (let idx = 0; idx < 7; idx++) {
result >>= 1;
result |= SWITCHES[idx] ? 0x80 : 0;
}
result >>= 1;
result |= nextBit ? 0x80 : 0;
switch (off & 0x83) {
case LOC.STATUS:
break;
case LOC.DATA_1:
debug('xmit 1');
break;
case LOC.DATA_0:
debug('xmit 0');
break;
default:
debug('Serial card unknown soft switch', toHex(off));
}
} else {
debug('Serial card write to', toHex(off), toHex(val));
}
return result;
}
ioSwitch(off: byte, val: byte) {
return this._access(off, val);
}
read(page: byte, off: byte) {
if (page < 0xC8) {
return P7[off];
} else {
return P8A[((page % 2) << 8) | off];
}
}
write(_page: byte, _off: byte, _val: byte) {
}
getState() {
return {};
}
setState(_: unknown) {
}
}

View File

@ -6,6 +6,7 @@ import Printer from './ui/printer';
import DiskII from './cards/disk2';
import Parallel from './cards/parallel';
import RAMFactor from './cards/ramfactor';
import Serial from './cards/serial';
import SmartPort from './cards/smartport';
import Thunderclock from './cards/thunderclock';
@ -59,10 +60,12 @@ apple2.ready.then(() => {
const slinky = new RAMFactor(1024 * 1024);
const disk2 = new DiskII(io, driveLights);
const clock = new Thunderclock();
const serial = new Serial();
const smartport = new SmartPort(cpu, { block: !enhanced });
io.setSlot(1, parallel);
io.setSlot(2, slinky);
io.setSlot(2, serial);
io.setSlot(3, slinky);
io.setSlot(5, clock);
io.setSlot(6, disk2);
io.setSlot(7, smartport);