-
Notifications
You must be signed in to change notification settings - Fork 70
Add mouse as analogue joystick support #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implements analogue joystick emulation using the mouse position, addressing issue #501. The mouse position on the BBC display is mapped to ADC channels 0 (X-axis) and 1 (Y-axis), with left mouse button acting as fire button 1. Key features: - Mouse position tracked globally, even when not over the BBC display - Accessible via ADVAL(0) for X and ADVAL(1) for Y in BBC BASIC - Fire button triggered by left mouse click when over the display - Can be enabled via config dialog or URL parameter (?mouseJoystickEnabled) - Works alongside existing gamepad support Implementation details: - Created MouseJoystickSource class implementing AnalogueSource interface - Simplified ADC source management with updateAdcSources() helper function - Added proper cleanup and disposal of event listeners - Full test coverage for the new functionality Closes #501 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
The BBC Micro uses inverted joystick axes where: - X-axis: Left = 65535 (max), Right = 0 (min) - Y-axis: Up = 65535 (max), Down = 0 (min) The mouse joystick implementation was using direct mapping which gave the opposite behavior. This commit inverts the mouse position to match the BBC Micro's expected values. The gamepad implementation was already correct with its (1 - rawValue) formula. Also added documentation about this quirk to the README. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Remove unnecessary comment from config.js - Simplify getValue() function with direct returns - Remove extra braces and temporary variable - Add clarifying comments about dispose() and microphone status The microphone permission status functionality is preserved - setupMicrophone() still handles UI updates while updateAdcSources() handles channel assignment. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for using the mouse as an analogue joystick by mapping the mouse position on the BBC display to ADC channels and using the left button as fire.
- Introduces
MouseJoystickSource
with event handling and disposal - Updates VIA logic to combine mouse button state with gamepad buttons
- Integrates mouse joystick in
main.js
and adds configuration/UI and docs
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/mouse-joystick-source.js | New class mapping mouse movement and clicks to ADC |
src/via.js | Merge mouse fire button state into joystick output |
src/main.js | Wire up mouse joystick source, config, and ADC setup |
src/config.js | Add mouseJoystickEnabled parameter binding |
index.html | Add UI control for enabling mouse joystick |
tests/unit/test-mouse-joystick-source.js | Unit tests for mouse joystick source functionality |
README.md | Document inverted axes and support for mouse joystick |
Comments suppressed due to low confidence (2)
README.md:39
- The README notes the inverted axes but doesn’t explain how to enable mouse joystick (Settings dialog or
?mouseJoystickEnabled
URL param). Consider adding a brief instruction on toggling this feature.
- X-axis: Left = 65535, Right = 0
src/mouse-joystick-source.js:97
- There’s no test verifying that
handleMouseDown
is no-op whenvia
is unset orisActive
is false. Adding a unit test for those branches will ensure the guard logic stays correct.
if (!this.isActive || !this.via) return;
…dling - Replace event-driven approach with clean API methods: onMouseMove(), onMouseDown(), onMouseUp(), isEnabled() - Update main.js to use API methods instead of direct property manipulation - Fix config change handler to use updated parsedQuery values for immediate UI response - Remove debug console.log statements from MouseJoystickSource and VIA - Update tests to reflect new API-based approach - Remove event listener registration/cleanup code 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…tons - Correctly handle DDR in recalculatePortBPins(): output pins use ORB values, input pins default high - Fix inverted button logic: clear pin bits when buttons are pressed (active low) - Remove redundant DDR masking that was preventing proper input pin reads - This fixes ADVAL(0) not detecting mouse joystick fire button presses The original code wasn't respecting the Data Direction Register, causing joystick fire button states to not be readable by BBC BASIC's ADVAL(0) function. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Move fire button handling into rawPortB() method instead of special-casing in recalculatePortBPins(). This provides cleaner hardware abstraction and ensures DDR (data direction register) compliance - fire buttons can only affect pins configured as inputs, matching real hardware behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Tested with Elite |
Summary
Features
🎮 Mouse Tracking: Mouse position is tracked globally, even when not directly over the BBC display canvas
📊 BBC BASIC Access: Read joystick position via for X-axis and for Y-axis
🔫 Fire Button: Left mouse click triggers joystick fire button when mouse is over the display
⚙️ Configuration: Enable via Settings dialog or URL parameter
🎯 Compatibility: Works alongside existing gamepad support without conflicts
Implementation Details
Closes #501
🤖 Generated with Claude Code