Skip to content

Commit c253bf1

Browse files
authored
Joystick implementation (#163)
* Add new routines to query game devices and poll from them. Implement comparator to joystick voltages. Fix reversed controls, add CA2 auto-transition when bit 4 is zero. Add ability to set joystick via config file * Clarify README for joystick usage and JDK and JRE selection.
1 parent d539265 commit c253bf1

File tree

12 files changed

+604
-40
lines changed

12 files changed

+604
-40
lines changed

README.md

Lines changed: 142 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@
99

1010
1. [What Is It?](#what-is-it)
1111
2. [License](#license)
12-
3. [Compiling](#compiling)
13-
4. [Running](#running)
12+
3. [Requirements](#requirements)
13+
1. [Linux](#linux)
14+
2. [Windows](#windows)
15+
4. [Compiling From Source](#compiling-from-source)
16+
5. [Running](#running)
1417
1. [Specifying a System ROM](#specifying-a-system-rom)
1518
2. [Trace Mode](#trace-mode)
16-
5. [Cassette Tapes](#cassette-tapes)
19+
6. [Cassette Tapes](#cassette-tapes)
1720
1. [Reading](#reading)
1821
2. [Writing](#writing)
19-
6. [Disk Drives](#disk-drives)
22+
7. [Disk Drives](#disk-drives)
2023
1. [Loading a Disk Image](#loading-a-disk-image)
2124
2. [Saving a Disk Image](#saving-a-disk-image)
22-
7. [Configuration File](#configuration-file)
23-
8. [Keyboard](#keyboard)
25+
8. [Joysticks](#joysticks)
26+
9. [Configuration File](#configuration-file)
27+
10. [Keyboard](#keyboard)
2428
1. [Emulated Keyboard](#emulated-keyboard)
2529
2. [Pass-through Keyboard](#pass-through-keyboard)
26-
9. [Current Status](#current-status)
30+
11. [Current Status](#current-status)
2731

2832
## What Is It?
2933

@@ -53,36 +57,129 @@ Third Party Licenses and Attributions below for more information on those
5357
software components.
5458

5559

56-
## Compiling
60+
## Requirements
5761

58-
You will need a copy of the Java Development Kit (JDK) version 8 or greater
59-
installed in to compile the JAR file. I strongly recommend using an open-source
60-
licensed JDK build (GPL v2 with Classpath Exception), available at
61-
[https://adoptopenjdk.net](https://adoptopenjdk.net) and install OpenJDK 8 or
62-
OpenJDK 11.
62+
The project needs several different packages installed in order to run the
63+
emulator properly. Please see the platform specific steps below for
64+
more information.
6365

64-
To build the project, switch to the root of the source directory, and type:
66+
### Linux
67+
68+
At a minimum, you will need to install the Java Runtime Environment (JRE) 17 or
69+
higher. Additionally, if you wish to use joysticks, you will need to install the
70+
`libjinput` API bindings, add your username to the `group` file, as well as fix a
71+
potential API binding bug.
72+
73+
1. *Required* - a Java Runtime Environment (JRE) version 17 or higher. The simplest way to
74+
do this is to install OpenJDK 17 or higher. On Ubuntu or Debian systems, this can
75+
be done with :
6576

77+
```bash
78+
sudo apt update
79+
sudo apt install openjdk-17-jre
80+
```
81+
82+
2. *Optional* - for proper joystick support you will need to install the `jinput` joystick
83+
library API on the system with:
84+
85+
```bash
86+
sudo apt install libjinput-java libjinput-jni
87+
```
88+
89+
Once installed, you may need to correct a missing file problem with the `libjinput-jni`
90+
installation. The emulator dependencies require a shared object file called
91+
`libjinput-linux64.so` to be present in the `/usr/lib/jni` directory. However, the
92+
`libjinput-jni` package may only install a file called `libjinput.so`. The
93+
solution is to create a symbolic link from `libjinput.so` to `linjinput-linux64.so`.
94+
First, check to see if the `libjinput-linux64.so` file already exists with:
95+
96+
```bash
97+
ls -l /usr/lib/jni
98+
```
99+
100+
If the `libjinput-linux64.so` file is *NOT* listed, you will need to create a symbolic
101+
link with the following command:
102+
103+
```bash
104+
sudo ln -s /usr/lib/jni/libjinput.so /usr/lib/jni/libjinput-linux64.so
105+
```
106+
107+
Finally, you will need to add yourself to the `input` group so that the emulator can read
108+
joystick information:
109+
110+
```bash
111+
sudo usermod -a -G input <your username>
112+
```
113+
114+
You will need to end your current session and restart in order for the group information
115+
to be updated. In some cases, you may need to reboot for the group change to take effect.
116+
117+
To run the emulator, see the section called [Running](#running) below.
118+
119+
### Windows
120+
121+
At a minimum, you will need to install the Java Runtime Environment (JRE) 17 or
122+
higher.
123+
124+
1. *Required* - a Java Runtime Environment (JRE) version 17 or higher. I recommend using
125+
Eclipse Temurin JRE (formerly AdoptJDK) as the software
126+
is licensed under the GNU license version 2 with classpath exception. The latest
127+
JRE builds are available at [https://adoptium.net/en-GB/temurin/releases](https://adoptium.net/en-GB/temurin/releases)
128+
(make sure you select _JRE_ as the type you wish to download). Run the installer
129+
and follow the directions as required to install the runtime.
130+
131+
To run the emulator, see the section called [Running](#running) below.
132+
133+
## Compiling From Source
134+
135+
_Note this section is optional - this is only if you want to compile the project
136+
yourself from source code._ If you want to build the emulator from source code,
137+
you will need a copy of the Java Development Kit (JDK) version 17 or greater
138+
installed in to compile the JAR file.
139+
140+
### Linux
141+
142+
For most Linux distributions there is likely an `openjdk-17-jdk` package that will do
143+
this for you automatically. On Ubuntu and Debian based systems, this is typically:
144+
145+
```bash
146+
sudo apt update
147+
sudo apt install openjdk-17-jdk
148+
```
149+
150+
Next, to build the project, switch to the root of the source directory, and type:
151+
66152
```bash
67153
./gradlew build
68154
```
69155

70-
On Windows, switch to the root of the source directory, and type:
156+
The compiled Jar file will be placed in the `build/libs` directory. Note that
157+
for some components such as joystick detection and control to work correctly,
158+
operating-specific steps may be required. See the _Requirements_ section above
159+
to install necessary sub-systems.
160+
161+
162+
### Windows
163+
164+
For Windows, I recommend using Eclipse Temurin JDK (formerly AdoptJDK) as the software
165+
is licensed under the GNU license version 2 with classpath exception. The latest
166+
JDK builds are available at [https://adoptium.net/en-GB/temurin/releases](https://adoptium.net/en-GB/temurin/releases)
167+
(make sure you select _JDK_ as the type you wish to download).
168+
169+
Next, switch to the root of the source directory, and type:
71170

72171
```bash
73172
gradlew.bat build
74173
```
75174

76-
The compiled Jar file will be placed in the `build/libs` directory.
175+
The compiled Jar file will be placed in the `build/libs` directory. Note that
176+
for some components such as joystick detection and control to work correctly,
177+
operating-specific steps may be required. See the _Requirements_ section above
178+
to install necessary sub-systems.
77179

78180

79181
## Running
80182

81-
For the emulator to run, you will need to have the Java 8 Runtime Environment (JRE)
82-
installed on your computer. See [Oracle's Java SE Runtime Environment Download](https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
83-
page for more information on installing the JRE. Alternatively, you can
84-
use [OpenJDK](https://openjdk.java.net/install/).
85-
86183
Simply double-clicking the jar file will start the emulator running. By
87184
default, the emulator will be in paused mode until you attach a system
88185
ROM to it. You can do so by clicking *ROM*, *Load System ROM*. You can
@@ -192,6 +289,22 @@ select a location on your computer where the disk file will be saved to.
192289
Once entered, the contents of the drive will be saved to the virtual disk
193290
file, and can be loaded from the host computer in a future session.
194291

292+
## Joysticks
293+
294+
Joystick control is still experimental and only currently available under
295+
Linux. When running the emulator, to set the joystick to be used,
296+
click on *Joystick* and then *Left Joystick* or *Right Joystick* to select
297+
which device should be used as the left or right joystick. If no USB
298+
joystick devices are found, then *No joystick* will be the only option
299+
available.
300+
301+
To troubleshoot joystick configuration, when the emulator starts, a
302+
list of detected joysticks will be printed to the console. The
303+
`Joystick #0` device will always be `No Joystick`. Other enumerated
304+
joysticks will be printed after this one. The name of the detected joystick
305+
can be used in the configuration file below to automatically associate
306+
the left or right joystick device during emulator startup.
307+
195308

196309
## Configuration File
197310

@@ -205,19 +318,22 @@ Super Extended Color Basic ROM file).
205318
Megabug).
206319
* `cassetteROM` - the full path to the ROM file used in the cassette recorder.
207320
* `drive0Image` - the `DSK` image to be used in drive 0.
208-
* `drive1Image` - the `DSK` image to be used in drive 0.
209-
* `drive2Image` - the `DSK` image to be used in drive 0.
210-
* `drive3Image` - the `DSK` image to be used in drive 0.
321+
* `drive1Image` - the `DSK` image to be used in drive 1.
322+
* `drive2Image` - the `DSK` image to be used in drive 2.
323+
* `drive3Image` - the `DSK` image to be used in drive 3.
324+
* `leftJoystick` - the name of the detected joystick to use as the left joystick.
325+
* `rightJoystick` - the name of the detected joystick to use as the right joystick.
211326

212327
Leaving any one of the keys out will result in the emulator ignoring that particular
213-
ROM image. An example YAML configuration file that specifies ROMs to use for the
214-
system, cartridge slot, cassette, and drive 0 is as follows:
328+
configuration option. An example YAML configuration file that specifies ROMs to use for the
329+
system, cartridge slot, cassette, joystick, and drive 0 is as follows:
215330

216331
```
217332
systemROM: "C:\Users\basic3.rom"
218333
cartridgeROM: "C:\disk11.rom"
219334
cassetteROM: "C:\Users\zaxxon.cas"
220335
drive0Image: "C:\megabug.dsk"
336+
leftJoystick: "usb gamepad"
221337
```
222338

223339
If you start the emulator without command-line arguments, it will look for a configuration file named

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ dependencies {
3232
implementation 'org.apache.commons:commons-lang3:3.20.0'
3333
implementation 'com.beust:jcommander:1.82'
3434
implementation 'org.yaml:snakeyaml:2.5'
35+
implementation 'net.java.jinput:jinput:2.0.10'
36+
runtimeOnly 'net.java.jinput:jinput-platform:2.0.7:natives-linux'
37+
implementation 'net.java.jutils:jutils:1.0.0'
3538
testImplementation 'junit:junit:4.13.2'
3639
testImplementation 'org.mockito:mockito-core:5.21.0'
3740
}

0 commit comments

Comments
 (0)