Beginnings of BUS

main
Astoria 7 months ago
parent 47ae15deb9
commit 9721848c4e

@ -1,4 +0,0 @@
package net.brokenmoon.redcontrol.api;
public interface IRedBusConnectable {
}

@ -0,0 +1,10 @@
package net.brokenmoon.redcontrol.api;
import com.simon816.j65el02.Bus;
import com.simon816.j65el02.device.RedBus;
public class RCBus extends Bus {
public RCBus(RedBus redBus) {
super(redBus);
}
}

@ -4,7 +4,7 @@ import com.simon816.j65el02.Bus;
import com.simon816.j65el02.Cpu;
import com.simon816.j65el02.device.*;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.IRedBusConnectable;
import net.brokenmoon.redcontrol.api.RCBus;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
@ -16,7 +16,7 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Semaphore;
public class CpuEntity extends BlockEntity implements IRedBusConnectable, Runnable{
public class CpuEntity extends Peripheral implements Runnable{
static long interruptTimer = 50L;
//Adjust as needed to match original clock speed
@ -32,9 +32,7 @@ public class CpuEntity extends BlockEntity implements IRedBusConnectable, Runnab
private boolean running = false;
private Semaphore waiInterrupt = new Semaphore(2);
private final Bus bus;
private final Cpu cpu;
private final RedBus redBus;
private Path bootloader;
{
@ -47,9 +45,7 @@ public class CpuEntity extends BlockEntity implements IRedBusConnectable, Runnab
super(RedControl.CPU_BLOCK_ENTITY, pos, state);
RedControl.LOGGER.info("Making CpuEntity");
this.cpu = new Cpu();
this.redBus = new RedBus();
this.bus = new Bus(this.redBus);
this.cpu.setBus(this.bus);
this.cpu.setBus(this.getBus());
Memory ram = new Memory(0x0000, 0x2000);
try {
@ -57,16 +53,16 @@ public class CpuEntity extends BlockEntity implements IRedBusConnectable, Runnab
} catch (IOException e) {
throw new RuntimeException(e);
}
this.bus.addDevice(ram);
this.getBus().addDevice(ram);
reset();
}
public Bus getBus() {
return this.bus;
public RCBus getBus() {
return this.getBus();
}
public void setPeripheral(int id, RedBus.Peripheral peripheral) {
this.redBus.setPeripheral(id, peripheral);
this.getBus().getRedBus().setPeripheral(id, peripheral);
}
public int getDefaultDriveId() {
@ -114,14 +110,14 @@ public class CpuEntity extends BlockEntity implements IRedBusConnectable, Runnab
public void reset() {
stop();
this.cpu.reset();
this.bus.write(0, this.defaultDriveId);
this.bus.write(1, this.defaultMonitorId);
this.getBus().write(0, this.defaultDriveId);
this.getBus().write(1, this.defaultMonitorId);
}
public void step() {
this.waiInterrupt.acquireUninterruptibly();
this.cpu.step();
this.bus.update();
this.getBus().update();
if (this.cpu.isStopped()) {
this.stop();
return;

@ -1,12 +1,11 @@
package net.brokenmoon.redcontrol.blockentities;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.IRedBusConnectable;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
public class MonitorEntity extends BlockEntity implements IRedBusConnectable {
public class MonitorEntity extends Peripheral {
public MonitorEntity(BlockPos pos, BlockState state) {
super(RedControl.MONITOR_BLOCK_ENTITY, pos, state);
}

@ -0,0 +1,25 @@
package net.brokenmoon.redcontrol.blockentities;
import com.simon816.j65el02.Bus;
import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.api.RCBus;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.math.BlockPos;
public abstract class Peripheral extends BlockEntity {
private RCBus bus;
public Peripheral(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}
public RCBus getBus() {
return bus;
}
public void setBus(RCBus bus) {
this.bus = bus;
}
}

@ -8,7 +8,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public class CpuBlock extends Block implements BlockEntityProvider {
public class CpuBlock extends NetworkCarrier {
public CpuBlock(Settings settings) {
super(settings);
}

@ -8,7 +8,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
public class MonitorBlock extends Block implements BlockEntityProvider {
public class MonitorBlock extends NetworkCarrier {
public MonitorBlock(Settings settings) {
super(settings);
}

@ -0,0 +1,22 @@
package net.brokenmoon.redcontrol.blocks;
import net.brokenmoon.redcontrol.api.RCBus;
import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public abstract class NetworkCarrier extends Block implements BlockEntityProvider {
public NetworkCarrier(Settings settings) {
super(settings);
}
public RCBus getBus(World world, BlockPos pos){
return ((Peripheral)world.getBlockEntity(pos)).getBus();
}
public void setBus(World world, BlockPos pos, RCBus bus){
((Peripheral)world.getBlockEntity(pos)).setBus(bus);
}
}
Loading…
Cancel
Save