mirror of
https://github.com/fadden/6502bench.git
synced 2025-04-14 01:37:07 +00:00
Make address translation available to extension scripts
The current AddressMap is now passed into the plugin manager, which wraps it in an AddressTranslate object and passes that to the plugins at Prepare() time. This allows plugins to convert addresses to offsets, making it possible to format complex structures. This breaks existing plugins.
This commit is contained in:
parent
997242361a
commit
245e0bd9f3
CommonUtil
PluginCommon
SourceGen
RuntimeData/Apple
SGTestData
Sandbox
@ -45,6 +45,7 @@ namespace CommonUtil {
|
||||
/// Entries are mutable, but must only be altered by AddressMap. Don't retain
|
||||
/// instances of this across other activity.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class AddressMapEntry {
|
||||
public int Offset { get; set; }
|
||||
public int Addr { get; set; }
|
||||
@ -78,6 +79,30 @@ namespace CommonUtil {
|
||||
mAddrList.Add(new AddressMapEntry(0, 0, length));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="entries">List of AddressMapEntry.</param>
|
||||
public AddressMap(List<AddressMapEntry> entries) {
|
||||
// TODO(someday): validate list contents
|
||||
mTotalLength = entries[entries.Count - 1].Offset + entries[entries.Count - 1].Length;
|
||||
foreach (AddressMapEntry ent in entries) {
|
||||
mAddrList.Add(ent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the list of entries.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<AddressMapEntry> GetEntryList() {
|
||||
List<AddressMapEntry> newList = new List<AddressMapEntry>(mAddrList.Count);
|
||||
foreach (AddressMapEntry ent in mAddrList) {
|
||||
newList.Add(ent);
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
||||
// IEnumerable
|
||||
public IEnumerator<AddressMapEntry> GetEnumerator() {
|
||||
return ((IEnumerable<AddressMapEntry>)mAddrList).GetEnumerator();
|
||||
|
58
PluginCommon/AddressTranslate.cs
Normal file
58
PluginCommon/AddressTranslate.cs
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 CommonUtil;
|
||||
|
||||
namespace PluginCommon {
|
||||
/// <summary>
|
||||
/// Read-only wrapper around AddressMap.
|
||||
///
|
||||
/// Instance is immutable, though in theory the underlying AddressMap could change if
|
||||
/// some other code has a reference to it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is currently simple enough that it could just be an interface, but I don't want
|
||||
/// to rely on that remaining true.
|
||||
/// </remarks>
|
||||
public class AddressTranslate {
|
||||
private AddressMap mAddrMap;
|
||||
|
||||
public AddressTranslate(AddressMap addrMap) {
|
||||
mAddrMap = addrMap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the file offset that best contains the specified target address.
|
||||
/// </summary>
|
||||
/// <param name="srcOffset">Offset of the address reference. Only matters when
|
||||
/// multiple file offsets map to the same address.</param>
|
||||
/// <param name="targetAddr">Address to look up.</param>
|
||||
/// <returns>The file offset, or -1 if the address falls outside the file.</returns>
|
||||
public int AddressToOffset(int srcOffset, int targetAddr) {
|
||||
return mAddrMap.AddressToOffset(srcOffset, targetAddr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a file offset to an address.
|
||||
/// </summary>
|
||||
/// <param name="offset">File offset.</param>
|
||||
/// <returns>24-bit address.</returns>
|
||||
public int OffsetToAddress(int offset) {
|
||||
return mAddrMap.OffsetToAddress(offset);
|
||||
}
|
||||
}
|
||||
}
|
@ -37,10 +37,12 @@ namespace PluginCommon {
|
||||
/// </summary>
|
||||
/// <param name="appRef">Reference to application interface.</param>
|
||||
/// <param name="fileData">65xx code and data.</param>
|
||||
/// <param name="addrMap">Mapping between offsets and addresses.</param>
|
||||
/// <param name="plSyms">Symbols available to plugins, in no particular order. All
|
||||
/// platform, project, and user labels are included; auto-generated symbols and
|
||||
/// local variables are not.</param>
|
||||
void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSyms);
|
||||
void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -20,6 +20,8 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
using CommonUtil;
|
||||
|
||||
namespace PluginCommon {
|
||||
/// <summary>
|
||||
/// Manages loaded plugins, in the "remote" AppDomain.
|
||||
@ -152,9 +154,12 @@ namespace PluginCommon {
|
||||
/// Invokes the Prepare() method on all active plugins.
|
||||
/// </summary>
|
||||
/// <param name="appRef">Reference to host object providing app services.</param>
|
||||
public void PreparePlugins(IApplication appRef, List<PlSymbol> plSyms) {
|
||||
public void PreparePlugins(IApplication appRef,
|
||||
List<AddressMap.AddressMapEntry> addrEntries, List<PlSymbol> plSyms) {
|
||||
AddressMap addrMap = new AddressMap(addrEntries);
|
||||
AddressTranslate addrTrans = new AddressTranslate(addrMap);
|
||||
foreach (KeyValuePair<string, IPlugin> kvp in mActivePlugins) {
|
||||
kvp.Value.Prepare(appRef, mFileData, plSyms);
|
||||
kvp.Value.Prepare(appRef, mFileData, addrTrans, plSyms);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,8 @@ namespace RuntimeData.Apple {
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSyms) {
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
|
@ -41,7 +41,8 @@ namespace RuntimeData.Apple {
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSyms) {
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
|
@ -43,7 +43,8 @@ namespace RuntimeData.Apple {
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSyms) {
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
|
@ -43,7 +43,8 @@ namespace RuntimeData.Apple {
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSyms) {
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
|
@ -17,7 +17,8 @@ namespace RuntimeData.Test2011 {
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSymbols) {
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
|
@ -24,13 +24,14 @@ namespace RuntimeData.Test2022 {
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlSymbol> plSymbols) {
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans,
|
||||
List<PlSymbol> plSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
mAppRef.DebugLog("Test2022(id=" + AppDomain.CurrentDomain.Id + "): prepare()");
|
||||
|
||||
foreach (PlSymbol sym in plSymbols) {
|
||||
foreach (PlSymbol sym in plSyms) {
|
||||
switch (sym.Label) {
|
||||
case "PrintInline8String":
|
||||
mInline8StringAddr = sym.Value;
|
||||
|
@ -159,11 +159,13 @@ namespace SourceGen.Sandbox {
|
||||
List<PlSymbol> plSyms = GeneratePlSymbolList();
|
||||
|
||||
if (DomainMgr == null) {
|
||||
AddressTranslate addrTrans = new AddressTranslate(mProject.AddrMap);
|
||||
foreach (KeyValuePair<string, IPlugin> kvp in mActivePlugins) {
|
||||
kvp.Value.Prepare(appRef, mProject.FileData, plSyms);
|
||||
kvp.Value.Prepare(appRef, mProject.FileData, addrTrans, plSyms);
|
||||
}
|
||||
} else {
|
||||
DomainMgr.PluginMgr.PreparePlugins(appRef, plSyms);
|
||||
List<AddressMap.AddressMapEntry> addrEnts = mProject.AddrMap.GetEntryList();
|
||||
DomainMgr.PluginMgr.PreparePlugins(appRef, addrEnts, plSyms);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user