Skip to content

Commit 565739b

Browse files
committed
RAM disk system ready for testing
1 parent 0bb8179 commit 565739b

13 files changed

Lines changed: 152 additions & 16 deletions

File tree

ZXBStudio/DocumentEditors/NextDows/log/ExportManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ namespace ZXBasicStudio.DocumentEditors.NextDows.log
2020
/// </summary>
2121
public class ExportManager : IZXDocumentBuilder
2222
{
23+
24+
public Guid Id => Guid.Parse("2372bad1-0176-4881-8c2e-3b8c506cbaaf");
25+
26+
public Guid[]? DependsOn => null;
27+
2328
private FileTypes fileType = FileTypes.Undefined;
2429

2530
public bool Initialize(FileTypes fileType)

ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace ZXBasicStudio.DocumentEditors.ZXGraphics.log
2323
/// </summary>
2424
public class ExportManager : IZXDocumentBuilder
2525
{
26+
public Guid Id => Guid.Parse("4596ac56-9cd4-4553-b191-acdaa5ee3898");
27+
28+
public Guid[]? DependsOn => null;
29+
2630
private FileTypes fileType = FileTypes.Undefined;
2731

2832
public bool Initialize(FileTypes fileType)

ZXBStudio/DocumentEditors/ZXRamDisk/Classes/ZXRamDiskFile.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ namespace ZXBasicStudio.DocumentEditors.ZXRamDisk.Classes
1212
{
1313
public class ZXRamDiskFile
1414
{
15-
public bool EnableIndirect { get; set; }
16-
public int IndirectBufferSize { get; set; }
17-
public bool RelocateStack { get; set; }
15+
public bool EnableIndirect { get; set; } = false;
16+
public int IndirectBufferSize { get; set; } = 64;
17+
public bool RelocateStack { get; set; } = false;
18+
public bool PreserveBin { get; set; } = false;
1819
public ZXRamDiskLogicBank[] Banks { get; set; } = new ZXRamDiskLogicBank[]
1920
{
2021
new ZXRamDiskLogicBank{ Bank = ZXMemoryBank.Bank4 },

ZXBStudio/DocumentEditors/ZXRamDisk/Controls/ZXRamDiskEditor.axaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
x:Class="ZXBasicStudio.DocumentEditors.ZXRamDisk.Controls.ZXRamDiskEditor">
77
<Grid RowDefinitions="90,*,40">
88
<Border Margin="5,14,5,5" BorderBrush="White" BorderThickness="1" CornerRadius="5">
9-
<Grid RowDefinitions="5,*" ColumnDefinitions="140,20,148,160,148,20">
9+
<Grid RowDefinitions="5,*" ColumnDefinitions="140,20,130,80,100,20,120,20">
1010
<TextBlock Grid.Row="1" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Enable indirect load:</TextBlock>
1111
<CheckBox Grid.Row="1" Grid.Column="1" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right" Name="ckIndirect"></CheckBox>
1212

@@ -16,8 +16,9 @@
1616
</Border>
1717
<TextBlock Grid.Row="1" Grid.Column="4" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Relocate stack:</TextBlock>
1818
<CheckBox Grid.Row="1" Grid.Column="5" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right" Name="ckRelocate"></CheckBox>
19-
20-
19+
20+
<TextBlock Grid.Row="1" Grid.Column="6" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Preseve binaries:</TextBlock>
21+
<CheckBox Grid.Row="1" Grid.Column="7" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right" Name="ckPreserve"></CheckBox>
2122
</Grid>
2223
</Border>
2324
<Border Grid.Row="1" Margin="5,14,5,5" BorderBrush="White" BorderThickness="1" CornerRadius="5">

ZXBStudio/DocumentEditors/ZXRamDisk/Controls/ZXRamDiskEditor.axaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public ZXRamDiskEditor(string DocumentPath)
7777
ckIndirect.IsCheckedChanged += DocumentChanged;
7878
ckRelocate.IsCheckedChanged += DocumentChanged;
7979
nudIndSize.ValueChanged += DocumentChanged;
80+
ckPreserve.IsCheckedChanged += DocumentChanged;
81+
8082
cbBank.SelectionChanged += ChangeSelectedBank;
8183

8284
btnSelectFile.Click += BtnSelectFile_Click;
@@ -219,6 +221,7 @@ bool UpdateFileName(string NewPath)
219221
ckIndirect.IsChecked = fileContent.EnableIndirect;
220222
ckRelocate.IsChecked = fileContent.RelocateStack;
221223
nudIndSize.Value = fileContent.IndirectBufferSize;
224+
ckPreserve.IsChecked = fileContent.PreserveBin;
222225

223226
for (int buc = 0; buc < 5; buc++)
224227
{
@@ -260,6 +263,7 @@ public override bool SaveDocument(TextWriter OutputLog)
260263
fileContent.IndirectBufferSize = (int)(nudIndSize.Value ?? 0);
261264
fileContent.EnableIndirect = ckIndirect.IsChecked ?? false;
262265
fileContent.RelocateStack = ckRelocate.IsChecked ?? false;
266+
fileContent.PreserveBin = ckPreserve.IsChecked ?? false;
263267

264268
string content = JsonConvert.SerializeObject(fileContent, Formatting.Indented);
265269
try

ZXBStudio/DocumentEditors/ZXTapeBuilder/Classes/ZXTapeBuilderFile.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ public class ZXTapeBuilderFile
2121
public string? ScreenName { get; set; }
2222
public string? ScreenFile { get; set; }
2323
public ZXTapeBuilderDataBlock[]? DataBlocks { get; set; }
24+
public bool IncludeRAMDisk { get; set; }
25+
public ZXRAMDiskOrder RAMDiskOrder { get; set; }
26+
}
2427

28+
public enum ZXRAMDiskOrder
29+
{
30+
Before,
31+
After
2532
}
2633

2734
public class ZXTapeBuilderPoke

ZXBStudio/DocumentEditors/ZXTapeBuilder/Controls/ZXTapeBuilderEditor.axaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<UserControl.Resources>
1010
<local:BoolToColorConverter x:Key="BoolToColorConverter" />
1111
</UserControl.Resources>
12-
<Grid RowDefinitions="160,120,*,40">
12+
<Grid RowDefinitions="160,120,*,60,40">
1313
<Border Margin="5,14,5,5" BorderBrush="White" BorderThickness="1" CornerRadius="5">
1414
<Grid RowDefinitions="5,*,*,*" ColumnDefinitions="96,*">
1515
<TextBlock Grid.Row="1" Classes="dialog" VerticalAlignment="Center" HorizontalAlignment="Right">Program name:</TextBlock>
@@ -78,8 +78,8 @@
7878
<Grid RowDefinitions="5,24,*" ColumnDefinitions="320,*">
7979
<TextBlock Grid.Row="1" Classes="dialog" HorizontalAlignment="Center" VerticalAlignment="Center">Add block</TextBlock>
8080
<TextBlock Grid.Row="1" Grid.Column="1" Classes="dialog" HorizontalAlignment="Center" VerticalAlignment="Center">Block list</TextBlock>
81-
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto" Margin="10">
82-
<Grid ColumnDefinitions="56,*,32" RowDefinitions="Auto,Auto,Auto,Auto,16,*">
81+
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Auto" Margin="10,5,10,10">
82+
<Grid ColumnDefinitions="56,*,32" RowDefinitions="Auto,Auto,Auto,Auto,*">
8383
<TextBlock Classes="dialog" HorizontalAlignment="Right" VerticalAlignment="Center">File:</TextBlock>
8484
<TextBox Grid.Column="1" Classes="dialog" HorizontalAlignment="Stretch" MaxWidth="Infinity" Margin="5,5,0,5" Name="txtBlockFile"></TextBox>
8585
<Button Grid.Column="2" Classes="dialog" Margin="10,5,10,5" Width="32" Height="32" Name="btnSelectBlock">...</Button>
@@ -91,7 +91,7 @@
9191
</Border>
9292
<TextBlock Grid.Row="3" Classes="dialog" HorizontalAlignment="Right" VerticalAlignment="Center">Basic load:</TextBlock>
9393
<CheckBox Classes="dialog" Grid.Row="3" Grid.Column="1" Margin="10" Name="ckBasicLoad"></CheckBox>
94-
<Button Grid.Row="5" Grid.ColumnSpan="3" Classes="dialog" Margin="10,5,10,5" Height="32" Name="btnAddBlock" VerticalAlignment="Bottom">Add block</Button>
94+
<Button Grid.Row="4" Grid.ColumnSpan="3" Classes="dialog" Margin="10,5,10,5" Height="32" Name="btnAddBlock" VerticalAlignment="Bottom">Add block</Button>
9595
</Grid>
9696
</ScrollViewer>
9797
<Grid Grid.Row="2" Grid.Column="1" ColumnDefinitions="*,*,*,48" RowDefinitions="24,28,*,48">
@@ -128,7 +128,19 @@
128128
</Grid>
129129
</Border>
130130
<TextBlock Grid.Row="2" Margin="15,0,0,0" Padding="5" Background="#202020" HorizontalAlignment="Left" VerticalAlignment="Top">Data blocks</TextBlock>
131-
<Grid ColumnDefinitions="*,*" Grid.Row="3">
131+
<Border Grid.Row="3" Margin="5,14,5,5" BorderBrush="White" BorderThickness="1" CornerRadius="5">
132+
<Grid ColumnDefinitions="140,32,100,150,*">
133+
<TextBlock VerticalAlignment="Center" Margin="15,0,0,0" HorizontalAlignment="Right">Include RAM disk blocks:</TextBlock>
134+
<CheckBox Name="ckRAMDisk" Grid.Column="1" VerticalAlignment="Center" Margin="5" HorizontalAlignment="Left"></CheckBox>
135+
<TextBlock Grid.Column="2" VerticalAlignment="Center" Margin="15,0,0,0" HorizontalAlignment="Right">Inclusion order:</TextBlock>
136+
<ComboBox Grid.Column="3" Classes="dialog" SelectedIndex="0" Margin="5,0,0,0" Name="cbRAMDiskOrder">
137+
<ComboBoxItem>Before data blocks</ComboBoxItem>
138+
<ComboBoxItem>After data blocks</ComboBoxItem>
139+
</ComboBox>
140+
</Grid>
141+
</Border>
142+
<TextBlock Grid.Row="3" Margin="15,0,0,0" Padding="5" Background="#202020" HorizontalAlignment="Left" VerticalAlignment="Top">RAM disk</TextBlock>
143+
<Grid ColumnDefinitions="*,*" Grid.Row="4">
132144
<Button Classes="dialog" Name="btnSave">Save changes</Button>
133145
<Button Classes="dialog" Grid.Column="1" Name="btnDiscard">Discard changes</Button>
134146
</Grid>

ZXBStudio/DocumentEditors/ZXTapeBuilder/Controls/ZXTapeBuilderEditor.axaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public ZXTapeBuilderEditor(string DocumentPath)
8282
txtPokesAfter.TextChanged += DocumentChanged;
8383
txtScreenName.TextChanged += DocumentChanged;
8484
txtScreenFile.TextChanged += DocumentChanged;
85+
ckRAMDisk.IsCheckedChanged += DocumentChanged;
86+
cbRAMDiskOrder.SelectionChanged += DocumentChanged;
8587

8688
btnSelectScreen.Click += BtnSelectScreen_Click;
8789
btnSelectBlock.Click += BtnSelectBlock_Click;
@@ -278,7 +280,7 @@ bool UpdateFileName(string NewPath)
278280
cbPaper.SelectedIndex = fileContent.Paper;
279281
ckBorder.IsChecked = fileContent.UseBorder;
280282
cbBorder.SelectedIndex = fileContent.Border;
281-
283+
282284
if (fileContent.PokesBeforeLoad != null)
283285
{
284286
txtPokesBefore.Text = string.Join(';', fileContent.PokesBeforeLoad.Select(p => p.Address.ToString() + "," + p.Value.ToString()));
@@ -307,6 +309,13 @@ bool UpdateFileName(string NewPath)
307309
_blocks.Add(block);
308310
}
309311

312+
//RAM disk
313+
ckRAMDisk.IsChecked = fileContent.IncludeRAMDisk;
314+
if (fileContent.RAMDiskOrder == ZXRAMDiskOrder.Before)
315+
cbRAMDiskOrder.SelectedIndex = 0;
316+
else
317+
cbRAMDiskOrder.SelectedIndex = 1;
318+
310319
Task.Run(async () =>
311320
{
312321
await Task.Delay(100);
@@ -414,6 +423,8 @@ public override bool SaveDocument(TextWriter OutputLog)
414423
ScreenFile = txtScreenFile.Text,
415424
ScreenName = txtScreenName.Text,
416425
DataBlocks = _blocks.ToArray(),
426+
IncludeRAMDisk = ckRAMDisk.IsChecked ?? false,
427+
RAMDiskOrder = cbRAMDiskOrder.SelectedIndex == 0 ? ZXRAMDiskOrder.Before : ZXRAMDiskOrder.After
417428
};
418429

419430
string content = JsonConvert.SerializeObject(fileContent, Formatting.Indented);

ZXBStudio/DocumentModel/Classes/ZXDocumentProvider.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,41 @@ public static IEnumerable<string> GetDocumentCategories()
103103

104104
public static IEnumerable<IZXDocumentBuilder> GetPrecompilationDocumentBuilders()
105105
{
106-
return _docTypes.Where(d => d.DocumentBuilder != null && (d.DocumentBuildStage?.HasFlag(Enums.ZXBuildStage.PreBuild) ?? false)).Select(d => d.DocumentBuilder);
106+
var builders = _docTypes.Where(d => d.DocumentBuilder != null && (d.DocumentBuildStage?.HasFlag(Enums.ZXBuildStage.PreBuild) ?? false)).Select(d => d.DocumentBuilder);
107+
108+
var sortedBuilders = SortByDependency(builders, builder => builders.Where(b => b != null && builder != null && builder.DependsOn != null && builder.DependsOn.Contains(b.Id)));
109+
110+
return sortedBuilders;
107111
}
108112

109113
public static IEnumerable<IZXDocumentBuilder> GetPostcompilationDocumentBuilders()
110114
{
111-
return _docTypes.Where(d => d.DocumentBuilder != null && (d.DocumentBuildStage?.HasFlag(Enums.ZXBuildStage.PostBuild) ?? false)).Select(d => d.DocumentBuilder);
115+
var builders = _docTypes.Where(d => d.DocumentBuilder != null && (d.DocumentBuildStage?.HasFlag(Enums.ZXBuildStage.PostBuild) ?? false)).Select(d => d.DocumentBuilder);
116+
117+
var sortedBuilders = SortByDependency(builders, builder => builders.Where(b => b != null && builder != null && builder.DependsOn != null && builder.DependsOn.Contains(b.Id)));
118+
119+
return sortedBuilders;
120+
}
121+
122+
private static IEnumerable<T> SortByDependency<T>(this IEnumerable<T> nodes,
123+
Func<T, IEnumerable<T>> connected)
124+
{
125+
var elems = nodes.ToDictionary(node => node,
126+
node => new HashSet<T>(connected(node)));
127+
while (elems.Count > 0)
128+
{
129+
var elem = elems.FirstOrDefault(x => x.Value.Count == 0);
130+
if (elem.Key == null)
131+
{
132+
throw new ArgumentException("Cyclic connections are not allowed");
133+
}
134+
elems.Remove(elem.Key);
135+
foreach (var selem in elems)
136+
{
137+
selem.Value.Remove(elem.Key);
138+
}
139+
yield return elem.Key;
140+
}
112141
}
113142

114143
public static IZXDocumentType GetDocumentTypeInstance(Type DocumentType)

ZXBStudio/DocumentModel/Interfaces/IZXDocumentBuilder.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ namespace ZXBasicStudio.DocumentModel.Interfaces
1414
/// </summary>
1515
public interface IZXDocumentBuilder
1616
{
17+
/// <summary>
18+
/// Id of the builder
19+
/// </summary>
20+
public Guid Id { get; }
21+
22+
/// <summary>
23+
/// List of dependencies (only in the same stage)
24+
/// </summary>
25+
public Guid[]? DependsOn { get; }
26+
1727
/// <summary>
1828
/// Builds all the documents of the handled type belonging to the project.
1929
/// </summary>

0 commit comments

Comments
 (0)