standardized key codes to get ready for gamepad support

This commit is contained in:
Steven Hugg 2019-06-07 09:45:30 -04:00
parent cdc04a9cd5
commit 271c2ea020
13 changed files with 188 additions and 158 deletions

View File

@ -254,18 +254,17 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
</div>
<div class="emucontrols-nes text-center small control-insns" style="display:none">
<span class="control-def"><span class="control-key">&#x2190;&#x2191;&#x2193;&#x2192;</span> Joypad</span>
<span class="control-def"><span class="control-key">X</span> Button A</span>
<span class="control-def"><span class="control-key">Z</span> Button B</span>
<span class="control-def"><span class="control-key small">Space</span> Select</span>
<span class="control-def"><span class="control-key small">Space</span> Button A</span>
<span class="control-def"><span class="control-key small">Ctrl</span> Button B</span>
<span class="control-def"><span class="control-key small">\</span> Select</span>
<span class="control-def"><span class="control-key small">Enter</span> Start</span>
</div>
<div class="emucontrols-vicdual emucontrols-galaxian text-center small control-insns" style="display:none">
<div class="emucontrols-vicdual emucontrols-galaxian emucontrols-vector text-center small control-insns" style="display:none">
<span class="control-def"><span class="control-key">&#x2190;&#x2191;&#x2193;&#x2192;</span> Joystick</span>
<span class="control-def"><span class="control-key small">Space</span> Button 1</span>
<span class="control-def"><span class="control-key small">Shift</span> Button 2</span>
<span class="control-def"><span class="control-key">1</span> 1p</span>
<span class="control-def"><span class="control-key">2</span> 2p</span>
<span class="control-def"><span class="control-key">5</span> Coin</span>
<span class="control-def"><span class="control-key small">Ctrl</span> Button 2</span>
<span class="control-def"><span class="control-key">\</span> Coin</span>
<span class="control-def"><span class="control-key small">Enter</span> Start</span>
</div>
<div class="emucontrols-mw8080bw text-center small control-insns" style="display:none">
<span class="control-def"><span class="control-key">&#x2190;&nbsp;&#x2192;</span> Joystick</span>

View File

@ -317,9 +317,38 @@ export function dumpRAM(ram:Uint8Array|number[], ramofs:number, ramlen:number) :
return s;
}
interface KeyDef {c:number, n:string};
interface KeyDef {
c:number, // key code
n:string, // name
// for gamepad
plyr?:number,
xaxis?:number,
yaxis?:number,
button?:number
};
export const Keys : {[keycode:string]:KeyDef} = {
// gamepad and keyboard (player 0)
UP: {c: 38, n: "Up", plyr:0, yaxis:-1},
DOWN: {c: 40, n: "Down", plyr:0, yaxis:1},
LEFT: {c: 37, n: "Left", plyr:0, xaxis:-1},
RIGHT: {c: 39, n: "Right", plyr:0, xaxis:1},
A: {c: 32, n: "Space", plyr:0, button:0},
B: {c: 17, n: "Ctrl", plyr:0, button:1},
GP_A: {c: 88, n: "X", plyr:0, button:0},
GP_B: {c: 90, n: "Z", plyr:0, button:1},
SELECT: {c: 220, n: "\\", plyr:0, button:8},
START: {c: 13, n: "Enter", plyr:0, button:9},
// gamepad and keyboard (player 1)
P2_UP: {c: 87, n: "W", plyr:1, yaxis:-1},
P2_DOWN: {c: 83, n: "S", plyr:1, yaxis:1},
P2_LEFT: {c: 65, n: "A", plyr:1, xaxis:-1},
P2_RIGHT: {c: 68, n: "D", plyr:1, xaxis:1},
P2_A: {c: 84, n: "T", plyr:1, button:0},
P2_B: {c: 82, n: "R", plyr:1, button:1},
P2_SELECT: {c: 70, n: "F", plyr:1, button:8},
P2_START: {c: 71, n: "G", plyr:1, button:9},
// keyboard only
VK_ESCAPE: {c: 27, n: "Esc"},
VK_F1: {c: 112, n: "F1"},
VK_F2: {c: 113, n: "F2"},
@ -454,7 +483,7 @@ export function setKeyboardFromMap(video, switches, map, func?) {
}
export function makeKeycodeMap(table : [KeyDef,number,number][]) {
var map = {};
var map = new Map();
for (var i=0; i<table.length; i++) {
var entry = table[i];
map[entry[0].c] = {index:entry[1], mask:entry[2]};

View File

@ -31,11 +31,11 @@ const ASTROCADE_BIOS_PRESETS = [
const ASTROCADE_KEYCODE_MAP = makeKeycodeMap([
// player 1
[Keys.VK_UP, 0x10, 0x1],
[Keys.VK_DOWN, 0x10, 0x2],
[Keys.VK_LEFT, 0x10, 0x4],
[Keys.VK_RIGHT, 0x10, 0x8],
[Keys.VK_SPACE, 0x10, 0x10],
[Keys.UP, 0x10, 0x1],
[Keys.DOWN, 0x10, 0x2],
[Keys.LEFT, 0x10, 0x4],
[Keys.RIGHT, 0x10, 0x8],
[Keys.A, 0x10, 0x10],
// keypad $14
[Keys.VK_P, 0x14, 0x1],
[Keys.VK_SLASH, 0x14, 0x2],
@ -487,6 +487,7 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) {
s += "\n HORCB: $" + hex(st.horcb);
s += "\n INMOD: $" + hex(st.inmod);
s += "\n INFBK: $" + hex(st.infbk);
s += "\n INTST: $" + hex(st.in[8]); // intercept status
/*
s += "\nPalette: ";
for (var i=0; i<8; i++)

View File

@ -42,19 +42,19 @@ export var ColecoVision_PRESETS = [
];
var COLECOVISION_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_UP, 0, 0x1],
[Keys.VK_DOWN, 0, 0x4],
[Keys.VK_LEFT, 0, 0x8],
[Keys.VK_RIGHT, 0, 0x2],
[Keys.VK_SPACE, 0, 0x40],
[Keys.VK_CONTROL, 1, 0x40],
[Keys.UP, 0, 0x1],
[Keys.DOWN, 0, 0x4],
[Keys.LEFT, 0, 0x8],
[Keys.RIGHT, 0, 0x2],
[Keys.A, 0, 0x40],
[Keys.B, 1, 0x40],
[Keys.VK_W, 2, 0x1],
[Keys.VK_S, 2, 0x4],
[Keys.VK_A, 2, 0x8],
[Keys.VK_D, 2, 0x2],
[Keys.VK_Z, 2, 0x40],
[Keys.VK_X, 3, 0x40],
[Keys.P2_UP, 2, 0x1],
[Keys.P2_DOWN, 2, 0x4],
[Keys.P2_LEFT, 2, 0x8],
[Keys.P2_RIGHT, 2, 0x2],
[Keys.P2_A, 2, 0x40],
[Keys.P2_B, 3, 0x40],
]);
/// standard emulator

View File

@ -11,29 +11,29 @@ const GALAXIAN_PRESETS = [
];
const GALAXIAN_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SPACE, 0, 0x10], // P1
[Keys.VK_LEFT, 0, 0x4],
[Keys.VK_RIGHT, 0, 0x8],
[Keys.VK_S, 1, 0x10], // P2
[Keys.VK_A, 1, 0x4],
[Keys.VK_D, 1, 0x8],
[Keys.VK_5, 0, 0x1],
[Keys.VK_1, 1, 0x1],
[Keys.A, 0, 0x10], // P1
[Keys.LEFT, 0, 0x4],
[Keys.RIGHT, 0, 0x8],
[Keys.P2_A, 1, 0x10], // P2
[Keys.P2_LEFT, 1, 0x4],
[Keys.P2_RIGHT, 1, 0x8],
[Keys.SELECT, 0, 0x1],
[Keys.START, 1, 0x1],
[Keys.VK_2, 1, 0x2],
]);
const SCRAMBLE_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_UP, 0, -0x1], // P1
[Keys.VK_SHIFT, 0, -0x2], // fire
[Keys.UP, 0, -0x1], // P1
[Keys.B, 0, -0x2], // fire
[Keys.VK_7, 0, -0x4], // credit
[Keys.VK_SPACE, 0, -0x8], // bomb
[Keys.VK_RIGHT, 0, -0x10],
[Keys.VK_LEFT, 0, -0x20],
[Keys.A, 0, -0x8], // bomb
[Keys.RIGHT, 0, -0x10],
[Keys.LEFT, 0, -0x20],
[Keys.VK_6, 0, -0x40],
[Keys.VK_5, 0, -0x80],
[Keys.VK_1, 1, -0x80],
[Keys.SELECT, 0, -0x80],
[Keys.START, 1, -0x80],
[Keys.VK_2, 1, -0x40],
[Keys.VK_DOWN, 2, -0x40],
[Keys.DOWN, 2, -0x40],
//[Keys.VK_UP, 2, -0x10],
]);

View File

@ -18,19 +18,19 @@ var MSX_PRESETS = [
];
var MSX_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_UP, 0, 0x1],
[Keys.VK_DOWN, 0, 0x4],
[Keys.VK_LEFT, 0, 0x8],
[Keys.VK_RIGHT, 0, 0x2],
[Keys.VK_SPACE, 0, 0x40],
[Keys.VK_CONTROL, 1, 0x40],
[Keys.UP, 0, 0x1],
[Keys.DOWN, 0, 0x4],
[Keys.LEFT, 0, 0x8],
[Keys.RIGHT, 0, 0x2],
[Keys.A, 0, 0x40],
[Keys.B, 1, 0x40],
[Keys.VK_W, 2, 0x1],
[Keys.VK_S, 2, 0x4],
[Keys.VK_A, 2, 0x8],
[Keys.VK_D, 2, 0x2],
[Keys.VK_Z, 2, 0x40],
[Keys.VK_X, 3, 0x40],
[Keys.P2_UP, 2, 0x1],
[Keys.P2_DOWN, 2, 0x4],
[Keys.P2_LEFT, 2, 0x8],
[Keys.P2_RIGHT, 2, 0x2],
[Keys.P2_A, 2, 0x40],
[Keys.P2_B, 3, 0x40],
]);
/// standard emulator

View File

@ -13,15 +13,15 @@ const MW8080BW_PRESETS = [
];
const SPACEINV_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SPACE, 1, 0x10], // P1
[Keys.VK_LEFT, 1, 0x20],
[Keys.VK_RIGHT, 1, 0x40],
[Keys.VK_S, 2, 0x10], // P2
[Keys.VK_A, 2, 0x20],
[Keys.VK_D, 2, 0x40],
[Keys.VK_5, 1, 0x1],
[Keys.VK_1, 1, 0x4],
[Keys.VK_2, 1, 0x2],
[Keys.A, 1, 0x10], // P1
[Keys.LEFT, 1, 0x20],
[Keys.RIGHT, 1, 0x40],
[Keys.P2_A, 2, 0x10], // P2
[Keys.P2_LEFT, 2, 0x20],
[Keys.P2_RIGHT, 2, 0x40],
[Keys.SELECT, 1, 0x1],
[Keys.START, 1, 0x4],
[Keys.P2_START, 1, 0x2],
]);
const INITIAL_WATCHDOG = 256;

View File

@ -45,22 +45,23 @@ const JSNES_PRESETS = [
/// JSNES
const JSNES_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_X, 0, 0],
[Keys.VK_Z, 0, 1],
[Keys.VK_SPACE, 0, 2],
[Keys.VK_ENTER, 0, 3],
[Keys.VK_UP, 0, 4],
[Keys.VK_DOWN, 0, 5],
[Keys.VK_LEFT, 0, 6],
[Keys.VK_RIGHT, 0, 7],
[Keys.VK_Q, 1, 0],
[Keys.VK_E, 1, 1],
[Keys.VK_1, 1, 2],
[Keys.VK_2, 1, 3],
[Keys.VK_W, 1, 4],
[Keys.VK_S, 1, 5],
[Keys.VK_A, 1, 6],
[Keys.VK_D, 1, 7],
[Keys.A, 0, 0],
[Keys.B, 0, 1],
[Keys.SELECT, 0, 2],
[Keys.START, 0, 3],
[Keys.UP, 0, 4],
[Keys.DOWN, 0, 5],
[Keys.LEFT, 0, 6],
[Keys.RIGHT, 0, 7],
[Keys.P2_A, 1, 0],
[Keys.P2_B, 1, 1],
[Keys.P2_SELECT, 1, 2],
[Keys.P2_START, 1, 3],
[Keys.P2_UP, 1, 4],
[Keys.P2_DOWN, 1, 5],
[Keys.P2_LEFT, 1, 6],
[Keys.P2_RIGHT, 1, 7],
]);
class JSNESPlatform extends Base6502Platform implements Platform {

View File

@ -33,20 +33,20 @@ export var SG1000_PRESETS = [
var SG1000_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_UP, 0, 0x1],
[Keys.VK_DOWN, 0, 0x2],
[Keys.VK_LEFT, 0, 0x4],
[Keys.VK_RIGHT, 0, 0x8],
[Keys.VK_SPACE, 0, 0x10],
[Keys.VK_CONTROL, 0, 0x20],
[Keys.UP, 0, 0x1],
[Keys.DOWN, 0, 0x2],
[Keys.LEFT, 0, 0x4],
[Keys.RIGHT, 0, 0x8],
[Keys.A, 0, 0x10],
[Keys.B, 0, 0x20],
[Keys.VK_R, 0, 0x40],
[Keys.VK_F, 0, 0x80],
[Keys.VK_D, 1, 0x1],
[Keys.VK_G, 1, 0x2],
[Keys.VK_A, 1, 0x4],
[Keys.VK_S, 1, 0x8],
[Keys.VK_1, 1, 0x10],
[Keys.P2_UP, 0, 0x40],
[Keys.A, 0, 0x80],
[Keys.P2_RIGHT, 1, 0x1],
[Keys.B, 1, 0x2],
[Keys.P2_LEFT, 1, 0x4],
[Keys.P2_DOWN, 1, 0x8],
[Keys.START, 1, 0x10],
]);
class SG1000Platform extends BasicZ80ScanlinePlatform implements Platform {

View File

@ -16,29 +16,29 @@ var VECTOR_PRESETS = [
]
var ASTEROIDS_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SHIFT, 3, 0xff],
[Keys.VK_SPACE, 4, 0xff],
[Keys.VK_5, 8, 0xff],
[Keys.VK_6, 9, 0xff],
[Keys.VK_7, 10, 0xff],
[Keys.VK_1, 11, 0xff],
[Keys.VK_2, 12, 0xff],
[Keys.VK_UP, 13, 0xff],
[Keys.VK_RIGHT, 14, 0xff],
[Keys.VK_LEFT, 15, 0xff],
[Keys.B, 3, 0xff],
[Keys.A, 4, 0xff],
[Keys.SELECT, 8, 0xff],
[Keys.VK_6, 9, 0xff],
[Keys.VK_7, 10, 0xff],
[Keys.START, 11, 0xff],
[Keys.P2_START, 12, 0xff],
[Keys.UP, 13, 0xff],
[Keys.RIGHT, 14, 0xff],
[Keys.LEFT, 15, 0xff],
]);
var GRAVITAR_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SHIFT, 1, -0x1],
[Keys.VK_SPACE, 1, -0x2],
[Keys.VK_5, 0, 0x2],
[Keys.VK_6, 0, 0x1],
[Keys.VK_1, 2, 0x20],
[Keys.VK_2, 2, 0x40],
[Keys.VK_UP, 1, -0x10],
[Keys.VK_DOWN, 1, -0x20],
[Keys.VK_RIGHT, 1, -0x4],
[Keys.VK_LEFT, 1, -0x8],
[Keys.B, 1, -0x1],
[Keys.A, 1, -0x2],
[Keys.VK_5, 0, 0x2],
[Keys.VK_6, 0, 0x1],
[Keys.START, 2, 0x20],
[Keys.P2_START, 2, 0x40],
[Keys.UP, 1, -0x10],
[Keys.DOWN, 1, -0x20],
[Keys.RIGHT, 1, -0x4],
[Keys.LEFT, 1, -0x8],
]);
var AtariVectorPlatform = function(mainElement) {

View File

@ -42,22 +42,22 @@ var VERILOG_PRESETS = [
];
var VERILOG_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_LEFT, 0, 0x1],
[Keys.VK_RIGHT, 0, 0x2],
[Keys.VK_UP, 0, 0x4],
[Keys.VK_DOWN, 0, 0x8],
[Keys.VK_SPACE, 0, 0x10],
[Keys.VK_SHIFT, 0, 0x20],
[Keys.VK_A, 1, 0x1],
[Keys.VK_D, 1, 0x2],
[Keys.VK_W, 1, 0x4],
[Keys.VK_S, 1, 0x8],
[Keys.VK_Z, 1, 0x10],
[Keys.VK_X, 1, 0x20],
[Keys.VK_1, 2, 0x1],
[Keys.VK_2, 2, 0x2],
[Keys.VK_5, 2, 0x4],
[Keys.VK_6, 2, 0x8],
[Keys.LEFT, 0, 0x1],
[Keys.RIGHT, 0, 0x2],
[Keys.UP, 0, 0x4],
[Keys.DOWN, 0, 0x8],
[Keys.A, 0, 0x10],
[Keys.B, 0, 0x20],
[Keys.P2_LEFT, 0, 0x1],
[Keys.P2_RIGHT, 0, 0x2],
[Keys.P2_UP, 0, 0x4],
[Keys.P2_DOWN, 0, 0x8],
[Keys.P2_A, 0, 0x10],
[Keys.P2_B, 0, 0x20],
[Keys.START, 2, 0x1],
[Keys.P2_START, 2, 0x2],
[Keys.SELECT, 2, 0x4],
[Keys.P2_SELECT, 2, 0x8],
[Keys.VK_7, 2, 0x10],
]);

View File

@ -66,15 +66,15 @@ class VicDualDisplay {
}
const CARNIVAL_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SPACE, 2, -0x20],
[Keys.VK_SHIFT, 2, -0x40],
[Keys.VK_LEFT, 1, -0x10],
[Keys.VK_RIGHT, 1, -0x20],
[Keys.VK_UP, 1, -0x40],
[Keys.VK_DOWN, 1, -0x80],
[Keys.VK_1, 2, -0x10],
[Keys.VK_2, 3, -0x20],
[Keys.VK_5, 3, 0x8],
[Keys.A, 2, -0x20],
[Keys.B, 2, -0x40],
[Keys.LEFT, 1, -0x10],
[Keys.RIGHT, 1, -0x20],
[Keys.UP, 1, -0x40],
[Keys.DOWN, 1, -0x80],
[Keys.START, 2, -0x10],
[Keys.P2_START, 3, -0x20],
[Keys.SELECT, 3, 0x8],
]);
const XTAL = 15468000.0;

View File

@ -42,37 +42,37 @@ var WilliamsPlatform = function(mainElement, proto) {
var PIXEL_OFF = 0xff000000;
var DEFENDER_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_SPACE, 4, 0x1],
[Keys.VK_RIGHT, 4, 0x2],
[Keys.VK_Z, 4, 0x4],
[Keys.A, 4, 0x1],
[Keys.RIGHT, 4, 0x2],
[Keys.B, 4, 0x4],
[Keys.VK_X, 4, 0x8],
[Keys.VK_2, 4, 0x10],
[Keys.VK_1, 4, 0x20],
[Keys.VK_LEFT, 4, 0x40],
[Keys.VK_DOWN, 4, 0x80],
[Keys.VK_UP, 6, 0x1],
[Keys.VK_5, 0, 0x4],
[Keys.P2_START, 4, 0x10],
[Keys.START, 4, 0x20],
[Keys.LEFT, 4, 0x40],
[Keys.DOWN, 4, 0x80],
[Keys.UP, 6, 0x1],
[Keys.SELECT, 0, 0x4],
[Keys.VK_7, 0, 0x1],
[Keys.VK_8, 0, 0x2],
[Keys.VK_9, 0, 0x8],
]);
var ROBOTRON_KEYCODE_MAP = makeKeycodeMap([
[Keys.VK_W, 0, 0x1],
[Keys.VK_S, 0, 0x2],
[Keys.VK_A, 0, 0x4],
[Keys.VK_D, 0, 0x8],
[Keys.VK_1, 0, 0x10],
[Keys.VK_2, 0, 0x20],
[Keys.VK_UP, 0, 0x40],
[Keys.VK_DOWN, 0, 0x80],
[Keys.VK_LEFT, 2, 0x1],
[Keys.VK_RIGHT, 2, 0x2],
[Keys.P2_UP, 0, 0x1],
[Keys.P2_DOWN, 0, 0x2],
[Keys.P2_LEFT, 0, 0x4],
[Keys.P2_RIGHT, 0, 0x8],
[Keys.START, 0, 0x10],
[Keys.P2_START, 0, 0x20],
[Keys.UP, 0, 0x40],
[Keys.DOWN, 0, 0x80],
[Keys.LEFT, 2, 0x1],
[Keys.RIGHT, 2, 0x2],
[Keys.VK_7, 4, 0x1],
[Keys.VK_8, 4, 0x2],
[Keys.VK_6, 4, 0x4],
[Keys.VK_9, 4, 0x8],
[Keys.VK_5, 4, 0x10],
[Keys.SELECT, 4, 0x10],
]);
// TODO: sound board handshake