|
|
@ -20,29 +20,20 @@ public class RCBus extends Bus {
|
|
|
|
private World backupWorld;
|
|
|
|
private World backupWorld;
|
|
|
|
private BlockPos backupPos;
|
|
|
|
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) {
|
|
|
|
public void write(int address, int data, World world, BlockPos pos) {
|
|
|
|
if(isValid) {
|
|
|
|
if(isValid) {
|
|
|
|
getRedBus().write(address, data);
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
|
|
|
device.write(address - device.startAddress(), data);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
generateBusWithWrite(address, data, world, pos);
|
|
|
|
generateBusWithWrite(address, data, world, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(int address, int data) {
|
|
|
|
public void write(int address, int data) {
|
|
|
|
Device device = findDevice(address);
|
|
|
|
write(address, data, backupWorld, backupPos);
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) {
|
|
|
|
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) {
|
|
|
|
public int read(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
|
|
if(isValid) {
|
|
|
|
if(isValid) {
|
|
|
|
RedControl.LOGGER.info("Reading! " + address + " " + cpuAccess);
|
|
|
|
Device device = findDevice(address);
|
|
|
|
return getRedBus().read(address, cpuAccess) & 0xff;
|
|
|
|
return device.read(address - device.startAddress(), cpuAccess) & 0xff;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return generateBusWithRead(address, cpuAccess, world, pos);
|
|
|
|
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) {
|
|
|
|
private int generateBusWithRead(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
|
|
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess);
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
public int read(int address, boolean cpuAccess) {
|
|
|
|
public int read(int address, boolean cpuAccess) {
|
|
|
|
return read(address, cpuAccess, backupWorld, backupPos);
|
|
|
|
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){
|
|
|
|
public void generateBus(World world, BlockPos pos){
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,11 +83,7 @@ public class RCBus extends Bus {
|
|
|
|
this.getRedBus().updatePeripheral();
|
|
|
|
this.getRedBus().updatePeripheral();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean getValid(){
|
|
|
|
public void setValid(boolean val){
|
|
|
|
return this.isValid;
|
|
|
|
this.isValid = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setValid(boolean validity){
|
|
|
|
|
|
|
|
this.isValid = validity;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|