1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-11 17:29:29 +00:00
6502bench/SourceGen/AsmGen/IAssembler.cs
Andy McFadden 99cd0d3ac1 Improve handling of C64 PRG header
C64 PRG files are pretty common.  Their salient feature is that they
start with a 16-bit value that is used as the load address.  The
value is commonly generated by the assembler itself, rather than
explicitly added to the source file.

Not all assemblers know what a PRG file is, and some of them handle
it in ways that are difficult to guarantee in SourceGen.  ACME adds
the 16-bit header when the output file name ends in ".prg", cc65
uses a modified config file, 64tass uses a different command-line
option, and Merlin 32 has no idea what they are.

This change adds PRG file detection and handling to the 64tass code
generator.  Doing so required making a few changes to the gen/asm
interfaces, because we now need to have the generator pass additional
flags to the assembler, and sometimes we need code generation to
start somewhere other than offset zero.  Overall the changes were
pretty minor.

The 20042-address-changes test needed a 6502-only variant.  A new test
(20040-address-changes) has been added and given a PRG header.  As
part of this change the 65816 variant was changed to use addresses
in bank 2, which uncovered a code generation bug that this change
also fixes.

The 64tass --long-address flag doesn't appear to be necessary for
files <= 65536 bytes long, so we no longer emit it for those.

(issue #90)
2020-10-17 16:45:13 -07:00

83 lines
3.3 KiB
C#

/*
* Copyright 2019 faddenSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace SourceGen.AsmGen {
/// <summary>
/// Common interface for executing assemblers.
/// </summary>
public interface IAssembler {
/// <summary>
/// Gets identification strings for the executable. These are used when browsing for
/// the assembler binary.
/// </summary>
/// <param name="humanName">Human-readable name to show in the "open" dialog.</param>
/// <param name="exeName">Name of executable to find, without ".exe".</param>
void GetExeIdentifiers(out string humanName, out string exeName);
/// <summary>
/// Queries the assembler for its default configuration.
/// </summary>
/// <returns>Config object with default values.</returns>
AssemblerConfig GetDefaultConfig();
/// <summary>
/// Queries the assembler for its version. Assembler executable paths are queried from
/// the global settings object.
/// </summary>
/// <returns>Assembler version info, or null if query failed.</returns>
AssemblerVersion QueryVersion();
/// <summary>
/// Configures the object. Pass in the result object from IGenerator.GenerateSource(),
/// and the working directory to use for the shell command.
/// </summary>
/// <param name="pathNames">Source generation results.</param>
/// <param name="workDirectory">Working directory for shell command.</param>
void Configure(GenerationResults results, string workDirectory);
/// <summary>
/// Executes the assembler. Must call Configure() first. Executed on background thread.
/// </summary>
/// <param name="worker">Async work object, used to report progress updates and
/// check for cancellation.</param>
/// <returns>Execution results, or null on internal failure.</returns>
AssemblerResults RunAssembler(BackgroundWorker worker);
}
/// <summary>
/// Set of values returned by the assembler.
/// </summary>
public class AssemblerResults {
public string CommandLine { get; private set; }
public int ExitCode { get; private set; }
public string Stdout { get; private set; }
public string Stderr { get; private set; }
public string OutputPathName { get; private set; }
public AssemblerResults(string commandLine, int exitCode, string stdout, string stderr,
string outputFile) {
CommandLine = commandLine;
ExitCode = exitCode;
Stdout = stdout;
Stderr = stderr;
OutputPathName = outputFile;
}
}
}