Donkey Kong Land shakes horizontally [solved]

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Donkey Kong Land shakes horizontally [solved]

Post by zeroone »

I noticed this issue in several GB emulators, including one that I am attempting to code. The player select screen shakes horizontally and the same thing happens during game play. It seems like every other frame it out of alignment. If anyone has seen this issue before, perhaps you can provide me with a few hints to track this down? Thanks.
Last edited by zeroone on Mon Nov 27, 2017 12:12 pm, edited 1 time in total.
nitro2k01
Posts: 252
Joined: Sat Aug 28, 2010 9:01 am

Re: Donkey Kong Land shakes horizontally

Post by nitro2k01 »

Can you give an example of an emulator (other than yours) which exhibits this behavior?

Looking at the code, from 5AF2 and forward there's some code that seems to be related to camera panning. It later writes to FFAB which in turn is I'm going to go out on a limb and say that your bug is related to how flags are affected by the rr, sra, add or adc instructions.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Donkey Kong Land shakes horizontally

Post by zeroone »

nitro2k01 wrote:Can you give an example of an emulator (other than yours) which exhibits this behavior?

Looking at the code, from 5AF2 and forward there's some code that seems to be related to camera panning. It later writes to FFAB which in turn is I'm going to go out on a limb and say that your bug is related to how flags are affected by the rr, sra, add or adc instructions.
I saw a similar effect in JavaBoy. It's an old emulator, but it used to be hosted on many web pages. Whatever it is doing wrong, I'm doing the same thing incorrectly.

I reviewed the flags in those instructions and I can't visually see an issue. However, I did notice what appears to be a repeated typo in the Gameboy CPU (LR35902) instruction set table; the carry flag is marked as reset in all the SRA instructions. My emulator is setting the carry flag to the LSB.

If there is a particular test ROM that could vet the instruction flags, I'll gladly run it.

I noticed a similar issue with Street Fighter 2. Both of those are SGB roms. I'm not sure if there is a connection.
SuperWill24
Posts: 33
Joined: Sat May 13, 2017 7:54 pm

Re: Donkey Kong Land shakes horizontally

Post by SuperWill24 »

zeroone wrote:I noticed this issue in several GB emulators, including one that I am attempting to code. The player select screen shakes horizontally and the same thing happens during game play. It seems like every other frame it out of alignment. If anyone has seen this issue before, perhaps you can provide me with a few hints to track this down? Thanks.
What do you mean? There's no player select...
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Donkey Kong Land shakes horizontally

Post by zeroone »

SuperWill24 wrote:What do you mean? There's no player select...
After the title screen, there is a screen where you can select your player (your save game slot). That selection screen shakes horizontally.

In fact, the whole games seems like it is running at half speed. It's almost like it renders the frame correctly and then it re-renders it a second time with the wrong scroll offset.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Donkey Kong Land shakes horizontally [solved]

Post by zeroone »

[solved]

The problem was related to LYC. The wiki says that LYC and related registers "can be accessed even during Mode 3, but they have no effect until the end of the current scanline." To postpone the effect of LYC updates, I introduced a cached LYC variable and my buggy code was using the cached value instead of the latest during VBLANK.

On a side note, I suspect that updating LYC actually takes effect immediately since writing to LYC can trigger an LCD STAT interrupt. And, as such, I got rid of the cached version entirely.
Post Reply