News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Gameboy Disassembly  (Read 699 times)

Oracle451

  • Newbie
  • *
  • Posts: 1
    • View Profile
Gameboy Disassembly
« on: April 20, 2018, 10:10:39 pm »
Hi guys,

Can anyone point me in the direction of a good tutorial on Gameboy disassembly?

Most info out there seems to be "oh yeah use BGB" without any more info on how to do it.

Ideally I'd like to be able to write a disassembler from scratch with Python or something. I really just want to learn the process for making one so I can go write one myself.

FAST6191

  • Hero Member
  • *****
  • Posts: 2384
    • View Profile
Re: Gameboy Disassembly
« Reply #1 on: April 21, 2018, 10:25:35 am »
http://bgb.bircd.org/pandocs.htm#cpuregistersandflags
http://imrannazar.com/GameBoy-Z80-Opcode-Map

Your basic disassembler will blindly convert binary to opcodes using the info contained in the links above.

More advanced ones will start adding in pseudo instructions and the ability to set reference values for memory
I don't have a good one for GB/GBC right now but generally if you have something like copy into memory FFFF and your commands are only 16 bits long you are not going to do it all in one opcode. Your (dis)assembler can happily do either a shift or a rotate to get things where they need to be and then a second instruction to fill the remaining bits, more useful in an assembler but worth knowing about.
Equally if said location is known it is nicer to type #health_location than it is #C0F0 or something, especially as it will then throw an error if you type #health_lcoation but blindly carry on should you put #C0E0. It also helps with branches -- if you find the routine for game and note it over then scanning through the game if it branches to #game_over_routine then you can play with that if it is what you are doing.
If your system does not have a NOP then you might with to try detecting them.
If you want to do bounds checking ( http://bgb.bircd.org/pandocs.htm#memorymap ) then you can do that too.
After that you can then start going into https://www.hex-rays.com/products/ida/ and https://rada.re/r/ territory if you like but that is all you if so.

jonahstrix

  • Jr. Member
  • **
  • Posts: 22
    • View Profile
Re: Gameboy Disassembly
« Reply #2 on: July 12, 2018, 04:56:43 pm »
I don't know if you'll be back here but I ran into the same problem. This seemed to be the most thorough guide for getting started. I recommend starting on page 61.

http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf