jorotroid
Member
Intro
During the recent drama, I learned about the fact that you can import/export labels in Mesen's Debugger. Rather than looking to swap out ASM6 with ASM6f and risk introducing unknown bugs, I elected take a different route and write a script that scrapes the label data from the file demo.txt. demo.txt is a file that gets created each time you export and contains the entire assembly code of your game along with which address each line of code is located at. I have been using this file to manually look up what each variable and label were as I was debugging, but now you can use this script to automatically fill in (most of) those labels!
Instructions
There are three files in the zip file: TestBat.bat, ExtractLabels.bat and le.ps1. le.ps1 is the actually script, while ExtractLabels.bat and TestBat.bat are two different ways of running this script.
-First extract and place le.ps1 in your GameEngineData folder (where the demo.txt file is located).
-Now you have the option to either put ExtractLabels.bat or TestBat.bat in that folder. Replace the TestBat.bat that us already in the folder with my copy to automatically create the game.mlb file every time you export your game (this will add a few seconds to the export process). Or you can just bring over ExtractLabels.bat and whenever you feel like creating a label file, you can double click on this and it will create the game.mlb file.
-Once you are in Mesen, you can open up the Debugger and go to File>Workspace>Import Labels and import the game.mlb file. Now the code should get populated with the appropriate labels.
-If you want Mesen to automatically load up the game.mlb file, go to File>Workspace and make sure "Auto-load DGB/MLB files" is checked.
Known Limitations
There are some imperfections, however. The script has trouble with 2 types of labels and will skip them:
1. If the label didn't have a ':' at the end of it. There are only a few of these in the code, and I did't want to spend more time to take them into account.
2. If the label was made inside of a Macro.
Finally, one more limitation: the way Mesen sees addresses changes depending on which bank is loaded. So if you are browsing through the code in the debugger, you might run into some addresses that are either not labeled or mislabeled. But if you pause the code at those locations, the appropriate label should appear at that time. That said, this is probably the most likely cause for error on my part, so let me know if you come across a label that is wrong (as long as it's not one of the 3 types mentioned above).
Other Updates
It used to be that any "label+offest" wouldn't be recognized. I came up with sort of a solution to this. The '+' character is not allowed, so instead I used the '@'' character. So where you would see something like "temp16+1" in your code files, that will show up as a "temp16@1" in the debugger.
The original version missed the variables related to sound and maybe more. They are now included.
And that's it. I hope you find this useful. Let me know if you have any questions. Also if anyone can improve upon this, that is welcomed, too.
UPDATE for 4.1
This came up in the Facebook group, so I thought I would share the most up to date version of my label extractor. I haven't been keeping notes on what I changes I have been making to it, but it should be largely the same as previous versions. I don't remember now, but I think that maybe there were some changes between 4.0.11 and 4.1 that made the previous version of the extractor obselete for use with 4.1. For that reason I will keep the old version attached here for anyone still using older versions of NESmaker. One thing that I do know I added to this new version is support for extracting labels from more banks. The addressing of labels based on banks follows a pattern I haven't figured out yet, so I have just been adding support for banks once I start working in a bank only to discover the labels didn't import properly. Here is a list of the banks that I pretty sure should work fine: 14, 16, 17, 18, 1B, 1C, 1D, 1E, 1F
I also currently made it so labels will add a space and the bank number next to them, but label from Bank 1F will get a 1E next to it instead.
UPDATE Jan 14, 2020 - 4.1.1
Just checking to see if what I have in this thread is my most up to date version. Only a slight change: When adding a bank suffix to a label, it not puts an underscore between the label and the suffix instead of a space. This was due to an update with Mesen that seem to drop support for spaces in labels.