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.Memory;
import com.simon816.j65el02.device.RedBus; import com.simon816.j65el02.device.RedBus;
import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.blockentities.Peripheral;
import net.brokenmoon.redcontrol.blocks.NetworkCarrier; import net.brokenmoon.redcontrol.blocks.NetworkCarrier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; 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) { if(isValid) {
Device device = findDevice(address); Device device = findDevice(address, redbusStartAddress);
device.write(address - device.startAddress(), data); if(!(device instanceof Memory))
RedControl.LOGGER.info(device.toString());
device.write(address, data, redbusTarget, redbusStartAddress);
} else { } else {
generateBusWithWrite(address, data, world, pos); generateBusWithWrite(address, data, redbusTarget, redbusStartAddress, world, pos);
} }
} }
@Override @Override
public void write(int address, int data) { public void write(int address, int data, int redbusTarget, int redbusStartAddress) {
write(address, data, backupWorld, backupPos); write(address, data, redbusTarget, redbusStartAddress, backupWorld, backupPos);
} }
private void generateBusWithWrite(int address, int data, World world, BlockPos pos) { 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); ((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) { if(isValid) {
Device device = findDevice(address); Device device = findDevice(address, redbusStartAddress);
return device.read(address - device.startAddress(), cpuAccess) & 0xff; if(!(device instanceof Memory))
RedControl.LOGGER.info(device.toString());
return device.read(address, cpuAccess, redbusTarget, redbusStartAddress) & 0xff;
} else { } 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) { 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); return ((NetworkCarrier)(world.getBlockState(pos).getBlock())).generateBusWithRead(world, pos, address, cpuAccess, redbusTarget, redbusStartAddress);
} }
@Override @Override
public int read(int address, boolean cpuAccess) { public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress) {
return read(address, cpuAccess, backupWorld, backupPos); return read(address, cpuAccess, redbusTarget, redbusStartAddress, backupWorld, backupPos);
} }
public RCBus(RedBus redBus, World world, BlockPos pos) { public RCBus(RedBus redBus, World world, BlockPos pos) {
@ -79,12 +82,20 @@ public class RCBus extends Bus {
this.redBus = redBus; this.redBus = redBus;
} }
@Override
public void update() {
this.getRedBus().updatePeripheral();
}
public void setValid(boolean val){ public void setValid(boolean val){
this.isValid = 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.Bus;
import com.simon816.j65el02.Cpu; import com.simon816.j65el02.Cpu;
import com.simon816.j65el02.CpuState;
import com.simon816.j65el02.device.Memory; import com.simon816.j65el02.device.Memory;
import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.blockentities.CpuEntity; import net.brokenmoon.redcontrol.blockentities.CpuEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class RCCpu extends Cpu { public class RCCpu extends Cpu {
private CpuEntity cpuEntity; private CpuEntity cpuEntity;
private Memory ram = new Memory(0x0000, 0x2000);; private Memory ram = new Memory(0x0000, 0x2000);
public RCCpu(CpuEntity cpuEntity, RCBus bus) { public RCCpu(CpuEntity cpuEntity, RCBus bus) {
this.cpuEntity = cpuEntity; this.cpuEntity = cpuEntity;
@ -25,15 +21,15 @@ public class RCCpu extends Cpu {
@Override @Override
protected int readByte(int address) { protected int readByte(int address) {
return this.cpuEntity.getBus().getRedBus().read(address, true); return this.cpuEntity.getBus().getRedBus().read(address, true, redbusTarget, redbusStartAddress);
} }
@Override @Override
protected void writeMemory(int address, int value, boolean x) { 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; boolean flag = x ? this.state.indexWidthFlag : this.state.mWidthFlag;
if (!this.state.emulationFlag && !flag) { 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 { public class RCRedbus extends RedBus {
@Override @Override
public void write(int address, int data) { public void write(int address, int data, int redbusTarget, int redbusStartAddress) {
if (!this.enabled) { if (!this.enabled) {
return; return;
} }
Peripheral peripheral = this.peripherals[this.activeDeviceId]; Peripheral peripheral = this.peripherals[redbusTarget];
RedControl.LOGGER.info("Peripheral write at " + address + " for " + redbusTarget);
if (peripheral != null) { if (peripheral != null) {
peripheral.write(address, data & 0xff); peripheral.write(address, data & 0xff);
} }
} }
@Override @Override
public void setActiveDevice(int id) { public int read(int address, boolean cpuAccess, int redbusTarget, int redbusStartAddress) {
RedControl.LOGGER.info("Active device is now " + id); if (!this.enabled) {
this.activeDeviceId = id; return 0;
} }
Peripheral peripheral = this.peripherals[redbusTarget];
@Override RedControl.LOGGER.info("Peripheral read at " + address + " for " + redbusTarget);
public int getActiveDevice() { if (peripheral != null) {
RedControl.LOGGER.info("Active device is being read, and it is " + activeDeviceId); return peripheral.read(address);
return this.activeDeviceId; }
return 0;
} }
} }

@ -1,7 +1,6 @@
package net.brokenmoon.redcontrol.blockentities; package net.brokenmoon.redcontrol.blockentities;
import com.simon816.j65el02.Bus; import com.simon816.j65el02.device.RedBus;
import com.simon816.j65el02.device.*;
import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.RedControl;
import net.brokenmoon.redcontrol.api.RCBus; import net.brokenmoon.redcontrol.api.RCBus;
import net.brokenmoon.redcontrol.api.RCCpu; import net.brokenmoon.redcontrol.api.RCCpu;
@ -92,15 +91,15 @@ public class CpuEntity extends Peripheral{
public void reset() { public void reset() {
this.cpu.reset(); this.cpu.reset();
this.getBus().write(0, this.defaultDriveId, getWorld(), this.getPos()); this.getBus().write(0, this.defaultDriveId, cpu.redbusTarget, cpu.redbusStartAddress, getWorld(), this.getPos());
this.getBus().write(1, this.defaultMonitorId, getWorld(), this.getPos()); this.getBus().write(1, this.defaultMonitorId, cpu.redbusTarget, cpu.redbusStartAddress, getWorld(), this.getPos());
} }
public void step() { public void step() {
i++; i++;
if(!this.cpu.isWaitingForInterrupt()) { if(!this.cpu.isWaitingForInterrupt()) {
this.cpu.step(); 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){ if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos); Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
generateBus(world,pos); generateBus(world,pos);
floodBus(entityBlock.getBus(), 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){ if(world.getBlockEntity(pos) instanceof Peripheral){
Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos); Peripheral entityBlock = (Peripheral) world.getBlockEntity(pos);
generateBus(world,pos); generateBus(world,pos);
floodBus(entityBlock.getBus(), 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; return 0;
} }

Loading…
Cancel
Save