From f159ebcafbfa91cfe79c9b33a759108d1ca0a035 Mon Sep 17 00:00:00 2001 From: Fred Sauer Date: Sat, 21 Mar 2026 18:34:58 -0700 Subject: [PATCH] Add Apple SW0/SW1/SW2 button support --- src/common/baseplatform.ts | 5 +++++ src/common/devices.ts | 1 + src/common/emu.ts | 9 +++++++++ src/machine/apple2.ts | 15 +++++++++++++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/common/baseplatform.ts b/src/common/baseplatform.ts index 2fced0af..9fdd4be1 100644 --- a/src/common/baseplatform.ts +++ b/src/common/baseplatform.ts @@ -881,6 +881,11 @@ export abstract class BaseMachinePlatform extends BaseDebugPl if (hasPaddleInput(this.machine)) { this.machine.setPaddleInput(0, this.video.paddle_x); this.machine.setPaddleInput(1, this.video.paddle_y); + if (this.machine.setPaddleButton) { + this.machine.setPaddleButton(0, this.video.paddle_buttons[0]); + this.machine.setPaddleButton(1, this.video.paddle_buttons[1]); + this.machine.setPaddleButton(2, this.video.paddle_buttons[2]); + } } // TODO: put into interface if (this.machine['pollControls']) { diff --git a/src/common/devices.ts b/src/common/devices.ts index d22848fe..fd834088 100644 --- a/src/common/devices.ts +++ b/src/common/devices.ts @@ -112,6 +112,7 @@ export interface AcceptsKeyInput { export interface AcceptsPaddleInput { setPaddleInput(controller: number, value: number): void; + setPaddleButton?(index: number, pressed: boolean): void; } // TODO: interface not yet used (setKeyInput() handles joystick) diff --git a/src/common/emu.ts b/src/common/emu.ts index 902f0d26..ccc592a1 100644 --- a/src/common/emu.ts +++ b/src/common/emu.ts @@ -86,6 +86,8 @@ export class RasterVideo { // Start paddles/joystick centered in [0,255] range. paddle_x = 128; paddle_y = 128; + // Platforms can support up to three buttons. + paddle_buttons: boolean[] = [false, false, false]; setRotate(rotate: number) { var canvas = this.canvas; @@ -148,6 +150,13 @@ export class RasterVideo { var new_y = Math.round(pos.y * 255 / this.canvas.height); this.paddle_x = clamp(0, 255, new_x); this.paddle_y = clamp(0, 255, new_y); + }).mousedown((e) => { + // TODO Allows users to specify mapping in settings. + this.paddle_buttons[0] = !e.shiftKey && !e.altKey; + this.paddle_buttons[1] = e.shiftKey && !e.altKey; + this.paddle_buttons[2] = e.altKey && !e.shiftKey; + }).mouseup((e) => { + this.paddle_buttons.fill(false); }); }; } diff --git a/src/machine/apple2.ts b/src/machine/apple2.ts index cb858f55..8a75d0de 100644 --- a/src/machine/apple2.ts +++ b/src/machine/apple2.ts @@ -62,6 +62,7 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS, Accept bank2wroffset = 0; // Paddle/joystick, PDL0-PDL3 values (0-255). paddleValues = [0, 0, 0, 0]; + paddleButtons = [false, false, false]; paddleLastTriggered = 0; // disk II slots: SlotDevice[] = new Array(8); @@ -282,8 +283,12 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS, Accept case 1: // $C061 / $C069 - GAME SW0 case 2: // $C062 / $C06A - GAME SW1 case 3: // $C063 / $C06B - GAME SW2 - // buttons (off) - return this.floatbus() & 0x7f; + // buttons + var btn = (address & 7) - 1; + if (this.paddleButtons[btn]) + return this.floatbus() | 0x80; + else + return this.floatbus() & 0x7f; case 4: // $C064 / $C06C - GAME PDL0 case 5: // $C065 / $C06D - GAME PDL1 case 6: // $C066 / $C06E - GAME PDL2 @@ -441,6 +446,12 @@ export class AppleII extends BasicScanlineMachine implements AcceptsBIOS, Accept } } + setPaddleButton(index: number, pressed: boolean): void { + if (index >= 0 && index < this.paddleButtons.length) { + this.paddleButtons[index] = pressed; + } + } + doLanguageCardIO(address: number) { // TODO: require two writes in a row for some things switch (address & 0x0f) {