Skip to content
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

exe2adf support. #122

Merged
merged 6 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to the "amiga-debug" extension will be documented in this fi
- `Open Amiga Hardware Reference Manual`: opens the Amiga Hardware Reference Manual TOC hosted at amigadev.elowar.com.
- NEW: you can set your Kickstart paths in settings <kbd>Ctrl+,</kbd> under `Extensions` > `Amiga C/C++ Compile, Debug & Profile` > `Rom-paths: A500, A1200, A4000` ([PR#117 by merry^Architect](https://github.com/BartmanAbyss/vscode-amiga-debug/pull/117))
- NEW: template project's output now in `out/a.elf`, `out/a.exe`. Can be changed in settings `amiga.program` ([PR#119 by merry^Architect](https://github.com/BartmanAbyss/vscode-amiga-debug/pull/119))
- NEW: new command `Convert EXE to ADF` (right-click Amiga EXE files in the explorer) ([PR#122 by merry^Architect](https://github.com/BartmanAbyss/vscode-amiga-debug/pull/122))

## 1.5.3
- FIX: fix missing cycle timings in assembly view (was broken since 1.4.7)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ This extension contains binaries of:
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
- This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
- `cd`, `EndCLI`, `run`, `avail` from Workbench 1.3
- unpacked [exe2adf](http://www.exe2adf.com/)
- Copyright (c) 2015-2022 Bonefish/Reality. All rights reserved.

## Caveats
- sometimes when you're multiplying 2 WORDs together, `gcc` tries to use a (slow) 32-bit multiply. So if you have performance-critical multiplications, consider using the `muluw` and `mulsw` functions from `gcc8_c_support.h`
Expand Down
Binary file added bin/exe2adf.exe
Binary file not shown.
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"onCommand:amiga.profileSize",
"onCommand:amiga.shrinkler",
"onCommand:amiga.disassembleElf",
"onCommand:amiga.exe2adf",
"onCommand:amiga.externalResources.gradientMaster",
"onCommand:amiga.externalResources.imageTool",
"onCommand:amiga.externalResources.colorReducer",
Expand Down Expand Up @@ -125,7 +126,12 @@
"category": "Amiga",
"command": "amiga.terminal",
"title": "Open Terminal"
}
},
{
"category": "Amiga",
"command": "amiga.exe2adf",
"title": "Amiga: Convert EXE to ADF"
}
],
"languages": [
{
Expand Down Expand Up @@ -390,7 +396,12 @@
"command": "amiga.shrinkler",
"group": "1_amiga",
"when": "resourceExtname == '.exe'"
}
},
{
"command": "amiga.exe2adf",
"group": "1_amiga",
"when": "resourceExtname == '.exe'"
}
]
},
"views": {
Expand Down
96 changes: 56 additions & 40 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class AmigaCppConfigurationProvider implements CustomConfigurationProvider {
}
}

type OnOutputReadyFunction = (output: string) => void;

