You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB
Java

package net.brokenmoon;
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 Emulator(RedBus bus) {
this.bus = bus;
cpu = new Cpu();
cpu.setBus(new Bus(bus));
ram = new Memory(0x0000, 0x4000, new RedBusState());
try {
ram.loadFromFile(Paths.get(Main.class.getResource("/rpcboot.bin").toURI()), 0x400, 0x100);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (URISyntaxException 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.assertIrq();
}
public void step() {
this.cpu.step();
this.cpu.getBus().update(cpu.redBusState);
}
}