Bus definitely isnt working.

main
Astoria 7 months ago
parent 4a8ea0a098
commit b297f6363a

@ -14,4 +14,5 @@ public class RCCpu extends Cpu {
this.world = world; this.world = world;
this.pos = pos; this.pos = pos;
} }
} }

@ -17,23 +17,11 @@ import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
public class CpuEntity extends Peripheral implements Runnable{ public class CpuEntity extends Peripheral{
public int i = 0;
static long interruptTimer = 50L;
//Adjust as needed to match original clock speed
TimerTask cpuTask = new TimerTask(){
public void run(){
for(int i = 0; i < 50; i++)
step();
}
};
static Timer timer = new Timer();
boolean notTicked = true; boolean notTicked = true;
private boolean running = false; public RCCpu cpu;
private Semaphore waiInterrupt = new Semaphore(2);
private RCCpu cpu;
private RCBus rcbus; private RCBus rcbus;
private Path bootloader; private Path bootloader;
@ -54,7 +42,7 @@ public class CpuEntity extends Peripheral implements Runnable{
be.cpu = new RCCpu(world, pos); be.cpu = new RCCpu(world, pos);
be.setRCBus(new RCBus(new RedBus())); be.setRCBus(new RCBus(new RedBus()));
be.cpu.setBus(be.getRCBus()); be.cpu.setBus(be.getRCBus());
be.cpu.setBus(new Bus(be.getRCBus().getRedBus())); be.cpu.setBus(be.getRCBus());
Memory ram = new Memory(0x0000, 0x2000); Memory ram = new Memory(0x0000, 0x2000);
try { try {
ram.loadFromFile(be.bootloader, 0x400, 0x100); ram.loadFromFile(be.bootloader, 0x400, 0x100);
@ -64,12 +52,12 @@ public class CpuEntity extends Peripheral implements Runnable{
be.cpu.getBus().addDevice(ram); be.cpu.getBus().addDevice(ram);
be.reset(); be.reset();
be.notTicked = false; be.notTicked = false;
be.start();
} }
} for(int i = 0; i < 50; i++)
be.step();
public void start(){ if(be.cpu.isWaitingForInterrupt()){
timer.schedule(cpuTask, new Date(), 2L); be.cpu.setInterrupt(false);
}
} }
@ -102,47 +90,19 @@ public class CpuEntity extends Peripheral implements Runnable{
this.defaultMonitorId = id; this.defaultMonitorId = id;
} }
public boolean isRunning() {
return this.running;
}
public void run() {
this.running = true;
do {
step();
} while (this.running);
}
public void stop() {
this.running = false;
while (this.waiInterrupt.availablePermits() <= 0) {
this.waiInterrupt.release();
}
this.waiInterrupt.drainPermits();
this.waiInterrupt.release(2);
}
public void reset() { public void reset() {
stop();
this.cpu.reset(); this.cpu.reset();
this.getRCBus().write(0, this.defaultDriveId, getWorld(), this.getPos()); this.getRCBus().write(0, this.defaultDriveId, getWorld(), this.getPos());
this.getRCBus().write(1, this.defaultMonitorId, getWorld(), this.getPos()); this.getRCBus().write(1, this.defaultMonitorId, getWorld(), this.getPos());
} }
public void step() { public void step() {
this.waiInterrupt.acquireUninterruptibly(); i++;
this.cpu.step(); if(!this.cpu.isWaitingForInterrupt()) {
this.getRCBus().update(); this.cpu.step();
if (this.cpu.isStopped()) { this.getBus().update();
this.stop();
return;
}
if (this.cpu.isWaitingForInterrupt()) {
this.waiInterrupt.acquireUninterruptibly();
this.cpu.assertIrq();
}
if (this.waiInterrupt.availablePermits() < 2) {
this.waiInterrupt.release();
} }
} }

@ -4,10 +4,17 @@ import com.mojang.serialization.MapCodec;
import com.simon816.j65el02.Cpu; import com.simon816.j65el02.Cpu;
import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.blockentities.CpuEntity; import net.brokenmoon.redcontrol.blockentities.CpuEntity;
import net.brokenmoon.redcontrol.blockentities.MonitorEntity;
import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -33,4 +40,17 @@ public class CpuBlock extends NetworkCarrier {
return validateTicker(type, RedControl.CPU_BLOCK_ENTITY, (world1, pos, state1, be) -> CpuEntity.tick(world1, pos, state1, be)); return validateTicker(type, RedControl.CPU_BLOCK_ENTITY, (world1, pos, state1, be) -> CpuEntity.tick(world1, pos, state1, be));
} }
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
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.i)), false);
player.sendMessage(Text.literal(String.valueOf(peripheral.cpu.isWaitingForInterrupt())), false);
}
return ActionResult.SUCCESS;
}
} }

@ -104,6 +104,7 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
if (!world.isClient) { if (!world.isClient) {
Peripheral peripheral = (Peripheral) world.getBlockEntity(pos); Peripheral peripheral = (Peripheral) world.getBlockEntity(pos);
player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().hashCode())), false); player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().hashCode())), false);
player.sendMessage(Text.literal(String.valueOf(peripheral.getBus().getRedBus().hashCode())), false);
} }
return ActionResult.SUCCESS; return ActionResult.SUCCESS;

Loading…
Cancel
Save