Skip to content

Commit 08d09ea

Browse files
author
informedcitizenry
committed
version 2.5.2
1 parent f6c32e5 commit 08d09ea

File tree

9 files changed

+186
-61
lines changed

9 files changed

+186
-61
lines changed

Core6502DotNet.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Global
3333
SolutionGuid = {9BE7575F-6E99-4243-AEAA-4D1E1064DA97}
3434
EndGlobalSection
3535
GlobalSection(MonoDevelopProperties) = preSolution
36-
version = 2.5.1
36+
version = 2.5.2
3737
Policies = $0
3838
$0.VersionControlPolicy = $1
3939
$1.CommitMessageStyle = $2

Core6502DotNet/Core6502DotNet.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<PackageId>6502.Net</PackageId>
7-
<Version>2.5.1</Version>
7+
<Version>2.5.2</Version>
88
<Authors>informedcitizenry</Authors>
99
<Company>informedcitizenry</Company>
1010
<Product>6502.Net</Product>
@@ -13,8 +13,8 @@
1313
<ReleaseVersion>2.4.1</ReleaseVersion>
1414
<StartupObject>Core6502DotNet.Program</StartupObject>
1515
<AssemblyName>6502.Net</AssemblyName>
16-
<AssemblyVersion>2.5.1.1</AssemblyVersion>
17-
<FileVersion>2.5.1.1</FileVersion>
16+
<AssemblyVersion>2.5.2.1</AssemblyVersion>
17+
<FileVersion>2.5.2.1</FileVersion>
1818
<SignAssembly>false</SignAssembly>
1919
</PropertyGroup>
2020

Core6502DotNet/src/Core/Evaluator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ void DoOperation(Token op, ref StringView nonBase10, Stack<double> output)
413413
parms.Add(output.Pop());
414414
}
415415
if ((op.Name.Equals("||") || op.Name.Equals("&&") || op.Name.Equals("!")) && parms.Any(p => p != 1 && p != 0))
416-
throw new ExpressionException(op, "Type mismatch.");
416+
throw new ExpressionException(op, "Invalid conditional expression.");
417417
output.Push(operation.Item1(parms));
418418
}
419419
}

