|
|
|
@ -5,7 +5,6 @@ import com.simon816.j65el02.device.Device;
|
|
|
|
|
import com.simon816.j65el02.device.Memory;
|
|
|
|
|
import com.simon816.j65el02.device.RedBus;
|
|
|
|
|
import net.brokenmoon.redcontrol.RedControl;
|
|
|
|
|
import net.brokenmoon.redcontrol.blockentities.Peripheral;
|
|
|
|
|
import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
|
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
@ -23,40 +22,44 @@ public class RCBus extends Bus {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void write(int address, int data, World world, BlockPos pos) {
|
|
|
|
|
public void write(int address, int data, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
|
|
|
|
if(isValid) {
|
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
device.write(address - device.startAddress(), data);
|
|
|
|
|
Device device = findDevice(address, redbusStartAddress);
|
|
|
|
|
if(!(device instanceof Memory))
|
|
|
|
|
RedControl.LOGGER.info(device.toString());
|
|
|
|
|
device.write(address, data, redbusTarget, redbusStartAddress);
|
|
|
|
|
} else {
|
|
|
|
|
generateBusWithWrite(address, data, world, pos);
|
|
|
|
|
generateBusWithWrite(address, data, redbusTarget, redbusStartAddress, world, pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void write(int address, int data) {
|
|
|
|
|
write(address, data, backupWorld, backupPos);
|
|
|
|
|
public void write(int address, int data, int redbusTarget, int redbusStartAddress) {
|
|
|
|
|
write(address, data, redbusTarget, redbusStartAddress, backupWorld, backupPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) {
|
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data);
|
|
|
|
|
private void generateBusWithWrite(int address, int data, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data, redbusTarget, redbusStartAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int read(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
|
|
|
public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
|
|
|
|
if(isValid) {
|
|
|
|
|
Device device = findDevice(address);
|
|
|
|
|
return device.read(address - device.startAddress(), cpuAccess) & 0xff;
|
|
|
|
|
Device device = findDevice(address, redbusStartAddress);
|
|
|
|
|
if(!(device instanceof Memory))
|
|
|
|
|
RedControl.LOGGER.info(device.toString());
|
|
|
|
|
return device.read(address, cpuAccess, redbusTarget, redbusStartAddress) & 0xff;
|
|
|
|
|
} else {
|
|
|
|
|
return generateBusWithRead(address, cpuAccess, world, pos);
|
|
|
|
|
return generateBusWithRead(address, cpuAccess, redbusTarget, redbusStartAddress, world, pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int generateBusWithRead(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
|
|
|
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess);
|
|
|
|
|
private int generateBusWithRead(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
|
|
|
|
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess, redbusTarget, redbusStartAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int read(int address, boolean cpuAccess) {
|
|
|
|
|
return read(address, cpuAccess, backupWorld, backupPos);
|
|
|
|
|
public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress) {
|
|
|
|
|
return read(address, cpuAccess, redbusTarget, redbusStartAddress, backupWorld, backupPos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RCBus(RedBus redBus, World world, BlockPos pos) {
|
|
|
|
@ -79,12 +82,20 @@ public class RCBus extends Bus {
|
|
|
|
|
this.redBus = redBus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update() {
|
|
|
|
|
this.getRedBus().updatePeripheral();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setValid(boolean val){
|
|
|
|
|
this.isValid = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Device findDevice(int address, int redbusStartAddress) {
|
|
|
|
|
// RedBus takes priority
|
|
|
|
|
if (address >= redbusStartAddress && address <= (redbusStartAddress + 0xFF)) {
|
|
|
|
|
return this.redBus;
|
|
|
|
|
}
|
|
|
|
|
int idx = Arrays.binarySearch(this.boundaries, address);
|
|
|
|
|
if (idx < 0) {
|
|
|
|
|
idx = -idx - 2;
|
|
|
|
|
}
|
|
|
|
|
return this.devices.get(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|