private void btnAccept_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtPath.Text)) { MessageBox.Show("Specify file name"); return; } if (rbSinclair.Checked) { Mode = SpeccyDrawExportMode.SinclairBasic; } else if (rbBoriel.Checked) { Mode = SpeccyDrawExportMode.BorielBasic; } else { Mode = SpeccyDrawExportMode.Assembler; } FileName = txtPath.Text; DialogResult = DialogResult.OK; this.Close(); }
public bool ExportFile(string FileName, SpeccyDrawExportMode Mode) { try { List <byte> cpActions = new List <byte>(); SCAction lastAction = null; bool onPolygon = false; for (int buc = 0; buc < actions.Count; buc++) { SCAction currentAction = actions[buc]; if (buc == 0 || lastAction.Tool != currentAction.Tool || (onPolygon && lastAction.EndPoint != currentAction.StartPoint)) { byte action; if (buc < actions.Count + 1 && currentAction.Tool == SpeccyDrawControlTool.Line && actions[buc + 1].Tool == SpeccyDrawControlTool.Line && currentAction.EndPoint == actions[buc + 1].StartPoint) { onPolygon = true; action = 250; cpActions.Add(action); cpActions.Add((byte)(191 - currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); } else { onPolygon = false; action = (byte)(200 + ((byte)currentAction.Tool)); cpActions.Add(action); } } lastAction = currentAction; //Y y X están invertidos, de esta forma si Y es superior a 200 indica que es una nueva operación //si no se repite la operación anterior para ahorrar espacio switch (currentAction.Tool) { case SpeccyDrawControlTool.Line: if (!onPolygon) { cpActions.Add((byte)(191 - currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); } cpActions.Add((byte)(191 - currentAction.EndPoint.Y)); cpActions.Add((byte)currentAction.EndPoint.X); break; case SpeccyDrawControlTool.Rectangle: cpActions.Add((byte)(191 - currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); cpActions.Add((byte)(191 - currentAction.EndPoint.Y)); cpActions.Add((byte)currentAction.EndPoint.X); break; case SpeccyDrawControlTool.Arc: cpActions.Add((byte)(191 - currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); cpActions.Add((byte)(191 - currentAction.EndPoint.Y)); cpActions.Add((byte)currentAction.EndPoint.X); cpActions.Add((byte)((currentAction.Distance >> 8) & 0xFF)); cpActions.Add((byte)(currentAction.Distance & 0xFF)); break; case SpeccyDrawControlTool.Circle: cpActions.Add((byte)(191 - currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); cpActions.Add((byte)currentAction.StartPoint.Distance(currentAction.EndPoint)); break; case SpeccyDrawControlTool.Fill: cpActions.Add((byte)(currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); break; case SpeccyDrawControlTool.BlockEraser: cpActions.Add((byte)(currentAction.StartPoint.Y)); cpActions.Add((byte)currentAction.StartPoint.X); break; } } List <byte> attribs = new List <byte>(); for (int y = 0; y < 24; y++) { for (int x = 0; x < 32; x++) { attribs.Add(chars[x, y].Attribute.ToByte()); } } var encodedAttribs = RLEncode(attribs.ToArray()); List <byte> finalBuffer = new List <byte>(); finalBuffer.AddRange(cpActions); finalBuffer.Add(0xFF); finalBuffer.AddRange(encodedAttribs); StreamWriter output = File.CreateText(FileName); switch (Mode) { case SpeccyDrawExportMode.SinclairBasic: int line = 8999; for (int buc = 0; buc < finalBuffer.Count; buc++) { if (buc % 32 == 0) { line++; output.WriteLine(); output.Write($"{line} DATA {finalBuffer[buc]}"); } else { output.Write($", {finalBuffer[buc]}"); } } break; case SpeccyDrawExportMode.BorielBasic: output.Write($"Dim vectImg({finalBuffer.Count - 1}) as uByte => {{ _\r\n {finalBuffer[0]}"); for (int buc = 1; buc < finalBuffer.Count; buc++) { if (buc % 32 == 0) { output.Write($", _\r\n {finalBuffer[buc]}"); } else { output.Write($", {finalBuffer[buc]}"); } } output.Write(" _\r\n }"); break; case SpeccyDrawExportMode.Assembler: output.WriteLine("vectImg:"); for (int buc = 0; buc < finalBuffer.Count; buc++) { output.WriteLine($" DEFB {finalBuffer[buc]}"); } break; } output.Close(); return(true); } catch { return(false); } }