web-a2e 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.clangd +5 -0
- package/.mcp.json +12 -0
- package/CLAUDE.md +362 -0
- package/CMakeLists.txt +774 -0
- package/LICENSE +21 -0
- package/README.md +392 -0
- package/build-wasm/generated/roms.cpp +2447 -0
- package/docker-compose.staging.yml +9 -0
- package/docs/basic-rom-disassembly.md +6663 -0
- package/docs/softswitch-comparison.md +273 -0
- package/docs/thunderclock-debug.md +89 -0
- package/examples/cube.bas +72 -0
- package/examples/hello.s +55 -0
- package/examples/scroll.s +140 -0
- package/package.json +18 -0
- package/public/assets/apple-logo-old.png +0 -0
- package/public/assets/apple-logo.png +0 -0
- package/public/assets/drive-closed-light-on.png +0 -0
- package/public/assets/drive-closed.png +0 -0
- package/public/assets/drive-open-light-on.png +0 -0
- package/public/assets/drive-open.png +0 -0
- package/public/audio-worklet.js +82 -0
- package/public/disks/Apple DOS 3.3 January 1983.dsk +0 -0
- package/public/disks/ProDOS 2.4.3.po +0 -0
- package/public/disks/h32mb.2mg +0 -0
- package/public/disks/library.json +26 -0
- package/public/docs/llms/llm-assembler.txt +90 -0
- package/public/docs/llms/llm-basic-program.txt +256 -0
- package/public/docs/llms/llm-disk-drives.txt +72 -0
- package/public/docs/llms/llm-file-explorer.txt +50 -0
- package/public/docs/llms/llm-hard-drives.txt +80 -0
- package/public/docs/llms/llm-main.txt +51 -0
- package/public/docs/llms/llm-slot-configuration.txt +66 -0
- package/public/icons/icon-192.svg +4 -0
- package/public/icons/icon-512.svg +4 -0
- package/public/index.html +661 -0
- package/public/llms.txt +49 -0
- package/public/manifest.json +29 -0
- package/public/shaders/burnin.glsl +22 -0
- package/public/shaders/crt.glsl +706 -0
- package/public/shaders/edge.glsl +109 -0
- package/public/shaders/vertex.glsl +8 -0
- package/public/sw.js +186 -0
- package/roms/341-0027.bin +0 -0
- package/roms/341-0160-A-US-UK.bin +0 -0
- package/roms/341-0160-A.bin +0 -0
- package/roms/342-0273-A-US-UK.bin +0 -0
- package/roms/342-0349-B-C0-FF.bin +0 -0
- package/roms/Apple Mouse Interface Card ROM - 342-0270-C.bin +0 -0
- package/roms/Thunderclock Plus ROM.bin +0 -0
- package/scripts/generate_roms.sh +69 -0
- package/src/bindings/wasm_interface.cpp +1940 -0
- package/src/core/assembler/assembler.cpp +1239 -0
- package/src/core/assembler/assembler.hpp +115 -0
- package/src/core/audio/audio.cpp +160 -0
- package/src/core/audio/audio.hpp +81 -0
- package/src/core/basic/basic_detokenizer.cpp +436 -0
- package/src/core/basic/basic_detokenizer.hpp +41 -0
- package/src/core/basic/basic_tokenizer.cpp +286 -0
- package/src/core/basic/basic_tokenizer.hpp +26 -0
- package/src/core/basic/basic_tokens.hpp +295 -0
- package/src/core/cards/disk2_card.cpp +568 -0
- package/src/core/cards/disk2_card.hpp +316 -0
- package/src/core/cards/expansion_card.hpp +185 -0
- package/src/core/cards/mockingboard/ay8910.cpp +616 -0
- package/src/core/cards/mockingboard/ay8910.hpp +159 -0
- package/src/core/cards/mockingboard/via6522.cpp +530 -0
- package/src/core/cards/mockingboard/via6522.hpp +163 -0
- package/src/core/cards/mockingboard_card.cpp +312 -0
- package/src/core/cards/mockingboard_card.hpp +159 -0
- package/src/core/cards/mouse_card.cpp +654 -0
- package/src/core/cards/mouse_card.hpp +190 -0
- package/src/core/cards/smartport/block_device.cpp +202 -0
- package/src/core/cards/smartport/block_device.hpp +60 -0
- package/src/core/cards/smartport/smartport_card.cpp +603 -0
- package/src/core/cards/smartport/smartport_card.hpp +120 -0
- package/src/core/cards/thunderclock_card.cpp +237 -0
- package/src/core/cards/thunderclock_card.hpp +122 -0
- package/src/core/cpu/cpu6502.cpp +1609 -0
- package/src/core/cpu/cpu6502.hpp +203 -0
- package/src/core/debug/condition_evaluator.cpp +470 -0
- package/src/core/debug/condition_evaluator.hpp +87 -0
- package/src/core/disassembler/disassembler.cpp +552 -0
- package/src/core/disassembler/disassembler.hpp +171 -0
- package/src/core/disk-image/disk_image.hpp +267 -0
- package/src/core/disk-image/dsk_disk_image.cpp +827 -0
- package/src/core/disk-image/dsk_disk_image.hpp +204 -0
- package/src/core/disk-image/gcr_encoding.cpp +147 -0
- package/src/core/disk-image/gcr_encoding.hpp +78 -0
- package/src/core/disk-image/woz_disk_image.cpp +1049 -0
- package/src/core/disk-image/woz_disk_image.hpp +343 -0
- package/src/core/emulator.cpp +2126 -0
- package/src/core/emulator.hpp +434 -0
- package/src/core/filesystem/dos33.cpp +178 -0
- package/src/core/filesystem/dos33.hpp +66 -0
- package/src/core/filesystem/pascal.cpp +262 -0
- package/src/core/filesystem/pascal.hpp +87 -0
- package/src/core/filesystem/prodos.cpp +369 -0
- package/src/core/filesystem/prodos.hpp +119 -0
- package/src/core/input/keyboard.cpp +227 -0
- package/src/core/input/keyboard.hpp +111 -0
- package/src/core/mmu/mmu.cpp +1387 -0
- package/src/core/mmu/mmu.hpp +236 -0
- package/src/core/types.hpp +196 -0
- package/src/core/video/video.cpp +680 -0
- package/src/core/video/video.hpp +156 -0
- package/src/css/assembler-editor.css +1617 -0
- package/src/css/base.css +470 -0
- package/src/css/basic-debugger.css +791 -0
- package/src/css/basic-editor.css +792 -0
- package/src/css/controls.css +783 -0
- package/src/css/cpu-debugger.css +1413 -0
- package/src/css/debug-base.css +160 -0
- package/src/css/debug-windows.css +6455 -0
- package/src/css/disk-drives.css +406 -0
- package/src/css/documentation.css +392 -0
- package/src/css/file-explorer.css +867 -0
- package/src/css/hard-drive.css +180 -0
- package/src/css/layout.css +217 -0
- package/src/css/memory-windows.css +798 -0
- package/src/css/modals.css +510 -0
- package/src/css/monitor.css +425 -0
- package/src/css/release-notes.css +101 -0
- package/src/css/responsive.css +400 -0
- package/src/css/rule-builder.css +340 -0
- package/src/css/save-states.css +201 -0
- package/src/css/settings-windows.css +1231 -0
- package/src/css/window-switcher.css +150 -0
- package/src/js/agent/agent-manager.js +643 -0
- package/src/js/agent/agent-tools.js +293 -0
- package/src/js/agent/agent-version-tools.js +131 -0
- package/src/js/agent/assembler-tools.js +357 -0
- package/src/js/agent/basic-program-tools.js +894 -0
- package/src/js/agent/disk-tools.js +417 -0
- package/src/js/agent/file-explorer-tools.js +269 -0
- package/src/js/agent/index.js +13 -0
- package/src/js/agent/main-tools.js +222 -0
- package/src/js/agent/slot-tools.js +303 -0
- package/src/js/agent/smartport-tools.js +257 -0
- package/src/js/agent/window-tools.js +80 -0
- package/src/js/audio/audio-driver.js +417 -0
- package/src/js/audio/audio-worklet.js +85 -0
- package/src/js/audio/index.js +8 -0
- package/src/js/config/default-layout.js +34 -0
- package/src/js/config/version.js +8 -0
- package/src/js/data/apple2-rom-routines.js +577 -0
- package/src/js/debug/assembler-editor-window.js +2993 -0
- package/src/js/debug/basic-breakpoint-manager.js +529 -0
- package/src/js/debug/basic-program-parser.js +436 -0
- package/src/js/debug/basic-program-window.js +2594 -0
- package/src/js/debug/basic-variable-inspector.js +447 -0
- package/src/js/debug/breakpoint-manager.js +472 -0
- package/src/js/debug/cpu-debugger-window.js +2396 -0
- package/src/js/debug/index.js +22 -0
- package/src/js/debug/label-manager.js +238 -0
- package/src/js/debug/memory-browser-window.js +416 -0
- package/src/js/debug/memory-heat-map-window.js +481 -0
- package/src/js/debug/memory-map-window.js +206 -0
- package/src/js/debug/mockingboard-window.js +882 -0
- package/src/js/debug/mouse-card-window.js +355 -0
- package/src/js/debug/rule-builder-window.js +648 -0
- package/src/js/debug/soft-switch-window.js +458 -0
- package/src/js/debug/stack-viewer-window.js +221 -0
- package/src/js/debug/symbols.js +416 -0
- package/src/js/debug/trace-panel.js +291 -0
- package/src/js/debug/zero-page-watch-window.js +297 -0
- package/src/js/disk-manager/disk-drives-window.js +212 -0
- package/src/js/disk-manager/disk-operations.js +284 -0
- package/src/js/disk-manager/disk-persistence.js +301 -0
- package/src/js/disk-manager/disk-surface-renderer.js +388 -0
- package/src/js/disk-manager/drive-sounds.js +139 -0
- package/src/js/disk-manager/hard-drive-manager.js +481 -0
- package/src/js/disk-manager/hard-drive-persistence.js +187 -0
- package/src/js/disk-manager/hard-drive-window.js +57 -0
- package/src/js/disk-manager/index.js +890 -0
- package/src/js/display/display-settings-window.js +383 -0
- package/src/js/display/index.js +10 -0
- package/src/js/display/screen-window.js +342 -0
- package/src/js/display/webgl-renderer.js +705 -0
- package/src/js/file-explorer/disassembler.js +574 -0
- package/src/js/file-explorer/dos33.js +266 -0
- package/src/js/file-explorer/file-viewer.js +359 -0
- package/src/js/file-explorer/index.js +1261 -0
- package/src/js/file-explorer/prodos.js +549 -0
- package/src/js/file-explorer/utils.js +67 -0
- package/src/js/help/documentation-window.js +1096 -0
- package/src/js/help/index.js +10 -0
- package/src/js/help/release-notes-window.js +85 -0
- package/src/js/help/release-notes.js +612 -0
- package/src/js/input/gamepad-handler.js +176 -0
- package/src/js/input/index.js +12 -0
- package/src/js/input/input-handler.js +396 -0
- package/src/js/input/joystick-window.js +404 -0
- package/src/js/input/mouse-handler.js +99 -0
- package/src/js/input/text-selection.js +462 -0
- package/src/js/main.js +653 -0
- package/src/js/state/index.js +15 -0
- package/src/js/state/save-states-window.js +393 -0
- package/src/js/state/state-manager.js +409 -0
- package/src/js/state/state-persistence.js +218 -0
- package/src/js/ui/confirm.js +43 -0
- package/src/js/ui/disk-drive-positioner.js +347 -0
- package/src/js/ui/reminder-controller.js +129 -0
- package/src/js/ui/slot-configuration-window.js +560 -0
- package/src/js/ui/theme-manager.js +61 -0
- package/src/js/ui/toast.js +44 -0
- package/src/js/ui/ui-controller.js +897 -0
- package/src/js/ui/window-switcher.js +275 -0
- package/src/js/utils/basic-autocomplete.js +832 -0
- package/src/js/utils/basic-highlighting.js +473 -0
- package/src/js/utils/basic-tokenizer.js +153 -0
- package/src/js/utils/basic-tokens.js +117 -0
- package/src/js/utils/constants.js +28 -0
- package/src/js/utils/indexeddb-helper.js +225 -0
- package/src/js/utils/merlin-editor-support.js +905 -0
- package/src/js/utils/merlin-highlighting.js +551 -0
- package/src/js/utils/storage.js +125 -0
- package/src/js/utils/string-utils.js +19 -0
- package/src/js/utils/wasm-memory.js +54 -0
- package/src/js/windows/base-window.js +690 -0
- package/src/js/windows/index.js +9 -0
- package/src/js/windows/window-manager.js +375 -0
- package/tests/catch2/catch.hpp +17976 -0
- package/tests/common/basic_program_builder.cpp +119 -0
- package/tests/common/basic_program_builder.hpp +209 -0
- package/tests/common/disk_image_builder.cpp +444 -0
- package/tests/common/disk_image_builder.hpp +141 -0
- package/tests/common/test_helpers.hpp +118 -0
- package/tests/gcr/gcr-test.cpp +142 -0
- package/tests/integration/check-rom.js +70 -0
- package/tests/integration/compare-boot.js +239 -0
- package/tests/integration/crash-trace.js +102 -0
- package/tests/integration/disk-boot-test.js +264 -0
- package/tests/integration/memory-crash.js +108 -0
- package/tests/integration/nibble-read-test.js +249 -0
- package/tests/integration/phase-test.js +159 -0
- package/tests/integration/test_emulator.cpp +291 -0
- package/tests/integration/test_emulator_basic.cpp +91 -0
- package/tests/integration/test_emulator_debug.cpp +344 -0
- package/tests/integration/test_emulator_disk.cpp +153 -0
- package/tests/integration/test_emulator_state.cpp +163 -0
- package/tests/klaus/6502_functional_test.bin +0 -0
- package/tests/klaus/65C02_extended_opcodes_test.bin +0 -0
- package/tests/klaus/klaus_6502_test.cpp +184 -0
- package/tests/klaus/klaus_65c02_test.cpp +197 -0
- package/tests/thunderclock/thunderclock_mmu_test.cpp +304 -0
- package/tests/thunderclock/thunderclock_test.cpp +550 -0
- package/tests/unit/test_assembler.cpp +521 -0
- package/tests/unit/test_audio.cpp +196 -0
- package/tests/unit/test_ay8910.cpp +311 -0
- package/tests/unit/test_basic_detokenizer.cpp +265 -0
- package/tests/unit/test_basic_tokenizer.cpp +382 -0
- package/tests/unit/test_block_device.cpp +259 -0
- package/tests/unit/test_condition_evaluator.cpp +219 -0
- package/tests/unit/test_cpu6502.cpp +1301 -0
- package/tests/unit/test_cpu_addressing.cpp +361 -0
- package/tests/unit/test_cpu_cycle_counts.cpp +409 -0
- package/tests/unit/test_cpu_decimal.cpp +166 -0
- package/tests/unit/test_cpu_interrupts.cpp +285 -0
- package/tests/unit/test_disassembler.cpp +323 -0
- package/tests/unit/test_disk2_card.cpp +330 -0
- package/tests/unit/test_dos33.cpp +273 -0
- package/tests/unit/test_dsk_disk_image.cpp +315 -0
- package/tests/unit/test_expansion_card.cpp +178 -0
- package/tests/unit/test_gcr_encoding.cpp +232 -0
- package/tests/unit/test_keyboard.cpp +262 -0
- package/tests/unit/test_mmu.cpp +555 -0
- package/tests/unit/test_mmu_slots.cpp +323 -0
- package/tests/unit/test_mockingboard.cpp +352 -0
- package/tests/unit/test_mouse_card.cpp +386 -0
- package/tests/unit/test_pascal.cpp +248 -0
- package/tests/unit/test_prodos.cpp +259 -0
- package/tests/unit/test_smartport_card.cpp +321 -0
- package/tests/unit/test_thunderclock.cpp +354 -0
- package/tests/unit/test_via6522.cpp +323 -0
- package/tests/unit/test_video.cpp +319 -0
- package/tests/unit/test_woz_disk_image.cpp +257 -0
- package/vite.config.js +96 -0
- package/wiki/AI-Agent.md +372 -0
- package/wiki/Architecture-Overview.md +303 -0
- package/wiki/Audio-System.md +449 -0
- package/wiki/CPU-Emulation.md +477 -0
- package/wiki/Debugger.md +516 -0
- package/wiki/Disk-Drives.md +161 -0
- package/wiki/Disk-System-Internals.md +547 -0
- package/wiki/Display-Settings.md +88 -0
- package/wiki/Expansion-Slots.md +187 -0
- package/wiki/File-Explorer.md +259 -0
- package/wiki/Getting-Started.md +156 -0
- package/wiki/Home.md +69 -0
- package/wiki/Input-Devices.md +183 -0
- package/wiki/Keyboard-Shortcuts.md +158 -0
- package/wiki/Memory-System.md +364 -0
- package/wiki/Save-States.md +172 -0
- package/wiki/Video-Rendering.md +658 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* joystick-window.js - Virtual joystick and paddle configuration window
|
|
3
|
+
*
|
|
4
|
+
* Written by
|
|
5
|
+
* Mike Daley <michael_daley@icloud.com>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { BaseWindow } from "../windows/base-window.js";
|
|
9
|
+
|
|
10
|
+
export class JoystickWindow extends BaseWindow {
|
|
11
|
+
constructor(wasmModule) {
|
|
12
|
+
super({
|
|
13
|
+
id: "joystick",
|
|
14
|
+
title: "Joystick",
|
|
15
|
+
defaultWidth: 250,
|
|
16
|
+
defaultHeight: 470,
|
|
17
|
+
minWidth: 250,
|
|
18
|
+
minHeight: 480,
|
|
19
|
+
resizeDirections: [],
|
|
20
|
+
});
|
|
21
|
+
this.wasmModule = wasmModule;
|
|
22
|
+
this.isDraggingKnob = false;
|
|
23
|
+
this.knobX = 0.5; // 0-1 range, 0.5 = center
|
|
24
|
+
this.knobY = 0.5;
|
|
25
|
+
this.button0Pressed = false;
|
|
26
|
+
this.button1Pressed = false;
|
|
27
|
+
this.gamepadHandler = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
renderContent() {
|
|
31
|
+
return `
|
|
32
|
+
<div class="joystick-container">
|
|
33
|
+
<div class="joystick-area-wrapper">
|
|
34
|
+
<span class="joystick-axis-label joystick-axis-l">L</span>
|
|
35
|
+
<span class="joystick-axis-label joystick-axis-r">R</span>
|
|
36
|
+
<span class="joystick-axis-label joystick-axis-u">U</span>
|
|
37
|
+
<span class="joystick-axis-label joystick-axis-d">D</span>
|
|
38
|
+
<div class="joystick-area">
|
|
39
|
+
<div class="joystick-ring joystick-ring-75"></div>
|
|
40
|
+
<div class="joystick-ring joystick-ring-50"></div>
|
|
41
|
+
<div class="joystick-ring joystick-ring-25"></div>
|
|
42
|
+
<div class="joystick-crosshair"></div>
|
|
43
|
+
<div class="joystick-home-dot"></div>
|
|
44
|
+
<div class="joystick-knob"><div class="joystick-knob-highlight"></div></div>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
<div class="joystick-gauges">
|
|
48
|
+
<div class="joystick-gauge-row">
|
|
49
|
+
<span class="joystick-gauge-label">PDL0</span>
|
|
50
|
+
<div class="joystick-gauge-track joystick-gauge-x-track">
|
|
51
|
+
<div class="joystick-gauge-fill joystick-gauge-x-fill"></div>
|
|
52
|
+
</div>
|
|
53
|
+
<span class="joystick-gauge-value joystick-x-value">128</span>
|
|
54
|
+
</div>
|
|
55
|
+
<div class="joystick-gauge-row">
|
|
56
|
+
<span class="joystick-gauge-label">PDL1</span>
|
|
57
|
+
<div class="joystick-gauge-track joystick-gauge-y-track">
|
|
58
|
+
<div class="joystick-gauge-fill joystick-gauge-y-fill"></div>
|
|
59
|
+
</div>
|
|
60
|
+
<span class="joystick-gauge-value joystick-y-value">128</span>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="joystick-buttons">
|
|
64
|
+
<button class="joystick-btn joystick-btn-0" data-button="0">
|
|
65
|
+
<span class="joystick-btn-led"></span>
|
|
66
|
+
<span class="joystick-btn-label">PB0</span>
|
|
67
|
+
</button>
|
|
68
|
+
<button class="joystick-btn joystick-btn-1" data-button="1">
|
|
69
|
+
<span class="joystick-btn-led"></span>
|
|
70
|
+
<span class="joystick-btn-label">PB1</span>
|
|
71
|
+
</button>
|
|
72
|
+
</div>
|
|
73
|
+
<div class="joystick-center-btn-container">
|
|
74
|
+
<button class="joystick-center-btn" title="Center (reset to 128,128)">⌖</button>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="gamepad-section">
|
|
77
|
+
<div class="gamepad-status-row">
|
|
78
|
+
<label class="gamepad-toggle-label">
|
|
79
|
+
<div class="gamepad-toggle-switch">
|
|
80
|
+
<input type="checkbox" class="gamepad-toggle" />
|
|
81
|
+
<span class="gamepad-toggle-slider"></span>
|
|
82
|
+
</div>
|
|
83
|
+
<span class="gamepad-toggle-text">Gamepad</span>
|
|
84
|
+
</label>
|
|
85
|
+
<span class="gamepad-status"><span class="gamepad-status-dot"></span><span class="gamepad-status-text">No controller</span></span>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="gamepad-deadzone-row">
|
|
88
|
+
<span class="gamepad-deadzone-label">Deadzone</span>
|
|
89
|
+
<input type="range" class="gamepad-deadzone-slider" min="0" max="50" step="1" value="10" />
|
|
90
|
+
<span class="gamepad-deadzone-value">0.10</span>
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
onContentRendered() {
|
|
98
|
+
this.joystickArea = this.contentElement.querySelector(".joystick-area");
|
|
99
|
+
this.knobElement = this.contentElement.querySelector(".joystick-knob");
|
|
100
|
+
this.xValueSpan = this.contentElement.querySelector(".joystick-x-value");
|
|
101
|
+
this.yValueSpan = this.contentElement.querySelector(".joystick-y-value");
|
|
102
|
+
this.xGaugeFill = this.contentElement.querySelector(
|
|
103
|
+
".joystick-gauge-x-fill",
|
|
104
|
+
);
|
|
105
|
+
this.yGaugeFill = this.contentElement.querySelector(
|
|
106
|
+
".joystick-gauge-y-fill",
|
|
107
|
+
);
|
|
108
|
+
this.button0Element = this.contentElement.querySelector(".joystick-btn-0");
|
|
109
|
+
this.button1Element = this.contentElement.querySelector(".joystick-btn-1");
|
|
110
|
+
this.centerBtn = this.contentElement.querySelector(".joystick-center-btn");
|
|
111
|
+
|
|
112
|
+
// Gamepad UI elements
|
|
113
|
+
this.gamepadToggle = this.contentElement.querySelector(".gamepad-toggle");
|
|
114
|
+
this.gamepadStatusText = this.contentElement.querySelector(
|
|
115
|
+
".gamepad-status-text",
|
|
116
|
+
);
|
|
117
|
+
this.gamepadStatusDot = this.contentElement.querySelector(
|
|
118
|
+
".gamepad-status-dot",
|
|
119
|
+
);
|
|
120
|
+
this.gamepadDeadzoneSlider = this.contentElement.querySelector(
|
|
121
|
+
".gamepad-deadzone-slider",
|
|
122
|
+
);
|
|
123
|
+
this.gamepadDeadzoneValue = this.contentElement.querySelector(
|
|
124
|
+
".gamepad-deadzone-value",
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
this.setupJoystickEventListeners();
|
|
128
|
+
this.setupGamepadEventListeners();
|
|
129
|
+
this.updateKnobPosition();
|
|
130
|
+
this.updatePaddleValues();
|
|
131
|
+
|
|
132
|
+
// Watch for resize and update knob position
|
|
133
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
134
|
+
this.updateKnobPosition();
|
|
135
|
+
});
|
|
136
|
+
this.resizeObserver.observe(this.joystickArea);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
setupJoystickEventListeners() {
|
|
140
|
+
// Knob dragging
|
|
141
|
+
this.knobElement.addEventListener("mousedown", (e) => {
|
|
142
|
+
this.isDraggingKnob = true;
|
|
143
|
+
this.knobElement.classList.add("dragging");
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Also start drag when clicking anywhere in the joystick area
|
|
149
|
+
this.joystickArea.addEventListener("mousedown", (e) => {
|
|
150
|
+
if (
|
|
151
|
+
e.target === this.joystickArea ||
|
|
152
|
+
e.target.classList.contains("joystick-crosshair") ||
|
|
153
|
+
e.target.classList.contains("joystick-ring") ||
|
|
154
|
+
e.target.classList.contains("joystick-home-dot")
|
|
155
|
+
) {
|
|
156
|
+
this.isDraggingKnob = true;
|
|
157
|
+
this.knobElement.classList.add("dragging");
|
|
158
|
+
this.updateKnobFromMouse(e);
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
document.addEventListener("mousemove", (e) => {
|
|
164
|
+
if (this.isDraggingKnob) {
|
|
165
|
+
this.updateKnobFromMouse(e);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
document.addEventListener("mouseup", () => {
|
|
170
|
+
if (this.isDraggingKnob) {
|
|
171
|
+
this.isDraggingKnob = false;
|
|
172
|
+
this.knobElement.classList.remove("dragging");
|
|
173
|
+
// Snap back to center when released
|
|
174
|
+
this.knobX = 0.5;
|
|
175
|
+
this.knobY = 0.5;
|
|
176
|
+
this.updateKnobPosition();
|
|
177
|
+
this.updatePaddleValues();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Button handling with mousedown/mouseup for proper hold behavior
|
|
182
|
+
this.button0Element.addEventListener("mousedown", () => {
|
|
183
|
+
this.button0Pressed = true;
|
|
184
|
+
this.button0Element.classList.add("pressed");
|
|
185
|
+
this.wasmModule._setButton(0, true);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
this.button0Element.addEventListener("mouseup", () => {
|
|
189
|
+
this.button0Pressed = false;
|
|
190
|
+
this.button0Element.classList.remove("pressed");
|
|
191
|
+
this.wasmModule._setButton(0, false);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
this.button0Element.addEventListener("mouseleave", () => {
|
|
195
|
+
if (this.button0Pressed) {
|
|
196
|
+
this.button0Pressed = false;
|
|
197
|
+
this.button0Element.classList.remove("pressed");
|
|
198
|
+
this.wasmModule._setButton(0, false);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
this.button1Element.addEventListener("mousedown", () => {
|
|
203
|
+
this.button1Pressed = true;
|
|
204
|
+
this.button1Element.classList.add("pressed");
|
|
205
|
+
this.wasmModule._setButton(1, true);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
this.button1Element.addEventListener("mouseup", () => {
|
|
209
|
+
this.button1Pressed = false;
|
|
210
|
+
this.button1Element.classList.remove("pressed");
|
|
211
|
+
this.wasmModule._setButton(1, false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
this.button1Element.addEventListener("mouseleave", () => {
|
|
215
|
+
if (this.button1Pressed) {
|
|
216
|
+
this.button1Pressed = false;
|
|
217
|
+
this.button1Element.classList.remove("pressed");
|
|
218
|
+
this.wasmModule._setButton(1, false);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Center button
|
|
223
|
+
this.centerBtn.addEventListener("click", () => {
|
|
224
|
+
this.knobX = 0.5;
|
|
225
|
+
this.knobY = 0.5;
|
|
226
|
+
this.updateKnobPosition();
|
|
227
|
+
this.updatePaddleValues();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
updateKnobFromMouse(e) {
|
|
232
|
+
const rect = this.joystickArea.getBoundingClientRect();
|
|
233
|
+
const centerX = rect.left + rect.width / 2;
|
|
234
|
+
const centerY = rect.top + rect.height / 2;
|
|
235
|
+
const radius = Math.min(rect.width, rect.height) / 2;
|
|
236
|
+
|
|
237
|
+
// Calculate offset from center
|
|
238
|
+
let dx = e.clientX - centerX;
|
|
239
|
+
let dy = e.clientY - centerY;
|
|
240
|
+
|
|
241
|
+
// Clamp to circle
|
|
242
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
243
|
+
if (dist > radius) {
|
|
244
|
+
dx = (dx / dist) * radius;
|
|
245
|
+
dy = (dy / dist) * radius;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Convert to 0-1 range
|
|
249
|
+
this.knobX = Math.max(0, Math.min(1, 0.5 + dx / (radius * 2)));
|
|
250
|
+
this.knobY = Math.max(0, Math.min(1, 0.5 + dy / (radius * 2)));
|
|
251
|
+
|
|
252
|
+
this.updateKnobPosition();
|
|
253
|
+
this.updatePaddleValues();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
updateKnobPosition() {
|
|
257
|
+
if (!this.joystickArea || !this.knobElement) return;
|
|
258
|
+
|
|
259
|
+
const rect = this.joystickArea.getBoundingClientRect();
|
|
260
|
+
const knobSize = 28;
|
|
261
|
+
const areaSize = Math.min(rect.width, rect.height);
|
|
262
|
+
const radius = areaSize / 2;
|
|
263
|
+
const offsetX = (rect.width - areaSize) / 2;
|
|
264
|
+
const offsetY = (rect.height - areaSize) / 2;
|
|
265
|
+
|
|
266
|
+
// Convert 0-1 to position within the circular area
|
|
267
|
+
const cx = offsetX + radius + (this.knobX - 0.5) * areaSize;
|
|
268
|
+
const cy = offsetY + radius + (this.knobY - 0.5) * areaSize;
|
|
269
|
+
|
|
270
|
+
this.knobElement.style.left = `${cx - knobSize / 2}px`;
|
|
271
|
+
this.knobElement.style.top = `${cy - knobSize / 2}px`;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
updatePaddleValues() {
|
|
275
|
+
// Convert 0-1 range to 0-255 for paddle values
|
|
276
|
+
const paddleX = Math.round(this.knobX * 255);
|
|
277
|
+
const paddleY = Math.round(this.knobY * 255);
|
|
278
|
+
|
|
279
|
+
// Update display
|
|
280
|
+
if (this.xValueSpan) this.xValueSpan.textContent = paddleX.toString();
|
|
281
|
+
if (this.yValueSpan) this.yValueSpan.textContent = paddleY.toString();
|
|
282
|
+
|
|
283
|
+
// Update gauge bars
|
|
284
|
+
const pctX = (paddleX / 255) * 100;
|
|
285
|
+
const pctY = (paddleY / 255) * 100;
|
|
286
|
+
if (this.xGaugeFill) this.xGaugeFill.style.width = `${pctX}%`;
|
|
287
|
+
if (this.yGaugeFill) this.yGaugeFill.style.width = `${pctY}%`;
|
|
288
|
+
|
|
289
|
+
// Send to emulator
|
|
290
|
+
if (this.wasmModule._setPaddleValue) {
|
|
291
|
+
this.wasmModule._setPaddleValue(0, paddleX);
|
|
292
|
+
this.wasmModule._setPaddleValue(1, paddleY);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
setupGamepadEventListeners() {
|
|
297
|
+
if (this.gamepadToggle) {
|
|
298
|
+
// Restore persisted state
|
|
299
|
+
const enabled = localStorage.getItem("gamepad-enabled") !== "false";
|
|
300
|
+
this.gamepadToggle.checked = enabled;
|
|
301
|
+
|
|
302
|
+
this.gamepadToggle.addEventListener("change", () => {
|
|
303
|
+
if (this.gamepadHandler) {
|
|
304
|
+
this.gamepadHandler.setEnabled(this.gamepadToggle.checked);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (this.gamepadDeadzoneSlider) {
|
|
310
|
+
// Restore persisted deadzone
|
|
311
|
+
const dz = parseFloat(localStorage.getItem("gamepad-deadzone")) || 0.1;
|
|
312
|
+
this.gamepadDeadzoneSlider.value = Math.round(dz * 100);
|
|
313
|
+
this.gamepadDeadzoneValue.textContent = dz.toFixed(2);
|
|
314
|
+
|
|
315
|
+
this.gamepadDeadzoneSlider.addEventListener("input", () => {
|
|
316
|
+
const value = this.gamepadDeadzoneSlider.value / 100;
|
|
317
|
+
this.gamepadDeadzoneValue.textContent = value.toFixed(2);
|
|
318
|
+
if (this.gamepadHandler) {
|
|
319
|
+
this.gamepadHandler.setDeadzone(value);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Called by GamepadHandler to move the knob from external input.
|
|
327
|
+
* @param {number} normX - 0..1 position
|
|
328
|
+
* @param {number} normY - 0..1 position
|
|
329
|
+
*/
|
|
330
|
+
setExternalPosition(normX, normY) {
|
|
331
|
+
this.knobX = normX;
|
|
332
|
+
this.knobY = normY;
|
|
333
|
+
this.updateKnobPosition();
|
|
334
|
+
|
|
335
|
+
// Update value display and gauge bars (paddle values set by GamepadHandler)
|
|
336
|
+
const paddleX = Math.round(normX * 255);
|
|
337
|
+
const paddleY = Math.round(normY * 255);
|
|
338
|
+
if (this.xValueSpan) this.xValueSpan.textContent = paddleX.toString();
|
|
339
|
+
if (this.yValueSpan) this.yValueSpan.textContent = paddleY.toString();
|
|
340
|
+
|
|
341
|
+
const pctX = (paddleX / 255) * 100;
|
|
342
|
+
const pctY = (paddleY / 255) * 100;
|
|
343
|
+
if (this.xGaugeFill) this.xGaugeFill.style.width = `${pctX}%`;
|
|
344
|
+
if (this.yGaugeFill) this.yGaugeFill.style.width = `${pctY}%`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Called by GamepadHandler to reflect physical button state in the UI.
|
|
349
|
+
* @param {number} button - 0 or 1
|
|
350
|
+
* @param {boolean} pressed
|
|
351
|
+
*/
|
|
352
|
+
setExternalButton(button, pressed) {
|
|
353
|
+
const el = button === 0 ? this.button0Element : this.button1Element;
|
|
354
|
+
if (!el) return;
|
|
355
|
+
if (pressed) {
|
|
356
|
+
el.classList.add("pressed");
|
|
357
|
+
} else {
|
|
358
|
+
el.classList.remove("pressed");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Called by GamepadHandler when connection state changes.
|
|
364
|
+
* @param {string|null} name - Controller name or null if disconnected
|
|
365
|
+
* @param {boolean} enabled - Whether gamepad input is enabled
|
|
366
|
+
*/
|
|
367
|
+
updateGamepadStatus(name, enabled) {
|
|
368
|
+
if (this.gamepadStatusText) {
|
|
369
|
+
this.gamepadStatusText.textContent = name
|
|
370
|
+
? name.substring(0, 30)
|
|
371
|
+
: "No controller";
|
|
372
|
+
}
|
|
373
|
+
if (this.gamepadStatusDot) {
|
|
374
|
+
this.gamepadStatusDot.classList.toggle("connected", !!name);
|
|
375
|
+
}
|
|
376
|
+
if (this.gamepadToggle) {
|
|
377
|
+
this.gamepadToggle.checked = enabled;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
update(wasmModule) {
|
|
382
|
+
// No periodic update needed - values are set directly on drag
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
getState() {
|
|
386
|
+
const baseState = super.getState();
|
|
387
|
+
return {
|
|
388
|
+
...baseState,
|
|
389
|
+
knobX: this.knobX,
|
|
390
|
+
knobY: this.knobY,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
restoreState(state) {
|
|
395
|
+
super.restoreState(state);
|
|
396
|
+
if (state.knobX !== undefined) this.knobX = state.knobX;
|
|
397
|
+
if (state.knobY !== undefined) this.knobY = state.knobY;
|
|
398
|
+
// Update visuals after restoring
|
|
399
|
+
if (this.knobElement) {
|
|
400
|
+
this.updateKnobPosition();
|
|
401
|
+
this.updatePaddleValues();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* mouse-handler.js - Mouse input handling via Pointer Lock API
|
|
3
|
+
*
|
|
4
|
+
* Written by
|
|
5
|
+
* Mike Daley <michael_daley@icloud.com>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* MouseHandler - Browser mouse capture for Apple Mouse Interface Card
|
|
10
|
+
*
|
|
11
|
+
* Uses the Pointer Lock API to capture mouse movement and send deltas
|
|
12
|
+
* to the WASM emulator. Click on the canvas to engage pointer lock;
|
|
13
|
+
* press Escape to release it (browser default behavior).
|
|
14
|
+
*/
|
|
15
|
+
export class MouseHandler {
|
|
16
|
+
constructor(wasmModule) {
|
|
17
|
+
this.wasmModule = wasmModule;
|
|
18
|
+
this.canvas = null;
|
|
19
|
+
this.enabled = false;
|
|
20
|
+
this.locked = false;
|
|
21
|
+
|
|
22
|
+
this._onMouseMove = this._onMouseMove.bind(this);
|
|
23
|
+
this._onMouseDown = this._onMouseDown.bind(this);
|
|
24
|
+
this._onMouseUp = this._onMouseUp.bind(this);
|
|
25
|
+
this._onPointerLockChange = this._onPointerLockChange.bind(this);
|
|
26
|
+
this._onCanvasClick = this._onCanvasClick.bind(this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
init() {
|
|
30
|
+
this.canvas = document.getElementById("screen");
|
|
31
|
+
if (!this.canvas) return;
|
|
32
|
+
|
|
33
|
+
document.addEventListener("pointerlockchange", this._onPointerLockChange);
|
|
34
|
+
|
|
35
|
+
this.canvas.addEventListener("click", this._onCanvasClick);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
enable() {
|
|
39
|
+
this.enabled = true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
disable() {
|
|
43
|
+
this.enabled = false;
|
|
44
|
+
if (this.locked) {
|
|
45
|
+
document.exitPointerLock();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_onCanvasClick(event) {
|
|
50
|
+
if (!this.enabled || this.locked) return;
|
|
51
|
+
if (!event.altKey) return;
|
|
52
|
+
this.canvas.requestPointerLock();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_onPointerLockChange() {
|
|
56
|
+
if (document.pointerLockElement === this.canvas) {
|
|
57
|
+
this.locked = true;
|
|
58
|
+
document.addEventListener("mousemove", this._onMouseMove);
|
|
59
|
+
document.addEventListener("mousedown", this._onMouseDown);
|
|
60
|
+
document.addEventListener("mouseup", this._onMouseUp);
|
|
61
|
+
} else {
|
|
62
|
+
this.locked = false;
|
|
63
|
+
document.removeEventListener("mousemove", this._onMouseMove);
|
|
64
|
+
document.removeEventListener("mousedown", this._onMouseDown);
|
|
65
|
+
document.removeEventListener("mouseup", this._onMouseUp);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_onMouseMove(event) {
|
|
70
|
+
if (!this.enabled || !this.locked) return;
|
|
71
|
+
const dx = event.movementX;
|
|
72
|
+
const dy = event.movementY;
|
|
73
|
+
if (dx !== 0 || dy !== 0) {
|
|
74
|
+
this.wasmModule._mouseMove(dx, dy);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_onMouseDown(event) {
|
|
79
|
+
if (!this.enabled || !this.locked) return;
|
|
80
|
+
if (event.button === 0) {
|
|
81
|
+
this.wasmModule._mouseButton(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_onMouseUp(event) {
|
|
86
|
+
if (!this.enabled || !this.locked) return;
|
|
87
|
+
if (event.button === 0) {
|
|
88
|
+
this.wasmModule._mouseButton(0);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
destroy() {
|
|
93
|
+
this.disable();
|
|
94
|
+
document.removeEventListener("pointerlockchange", this._onPointerLockChange);
|
|
95
|
+
if (this.canvas) {
|
|
96
|
+
this.canvas.removeEventListener("click", this._onCanvasClick);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|