public void SquareNumberInCpu64ShouldDrawErrorMessageWhenValueIsGreaterThanMaxValue() { var cpu = new Cpu64(4); var motherboardMock = new Mock<IMotherboard>(); motherboardMock.Setup(x => x.LoadRamValue()).Returns(Cpu64.MaxValue + 1); cpu.AttachTo(motherboardMock.Object); cpu.SquareNumber(); motherboardMock.Verify(x => x.DrawOnVideoCard( It.Is<string>(param => param == Cpu.NumberTooHighMessage))); }
public void SquareNumberInCpu64ShouldDrawErrorMessageWhenValueIsGreaterThanMaxValue() { var cpu = new Cpu64(4); var motherboardMock = new Mock <IMotherboard>(); motherboardMock.Setup(x => x.LoadRamValue()).Returns(Cpu64.MaxValue + 1); cpu.AttachTo(motherboardMock.Object); cpu.SquareNumber(); motherboardMock.Verify(x => x.DrawOnVideoCard( It.Is <string>(param => param == Cpu.NumberTooHighMessage))); }
public void Run(IEnumerable <byte> program) { // Init the core Memory.Write(BaseAddres, program); Register.WriteUnsignedInt(Register.ProgramCounter, BaseAddres); var decoder = new InstructionDecoder(EndianCoding); var typeDecoder = new TypeDecoder(); // Create a simple bootstrap CPU var cpu = new Cpu64(); cpu.AssignMemory(Memory); cpu.AssignRegister(Register); cpu.AssignEEI(Environment); cpu.AssignRasStack(RasStack); cpu.AssignCrs(CsrRegister); cpu.Init(); // Fetch the first instruction and run the loop var pc = Register.ReadUnsignedInt(Register.ProgramCounter); // Get the first 2 Bytes from the Base Address aka PC var instructionCoding = Memory.GetHalfWord(pc); while (ContinueIfValid(instructionCoding)) { // Loop for the commands var instruction = decoder.Decode(instructionCoding); InstructionsProcessed.Add(instruction); // If the decoder cannot decode the parameter pattern, throw an exception if (instruction.Type == InstructionType.Unknown) { string unknownOpCodeErrorMessage = String.Format("Error: OpCode = {0}", instruction.OpCode); throw new OpCodeNotSupportedException(unknownOpCodeErrorMessage) { Coding = instructionCoding, Type = instruction.Type, OpCode = instruction.OpCode }; } // Reload the other bytes if required! if (instruction.InstructionLength == 4) { // Read the complete 32 Bit instruction set for the decoding var inst32Coding = Memory.GetWord(pc); var payload = typeDecoder.DecodeType(instruction, inst32Coding); if (payload == null) { throw new RiscVSimException("No Payload available!"); } // For UnitTesting: Add the result to the list InstructionPayloads.Add(payload); // Execute the command cpu.Execute(instruction, payload); } // Done. Next run. pc = Register.ReadUnsignedInt(Register.ProgramCounter); instructionCoding = Memory.GetHalfWord(pc); } }