diff --git a/J65el02 b/J65el02 index 3690b00..419245b 160000 --- a/J65el02 +++ b/J65el02 @@ -1 +1 @@ -Subproject commit 3690b0031fd685abecc2f7d21678c61dca69f40f +Subproject commit 419245bf18a266be19f8b02a565fb5e7150a39a3 diff --git a/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java b/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java index 5e7d44e..ac2521c 100644 --- a/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java +++ b/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java @@ -5,6 +5,7 @@ import com.simon816.j65el02.Cpu; import com.simon816.j65el02.device.Memory; import com.simon816.j65el02.device.RedBus; import com.simon816.j65el02.device.RedBusState; +import net.brokenmoon.redcontrol.RedControl; import java.io.IOException; import java.net.URISyntaxException; @@ -15,13 +16,12 @@ public class Emulator { private RedBus bus; public Cpu cpu; private Memory ram; - public boolean isRunning = false; public Emulator(RedBus bus){ this.bus = bus; cpu = new Cpu(); - cpu.setBus(new Bus(bus)); - ram = new Memory(0x0000, 0x2000, new RedBusState()); + cpu.setBus(new TempBus(bus)); + ram = new Memory(0x0000, 0x2000 - 1, cpu.redBusState); try { ram.loadFromFile(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/redforth.img"), 0x400, 0x100); @@ -40,6 +40,7 @@ public class Emulator { } public void setBus(RedBus bus) { + RedControl.LOGGER.info("Setting Emulator bus"); this.bus = bus; this.cpu.getBus().setRedBus(bus); } @@ -60,7 +61,6 @@ public class Emulator { } public void reset(){ - isRunning = false; cpu.reset(); ram.write(0, 2, cpu.redBusState); ram.write(1, 1, cpu.redBusState); diff --git a/src/main/java/net/brokenmoon/redcontrol/api/TempBus.java b/src/main/java/net/brokenmoon/redcontrol/api/TempBus.java new file mode 100644 index 0000000..93b861c --- /dev/null +++ b/src/main/java/net/brokenmoon/redcontrol/api/TempBus.java @@ -0,0 +1,27 @@ +package net.brokenmoon.redcontrol.api; + +import com.simon816.j65el02.Bus; +import com.simon816.j65el02.device.Device; +import com.simon816.j65el02.device.RedBus; +import com.simon816.j65el02.device.RedBusState; +import net.brokenmoon.redcontrol.RedControl; + +public class TempBus extends Bus { + public TempBus(RedBus redBus) { + super(redBus); + } + + @Override + public void write(int address, int data, RedBusState state) { + Device device = findDevice(address,state); + RedControl.LOGGER.info("Writing to bus with device " + device + "at address " + (address - device.startAddress(state)) + " with data " + data + " with target " + state.activeDeviceId + " and redbus offset of " + state.offset); + device.write(address - device.startAddress(state) % 0x2000, data, state); + } + + @Override + public int read(int address, boolean cpuAccess, RedBusState state) { + Device device = findDevice(address,state); + RedControl.LOGGER.info("Reading from bus with device " + device + "at address " + (address - device.startAddress(state)) + " with target " + state.activeDeviceId + " and redbus offset of " + state.offset); + return device.read(address - device.startAddress(state) % 0x2000, cpuAccess, state) & 0xff; + } +} diff --git a/src/main/java/net/brokenmoon/redcontrol/api/TempRedBus.java b/src/main/java/net/brokenmoon/redcontrol/api/TempRedBus.java new file mode 100644 index 0000000..5cad760 --- /dev/null +++ b/src/main/java/net/brokenmoon/redcontrol/api/TempRedBus.java @@ -0,0 +1,33 @@ +package net.brokenmoon.redcontrol.api; + +import com.simon816.j65el02.device.RedBus; +import com.simon816.j65el02.device.RedBusState; +import net.brokenmoon.redcontrol.RedControl; + +public class TempRedBus extends RedBus { + + @Override + public void write(int address, int data, RedBusState state) { + RedControl.LOGGER.info("Writing at " + address); + if (!state.enabled) { + return; + } + Peripheral peripheral = this.peripherals[state.activeDeviceId]; + if (peripheral != null) { + peripheral.write(address, data & 0xff); + } + } + + @Override + public int read(int address, boolean cpuAccess, RedBusState state) { + RedControl.LOGGER.info("Reading at " + address); + if (!state.enabled) { + return 0; + } + Peripheral peripheral = this.peripherals[state.activeDeviceId]; + if (peripheral != null) { + return peripheral.read(address); + } + return 0; + } +} diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java index 902291d..4efb519 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java @@ -4,6 +4,7 @@ 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.brokenmoon.redcontrol.api.TempRedBus; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -16,7 +17,7 @@ public class CpuEntity extends Peripheral{ public int i = 0; public boolean notTicked = true; - public Emulator core = new Emulator(new RedBus()); + public Emulator core = new Emulator(new TempRedBus()); private Path bootloader; diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java index 0c6d554..0c92e1f 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java @@ -146,6 +146,7 @@ public class MonitorEntity extends Peripheral { @Override public void update() { + RedControl.LOGGER.info("MONITOR UPDATED"); int maxWidth = Math.min(WIDTH, this.blitWidth + this.blitXOffset); int maxHeight = Math.min(HEIGHT, this.blitHeight + this.blitYOffset); diff --git a/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java b/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java index e44c90b..0c3b2b0 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java +++ b/src/main/java/net/brokenmoon/redcontrol/blocks/CpuBlock.java @@ -45,7 +45,7 @@ public class CpuBlock extends NetworkCarrier { if (!world.isClient) { CpuEntity peripheral = (CpuEntity) world.getBlockEntity(pos); player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().hashCode())), false); - player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().getRedBus().hashCode())), false); + player.sendMessage(Text.literal(String.valueOf(peripheral.core.cpu.getBus().getRedBus().hashCode())), false); player.sendMessage(Text.literal(String.valueOf(peripheral.i)), false); player.sendMessage(Text.literal(String.valueOf(peripheral.core.isWaitingOnInterrupt())), false); } diff --git a/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java b/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java index d0e989f..07946bb 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java +++ b/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java @@ -2,6 +2,7 @@ package net.brokenmoon.redcontrol.blocks; import com.simon816.j65el02.device.RedBus; import net.brokenmoon.redcontrol.api.RCWorldBus; +import net.brokenmoon.redcontrol.api.TempRedBus; import net.brokenmoon.redcontrol.blockentities.Peripheral; import net.minecraft.block.*; import net.minecraft.entity.LivingEntity; @@ -54,7 +55,7 @@ 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); - RCWorldBus bus = new RCWorldBus(new RedBus(), world, pos); + RCWorldBus bus = new RCWorldBus(new TempRedBus(), world, pos); entityBlock.setBus(bus); entityBlock.getBus().setValid(true); floodBus(entityBlock.getBus(), world, pos); @@ -84,6 +85,11 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt Peripheral peripheral = (Peripheral) world.getBlockEntity(pos); player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().hashCode())), false); player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().getRedBus().hashCode())), false); + for(int i = 0; i < peripheral.getBus().getRedBus().peripherals.length; i++){ + if (peripheral.getBus().getRedBus().peripherals[i] != null){ + player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().getRedBus().peripherals[i])), false); + } + } } return ActionResult.SUCCESS;