diff --git a/src/main/java/net/brokenmoon/redcontrol/RedControl.java b/src/main/java/net/brokenmoon/redcontrol/RedControl.java index 550beea..e3fd360 100644 --- a/src/main/java/net/brokenmoon/redcontrol/RedControl.java +++ b/src/main/java/net/brokenmoon/redcontrol/RedControl.java @@ -46,10 +46,10 @@ public class RedControl implements ModInitializer { LOGGER.info("Initializing RedControl!"); Registry.register(Registries.BLOCK, new Identifier("redcontrol", "cpu"), CPU); Registry.register(Registries.BLOCK, new Identifier("redcontrol", "monitor"), MONITOR); - Registry.register(Registries.BLOCK, new Identifier("redcontrol", "drive"), DRIVE); + Registry.register(Registries.BLOCK, new Identifier("redcontrol", "disk_drive"), DRIVE); Registry.register(Registries.ITEM, new Identifier("redcontrol", "cpu"), new BlockItem(CPU, new FabricItemSettings())); Registry.register(Registries.ITEM, new Identifier("redcontrol", "monitor"), new BlockItem(MONITOR, new FabricItemSettings())); - Registry.register(Registries.ITEM, new Identifier("redcontrol", "drive"), new BlockItem(DRIVE, new FabricItemSettings())); + Registry.register(Registries.ITEM, new Identifier("redcontrol", "disk_drive"), new BlockItem(DRIVE, new FabricItemSettings())); } } \ No newline at end of file diff --git a/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java b/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java index 84caa27..a843ae7 100644 --- a/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java +++ b/src/main/java/net/brokenmoon/redcontrol/api/Emulator.java @@ -1,5 +1,6 @@ package net.brokenmoon.redcontrol.api; +import com.simon816.j65el02.Bus; import com.simon816.j65el02.Cpu; import com.simon816.j65el02.CpuState; import com.simon816.j65el02.device.Memory; @@ -20,11 +21,12 @@ public class Emulator { public Emulator(RedBus bus){ this.bus = bus; cpu = new Cpu(); - cpu.setBus(new TempBus(bus)); + cpu.setLogCallback(new LogConsumer()); + cpu.setBus(new Bus(bus)); ram = new Memory(0x0000, 0x2000 - 1, ((CpuAccessor)cpu).getRedBusState()); try { - ram.loadFromFile(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/rpcboot.bin"),0x00, 0x400); - ram.loadFromFile(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/redforth.img"), 0x400, 0x100); + ram.loadFromFile(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/rpcboot.bin"),0x400, 0x100); + } catch (IOException e) { throw new RuntimeException(e); } @@ -32,7 +34,6 @@ public class Emulator { cpu.reset(); ram.write(0, 2, ((CpuAccessor)cpu).getRedBusState()); ram.write(1, 1, ((CpuAccessor)cpu).getRedBusState()); - System.out.println("Emulator made"); } public RedBus getBus() { @@ -40,7 +41,6 @@ public class Emulator { } public void setBus(RedBus bus) { - RedControl.LOGGER.info("Setting Emulator bus"); this.bus = bus; ((BusAccessor)this.cpu.getBus()).setRedBus(bus); } @@ -56,9 +56,6 @@ public class Emulator { public void step() { if(!isWaitingOnInterrupt()) { CpuState state = ((CpuAccessor)this.cpu).getState(); - if (state.pc != state.brk) { - RedControl.LOGGER.trace(state.toTraceEvent()); - } this.cpu.step(); this.cpu.getBus().update(((CpuAccessor)cpu).getRedBusState()); } diff --git a/src/main/java/net/brokenmoon/redcontrol/api/LogConsumer.java b/src/main/java/net/brokenmoon/redcontrol/api/LogConsumer.java new file mode 100644 index 0000000..facf7ff --- /dev/null +++ b/src/main/java/net/brokenmoon/redcontrol/api/LogConsumer.java @@ -0,0 +1,12 @@ +package net.brokenmoon.redcontrol.api; + +import net.brokenmoon.redcontrol.RedControl; + +import java.util.function.IntConsumer; + +public class LogConsumer implements IntConsumer { + @Override + public void accept(int value) { + RedControl.LOGGER.info("Cpu MMU Logger: " + value); + } +} diff --git a/src/main/java/net/brokenmoon/redcontrol/api/TempBus.java b/src/main/java/net/brokenmoon/redcontrol/api/TempBus.java deleted file mode 100644 index f267675..0000000 --- a/src/main/java/net/brokenmoon/redcontrol/api/TempBus.java +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 5cad760..0000000 --- a/src/main/java/net/brokenmoon/redcontrol/api/TempRedBus.java +++ /dev/null @@ -1,33 +0,0 @@ -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 8eb5f9e..a5f3a13 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/CpuEntity.java @@ -4,20 +4,15 @@ 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; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; - public class CpuEntity extends Peripheral{ public int i = 0; public boolean notTicked = true; - public Emulator core = new Emulator(new TempRedBus()); + public Emulator core = new Emulator(new RedBus()); private int defaultMonitorId = 1; private int defaultDriveId = 2; @@ -27,7 +22,6 @@ public class CpuEntity extends Peripheral{ public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) { if(be.notTicked) { - be.reset(); be.notTicked = false; } for(int i = 0; i < 500; i++) diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java index b5dbff1..a53dd4a 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/DriveEntity.java @@ -60,7 +60,6 @@ public class DriveEntity extends Peripheral{ @Override public int read(int address) { - RedControl.LOGGER.info("Drive Reading"); switch (address) { case 0x80: // Sector number (lo) return this.sector & 0xff; diff --git a/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java b/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java index 0c92e1f..1bfac77 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java +++ b/src/main/java/net/brokenmoon/redcontrol/blockentities/MonitorEntity.java @@ -47,7 +47,6 @@ public class MonitorEntity extends Peripheral { @Override public void write(int address, int data) { - RedControl.LOGGER.info("Monitor Writing"); switch (address) { case 0x00: this.accessRow = data; @@ -146,7 +145,6 @@ 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/NetworkCarrier.java b/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java index 3ce9e6f..77f0e94 100644 --- a/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java +++ b/src/main/java/net/brokenmoon/redcontrol/blocks/NetworkCarrier.java @@ -2,13 +2,15 @@ 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.brokenmoon.redcontrol.mixin.RedBusAccessor; import net.minecraft.block.*; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Properties; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -38,7 +40,8 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt @Override public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { if(state.hasBlockEntity() && world.getBlockEntity(pos) instanceof Peripheral){ - ((Peripheral) world.getBlockEntity(pos)).getBus().setValid(false); + if(((Peripheral) world.getBlockEntity(pos)).getBus() != null) + ((Peripheral) world.getBlockEntity(pos)).getBus().setValid(false); } if (state.hasBlockEntity() && !state.isOf(newState.getBlock())) { world.removeBlockEntity(pos); @@ -56,7 +59,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 TempRedBus(), world, pos); + RCWorldBus bus = new RCWorldBus(new RedBus(), world, pos); entityBlock.setBus(bus); entityBlock.getBus().setValid(true); floodBus(entityBlock.getBus(), world, pos); @@ -98,4 +101,15 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt return ActionResult.SUCCESS; } + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(Properties.HORIZONTAL_FACING); + } + + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite()); + } + } diff --git a/src/main/resources/assets/redcontrol/blockstates/cpu.json b/src/main/resources/assets/redcontrol/blockstates/cpu.json new file mode 100644 index 0000000..f817c96 --- /dev/null +++ b/src/main/resources/assets/redcontrol/blockstates/cpu.json @@ -0,0 +1,8 @@ +{ + "variants": { + "facing=north": { "model": "redcontrol:block/cpu", "uvlock": false }, + "facing=east": { "model": "redcontrol:block/cpu", "y": 90, "uvlock": false }, + "facing=south": { "model": "redcontrol:block/cpu", "y": 180, "uvlock": false }, + "facing=west": { "model": "redcontrol:block/cpu", "y": 270, "uvlock": false } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/blockstates/disk_drive.json b/src/main/resources/assets/redcontrol/blockstates/disk_drive.json new file mode 100644 index 0000000..cf95c47 --- /dev/null +++ b/src/main/resources/assets/redcontrol/blockstates/disk_drive.json @@ -0,0 +1,8 @@ +{ + "variants": { + "facing=north": { "model": "redcontrol:block/disk_drive", "uvlock": false }, + "facing=east": { "model": "redcontrol:block/disk_drive", "y": 90, "uvlock": false }, + "facing=south": { "model": "redcontrol:block/disk_drive", "y": 180, "uvlock": false }, + "facing=west": { "model": "redcontrol:block/disk_drive", "y": 270, "uvlock": false } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/blockstates/monitor.json b/src/main/resources/assets/redcontrol/blockstates/monitor.json new file mode 100644 index 0000000..dfa8163 --- /dev/null +++ b/src/main/resources/assets/redcontrol/blockstates/monitor.json @@ -0,0 +1,8 @@ +{ + "variants": { + "facing=north": { "model": "redcontrol:block/monitor", "uvlock": false }, + "facing=east": { "model": "redcontrol:block/monitor", "y": 90, "uvlock": false }, + "facing=south": { "model": "redcontrol:block/monitor", "y": 180, "uvlock": false }, + "facing=west": { "model": "redcontrol:block/monitor", "y": 270, "uvlock": false } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/block/cpu.json b/src/main/resources/assets/redcontrol/models/block/cpu.json new file mode 100644 index 0000000..64cebdb --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/block/cpu.json @@ -0,0 +1,23 @@ +{ "parent": "block/block", + "textures": { + "front": "redcontrol:block/cpu", + "left": "redcontrol:block/monitor_left", + "right": "redcontrol:block/monitor_right", + "back": "redcontrol:block/monitor_back", + "top": "redcontrol:block/monitor_bottom", + "bottom": "redcontrol:block/monitor_top" + }, + "elements": [ + { "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#bottom", "cullface": "down" }, + "up": { "texture": "#top", "cullface": "up" }, + "north": { "texture": "#front", "cullface": "north" }, + "south": { "texture": "#back", "cullface": "south" }, + "west": { "texture": "#right", "cullface": "west" }, + "east": { "texture": "#left", "cullface": "east" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/block/disk_drive.json b/src/main/resources/assets/redcontrol/models/block/disk_drive.json new file mode 100644 index 0000000..b839bb0 --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/block/disk_drive.json @@ -0,0 +1,23 @@ +{ "parent": "block/block", + "textures": { + "front": "redcontrol:block/disk_drive", + "left": "redcontrol:block/monitor_left", + "right": "redcontrol:block/monitor_right", + "back": "redcontrol:block/monitor_back", + "top": "redcontrol:block/monitor_bottom", + "bottom": "redcontrol:block/monitor_top" + }, + "elements": [ + { "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#bottom", "cullface": "down" }, + "up": { "texture": "#top", "cullface": "up" }, + "north": { "texture": "#front", "cullface": "north" }, + "south": { "texture": "#back", "cullface": "south" }, + "west": { "texture": "#right", "cullface": "west" }, + "east": { "texture": "#left", "cullface": "east" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/block/monitor.json b/src/main/resources/assets/redcontrol/models/block/monitor.json new file mode 100644 index 0000000..343d9d4 --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/block/monitor.json @@ -0,0 +1,23 @@ +{ "parent": "block/block", + "textures": { + "front": "redcontrol:block/monitor_front", + "left": "redcontrol:block/monitor_left", + "right": "redcontrol:block/monitor_right", + "back": "redcontrol:block/monitor_back", + "top": "redcontrol:block/monitor_bottom", + "bottom": "redcontrol:block/monitor_top" + }, + "elements": [ + { "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#bottom", "cullface": "down" }, + "up": { "texture": "#top", "cullface": "up" }, + "north": { "texture": "#front", "cullface": "north" }, + "south": { "texture": "#back", "cullface": "south" }, + "west": { "texture": "#right", "cullface": "west" }, + "east": { "texture": "#left", "cullface": "east" } + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/item/cpu.json b/src/main/resources/assets/redcontrol/models/item/cpu.json new file mode 100644 index 0000000..4530cc2 --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/cpu.json @@ -0,0 +1,3 @@ +{ + "parent": "redcontrol:block/cpu" +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/item/disk_drive.json b/src/main/resources/assets/redcontrol/models/item/disk_drive.json new file mode 100644 index 0000000..4125203 --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/disk_drive.json @@ -0,0 +1,3 @@ +{ + "parent": "redcontrol:block/disk_drive" +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/models/item/monitor.json b/src/main/resources/assets/redcontrol/models/item/monitor.json new file mode 100644 index 0000000..a63f05a --- /dev/null +++ b/src/main/resources/assets/redcontrol/models/item/monitor.json @@ -0,0 +1,3 @@ +{ + "parent": "redcontrol:block/monitor" +} \ No newline at end of file diff --git a/src/main/resources/assets/redcontrol/textures/block/cpu.ase b/src/main/resources/assets/redcontrol/textures/block/cpu.ase new file mode 100644 index 0000000..3da393b Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/cpu.ase differ diff --git a/src/main/resources/assets/redcontrol/textures/block/cpu.png b/src/main/resources/assets/redcontrol/textures/block/cpu.png new file mode 100644 index 0000000..14d3dbf Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/cpu.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/disk_drive.ase b/src/main/resources/assets/redcontrol/textures/block/disk_drive.ase new file mode 100644 index 0000000..de5b0f9 Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/disk_drive.ase differ diff --git a/src/main/resources/assets/redcontrol/textures/block/disk_drive.png b/src/main/resources/assets/redcontrol/textures/block/disk_drive.png new file mode 100644 index 0000000..c106094 Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/disk_drive.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor.ase b/src/main/resources/assets/redcontrol/textures/block/monitor.ase new file mode 100644 index 0000000..0e6b10d Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor.ase differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor.png b/src/main/resources/assets/redcontrol/textures/block/monitor.png new file mode 100644 index 0000000..434d196 Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor_back.png b/src/main/resources/assets/redcontrol/textures/block/monitor_back.png new file mode 100644 index 0000000..18b441e Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor_back.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor_bottom.png b/src/main/resources/assets/redcontrol/textures/block/monitor_bottom.png new file mode 100644 index 0000000..0cd1aee Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor_bottom.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor_front.png b/src/main/resources/assets/redcontrol/textures/block/monitor_front.png new file mode 100644 index 0000000..c329a8b Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor_front.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor_left.png b/src/main/resources/assets/redcontrol/textures/block/monitor_left.png new file mode 100644 index 0000000..246257c Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor_left.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor_right.png b/src/main/resources/assets/redcontrol/textures/block/monitor_right.png new file mode 100644 index 0000000..1b960d9 Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor_right.png differ diff --git a/src/main/resources/assets/redcontrol/textures/block/monitor_top.png b/src/main/resources/assets/redcontrol/textures/block/monitor_top.png new file mode 100644 index 0000000..f3e98e7 Binary files /dev/null and b/src/main/resources/assets/redcontrol/textures/block/monitor_top.png differ