Skip to content

Instantly share code, notes, and snippets.

@pwillard
Created February 12, 2024 13:25
Show Gist options
  • Save pwillard/e0f0bc16d557a091a0c4dbe1bee8eefa to your computer and use it in GitHub Desktop.
Save pwillard/e0f0bc16d557a091a0c4dbe1bee8eefa to your computer and use it in GitHub Desktop.
A tool to compile Color Computer assembler code to a binary and create a DSK file for emulators to test it.
<#
############################################################################################
.SYNOPSIS
Compile 6809 Assmembler file with LWASM
.DESCRIPTION
This PowerShell script will assemble a Color Computer ASM file
.PARAMETER fileName
Specifies the file name to be assembled
.EXAMPLE
PS> ./lwasm_make.ps1 "$justName.asm"
.LINK
pending
.NOTES
Author: Pete Willard | License: CC0 Version 1.0 | Date: 2021-08-13
Version history: Barely Working | 2021-08-13 V1.0
Fought with Powershell eating my commas for a few hours. Online docs are stale.
This is a work in progress.
TODO: Create functions instead of top-down stream.
(Would allow for error recovery versus just exiting the script)
############################################################################################
#>
param([string]$fileName = "", [string]$favoriteEmulator = "")
Clear-Host
write-Host "================================================================================"
Write-Host " LWASM Asistant" -foregroundColor green
Write-Host "================================================================================"
write-Host " "
############################################################################################
# Check for LWASM executable
try {
Write-Host "⏳ (1/6) Searching for LWASM executable... " -noNewline
& lwasm --version
if ($lastExitCode -ne "0") {
throw "Can't execute 'lwasm' - make sure `lwasm` is installed and in the PATH"
}
Write-Host "✔️ LWASM checks out... good." -foregroundColor green
############################################################################################
# Query user for input filename if not provided
# Validate filename by checking extension
# Convert file name to Uppercase, since that is what DECB expects
Write-Host "⏳ (2/6) Query user settings..."
if ($fileName -eq "") {
$fileName = Read-Host " Enter the filename ro assemble (e.g. 'MYPROG.ASM') "
}
$fileName = $fileName.toUpper()
Write-Host "✔️ $filename checks out... good." -foregroundColor green
############################################################################################
# Check if DECB is installed and available in the path
# Throw an error if DECB cannot be executed
Write-Host "⏳ (3/6) Searching for TOOLSHED executable... " -noNewline
# Just check if its there... squash any errors or output
& decb > nul 2>&1
if ($lastExitCode -ne "0") {
throw "Can't execute 'decb' - make sure `decb` is installed and in the PATH"
}
Write-Host "✔️ DECB checks out... good." -foregroundColor green
############################################################################################
# Checks if the input file exists and throws an error if not found.
# Otherwise prints a success message.
Write-Host "⏳ (4/6) Checking Source Code file... $filename " -noNewline
if (!(Test-Path $fileName)) {
Write-Warning "$fileName is absent, check name and try again."
exit 1
}
Write-Host "✔️ $fileName checks out... good." -foregroundColor green
############################################################################################
# Assembles the input file using LWASM and outputs the binary and listing files.
# Checks for successful assembly and throws an error if assembly fails.
Write-Host "⏳ (5/6) Running LWASM on $filename... "
$justName = (Get-Item $fileName).Basename
& lwasm $fileName --6809 --list --symbols --6800compat --output=$justName.bin > $justName.txt
#Write-Output "lwasm $fileName --6809 --list --symbols --6800compat --output=$justName.bin"
if ($lastExitCode -ne "0") {
throw "Assembly failed for $filename"
exit 1
}
############################################################################################
# Creates a DSK emulator disk image containing the assembled binary
# and assembly listing files. Calls DECB to initialize a new DSK file,
# copy the binary into the DSK as AUTORUN.BIN, and copy the assembly
# listing as AUTORUN.ASM.
Write-Host "⏳ (6/6) Creating Emulator DSK file for $filename... "
# File name juggling to get the right file names for DECB
$diskname = "$justname.DSK"
$binname = "$justname.BIN"
$asmname = "$justname.ASM"
# We should be able to just call DECB from anywhere as it was verified to be in the PATH
$exefile = "decb.exe"
# Using an array to pass arguments to DECB for each activity
# using back ticks (tilde) to escape the ',' in the parameter for copy command
# not '\' lile OLD Powershell docs say.
$initArgs = @(
"dskini" ,
"$diskname"
)
$binArgs = @(
"copy" ,
"-2",
"$binname" ,
"$diskname`,$binname",
"-r"
)
$asmargs = @(
"copy" ,
"-3",
"$asmname" ,
"$diskname`,$asmname",
"-r"
)
################################################################################################
# Checks if the disk file already exists.
# If it does, delete it.
# If it does not, indicate that it will be created.
if (Test-Path $diskname -PathType leaf) {
write-Host " - Removing existing $diskname "
Remove-Item $diskname
}
else {
write-Host " - Creating $diskname "
}
# Run DECB to create the disk file
& $exefile $initArgs
if ($lastExitCode -ne "0") {
throw "Disk creation failed for $diskname"
exit 1
}
Write-Host " - Copy Binary $binname to DSK "
& $exefile $binArgs
if ($lastExitCode -ne "0") {
throw "Disk copy failed for $binname"
exit 1
}
Write-Host " - Copy Source $asmname to DSK "
& $exefile $asmargs
if ($lastExitCode -ne "0") {
throw "Disk copy failed for $asmname"
exit 1
}
# Exit with success code after printing confirmation that disk was created
Write-Host "✔️ $diskname created... ready for emulator." -foregroundColor green
exit 0 # success
# Handles any errors in the script by outputting an error message and exiting with code 1
}
catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber)): $($Error[0])"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment