2 JPC-RR: A x86 PC Hardware Emulator
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
.luaextensions
;
34 import org
.jpc
.modules
.Joystick
;
35 import org
.jpc
.emulator
.peripheral
.Keyboard
;
37 import org
.jpc
.plugins
.LuaPlugin
;
39 //Locking this class is used for preventing termination and when terminating.
40 public class InputDevices
extends LuaPlugin
.LuaResource
46 private InputDevices(LuaPlugin plugin
)
51 public static int luaCB_keypressed(Lua l
, LuaPlugin plugin
)
53 if(l
.type(1) != Lua
.TNUMBER
) {
54 l
.error("Unexpected types to keypressed");
57 Keyboard key
= (Keyboard
)plugin
.getComponent(Keyboard
.class);
59 l
.pushBoolean(key
.getKeyExecStatus((byte)l
.checkNumber(1)));
65 public static int luaCB_keypressed_edge(Lua l
, LuaPlugin plugin
)
67 if(l
.type(1) != Lua
.TNUMBER
) {
68 l
.error("Unexpected types to keypressed");
71 Keyboard key
= (Keyboard
)plugin
.getComponent(Keyboard
.class);
73 l
.pushBoolean(key
.getKeyStatus((byte)l
.checkNumber(1)));
79 public static int luaCB_keyboard_leds(Lua l
, LuaPlugin plugin
)
81 Keyboard key
= (Keyboard
)plugin
.getComponent(Keyboard
.class);
83 int status
= key
.getLEDStatus();
88 l
.pushBoolean((status
& 2) != 0);
89 l
.pushBoolean((status
& 4) != 0);
90 l
.pushBoolean((status
& 1) != 0);
99 public static int luaCB_joystick_state(Lua l
, LuaPlugin plugin
)
101 Joystick joy
= (Joystick
)plugin
.getComponent(Joystick
.class);
104 l
.push(new Double(joy
.axisHoldTime(0, false)));
105 l
.push(new Double(joy
.axisHoldTime(1, false)));
106 l
.push(new Double(joy
.axisHoldTime(2, false)));
107 l
.push(new Double(joy
.axisHoldTime(3, false)));
108 l
.pushBoolean(joy
.buttonState(0, false));
109 l
.pushBoolean(joy
.buttonState(1, false));
110 l
.pushBoolean(joy
.buttonState(2, false));
111 l
.pushBoolean(joy
.buttonState(3, false));
119 public static int luaCB_mouse_state(Lua l
, LuaPlugin plugin
)
121 Keyboard kbd
= (Keyboard
)plugin
.getComponent(Keyboard
.class);
123 l
.push(new Double(kbd
.getMouseXPendingMotion()));
124 l
.push(new Double(kbd
.getMouseYPendingMotion()));
125 l
.push(new Double(kbd
.getMouseZPendingMotion()));
126 int b
= kbd
.getMouseButtonStatus();
127 l
.pushBoolean((b
& 1) != 0);
128 l
.pushBoolean((b
& 2) != 0);
129 l
.pushBoolean((b
& 4) != 0);
130 l
.pushBoolean((b
& 8) != 0);
131 l
.pushBoolean((b
& 16) != 0);