2014-02-10 01:06:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using System.IO;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Components.H6280;
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.PCEngine;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public partial class PCECDL : Form, IToolForm
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
// TODO
|
|
|
|
|
// Loading doesn't work
|
|
|
|
|
// Save
|
|
|
|
|
// Save Window position and size
|
|
|
|
|
// Restore settings
|
|
|
|
|
private PCEngine _emu;
|
|
|
|
|
private CodeDataLog _cdl;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
|
|
|
|
|
public PCECDL()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-04-13 01:05:23 +00:00
|
|
|
|
TopMost = Global.Config.PceCdlSettings.TopMost;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
Restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateValues()
|
|
|
|
|
{
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Restart()
|
|
|
|
|
{
|
|
|
|
|
if (Global.Emulator is PCEngine)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_emu = (PCEngine)Global.Emulator;
|
|
|
|
|
LoggingActiveCheckbox.Checked = _emu.Cpu.CDLLoggingActive;
|
|
|
|
|
_cdl = _emu.Cpu.CDL;
|
|
|
|
|
_emu.InitCDLMappings();
|
2014-02-10 01:06:06 +00:00
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_emu = null;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void UpdateDisplay()
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
var lines = new List<string>();
|
|
|
|
|
if (_cdl == null)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
lines.Add("No CDL loaded.");
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
lines.Add("CDL contains the following domains:");
|
|
|
|
|
foreach (var kvp in _cdl)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
int total = 0;
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
fixed (byte* data = kvp.Value)
|
|
|
|
|
{
|
|
|
|
|
byte* src = data;
|
|
|
|
|
byte* end = data + kvp.Value.Length;
|
|
|
|
|
while (src < end)
|
|
|
|
|
{
|
|
|
|
|
if (*src++ != 0)
|
2014-04-13 01:05:23 +00:00
|
|
|
|
{
|
2014-02-10 01:06:06 +00:00
|
|
|
|
total++;
|
2014-04-13 01:05:23 +00:00
|
|
|
|
}
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-13 01:05:23 +00:00
|
|
|
|
|
|
|
|
|
lines.Add(string.Format("Domain {0} Size {1} Mapped {2}%", kvp.Key, kvp.Value.Length, total / (float) kvp.Value.Length * 100f));
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-13 01:05:23 +00:00
|
|
|
|
|
|
|
|
|
CdlTextbox.Lines = lines.ToArray();
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AskSave()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UpdateBefore
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void LoadFileFromRecent(string path)
|
|
|
|
|
{
|
|
|
|
|
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
|
|
|
|
|
{
|
|
|
|
|
var newCDL = CodeDataLog.Load(fs);
|
|
|
|
|
if (!newCDL.CheckConsistency(_emu.Cpu.Mappings))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "CDL file does not match emulator's current memory map!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_cdl = newCDL;
|
|
|
|
|
_emu.Cpu.CDL = _cdl;
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RecentSubMenu.DropDownItems.Clear();
|
|
|
|
|
RecentSubMenu.DropDownItems.AddRange(
|
|
|
|
|
ToolHelpers.GenerateRecentMenu(Global.Config.RecentPceCdlFiles, LoadFileFromRecent));
|
|
|
|
|
RecentSubMenu.DropDownItems.Add(
|
|
|
|
|
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentPceCdlFiles));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NewMenuItem_Click(object sender, EventArgs e)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
var result = MessageBox.Show(this, "OK to create new CDL?", "Query", MessageBoxButtons.YesNo);
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_cdl = CodeDataLog.Create(_emu.Cpu.Mappings);
|
|
|
|
|
_emu.Cpu.CDL = _cdl;
|
2014-02-10 01:06:06 +00:00
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void OpenMenuItem_Click(object sender, EventArgs e)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
var result = MessageBox.Show(this, "OK to load new CDL?", "Query", MessageBoxButtons.YesNo);
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
|
|
|
|
result = ofd.ShowDialog(this);
|
|
|
|
|
if (result == DialogResult.OK)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using (var fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-02-10 05:02:30 +00:00
|
|
|
|
var newCDL = CodeDataLog.Load(fs);
|
2014-04-13 01:05:23 +00:00
|
|
|
|
if (!newCDL.CheckConsistency(_emu.Cpu.Mappings))
|
2014-02-10 05:02:30 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "CDL file does not match emulator's current memory map!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_cdl = newCDL;
|
|
|
|
|
_emu.Cpu.CDL = _cdl;
|
2014-02-10 05:02:30 +00:00
|
|
|
|
UpdateDisplay();
|
2014-04-13 01:05:23 +00:00
|
|
|
|
Global.Config.RecentPceCdlFiles.Add(ofd.FileName);
|
2014-02-10 05:02:30 +00:00
|
|
|
|
}
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void SaveMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveAsMenuItem_Click(object sender, EventArgs e)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
if (_cdl == null)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "Cannot save with no CDL loaded!", "Alert");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog();
|
|
|
|
|
var result = sfd.ShowDialog(this);
|
|
|
|
|
if (result == DialogResult.OK)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_cdl.Save(fs);
|
|
|
|
|
Global.Config.RecentPceCdlFiles.Add(sfd.FileName);
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void AppendMenuItem_Click(object sender, EventArgs e)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
if (_cdl == null)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "Cannot union with no CDL loaded!", "Alert");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
|
|
|
|
var result = ofd.ShowDialog(this);
|
|
|
|
|
if (result == DialogResult.OK)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using (var fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
var newCDL = CodeDataLog.Load(fs);
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_cdl.LogicalOrFrom(newCDL);
|
2014-02-10 01:06:06 +00:00
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void ClearMenuItem_Click(object sender, EventArgs e)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
if (_cdl == null)
|
2014-02-10 01:06:06 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "Cannot clear with no CDL loaded!", "Alert");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var result = MessageBox.Show(this, "OK to clear CDL?", "Query", MessageBoxButtons.YesNo);
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_cdl.ClearData();
|
2014-02-10 01:06:06 +00:00
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 01:05:23 +00:00
|
|
|
|
private void DisassembleMenuItem_Click(object sender, EventArgs e)
|
2014-02-20 22:59:37 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
if (_cdl == null)
|
2014-02-20 22:59:37 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "Cannot disassemble with no CDL loaded!", "Alert");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog();
|
|
|
|
|
var result = sfd.ShowDialog(this);
|
|
|
|
|
if (result == DialogResult.OK)
|
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
|
2014-02-20 22:59:37 +00:00
|
|
|
|
{
|
2014-04-13 01:05:23 +00:00
|
|
|
|
_cdl.Disassemble(fs, Global.Emulator.MemoryDomains);
|
2014-02-20 22:59:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-13 01:05:23 +00:00
|
|
|
|
|
|
|
|
|
private void ExitMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SaveWindowPositionMenuItem.Checked = Global.Config.PceCdlSettings.SaveWindowPosition;
|
|
|
|
|
TopMost = AlwaysOnTopMenuItem.Checked = Global.Config.PceCdlSettings.TopMost;
|
|
|
|
|
FloatingWindowMenuItem.Checked = Global.Config.PceCdlSettings.FloatingWindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Global.Config.PceCdlSettings.SaveWindowPosition ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Global.Config.PceCdlSettings.TopMost ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FloatingWindowMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Global.Config.PceCdlSettings.FloatingWindow ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PCECDL_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Global.Config.RecentPceCdlFiles.AutoLoad)
|
|
|
|
|
{
|
|
|
|
|
LoadFileFromRecent(Global.Config.RecentPceCdlFiles.MostRecent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoggingActiveCheckbox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (LoggingActiveCheckbox.Checked && _cdl == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(this, "Cannot log with no CDL loaded!", "Alert");
|
|
|
|
|
LoggingActiveCheckbox.Checked = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_emu.Cpu.CDLLoggingActive = LoggingActiveCheckbox.Checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2014-02-10 01:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|