public virtual void TestDataRegs() { for (int r = 0; r < 7; r++) { cpu.SetDataRegisterByte(r, 0xaa); Assert.Equal(0xaa, cpu.GetDataRegisterByte(r)); Assert.Equal(0xaa, cpu.GetDataRegisterWord(r)); Assert.Equal(0xaa, cpu.GetDataRegisterLong(r)); Assert.Equal(-86, cpu.GetDataRegisterByteSigned(r)); Assert.Equal(170, cpu.GetDataRegisterWordSigned(r)); cpu.SetDataRegisterWord(r, 0xa5a5); Assert.Equal(0xa5, cpu.GetDataRegisterByte(r)); Assert.Equal(0xa5a5, cpu.GetDataRegisterWord(r)); Assert.Equal(0xa5a5, cpu.GetDataRegisterLong(r)); Assert.Equal(-91, cpu.GetDataRegisterByteSigned(r)); Assert.Equal(-23131, cpu.GetDataRegisterWordSigned(r)); cpu.SetDataRegisterLong(r, -2054847099); Assert.Equal(0x85, cpu.GetDataRegisterByte(r)); Assert.Equal(0x8585, cpu.GetDataRegisterWord(r)); Assert.Equal(-2054847099, cpu.GetDataRegisterLong(r)); Assert.Equal(-123, cpu.GetDataRegisterByteSigned(r)); Assert.Equal(-31355, cpu.GetDataRegisterWordSigned(r)); cpu.SetDataRegisterLong(r, 305419896); Assert.Equal(0x78, cpu.GetDataRegisterByte(r)); Assert.Equal(0x5678, cpu.GetDataRegisterWord(r)); Assert.Equal(305419896, cpu.GetDataRegisterLong(r)); Assert.Equal(0x78, cpu.GetDataRegisterByteSigned(r)); Assert.Equal(0x5678, cpu.GetDataRegisterWordSigned(r)); } }
protected void HandleDataRegs(string[] tokens) { if (tokens is null) { throw new ArgumentNullException(nameof(tokens)); } string reg = tokens[0].Trim(); if (reg.Length != 2) { writer.WriteLine($"Bad identifier [{reg}]"); return; } var r = reg[1] - '0'; if (r < 0 || r > 7) { writer.WriteLine($"Bad identifier [{reg}]"); return; } if (tokens.Length == 2) { int value; try { value = ParseInt(tokens[1]); } catch (FormatException) { writer.WriteLine($"Bad value [{tokens[1]}]"); return; } cpu.SetDataRegisterLong(r, value); } else { writer.WriteLine("D{0}: {1}", r.ToString("d", CultureInfo.InvariantCulture), cpu.GetDataRegisterLong(r).ToString("x", CultureInfo.InvariantCulture)); } }