santiontanon / castlemaster2-disassembly

Disassembly of the original 1990 Castle Master II: The Crypt ZX Spectrum game

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: Castle Master

neuromancer opened this issue · comments

It seems likely that the same routines were reused from castle master. So I'm wondering how difficult will be to map the ones we have into a disassembly of the Castle Master for ZX. I personally do not care about adding comments to the data part (which will be different for sure), but everything else will be interesting to look (constant, differences between engines, etc).

That would be very interesting indeed! Do you know if anyone has tried to disassembler Castle Master 1 already? I wonder how easy/hard would it be to prepare some script that would automatically match the routines to see which match. Direct byte comparison to find common routines might not work since labels would be different, but perhaps something can be set up!

I'm wondering if the first part of the binary of Castle Master, up to starting with the data is very similar to Castle Master 2 (or even the same).

I'm taking a look at the disassembly of Dark Side and most of the functions look quite similar! (except for the game state, of course). Ghidra is actually quite good to decompile functions and identify parameters. For instance, it identified correctly the pointers in draw_string using the automatic analysis. I will continue matching the functions with your code and then get back to see how we can share the result.

Cool!! I have never used Ghidra before, but I should take a look! I did all mostly manually haha

In case you want to try Ghidra on Castle Master 2, there is a quick tutorial here:

  1. Install latest release of Ghidra (older versions had some annoying bugs, so very recommended to get 11.0.1)
  2. Get the Castle Master 2 executable from a tzx (e.g. tzxcat -b 5 CM2.TZX > CM2)
  3. Open Ghidra, create a new project and import CM2. As expected, it won't recognize the format, so select Z80 (default) from the list.
  4. Open the default tool, when asked for running the auto-analyze, say NO. We need to change the base address first
  5. Go to Window -> Memory Map. Select the only range, and click in the home button. Enter the base address: ram:6a00 and close the window.
  6. Time for Ghidra to do its magic: Open Analysis -> Auto Analyze ... (use the default options).
  7. After the analysis is done (it takes a few seconds), you should have most of the strings recognized, almost no invalid assembly (except self-modifying code) and the same labels between your annotated version.

Next steps: adjust function parameters and global memory addresses, but of course, you probably don't want to redo it for this game (except for parts you want see how Ghidra decompiled)