logicsimulator/components/ic74xx374.ts

77 lines
3.2 KiB
TypeScript

// 74xx374 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 IC74xx374Init() {
class IC74xx374 extends DILBase {
private clock = false;
private internalstate: boolean[];
private oldinternalstate: boolean[];
constructor(simulator: Simulator, id: string, param: BaseComponentParam) {
super(simulator, id, 20, param);
this.internalstate = [];
this.oldinternalstate = [];
for (let i = 0; i <= 8; ++i) {
this.internalstate[i] = false;
this.oldinternalstate[i] = false;
}
}
setup(canvas: SVGElement) {
super.DILBASEsetup('ic20', canvas, '74xx374');
}
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('p11'), true) && this.clock === false) {
this.oldinternalstate = this.internalstate;
this.internalstate[0] = this.binary(this.getStateWire('p3'), true);
this.internalstate[1] = this.binary(this.getStateWire('p4'), true);
this.internalstate[2] = this.binary(this.getStateWire('p7'), true);
this.internalstate[3] = this.binary(this.getStateWire('p8'), true);
this.internalstate[4] = this.binary(this.getStateWire('p13'), true);
this.internalstate[5] = this.binary(this.getStateWire('p14'), true);
this.internalstate[6] = this.binary(this.getStateWire('p16'), true);
this.internalstate[7] = this.binary(this.getStateWire('p18'), true);
}
let mod = false;
if (this.binary(this.getStateWire('p1'), true) === false) {
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]);
mod = this.internalstate !== this.oldinternalstate;
}
this.clock = this.binary(this.getStateWire('p11'), true);
return mod;
}
}
window.IC74xx374 = IC74xx374;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function IC74xx374Depends() {
return 'dilbase';
}