|
|
@ -1,6 +1,7 @@
|
|
|
|
package net.brokenmoon.redcontrol.api;
|
|
|
|
package net.brokenmoon.redcontrol.api;
|
|
|
|
|
|
|
|
|
|
|
|
import com.simon816.j65el02.Bus;
|
|
|
|
import com.simon816.j65el02.Bus;
|
|
|
|
|
|
|
|
import com.simon816.j65el02.device.Device;
|
|
|
|
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.blockentities.Peripheral;
|
|
|
@ -8,26 +9,42 @@ 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
|
|
public class RCBus extends Bus {
|
|
|
|
public class RCBus extends Bus {
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isValid = false;
|
|
|
|
private boolean isValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
private RedBus redBus;
|
|
|
|
private RedBus redBus;
|
|
|
|
|
|
|
|
|
|
|
|
public RCBus(RedBus redBus) {
|
|
|
|
private World backupWorld;
|
|
|
|
|
|
|
|
private BlockPos backupPos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RCBus(RedBus redBus, World world, BlockPos pos) {
|
|
|
|
super(redBus);
|
|
|
|
super(redBus);
|
|
|
|
this.redBus = 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) {
|
|
|
|
RedControl.LOGGER.info("Writing! " + address + " " + data);
|
|
|
|
|
|
|
|
getRedBus().write(address, data);
|
|
|
|
getRedBus().write(address, data);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
generateBusWithWrite(address, data, world, pos);
|
|
|
|
generateBusWithWrite(address, data, world, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) {
|
|
|
|
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) {
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data);
|
|
|
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -44,6 +61,28 @@ 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
|
|
|
|
|
|
|
|
public int read(int address, boolean cpuAccess) {
|
|
|
|
|
|
|
|
return read(address, cpuAccess, backupWorld, backupPos);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
@ -57,8 +96,9 @@ public class RCBus extends Bus {
|
|
|
|
this.redBus = redBus;
|
|
|
|
this.redBus = redBus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
public void update() {
|
|
|
|
this.redBus.updatePeripheral();
|
|
|
|
this.getRedBus().updatePeripheral();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean getValid(){
|
|
|
|
public boolean getValid(){
|
|
|
|