private int HandleMapProject(GR.Text.ArgumentParser ArgParser) { if (!ValidateExportType("map project file", ArgParser.Parameter("TYPE"), new string[] { "MAPDATA", "MAPDATAASM" })) { return(1); } GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(ArgParser.Parameter("MAPPROJECT")); if (data == null) { System.Console.WriteLine("Couldn't read binary char file " + ArgParser.Parameter("MAPPROJECT")); return(1); } var mapProject = new RetroDevStudio.Formats.MapProject(); if (!mapProject.ReadFromBuffer(data)) { System.Console.WriteLine("Couldn't read map project from file " + ArgParser.Parameter("MAPPROJECT")); return(1); } GR.Memory.ByteBuffer resultingData = new GR.Memory.ByteBuffer(); if (ArgParser.Parameter("TYPE").Contains("MAPDATAASM")) { foreach (var map in mapProject.Maps) { var mapData = new ByteBuffer((uint)(map.Tiles.Width * map.Tiles.Height)); for (int j = 0; j < 0 + map.Tiles.Height; ++j) { for (int i = 0; i < 0 + map.Tiles.Width; ++i) { mapData.SetU8At(i + j * map.Tiles.Width, (byte)map.Tiles[i, j]); } } resultingData.Append(Encoding.ASCII.GetBytes("MAP_" + map.Name + "\n!hex \"" + mapData.ToString() + "\"\n")); } } else if (ArgParser.Parameter("TYPE").Contains("MAPDATA")) { foreach (var map in mapProject.Maps) { for (int j = 0; j < 0 + map.Tiles.Height; ++j) { for (int i = 0; i < 0 + map.Tiles.Width; ++i) { resultingData.AppendU8((byte)map.Tiles[i, j]); } } } } if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), resultingData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }
private int HandleSpriteProject(GR.Text.ArgumentParser ArgParser) { if (!ValidateExportType("sprite project", ArgParser.Parameter("TYPE"), new string[] { "SPRITES" })) { return(1); } var spriteProject = new C64Studio.Formats.SpriteProject(); if (!spriteProject.ReadFromBuffer(GR.IO.File.ReadAllBytes(ArgParser.Parameter("SPRITEPROJECT")))) { System.Console.WriteLine("Couldn't read sprite project from file " + ArgParser.Parameter("SPRITEPROJECT")); return(1); } int firstSprite = 0; int count = -1; if (ArgParser.IsParameterSet("OFFSET")) { firstSprite = GR.Convert.ToI32(ArgParser.Parameter("OFFSET")); } if (ArgParser.IsParameterSet("COUNT")) { count = GR.Convert.ToI32(ArgParser.Parameter("COUNT")); } if (count == -1) { count = spriteProject.TotalNumberOfSprites; } if ((firstSprite < 0) || (firstSprite >= spriteProject.TotalNumberOfSprites)) { System.Console.WriteLine("OFFSET is invalid"); return(1); } if ((count <= 0) || (firstSprite + count > spriteProject.TotalNumberOfSprites)) { System.Console.WriteLine("COUNT is invalid"); return(1); } GR.Memory.ByteBuffer spriteData = new GR.Memory.ByteBuffer((uint)(count * 64)); for (int i = 0; i < count; ++i) { spriteProject.Sprites[firstSprite + i].Tile.Data.CopyTo(spriteData, 0, 63, i * 64); } if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), spriteData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }
private int HandleCharsetProject(GR.Text.ArgumentParser ArgParser) { if (!ValidateExportType("charset project", ArgParser.Parameter("TYPE"), new string[] { "CHARS" })) { return(1); } var charsetProject = new C64Studio.Formats.CharsetProject(); if (!charsetProject.ReadFromBuffer(GR.IO.File.ReadAllBytes(ArgParser.Parameter("CHARSETPROJECT")))) { System.Console.WriteLine("Couldn't read charset project from file " + ArgParser.Parameter("CHARSETPROJECT")); return(1); } int firstUnit = 0; int count = -1; if (ArgParser.IsParameterSet("OFFSET")) { firstUnit = GR.Convert.ToI32(ArgParser.Parameter("OFFSET")); } if (ArgParser.IsParameterSet("COUNT")) { count = GR.Convert.ToI32(ArgParser.Parameter("COUNT")); } if (count == -1) { count = charsetProject.Characters.Count; } if ((firstUnit < 0) || (firstUnit >= charsetProject.Characters.Count)) { System.Console.WriteLine("OFFSET is invalid"); return(1); } if ((count <= 0) || (firstUnit + count > charsetProject.Characters.Count)) { System.Console.WriteLine("COUNT is invalid"); return(1); } GR.Memory.ByteBuffer exportData = new GR.Memory.ByteBuffer((uint)(count * 8)); for (int i = 0; i < count; ++i) { charsetProject.Characters[firstUnit + i].Tile.Data.CopyTo(exportData, 0, 8, i * 8); } if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), exportData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }
public int Handle(string[] args) { var argParser = new GR.Text.ArgumentParser(); argParser.AddOptionalParameter("SPRITEPROJECT"); argParser.AddOptionalParameter("SPRITES"); argParser.AddOptionalParameter("CHARSETPROJECT"); argParser.AddOptionalParameter("CHARS"); argParser.AddOptionalParameter("OFFSET"); argParser.AddOptionalParameter("COUNT"); argParser.AddParameter("EXPORT"); argParser.AddSwitch("TYPE", false); argParser.AddSwitchValue("TYPE", "SPRITES"); argParser.AddSwitchValue("TYPE", "CHARS"); if (!argParser.CheckParameters(args)) { System.Console.WriteLine("MediaTool V" + System.Windows.Forms.Application.ProductVersion); System.Console.WriteLine(""); System.Console.WriteLine(argParser.ErrorInfo()); System.Console.WriteLine(""); System.Console.WriteLine("Call with mediatool"); System.Console.WriteLine(" [-spriteproject <sprite project file>]"); System.Console.WriteLine(" [-sprites <binary sprite file>]"); System.Console.WriteLine(" [-charsetproject <charset project file>]"); System.Console.WriteLine(" [-chars <binary charset file>]"); System.Console.WriteLine(" [-type <export format>]"); System.Console.WriteLine(" [-export <file name>]"); System.Console.WriteLine(" [-offset <first unit to affect, default 0>]"); System.Console.WriteLine(" [-count <count of units to affect, default all>]"); return(1); } if (argParser.IsParameterSet("SPRITEPROJECT")) { return(HandleSpriteProject(argParser)); } else if (argParser.IsParameterSet("SPRITES")) { return(HandleSpriteFile(argParser)); } else if (argParser.IsParameterSet("CHARSETPROJECT")) { return(HandleCharsetProject(argParser)); } else if (argParser.IsParameterSet("CHARS")) { return(HandleCharFile(argParser)); } System.Console.Error.WriteLine("Missing medium"); return(1); }
private int HandleCharFile(GR.Text.ArgumentParser ArgParser) { if (!ValidateExportType("charset file", ArgParser.Parameter("TYPE"), new string[] { "CHARS" })) { return(1); } GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(ArgParser.Parameter("CHARS")); if (data == null) { System.Console.WriteLine("Couldn't read binary char file " + ArgParser.Parameter("CHARS")); return(1); } int firstUnit = 0; int count = -1; if (ArgParser.IsParameterSet("OFFSET")) { firstUnit = GR.Convert.ToI32(ArgParser.Parameter("OFFSET")); } if (ArgParser.IsParameterSet("COUNT")) { count = GR.Convert.ToI32(ArgParser.Parameter("COUNT")); } if (count == -1) { count = (int)data.Length / 8; } if ((firstUnit < 0) || (firstUnit >= (int)data.Length / 8)) { System.Console.WriteLine("OFFSET is invalid"); return(1); } if ((count <= 0) || (firstUnit + count > (int)data.Length / 8)) { System.Console.WriteLine("COUNT is invalid"); return(1); } GR.Memory.ByteBuffer spriteData = new GR.Memory.ByteBuffer((uint)(count * 8)); data.CopyTo(spriteData, firstUnit * 8, count * 8); if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), spriteData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }
private int HandleSpriteFile(GR.Text.ArgumentParser ArgParser) { if (!ValidateExportType("sprite file", ArgParser.Parameter("TYPE"), new string[] { "SPRITES" })) { return(1); } GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(ArgParser.Parameter("SPRITES")); if (data == null) { System.Console.WriteLine("Couldn't read binary sprite file " + ArgParser.Parameter("SPRITES")); return(1); } int firstSprite = 0; int count = -1; if (ArgParser.IsParameterSet("OFFSET")) { firstSprite = GR.Convert.ToI32(ArgParser.Parameter("OFFSET")); } if (ArgParser.IsParameterSet("COUNT")) { count = GR.Convert.ToI32(ArgParser.Parameter("COUNT")); } if (count == -1) { count = (int)data.Length / 64; } if ((firstSprite < 0) || (firstSprite >= (int)data.Length / 64)) { System.Console.WriteLine("OFFSET is invalid"); return(1); } if ((count <= 0) || (firstSprite + count > (int)data.Length / 64)) { System.Console.WriteLine("COUNT is invalid"); return(1); } GR.Memory.ByteBuffer spriteData = new GR.Memory.ByteBuffer((uint)(count * 64)); data.CopyTo(spriteData, firstSprite * 64, count * 64); if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), spriteData)) { return(1); } return(0); }
private int HandleGraphicscreenFile(GR.Text.ArgumentParser ArgParser) { string exportType = ArgParser.Parameter("TYPE"); if (!ValidateExportType("graphicscreen file", exportType, new string[] { "MULTICOLORBITMAPSCREENCOLOR", "MULTICOLORBITMAPCOLORSCREEN", "MULTICOLORBITMAPSCREEN", "MULTICOLORBITMAPCOLOR", "MULTICOLORBITMAP", "HIRESBITMAPSCREENCOLOR", "HIRESBITMAPCOLORSCREEN", "HIRESBITMAPSCREEN", "HIRESBITMAPCOLOR", "HIRESBITMAP" })) { return(1); } string inputFile = ArgParser.Parameter("GRAPHICSCREEN"); GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(inputFile); if (data == null) { System.Console.WriteLine("Couldn't read binary char file " + inputFile); return(1); } var graphicScreen = new C64Studio.Formats.GraphicScreenProject(); if (!graphicScreen.ReadFromBuffer(data)) { System.Console.WriteLine("Couldn't read graphicscreen project from file " + inputFile); return(1); } // import if (ArgParser.IsParameterSet("IMPORTIMAGE")) { var image = LoadImageFromFile(ArgParser.Parameter("IMPORTIMAGE")); if (image == null) { System.Console.WriteLine("Couldn't read image from file " + ArgParser.Parameter("IMPORTIMAGE")); return(1); } if ((image.Width > graphicScreen.ScreenWidth) || (image.Height > graphicScreen.ScreenHeight)) { System.Console.WriteLine("Couldn't read image from file " + ArgParser.Parameter("IMPORTIMAGE")); return(1); } if (image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { image.Dispose(); Console.WriteLine("Image format invalid!\nNeeds to be 8bit index"); return(1); } } // export int x = 0; int y = 0; int width = -1; int height = -1; if (ArgParser.IsParameterSet("AREA")) { string rangeInfo = ArgParser.Parameter("AREA"); string[] rangeParts = rangeInfo.Split(','); if (rangeParts.Length != 4) { System.Console.WriteLine("AREA is invalid, expected four values separated by comma: x,y,width,height"); return(1); } x = GR.Convert.ToI32(rangeParts[0]); y = GR.Convert.ToI32(rangeParts[1]); width = GR.Convert.ToI32(rangeParts[2]); height = GR.Convert.ToI32(rangeParts[3]); if ((width <= 0) || (height <= 0) || (x < 0) || (y < 0) || (x + width > graphicScreen.ScreenWidth) || (y + height > graphicScreen.ScreenHeight)) { System.Console.WriteLine("AREA values are out of bounds or invalid, expected four values separated by comma: x,y,width,height"); return(1); } } else { width = graphicScreen.ScreenWidth; height = graphicScreen.ScreenHeight; } bool exportMC = exportType.Contains("MULTICOLOR"); bool exportScreen = exportType.Contains("SCREEN"); bool exportColors = exportType.Contains("COLORS"); bool exportBitmap = exportType.Contains("BITMAP"); GR.Memory.ByteBuffer screenChar = new GR.Memory.ByteBuffer(); GR.Memory.ByteBuffer screenColor = new GR.Memory.ByteBuffer(); GR.Memory.ByteBuffer bitmapData = new GR.Memory.ByteBuffer(); bool[,] errornousChars = new bool[(width + 7) / 8, (height + 7) / 8]; var charData = new List <C64Studio.Formats.CharData>(errornousChars.Length); int numErrors = 0; if (!exportMC) { // HIRES numErrors = graphicScreen.ImageToHiresBitmapData(charData, errornousChars, x / 8, y / 8, width / 8, height / 8, out bitmapData, out screenChar, out screenColor); } else { // MC numErrors = graphicScreen.ImageToMCBitmapData(graphicScreen.ColorMapping, charData, errornousChars, x / 8, y / 8, width / 8, height / 8, out bitmapData, out screenChar, out screenColor); } if (numErrors > 0) { System.Console.WriteLine("Format did not match expectations (check for color clashes)"); return(1); } // build export data GR.Memory.ByteBuffer exportData = new GR.Memory.ByteBuffer(); if (exportType.Contains("BITMAPSCREENCOLORS")) { exportData.Append(bitmapData); exportData.Append(screenChar); exportData.Append(screenColor); } else if (exportType.Contains("BITMAPCOLORSSCREEN")) { exportData.Append(bitmapData); exportData.Append(screenColor); exportData.Append(screenChar); } else if (exportType.Contains("BITMAPCOLORS")) { exportData.Append(bitmapData); exportData.Append(screenColor); } else if (exportType.Contains("BITMAPSCREEN")) { exportData.Append(bitmapData); exportData.Append(screenChar); } else if (exportType.Contains("BITMAP")) { exportData.Append(bitmapData); } if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), exportData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }
public int Handle(string[] args) { var argParser = new GR.Text.ArgumentParser(); argParser.AddOptionalParameter("SPRITEPROJECT"); argParser.AddOptionalParameter("SPRITES"); argParser.AddOptionalParameter("CHARSETPROJECT"); argParser.AddOptionalParameter("CHARS"); argParser.AddOptionalParameter("CHARSCREEN"); argParser.AddOptionalParameter("GRAPHICSCREEN"); argParser.AddOptionalParameter("MAPPROJECT"); argParser.AddOptionalParameter("OFFSET"); argParser.AddOptionalParameter("COUNT"); argParser.AddOptionalParameter("AREA"); argParser.AddOptionalParameter("BINARY"); argParser.AddOptionalParameter("IMPORTIMAGE"); argParser.AddParameter("EXPORT"); argParser.AddSwitch("TYPE", false); argParser.AddSwitchValue("TYPE", "SPRITES"); argParser.AddSwitchValue("TYPE", "CHARS"); argParser.AddSwitchValue("TYPE", "CHARSCOLORS"); argParser.AddSwitchValue("TYPE", "COLORS"); argParser.AddSwitchValue("TYPE", "BYTES"); argParser.AddSwitchValue("TYPE", "MULTICOLORBITMAP"); argParser.AddSwitchValue("TYPE", "MULTICOLORBITMAPCOLORS"); argParser.AddSwitchValue("TYPE", "MULTICOLORBITMAPSCREEN"); argParser.AddSwitchValue("TYPE", "MULTICOLORBITMAPSCREENCOLORS"); argParser.AddSwitchValue("TYPE", "MULTICOLORBITMAPCOLORSSCREEN"); argParser.AddSwitchValue("TYPE", "HIRESBITMAP"); argParser.AddSwitchValue("TYPE", "HIRESBITMAPCOLORS"); argParser.AddSwitchValue("TYPE", "HIRESBITMAPSCREEN"); argParser.AddSwitchValue("TYPE", "HIRESBITMAPSCREENCOLORS"); argParser.AddSwitchValue("TYPE", "HIRESBITMAPCOLORSSCREEN"); argParser.AddSwitchValue("TYPE", "MAPDATA"); argParser.AddSwitchValue("TYPE", "MAPDATAASM"); if (!argParser.CheckParameters(args)) { System.Console.WriteLine("MediaTool V" + System.Windows.Forms.Application.ProductVersion); System.Console.WriteLine(""); System.Console.WriteLine(argParser.ErrorInfo()); System.Console.WriteLine(""); System.Console.WriteLine("Call with mediatool"); System.Console.WriteLine(" [-spriteproject <sprite project file>]"); System.Console.WriteLine(" [-sprites <binary sprite file>]"); System.Console.WriteLine(" [-charsetproject <charset project file>]"); System.Console.WriteLine(" [-chars <binary charset file>]"); System.Console.WriteLine(" [-charscreen <charscreen project file>]"); System.Console.WriteLine(" [-graphicscreen <graphicscreen project file>]"); System.Console.WriteLine(" [-mapproject <map project file>]"); System.Console.WriteLine(" [-binary <file>]"); System.Console.WriteLine(" [-type <export format>]"); System.Console.WriteLine(" [-export <file name>]"); System.Console.WriteLine(" [-importimage <image name>]"); System.Console.WriteLine(" [-area <x,y,width,height>]"); System.Console.WriteLine(" [-offset <first unit to affect, default 0>]"); System.Console.WriteLine(" [-count <count of units to affect, default all>]"); System.Console.WriteLine(""); System.Console.WriteLine(" -area is only applicable for charscreen"); return(1); } if (argParser.IsParameterSet("SPRITEPROJECT")) { return(HandleSpriteProject(argParser)); } else if (argParser.IsParameterSet("SPRITES")) { return(HandleSpriteFile(argParser)); } else if (argParser.IsParameterSet("CHARSETPROJECT")) { return(HandleCharsetProject(argParser)); } else if (argParser.IsParameterSet("CHARS")) { return(HandleCharFile(argParser)); } else if (argParser.IsParameterSet("CHARSCREEN")) { return(HandleCharscreenFile(argParser)); } else if (argParser.IsParameterSet("GRAPHICSCREEN")) { return(HandleGraphicscreenFile(argParser)); } else if (argParser.IsParameterSet("MAPPROJECT")) { return(HandleMapProject(argParser)); } else if (argParser.IsParameterSet("BINARY")) { return(HandleBinaryFile(argParser)); } System.Console.Error.WriteLine("Missing medium"); return(1); }
private int HandleCharscreenFile(GR.Text.ArgumentParser ArgParser) { if (!ValidateExportType("charscreen file", ArgParser.Parameter("TYPE"), new string[] { "CHARS", "CHARSCOLORS", "COLORS" })) { return(1); } GR.Memory.ByteBuffer data = GR.IO.File.ReadAllBytes(ArgParser.Parameter("CHARSCREEN")); if (data == null) { System.Console.WriteLine("Couldn't read binary char file " + ArgParser.Parameter("CHARSCREEN")); return(1); } var charScreenProject = new RetroDevStudio.Formats.CharsetScreenProject(); if (!charScreenProject.ReadFromBuffer(data)) { System.Console.WriteLine("Couldn't read charscreen project from file " + ArgParser.Parameter("CHARSCREEN")); return(1); } int x = 0; int y = 0; int width = -1; int height = -1; if (ArgParser.IsParameterSet("AREA")) { string rangeInfo = ArgParser.Parameter("AREA"); string[] rangeParts = rangeInfo.Split(','); if (rangeParts.Length != 4) { System.Console.WriteLine("AREA is invalid, expected four values separated by comma: x,y,width,height"); return(1); } x = GR.Convert.ToI32(rangeParts[0]); y = GR.Convert.ToI32(rangeParts[1]); width = GR.Convert.ToI32(rangeParts[2]); height = GR.Convert.ToI32(rangeParts[3]); if ((width <= 0) || (height <= 0) || (x < 0) || (y < 0) || (x + width > charScreenProject.ScreenWidth) || (y + height > charScreenProject.ScreenHeight)) { System.Console.WriteLine("AREA values are out of bounds or invalid, expected four values separated by comma: x,y,width,height"); return(1); } } else { width = charScreenProject.ScreenWidth; height = charScreenProject.ScreenHeight; } GR.Memory.ByteBuffer resultingData = new GR.Memory.ByteBuffer(); if (ArgParser.Parameter("TYPE").Contains("CHARS")) { for (int j = y; j < y + height; ++j) { for (int i = x; i < x + width; ++i) { resultingData.AppendU8((byte)charScreenProject.Chars[i + j * charScreenProject.ScreenWidth]); } } } if (ArgParser.Parameter("TYPE").Contains("COLORS")) { for (int j = y; j < y + height; ++j) { for (int i = x; i < x + width; ++i) { resultingData.AppendU8((byte)(charScreenProject.Chars[i + j * charScreenProject.ScreenWidth] >> 8)); } } } if (!GR.IO.File.WriteAllBytes(ArgParser.Parameter("EXPORT"), resultingData)) { Console.WriteLine("Could not write to file " + ArgParser.Parameter("EXPORT")); return(1); } return(0); }