Skip to content

Commit c9a0b96

Browse files
committed
Some initial work towards implementing the RESTORE key.
1 parent 61ab4d7 commit c9a0b96

8 files changed

Lines changed: 51 additions & 32 deletions

File tree

core/src/main/java/emu/jvic/KeyboardMatrix.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
*/
2020
public abstract class KeyboardMatrix extends InputAdapter {
2121

22+
// The keyboard matrix data array is of size 513, in both desktop and html versions,
23+
// so all index values must be below this. 0-255 is reversed for the normal keys,
24+
// whereas the joystick keys and special keys (such as restore) use values above 255.
2225
public static final int SHIFT_LOCK = 511;
2326
public static final int RUN_STOP = 510;
2427
public static final int RESTORE = 509;
28+
2529
public static final int JOYSTICK = 256;
2630

2731
/**
@@ -110,17 +114,14 @@ public abstract class KeyboardMatrix extends InputAdapter {
110114
{ VicKeys.JOYSTICK_SE, JOYSTICK, 0x88 }, // SE
111115
{ VicKeys.JOYSTICK_NW, JOYSTICK, 0x14 }, // NW
112116
{ VicKeys.JOYSTICK_NE, JOYSTICK, 0x84 }, // NE
117+
118+
{ VicKeys.RESTORE, RESTORE, 0x01 },
113119
};
114120

115121
/**
116122
* Whether the SHIFT LOCK is currently on or not (this is a toggle).
117123
*/
118124
private boolean shiftLockOn;
119-
120-
/**
121-
* Whether the RESTORE key is currently down or not.
122-
*/
123-
private boolean restoreDown;
124125

125126
/**
126127
* The ALT key is not directly mapped to the VIC keyboard, as there is no corresponding
@@ -221,9 +222,6 @@ public void vicKeyDown(int vicKey) {
221222
setKeyMatrixRow(8, getKeyMatrixRow(8) & ~2);
222223
}
223224
break;
224-
case RESTORE:
225-
restoreDown = true;
226-
break;
227225
default:
228226
break;
229227
}
@@ -266,11 +264,6 @@ public void vicKeyUp(int vicKey) {
266264
if (keyDetails != null) {
267265
int currentRowValue = getKeyMatrixRow(keyDetails[1]);
268266
setKeyMatrixRow(keyDetails[1], currentRowValue & ~keyDetails[2]);
269-
} else {
270-
// Special keycodes.
271-
if (vicKey == RESTORE) {
272-
restoreDown = false;
273-
}
274267
}
275268

276269
// If SHIFT LOCK is on, we override the left shift key.

core/src/main/java/emu/jvic/KeyboardType.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package emu.jvic;
22

3-
import com.badlogic.gdx.Input.Keys;
43
import com.badlogic.gdx.graphics.Texture;
54

65
import emu.jvic.ui.ViewportManager;
76

8-
import static emu.jvic.KeyboardMatrix.RESTORE;
9-
import static emu.jvic.KeyboardMatrix.RUN_STOP;
10-
import static emu.jvic.KeyboardMatrix.SHIFT_LOCK;
11-
127
/**
138
* Enum representing the different types of keyboard available within JVic.
149
*
@@ -19,8 +14,8 @@ public enum KeyboardType {
1914
LANDSCAPE(
2015
new Integer[][] {
2116
{ VicKeys.LEFT_ARROW, VicKeys.LEFT_ARROW, VicKeys.ONE, VicKeys.ONE, VicKeys.TWO, VicKeys.TWO, VicKeys.THREE, VicKeys.THREE, VicKeys.FOUR, VicKeys.FOUR, VicKeys.FIVE, VicKeys.FIVE, VicKeys.SIX, VicKeys.SIX, VicKeys.SEVEN, VicKeys.SEVEN, VicKeys.EIGHT, VicKeys.EIGHT, VicKeys.NINE, VicKeys.NINE, VicKeys.ZERO, VicKeys.ZERO, VicKeys.PLUS, VicKeys.PLUS, VicKeys.HYPHEN, VicKeys.HYPHEN, VicKeys.POUND, VicKeys.POUND, VicKeys.HOME, VicKeys.HOME, VicKeys.DELETE, VicKeys.DELETE },
22-
{ VicKeys.CONTROL, VicKeys.CONTROL, VicKeys.CONTROL, VicKeys.Q, VicKeys.Q, VicKeys.W, VicKeys.W, VicKeys.E, VicKeys.E, VicKeys.R, VicKeys.R, VicKeys.T, VicKeys.T, VicKeys.Y, VicKeys.Y, VicKeys.U, VicKeys.U, VicKeys.I, VicKeys.I, VicKeys.O, VicKeys.O, VicKeys.P, VicKeys.P, VicKeys.AT, VicKeys.AT, VicKeys.ASTERISK, VicKeys.ASTERISK, VicKeys.UP_ARROW, VicKeys.UP_ARROW, RESTORE, RESTORE, RESTORE },
23-
{ VicKeys.RUN_STOP, VicKeys.RUN_STOP, SHIFT_LOCK, SHIFT_LOCK, VicKeys.A, VicKeys.A, VicKeys.S, VicKeys.S, VicKeys.D, VicKeys.D, VicKeys.F, VicKeys.F, VicKeys.G, VicKeys.G, VicKeys.H, VicKeys.H, VicKeys.J, VicKeys.J, VicKeys.K, VicKeys.K, VicKeys.L, VicKeys.L, VicKeys.COLON, VicKeys.COLON, VicKeys.SEMI_COLON, VicKeys.SEMI_COLON, VicKeys.EQUALS, VicKeys.EQUALS, VicKeys.RETURN, VicKeys.RETURN, VicKeys.RETURN, VicKeys.RETURN },
17+
{ VicKeys.CONTROL, VicKeys.CONTROL, VicKeys.CONTROL, VicKeys.Q, VicKeys.Q, VicKeys.W, VicKeys.W, VicKeys.E, VicKeys.E, VicKeys.R, VicKeys.R, VicKeys.T, VicKeys.T, VicKeys.Y, VicKeys.Y, VicKeys.U, VicKeys.U, VicKeys.I, VicKeys.I, VicKeys.O, VicKeys.O, VicKeys.P, VicKeys.P, VicKeys.AT, VicKeys.AT, VicKeys.ASTERISK, VicKeys.ASTERISK, VicKeys.UP_ARROW, VicKeys.UP_ARROW, VicKeys.RESTORE, VicKeys.RESTORE, VicKeys.RESTORE },
18+
{ VicKeys.RUN_STOP, VicKeys.RUN_STOP, VicKeys.SHIFT_LOCK, VicKeys.SHIFT_LOCK, VicKeys.A, VicKeys.A, VicKeys.S, VicKeys.S, VicKeys.D, VicKeys.D, VicKeys.F, VicKeys.F, VicKeys.G, VicKeys.G, VicKeys.H, VicKeys.H, VicKeys.J, VicKeys.J, VicKeys.K, VicKeys.K, VicKeys.L, VicKeys.L, VicKeys.COLON, VicKeys.COLON, VicKeys.SEMI_COLON, VicKeys.SEMI_COLON, VicKeys.EQUALS, VicKeys.EQUALS, VicKeys.RETURN, VicKeys.RETURN, VicKeys.RETURN, VicKeys.RETURN },
2419
{ VicKeys.CBM, VicKeys.CBM, VicKeys.LEFT_SHIFT, VicKeys.LEFT_SHIFT, VicKeys.LEFT_SHIFT, VicKeys.Z, VicKeys.Z, VicKeys.X, VicKeys.X, VicKeys.C, VicKeys.C, VicKeys.V, VicKeys.V, VicKeys.B, VicKeys.B, VicKeys.N, VicKeys.N, VicKeys.M, VicKeys.M, VicKeys.COMMA, VicKeys.COMMA, VicKeys.PERIOD, VicKeys.PERIOD, VicKeys.FORWARD_SLASH, VicKeys.FORWARD_SLASH, VicKeys.RIGHT_SHIFT, VicKeys.RIGHT_SHIFT, VicKeys.RIGHT_SHIFT, VicKeys.CURSOR_DOWN, VicKeys.CURSOR_DOWN, VicKeys.CURSOR_RIGHT, VicKeys.CURSOR_RIGHT },
2520
{ VicKeys.F1, VicKeys.F1, VicKeys.F1, VicKeys.F3, VicKeys.F3, VicKeys.F3, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.F5, VicKeys.F5, VicKeys.F5, VicKeys.F7, VicKeys.F7, VicKeys.F7 }
2621
},
@@ -34,12 +29,12 @@ public enum KeyboardType {
3429
PORTRAIT(
3530
new Integer[][] {
3631
{ VicKeys.CONTROL, VicKeys.LEFT_ARROW, VicKeys.UP_ARROW, VicKeys.F1, VicKeys.F3, VicKeys.F5, VicKeys.F7, VicKeys.POUND, VicKeys.HOME, VicKeys.DELETE },
37-
{ VicKeys.COLON, VicKeys.SEMI_COLON, VicKeys.EQUALS, VicKeys.AT, VicKeys.PLUS, VicKeys.HYPHEN, VicKeys.ASTERISK, VicKeys.FORWARD_SLASH, VicKeys.RUN_STOP, RESTORE },
32+
{ VicKeys.COLON, VicKeys.SEMI_COLON, VicKeys.EQUALS, VicKeys.AT, VicKeys.PLUS, VicKeys.HYPHEN, VicKeys.ASTERISK, VicKeys.FORWARD_SLASH, VicKeys.RUN_STOP, VicKeys.RESTORE },
3833
{ VicKeys.ONE, VicKeys.TWO, VicKeys.THREE, VicKeys.FOUR, VicKeys.FIVE, VicKeys.SIX, VicKeys.SEVEN, VicKeys.EIGHT, VicKeys.NINE, VicKeys.ZERO },
3934
{ VicKeys.Q, VicKeys.W, VicKeys.E, VicKeys.R, VicKeys.T, VicKeys.Y, VicKeys.U, VicKeys.I, VicKeys.O, VicKeys.P },
4035
{ VicKeys.A, VicKeys.S, VicKeys.D, VicKeys.F, VicKeys.G, VicKeys.H, VicKeys.J, VicKeys.K, VicKeys.L, VicKeys.RETURN },
4136
{ VicKeys.Z, VicKeys.X, VicKeys.C, VicKeys.V, VicKeys.B, VicKeys.N, VicKeys.M, VicKeys.COMMA, VicKeys.PERIOD, VicKeys.RETURN },
42-
{ VicKeys.CBM, SHIFT_LOCK, VicKeys.LEFT_SHIFT, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.RIGHT_SHIFT, VicKeys.CURSOR_DOWN, VicKeys.CURSOR_RIGHT }
37+
{ VicKeys.CBM, VicKeys.SHIFT_LOCK, VicKeys.LEFT_SHIFT, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.SPACE, VicKeys.RIGHT_SHIFT, VicKeys.CURSOR_DOWN, VicKeys.CURSOR_RIGHT }
4338
},
4439
"png/keyboard_portrait_10x7.png",
4540
1.0f,

core/src/main/java/emu/jvic/Machine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Callable<Queue<char[]>> init(
144144
c1541Drive = new C1541Drive(serialBus, dos1541Rom);
145145

146146
// Create two instances of the VIA chip; one for VIA1 and one for VIA2.
147-
via1 = new Via1(cpu, joystick, serialBus, snapshot);
147+
via1 = new Via1(cpu, keyboard, joystick, serialBus, snapshot);
148148
via2 = new Via2(cpu, keyboard, joystick, serialBus, snapshot);
149149

150150
// Now we create the memory, which will include mapping the VIC chip,

core/src/main/java/emu/jvic/VicKeys.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public interface VicKeys {
9595
public static final int LEFT_ARROW = 63;
9696
public static final int ONE = 64;
9797

98+
// Special keys.
99+
public static final int RESTORE = 88;
100+
public static final int SHIFT_LOCK = 89;
101+
98102
// Joystick keys.
99103
public static final int JOYSTICK_FIRE = 90;
100104
public static final int JOYSTICK_LEFT = 91;
@@ -237,6 +241,8 @@ public interface VicKeys {
237241
{ Keys.F7, VicKeys.F7 },
238242
{ Keys.F8, VicKeys.LEFT_SHIFT, VicKeys.F7 },
239243

244+
{ Keys.F12, VicKeys.RESTORE },
245+
240246
{ Keys.NUMPAD_0, VicKeys.JOYSTICK_FIRE }, // Fire button
241247
{ Keys.NUMPAD_1, VicKeys.JOYSTICK_SW }, // SW
242248
{ Keys.NUMPAD_2, VicKeys.JOYSTICK_DOWN }, // Down

core/src/main/java/emu/jvic/io/Keyboard.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,18 @@ public int scanKeyboardColumn(int selectedColumn) {
6868

6969
return ((~(rowData)) & 0xFF);
7070
}
71+
72+
/**
73+
* Gets the current restore key state.
74+
*
75+
* @return The current restore key state.
76+
*/
77+
public int getRestoreKeyState() {
78+
int restoreKeyState = keyboardMatrix.getKeyMatrixRow(KeyboardMatrix.RESTORE);
79+
// TODO: For some reason pressing the RESTORE key hangs the machine.
80+
//return (restoreKeyState & 0x01);
81+
return 0;
82+
}
83+
84+
private int currentRestoreState;
7185
}

