示例#1
0
        private bool FileWriteChosenInterrupt()
        {
            int[] xy = GetCurrentCommandLastTwoArguments();
            int   R1 = Processor.GetRegisterValue("R1").HexToInt();
            int   R2 = Processor.GetRegisterValue("R2").HexToInt();

            char[][] blockToFile = new char[R2][];

            bool first = true;

            for (int i = 0, block = 0; i < R2; block++)
            {
                for (int ii = 0; ii < Utility.BLOCK_SIZE || i < R2; ii++, i++)
                {
                    if (first)
                    {
                        ii = xy[1]; first = false;
                    }
                    int blockAddress = VirtualMemory.GetPager().GetCellRealAddress(((xy[0]) + block) * Utility.BLOCK_SIZE);
                    blockToFile[i] = RealMemory.GetUserMemoryValue(blockAddress + ii);
                }
            }

            bool result = FileManager.WriteFile(R1, blockToFile);

            if (!result)
            {
                return(false);
            }

            ResetSIRegister();
            return(true);
        }
示例#2
0
        private bool FileReadChosenInterrupt()
        {
            int[] xy = GetCurrentCommandLastTwoArguments();
            int   R1 = Processor.GetRegisterValue("R1").HexToInt();
            int   R2 = Processor.GetRegisterValue("R2").HexToInt();

            char[][] blockFromFile = FileManager.ReadFile(R1, R2);
            if (blockFromFile == null)
            {
                return(false);
            }

            bool first = true;

            for (int i = 0, block = 0; i < R2; block++)
            {
                for (int ii = 0; ii < Utility.BLOCK_SIZE || i < R2; ii++, i++)
                {
                    if (first)
                    {
                        ii = xy[1]; first = false;
                    }
                    int blockAddress = VirtualMemory.GetPager().GetCellRealAddress(((xy[0]) + block) * Utility.BLOCK_SIZE);
                    RealMemory.SetUserMemoryValue(blockAddress + ii, blockFromFile[i]);
                }
            }

            ResetSIRegister();
            return(true);
        }
示例#3
0
        private bool OutputBlockInterrupt()
        {
            int x = GetCurrentCommandLastArgument();

            Processor.UseChannelTool(VirtualMemory.GetPager().GetCellRealAddress(x * Utility.BLOCK_SIZE), 0, 1, 4);
            ResetSIRegister();
            return(true);
        }
示例#4
0
        public bool LoadVirtualMachine(string filePath)
        {
            //Get all file to one string
            string uncutTask = ReadTaskFile(filePath);

            if (uncutTask == string.Empty)
            {
                return(false);
            }

            //Cut string to blocks words and bytes
            char[][][] taskCutToBlocks         = CutToBlocks(uncutTask);
            int        taskBlockLengthUnsorted = taskCutToBlocks.Length;

            //Store blocks to supervisor memory
            PutTaskToSupervisorMemory(taskCutToBlocks);

            //Create task program in supervisor memory
            Tuple <int, int> result     = CreateTaskProgramInSupervisorMemory(0, taskBlockLengthUnsorted);
            int supervisorAddressSorted = result.Item1;
            int taskBlockLengthSorted   = result.Item2;

            //Copy task program to external memory and clear supervisor memory
            CopyTaskToExternalMemory(supervisorAddressSorted, taskBlockLengthSorted);

            //Create virtual memory
            VirtualMemory = RealMemory.CreateVirtualMemory(Utility.VIRTUAL_MEMORY_BLOCKS);

            Pager = VirtualMemory.GetPager();

            //Move task program from external memory to user / virtual memory
            UploadTaskToVirtualMemory(0, Utility.VIRTUAL_MEMORY_BLOCKS);

            GetProcessor().SetVirtualMemory(VirtualMemory, Pager);

            GetProcessor().SetICRegisterValue(0);

            return(true);
        }