
package cz.karry.dop.core;

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

    @Override
    public int getValue() {
        return (parentBus.getValue() & 0xff00) >> 8;
    }

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

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