mirror of
https://github.com/badvision/jace.git
synced 2025-08-07 15:26:14 +00:00
Moved Joystick enable flag to Apple2e computer class
This commit is contained in:
@@ -35,7 +35,6 @@ import jace.hardware.CardExt80Col;
|
|||||||
import jace.hardware.ConsoleProbe;
|
import jace.hardware.ConsoleProbe;
|
||||||
import jace.hardware.Joystick;
|
import jace.hardware.Joystick;
|
||||||
import jace.hardware.massStorage.CardMassStorage;
|
import jace.hardware.massStorage.CardMassStorage;
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -83,6 +82,11 @@ public class Apple2e extends Computer {
|
|||||||
public ClassSelection videoRenderer = new ClassSelection(Video.class, VideoNTSC.class);
|
public ClassSelection videoRenderer = new ClassSelection(Video.class, VideoNTSC.class);
|
||||||
@ConfigurableField(name = "Aux Ram", shortName = "ram", description = "Aux ram card")
|
@ConfigurableField(name = "Aux Ram", shortName = "ram", description = "Aux ram card")
|
||||||
public ClassSelection ramCard = new ClassSelection(RAM128k.class, CardExt80Col.class);
|
public ClassSelection ramCard = new ClassSelection(RAM128k.class, CardExt80Col.class);
|
||||||
|
@ConfigurableField(name = "Joystick 1 Enabled", shortName = "joy1", description = "If unchecked, then there is no joystick support.", enablesDevice = true)
|
||||||
|
public boolean joy1enabled = false;
|
||||||
|
@ConfigurableField(name = "Joystick 2 Enabled", shortName = "joy2", description = "If unchecked, then there is no joystick support.", enablesDevice = true)
|
||||||
|
public boolean joy2enabled = false;
|
||||||
|
|
||||||
public Joystick joystick1;
|
public Joystick joystick1;
|
||||||
public Joystick joystick2;
|
public Joystick joystick2;
|
||||||
@ConfigurableField(name = "Activate Cheats", shortName = "cheat", defaultValue = "")
|
@ConfigurableField(name = "Activate Cheats", shortName = "cheat", defaultValue = "")
|
||||||
@@ -96,9 +100,6 @@ public class Apple2e extends Computer {
|
|||||||
super();
|
super();
|
||||||
try {
|
try {
|
||||||
reconfigure();
|
reconfigure();
|
||||||
// Setup core resources
|
|
||||||
joystick1 = new Joystick(0, this);
|
|
||||||
joystick2 = new Joystick(1, this);
|
|
||||||
setCpu(new MOS65C02(this));
|
setCpu(new MOS65C02(this));
|
||||||
reinitMotherboard();
|
reinitMotherboard();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@@ -118,8 +119,6 @@ public class Apple2e extends Computer {
|
|||||||
}
|
}
|
||||||
motherboard = new Motherboard(this);
|
motherboard = new Motherboard(this);
|
||||||
motherboard.reconfigure();
|
motherboard.reconfigure();
|
||||||
motherboard.miscDevices.add(joystick1);
|
|
||||||
motherboard.miscDevices.add(joystick2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -193,7 +192,7 @@ public class Apple2e extends Computer {
|
|||||||
super.reconfigure();
|
super.reconfigure();
|
||||||
|
|
||||||
RAM128k currentMemory = (RAM128k) getMemory();
|
RAM128k currentMemory = (RAM128k) getMemory();
|
||||||
if (currentMemory != null && !(currentMemory.getClass().equals(ramCard.getValue()))) {
|
if (currentMemory != null && ramCard.getValue() != null && !(currentMemory.getClass().equals(ramCard.getValue()))) {
|
||||||
try {
|
try {
|
||||||
RAM128k newMemory = (RAM128k) ramCard.getValue().getConstructor(Computer.class).newInstance(this);
|
RAM128k newMemory = (RAM128k) ramCard.getValue().getConstructor(Computer.class).newInstance(this);
|
||||||
newMemory.copyFrom(currentMemory);
|
newMemory.copyFrom(currentMemory);
|
||||||
@@ -219,6 +218,28 @@ public class Apple2e extends Computer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentMemory.reconfigure();
|
currentMemory.reconfigure();
|
||||||
|
|
||||||
|
if (joy1enabled) {
|
||||||
|
if (joystick1 == null) {
|
||||||
|
joystick1 = new Joystick(0, this);
|
||||||
|
motherboard.miscDevices.add(joystick1);
|
||||||
|
}
|
||||||
|
} else if (joystick1 != null) {
|
||||||
|
joystick1.detach();
|
||||||
|
motherboard.miscDevices.remove(joystick1);
|
||||||
|
joystick1 = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (joy2enabled) {
|
||||||
|
if (joystick2 == null) {
|
||||||
|
joystick2 = new Joystick(1, this);
|
||||||
|
motherboard.miscDevices.add(joystick2);
|
||||||
|
}
|
||||||
|
} else if (joystick2 != null) {
|
||||||
|
joystick2.detach();
|
||||||
|
motherboard.miscDevices.remove(joystick2);
|
||||||
|
joystick2 = null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (useConsoleProbe) {
|
if (useConsoleProbe) {
|
||||||
@@ -234,7 +255,6 @@ public class Apple2e extends Computer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getVideo() == null || getVideo().getClass() != videoRenderer.getValue()) {
|
if (getVideo() == null || getVideo().getClass() != videoRenderer.getValue()) {
|
||||||
Graphics g = null;
|
|
||||||
if (getVideo() != null) {
|
if (getVideo() != null) {
|
||||||
getVideo().suspend();
|
getVideo().suspend();
|
||||||
}
|
}
|
||||||
|
@@ -42,14 +42,11 @@ import java.util.logging.Logger;
|
|||||||
* Actual joystick support isn't offered by Java at this moment in time
|
* Actual joystick support isn't offered by Java at this moment in time
|
||||||
* unfortunately.
|
* unfortunately.
|
||||||
*
|
*
|
||||||
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
||||||
*/
|
*/
|
||||||
@Stateful
|
@Stateful
|
||||||
public class Joystick extends Device {
|
public class Joystick extends Device {
|
||||||
|
@ConfigurableField(name = "Center Mouse", shortName = "center", description = "Moves mouse back to the center of the screen, can get annoying.")
|
||||||
@ConfigurableField(name = "Enabled", shortName = "enabled", description = "If unchecked, then there is no joystick support.")
|
|
||||||
public boolean enabled;
|
|
||||||
@ConfigurableField(name = "Center Mouse", shortName="center", description = "Moves mouse back to the center of the screen, can get annoying.")
|
|
||||||
public boolean centerMouse;
|
public boolean centerMouse;
|
||||||
@ConfigurableField(name = "Use keyboard", shortName = "useKeys", description = "Arrow keys will control joystick instead of the mouse.")
|
@ConfigurableField(name = "Use keyboard", shortName = "useKeys", description = "Arrow keys will control joystick instead of the mouse.")
|
||||||
public boolean useKeyboard;
|
public boolean useKeyboard;
|
||||||
@@ -185,14 +182,12 @@ public class Joystick extends Device {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reconfigure() {
|
public void reconfigure() {
|
||||||
|
removeListeners();
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
if (enabled) {
|
registerListeners();
|
||||||
registerListeners();
|
|
||||||
} else {
|
|
||||||
removeListeners();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RAMListener listener = new RAMListener(RAMEvent.TYPE.ANY, RAMEvent.SCOPE.RANGE, RAMEvent.VALUE.ANY) {
|
RAMListener listener = new RAMListener(RAMEvent.TYPE.ANY, RAMEvent.SCOPE.RANGE, RAMEvent.VALUE.ANY) {
|
||||||
@Override
|
@Override
|
||||||
protected void doConfig() {
|
protected void doConfig() {
|
||||||
@@ -215,33 +210,51 @@ public class Joystick extends Device {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@InvokableAction(name="Left", category = "joystick", defaultKeyMapping = "left", notifyOnRelease = true)
|
@InvokableAction(name = "Left", category = "joystick", defaultKeyMapping = "left", notifyOnRelease = true)
|
||||||
public boolean joystickLeft(boolean pressed) {
|
public boolean joystickLeft(boolean pressed) {
|
||||||
leftPressed = pressed;
|
leftPressed = pressed;
|
||||||
|
if (pressed) {
|
||||||
|
rightPressed = false;
|
||||||
|
}
|
||||||
return hogKeyboard;
|
return hogKeyboard;
|
||||||
};
|
}
|
||||||
@InvokableAction(name="Right", category = "joystick", defaultKeyMapping = "right", notifyOnRelease = true)
|
|
||||||
|
;
|
||||||
|
@InvokableAction(name = "Right", category = "joystick", defaultKeyMapping = "right", notifyOnRelease = true)
|
||||||
public boolean joystickRight(boolean pressed) {
|
public boolean joystickRight(boolean pressed) {
|
||||||
rightPressed = pressed;
|
rightPressed = pressed;
|
||||||
|
if (pressed) {
|
||||||
|
leftPressed = false;
|
||||||
|
}
|
||||||
return hogKeyboard;
|
return hogKeyboard;
|
||||||
};
|
}
|
||||||
@InvokableAction(name="Up", category = "joystick", defaultKeyMapping = "up", notifyOnRelease = true)
|
|
||||||
|
;
|
||||||
|
@InvokableAction(name = "Up", category = "joystick", defaultKeyMapping = "up", notifyOnRelease = true)
|
||||||
public boolean joystickUp(boolean pressed) {
|
public boolean joystickUp(boolean pressed) {
|
||||||
upPressed = pressed;
|
upPressed = pressed;
|
||||||
|
if (pressed) {
|
||||||
|
downPressed = false;
|
||||||
|
}
|
||||||
return hogKeyboard;
|
return hogKeyboard;
|
||||||
};
|
}
|
||||||
@InvokableAction(name="Down", category = "joystick", defaultKeyMapping = "down", notifyOnRelease = true)
|
|
||||||
|
;
|
||||||
|
@InvokableAction(name = "Down", category = "joystick", defaultKeyMapping = "down", notifyOnRelease = true)
|
||||||
public boolean joystickDown(boolean pressed) {
|
public boolean joystickDown(boolean pressed) {
|
||||||
leftPressed = pressed;
|
downPressed = pressed;
|
||||||
|
if (pressed) {
|
||||||
|
upPressed = false;
|
||||||
|
}
|
||||||
return hogKeyboard;
|
return hogKeyboard;
|
||||||
};
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
computer.getMemory().addListener(listener);
|
computer.getMemory().addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeListeners() {
|
private void removeListeners() {
|
||||||
computer.getMemory().removeListener(listener);
|
computer.getMemory().removeListener(listener);
|
||||||
Keyboard.unregisterAllHandlers(this);
|
Keyboard.unregisterAllHandlers(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user