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