Exemple #1
0
 public ImageDisplayForm(BinFile dt, DataLabel ds)
 {
     InitializeComponent();
     dst = ds;
     bin = dt;
     gbs = ds.Palette;
     labelOff = ds.Offset;
     labelLen = ds.Length;
     SetColors();
     InitializeImage();
 }
 public bool TryGetDataLabel(int current, out DataLabel label)
 {
     lock (symbolListLock)
     {
         var s = from item in _dataList
                 where item.Offset == current
                 select item;
         var success = s.Count() != 0;
         label = success ? s.First() : new DataLabel(current);
         return(success);
     }
 }
 public void RemoveDataLabel(DataLabel toBeRemoved)
 {
     lock (symbolListLock)
     {
         _dataList.Remove(toBeRemoved);
         var sym = new Symbol()
         {
             Name = toBeRemoved.Name
         };
         symbolTable.RemoveSymbol(sym);
         _dataAddrs.RemoveWhere(x => x >= toBeRemoved.Offset && x < toBeRemoved.Offset + toBeRemoved.Length);
     }
 }
 public void AddDataLabel(DataLabel toBeAdded)
 {
     lock (symbolListLock)
     {
         var sym = new Symbol()
         {
             Name  = toBeAdded.Name,
             Value = toBeAdded.Offset
         };
         if (!symbolTable.ContainsSymbol(sym))
         {
             _dataList.Add(toBeAdded);
             symbolTable.AddSymbol(sym);
             for (int i = toBeAdded.Offset; i < toBeAdded.Offset + toBeAdded.Length; i++)
             {
                 _dataAddrs.Add(i);
             }
         }
     }
 }
 public AddDataLabelForm(LabelContainer lblContainer, LabelEditMode editMode, DataLabel newPriorLabel = null)
 {
     InitializeComponent();
     labelContainer = lblContainer;
     editingMode = editMode;
     editedLabel = newPriorLabel;
     dataTypeBox.SelectedIndex = 0;
     if (editMode == LabelEditMode.Edit)
     {
         Text = "Edit Data Section";
         if (editedLabel != null)
         {
             nameBox.Text = editedLabel.Name;
             offsetBox.Text = editedLabel.Offset.ToString("X");
             lengthBox.Text = editedLabel.Length.ToString("X");
             dataTypeBox.SelectedIndex = (int)editedLabel.DSectionType;
             if (!String.IsNullOrEmpty(editedLabel.Comment))
             {
                 commentBox.Text = editedLabel.Comment;
             }
             dataTemplateBox.Text = TemplateBuilder.TemplateToString(editedLabel.PrintTemplate);
         }
     }
 }
Exemple #6
0
 public DataLabel(DataLabel prev)
     : this(prev.Value, prev._length, prev.Name, prev.Comment, prev._printTemplate, prev.dataSectType)
 {
 }
Exemple #7
0
 public bool TryGetDataLabel(int current, out DataLabel label)
 {
     lock (symbolListLock)
     {
         var s = from item in _dataList
                 where item.Offset == current
                 select item;
         var success = s.Count() != 0;
         label = success ? s.First() : new DataLabel(current);
         return success;
     }
 }
Exemple #8
0
 public void RemoveDataLabel(DataLabel toBeRemoved)
 {
     lock (symbolListLock)
     {
         _dataList.Remove(toBeRemoved);
         var sym = new Symbol()
         {
             Name = toBeRemoved.Name
         };
         symbolTable.RemoveSymbol(sym);
         _dataAddrs.RemoveWhere(x => x >= toBeRemoved.Offset && x < toBeRemoved.Offset + toBeRemoved.Length);
     }
 }
