
package cz.karry.dop.core;

/**
 *
 * @author karry
 */
public class EightBitLoBus extends Bus implements BusListener{
    private Bus parentBus;
    
    EightBitLoBus(Bus parentBus, String name){
        super(name);
        this.parentBus = parentBus;
        parentBus.addBusListener(this);
    }
    
    @Override
    public void setValue(int value){
        parentBus.setValue(value | (parentBus.getValue() & 0xff00));
    }

    @Override
    public int getValue() {
        return parentBus.getValue() & 0x00ff;
    }

    public void busChangePerformed(Bus bus, int value) {
        changePerformed(value & 0x00ff);
    }

    private void changePerformed(int value){
        for (int i=0; i<listeners.size(); i++){
            listeners.get(i).busChangePerformed(this,value);
        }        
    }
}
