Moved Joystick enable flag to Apple2e computer class

This commit is contained in:
Brendan Robert 2015-03-29 00:24:07 -05:00
parent b0272f7d6a
commit 6338b1789b
2 changed files with 63 additions and 30 deletions

View File

@ -35,7 +35,6 @@ import jace.hardware.CardExt80Col;
import jace.hardware.ConsoleProbe;
import jace.hardware.Joystick;
import jace.hardware.massStorage.CardMassStorage;
import java.awt.Graphics;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@ -83,6 +82,11 @@ public class Apple2e extends Computer {
public ClassSelection videoRenderer = new ClassSelection(Video.class, VideoNTSC.class);
@ConfigurableField(name = "Aux Ram", shortName = "ram", description = "Aux ram card")
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 joystick2;
@ConfigurableField(name = "Activate Cheats", shortName = "cheat", defaultValue = "")
@ -96,9 +100,6 @@ public class Apple2e extends Computer {
super();
try {
reconfigure();
// Setup core resources
joystick1 = new Joystick(0, this);
joystick2 = new Joystick(1, this);
setCpu(new MOS65C02(this));
reinitMotherboard();
} catch (Throwable t) {
@ -118,8 +119,6 @@ public class Apple2e extends Computer {
}
motherboard = new Motherboard(this);
motherboard.reconfigure();
motherboard.miscDevices.add(joystick1);
motherboard.miscDevices.add(joystick2);
}
@Override
@ -193,7 +192,7 @@ public class Apple2e extends Computer {
super.reconfigure();
RAM128k currentMemory = (RAM128k) getMemory();
if (currentMemory != null && !(currentMemory.getClass().equals(ramCard.getValue()))) {
if (currentMemory != null && ramCard.getValue() != null && !(currentMemory.getClass().equals(ramCard.getValue()))) {
try {
RAM128k newMemory = (RAM128k) ramCard.getValue().getConstructor(Computer.class).newInstance(this);
newMemory.copyFrom(currentMemory);
@ -219,6 +218,28 @@ public class Apple2e extends Computer {
}
}
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 {
if (useConsoleProbe) {
@ -234,7 +255,6 @@ public class Apple2e extends Computer {
}
if (getVideo() == null || getVideo().getClass() != videoRenderer.getValue()) {
Graphics g = null;
if (getVideo() != null) {
getVideo().suspend();
}

View File

@ -42,14 +42,11 @@ import java.util.logging.Logger;
* Actual joystick support isn't offered by Java at this moment in time
* unfortunately.
*
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
*/
@Stateful
public class Joystick extends Device {
@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.")
@ConfigurableField(name = "Center Mouse", shortName = "center", description = "Moves mouse back to the center of the screen, can get annoying.")
public boolean centerMouse;
@ConfigurableField(name = "Use keyboard", shortName = "useKeys", description = "Arrow keys will control joystick instead of the mouse.")
public boolean useKeyboard;
@ -185,14 +182,12 @@ public class Joystick extends Device {
@Override
public void reconfigure() {
removeListeners();
x = 0;
y = 0;
if (enabled) {
registerListeners();
} else {
removeListeners();
}
registerListeners();
}
RAMListener listener = new RAMListener(RAMEvent.TYPE.ANY, RAMEvent.SCOPE.RANGE, RAMEvent.VALUE.ANY) {
@Override
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) {
leftPressed = pressed;
if (pressed) {
rightPressed = false;
}
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) {
rightPressed = pressed;
if (pressed) {
leftPressed = false;
}
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) {
upPressed = pressed;
if (pressed) {
downPressed = false;
}
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) {
leftPressed = pressed;
downPressed = pressed;
if (pressed) {
upPressed = false;
}
return hogKeyboard;
};
}
private void registerListeners() {
computer.getMemory().addListener(listener);
}
private void removeListeners() {
computer.getMemory().removeListener(listener);
Keyboard.unregisterAllHandlers(this);
}
}
}