Background collision issue?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
fjsantosb
Posts: 5
Joined: Sun Jan 29, 2017 6:30 am

Background collision issue?

Post by fjsantosb »

Hi all,

I am working on a nes emulator from scratch (mainly for learning purposes) in javascript. I have build the cpu allready (it's seems to be Ok and have passed a few test for llegal opcodes); i have build the ppu too (almost 80%), and some games are fully playable right now (like Donkey Kong). But I have found some extrange behaviour in some games like 'Mario Bros' (not 'Super Mario Bros') or 'Pac-Man'. All seems to work properly, but the sprites (Mario and turtles), falls without collides with the background. I have check the sprite 0 hit collision on PPUSTATUS register and it's set to 0x40 (six bit) when a collision is detected between sprite and background (I have force the collision bit on this register all the time for test purposes, but nothing changes)... I wonder if there is another collision system / register that I am not implementing or if my sprite 0 hit collision is not implemented correctly.

I am stuck on that right now, any help will be appreciated.

Thanks in advance,

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

Re: Background collision issue?

Post by tokumaru »

Besides the sprite 0 hit, which is used exclusively for synchronizing the CPU and the PPU for raster effects, having nothing to do with in-game object collisions, the NES doesn't have any collision-related features.

AFAIK, all games handle collision entirely in software, meaning that there must be something wrong with your CPU emulation. I suggest logging all executed instructions and comparing the log to that of an emulator where the game works, so you can identify when things go wrong.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Background collision issue?

Post by thefox »

Make sure that you have correctly implemented nametable reads (via $2006/$2007).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Background collision issue?

Post by tokumaru »

Yes, it's possible that a game uses the name table data previously written to VRAM for collisions against the background, instead of a map in CPU RAM or ROM. Don't forget that reads from $2007 are buffered, so the CPU doesn't immediately get the byte from VRAM, it gets the buffered byte and the actual data from VRAM is buffered for the NEXT read. This is true for all of VRAM/ROM except for the palette RAM, which returns values without any delay (on PPUs that support pallets read back, early revisions didn't).

EDIT: I might have confused palette readback and OAM readback. I'm not sure if palette readback was broken on early PPUs (I'm pretty sure that OAM readback was though), so I'm crossing that part out. It'd be nice if someone could confirm this readback deal.
Last edited by tokumaru on Sun Jan 29, 2017 12:37 pm, edited 1 time in total.
fjsantosb
Posts: 5
Joined: Sun Jan 29, 2017 6:30 am

Re: Background collision issue?

Post by fjsantosb »

Hi,

Thanks for help to solve the problem; the issue was effectively on the VRAM read (I was reading cpu memory not ppu memory which is where the background tiles are). Now all it's seems to work properly (and mario doesn't fall continously).

Thanks so much for the help!

Regards,
fjsantosb
Posts: 5
Joined: Sun Jan 29, 2017 6:30 am

Re: Background collision issue?

Post by fjsantosb »

By the way.

The trick was the buffered byte as mentioned by tokumaru; that it's seems a few more games works properly (like Pac-Man).

Thanks again,

Regards,
fjsantosb
Posts: 5
Joined: Sun Jan 29, 2017 6:30 am

Re: Background collision issue?

Post by fjsantosb »

Hi all,

I have another issue with the background collision. All seems to work great in games tested so far, but I found issues on 'Ice Climber' game; the player is falling on all the left edges of the level, as you can see in the attached picture (i add red circles on the places where player falls).

I have just implemented scroll y, but seems to work properly in the rest of the game but in the left edges.

Anyone can help?

Thanks in advance,

Regards,
Attachments
ice_climber.png
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: Background collision issue?

Post by Zepper »

Did you test your CPU with a test ROM?
fjsantosb
Posts: 5
Joined: Sun Jan 29, 2017 6:30 am

Re: Background collision issue?

Post by fjsantosb »

Yep, I tested and It's seem all OK.

All other games (collision), tested seems to work properly (like Mario Bros).

Regards,
Post Reply