Skip to content

Commit

Permalink
some new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Awuwunya committed Jan 4, 2019
1 parent 6d41f88 commit d899b48
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
16 changes: 9 additions & 7 deletions SMPS2ASMv2/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down
7 changes: 6 additions & 1 deletion SMPS2ASMv2/Parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "";
}
Expand Down
17 changes: 8 additions & 9 deletions SMPS2ASMv2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
37 changes: 24 additions & 13 deletions SMPS2ASMv2/S2AScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,26 +450,37 @@ private void ParseScript(string data, string[] args, int lnoffs, ref Stack<Scrip
string mac = line.Substring(1, idx >= 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;
Expand Down

0 comments on commit d899b48

Please sign in to comment.