/*
 * 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.Bus;
import cz.karry.dop.core.Signal;
import cz.karry.dop.core.SignalListener;

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

    private Signal outputIntVector;
    protected Bus output;

    public IrRegister(String name,Bus input, Bus output, Signal reset, Signal clock, Signal enableLoad, Signal outputIntVector){
        super(name, input, reset, clock, enableLoad);
        this.outputIntVector = outputIntVector;
        outputIntVector.addSignalListener(this);
        this.output = output;
    }
    
    @Override
    public void signalChangePerformed(Signal signal, boolean active) {
        super.signalChangePerformed(signal, active);
    
        if ((signal == outputIntVector) && (outputIntVector.isActive())){
            output.setValue(getInteruptVetor());
        }
        if ((signal == clock) && (!active) && outputIntVector.isActive()){
            output.setValue(getInteruptVetor());
        }
    }
    
    private int getInteruptVetor(){
        return (getValue() & 0x1f) << 2;
    }
    

}
