public synchronized byte[] getExtendedRAM(int size) { byte[] rv = null; if (size > 0) { if (this.ramExtended != null) { if (size > this.ramExtended.length) { rv = new byte[size]; Arrays.fill(rv, (byte) 0); System.arraycopy(this.ramExtended, 0, rv, 0, this.ramExtended.length); this.ramExtended = rv; } else { rv = this.ramExtended; } } else { rv = new byte[size]; Arrays.fill(rv, (byte) 0); this.ramExtended = rv; } } return rv; }
public EmuThread(ScreenFrm screenFrm, Properties props) { super("JKCEMU CPU"); this.screenFrm = screenFrm; this.z80cpu = new Z80CPU(this, this); this.monitor = "a monitor object for synchronization"; this.joyFrm = null; this.joyThreads = new JoystickThread[2]; this.ram = new byte[0x10000]; this.ramExtended = null; this.ramFloppy1 = new RAMFloppy(); this.ramFloppy2 = new RAMFloppy(); this.printMngr = new PrintMngr(); this.audioIn = null; this.audioOut = null; this.loadData = null; this.resetLevel = ResetLevel.POWER_ON; this.emuRunning = false; this.emuSys = null; Arrays.fill(this.joyThreads, null); applySettings(props); }
@Override public void run() { this.emuRunning = true; while (this.emuRunning) { try { /* * Pruefen, ob ein Programm geladen oder der Emulator * tatsaechlich zurueckgesetzt werden soll */ LoadData loadData = null; synchronized (this.monitor) { loadData = this.loadData; if (loadData != null) { this.loadData = null; } else { if (this.resetLevel == ResetLevel.POWER_ON) { Arrays.fill(this.ram, (byte) 0); } } } if (loadData != null) { loadData.loadIntoMemory(this); this.z80cpu.setRegPC(loadData.getStartAddr()); if (this.emuSys != null) { int spInitValue = this.emuSys.getAppStartStackInitValue(); if (spInitValue > 0) { this.z80cpu.setRegSP(spInitValue); } } } else { if ((this.resetLevel == ResetLevel.COLD_RESET) || (this.resetLevel == ResetLevel.POWER_ON)) { this.z80cpu.resetCPU(true); } else { this.z80cpu.resetCPU(false); } if (this.emuSys != null) { this.emuSys.reset(this.resetLevel, Main.getProperties()); this.z80cpu.setRegPC(this.emuSys.getResetStartAddress(this.resetLevel)); } } // RAM-Floppies und Druckmanager zuruecksetzen this.printMngr.reset(); this.ramFloppy1.reset(); this.ramFloppy2.reset(); if ((this.emuSys != null) && (this.resetLevel == ResetLevel.POWER_ON) && Main.getBooleanProperty("jkcemu.ramfloppy.clear_on_power_on", false)) { if (this.emuSys.supportsRAMFloppy1() && (this.ramFloppy1.getUsedSize() > 0)) { this.ramFloppy1.clear(); } if (this.emuSys.supportsRAMFloppy2() && (this.ramFloppy2.getUsedSize() > 0)) { this.ramFloppy2.clear(); } } // Fenster informieren final Frame[] frms = Frame.getFrames(); if (frms != null) { EventQueue.invokeLater( new Runnable() { @Override public void run() { for (Frame f : frms) { if (f instanceof BasicFrm) { ((BasicFrm) f).resetFired(); } } } }); } // in die Z80-Emulation verzweigen this.resetLevel = ResetLevel.NO_RESET; this.z80cpu.run(); } catch (Z80ExternalException ex) { } catch (Exception ex) { this.emuRunning = false; EventQueue.invokeLater(new ErrorMsg(this.screenFrm, ex)); } } }