Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Version 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
informedcitizenry committed Dec 17, 2017
1 parent b852120 commit d2f58e1
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 38 deletions.
94 changes: 78 additions & 16 deletions DotNetAsm/AssemblyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ namespace DotNetAsm

public delegate byte[] WriteBytesEventHandler(object sender);

public class SymbolNotDefinedException : Exception
{
public SymbolNotDefinedException(string symbol)
{
Symbol = symbol;
}

public string Symbol { get; private set; }
}

/// <summary>
/// Implements an assembly controller to process source input and convert
/// to assembled output.
Expand Down Expand Up @@ -350,6 +360,10 @@ void FirstPass(IEnumerable<SourceLine> source)
else
Log.LogEntry(_currentLine, ErrorStrings.LabelNotValid, _currentLine.Label);
}
catch (SymbolNotDefinedException symNotFound)
{
Log.LogEntry(_currentLine, ErrorStrings.LabelNotDefined, symNotFound.Symbol);
}
catch (ExpressionException exprEx)
{
Log.LogEntry(_currentLine, ErrorStrings.BadExpression, exprEx.Message);
Expand Down Expand Up @@ -382,7 +396,16 @@ void FirstPassLine()
}
else if (_currentLine.Instruction.Equals(ConstStrings.VAR_DIRECTIVE, Options.StringComparison))
{
_currentLine.PC = Variables.SetVariable(_currentLine.Operand, _currentLine.Scope).Value;
var varname = Variables.GetVariableFromExpression(_currentLine.Operand, _currentLine.Scope);
try
{
_currentLine.PC = Variables.SetVariable(_currentLine.Operand, _currentLine.Scope).Value;
}
catch (SymbolNotDefinedException)
{
Variables.SetSymbol(varname, 0, false);
_currentLine.PC = 0;
}
}

UpdatePC();
Expand Down Expand Up @@ -505,6 +528,10 @@ void SecondPass()
if (!passNeeded)
passNeeded = needpass;
}
catch (SymbolNotDefinedException symEx)
{
Log.LogEntry(line, ErrorStrings.LabelNotDefined, symEx.Symbol);
}
catch (ExpressionException exprEx)
{
Log.LogEntry(line, ErrorStrings.BadExpression, exprEx.Message);
Expand Down Expand Up @@ -565,9 +592,16 @@ public void AssembleLine()
/// <returns>The size in bytes of the instruction, including opcode and operand</returns>
int GetInstructionSize()
{
var asm = _assemblers.FirstOrDefault(a => a.AssemblesInstruction(_currentLine.Instruction));
var size = (asm != null) ? asm.GetInstructionSize(_currentLine) : 0;
return size;
try
{
var asm = _assemblers.FirstOrDefault(a => a.AssemblesInstruction(_currentLine.Instruction));
var size = (asm != null) ? asm.GetInstructionSize(_currentLine) : 0;
return size;
}
catch (SymbolNotDefinedException)
{
return 0;
}
}

/// <summary>
Expand All @@ -583,9 +617,20 @@ void DefineLabel()
if (_specialLabels.IsMatch(_currentLine.Label))
{
if (IsAssignmentDirective())
_currentLine.PC = Convert.ToInt32(Evaluator.Eval(_currentLine.Operand));
{
try
{
_currentLine.PC = Convert.ToInt32(Evaluator.Eval(_currentLine.Operand));
}
catch (SymbolNotDefinedException)
{
_currentLine.PC = 0;
}
}
else
{
_currentLine.PC = Output.LogicalPC;
}

if (_currentLine.Label.Equals("+") || _currentLine.Label.Equals("-"))
{
Expand All @@ -611,11 +656,18 @@ void DefineLabel()

scopedLabel = _currentLine.Scope + _currentLine.Label;

long val;
long val = _currentLine.PC;
if (IsAssignmentDirective())
val = Evaluator.Eval(_currentLine.Operand, int.MinValue, uint.MaxValue);
else
val = _currentLine.PC;
{
try
{
val = Evaluator.Eval(_currentLine.Operand, int.MinValue, uint.MaxValue);
}
catch (SymbolNotDefinedException)
{
val = 0;
}
}
_labelCollection.SetLabel(scopedLabel, val, false, true);

}
Expand All @@ -632,7 +684,14 @@ void UpdatePC()
{
if (IsAssignmentDirective())
{
val = Evaluator.Eval(_currentLine.Operand, UInt16.MinValue, UInt16.MaxValue);
try
{
val = Evaluator.Eval(_currentLine.Operand, UInt16.MinValue, UInt16.MaxValue);
}
catch (SymbolNotDefinedException)
{

}
Output.SetPC(Convert.ToUInt16(val));
}
else
Expand All @@ -654,7 +713,14 @@ void UpdatePC()
Log.LogEntry(_currentLine, ErrorStrings.TooFewArguments, _currentLine.Instruction);
return;
}
val = Evaluator.Eval(_currentLine.Operand, uint.MinValue, uint.MaxValue);
try
{
val = Evaluator.Eval(_currentLine.Operand, uint.MinValue, uint.MaxValue);
}
catch (SymbolNotDefinedException)
{

}
Output.SetLogicalPC(Convert.ToUInt16(val));
}
break;
Expand Down Expand Up @@ -892,11 +958,7 @@ string GetNamedSymbolValue(string symbol)

long value = _labelCollection.GetScopedSymbolValue(symbol, _currentLine.Scope);
if (value.Equals(long.MinValue))
{
if (_passes > 0)
Log.LogEntry(_currentLine, ErrorStrings.LabelNotDefined, symbol);
return "0";
}
throw new SymbolNotDefinedException(symbol);
return value.ToString();

}
Expand Down
2 changes: 1 addition & 1 deletion DotNetAsm/DotNetAsm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>DotNetAsm</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ReleaseVersion>1.7.2.0</ReleaseVersion>
<ReleaseVersion>1.8</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
17 changes: 5 additions & 12 deletions DotNetAsm/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -266,16 +267,8 @@ string EvalUnaries(string expression)
/// </summary>
/// <param name="expression">The expression string to evaluate</param>
/// <returns>True, if the expression contains user-defined symbols, otherwise false</returns>
bool ContainsSymbols(string expression)
{
foreach (var lookup in _symbolLookups)
{
Regex r = lookup.Value.Item1;
if (r.IsMatch(expression))
return true;
}
return false;
}
bool ContainsSymbols(string expression) =>
_symbolLookups.Values.Any(l => l.Item1.IsMatch(expression));

