Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
2a9a029
Add VSCode debugger MVP for 6502 machine code
highbyte Jan 23, 2026
a2249a2
Add MVP completion summary document
highbyte Jan 23, 2026
02da856
Fix extension testing documentation and add VSCode config
highbyte Jan 23, 2026
9a3ff99
Add test program build script and quick test guide
highbyte Jan 23, 2026
769b88c
Add separate test workspace to avoid confusion
highbyte Jan 23, 2026
3f2c963
Remove redundant test files from vscode-extension folder
highbyte Jan 23, 2026
b511666
Improve stack frame handling and add known issues doc
highbyte Jan 23, 2026
a8fc474
WIP: Disassembly view padding for DAP instruction count requirement
highbyte Jan 24, 2026
7fc2cf8
Refactored from scratch. Now mostly working, scrolling to correct pos…
highbyte Jan 24, 2026
1e36157
Testing some other fix. Still mostly working, scrolling to correct p…
highbyte Jan 24, 2026
a308585
Add doc
highbyte Jan 24, 2026
01287ee
Move the vscode extension code and tests to tools folder.
highbyte Jan 29, 2026
297ca18
Add logging and docs
highbyte Jan 29, 2026
a7cb953
Test using cc65 as assembler and update example .asm format and assem…
highbyte Jan 29, 2026
9cc5382
Make .asm build script work on Windows, MacOS, Linux.
highbyte Jan 30, 2026
3e80d9f
WIP: .asm source level debugging with the VSCode extension
highbyte Jan 30, 2026
101b8d9
Add support for source debugging using .bin program without two byte …
highbyte Jan 30, 2026
8b21e4b
Add memory inspection to VSCode extension
highbyte Jan 30, 2026
787ccad
Add info on how to debug the .NET Code in the emulator while debuggi…
highbyte Jan 30, 2026
642d5e9
Handle PC outside assembly source code.
highbyte Jan 30, 2026
ae3aa97
Example how to auto build via VSCode build task before launching debu…
highbyte Jan 30, 2026
1d2a0af
Tweak VSCode extension provide a built-in build task for C64 that can…
highbyte Feb 1, 2026
767ac1a
Tweak test assembly
highbyte Feb 1, 2026
ad34e62
Add task and launch configuration generation.
highbyte Feb 1, 2026
f2642ca
Cleanup
highbyte Feb 1, 2026
3c372bf
Fix breakpoints no longer working in VSCode extension
highbyte Feb 2, 2026
bfddb7f
Fix stepping outside .asm source locations doesn't clear Variables ea…
highbyte Feb 2, 2026
81bc511
Add doc
highbyte Feb 2, 2026
b2c8b93
Minor fixes
highbyte Feb 2, 2026
a984ce6
Add a VSCode debug console repl command for memory dump
highbyte Feb 2, 2026
d109791
Add VSCode custom memory viewer document
highbyte Feb 2, 2026
3539e05
Tweak memory inspection editor tab.
highbyte Feb 2, 2026
39a462f
Refactor core VSCode adapter logic to a library.
highbyte Feb 2, 2026
064b0a2
WIP: Add TCP protocol support for VSCode debugger adapter. Test inte…
highbyte Feb 2, 2026
e38eb12
Fix VSCode debugger able to continue with F5 after first breakpoint.
highbyte Feb 3, 2026
c01b82d
Allow Avalonia desktop app to accept incoming debugger sessions anytime.
highbyte Feb 3, 2026
8123e71
Formatting
highbyte Feb 3, 2026
8b46ee5
Refactor .NET tcp debug server to separate class.
highbyte Feb 3, 2026
aa23429
Avalonia debugger adapter tweaks
highbyte Feb 3, 2026
60e3929
Show status message when external debugger is attached to Avalonia app.
highbyte Feb 3, 2026
7017b05
WIP: Fix launch debug from VSCode
highbyte Feb 5, 2026
9f5815d
Enable debugging the VSCode debugger adapter in the Avalonia desktop …
highbyte Feb 6, 2026
b1d1e3e
Fix threading problem in TcpDebugServerManager
highbyte Feb 6, 2026
5e1db94
Fix so TCP debugger adapter is enabled after system has booted an .pr…
highbyte Feb 6, 2026
0320924
WIP: Refactor vscode-debugger for more common use case not tied to Av…
highbyte Feb 8, 2026
cdc0f62
VSCode debugger StopOnEntry hack
highbyte Feb 8, 2026
8bb036e
Disable F12 (toggle monitor) in Avalonia Desktop app when external de…
highbyte Feb 9, 2026
0d80dae
Fix step over debugging from VSCode to automatically detect JSR and c…
highbyte Feb 9, 2026
08ca3ba
Minor fix
highbyte Feb 9, 2026
ce18689
Fix regression after changing .NET console debug adapter executable n…
highbyte Feb 9, 2026
cdb079e
Added VSCode extension parameter debugAdapter and removed others.
highbyte Feb 9, 2026
f8d4d13
Make VSCode extension parameters more uniform
highbyte Feb 9, 2026
6a9fae9
Tweak example launch configs
highbyte Feb 9, 2026
5619eb4
If debugging binary program files without .asm source file.
highbyte Feb 9, 2026
716c608
Fix pausing in VSCode debugger extension
highbyte Feb 9, 2026
a2a1a4e
Remove dead code
highbyte Feb 10, 2026
f1a9cec
Fix connection/disconnection in .NET debug adapter
highbyte Feb 10, 2026
98a1058
Fix so stopping debugging from VSCode now only takes one button press…
highbyte Feb 10, 2026
1b5794c
Change attach mode to work similar to launch regarding TCP connection.
highbyte Feb 10, 2026
ce159ed
Update doc
highbyte Feb 10, 2026
ae54515
Make it possible to use VSCode debug extension to debug startup of em…
highbyte Feb 10, 2026
0620842
Make it possible to debug from first instruction
highbyte Feb 10, 2026
ea0cf8d
Update examples
highbyte Feb 11, 2026
f64cf61
Tweak build tasks
highbyte Feb 11, 2026
c7e8e81
Fix build tasks
highbyte Feb 11, 2026
bad275e
Revert task
highbyte Feb 11, 2026
d7501c1
Tweak docs
highbyte Feb 12, 2026
dfb671e
Improve VSCode extension parsing and edit of launch.json and tasks.json
highbyte Feb 12, 2026
3f19f14
Add new auto generation options for launch configurations
highbyte Feb 12, 2026
db7ef40
Move example code
highbyte Feb 12, 2026
9c18089
Fix source debugging breakpoints
highbyte Feb 12, 2026
d9774f9
Fix source debugging between multiple .asm files.
highbyte Feb 12, 2026
1d6197e
Try to fix disassembly view breakpoint toggle on/off behavior.
highbyte Feb 12, 2026
721d9b8
Rebuild example
highbyte Feb 12, 2026
4eeac69
Change default TCP debug port
highbyte Feb 13, 2026
a7976af
Stop launched debug host after stopping debugging.
highbyte Feb 13, 2026
bef8b08
Fix simple debug host execution
highbyte Feb 13, 2026
9c728f7
Make it possible to attach debugger before emulator is started.
highbyte Feb 15, 2026
19bf63e
Add attach parameter warnings
highbyte Feb 15, 2026
7402032
Move most logic for handling automatic startup in combination with de…
highbyte Feb 15, 2026
1a65486
Change to check for breakpoints (and other possible ExecEval implemen…
highbyte Feb 16, 2026
f395f06
Fix stepping with VSCode debug adapter to run the instruction through…
highbyte Feb 16, 2026
8d8b277
Fix debug adapter Attach logic to be able to derive .dbg and .prg fro…
highbyte Feb 16, 2026
6583e47
Add support for symbols in the cc65 .dbg file in the VSCode debug ada…
highbyte Feb 16, 2026
a01c67a
VSCode debug extension: Add after-line decoration with address in .as…
highbyte Feb 16, 2026
02567bf
VSCode debug adapter: fix showing after-line address decoration dyn…
highbyte Feb 16, 2026
b667c60
Handle immediate mode values as numbers and not addresses in the VSCo…
highbyte Feb 17, 2026
d90265f
Make stopping emulator disconnect VSCode debugger in attach mode, and…
highbyte Feb 17, 2026
0c276b6
VSCode extension: Enable setting memory location values in watch, la…
highbyte Feb 17, 2026
6b69566
Detect labels of different types depending on source directives (.cod…
highbyte Feb 17, 2026
d311a58
Use section directives
highbyte Feb 17, 2026
7ba377c
Fix intermittent TCP connection issue
highbyte Feb 17, 2026
7ee700b
Lower timeout for TCP connection when using attach mode.
highbyte Feb 17, 2026
1c59b51
Change deriving source file base directory from location of .prg file…
highbyte Feb 18, 2026
16d4b4d
Fix source debugging issue with complex .dbg files.
highbyte Feb 18, 2026
a08824a
Make it possible to use "stopOnEntry": true with VSCode "attach" debu…
highbyte Feb 18, 2026
47b2f0f
Fix source debug filename case issue.
highbyte Feb 18, 2026
571ef6f
Add VSCode debug parameter dbgFiles that can specify extra .dbg files.
highbyte Feb 18, 2026
e0927ed
Fix bug in macro detection.
highbyte Feb 18, 2026
8510cab
Remove .claude
highbyte Feb 18, 2026
b75b11c
Make sure VSCode refreshes/invalidates after PC is changed
highbyte Feb 19, 2026
733faa3
Add function to jump to line in VSCode emulator.
highbyte Feb 19, 2026
6032af0
Update VSCode extension readme
highbyte Feb 19, 2026
86ac53a
Fix doc
highbyte Feb 19, 2026
81724ef
Replace spin-wait loops with TaskCompletionSource
highbyte Feb 19, 2026
2190a3c
Refactot OnClientConnected method to separate functions to reduce com…
highbyte Feb 23, 2026
ad01dba
Update doc
highbyte Feb 23, 2026
013baa1
Refactor StdioTransport and TcpTransport to reduce code duplication. …
highbyte Feb 23, 2026
21e61a8
Simplify HandleDisassembleAsync method
highbyte Feb 23, 2026
ec78235
Move external debugging-related members from AvaloniaHostApp to a new…
highbyte Feb 23, 2026
d50818a
Refactor TcpDebugServerManager class from being Avalonia-specific to …
highbyte Feb 23, 2026
c0b7368
Simplify and clean up DebugAdapterLogic
highbyte Feb 23, 2026
b8b5744
Handle debugger disconnect and reconnect state.
highbyte Feb 23, 2026
450276c
Refactor breakpoint handling in built-in debugger/monitor and the ext…
highbyte Feb 23, 2026
3f994d0
Clean up Disassembly debug view
highbyte Feb 24, 2026
0c9db78
Support setting breakpoints manually for Disassembly view.
highbyte Feb 24, 2026
69ed00e
Add support for conditional breakpoints in VSCode debugger.
highbyte Feb 24, 2026
0103037
Update doc
highbyte Feb 24, 2026
01585b9
Cleanup
highbyte Feb 24, 2026
8f9b2d3
Skip stepping into interrupt requests by default (if not in included …
highbyte Feb 24, 2026
d26db17
Add log message support for break points
highbyte Feb 24, 2026
c1d7162
Add support for hit count and hit conditions break points.
highbyte Feb 24, 2026
933fb9a
Add source level stepping over macros.
highbyte Feb 24, 2026
0e0328e
Update docs
highbyte Mar 2, 2026
eb9a0b3
Update docs
highbyte Mar 2, 2026
8dbb9ba
Make AutomatedStartupHandler reusable from other host apps.
highbyte Mar 2, 2026
da6e4cd
Add abstraction for checking if a system is ready.
highbyte Mar 2, 2026
0516916
Fix possible race condition when waiting for Avalonia host app to be …
highbyte Mar 2, 2026
8405668
Update docs
highbyte Mar 2, 2026
882f58a
Update doc
highbyte Mar 2, 2026
dd7c1a7
Cleanup
highbyte Mar 2, 2026
9fb5f4e
Fix typo
highbyte Mar 2, 2026
e750bbc
When paused, still show last frame of emulator screen.
highbyte Mar 2, 2026
4b5f4ea
Only allow built-in monitor to open when running.
highbyte Mar 2, 2026
6e1c950
Fix VSCode extension auto-detect of .prg and .dbg file paths from pre…
highbyte Mar 3, 2026
49a42fc
Add Avalonia UI (desktop) option in UI to toggle debug server on/off …
highbyte Mar 3, 2026
6cc373c
Fix debug server logging
highbyte Mar 3, 2026
4d60679
Update doc
highbyte Mar 3, 2026
3b72702
Fix Windows console log window issue when used from VSCode extension.
highbyte Mar 3, 2026
846c161
Improve debug adapter logging
highbyte Mar 3, 2026
f556494
Pause audio when in VSCode debugger
highbyte Mar 4, 2026
247ff4d
Fix pause sometimes not showing latest rendered frame on Mac.
highbyte Mar 4, 2026
84c8439
Fix potential arbitrary OS command injection vulnerability when start…
highbyte Mar 4, 2026
fbb1478
Reduce code duplication in extension.ts.
highbyte Mar 4, 2026
3471d89
Tweak launch config generation
highbyte Mar 4, 2026
18bad37
Tweak build task working folder.
highbyte Mar 4, 2026
93526a9
Fix view bug
highbyte Mar 4, 2026
7933016
Update doc
highbyte Mar 4, 2026
ebb2bc5
Fix Benchmark project compilation error.
highbyte Mar 5, 2026
39971be
Fix tests
highbyte Mar 5, 2026
5b11985
Fix functional 6502 test to also work on Mac and Linux.
highbyte Mar 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,48 @@
"console": "integratedTerminal",
"stopAtEntry": false
},
{
"name": "Avalonia desktop app with TCP debug server",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build avalonia desktop app",
"program": "${workspaceFolder}/src/apps/Avalonia/Highbyte.DotNet6502.App.Avalonia.Desktop/bin/Debug/net10.0/Highbyte.DotNet6502.App.Avalonia.Desktop.dll",
"args": ["--enableExternalDebug", "--debug-port", "6502", "--console-log", "-l", "Debug"],
"cwd": "${workspaceFolder}/src/apps/Avalonia/Highbyte.DotNet6502.App.Avalonia.Desktop/bin/Debug/net10.0",
"console": "integratedTerminal",
"stopAtEntry": false
},
{
"name": "Avalonia desktop app with auto starting C64, loading specified program, and enable TCP debug server",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build avalonia desktop app",
"program": "${workspaceFolder}/src/apps/Avalonia/Highbyte.DotNet6502.App.Avalonia.Desktop/bin/Debug/net10.0/Highbyte.DotNet6502.App.Avalonia.Desktop.dll",
"args": ["--system", "C64", "--start", "--waitForSystemReady", "--loadPrg", "~/source/repos/dotnet-6502/samples/Assembler/C64/Raster/Build/smooth_scroller_and_raster.prg", "--runLoadedProgram", "--enableExternalDebug", "--debug-port", "6502", "--console-log", "-l", "Debug"],
"cwd": "${workspaceFolder}/src/apps/Avalonia/Highbyte.DotNet6502.App.Avalonia.Desktop/bin/Debug/net10.0",
"console": "integratedTerminal",
"stopAtEntry": false
},

{
"name": "C#: Highbyte.DotNet6502.App.Avalonia.Browser",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/src/apps/Avalonia/Highbyte.DotNet6502.App.Avalonia.Browser/Highbyte.DotNet6502.App.Avalonia.Browser.csproj",
"launchConfigurationId": "TargetFramework=;Avalonia.Browser"
},
{
"name": "Attach to Avalonia desktop app",
"type": "coreclr",
"request": "attach",
"processName": "Highbyte.DotNet6502.App.Avalonia.Desktop"
},
{
"name": "Attach to DotNet6502 VSCode Debug Adapter ConsoleApp",
"type": "coreclr",
"request": "attach",
"processName": "Highbyte.DotNet6502.DebugAdapter.ConsoleApp"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
Expand Down
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@
"isDefault": true
}
},
{
"label": "build simple debug adapter console host",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/apps/Highbyte.DotNet6502.DebugAdapter/Highbyte.DotNet6502.DebugAdapter.ConsoleApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"command": "dotnet",
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<PackageVersion Include="SkiaSharp.Views.Blazor" Version="3.119.1" />
<!-- SourceLink -->
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<!-- StreamJsonRpc for Debug Adapter Protocol -->
<PackageVersion Include="StreamJsonRpc" Version="2.19.27" />
<!-- System packages -->
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Net.Http.Json" Version="10.0.0" />
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@

See [Desktop Apps](doc/DESKTOP_APPS.md) for download links for pre-built executables and instructions for Windows, Linux, and macOS.

## VS Code debugger extension

| [VSCode source debugging](tools/vscode-extension/README.md)| [VSCode disassembly debugging](tools/vscode-extension/README.md) |
| ----------------------------------------------- | ------------------------------------------------- |
| <img src="doc/Screenshots/VSCode_source_debug.png" title="VSCode source debug"/> | <img src="doc/Screenshots/VSCode_disassembly_debug.png" title="VSCode disassembly debug"/> |

## Other features

| [Run 6502 machine code in your own .NET apps](doc/CPU_LIBRARY.md) | [Machine code monitor](doc/MONITOR.md) | [C64 Basic AI code completion](doc/SYSTEMS_C64_AI_CODE_COMPLETION.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Jobs;
using Highbyte.DotNet6502.Systems;
using Highbyte.DotNet6502.Systems.Commodore64;
Expand All @@ -17,8 +16,6 @@ public class C64ExecuteFrameBenchmark
{
private C64 _c64WithInstrumentation = default!;
private C64 _c64WithoutInstrumentation = default!;
private SystemRunner _systemRunnerWithInstrumentation = default!;
private SystemRunner _systemRunnerWithoutInstrumentation = default!;
private ushort _startAddress;

[Params(1)]
Expand Down Expand Up @@ -50,8 +47,6 @@ public void Setup()
LoadProgram(_c64WithInstrumentation.Mem, _startAddress);
LoadProgram(_c64WithoutInstrumentation.Mem, _startAddress);

_systemRunnerWithInstrumentation = new SystemRunner(_c64WithInstrumentation);
_systemRunnerWithoutInstrumentation = new SystemRunner(_c64WithoutInstrumentation);
}

private void LoadProgram(Memory mem, ushort startAddress)
Expand Down Expand Up @@ -96,7 +91,7 @@ public void ExecFrameWithoutInstrumentation()
_c64WithoutInstrumentation.CPU.PC = _startAddress;
for (var i = 0; i < NumberOfFramesToExecute; i++)
{
var execEvaluatorTriggerResult = _c64WithoutInstrumentation.ExecuteOneFrame(_systemRunnerWithoutInstrumentation);
var execEvaluatorTriggerResult = _c64WithoutInstrumentation.ExecuteOneFrame();
}
}

Expand All @@ -106,7 +101,7 @@ public void ExecFrameWithInstrumentation()
_c64WithInstrumentation.CPU.PC = _startAddress;
for (var i = 0; i < NumberOfFramesToExecute; i++)
{
var execEvaluatorTriggerResult = _c64WithInstrumentation.ExecuteOneFrame(_systemRunnerWithInstrumentation);
var execEvaluatorTriggerResult = _c64WithInstrumentation.ExecuteOneFrame();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Jobs;
using Highbyte.DotNet6502.Systems;
using Highbyte.DotNet6502.Systems.Commodore64;
Expand All @@ -17,8 +16,6 @@ public class C64ExecuteInstructionBenchmark
{
private C64 _c64WithInstrumentation = default!;
private C64 _c64WithoutInstrumentation = default!;
private SystemRunner _systemRunnerWithInstrumentation = default!;
private SystemRunner _systemRunnerWithoutInstrumentation = default!;
private ushort _startAddress;

//[Params(1)]
Expand Down Expand Up @@ -50,8 +47,6 @@ public void Setup()
LoadProgram(_c64WithInstrumentation.Mem, _startAddress);
LoadProgram(_c64WithoutInstrumentation.Mem, _startAddress);

_systemRunnerWithInstrumentation = new SystemRunner(_c64WithInstrumentation);
_systemRunnerWithoutInstrumentation = new SystemRunner(_c64WithoutInstrumentation);
}

private void LoadProgram(Memory mem, ushort startAddress)
Expand Down Expand Up @@ -96,7 +91,7 @@ public void ExecInsWithoutInstrumentation()
_c64WithoutInstrumentation.CPU.PC = _startAddress;
for (var i = 0; i < NumberOfInstructionsToExecute; i++)
{
_c64WithoutInstrumentation.ExecuteOneInstruction(_systemRunnerWithoutInstrumentation, out InstructionExecResult instructionExecResult);
_c64WithoutInstrumentation.ExecuteOneInstruction(out InstructionExecResult instructionExecResult);
}
}

Expand All @@ -106,7 +101,7 @@ public void ExecInsWithInstrumentation()
_c64WithInstrumentation.CPU.PC = _startAddress;
for (var i = 0; i < NumberOfInstructionsToExecute; i++)
{
_c64WithInstrumentation.ExecuteOneInstruction(_systemRunnerWithInstrumentation, out InstructionExecResult instructionExecResult);
_c64WithInstrumentation.ExecuteOneInstruction(out InstructionExecResult instructionExecResult);
}
}
}
2 changes: 2 additions & 0 deletions doc/APPS_CONSOLE_MONITOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Cross-platform desktop console application with a only UI being a machine code m

