Exemple #1
0
        public static void LoadFile(string file)
        {
            // format filename
            if (!file.StartsWith(@"0:\"))
            {
                file = @"0:\" + file;
            }

            // load file
            bool error = false;

            if (PMFAT.FileExists(file))
            {
                try
                {
                    string[] lines = PMFAT.ReadLines(file);
                    Clear(false);
                    for (int i = 0; i < lines.Length; i++)
                    {
                        Lines.Add(lines[i]);
                    }
                    TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black);
                    TextGraphics.DrawString(0, StartY, "Successfully loaded \"" + file + "\"", Color.Green, Color.Black);
                    error = false;
                }
                catch (Exception ex) { error = true; }
            }
            else
            {
                error = true;
            }

            if (error)
            {
                TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black);
                TextGraphics.DrawString(0, StartY, "Unable to load file \"" + file + "\"", Color.Red, Color.Black);
            }

            if (!error)
            {
                CurrentFile = file;
            }
            Kernel.Delay(500);
            Draw();
            ReadInput();
        }
Exemple #2
0
        // save assembled code to file
        public static bool AssembleFile(string fileIn, string fileOut)
        {
            try
            {
                if (PMFAT.FileExists(fileIn))
                {
                    // read file
                    Input = DataUtils.StringArrayToList(PMFAT.ReadLines(fileIn));

                    // store variables, then labels

                    // store labels
                    StoreVariables();
                    if (!StoreLabels())
                    {
                        CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Problem occured while storing labels."); return(false);
                    }
                    if (!ReplaceLabels())
                    {
                        CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Problem occured while replacing labels with jumps."); return(false);
                    }
                    if (!AssembleCode(fileOut))
                    {
                        CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Problem occured while converting assmebler to bytecode."); return(false);
                    }
                    return(true);
                }
                else
                {
                    CLI.WriteLine("File system error!", Color.Red);
                    CLI.WriteLine("Input: " + fileIn, Color.White);
                    CLI.WriteLine("Output: " + fileOut, Color.White);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                CLI.WriteLine("Unknown error has occured while assembling!", Color.Red);
                CLI.Write("[INTERNAL] ", Color.Red); CLI.WriteLine(ex.Message, Color.White);
            }
            return(false);
        }
Exemple #3
0
        // load system configuration file
        public static void LoadConfig(string file, bool clear)
        {
            if (!PMFAT.FileExists(file))
            {
                CLI.WriteLine("Could not locate configuration file!", Color.Red);
            }
            else
            {
                try
                {
                    string[] lines = PMFAT.ReadLines(file);

                    foreach (string line in lines)
                    {
                        string[] args = line.Split(',');

                        // load config attributes
                        if (args[0] == "back_col")
                        {
                            CLI.BackColor = (Color)int.Parse(args[1]);
                        }
                        if (args[0] == "text_col")
                        {
                            CLI.ForeColor = (Color)int.Parse(args[1]);
                        }
                        if (args[0] == "titlebar_col")
                        {
                            Shell.TitleBarColor = (Color)int.Parse(args[1]);
                        }
                        if (args[0] == "title_col")
                        {
                            Shell.TitleColor = (Color)int.Parse(args[1]);
                        }
                        if (args[0] == "time_col")
                        {
                            Shell.DateTimeColor = (Color)int.Parse(args[1]);
                        }
                        if (args[0] == "titlebar_show")
                        {
                            Shell.TitleBarVisible = DataUtils.IntToBool(int.Parse(args[1]));
                        }
                    }

                    // reset screen
                    if (clear)
                    {
                        Shell.DrawFresh();
                    }
                    else
                    {
                        Shell.DrawTitleBar();
                    }
                }
                // unexpected error!
                catch (Exception ex)
                {
                    CLI.WriteLine("Error loading system configuration file!", Color.Red);
                    CLI.Write("[INTERNAL] ", Color.Red); CLI.WriteLine(ex.Message);
                }
            }
        }