mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-22 12:29:06 +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,
|
||||
}
|
||||
|
||||
// TODO: don't use which/keyCode anymore?
|
||||
export function _setKeyboardEvents(canvas:HTMLElement, callback:KeyboardCallback) {
|
||||
canvas.onkeydown = (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
|
||||
};
|
||||
canvas.onkeyup = (e) => {
|
||||
callback(e.which, 0, KeyFlags.KeyUp|_metakeyflags(e));
|
||||
};
|
||||
canvas.onkeypress = (e) => {
|
||||
callback(e.which, e.charCode, KeyFlags.KeyPress|_metakeyflags(e));
|
||||
callback(e.which, e.keyCode, KeyFlags.KeyUp|_metakeyflags(e));
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -325,23 +325,14 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS {
|
||||
}
|
||||
|
||||
setKeyInput(key:number, code:number, flags:number) : void {
|
||||
if (flags & KeyFlags.KeyPress) {
|
||||
// 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) {
|
||||
if (flags & KeyFlags.KeyDown) {
|
||||
code = 0;
|
||||
switch (key) {
|
||||
case 16: case 17: case 18:
|
||||
break; // ignore shift/ctrl/etc
|
||||
case 8:
|
||||
code=8; // left
|
||||
if (flags & KeyFlags.Ctrl) {
|
||||
if (flags & KeyFlags.Shift) {
|
||||
// (possibly) soft reset
|
||||
this.cpu.reset();
|
||||
return;
|
||||
@ -354,20 +345,19 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS {
|
||||
case 38: code=11; break; // up
|
||||
case 40: code=10; break; // down
|
||||
default:
|
||||
if (flags & KeyFlags.Ctrl) {
|
||||
code = key;
|
||||
if (code >= 0x61 && code <= 0x7a)
|
||||
code -= 32;
|
||||
if (key >= 65 && code < 65+26) {
|
||||
code -= 64; // ctrl
|
||||
code = key;
|
||||
// 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
|
||||
}
|
||||
else {
|
||||
code = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (code)
|
||||
if (code) {
|
||||
this.kbdlatch = (code | 0x80) & 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
video = new RasterVideo(mainElement,videoWidth,videoHeight,{overscan:true});
|
||||
video.create();
|
||||
poller = setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP, (o,key,code,flags) => {
|
||||
if (flags & KeyFlags.KeyPress) {
|
||||
if (flags & KeyFlags.KeyDown) {
|
||||
keycode = code | 0x80;
|
||||
}
|
||||
}, true); // true = always send function
|
||||
|
@ -227,7 +227,7 @@ describe('Platform Replay', () => {
|
||||
it('Should run apple2', async () => {
|
||||
var platform = await testPlatform('apple2', 'cosmic.c.rom', 72, (platform, frameno) => {
|
||||
if (frameno == 62) {
|
||||
keycallback(32, 32, 128); // space bar
|
||||
keycallback(32, 32, 1); // space bar
|
||||
}
|
||||
});
|
||||
assert.equal(platform.saveState().kbdlatch, 0x20); // strobe cleared
|
||||
|
Loading…
x
Reference in New Issue
Block a user