mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-27 13:29:32 +00:00
verilog: added keycode/keystrobe
This commit is contained in:
parent
44389d8e52
commit
a7cf37b67f
@ -1 +1 @@
|
|||||||
Subproject commit 7ecf62faa30fb0de99b76609f16c58a7bf032820
|
Subproject commit 4334727f0e07acd4541b0a7b8f81a5984cd4aafe
|
@ -121,7 +121,6 @@ TODO:
|
|||||||
- can't add control instructions b/c of split
|
- can't add control instructions b/c of split
|
||||||
- bad error msg if >2 moduels and top module doesn't match filename
|
- bad error msg if >2 moduels and top module doesn't match filename
|
||||||
- separate Scope View
|
- separate Scope View
|
||||||
- keyboard interface
|
|
||||||
- single-stepping vector games makes screen fade
|
- single-stepping vector games makes screen fade
|
||||||
- break on stack overflow, illegal op, bad access, BRK, etc
|
- break on stack overflow, illegal op, bad access, BRK, etc
|
||||||
- nes
|
- nes
|
||||||
|
10
src/emu.ts
10
src/emu.ts
@ -470,15 +470,15 @@ function _metakeyflags(e) {
|
|||||||
|
|
||||||
type KeyMapFunction = (o:KeyMapEntry, key:number, code:number, flags:number) => void;
|
type KeyMapFunction = (o:KeyMapEntry, key:number, code:number, flags:number) => void;
|
||||||
|
|
||||||
export function setKeyboardFromMap(video:RasterVideo, switches:number[]|Uint8Array, map:KeyCodeMap, func?:KeyMapFunction) {
|
export function newKeyboardHandler(switches:number[]|Uint8Array, map:KeyCodeMap, func?:KeyMapFunction, alwaysfunc?:boolean) {
|
||||||
var handler = (key,code,flags) => {
|
return (key:number,code:number,flags:number) => {
|
||||||
if (!map) {
|
if (!map) {
|
||||||
func(null, key, code, flags);
|
func(null, key, code, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var o : KeyMapEntry = map[key];
|
var o : KeyMapEntry = map[key];
|
||||||
if (!o) o = map[0];
|
if (!o) o = map[0];
|
||||||
if (o && func) {
|
if (func && (o || alwaysfunc)) {
|
||||||
func(o, key, code, flags);
|
func(o, key, code, flags);
|
||||||
}
|
}
|
||||||
if (o) {
|
if (o) {
|
||||||
@ -496,6 +496,10 @@ export function setKeyboardFromMap(video:RasterVideo, switches:number[]|Uint8Arr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setKeyboardFromMap(video:RasterVideo, switches:number[]|Uint8Array, map:KeyCodeMap, func?:KeyMapFunction, alwaysfunc?:boolean) {
|
||||||
|
var handler = newKeyboardHandler(switches, map, func, alwaysfunc);
|
||||||
video.setKeyboardEvents(handler);
|
video.setKeyboardEvents(handler);
|
||||||
return new ControllerPoller(map, handler);
|
return new ControllerPoller(map, handler);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { Platform, BasePlatform } from "../baseplatform";
|
import { Platform, BasePlatform } from "../baseplatform";
|
||||||
import { PLATFORMS, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, getMousePos } from "../emu";
|
import { PLATFORMS, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, getMousePos, KeyFlags } from "../emu";
|
||||||
import { SampleAudio } from "../audio";
|
import { SampleAudio } from "../audio";
|
||||||
import { safe_extend, clamp } from "../util";
|
import { safe_extend, clamp } from "../util";
|
||||||
import { WaveformView, WaveformProvider, WaveformMeta } from "../waveform";
|
import { WaveformView, WaveformProvider, WaveformMeta } from "../waveform";
|
||||||
@ -235,6 +235,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
|
|
||||||
// control inputs
|
// control inputs
|
||||||
var switches = [0,0,0];
|
var switches = [0,0,0];
|
||||||
|
var keycode = 0;
|
||||||
|
|
||||||
// inspect feature
|
// inspect feature
|
||||||
var inspect_obj, inspect_sym;
|
var inspect_obj, inspect_sym;
|
||||||
@ -280,6 +281,8 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
gen.tick2();
|
gen.tick2();
|
||||||
if (useAudio)
|
if (useAudio)
|
||||||
audio.feedSample(gen.spkr*(1.0/255.0), 1);
|
audio.feedSample(gen.spkr*(1.0/255.0), 1);
|
||||||
|
if (keycode && keycode >= 128 && gen.keystrobe) // keystrobe = clear hi bit of key buffer
|
||||||
|
keycode = gen.keycode = keycode & 0x7f;
|
||||||
if (debugCond && debugCond())
|
if (debugCond && debugCond())
|
||||||
debugCond = null;
|
debugCond = null;
|
||||||
}
|
}
|
||||||
@ -328,7 +331,11 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
ctx.font = "8px TinyFont";
|
ctx.font = "8px TinyFont";
|
||||||
ctx.fillStyle = "white";
|
ctx.fillStyle = "white";
|
||||||
ctx.textAlign = "left";
|
ctx.textAlign = "left";
|
||||||
poller = setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP);
|
poller = setKeyboardFromMap(video, switches, VERILOG_KEYCODE_MAP, (o,key,code,flags) => {
|
||||||
|
if (flags & KeyFlags.KeyPress) {
|
||||||
|
keycode = code | 0x80;
|
||||||
|
}
|
||||||
|
}, true); // true = always send function
|
||||||
var vcanvas = $(video.canvas);
|
var vcanvas = $(video.canvas);
|
||||||
idata = video.getFrameData();
|
idata = video.getFrameData();
|
||||||
timerCallback = () => {
|
timerCallback = () => {
|
||||||
@ -389,6 +396,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
gen.switches_p1 = switches[0];
|
gen.switches_p1 = switches[0];
|
||||||
gen.switches_p2 = switches[1];
|
gen.switches_p2 = switches[1];
|
||||||
gen.switches_gen = switches[2];
|
gen.switches_gen = switches[2];
|
||||||
|
gen.keycode = keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVideoFrame() {
|
updateVideoFrame() {
|
||||||
@ -768,6 +776,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
sw0: switches[0],
|
sw0: switches[0],
|
||||||
sw1: switches[1],
|
sw1: switches[1],
|
||||||
sw2: switches[2],
|
sw2: switches[2],
|
||||||
|
keycode: keycode
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
loadControlsState(state) {
|
loadControlsState(state) {
|
||||||
@ -776,6 +785,7 @@ var VerilogPlatform = function(mainElement, options) {
|
|||||||
switches[0] = state.sw0;
|
switches[0] = state.sw0;
|
||||||
switches[1] = state.sw1;
|
switches[1] = state.sw1;
|
||||||
switches[2] = state.sw2;
|
switches[2] = state.sw2;
|
||||||
|
keycode = state.keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of inner class
|
} // end of inner class
|
||||||
|
Loading…
x
Reference in New Issue
Block a user