84 lines
3.7 KiB
TypeScript
84 lines
3.7 KiB
TypeScript
// 74xx273 emulation component 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
|
|
function IC74xx273Init() {
|
|
class IC74xx273 extends DILBase {
|
|
private clock = false;
|
|
private internalstate: boolean[];
|
|
constructor(simulator: Simulator, id: string, param: BaseComponentParam) {
|
|
super(simulator, id, 20, param);
|
|
this.internalstate = [];
|
|
for (let i = 0; i < 8; ++i) {
|
|
this.internalstate[i] = false;
|
|
}
|
|
}
|
|
|
|
setup(canvas: SVGElement) {
|
|
super.DILBASEsetup('ic20', canvas, '74xx273');
|
|
}
|
|
|
|
update(): boolean {
|
|
if (this.startdelay) {
|
|
--this.startdelay;
|
|
return false;
|
|
}
|
|
if (this.getStateWire('p20') !== WireState.high || this.getStateWire('p10') !== WireState.low) return false; // no power
|
|
if (this.binary(this.getStateWire('p1'), true) === false) {
|
|
// reset
|
|
for (let i = 0; i < 8; ++i) {
|
|
this.internalstate[i] = false;
|
|
}
|
|
}
|
|
let mod = false;
|
|
if (this.binary(this.getStateWire('p11'), true) && this.clock === false) {
|
|
mod ||= this.internalstate[0] !== this.binary(this.getStateWire('p3'), true);
|
|
this.internalstate[0] = this.binary(this.getStateWire('p3'), true);
|
|
mod ||= this.internalstate[1] !== this.binary(this.getStateWire('p4'), true);
|
|
this.internalstate[1] = this.binary(this.getStateWire('p4'), true);
|
|
mod ||= this.internalstate[2] !== this.binary(this.getStateWire('p7'), true);
|
|
this.internalstate[2] = this.binary(this.getStateWire('p7'), true);
|
|
mod ||= this.internalstate[3] !== this.binary(this.getStateWire('p8'), true);
|
|
this.internalstate[3] = this.binary(this.getStateWire('p8'), true);
|
|
mod ||= this.internalstate[4] !== this.binary(this.getStateWire('p13'), true);
|
|
this.internalstate[4] = this.binary(this.getStateWire('p13'), true);
|
|
mod ||= this.internalstate[5] !== this.binary(this.getStateWire('p14'), true);
|
|
this.internalstate[5] = this.binary(this.getStateWire('p14'), true);
|
|
mod ||= this.internalstate[6] !== this.binary(this.getStateWire('p17'), true);
|
|
this.internalstate[6] = this.binary(this.getStateWire('p17'), true);
|
|
mod ||= this.internalstate[7] !== this.binary(this.getStateWire('p18'), true);
|
|
this.internalstate[7] = this.binary(this.getStateWire('p18'), true);
|
|
}
|
|
this.getPin('p2').setBool(this.internalstate[0]);
|
|
this.getPin('p5').setBool(this.internalstate[1]);
|
|
this.getPin('p6').setBool(this.internalstate[2]);
|
|
this.getPin('p9').setBool(this.internalstate[3]);
|
|
this.getPin('p12').setBool(this.internalstate[4]);
|
|
this.getPin('p15').setBool(this.internalstate[5]);
|
|
this.getPin('p16').setBool(this.internalstate[6]);
|
|
this.getPin('p19').setBool(this.internalstate[7]);
|
|
this.clock = this.binary(this.getStateWire('p11'), true);
|
|
return mod;
|
|
}
|
|
}
|
|
window.IC74xx273 = IC74xx273;
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
function IC74xx273Depends() {
|
|
return 'dilbase';
|
|
}
|