Advertisement
ckirby101

zx boriel to sjasm

May 10th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. class BasToSjasm
  2. {
  3. private static bool show_help = false;
  4. private static string outfile = "";
  5. private static string label = "label";
  6. private static List<string>files = new List<string>();
  7.  
  8. static void Main(string[] args)
  9. {
  10. OptionSet p = new OptionSet
  11. {
  12. {
  13. "a|asm=", "bas generated asm filename",
  14. v => files.Add(v)
  15. },
  16. {
  17. "o|outfile=", "output asm file",
  18. v => outfile = v
  19. },
  20. {
  21. "h|help", "show this message and exit",
  22. v => show_help = v != null
  23. }
  24. };
  25.  
  26.  
  27. List<string> extra;
  28. try
  29. {
  30. extra = p.Parse(args);
  31. }
  32. catch (OptionException e)
  33. {
  34. Console.Write("greet: ");
  35. Console.WriteLine(e.Message);
  36. Console.WriteLine("Try `greet --help' for more information.");
  37. return;
  38. }
  39.  
  40. if (show_help)
  41. {
  42. ShowHelp(p);
  43. return;
  44. }
  45.  
  46.  
  47. if (files.Count == 0)
  48. {
  49. Console.WriteLine("must specify asm input files");
  50. return;
  51. }
  52.  
  53. if (string.IsNullOrEmpty(outfile))
  54. {
  55. Console.WriteLine("must specify asm output file");
  56. return;
  57. }
  58.  
  59.  
  60. string Output = "; export of bas 2 asm data , on " + DateTime.Now.ToShortDateString() + "\n";
  61.  
  62. RegexOptions options = RegexOptions.Multiline;
  63. string baspattern = @"__(?=\w)";
  64.  
  65. string hyphenpattern = @"(?<!\w)_(?=\w)";
  66.  
  67. string endpattern = @"\sEND";
  68. string eipattern = @"\sei";
  69.  
  70. for (int i=0;i<files.Count;i++)
  71. {
  72. string[] infile = File.ReadAllLines(files[i]);
  73. Output = Output + "; Conversion from file "+files[i]+"\n";
  74.  
  75. foreach (string s in infile)
  76. {
  77. if (s.StartsWith("#")) Output = Output + ";";
  78.  
  79. //get rid of __ varibles
  80. string o = Regex.Replace(s,baspattern,"BAS_");
  81.  
  82. //remove _ varibles
  83. o = Regex.Replace(o,hyphenpattern,"BAS_");
  84. //remove end statement
  85. o = Regex.Replace(o,endpattern,";END");
  86. //remove ei
  87. o = Regex.Replace(o,eipattern,";ei");
  88.  
  89.  
  90.  
  91. string notabs = o.ToLower().Replace('\t',' ');
  92.  
  93. //turn equ to defl so we can define stuff over and over
  94. if (notabs.Contains("equ"))
  95. {
  96. o = o.Replace("EQU","defl");
  97. o = o.TrimStart(('\t'));
  98. o = o.TrimStart((' '));
  99. }
  100.  
  101.  
  102. //remove local proc & endp
  103. if (o.ToLower().Contains("local ") || notabs.TrimStart(' ').StartsWith("proc") || notabs.TrimStart(' ').StartsWith("endp") || notabs.TrimStart(' ').StartsWith("org"))
  104. {
  105. o = ";"+o;
  106. }
  107.  
  108. Output = Output + o + "\n";
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. //Output = Output + "\tHEX\t" + outpal.GetAsm(16)+";"+Path.GetFileName(files[i])+"\n";
  116.  
  117.  
  118. }
  119.  
  120. File.WriteAllText(outfile, Output);
  121.  
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement