public static void ToConsole(this IRandomAccessMemory ram, ushort start, ushort length) { var bytesBuilder = new StringBuilder(16 * 4); var characterBuilder = new StringBuilder(16); ushort width = 16; for (var address = start; address <= start + length; address += width) { Console.Write($"{address:X4} ".Pastel(Color.Goldenrod)); bytesBuilder.Clear(); characterBuilder.Clear(); var bytes = new byte[16]; for (ushort column = 0; column < width; column++) { var value = ram[(ushort)(address + column)]; bytes[column] = value; bytesBuilder.Append($"{value:X2} "); characterBuilder.Append(MockAsciiMapper.ConvertByteToChar(value)); } Console.Write(bytesBuilder.ToString().Pastel(Color.Orchid)); Console.Write(characterBuilder.ToString().Pastel(Color.Teal)); Console.WriteLine(); } }
public void Execute(ICpu cpu) { var address = cpu.Registers[0]; while (cpu.Memory[address] != 0) { var mascii = cpu.Memory[address]; if (mascii == MockAsciiMapper.NewLine) { Console.WriteLine(); } else { Console.Write(MockAsciiMapper.ConvertByteToChar(mascii)); } address++; } }
[TestCase(27, '.')] // unknown to period public void ConvertByteToChar_whenInvoked_MapsAsExpected(byte from, char expected) { var res = MockAsciiMapper.ConvertByteToChar(from); res.Should().Be(expected); }