diff --git a/J65el02 b/J65el02 index c6de658..e82ee86 160000 --- a/J65el02 +++ b/J65el02 @@ -1 +1 @@ -Subproject commit c6de658396d537fd0c1fc0046d5222c2dc44de3d +Subproject commit e82ee867d35793695a3d5013f654c1732c06b74c diff --git a/src/main/java/net/brokenmoon/redcontrol/api/FakeBus.java b/src/main/java/net/brokenmoon/redcontrol/api/FakeBus.java new file mode 100644 index 0000000..4a89d01 --- /dev/null +++ b/src/main/java/net/brokenmoon/redcontrol/api/FakeBus.java @@ -0,0 +1,9 @@ +package net.brokenmoon.redcontrol.api; + +import com.simon816.j65el02.device.RedBus; + +public class FakeBus extends RCBus{ + public FakeBus(RedBus redBus) { + super(redBus); + } +} diff --git a/src/main/java/net/brokenmoon/redcontrol/api/RCCpu.java b/src/main/java/net/brokenmoon/redcontrol/api/RCCpu.java index 26e67c3..2713a61 100644 --- a/src/main/java/net/brokenmoon/redcontrol/api/RCCpu.java +++ b/src/main/java/net/brokenmoon/redcontrol/api/RCCpu.java @@ -1,18 +1,37 @@ package net.brokenmoon.redcontrol.api; +import com.simon816.j65el02.Bus; import com.simon816.j65el02.Cpu; import com.simon816.j65el02.CpuState; +import net.brokenmoon.redcontrol.blockentities.CpuEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class RCCpu extends Cpu { - private final World world; - private final BlockPos pos; + private CpuEntity cpuEntity; - public RCCpu(World world, BlockPos pos) { - this.world = world; - this.pos = pos; + public RCCpu(CpuEntity cpuEntity) { + this.cpuEntity = cpuEntity; } + public void setInterrupt(boolean val){ + state.intWait = val; + } + + @Override + private int readByte(int address) { + return this.cpuEntity.getBus().read(address, true); + } + + @Override + private void writeMemory(int address, int value, boolean x) { + this.getBus().write(address, value); + boolean flag = x ? this.state.indexWidthFlag : this.state.mWidthFlag; + if (!this.state.emulationFlag && !flag) { + this.cpuEntity.getBus().write(address + 1, value >>> 8); + } + } + + @Override } diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java index fed9b1e..b3db297 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.Bus; import com.simon816.j65el02.device.*; import net.brokenmoon.redcontrol.RedControl; +import net.brokenmoon.redcontrol.api.FakeBus; import net.brokenmoon.redcontrol.api.RCBus; import net.brokenmoon.redcontrol.api.RCCpu; import net.minecraft.block.BlockState; @@ -39,9 +40,9 @@ public class CpuEntity extends Peripheral{ public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) { if(be.notTicked) { - be.cpu = new RCCpu(world, pos); + be.cpu = new RCCpu(be); be.setRCBus(new RCBus(new RedBus())); - be.cpu.setBus(be.getRCBus()); + be.cpu.setBus((FakeBus)be.getRCBus()); be.cpu.setBus(be.getRCBus()); Memory ram = new Memory(0x0000, 0x2000); try {