Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BasToSjasm
- {
- private static bool show_help = false;
- private static string outfile = "";
- private static string label = "label";
- private static List<string>files = new List<string>();
- static void Main(string[] args)
- {
- OptionSet p = new OptionSet
- {
- {
- "a|asm=", "bas generated asm filename",
- v => files.Add(v)
- },
- {
- "o|outfile=", "output asm file",
- v => outfile = v
- },
- {
- "h|help", "show this message and exit",
- v => show_help = v != null
- }
- };
- List<string> extra;
- try
- {
- extra = p.Parse(args);
- }
- catch (OptionException e)
- {
- Console.Write("greet: ");
- Console.WriteLine(e.Message);
- Console.WriteLine("Try `greet --help' for more information.");
- return;
- }
- if (show_help)
- {
- ShowHelp(p);
- return;
- }
- if (files.Count == 0)
- {
- Console.WriteLine("must specify asm input files");
- return;
- }
- if (string.IsNullOrEmpty(outfile))
- {
- Console.WriteLine("must specify asm output file");
- return;
- }
- string Output = "; export of bas 2 asm data , on " + DateTime.Now.ToShortDateString() + "\n";
- RegexOptions options = RegexOptions.Multiline;
- string baspattern = @"__(?=\w)";
- string hyphenpattern = @"(?<!\w)_(?=\w)";
- string endpattern = @"\sEND";
- string eipattern = @"\sei";
- for (int i=0;i<files.Count;i++)
- {
- string[] infile = File.ReadAllLines(files[i]);
- Output = Output + "; Conversion from file "+files[i]+"\n";
- foreach (string s in infile)
- {
- if (s.StartsWith("#")) Output = Output + ";";
- //get rid of __ varibles
- string o = Regex.Replace(s,baspattern,"BAS_");
- //remove _ varibles
- o = Regex.Replace(o,hyphenpattern,"BAS_");
- //remove end statement
- o = Regex.Replace(o,endpattern,";END");
- //remove ei
- o = Regex.Replace(o,eipattern,";ei");
- string notabs = o.ToLower().Replace('\t',' ');
- //turn equ to defl so we can define stuff over and over
- if (notabs.Contains("equ"))
- {
- o = o.Replace("EQU","defl");
- o = o.TrimStart(('\t'));
- o = o.TrimStart((' '));
- }
- //remove local proc & endp
- if (o.ToLower().Contains("local ") || notabs.TrimStart(' ').StartsWith("proc") || notabs.TrimStart(' ').StartsWith("endp") || notabs.TrimStart(' ').StartsWith("org"))
- {
- o = ";"+o;
- }
- Output = Output + o + "\n";
- }
- //Output = Output + "\tHEX\t" + outpal.GetAsm(16)+";"+Path.GetFileName(files[i])+"\n";
- }
- File.WriteAllText(outfile, Output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement