My Nes emulator causes the main character's body in Kung Fu to split in half?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
nesemu101
Posts: 5
Joined: Wed Dec 23, 2020 1:25 pm

My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by nesemu101 » Mon Jan 18, 2021 1:22 am

I've recently written my Nes emulator's ppu and almost every game(donkey kong, smb, ice climbers, balloon fight) runs fine except Kung Fu. Here's what happens to him:
Image
https://imgur.com/a/G4Chx8D

Does anyone have any idea as to what is causing this? I'm stuck and i can't find anything. Anything is appreciated.

User avatar
tokumaru
Posts: 11998
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by tokumaru » Mon Jan 18, 2021 1:46 am

The main character in this game is drawn with background tiles, not sprites, so the game need to change the scroll mid-frame in order to control the positions of the background and the player. The scroll split is supposed to happen much closer to the top of the screen, so maybe this is a timing issue?

nesemu101
Posts: 5
Joined: Wed Dec 23, 2020 1:25 pm

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by nesemu101 » Mon Jan 18, 2021 2:22 am

tokumaru wrote:
Mon Jan 18, 2021 1:46 am
The main character in this game is drawn with background tiles, not sprites, so the game need to change the scroll mid-frame in order to control the positions of the background and the player. The scroll split is supposed to happen much closer to the top of the screen, so maybe this is a timing issue?
Where exactly would be the first play i should start looking in my emulator for errors with the timing?

User avatar
tokumaru
Posts: 11998
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by tokumaru » Mon Jan 18, 2021 2:50 am

It could be a sprite 0 hit issue, or the execution time of the instructions. Are you keeping track of the CPU cycles relative to the PPU cycles? Many games will use timed code while the PPU is rendering in order to wait for specific moments and apply some sort of PPU effect, such as a scroll change, and for that to work you must make sure that the PPU and the CPU run in parallel, with each instruction taking the correct number of cycles to execute.

nesemu101
Posts: 5
Joined: Wed Dec 23, 2020 1:25 pm

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by nesemu101 » Tue Jan 19, 2021 1:43 am

tokumaru wrote:
Mon Jan 18, 2021 2:50 am
It could be a sprite 0 hit issue, or the execution time of the instructions. Are you keeping track of the CPU cycles relative to the PPU cycles? Many games will use timed code while the PPU is rendering in order to wait for specific moments and apply some sort of PPU effect, such as a scroll change, and for that to work you must make sure that the PPU and the CPU run in parallel, with each instruction taking the correct number of cycles to execute.
0x3000-0x3eff is a mirror of 0x2000-0x2eff
does that mean data written to 0x3000 - 0x3eff is also written to 0x2000-0x2eff?

Myself086
Posts: 52
Joined: Sat Nov 10, 2018 2:49 pm

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by Myself086 » Tue Jan 19, 2021 7:59 am

nesemu101 wrote:
Tue Jan 19, 2021 1:43 am
0x3000-0x3eff is a mirror of 0x2000-0x2eff
does that mean data written to 0x3000 - 0x3eff is also written to 0x2000-0x2eff?
Yes and I didn't know about this mirror, thanks. My NES emulator doesn't support it. Data at this range isn't "also" written to the other range, mirrors work by masking part of the address during access.

As for the scrolling split, the one between HUD and play field is done with sprite 0. The next 2 are timed by the CPU relative to where sprite 0 hit. It's hard to tell exactly what's wrong in this screenshot.

How many CPU cycles do you emulate per scan line?
How do you count CPU cycles?

User avatar
Zepper
Formerly Fx3
Posts: 3223
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by Zepper » Thu Jan 21, 2021 2:37 pm

How many CPU cycles do you emulate per scan line?
How do you count CPU cycles?
For each CPU access (read/write), the NTSC PPU runs for 3 cycles, or 341 PPU cycles per scanline, or 113.6 CPU cycles.

unregistered
Posts: 1126
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: My Nes emulator causes the main character's body in Kung Fu to split in half?

Post by unregistered » Mon Jan 25, 2021 5:49 pm

nesemu101 wrote:
Tue Jan 19, 2021 1:43 am
tokumaru wrote:
Mon Jan 18, 2021 2:50 am
It could be a sprite 0 hit issue, or the execution time of the instructions. Are you keeping track of the CPU cycles relative to the PPU cycles? Many games will use timed code while the PPU is rendering in order to wait for specific moments and apply some sort of PPU effect, such as a scroll change, and for that to work you must make sure that the PPU and the CPU run in parallel, with each instruction taking the correct number of cycles to execute.
0x3000-0x3eff is a mirror of 0x2000-0x2eff
does that mean data written to 0x3000 - 0x3eff is also written to 0x2000-0x2eff?
nesemu101, next time, if your response has nothing to do with a quoted post, please don’t quote the post. :) I was utterly confused as why you thought tokumaru’s post meant data written to 0x3000 - 0x3eff is also written to 0x2000-0x2eff.

If you want tokumaru to respond to a new question, you might try thanking him for his crucial help and THEN ask your new question. :)

Post Reply