Skip to content

Commit

Permalink
Add non-fatal error for invalid terminal colours
Browse files Browse the repository at this point in the history
  • Loading branch information
TollyH committed May 13, 2024
1 parent 5b29b8e commit c90dd90
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion AssemblerWarnings.Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ public partial class AssemblerWarnings
{ new Opcode(0x05, 0x16), new ulong[] { 1 } }, // HEAP_TRE reg, adr

{ new Opcode(0x06, 0x00), new ulong[] { 0 } }, // FSYS_CWD adr
{ new Opcode(0x06, 0x02), new ulong[] { 0 } }, // FSYS_GWD adr
{ new Opcode(0x06, 0x10), new ulong[] { 0 } }, // FSYS_CDR adr
{ new Opcode(0x06, 0x20), new ulong[] { 0 } }, // FSYS_DDR adr
{ new Opcode(0x06, 0x22), new ulong[] { 0 } }, // FSYS_DDE adr
Expand Down Expand Up @@ -731,5 +730,14 @@ public partial class AssemblerWarnings
new Opcode(0x02, 0x81), // FLPT_WFN reg, lit
new Opcode(0x02, 0xD1), // FLPT_CMP reg, lit
};

/// <summary>
/// All opcodes that require a valid terminal colour literal
/// </summary>
internal static readonly HashSet<Opcode> terminalColorInstructions = new()
{
new Opcode(0x07, 0x51),
new Opcode(0x07, 0x55)
};
}
}
1 change: 1 addition & 0 deletions AssemblerWarnings.Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class AssemblerWarnings
{ 0002, Strings.AssemblerWarnings_NonFatal_0002 },
{ 0003, Strings.AssemblerWarnings_NonFatal_0003 },
{ 0004, Strings.AssemblerWarnings_NonFatal_0004 },
{ 0005, Strings.AssemblerWarnings_NonFatal_0005 },
};

[Localizable(true)]
Expand Down
14 changes: 13 additions & 1 deletion AssemblerWarnings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public AssemblerWarnings(bool usingV1Format)
{ 0002, Analyzer_Rolling_NonFatalError_0002 },
{ 0003, Analyzer_Rolling_NonFatalError_0003 },
{ 0004, Analyzer_Rolling_NonFatalError_0004 },
{ 0005, Analyzer_Rolling_NonFatalError_0005 },
};
warningRollingAnalyzers = new Dictionary<int, RollingWarningAnalyzer>
{
Expand Down Expand Up @@ -485,14 +486,25 @@ private bool Analyzer_Rolling_NonFatalError_0003()
private bool Analyzer_Rolling_NonFatalError_0004()
{
// Non-Fatal Error 0004: Allocating constant 0 bytes.
if (allocationOfLiteral.Contains(instructionOpcode))
if (newBytes.Length > 0 && !instructionIsData && allocationOfLiteral.Contains(instructionOpcode))
{
_ = Assembler.ParseLiteral(operands[1], false, out ulong number);
return number == 0;
}
return false;
}

private bool Analyzer_Rolling_NonFatalError_0005()
{
// Non-Fatal Error 0005: The given literal value does not correspond to a valid terminal colour.
if (newBytes.Length > 0 && !instructionIsData && terminalColorInstructions.Contains(instructionOpcode))
{
_ = Assembler.ParseLiteral(operands[0], false, out ulong number);
return !Enum.IsDefined((ConsoleColor)number);
}
return false;
}

private bool Analyzer_Rolling_Warning_0001()
{
// Warning 0001: Data insertion is not directly preceded by unconditional jump, return, or halt instruction.
Expand Down
9 changes: 9 additions & 0 deletions Resources/Localization/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Resources/Localization/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1730,4 +1730,7 @@ Current while stack (deepest while first):</value>
<data name="AssemblerWarnings_Suggestion_0020" xml:space="preserve">
<value>Use the `HLT` instruction instead of `EXTD_HLT` when the exit code is always 0.</value>
</data>
<data name="AssemblerWarnings_NonFatal_0005" xml:space="preserve">
<value>The given literal value does not correspond to a valid terminal colour.</value>
</data>
</root>

0 comments on commit c90dd90

Please sign in to comment.