ControllerPoller uses default list of keys; fixed pokey
This commit is contained in:
parent
c422de0571
commit
10a0d98f23
|
@ -1219,6 +1219,7 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
|
|||
timer : AnimationTimer;
|
||||
video : RasterVideo;
|
||||
audio : SampledAudio;
|
||||
poller : ControllerPoller;
|
||||
|
||||
abstract newMachine() : T;
|
||||
abstract getToolForFilename(s:string) : string;
|
||||
|
@ -1257,7 +1258,7 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
|
|||
}
|
||||
if (hasInput(m)) {
|
||||
this.video.setKeyboardEvents(m.setInput.bind(m));
|
||||
// TODO: ControllerPoller
|
||||
this.poller = new ControllerPoller(m.setInput.bind(m));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1266,6 +1267,8 @@ export abstract class BaseMachinePlatform<T extends Machine> extends BaseDebugPl
|
|||
this.reset();
|
||||
}
|
||||
|
||||
pollControls() { this.poller.poll(); }
|
||||
|
||||
advance(novideo:boolean) {
|
||||
this.machine.advanceFrame(999999, this.getDebugCallback());
|
||||
if (!novideo) this.video.updateFrame();
|
||||
|
|
17
src/emu.ts
17
src/emu.ts
|
@ -501,7 +501,7 @@ export function newKeyboardHandler(switches:number[]|Uint8Array, map:KeyCodeMap,
|
|||
export function setKeyboardFromMap(video:RasterVideo, switches:number[]|Uint8Array, map:KeyCodeMap, func?:KeyMapFunction) {
|
||||
var handler = newKeyboardHandler(switches, map, func);
|
||||
video.setKeyboardEvents(handler);
|
||||
return new ControllerPoller(map, handler);
|
||||
return new ControllerPoller(handler);
|
||||
}
|
||||
|
||||
export function makeKeycodeMap(table : [KeyDef,number,number][]) : KeyCodeMap {
|
||||
|
@ -514,15 +514,18 @@ export function makeKeycodeMap(table : [KeyDef,number,number][]) : KeyCodeMap {
|
|||
return map;
|
||||
}
|
||||
|
||||
const DEFAULT_CONTROLLER_KEYS : KeyDef[] = [
|
||||
Keys.UP, Keys.DOWN, Keys.LEFT, Keys.RIGHT, Keys.A, Keys.B, Keys.SELECT, Keys.START,
|
||||
Keys.P2_UP, Keys.P2_DOWN, Keys.P2_LEFT, Keys.P2_RIGHT, Keys.P2_A, Keys.P2_B, Keys.P2_SELECT, Keys.P2_START,
|
||||
];
|
||||
|
||||
export class ControllerPoller {
|
||||
active = false;
|
||||
map : KeyCodeMap;
|
||||
handler;
|
||||
state = new Int8Array(32);
|
||||
lastState = new Int8Array(32);
|
||||
AXIS0 = 24; // first joystick axis index
|
||||
constructor(map:KeyCodeMap, handler:(key,code,flags) => void) {
|
||||
this.map = map;
|
||||
constructor(handler:(key,code,flags) => void) {
|
||||
this.handler = handler;
|
||||
window.addEventListener("gamepadconnected", (event) => {
|
||||
console.log("Gamepad connected:", event);
|
||||
|
@ -557,11 +560,11 @@ export class ControllerPoller {
|
|||
}
|
||||
handleStateChange(gpi:number, k:number) {
|
||||
var axis = k - this.AXIS0;
|
||||
for (var code in this.map) {
|
||||
var entry = this.map[code];
|
||||
var def = entry.def;
|
||||
// TODO: this is slow
|
||||
for (var def of DEFAULT_CONTROLLER_KEYS) {
|
||||
// is this a gamepad entry? same player #?
|
||||
if (def && def.plyr == gpi) {
|
||||
var code = def.c;
|
||||
var state = this.state[k];
|
||||
var lastState = this.lastState[k];
|
||||
// check for button/axis match
|
||||
|
|
|
@ -30,7 +30,6 @@ interface Atari7800State extends Atari7800StateBase, Atari7800ControlsState {
|
|||
regs : Uint8Array,
|
||||
offset,dll,dlstart : number;
|
||||
dli,h16,h8 : boolean;
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -67,6 +66,7 @@ const numVisibleLines = 258-16;
|
|||
const colorClocksPerLine = 454; // 456?
|
||||
const colorClocksPreDMA = 28;
|
||||
const romLength = 0xc000;
|
||||
const oversampling = 4;
|
||||
|
||||
// TIA chip
|
||||
|
||||
|
@ -352,7 +352,7 @@ export class Atari7800 implements HasCPU, Bus, RasterFrameBased, SampledAudioSou
|
|||
this.cpu.connectMemoryBus(this);
|
||||
this.handler = newKeyboardHandler(this.inputs, Atari7800_KEYCODE_MAP);
|
||||
this.pokey1 = new POKEYDeviceChannel();
|
||||
this.pokey1.setBufferLength(4);
|
||||
this.pokey1.setBufferLength(oversampling*2);
|
||||
this.pokey1.setSampleRate(this.getAudioParams().sampleRate);
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ export class Atari7800 implements HasCPU, Bus, RasterFrameBased, SampledAudioSou
|
|||
return {width:320, height:numVisibleLines};
|
||||
}
|
||||
getAudioParams() {
|
||||
return {sampleRate:linesPerFrame*60*2, stereo:false};
|
||||
return {sampleRate:linesPerFrame*60*oversampling, stereo:false};
|
||||
}
|
||||
connectVideo(pixels:Uint32Array) {
|
||||
this.pixels = pixels;
|
||||
|
@ -439,10 +439,10 @@ export class Atari7800 implements HasCPU, Bus, RasterFrameBased, SampledAudioSou
|
|||
}
|
||||
// audio
|
||||
if (this.audio) {
|
||||
const audioGain = 1.0 / 16384;
|
||||
this.pokey1.generate(4);
|
||||
this.audio.feedSample(this.pokey1.getBuffer()[0] * audioGain, 1);
|
||||
this.audio.feedSample(this.pokey1.getBuffer()[2] * audioGain, 1);
|
||||
const audioGain = 1.0 / 8192;
|
||||
this.pokey1.generate(oversampling*2);
|
||||
for (let i=0; i<oversampling; i++)
|
||||
this.audio.feedSample(this.pokey1.getBuffer()[i*2] * audioGain, 1);
|
||||
}
|
||||
}
|
||||
// update video frame
|
||||
|
|
Loading…
Reference in New Issue