Exemple #9
0
        // TODO: Make sure everything saves and loads properly.
        public void LoadLabelFile(string fileName)
        {
            using (TextReader labelFile = new StreamReader(fileName))
            {
                using (TextWriter errFile = new StreamWriter("err.txt"))
                {
                    if (labelFile.ReadLine() != "gbr")
                    {
                        return;
                    }
                    else
                    {
                        var items = new List<Dictionary<string, string>>();
                        int curItem = -1;
                        string currentLine;
                        while ((currentLine = labelFile.ReadLine()) != null)
                        {
                            switch (currentLine)
                            {
                                case ".label":
                                    {
                                        items.Add(new Dictionary<string, string>() { { "tag", "label" } });
                                        curItem++;
                                    }
                                    break;

                                case ".data":
                                    {
                                        items.Add(new Dictionary<string, string>() { { "tag", "data" } });
                                        curItem++;
                                    }
                                    break;

                                case ".var":
                                    {
                                        items.Add(new Dictionary<string, string>() { { "tag", "var" } });
                                        curItem++;
                                    }
                                    break;

                                case ".comment":
                                    {
                                        items.Add(new Dictionary<string, string>() { { "tag", "comment" } });
                                        curItem++;
                                    }
                                    break;

                                default:
                                    if (curItem == -1)
                                    {
                                        break;
                                    }
                                    string[] opt = currentLine.Split(new[] { ':' }, 2);
                                    if (opt.Length == 1)
                                    {
                                        if (items[curItem].ContainsKey("_c"))
                                        {
                                            items[curItem]["_c"] += "\n" + currentLine;
                                        }
                                        else
                                        {
                                            items[curItem].Add("_c", currentLine);
                                        }
                                    }
                                    else
                                    {
                                        if (items[curItem].ContainsKey(opt[0]))
                                        {
                                            items[curItem][opt[0]] = opt[1];
                                        }
                                        else
                                        {
                                            items[curItem].Add(opt[0], opt[1]);
                                        }
                                    }
                                    break;
                            }
                        }
                        foreach (var currentItem in items)
                        {
                            switch (currentItem["tag"])
                            {
                                case "label":
                                    {
                                        int offset = 0;
                                        string name = "";
                                        string comment = "";
                                        bool offsetGood = false;
                                        foreach (var kvp in currentItem)
                                        {
                                            switch (kvp.Key)
                                            {
                                                case "_o":
                                                    {
                                                        offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset);
                                                    }

                                                    break;

                                                case "_n":
                                                    {
                                                        if (Utility.IsWord(kvp.Value))
                                                        {
                                                            name = kvp.Value;
                                                        }
                                                    }

                                                    break;

                                                case "_c":
                                                    {
                                                        comment = kvp.Value;
                                                    }

                                                    break;
                                            }
                                        }
                                        if (offsetGood)
                                        {
                                            FunctionLabel fl = new FunctionLabel(offset, name, comment);
                                            AddFuncLabel(fl);
                                        }
                                        else
                                        {
                                            errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                        }
                                    }

                                    break;

                                case "data":
                                    {
                                        int offset = -1;
                                        int length = -1;
                                        string printTemp = "";
                                        string name = "";
                                        string comment = "";
                                        DataSectionType dst = DataSectionType.Data;
                                        GBPalette gbp = new GBPalette();
                                        bool offsetGood = false;
                                        bool lengthGood = false;
                                        foreach (var kvp in currentItem)
                                        {
                                            switch (kvp.Key)
                                            {
                                                case "_o":
                                                    {
                                                        offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset);
                                                    }

                                                    break;

                                                case "_l":
                                                    {
                                                        lengthGood = Utility.OffsetStringToInt(kvp.Value, out length);
                                                    }
                                                    break;

                                                case "_n":
                                                    {
                                                        if (Utility.IsWord(kvp.Value))
                                                        {
                                                            name = kvp.Value;
                                                        }
                                                    }

                                                    break;

                                                case "_d":
                                                    {
                                                        printTemp = kvp.Value;
                                                    }
                                                    break;

                                                case "_p1":
                                                    {
                                                        dst = DataSectionType.Image;
                                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_1);
                                                    }

                                                    break;

                                                case "_p2":
                                                    {
                                                        dst = DataSectionType.Image;
                                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_2);
                                                    }

                                                    break;

                                                case "_p3":
                                                    {
                                                        dst = DataSectionType.Image;
                                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_3);
                                                    }

                                                    break;

                                                case "_p4":
                                                    {
                                                        dst = DataSectionType.Image;
                                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_4);
                                                    }

                                                    break;

                                                case "_c":
                                                    {
                                                        comment = kvp.Value;
                                                    }

                                                    break;
                                            }
                                        }

                                        if (offsetGood && lengthGood)
                                        {
                                            DataLabel ds = new DataLabel(offset, length, name, printTemp, comment, dst, gbp);
                                            AddDataLabel(ds);
                                        }
                                        else
                                        {
                                            errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                        }
                                    }

                                    break;

                                case "var":
                                    {
                                        int variable = -1;
                                        string name = "";
                                        string comment = "";
                                        bool variableGood = false;

                                        foreach (var kvp in currentItem)
                                        {
                                            switch (kvp.Key)
                                            {
                                                case "_v":
                                                    {
                                                        variableGood = Utility.OffsetStringToInt(kvp.Value, out variable);
                                                    }

                                                    break;

                                                case "_n":
                                                    {
                                                        if (Utility.IsWord(kvp.Value))
                                                        {
                                                            name = kvp.Value;
                                                        }
                                                    }

                                                    break;

                                                case "_c":
                                                    {
                                                        comment = kvp.Value;
                                                    }

                                                    break;
                                            }
                                        }

                                        if (variableGood)
                                        {
                                            VarLabel vl = new VarLabel(variable, name, comment);
                                            AddVarLabel(vl);
                                        }
                                        else
                                        {
                                            errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                        }
                                    }

                                    break;

                                case "comment":
                                    {
                                        int offset = 0;
                                        string name = String.Empty;
                                        string comment = "";
                                        bool offsetGood = false;

                                        foreach (var kvp in currentItem)
                                        {
                                            switch (kvp.Key)
                                            {
                                                case "_o":
                                                    {
                                                        offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset);
                                                    }

                                                    break;

                                                case "_c":
                                                    {
                                                        comment = kvp.Value;
                                                    }

                                                    break;
                                            }
                                        }
                                        if (offsetGood)
                                        {
                                            AddComment(offset, comment);
                                        }
                                        else
                                        {
                                            errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                        }
                                    }
                                    break;

                                default:

                                    break;
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
 public void AddDataLabel(DataLabel toBeAdded)
 {
     lock (symbolListLock)
     {
         var sym = new Symbol()
         {
             Name = toBeAdded.Name,
             Value = toBeAdded.Offset
         };
         if (!symbolTable.ContainsSymbol(sym))
         {
             _dataList.Add(toBeAdded);
             symbolTable.AddSymbol(sym);
             for (int i = toBeAdded.Offset; i < toBeAdded.Offset + toBeAdded.Length; i++)
             {
                 _dataAddrs.Add(i);
             }
         }
     }
 }
