From 6703a9e210958551c97f29b1071bf2de407a6478 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Wed, 25 Jan 2012 11:37:08 -0600 Subject: [PATCH 1/7] Finished MeetProfOak Channel 1 Music Data hg-commit-id: 7771e5004979 --- music.asm | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/music.asm b/music.asm index 66882c54..e7e7ad0d 100644 --- a/music.asm +++ b/music.asm @@ -5261,7 +5261,84 @@ branch_aee1: ;Meet Prof. Oak MeetProfOak_md_1: ;AF59 - AFA8 -INCBIN "baserom.gbc",$af59,$afa9 - $af59 + ; AF59 + mus_tempo 0, 112 + mus_volume 119 + mus_duty duty75 + db $E8 + mus_vel 11, 4 + + mus_octave oct2 + mus_note noteF#, note16 + mus_note noteB, note16 + + mus_octave oct3 + mus_note noteD#, note16 + mus_note noteE, note16 + mus_note noteF#, note2_4 + mus_vel 10, 2 + + mus_octave oct2 + mus_note noteE, note4_8 + mus_note noteB, note2_8 + mus_note noteE, note4_8 + mus_note noteB, note2_8 + mus_note noteE, note4_8 + mus_note noteD#, note4 + mus_note noteF#, note8 + mus_note noteF#, note4 + mus_note noteE, note4_8 + mus_note noteD#, note4 + mus_note noteF#, note8 + mus_note noteF#, note4 + mus_note noteE, note4_8 + mus_note noteB, note2_8 + mus_note noteE, note4_8 + mus_note noteB, note2_8 + mus_note noteE, note4_8 + mus_note noteD#, note4 + mus_note noteF#, note8 + mus_note noteF#, note4 + mus_note noteE, note4_8 + mus_note noteD#, note4 + mus_note noteF#, note8 + mus_note noteF#, note4 + +branch_af85: + mus_note noteF#, note4_8 + mus_note noteE, note4 + mus_note noteA, note8 + mus_note noteA, note4 + mus_note noteF#, note4_8 + mus_note noteE, note4 + mus_note noteA, note8 + mus_note noteA, note4 + mus_note noteF#, note4_8 + mus_note noteE, note4 + mus_note noteG#, note8 + mus_note noteG#, note4 + mus_note noteF#, note4_8 + mus_note noteE, note4 + mus_note noteG#, note8 + mus_note noteG#, note4 + mus_note noteE, note4_8 + mus_note noteD#, note4 + mus_note noteF#, note8 + mus_note noteF#, note4 + mus_note noteE, note4_8 + mus_note noteD#, note4 + mus_note noteF#, note8 + mus_note noteF#, note4 + mus_note noteF#, note4_8 + mus_note noteE, note4 + mus_note noteG#, note8 + mus_note noteG#, note4 + mus_note noteF#, note4_8 + mus_note noteE, note4 + mus_note noteG#, note8 + mus_note noteG#, note4 + mus_jump 0, branch_af85 + ; AFA8 MeetProfOak_md_2: ;AFA9 - B03D INCBIN "baserom.gbc",$afa9,$b03d - $afa9 From 25e09f50668a6a90620522bacd9bfaba2b6f6ee5 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Wed, 25 Jan 2012 12:03:51 -0600 Subject: [PATCH 2/7] Finished MeetProfOak Channel 3 Music Data hg-commit-id: c9d95def0a7f --- music.asm | 393 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 391 insertions(+), 2 deletions(-) diff --git a/music.asm b/music.asm index e7e7ad0d..fd0a1915 100644 --- a/music.asm +++ b/music.asm @@ -5341,10 +5341,399 @@ branch_af85: ; AFA8 MeetProfOak_md_2: ;AFA9 - B03D -INCBIN "baserom.gbc",$afa9,$b03d - $afa9 + ; AFA9 + mus_mod 8, 1, 1 + mus_duty duty50 + mus_vel 12, 4 + + mus_octave oct2 + mus_note noteB, note16 + + mus_octave oct3 + mus_note noteD#, note16 + mus_note noteF#, note16 + mus_note noteA#, note16 + mus_note noteB, note2_4 + mus_vel 11, 2 + + mus_octave oct2 + mus_note noteB, note8 + + mus_octave oct3 + mus_note noteC#, note8 + mus_note noteD#, note8 + mus_note noteE, note4 + mus_note noteD#, note8 + mus_note noteC#, note4 + mus_vel 6, 4 + + mus_octave oct3 + mus_note noteB, note8 + + mus_octave oct4 + mus_note noteC#, note8 + mus_note noteD#, note8 + mus_note noteE, note4 + mus_note noteD#, note8 + mus_note noteC#, note4 + mus_vel 11, 2 + + mus_octave oct2 + mus_note noteB, note8 + mus_note noteA, note8 + mus_note noteG#, note8 + mus_note noteA, note4 + mus_note noteB, note8 + mus_note noteB, note4 + mus_vel 8, 1 + + mus_octave oct3 + mus_note noteB, note8 + mus_note noteA, note8 + mus_note noteG#, note8 + mus_note noteA, note4 + mus_note noteB, note8 + mus_note noteB, note4 + mus_vel 11, 2 + + mus_octave oct2 + mus_note noteB, note8 + + mus_octave oct3 + mus_note noteC#, note8 + mus_note noteD#, note8 + mus_note noteE, note4 + mus_note noteD#, note8 + mus_note noteC#, note4 + mus_vel 6, 4 + + mus_octave oct3 + mus_note noteB, note8 + + mus_octave oct4 + mus_note noteC#, note8 + mus_note noteD#, note8 + mus_note noteE, note4 + mus_note noteD#, note8 + mus_note noteC#, note4 + mus_vel 11, 2 + + mus_octave oct2 + mus_note noteB, note8 + mus_note noteA, note8 + mus_note noteG#, note8 + mus_note noteA, note4 + mus_note noteB, note8 + mus_note noteB, note4 + mus_vel 8, 1 + + mus_octave oct3 + mus_note noteB, note8 + mus_note noteA, note8 + mus_note noteG#, note8 + mus_note noteA, note4 + mus_note noteB, note8 + mus_note noteB, note4 + mus_vel 11, 5 + +branch_b005: + mus_octave oct3 + mus_note noteC#, note4_8 + + mus_octave oct2 + mus_note noteA, note16 + + mus_octave oct3 + mus_note noteC#, note16 + mus_note noteE, note4_8 + mus_note noteC#, note16 + mus_note noteE, note16 + mus_note noteF#, note4 + mus_note noteE, note4 + mus_note noteD#, note4 + mus_note noteC#, note4 + + mus_octave oct2 + mus_note noteB, note4_8 + mus_note noteG#, note16 + mus_note noteB, note16 + + mus_octave oct3 + mus_note noteE, note2 + mus_vel 6, 5 + + mus_octave oct3 + mus_note noteB, note4_8 + mus_note noteG#, note16 + mus_note noteB, note16 + + mus_octave oct4 + mus_note noteE, note2 + mus_vel 11, 5 + + mus_octave oct2 + mus_note noteA, note4_8 + mus_note noteF#, note16 + mus_note noteA, note16 + + mus_octave oct3 + mus_note noteD#, note2 + mus_note noteE, note4 + mus_note noteD#, note4 + mus_note noteC#, note4 + mus_note noteC, note4 + + mus_octave oct2 + mus_note noteB, note4_8 + mus_note noteG#, note16 + mus_note noteB, note16 + + mus_octave oct3 + mus_note noteE, note4_8 + + mus_octave oct2 + mus_note noteB, note16 + + mus_octave oct3 + mus_note noteE, note16 + mus_vel 11, 7 + mus_note noteG#, note1 + mus_jump 0, branch_b005 + ; B03C MeetProfOak_md_3: ;B03D - B11F -INCBIN "baserom.gbc",$b03d,$b120 - $b03d + ; B03D + mus_vel 1, 2 + mus_note noteRst, note2_8 + + mus_octave oct3 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteC#, note16 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteB, note16 + mus_note noteRst, note4_16 + + mus_octave oct4 + mus_note noteE, note4 + mus_note noteRst, note4_8 + + mus_octave oct3 + mus_note noteB, note16 + mus_note noteRst, note4_16 + + mus_octave oct4 + mus_note noteE, note4 + + mus_octave oct3 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteC#, note16 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteE, note16 + mus_note noteRst, note16 + mus_note noteA, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteG, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + +branch_bobc: + mus_octave oct3 + mus_note noteA, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteC#, note16 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteA, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteC#, note16 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteA, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteC#, note16 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteA, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteC#, note16 + mus_note noteRst, note16 + mus_jump 2, branch_bobc + +branch_b0d8: + mus_octave oct3 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_jump 2, branch_b0d8 + +branch_b0ed: + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteA, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteA, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteA, note16 + mus_note noteRst, note16 + mus_note noteF#, note16 + mus_note noteRst, note16 + mus_note noteA, note16 + mus_note noteRst, note16 + mus_jump 2, branch_b0ed + +branch_b101: + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_note noteG#, note16 + mus_note noteRst, note16 + mus_note noteB, note16 + mus_note noteRst, note16 + mus_jump 2, branch_b101 + mus_jump 0, branch_bobc + mus_tempo 0, 100 + mus_jump 0, $7123 + ; B11F ;Meet Rival MeetRival_md_1: ;B120 - B1BA From bf1968297996fa8e2a5f004d60b83e516840a632 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Thu, 26 Jan 2012 06:22:29 -0600 Subject: [PATCH 3/7] Made several large upgrades to Music Disassembler hg-commit-id: 0b180a6e2ec5 --- music/pokeredmusicdisasm/AbstractData.h | 6 +- music/pokeredmusicdisasm/Parser.cpp | 200 +++++++++++++++--------- music/pokeredmusicdisasm/Parser.h | 37 +++-- music/pokeredmusicdisasm/UnkCode.cpp | 67 ++++++++ music/pokeredmusicdisasm/UnkCode.h | 29 ++++ music/pokeredmusicdisasm/UnkEB.cpp | 69 ++++++++ music/pokeredmusicdisasm/UnkEB.h | 29 ++++ 7 files changed, 348 insertions(+), 89 deletions(-) create mode 100644 music/pokeredmusicdisasm/UnkCode.cpp create mode 100644 music/pokeredmusicdisasm/UnkCode.h create mode 100644 music/pokeredmusicdisasm/UnkEB.cpp create mode 100644 music/pokeredmusicdisasm/UnkEB.h diff --git a/music/pokeredmusicdisasm/AbstractData.h b/music/pokeredmusicdisasm/AbstractData.h index 2a9fbbaf..0b49255d 100644 --- a/music/pokeredmusicdisasm/AbstractData.h +++ b/music/pokeredmusicdisasm/AbstractData.h @@ -10,11 +10,11 @@ public: AbstractData(); virtual std::string GenAsm(); // Generate Assembly Output - virtual bool IsValid(unsigned char* byte); // Check for byte validity virtual bool Parse(unsigned char* byte); // Parse Given Data - virtual unsigned int Arguments(); // Number of arguments taken + virtual bool GetError(); // Get Error (No Write, Error is read only) - virtual bool GetError(); // Get Error (No Write, Error is read only) + virtual bool IsValid(unsigned char* byte); // Check for byte validity + virtual unsigned int Arguments(); // Number of arguments taken protected: bool error; // Whether there's an error in parsing or not diff --git a/music/pokeredmusicdisasm/Parser.cpp b/music/pokeredmusicdisasm/Parser.cpp index 9fa0af7f..4878ee10 100644 --- a/music/pokeredmusicdisasm/Parser.cpp +++ b/music/pokeredmusicdisasm/Parser.cpp @@ -18,6 +18,7 @@ Parser::Parser(std::string filename) fileLength = 0; filePos = 0; stop = false; + stopAddress = 0; SetFilename(filename); } @@ -87,6 +88,8 @@ void Parser::Read() // Read filedata tmpFile.read(rawBytes, fileLength); tmpFile.close(); + + rawBytesFixed = (unsigned char*)rawBytes; } // Code Operations @@ -96,114 +99,165 @@ void Parser::Parse(unsigned int offset) ParseNext(); } +template +bool Parser::ParseData(unsigned int& pos, bool reado) +{ + // Create the class to use if correct and a dummy class for validating + T* tmpC = 0; + T dummy; + + // If the bytes are this data type then create and save it + if(dummy.IsValid(&rawBytesFixed[pos])) + { + // Ensure this whole opperation isn't read-only (just peeking) + if(!reado) + { + // Initialize the class + tmpC = new T(&rawBytesFixed[pos]); + + // Push it onto the stack and it's assembly generation onto the output class + parsedBytes.push_back(tmpC); // + parsedString.push_back(tmpC->GenAsm()); + + // If the class had any arguments, increment the counter that much forward + pos += tmpC->Arguments(); + } + return true; // Let the code know this class was valid + } + + return false; // Let the code know this class wasn't valid +} + void Parser::ParseNext() // Parses the block immidiately following { stringstream tmpStr; - unsigned char* rawBytesFixed = (unsigned char*)rawBytes; stop = false; // Smart generation - bool indent = false; - bool firstNonNote = false; // First byte wasn't a note or octacve switch, add ";Setup" comment - bool firstNote = false; // First note or octave + 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; stringstream pos; pos << "; " << hex << uppercase << (unsigned int)filePos; parsedString.push_back(pos.str()); + unsigned int count = 1; // Counter for processed instructions for(unsigned int i = filePos; (i <= fileLength) && (stop == false); i++) { - // There's a way to make this block shorter but for now it does it's job + // First peek to see what kind of data it is, then perform any pre and post setup + if(ParseData(i, true)) + { + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes - // Check to see if it's the correct data type and if so then use it - if(tmpCall.IsValid(&rawBytesFixed[i])) // Should have made IsValid static + ParseData(i); + lDataType = DATA_CALL; + } + else if(ParseData(i, true)) { - // Call data type + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes - // Create data type then move the increment pointer further up as needed - parsedBytes.push_back(new Call(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpCall.Arguments(); // should have made Arguments static + ParseData(i); + lDataType = DATA_DUTY; + } + else if(ParseData(i, true)) + { + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes - Call* _tmp = (Call*)parsedBytes[parsedBytes.size() - 1]; + ParseData(i); + lDataType = DATA_JUMP; } - else if(tmpDuty.IsValid(&rawBytesFixed[i])) + else if(ParseData(i, true)) { - // Duty data type - parsedBytes.push_back(new Duty(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpDuty.Arguments(); - } - else if(tmpJump.IsValid(&rawBytesFixed[i])) - { - // Jump data type - parsedBytes.push_back(new Jump(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpJump.Arguments(); + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes - Jump* _tmp = (Jump*)parsedBytes[parsedBytes.size() - 1]; + ParseData(i); + lDataType = DATA_MODULATION; } - else if(tmpModulation.IsValid(&rawBytesFixed[i])) + else if(ParseData(i, true)) { - // Modulation data type - parsedBytes.push_back(new Modulation(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpModulation.Arguments(); - } - else if(tmpNote.IsValid(&rawBytesFixed[i])) - { - // Note data type - parsedBytes.push_back(new Note(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpNote.Arguments(); - } - else if(tmpOctave.IsValid(&rawBytesFixed[i])) - { - // Octave data type - parsedBytes.push_back(new Octave(&rawBytesFixed[i])); - parsedString.push_back("\n" + parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpOctave.Arguments(); - } - else if(tmpStop.IsValid(&rawBytesFixed[i])) - { - // Stop data type - parsedBytes.push_back(new Stop(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpStop.Arguments(); + // Insert a newline after certain types + if((lDataType == DATA_UNKCODE) || + (lDataType == DATA_UNKEB)) parsedString.push_back("\n"); - stop = true; // Stop all further processing, we've reached the end of the song + // If the previous item was a rest note then insert a new line + else if(lDataType == DATA_NOTE) + { + Note* _tmpNote = (Note*)parsedBytes[parsedBytes.size() - 1]; + if(_tmpNote->GetPitch() == _tmpNote->noteRst) parsedString.push_back("\n"); + } + + ParseData(i); + + // Further indent each note + parsedString[parsedString.size() - 1] = "\t" + parsedString[parsedString.size() - 1]; + lDataType = DATA_NOTE; } - else if(tmpTempo.IsValid(&rawBytesFixed[i])) + else if(ParseData(i, true)) { - // Tempo data type - parsedBytes.push_back(new Tempo(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpTempo.Arguments(); + // Insert new-line if previous line isn't a newline + if(parsedString[parsedString.size() - 1] != "\n") parsedString.push_back("\n"); + + ParseData(i); + lDataType = DATA_OCTAVE; } - else if(tmpVelocity.IsValid(&rawBytesFixed[i])) + else if(ParseData(i, true)) { - // Velocity data type - parsedBytes.push_back(new Velocity(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpVelocity.Arguments(); + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes + + ParseData(i); + lDataType = DATA_TEMPO; } - else if(tmpVolume.IsValid(&rawBytesFixed[i])) + else if(ParseData(i, true)) { - // Volume data type - parsedBytes.push_back(new Volume(&rawBytesFixed[i])); - parsedString.push_back(parsedBytes[parsedBytes.size() - 1]->GenAsm()); - i += tmpVolume.Arguments(); + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes + + ParseData(i); + lDataType = DATA_VELOCITY; + } + else if(ParseData(i, true)) + { + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes + + ParseData(i); + lDataType = DATA_VOLUME; + } + else if(ParseData(i, true)) // The opcode is 0xEB which is unknown and takes a 1-byte argument + { + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes + + ParseData(i); + lDataType = DATA_UNKEB; + } + else if(ParseData(i, true)) + { + 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 + lDataType = DATA_STOP; } else { - // Unknown code - stringstream unkCode; - short tmpByte = (short)rawBytesFixed[i]; - unkCode << "db $" << hex << uppercase << (short)rawBytesFixed[i]; - parsedString.push_back(unkCode.str()); + if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes + + ParseData(i); // The opcode is unknown - process the raw byte and move on + lDataType = DATA_UNKCODE; + } + + // Put everything tabbed over at least 1 time to fix some weird RGBDS bug by pre-pending a tab character + parsedString[parsedString.size() - 1] = "\t" + parsedString[parsedString.size() - 1]; + + // Append File Position in hexidecimal at end of line every 5 instructions + if((count % 5) == 0) + { + stringstream _tmpCount; + _tmpCount << hex << uppercase << i; + parsedString[parsedString.size() - 1] = parsedString[parsedString.size() - 1] + "; " + _tmpCount.str(); } filePos = i; + count++; // If the stop address parameter is set, break when we get there if( (stopAddress != 0) && (i >= stopAddress) ) break; diff --git a/music/pokeredmusicdisasm/Parser.h b/music/pokeredmusicdisasm/Parser.h index 515d07ad..20af39a7 100644 --- a/music/pokeredmusicdisasm/Parser.h +++ b/music/pokeredmusicdisasm/Parser.h @@ -13,11 +13,12 @@ #include "Modulation.h" #include "Note.h" #include "Octave.h" -#include "Parser.h" #include "Stop.h" #include "Tempo.h" #include "Velocity.h" #include "Volume.h" +#include "UnkCode.h" +#include "UnkEB.h" // This is the final class, it takes all of the data types, abstract class, and helper functions and uses them // for parsing @@ -49,30 +50,40 @@ public: void Parse(unsigned int offset); void ParseNext(); // Parses the block immidiately following + // Templates + template + bool ParseData(unsigned int& pos, bool reado = false); + + const enum dataType : unsigned char + { + DATA_NA, + DATA_CALL, + DATA_DUTY, + DATA_JUMP, + DATA_MODULATION, + DATA_NOTE, + DATA_OCTAVE, + DATA_STOP, + DATA_TEMPO, + DATA_UNKCODE, + DATA_UNKEB, + DATA_VELOCITY, + DATA_VOLUME + }; + private: std::string filename; std::vector parsedBytes; std::vector parsedString; char* rawBytes; + unsigned char* rawBytesFixed; unsigned int fileLength; unsigned int filePos; bool stop; // Optional Settings unsigned int stopAddress; - - // A lot of tmp classes - Call tmpCall; - Duty tmpDuty; - Jump tmpJump; - Modulation tmpModulation; - Note tmpNote; - Octave tmpOctave; - Stop tmpStop; - Tempo tmpTempo; - Velocity tmpVelocity; - Volume tmpVolume; }; #endif \ No newline at end of file diff --git a/music/pokeredmusicdisasm/UnkCode.cpp b/music/pokeredmusicdisasm/UnkCode.cpp new file mode 100644 index 00000000..93c74f66 --- /dev/null +++ b/music/pokeredmusicdisasm/UnkCode.cpp @@ -0,0 +1,67 @@ +#include + +#include "Call.h" +#include "Duty.h" +#include "Jump.h" +#include "Modulation.h" +#include "Note.h" +#include "Octave.h" +#include "Stop.h" +#include "Tempo.h" +#include "Velocity.h" +#include "Volume.h" + +#include "UnkCode.h" + +using namespace std; + +UnkCode::UnkCode() +{ + code = 0; +} + +UnkCode::UnkCode(unsigned char* byte) +{ + code = 0; + Parse(byte); +} + +UnkCode::UnkCode(unsigned char code, bool) +{ + SetCode(code); +} + +// Getters / Setters +unsigned char UnkCode::GetCode() +{ + return code; +} + +void UnkCode::SetCode(unsigned char value) +{ + code = value; +} + +// Re-implemented +string UnkCode::GenAsm() +{ + stringstream tmpAsmOut; + tmpAsmOut << "db $" << hex << (short)code; + return tmpAsmOut.str(); +} + +bool UnkCode::Parse(unsigned char* byte) +{ + code = byte[0]; + return true; +} + +bool UnkCode::IsValid(unsigned char* byte) +{ + return true; +} + +unsigned int UnkCode::Arguments() +{ + return 0; +} \ No newline at end of file diff --git a/music/pokeredmusicdisasm/UnkCode.h b/music/pokeredmusicdisasm/UnkCode.h new file mode 100644 index 00000000..28204448 --- /dev/null +++ b/music/pokeredmusicdisasm/UnkCode.h @@ -0,0 +1,29 @@ +#ifndef UNKCODE_H +#define UNKCODE_H + +#include "AbstractData.h" + +// Represents an unknown opcode +class UnkCode : public AbstractData +{ +public: + // Constructors + UnkCode(); + UnkCode(unsigned char* byte); // Parse Immidiately + UnkCode(unsigned char code, bool); // Set Value + + // Getters / Setters + unsigned char GetCode(); + void SetCode(unsigned char value); + + // Re-implemented + virtual std::string GenAsm(); + virtual bool Parse(unsigned char* byte); + virtual bool IsValid(unsigned char* byte); + virtual unsigned int Arguments(); + +private: + unsigned char code; +}; + +#endif \ No newline at end of file diff --git a/music/pokeredmusicdisasm/UnkEB.cpp b/music/pokeredmusicdisasm/UnkEB.cpp new file mode 100644 index 00000000..c8db595f --- /dev/null +++ b/music/pokeredmusicdisasm/UnkEB.cpp @@ -0,0 +1,69 @@ +#include + +#include "Call.h" +#include "Duty.h" +#include "Jump.h" +#include "Modulation.h" +#include "Note.h" +#include "Octave.h" +#include "Stop.h" +#include "Tempo.h" +#include "Velocity.h" +#include "Volume.h" + +#include "UnkEB.h" + +using namespace std; + +UnkEB::UnkEB() +{ + param = 0; +} + +UnkEB::UnkEB(unsigned char* byte) +{ + param = 0; + Parse(byte); +} + +UnkEB::UnkEB(unsigned char code, bool) +{ + SetParam(code); +} + +// Getters / Setters +unsigned char UnkEB::GetParam() +{ + return param; +} + +void UnkEB::SetParam(unsigned char value) +{ + param = value; +} + +// Re-implemented +string UnkEB::GenAsm() +{ + stringstream tmpAsmOut; + tmpAsmOut << hex << "db $" << (short)0xEB << ", $" << (short)param; + return tmpAsmOut.str(); +} + +bool UnkEB::Parse(unsigned char* byte) +{ + param = byte[1]; + return true; +} + +bool UnkEB::IsValid(unsigned char* byte) +{ + if(byte[0] == 0xEB) return true; + else return false; +} + +unsigned int UnkEB::Arguments() +{ + // 1 1-Byte param + return 1; +} \ No newline at end of file diff --git a/music/pokeredmusicdisasm/UnkEB.h b/music/pokeredmusicdisasm/UnkEB.h new file mode 100644 index 00000000..ab11a655 --- /dev/null +++ b/music/pokeredmusicdisasm/UnkEB.h @@ -0,0 +1,29 @@ +#ifndef UNKEB_H +#define UNKEB_H + +#include "AbstractData.h" + +// Represents an unknown opcode +class UnkEB : public AbstractData +{ +public: + // Constructors + UnkEB(); + UnkEB(unsigned char* byte); // Parse Immidiately + UnkEB(unsigned char code, bool); // Set Value + + // Getters / Setters + unsigned char GetParam(); + void SetParam(unsigned char value); + + // Re-implemented + virtual std::string GenAsm(); + virtual bool Parse(unsigned char* byte); + virtual bool IsValid(unsigned char* byte); + virtual unsigned int Arguments(); + +private: + unsigned char param; +}; + +#endif \ No newline at end of file From 000b0f74b3576fe317f9782bd67a00868b8034d8 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Thu, 26 Jan 2012 07:05:20 -0600 Subject: [PATCH 4/7] Finsihed MeetRival Channel 1 Music Data and made some improvements to Music Disassembler hg-commit-id: 1dcd37dff2f3 --- music.asm | 172 +++++++++++++++++++++++++++- music/pokeredmusicdisasm/Parser.cpp | 4 +- 2 files changed, 174 insertions(+), 2 deletions(-) diff --git a/music.asm b/music.asm index fd0a1915..49ce3038 100644 --- a/music.asm +++ b/music.asm @@ -5737,7 +5737,177 @@ branch_b101: ;Meet Rival MeetRival_md_1: ;B120 - B1BA -INCBIN "baserom.gbc",$b120,$b1bb - $b120 +; B120 + mus_tempo 0, 112 + mus_volume 119 + mus_duty duty75 + mus_mod 6, 3, 4 + db $e8; B12A + mus_vel 11, 3 + + mus_octave oct3 + mus_note noteD, note16 + mus_note noteC#, note16 + mus_note noteC, note16; B130 + + mus_octave oct2 + mus_note noteB, note16 + mus_note noteA#, note8 + mus_note noteA, note16 + mus_note noteG#, note16; B135 + mus_note noteG, note16 + mus_note noteF#, note16 + mus_note noteF, note4_8 + mus_note noteD, note16 + mus_note noteRst, note8_16; B13A + + mus_note noteD, note16 + mus_note noteRst, note4_16 + + mus_note noteA, note8 + mus_note noteG, note8 + mus_note noteA, note8; B13F + +branch_b140: + mus_note noteB, note4 + mus_note noteA#, note8 + mus_note noteA, note4 + mus_note noteG, note8 + + mus_octave oct3; B144 + mus_note noteC, note4 + mus_note noteD, note8 + mus_note noteRst, note4 + + mus_note noteD, note4 + mus_note noteC#, note8; B149 + mus_note noteC, note8 + + mus_octave oct2 + mus_note noteB, note8 + + mus_octave oct3 + mus_note noteC, note4; B14E + mus_note noteE, note8 + mus_note noteD, note4 + mus_note noteC, note8 + + mus_octave oct2 + mus_note noteB, note4; B153 + + mus_octave oct3 + mus_note noteC, note8 + mus_note noteRst, note4 + + mus_note noteG, note4 + mus_note noteG, note8; B158 + mus_note noteF#, note8 + mus_note noteE, note8 + mus_note noteD, note8 + mus_note noteF#, note8 + + mus_octave oct2; B15D + mus_note noteA, note8 + + mus_octave oct3 + mus_note noteD, note8 + mus_note noteF#, note8 + + mus_octave oct2; B162 + mus_note noteA, note8 + + mus_octave oct3 + mus_note noteD, note8 + + mus_octave oct2 + mus_note noteD, note8; B167 + + mus_octave oct3 + mus_note noteD, note8 + mus_note noteRst, note8 + + mus_octave oct2 + mus_note noteD, note8; B16C + + mus_octave oct3 + mus_note noteC, note4 + + mus_octave oct2 + mus_note noteB, note8 + mus_note noteA#, note8; B171 + mus_note noteB, note8 + + mus_octave oct3 + mus_note noteC, note8 + mus_note noteF, note8 + + mus_octave oct2; B176 + mus_note noteG, note8 + + mus_octave oct3 + mus_note noteC, note8 + mus_note noteF, note8 + mus_note noteD#, note8; B17B + mus_note noteC, note8 + + mus_octave oct2 + mus_note noteA#, note8 + mus_note noteG, note8 + mus_note noteRst, note4; B180 + + mus_note noteA#, note4 + + mus_octave oct3 + mus_note noteC, note8 + + mus_octave oct2 + mus_note noteA#, note8; B185 + + mus_octave oct3 + mus_note noteC, note8 + + mus_vel 11, 7 + + mus_octave oct2 + mus_note noteG, note4; B18B + mus_note noteD, note8 + mus_note noteF, note4_8 + mus_note noteF#, note4 + mus_note noteD, note8 + mus_note noteRst, note4; B190 + + mus_note noteD, note4 + + mus_vel 11, 3 + mus_note noteA, note8 + mus_note noteG, note8 + mus_note noteA, note8; B196 + + mus_jump 0, branch_b140 + mus_tempo 0, 100 + mus_jump 0, branch_b1a5 + mus_tempo 0, 112 + +branch_b1a5: + mus_volume 119; B1A6 + mus_duty duty75 + mus_mod 6, 3, 4 + db $e8 + mus_vel 11, 3 + + mus_octave oct2; B1AF + mus_note noteD, note16 + mus_note noteRst, note8_16 + + mus_note noteD, note16 + mus_note noteRst, note4_16 + + mus_note noteA, note8; B1B4 + mus_note noteG, note8 + mus_note noteA, note8 + + mus_jump 0, branch_b140 +; B1BA MeetRival_md_2: ;B1BB - B232 INCBIN "baserom.gbc",$b1bb,$b233 - $b1bb diff --git a/music/pokeredmusicdisasm/Parser.cpp b/music/pokeredmusicdisasm/Parser.cpp index 4878ee10..b900b575 100644 --- a/music/pokeredmusicdisasm/Parser.cpp +++ b/music/pokeredmusicdisasm/Parser.cpp @@ -64,7 +64,9 @@ string Parser::GetParsedAsm() for(unsigned int i = 0; i < parsedString.size(); i++) { - tmpStr += parsedString[i] + "\n"; + // Ensure each line isn't already a new-line, this prevents double or tripple empty lines from piling up + if(parsedString[i] != "\n") tmpStr += parsedString[i] + "\n"; + else tmpStr += parsedString[i]; } return tmpStr; From 76afbf6ca3efc219967b9ba0c0fa330e30fd66e9 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Thu, 26 Jan 2012 07:12:00 -0600 Subject: [PATCH 5/7] Finsihed MeetRival Channel 2 Music Data hg-commit-id: 835d7a180605 --- music.asm | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/music.asm b/music.asm index 49ce3038..37a84fe4 100644 --- a/music.asm +++ b/music.asm @@ -5910,7 +5910,138 @@ branch_b1a5: ; B1BA MeetRival_md_2: ;B1BB - B232 -INCBIN "baserom.gbc",$b1bb,$b233 - $b1bb +; B1BB + mus_duty duty75 + mus_mod 10, 2, 6 + mus_vel 12, 7 + + mus_octave oct3 + mus_note noteB, note16; B1C3 + mus_note noteA#, note16 + mus_note noteA, note16 + mus_note noteG#, note16 + mus_note noteG, note8 + mus_note noteF#, note16; B1C8 + mus_note noteF, note16 + mus_note noteE, note16 + mus_note noteD#, note16 + mus_note noteD, note4_8 + + mus_octave oct2; B1CD + mus_note noteG, note16 + mus_note noteRst, note8_16 + + mus_note noteG, note16 + mus_note noteRst, note8_16 + + mus_note noteD, note16; B1D2 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteD, note8 + mus_note noteF, note8 + mus_note noteF#, note8; B1D7 + +branch_b1d8: + mus_vel 12, 7 + mus_note noteG, note4 + mus_note noteD, note8 + mus_note noteF, note4_8 + mus_note noteF#, note4; B1DD + mus_note noteG, note8 + mus_note noteRst, note4 + + mus_note noteG, note4 + mus_note noteG, note8 + mus_note noteA#, note8; B1E2 + mus_note noteB, note8 + + mus_octave oct4 + mus_note noteC, note4 + + mus_octave oct3 + mus_note noteG, note8; B1E7 + mus_note noteA#, note4_8 + mus_note noteB, note4 + + mus_octave oct4 + mus_note noteC, note8 + mus_note noteRst, note4; B1EC + + mus_note noteC, note4 + mus_note noteC, note8 + + mus_octave oct3 + mus_note noteB, note8 + + mus_octave oct4; B1F1 + mus_note noteC, note8 + + mus_vel 11, 0 + mus_note noteD, note1 + + mus_vel 11, 5 + mus_note noteD, note4_8; B1F8 + + mus_vel 12, 7 + mus_note noteF, note4 + mus_note noteD, note8 + mus_note noteC, note8 + mus_note noteD, note8; B1FE + + mus_vel 11, 0 + mus_note noteC, note2 + + mus_vel 12, 7 + mus_note noteC, note2 + + mus_octave oct3; B205 + mus_note noteC, note8 + mus_note noteRst, note4 + + mus_note noteA#, note4 + mus_note noteG, note8 + mus_note noteF, note8; B20A + + mus_vel 11, 0 + mus_note noteG, note1 + + mus_vel 11, 3 + mus_note noteG, note8 + + mus_octave oct2; B211 + mus_note noteG, note8 + mus_note noteRst, note4 + + mus_note noteG, note4 + + mus_octave oct3 + mus_note noteD, note8; B216 + mus_note noteF, note8 + mus_note noteF#, note8 + + mus_jump 0, branch_b1d8 + mus_duty duty75 + mus_mod 10, 2, 6; B221 + mus_vel 12, 7 + + mus_octave oct2 + mus_note noteG, note16 + mus_note noteRst, note8_16 + + mus_note noteG, note16; B227 + mus_note noteRst, note8_16 + + mus_note noteD, note16 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteD, note8; B22C + mus_note noteF, note8 + mus_note noteF#, note8 + + mus_jump 0, branch_b1d8 +; B232 MeetRival_md_3: ;B233 - B3A6 INCBIN "baserom.gbc",$b233,$b3a7 - $b233 From c57d257243a214f269859439cbca46f55791e2e1 Mon Sep 17 00:00:00 2001 From: KuroiIeWa5Da Date: Thu, 26 Jan 2012 07:21:41 -0600 Subject: [PATCH 6/7] Finsihed MeetRival Channel 3 Music Data hg-commit-id: 7183c6c543c3 --- music.asm | 513 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 512 insertions(+), 1 deletion(-) diff --git a/music.asm b/music.asm index 37a84fe4..2e7bff8b 100644 --- a/music.asm +++ b/music.asm @@ -6044,7 +6044,518 @@ branch_b1d8: ; B232 MeetRival_md_3: ;B233 - B3A6 -INCBIN "baserom.gbc",$b233,$b3a7 - $b233 +; B233 + mus_vel 1, 4 + + mus_octave oct4 + mus_note noteD, note8 + mus_note noteRst, note8 + + mus_note noteC#, note8; B238 + mus_note noteRst, note8 + + mus_note noteC, note8 + mus_note noteRst, note8 + + mus_octave oct3 + mus_note noteB, note8; B23D + mus_note noteRst, note8 + + mus_note noteG, note16 + mus_note noteRst, note8_16 + + mus_note noteG, note16 + mus_note noteRst, note8_16; B242 + + mus_note noteG, note16 + mus_note noteRst, note16 + + mus_note noteG, note16 + mus_note noteRst, note16 + + mus_note noteG, note16; B247 + mus_note noteRst, note16 + + mus_note noteG, note16 + mus_note noteRst, note16 + +branch_b24b: + mus_note noteG, note8 + + mus_octave oct4; B24C + mus_note noteD, note8 + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteRst, note8 + + mus_octave oct4; B251 + mus_note noteD, note8 + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteRst, note8 + + mus_octave oct4; B256 + mus_note noteD, note8 + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteRst, note4 + + mus_octave oct4; B25B + mus_note noteD, note4 + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteA#, note8 + mus_note noteB, note8; B260 + mus_note noteG, note8 + + mus_octave oct4 + mus_note noteC, note8 + + mus_octave oct3 + mus_note noteG, note8; B265 + mus_note noteRst, note8 + + mus_octave oct4 + mus_note noteC, note8 + + mus_octave oct3 + mus_note noteG, note8; B26A + mus_note noteRst, note8 + + mus_note noteB, note8 + + mus_octave oct4 + mus_note noteC, note8 + mus_note noteRst, note4; B26F + + mus_note noteC, note4 + mus_note noteC, note8 + + mus_octave oct3 + mus_note noteB, note8 + mus_note noteA, note8; B274 + mus_note noteF#, note8 + mus_note noteA, note8 + mus_note noteRst, note8 + + mus_note noteF#, note8 + mus_note noteA, note8; B279 + mus_note noteF#, note8 + mus_note noteRst, note8 + + mus_note noteA, note8 + mus_note noteF#, note8 + mus_note noteA, note8; B27E + mus_note noteRst, note8 + + mus_note noteF#, note8 + mus_note noteA, note8 + mus_note noteF#, note8 + + mus_octave oct4; B283 + mus_note noteD, note8 + + mus_octave oct3 + mus_note noteA, note8 + mus_note noteE, note8 + + mus_octave oct4; B288 + mus_note noteC, note8 + mus_note noteRst, note8 + + mus_octave oct3 + mus_note noteE, note8 + + mus_octave oct4; B28D + mus_note noteC, note8 + + mus_octave oct3 + mus_note noteE, note8 + mus_note noteF, note8 + mus_note noteG, note8; B292 + mus_note noteE, note8 + mus_note noteRst, note4 + + mus_note noteE, note8 + + mus_octave oct4 + mus_note noteC, note8; B297 + + mus_octave oct3 + mus_note noteB, note8 + mus_note noteA#, note8 + mus_note noteA, note8 + mus_note noteG, note8; B29C + mus_note noteA#, note8 + mus_note noteRst, note8 + + mus_note noteG, note8 + mus_note noteA#, note8 + mus_note noteG, note8; B2A1 + mus_note noteRst, note8 + + mus_note noteA#, note8 + mus_note noteG, note8 + + mus_octave oct4 + mus_note noteD, note8; B2A6 + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteRst, note8 + + mus_octave oct4 + mus_note noteD, note8; B2AB + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteRst, note8 + + mus_octave oct4 + mus_note noteD, note8; B2B0 + + mus_jump 0, branch_b24b + mus_vel 1, 4 + + mus_octave oct3 + mus_note noteG, note16 + mus_note noteRst, note8_16; B2B9 + + mus_note noteG, note16 + mus_note noteRst, note8_16 + + mus_note noteG, note16 + mus_note noteRst, note16 + + mus_note noteG, note16; B2BE + mus_note noteRst, note16 + + mus_note noteG, note16 + mus_note noteRst, note16 + + mus_note noteG, note16 + mus_note noteRst, note16; B2C3 + + mus_jump 0, branch_b24b + db $f8 + mus_tempo 1, 0 + mus_volume 119 + mus_duty duty50; B2CF + db $d5 + + mus_note noteB, note8 + + mus_octave oct2 + mus_note noteA, note8 + mus_note noteA, note8; B2D4 + mus_note noteG, note8 + mus_note noteG, note8 + mus_note noteF, note8 + mus_note noteE, note8 + mus_note noteF, note8; B2D9 + mus_note noteA, note8 + + mus_octave oct3 + mus_note noteC, note4 + mus_note noteE, note4 + + mus_octave oct2; B2DE + mus_note noteF, note4 + + mus_end +; B2E0 + +; B2E1 +branch_b2e1: + db $f8 + mus_duty duty50 + db $d5 + + mus_note noteRst, note8_16 + + mus_octave oct4; B2E6 + mus_note noteF, note8 + mus_note noteE, note16 + mus_note noteRst, note16 + + mus_note noteD, note8 + mus_note noteC, note16; B2EB + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteA#, note8 + + mus_octave oct4 + mus_note noteC, note8; B2F0 + mus_note noteD, note8 + mus_note noteE, note8 + mus_note noteF, note4 + mus_note noteG, note4 + mus_note noteF, note4; B2F5 + + mus_end +; B2F6 + +; B2F7 +branch_b2f7: + db $f8 + db $d5 + + mus_note noteC#, note16 + + mus_octave oct4 + mus_note noteC, note16; B2FB + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteF, note8 + + mus_octave oct4 + mus_note noteC, note16; B300 + mus_note noteRst, note16 + + mus_octave oct3 + mus_note noteA#, note16 + mus_note noteRst, note16 + + mus_note noteA, note16; B305 + mus_note noteRst, note16 + + mus_note noteG, note16 + mus_note noteRst, note16 + + mus_note noteF, note16 + mus_note noteRst, note16; B30A + + mus_note noteE, note16 + mus_note noteRst, note16 + + mus_octave oct4 + mus_note noteF, note16 + mus_note noteRst, note8_16; B30F + + mus_note noteC, note16 + mus_note noteRst, note8_16 + + mus_octave oct3 + mus_note noteF, note8 + mus_note noteRst, note8; B314 + + mus_end +; B315 + +; B316 +branch_b316: + db $f8 + mus_tempo 1, 0 + mus_volume 119 + mus_duty duty50 + db $e8; B31E + db $d5 + + mus_note noteB, note4_16 + + mus_octave oct3 + mus_note noteD, note4 + mus_note noteC, note4; B323 + + mus_octave oct2 + mus_note noteA, note2 + + db $d5 + + mus_note noteB, note8_16 + + mus_octave oct3; B328 + mus_note noteD#, note8 + mus_note noteD#, note8 + mus_note noteD, note8 + mus_note noteC, note8 + mus_note noteC, note8; B32D + + mus_octave oct2 + mus_note noteA#, note8 + + db $d5 + + mus_note noteB, note4_16 + + mus_octave oct3; B332 + mus_note noteC, note2 + + mus_end +; B334 + +; B335 +branch_b335: + db $f8 + mus_mod 8, 2, 7 + mus_duty duty50 + db $d5 + + mus_note noteRst, note4_8; B33C + + mus_octave oct3 + mus_note noteA, note4 + mus_note noteF, note4 + mus_note noteC, note2 + + db $d5; B341 + + mus_note noteRst, note8_16 + + mus_note noteA#, note8 + mus_note noteA#, note8 + mus_note noteA#, note8 + mus_note noteG, note8; B346 + mus_note noteG, note8 + mus_note noteA#, note8 + + db $d5 + + mus_note noteRst, note4_16 + + mus_note noteA, note2; B34B + + mus_end +; B34C + +; B34D +branch_b34d: + db $f8 + db $d5 + + mus_note noteC#, note16 + + mus_octave oct4 + mus_note noteF, note4; B351 + mus_note noteD#, note4 + mus_note noteC, note2 + mus_note noteD#, note16 + mus_note noteRst, note16 + + mus_note noteD#, note16; B356 + mus_note noteRst, note16 + + mus_note noteE, note16 + mus_note noteRst, note16 + + mus_note noteF, note16 + mus_note noteRst, note16; B35B + + mus_note noteF, note16 + mus_note noteRst, note16 + + mus_note noteG, note16 + mus_note noteRst, note16 + + mus_note noteA, note2; B360 + + mus_end +; B361 + +; B362 +branch_b362: + db $f8 + mus_tempo 1, 0 + mus_volume 119 + mus_duty duty50 + db $e8; B36A + db $d5 + + mus_note noteA#, note4_16 + + mus_octave oct2 + mus_note noteA#, note4 + + db $d5; B36F + + mus_note noteB, note8 + + mus_octave oct3 + mus_note noteC, note8 + mus_note noteC, note16 + mus_note noteC, note16; B374 + + db $d5 + + mus_note noteA#, note4_16 + mus_note noteD#, note4 + + db $d5 + + mus_note noteB, note8; B379 + mus_note noteF, note8 + mus_note noteF, note16 + mus_note noteF, note16 + + db $d5 + + mus_note noteB, note4_16; B37E + mus_note noteA#, note2 + + mus_end +; B380 + +; B381 +branch_b381: + db $f8 + mus_mod 4, 2, 3 + mus_duty duty50 + db $d5 + db $d1; B388 + + mus_octave oct3 + mus_note noteG, note8 + mus_note noteG, note16 + mus_note noteG, note16 + + db $d5; B38D + + mus_note noteRst, note4_16 + + mus_note noteD#, note4 + + db $d5 + db $d1 + + mus_note noteG#, note8; B392 + mus_note noteG#, note16 + mus_note noteG#, note16 + mus_note noteA#, note8 + mus_note noteA#, note16 + mus_note noteA#, note16; B397 + + db $d5 + + mus_note noteRst, note4_16 + + mus_octave oct4 + mus_note noteD#, note2 + + mus_end; B39C +; B39C + +; B39D +branch_b39d: + db $f8 + db $d5 + + mus_note noteC#, note16 + + mus_octave oct3 + mus_note noteD#, note4; B3A1 + mus_note noteG#, note4 + mus_note noteG, note4 + mus_note noteF, note4 + mus_note noteD#, note2 + + mus_end; B3A6 +; B3A6 ;SS Anne SSAnne_md_1: ;B3A7 - B418 From 96db7d1cd78232f345eb74bc2c91ad5698d1b11f Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Thu, 26 Jan 2012 10:31:04 -0800 Subject: [PATCH 7/7] diasm of some bank 0 code (mostly menu related) hg-commit-id: f22d2b2ca017 --- constants.asm | 31 +++++ main.asm | 333 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 363 insertions(+), 1 deletion(-) diff --git a/constants.asm b/constants.asm index 56301a4b..8fab2fb9 100644 --- a/constants.asm +++ b/constants.asm @@ -89,9 +89,36 @@ TX_RAM: MACRO ; wram locations +; coordinates of the position of the cursor for the top menu item (id 0) +W_TOPMENUITEMY EQU $CC24 +W_TOPMENUITEMX EQU $CC25 + +; the id of the currently selected menu item +; the top item has id 0, the one below that has id 1, etc. +W_CURMENUITEMID EQU $CC26 + +; the tile that was behind the menu cursor's current location +W_TILEBEHINDCURSOR EQU $CC27 + +W_MAXMENUITEMID EQU $CC28 ; id of the bottom menu item + +W_MENUWATCHEDKEYS EQU $CC29 ; bit mask of keys that the menu will respond to + +W_OLDMENUITEMID EQU $CC2A ; id of previously selected menu item + +; how many times should HandleMenuInput poll the joypad state before it returns? +W_MENUJOYPADPOLLCOUNT EQU $CC34 + W_PLAYERMOVELISTINDEX EQU $CC2E W_PLAYERMONNUMBER EQU $CC2F +; the address of the menu cursor's current location within C3A0-C507 +W_MENUCURSORLOCATION EQU $CC30 ; 2 bytes + +; set to 1 if you can go from the bottom to the top or top to bottom of a menu +; set to 0 if you can't go past the top or bottom of the menu +W_MENUWRAPPINGENABLED EQU $CC4A + ; current HP of player and enemy substitutes W_PLAYERSUBSITUTEHP EQU $CCD7 W_ENEMYSUBSITUTEHP EQU $CCD8 @@ -699,6 +726,10 @@ W_BOXITEM50QTY EQU $D59E W_SAFARITIMER1 EQU $D70D ; use 01 for maximum W_SAFARITIMER2 EQU $D70E ; use F4 for maximum +; counters for blinking down arrow +H_DOWNARROWBLINKCNT1 EQU $FF8B +H_DOWNARROWBLINKCNT2 EQU $FF8C + ; Note: the following multiplication and division addresses are used for multiple purposes ; and so they overlap with each other diff --git a/main.asm b/main.asm index ea1eccf0..427c6b24 100644 --- a/main.asm +++ b/main.asm @@ -4847,7 +4847,338 @@ AddNTimes: ; 3A87 jr nz,.loop\@ ret -INCBIN "baserom.gbc",$3A8E,$3C49 - $3A8E +; Compare strings, c bytes in length, at de and hl. +; Often used to compare big endian numbers in battle calculations. +StringCmp: ; 3A8E + ld a,[de] + cp [hl] + ret nz + inc de + inc hl + dec c + jr nz,StringCmp + ret + +; INPUT: +; a = oam block index (each block is 4 oam entries) +; b = Y coordinate of upper left corner of sprite +; c = X coordinate of upper left corner of sprite +; de = base address of 4 tile number and attribute pairs +WriteOAMBlock: ; 3A97 + ld h,$c3 + swap a ; multiply by 16 + ld l,a + call .writeOneEntry\@ ; upper left + push bc + ld a,8 + add c + ld c,a + call .writeOneEntry\@ ; upper right + pop bc + ld a,8 + add b + ld b,a + call .writeOneEntry\@ ; lower left + ld a,8 + add c + ld c,a + ; lower right +.writeOneEntry\@ + ld [hl],b ; Y coordinate + inc hl + ld [hl],c ; X coordinate + inc hl + ld a,[de] ; tile number + inc de + ld [hli],a + ld a,[de] ; attribute + inc de + ld [hli],a + ret + +HandleMenuInput: ; 3ABE + xor a + ld [$d09b],a + +HandleMenuInputPokemonSelection: ; 3AC2 + ld a,[H_DOWNARROWBLINKCNT1] + push af + ld a,[H_DOWNARROWBLINKCNT2] + push af ; save existing values on stack + xor a + ld [H_DOWNARROWBLINKCNT1],a ; blinking down arrow timing value 1 + ld a,$06 + ld [H_DOWNARROWBLINKCNT2],a ; blinking down arrow timing value 2 +.loop1\@ + xor a + ld [$d08b],a ; counter for pokemon shaking animation + call PlaceMenuCursor + call Delay3 +.loop2\@ + push hl + ld a,[$d09b] + and a ; is it a pokemon selection menu? + jr z,.getJoypadState\@ + ld b,$1c + ld hl,$56ff ; shake mini sprite of selected pokemon + call Bankswitch +.getJoypadState\@ + pop hl + call GetJoypadStateLowSensitivity + ld a,[$ffb5] + and a ; was a key pressed? + jr nz,.keyPressed\@ + push hl + FuncCoord 18,11 ; coordinates of blinking down arrow in some menus + ld hl,Coord + call $3c04 ; blink down arrow (if any) + pop hl + ld a,[W_MENUJOYPADPOLLCOUNT] + dec a + jr z,.giveUpWaiting\@ + jr .loop2\@ +.giveUpWaiting\@ +; if a key wasn't pressed within the specified number of checks + pop af + ld [H_DOWNARROWBLINKCNT2],a + pop af + ld [H_DOWNARROWBLINKCNT1],a ; restore previous values + xor a + ld [W_MENUWRAPPINGENABLED],a ; disable menu wrapping + ret +.keyPressed\@ + xor a + ld [$cc4b],a + ld a,[$ffb5] + ld b,a + bit 6,a ; pressed Up key? + jr z,.checkIfDownPressed\@ +.upPressed\@ + ld a,[W_CURMENUITEMID] ; selected menu item + and a ; already at the top of the menu? + jr z,.alreadyAtTop\@ +.notAtTop\@ + dec a + ld [W_CURMENUITEMID],a ; move selected menu item up one space + jr .checkOtherKeys\@ +.alreadyAtTop\@ + ld a,[W_MENUWRAPPINGENABLED] + and a ; is wrapping around enabled? + jr z,.noWrappingAround\@ + ld a,[W_MAXMENUITEMID] + ld [W_CURMENUITEMID],a ; wrap to the bottom of the menu + jr .checkOtherKeys\@ +.checkIfDownPressed\@ + bit 7,a + jr z,.checkOtherKeys\@ +.downPressed\@ + ld a,[W_CURMENUITEMID] + inc a + ld c,a + ld a,[W_MAXMENUITEMID] + cp c + jr nc,.notAtBottom\@ +.alreadyAtBottom\@ + ld a,[W_MENUWRAPPINGENABLED] + and a ; is wrapping around enabled? + jr z,.noWrappingAround\@ + ld c,$00 ; wrap from bottom to top +.notAtBottom\@ + ld a,c + ld [W_CURMENUITEMID],a +.checkOtherKeys\@ + ld a,[W_MENUWATCHEDKEYS] + and b ; does the menu care about any of the pressed keys? + jp z,.loop1\@ +.checkIfAButtonOrBButtonPressed\@ + ld a,[$ffb5] + and a,%00000011 ; pressed A button or B button? + jr z,.skipPlayingSound\@ +.AButtonOrBButtonPressed\@ + push hl + ld hl,$cd60 + bit 5,[hl] + pop hl + jr nz,.skipPlayingSound\@ + ld a,$90 + call $23b1 ; play sound +.skipPlayingSound\@ + pop af + ld [H_DOWNARROWBLINKCNT2],a + pop af + ld [H_DOWNARROWBLINKCNT1],a ; restore previous values + xor a + ld [W_MENUWRAPPINGENABLED],a ; disable menu wrapping + ld a,[$ffb5] + ret +.noWrappingAround\@ + ld a,[$cc37] + and a ; should we return if the user tried to go past the top or bottom? + jr z,.checkOtherKeys\@ + jr .checkIfAButtonOrBButtonPressed\@ + +PlaceMenuCursor: ; 3B7C + ld a,[W_TOPMENUITEMY] + and a ; is the y coordinate 0? + jr z,.adjustForXCoord\@ + ld hl,$c3a0 + ld bc,20 ; screen width +.topMenuItemLoop\@ + add hl,bc + dec a + jr nz,.topMenuItemLoop\@ +.adjustForXCoord\@ + ld a,[W_TOPMENUITEMX] + ld b,$00 + ld c,a + add hl,bc + push hl + ld a,[W_OLDMENUITEMID] + and a ; was the previous menu id 0? + jr z,.checkForArrow1\@ + push af + ld a,[$fff6] + bit 1,a ; is the menu double spaced? + jr z,.doubleSpaced1\@ + ld bc,20 + jr .getOldMenuItemScreenPosition\@ +.doubleSpaced1\@ + ld bc,40 +.getOldMenuItemScreenPosition\@ + pop af +.oldMenuItemLoop\@ + add hl,bc + dec a + jr nz,.oldMenuItemLoop\@ +.checkForArrow1\@ + ld a,[hl] + cp a,$ed ; was an arrow next to the previously selected menu item? + jr nz,.skipClearingArrow\@ +.clearArrow\@ + ld a,[W_TILEBEHINDCURSOR] + ld [hl],a +.skipClearingArrow\@ + pop hl + ld a,[W_CURMENUITEMID] + and a + jr z,.checkForArrow2\@ + push af + ld a,[$fff6] + bit 1,a ; is the menu double spaced? + jr z,.doubleSpaced2\@ + ld bc,20 + jr .getCurrentMenuItemScreenPosition\@ +.doubleSpaced2\@ + ld bc,40 +.getCurrentMenuItemScreenPosition\@ + pop af +.currentMenuItemLoop\@ + add hl,bc + dec a + jr nz,.currentMenuItemLoop\@ +.checkForArrow2\@ + ld a,[hl] + cp a,$ed ; has the right arrow already been placed? + jr z,.skipSavingTile\@ ; if so, don't lose the saved tile + ld [W_TILEBEHINDCURSOR],a ; save tile before overwriting with right arrow +.skipSavingTile\@ + ld a,$ed ; place right arrow + ld [hl],a + ld a,l + ld [W_MENUCURSORLOCATION],a + ld a,h + ld [W_MENUCURSORLOCATION + 1],a + ld a,[W_CURMENUITEMID] + ld [W_OLDMENUITEMID],a + ret + +; Used when swapping positions of items in a list menu. +; The item that the user selects first is marked with an outline of a right arrow +; to distinguish it from the arrow being used to select the second item. +PlaceUnfilledArrowMenuCursor: ; 3BEC + ld b,a + ld a,[W_MENUCURSORLOCATION] + ld l,a + ld a,[W_MENUCURSORLOCATION + 1] + ld h,a + ld [hl],$ec ; outline of right arrow + ld a,b + ret + +; Replaces the menu cursor with a blank space. +EraseMenuCursor: ; 3BF9 + ld a,[W_MENUCURSORLOCATION] + ld l,a + ld a,[W_MENUCURSORLOCATION + 1] + ld h,a + ld [hl],$7f ; blank space + ret + +; This toggles a blinking down arrow at hl on and off after a delay has passed. +; This is often called even when no blinking is occurring. +; The reason is that most functions that call this initialize H_DOWNARROWBLINKCNT1 to 0. +; The effect is that if the tile at hl is initialized with a down arrow, +; this function will toggle that down arrow on and off, but if the tile isn't +; initliazed with a down arrow, this function does nothing. +; That allows this to be called without worrying about if a down arrow should +; be blinking. +HandleDownArrowBlinkTiming: ; 3C04 + ld a,[hl] + ld b,a + ld a,$ee ; down arrow + cp b + jr nz,.downArrowOff\@ +.downArrowOn\@ + ld a,[H_DOWNARROWBLINKCNT1] + dec a + ld [H_DOWNARROWBLINKCNT1],a + ret nz + ld a,[H_DOWNARROWBLINKCNT2] + dec a + ld [H_DOWNARROWBLINKCNT2],a + ret nz + ld a,$7f ; blank space + ld [hl],a + ld a,$ff + ld [H_DOWNARROWBLINKCNT1],a + ld a,$06 + ld [H_DOWNARROWBLINKCNT2],a + ret +.downArrowOff\@ + ld a,[H_DOWNARROWBLINKCNT1] + and a + ret z + dec a + ld [H_DOWNARROWBLINKCNT1],a + ret nz + dec a + ld [H_DOWNARROWBLINKCNT1],a + ld a,[H_DOWNARROWBLINKCNT2] + dec a + ld [H_DOWNARROWBLINKCNT2],a + ret nz + ld a,$06 + ld [H_DOWNARROWBLINKCNT2],a + ld a,$ee ; down arrow + ld [hl],a + ret + +; The following code either enables or disables the automatic drawing of +; text boxes by DisplayTextID. Both functions cause DisplayTextID to wait +; for a button press after displaying text (unless [$cc47] is set). + +EnableAutoTextBoxDrawing: ; 3C3C + xor a + jr AutoTextBoxDrawingCommon + +DisableAutoTextBoxDrawing: ; 3C3F + ld a,$01 + +AutoTextBoxDrawingCommon: ; 3C41 + ld [$cf0c],a ; control text box drawing + xor a + ld [$cc3c],a ; make DisplayTextID wait for button press + ret PrintText: ; 3C49 ; given a pointer in hl, print the text there