65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
// DIL Base class for the LogicSimulator
|
|
// Copyright (C) 2022 Sascha Nitsch
|
|
|
|
// This program 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.
|
|
|
|
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
class DILBase extends BaseComponent {
|
|
protected pincount: number;
|
|
constructor(simulator: Simulator, id: string, pincount: number, param: BaseComponentParam) {
|
|
super(simulator, id, param);
|
|
for (let i = 0; i < pincount / 2; ++i) {
|
|
this.pins.set('p' + (i + 1), new TriState(this, i * 5.08, 0, undefined, { id: 'p' + (i + 1) }));
|
|
this.pins.set(
|
|
'p' + (pincount - i),
|
|
new TriState(this, i * 5.08, -5.08 * 3, undefined, { id: 'p' + (pincount - i) })
|
|
);
|
|
this.stateMapWire.set('p' + (i + 1), WireState.float);
|
|
this.stateMapWire.set('p' + (pincount - i), WireState.float);
|
|
}
|
|
this.pincount = pincount;
|
|
}
|
|
|
|
DILBASEsetup(id: string, canvas: SVGElement, title: string) {
|
|
super.doSetup(id, canvas);
|
|
if (this.breadboard) {
|
|
for (let i = 0; i < this.pincount / 2; ++i) {
|
|
this.simulator.wire(
|
|
null,
|
|
[this.getPin('p' + (i + 1)), this.breadboard.getPin('E' + (i + this.col))],
|
|
this.id + 'p' + (i + 1)
|
|
);
|
|
this.simulator.wire(
|
|
null,
|
|
[this.getPin('p' + (this.pincount - i)), this.breadboard.getPin('F' + (i + this.col))],
|
|
this.id + 'p' + (this.pincount - i)
|
|
);
|
|
}
|
|
}
|
|
if (title && this.element) {
|
|
const text = this.element.getElementsByTagName('text');
|
|
if (text) {
|
|
const node = document.createTextNode(title);
|
|
text[0].appendChild(node);
|
|
}
|
|
}
|
|
}
|
|
|
|
io() {
|
|
for (let p = 1; p <= this.pincount; ++p) {
|
|
this.stateMapWire.set('p' + p, this.getPin('p' + p).getAndReset());
|
|
}
|
|
}
|
|
}
|