Tweak Merlin32 generator

Merlin32 v1.2 requires DSK and TYP directives.  We now add these if
version 1.2 is detected.  (Earlier versions of Merlin32 accept them,
so at some point we may just want to output them always.)

The version-parsing code has been updated to deal with pre-release
version strings.
This commit is contained in:
Andy McFadden committed 2025-05-04 07:58:49 -07:00
1 parent 913dfb5dd2
commit bde4f2ed07
2 files changed
+25 -15

No files matched your search

+23 -14
View File
@@ -19,6 +19,7 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using Asm65; using Asm65;
using CommonUtil; using CommonUtil;
@@ -32,6 +33,7 @@ namespace SourceGen.AsmGen {
/// </summary> /// </summary>
public class GenMerlin32 : IGenerator { public class GenMerlin32 : IGenerator {
private const string ASM_FILE_SUFFIX = "_merlin32.S"; // must start with underscore private const string ASM_FILE_SUFFIX = "_merlin32.S"; // must start with underscore
private const string OUT_FILE_SUFFIX = "_merlin32";
// IGenerator // IGenerator
public DisasmProject Project { get; private set; } public DisasmProject Project { get; private set; }
@@ -115,6 +117,7 @@ namespace SourceGen.AsmGen {
// Interesting versions. // Interesting versions.
private static CommonUtil.Version V1_0 = new CommonUtil.Version(1, 0); private static CommonUtil.Version V1_0 = new CommonUtil.Version(1, 0);
private static CommonUtil.Version V1_2 = new CommonUtil.Version(1, 2);
// Pseudo-op string constants. // Pseudo-op string constants.
@@ -251,6 +254,17 @@ namespace SourceGen.AsmGen {
return new GenerationResults(pathNames, string.Empty, mBinaryIncludes); return new GenerationResults(pathNames, string.Empty, mBinaryIncludes);
} }
// IGenerator
public void OutputAsmConfig() {
// Merlin v1.2 requires TYP and DSK directives.
if (mAsmVersion >= V1_2) {
OutputLine(string.Empty, SourceFormatter.FormatPseudoOp("DSK"),
mFileNameBase + OUT_FILE_SUFFIX, string.Empty);
OutputLine(string.Empty, SourceFormatter.FormatPseudoOp("TYP"),
"BIN", string.Empty);
}
}
// IGenerator // IGenerator
public void OutputDataOp(int offset) { public void OutputDataOp(int offset) {
Formatter formatter = SourceFormatter; Formatter formatter = SourceFormatter;
@@ -498,11 +512,6 @@ namespace SourceGen.AsmGen {
operand = sb.ToString(); operand = sb.ToString();
} }
// IGenerator
public void OutputAsmConfig() {
// nothing to do (though we could emit "xc off" for 6502)
}
// IGenerator // IGenerator
public void OutputEquDirective(string name, string valueStr, string comment) { public void OutputEquDirective(string name, string valueStr, string comment) {
OutputLine(name, SourceFormatter.FormatPseudoOp(sDataOpNames.EquDirective), OutputLine(name, SourceFormatter.FormatPseudoOp(sDataOpNames.EquDirective),
@@ -831,6 +840,12 @@ namespace SourceGen.AsmGen {
return new AssemblerConfig(string.Empty, new int[] { 9, 6, 11, 74 }); return new AssemblerConfig(string.Empty, new int[] { 9, 6, 11, 74 });
} }
// Stdout: "C:\Src\WorkBench\Merlin32.exe v 1.0, (c) Brutal Deluxe ..."
// "C:\Src\WorkBench\Merlin32.exe v 1.2 beta 1, (c) Brutal Deluxe ..."
// Other platforms may not have the ".exe". Start at first occurrence of " v ".
private static string sVersionPattern = @" v (\d.\d)( [^,]+)?,";
private static Regex sVersionRegex = new Regex(sVersionPattern);
// IAssembler // IAssembler
public AssemblerVersion QueryVersion() { public AssemblerVersion QueryVersion() {
AssemblerConfig config = AssemblerConfig config =
@@ -846,20 +861,14 @@ namespace SourceGen.AsmGen {
return null; return null;
} }
// Stdout: "C:\Src\WorkBench\Merlin32.exe v 1.0, (c) Brutal Deluxe ..."
// Other platforms may not have the ".exe". Find first occurrence of " v ".
const string PREFIX = " v "; // not expecting this to appear in the path
string str = cmd.Stdout; string str = cmd.Stdout;
int start = str.IndexOf(PREFIX); MatchCollection matches = sVersionRegex.Matches(str);
int end = (start < 0) ? -1 : str.IndexOf(',', start);
if (start < 0 || end < 0 || start + PREFIX.Length >= end) { if (matches.Count != 1) {
Debug.WriteLine("Couldn't find version in " + str); Debug.WriteLine("Couldn't find version in " + str);
return null; return null;
} }
start += PREFIX.Length; string versionStr = matches[0].Groups[1].Value;
string versionStr = str.Substring(start, end - start);
CommonUtil.Version version = CommonUtil.Version.Parse(versionStr); CommonUtil.Version version = CommonUtil.Version.Parse(versionStr);
if (!version.IsValid) { if (!version.IsValid) {
return null; return null;
+2 -1
View File
@@ -417,7 +417,8 @@ namespace SourceGen.Tests {
while (iter.MoveNext()) { while (iter.MoveNext()) {
AssemblerInfo info = iter.Current; AssemblerInfo info = iter.Current;
AssemblerVersion version = AssemblerVersionCache.GetVersion(info.AssemblerId); AssemblerVersion version = AssemblerVersionCache.GetVersion(info.AssemblerId);
ReportProgress(" " + info.Name + " v" + version.VersionStr); ReportProgress(" " + info.Name + " v" +
(version != null ? version.VersionStr : "UNAVAILABLE"));
} }
ReportProgress("\n"); ReportProgress("\n");
} }