class AmigaDebugExtension {
private registerProvider: RegisterTreeProvider;
private outputChannel: vscode.OutputChannel;
Expand Down Expand Up @@ -141,6 +143,7 @@ class AmigaDebugExtension {
vscode.commands.registerCommand('amiga.bin-path', () => path.join(this.extensionPath, 'bin')),
vscode.commands.registerCommand('amiga.initProject', this.initProject.bind(this)),
vscode.commands.registerCommand('amiga.terminal', this.openTerminal.bind(this)),
vscode.commands.registerCommand('amiga.exe2adf', (uri: vscode.Uri) => this.exe2adf(uri)),
vscode.commands.registerCommand('amiga.externalResources.gradientMaster', () => MinimalBrowser.launchUrl('http://deadliners.net/gradientmaster', 'Amiga Gradient Master')),
vscode.commands.registerCommand('amiga.externalResources.imageTool', () => MinimalBrowser.launchUrl('http://deadliners.net/ImageTool', 'Image Tool')),
vscode.commands.registerCommand('amiga.externalResources.colorReducer', () => MinimalBrowser.launchUrl('http://deadliners.net/ColorReducer', 'Color Reducer')),
Expand Down Expand Up @@ -368,42 +371,55 @@ class AmigaDebugExtension {
await vscode.commands.executeCommand("workbench.action.moveEditorToLeftGroup");
}

private shrinklerTerminal: vscode.Terminal;
private shrinklerFinished = false;

private async shrinkler(uri: vscode.Uri) {
if(uri.scheme !== 'file') {
void vscode.window.showErrorMessage(`Error during shrinkling: Don't know how to open ${uri.toString()}`);
return;
}
const binPath = path.join(this.extensionPath, 'bin');

const workspaceFolder = vscode.workspace.workspaceFolders[0].uri.fsPath;
const jsonPath = path.join(workspaceFolder, ".vscode", "amiga.json");
let config: AmigaConfiguration;
try {
const workspaceFolder = vscode.workspace.workspaceFolders[0].uri.fsPath;
const jsonPath = path.join(workspaceFolder, ".vscode", "amiga.json");
let config: AmigaConfiguration;
try {
config = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')) as AmigaConfiguration;
} catch(e) { /**/ }
if(config === undefined || config.shrinkler === undefined || Object.keys(config.shrinkler).length === 0) {
void vscode.window.showErrorMessage(`No shrinkler configurations found in '.vscode/amiga.json'`);
return;
}

const items: vscode.QuickPickItem[] = [];
config = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')) as AmigaConfiguration;
} catch(e) { /**/ }
if(config === undefined || config.shrinkler === undefined || Object.keys(config.shrinkler).length === 0) {
void vscode.window.showErrorMessage(`No shrinkler configurations found in '.vscode/amiga.json'`);
return;
}

const items: vscode.QuickPickItem[] = [];

// eslint-disable-next-line guard-for-in
for(const key in config.shrinkler) {
items.push({ label: key, description: config.shrinkler[key] });
}

const result = await vscode.window.showQuickPick(items, { placeHolder: 'Select shrinkler configuration', matchOnDescription: true, ignoreFocusOut: true });
if(result === undefined)
return;
const output = uri.fsPath + '.' + result.label + '.shrinkled';
const args = [...result.description.split(' '), uri.fsPath, output];
const cmd = `${binPath}\\shrinkler.exe`;
return this.runExternalCommand(uri, cmd, args, output, () => {
void vscode.commands.executeCommand("vscode.open", vscode.Uri.file(output + '.shrinklerstats'), { preview: false } as vscode.TextDocumentShowOptions);
});
}

// eslint-disable-next-line guard-for-in
for(const key in config.shrinkler) {
items.push({ label: key, description: config.shrinkler[key] });
}
private exe2adf(uri: vscode.Uri) {
const binPath = path.join(this.extensionPath, 'bin');
const output = path.join(path.dirname(uri.fsPath), path.basename(uri.fsPath, path.extname(uri.fsPath)) + '.adf');
const args = [ '-i', uri.fsPath, '-a', output ];
const cmd = `${binPath}\\exe2adf.exe`;
return this.runExternalCommand(uri, cmd, args, output, null);
}

const result = await vscode.window.showQuickPick(items, { placeHolder: 'Select shrinkler configuration', matchOnDescription: true, ignoreFocusOut: true });
if(result === undefined)
return;
const output = uri.fsPath + '.' + result.label + '.shrinkled';
const args = [...result.description.split(' '), uri.fsPath, output];
const cmd = `${binPath}\\shrinkler.exe`;
private externalCommandTerminal: vscode.Terminal;
private externalCommandFinished = false;

private runExternalCommand(uri: vscode.Uri, cmd: string, args: string[], output: string, onOutputReady: OnOutputReadyFunction)
{
if(uri.scheme !== 'file') {
void vscode.window.showErrorMessage(`Error running external command: Don't know how to open ${uri.toString()}`);
return;
}
try {
const writeEmitter = new vscode.EventEmitter<string>();
let p: cp.ChildProcess;
const pty: vscode.Pseudoterminal = {
Expand All @@ -425,9 +441,9 @@ class AmigaDebugExtension {
writeEmitter.fire('-----------------------\r\n');
writeEmitter.fire('\r\n');
} else {
void vscode.commands.executeCommand("vscode.open", vscode.Uri.file(output + '.shrinklerstats'), { preview: false } as vscode.TextDocumentShowOptions);
onOutputReady?.(output);
}
this.shrinklerFinished = true;
this.externalCommandFinished = true;
});
},
close: () => { /**/ },
Expand All @@ -437,21 +453,21 @@ class AmigaDebugExtension {
}
};

if(this.shrinklerTerminal && this.shrinklerFinished) {
this.shrinklerTerminal.dispose();
this.shrinklerTerminal = null;
this.shrinklerFinished = false;
if (this.externalCommandTerminal && this.externalCommandFinished) {
this.externalCommandTerminal.dispose();
this.externalCommandTerminal = null;
this.externalCommandFinished = false;
}

this.shrinklerTerminal = vscode.window.createTerminal({
this.externalCommandTerminal = vscode.window.createTerminal({
name: 'Amiga',
pty
});
this.shrinklerTerminal.show();
this.externalCommandTerminal.show();
} catch(error) {
void vscode.window.showErrorMessage(`Error during shrinkling: ${error.message}`);
void vscode.window.showErrorMessage(`Error running external command: ${error.message}`);
}
}
}

private async examineMemory() {
function validateValue(address: string) {
Expand Down