mirror of
https://github.com/fadden/6502bench.git
synced 2026-04-20 04:16:47 +00:00
Rearrange the tutorial files
Copied the extension script tutorial files out of the Scripts directory and into the Tutorial directory. This makes more sense, and makes it possible to expand the script sample without altering the tutorial. Reverted the Scripts sample to be an actual sample, rather than a tutorial. Renumbered the last two tutorials and added them to the ToC. This gives them actual numbers rather than treating them as add-ons to the advanced tutorial. Moved the source files for the tutorial binaries into a subdirectory to reduce clutter. This does mean we have two separate copies of the inline string sample plugins, but that's an artifact of our attempts at security.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// Copyright 2019 faddenSoft. All Rights Reserved.
|
||||
// See the LICENSE.txt file for distribution terms (Apache 2.0).
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using PluginCommon;
|
||||
|
||||
namespace ExtensionScriptSample {
|
||||
/// <summary>
|
||||
/// Sample class for handling a JSR followed by a string prefixed with a 1-byte length.
|
||||
/// </summary>
|
||||
public class InlineL1String: MarshalByRefObject, IPlugin, IPlugin_SymbolList,
|
||||
IPlugin_InlineJsr {
|
||||
private IApplication mAppRef;
|
||||
private byte[] mFileData;
|
||||
|
||||
// Only one call.
|
||||
private const string CALL_LABEL = "PrintInlineL1String";
|
||||
private int mInlineL1StringAddr; // jsr
|
||||
|
||||
public string Identifier {
|
||||
get {
|
||||
return "Inline L1 ASCII string handler";
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
mAppRef.DebugLog("InlineL1String(id=" +
|
||||
AppDomain.CurrentDomain.Id + "): prepare()");
|
||||
}
|
||||
|
||||
public void UpdateSymbolList(List<PlSymbol> plSyms) {
|
||||
// reset this every time, in case they remove the symbol
|
||||
mInlineL1StringAddr = -1;
|
||||
|
||||
foreach (PlSymbol sym in plSyms) {
|
||||
if (sym.Label == CALL_LABEL) {
|
||||
mInlineL1StringAddr = sym.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mAppRef.DebugLog(CALL_LABEL + " @ $" + mInlineL1StringAddr.ToString("x6"));
|
||||
}
|
||||
public bool IsLabelSignificant(string beforeLabel, string afterLabel) {
|
||||
return beforeLabel == CALL_LABEL || afterLabel == CALL_LABEL;
|
||||
}
|
||||
|
||||
public void CheckJsr(int offset, int operand, out bool noContinue) {
|
||||
noContinue = false;
|
||||
if (operand != mInlineL1StringAddr) {
|
||||
return;
|
||||
}
|
||||
if (offset + 3 >= mFileData.Length) {
|
||||
return; // length byte is off end
|
||||
}
|
||||
int len = mFileData[3]; // first byte past JSR
|
||||
if (offset + 4 + len > mFileData.Length) {
|
||||
mAppRef.DebugLog("L1 string ran off end of file at +" +
|
||||
(offset + 4).ToString("x6"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Assuming ASCII. This can be hard-coded, use auto-detection, or look
|
||||
// up a value in a project constant.
|
||||
mAppRef.SetInlineDataFormat(offset + 3, len + 1,
|
||||
DataType.StringL8, DataSubType.Ascii, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright 2019 faddenSoft. All Rights Reserved.
|
||||
// See the LICENSE.txt file for distribution terms (Apache 2.0).
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using PluginCommon;
|
||||
|
||||
namespace ExtensionScriptSample {
|
||||
/// <summary>
|
||||
/// Sample class for handling a JSR followed by an inline null-terminated string. Any
|
||||
/// label that starts with "PrintLineNullString" is matched.
|
||||
/// </summary>
|
||||
public class InlineNullTermString : MarshalByRefObject, IPlugin, IPlugin_SymbolList,
|
||||
IPlugin_InlineJsr {
|
||||
private IApplication mAppRef;
|
||||
private byte[] mFileData;
|
||||
|
||||
private const string LABEL_PREFIX = "PrintInlineNullString";
|
||||
private Dictionary<int, PlSymbol> mNullStringAddrs = new Dictionary<int, PlSymbol>();
|
||||
|
||||
public string Identifier {
|
||||
get {
|
||||
return "Inline null-terminated ASCII string handler";
|
||||
}
|
||||
}
|
||||
|
||||
public void Prepare(IApplication appRef, byte[] fileData, AddressTranslate addrTrans) {
|
||||
mAppRef = appRef;
|
||||
mFileData = fileData;
|
||||
|
||||
mAppRef.DebugLog("InlineNullStringHandler(id=" +
|
||||
AppDomain.CurrentDomain.Id + "): prepare()");
|
||||
}
|
||||
|
||||
public void UpdateSymbolList(List<PlSymbol> plSyms) {
|
||||
mNullStringAddrs.Clear();
|
||||
|
||||
foreach (PlSymbol sym in plSyms) {
|
||||
if (sym.Label.StartsWith(LABEL_PREFIX)) {
|
||||
mNullStringAddrs.Add(sym.Value, sym);
|
||||
}
|
||||
}
|
||||
mAppRef.DebugLog(LABEL_PREFIX + " matched " + mNullStringAddrs.Count + " labels");
|
||||
}
|
||||
public bool IsLabelSignificant(string beforeLabel, string afterLabel) {
|
||||
return beforeLabel.StartsWith(LABEL_PREFIX) || afterLabel.StartsWith(LABEL_PREFIX);
|
||||
}
|
||||
|
||||
public void CheckJsr(int offset, int operand, out bool noContinue) {
|
||||
noContinue = false;
|
||||
if (!mNullStringAddrs.ContainsKey(operand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// search for the terminating null byte
|
||||
int nullOff = offset + 3;
|
||||
while (nullOff < mFileData.Length) {
|
||||
if (mFileData[nullOff] == 0) {
|
||||
break;
|
||||
}
|
||||
nullOff++;
|
||||
}
|
||||
if (nullOff == mFileData.Length) {
|
||||
mAppRef.DebugLog("Unable to find end of null-terminated string at +" +
|
||||
(offset+3).ToString("x6"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Assuming ASCII. This can be hard-coded, use auto-detection, or look
|
||||
// up a value in a project constant.
|
||||
mAppRef.SetInlineDataFormat(offset + 3, nullOff - (offset + 3) + 1,
|
||||
DataType.StringNullTerm, DataSubType.Ascii, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
; Copyright 2019 faddenSoft. All Rights Reserved.
|
||||
; See the LICENSE.txt file for distribution terms (Apache 2.0).
|
||||
;
|
||||
; Assembler: Merlin 32
|
||||
|
||||
org $1000
|
||||
|
||||
jsr PrintInlineL1String
|
||||
str 'How long?'
|
||||
|
||||
jsr PrintInlineZString1
|
||||
asc 'Test one',00
|
||||
|
||||
jsr PrintInlineZString2
|
||||
asc 'Test two',00
|
||||
rts
|
||||
|
||||
PrintInlineL1String
|
||||
rts
|
||||
PrintInlineZString1
|
||||
rts
|
||||
PrintInlineZString2
|
||||
rts
|
||||
Binary file not shown.
Reference in New Issue
Block a user