From 1e6b99faa21da4908f67950976a597e19fe87ad2 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Sat, 28 Jan 2012 08:16:42 -0600 Subject: Updated program to support the -fo option - forces continuation of parsing past mus_end hg-commit-id: 595e13f32986 --- music/pokeredmusicdisasm/Parser.cpp | 28 +++++++++++++++++++++++++++- music/pokeredmusicdisasm/Parser.h | 4 ++++ music/pokeredmusicdisasm/main.cpp | 14 +++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/music/pokeredmusicdisasm/Parser.cpp b/music/pokeredmusicdisasm/Parser.cpp index b900b575..765766ec 100644 --- a/music/pokeredmusicdisasm/Parser.cpp +++ b/music/pokeredmusicdisasm/Parser.cpp @@ -10,6 +10,7 @@ Parser::Parser() filePos = 0; stop = false; stopAddress = 0; + force = false; } Parser::Parser(std::string filename) @@ -19,6 +20,7 @@ Parser::Parser(std::string filename) filePos = 0; stop = false; stopAddress = 0; + force = false; SetFilename(filename); } @@ -58,6 +60,16 @@ void Parser::SetStopAddress(unsigned int value) stopAddress = value; } +bool Parser::GetForce() +{ + return force; +} + +void Parser::SetForce(bool value) +{ + force = value; +} + string Parser::GetParsedAsm() { string tmpStr; @@ -139,14 +151,27 @@ void Parser::ParseNext() // Parses the block immidiately following 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; 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(i, true)) { @@ -236,7 +261,8 @@ void Parser::ParseNext() // Parses the block immidiately following if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes ParseData(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 diff --git a/music/pokeredmusicdisasm/Parser.h b/music/pokeredmusicdisasm/Parser.h index 9630a519..385195ec 100644 --- a/music/pokeredmusicdisasm/Parser.h +++ b/music/pokeredmusicdisasm/Parser.h @@ -41,6 +41,9 @@ public: unsigned int GetStopAddress(); void SetStopAddress(unsigned int value); + bool GetForce(); + void SetForce(bool value); + std::string GetParsedAsm(); // File Operations @@ -81,6 +84,7 @@ private: unsigned int fileLength; unsigned int filePos; bool stop; + bool force; // Optional Settings unsigned int stopAddress; diff --git a/music/pokeredmusicdisasm/main.cpp b/music/pokeredmusicdisasm/main.cpp index f486e28f..19d302b4 100644 --- a/music/pokeredmusicdisasm/main.cpp +++ b/music/pokeredmusicdisasm/main.cpp @@ -33,6 +33,7 @@ void PrintUsage() 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 @@ int main(int argc, char** argv) 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 @@ int main(int argc, char** argv) else Console::Ask("Offset: ", offset, ios_base::hex | ios_base::uppercase); // Get the stop parameter, this can be set with -s , --stop= (it must be set via args) - if(a.SearchKeys("s") != -1) a.GetValueC(a.SearchKeys("s"), offset, ios_base::hex | ios_base::uppercase, true); + if(a.SearchKeys("s") != -1) a.GetValueC(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()); -- cgit v1.2.3