Comparing version 0.0.68 to 0.0.69
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
['ALU', 'ARegister', 'Add16', 'And', 'And16', 'Bit', 'DFF', 'DMux', 'DMux4Way', 'DMux8Way', 'DRegister', 'FullAdder', 'HalfAdder', 'Inc16', 'MipsAlu', 'Mux', 'Mux16', 'Mux4Way16', 'Mux8Way16', 'Nand', 'Nor', 'Nor16Way', 'Not', 'Not16', 'Or', 'Or16', 'Or8Way', 'PC', 'RAM', 'RAM16K', 'RAM4K', 'RAM512', 'RAM64', 'RAM8', 'Register', 'Xor'].forEach(function (gate) { | ||
['ALU', 'ARegister', 'Add16', 'And', 'And16', 'Bit', 'DFF', 'DMux', 'DMux4Way', 'DMux8Way', 'DRegister', 'FullAdder', 'HalfAdder', 'Inc16', 'MipsAlu', 'Mux', 'Mux16', 'Mux4Way16', 'Mux8Way16', 'Nand', 'Nor', 'Nor16Way', 'Not', 'Not16', 'Or', 'Or16', 'Or8Way', 'PC', 'RAM', 'RAM16K', 'RAM4K', 'RAM512', 'RAM64', 'RAM8', 'Register', 'Screen', 'Xor'].forEach(function (gate) { | ||
return BuiltInGates[gate] = require('./' + gate); | ||
@@ -20,0 +20,0 @@ }); |
@@ -23,102 +23,15 @@ /** | ||
*/ | ||
// prettier-ignore | ||
var TRUTH_TABLE = [ | ||
// Add | ||
{ | ||
a: 1, | ||
b: 1, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 0, | ||
op: 2, | ||
out: 0, | ||
cout: 1, | ||
set: 0 | ||
}, { | ||
a: 1, | ||
b: 1, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 1, | ||
op: 2, | ||
out: 1, | ||
cout: 1, | ||
set: 0 | ||
}, { | ||
a: 0, | ||
b: 0, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 1, | ||
op: 2, | ||
out: 1, | ||
cout: 0, | ||
set: 0 | ||
}, | ||
{ a: 1, b: 1, na: 0, nb: 0, less: 0, cin: 0, op: 2, out: 0, cout: 1, set: 0 }, { a: 1, b: 1, na: 0, nb: 0, less: 0, cin: 1, op: 2, out: 1, cout: 1, set: 0 }, { a: 0, b: 0, na: 0, nb: 0, less: 0, cin: 1, op: 2, out: 1, cout: 0, set: 0 }, | ||
// Sub | ||
{ | ||
a: 1, | ||
b: 1, | ||
na: 0, | ||
nb: 1, | ||
less: 0, | ||
cin: 1, | ||
op: 2, | ||
out: 0, | ||
cout: 1, | ||
set: 0 | ||
}, | ||
{ a: 1, b: 1, na: 0, nb: 1, less: 0, cin: 1, op: 2, out: 0, cout: 1, set: 0 }, | ||
// And | ||
{ | ||
a: 1, | ||
b: 1, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 0, | ||
op: 0, | ||
out: 1, | ||
cout: 0, | ||
set: 0 | ||
}, | ||
{ a: 1, b: 1, na: 0, nb: 0, less: 0, cin: 0, op: 0, out: 1, cout: 0, set: 0 }, | ||
// Or | ||
{ | ||
a: 1, | ||
b: 1, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 0, | ||
op: 1, | ||
out: 1, | ||
cout: 0, | ||
set: 0 | ||
}, { | ||
a: 0, | ||
b: 1, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 0, | ||
op: 1, | ||
out: 1, | ||
cout: 0, | ||
set: 0 | ||
}, { | ||
a: 0, | ||
b: 0, | ||
na: 0, | ||
nb: 0, | ||
less: 0, | ||
cin: 0, | ||
op: 1, | ||
out: 0, | ||
cout: 0, | ||
set: 0 | ||
}]; | ||
{ a: 1, b: 1, na: 0, nb: 0, less: 0, cin: 0, op: 1, out: 1, cout: 0, set: 0 }, { a: 0, b: 1, na: 0, nb: 0, less: 0, cin: 0, op: 1, out: 1, cout: 0, set: 0 }, { a: 0, b: 0, na: 0, nb: 0, less: 0, cin: 0, op: 1, out: 0, cout: 0, set: 0 }]; | ||
@@ -210,3 +123,3 @@ /** | ||
description: '1-bit Mips Alu.\n\nImplements 1-bit MIPS ALU chip.\n\nThe actual ALU operation is controlled by the 2-bit "op" input, which takes the following values:\n\n- 0 - AND\n- 1 - OR\n- 2 - ADD\n- 3 - propagate "less" input\n\nOther operations can be achieved by manipulating different inputs, and the "op" code.\nFor example, to do a subtraction operation "a - b", we need to set cin = 1, and nb = 1.\n\nSetting inputs "na" and "nb" negates the inputs "a" and "b" before performing the operation.\n', | ||
inputPins: ['a', 'b', 'na', 'nb', 'less', 'cin', 'op'], | ||
inputPins: ['a', 'b', 'na', 'nb', 'less', 'cin', { name: 'op', size: 2 }], | ||
outputPins: ['out', 'cout', 'set'], | ||
@@ -213,0 +126,0 @@ truthTable: TRUTH_TABLE |
@@ -102,2 +102,5 @@ /** | ||
_this._storage = new Int16Array(_this.getSize()); | ||
// Addresses which are updated (used in `reset`). | ||
_this._modifiedAddresses = new Set(); | ||
return _this; | ||
@@ -133,2 +136,13 @@ } | ||
/** | ||
* Sets storage. | ||
*/ | ||
}, { | ||
key: 'setStorage', | ||
value: function setStorage(storage) { | ||
this._storage = storage; | ||
return this; | ||
} | ||
/** | ||
* Returns values at address. | ||
@@ -150,6 +164,24 @@ */ | ||
value: function setValueAt(address, value) { | ||
return this._storage[this._checkAddress(address)] = value; | ||
this._storage[this._checkAddress(address)] = value; | ||
this._modifiedAddresses.add(address); | ||
return this; | ||
} | ||
/** | ||
* Resets the memory to all zeros. | ||
*/ | ||
}, { | ||
key: 'reset', | ||
value: function reset() { | ||
var _this2 = this; | ||
this._modifiedAddresses.forEach(function (address) { | ||
_this2._storage[address] = 0; | ||
}); | ||
this._modifiedAddresses.clear(); | ||
return this; | ||
} | ||
/** | ||
* Checks address range. | ||
@@ -162,3 +194,3 @@ */ | ||
if (address < 0 || address > this._size - 1) { | ||
throw new TypeError('Chip "' + this.getClass().name + '": invalid address ' + address + ', ' + ('while the size is ' + this._size + '.')); | ||
throw new TypeError('Chip "' + this.getClass().name + '": invalid address ' + address + ', ' + ('the max address is ' + (this._size - 1) + '.')); | ||
} | ||
@@ -165,0 +197,0 @@ return address; |
@@ -345,3 +345,4 @@ /** | ||
name: Pin.CLOCK, | ||
value: SystemClock.getValue() | ||
value: SystemClock.getValue(), | ||
size: 16 | ||
}); | ||
@@ -348,0 +349,0 @@ } |
@@ -19,3 +19,7 @@ /** | ||
var _require = require('../../util/numbers'), | ||
int16 = _require.int16; | ||
getBitAt = _require.getBitAt, | ||
getBitRange = _require.getBitRange, | ||
int16 = _require.int16, | ||
setBitAt = _require.setBitAt, | ||
setBitRange = _require.setBitRange; | ||
@@ -61,2 +65,3 @@ /** | ||
_this._size = size; | ||
_this._maxAllowed = Math.pow(2, _this._size) - 1; | ||
_this.setValue(value); | ||
@@ -107,2 +112,7 @@ | ||
} | ||
if (value > this._maxAllowed) { | ||
throw new TypeError('Pin "' + this.getName() + '": value ' + value + ' doesn\'t match pin\'s width. ' + ('Max allowed is ' + this._maxAllowed + ' (size ' + this._size + ').')); | ||
} | ||
this._value = int16(value); | ||
@@ -132,12 +142,4 @@ this.emit('change', this._value, oldValue); | ||
// Set 1. | ||
if (value === 1) { | ||
this._value |= 1 << index; | ||
} else { | ||
// Set 0 ("clear"). | ||
this._value &= ~(1 << index); | ||
} | ||
// Always adjust to int16 on individual bits set | ||
this._value = int16(this._value); | ||
this._value = int16(setBitAt(this._value, index, value)); | ||
@@ -155,3 +157,3 @@ this.emit('change', this._value, oldValue, index); | ||
this._checkIndex(index); | ||
return this._value >> index & 1; | ||
return getBitAt(this._value, index); | ||
} | ||
@@ -168,3 +170,3 @@ | ||
this._checkIndex(to); | ||
return this._value >> from & (1 << to + 1 - from) - 1; | ||
return getBitRange(this._value, from, to); | ||
} | ||
@@ -190,4 +192,3 @@ | ||
var oldValue = this._value; | ||
var mask = (1 << to + 1 - from) - 1 << from; | ||
this._value = oldValue & ~mask | range << from & mask; | ||
this._value = setBitRange(this._value, from, to, range); | ||
@@ -194,0 +195,0 @@ this.emit('change', this._value, oldValue, from, to); |
@@ -82,8 +82,48 @@ /** | ||
/** | ||
* Returns the value of particular bit in a 16-bit number. | ||
*/ | ||
function getBitAt(number, index) { | ||
return number >> index & 1; | ||
} | ||
/** | ||
* Sets a particular bit to the value. | ||
*/ | ||
function setBitAt(number, index, value) { | ||
// Set 1. | ||
if (value === 1) { | ||
number |= 1 << index; | ||
} else { | ||
// Set 0 ("clear"). | ||
number &= ~(1 << index); | ||
} | ||
return number; | ||
} | ||
/** | ||
* Returns a bit range. | ||
*/ | ||
function getBitRange(number, from, to) { | ||
return number >> from & (1 << to + 1 - from) - 1; | ||
} | ||
/** | ||
* Sets a bits range. | ||
*/ | ||
function setBitRange(number, from, to, range) { | ||
var mask = (1 << to + 1 - from) - 1 << from; | ||
return number & ~mask | range << from & mask; | ||
} | ||
module.exports = { | ||
getBitAt: getBitAt, | ||
getBitRange: getBitRange, | ||
int16: int16, | ||
int16Table: int16Table, | ||
uint16: uint16, | ||
isNegativeZero: isNegativeZero, | ||
toSignedString: toSignedString | ||
setBitAt: setBitAt, | ||
setBitRange: setBitRange, | ||
toSignedString: toSignedString, | ||
uint16: uint16 | ||
}; |
{ | ||
"name": "hdl-js", | ||
"version": "0.0.68", | ||
"version": "0.0.69", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Hardware definition language (HDL) and Hardware simulator", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
385824
81
8389