2019-10-07 21:21:26 +00:00
|
|
|
|
// Copyright 2019 faddenSoft. All Rights Reserved.
|
|
|
|
|
// See the LICENSE.txt file for distribution terms (Apache 2.0).
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using PluginCommon;
|
|
|
|
|
|
|
|
|
|
namespace RuntimeData.Test2022 {
|
|
|
|
|
public class Test2022B : MarshalByRefObject, IPlugin, IPlugin_InlineBrk {
|
|
|
|
|
private IApplication mAppRef;
|
|
|
|
|
private byte[] mFileData;
|
|
|
|
|
private AddressTranslate mAddrTrans;
|
|
|
|
|
|
|
|
|
|
public string Identifier {
|
|
|
|
|
get {
|
|
|
|
|
return "Test 2022-extension-scripts B";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) {
|
2019-10-07 21:21:26 +00:00
|
|
|
|
mAppRef = appRef;
|
|
|
|
|
mFileData = fileData;
|
|
|
|
|
mAddrTrans = addrTrans;
|
|
|
|
|
|
|
|
|
|
mAppRef.DebugLog("Test2022-B(id=" + AppDomain.CurrentDomain.Id + "): prepare()");
|
|
|
|
|
}
|
|
|
|
|
|
Optionally treat BRKs as two-byte instructions
Early data sheets listed BRK as one byte, but RTI after a BRK skips
the following byte, effectively making BRK a 2-byte instruction.
Sometimes, such as when diassembling Apple /// SOS code, it's handy
to treat it that way explicitly.
This change makes two-byte BRKs optional, controlled by a checkbox
in the project settings. In the system definitions it defaults to
true for Apple ///, false for all others.
ACME doesn't allow BRK to have an arg, and cc65 only allows it for
65816 code (?), so it's emitted as a hex blob for those assemblers.
Anyone wishing to target those assemblers should stick to 1-byte mode.
Extension scripts have to switch between formatting one byte of
inline data and formatting an instruction with a one-byte operand.
A helper function has been added to the plugin Util class.
To get some regression test coverage, 2022-extension-scripts has
been configured to use two-byte BRK.
Also, added/corrected some SOS constants.
See also issue #44.
2019-10-09 21:55:56 +00:00
|
|
|
|
public void CheckBrk(int offset, bool twoByteBrk, out bool noContinue) {
|
2019-10-07 21:21:26 +00:00
|
|
|
|
noContinue = true;
|
|
|
|
|
|
|
|
|
|
// need BRK, function byte, and two-byte address
|
|
|
|
|
if (!Util.IsInBounds(mFileData, offset, 4)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
byte func = mFileData[offset + 1];
|
2019-10-19 23:23:42 +00:00
|
|
|
|
if (func != 0x85 && (func < 0x01 || func > 0x02)) {
|
2019-10-07 21:21:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Optionally treat BRKs as two-byte instructions
Early data sheets listed BRK as one byte, but RTI after a BRK skips
the following byte, effectively making BRK a 2-byte instruction.
Sometimes, such as when diassembling Apple /// SOS code, it's handy
to treat it that way explicitly.
This change makes two-byte BRKs optional, controlled by a checkbox
in the project settings. In the system definitions it defaults to
true for Apple ///, false for all others.
ACME doesn't allow BRK to have an arg, and cc65 only allows it for
65816 code (?), so it's emitted as a hex blob for those assemblers.
Anyone wishing to target those assemblers should stick to 1-byte mode.
Extension scripts have to switch between formatting one byte of
inline data and formatting an instruction with a one-byte operand.
A helper function has been added to the plugin Util class.
To get some regression test coverage, 2022-extension-scripts has
been configured to use two-byte BRK.
Also, added/corrected some SOS constants.
See also issue #44.
2019-10-09 21:55:56 +00:00
|
|
|
|
Util.FormatBrkByte(mAppRef, twoByteBrk, offset, DataSubType.Hex, null);
|
2019-10-07 21:21:26 +00:00
|
|
|
|
mAppRef.SetInlineDataFormat(offset + 2, 2, DataType.NumericLE,
|
|
|
|
|
DataSubType.Address, null);
|
|
|
|
|
noContinue = false;
|
|
|
|
|
|
|
|
|
|
int structAddr = Util.GetWord(mFileData, offset + 2, 2, false);
|
|
|
|
|
int structOff = mAddrTrans.AddressToOffset(offset, structAddr);
|
|
|
|
|
if (structOff < 0) {
|
|
|
|
|
mAppRef.DebugLog("Unable to get offset for address $" + structAddr.ToString("x6"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (func) {
|
|
|
|
|
case 0x01:
|
|
|
|
|
if (!Util.IsInBounds(mFileData, structOff, 27)) {
|
|
|
|
|
mAppRef.DebugLog("Struct doesn't fit in file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 0, 2, DataType.NumericLE,
|
|
|
|
|
DataSubType.Decimal, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 2, 2, DataType.NumericBE,
|
|
|
|
|
DataSubType.Hex, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 4, 4, DataType.NumericLE,
|
|
|
|
|
DataSubType.Hex, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 8, 4, DataType.NumericBE,
|
|
|
|
|
DataSubType.Hex, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 12, 1, DataType.NumericLE,
|
|
|
|
|
DataSubType.Ascii, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 13, 1, DataType.NumericLE,
|
|
|
|
|
DataSubType.HighAscii, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 14, 8, DataType.StringDci,
|
|
|
|
|
DataSubType.Ascii, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 22, 3, DataType.NumericLE,
|
|
|
|
|
DataSubType.Address, null);
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff + 25, 2, DataType.NumericLE,
|
|
|
|
|
DataSubType.Symbol, "data02");
|
|
|
|
|
break;
|
|
|
|
|
case 0x02:
|
|
|
|
|
if (!Util.IsInBounds(mFileData, structOff, 2)) {
|
|
|
|
|
mAppRef.DebugLog("Struct doesn't fit in file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(structOff, 2, DataType.NumericLE,
|
|
|
|
|
DataSubType.Address, null);
|
|
|
|
|
int nextAddr = Util.GetWord(mFileData, structOff + 2, 2, false);
|
|
|
|
|
int nextOff = mAddrTrans.AddressToOffset(structOff, nextAddr);
|
|
|
|
|
if (!Util.IsInBounds(mFileData, nextOff, 1)) {
|
|
|
|
|
mAppRef.DebugLog("Struct doesn't fit in file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mAppRef.SetInlineDataFormat(nextOff, 8, DataType.StringGeneric,
|
|
|
|
|
DataSubType.HighAscii, null);
|
|
|
|
|
break;
|
2019-10-19 23:23:42 +00:00
|
|
|
|
case 0x85:
|
|
|
|
|
// do nothing further
|
|
|
|
|
break;
|
2019-10-07 21:21:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|