private Tuple <int, int> CreateTaskProgramInSupervisorMemory(int supervisorAddress, int blockSize) { string oneLine = string.Empty; for (int i = 0; i < blockSize; i++) { char[][] block = RealMemory.GetSupervisorMemoryBlockValues(supervisorAddress + i * Utility.BLOCK_SIZE); oneLine += block.CharsToString(); } string[] lines = oneLine.Split('\n'); var segments = SegmentTask(lines); List <string> code = segments.Item1; List <string> data = segments.Item2; char[][] cleanCode = CleanCode(code); int dataStartBlock = Utility.VIRTUAL_MEMORY_BLOCKS / 2; char[][] cleanData = CleanData(data, ref dataStartBlock); char[][][] taskMemory = CreateTaskMemory(cleanCode, cleanData, dataStartBlock); PutTaskProgramToSupervisorMemory(taskMemory, supervisorAddress); return(Tuple.Create(supervisorAddress, Utility.VIRTUAL_MEMORY_BLOCKS)); }
public void XCHG() { char[][] sourceBlock = null; char[] sourceWord = null; int sourceAddress = ((HexRegister)registers["SB"]).GetIntValue(); int destinationAddress = ((HexRegister)registers["DB"]).GetIntValue(); int STvalue = ((ChoiceRegister)registers["ST"]).GetIntValue(); int DTvalue = ((ChoiceRegister)registers["DT"]).GetIntValue(); if ((STvalue == '5' || STvalue == '6' || STvalue == '7') ^ (DTvalue == '5' || DTvalue == '6' || DTvalue == '7')) { throw new Exception("Channel tool cannot work with word and block at the same time."); } switch (STvalue) { case 1: sourceBlock = RealMemory.GetUserMemoryBlockValues(sourceAddress); break; case 2: sourceBlock = RealMemory.GetSupervisorMemoryBlockValues(sourceAddress); break; case 3: sourceBlock = ExternalMemory.GetBlockValues(sourceAddress); break; case 4: sourceBlock = InputHandler.ReadBlock(); break; case 5: sourceWord = InputHandler.ReadWord(); break; case 6: sourceWord = Processor.GetRegisterValue("R1"); break; case 7: sourceWord = Processor.GetRegisterValue("R2"); break; default: throw new Exception("Channel tool ST register value is incorrect."); } switch (DTvalue) { case 1: RealMemory.SetUserMemoryBlockValues(destinationAddress, sourceBlock); break; case 2: RealMemory.SetSupervisorMemoryBlockValues(destinationAddress, sourceBlock); break; case 3: ExternalMemory.SetBlockValues(destinationAddress, sourceBlock); break; case 4: OutputHandler.WriteBlock(sourceBlock); break; case 5: OutputHandler.WriteWord(sourceWord); break; case 6: Processor.SetRegisterValue("R1", sourceWord); break; case 7: Processor.SetRegisterValue("R2", sourceWord); break; default: throw new Exception("Channel tool ST register value is incorrect."); } }