2020-02-22 18:52:10 -05:00
|
|
|
|
using Mesen.GUI.Config;
|
|
|
|
|
using Mesen.GUI.Debugger.Labels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
2020-05-08 18:05:14 -04:00
|
|
|
|
public class BassLabelFile
|
2020-02-22 18:52:10 -05:00
|
|
|
|
{
|
|
|
|
|
public static void Import(string path, bool silent = false)
|
|
|
|
|
{
|
|
|
|
|
List<CodeLabel> labels = new List<CodeLabel>(1000);
|
|
|
|
|
|
|
|
|
|
int errorCount = 0;
|
|
|
|
|
foreach(string row in File.ReadAllLines(path, Encoding.UTF8)) {
|
2020-05-08 18:05:14 -04:00
|
|
|
|
string lineData = row.Trim();
|
|
|
|
|
int splitIndex = lineData.IndexOf(' ');
|
|
|
|
|
UInt32 address;
|
|
|
|
|
|
|
|
|
|
if(!UInt32.TryParse(lineData.Substring(0, splitIndex), NumberStyles.HexNumber, null, out address)) {
|
2020-02-22 18:52:10 -05:00
|
|
|
|
errorCount++;
|
2020-06-02 19:41:47 -04:00
|
|
|
|
continue;
|
2020-05-08 18:05:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.CpuMemory });
|
|
|
|
|
|
|
|
|
|
if(absAddress.Address >= 0) {
|
|
|
|
|
CodeLabel label = new CodeLabel();
|
|
|
|
|
label.Address = (UInt32)absAddress.Address;
|
|
|
|
|
label.MemoryType = absAddress.Type;
|
|
|
|
|
label.Comment = "";
|
|
|
|
|
string labelName = lineData.Substring(splitIndex + 1).Replace('.', '_');
|
|
|
|
|
if(string.IsNullOrEmpty(labelName) || !LabelManager.LabelRegex.IsMatch(labelName)) {
|
|
|
|
|
errorCount++;
|
|
|
|
|
} else {
|
|
|
|
|
label.Label = labelName;
|
|
|
|
|
labels.Add(label);
|
|
|
|
|
}
|
2020-02-22 18:52:10 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelManager.SetLabels(labels);
|
|
|
|
|
|
|
|
|
|
if(!silent) {
|
|
|
|
|
string message = $"Import completed with {labels.Count} labels imported";
|
|
|
|
|
if(errorCount > 0) {
|
|
|
|
|
message += $" and {errorCount} error(s)";
|
|
|
|
|
}
|
|
|
|
|
MessageBox.Show(message, "Mesen-S", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|