Skip to content

Commit 45383f3

Browse files
authored
Merge branch 'master' into memory-viewer-button-bar
2 parents 03c091a + dee5017 commit 45383f3

14 files changed

Lines changed: 330 additions & 26 deletions

ZXBStudio/BuildSystem/ZXProjectBuilder.cs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public class ZXProjectBuilder
100100

101101
OutputLogWritter.WriteLine("Program built successfully.");
102102

103+
if (settings.NextMode)
104+
{
105+
if (!BuildNexFile(binary, settings, project, OutputLogWritter))
106+
{
107+
return null;
108+
}
109+
}
110+
103111
return program;
104112
}
105113
catch (Exception ex)
@@ -108,6 +116,127 @@ public class ZXProjectBuilder
108116
return null;
109117
}
110118
}
119+
120+
121+
private static bool BuildNexFile(byte[] binary, ZXBuildSettings settings, ZXProjectManager project, TextWriter outputLogWritter)
122+
{
123+
try
124+
{
125+
outputLogWritter.WriteLine("Building .nex file...");
126+
string binFile = "";
127+
string cfgFile = "";
128+
129+
// Create .bin file
130+
{
131+
binFile = Path.Combine(project.ProjectPath, Path.GetFileNameWithoutExtension(settings.MainFile) + ".bin");
132+
if (File.Exists(binFile))
133+
{
134+
File.Delete(binFile);
135+
}
136+
File.WriteAllBytes(binFile, binary);
137+
}
138+
139+
// Create nex.cfg file
140+
{
141+
outputLogWritter.WriteLine("Creating nex.cfg configuration file...");
142+
var sb = new StringBuilder();
143+
sb.AppendLine("; Minimum core version");
144+
sb.AppendLine("!COR3,0,0");
145+
// sysvars.inc
146+
{
147+
var sysVarsPath = Path.Combine(Environment.CurrentDirectory, "Resources", "sysvars.inc");
148+
var sysVarsDest = Path.Combine(project.ProjectPath, "sysvars.inc");
149+
if (!File.Exists(sysVarsDest))
150+
{
151+
File.Copy(sysVarsPath, sysVarsDest);
152+
}
153+
sb.AppendLine("!MMU./sysvars.inc,10,$1C00");
154+
}
155+
// Origin
156+
{
157+
int org = settings.Origin == null ? 32768 : settings.Origin.Value;
158+
sb.AppendLine(string.Format("!PCSP${0:X2},${1:X2}", org, org - 2));
159+
}
160+
// Main file
161+
{
162+
var bank = 5;
163+
var address = 0x2000;
164+
sb.AppendLine(string.Format(".\\{0},{1},${2:X2}",
165+
Path.Combine(Path.GetFileNameWithoutExtension(settings.MainFile) + ".bin"),
166+
bank,
167+
address));
168+
}
169+
// Save nex.cfg file
170+
{
171+
cfgFile = Path.Combine(project.ProjectPath, "nex.cfg");
172+
if (File.Exists(cfgFile))
173+
{
174+
File.Delete(cfgFile);
175+
}
176+
File.WriteAllText(cfgFile, sb.ToString());
177+
}
178+
}
179+
// Build nex file
180+
{
181+
string nextDriveFolder = "nextdrive";
182+
// Delete old .nex file
183+
string nexFile = Path.Combine(project.ProjectPath, Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex");
184+
if (File.Exists(nexFile))
185+
{
186+
File.Delete(nexFile);
187+
}
188+
// Check if nextdata folder exists
189+
string dataFolder = Path.Combine(project.ProjectPath, nextDriveFolder);
190+
if (!Directory.Exists(dataFolder))
191+
{
192+
Directory.CreateDirectory(dataFolder);
193+
}
194+
// Delete old .next file in data folder
195+
string nexDataFile = Path.Combine(project.ProjectPath, nextDriveFolder, Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex");
196+
if (File.Exists(nexDataFile))
197+
{
198+
File.Delete(nexDataFile);
199+
}
200+
201+
outputLogWritter.WriteLine("Building .nex file...");
202+
Process process = new Process();
203+
process.StartInfo.FileName = "python.exe";
204+
process.StartInfo.Arguments = string.Format("{0} nex.cfg {1}",
205+
Path.Combine(Path.GetDirectoryName(ZXOptions.Current.ZxbcPath), "tools", "nextcreator.py"),
206+
Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex");
207+
process.StartInfo.WorkingDirectory = project.ProjectPath;
208+
process.StartInfo.UseShellExecute = false;
209+
process.StartInfo.CreateNoWindow = true;
210+
process.StartInfo.RedirectStandardOutput = true;
211+
process.Start();
212+
213+
process.WaitForExit();
214+
215+
if (!File.Exists(nexFile))
216+
{
217+
outputLogWritter.WriteLine("Error building .nex file");
218+
using (StreamReader reader = process.StandardOutput)
219+
{
220+
string output = reader.ReadToEnd();
221+
outputLogWritter.WriteLine(output);
222+
}
223+
return false;
224+
}
225+
226+
// Copy .nex file to data folder
227+
File.Copy(nexFile, nexDataFile);
228+
}
229+
return true;
230+
}
231+
catch (Exception ex)
232+
{
233+
outputLogWritter.WriteLine($"Exception: {ex.Message} {ex.StackTrace}");
234+
return false;
235+
}
236+
237+
}
238+
239+
111240
public static ZXProgram? BuildDebug(TextWriter OutputLogWritter)
112241
{
113242
try
@@ -279,6 +408,12 @@ public class ZXProjectBuilder
279408

280409
OutputLogWritter.WriteLine("Program built successfully.");
281410

411+
if (settings.NextMode)
412+
{
413+
OutputLogWritter.WriteLine("Debugging in Next not supported.");
414+
return null;
415+
}
416+
282417
return program;
283418
}
284419
catch (LineOutOfRangeException ex)
@@ -292,6 +427,8 @@ public class ZXProjectBuilder
292427
return null;
293428
}
294429
}
430+
431+
295432
public static bool Export(ZXExportOptions Export, TextWriter OutputLogWritter)
296433
{
297434
try
@@ -363,6 +500,8 @@ public static bool Export(ZXExportOptions Export, TextWriter OutputLogWritter)
363500
return false;
364501
}
365502
}
503+
504+
366505
private static void Cleanup(string Folder, string? BinFile = null, string? DisassemblyFile = null)
367506
{
368507

@@ -383,6 +522,8 @@ private static void Cleanup(string Folder, string? BinFile = null, string? Disas
383522
foreach (var dir in dirs)
384523
Cleanup(dir);
385524
}
525+
526+
386527
private static IEnumerable<ZXCodeFile> ScanFolder(string folder)
387528
{
388529
List<ZXCodeFile> files = new List<ZXCodeFile>();
@@ -403,6 +544,8 @@ private static IEnumerable<ZXCodeFile> ScanFolder(string folder)
403544

404545
return files;
405546
}
547+
548+
406549
private static void OutputProcessLog(TextWriter OutputLogWritter, Process proc, out string Log)
407550
{
408551
StringBuilder sbLog = new StringBuilder();
@@ -433,6 +576,8 @@ private static void OutputProcessLog(TextWriter OutputLogWritter, Process proc,
433576

434577
Log = sbLog.ToString();
435578
}
579+
580+
436581
private static bool PreBuild(bool debug, string path, TextWriter outLog)
437582
{
438583
outLog.WriteLine("Building precompilation documents...");
@@ -449,6 +594,8 @@ private static bool PreBuild(bool debug, string path, TextWriter outLog)
449594

450595
return true;
451596
}
597+
598+
452599
private static bool PostBuild(bool debug, string path, ZXProgram CompiledProgram, TextWriter outLog)
453600
{
454601
outLog.WriteLine("Building postcompilation documents...");

ZXBStudio/Classes/ZXBuildSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class ZXBuildSettings
2424
public bool Strict { get; set; }
2525
public bool Headerless { get; set; }
2626
public bool NextMode { get; set; }
27-
public string? NextCmd { get; set; }
2827
public string GetSettings()
2928
{
3029
List<string> settings = new List<string>();
@@ -70,6 +69,12 @@ public string GetSettings()
7069
if (Strict)
7170
settings.Add("--strict");
7271

72+
if (NextMode)
73+
{
74+
settings.Add("--zxnext");
75+
settings.Add("--arch=zxnext");
76+
}
77+
7378
return string.Join(' ', settings);
7479
}
7580

ZXBStudio/Classes/ZXOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public static void SaveCurrentSettings()
4040
public bool Cls { get; set; }
4141
public bool Borderless { get; set; }
4242
public bool AntiAlias { get; set; }
43+
public string LastProjectPath { get; set; }
4344
public ZXBuildSettings? DefaultBuildSettings { get; set; }
45+
public string? NextEmulatorPath { get; set; }
4446
}
4547
}

ZXBStudio/Dialogs/ZXBuildSettingsDialog.axaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
xmlns:wnd="using:ZXBasicStudio.Classes"
66
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="520"
77
MinWidth="400" MaxWidth="400"
8-
MinHeight="520" MaxHeight="520"
8+
MinHeight="450" MaxHeight="450"
99
CanResize="False"
1010
Icon="/Assets/zxbs.ico"
1111
x:Class="ZXBasicStudio.Dialogs.ZXBuildSettingsDialog"
1212
Title="Build settings" WindowStartupLocation="CenterOwner">
13-
<Grid ColumnDefinitions="*,5*,12*,*,*,6*,2*,2*" RowDefinitions="*,*,*,*,*,*,*,*,2*">
13+
<Grid ColumnDefinitions="*,5*,12*,*,*,6*,2*,2*" RowDefinitions="*,*,*,*,*,*,*,*,1.5*">
1414
<TextBlock Classes="dialog" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">Main file:</TextBlock>
1515
<TextBox Classes="dialog" Grid.Row="0" Grid.Column="2" Name="txtFile"></TextBox>
1616
<TextBlock Classes="dialog" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">Optimization:</TextBlock>
@@ -44,8 +44,6 @@
4444
</Border>
4545
<TextBlock Classes="dialog" Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">Defines:</TextBlock>
4646
<TextBox Classes="dialog" Grid.Row="6" Grid.Column="2" Name="txtDefines"></TextBox>
47-
<TextBlock Classes="dialog" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">Next cmd:</TextBlock>
48-
<TextBox Classes="dialog" Grid.Row="7" Grid.Column="2" Name="txtNextCommand"></TextBox>
4947

5048
<TextBlock Classes="dialog" Grid.Row="0" Grid.Column="5" VerticalAlignment="Center" HorizontalAlignment="Right">Sinclair mode:</TextBlock>
5149
<CheckBox Classes="dialog" Grid.Row="0" Grid.Column="6" Name="ckSinclair"></CheckBox>

ZXBStudio/Dialogs/ZXBuildSettingsDialog.axaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void UpdateUI()
7474
txtDefines.Text = _settings.Defines == null || _settings.Defines.Length == 0 ? "" : string.Join(", ", _settings.Defines);
7575
ckStrict.IsChecked = _settings.StrictBool;
7676
ckHeaderless.IsChecked = _settings.Headerless;
77+
ckNext.IsChecked = _settings.NextMode;
7778
}
7879
else
7980
{
@@ -91,6 +92,7 @@ void UpdateUI()
9192
ckCase.IsChecked = false;
9293
ckStrict.IsChecked = false;
9394
ckHeaderless.IsChecked = false;
95+
ckNext.IsChecked = false;
9496
}
9597
}
9698