<img align="top" src="Screenshots/ConsoleMonitor.png" width="25%" height="25%" title="Machine code monitor native console host window" />

> Note: There is also the [VS Code debugger extension](../tools/vscode-extension/README.md) that can be used for debugging both assembly source and raw disassembly. It's a lost more powerful than the built-in machine code monitor described here.

Technologies
- UI: standard .NET console.
- Input: standard .NET console.
Expand Down
169 changes: 169 additions & 0 deletions doc/DEBUG_ADAPTER_TCP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# TCP Debug Adapter Integration

## Overview

The debug adapter now supports TCP transport in addition to STDIN/STDOUT, enabling debugging of desktop GUI applications like the Avalonia Desktop app.

## Architecture

### Library Structure

- **Highbyte.DotNet6502.DebugAdapter** (library)
- `IDebugAdapterTransport` - Interface for transport implementations
- `StdioTransport` - STDIN/STDOUT implementation for console apps
- `TcpTransport` - TCP socket implementation for network connections
- `TcpDebugAdapterServer` - TCP listener that accepts debug connections
- `DapProtocol` - Debug Adapter Protocol message handling
- `DebugAdapterLogic` - Core DAP request/response logic
- `Ca65DbgParser` - Debug symbol parser

### Console Application

- **Highbyte.DotNet6502.DebugAdapter.ConsoleApp**
- Uses `StdioTransport` for VSCode extension integration
- Launched by VSCode extension as a child process
- Maintains backward compatibility with existing VSCode extension

