Skip to content

Commit

Permalink
Removing Console.WriteLine and using Debug.Print
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Rocha Lima e Marcondes committed Feb 20, 2019
1 parent 9a77a94 commit e424f16
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 187 deletions.
23 changes: 12 additions & 11 deletions Chip8.Sharp/Chip8.Core/CPU.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -138,7 +139,7 @@ public void LoadGame(string fileName)
{
var buffer = new byte[MAX_BUFFER_SIZE];
var bufferSize = stream.Read(this.Memory, 0x200, MAX_BUFFER_SIZE);
Console.WriteLine($"Loaded {bufferSize.ToString(NumberFormatInfo.CurrentInfo)} bytes");
Debug.Print($"Loaded {bufferSize.ToString(NumberFormatInfo.CurrentInfo)} bytes");
}
}

Expand Down Expand Up @@ -188,7 +189,7 @@ public void EmulateCycle()
if (this.SP == 0)
{
var message = "Illegal return operation, stack is empty.";
Console.WriteLine(message);
Debug.Print(message);
throw new StackOverflowException(message);
}

Expand All @@ -206,7 +207,7 @@ public void EmulateCycle()
default:
{
var message = $"Illegal call to RCA 1802 program: 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}";
Console.WriteLine(message);
Debug.Print(message);
throw new InvalidOperationException(message);
}
}
Expand All @@ -221,7 +222,7 @@ public void EmulateCycle()
if (op.NNN < 0x200)
{
var message = $"Illegal jump target: 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}";
Console.WriteLine(message);
Debug.Print(message);
throw new InvalidOperationException(message);
}

Expand All @@ -233,7 +234,7 @@ public void EmulateCycle()
if (this.SP > 0xF)
{
var message = "Illegal call operation, stack is full.";
Console.WriteLine(message);
Debug.Print(message);
throw new StackOverflowException(message);
}

Expand Down Expand Up @@ -608,7 +609,7 @@ public void EmulateCycle()
break;

default:
Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
break;
}
break;
Expand Down Expand Up @@ -666,14 +667,14 @@ public void EmulateCycle()
if (dest < 0x200)
{
var message = $"Illegal jump target: 0x{dest.ToString("X4", NumberFormatInfo.CurrentInfo)} => 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)} + this.V[0] (0x{this.V[0].ToString("X2", NumberFormatInfo.CurrentInfo)})";
Console.WriteLine(message);
Debug.Print(message);
throw new InvalidOperationException(message);
}

if (dest > 0xFFF)
{
var message = $"Illegal jump target: 0x{dest.ToString("X4", NumberFormatInfo.CurrentInfo)} => 0x{this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)} + this.V[0] (0x{this.V[0].ToString("X2", NumberFormatInfo.CurrentInfo)})";
Console.WriteLine(message);
Debug.Print(message);
throw new InvalidOperationException(message);
}

Expand Down Expand Up @@ -803,7 +804,7 @@ public void EmulateCycle()
break;

default:
Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
break;
}
break;
Expand Down Expand Up @@ -1023,13 +1024,13 @@ public void EmulateCycle()
break;

default:
Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
break;
}
break;

default:
Console.WriteLine($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
Debug.Print($"Unknown opcode: {this.Opcode.ToString("X4", NumberFormatInfo.CurrentInfo)}");
break;
}

Expand Down
Loading

0 comments on commit e424f16

Please sign in to comment.