diff --git a/Processor.cs b/Processor.cs index 49b8e0f..efa9e1a 100644 --- a/Processor.cs +++ b/Processor.cs @@ -1343,54 +1343,53 @@ public bool Execute(bool runUntilHalt, Stream? stdoutOverride = null, Stream? st switch (opcodeLow) { case 0x0: // WCN reg - Console.Write(ReadMemoryRegister(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(ReadMemoryRegister(operandStart).ToString())); Registers[(int)Register.rpo]++; break; case 0x1: // WCN lit - Console.Write(ReadMemoryQWord(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(ReadMemoryQWord(operandStart).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x2: // WCN adr - Console.Write(ReadMemoryPointedQWord(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(ReadMemoryPointedQWord(operandStart).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x3: // WCN ptr - Console.Write(ReadMemoryRegisterPointedNumber(operandStart, out byteCount)); + stdout.Write(Encoding.UTF8.GetBytes(ReadMemoryRegisterPointedNumber(operandStart, out byteCount).ToString())); Registers[(int)Register.rpo] += byteCount; break; case 0x4: // WCB reg - Console.Write(0xFF & ReadMemoryRegister(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes((0xFF & ReadMemoryRegister(operandStart)).ToString())); Registers[(int)Register.rpo]++; break; case 0x5: // WCB lit - Console.Write(Memory[operandStart]); + stdout.Write(Encoding.UTF8.GetBytes(Memory[operandStart].ToString())); Registers[(int)Register.rpo] += 8; break; case 0x6: // WCB adr - Console.Write(ReadMemoryPointedByte(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(ReadMemoryPointedByte(operandStart).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x7: // WCB ptr - Console.Write(ReadMemoryRegisterPointedByte(operandStart, out byteCount)); + stdout.Write(Encoding.UTF8.GetBytes(ReadMemoryRegisterPointedByte(operandStart, out byteCount).ToString())); Registers[(int)Register.rpo] += byteCount; break; case 0x8: // WCX reg - Console.Write(Strings.Generic_Hex_Value, 0xFF & ReadMemoryRegister(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(string.Format(Strings.Generic_Hex_Value, 0xFF & ReadMemoryRegister(operandStart)))); Registers[(int)Register.rpo]++; break; case 0x9: // WCX lit - Console.Write(Strings.Generic_Hex_Value, Memory[operandStart]); + stdout.Write(Encoding.UTF8.GetBytes(string.Format(Strings.Generic_Hex_Value, Memory[operandStart]))); Registers[(int)Register.rpo] += 8; break; case 0xA: // WCX adr - Console.Write(Strings.Generic_Hex_Value, ReadMemoryPointedByte(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(string.Format(Strings.Generic_Hex_Value, ReadMemoryPointedByte(operandStart)))); Registers[(int)Register.rpo] += 8; break; case 0xB: // WCX ptr - Console.Write(Strings.Generic_Hex_Value, ReadMemoryRegisterPointedByte(operandStart, out byteCount)); + stdout.Write(Encoding.UTF8.GetBytes(string.Format(Strings.Generic_Hex_Value, ReadMemoryRegisterPointedByte(operandStart, out byteCount)))); Registers[(int)Register.rpo] += byteCount; break; - // Following instructions write raw bytes to stdout to prevent C# converting our UTF-8 bytes to UTF-16. case 0xC: // WCC reg { stdout.WriteByte((byte)(0xFF & ReadMemoryRegister(operandStart))); @@ -2099,35 +2098,35 @@ is not (ulong)StatusFlags.Sign and not (ulong)StatusFlags.Overflow) switch (opcodeLow) { case 0x0: // SIGN_WCN reg - Console.Write((long)ReadMemoryRegister(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(((long)ReadMemoryRegister(operandStart)).ToString())); Registers[(int)Register.rpo]++; break; case 0x1: // SIGN_WCN lit - Console.Write((long)ReadMemoryQWord(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(((long)ReadMemoryQWord(operandStart)).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x2: // SIGN_WCN adr - Console.Write((long)ReadMemoryPointedQWord(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(((long)ReadMemoryPointedQWord(operandStart)).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x3: // SIGN_WCN ptr - Console.Write((long)ReadMemoryRegisterPointedNumber(operandStart, out byteCount)); + stdout.Write(Encoding.UTF8.GetBytes(((long)ReadMemoryRegisterPointedNumber(operandStart, out byteCount)).ToString())); Registers[(int)Register.rpo] += byteCount; break; case 0x4: // SIGN_WCB reg - Console.Write((sbyte)ReadMemoryRegister(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(((sbyte)ReadMemoryRegister(operandStart)).ToString())); Registers[(int)Register.rpo]++; break; case 0x5: // SIGN_WCB lit - Console.Write((sbyte)Memory[operandStart]); + stdout.Write(Encoding.UTF8.GetBytes(((sbyte)Memory[operandStart]).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x6: // SIGN_WCB adr - Console.Write((sbyte)ReadMemoryPointedByte(operandStart)); + stdout.Write(Encoding.UTF8.GetBytes(((sbyte)ReadMemoryPointedByte(operandStart)).ToString())); Registers[(int)Register.rpo] += 8; break; case 0x7: // SIGN_WCB ptr - Console.Write((sbyte)ReadMemoryRegisterPointedByte(operandStart, out byteCount)); + stdout.Write(Encoding.UTF8.GetBytes(((sbyte)ReadMemoryRegisterPointedByte(operandStart, out byteCount)).ToString())); Registers[(int)Register.rpo] += byteCount; break; default: @@ -2724,19 +2723,19 @@ is not (ulong)StatusFlags.Sign and not (ulong)StatusFlags.Overflow) switch (opcodeLow) { case 0x0: // FLPT_WCN reg - Console.Write(BitConverter.UInt64BitsToDouble(ReadMemoryRegister(operandStart))); + stdout.Write(Encoding.UTF8.GetBytes(BitConverter.UInt64BitsToDouble(ReadMemoryRegister(operandStart)).ToString(CultureInfo.InvariantCulture))); Registers[(int)Register.rpo]++; break; case 0x1: // FLPT_WCN lit - Console.Write(BitConverter.UInt64BitsToDouble(ReadMemoryQWord(operandStart))); + stdout.Write(Encoding.UTF8.GetBytes(BitConverter.UInt64BitsToDouble(ReadMemoryQWord(operandStart)).ToString(CultureInfo.InvariantCulture))); Registers[(int)Register.rpo] += 8; break; case 0x2: // FLPT_WCN adr - Console.Write(BitConverter.UInt64BitsToDouble(ReadMemoryPointedQWord(operandStart))); + stdout.Write(Encoding.UTF8.GetBytes(BitConverter.UInt64BitsToDouble(ReadMemoryPointedQWord(operandStart)).ToString(CultureInfo.InvariantCulture))); Registers[(int)Register.rpo] += 8; break; case 0x3: // FLPT_WCN ptr - Console.Write(BitConverter.UInt64BitsToDouble(ReadMemoryRegisterPointedNumber(operandStart, out byteCount))); + stdout.Write(Encoding.UTF8.GetBytes(BitConverter.UInt64BitsToDouble(ReadMemoryRegisterPointedNumber(operandStart, out byteCount)).ToString(CultureInfo.InvariantCulture))); Registers[(int)Register.rpo] += byteCount; break; default: diff --git a/Test/ProcessorTests/FullOpcodeTest.Base.cs b/Test/ProcessorTests/FullOpcodeTest.Base.cs index 99399fc..ed37e61 100644 --- a/Test/ProcessorTests/FullOpcodeTest.Base.cs +++ b/Test/ProcessorTests/FullOpcodeTest.Base.cs @@ -5831,12 +5831,11 @@ public void WCN_Register() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC0, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(1234567890UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -5844,12 +5843,11 @@ public void WCN_Register() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = unchecked((ulong)-1); testProcessor.LoadProgram(new byte[] { 0xC0, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("18446744073709551615", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("18446744073709551615", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(unchecked((ulong)-1), testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -5862,23 +5860,21 @@ public void WCN_Literal() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC1, 0xD2, 0x02, 0x96, 0x49, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xC1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("18446744073709551615", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("18446744073709551615", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -5890,25 +5886,23 @@ public void WCN_Address() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC2, 225, 0, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, 1234567890); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xC2, 225, 0, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, unchecked((ulong)-1)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("18446744073709551615", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("18446744073709551615", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -5921,13 +5915,12 @@ public void WCN_Pointer() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC3, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, 1234567890); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(225UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -5935,13 +5928,12 @@ public void WCN_Pointer() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = 225; testProcessor.LoadProgram(new byte[] { 0xC3, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, unchecked((ulong)-1)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("18446744073709551615", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("18446744073709551615", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(225UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -5955,12 +5947,11 @@ public void WCB_Register() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC4, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("210", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("210", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(1234567890UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -5968,12 +5959,11 @@ public void WCB_Register() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = unchecked((ulong)-1); testProcessor.LoadProgram(new byte[] { 0xC4, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("255", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("255", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(unchecked((ulong)-1), testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -5986,23 +5976,21 @@ public void WCB_Literal() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC5, 0xD2, 0x02, 0x96, 0x49, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("210", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("210", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xC5, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("255", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("255", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -6014,25 +6002,23 @@ public void WCB_Address() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC6, 0xFD, 7, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = 210; - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, stdoutOverride: consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("210", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("210", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xC6, 0xFD, 7, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = unchecked((byte)-1); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("255", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("255", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -6045,13 +6031,12 @@ public void WCB_Pointer() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC7, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = 210; - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("210", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("210", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(2045UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -6059,13 +6044,12 @@ public void WCB_Pointer() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = 2045; testProcessor.LoadProgram(new byte[] { 0xC7, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = unchecked((byte)-1); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("255", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("255", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(2045UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -6079,12 +6063,11 @@ public void WCX_Register() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC8, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("D2", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("D2", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(1234567890UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -6092,12 +6075,11 @@ public void WCX_Register() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = unchecked((ulong)-1); testProcessor.LoadProgram(new byte[] { 0xC8, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("FF", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("FF", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(unchecked((ulong)-1), testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -6110,23 +6092,21 @@ public void WCX_Literal() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xC9, 0xD2, 0x02, 0x96, 0x49, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("D2", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("D2", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xC9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("FF", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("FF", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -6138,25 +6118,23 @@ public void WCX_Address() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xCA, 0xFD, 7, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = 210; - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("D2", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("D2", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xCA, 0xFD, 7, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = unchecked((byte)-1); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(9UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("FF", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("FF", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -6169,13 +6147,12 @@ public void WCX_Pointer() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xCB, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = 210; - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("D2", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("D2", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(2045UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -6183,13 +6160,12 @@ public void WCX_Pointer() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = 2045; testProcessor.LoadProgram(new byte[] { 0xCB, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = unchecked((byte)-1); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(2UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("FF", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("FF", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(2045UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } diff --git a/Test/ProcessorTests/FullOpcodeTest.Floating.cs b/Test/ProcessorTests/FullOpcodeTest.Floating.cs index 03338a5..d86433f 100644 --- a/Test/ProcessorTests/FullOpcodeTest.Floating.cs +++ b/Test/ProcessorTests/FullOpcodeTest.Floating.cs @@ -2148,12 +2148,11 @@ public void FLPT_WCN_Register() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x70, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(BitConverter.DoubleToUInt64Bits(123.456), testProcessor.Registers[(int)Register.rg7], "Instruction updated the operand"); } @@ -2161,12 +2160,11 @@ public void FLPT_WCN_Register() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = BitConverter.DoubleToUInt64Bits(-123.456); testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x70, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(BitConverter.DoubleToUInt64Bits(-123.456), testProcessor.Registers[(int)Register.rg7], "Instruction updated the operand"); } @@ -2180,24 +2178,22 @@ public void FLPT_WCN_Literal() testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x71 }); testProcessor.WriteMemoryQWord(3, BitConverter.DoubleToUInt64Bits(123.456)); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x71 }); testProcessor.WriteMemoryQWord(3, BitConverter.DoubleToUInt64Bits(-123.456)); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -2209,25 +2205,23 @@ public void FLPT_WCN_Address() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x72, 225, 0, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, BitConverter.DoubleToUInt64Bits(123.456)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x72, 225, 0, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, BitConverter.DoubleToUInt64Bits(-123.456)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -2240,13 +2234,12 @@ public void FLPT_WCN_Pointer() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x73, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, BitConverter.DoubleToUInt64Bits(123.456)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(225UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the operand"); } @@ -2254,13 +2247,12 @@ public void FLPT_WCN_Pointer() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = 225; testProcessor.LoadProgram(new byte[] { 0xFF, 0x02, 0x73, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, BitConverter.DoubleToUInt64Bits(-123.456)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-123.456", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-123.456", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(225UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the operand"); } diff --git a/Test/ProcessorTests/FullOpcodeTest.Signed.cs b/Test/ProcessorTests/FullOpcodeTest.Signed.cs index 9cbf230..fa33424 100644 --- a/Test/ProcessorTests/FullOpcodeTest.Signed.cs +++ b/Test/ProcessorTests/FullOpcodeTest.Signed.cs @@ -2301,12 +2301,11 @@ public void SIGN_WCN_Register() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x50, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(1234567890UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2314,12 +2313,11 @@ public void SIGN_WCN_Register() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = unchecked((ulong)-1); testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x50, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(unchecked((ulong)-1), testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2332,23 +2330,21 @@ public void SIGN_WCN_Literal() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x51, 0xD2, 0x02, 0x96, 0x49, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -2360,25 +2356,23 @@ public void SIGN_WCN_Address() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x52, 225, 0, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, 1234567890); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x52, 225, 0, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, unchecked((ulong)-1)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -2391,13 +2385,12 @@ public void SIGN_WCN_Pointer() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x53, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, 1234567890); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("1234567890", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("1234567890", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(225UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2405,13 +2398,12 @@ public void SIGN_WCN_Pointer() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = 225; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x53, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.WriteMemoryQWord(225, unchecked((ulong)-1)); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(225UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2425,12 +2417,11 @@ public void SIGN_WCB_Register() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x54, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-46", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-46", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(1234567890UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2438,12 +2429,11 @@ public void SIGN_WCB_Register() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = unchecked((ulong)-1); testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x54, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(unchecked((ulong)-1), testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2456,23 +2446,21 @@ public void SIGN_WCB_Literal() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x55, 0xD2, 0x02, 0x96, 0x49, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-46", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-46", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x55, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -2484,25 +2472,23 @@ public void SIGN_WCB_Address() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x56, 0xFD, 7, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = 210; - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-46", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-46", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } testProcessor = new(2046); testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x56, 0xFD, 7, 0, 0, 0, 0, 0, 0 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = unchecked((byte)-1); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(11UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); } } @@ -2515,13 +2501,12 @@ public void SIGN_WCB_Pointer() // Set all status flags to ensure the instruction doesn't update them testProcessor.Registers[(int)Register.rsf] = ulong.MaxValue; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x57, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = 210; - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-46", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-46", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(ulong.MaxValue, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(2045UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); } @@ -2529,13 +2514,12 @@ public void SIGN_WCB_Pointer() testProcessor = new(2046); testProcessor.Registers[(int)Register.rg7] = 2045; testProcessor.LoadProgram(new byte[] { 0xFF, 0x01, 0x57, (int)Register.rg7 }); - using (StringWriter consoleOutput = new()) + using (MemoryStream consoleOutput = new()) { - Console.SetOut(consoleOutput); testProcessor.Memory[2045] = unchecked((byte)-1); - _ = testProcessor.Execute(false); + _ = testProcessor.Execute(false, consoleOutput); Assert.AreEqual(4UL, testProcessor.Registers[(int)Register.rpo], "Instruction updated the rpo register by an incorrect amount"); - Assert.AreEqual("-1", consoleOutput.ToString(), "Instruction printed an incorrect result to the console"); + Assert.AreEqual("-1", Encoding.UTF8.GetString(consoleOutput.ToArray()), "Instruction printed an incorrect result to the console"); Assert.AreEqual(0UL, testProcessor.Registers[(int)Register.rsf], "Instruction updated the status flags"); Assert.AreEqual(2045UL, testProcessor.Registers[(int)Register.rg7], "Instruction updated the second operand"); }