core/src/main/java/emu/jvic/io/Via1.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class Via1 extends Via6522 {
1616
* The CPU that the VIC 20 is using. This is where VIA 1 IRQ signals will be sent.
1717
*/
1818
private Cpu6502 cpu6502;
19+
20+
/**
21+
* The Keyboard from which we get the current keyboard state from.
22+
*/
23+
private Keyboard keyboard;
1924

2025
/**
2126
* The Joystick from which we get the current joystick state from.
@@ -31,13 +36,15 @@ public class Via1 extends Via6522 {
3136
* Constructor for Via1.
3237
*
3338
* @param cpu6502 The CPU that the VIC 20 is using. This is where VIA 2 IRQ signals will be sent.
39+
* @param keyboard The Keyboard from which we get the current keyboard state from.
3440
* @param joystick The Joystick from which the Via gets the current joystick state from.
3541
* @param serialBus The SerialBus that VIA 1 is connected to for Data IN, Clock IN and Atn OUT.
3642
* @param snapshot Optional snapshot of the machine state to start with.
3743
*/
38-
public Via1(Cpu6502 cpu6502, Joystick joystick, SerialBus serialBus, Snapshot snapshot) {
44+
public Via1(Cpu6502 cpu6502, Keyboard keyboard, Joystick joystick, SerialBus serialBus, Snapshot snapshot) {
3945
super(false);
4046
this.cpu6502 = cpu6502;
47+
this.keyboard = keyboard;
4148
this.joystick = joystick;
4249
this.serialBus = serialBus;
4350
if (snapshot != null) {
@@ -149,4 +156,8 @@ protected void updateIrqPin(int pinState) {
149156
cpu6502.clearInterrupt(Cpu6502.S_NMI);
150157
}
151158
}
159+
160+
protected int getCa1() {
161+
return keyboard.getRestoreKeyState();
162+
}
152163
}

core/src/main/java/emu/jvic/io/Via6522.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,12 @@ public int getDataDirectionRegisterA() {
869869
}
870870

871871
// Template method for subclasses to provide new CA1 input. If not used, then never changes.
872-
public int getCa1() {
872+
protected int getCa1() {
873873
return ca1;
874874
}
875875

876876
// Template method for subclasses to provide new CB1 input. IF not used, then never changes.
877-
public int getCb1() {
877+
protected int getCb1() {
878878
return cb1;
879879
}
880880

core/src/main/java/emu/jvic/ui/MachineInputProcessor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ public boolean keyUp(int keycode) {
154154
case Keys.W:
155155
handleWarpSpeedToggle();
156156
return true;
157+
case Keys.Y:
158+
// Web version doesn't support screen shots... yet.
159+
if (!Gdx.app.getType().equals(ApplicationType.WebGL)) {
160+
machineScreen.saveScreenshot();
161+
}
162+
return true;
157163
case Keys.Z:
158164
rotateScreenSize();
159165
return true;
@@ -167,12 +173,6 @@ else if (keycode == Keys.F11) {
167173
handleFullScreenToggle();
168174
}
169175
}
170-
else if (keycode == Keys.F12) {
171-
// Web version doesn't support screen shots.
172-
if (!Gdx.app.getType().equals(ApplicationType.WebGL)) {
173-
machineScreen.saveScreenshot();
174-
}
175-
}
176176
return false;
177177
}
178178

0 commit comments

Comments
 (0)