Exemple #11
0
        // TODO: Make sure everything saves and loads properly.

        public void LoadLabelFile(string fileName)
        {
            using (TextReader labelFile = new StreamReader(fileName))
            {
                using (TextWriter errFile = new StreamWriter("err.txt"))
                {
                    if (labelFile.ReadLine() != "gbr")
                    {
                        return;
                    }
                    else
                    {
                        var    items   = new List <Dictionary <string, string> >();
                        int    curItem = -1;
                        string currentLine;
                        while ((currentLine = labelFile.ReadLine()) != null)
                        {
                            switch (currentLine)
                            {
                            case ".label":
                            {
                                items.Add(new Dictionary <string, string>()
                                    {
                                        { "tag", "label" }
                                    });
                                curItem++;
                            }
                            break;

                            case ".data":
                            {
                                items.Add(new Dictionary <string, string>()
                                    {
                                        { "tag", "data" }
                                    });
                                curItem++;
                            }
                            break;

                            case ".var":
                            {
                                items.Add(new Dictionary <string, string>()
                                    {
                                        { "tag", "var" }
                                    });
                                curItem++;
                            }
                            break;

                            case ".comment":
                            {
                                items.Add(new Dictionary <string, string>()
                                    {
                                        { "tag", "comment" }
                                    });
                                curItem++;
                            }
                            break;

                            default:
                                if (curItem == -1)
                                {
                                    break;
                                }
                                string[] opt = currentLine.Split(new[] { ':' }, 2);
                                if (opt.Length == 1)
                                {
                                    if (items[curItem].ContainsKey("_c"))
                                    {
                                        items[curItem]["_c"] += "\n" + currentLine;
                                    }
                                    else
                                    {
                                        items[curItem].Add("_c", currentLine);
                                    }
                                }
                                else
                                {
                                    if (items[curItem].ContainsKey(opt[0]))
                                    {
                                        items[curItem][opt[0]] = opt[1];
                                    }
                                    else
                                    {
                                        items[curItem].Add(opt[0], opt[1]);
                                    }
                                }
                                break;
                            }
                        }
                        foreach (var currentItem in items)
                        {
                            switch (currentItem["tag"])
                            {
                            case "label":
                            {
                                int    offset     = 0;
                                string name       = "";
                                string comment    = "";
                                bool   offsetGood = false;
                                foreach (var kvp in currentItem)
                                {
                                    switch (kvp.Key)
                                    {
                                    case "_o":
                                    {
                                        offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset);
                                    }

                                    break;

                                    case "_n":
                                    {
                                        if (Utility.IsWord(kvp.Value))
                                        {
                                            name = kvp.Value;
                                        }
                                    }

                                    break;

                                    case "_c":
                                    {
                                        comment = kvp.Value;
                                    }

                                    break;
                                    }
                                }
                                if (offsetGood)
                                {
                                    FunctionLabel fl = new FunctionLabel(offset, name, comment);
                                    AddFuncLabel(fl);
                                }
                                else
                                {
                                    errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                }
                            }

                            break;

                            case "data":
                            {
                                int             offset     = -1;
                                int             length     = -1;
                                string          printTemp  = "";
                                string          name       = "";
                                string          comment    = "";
                                DataSectionType dst        = DataSectionType.Data;
                                GBPalette       gbp        = new GBPalette();
                                bool            offsetGood = false;
                                bool            lengthGood = false;
                                foreach (var kvp in currentItem)
                                {
                                    switch (kvp.Key)
                                    {
                                    case "_o":
                                    {
                                        offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset);
                                    }

                                    break;

                                    case "_l":
                                    {
                                        lengthGood = Utility.OffsetStringToInt(kvp.Value, out length);
                                    }
                                    break;

                                    case "_n":
                                    {
                                        if (Utility.IsWord(kvp.Value))
                                        {
                                            name = kvp.Value;
                                        }
                                    }

                                    break;

                                    case "_d":
                                    {
                                        printTemp = kvp.Value;
                                    }
                                    break;

                                    case "_p1":
                                    {
                                        dst = DataSectionType.Image;
                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_1);
                                    }

                                    break;

                                    case "_p2":
                                    {
                                        dst = DataSectionType.Image;
                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_2);
                                    }

                                    break;

                                    case "_p3":
                                    {
                                        dst = DataSectionType.Image;
                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_3);
                                    }

                                    break;

                                    case "_p4":
                                    {
                                        dst = DataSectionType.Image;
                                        Utility.OffsetStringToInt(kvp.Value, out gbp.Col_4);
                                    }

                                    break;

                                    case "_c":
                                    {
                                        comment = kvp.Value;
                                    }

                                    break;
                                    }
                                }

                                if (offsetGood && lengthGood)
                                {
                                    DataLabel ds = new DataLabel(offset, length, name, printTemp, comment, dst, gbp);
                                    AddDataLabel(ds);
                                }
                                else
                                {
                                    errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                }
                            }

                            break;

                            case "var":
                            {
                                int    variable     = -1;
                                string name         = "";
                                string comment      = "";
                                bool   variableGood = false;

                                foreach (var kvp in currentItem)
                                {
                                    switch (kvp.Key)
                                    {
                                    case "_v":
                                    {
                                        variableGood = Utility.OffsetStringToInt(kvp.Value, out variable);
                                    }

                                    break;

                                    case "_n":
                                    {
                                        if (Utility.IsWord(kvp.Value))
                                        {
                                            name = kvp.Value;
                                        }
                                    }

                                    break;

                                    case "_c":
                                    {
                                        comment = kvp.Value;
                                    }

                                    break;
                                    }
                                }

                                if (variableGood)
                                {
                                    VarLabel vl = new VarLabel(variable, name, comment);
                                    AddVarLabel(vl);
                                }
                                else
                                {
                                    errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                }
                            }

                            break;

                            case "comment":
                            {
                                int    offset     = 0;
                                string name       = String.Empty;
                                string comment    = "";
                                bool   offsetGood = false;

                                foreach (var kvp in currentItem)
                                {
                                    switch (kvp.Key)
                                    {
                                    case "_o":
                                    {
                                        offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset);
                                    }

                                    break;

                                    case "_c":
                                    {
                                        comment = kvp.Value;
                                    }

                                    break;
                                    }
                                }
                                if (offsetGood)
                                {
                                    AddComment(offset, comment);
                                }
                                else
                                {
                                    errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized.");
                                }
                            }
                            break;

                            default:

                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #12
