private void okButton_Click(object sender, EventArgs e) { bool checkNameCollision = editingMode == LabelEditMode.Add ? true : !nameBox.Text.Equals(editedLabel.Name, StringComparison.Ordinal); int val = 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 (!Int32.TryParse(offsetBox.Text, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out val)) { Error.ShowErrorMessage(ErrorMessage.Label_InvalidVariable); } else { if (editingMode == LabelEditMode.Edit) { labelContainer.RemoveVarLabel(editedLabel); } editedLabel = new VarLabel(val, nameBox.Text, commentBox.Text); labelContainer.AddVarLabel(editedLabel); this.DialogResult = System.Windows.Forms.DialogResult.OK; } }
public void RemoveVarLabel(VarLabel toBeRemoved) { lock (symbolListLock) { _varList.Remove(toBeRemoved); var sym = new Symbol() { Name = toBeRemoved.Name }; symbolTable.RemoveSymbol(sym); } }
public bool TryGetVarLabel(ushort current, out VarLabel label) { lock (symbolListLock) { var s = from item in _varList where item.Variable == current select item; var success = s.Count() != 0; label = success ? s.First() : new VarLabel(current); return(success); } }
public void AddVarLabel(VarLabel toBeAdded) { lock (symbolListLock) { var sym = new Symbol() { Name = toBeAdded.Name, Value = toBeAdded.Value, IsConstant = true }; if (!symbolTable.ContainsSymbol(sym)) { _varList.Add(toBeAdded); symbolTable.AddSymbol(sym); } } }
public AddVarLabelForm(LabelContainer lblContainer, LabelEditMode editMode, VarLabel newPriorLabel = null) { InitializeComponent(); labelContainer = lblContainer; editingMode = editMode; editedLabel = newPriorLabel; if (editMode == LabelEditMode.Edit) { Text = "Edit Variable"; if (editedLabel != null) { nameBox.Text = editedLabel.Name; offsetBox.Text = editedLabel.Value.ToString("X"); if (!String.IsNullOrEmpty(editedLabel.Comment)) { commentBox.Text = editedLabel.Comment; } } } }
public VarLabel(VarLabel prev) : this(prev.Value, prev.Name, prev.Comment) { }
public bool TryGetVarLabel(ushort current, out VarLabel label) { lock (symbolListLock) { var s = from item in _varList where item.Variable == current select item; var success = s.Count() != 0; label = success ? s.First() : new VarLabel(current); return success; } }
// 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; } } } } } }
// 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; } } } } } }
public Task<string> ShowVarLabelAsync(VarLabel varLabel) { var task = new Task<string>(() => ShowVarLabel(varLabel)); task.Start(); return task; }
public string ShowVarLabel(VarLabel varLabel) { StringBuilder ret = new StringBuilder(); ret.AppendLine(varLabel.ToDisplayString()); ret.AppendLine(SearchForReference(varLabel)); return ret.ToString(); }