Joystick should play nicely with oa+ca keys, also fixed smartport crash bug!

This commit is contained in:
Brendan Robert 2024-03-08 09:09:47 -06:00
parent d7bfb5e197
commit 58e43c468d
3 changed files with 15 additions and 12 deletions

View File

@ -302,13 +302,17 @@ public class Keyboard implements Reconfigurable {
e.consume(); e.consume();
} }
public static boolean isOpenApplePressed = false;
@InvokableAction(name = "Open Apple Key", alternatives = "OA", category = "Keyboard", notifyOnRelease = true, defaultKeyMapping = "Alt", consumeKeyEvent = false) @InvokableAction(name = "Open Apple Key", alternatives = "OA", category = "Keyboard", notifyOnRelease = true, defaultKeyMapping = "Alt", consumeKeyEvent = false)
public void openApple(boolean pressed) { public void openApple(boolean pressed) {
isOpenApplePressed = pressed;
SoftSwitches.PB0.getSwitch().setState(pressed); SoftSwitches.PB0.getSwitch().setState(pressed);
} }
public static boolean isClosedApplePressed = false;
@InvokableAction(name = "Closed Apple Key", alternatives = "CA", category = "Keyboard", notifyOnRelease = true, defaultKeyMapping = {"Shortcut","Meta","Command"}, consumeKeyEvent = false) @InvokableAction(name = "Closed Apple Key", alternatives = "CA", category = "Keyboard", notifyOnRelease = true, defaultKeyMapping = {"Shortcut","Meta","Command"}, consumeKeyEvent = false)
public void solidApple(boolean pressed) { public void solidApple(boolean pressed) {
isClosedApplePressed = pressed;
SoftSwitches.PB1.getSwitch().setState(pressed); SoftSwitches.PB1.getSwitch().setState(pressed);
} }

View File

@ -34,6 +34,7 @@ import jace.config.DynamicSelection;
import jace.config.InvokableAction; import jace.config.InvokableAction;
import jace.core.Computer; import jace.core.Computer;
import jace.core.Device; import jace.core.Device;
import jace.core.Keyboard;
import jace.core.RAMEvent; import jace.core.RAMEvent;
import jace.core.RAMListener; import jace.core.RAMListener;
import jace.state.Stateful; import jace.state.Stateful;
@ -329,6 +330,7 @@ public class Joystick extends Device {
String guid = GLFW.glfwGetJoystickGUID(controllerNumber); String guid = GLFW.glfwGetJoystickGUID(controllerNumber);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
POLLING_TIME = (end - start) / CALIBRATION_ITERATIONS + 1; POLLING_TIME = (end - start) / CALIBRATION_ITERATIONS + 1;
POLLING_TIME = Math.min(POLLING_TIME*2, 45);
lastPollTime = end; lastPollTime = end;
System.out.println("Calibrated polling time to " + POLLING_TIME + "ms for joystick " + guid); System.out.println("Calibrated polling time to " + POLLING_TIME + "ms for joystick " + guid);
} }
@ -362,8 +364,8 @@ public class Joystick extends Device {
b0 = button0 >=0 && button0 < buttons.capacity() ? buttons.get(button0) : 0; b0 = button0 >=0 && button0 < buttons.capacity() ? buttons.get(button0) : 0;
b1 = button1 >=0 && button1 < buttons.capacity() ? buttons.get(button1) : 0; b1 = button1 >=0 && button1 < buttons.capacity() ? buttons.get(button1) : 0;
} }
SoftSwitches.PB0.getSwitch().setState(b0 != 0); SoftSwitches.PB0.getSwitch().setState(b0 != 0 || Keyboard.isOpenApplePressed);
SoftSwitches.PB1.getSwitch().setState(b1 != 0); SoftSwitches.PB1.getSwitch().setState(b1 != 0 || Keyboard.isClosedApplePressed);
} }
} }
@ -381,7 +383,6 @@ public class Joystick extends Device {
@Override @Override
public void tick() { public void tick() {
ticksSinceLastRead++;
boolean finished = true; boolean finished = true;
if (x > 0) { if (x > 0) {
if (--x == 0) { if (--x == 0) {
@ -398,9 +399,8 @@ public class Joystick extends Device {
} }
} }
if (selectedPhysicalController()) { if (selectedPhysicalController()) {
if (finished && ticksSinceLastRead >= 1000000) { ticksSinceLastRead++;
setRun(false); if (ticksSinceLastRead % 1000 == 0) {
} else if (ticksSinceLastRead > 1000 && ticksSinceLastRead % 1000 == 0) {
readButtons(); readButtons();
} }
} else if (finished) { } else if (finished) {

View File

@ -58,9 +58,8 @@ public abstract class SmartportDriver {
boolean extendedCall = command >= 0x040; boolean extendedCall = command >= 0x040;
// command &= 0x0f; // command &= 0x0f;
// Modify stack so that RTS goes to the right place after the smartport device call // Modify stack so that RTS goes to the right place after the smartport device call
//cpu.pushWord(callAddress + (extendedCall ? 5 : 3));
// Kludge due to the CPU not getting the faked RTS opcode // Kludge due to the CPU not getting the faked RTS opcode
cpu.setProgramCounter(callAddress + (extendedCall ? 5 : 3)); cpu.setProgramCounter(callAddress + (extendedCall ? 4 : 2));
// Calculate parameter address block // Calculate parameter address block
int parmAddr; int parmAddr;
@ -73,15 +72,15 @@ public abstract class SmartportDriver {
parmAddr = parmAddrHi << 16 | parmAddrLo; parmAddr = parmAddrHi << 16 | parmAddrLo;
} }
// Now process command // Now process command
System.out.println("Received command " + command + " with address block " + Integer.toHexString(parmAddr)); // System.out.println(String.format("Received %s command %d with address block %s", (extendedCall ? "extended" : "normal"), command, Integer.toHexString(parmAddr)));
// byte numParms = ram.readRaw(parmAddr); // byte numParms = ram.readRaw(parmAddr);
int[] params = new int[16]; int[] params = new int[16];
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
int value = 0x0ff & ram.readRaw(parmAddr + i); int value = 0x0ff & ram.readRaw(parmAddr + i);
params[i] = value; params[i] = value;
System.out.print(Integer.toHexString(value) + " "); // System.out.print(Integer.toHexString(value) + " ");
} }
System.out.println(); // System.out.println();
int unitNumber = params[1]; int unitNumber = params[1];
if (!changeUnit(unitNumber)) { if (!changeUnit(unitNumber)) {
System.out.println("Invalid unit: "+unitNumber); System.out.println("Invalid unit: "+unitNumber);
@ -96,8 +95,8 @@ public abstract class SmartportDriver {
case 1: //Read Block case 1: //Read Block
int blockNum = params[4] | (params[5] << 8) | (params[6] << 16); int blockNum = params[4] | (params[5] << 8) | (params[6] << 16);
read(blockNum, dataBuffer); read(blockNum, dataBuffer);
// System.out.println("reading "+blockNum+" to $"+Integer.toHexString(dataBuffer));
return ERROR_CODE.NO_ERROR; return ERROR_CODE.NO_ERROR;
// System.out.println("reading "+blockNum+" to $"+Integer.toHexString(dataBuffer));
case 2: //Write Block case 2: //Write Block
blockNum = params[4] | (params[5] << 8) | (params[6] << 16); blockNum = params[4] | (params[5] << 8) | (params[6] << 16);
write(blockNum, dataBuffer); write(blockNum, dataBuffer);