Core6502DotNet/src/Core/Function.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public double Invoke(List<object> parameterList)
104104
{
105105
var parm = parameterList[i];
106106
if (parm is string)
107-
_services.SymbolManager.DefineSymbol(Params[i].Name, parm.ToString().TrimOnce('"'));
107+
_services.SymbolManager.DefineSymbol(Params[i].Name, parm.ToString().TrimOnce('"'), true);
108108
else
109-
_services.SymbolManager.DefineSymbol(Params[i].Name, (double)parm);
109+
_services.SymbolManager.DefineSymbol(Params[i].Name, (double)parm, true);
110110
}
111111
}
112112
var iterator = _definedLines.GetIterator();
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
//-----------------------------------------------------------------------------
2+
// Copyright (c) 2017-2021 informedcitizenry <[email protected]>
3+
//
4+
// Licensed under the MIT license. See LICENSE for full license information.
5+
//
6+
//-----------------------------------------------------------------------------
7+
using System;
8+
9+
namespace Core6502DotNet
10+
{
11+
12+
/// <summary>
13+
/// Represents an invalid CPU error.
14+
/// </summary>
15+
public class InvalidCpuException : Exception
16+
{
17+
/// <summary>
18+
/// Construct a new invalid CPU exception.
19+
/// </summary>
20+
/// <param name="cpu">The CPU specified that caused the exception.</param>
21+
public InvalidCpuException(string cpu)
22+
: base($"Invalid CPU \"{cpu}\" specified.")
23+
{
24+
25+
}
26+
}
27+
28+
/// <summary>
29+
/// Represents an assembler for CPU-specified. instructions and operations. This class
30+
/// must be inherited.
31+
/// </summary>
32+
public abstract class CpuAssembler : AssemblerBase
33+
{
34+
#region Members
35+
36+
readonly string _initCpu;
37+
string _cpu;
38+
39+
#endregion
40+
41+
#region Constructors
42+
43+
/// <summary>
44+
/// Constructs a new instance of a CPU assembler.
45+
/// </summary>
46+
/// <param name="services">The shared <see cref="AssemblyServices"/> object.</param>
47+
protected CpuAssembler(AssemblyServices services)
48+
: base(services)
49+
{
50+
51+
Reserved.DefineType("CPU", ".cpu");
52+
if (!string.IsNullOrEmpty(Services.CPU))
53+
CPU = Services.CPU;
54+
else
55+
_cpu = string.Empty;
56+
_initCpu = _cpu;
57+
OnSetCpu();
58+
59+
Evaluations = new double[]
60+
{
61+
double.NaN, double.NaN, double.NaN
62+
};
63+
}
64+
65+
#endregion
66+
67+
#region Methods
68+
69+
/// <summary>
70+
/// Resets the state of the <see cref="CpuAssembler"/>.
71+
/// </summary>
72+
protected virtual void OnReset() => _cpu = _initCpu;
73+
74+
/// <summary>
75+
/// Actions to perform when the CPU is set. This method must be inherited.
76+
/// </summary>
77+
protected abstract void OnSetCpu();
78+
79+
/// <summary>
80+
/// Assembles the instruction/mnemonic specific to the CPU.
81+
/// </summary>
82+
/// <param name="line">The <see cref="SourceLine"/> of the instruction.</param>
83+
/// <returns>The listing representation of the instruction.</returns>
84+
protected abstract string AssembleCpuInstruction(SourceLine line);
85+
86+
/// <summary>
87+
/// Determines whether the CPU selected is valid. This method must be inherited.
88+
/// </summary>
89+
/// <param name="cpu">The CPU name.</param>
90+
/// <returns><c>true</c> if the CPU is valid, <c>false</c> otherwise.</returns>
91+
public abstract bool IsCpuValid(string cpu);
92+
93+
void OnPassChanged(object sender, EventArgs args)
94+
=> OnReset();
95+
96+
97+
protected override string OnAssemble(RandomAccessIterator<SourceLine> lines)
98+
{
99+
var line = lines.Current;
100+
if (Reserved.IsOneOf("CPU", line.Instruction.Name))
101+
{
102+
var iterator = line.Operands.GetIterator();
103+
if (!iterator.MoveNext() || !StringHelper.IsStringLiteral(iterator) || iterator.PeekNext() != null)
104+
Services.Log.LogEntry(line.Instruction,
105+
"String expression expected.");
106+
else
107+
{
108+
CPU = iterator.Current.Name.ToString().TrimOnce('"');
109+
OnSetCpu();
110+
}
111+
return string.Empty;
112+
}
113+
Evaluations[0] = Evaluations[1] = Evaluations[2] = double.NaN;
114+
return AssembleCpuInstruction(line);
115+
}
116+
#endregion
117+
118+
#region Properties
119+
120+
/// <summary>
121+
/// Gets the CPU.
122+
/// </summary>
123+
/// <exception cref="InvalidCpuException"></exception>
124+
protected string CPU
125+
{
126+
get => _cpu;
127+
private set
128+
{
129+
if (!IsCpuValid(value))
130+
throw new InvalidCpuException(value);
131+
_cpu = value;
132+
}
133+
}
134+
135+
/// <summary>
136+
/// Gets the individual evaluations in the expression.
137+
/// </summary>
138+
protected double[] Evaluations { get; }
139+
140+
#endregion
141+
}
142+
}

