1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-05-31 22:41:37 +00:00
6502bench/PluginCommon/Interfaces.cs
Andy McFadden dfd5bcab1b 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 14:55:56 -07:00

166 lines
6.5 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;
namespace PluginCommon {
/// <summary>
/// Extension script "plugins" must implement this interface.
/// </summary>
public interface IPlugin {
/// <summary>
/// Identification string. Contents are arbitrary, but should briefly identify the
/// purpose of the plugin, e.g. "Apple II ProDOS 8 MLI call handler". It may
/// contain version information, but should not be expected to be machine-readable.
/// </summary>
string Identifier { get; }
/// <summary>
/// Prepares the plugin for action. Called at the start of the code analysis pass.
///
/// In the current implementation, the file data will be the same every time,
/// because it doesn't change after the project is opened. However, this could
/// change if we add a descramble feature.
/// </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, AddressTranslate addrTrans,
List<PlSymbol> plSyms);
}
/// <summary>
/// Extension scripts that want to handle inline JSRs must implement this interface.
/// </summary>
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 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);
}
/// <summary>
/// Extension scripts that want to handle inline JSLs must implement this interface.
/// </summary>
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 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);
}
/// <summary>
/// Extension scripts that want to handle inline BRKs must implement this interface.
/// </summary>
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="isTwoBytes">True if the CPU is configured for two-byte BRKs.</param>
/// <param name="noContinue">Set to true if the BRK doesn't actually return.</param>
void CheckBrk(int offset, bool isTwoBytes, out bool noContinue);
}
/// <summary>
/// Interfaces provided by the application for use by plugins. An IApplication instance
/// is passed to the plugin as an argument Prepare().
/// </summary>
public interface IApplication {
/// <summary>
/// Sends a debug message to the application. This can be useful when debugging scripts.
/// (Use DEBUG > Show Analyzer Output to view it.)
/// </summary>
/// <param name="msg">Message to send.</param>
void DebugLog(string msg);
/// <summary>
/// Specifies operand formatting.
/// </summary>
/// <param name="offset">File offset of opcode.</param>
/// <param name="subType">Sub-type. Must be appropriate for NumericLE.</param>
/// <param name="label">Optional symbolic label.</param>
/// <returns>True if the change was made, false if it was rejected.</returns>
bool SetOperandFormat(int offset, DataSubType subType, string label);
/// <summary>
/// Formats file data as inline data.
/// </summary>
/// <param name="offset">File offset.</param>
/// <param name="length">Length of item.</param>
/// <param name="type">Type of item. Must be NumericLE, NumericBE, or Dense.</param>
/// <param name="subType">Sub-type. Must be appropriate for type.</param>
/// <param name="label">Optional symbolic label.</param>
/// <returns>True if the change was made, false if it was rejected (e.g. because
/// the area is already formatted, or contains code).</returns>
/// <exception cref="PluginException">If something is really wrong, e.g. data runs
/// off end of file.</exception>
bool SetInlineDataFormat(int offset, int length, DataType type,
DataSubType subType, string label);
}
/// <summary>
/// Data format type.
/// </summary>
public enum DataType {
Unknown = 0,
NumericLE,
NumericBE,
StringGeneric,
StringReverse,
StringNullTerm,
StringL8,
StringL16,
StringDci,
Dense,
Fill
}
/// <summary>
/// Data format sub-type.
/// </summary>
public enum DataSubType {
// No sub-type specified.
None = 0,
// For NumericLE/BE
Hex,
Decimal,
Binary,
Address,
Symbol,
// Strings and NumericLE/BE (single character)
Ascii,
HighAscii,
C64Petscii,
C64Screen
}
}