1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-12-01 22:50:35 +00:00
6502bench/SourceGen/RuntimeData/Apple/IIgs-Toolbox.cs
Andy McFadden 0616e4e4a4 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.
2019-08-02 16:06:27 -07:00

78 lines
2.6 KiB
C#

/*
* Copyright 2018 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;
/*
# toolbox equ $e10000
# pea ...
# pea ...
# ldx #function
# jsl toolbox
*/
namespace RuntimeData.Apple {
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;
private IApplication mAppRef;
private byte[] mFileData;
private Dictionary<int, PlatSym> mFunctionList;
public string Identifier {
get {
return "Apple IIgs toolbox call handler";
}
}
public void Prepare(IApplication appRef, byte[] fileData, List<PlatSym> platSyms) {
mAppRef = appRef;
mFileData = fileData;
mAppRef.DebugLog("IIgsToolbox(id=" + AppDomain.CurrentDomain.Id + "): prepare()");
mFunctionList = PlatSym.GenerateValueList(platSyms, TOOLBOX_FUNC_TAG, appRef);
}
public void CheckJsl(int offset, out bool noContinue) {
noContinue = false;
if (offset < 3) {
return;
}
// This only works if the LDX with the function comes right before the JSL.
// Fortunately, the assembler macros all work that way.
if (mFileData[offset + 1] == 0x00 && mFileData[offset + 2] == 0x00 &&
mFileData[offset + 3] == 0xe1 && mFileData[offset - 3] == 0xa2 /*LDX imm*/) {
// match!
int func = Util.GetWord(mFileData, offset - 2, 2, false);
if (VERBOSE) {
mAppRef.DebugLog("Toolbox call detected at +" + offset.ToString("x6") +
", func=$" + func.ToString("x4"));
}
PlatSym sym;
if (mFunctionList.TryGetValue(func, out sym)) {
mAppRef.SetOperandFormat(offset - 3, DataSubType.Symbol, sym.Label);
}
}
}
}
}