### Desktop Application Integration

- **Highbyte.DotNet6502.App.Avalonia.Desktop**
- Integrated `TcpDebugAdapterServer` for TCP-based debugging
- Accepts `--debug-port <port>` command-line argument
- Accepts `--debug-wait` flag to wait for debugger connection before starting
- Runs debug adapter server on background thread

## Usage

### Avalonia Desktop App with TCP Debug Adapter

Start the Avalonia Desktop app with debug adapter enabled:

```bash
./Highbyte.DotNet6502.App.Avalonia.Desktop --debug-port 6502
```

To wait for the debugger to connect before starting:

```bash
./Highbyte.DotNet6502.App.Avalonia.Desktop --debug-port 6502 --debug-wait
```

Combined with console logging:

```bash
./Highbyte.DotNet6502.App.Avalonia.Desktop --debug-port 6502 --console-log -l Debug
```

### VSCode Configuration

To debug the Avalonia Desktop app from VSCode, you'll need to add a launch configuration that connects to the TCP port:

```json
{
"type": "dotnet6502-debug",
"request": "attach",
"name": "Attach to Avalonia Desktop",
"debugServer": 6502,
"program": "${workspaceFolder}/samples/Assembler/GenericComputer/snake6502/build/snake6502.prg",
"stopOnEntry": true,
"trace": true
}
```

