Skip to content

Commit 2935832

Browse files
committed
Sprite editor:
- PutChars exports to DIM, ASM, BIN and TAP
1 parent 0cf3fa6 commit 2935832

3 files changed

Lines changed: 113 additions & 3 deletions

File tree

ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,49 @@ private void CreateExample_PutChars()
216216
sb.AppendLine(ExportManager.Export_Sprite_PutChars(exportConfig, sprites));
217217
}
218218
break;
219+
220+
case ExportDataTypes.BIN:
221+
{
222+
sb.AppendLine("'- Includes -----------------------------------------------");
223+
sb.AppendLine("#INCLUDE <putchars.bas>");
224+
sb.AppendLine("");
225+
sb.AppendLine("'- Draw sprite --------------------------------------------");
226+
var sprite = sprites.ElementAt(0);
227+
sb.AppendLine(string.Format(
228+
"putChars(10,5,{0},{1},@{2})",
229+
sprite.Width / 8,
230+
sprite.Height / 8,
231+
exportConfig.LabelName));
232+
sb.AppendLine("");
233+
sb.AppendLine("' This section must not be executed");
234+
sb.AppendLine(string.Format(
235+
"{0}:",
236+
exportConfig.LabelName));
237+
sb.AppendLine("ASM");
238+
sb.AppendLine(string.Format("\tINCBIN \"{0}\"",
239+
Path.GetFileName(exportConfig.ExportFilePath)));
240+
sb.AppendLine("END ASM");
241+
}
242+
break;
243+
244+
case ExportDataTypes.TAP:
245+
{
246+
sb.AppendLine("'- Includes -----------------------------------------------");
247+
sb.AppendLine("#INCLUDE <putchars.bas>");
248+
sb.AppendLine("");
249+
sb.AppendLine("' Load .tap data ------------------------------------------");
250+
sb.AppendLine("LOAD \"\" CODE");
251+
sb.AppendLine("");
252+
sb.AppendLine("'- Draw sprite --------------------------------------------");
253+
var sprite = sprites.ElementAt(0);
254+
sb.AppendLine(string.Format(
255+
"putChars(10,5,{0},{1},@{2})",
256+
sprite.Width / 8,
257+
sprite.Height / 8,
258+
exportConfig.LabelName));
259+
sb.AppendLine("");
260+
}
261+
break;
219262
}
220263

