Merge branch 'master' of https://git.broken-moon.net/astoriaFloyd/RedControl
commit
83fdc7b864
@ -1 +1 @@
|
|||||||
Subproject commit d4975fa8a08d2026086a08b7eae6543696b61cf7
|
Subproject commit 419245bf18a266be19f8b02a565fb5e7150a39a3
|
@ -0,0 +1,68 @@
|
|||||||
|
package net.brokenmoon.redcontrol.api;
|
||||||
|
|
||||||
|
import com.simon816.j65el02.Bus;
|
||||||
|
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;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class Emulator {
|
||||||
|
|
||||||
|
private RedBus bus;
|
||||||
|
public Cpu cpu;
|
||||||
|
private Memory ram;
|
||||||
|
|
||||||
|
public Emulator(RedBus bus){
|
||||||
|
this.bus = bus;
|
||||||
|
cpu = new Cpu();
|
||||||
|
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);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
cpu.getBus().addDevice(ram, cpu.redBusState);
|
||||||
|
cpu.reset();
|
||||||
|
ram.write(0, 2, cpu.redBusState);
|
||||||
|
ram.write(1, 1, cpu.redBusState);
|
||||||
|
System.out.println("Emulator made");
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedBus getBus() {
|
||||||
|
return bus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBus(RedBus bus) {
|
||||||
|
RedControl.LOGGER.info("Setting Emulator bus");
|
||||||
|
this.bus = bus;
|
||||||
|
this.cpu.getBus().setRedBus(bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWaitingOnInterrupt(){
|
||||||
|
return cpu.isWaitingForInterrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWaitingOnInterrupt(){
|
||||||
|
cpu.getCpuState().intWait = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void step() {
|
||||||
|
if(!isWaitingOnInterrupt()) {
|
||||||
|
this.cpu.step();
|
||||||
|
this.cpu.getBus().update(cpu.redBusState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset(){
|
||||||
|
cpu.reset();
|
||||||
|
ram.write(0, 2, cpu.redBusState);
|
||||||
|
ram.write(1, 1, cpu.redBusState);
|
||||||
|
}
|
||||||
|
}
|
@ -1,89 +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 net.brokenmoon.redcontrol.RedControl;
|
|
||||||
import net.brokenmoon.redcontrol.blockentities.Peripheral;
|
|
||||||
import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class RCBus extends Bus {
|
|
||||||
|
|
||||||
private boolean isValid = false;
|
|
||||||
|
|
||||||
private RedBus redBus;
|
|
||||||
|
|
||||||
private World backupWorld;
|
|
||||||
private BlockPos backupPos;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void write(int address, int data, World world, BlockPos pos) {
|
|
||||||
if(isValid) {
|
|
||||||
Device device = findDevice(address);
|
|
||||||
device.write(address - device.startAddress(), data);
|
|
||||||
} else {
|
|
||||||
generateBusWithWrite(address, data, world, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(int address, int data) {
|
|
||||||
write(address, data, backupWorld, backupPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) {
|
|
||||||
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
||||||
if(isValid) {
|
|
||||||
Device device = findDevice(address);
|
|
||||||
return device.read(address - device.startAddress(), cpuAccess) & 0xff;
|
|
||||||
} else {
|
|
||||||
return generateBusWithRead(address, cpuAccess, world, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int generateBusWithRead(int address, boolean cpuAccess, World world, BlockPos pos) {
|
|
||||||
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(int address, boolean cpuAccess) {
|
|
||||||
return read(address, cpuAccess, backupWorld, backupPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RCBus(RedBus redBus, World world, BlockPos pos) {
|
|
||||||
super(redBus);
|
|
||||||
this.redBus = redBus;
|
|
||||||
backupWorld = world;
|
|
||||||
backupPos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void generateBus(World world, BlockPos pos){
|
|
||||||
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RedBus getRedBus() {
|
|
||||||
return redBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRedBus(RedBus redBus) {
|
|
||||||
this.redBus = redBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
this.getRedBus().updatePeripheral();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValid(boolean val){
|
|
||||||
this.isValid = val;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
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;
|
|
||||||
import net.brokenmoon.redcontrol.RedControl;
|
|
||||||
import net.brokenmoon.redcontrol.blockentities.CpuEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class RCCpu extends Cpu {
|
|
||||||
|
|
||||||
private CpuEntity cpuEntity;
|
|
||||||
private Memory ram = new Memory(0x0000, 0x2000);;
|
|
||||||
|
|
||||||
public RCCpu(CpuEntity cpuEntity) {
|
|
||||||
this.cpuEntity = cpuEntity;
|
|
||||||
this.setBus(this.cpuEntity.getBus());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInterrupt(boolean val){
|
|
||||||
state.intWait = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int readByte(int address) {
|
|
||||||
return this.cpuEntity.getBus().getRedBus().read(address, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void writeMemory(int address, int value, boolean x) {
|
|
||||||
this.getBus().write(address, value);
|
|
||||||
boolean flag = x ? this.state.indexWidthFlag : this.state.mWidthFlag;
|
|
||||||
if (!this.state.emulationFlag && !flag) {
|
|
||||||
this.cpuEntity.getBus().getRedBus().write(address + 1, value >>> 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBus(Bus bus) {
|
|
||||||
super.setBus(bus);
|
|
||||||
if(!cpuEntity.notTicked)
|
|
||||||
getBus().addDevice(this.ram);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Memory getRam() {
|
|
||||||
return ram;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,39 @@
|
|||||||
|
package net.brokenmoon.redcontrol.api;
|
||||||
|
|
||||||
|
import com.simon816.j65el02.device.RedBus;
|
||||||
|
import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class RCWorldBus {
|
||||||
|
|
||||||
|
private boolean isValid = false;
|
||||||
|
|
||||||
|
private RedBus redBus;
|
||||||
|
|
||||||
|
private World backupWorld;
|
||||||
|
private BlockPos backupPos;
|
||||||
|
|
||||||
|
public RCWorldBus(RedBus redBus, World world, BlockPos pos) {
|
||||||
|
this.redBus = redBus;
|
||||||
|
backupWorld = world;
|
||||||
|
backupPos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void generateBus(World world, BlockPos pos){
|
||||||
|
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBus(world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RedBus getRedBus() {
|
||||||
|
return redBus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRedBus(RedBus redBus) {
|
||||||
|
this.redBus = redBus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValid(boolean val){
|
||||||
|
this.isValid = val;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue