UNPKG

hdl-js

Version:

Hardware definition language (HDL) and Hardware simulator

49 lines (32 loc) 2.09 kB
/** * The MIT License (MIT) * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com> */ 'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var colors = require('colors'); var Register = require('./Register'); /** * 16-bit D (Data) register. */ var DRegister = function (_Register) { _inherits(DRegister, _Register); function DRegister() { _classCallCheck(this, DRegister); return _possibleConstructorReturn(this, (DRegister.__proto__ || Object.getPrototypeOf(DRegister)).apply(this, arguments)); } return DRegister; }(Register); /** * Specification of the `DRegister` gate. */ DRegister.Spec = { name: 'DRegister', description: '16-bit D (Data) register.\n\nIf load[t]=1 then out[t+1] = in[t] else out does not change.\n\nClock rising edge updates the value from the input,\nif the `load` is set; otherwise, preserves the state.\n\n ' + colors.bold('↗') + ' : value = load ? in : value\n\nClock falling edge propagates the value to the output:\n\n ' + colors.bold('↘') + ' : out = value\n', inputPins: [{ name: 'in', size: 16 }, { name: 'load', size: 1 }], outputPins: [{ name: 'out', size: 16 }], truthTable: Register.Spec.truthTable }; module.exports = DRegister;