Skip to content

Commit

Permalink
Version 2.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
informedcitizenry committed Nov 19, 2021
1 parent 37deaa6 commit 1473abf
Show file tree
Hide file tree
Showing 24 changed files with 633 additions and 357 deletions.
2 changes: 1 addition & 1 deletion Core6502DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Global
SolutionGuid = {9BE7575F-6E99-4243-AEAA-4D1E1064DA97}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 2.8.0.1
version = 2.8.1.1
Policies = $0
$0.VersionControlPolicy = $1
$1.CommitMessageStyle = $2
Expand Down
6 changes: 3 additions & 3 deletions Core6502DotNet/Core6502DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<PackageId>6502.Net</PackageId>
<Version>2.8.0.1</Version>
<Version>2.8.1.1</Version>
<Authors>informedcitizenry</Authors>
<Company>informedcitizenry</Company>
<Product>6502.Net</Product>
Expand All @@ -13,8 +13,8 @@
<ReleaseVersion>2.4.1</ReleaseVersion>
<StartupObject>Core6502DotNet.Program</StartupObject>
<AssemblyName>6502.Net</AssemblyName>
<AssemblyVersion>2.8.0.1</AssemblyVersion>
<FileVersion>2.8.0.1</FileVersion>
<AssemblyVersion>2.8.1.1</AssemblyVersion>
<FileVersion>2.8.1.1</FileVersion>
<SignAssembly>false</SignAssembly>
<PackageProjectUrl>https://github.com/informedcitizenry/6502.Net</PackageProjectUrl>
</PropertyGroup>
Expand Down
5 changes: 4 additions & 1 deletion Core6502DotNet/src/Core/AssembleErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public void HandleError(object sender, AssemblyErrorEventArgs args)
}
else if (args.Exception is BlockClosureException blockEx)
{
_services.Log.LogEntry(blockEx.LineExpectingClosure.Instruction, blockEx.Message);
if (blockEx.LineExpectingClosure.Instruction != null)
_services.Log.LogEntry(blockEx.LineExpectingClosure.Instruction, blockEx.Message);
else
_services.Log.LogEntry(blockEx.LineExpectingClosure, 1, blockEx.Message);
}
else
{
Expand Down
19 changes: 15 additions & 4 deletions Core6502DotNet/src/Core/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public static class Assembler
#region Properties

/// <summary>
/// Gets the version of the assembler. This can and should be set
/// by the client code.
/// Gets the version of the assembler.
/// </summary>
public static string AssemblerVersion
{
Expand All @@ -31,8 +30,20 @@ public static string AssemblerVersion
}

/// <summary>
/// Gets the assembler (product) name. This can and should be set
/// by the client code.
/// Gets the assembly product summary, including simple name and version.
/// </summary>
public static string ProductSummary
{
get
{
var product = Assembly.GetEntryAssembly().GetName();
return $"{product.Name} Version {product.Version}";
}
}


/// <summary>
/// Gets the assembler (product) name.
/// </summary>
public static string AssemblerName
{
Expand Down
7 changes: 7 additions & 0 deletions Core6502DotNet/src/Core/AssemblerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public string Assemble(RandomAccessIterator<SourceLine> lines)
var first = lines.Current;
bool isSpecial = first.Label != null && first.Label.IsSpecialOperator();
LogicalPCOnAssemble = Services.Output.LogicalPC;
LongLogicalPCOnAssemble = Services.Output.LongLogicalPC;
PCOnAssemble = Services.Output.ProgramCounter;
LongPCOnAssemble = Services.Output.LongProgramCounter;
if (first.Label != null && !first.Label.Name.Equals("*"))
Expand Down Expand Up @@ -193,6 +194,12 @@ protected void DefineLabel(Token label, double address, bool setLocalScope)
/// </summary>
protected int LogicalPCOnAssemble { get; private set; }

/// <summary>
/// Gets the state of the long Logical Program Counter for the <see cref="Assembler"/>'s <see cref="BinaryOutput"/>
/// object when OnAssemble was invoked.
/// </summary>
protected int LongLogicalPCOnAssemble { get; private set; }

/// <summary>
/// Gets the state of the real Program Counter for the <see cref="Assembler"/>'s <see cref="BinaryOutput"/>
/// object when OnAssemble was invoked.
Expand Down
7 changes: 3 additions & 4 deletions Core6502DotNet/src/Core/AssemblyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ public double Assemble()
else
{
var passedArgs = _services.Options.GetPassedArgs();
var exec = Process.GetCurrentProcess().MainModule.ModuleName;
var inputFiles = string.Join("\n// ", preprocessor.GetInputFiles());
var fullDisasm = $"// {Assembler.AssemblerNameSimple}\n" +
$"// {exec} {string.Join(' ', passedArgs)}\n" +
$"// {DateTime.Now:f}\n\n// Input files:\n\n" +
var fullDisasm = $"// {Assembler.ProductSummary}\n" +
$"// Options: {string.Join(' ', passedArgs)}\n" +
$"// {DateTime.Now:f}\n// Input files:\n\n" +
$"// {inputFiles}\n\n" + disassembly;
byteCount = WriteOutput(fullDisasm);
if (!_services.Options.NoWarnings && _services.Log.HasWarnings)
Expand Down
34 changes: 19 additions & 15 deletions Core6502DotNet/src/Core/AssemblyServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AssemblyServices(Options options)
OutputFormat = Options.Format ?? string.Empty;
CPU = Options.CPU;
Encoding = new AsmEncoding(Options.CaseSensitive);
Evaluator = new Evaluator(Options.CaseSensitive) { SymbolEvaluator = EvaluateSymbol };
Evaluator = new Evaluator(Options.CaseSensitive) { UnknownValueEvaluator = EvaluateUnknownOperand };
SymbolManager = new SymbolManager(options.CaseSensitive, Evaluator);
Log = new ErrorLog(Options.WarningsAsErrors);
Output = new BinaryOutput(true, Options.CaseSensitive, Options.LongAddressing);
Expand All @@ -43,17 +43,20 @@ public AssemblyServices(Options options)

#region Methods

double EvaluateSymbol(RandomAccessIterator<Token> tokens)
double EvaluateUnknownOperand(RandomAccessIterator<Token> tokens)
{
var token = tokens.Current;
var subscript = -1;
var subscript = -1.0;
var converted = double.NaN;
var isString = token.IsDoubleQuote();
if (char.IsLetter(token.Name[0]) || token.Name[0] == '_')
{
var next = tokens.GetNext();
if (next != null && next.IsOpen() && next.Name.Equals("["))
subscript = (int)Evaluator.Evaluate(tokens, 0, int.MaxValue);
var next = tokens.PeekNext();
if (next?.IsOpen() == true && next.Name.Equals("["))
{
tokens.MoveNext();
subscript = Evaluator.Evaluate(tokens, 0, int.MaxValue);
}
var symbol = SymbolManager.GetSymbol(token, CurrentPass > 0);
if (symbol == null)
{
Expand All @@ -71,15 +74,16 @@ public AssemblyServices(Options options)
}
if (subscript >= 0)
{
if (symbol.StorageType != StorageType.Vector)
throw new SyntaxException(token.Position, "Type mismatch.");
if ((symbol.IsNumeric && subscript >= symbol.NumericVector.Count) ||
(!symbol.IsNumeric && subscript >= symbol.StringVector.Count))
throw new SyntaxException(token.Position, "Index was out of range.");
if (symbol.IsNumeric)
return symbol.NumericVector[subscript];
token = new Token(symbol.StringVector[subscript], TokenType.Operand);
isString = true;
StringView tokenStringValue = "";
double tokenValue = double.NaN;
isString = symbol.DataType == DataType.String && symbol.StorageType == StorageType.Vector;
Symbol.AccessResult result = isString ? symbol.TryGetElementAt(subscript, out tokenStringValue) :
symbol.TryGetElementAt(subscript, out tokenValue);
if (result != Symbol.AccessResult.Success)
throw new ExpressionException(next, SymbolManager.GetErrorMessageFromGetResult(result));
if (!isString)
return tokenValue;
token = new Token(tokenStringValue, TokenType.Operand);
}
else if (symbol.IsNumeric)
{
Expand Down
20 changes: 13 additions & 7 deletions Core6502DotNet/src/Core/BinaryOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static int GetAlignmentSize(int pc, int amount)
/// <returns>The byte string converted.</returns>
public IEnumerable<byte> ConvertToBytes(double value)
{
var bytes = BitConverter.GetBytes(Convert.ToInt64(value)).ToList();
var bytes = BitConverter.GetBytes((long)value).ToList();
int nonZero;
if (value < 0)
nonZero = bytes.FindLastIndex(b => b != 255);
Expand Down Expand Up @@ -420,8 +420,8 @@ public void AddBytes(IEnumerable<byte> bytes, int size, bool ignoreEndian)
}
_logicalPc = (_logicalPc + size) % BufferSize;

if (ProgramEnd < ((_blocks << 16) | ProgramCounter))
ProgramEnd = (_blocks << 16) | ProgramCounter;
if (ProgramEnd < LongProgramCounter)
ProgramEnd = LongProgramCounter;
if (_sectionCollection.SectionSelected)
_sectionCollection.SetOutputCount(_pc - _sectionCollection.SelectedStartAddress);
}
Expand Down Expand Up @@ -502,12 +502,12 @@ public int GetRelativeOffset(int address1, int offsetfromPc)
/// <returns>The set of bytes from the specified start address to Program End.</returns>
public ReadOnlyCollection<byte> GetBytesFrom(int start)
{
if (!_compilingStarted || ((_blocks << 16) | ProgramCounter) < ProgramStart)
if (!_compilingStarted || LongProgramCounter < ProgramStart)
return new List<byte>().AsReadOnly();
if ((ProgramCounter & MaxAddress) != _logicalPc)
if (LongProgramCounter != LongLogicalPC)
{
var diff = _logicalPc - start;
start = ProgramCounter - diff;
var diff = LongLogicalPC - start;
start = LongProgramCounter - diff;
}
if (start < ProgramStart || start >= ProgramEnd)
return new List<byte>().AsReadOnly();
Expand Down Expand Up @@ -755,6 +755,12 @@ private set
/// </summary>
public int LongProgramCounter => ProgramCounter | (_blocks << 16);

/// <summary>
/// Gets the long logical Program Counter.
/// </summary>
public int LongLogicalPC => _logicalPc | (_blocks << 16);


/// <summary>
/// Gets the names of any defined sections not used during
/// assembly.
Expand Down

0 comments on commit 1473abf

Please sign in to comment.