mirror of
https://github.com/fadden/6502bench.git
synced 2025-02-18 08:30:28 +00:00
Add first-word-is-load-addr parameter to system definitions
If set, the first word of the file is used to set the load address. The initial code entry hint is placed at offset +000002 instead of the start of the file. Set it to true for the C64 system definition. (issue #23)
This commit is contained in:
parent
a23c7e5ab6
commit
92add74fc3
@ -227,7 +227,8 @@ namespace SourceGen {
|
||||
mDataFileName = dataFileName;
|
||||
FileDataCrc32 = CommonUtil.CRC32.OnWholeBuffer(0, mFileData);
|
||||
|
||||
// Mark the first byte as code so we have something to do.
|
||||
// Mark the first byte as code so we have something to do. This may get
|
||||
// overridden later.
|
||||
TypeHints[0] = CodeAnalysis.TypeHint.Code;
|
||||
}
|
||||
|
||||
@ -241,9 +242,6 @@ namespace SourceGen {
|
||||
bool includeUndoc = Setup.SystemDefaults.GetUndocumentedOpcodes(sysDef);
|
||||
CpuDef tmpDef = CpuDef.GetBestMatch(cpuType, includeUndoc);
|
||||
|
||||
int loadAddr = Setup.SystemDefaults.GetLoadAddress(sysDef);
|
||||
mAddrMap.Set(0, loadAddr);
|
||||
|
||||
// Store the best-matched CPU in properties, rather than whichever was originally
|
||||
// requested. This way the behavior of the project is the same for everyone, even
|
||||
// if somebody has a newer app version with specialized handling for the
|
||||
@ -254,6 +252,23 @@ namespace SourceGen {
|
||||
|
||||
ProjectProps.EntryFlags = Setup.SystemDefaults.GetEntryFlags(sysDef);
|
||||
|
||||
// Configure the load address.
|
||||
int loadAddr;
|
||||
if (Setup.SystemDefaults.GetFirstWordIsLoadAddr(sysDef) && mFileData.Length > 2) {
|
||||
loadAddr = RawData.GetWord(mFileData, 0, 2, false);
|
||||
loadAddr -= 2;
|
||||
if (loadAddr < 0) {
|
||||
loadAddr += 65536;
|
||||
}
|
||||
OperandFormats[0] = FormatDescriptor.Create(2, FormatDescriptor.Type.NumericLE,
|
||||
FormatDescriptor.SubType.None);
|
||||
TypeHints[0] = CodeAnalysis.TypeHint.NoHint;
|
||||
TypeHints[2] = CodeAnalysis.TypeHint.Code;
|
||||
} else {
|
||||
loadAddr = Setup.SystemDefaults.GetLoadAddress(sysDef);
|
||||
}
|
||||
mAddrMap.Set(0, loadAddr);
|
||||
|
||||
foreach (string str in sysDef.SymbolFiles) {
|
||||
ProjectProps.PlatformSymbolFileIdentifiers.Add(str);
|
||||
}
|
||||
|
@ -173,6 +173,7 @@
|
||||
"ExtensionScripts" : [
|
||||
],
|
||||
"Parameters" : {
|
||||
"first-word-is-load-addr":"true"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -20,10 +20,14 @@ using System.Diagnostics;
|
||||
using Asm65;
|
||||
|
||||
namespace SourceGen.Setup {
|
||||
public class SystemDefaults {
|
||||
/// <summary>
|
||||
/// Helper functions for extracting values from a SystemDef instance.
|
||||
/// </summary>
|
||||
public static class SystemDefaults {
|
||||
private const string LOAD_ADDRESS = "load-address";
|
||||
private const string ENTRY_FLAGS = "entry-flags";
|
||||
private const string UNDOCUMENTED_OPCODES = "undocumented-opcodes";
|
||||
private const string FIRST_WORD_IS_LOAD_ADDR = "first-word-is-load-addr";
|
||||
|
||||
private const string ENTRY_FLAG_EMULATION = "emulation";
|
||||
private const string ENTRY_FLAG_NATIVE_LONG = "native-long";
|
||||
@ -34,7 +38,7 @@ namespace SourceGen.Setup {
|
||||
/// Gets the default load address.
|
||||
/// </summary>
|
||||
/// <param name="sysDef">SystemDef instance.</param>
|
||||
/// <returns>Load address.</returns>
|
||||
/// <returns>Specified load address, or 0x1000 if nothing defined.</returns>
|
||||
public static int GetLoadAddress(SystemDef sysDef) {
|
||||
Dictionary<string, string> parms = sysDef.Parameters;
|
||||
int retVal = 0x1000;
|
||||
@ -94,15 +98,40 @@ namespace SourceGen.Setup {
|
||||
/// <param name="sysDef">SystemDef instance.</param>
|
||||
/// <returns>Enable/disable value.</returns>
|
||||
public static bool GetUndocumentedOpcodes(SystemDef sysDef) {
|
||||
Dictionary<string, string> parms = sysDef.Parameters;
|
||||
bool retVal = false;
|
||||
return GetBoolParam(sysDef, UNDOCUMENTED_OPCODES, false);
|
||||
}
|
||||
|
||||
if (parms.TryGetValue(UNDOCUMENTED_OPCODES, out string valueStr)) {
|
||||
/// <summary>
|
||||
/// Gets the default setting for using the first two bytes of the file as the
|
||||
/// load address.
|
||||
///
|
||||
/// This is primarily for C64. Apple II DOS 3.3 binary files also put the load
|
||||
/// address first, followed by the length, but that's typically stripped out when
|
||||
/// the file is extracted.
|
||||
/// </summary>
|
||||
/// <param name="sysDef"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetFirstWordIsLoadAddr(SystemDef sysDef) {
|
||||
return GetBoolParam(sysDef, FIRST_WORD_IS_LOAD_ADDR, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks for a parameter with a matching name and a boolean value.
|
||||
/// </summary>
|
||||
/// <param name="sysDef">SystemDef reference.</param>
|
||||
/// <param name="paramName">Name of parameter to look for.</param>
|
||||
/// <param name="defVal">Default value.</param>
|
||||
/// <returns>Parsed value, or defVal if the parameter doesn't exist or the value is not
|
||||
/// a boolean string.</returns>
|
||||
private static bool GetBoolParam(SystemDef sysDef, string paramName, bool defVal) {
|
||||
Dictionary<string, string> parms = sysDef.Parameters;
|
||||
bool retVal = defVal;
|
||||
|
||||
if (parms.TryGetValue(paramName, out string valueStr)) {
|
||||
if (bool.TryParse(valueStr, out bool parseVal)) {
|
||||
retVal = parseVal;
|
||||
} else {
|
||||
Debug.WriteLine("WARNING: bad value for " + UNDOCUMENTED_OPCODES +
|
||||
": " + valueStr);
|
||||
Debug.WriteLine("WARNING: bad value for " + paramName + ": " + valueStr);
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
|
Loading…
x
Reference in New Issue
Block a user