221264
txtCode.Text = sb.ToString();
@@ -300,6 +343,25 @@ private void CmbDataType_SelectionChanged(object? sender, SelectionChangedEventA
300343
{
301344
var idx = cmbDataType.SelectedIndex;
302345
exportConfig.ExportDataType = (ExportDataTypes)idx;
346+
347+
var ext = "";
348+
switch (exportConfig.ExportDataType)
349+
{
350+
case ExportDataTypes.ASM:
351+
case ExportDataTypes.DIM:
352+
ext = ".bas";
353+
break;
354+
case ExportDataTypes.BIN:
355+
ext = ".bin";
356+
break;
357+
case ExportDataTypes.TAP:
358+
ext = ".tap";
359+
break;
360+
default:
361+
return;
362+
}
363+
txtOutputFile.Text = Path.Combine(Path.GetDirectoryName(txtOutputFile.Text), Path.GetFileNameWithoutExtension(txtOutputFile.Text) + ext);
364+
exportConfig.ExportFilePath = txtOutputFile.Text;
303365
Refresh();
304366
}
305367

ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Reactive.Joins;
78
using System.Text;
89
using System.Threading.Tasks;
910
using ZXBasicStudio.BuildSystem;
@@ -12,6 +13,8 @@
1213
using ZXBasicStudio.DocumentEditors.ZXGraphics.neg;
1314
using ZXBasicStudio.DocumentModel.Enums;
1415
using ZXBasicStudio.DocumentModel.Interfaces;
16+
using static System.Runtime.InteropServices.JavaScript.JSType;
17+
using Pattern = ZXBasicStudio.DocumentEditors.ZXGraphics.neg.Pattern;
1518

1619
namespace ZXBasicStudio.DocumentEditors.ZXGraphics.log
1720
{
@@ -466,6 +469,10 @@ public static string Export_Sprite_PutChars(ExportConfig exportConfig, IEnumerab
466469
return Export_Sprite_PutChars_DIM(exportConfig, sprites);
467470
case ExportDataTypes.ASM:
468471
return Export_Sprite_PutChars_ASM(exportConfig, sprites);
472+
case ExportDataTypes.BIN:
473+
return Export_Sprite_PutChars_BIN(exportConfig, sprites);
474+
case ExportDataTypes.TAP:
475+
return Export_Sprite_PutChars_TAP(exportConfig, sprites);
469476
default:
470477
return "ERROR: Not implemented!";
471478
}
@@ -677,7 +684,7 @@ private static string Export_Sprite_PutChars_Pattern(Sprite sprite, int n, Expor
677684
var sb = new StringBuilder();
678685

679686
var pattern = sprite.Patterns[n];
680-
var data = ServiceLayer.Files_CreateBinDataUpDown(pattern, sprite.Width, sprite.Height, exportConfig);
687+
var data = ServiceLayer.Files_CreateBinDataUpDown(pattern, sprite.Width, sprite.Height);
681688

682689
if (sprite.Frames > 1 &&
683690
!(sprite.Frames == 2 && sprite.Masked))
@@ -907,7 +914,7 @@ private static string Export_Sprite_PutChars_Pattern_ASM(Sprite sprite, int n, E
907914
var sb = new StringBuilder();
908915

909916
var pattern = sprite.Patterns[n];
910-
var data = ServiceLayer.Files_CreateBinDataUpDown(pattern, sprite.Width, sprite.Height, exportConfig);
917+
var data = ServiceLayer.Files_CreateBinDataUpDown(pattern, sprite.Width, sprite.Height);
911918

912919
int col = 0;
913920
int row = 0;
@@ -992,6 +999,47 @@ private static string Export_Sprite_PutChars_Attribute_ASM(Sprite sprite, int n,
992999
#endregion
9931000

9941001

1002+
#region TAP and BIN
1003+
1004+
1005+
public static string Export_Sprite_PutChars_BIN(ExportConfig exportConfig, IEnumerable<Sprite> sprites)
1006+
{
1007+
var binData = Export_Sprite_PutChars_GetBinaryData(sprites);
1008+
ServiceLayer.Files_SaveFileData(exportConfig.ExportFilePath, binData);
1009+
return "";
1010+
}
1011+
1012+
1013+
public static string Export_Sprite_PutChars_TAP(ExportConfig exportConfig, IEnumerable<Sprite> sprites)
1014+
{
1015+
var binData = Export_Sprite_PutChars_GetBinaryData(sprites);
1016+
binData = ServiceLayer.Bin2Tap(exportConfig.ZXFileName, exportConfig.ZXAddress, binData);
1017+
ServiceLayer.Files_SaveFileData(exportConfig.ExportFilePath, binData);
1018+
return "";
1019+
}
1020+
1021+
1022+
private static byte[] Export_Sprite_PutChars_GetBinaryData(IEnumerable<Sprite> sprites)
1023+
{
1024+
var binData=new List<byte>();
1025+
1026+
foreach (var sprite in sprites)
1027+
{
1028+
if (sprite != null)
1029+
{
1030+
foreach (var pattern in sprite.Patterns)
1031+
{
1032+
var data = ServiceLayer.Files_CreateBinDataUpDown(pattern, sprite.Width, sprite.Height);
1033+
binData.AddRange(data);
1034+
}
1035+
}
1036+
}
1037+
1038+
return binData.ToArray();
1039+
}
1040+
1041+
#endregion
1042+
9951043
#endregion
9961044
}
9971045
}

ZXBStudio/DocumentEditors/ZXGraphics/log/ServiceLayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public static byte[] Files_CreateBinData_GDUorFont(FileTypeConfig fileType, IEnu
245245
/// <param name="fileType">File information</param>
246246
/// <param name="sprite">Sprite or tile data</param>
247247
/// <returns>Arrfay of byte with the data ready to save on disk</returns>
248-
public static byte[] Files_CreateBinDataUpDown(Pattern pattern, int width, int height, ExportConfig export)
248+
public static byte[] Files_CreateBinDataUpDown(Pattern pattern, int width, int height)
249249
{
250250
try
251251
{

0 commit comments

Comments
 (0)