@@ -113,6 +115,7 @@ void UpdateSettings()
113115
_settings.IgnoreCase = ckCase.IsChecked ?? false;
114116
_settings.StrictBool = ckStrict.IsChecked ?? false;
115117
_settings.Headerless = ckHeaderless.IsChecked ?? false;
118+
_settings.NextMode = ckNext.IsChecked ?? false;
116119
}
117120
}
118121
}

ZXBStudio/Dialogs/ZXOptionsDialog.axaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
CanResize="False"
1111
Icon="/Assets/zxbs.ico"
1212
Title="General options" WindowStartupLocation="CenterOwner">
13-
<Grid ColumnDefinitions="*,7*,8*,2*,*" RowDefinitions="*,*,*,*,*,*,*,*,1.5*,1.5*,1.5*">
13+
<Grid ColumnDefinitions="*,7*,8*,2*,*" RowDefinitions="*,*,*,*,*,*,*,*,*,1.5*,1.5*,1.5*">
1414
<TextBlock Classes="dialog" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">ZXBC path:</TextBlock>
1515
<TextBox Classes="dialog" Grid.Row="0" Grid.Column="2" Name="txtZxbc" IsReadOnly="True"></TextBox>
1616
<Button Classes="dialog" Grid.Row="0" Grid.Column="3" VerticalAlignment="Center" Name="btnSelectZxbc">...</Button>
@@ -33,10 +33,14 @@
3333

