⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpc.java

📁 JPC: x86 PC Hardware Emulator. 牛津大学开发的一个纯JAVA的x86系统结构硬件模拟器。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        if (returnVal == 0)                try                {                    System.out.println("Loading a snapshot of JPC");                    ((PC) objects.getObject(PC.class)).loadState(file);                                        System.out.println("Loading data");                    ((PCMonitorFrame) objects.getObject(PCMonitorFrame.class)).resizeDisplay();                    ((PCMonitorFrame) objects.getObject(PCMonitorFrame.class)).loadMonitorState(file);                                        System.out.println("done");                }                catch (IOException e)                {                    e.printStackTrace();                }        }        else if (src == saveSnapshot)        {            runMenu.stop();            JFileChooser fc = new JFileChooser();            try            {                BufferedReader in = new BufferedReader(new FileReader("prefs.txt"));                String path = in.readLine();                in.close();                if (path != null)                {                    File f = new File(path);                    if (f.isDirectory())                        fc.setCurrentDirectory(f);                }            }            catch (Exception e) {}                        int returnVal = fc.showDialog(this, "Save JPC Snapshot");            File file = fc.getSelectedFile();            try            {                if (file != null)                {                    BufferedWriter out = new BufferedWriter(new FileWriter("prefs.txt"));                    out.write(file.getPath());                    out.close();                }            }            catch (Exception e) {e.printStackTrace();}                        if (returnVal == 0)                try                {                    DataOutputStream out = new DataOutputStream(new FileOutputStream(file));                    ZipOutputStream zip = new ZipOutputStream(out);                                        ((PC) objects.getObject(PC.class)).saveState(zip);                    ((PCMonitorFrame) objects.getObject(PCMonitorFrame.class)).saveState(zip);                    zip.close();                }                catch (IOException e)                {                    e.printStackTrace();                }        }        else if (src == createBlankDisk)            createBlankHardDisk();        else if (src == processorFrame)        {            ProcessorFrame pf = (ProcessorFrame) objects.getObject(ProcessorFrame.class);            if (pf != null)                bringToFront(pf);            else            {                pf = new ProcessorFrame();                addInternalFrame(desktop, 10, 10, pf);            }        }        else if (src == physicalMemoryViewer)        {            MemoryViewer mv = (MemoryViewer) objects.getObject(MemoryViewer.class);                        if (mv != null)                bringToFront(mv);            else            {                mv = new MemoryViewer("Physical Memory");                addInternalFrame(desktop, 360, 50, mv);            }        }        else if (src == linearMemoryViewer)        {            LinearMemoryViewer lmv = (LinearMemoryViewer) objects.getObject(LinearMemoryViewer.class);                        if (lmv != null)                bringToFront(lmv);            else            {                lmv = new LinearMemoryViewer("Linear Memory");                addInternalFrame(desktop, 360, 50, lmv);            }        }        else if (src == breakpoints)        {            BreakpointsFrame bp = (BreakpointsFrame) objects.getObject(BreakpointsFrame.class);            if (bp != null)                bringToFront(bp);            else            {                bp = new BreakpointsFrame();                addInternalFrame(desktop, 550, 360, bp);            }        }        else if (src == opcodeFrame)        {            OpcodeFrame op = (OpcodeFrame) objects.getObject(OpcodeFrame.class);            if (op != null)                bringToFront(op);            else            {                op = new OpcodeFrame();                addInternalFrame(desktop, 100, 200, op);            }        }        else if (src == traceFrame)        {            ExecutionTraceFrame tr = (ExecutionTraceFrame) objects.getObject(ExecutionTraceFrame.class);            if (tr != null)                bringToFront(tr);            else            {                tr = new ExecutionTraceFrame();                addInternalFrame(desktop, 30, 100, tr);            }        }        else if (src == monitor)        {            PCMonitorFrame m = (PCMonitorFrame) objects.getObject(PCMonitorFrame.class);            if (m != null)                bringToFront(m);            else            {                m = new PCMonitorFrame();                addInternalFrame(desktop, 30, 30, m);            }        }  //         else if (src == frequencies)//         {//             OpcodeFrequencyFrame f = (OpcodeFrequencyFrame) objects.getObject(OpcodeFrequencyFrame.class);//             if (f != null)//                 bringToFront(f);//             else//             {//                 f = new OpcodeFrequencyFrame();//                 addInternalFrame(desktop, 550, 30, f);//             }//         }        else if (src == codeBlockTreeFrame)        {            CodeBlockCacheFrame f = (CodeBlockCacheFrame) objects.getObject(CodeBlockCacheFrame.class);            if (f != null)                bringToFront(f);            else            {                f = new CodeBlockCacheFrame();                addInternalFrame(desktop, 60, 60, f);            }        }        refresh();    }    public void notifyExecutionStarted()    {        for (int i=0; i<objects.getSize(); i++)        {            Object obj = objects.getObjectAt(i);            if (!(obj instanceof PCListener))                continue;            try            {                PCListener l = (PCListener) obj;                l.executionStarted();            }            catch (Exception e)            {                e.printStackTrace();            }        }    }    public void notifyExecutionStopped()    {        for (int i=0; i<objects.getSize(); i++)        {            Object obj = objects.getObjectAt(i);            if (!(obj instanceof PCListener))                continue;            try            {                PCListener l = (PCListener) obj;                l.executionStopped();            }            catch (Exception e)            {                e.printStackTrace();            }        }    }    public void notifyPCDisposed()    {        for (int i=0; i<objects.getSize(); i++)        {            Object obj = objects.getObjectAt(i);            if (!(obj instanceof PCListener))                continue;            try            {                PCListener l = (PCListener) obj;                l.PCDisposed();            }            catch (Exception e)            {                e.printStackTrace();            }        }    }    public void notifyPCCreated()    {        for (int i=0; i<objects.getSize(); i++)        {            Object obj = objects.getObjectAt(i);            if (!(obj instanceof PCListener))                continue;            try            {                PCListener l = (PCListener) obj;                l.PCCreated();            }            catch (Exception e)            {                e.printStackTrace();            }        }    }    public void refresh()    {        for (int i=0; i<objects.getSize(); i++)        {            Object obj = objects.getObjectAt(i);            if (!(obj instanceof PCListener))                continue;                        try            {                PCListener l = (PCListener) obj;                l.refreshDetails();            }            catch (Exception e)            {                e.printStackTrace();            }        }    }    public PC loadNewPC(PC pc)    {        PC oldPC = (PC) objects.removeObject(PC.class);        if (oldPC != null)            notifyPCDisposed();                JInternalFrame[] frames = desktop.getAllFrames();        for (int i=0; i<frames.length; i++)            frames[i].dispose();        runMenu.refresh();        objects.removeObject(Processor.class);        objects.removeObject(PhysicalAddressSpace.class);        objects.removeObject(LinearAddressSpace.class);        objects.removeObject(VGACard.class);        objects.removeObject(Keyboard.class);        objects.removeObject(ProcessorAccess.class);        objects.removeObject(CodeBlockRecord.class);                for (int i=0; i<10; i++)        {            System.gc();            try            {                Thread.sleep(100);            }            catch (Exception e) {}        }        setTitle("JPC Debugger            Boot Device: "+pc.getBootDevice());        objects.addObject(pc);        objects.addObject(pc.getProcessor());        objects.addObject(pc.getLinearMemory());        objects.addObject(pc.getPhysicalMemory());        objects.addObject(pc.getGraphicsCard());        objects.addObject(pc.getKeyboard());        ProcessorAccess pca = new ProcessorAccess(pc.getProcessor());        codeBlocks = new CodeBlockRecord(pc);        objects.addObject(pca);        objects.addObject(codeBlocks);        runMenu.refresh();        notifyPCCreated();         //processorFrame.doClick();         //breakpoints.doClick();        monitor.doClick();         //codeBlockTreeFrame.doClick();         //opcodeFrame.doClick();                return pc;    }    public PC createPC(DriveSet drives) throws IOException    {        PC newPC = new PC(new VirtualClock(), drives);                BlockDevice fdd = drives.getFloppyDrive(0);        if (fdd != null)            floppyDisk.setSelectedFile(new File(fdd.getImageFileName()), fdd == drives.getBootDevice());        BlockDevice hdd = drives.getHardDrive(0);        if (hdd != null)            hardDisk.setSelectedFile(new File(hdd.getImageFileName()), hdd == drives.getBootDevice());        return loadNewPC(newPC);    }    public PC createPC(String[] args) throws IOException    {        DriveSet drives = DriveSet.buildFromArgs(args);        PC pc = createPC(drives);        String snapShot = ArgProcessor.findArg(args, "ss" , null);        if (snapShot != null)        {            //load PC snapshot            File f = new File(snapShot);            pc.loadState(f);            ((PCMonitorFrame) objects.getObject(PCMonitorFrame.class)).resizeDisplay();            ((PCMonitorFrame) objects.getObject(PCMonitorFrame.class)).loadMonitorState(f);        }        return pc;    }        class Hz extends JLabel implements ActionListener    {        DecimalFormat fmt;        long lastCount, lastTime;        Hz()        {            super("MHz = 0");            fmt = new DecimalFormat("#.##");            lastTime = System.currentTimeMillis();            javax.swing.Timer timer = new javax.swing.Timer(1000, this);            timer.setRepeats(true);            timer.start();        }        public void actionPerformed(ActionEvent evt)        {            if (codeBlocks == null)                return;            long count = codeBlocks.getInstructionCount();            long decoded = codeBlocks.getDecodedCount();            long optimised = codeBlocks.getOptimisedBlockCount();            long executed = codeBlocks.getExecutedBlockCount();            long now = System.currentTimeMillis();            double mhz = 1000.0*(count - lastCount)/(now - lastTime)/1000000;            setText("Decoded: ("+decoded+" x86 Instr) ("+optimised+" UBlocks) | Executed: ("+count+" x86 Instr) ("+executed+" UBlocks) | "+fmt.format(mhz)+" MHz");            lastCount = count;            lastTime = now;        }    }    public void createBlankHardDisk()    {        try        {            JFileChooser chooser = (JFileChooser) objects.getObject(JFileChooser.class);            if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)                return;            String sizeString = JOptionPane.showInputDialog(this, "Enter the size in MB for the disk", "Disk Image Creation", JOptionPane.QUESTION_MESSAGE);            if (sizeString == null)                return;            long size = Long.parseLong(sizeString)*1024l*1024l;            if (size < 0)                throw new Exception("Negative file size");                                RandomAccessFile f = new RandomAccessFile(chooser.getSelectedFile(), "rw");            f.setLength(size);            f.close();        }        catch (Exception e)         {            alert("Failed to create blank disk "+e, "Create Disk", JOptionPane.ERROR_MESSAGE);        }    }    public static Object getObject(Class cls)    {        return instance.get(cls);    }    public static JPC getInstance()    {        return instance;    }    public static void main(String[] args) throws IOException    {	initialise();	boolean fullScreen = true;	for (int i=0; i<args.length; i++)	    if (args[i].startsWith("full"))	    {		fullScreen = true;		break;	    }	instance = new JPC(fullScreen);	instance.validate();	instance.setVisible(true);	if (args.length > 0)	    instance.createPC(args);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -