logicsimulator/components/ic74xx283.ts

71 lines
3.0 KiB
TypeScript

// 74xx283 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 IC74xx283Init() {
class IC74xx283 extends DILBase {
constructor(simulator: Simulator, id: string, param: BaseComponentParam) {
super(simulator, id, 16, param);
}
setup(canvas: SVGElement) {
super.DILBASEsetup('ic16', canvas, '74xx283');
}
update(): boolean {
if (this.startdelay) {
--this.startdelay;
return false;
}
if (this.binary(this.getStateWire('p16'), true) !== true || this.binary(this.getStateWire('p8'), true) !== false)
return false; // no power
let mod = false;
let state;
state =
this.asint(this.binary(this.getStateWire('p5'), true), 1) +
this.asint(this.binary(this.getStateWire('p6'), true), 1) +
this.asint(this.binary(this.getStateWire('p7'), true), 1);
mod ||= this.asint(this.binary(this.getStateWire('p4'), true), 1) !== (state & 1);
this.getPin('p4').setBool((state & 1) === 1);
state =
this.asint(this.binary(this.getStateWire('p3'), true), 1) +
this.asint(this.binary(this.getStateWire('p2'), true), 1) +
(state > 1 ? 1 : 0);
mod ||= this.asint(this.binary(this.getStateWire('p1'), true), 1) !== (state & 1);
this.getPin('p1').setBool((state & 1) === 1);
state =
this.asint(this.binary(this.getStateWire('p14'), true), 1) +
this.asint(this.binary(this.getStateWire('p15'), true), 1) +
(state > 1 ? 1 : 0);
mod ||= this.asint(this.binary(this.getStateWire('p13'), true), 1) !== (state & 1);
this.getPin('p13').setBool((state & 1) === 1);
state =
this.asint(this.binary(this.getStateWire('p12'), true), 1) +
this.asint(this.binary(this.getStateWire('p11'), true), 1) +
(state > 1 ? 1 : 0);
mod ||= this.asint(this.binary(this.getStateWire('p10'), true), 1) !== (state & 1);
this.getPin('p10').setBool((state & 1) === 1);
mod ||= this.asint(this.binary(this.getStateWire('p9'), true), 2) !== (state & 2);
this.getPin('p9').setBool((state & 2) === 2);
return mod;
}
}
window.IC74xx283 = IC74xx283;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function IC74xx283Depends() {
return 'dilbase';
}