Weird timing issue?

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
Gideon Zhi
Newbie
Posts: 4
Joined: Sun Mar 20, 2011 12:00 am
Contact:

Weird timing issue?

Post by Gideon Zhi » Wed Aug 19, 2020 5:22 am

Hi folks,

I've put together a JP->EN translation of a Megadrive game. Can't talk too much about it, under NDA, but I've hit a really weird issue with what little of the code I changed. Execution hits a certain spot, the stack pointer gets offset by several bytes, the PC jumps to a completely different address, and the game crashes. But it only does this on accurate emulators like Bizhawk or Exodus; I developed using the tracing enabled version of Gens, which it *does* successfully work on.

Here's some traces of the old code vs the new code obtained with Bizhawk, showing where the issue happens after 10A80:
https://pastebin.com/HFzDBRLQ

And the code I actually wrote:
https://pastebin.com/90BsSRmh

Anything jump out that I'm doing obviously wrong?

Sik
Very interested
Posts: 934
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Weird timing issue?

Post by Sik » Wed Aug 19, 2020 7:11 am

Address error (trying to do a word or longword access on an odd address). Old emulators didn't emulate it, but newer emulators (and the real thing) will throw an address error exception when that happens.

The error seems to be at cmpi.w #-1, (A5) (with a5 = $10B27, which is odd), and a5 seems to have reached that value from move.b (A5)+, D0 earlier (where it read a single byte and hence moved from $10B26 to $10B27).
Sik is pronounced as "seek", not as "sick".

Gideon Zhi
Newbie
Posts: 4
Joined: Sun Mar 20, 2011 12:00 am
Contact:

Re: Weird timing issue?

Post by Gideon Zhi » Wed Aug 19, 2020 2:14 pm

Yeah, if I change the move.b to a move.w, the game no longer crashes (but it also no longer displays anything resembling text.) On the other hand, if I change the cmpi.w to a cmpi.b, it seems to work, so thanks! The game originally stored its text using 16-bit values; I switched it to 8-bit values so I could squeeze more text in.

This was done to minimize the amount of original code changed. Just so I'm sure I understand, this is happening because the compare operation is comparing an address expecting a word value but that the address isn't word-aligned?

Thanks so much for the help here!

Post Reply