mirror of
https://github.com/fadden/6502bench.git
synced 2024-11-26 06:49:19 +00:00
Define interfaces for inline call handlers and BRK
Instead of providing no-op CheckJsr/CheckJsl, plugins now declare which calls they support by defining interfaces on the plugin class. I added a CheckBrk call for code like Apple /// SOS calls, which use BRK as an OS call mechanism. The formatting doesn't work quite right yet because I've been treating BRK as a two-byte instruction. Hardly anything else does, and I think it's time I stopped (but not in this commit). Note: THIS BREAKS ALL PLUGINS that use the inline JSR/JSL feature, which is pretty much all of them.
This commit is contained in:
parent
d41266442d
commit
0616e4e4a4
@ -45,26 +45,41 @@ namespace PluginCommon {
|
||||
/// <param name="fileData">65xx code and data.</param>
|
||||
/// <param name="platSyms">Platform symbols, in no particular order.</param>
|
||||
void Prepare(IApplication appRef, byte[] fileData, List<PlatSym> platSyms);
|
||||
}
|
||||
|
||||
public interface IPlugin_InlineJsr {
|
||||
/// <summary>
|
||||
/// Checks to see if code/data near a JSR instruction should be formatted.
|
||||
///
|
||||
/// The file data is guaranteed to hold the JSR (offset + 2).
|
||||
///
|
||||
/// The file data is guaranteed to hold all bytes of the JSR (offset + 2).
|
||||
/// </summary>
|
||||
/// <param name="offset">Offset of the JSR instruction.</param>
|
||||
/// <param name="noContinue">Set to true if the JSR doesn't actually return.</param>
|
||||
void CheckJsr(int offset, out bool noContinue);
|
||||
}
|
||||
|
||||
public interface IPlugin_InlineJsl {
|
||||
/// <summary>
|
||||
/// Checks to see if code/data near a JSL instruction should be formatted.
|
||||
///
|
||||
/// The file data is guaranteed to hold the JSL (offset + 3).
|
||||
///
|
||||
/// The file data is guaranteed to hold all bytes of the JSL (offset + 3).
|
||||
/// </summary>
|
||||
/// <param name="offset">Offset of the JSL instruction.</param>
|
||||
/// <param name="noContinue">Set to true if the JSL doesn't actually return.</param>
|
||||
void CheckJsl(int offset, out bool noContinue);
|
||||
}
|
||||
|
||||
public interface IPlugin_InlineBrk {
|
||||
/// <summary>
|
||||
/// Checks to see if code/data near a BRK instruction should be formatted.
|
||||
///
|
||||
/// The file data is only guaranteed to hold the BRK opcode byte.
|
||||
/// </summary>
|
||||
/// <param name="offset">Offset of the BRK instruction.</param>
|
||||
/// <param name="noContinue">Set to true if the BRK doesn't actually return.</param>
|
||||
void CheckBrk(int offset, out bool noContinue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interfaces provided by the application for use by plugins.
|
||||
/// </summary>
|
||||
|
@ -644,6 +644,13 @@ namespace SourceGen {
|
||||
}
|
||||
}
|
||||
|
||||
// On first visit, check for BRK inline call.
|
||||
if (firstVisit) {
|
||||
if (op == OpDef.OpBRK_StackInt) {
|
||||
CheckForInlineCall(op, offset, out bool unused);
|
||||
}
|
||||
}
|
||||
|
||||
if (!doContinue) {
|
||||
mAnattribs[offset].DoesNotContinue = true;
|
||||
break;
|
||||
@ -899,14 +906,15 @@ namespace SourceGen {
|
||||
noContinue = false;
|
||||
for (int i = 0; i < mScriptArray.Length; i++) {
|
||||
IPlugin script = mScriptArray[i];
|
||||
if (op == OpDef.OpJSR_Abs) {
|
||||
script.CheckJsr(offset, out bool noCont);
|
||||
if (op == OpDef.OpJSR_Abs && script is IPlugin_InlineJsr) {
|
||||
((IPlugin_InlineJsr)script).CheckJsr(offset, out bool noCont);
|
||||
noContinue |= noCont;
|
||||
} else if (op == OpDef.OpJSR_AbsLong) {
|
||||
script.CheckJsl(offset, out bool noCont);
|
||||
} else if (op == OpDef.OpJSR_AbsLong && script is IPlugin_InlineJsl) {
|
||||
((IPlugin_InlineJsl)script).CheckJsl(offset, out bool noCont);
|
||||
noContinue |= noCont;
|
||||
} else {
|
||||
Debug.Assert(false);
|
||||
} else if (op == OpDef.OpBRK_StackInt && script is IPlugin_InlineBrk) {
|
||||
((IPlugin_InlineBrk)script).CheckBrk(offset, out bool noCont);
|
||||
noContinue &= noCont;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ using PluginCommon;
|
||||
*/
|
||||
|
||||
namespace RuntimeData.Apple {
|
||||
public class GSOS : MarshalByRefObject, IPlugin {
|
||||
public class GSOS : MarshalByRefObject, IPlugin, IPlugin_InlineJsl {
|
||||
private const string GSOS_FUNC_TAG = "AppleIIgs-GSOS-Functions"; // tag used in .sym65 file
|
||||
private bool VERBOSE = false;
|
||||
|
||||
@ -58,11 +58,6 @@ namespace RuntimeData.Apple {
|
||||
mFunctionList = PlatSym.GenerateValueList(platSyms, GSOS_FUNC_TAG, appRef);
|
||||
}
|
||||
|
||||
public void CheckJsr(int offset, out bool noContinue) {
|
||||
// Not used by GS/OS
|
||||
noContinue = false;
|
||||
}
|
||||
|
||||
public void CheckJsl(int offset, out bool noContinue) {
|
||||
noContinue = false;
|
||||
if (offset + 7 < mFileData.Length && mFileData[offset + 1] == 0xa8 &&
|
||||
|
@ -27,7 +27,7 @@ using PluginCommon;
|
||||
*/
|
||||
|
||||
namespace RuntimeData.Apple {
|
||||
public class IIgsToolbox : MarshalByRefObject, IPlugin {
|
||||
public class IIgsToolbox : MarshalByRefObject, IPlugin, IPlugin_InlineJsl {
|
||||
private const string TOOLBOX_FUNC_TAG = "AppleIIgs-Toolbox-Functions"; // tag used in .sym65 file
|
||||
private bool VERBOSE = false;
|
||||
|
||||
@ -50,11 +50,6 @@ namespace RuntimeData.Apple {
|
||||
mFunctionList = PlatSym.GenerateValueList(platSyms, TOOLBOX_FUNC_TAG, appRef);
|
||||
}
|
||||
|
||||
public void CheckJsr(int offset, out bool noContinue) {
|
||||
// Not used
|
||||
noContinue = false;
|
||||
}
|
||||
|
||||
public void CheckJsl(int offset, out bool noContinue) {
|
||||
noContinue = false;
|
||||
if (offset < 3) {
|
||||
|
@ -29,7 +29,7 @@ parm_block
|
||||
*/
|
||||
|
||||
namespace RuntimeData.Apple {
|
||||
public class ProDOS8 : MarshalByRefObject, IPlugin {
|
||||
public class ProDOS8 : MarshalByRefObject, IPlugin, IPlugin_InlineJsr {
|
||||
private const string P8_MLI_TAG = "ProDOS8-MLI-Functions"; // tag used in .sym65 file
|
||||
private bool VERBOSE = false;
|
||||
|
||||
@ -82,10 +82,5 @@ namespace RuntimeData.Apple {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckJsl(int offset, out bool noContinue) {
|
||||
// Not used by ProDOS 8.
|
||||
noContinue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
88
SourceGen/RuntimeData/Apple/SOS.cs
Normal file
88
SourceGen/RuntimeData/Apple/SOS.cs
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 PluginCommon;
|
||||
|
||||
/*
|
||||
BRK
|
||||
DFB command_code
|
||||
DW parm_block
|
||||
|
||||
parm_block
|
||||
dfb parm_count
|
||||
parameters...
|
||||
*/
|
||||
|
||||
namespace RuntimeData.Apple {
|
||||
public class SOS : MarshalByRefObject, IPlugin, IPlugin_InlineBrk {
|
||||
private const string SOS_MLI_TAG = "SOS-MLI-Functions"; // tag used in .sym65 file
|
||||
private bool VERBOSE = true;
|
||||
|
||||
private IApplication mAppRef;
|
||||
private byte[] mFileData;
|
||||
private Dictionary<int, PlatSym> mFunctionList;
|
||||
|
||||
public string Identifier {
|
||||
get {
|
||||
return "Apple III SOS MLI call handler";
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, List<PlatSym> platSyms) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
mAppRef.DebugLog("SOS(id=" + AppDomain.CurrentDomain.Id + "): prepare()");
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
|
||||
mFunctionList = PlatSym.GenerateValueList(platSyms, SOS_MLI_TAG, appRef);
|
||||
}
|
||||
|
||||
public void CheckBrk(int offset, out bool noContinue) {
|
||||
noContinue = true;
|
||||
if (offset + 4 >= mFileData.Length) {
|
||||
// ran off the end
|
||||
return;
|
||||
}
|
||||
|
||||
// We don't want every BRK to get formatted, so we only format it if we find
|
||||
// a matching symbol for the command code.
|
||||
|
||||
byte req = mFileData[offset + 1];
|
||||
if (VERBOSE) {
|
||||
int addr = Util.GetWord(mFileData, offset + 2, 2, false);
|
||||
mAppRef.DebugLog("Potential SOS call detected at +" + offset.ToString("x6") +
|
||||
", cmd=$" + req.ToString("x2") + " addr=$" + addr.ToString("x4"));
|
||||
}
|
||||
|
||||
PlatSym sym;
|
||||
if (!mFunctionList.TryGetValue(req, out sym)) {
|
||||
return;
|
||||
}
|
||||
mAppRef.SetInlineDataFormat(offset + 1, 1, DataType.NumericLE,
|
||||
DataSubType.Symbol, sym.Label);
|
||||
mAppRef.SetInlineDataFormat(offset + 2, 2, DataType.NumericLE,
|
||||
DataSubType.Address, null);
|
||||
|
||||
// Clear the "no continue" flag unless this is a QUIT call.
|
||||
if (req != 0x65) { // QUIT call
|
||||
noContinue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -90,6 +90,7 @@
|
||||
"RT:Apple/SOS.sym65"
|
||||
],
|
||||
"ExtensionScripts" : [
|
||||
"RT:Apple/SOS.cs"
|
||||
],
|
||||
"Parameters" : {
|
||||
"load-address":"0x2000"
|
||||
|
@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using PluginCommon;
|
||||
|
||||
namespace RuntimeData.Test2011 {
|
||||
public class Test2011 : MarshalByRefObject, IPlugin {
|
||||
public class Test2011 : MarshalByRefObject, IPlugin, IPlugin_InlineJsr {
|
||||
private IApplication mAppRef;
|
||||
private byte[] mFileData;
|
||||
|
||||
@ -32,9 +32,5 @@ namespace RuntimeData.Test2011 {
|
||||
DataSubType.None, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckJsl(int offset, out bool noContinue) {
|
||||
noContinue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user