Skip to content

Commit

Permalink
+printing
Browse files Browse the repository at this point in the history
+running standalone scripts
  • Loading branch information
Awuwunya committed Dec 17, 2017
1 parent 178155e commit 9e37b70
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
19 changes: 19 additions & 0 deletions SMPS2ASMv2/ConvertSMPS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,25 @@ private void ProcessItem(GenericScriptItem i, ref string[] args, out bool stop,
}
break;

case ScriptItemType.Print: {
// get the comment, and replace any case of escaped { and } with temp chars
string comm = (i as ScriptPrint).comment;
uint pos2 = pos;

// translate all the conversion things
while (comm.Contains("{") && comm.Contains("}")) {
int i1 = comm.IndexOf('{'), i2 = comm.IndexOf('}');
string arg = Parse.ParseNumber(comm.Substring(i1 + 1, i2 - i1 - 1), i.line, i.parent);
comm = comm.Substring(0, i1) + arg + comm.Substring(i2 + 1);
}

if (debug) Debug(pos + offset, i.line, i.identifier, '%' + comm);
comm = comm.Replace("\\t", "\t").Replace("\\r", "\r").Replace("\\n", "\n");
// add the comment
Console.WriteLine(comm);
}
break;

case ScriptItemType.ArrayItem:
break;

Expand Down
41 changes: 38 additions & 3 deletions SMPS2ASMv2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static void error(string v) {
public static bool pause, debug;
private static StreamWriter dbWr;

// check file name (special)
public static string chkfilext2(string data, bool ret) {
string d = Directory.GetFiles(folder, data, SearchOption.AllDirectories).FirstOrDefault();
return ret ? d : d != null ? null : "Input file '" + data + "' does not exist!";
}

// check file name
public static string chkfilext(string data, bool ret) {
string d = folder + "\\music\\" + data;
Expand Down Expand Up @@ -82,7 +88,7 @@ static void Main(string[] args) {

// args[input file with ext, Sound driver name, label, extra: may be used by script]
// get the exe folder
folder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(System.Environment.CurrentDirectory), @""));
folder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Environment.CurrentDirectory), @""));
string[] a = args;

//check if we have a debug option
Expand All @@ -91,6 +97,34 @@ static void Main(string[] args) {
debug = true;
}

//check if a script file was dragged in
if(args.Length > 0) {
if(File.Exists(args[0]) && args[0].EndsWith(".smpss")) {
string script = args[0];
args = args.Skip(1).ToArray();

// check if all arguments are gotten
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),
});

} else {
args[0] = chkfilext2(args[0], true);
args[1] = chkname(args[1], true);
}

args = new string[] { args[0], script, args[1] };

goto oops;
}
}

// check if all arguments are gotten
if (args.Length < 3) {
pause = true;
Expand All @@ -108,8 +142,9 @@ static void Main(string[] args) {
args[1] = chkfolext(args[1], true);
args[2] = chkname(args[2], true);
}

// time how long this will take
oops:
timer = new Stopwatch();
timer.Start();

Expand Down Expand Up @@ -142,9 +177,9 @@ static void Main(string[] args) {
Debug("--; args=["+ string.Join(", ", a) +"]");
Debug("--; filein=" + args[0]);
Debug("--; fileout="+ fileout);
Debug("--; folder=" + folder);
Debug("--; script=" + args[1]);
Debug("--; lable=" + args[2]);
Debug("--; folder=" + folder);
}

// get new SMPS object
Expand Down
11 changes: 8 additions & 3 deletions SMPS2ASMv2/S2AScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,19 @@ private void ParseScript(string data, string[] args) {
if (debug) Debug(lnum,tabs, '>' + ttype +' '+ line);
break;

case ';':
stack.Peek().Add(new ScriptStop(lnum, stack.Peek()));
if (debug) Debug(lnum, tabs, ";");
break;

case '%':
stack.Peek().Add(new ScriptComment(lnum, stack.Peek(), line.Substring(1)));
if (debug) Debug(lnum,tabs, line);
break;

case ';':
stack.Peek().Add(new ScriptStop(lnum, stack.Peek()));
if (debug) Debug(lnum,tabs, ";");
case '+':
stack.Peek().Add(new ScriptPrint(lnum, stack.Peek(), line.Substring(1)));
if (debug) Debug(lnum, tabs, line);
break;

default:
Expand Down
10 changes: 9 additions & 1 deletion SMPS2ASMv2/ScriptItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum ScriptItemType {
NULL = 0, Equate, Macro, Operation,
Condition, Repeat, Goto, Stop,
Executable, Import, ArgMod,
LableMod, LableDo, Comment,
LableMod, LableDo, Comment, Print,
ArrayItem, // SPECIAL
}

Expand Down Expand Up @@ -201,6 +201,14 @@ public ScriptComment(uint lnum, ScriptArray parent, string comment) : base(lnum,
}
}

public class ScriptPrint : GenericScriptItem {
public string comment;

public ScriptPrint(uint lnum, ScriptArray parent, string comment) : base(lnum, parent, "PRI", ScriptItemType.Print) {
this.comment = comment;
}
}

public class ScriptStop : GenericScriptItem {
public ScriptStop(uint lnum, ScriptArray parent) : base(lnum, parent, "STP", ScriptItemType.Stop) { }
}
Expand Down

0 comments on commit 9e37b70

Please sign in to comment.