logicsimulator/components/ic74xx08.ts

72 lines
2.9 KiB
TypeScript

// 74xx08 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 IC74xx08Init() {
class IC74xx08 extends DILBase {
constructor(simulator: Simulator, id: string, param: BaseComponentParam) {
super(simulator, id, 14, param);
}
setup(canvas: SVGElement) {
super.DILBASEsetup('ic14', canvas, '74xx08');
}
update(): boolean {
if (this.startdelay) {
--this.startdelay;
return false;
}
if (this.getStateWire('p14') !== WireState.high || this.getStateWire('p7') !== WireState.low) return false; // no power
let mod = false;
let oldstate;
let s;
oldstate = this.getStateWire('p3');
s = this.binary(this.getStateWire('p1'), true) !== false && this.binary(this.getStateWire('p2'), true) !== false;
this.stateMapWire.set('p3', s ? WireState.high : WireState.low);
mod ||= this.getStateWire('p3') !== oldstate;
oldstate = this.getStateWire('p6');
s = this.binary(this.getStateWire('p4'), true) !== false && this.binary(this.getStateWire('p5'), true) !== false;
this.stateMapWire.set('p6', s ? WireState.high : WireState.low);
mod ||= this.getStateWire('p6') !== oldstate;
oldstate = this.getStateWire('p8');
s = this.binary(this.getStateWire('p9'), true) !== false && this.binary(this.getStateWire('p10'), true) !== false;
this.stateMapWire.set('p8', s ? WireState.high : WireState.low);
mod ||= this.getStateWire('p8') !== oldstate;
oldstate = this.getStateWire('p11');
s =
this.binary(this.getStateWire('p12'), true) !== false && this.binary(this.getStateWire('p13'), true) !== false;
this.stateMapWire.set('p11', s ? WireState.high : WireState.low);
mod ||= this.getStateWire('p11') !== oldstate;
this.getPin('p3').setState(this.getStateWire('p3'));
this.getPin('p6').setState(this.getStateWire('p6'));
this.getPin('p8').setState(this.getStateWire('p8'));
this.getPin('p11').setState(this.getStateWire('p11'));
return mod;
}
}
window.IC74xx08 = IC74xx08;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function IC74xx08Depends() {
return 'dilbase';
}