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
|
||||
- bad error msg if >2 moduels and top module doesn't match filename
|
||||
- separate Scope View
|
||||
- keyboard interface
|
||||
- single-stepping vector games makes screen fade
|
||||
- break on stack overflow, illegal op, bad access, BRK, etc
|
||||
- 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;
|
||||
|
||||
export function setKeyboardFromMap(video:RasterVideo, switches:number[]|Uint8Array, map:KeyCodeMap, func?:KeyMapFunction) {
|
||||
var handler = (key,code,flags) => {
|
||||
export function newKeyboardHandler(switches:number[]|Uint8Array, map:KeyCodeMap, func?:KeyMapFunction, alwaysfunc?:boolean) {
|
||||
return (key:number,code:number,flags:number) => {
|
||||
if (!map) {
|
||||
func(null, key, code, flags);
|
||||
return;
|
||||
}
|
||||
var o : KeyMapEntry = map[key];
|
||||
if (!o) o = map[0];
|
||||
if (o && func) {
|
||||
if (func && (o || alwaysfunc)) {
|
||||
func(o, key, code, flags);
|
||||
}
|
||||
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);
|
||||
return new ControllerPoller(map, handler);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
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 { safe_extend, clamp } from "../util";
|
||||
import { WaveformView, WaveformProvider, WaveformMeta } from "../waveform";
|
||||
@ -235,6 +235,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
|
||||
// control inputs
|
||||
var switches = [0,0,0];
|
||||
var keycode = 0;
|
||||
|
||||
// inspect feature
|
||||
var inspect_obj, inspect_sym;
|
||||
@ -280,6 +281,8 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
gen.tick2();
|
||||
if (useAudio)
|
||||
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())
|
||||
debugCond = null;
|
||||
}
|
||||
@ -328,7 +331,11 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
ctx.font = "8px TinyFont";
|
||||
ctx.fillStyle = "white";
|
||||
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);
|
||||
idata = video.getFrameData();
|
||||
timerCallback = () => {
|
||||
@ -389,6 +396,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
gen.switches_p1 = switches[0];
|
||||
gen.switches_p2 = switches[1];
|
||||
gen.switches_gen = switches[2];
|
||||
gen.keycode = keycode;
|
||||
}
|
||||
|
||||
updateVideoFrame() {
|
||||
@ -768,6 +776,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
sw0: switches[0],
|
||||
sw1: switches[1],
|
||||
sw2: switches[2],
|
||||
keycode: keycode
|
||||
};
|
||||
}
|
||||
loadControlsState(state) {
|
||||
@ -776,6 +785,7 @@ var VerilogPlatform = function(mainElement, options) {
|
||||
switches[0] = state.sw0;
|
||||
switches[1] = state.sw1;
|
||||
switches[2] = state.sw2;
|
||||
keycode = state.keycode;
|
||||
}
|
||||
|
||||
} // end of inner class
|
||||
|
Loading…
x
Reference in New Issue
Block a user