/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.karry.dop.core.registers;

import cz.karry.dop.core.*;

/**
 *
 * @author karry
 */
public class LoadRegister extends Register implements SignalListener{
    protected Signal clock;
    protected int dValue = 0;
    protected Bus input;
    protected Signal enableLoad;
    
    public LoadRegister(String name, Bus input, Signal reset, Signal clock, Signal enableLoad){
        super(name,reset);
        this.clock = clock;
        this.enableLoad = enableLoad;
        this.input = input;
        
        clock.addSignalListener(this);
    }

    @Override
    public void signalChangePerformed(Signal signal, boolean active) {
        super.signalChangePerformed(signal, active);
        
        if (signal == clock){
            if (active){
                if (enableLoad.isActive()){
                    dValue = input.getValue();
                }else{
                    dValue = getValue();
                }
            }
            
            if (!active){
                setValue(dValue);
            }
        }
    }
    

}
