public void ConvertScreens(string BasePath, List <string> ProjectFiles) { var projects = new List <RetroDevStudio.Formats.GraphicScreenProject>(); foreach (var file in ProjectFiles) { var project = new RetroDevStudio.Formats.GraphicScreenProject(); project.ReadFromBuffer(GR.IO.File.ReadAllBytes(file)); projects.Add(project); } int numChars = 0; foreach (var project in projects) { numChars += ((project.Image.Width + 7) / 8) * ((project.Image.Height + 7) / 8); } for (int i = 0; i < numChars; ++i) { m_Chars.Add(new RetroDevStudio.Formats.CharData()); } int curCharOffset = 0; int projectIndex = 0; foreach (var project in projects) { if (CheckForMCCharsetErrors(project, curCharOffset)) { Debug.Log("Found error in " + ProjectFiles[projectIndex]); return; } curCharOffset += ((project.Image.Width + 7) / 8) * ((project.Image.Height + 7) / 8); ++projectIndex; } if (CheckForDuplicates()) { // charset GR.Memory.ByteBuffer charSet = new GR.Memory.ByteBuffer(); foreach (var charInfo in m_Chars) { if (charInfo.Replacement == null) { charSet.Append(charInfo.Tile.Data); } } GR.IO.File.WriteAllBytes(System.IO.Path.Combine(BasePath, "combined.chr"), charSet); // screens int charIndexOffset = 0; projectIndex = 0; foreach (var project in projects) { // create screens from graphic var screen = new RetroDevStudio.Formats.CharsetScreenProject(); int blockWidth = ((project.Image.Width + 7) / 8); int blockHeight = ((project.Image.Height + 7) / 8); screen.SetScreenSize(blockWidth, blockHeight); for (int y = 0; y < blockHeight; ++y) { for (int x = 0; x < blockWidth; ++x) { var charData = m_Chars[charIndexOffset + x + y * blockWidth]; var origCharData = charData; while (charData.Replacement != null) { charData = charData.Replacement; } screen.Chars[x + y * blockWidth] = (ushort)((origCharData.Tile.CustomColor << 8) + charData.Index); screen.Mode = project.MultiColor ? RetroDevStudio.TextMode.COMMODORE_40_X_25_MULTICOLOR : RetroDevStudio.TextMode.COMMODORE_40_X_25_HIRES; screen.CharSet.Colors.MultiColor1 = project.Colors.MultiColor1; screen.CharSet.Colors.MultiColor2 = project.Colors.MultiColor2; screen.CharSet.Colors.BackgroundColor = project.Colors.BackgroundColor; } } screen.CharSet = new RetroDevStudio.Formats.CharsetProject(); screen.CharSet.Colors.BackgroundColor = project.Colors.BackgroundColor; screen.CharSet.Colors.MultiColor1 = project.Colors.MultiColor1; screen.CharSet.Colors.MultiColor2 = project.Colors.MultiColor2; for (uint c = 0; c < charSet.Length / 8; ++c) { screen.CharSet.Characters[(int)c].Tile.Data = charSet.SubBuffer((int)c * 8, 8); screen.CharSet.Characters[(int)c].Tile.CustomColor = 9; } string origFile = System.IO.Path.GetFileNameWithoutExtension(ProjectFiles[projectIndex]); GR.IO.File.WriteAllBytes(System.IO.Path.Combine(BasePath, origFile + ".charscreen"), screen.SaveToBuffer()); ++projectIndex; charIndexOffset += blockWidth * blockHeight; } } }
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); }