3434
<TextBlock Classes="dialog" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center">Antialias rendering:</TextBlock>
3535
<CheckBox Classes="dialog" Name="ckAntiAlias" Grid.Column="2" Grid.Row="7"></CheckBox>
36-
37-
<Button Classes="dialog" Grid.Row="8" Grid.Column="2" Padding="6" VerticalAlignment="Center" Name="btnKeybMap">Keyboard mappings</Button>
38-
<Button Classes="dialog" Grid.Row="9" Grid.Column="2" Padding="6" VerticalAlignment="Center" Name="btnDefaultBuildConfig">Default build options</Button>
39-
<StackPanel Margin="0,0,0,10" Grid.Row="10" Grid.ColumnSpan="4" Orientation="Horizontal" HorizontalAlignment="Right">
36+
37+
<TextBlock Classes="dialog" Grid.Row="8" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">Next emulator path:</TextBlock>
38+
<TextBox Classes="dialog" Grid.Row="8" Grid.Column="2" Name="txtNextEmulator" IsReadOnly="True"></TextBox>
39+
<Button Classes="dialog" Grid.Row="8" Grid.Column="3" VerticalAlignment="Center" Name="btnSelectNextEmulator">...</Button>
40+
41+
<Button Classes="dialog" Grid.Row="9" Grid.Column="2" Padding="6" VerticalAlignment="Center" Name="btnKeybMap">Keyboard mappings</Button>
42+
<Button Classes="dialog" Grid.Row="10" Grid.Column="2" Padding="6" VerticalAlignment="Center" Name="btnDefaultBuildConfig">Default build options</Button>
43+
<StackPanel Margin="0,0,0,10" Grid.Row="11" Grid.ColumnSpan="4" Orientation="Horizontal" HorizontalAlignment="Right">
4044
<Button Classes="dialog" VerticalAlignment="Bottom" Padding="7" Name="btnCancel">Cancel</Button>
4145
<Button Classes="dialog" VerticalAlignment="Bottom" Padding="7" Name="btnAccept">Accept</Button>
4246
</StackPanel>

