Thursday 12 June 2014

One last subtle bug

I found the bug I mentioned in the next-to-last post, namely the guard dropping the gold in the wrong place right at the end of the 3rd demo level. I actually found it quite quickly - yet another missing piece of code! Although guards always drop the gold when falling into a hole, they also drop them under other conditions - at least when the code to do so has actually been written! Doh!

So having fixed the "last" bug I fired up the demo's again side-by-side - only to notice that the guards were re-spawning in different places at the end of the 3rd level. Since the whole game is deterministic (otherwise the demo wouldn't run) this can only mean a bug in my port. Damn!

After an hour or two of debugging I've discovered that the game state is out of sync somewhere in the first demo level, between the time the 1st guard is killed to the time the 2nd is killed. I know this because the re-spawn column, which is incremented every main in-game loop, is wrong for the 2nd guard. This can only be the case if the guard movements (guard state update) are inaccurate. Further debugging reveals that the state of the 3rd guard is wrong by the time the 2nd guard is killed.

Further debugging has thus far been fruitless but I'm yet to exhaust all avenues - it's just very, very late now and time to get to bed. One area of possibility I've yet to explore is the AI... and I'm not looking forward to that. So I'll continue when I next get the chance.

The one positive to come out of all of this is that, by the time I've found this bug, I can be 99.9% sure that all of the game logic has been ported accurately. The demo mode has been an invaluable tool in that regard!

Wish me luck!

2 comments:

  1. MAME (and I assume MESS) has some tracing facilities that may be of use. In the simplest case you could have it dump full instruction traces of the original and your port. A little post-processing to line up common routines should be able to track down a divergence.

    I think it may be possible to have MAME/MESS log state when the PC reaches specified watchpoints. Attaching state logging to some particular routine could give a much simpler trace for comparison purposes.

    Might be easier than checking by hand, but sometimes there's nothing for it but elbow grease. Either way, good luck!

    ReplyDelete
  2. The 'state' of the game is more-or-less contained in a couple of small tables in a single block of memory, plus a couple of zero-page registers. So some sort of process that could trace these values for each platform and compare side-by-side would be just perfect.

    I've been using the MAME/MESS debugger for over a decade now so I'm reasonably familiar with the feature set, though it's only recently that I've been experimenting with the more advanced features, such as watchpoint triggers that can evaluate expressions (execute commands). I'm not exactly sure whether it can be coaxed to dump memory segments, but I'll certainly be exploring these possibilities.

    My next plan of attack was to trace the changes on a single zero-page register, as it may give me enough information. But I won't know until I try...

    Good to know we're thinking along the same lines!

    ReplyDelete