mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-05-28 08:41:30 +00:00
verilog, apple2: don't use KeyPress event anymore, use KeyDown/KeyUp
This commit is contained in:
parent
20954fd5ce
commit
3018ddf27a
|
@ -47,17 +47,15 @@ export enum KeyFlags {
|
||||||
KeyPress = 128,
|
KeyPress = 128,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: don't use which/keyCode anymore?
|
||||||
export function _setKeyboardEvents(canvas:HTMLElement, callback:KeyboardCallback) {
|
export function _setKeyboardEvents(canvas:HTMLElement, callback:KeyboardCallback) {
|
||||||
canvas.onkeydown = (e) => {
|
canvas.onkeydown = (e) => {
|
||||||
let flags = _metakeyflags(e);
|
let flags = _metakeyflags(e);
|
||||||
callback(e.which, 0, KeyFlags.KeyDown|flags);
|
callback(e.which, e.keyCode, KeyFlags.KeyDown|flags);
|
||||||
if (!flags) e.preventDefault(); // eat all keys that don't have a modifier
|
if (!flags) e.preventDefault(); // eat all keys that don't have a modifier
|
||||||
};
|
};
|
||||||
canvas.onkeyup = (e) => {
|
canvas.onkeyup = (e) => {
|
||||||
callback(e.which, 0, KeyFlags.KeyUp|_metakeyflags(e));
|
callback(e.which, e.keyCode, KeyFlags.KeyUp|_metakeyflags(e));
|
||||||
};
|
|
||||||
canvas.onkeypress = (e) => {
|
|
||||||
callback(e.which, e.charCode, KeyFlags.KeyPress|_metakeyflags(e));
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -325,23 +325,14 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS {
|
||||||
}
|
}
|
||||||
|
|
||||||
setKeyInput(key:number, code:number, flags:number) : void {
|
setKeyInput(key:number, code:number, flags:number) : void {
|
||||||
if (flags & KeyFlags.KeyPress) {
|
if (flags & KeyFlags.KeyDown) {
|
||||||
// convert to uppercase for Apple ][
|
|
||||||
if (code >= 0x61 && code <= 0x7a)
|
|
||||||
code -= 32;
|
|
||||||
if (code >= 32) {
|
|
||||||
if (code >= 65 && code < 65+26) {
|
|
||||||
if (flags & KeyFlags.Ctrl)
|
|
||||||
code -= 64; // ctrl
|
|
||||||
}
|
|
||||||
this.kbdlatch = (code | 0x80) & 0xff;
|
|
||||||
}
|
|
||||||
} else if (flags & KeyFlags.KeyDown) {
|
|
||||||
code = 0;
|
code = 0;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
case 16: case 17: case 18:
|
||||||
|
break; // ignore shift/ctrl/etc
|
||||||
case 8:
|
case 8:
|
||||||
code=8; // left
|
code=8; // left
|
||||||
if (flags & KeyFlags.Ctrl) {
|
if (flags & KeyFlags.Shift) {
|
||||||
// (possibly) soft reset
|
// (possibly) soft reset
|
||||||
this.cpu.reset();
|
this.cpu.reset();
|
||||||
return;
|
return;
|
||||||
|
@ -354,20 +345,19 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS {
|
||||||
case 38: code=11; break; // up
|
case 38: code=11; break; // up
|
||||||
case 40: code=10; break; // down
|
case 40: code=10; break; // down
|
||||||
default:
|
default:
|
||||||
if (flags & KeyFlags.Ctrl) {
|
code = key;
|
||||||
code = key;
|
// convert to uppercase for Apple ][
|
||||||
if (code >= 0x61 && code <= 0x7a)
|
if (code >= 0x61 && code <= 0x7a) code -= 32;
|
||||||
code -= 32;
|
if (code >= 32) {
|
||||||
if (key >= 65 && code < 65+26) {
|
if (code >= 65 && code < 65+26) {
|
||||||
code -= 64; // ctrl
|
if (flags & KeyFlags.Ctrl)
|
||||||
|
code -= 64; // ctrl
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
code = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (code)
|
if (code) {
|
||||||
this.kbdlatch = (code | 0x80) & 0xff;
|
this.kbdlatch = (code | 0x80) & 0xff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||||
video = new RasterVideo(mainElement,videoWidth,videoHeight,{overscan:true});
|
video = new RasterVideo(mainElement,videoWidth,videoHeight,{overscan:true});
|
||||||
video.create();
|
video.create();
|
||||||
poller = setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP, (o,key,code,flags) => {
|
poller = setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP, (o,key,code,flags) => {
|
||||||
if (flags & KeyFlags.KeyPress) {
|
if (flags & KeyFlags.KeyDown) {
|
||||||
keycode = code | 0x80;
|
keycode = code | 0x80;
|
||||||
}
|
}
|
||||||
}, true); // true = always send function
|
}, true); // true = always send function
|
||||||
|
|
|
@ -227,7 +227,7 @@ describe('Platform Replay', () => {
|
||||||
it('Should run apple2', async () => {
|
it('Should run apple2', async () => {
|
||||||
var platform = await testPlatform('apple2', 'cosmic.c.rom', 72, (platform, frameno) => {
|
var platform = await testPlatform('apple2', 'cosmic.c.rom', 72, (platform, frameno) => {
|
||||||
if (frameno == 62) {
|
if (frameno == 62) {
|
||||||
keycallback(32, 32, 128); // space bar
|
keycallback(32, 32, 1); // space bar
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assert.equal(platform.saveState().kbdlatch, 0x20); // strobe cleared
|
assert.equal(platform.saveState().kbdlatch, 0x20); // strobe cleared
|
||||||
|
|
Loading…
Reference in New Issue
Block a user