Add emuname for telling apart multiple emulators
[jpcrr.git] / org / jpc / plugins / PCStartStopTest.java
blob413ea2a614e0391e7b3742c9981ac113ec3574fd
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 java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.security.AccessControlException;
35 import javax.swing.*;
37 import org.jpc.pluginsbase.Plugins;
38 import org.jpc.pluginsbase.Plugin;
39 import org.jpc.emulator.PC;
40 import org.jpc.emulator.peripheral.Keyboard;
41 import org.jpc.Misc;
42 import static org.jpc.Misc.errorDialog;
43 import static org.jpc.Misc.moveWindow;
45 public class PCStartStopTest extends JFrame implements Plugin
47 private static final long serialVersionUID = 8;
48 private Plugins vPluginManager;
49 private Keyboard keyboard;
51 public boolean systemShutdown()
53 //Not interested (JVM kill ok)
54 return true;
57 public void reconnect(PC pc)
59 if(pc != null) {
60 keyboard = (Keyboard)pc.getComponent(Keyboard.class);
61 } else {
62 keyboard = null;
66 public void pcStarting()
68 //Not interested.
71 public void pcStopping()
73 //Not interested.
76 public void main()
78 //Not interested.
81 public void connectPC(PC pc)
83 //Not interested.
86 public void eci_pcstartstoptest_setwinpos(Integer x, Integer y)
88 moveWindow(this, x.intValue(), y.intValue(), 720, 50);
92 public PCStartStopTest(Plugins manager) throws Exception
94 super("Control test" + Misc.emuname);
96 this.vPluginManager = manager;
98 JMenuBar bar = new JMenuBar();
99 JMenuItem tmp;
101 JMenu file = new JMenu("Action");
102 (tmp = file.add("Vretrace start trap on")).addActionListener(new ActionListener() {
103 public void actionPerformed(ActionEvent e)
105 vPluginManager.invokeExternalCommand("trap-vretrace-start-on", null);
108 tmp.setAccelerator(KeyStroke.getKeyStroke("3"));
110 (tmp = file.add("Vretrace start trap off")).addActionListener(new ActionListener() {
111 public void actionPerformed(ActionEvent e)
113 vPluginManager.invokeExternalCommand("trap-vretrace-start-off", null);
116 tmp.setAccelerator(KeyStroke.getKeyStroke("4"));
118 (tmp = file.add("Start")).addActionListener(new ActionListener() {
119 public void actionPerformed(ActionEvent e)
121 vPluginManager.invokeExternalCommand("pc-start", null);
124 tmp.setAccelerator(KeyStroke.getKeyStroke("5"));
126 (tmp = file.add("Stop")).addActionListener(new ActionListener() {
127 public void actionPerformed(ActionEvent e)
129 vPluginManager.invokeExternalCommand("pc-stop", null);
132 tmp.setAccelerator(KeyStroke.getKeyStroke("6"));
134 (tmp = file.add("Send <Left> Edge")).addActionListener(new ActionListener() {
135 public void actionPerformed(ActionEvent e)
137 try {
138 keyboard.sendEdge(128 + 75);
139 } catch(Exception f) {
140 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
144 tmp.setAccelerator(KeyStroke.getKeyStroke("J"));
146 (tmp = file.add("Send <Down> Edge")).addActionListener(new ActionListener() {
147 public void actionPerformed(ActionEvent e)
149 try {
150 keyboard.sendEdge(128 + 80);
151 } catch(Exception f) {
152 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
156 tmp.setAccelerator(KeyStroke.getKeyStroke("K"));
158 (tmp = file.add("Send <Right> Edge")).addActionListener(new ActionListener() {
159 public void actionPerformed(ActionEvent e)
161 try {
162 keyboard.sendEdge(128 + 77);
163 } catch(Exception f) {
164 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
168 tmp.setAccelerator(KeyStroke.getKeyStroke("L"));
170 (tmp = file.add("Send <Up> Edge")).addActionListener(new ActionListener() {
171 public void actionPerformed(ActionEvent e)
173 try {
174 keyboard.sendEdge(128 + 72);
175 } catch(Exception f) {
176 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
180 tmp.setAccelerator(KeyStroke.getKeyStroke("I"));
182 (tmp = file.add("Send <Enter> Edge")).addActionListener(new ActionListener() {
183 public void actionPerformed(ActionEvent e)
185 try {
186 keyboard.sendEdge(28);
187 } catch(Exception f) {
188 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
192 tmp.setAccelerator(KeyStroke.getKeyStroke("M"));
194 (tmp = file.add("Send <Escape> Edge")).addActionListener(new ActionListener() {
195 public void actionPerformed(ActionEvent e)
197 try {
198 keyboard.sendEdge(1);
199 } catch(Exception f) {
200 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
204 tmp.setAccelerator(KeyStroke.getKeyStroke("N"));
206 (tmp = file.add("Send <RShift> Edge")).addActionListener(new ActionListener() {
207 public void actionPerformed(ActionEvent e)
209 try {
210 keyboard.sendEdge(54);
211 } catch(Exception f) {
212 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
216 tmp.setAccelerator(KeyStroke.getKeyStroke("B"));
218 (tmp = file.add("Send <RCTRL> Edge")).addActionListener(new ActionListener() {
219 public void actionPerformed(ActionEvent e)
221 try {
222 keyboard.sendEdge(128 + 29);
223 } catch(Exception f) {
224 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
228 tmp.setAccelerator(KeyStroke.getKeyStroke("V"));
230 (tmp = file.add("Send <RALT> Edge")).addActionListener(new ActionListener() {
231 public void actionPerformed(ActionEvent e)
233 try {
234 keyboard.sendEdge(128 + 56);
235 } catch(Exception f) {
236 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
240 tmp.setAccelerator(KeyStroke.getKeyStroke("C"));
242 (tmp = file.add("Send <SPACE> Edge")).addActionListener(new ActionListener() {
243 public void actionPerformed(ActionEvent e)
245 try {
246 keyboard.sendEdge(57);
247 } catch(Exception f) {
248 errorDialog(f, "Failed to send keyboard event", null, "Dismiss");
252 tmp.setAccelerator(KeyStroke.getKeyStroke("X"));
254 bar.add(file);
256 JMenu save = new JMenu("Save");
257 for(int i = 1; i <= 12; i++) {
258 final int i2 = i;
259 (tmp = save.add("Save slot #" + i)).addActionListener(new ActionListener() {
260 public void actionPerformed(ActionEvent e)
262 try {
263 vPluginManager.invokeExternalCommand("state-save", new String[]{"saveslot-" + i2 + ".jrsr"});
264 } catch(Exception f) {
265 errorDialog(f, "Failed to save state", null, "Dismiss");
269 tmp.setAccelerator(KeyStroke.getKeyStroke("F" + i));
271 (tmp = save.add("Load slot #" + i)).addActionListener(new ActionListener() {
272 public void actionPerformed(ActionEvent e)
274 try {
275 vPluginManager.invokeExternalCommand("state-load", new String[]{"saveslot-" + i2 + ".jrsr"});
276 } catch(Exception f) {
277 errorDialog(f, "Failed to load state", null, "Dismiss");
281 tmp.setAccelerator(KeyStroke.getKeyStroke("shift F" + i));
284 bar.add(save);
285 setJMenuBar(bar);
289 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
291 catch (AccessControlException e)
293 System.err.println("Error: Not able to add some components to frame: " + e.getMessage());
296 setBounds(150, 150, 720, 50);
297 validate();
298 setVisible(true);