

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 UpRegister extends IORegister implements SignalListener{
    protected Signal enableCount;

    public UpRegister(String name,Bus input, Bus output, Signal reset, Signal clock, Signal enableLoad, Signal outputEnable, Signal enableCount){
        super(name, input, output, reset, clock, enableLoad, outputEnable);
        this.enableCount = enableCount;
        enableCount.addSignalListener(this);
    }
    
    @Override
    public void signalChangePerformed(Signal signal, boolean active) {
        super.signalChangePerformed(signal, active);
        
        if (signal == clock){
            if (active){
                if ((enableCount.isActive()) && (!enableLoad.isActive())){
                    if (getValue() < 0xffff)
                        dValue = getValue()+1;
                    else{
                        dValue = 0;
                    }
                }
            }
        }
        
    }

}