Core6502DotNet/src/Preprocessing/Preprocessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ List<SourceLine> ProcessFromStream(string fileName, int lineNumber, StreamReader
317317
}
318318
if (c == ':')
319319
{
320-
if ((expected != TokenType.Instruction && expected != TokenType.EndOrBinary) || !LineTerminates())
320+
if ((expected != TokenType.Instruction && expected != TokenType.EndOrBinary &&
321+
(tokens.Count == 0 || tokens[^1].Type != TokenType.Instruction)) || !LineTerminates())
321322
{
322323
LogError(fileName, lineNumber, it.Index + 1, "Unexpected expression.");
323324
break;

Core6502DotNet/src/m65xx/Asm6502Members.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public sealed partial class Asm6502 : MotorolaBase
3737
{ ("asl", Modes.ZeroPageX ), new CpuInstruction( "6502", 0x16, 2) },
3838
{ ("clc", Modes.Implied ), new CpuInstruction( "6502", 0x18) },
3939
{ ("ora", Modes.AbsoluteY ), new CpuInstruction( "6502", 0x19, 3) },
40-
{ ("top", Modes.AbsoluteX ), new CpuInstruction( "6502", 0x1c, 3) },
4140
{ ("ora", Modes.AbsoluteX ), new CpuInstruction( "6502", 0x1d, 3) },
4241
{ ("asl", Modes.AbsoluteX ), new CpuInstruction( "6502", 0x1e, 3) },
4342
{ ("jsr", Modes.Absolute ), new CpuInstruction( "6502", 0x20, 3) },
@@ -232,7 +231,7 @@ public sealed partial class Asm6502 : MotorolaBase
232231
{ ("rmb", Modes.Zp7 ), new CpuInstruction( "R65C02", 0x77, 2) },
233232
{ ("bbr", Modes.ThreeOpRel7 ), new CpuInstruction( "R65C02", 0x7f, 3) },
234233
{ ("smb", Modes.Zp0 ), new CpuInstruction( "R65C02", 0x87, 2) },
235-
{ ("bbs", Modes.ThreeOpRel ), new CpuInstruction( "R65C02", 0x8f, 3) },
234+
{ ("bbs", Modes.ThreeOpRel0 ), new CpuInstruction( "R65C02", 0x8f, 3) },
236235
{ ("smb", Modes.Zp1 ), new CpuInstruction( "R65C02", 0x97, 2) },
237236
{ ("bbs", Modes.ThreeOpRel1 ), new CpuInstruction( "R65C02", 0x9f, 3) },
238237
{ ("smb", Modes.Zp2 ), new CpuInstruction( "R65C02", 0xa7, 2) },
@@ -434,7 +433,6 @@ public sealed partial class Asm6502 : MotorolaBase
434433
static readonly Dictionary<(string Mnem, Modes Mode), CpuInstruction> s_opcodes65816 =
435434
new Dictionary<(string Mnem, Modes Mode), CpuInstruction>()
436435
{
437-
{ ("cop", Modes.Implied ), new CpuInstruction( "65816", 0x03) },
438436
{ ("cop", Modes.Immediate ), new CpuInstruction( "65816", 0x02, 2) },
439437
{ ("ora", Modes.ZeroPageS ), new CpuInstruction( "65816", 0x03, 2) },
440438
{ ("ora", Modes.Dir ), new CpuInstruction( "65816", 0x07, 2) },
@@ -454,7 +452,7 @@ public sealed partial class Asm6502 : MotorolaBase
454452
{ ("and", Modes.DirY ), new CpuInstruction( "65816", 0x37, 2) },
455453
{ ("tsc", Modes.Implied ), new CpuInstruction( "65816", 0x3b) },
456454
{ ("and", Modes.LongX ), new CpuInstruction( "65816", 0x3f, 4) },
457-
{ ("wdm", Modes.Implied ), new CpuInstruction( "65816", 0x43) },
455+
{ ("wdm", Modes.Implied ), new CpuInstruction( "65816", 0x42) },
458456
{ ("eor", Modes.ZeroPageS ), new CpuInstruction( "65816", 0x43, 2) },
459457
{ ("mvp", Modes.TwoOperand ), new CpuInstruction( "65816", 0x44, 3) },
460458
{ ("eor", Modes.Dir ), new CpuInstruction( "65816", 0x47, 2) },
@@ -512,6 +510,7 @@ public sealed partial class Asm6502 : MotorolaBase
512510
{ ("pea", Modes.Absolute ), new CpuInstruction( "65816", 0xf4, 3) }, // both are acceptable
513511
{ ("sbc", Modes.DirY ), new CpuInstruction( "65816", 0xf7, 2) },
514512
{ ("xce", Modes.Implied ), new CpuInstruction( "65816", 0xfb) },
513+
{ ("jsr", Modes.IndAbsX ), new CpuInstruction( "65816", 0xfc, 3) },
515514
{ ("sbc", Modes.LongX ), new CpuInstruction( "65816", 0xff, 4) },
516515
};
517516
static readonly Dictionary<(string Mnem, Modes Mode), CpuInstruction> s_opcodes6502i =

Core6502DotNet/src/z80/Z80Asm.cs

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,55 +65,38 @@ public Z80Asm(AssemblyServices services)
6565
"djnz", "jr"
6666
);
6767

68-
if (CPU.Equals("z80"))
68+
_namedModes = new Dictionary<StringView, Z80Mode>(Services.StringViewComparer)
6969
{
70-
_namedModes = new Dictionary<StringView, Z80Mode>(Services.StringViewComparer)
71-
{
72-
{ "a", Z80Mode.A },
73-
{ "af", Z80Mode.AF },
74-
{ "af'", Z80Mode.ShadowAF },
75-
{ "b", Z80Mode.B },
76-
{ "bc", Z80Mode.BC },
77-
{ "c", Z80Mode.C },
78-
{ "d", Z80Mode.D },
79-
{ "de", Z80Mode.DE },
80-
{ "e", Z80Mode.E },
81-
{ "h", Z80Mode.H },
82-
{ "hl", Z80Mode.HL },
83-
{ "i", Z80Mode.I },
84-
{ "ix", Z80Mode.IX },
85-
{ "ixh", Z80Mode.XH },
86-
{ "ixl", Z80Mode.XL },
87-
{ "iy", Z80Mode.IY },
88-
{ "iyh", Z80Mode.YH },
89-
{ "iyl", Z80Mode.YL },
90-
{ "l", Z80Mode.L },
91-
{ "m", Z80Mode.M },
92-
{ "nc", Z80Mode.NC },
93-
{ "nz", Z80Mode.NZ },
94-
{ "p", Z80Mode.P },
95-
{ "pe", Z80Mode.PE },
96-
{ "po", Z80Mode.PO },
97-
{ "r", Z80Mode.R },
98-
{ "sp", Z80Mode.SP },
99-
{ "z", Z80Mode.Z }
100-
};
101-
}
102-
else
103-
{
104-
_namedModes = new Dictionary<StringView, Z80Mode>(Services.StringViewComparer)
105-
{
106-
{ "a", Z80Mode.A },
107-
{ "b", Z80Mode.B },
108-
{ "c", Z80Mode.C },
109-
{ "d", Z80Mode.D },
110-
{ "e", Z80Mode.E },
111-
{ "h", Z80Mode.H },
112-
{ "l", Z80Mode.L },
113-
{ "m", Z80Mode.M },
114-
{ "psw", Z80Mode.PSW }
115-
};
116-
}
70+
{ "a", Z80Mode.A },
71+
{ "af", Z80Mode.AF },
72+
{ "af'", Z80Mode.ShadowAF },
73+
{ "b", Z80Mode.B },
74+
{ "bc", Z80Mode.BC },
75+
{ "c", Z80Mode.C },
76+
{ "d", Z80Mode.D },
77+
{ "de", Z80Mode.DE },
78+
{ "e", Z80Mode.E },
79+
{ "h", Z80Mode.H },
80+
{ "hl", Z80Mode.HL },
81+
{ "i", Z80Mode.I },
82+
{ "ix", Z80Mode.IX },
83+
{ "ixh", Z80Mode.XH },
84+
{ "ixl", Z80Mode.XL },
85+
{ "iy", Z80Mode.IY },
86+
{ "iyh", Z80Mode.YH },
87+
{ "iyl", Z80Mode.YL },
88+
{ "l", Z80Mode.L },
89+
{ "m", Z80Mode.M },
90+
{ "nc", Z80Mode.NC },
91+
{ "nz", Z80Mode.NZ },
92+
{ "p", Z80Mode.P },
93+
{ "pe", Z80Mode.PE },
94+
{ "po", Z80Mode.PO },
95+
{ "psw", Z80Mode.PSW },
96+
{ "r", Z80Mode.R },
97+
{ "sp", Z80Mode.SP },
98+
{ "z", Z80Mode.Z }
99+
};
117100
Services.SymbolManager.AddValidSymbolNameCriterion(s => !_namedModes.ContainsKey(s));
118101
}
119102

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
6502.Net, A .Net-Based Cross-Assembler for Several 8-Bit Microprocessors.
22

3-
Version 2.5.1
3+
Version 2.5.2
44

55
## Overview
66

0 commit comments

Comments
 (0)