ZXBStudio/Dialogs/ZXOptionsDialog.axaml.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public ZXOptionsDialog()
1818
btnSelectZxbc.Click += BtnSelectZxbc_Click;
1919
btnSelectZxbasm.Click += BtnSelectZxbasm_Click;
2020
btnDefaultBuildConfig.Click += BtnDefaultBuildConfig_Click;
21-
21+
btnSelectNextEmulator.Click += BtnSelectNextEmulator_Click;
22+
2223
txtZxbasm.Text = ZXOptions.Current.ZxbasmPath;
2324
txtZxbc.Text = ZXOptions.Current.ZxbcPath;
2425
nudFontSize.Value = (decimal)ZXOptions.Current.EditorFontSize;
@@ -27,9 +28,10 @@ public ZXOptionsDialog()
2728
ckCls.IsChecked = ZXOptions.Current.Cls;
2829
ckBorderless.IsChecked = ZXOptions.Current.Borderless;
2930
ckAntiAlias.IsChecked = ZXOptions.Current.AntiAlias;
31+
txtNextEmulator.Text = ZXOptions.Current.NextEmulatorPath;
3032

3133
btnKeybMap.Click += BtnKeybMap_Click;
32-
}
34+
}
3335

3436
private void BtnKeybMap_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
3537
{
@@ -85,6 +87,28 @@ private async void BtnSelectZxbc_Click(object? sender, Avalonia.Interactivity.Ro
8587
txtZxbc.Text = Path.GetFullPath(select[0].Path.LocalPath);
8688
}
8789

90+
91+
private async void BtnSelectNextEmulator_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
92+
{
93+
var select = await StorageProvider.OpenFilePickerAsync(new Avalonia.Platform.Storage.FilePickerOpenOptions
94+
{
95+
AllowMultiple = false,
96+
Title = "Select Next emulator path...",
97+
FileTypeFilter = new[]
98+
{
99+
new FilePickerFileType("CSpect") { Patterns = new[] { "CSpect.exe" } },
100+
new FilePickerFileType("ZEsarUX") { Patterns = new[] { "zesarux.exe" } },
101+
new FilePickerFileType("All files") { Patterns = new[] { "*", "*.*" } }
102+
}
103+
});
104+
105+
if (select != null && select.Count > 0)
106+
{
107+
txtNextEmulator.Text = Path.GetFullPath(select[0].Path.LocalPath);
108+
}
109+
}
110+
111+
88112
private void BtnCancel_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
89113
{
90114
this.Close(false);
@@ -112,6 +136,7 @@ private async void BtnAccept_Click(object? sender, Avalonia.Interactivity.Routed
112136
ZXOptions.Current.Cls = ckCls.IsChecked ?? false;
113137
ZXOptions.Current.Borderless = ckBorderless.IsChecked ?? false;
114138
ZXOptions.Current.AntiAlias = ckAntiAlias.IsChecked ?? false;
139+
ZXOptions.Current.NextEmulatorPath = txtNextEmulator.Text;
115140

116141
if (bsett != null)
117142
ZXOptions.Current.DefaultBuildSettings = bsett;

ZXBStudio/DocumentEditors/ZXGraphics/SpritePatternEditor.axaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,10 @@ private void Tmr_Tick(object? sender, EventArgs e)
315315
/// </summary>
316316
public void Clear()
317317
{
318-
foreach (var p in SpriteData.Patterns[SpriteData.CurrentFrame].Data)
318+
var rd = SpriteData.Patterns[SpriteData.CurrentFrame].RawData;
319+
for (int n=0; n<rd.Length; n++)
319320
{
320-
p.ColorIndex = SecondaryColorIndex;
321+
rd[n] = SecondaryColorIndex;
321322
}
322323
Refresh(true);
323324
}
@@ -363,6 +364,7 @@ public async void Paste()
363364
if (cbPatterns.Length == 1)
364365
{
365366
SpriteData.Patterns[SpriteData.CurrentFrame].Data = cbPatterns[0].Data;
367+
SpriteData.Patterns[SpriteData.CurrentFrame].RawData = cbPatterns[0].RawData;
366368
}
367369
else
368370
{

0 commit comments

Comments
 (0)