mirror of
https://github.com/fadden/6502bench.git
synced 2024-11-29 10:50:28 +00:00
First pass at Generate & Assemble dialog
Got the basic parts laid out and working, but it depends on the progress dialogs to do actual work.
This commit is contained in:
parent
b91124999a
commit
985eba804b
@ -238,5 +238,27 @@ namespace CommonUtil {
|
|||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a char[] to a string, inserting line numbers at the start of each line.
|
||||||
|
/// Assumes lines end with '\n' (with or without a preceding '\r').
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">Character data to process.</param>
|
||||||
|
/// <returns>String with line numbers.</returns>
|
||||||
|
public static string CharArrayToLineNumberedString(char[] data) {
|
||||||
|
StringBuilder sb = new StringBuilder(data.Length + data.Length / 40); // guess
|
||||||
|
int lineStart = 0;
|
||||||
|
int lineNum = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < data.Length; i++) {
|
||||||
|
if (data[i] == '\n') {
|
||||||
|
sb.AppendFormat("{0,4:D0} ", ++lineNum);
|
||||||
|
sb.Append(data, lineStart, i - lineStart + 1);
|
||||||
|
lineStart = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
109
SourceGenWPF/AsmGen/WpfGui/GenAndAsm.xaml
Normal file
109
SourceGenWPF/AsmGen/WpfGui/GenAndAsm.xaml
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<!--
|
||||||
|
Copyright 2019 faddenSoft
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Window x:Class="SourceGenWPF.AsmGen.WpfGui.GenAndAsm"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:SourceGenWPF.AsmGen.WpfGui"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Generate and Assemble"
|
||||||
|
Width="800" Height="700" MinWidth="600" MinHeight="600" ResizeMode="CanResizeWithGrip"
|
||||||
|
ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Loaded="Window_Loaded">
|
||||||
|
<Grid Margin="8">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="2*" MinHeight="150"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="*" MinHeight="100"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Grid Grid.Row="0">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="12"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="20"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="0" Margin="0,3,8,0">Assembler:</TextBlock>
|
||||||
|
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
|
||||||
|
<ComboBox Name="assemblerComboBox" Width="150" IsReadOnly="True"
|
||||||
|
SelectionChanged="AssemblerComboBox_SelectionChanged">
|
||||||
|
<ComboBox.Items>
|
||||||
|
<ComboBoxItem>ONE</ComboBoxItem>
|
||||||
|
<ComboBoxItem>TWO</ComboBoxItem>
|
||||||
|
</ComboBox.Items>
|
||||||
|
</ComboBox>
|
||||||
|
<Button Name="assemblerSettingsButton" Width="75" Margin="8,0,0,0"
|
||||||
|
Content="Settings" Click="AssemblerSettingsButton_Click"/>
|
||||||
|
</StackPanel>
|
||||||
|
<Button Grid.Column="3" Grid.Row="0" Name="generateButton" Width="100"
|
||||||
|
HorizontalAlignment="Left" FontWeight="Bold" Content="Generate" Click="GenerateButton_Click"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Column="0" Grid.Row="2" Margin="0,3,8,0">Preview file:</TextBlock>
|
||||||
|
<StackPanel Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left">
|
||||||
|
<ComboBox Name="previewFileComboBox" Width="260" IsReadOnly="True"
|
||||||
|
SelectionChanged="PreviewFileComboBox_SelectionChanged">
|
||||||
|
<ComboBox.Items>
|
||||||
|
<ComboBoxItem>ONE</ComboBoxItem>
|
||||||
|
<ComboBoxItem>TWO</ComboBoxItem>
|
||||||
|
</ComboBox.Items>
|
||||||
|
</ComboBox>
|
||||||
|
</StackPanel>
|
||||||
|
<DockPanel Grid.Column="3" Grid.Row="2">
|
||||||
|
<TextBlock DockPanel.Dock="Left" Margin="0,1,0,0">Work directory:</TextBlock>
|
||||||
|
<TextBox DockPanel.Dock="Right" Name="workDirectoryTextBox" Margin="8,0,0,0"
|
||||||
|
Text="C:\this\that\theother"/>
|
||||||
|
</DockPanel>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<TextBox Grid.Row="1" Name="previewTextBox" IsReadOnly="True" Margin="0,4,0,0"
|
||||||
|
FontFamily="{StaticResource GeneralMonoFont}">
|
||||||
|
sample text1
|
||||||
|
</TextBox>
|
||||||
|
|
||||||
|
<GridSplitter Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||||
|
Height="4" Margin="-4,4"/>
|
||||||
|
|
||||||
|
<DockPanel Grid.Row="3">
|
||||||
|
<DockPanel DockPanel.Dock="Top" LastChildFill="False">
|
||||||
|
<Button DockPanel.Dock="Left" Name="runAssemblerButton" Width="120"
|
||||||
|
FontWeight="Bold" Content="Run Assembler" Click="RunAssemblerButton_Click"/>
|
||||||
|
<TextBlock Name="asmNotConfiguredText" DockPanel.Dock="Left" Margin="16,0,0,0"
|
||||||
|
Foreground="Red">Assembler not configured</TextBlock>
|
||||||
|
</DockPanel>
|
||||||
|
|
||||||
|
<TextBox DockPanel.Dock="Top" Name="cmdOutputTextBox" IsReadOnly="True" Margin="0,4,0,0"
|
||||||
|
FontFamily="{StaticResource GeneralMonoFont}">
|
||||||
|
sample text2
|
||||||
|
a
|
||||||
|
b
|
||||||
|
</TextBox>
|
||||||
|
</DockPanel>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="4" HorizontalAlignment="Right" Margin="0,4">
|
||||||
|
<Button Width="70" IsCancel="True">Close</Button>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
376
SourceGenWPF/AsmGen/WpfGui/GenAndAsm.xaml.cs
Normal file
376
SourceGenWPF/AsmGen/WpfGui/GenAndAsm.xaml.cs
Normal file
@ -0,0 +1,376 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 faddenSoft
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
using CommonUtil;
|
||||||
|
|
||||||
|
namespace SourceGenWPF.AsmGen.WpfGui {
|
||||||
|
/// <summary>
|
||||||
|
/// Code generation and assembler execution dialog.
|
||||||
|
/// </summary>
|
||||||
|
public partial class GenAndAsm : Window {
|
||||||
|
private const int PREVIEW_BUF_SIZE = 64 * 1024; // 64KB should be enough for preview
|
||||||
|
private static string NO_PREVIEW_FILES = "<" + Res.Strings.NO_FILES_AVAILABLE + ">";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Holds data for the preview combo box.
|
||||||
|
/// </summary>
|
||||||
|
private class ComboPath {
|
||||||
|
public string FileName { get; private set; }
|
||||||
|
public string PathName { get; private set; }
|
||||||
|
public ComboPath(string pathName) {
|
||||||
|
PathName = pathName;
|
||||||
|
if (string.IsNullOrEmpty(pathName)) {
|
||||||
|
FileName = NO_PREVIEW_FILES;
|
||||||
|
} else {
|
||||||
|
FileName = Path.GetFileName(pathName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override string ToString() {
|
||||||
|
return FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Project with data.
|
||||||
|
/// </summary>
|
||||||
|
private DisasmProject mProject;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Directory where generated files and assembler output will go.
|
||||||
|
/// </summary>
|
||||||
|
private string mWorkDirectory;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base file name. For example, if this is "GenFile", we might generate
|
||||||
|
/// "GenFile_Cc65.S".
|
||||||
|
/// </summary>
|
||||||
|
private string mBaseFileName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Currently-selected assembler ID.
|
||||||
|
/// </summary>
|
||||||
|
private AssemblerInfo.Id mSelectedAssemblerId;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Results from last source generation.
|
||||||
|
/// </summary>
|
||||||
|
private List<string> mGenerationResults;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Holds an item for the pick-your-assembler combox box.
|
||||||
|
/// </summary>
|
||||||
|
private class AsmComboItem {
|
||||||
|
public AssemblerInfo.Id AssemblerId { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public AssemblerVersion AsmVersion { get; private set; }
|
||||||
|
|
||||||
|
public AsmComboItem(AssemblerInfo info, AssemblerVersion version) {
|
||||||
|
AssemblerId = info.AssemblerId;
|
||||||
|
Name = info.Name;
|
||||||
|
AsmVersion = version;
|
||||||
|
}
|
||||||
|
// This determines what the combo box shows.
|
||||||
|
public override string ToString() {
|
||||||
|
if (AsmVersion == null) {
|
||||||
|
return Name + " " + Res.Strings.ASM_LATEST_VERSION;
|
||||||
|
} else {
|
||||||
|
return Name + " v" + AsmVersion.VersionStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="project">Project reference.</param>
|
||||||
|
/// <param name="projectPathName">Full path to the project file.</param>
|
||||||
|
public GenAndAsm(Window owner, DisasmProject project, string projectPathName) {
|
||||||
|
InitializeComponent();
|
||||||
|
Owner = owner;
|
||||||
|
|
||||||
|
mProject = project;
|
||||||
|
mWorkDirectory = Path.GetDirectoryName(projectPathName);
|
||||||
|
mBaseFileName = Path.GetFileNameWithoutExtension(projectPathName);
|
||||||
|
|
||||||
|
workDirectoryTextBox.Text = mWorkDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||||
|
// Try to select the previously-used asm format.
|
||||||
|
string defaultAsm =
|
||||||
|
AppSettings.Global.GetString(AppSettings.SRCGEN_DEFAULT_ASM, string.Empty);
|
||||||
|
PopulateAssemblerComboBox(defaultAsm);
|
||||||
|
|
||||||
|
ResetElements();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Populates the assembler combo box. Attempts to match the defaultAsm arg with
|
||||||
|
/// the entries to configure the initial value.
|
||||||
|
/// </summary>
|
||||||
|
private void PopulateAssemblerComboBox(string defaultAsm) {
|
||||||
|
//assemblerComboBox.DisplayMember = "Name"; // show this property
|
||||||
|
|
||||||
|
assemblerComboBox.Items.Clear();
|
||||||
|
IEnumerator<AssemblerInfo> iter = AssemblerInfo.GetInfoEnumerator();
|
||||||
|
bool foundMatch = false;
|
||||||
|
while (iter.MoveNext()) {
|
||||||
|
AssemblerInfo info = iter.Current;
|
||||||
|
AssemblerVersion version = AssemblerVersionCache.GetVersion(info.AssemblerId);
|
||||||
|
AsmComboItem item = new AsmComboItem(info, version);
|
||||||
|
assemblerComboBox.Items.Add(item);
|
||||||
|
if (item.AssemblerId.ToString() == defaultAsm) {
|
||||||
|
Debug.WriteLine("matched current " + defaultAsm);
|
||||||
|
assemblerComboBox.SelectedItem = item;
|
||||||
|
foundMatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundMatch) {
|
||||||
|
// Need to do this or box will show empty.
|
||||||
|
assemblerComboBox.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the selected assembler as the combo box selection changes. This is
|
||||||
|
/// expected to be called during the window load event, to initialize the field.
|
||||||
|
/// </summary>
|
||||||
|
private void AssemblerComboBox_SelectionChanged(object sender,
|
||||||
|
SelectionChangedEventArgs e) {
|
||||||
|
AsmComboItem sel = (AsmComboItem)assemblerComboBox.SelectedItem;
|
||||||
|
if (sel == null) {
|
||||||
|
// this happens on Items.Clear()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mSelectedAssemblerId != sel.AssemblerId) {
|
||||||
|
// Selection changed, discard window contents.
|
||||||
|
mSelectedAssemblerId = sel.AssemblerId;
|
||||||
|
AppSettings.Global.SetString(AppSettings.SRCGEN_DEFAULT_ASM,
|
||||||
|
mSelectedAssemblerId.ToString());
|
||||||
|
ResetElements();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the appropriate preview file when the combo box selection changes.
|
||||||
|
/// </summary>
|
||||||
|
private void PreviewFileComboBox_SelectionChanged(object sender,
|
||||||
|
SelectionChangedEventArgs e) {
|
||||||
|
ComboPath cpath = (ComboPath)previewFileComboBox.SelectedItem;
|
||||||
|
if (cpath == null || string.IsNullOrEmpty(cpath.PathName)) {
|
||||||
|
// nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadPreviewFile(cpath.PathName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resets all of the active elements to the initial state, before any source code
|
||||||
|
/// was generated.
|
||||||
|
/// </summary>
|
||||||
|
private void ResetElements() {
|
||||||
|
mGenerationResults = null;
|
||||||
|
previewFileComboBox.Items.Clear();
|
||||||
|
previewFileComboBox.Items.Add(new ComboPath(null));
|
||||||
|
previewFileComboBox.SelectedIndex = 0;
|
||||||
|
|
||||||
|
previewTextBox.Text = string.Empty;
|
||||||
|
|
||||||
|
cmdOutputTextBox.Text = string.Empty;
|
||||||
|
|
||||||
|
UpdateAssemblerControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the controls in the lower (assembler) half of the dialog.
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateAssemblerControls() {
|
||||||
|
bool asmConf = IsAssemblerConfigured();
|
||||||
|
//Debug.WriteLine("ID=" + mSelectedAssemblerId + " asmConf=" + asmConf);
|
||||||
|
asmNotConfiguredText.Visibility = asmConf ? Visibility.Hidden : Visibility.Visible;
|
||||||
|
if (mGenerationResults == null || !asmConf) {
|
||||||
|
runAssemblerButton.IsEnabled = false;
|
||||||
|
} else {
|
||||||
|
runAssemblerButton.IsEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the selected cross-assembler executable has been configured.
|
||||||
|
/// </summary>
|
||||||
|
private bool IsAssemblerConfigured() {
|
||||||
|
AssemblerConfig config =
|
||||||
|
AssemblerConfig.GetConfig(AppSettings.Global, mSelectedAssemblerId);
|
||||||
|
return config != null && !string.IsNullOrEmpty(config.ExecutablePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssemblerSettingsButton_Click(object sender, RoutedEventArgs e) {
|
||||||
|
// Pop open the app settings dialog, with the appropriate tab selected.
|
||||||
|
#if false
|
||||||
|
mMainCtrl.ShowAppSettings(AppForms.EditAppSettings.Tab.AsmConfig,
|
||||||
|
mSelectedAssemblerId);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Update the controls based on whether or not the assembler is now available.
|
||||||
|
UpdateAssemblerControls();
|
||||||
|
AsmComboItem item = (AsmComboItem)assemblerComboBox.SelectedItem;
|
||||||
|
Debug.Assert(item != null);
|
||||||
|
PopulateAssemblerComboBox(item.AssemblerId.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateButton_Click(object sender, RoutedEventArgs e) {
|
||||||
|
#if false
|
||||||
|
IGenerator gen = AssemblerInfo.GetGenerator(mSelectedAssemblerId);
|
||||||
|
if (gen == null) {
|
||||||
|
Debug.WriteLine("Unable to get generator for " + mSelectedAssemblerId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gen.Configure(mProject, mWorkDirectory, mBaseFileName,
|
||||||
|
AssemblerVersionCache.GetVersion(mSelectedAssemblerId), AppSettings.Global);
|
||||||
|
|
||||||
|
GeneratorProgress dlg = new GeneratorProgress(gen);
|
||||||
|
dlg.ShowDialog();
|
||||||
|
Debug.WriteLine("Dialog returned: " + dlg.DialogResult);
|
||||||
|
|
||||||
|
List<string> pathNames = dlg.Results;
|
||||||
|
dlg.Dispose();
|
||||||
|
|
||||||
|
if (pathNames == null) {
|
||||||
|
// errors already reported
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResetElements();
|
||||||
|
mGenerationResults = pathNames;
|
||||||
|
previewFileComboBox.Items.Clear();
|
||||||
|
foreach (string str in pathNames) {
|
||||||
|
previewFileComboBox.Items.Add(new ComboPath(str));
|
||||||
|
}
|
||||||
|
previewFileComboBox.SelectedIndex = 0; // should trigger update
|
||||||
|
|
||||||
|
UpdateAssemblerControls();
|
||||||
|
#else
|
||||||
|
Debug.WriteLine("GENERATE");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadPreviewFile(string pathName) {
|
||||||
|
Debug.WriteLine("LOAD " + pathName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
using (StreamReader sr = new StreamReader(pathName, Encoding.UTF8)) {
|
||||||
|
char[] bigbuf = new char[PREVIEW_BUF_SIZE];
|
||||||
|
int actual = sr.Read(bigbuf, 0, bigbuf.Length);
|
||||||
|
string str = TextUtil.CharArrayToLineNumberedString(bigbuf);
|
||||||
|
if (actual < PREVIEW_BUF_SIZE) {
|
||||||
|
previewTextBox.Text = str;
|
||||||
|
} else {
|
||||||
|
previewTextBox.Text = str + "\r\n" +
|
||||||
|
Res.Strings.ERR_TOO_LARGE_FOR_PREVIEW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
previewTextBox.Text = ex.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RunAssemblerButton_Click(object sender, RoutedEventArgs e) {
|
||||||
|
#if false
|
||||||
|
IAssembler asm = AssemblerInfo.GetAssembler(mSelectedAssemblerId);
|
||||||
|
if (asm == null) {
|
||||||
|
Debug.WriteLine("Unable to get assembler for " + mSelectedAssemblerId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
asm.Configure(mGenerationResults, mWorkDirectory);
|
||||||
|
AssemblerProgress dlg = new AssemblerProgress(asm);
|
||||||
|
dlg.ShowDialog();
|
||||||
|
Debug.WriteLine("Dialog returned: " + dlg.DialogResult);
|
||||||
|
if (dlg.DialogResult != DialogResult.OK) {
|
||||||
|
// Cancelled, or failed to even run the assembler.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssemblerResults results = dlg.Results;
|
||||||
|
if (results == null) {
|
||||||
|
Debug.WriteLine("Dialog returned OK, but no assembler results found");
|
||||||
|
Debug.Assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb =
|
||||||
|
new StringBuilder(results.Stdout.Length + results.Stderr.Length + 200);
|
||||||
|
sb.Append(results.CommandLine);
|
||||||
|
sb.Append("\r\n");
|
||||||
|
sb.AppendFormat("ExitCode={0} - ", results.ExitCode);
|
||||||
|
if (results.ExitCode == 0) {
|
||||||
|
FileInfo fi = new FileInfo(results.OutputPathName);
|
||||||
|
if (!fi.Exists) {
|
||||||
|
MessageBox.Show(this, Properties.Resources.ASM_OUTPUT_NOT_FOUND,
|
||||||
|
Properties.Resources.ASM_MISMATCH_CAPTION,
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
sb.Append(Properties.Resources.ASM_MATCH_FAILURE);
|
||||||
|
} else if (!CommonUtil.FileUtil.CompareBinaryFile(mProject.FileData,
|
||||||
|
results.OutputPathName, out int offset, out byte fileVal)) {
|
||||||
|
if (fi.Length != mProject.FileData.Length &&
|
||||||
|
offset == fi.Length || offset == mProject.FileData.Length) {
|
||||||
|
// The files matched up to the point where one ended.
|
||||||
|
string msg = string.Format(Properties.Resources.ASM_MISMATCH_LENGTH_FMT,
|
||||||
|
fi.Length, mProject.FileData.Length);
|
||||||
|
MessageBox.Show(this, msg, Properties.Resources.ASM_MISMATCH_CAPTION,
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
sb.Append(msg);
|
||||||
|
} else {
|
||||||
|
string msg = string.Format(Properties.Resources.ASM_MISMATCH_DATA_FMT,
|
||||||
|
offset, fileVal, mProject.FileData[offset]);
|
||||||
|
MessageBox.Show(this, msg, Properties.Resources.ASM_MISMATCH_CAPTION,
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
sb.Append(msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sb.Append(Properties.Resources.ASM_MATCH_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.Append("\r\n\r\n");
|
||||||
|
|
||||||
|
if (results.Stdout != null && results.Stdout.Length > 2) {
|
||||||
|
sb.Append("----- stdout -----\r\n");
|
||||||
|
sb.Append(results.Stdout);
|
||||||
|
sb.Append("\r\n");
|
||||||
|
}
|
||||||
|
if (results.Stderr != null && results.Stderr.Length > 2) {
|
||||||
|
sb.Append("----- stderr -----\r\n");
|
||||||
|
sb.Append(results.Stderr);
|
||||||
|
sb.Append("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdOutputTextBox.Text = sb.ToString();
|
||||||
|
cmdOutputTextBox.BackColor = SystemColors.Window;
|
||||||
|
#else
|
||||||
|
Debug.WriteLine("ASSEMBLE");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1130,6 +1130,24 @@ namespace SourceGenWPF {
|
|||||||
return mProject != null;
|
return mProject != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AssembleProject() {
|
||||||
|
if (string.IsNullOrEmpty(mProjectPathName)) {
|
||||||
|
// We need a project pathname so we know where to write the assembler
|
||||||
|
// source files, and what to call the output files. We could just pop up the
|
||||||
|
// Save As dialog, but that seems confusing unless we do a custom dialog with
|
||||||
|
// an explanation, or have some annoying click-through.
|
||||||
|
//
|
||||||
|
// This only appears for never-saved projects, not projects with unsaved data.
|
||||||
|
MessageBox.Show(Res.Strings.SAVE_BEFORE_ASM, Res.Strings.SAVE_BEFORE_ASM_CAPTION,
|
||||||
|
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsmGen.WpfGui.GenAndAsm dlg =
|
||||||
|
new AsmGen.WpfGui.GenAndAsm(mMainWin, mProject, mProjectPathName);
|
||||||
|
dlg.ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
public void HandleCodeListDoubleClick(int row, int col) {
|
public void HandleCodeListDoubleClick(int row, int col) {
|
||||||
Debug.WriteLine("DCLICK: row=" + row + " col=" + col);
|
Debug.WriteLine("DCLICK: row=" + row + " col=" + col);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ limitations under the License.
|
|||||||
xmlns:system="clr-namespace:System;assembly=mscorlib"
|
xmlns:system="clr-namespace:System;assembly=mscorlib"
|
||||||
xmlns:local="clr-namespace:SourceGenWPF.Res">
|
xmlns:local="clr-namespace:SourceGenWPF.Res">
|
||||||
|
|
||||||
|
<system:String x:Key="str_AsmLatestVersion">[latest version]</system:String>
|
||||||
<system:String x:Key="str_DefaultValue">Default</system:String>
|
<system:String x:Key="str_DefaultValue">Default</system:String>
|
||||||
<system:String x:Key="str_ErrBadFd">Bad format descriptor at +{0:x6}.</system:String>
|
<system:String x:Key="str_ErrBadFd">Bad format descriptor at +{0:x6}.</system:String>
|
||||||
<system:String x:Key="str_ErrBadFdFormat">Bad format descriptor type</system:String>
|
<system:String x:Key="str_ErrBadFdFormat">Bad format descriptor type</system:String>
|
||||||
@ -41,6 +42,7 @@ limitations under the License.
|
|||||||
<system:String x:Key="str_ErrProjectFileCorrupt">Project file may be corrupt</system:String>
|
<system:String x:Key="str_ErrProjectFileCorrupt">Project file may be corrupt</system:String>
|
||||||
<system:String x:Key="str_ErrProjectLoadFail">Unable to load project file</system:String>
|
<system:String x:Key="str_ErrProjectLoadFail">Unable to load project file</system:String>
|
||||||
<system:String x:Key="str_ErrProjectSaveFail">Unable to save project file</system:String>
|
<system:String x:Key="str_ErrProjectSaveFail">Unable to save project file</system:String>
|
||||||
|
<system:String x:Key="str_ErrTooLargeForPreview">[File was too large for preview window]</system:String>
|
||||||
<system:String x:Key="str_FileFilterAll">All files (*.*)|*.*</system:String>
|
<system:String x:Key="str_FileFilterAll">All files (*.*)|*.*</system:String>
|
||||||
<system:String x:Key="str_FileFilterCs">C# Source Files(*.cs)|*.cs</system:String>
|
<system:String x:Key="str_FileFilterCs">C# Source Files(*.cs)|*.cs</system:String>
|
||||||
<system:String x:Key="str_FileFilterDis65">SourceGen projects(*.dis65)|*.dis65</system:String>
|
<system:String x:Key="str_FileFilterDis65">SourceGen projects(*.dis65)|*.dis65</system:String>
|
||||||
@ -54,6 +56,7 @@ limitations under the License.
|
|||||||
<system:String x:Key="str_InitialExtensionScripts">Extension scripts:</system:String>
|
<system:String x:Key="str_InitialExtensionScripts">Extension scripts:</system:String>
|
||||||
<system:String x:Key="str_InitialParameters">Default settings:</system:String>
|
<system:String x:Key="str_InitialParameters">Default settings:</system:String>
|
||||||
<system:String x:Key="str_InitialSymbolFiles">Symbol files:</system:String>
|
<system:String x:Key="str_InitialSymbolFiles">Symbol files:</system:String>
|
||||||
|
<system:String x:Key="str_NoFilesAvailable">no files available</system:String>
|
||||||
<system:String x:Key="str_OpenDataDoesntExist">The file doesn't exist.</system:String>
|
<system:String x:Key="str_OpenDataDoesntExist">The file doesn't exist.</system:String>
|
||||||
<system:String x:Key="str_OpenDataEmpty">File is empty</system:String>
|
<system:String x:Key="str_OpenDataEmpty">File is empty</system:String>
|
||||||
<system:String x:Key="str_OpenDataFailCaption">Unable to load data file</system:String>
|
<system:String x:Key="str_OpenDataFailCaption">Unable to load data file</system:String>
|
||||||
@ -79,5 +82,7 @@ limitations under the License.
|
|||||||
<!--<system:String x:Key="str_RecentProjectLinkFmt">#{0}: {1}</system:String>-->
|
<!--<system:String x:Key="str_RecentProjectLinkFmt">#{0}: {1}</system:String>-->
|
||||||
<system:String x:Key="str_RuntimeDirNotFound">The RuntimeData directory was not found. It should be in the same directory as the executable.</system:String>
|
<system:String x:Key="str_RuntimeDirNotFound">The RuntimeData directory was not found. It should be in the same directory as the executable.</system:String>
|
||||||
<system:String x:Key="str_RuntimeDirNotFoundCaption">RuntimeData Not Found</system:String>
|
<system:String x:Key="str_RuntimeDirNotFoundCaption">RuntimeData Not Found</system:String>
|
||||||
|
<system:String x:Key="str_SaveBeforeAsm">Please save your project before assembling. The generated source code will be placed in the same directory as the project file.</system:String>
|
||||||
|
<system:String x:Key="str_SaveBeforeAsmCaption">Save Project First</system:String>
|
||||||
<system:String x:Key="str_SetupSystemSummaryFmt">{1} CPU @ {2} MHz</system:String>
|
<system:String x:Key="str_SetupSystemSummaryFmt">{1} CPU @ {2} MHz</system:String>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
@ -18,6 +18,8 @@ using System.Windows;
|
|||||||
|
|
||||||
namespace SourceGenWPF.Res {
|
namespace SourceGenWPF.Res {
|
||||||
public static class Strings {
|
public static class Strings {
|
||||||
|
public static string ASM_LATEST_VERSION =
|
||||||
|
(string)Application.Current.FindResource("str_AsmLatestVersion");
|
||||||
public static string DEFAULT_VALUE =
|
public static string DEFAULT_VALUE =
|
||||||
(string)Application.Current.FindResource("str_DefaultValue");
|
(string)Application.Current.FindResource("str_DefaultValue");
|
||||||
public static string ERR_BAD_FD =
|
public static string ERR_BAD_FD =
|
||||||
@ -62,6 +64,8 @@ namespace SourceGenWPF.Res {
|
|||||||
(string)Application.Current.FindResource("str_ErrProjectLoadFail");
|
(string)Application.Current.FindResource("str_ErrProjectLoadFail");
|
||||||
public static string ERR_PROJECT_SAVE_FAIL =
|
public static string ERR_PROJECT_SAVE_FAIL =
|
||||||
(string)Application.Current.FindResource("str_ErrProjectSaveFail");
|
(string)Application.Current.FindResource("str_ErrProjectSaveFail");
|
||||||
|
public static string ERR_TOO_LARGE_FOR_PREVIEW =
|
||||||
|
(string)Application.Current.FindResource("str_ErrTooLargeForPreview");
|
||||||
public static string FILE_FILTER_ALL =
|
public static string FILE_FILTER_ALL =
|
||||||
(string)Application.Current.FindResource("str_FileFilterAll");
|
(string)Application.Current.FindResource("str_FileFilterAll");
|
||||||
public static string FILE_FILTER_CS =
|
public static string FILE_FILTER_CS =
|
||||||
@ -88,6 +92,8 @@ namespace SourceGenWPF.Res {
|
|||||||
(string)Application.Current.FindResource("str_InitialParameters");
|
(string)Application.Current.FindResource("str_InitialParameters");
|
||||||
public static string INITIAL_SYMBOL_FILES =
|
public static string INITIAL_SYMBOL_FILES =
|
||||||
(string)Application.Current.FindResource("str_InitialSymbolFiles");
|
(string)Application.Current.FindResource("str_InitialSymbolFiles");
|
||||||
|
public static string NO_FILES_AVAILABLE =
|
||||||
|
(string)Application.Current.FindResource("str_NoFilesAvailable");
|
||||||
public static string OPEN_DATA_DOESNT_EXIST =
|
public static string OPEN_DATA_DOESNT_EXIST =
|
||||||
(string)Application.Current.FindResource("str_OpenDataDoesntExist");
|
(string)Application.Current.FindResource("str_OpenDataDoesntExist");
|
||||||
public static string OPEN_DATA_EMPTY =
|
public static string OPEN_DATA_EMPTY =
|
||||||
@ -138,6 +144,10 @@ namespace SourceGenWPF.Res {
|
|||||||
(string)Application.Current.FindResource("str_RuntimeDirNotFound");
|
(string)Application.Current.FindResource("str_RuntimeDirNotFound");
|
||||||
public static string RUNTIME_DIR_NOT_FOUND_CAPTION =
|
public static string RUNTIME_DIR_NOT_FOUND_CAPTION =
|
||||||
(string)Application.Current.FindResource("str_RuntimeDirNotFoundCaption");
|
(string)Application.Current.FindResource("str_RuntimeDirNotFoundCaption");
|
||||||
|
public static string SAVE_BEFORE_ASM =
|
||||||
|
(string)Application.Current.FindResource("str_SaveBeforeAsm");
|
||||||
|
public static string SAVE_BEFORE_ASM_CAPTION =
|
||||||
|
(string)Application.Current.FindResource("str_SaveBeforeAsmCaption");
|
||||||
public static string SETUP_SYSTEM_SUMMARY_FMT =
|
public static string SETUP_SYSTEM_SUMMARY_FMT =
|
||||||
(string)Application.Current.FindResource("str_SetupSystemSummaryFmt");
|
(string)Application.Current.FindResource("str_SetupSystemSummaryFmt");
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,9 @@
|
|||||||
<Compile Include="AsmGen\IGenerator.cs" />
|
<Compile Include="AsmGen\IGenerator.cs" />
|
||||||
<Compile Include="AsmGen\LabelLocalizer.cs" />
|
<Compile Include="AsmGen\LabelLocalizer.cs" />
|
||||||
<Compile Include="AsmGen\StringGather.cs" />
|
<Compile Include="AsmGen\StringGather.cs" />
|
||||||
|
<Compile Include="AsmGen\WpfGui\GenAndAsm.xaml.cs">
|
||||||
|
<DependentUpon>GenAndAsm.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="DisplayList.cs" />
|
<Compile Include="DisplayList.cs" />
|
||||||
<Compile Include="MainController.cs" />
|
<Compile Include="MainController.cs" />
|
||||||
<Compile Include="WpfGui\DataFileLoadIssue.xaml.cs">
|
<Compile Include="WpfGui\DataFileLoadIssue.xaml.cs">
|
||||||
@ -158,6 +161,10 @@
|
|||||||
<Resource Include="Res\Logo.png" />
|
<Resource Include="Res\Logo.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Page Include="AsmGen\WpfGui\GenAndAsm.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="WpfGui\CodeListItemStyle.xaml">
|
<Page Include="WpfGui\CodeListItemStyle.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
@ -718,8 +718,7 @@ namespace SourceGenWPF.WpfGui {
|
|||||||
#region Command handlers
|
#region Command handlers
|
||||||
|
|
||||||
private void AssembleCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
private void AssembleCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||||
// test
|
mMainCtrl.AssembleProject();
|
||||||
Debug.WriteLine("assembling");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CloseCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
private void CloseCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user