How to use the 3vl.Vector3vl.fromBin function in 3vl

To help you get started, we’ve selected a few 3vl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tilk / digitaljs / src / cells / io.js View on Github external
constructor: function(args) {
        args.constantCache = Vector3vl.fromBin(args.constant, args.constant.length);
        args.bits = args.constant.length;
        args.outputSignals = { out: args.constantCache };
        this.markup = [
            this.addWire(args, 'right', 0.5, { id: 'out', dir: 'out', bits: args.constant.length }),
            '
github tilk / digitaljs / src / cells / fsm.js View on Github external
'<a class="zoom">🔍</a>',
            ''].join(''));
        this.markup = markup.join('');
        this.fsmgraph = new joint.dia.Graph;
        const statenodes = [];
        for (let n = 0; n &lt; args.states; n++) {
            const node = new joint.shapes.standard.Circle({stateNo: n, id: 'state' + n, isInit: n == args.init_state});
            node.attr('label/text', String(n));
            node.resize(100,50);
            node.addTo(this.fsmgraph);
            statenodes.push(node);
        }
        for (const tr of args.trans_table) {
            const trans = new joint.shapes.standard.Link({
                ctrlIn: Vector3vl.fromBin(tr.ctrl_in, args.bits.in),
                ctrlOut: Vector3vl.fromBin(tr.ctrl_out, args.bits.out)
            });
            trans.appendLabel({
                attrs: {
                    text: {
                        text: trans.get('ctrlIn').toBin() + '/' + trans.get('ctrlOut').toBin()
                    }
                }
            });
            trans.source({ id: 'state' + tr.state_in });
            trans.target({ id: 'state' + tr.state_out });
            trans.addTo(this.fsmgraph);
        }
        Box.prototype.constructor.apply(this, arguments);
        this.last_clk = 0;
    },
    operation: function(data) {
github tilk / digitaljs / src / help.js View on Github external
export function base2sig(str, bits, base) {
    switch(base) {
        case 'bin': return Vector3vl.fromBin(str, bits);
        case 'oct': return Vector3vl.fromOct(str, bits);
        case 'hex': return Vector3vl.fromHex(str, bits);
        case 'dec': 
            if (str == 'x') return Vector3vl.xes(bits);
            return bigint2sig(bigInt(str), bits);
    }
}
github tilk / digitaljs / src / cells / dff.js View on Github external
operation: function(data) {
        const polarity = this.get('polarity');
        const pol = what => polarity[what] ? 1 : -1
        if ('enable' in polarity && data.en.get(0) != pol('enable'))
            return this.get('outputSignals');
        if ('arst' in polarity && data.arst.get(0) == pol('arst'))
            return { out: Vector3vl.fromBin(this.get('arst_value'), this.get('bits')) };
        if ('clock' in polarity) {
            const last_clk = this.last_clk;
            this.last_clk = data.clk.get(0);
            if (data.clk.get(0) == pol('clock') && last_clk == -pol('clock'))
                return { out: data.in };
            else
                return this.get('outputSignals');
        } else return { out: data.in };
    },
    gateParams: Box.prototype.gateParams.concat(['polarity', 'bits'])
github tilk / digitaljs / src / cells / fsm.js View on Github external
'',
            '<a class="zoom">🔍</a>',
            ''].join(''));
        this.markup = markup.join('');
        this.fsmgraph = new joint.dia.Graph;
        const statenodes = [];
        for (let n = 0; n &lt; args.states; n++) {
            const node = new joint.shapes.standard.Circle({stateNo: n, id: 'state' + n, isInit: n == args.init_state});
            node.attr('label/text', String(n));
            node.resize(100,50);
            node.addTo(this.fsmgraph);
            statenodes.push(node);
        }
        for (const tr of args.trans_table) {
            const trans = new joint.shapes.standard.Link({
                ctrlIn: Vector3vl.fromBin(tr.ctrl_in, args.bits.in),
                ctrlOut: Vector3vl.fromBin(tr.ctrl_out, args.bits.out)
            });
            trans.appendLabel({
                attrs: {
                    text: {
                        text: trans.get('ctrlIn').toBin() + '/' + trans.get('ctrlOut').toBin()
                    }
                }
            });
            trans.source({ id: 'state' + tr.state_in });
            trans.target({ id: 'state' + tr.state_out });
            trans.addTo(this.fsmgraph);
        }
        Box.prototype.constructor.apply(this, arguments);
        this.last_clk = 0;
    },
github tilk / digitaljs / src / cells / dff.js View on Github external
constructor: function(args) {
        _.defaults(args, { bits: 1, polarity: {}, initial: 'x' });
        if (!args.outputSignals)
            args.outputSignals = { 
                out: Vector3vl.fromBin(args.initial, args.bits)
            };
        if ('arst' in args.polarity &amp;&amp; !args.arst_value)
            args.arst_value = Array(args.bits).fill('0').join('');
        const markup = [];
        const lblmarkup = [];
        markup.push(this.addLabelledWire(args, lblmarkup, 'right', 0.5, { id: 'out', dir: 'out', bits: args.bits, label: 'Q' }));
        let num = 0;
        markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'in', dir: 'in', bits: args.bits, label: 'D' }));
        if ('clock' in args.polarity)
            markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'clk', dir: 'in', bits: 1, polarity: args.polarity.clock, clock: true }));
        if ('arst' in args.polarity)
            markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'arst', dir: 'in', bits: 1, polarity: args.polarity.arst }));
        if ('enable' in args.polarity)
            markup.push(this.addLabelledWire(args, lblmarkup, 'left', (num++*16)+12, { id: 'en', dir: 'in', bits: 1, polarity: args.polarity.enable }));
        markup.push('