/// <summary>
/// Evaluate the expression strings for user-defined symbols, then do a callback
Expand All @@ -284,7 +277,7 @@ bool ContainsSymbols(string expression)
/// <param name="expression">The expression to evaluate</param>
/// <returns>The modified expression string with user-defined symbols replaced
/// with real values</returns>
string EvalSymbols(string expression)
string EvalDefinedSymbols(string expression)
{
// convert client-defined symbols into values
foreach (var lookup in _symbolLookups)
Expand Down Expand Up @@ -490,7 +483,7 @@ string PreEvaluate(string expression)
if (!ContainsSymbols(expression))
_cache.Add(unevaluated, Double.NaN);

expression = EvalUnaries(EvalFunctions(EvalSymbols(expression)));
expression = EvalUnaries(EvalFunctions(EvalDefinedSymbols(expression)));

foreach (var replacement in _replacements)
expression = replacement.Item1.Replace(expression, replacement.Item2);
Expand Down
4 changes: 2 additions & 2 deletions DotNetAsm/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.2.0")]
[assembly: AssemblyFileVersion("1.7.2.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
2 changes: 1 addition & 1 deletion NUnit.z80Tests/NUnit.z80Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<ReleaseVersion>1.7.2.0</ReleaseVersion>
<ReleaseVersion>1.8</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# z80DotNet, A Simple .Net-Based Z80 Cross-Assembler
### Version 1.7.2.0
### Version 1.8
## Introduction

The z80DotNet Macro Assembler is a simple cross-assembler targeting the Zilog Z80 and compatible CPU. It is written for .Net (Version 4.5.1) and supports all of the published (legal) instructions of the Z80 processor, as well as most of the unpublished (illegal) operations. Like the MOS 6502, the Z80 was a popular choice for video game system and microcomputer manufacturers in the 1970s and mid-1980s. For more information, see [wiki entry](https://en.wikipedia.org/wiki/Zilog_Z80) or [Z80 resource page](http://www.z80.info/) to learn more about this microprocessor.
Expand Down Expand Up @@ -201,7 +201,7 @@ start = $c000
startstr .string str(start) ; assembles as $34,$39,$31,$35,$32
; literally the digits "4","9","1","5","2"
```
The `format()` function allows you to output non-string data using a .Net format string:
The `format()` function allows you to convert non-string data to string data using a .Net format string:
```
stdout = $15ef
stdstring .string format("The stdout routine is at ${0:X4}", stdout)
Expand Down
2 changes: 1 addition & 1 deletion z80DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 1.7.2.0
version = 1.8
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions z80DotNet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.2.0")]
[assembly: AssemblyFileVersion("1.7.2.0")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
2 changes: 1 addition & 1 deletion z80DotNet/z80DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<ReleaseVersion>1.7.2.0</ReleaseVersion>
<ReleaseVersion>1.8</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down

0 comments on commit d2f58e1

Please sign in to comment.