2019-08-02 23:06:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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 {
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public class SOS : MarshalByRefObject, IPlugin, IPlugin_SymbolList, IPlugin_InlineBrk {
|
2019-08-02 23:06:27 +00:00
|
|
|
|
private const string SOS_MLI_TAG = "SOS-MLI-Functions"; // tag used in .sym65 file
|
|
|
|
|
private bool VERBOSE = true;
|
|
|
|
|
|
|
|
|
|
private IApplication mAppRef;
|
|
|
|
|
private byte[] mFileData;
|
2019-10-04 23:53:31 +00:00
|
|
|
|
private Dictionary<int, PlSymbol> mFunctionList;
|
2019-08-02 23:06:27 +00:00
|
|
|
|
|
|
|
|
|
public string Identifier {
|
|
|
|
|
get {
|
|
|
|
|
return "Apple III SOS MLI call handler";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) {
|
2019-08-02 23:06:27 +00:00
|
|
|
|
mAppRef = appRef;
|
|
|
|
|
mFileData = fileData;
|
|
|
|
|
|
|
|
|
|
mAppRef.DebugLog("SOS(id=" + AppDomain.CurrentDomain.Id + "): prepare()");
|
|
|
|
|
//System.Diagnostics.Debugger.Break();
|
2019-10-14 01:19:28 +00:00
|
|
|
|
}
|
2019-08-02 23:06:27 +00:00
|
|
|
|
|
2019-12-01 01:52:33 +00:00
|
|
|
|
public void Unprepare() {
|
|
|
|
|
mAppRef = null;
|
|
|
|
|
mFileData = null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 01:19:28 +00:00
|
|
|
|
public void UpdateSymbolList(List<PlSymbol> plSyms) {
|
|
|
|
|
// Extract the list of function name constants from the platform symbol file.
|
|
|
|
|
mFunctionList = PlSymbol.GeneratePlatformValueList(plSyms, SOS_MLI_TAG, mAppRef);
|
|
|
|
|
}
|
|
|
|
|
public bool IsLabelSignificant(string beforeLabel, string afterLabel) {
|
|
|
|
|
return false;
|
2019-08-02 23:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-08-02 23:06:27 +00:00
|
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-04 23:53:31 +00:00
|
|
|
|
PlSymbol sym;
|
2019-08-02 23:06:27 +00:00
|
|
|
|
if (!mFunctionList.TryGetValue(req, out sym)) {
|
|
|
|
|
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.Symbol, sym.Label);
|
2019-08-02 23:06:27 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|