// Chip select component for the LogicSimulator used on the 8-bit-computer // 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 . // eslint-disable-next-line @typescript-eslint/no-unused-vars class ChipSelect extends BaseComponent { private addr = 0; private rom = true; private ram = true; constructor(simulator: Simulator, id: string, param: BaseComponentParam) { super(simulator, id, param); for (let a = 0; a < 8; ++a) { this.pins.set('A' + (15 - a), new TriState(this, -40, a * 10 - 35)); } this.pins.set('rom', new TriState(this, 40, -25)); this.pins.set('ram', new TriState(this, 40, -35)); } setup(canvas: SVGElement) { super.doSetup('chipselect', canvas); } update(): boolean { const addr = this.addr; let changed = false; if (addr < 0x3fff) { // ROM changed ||= this.rom !== false || this.ram !== true; this.getPin('rom').setBool(false); this.getPin('ram').setBool(true); } else if (addr < 0x7fff) { // RAM changed ||= this.rom !== false || this.ram !== true; this.getPin('rom').setBool(true); this.getPin('ram').setBool(false); } else { this.getPin('rom').setBool(true); this.getPin('ram').setBool(true); } return changed; } io() { this.getPin('rom').getAndReset(); this.getPin('ram').getAndReset(); this.addr = 0; let multi = 256; for (let i = 8; i < 16; ++i) { this.addr += this.asint(this.binary(this.getPin('A' + i).getAndReset(), true), multi); multi <<= 1; } } }