Skip to content

Commit

Permalink
server v3.4, convert data to code
Browse files Browse the repository at this point in the history
  • Loading branch information
dfgordon committed Nov 17, 2024
1 parent bde674b commit f68deeb
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 16 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.2.0] - 2024-11-17

### Fixes

* Fix some issues in disassembly workflows

### New Features

* Disassembly: data sections can be converted back to code
* Guard against excessive workspace scans
- maximum directory count and recursion depth
- passes over `build`, `node_modules`, and `target` directories

## [3.1.2] - 2024-09-29

### Fixes
Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Language support for Merlin 8/16/16+/32 assembly language for the 6502 family of
* Diagnostics, symbol manipulations, macro expansions
* Resolves labels across project workspace
* Comprehensive highlights, completions, and hovers
* Interact with emulators and disk images, see below
* Options : see `Ctrl+Comma` -> `Extensions` -> `Merlin 6502`
* Commands: see `Ctrl+P` -> `merlin6502`
* Activates for file extensions `.asm`, `.S`
* Interact with [emulators](#using-with-applewin) and [disk images](#using-with-disk-images)
* Perform [disassembly](#disassembly) within the editor

Activates for file extensions `.asm`, `.S`

<img src="sample/demo-merlin.gif" alt="session capture"/>

Expand Down Expand Up @@ -135,19 +135,32 @@ You can access files on a disk image. As of this writing, the supported image t

Another way to access disk images directly from VS Code is using the `Disk Image Notebook` extension.

## Troubleshooting Tips
## Disassembly

You can work through a disassembly process entirely within the editor.

* Perform initial disassembly by accessing a disk image or emulator (see above)
- Disassemble with "label all lines" and save it as a fixed reference
- Disassemble with "label some lines" and use it as a basis for modification
* If there is a suspected data section, use `merlin6502: Convert code lines to data lines`
* If data was interpreted too aggressively, revert using `merlin6502: Convert data lines to code lines`
* The conversions make use of a "spot-assembler" that sometimes needs a program-counter hint
- In the lines to be converted, insert `ORG` or a *literal label*
- Labels of the form `_XXXX`, where `X` is a hex digit, are interpreted as *literal labels*
* You can insert `MX` at the beginning of a possible code section before converting
* You can adjust how `BRK` is handled in settings

As the disassembly progresses, gradually give the literal labels more meaningful names, and change them to local labels if appropriate.

## Tips

* VS Code
- the language server will not analyze untitled documents; when creating a new document save it early
- when entering hexadecimal into *editor* commands, use the modern convention, e.g. use `0xff` rather than `$ff`.
- tab your way to the end of snippets
- to mitigate diagnostic delay, break large source files into smaller modules, or adjust live diagnostics setting
- For very large projects you may want to adjust live diagnostics setting
* Disk Images
- Do not write to disk images while they are mounted in an emulator
* Disassembly
- convert code to data using `merlin6502: Convert code lines to data lines`
- insert ORG at the start of possible data sections to help spot-assembler resolve PC
- adjust handling of BRK instruction in settings
* Merlin
- restore the configuration defaults, especially memory banks
- use the 128K version of Merlin 8
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-language-merlin6502-client",
"description": "Language client for Merlin 6502",
"version": "3.1.2",
"version": "3.2.0",
"license": "GPL-3.0-only",
"publisher": "dfgordon",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class EmulatorTool extends lxbase.LangExtBase
dasm = new DisassemblyTool();
params = await dasm.getDisassemblyParameters(dasm_range_type(getWhat), 0, 2 ** 16);
}
const warnMess = getWhat.includes('Disassembly') ? 'Please verify that Merlin is running in the front machine' : 'Please verify the front machine is ready';
const warnMess = getWhat.includes('Disassembly') ? 'Please verify the front machine is ready' : 'Please verify that Merlin is running in the front machine';
const res = await vscode.window.showWarningMessage(warnMess,'Proceed','Cancel');
if (res!='Proceed')
return;
Expand Down
12 changes: 10 additions & 2 deletions client/src/disassembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class DisassemblyTool
}
}

