Bus: maybe not broken but still not working
parent
a3364cb260
commit
9ad756e11b
@ -1 +1 @@
|
||||
Subproject commit 9e2e5145e04787fc2cd36f53e67c572887ee1b15
|
||||
Subproject commit 3690b0031fd685abecc2f7d21678c61dca69f40f
|
@ -0,0 +1,67 @@
|
||||
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 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 boolean isRunning = false;
|
||||
|
||||
public Emulator(RedBus bus){
|
||||
this.bus = bus;
|
||||
cpu = new Cpu();
|
||||
cpu.setBus(new Bus(bus));
|
||||
ram = new Memory(0x0000, 0x2000, new 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) {
|
||||
this.bus = bus;
|
||||
}
|
||||
|
||||
public boolean isWaitingOnInterrupt(){
|
||||
return cpu.isWaitingForInterrupt();
|
||||
}
|
||||
|
||||
public void setWaitingOnInterrupt(){
|
||||
cpu.getCpuState().intWait = false;
|
||||
}
|
||||
|
||||
public void step() {
|
||||
if(!isWaitingOnInterrupt() && isRunning) {
|
||||
this.cpu.step();
|
||||
this.cpu.getBus().update(cpu.redBusState);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
isRunning = false;
|
||||
cpu.reset();
|
||||
ram.write(0, 2, cpu.redBusState);
|
||||
ram.write(1, 1, cpu.redBusState);
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
package net.brokenmoon.redcontrol.api;
|
||||
|
||||
import com.simon816.j65el02.Bus;
|
||||
import com.simon816.j65el02.device.Device;
|
||||
import com.simon816.j65el02.device.Memory;
|
||||
import com.simon816.j65el02.device.RedBus;
|
||||
import net.brokenmoon.redcontrol.RedControl;
|
||||
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, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
||||
if(isValid) {
|
||||
Device device = findDevice(address, redbusStartAddress);
|
||||
if(!(device instanceof Memory))
|
||||
RedControl.LOGGER.info(device.toString());
|
||||
device.write(address, data, redbusTarget, redbusStartAddress);
|
||||
} else {
|
||||
generateBusWithWrite(address, data, redbusTarget, redbusStartAddress, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int address, int data, int redbusTarget, int redbusStartAddress) {
|
||||
write(address, data, redbusTarget, redbusStartAddress, backupWorld, backupPos);
|
||||
}
|
||||
|
||||
private void generateBusWithWrite(int address, int data, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
||||
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data, redbusTarget, redbusStartAddress);
|
||||
}
|
||||
|
||||
public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
||||
if(isValid) {
|
||||
Device device = findDevice(address, redbusStartAddress);
|
||||
if(!(device instanceof Memory))
|
||||
RedControl.LOGGER.info(device.toString());
|
||||
return device.read(address, cpuAccess, redbusTarget, redbusStartAddress) & 0xff;
|
||||
} else {
|
||||
return generateBusWithRead(address, cpuAccess, redbusTarget, redbusStartAddress, world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private int generateBusWithRead(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
|
||||
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess, redbusTarget, redbusStartAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress) {
|
||||
return read(address, cpuAccess, redbusTarget, redbusStartAddress, 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;
|
||||
}
|
||||
|
||||
public void setValid(boolean val){
|
||||
this.isValid = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Device findDevice(int address, int redbusStartAddress) {
|
||||
// RedBus takes priority
|
||||
if (address >= redbusStartAddress && address <= (redbusStartAddress + 0xFF)) {
|
||||
return this.redBus;
|
||||
}
|
||||
int idx = Arrays.binarySearch(this.boundaries, address);
|
||||
if (idx < 0) {
|
||||
idx = -idx - 2;
|
||||
}
|
||||
return this.devices.get(idx);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package net.brokenmoon.redcontrol.api;
|
||||
|
||||
import com.simon816.j65el02.Bus;
|
||||
import com.simon816.j65el02.Cpu;
|
||||
import com.simon816.j65el02.device.Memory;
|
||||
import net.brokenmoon.redcontrol.blockentities.CpuEntity;
|
||||
|
||||
public class RCCpu extends Cpu {
|
||||
|
||||
private CpuEntity cpuEntity;
|
||||
private Memory ram = new Memory(0x0000, 0x2000);
|
||||
|
||||
public RCCpu(CpuEntity cpuEntity, RCBus bus) {
|
||||
this.cpuEntity = cpuEntity;
|
||||
this.setBus(bus);
|
||||
}
|
||||
|
||||
public void setInterrupt(boolean val){
|
||||
state.intWait = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int readByte(int address) {
|
||||
return this.cpuEntity.getBus().getRedBus().read(address, true, redbusTarget, redbusStartAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeMemory(int address, int value, boolean x) {
|
||||
this.getBus().write(address, value, this.redbusTarget, this.redbusStartAddress);
|
||||
boolean flag = x ? this.state.indexWidthFlag : this.state.mWidthFlag;
|
||||
if (!this.state.emulationFlag && !flag) {
|
||||
this.cpuEntity.getBus().getRedBus().write(address + 1, value >>> 8, redbusTarget, redbusStartAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBus(Bus bus) {
|
||||
super.setBus(bus);
|
||||
this.getBus().addDevice(this.ram);
|
||||
}
|
||||
|
||||
public Memory getRam() {
|
||||
return ram;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package net.brokenmoon.redcontrol.api;
|
||||
|
||||
import com.simon816.j65el02.device.RedBus;
|
||||
import net.brokenmoon.redcontrol.RedControl;
|
||||
|
||||
public class RCRedbus extends RedBus {
|
||||
@Override
|
||||
public void write(int address, int data, int redbusTarget, int redbusStartAddress) {
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
Peripheral peripheral = this.peripherals[redbusTarget];
|
||||
RedControl.LOGGER.info("Peripheral write at " + address + " for " + redbusTarget);
|
||||
if (peripheral != null) {
|
||||
peripheral.write(address, data & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress) {
|
||||
if (!this.enabled) {
|
||||
return 0;
|
||||
}
|
||||
Peripheral peripheral = this.peripherals[redbusTarget];
|
||||
RedControl.LOGGER.info("Peripheral read at " + address + " for " + redbusTarget);
|
||||
if (peripheral != null) {
|
||||
return peripheral.read(address);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue