Bus: still broken!

main
Astoria 7 months ago
parent 61042af398
commit fecf68e816

@ -2,6 +2,7 @@ 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.Device;
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.blockentities.Peripheral;

@ -14,9 +14,9 @@ public class RCCpu extends Cpu {
private CpuEntity cpuEntity; private CpuEntity cpuEntity;
private Memory ram = new Memory(0x0000, 0x2000);; private Memory ram = new Memory(0x0000, 0x2000);;
public RCCpu(CpuEntity cpuEntity) { public RCCpu(CpuEntity cpuEntity, RCBus bus) {
this.cpuEntity = cpuEntity; this.cpuEntity = cpuEntity;
this.setBus(this.cpuEntity.getBus()); this.setBus(bus);
} }
public void setInterrupt(boolean val){ public void setInterrupt(boolean val){
@ -40,8 +40,7 @@ public class RCCpu extends Cpu {
@Override @Override
public void setBus(Bus bus) { public void setBus(Bus bus) {
super.setBus(bus); super.setBus(bus);
if(!cpuEntity.notTicked) this.getBus().addDevice(this.ram);
getBus().addDevice(this.ram);
} }
public Memory getRam() { public Memory getRam() {

@ -0,0 +1,29 @@
package net.brokenmoon.redcontrol.api;
import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.RedControl;
public class RCRedbus extends RedBus {
@Override
public void write(int address, int data) {
if (!this.enabled) {
return;
}
Peripheral peripheral = this.peripherals[this.activeDeviceId];
if (peripheral != null) {
peripheral.write(address, data & 0xff);
}
}
@Override
public void setActiveDevice(int id) {
RedControl.LOGGER.info("Active device is now " + id);
this.activeDeviceId = id;
}
@Override
public int getActiveDevice() {
RedControl.LOGGER.info("Active device is being read, and it is " + activeDeviceId);
return this.activeDeviceId;
}
}

@ -1,9 +1,11 @@
package net.brokenmoon.redcontrol.blockentities; package net.brokenmoon.redcontrol.blockentities;
import com.simon816.j65el02.Bus;
import com.simon816.j65el02.device.*; import com.simon816.j65el02.device.*;
import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.RCBus; import net.brokenmoon.redcontrol.api.RCBus;
import net.brokenmoon.redcontrol.api.RCCpu; import net.brokenmoon.redcontrol.api.RCCpu;
import net.brokenmoon.redcontrol.api.RCRedbus;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -29,16 +31,22 @@ public class CpuEntity extends Peripheral{
private int defaultDriveId = 2; private int defaultDriveId = 2;
public CpuEntity(BlockPos pos, BlockState state) { public CpuEntity(BlockPos pos, BlockState state) {
super(RedControl.CPU_BLOCK_ENTITY, pos, state, 0); super(RedControl.CPU_BLOCK_ENTITY, pos, state, 0);
RedControl.LOGGER.info("Making CpuEntity");
} }
public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) { public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) {
if(be.notTicked) { if(be.notTicked) {
be.cpu = new RCCpu(be); RCBus bus;
be.setBus(new RCBus(new RedBus(), world, pos)); if(be.getBus() == null) {
be.cpu.setBus(be.getBus()); bus = new RCBus(new RCRedbus(), world, pos);
be.cpu.getBus().addDevice(be.cpu.getRam()); be.bus = bus;
} else {
bus = be.getBus();
}
if (be.cpu == null){
RedControl.LOGGER.info("Making CpuEntity");
be.cpu = new RCCpu(be, bus);
}
try { try {
be.cpu.getRam().loadFromFile(be.bootloader, 0x400, 0x100); be.cpu.getRam().loadFromFile(be.bootloader, 0x400, 0x100);
} catch (IOException e) { } catch (IOException e) {
@ -54,9 +62,14 @@ public class CpuEntity extends Peripheral{
} }
} }
@Override
public void setPeripheral(int id, RedBus.Peripheral peripheral) { public void setBus(RCBus bus){
this.getBus().getRedBus().setPeripheral(id, peripheral); this.bus = bus;
if(cpu == null) {
RedControl.LOGGER.info("Making CpuEntity setbus edition");
this.cpu = new RCCpu(this, bus);
}
this.cpu.setBus(bus);
} }
public int getDefaultDriveId() { public int getDefaultDriveId() {

@ -33,6 +33,7 @@ public abstract class Peripheral extends BlockEntity implements RedBus.Periphera
public void setBus(RCBus bus){ public void setBus(RCBus bus){
this.bus = bus; this.bus = bus;
this.bus.getRedBus().setPeripheral(id, this);
} }
public int getId() { public int getId() {

@ -2,6 +2,7 @@ package net.brokenmoon.redcontrol.blocks;
import com.simon816.j65el02.device.RedBus; import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.api.RCBus; import net.brokenmoon.redcontrol.api.RCBus;
import net.brokenmoon.redcontrol.api.RCRedbus;
import net.brokenmoon.redcontrol.blockentities.Peripheral; import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
@ -54,9 +55,8 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
Block worldBlock = world.getBlockState(pos).getBlock(); Block worldBlock = world.getBlockState(pos).getBlock();
if(world.getBlockEntity(pos) instanceof Peripheral){ if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos); Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
if(entityBlock.getBus() == null) RCBus bus = new RCBus(new RCRedbus(), world, pos);
entityBlock.setBus(new RCBus(new RedBus(), world, pos)); entityBlock.setBus(bus);
entityBlock.getBus().getRedBus().setPeripheral(entityBlock.getId(), entityBlock);
entityBlock.getBus().setValid(true); entityBlock.getBus().setValid(true);
floodBus(entityBlock.getBus(), world, pos); floodBus(entityBlock.getBus(), world, pos);
} }

Loading…
Cancel
Save