export async function toData() {
async function convert(cmd: string) {
let verified = lxbase.verify_document();
if (!verified)
return;
Expand All @@ -145,7 +145,7 @@ export async function toData() {
return;
const [beg, end] = lxbase.selectionToLineRange(verified.ed.selection);
try {
const content = await lxbase.request<string>('merlin6502.toData', [
const content = await lxbase.request<string>(cmd, [
verified.doc.getText(),
verified.doc.uri.toString(),
beg,
Expand All @@ -165,3 +165,11 @@ export async function toData() {
vscode.window.showErrorMessage(error.message);
}
}

export async function toData() {
convert('merlin6502.toData');
}

export async function toCode() {
convert('merlin6502.toCode');
}
2 changes: 2 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function activate(context: vscode.ExtensionContext)
client.start().then(() => {
if (client.initializeResult?.serverInfo?.version) {
const vstr = client.initializeResult.serverInfo.version;
client.outputChannel.appendLine("Server version is " + vstr);
const v= vstr.split('.')
if (parseInt(v[0]) != 3) {
vscode.window.showErrorMessage('Server version is ' + vstr + ', expected 3.x, stopping.');
Expand Down Expand Up @@ -143,6 +144,7 @@ export function activate(context: vscode.ExtensionContext)
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.getAppleWinSaveState",emulator.getAppleWinSaveState,emulator));
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.format",com.showPasteableProgram));
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.toData", dasm.toData));
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.toCode", dasm.toCode));
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.getFromDiskImage", a2kit.getFromImage, a2kit));
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.saveToDiskImage", a2kit.putToImage, a2kit));
context.subscriptions.push(vscode.commands.registerCommand("merlin6502.selectMaster", masterSelect.selectMaster, masterSelect));
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Merlin 6502",
"description": "Merlin assembly language for 6502 family of processors",
"icon": "language-merlin-icon.png",
"version": "3.1.2",
"version": "3.2.0",
"license": "GPL-3.0-only",
"publisher": "dfgordon",
"repository": {
Expand Down Expand Up @@ -161,6 +161,10 @@
{
"command": "merlin6502.toData",
"title": "merlin6502: Convert code lines to data lines"
},
{
"command": "merlin6502.toCode",
"title": "merlin6502: Convert data lines to code lines"
}
],
"menus": {
Expand Down Expand Up @@ -195,7 +199,11 @@
},
{
"command": "merlin6502.toData",
"title": "editorLangId == merlin6502"
"when": "editorLangId == merlin6502"
},
{
"command": "merlin6502.toCode",
"when": "editorLangId == merlin6502"
}
]
}
Expand Down
54 changes: 54 additions & 0 deletions server/prepub.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Run from project root, such as `.\server\prepub.ps1 darwin-arm64`
# This helps prepare for `vsce publish --target <platform>` by putting the appropriate
# server executable in `./server` and removing all others.
# It also carries out a few simple checks on the project.

param (
[Parameter(Mandatory)]
[ValidateSet("win32-x64","linux-x64","darwin-x64","darwin-arm64","universal")]
[string]$platform
)

$changelog = Get-Content .\CHANGELOG.md
if ($changelog.ToLower() -match "unreleased") {
Write-Error "unreleased appears in CHANGELOG"
exit 1
}

if (! ($changelog -match (Get-Date -Format yyyy-M-d))) {
Write-Error "today's date is not in the CHANGELOG"
exit 1
}

$package1 = Get-Content .\package.json | ConvertFrom-Json
$package2 = Get-Content .\client\package.json | ConvertFrom-Json
if (! ($package1.version -match $package2.version)) {
Write-Error "inner and outer package versions are different"
exit 1
}
Write-Output ("package version is " + $package1.version)

if ($platform -eq "universal") {
Remove-Item server/server-*
Get-ChildItem server
return
}

if ($platform -eq "win32-x64") {
$server = "x86_64-pc-windows-msvc"
} elseif ($platform -eq "linux-x64") {
$server = "x86_64-unknown-linux-musl"
} elseif ($platform -eq "darwin-x64") {
$server = "x86_64-apple-darwin"
} elseif ($platform -eq "darwin-arm64") {
$server = "aarch64-apple-darwin"
}

$srcPath = $home + "/Downloads/result-" + $server + "/" + "server-merlin-" + $server
if ($platform -eq "win32-x64") {
$srcPath += ".exe"
}

Remove-Item server/server-*
Copy-Item -Path $srcPath -Destination server
Get-ChildItem server

0 comments on commit f68deeb

Please sign in to comment.