okay I think this will work (I hope I dont break EVERYTHING)

main
Walker Fowlkes 7 months ago
commit 7a47e17053

@ -46,10 +46,10 @@ public class RedControl implements ModInitializer {
LOGGER.info("Initializing RedControl!"); LOGGER.info("Initializing RedControl!");
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "cpu"), CPU); 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", "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", "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", "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()));
} }
} }

@ -1,5 +1,6 @@
package net.brokenmoon.redcontrol.api; package net.brokenmoon.redcontrol.api;
import com.simon816.j65el02.Bus;
import com.simon816.j65el02.Cpu; import com.simon816.j65el02.Cpu;
import com.simon816.j65el02.CpuState; import com.simon816.j65el02.CpuState;
import com.simon816.j65el02.device.Memory; import com.simon816.j65el02.device.Memory;
@ -20,11 +21,12 @@ public class Emulator {
public Emulator(RedBus bus){ public Emulator(RedBus bus){
this.bus = bus; this.bus = bus;
cpu = new Cpu(); 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()); ram = new Memory(0x0000, 0x2000 - 1, ((CpuAccessor)cpu).getRedBusState());
try { 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/rpcboot.bin"),0x400, 0x100);
ram.loadFromFile(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/redforth.img"), 0x400, 0x100);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -32,7 +34,6 @@ public class Emulator {
cpu.reset(); cpu.reset();
ram.write(0, 2, ((CpuAccessor)cpu).getRedBusState()); ram.write(0, 2, ((CpuAccessor)cpu).getRedBusState());
ram.write(1, 1, ((CpuAccessor)cpu).getRedBusState()); ram.write(1, 1, ((CpuAccessor)cpu).getRedBusState());
System.out.println("Emulator made");
} }
public RedBus getBus() { public RedBus getBus() {
@ -40,7 +41,6 @@ public class Emulator {
} }
public void setBus(RedBus bus) { public void setBus(RedBus bus) {
RedControl.LOGGER.info("Setting Emulator bus");
this.bus = bus; this.bus = bus;
((BusAccessor)this.cpu.getBus()).setRedBus(bus); ((BusAccessor)this.cpu.getBus()).setRedBus(bus);
} }
@ -56,9 +56,6 @@ public class Emulator {
public void step() { public void step() {
if(!isWaitingOnInterrupt()) { if(!isWaitingOnInterrupt()) {
CpuState state = ((CpuAccessor)this.cpu).getState(); CpuState state = ((CpuAccessor)this.cpu).getState();
if (state.pc != state.brk) {
RedControl.LOGGER.trace(state.toTraceEvent());
}
this.cpu.step(); this.cpu.step();
this.cpu.getBus().update(((CpuAccessor)cpu).getRedBusState()); this.cpu.getBus().update(((CpuAccessor)cpu).getRedBusState());
} }

@ -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);
}
}

@ -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;
}
}

@ -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;
}
}

@ -4,20 +4,15 @@ import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.Emulator; import net.brokenmoon.redcontrol.api.Emulator;
import net.brokenmoon.redcontrol.api.RCWorldBus; import net.brokenmoon.redcontrol.api.RCWorldBus;
import net.brokenmoon.redcontrol.api.TempRedBus;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; 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 class CpuEntity extends Peripheral{
public int i = 0; public int i = 0;
public boolean notTicked = true; public boolean notTicked = true;
public Emulator core = new Emulator(new TempRedBus()); public Emulator core = new Emulator(new RedBus());
private int defaultMonitorId = 1; private int defaultMonitorId = 1;
private int defaultDriveId = 2; 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) { public static void tick(World world, BlockPos pos, BlockState state, CpuEntity be) {
if(be.notTicked) { if(be.notTicked) {
be.reset();
be.notTicked = false; be.notTicked = false;
} }
for(int i = 0; i < 500; i++) for(int i = 0; i < 500; i++)

@ -60,7 +60,6 @@ public class DriveEntity extends Peripheral{
@Override @Override
public int read(int address) { public int read(int address) {
RedControl.LOGGER.info("Drive Reading");
switch (address) { switch (address) {
case 0x80: // Sector number (lo) case 0x80: // Sector number (lo)
return this.sector & 0xff; return this.sector & 0xff;

@ -47,7 +47,6 @@ public class MonitorEntity extends Peripheral {
@Override @Override
public void write(int address, int data) { public void write(int address, int data) {
RedControl.LOGGER.info("Monitor Writing");
switch (address) { switch (address) {
case 0x00: case 0x00:
this.accessRow = data; this.accessRow = data;
@ -146,7 +145,6 @@ public class MonitorEntity extends Peripheral {
@Override @Override
public void update() { public void update() {
RedControl.LOGGER.info("MONITOR UPDATED");
int maxWidth = Math.min(WIDTH, this.blitWidth + this.blitXOffset); int maxWidth = Math.min(WIDTH, this.blitWidth + this.blitXOffset);
int maxHeight = Math.min(HEIGHT, this.blitHeight + this.blitYOffset); int maxHeight = Math.min(HEIGHT, this.blitHeight + this.blitYOffset);

@ -2,13 +2,15 @@ package net.brokenmoon.redcontrol.blocks;
import com.simon816.j65el02.device.RedBus; import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.api.RCWorldBus; import net.brokenmoon.redcontrol.api.RCWorldBus;
import net.brokenmoon.redcontrol.api.TempRedBus;
import net.brokenmoon.redcontrol.blockentities.Peripheral; import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.brokenmoon.redcontrol.mixin.RedBusAccessor; import net.brokenmoon.redcontrol.mixin.RedBusAccessor;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -38,7 +40,8 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
@Override @Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if(state.hasBlockEntity() && world.getBlockEntity(pos) instanceof Peripheral){ 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())) { if (state.hasBlockEntity() && !state.isOf(newState.getBlock())) {
world.removeBlockEntity(pos); world.removeBlockEntity(pos);
@ -56,7 +59,7 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
Block worldBlock = world.getBlockState(pos).getBlock(); Block worldBlock = world.getBlockState(pos).getBlock();
if(world.getBlockEntity(pos) instanceof Peripheral){ if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos); 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.setBus(bus);
entityBlock.getBus().setValid(true); entityBlock.getBus().setValid(true);
floodBus(entityBlock.getBus(), world, pos); floodBus(entityBlock.getBus(), world, pos);
@ -98,4 +101,15 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
} }

@ -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 }
}
}

@ -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 }
}
}

@ -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 }
}
}

@ -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" }
}
}
]
}

@ -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" }
}
}
]
}

@ -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" }
}
}
]
}

@ -0,0 +1,3 @@
{
"parent": "redcontrol:block/cpu"
}

@ -0,0 +1,3 @@
{
"parent": "redcontrol:block/disk_drive"
}

@ -0,0 +1,3 @@
{
"parent": "redcontrol:block/monitor"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Loading…
Cancel
Save