Ejemplo n.º 1
0
 public void ReleaseResources()
 {
     PagesTable.DeallocateAllPages();
 }
Ejemplo n.º 2
0
        //Loads program (file) to memory and checks if program is good
        public void LoadProgramToMemmory(string programFilePath)
        {
            StreamReader file = new StreamReader(@programFilePath);

            try
            {
                //first line must be $AMJ
                var line = file.ReadLine();
                checkLine(line);
                if (!line.ToUpper().Equals(Settings.Default.ProgramCodeStartSymbol))
                {
                    throw new ProgramContractException("Program must start with $AMJ sign");
                }

                line = file.ReadLine();
                checkLine(line);
                Name = line;

                int  programPointer         = 0;
                var  maxProgramPointerValue = Settings.Default.ProgramSegmentPagesCount * Settings.Default.PageSize - 1;
                bool stopReadingProgramCode = false;
                do
                {
                    line = file.ReadLine();
                    checkLine(line);

                    if (programPointer > maxProgramPointerValue)
                    {
                        throw new ProgramContractException("Program's code is too long!");
                    }
                    if (!line.ToUpper().Equals(Settings.Default.ProgramDataStartSymbol))
                    {
                        var physicalAddress = PagesTable.GetPhysicalAddress(programPointer);
                        m_realMachine.WriteMem(physicalAddress, new Word(line));
                    }
                    else
                    {
                        stopReadingProgramCode = true;
                    }
                    programPointer++;
                } while (!stopReadingProgramCode);

                var dataPointer         = maxProgramPointerValue + 1;
                var maxDataPointerValue = dataPointer + Settings.Default.DataSegmentPagesCount * Settings.Default.PageSize;
                var stopReadingDataCode = false;
                do
                {
                    line = file.ReadLine();
                    checkLine(line);
                    if (dataPointer > maxDataPointerValue)
                    {
                        throw new ProgramContractException("Data code is too long!");
                    }
                    if (!line.ToUpper().Equals(Settings.Default.ProgramEndSymbol))
                    {
                        m_realMachine.WriteMem(PagesTable.GetPhysicalAddress(dataPointer), new Word(line));
                    }
                    else
                    {
                        stopReadingDataCode = true;
                    }
                    dataPointer++;
                } while (!stopReadingDataCode);
            }
            catch (Exception e)
            {
                PagesTable.DeallocateAllPages();
                throw;
            }
            finally
            {
                file.Close();
            }
        }