
package cz.karry.dop.core.registers;

import cz.karry.dop.core.Bus;
import cz.karry.dop.core.Signal;
import cz.karry.dop.core.SignalListener;

/**
 *
 * @author karry
 */
public class IORegister extends LoadRegister implements SignalListener{

    private Signal outputEnable;
    protected Bus output;
    
    public IORegister(String name,Bus input, Bus output, Signal reset, Signal clock, Signal enableLoad, Signal outputEnable){
        super(name, input, reset, clock, enableLoad);
        this.outputEnable = outputEnable;
        this.output = output;
        outputEnable.addSignalListener(this);
    }
    
    @Override
    public void signalChangePerformed(Signal signal, boolean active) {
        super.signalChangePerformed(signal, active);
    
        if ((signal == outputEnable) && (outputEnable.isActive())){
            output.setValue(getValue());
        }
        if ((signal == clock) && (!signal.isActive()) && outputEnable.isActive()){
            output.setValue(getValue());
        }
    }
}
