Add emuname for telling apart multiple emulators
[jpcrr.git] / org / jpc / plugins / TimeDisplay.java
blob2b47d84f16d21783dc43a9190721ea649a208235
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009-2010 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org.jpc.plugins;
32 import org.jpc.emulator.PC;
33 import org.jpc.emulator.Clock;
34 import org.jpc.emulator.EventRecorder;
35 import org.jpc.Misc;
36 import org.jpc.pluginsbase.Plugins;
37 import org.jpc.pluginsbase.Plugin;
38 import static org.jpc.Misc.moveWindow;
40 import javax.swing.*;
41 import java.awt.*;
43 public class TimeDisplay implements Plugin
45 private JFrame window;
46 private JPanel panel;
47 private JLabel display;
48 private PC pc;
49 private Plugins pluginManager;
50 private int nativeWidth, nativeHeight;
52 public void eci_timedisplay_setwinpos(Integer x, Integer y)
54 moveWindow(window, x.intValue(), y.intValue(), nativeWidth, nativeHeight);
58 public TimeDisplay(Plugins _pluginManager)
60 pluginManager = _pluginManager;
61 pc = null;
62 window = new JFrame("Time Display" + Misc.emuname);
63 panel = new JPanel();
64 window.add(panel);
65 display = new JLabel("Time: <NO PC CONNECTED> ");
66 panel.add(display);
68 window.pack();
69 window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
70 Dimension d = window.getSize();
71 nativeWidth = d.width;
72 nativeHeight = d.height;
73 window.setVisible(true);
76 public void main()
78 //This runs entierely in other threads
81 public boolean systemShutdown()
83 //OK to proceed with JVM shutdown.
84 return true;
87 private void updateTime(long timeNow, long timeEnd)
89 String text1;
90 if(timeNow >= 0)
91 text1 = "Time: " + (timeNow / 1000000) + " / " + (timeEnd / 1000000);
92 else if(timeNow == -1)
93 text1 = "Time: <NO PC CONNECTED>";
94 else
95 text1 = "Time: <N/A>";
96 final String text = text1;
98 if(pluginManager.isShuttingDown())
99 return; //Too much of deadlock risk.
101 if(!SwingUtilities.isEventDispatchThread())
102 try {
103 SwingUtilities.invokeAndWait(new Thread() { public void run() { display.setText(text); }});
104 } catch(Exception e) {
106 else
107 display.setText(text);
110 public void pcStarting()
112 updateTime(-2, 0);
115 public void pcStopping()
117 PC.ResetButton brb = (PC.ResetButton)pc.getComponent(PC.ResetButton.class);
118 EventRecorder rec = brb.getRecorder();
119 long lastTime = rec.getLastEventTime();
120 updateTime(((Clock)pc.getComponent(Clock.class)).getTime(), lastTime);
123 public void reconnect(org.jpc.emulator.PC _pc)
125 pc = _pc;
126 if(pc != null) {
127 PC.ResetButton brb = (PC.ResetButton)pc.getComponent(PC.ResetButton.class);
128 EventRecorder rec = brb.getRecorder();
129 long lastTime = rec.getLastEventTime();
130 updateTime(((Clock)pc.getComponent(Clock.class)).getTime(), lastTime);
131 } else
132 updateTime(-1, 0);