-
Notifications
You must be signed in to change notification settings - Fork 0
/
InlineBTRString.cs
95 lines (78 loc) · 3.39 KB
/
InlineBTRString.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// https://github.com/fadden/6502bench/blob/master/PluginCommon/Interfaces.cs
// https://github.com/fadden/6502bench/blob/master/PluginCommon/Util.cs
// Original license:
// 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 ExtensionScriptSample {
/// <summary>
/// Class for handling a JSR followed by a 1-byte position, then a string terminated with $FF.
/// </summary>
public class InlineBTRString: MarshalByRefObject, IPlugin, IPlugin_SymbolList,
IPlugin_InlineJsr {
private IApplication mAppRef;
private byte[] mFileData;
// Only one call.
private const string LABEL_SUFFIX = "PRNTSTR";
private Dictionary<int, PlSymbol> mBTRStringAddrs = new Dictionary<int, PlSymbol>();
private int terminatingByte = 0xff;
public string Identifier {
get {
return "Inline BTR string handler";
}
}
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) {
mAppRef = appRef;
mFileData = fileData;
mAppRef.DebugLog("InlineBTRString(id=" +
AppDomain.CurrentDomain.Id + "): prepare()");
}
public void Unprepare() {
mAppRef = null;
mFileData = null;
}
public void UpdateSymbolList(List<PlSymbol> plSyms) {
mBTRStringAddrs.Clear();
foreach (PlSymbol sym in plSyms) {
if (sym.Label.EndsWith(LABEL_SUFFIX)) {
mBTRStringAddrs.Add(sym.Value, sym);
}
}
mAppRef.DebugLog(LABEL_SUFFIX + " matched " + mBTRStringAddrs.Count + " labels");
}
public bool IsLabelSignificant(string beforeLabel, string afterLabel) {
return beforeLabel.EndsWith(LABEL_SUFFIX) || afterLabel.EndsWith(LABEL_SUFFIX);
}
public void CheckJsr(int offset, int operand, out bool noContinue) {
noContinue = false;
if (!mBTRStringAddrs.ContainsKey(operand)) {
return;
}
// search for the terminating byte
if (offset + 3 >= mFileData.Length) {
mAppRef.DebugLog("Unable to find BTR formatting byte at +" +
(offset+3).ToString("x6"));
return;
}
int termOff = offset + 3 + 1;
while (termOff < mFileData.Length) {
if (mFileData[termOff] == terminatingByte) {
break;
}
termOff++;
}
if (termOff == mFileData.Length) {
mAppRef.DebugLog("Unable to find end of BTR string at +" +
(offset+3).ToString("x6"));
return;
}
mAppRef.SetInlineDataFormat(offset + 3, 1, DataType.NumericLE, DataSubType.Hex, null);
int strLength = termOff - (offset + 3 + 1);
mAppRef.SetInlineDataFormat(offset + 3 + 1, strLength,
DataType.StringGeneric, DataSubType.HighAscii, null);
mAppRef.SetInlineDataFormat(offset + 3 + 1 + strLength, 1, DataType.NumericLE, DataSubType.Hex, null);
}
}
}