From 17ff02dfe1cdccb59425624693e5aecfa0536804 Mon Sep 17 00:00:00 2001 From: Astoria Date: Wed, 10 Apr 2024 14:28:38 -0500 Subject: [PATCH] send bus to emulator --- .../net/brokenmoon/redcontrol/api/Emulator.java | 3 ++- .../redcontrol/blockentities/CpuEntity.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java b/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java index 327f9e9..5e7d44e 100644 --- a/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java +++ b/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java @@ -41,6 +41,7 @@ public class Emulator { public void setBus(RedBus bus) { this.bus = bus; + this.cpu.getBus().setRedBus(bus); } public boolean isWaitingOnInterrupt(){ @@ -52,7 +53,7 @@ public class Emulator { } public void step() { - if(!isWaitingOnInterrupt() && isRunning) { + if(!isWaitingOnInterrupt()) { this.cpu.step(); this.cpu.getBus().update(cpu.redBusState); } diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java index 0e1230e..902291d 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java @@ -3,6 +3,7 @@ package net.brokenmoon.redcontrol.blockentities; import com.simon816.j65el02.device.RedBus; import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.api.Emulator; +import net.brokenmoon.redcontrol.api.RCWorldBus; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -15,7 +16,7 @@ public class CpuEntity extends Peripheral{ public int i = 0; public boolean notTicked = true; - public Emulator core; + public Emulator core = new Emulator(new RedBus()); private Path bootloader; @@ -31,10 +32,6 @@ public class CpuEntity extends Peripheral{ public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) { if(be.notTicked) { - if (be.core == null){ - RedControl.LOGGER.info("Making CpuEntity"); - be.core = new Emulator(new RedBus()); - } be.reset(); be.notTicked = false; } @@ -86,4 +83,12 @@ public class CpuEntity extends Peripheral{ public void update() { } + + @Override + public void setBus(RCWorldBus bus){ + this.bus = bus.getRedBus(); + this.core.setBus(this.bus); + this.bus.setPeripheral(id, this); + this.worldBus = bus; + } }