**Note:** The VSCode extension may need updates to support the `debugServer` configuration property for TCP connections.

## Implementation Details

### TCP Transport

The `TcpTransport` class implements `IDebugAdapterTransport` using a `TcpClient` and `NetworkStream`:

- Reads DAP messages with Content-Length headers
- Writes DAP messages with proper framing
- Fires `Disconnected` event when connection is closed

### TCP Debug Adapter Server

The `TcpDebugAdapterServer` class:

- Listens on `IPAddress.Loopback` (localhost only)
- Accepts a single client connection at a time
- Fires `ClientConnected` event with a `TcpTransport` instance
- Supports port 0 for random port assignment

### Avalonia Desktop Integration

The Avalonia Desktop app:

1. Parses `--debug-port` and `--debug-wait` command-line arguments
2. Creates a `TcpDebugAdapterServer` when debug port is specified
3. Handles `ClientConnected` event by:
- Creating `DapProtocol` and `DebugAdapterLogic` instances
- Starting a message loop on a background thread
- Logging to a separate file in the temp directory
4. Optionally waits for debugger connection (30 second timeout)
5. Continues with normal application startup

### Debug Logging

Debug adapter activity is logged to:

```
$TMPDIR/dotnet6502-debugadapter-avalonia-{timestamp}.log
```

This log file contains:
- Connection events
- DAP messages sent/received
- Errors and exceptions

## Future Enhancements

1. **VSCode Extension Updates**
- Add support for `debugServer` configuration property
- Allow attaching to running desktop applications
- Provide UI for discovering running instances

2. **Multiple Client Support**
- Allow multiple simultaneous debug connections
- Share breakpoints and state across clients

3. **Auto-Discovery**
- Broadcast availability on local network
- Allow VSCode to discover running instances

4. **Security**
- Add authentication token support
- Support remote debugging with encryption

## Testing

### Manual Testing

1. Start the Avalonia Desktop app with debug port:
```bash
./Highbyte.DotNet6502.App.Avalonia.Desktop --debug-port 6502 --debug-wait --console-log
```

2. Connect with a TCP client (e.g., `nc`):
```bash
nc localhost 6502
```

3. Send a DAP initialize request:
```
Content-Length: 122

{"seq":1,"type":"request","command":"initialize","arguments":{"adapterID":"dotnet6502","pathFormat":"path"}}
```

4. Verify response is received

### Automated Testing

Future work: Add integration tests that:
- Start the desktop app with debug port
- Connect via TCP
- Send DAP requests
- Verify responses
- Test breakpoint functionality
Loading
Loading