diff --git a/src/main/java/net/brokenmoon/BasicMonitorDriver.java b/src/main/java/net/brokenmoon/BasicMonitorDriver.java index 1277b1f..073a41c 100644 --- a/src/main/java/net/brokenmoon/BasicMonitorDriver.java +++ b/src/main/java/net/brokenmoon/BasicMonitorDriver.java @@ -1,6 +1,5 @@ package net.brokenmoon; -import com.simon816.j65el02.Machine; import com.simon816.j65el02.device.MonitorDriver; import com.simon816.j65el02.device.RPMonitor; @@ -23,13 +22,11 @@ public class BasicMonitorDriver implements MonitorDriver, KeyListener { BufferedImage display; JLabel[] lines = new JLabel[HEIGHT]; - Machine emu; byte[][] windowDataOld = new byte[HEIGHT][WIDTH]; int xoffset = 30; int yoffset = 26; public BasicMonitorDriver() { - this.emu = emu; try{ display = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/display.png"))); } catch(IOException e){ diff --git a/src/main/java/net/brokenmoon/Emulator.java b/src/main/java/net/brokenmoon/Emulator.java new file mode 100644 index 0000000..309546a --- /dev/null +++ b/src/main/java/net/brokenmoon/Emulator.java @@ -0,0 +1,59 @@ +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); + } +} diff --git a/src/main/java/net/brokenmoon/Main.java b/src/main/java/net/brokenmoon/Main.java index 186a77a..5226ed9 100644 --- a/src/main/java/net/brokenmoon/Main.java +++ b/src/main/java/net/brokenmoon/Main.java @@ -1,6 +1,5 @@ package net.brokenmoon; -import com.simon816.j65el02.Machine; import com.simon816.j65el02.device.FileDiskDriver; import com.simon816.j65el02.device.RPDrive; import com.simon816.j65el02.device.RPMonitor; @@ -21,7 +20,7 @@ public class Main { static { try { rpcboot = Paths.get(Main.class.getResource("/rpcboot.bin").toURI()); - disk = Paths.get(Main.class.getResource("/slideshow.img").toURI()); + disk = Paths.get(Main.class.getResource("/basic.img").toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e); } @@ -42,14 +41,15 @@ public class Main { TimerTask interruptTask = new TimerTask(){ public void run(){ if(core.cpu.isWaitingForInterrupt()) - core.setWaitingOnInterrupt(); + core.cpu.state.irqDisableFlag = true; } }; TimerTask cpuTask = new TimerTask(){ public void run(){ - for(int i = 0; i < 50; i++) + for(int i = 0; i < 50; i++) { core.step(); + } } }; diff --git a/src/main/resources/basic.img b/src/main/resources/basic.img new file mode 100644 index 0000000..105176a Binary files /dev/null and b/src/main/resources/basic.img differ