|
|
|
@ -20,29 +20,20 @@ public class RCBus extends Bus {
|
|
|
|
|
private World backupWorld;
|
|
|
|
|
private BlockPos backupPos;
|
|
|
|
|
|
|
|
|
|
public RCBus(RedBus redBus, World world, BlockPos pos) {
|
|
|
|
|
super(redBus);
|
|
|
|
|
this.redBus = redBus;
|
|
|
|
|
backupWorld = world;
|
|
|
|
|
backupPos = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void write(int address, int data, World world, BlockPos pos) {
|
|
|
|
|
if(isValid) {
|
|
|
|
|
getRedBus().write(address, data);
|
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
device.write(address - device.startAddress(), data);
|
|
|
|
|
} else {
|
|
|
|
|
generateBusWithWrite(address, data, world, pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void write(int address, int data) {
|
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
device.write(address - device.startAddress(), data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int read(int address, boolean cpuAccess) {
|
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
return device.read(address - device.startAddress(), cpuAccess) & 0xff;
|
|
|
|
|
write(address, data, backupWorld, backupPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) {
|
|
|
|
@ -51,8 +42,8 @@ public class RCBus extends Bus {
|
|
|
|
|
|
|
|
|
|
public int read(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
|
|
|
if(isValid) {
|
|
|
|
|
RedControl.LOGGER.info("Reading! " + address + " " + cpuAccess);
|
|
|
|
|
return getRedBus().read(address, cpuAccess) & 0xff;
|
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
return device.read(address - device.startAddress(), cpuAccess) & 0xff;
|
|
|
|
|
} else {
|
|
|
|
|
return generateBusWithRead(address, cpuAccess, world, pos);
|
|
|
|
|
}
|
|
|
|
@ -61,29 +52,20 @@ public class RCBus extends Bus {
|
|
|
|
|
private int generateBusWithRead(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
|
|
|
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected Device findDevice(int address) {
|
|
|
|
|
// RedBus takes priority
|
|
|
|
|
if (this.redBus.inRange(address)) {
|
|
|
|
|
return this.redBus;
|
|
|
|
|
}
|
|
|
|
|
int idx = Arrays.binarySearch(this.boundaries, address);
|
|
|
|
|
if (idx < 0) {
|
|
|
|
|
idx = -idx - 2;
|
|
|
|
|
}
|
|
|
|
|
return this.devices.get(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void write(int address, int data) {
|
|
|
|
|
write(address, data, backupWorld, backupPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int read(int address, boolean cpuAccess) {
|
|
|
|
|
return read(address, cpuAccess, backupWorld, backupPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RCBus(RedBus redBus, World world, BlockPos pos) {
|
|
|
|
|
super(redBus);
|
|
|
|
|
this.redBus = redBus;
|
|
|
|
|
backupWorld = world;
|
|
|
|
|
backupPos = pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void generateBus(World world, BlockPos pos){
|
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
|
|
|
|
|
}
|
|
|
|
@ -101,11 +83,7 @@ public class RCBus extends Bus {
|
|
|
|
|
this.getRedBus().updatePeripheral();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getValid(){
|
|
|
|
|
return this.isValid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setValid(boolean validity){
|
|
|
|
|
this.isValid = validity;
|
|
|
|
|
public void setValid(boolean val){
|
|
|
|
|
this.isValid = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|