shithub: pokered

Download patch

ref: 1e6b99faa21da4908f67950976a597e19fe87ad2
parent: 436c486d95721a0a4a2b25730d0a36fc294e27ea
author: KuroiIeWa5Da <tyuki@adu.me>
date: Sat Jan 28 03:16:42 EST 2012

Updated program to support the -fo option - forces continuation of parsing past mus_end

hg-commit-id: 595e13f32986


--- a/music/pokeredmusicdisasm/Parser.cpp
+++ b/music/pokeredmusicdisasm/Parser.cpp
@@ -10,6 +10,7 @@
 	filePos = 0;
 	stop = false;
 	stopAddress = 0;
+	force = false;
 }
 
 Parser::Parser(std::string filename)
@@ -19,6 +20,7 @@
 	filePos = 0;
 	stop = false;
 	stopAddress = 0;
+	force = false;
 
 	SetFilename(filename);
 }
@@ -58,6 +60,16 @@
 	stopAddress = value;
 }
 
+bool Parser::GetForce()
+{
+	return force;
+}
+
+void Parser::SetForce(bool value)
+{
+	force = value;
+}
+
 string Parser::GetParsedAsm()
 {
 	string tmpStr;
@@ -139,6 +151,7 @@
 	bool firstNonNote = false;	// (unused so far)First byte wasn't a note or octacve switch, add ";Setup" comment
 	bool firstNote = false;	// (unused so far) First note or octave
 	unsigned char lDataType = DATA_NA;
+	bool newBranch = false;	// Create a new branch
 
 	stringstream pos;
 	pos << "; " << hex << uppercase << (unsigned int)filePos;
@@ -145,8 +158,20 @@
 	parsedString.push_back(pos.str());
 
 	unsigned int count = 1;	// Counter for processed instructions
+	newBranch = true;
 	for(unsigned int i = filePos; (i <= fileLength) && (stop == false); i++)
 	{
+		if(newBranch)
+		{
+			stringstream _tmpBr;
+			_tmpBr << "\n";
+			_tmpBr << "UnknSong_md_" << hex << i << ":";
+			parsedString.push_back(_tmpBr.str());
+
+			_tmpBr.str("");
+			newBranch = false;
+		}
+
 		// First peek to see what kind of data it is, then perform any pre and post setup
 		if(ParseData<Call>(i, true))
 		{
@@ -236,7 +261,8 @@
 			if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes
 
 			ParseData<Stop>(i);
-			stop = true; // Raise the stop flag informing the parser to stop
+			if(!force) stop = true; // Raise the stop flag informing the parser to stop
+			newBranch = true;
 			lDataType = DATA_STOP;
 		}
 		else
--- a/music/pokeredmusicdisasm/Parser.h
+++ b/music/pokeredmusicdisasm/Parser.h
@@ -41,6 +41,9 @@
 	unsigned int GetStopAddress();
 	void SetStopAddress(unsigned int value);
 
+	bool GetForce();
+	void SetForce(bool value);
+
 	std::string GetParsedAsm();
 
 	// File Operations
@@ -81,6 +84,7 @@
 	unsigned int fileLength;
 	unsigned int filePos;
 	bool stop;
+	bool force;
 
 	// Optional Settings
 	unsigned int stopAddress;
--- a/music/pokeredmusicdisasm/main.cpp
+++ b/music/pokeredmusicdisasm/main.cpp
@@ -33,6 +33,7 @@
 	Console::PrintLn("--offset, -o - the parameterized offset in hexidecimal, It tells the parser where to start parsing");
 	Console::PrintLn("--file, -f - the parameterized file path, It tells the parser which rom file to parse");
 	Console::PrintLn("--stop, -s - tells the parser to stop at that hexidecimal address or until it reaches mus_end.");
+	Console::PrintLn("-fo - must be used with --stop, forces the program to proceed on despite discovering any mus_end");
 	Console::PrintLn("help, --help, -h - prints this info and exits, if the bare parameter is used it must be the first parameter");
 }
 
@@ -51,6 +52,7 @@
 	string filePath = "";
 	unsigned int offset = 0;
 	unsigned int stop = 0;
+	bool force = false;
 
 	// Get the file path, this can be set with -f filename, --file=filename, arg #2, or missing (missing means default)
 	// the filepath can contain the actual filename or -- to use the built-in path, if the path is not missing then it must be set (can't be blank)
@@ -97,11 +99,21 @@
 	else Console::Ask<unsigned int>("Offset: ", offset, ios_base::hex | ios_base::uppercase);
 
 	// Get the stop parameter, this can be set with -s <offset>, --stop=<offset> (it must be set via args)
-	if(a.SearchKeys("s") != -1) a.GetValueC<unsigned int>(a.SearchKeys("s"), offset, ios_base::hex | ios_base::uppercase, true);
+	if(a.SearchKeys("s") != -1) a.GetValueC<unsigned int>(a.SearchKeys("s"), stop, ios_base::hex | ios_base::uppercase, true);
 	else if(a.SearchKeys("stop") != -1) filePath = a.GetValue(a.SearchKeys("stop"));
 
+	// Get the force parameter, this can be set with -f (it must be set via args)
+	if(a.SearchKeys("fo") != -1) force = true;
+
+	if((stop == 0) && (force == true))
+	{
+		Console::ErrorLn("Error! You set the force command but did not set the stop command, this means it will parse every line until the end of the rom.");
+		return 1;
+	}
+
 	Parser p(filePath);
 	if(stop != 0) p.SetStopAddress(stop);
+	if(force) p.SetForce(true);
 	p.Parse(offset);
 
 	Console::PrintLn(p.GetParsedAsm().c_str());