Has anyone tried to make a website specifically for revers engineered games?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Sat Jul 25, 2020 5:40 pm

I just finished a complete disassembly of Dragon Warrior 1 (https://github.com/nmikstas/dragon-warrior-disassembly). I really enjoyed doing it and was wondering if there is a site dedicated to the explanation and storage of reverse engineered games. Romhacking.net has some stuff but also has a lot of translations. I was thinking about a site with strict lint rules and folder structures for disassembled games to follow some kind of standard. I can't seem to find anything specifically. If it doesn't exist, would it be worth while to build something like that? If so, could legal things get the site in trouble? Since the games would not be functional without assembling it, maybe it would be ok? Any thought on this would be appreciated.

User avatar
Controllerhead
Posts: 97
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by Controllerhead » Sat Jul 25, 2020 7:09 pm

DirtyMcDingus wrote:
Sat Jul 25, 2020 5:40 pm
a site dedicated to the explanation and storage of reverse engineered games.
None exist specifically, to my knowledge. That would be awesome!
DirtyMcDingus wrote:
Sat Jul 25, 2020 5:40 pm
Romhacking.net has some stuff but also has a lot of translations.
That is probably the closest thing that exists right now. Besides the posted documents, there is a ton of info buried in forum posts as well as README's for specific game editing tools.

Other sites that exist are TCRF.net (The Cutting Room Floor), which contains info on unused assets within ROMs, and sometimes will have detailed information about specific code or ROM locations. tasvideos.org has robotic playthroughs done with emulator tools, usually as quick as possible, or sometimes just to be interesting or flashy, or both. There is info there as well. There are various speedrunning communities with detailed info about game mechanics on the speedrun.com forums, and sometimes their own sites. And, of course, the NESdev wiki has specific game info as well. There are also various fan sites like metroid2002 that have info, there are too many to name...
DirtyMcDingus wrote:
Sat Jul 25, 2020 5:40 pm
could legal things get the site in trouble? Since the games would not be functional without assembling it, maybe it would be ok? Any thought on this would be appreciated.
CHR data / graphics is a no-no. That is protected for sure. I think posting reverse engineered source code without is ok? I'm fairly sure "clean room" reverse engineered stuff, like your project, is kosher to possess and post.

You know, another huge nintendo leak happened yesterday and i've been reading the official source code for Super Mario Kart, what a world... I do think posting official source code that was not obtained legitimately can get you in hot water.
DirtyMcDingus wrote:
Sat Jul 25, 2020 5:40 pm
I just finished a complete disassembly of Dragon Warrior 1 (https://github.com/nmikstas/dragon-warrior-disassembly). I really enjoyed doing it and was wondering if there is
Nice job! I loved the SMB disassembly and even compiled it with labels w/ ASM6F and stepped it through the Mesen debugger. It was awesome! I'll be sure to check yours =)

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Sat Jul 25, 2020 8:57 pm

I think maybe this could be a site I create! I just took a full stack coding boot-camp with my brother and we've been itching for a cool project! One of the biggest things I think would need to be done is set standards for the way the disassembly needs to be formatted and commented, variable names, function names, etc. Also, standard file structures need to be specified along with makefile parameters. That would be something I would need a lot of help with from the community. Along with dragon warrior, I did disassemblies for Metroid(not complete), Star Wars arcade sound ROM and Asteroids arcade. I also started SMB but stopped after the sound engine when I realized someone else had already completed a full disassembly. I have developed a commenting style that is very descriptive and I am quite fond of it. It may not be the best way of doing it, however.

Also, I've been using Ophis for 6502 assembly but it has some problems (ADC $00B4,X assembles as ADC $B4,X, for example). Also, I would really like an assembler that has a linker to search for function names across memory banks. I don't know of any assemblers that do that. I was looking at the documentation for asm6f but it does not appear to support it. I may have to break down and write an assembler with all the options I want...unless someone knows where I can find what I'm looking for!

If anyone is interested in trying to define some standards for this type of thing, let me know!

User avatar
Controllerhead
Posts: 97
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by Controllerhead » Sat Jul 25, 2020 11:29 pm

Go for it! I would definitely post in the romhacking.net forums, i'm sure you could recruit some knowledgeable people who may have already done some decent work in dissecting several games. This site is geared more towards homebrew and emulator dev, generally.
DirtyMcDingus wrote:
Sat Jul 25, 2020 8:57 pm
ADC $00B4,X assembles as ADC $B4,X, for example).
That's quite expected, for the 6502 at least, just a zero page addressing optimization. If your assembler can't force absolute addressing in the syntax, you can always just reference the actual instruction byte, like .db $7D, $B4, $00 for ADC $00B4, X absolute. I use this site for quick reference.
https://www.masswerk.at/6502/6502_instruction_set.html
DirtyMcDingus wrote:
Sat Jul 25, 2020 8:57 pm
search for function names across memory banks.
Well, as far as raw ASM goes, there isn't really such thing as a "function". There is only JMP or JSR, jump or jump subroutine respectively; both goto a specific location but JSR pushes the return location on the stack to use with RTS. You can search for a JMP absolute or JSR byte and the address where a "function" starts, i suppose. For a JMP indirect from RAM though it would be much more tricky. ...I may not be sure what you're asking?
DirtyMcDingus wrote:
Sat Jul 25, 2020 8:57 pm
I may have to break down and write an assembler with all the options I want
ASM6F does include the C source code file, it's one file and a few thousand lines, if you want to poke around...

Anyway, what tools did you use to make this disassembly?

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Sun Jul 26, 2020 7:52 am

Yeah. I used a style like you mentioned (.byte $7D, $B4, $00) for the instructions that would not assemble properly. I suppose I really need to start using asm6f as it seems its the popular choice these days and has a lot more options.

For disassembly I used an online disassembler for the most part: https://www.masswerk.at/6502/disassembler.html

I then used regular expression search and replacement in Notepad++ to get the format the way I wanted it. For the large data tables (music and text) I wrote quick little Java programs to format and comment the raw hex data after I fully understood the data table formats. It would have been way too time consuming and error prone to do it by hand. I had to go in by hand and fix a lot of stuff. Dragon Warrior uses the BRK command to call an IRQ to run subroutines on different banks and has 1 or 2 data bytes after the BRK to indicate which subroutine and memory bank to use. This was really annoying to when it came to identifying and separating out data from code. It was very time consuming to manually review all the code and find these sections.

User avatar
Controllerhead
Posts: 97
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by Controllerhead » Sun Jul 26, 2020 12:39 pm

DirtyMcDingus wrote:
Sun Jul 26, 2020 7:52 am
Dragon Warrior uses the BRK command to call an IRQ to run subroutines on different banks and has 1 or 2 data bytes after the BRK to indicate which subroutine and memory bank to use ... It was very time consuming to manually review all the code and find these sections.
Ahhh, i see now. It's probably using the IRQ vector to call subroutines that replace the ROM bank it is currently using; BRK to a non-switched (or identical, if switched) part of ROM, switch bank, run the code, switch the bank back and RTI. I don't know if you could universally search for that in an assembler; there are a bunch of different ways to do it. To sniff those out, you could run it, set a break on interrupt in the Mesen debugger and see where it jumps to after. You might be able to write a LUA script to record that behavior and those bytes to sort it out. This would, of course, require the code to be running... Maybe write a LUA script and run a TAS movie from TASvideos and suck up all the function calls, that might work, i don't know, just spitballin' ideas here...
DirtyMcDingus wrote:
Sun Jul 26, 2020 7:52 am
asm6f ... Notepad++
This is what i use, besides a few nitpicks, i'm pretty happy with this setup. I did a few things to aid workflow. I have 6502 instruction keywords defined in the Style Configurator, a Run keyboard shortcut defined to run a .BAT file to trigger ASM6F, and if there are no errors, run Mesen with the compiled .nes file (w/ a Lua script).
Image

tepples
Posts: 22017
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by tepples » Sun Jul 26, 2020 6:09 pm

The closest that I'm aware of is Data Crystal, a game internals documentation wiki hosted by RomHacking.net.

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Mon Jul 27, 2020 3:00 pm

Oh yeah! I remember data crystal from back in the day. The Metroid disassembly I worked on is linked there. I was just browsing through it. This site is pretty close to what I had in mind. I was thinking something with a standardized rule set for a universal disassembly format. Data crystal is pretty cool though.

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Mon Jul 27, 2020 5:48 pm

@Controllerhead:
Finding the BRK commands wasn't the time sink. It was manually going in and fixing the disassembly because you have a BRK followed by 1 or 2 bytes of data to tell the bank switching subroutine which bank to switch to and what subroutine to run after switched. There are DOZENS of spots peppered throughout the Dragon Warrior code that uses the BRK instruction to bank switch. In most games, the data tables are grouped together and a quick Java program can format the tables easily. Since Dragon warrior has these data bytes scattered all throughout the code, they can be seen by the assembler as an opcode and mess up the instructions that follow it. The only way to really fix it is by hand. For example, I'm working on Mike Tyson's Punchout now and I got the game engine bank to assemble properly in a day. I think it took about 2 weeks to get the game engine bank in Dragon Warrior to assemble properly just because of all the manual code/data disambiguation that has to be done. I've looked at the code for about a half dozen NES games and Dragon Warrior is the only one I've seen so far that uses the IRQ. Since Dragon Warrior is now a complete project, I hope I don't have to do that again anytime soon!

Dragon Warrior is weird. The other games I've looked at have some kind of state variables that keep track of what's happening in the game. they are fairly easy to follow and have a logical progression. Dragon Warrior is like a gigantic run-on sentence. If it were a C program, it would be filled with massive if else-if structures to check for every possible situation. Not sure if that makes sense but it definitely has a unique programming style.

User avatar
oRBIT2002
Posts: 622
Joined: Sun Mar 19, 2006 3:06 am
Location: Gothenburg/Sweden

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by oRBIT2002 » Tue Jul 28, 2020 12:50 pm

DirtyMcDingus wrote:
Sat Jul 25, 2020 5:40 pm
I just finished a complete disassembly of Dragon Warrior 1 (https://github.com/nmikstas/dragon-warrior-disassembly).
Perhaps slightly off-topic but how did your workflow look like when you did this?

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Tue Jul 28, 2020 7:58 pm

My workflow was pretty simple. I set up the folder structure as seen in the repository. I just used Notepad++ to do all my work. I would regularly run the build_script file. The build script assembles each of the 4 memory banks and then runs md5sum on the newly assembled banks and then on the original binaries and displays the hashes.

Sometimes if I couldn't figure out what a certain variable did, I would run the game in FCEUX and change things in the hex editor and observe the results.

DirtyMcDingus
Posts: 22
Joined: Sat Jul 25, 2020 5:31 pm

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by DirtyMcDingus » Tue Jul 28, 2020 8:00 pm

I forgot to mention I'm using a Windows machine. I run the script through Git bash.

User avatar
oRBIT2002
Posts: 622
Joined: Sun Mar 19, 2006 3:06 am
Location: Gothenburg/Sweden

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by oRBIT2002 » Wed Jul 29, 2020 2:56 am

I meant more like, how did you disassemble the entire game and figure out everything?

User avatar
Memblers
Site Admin
Posts: 3861
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by Memblers » Wed Jul 29, 2020 3:44 am

I've looked at the arcade disassemblies on here, there is more than that, though.
https://computerarcheology.com/

calima
Posts: 1158
Joined: Tue Oct 06, 2015 10:16 am

Re: Has anyone tried to make a website specifically for revers engineered games?

Post by calima » Wed Jul 29, 2020 10:19 am

oRBIT2002 wrote:
Wed Jul 29, 2020 2:56 am
I meant more like, how did you disassemble the entire game and figure out everything?
Slowly and painstakingly tends to be the answer :P

Post Reply