Page 1 of 1

Background collision issue?

Posted: Sun Jan 29, 2017 6:39 am
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,

Re: Background collision issue?

Posted: Sun Jan 29, 2017 7:36 am
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.

Re: Background collision issue?

Posted: Sun Jan 29, 2017 7:43 am
by thefox
Make sure that you have correctly implemented nametable reads (via $2006/$2007).

Re: Background collision issue?

Posted: Sun Jan 29, 2017 8:02 am
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.

Re: Background collision issue?

Posted: Sun Jan 29, 2017 9:11 am
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,

Re: Background collision issue?

Posted: Sun Jan 29, 2017 11:37 am
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,

Re: Background collision issue?

Posted: Sat Feb 18, 2017 5:29 am
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,

Re: Background collision issue?

Posted: Sat Feb 18, 2017 5:37 am
by Zepper
Did you test your CPU with a test ROM?

Re: Background collision issue?

Posted: Sat Feb 18, 2017 6:46 am
by fjsantosb
Yep, I tested and It's seem all OK.

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

Regards,