From d899b48b254b59b3b1999cbcb17e07815150aa6f Mon Sep 17 00:00:00 2001 From: Natsumi Date: Fri, 4 Jan 2019 20:44:51 +0200 Subject: [PATCH] some new changes --- SMPS2ASMv2/Output.cs | 16 +++++++++------- SMPS2ASMv2/Parse.cs | 7 ++++++- SMPS2ASMv2/Program.cs | 17 ++++++++--------- SMPS2ASMv2/S2AScript.cs | 37 ++++++++++++++++++++++++------------- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/SMPS2ASMv2/Output.cs b/SMPS2ASMv2/Output.cs index d8f475f..d3d8d75 100644 --- a/SMPS2ASMv2/Output.cs +++ b/SMPS2ASMv2/Output.cs @@ -5,6 +5,8 @@ namespace SMPS2ASMv2 { public static class Output { + public static string DataMacro = "dc.b"; + public static void DoIt(ConvertSMPS cvt) { if (debug) Debug("--; Prepare output to "+ cvt.fileout); // if file exists already @@ -25,7 +27,7 @@ public static void DoIt(ConvertSMPS cvt) { OffsetString last = null; // used for nicely formatting dc.b's - string line = "\tdc.b "; + string line = "\t"+ DataMacro + " "; int bytes = 0; bool unused = false; // if last was unused bool lastlable = true; // if last line was a lable. Essentially just omits extra newline @@ -43,7 +45,7 @@ public static void DoIt(ConvertSMPS cvt) { lastlable = false; writer.WriteLine(line.Substring(0, line.Length - 2) + (unused ? "\t; Unused" : "")); if (debug) Debug(i, line.Substring(0, line.Length - 2) + (unused ? "\t; Unused" : "")); - line = "\tdc.b "; + line = "\t" + DataMacro + " "; bytes = 0; } @@ -78,7 +80,7 @@ public static void DoIt(ConvertSMPS cvt) { if (unused) { if (bytes > 0) writer.WriteLine(line.Substring(0, line.Length - 2) + "\t; Unused"); if (debug) Debug(i, line.Substring(0, line.Length - 2) + "\t; Unused"); - line = "\tdc.b "; + line = "\t" + DataMacro + " "; bytes = 0; } @@ -93,7 +95,7 @@ public static void DoIt(ConvertSMPS cvt) { if (bytes >= 8) { writer.WriteLine(line.Substring(0, line.Length - 2)); if (debug) Debug(i, line.Substring(0, line.Length - 2)); - line = "\tdc.b "; + line = "\t" + DataMacro + " "; bytes = 0; } @@ -113,7 +115,7 @@ public static void DoIt(ConvertSMPS cvt) { if (bytes > 0) { writer.WriteLine(line.Substring(0, line.Length - 2) + (unused ? "\t; Unused" : "")); if (debug) Debug(i, line.Substring(0, line.Length - 2) + (unused ? "\t; Unused" : "")); - line = "\tdc.b "; + line = "\t" + DataMacro + " "; bytes = 0; } @@ -135,7 +137,7 @@ public static void DoIt(ConvertSMPS cvt) { if (!unused) { if (bytes > 0) writer.WriteLine(line.Substring(0, line.Length - 2)); if (debug) Debug(i, line.Substring(0, line.Length - 2)); - line = "\tdc.b "; + line = "\t" + DataMacro + " "; bytes = 0; } @@ -149,7 +151,7 @@ public static void DoIt(ConvertSMPS cvt) { if (bytes >= 8) { writer.WriteLine(line.Substring(0, line.Length - 2) + "\t; Unused"); if (debug) Debug(i, line.Substring(0, line.Length - 2) + "\t; Unused"); - line = "\tdc.b "; + line = "\t" + DataMacro + " "; bytes = 0; } } diff --git a/SMPS2ASMv2/Parse.cs b/SMPS2ASMv2/Parse.cs index 403dde3..2c94034 100644 --- a/SMPS2ASMv2/Parse.cs +++ b/SMPS2ASMv2/Parse.cs @@ -120,6 +120,7 @@ internal static string ParseMultiple(string val, uint? lnum) { } public static string ParseNumber(string s, uint? lnun) { + string old = s; try { char type = '\0'; int len = 0; @@ -177,7 +178,11 @@ public static string ParseNumber(string s, uint? lnun) { } } catch (Exception e) { - if (debug) Debug("--! ERROR: " + e.ToString()); + if (debug) { + Debug("--! ERROR IN EXPRESSION: " + s); + Debug("--! INITIAL EXPRESSION: " + old); + Debug("--! " + e.ToString()); + } // Console.WriteLine("'"+ s +"' "+ e); return ""; } diff --git a/SMPS2ASMv2/Program.cs b/SMPS2ASMv2/Program.cs index 6333258..d72f3a6 100644 --- a/SMPS2ASMv2/Program.cs +++ b/SMPS2ASMv2/Program.cs @@ -1,5 +1,4 @@ - -using System; +using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -109,12 +108,12 @@ static void Main(string[] args) { if (args.Length < 2) { pause = true; args = ConsoleArguments.Get(args, new ArgHandler[] { - new ArgHandler("Music file name with extension:", chkfilext2), - new ArgHandler("Project name:", chkname), }, new ButtonHandler[]{ - new ButtonHandler(ConsoleKey.Escape, "Quit the program", quitprg, quitcl), - new ButtonHandler(ConsoleKey.F1, "Pause program at the end", pauseprg, pausecl), - new ButtonHandler(ConsoleKey.F2, "Print debug info", debugprg, debugcl), - }); + new ArgHandler("Music file name with extension:", chkfilext2), + new ArgHandler("Project name:", chkname), }, new ButtonHandler[]{ + new ButtonHandler(ConsoleKey.Escape, "Quit the program", quitprg, quitcl), + new ButtonHandler(ConsoleKey.F1, "Pause program at the end", pauseprg, pausecl), + new ButtonHandler(ConsoleKey.F2, "Print debug info", debugprg, debugcl), + }); } else { args[0] = chkfilext2(args[0], true); @@ -137,7 +136,7 @@ static void Main(string[] args) { new ButtonHandler(ConsoleKey.Escape, "Quit the program", quitprg, quitcl), new ButtonHandler(ConsoleKey.F1, "Pause program at the end", pauseprg, pausecl), new ButtonHandler(ConsoleKey.F2, "Print debug info", debugprg, debugcl), - }); + }); } else { args[0] = chkfilext(args[0], true); diff --git a/SMPS2ASMv2/S2AScript.cs b/SMPS2ASMv2/S2AScript.cs index abe80e3..94d86e5 100644 --- a/SMPS2ASMv2/S2AScript.cs +++ b/SMPS2ASMv2/S2AScript.cs @@ -450,26 +450,37 @@ private void ParseScript(string data, string[] args, int lnoffs, ref Stack= 0 ? idx - 1 : line.Length - 1); switch (mac.ToLowerInvariant()) { - case "inc": - if(idx == -1) screrr(lnum, "Macro does not have a file name!"); - string path = line.Substring(idx + 1, line.Length - idx - 1); + case "inc": { + if (idx == -1) screrr(lnum, "Macro does not have a file name!"); + string path = line.Substring(idx + 1, line.Length - idx - 1); - if (path.StartsWith("\"") && path.EndsWith("\"")) - path = path.Substring(1, path.Length - 2); + if (path.StartsWith("\"") && path.EndsWith("\"")) + path = path.Substring(1, path.Length - 2); - if(!File.Exists(path)) screrr(lnum, "File '"+ path +"' does not exist!"); + if (!File.Exists(path)) screrr(lnum, "File '" + path + "' does not exist!"); - try { - string[] file = File.ReadAllLines(path); - if (debug) Debug(lnum, tabs, "--; macro: parse another file '"+ path +"' ("+ file.Length +" lines)"); - ParseScript(string.Join("\n", file), args, 0, ref stack); - if (debug) Debug(lnum, tabs, "--; return to previous file"); + try { + string[] file = File.ReadAllLines(path); + if (debug) Debug(lnum, tabs, "--; macro: parse another file '" + path + "' (" + file.Length + " lines)"); + ParseScript(string.Join("\n", file), args, 0, ref stack); + if (debug) Debug(lnum, tabs, "--; return to previous file"); + + } catch (Exception ex) { + screrr(lnum, "Failed to load file contents for file '" + path + "'!"); + } + } + break; - } catch(Exception ex) { - screrr(lnum, "Failed to load file contents for file '"+ path +"'!"); + case "datamacro": { + if (idx == -1) screrr(lnum, "Data macro has not been defined!"); + Output.DataMacro = line.Substring(idx + 1, line.Length - idx - 1).Trim(); } break; + case "version": + // lol + break; + default: screrr(lnum, "Macro type '" + mac + "' not recognized!"); break;