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.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;

@ -14,9 +14,9 @@ public class RCCpu extends Cpu {
private CpuEntity cpuEntity;
private Memory ram = new Memory(0x0000, 0x2000);;
public RCCpu(CpuEntity cpuEntity) {
public RCCpu(CpuEntity cpuEntity, RCBus bus) {
this.cpuEntity = cpuEntity;
this.setBus(this.cpuEntity.getBus());
this.setBus(bus);
}
public void setInterrupt(boolean val){
@ -40,8 +40,7 @@ public class RCCpu extends Cpu {
@Override
public void setBus(Bus bus) {
super.setBus(bus);
if(!cpuEntity.notTicked)
getBus().addDevice(this.ram);
this.getBus().addDevice(this.ram);
}
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;
import com.simon816.j65el02.Bus;
import com.simon816.j65el02.device.*;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.RCBus;
import net.brokenmoon.redcontrol.api.RCCpu;
import net.brokenmoon.redcontrol.api.RCRedbus;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -29,16 +31,22 @@ public class CpuEntity extends Peripheral{
private int defaultDriveId = 2;
public CpuEntity(BlockPos pos, BlockState state) {
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) {
if(be.notTicked) {
be.cpu = new RCCpu(be);
be.setBus(new RCBus(new RedBus(), world, pos));
be.cpu.setBus(be.getBus());
be.cpu.getBus().addDevice(be.cpu.getRam());
RCBus bus;
if(be.getBus() == null) {
bus = new RCBus(new RCRedbus(), world, pos);
be.bus = bus;
} else {
bus = be.getBus();
}
if (be.cpu == null){
RedControl.LOGGER.info("Making CpuEntity");
be.cpu = new RCCpu(be, bus);
}
try {
be.cpu.getRam().loadFromFile(be.bootloader, 0x400, 0x100);
} catch (IOException e) {
@ -54,9 +62,14 @@ public class CpuEntity extends Peripheral{
}
}
public void setPeripheral(int id, RedBus.Peripheral peripheral) {
this.getBus().getRedBus().setPeripheral(id, peripheral);
@Override
public void setBus(RCBus bus){
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() {

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

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

Loading…
Cancel
Save