Bus: still broken, but closer, i think.

main
Astoria 7 months ago
parent fecf68e816
commit a3364cb260

@ -1 +1 @@
Subproject commit d4975fa8a08d2026086a08b7eae6543696b61cf7
Subproject commit 9e2e5145e04787fc2cd36f53e67c572887ee1b15

@ -5,7 +5,6 @@ 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.blockentities.Peripheral;
import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -23,40 +22,44 @@ public class RCBus extends Bus {
public void write(int address, int data, World world, BlockPos pos) {
public void write(int address, int data, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
if(isValid) {
Device device = findDevice(address);
device.write(address - device.startAddress(), data);
Device device = findDevice(address, redbusStartAddress);
if(!(device instanceof Memory))
RedControl.LOGGER.info(device.toString());
device.write(address, data, redbusTarget, redbusStartAddress);
} else {
generateBusWithWrite(address, data, world, pos);
generateBusWithWrite(address, data, redbusTarget, redbusStartAddress, world, pos);
}
}
@Override
public void write(int address, int data) {
write(address, data, backupWorld, backupPos);
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, World world, BlockPos pos) {
((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithWrite(world, pos, address, data);
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, World world, BlockPos pos) {
public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress, World world, BlockPos pos) {
if(isValid) {
Device device = findDevice(address);
return device.read(address - device.startAddress(), cpuAccess) & 0xff;
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, world, pos);
return generateBusWithRead(address, cpuAccess, redbusTarget, redbusStartAddress, world, pos);
}
}
private int generateBusWithRead(int address, boolean cpuAccess, World world, BlockPos pos) {
return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess);
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) {
return read(address, cpuAccess, backupWorld, backupPos);
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) {
@ -79,12 +82,20 @@ public class RCBus extends Bus {
this.redBus = redBus;
}
@Override
public void update() {
this.getRedBus().updatePeripheral();
}
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);
}
}

@ -2,17 +2,13 @@ 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);;
private Memory ram = new Memory(0x0000, 0x2000);
public RCCpu(CpuEntity cpuEntity, RCBus bus) {
this.cpuEntity = cpuEntity;
@ -25,15 +21,15 @@ public class RCCpu extends Cpu {
@Override
protected int readByte(int address) {
return this.cpuEntity.getBus().getRedBus().read(address, true);
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.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);
this.cpuEntity.getBus().getRedBus().write(address + 1, value >>> 8, redbusTarget, redbusStartAddress);
}
}

@ -5,25 +5,27 @@ import net.brokenmoon.redcontrol.RedControl;
public class RCRedbus extends RedBus {
@Override
public void write(int address, int data) {
public void write(int address, int data, int redbusTarget, int redbusStartAddress) {
if (!this.enabled) {
return;
}
Peripheral peripheral = this.peripherals[this.activeDeviceId];
Peripheral peripheral = this.peripherals[redbusTarget];
RedControl.LOGGER.info("Peripheral write at " + address + " for " + redbusTarget);
if (peripheral != null) {
peripheral.write(address, data & 0xff);
}
}
@Override
public void setActiveDevice(int id) {
RedControl.LOGGER.info("Active device is now " + id);
this.activeDeviceId = id;
}
@Override
public int getActiveDevice() {
RedControl.LOGGER.info("Active device is being read, and it is " + activeDeviceId);
return this.activeDeviceId;
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;
}
}

@ -1,7 +1,6 @@
package net.brokenmoon.redcontrol.blockentities;
import com.simon816.j65el02.Bus;
import com.simon816.j65el02.device.*;
import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.RCBus;
import net.brokenmoon.redcontrol.api.RCCpu;
@ -92,15 +91,15 @@ public class CpuEntity extends Peripheral{
public void reset() {
this.cpu.reset();
this.getBus().write(0, this.defaultDriveId, getWorld(), this.getPos());
this.getBus().write(1, this.defaultMonitorId, getWorld(), this.getPos());
this.getBus().write(0, this.defaultDriveId, cpu.redbusTarget, cpu.redbusStartAddress, getWorld(), this.getPos());
this.getBus().write(1, this.defaultMonitorId, cpu.redbusTarget, cpu.redbusStartAddress, getWorld(), this.getPos());
}
public void step() {
i++;
if(!this.cpu.isWaitingForInterrupt()) {
this.cpu.step();
this.getBus().update();
this.getBus().update(this.cpu.redbusTarget);
}
}

@ -79,21 +79,21 @@ public abstract class NetworkCarrier extends BlockWithEntity implements BlockEnt
}
}
public void generateBusWithWrite(World world, BlockPos pos, int address, int data) {
public void generateBusWithWrite(World world, BlockPos pos, int address, int data, int redbusTarget, int redbusStartAddress) {
if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
generateBus(world,pos);
floodBus(entityBlock.getBus(), world, pos);
entityBlock.getBus().write(address, data, world, pos);
entityBlock.getBus().write(address, data, redbusTarget, redbusStartAddress, world, pos);
}
}
public int generateBusWithRead(World world, BlockPos pos, int address, boolean cpuAccess) {
public int generateBusWithRead(World world, BlockPos pos, int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress) {
if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
generateBus(world,pos);
floodBus(entityBlock.getBus(), world, pos);
return entityBlock.getBus().read(address, cpuAccess, world, pos);
return entityBlock.getBus().read(address, cpuAccess, redbusTarget, redbusStartAddress, world, pos);
}
return 0;
}

Loading…
Cancel
Save