0
 public Task<string> ShowDataLabelAsync(DataLabel dataLabel)
 {
     var task = new Task<string>(() => ShowDataLabel(dataLabel));
     task.Start();
     return task;
 }
Exemple #13
0
 // TODO: Handle the case where the DL goes out of bounds.
 public string ShowDataLabel(DataLabel dataLabel)
 {
     StringBuilder ret = new StringBuilder(String.Empty);
     ret.Append(GetDataTemplateSection(dataLabel.PrintTemplate, dataLabel.Offset, dataLabel.Length));
     return ret.ToString();
 }
Exemple #14
0
 public DataLabel(DataLabel prev) : this(prev.Value, prev._length, prev.Name, prev.Comment, prev._printTemplate, prev.dataSectType)
 {
 }
 private void okButton_Click(object sender, EventArgs e)
 {
     bool checkNameCollision = editingMode == LabelEditMode.Add ?
         true :
         !nameBox.Text.Equals(editedLabel.Name, StringComparison.Ordinal);
     int off = -1;
     int len = 0;
     Symbol sym = new Symbol()
     {
         Name = nameBox.Text
     };
     if (!Utility.IsWord(nameBox.Text))
     {
         Error.ShowErrorMessage(ErrorMessage.Label_InvalidName);
     }
     else if (checkNameCollision && labelContainer.IsSymbolDefined(sym))
     {
         Error.ShowErrorMessage(ErrorMessage.Label_NameAlreadyDefined);
     }
     else if (!Utility.OffsetStringToInt(offsetBox.Text, out off))
     {
         Error.ShowErrorMessage(ErrorMessage.Label_InvalidOffset);
     }
     else if (!Int32.TryParse(lengthBox.Text, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out len) || len <= 0)
     {
         Error.ShowErrorMessage(ErrorMessage.Label_InvalidLength);
     }
     else
     {
         TemplateBuilder tb = new TemplateBuilder();
         string input = dataTemplateBox.Text;
         bool success = false;
         CompError error = new CompError();
         var printTemplate = tb.ValidateTemplate(input, ref error, out success);
         if (!success)
         {
             Error.ShowErrorMessage(error);
         }
         else
         {
             if (editingMode == LabelEditMode.Edit)
             {
                 labelContainer.RemoveDataLabel(editedLabel);
             }
             editedLabel = new DataLabel(off, len, nameBox.Text, printTemplate, commentBox.Text, (DataSectionType)dataTypeBox.SelectedIndex);
             labelContainer.AddDataLabel(editedLabel);
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
         }
     }
 }