$2007 read help

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
JSBryan
Posts: 3
Joined: Sat Oct 08, 2016 4:13 pm

$2007 read help

Post by JSBryan » Sun Nov 13, 2016 6:18 pm

I am having trouble getting the screen to display right if I increment vram address after a $2007 read.

If not increment vram address after read:
no_increment.png
If increment vram address after read:
increment.png
I know both screens are not right but it is worse if I increment vram address. Has anyone run into the same issue before?

zzo38
Posts: 1077
Joined: Mon Feb 07, 2011 12:46 pm

Re: $2007 read help

Post by zzo38 » Sun Nov 13, 2016 7:28 pm

Did you ensure to be incremented by 1 or 32 correctly? (I don't know if that will cause the problem here or not, but that is what I can think of right now.)
[url=gopher://zzo38computer.org/].[/url]

User avatar
rainwarrior
Posts: 8006
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: $2007 read help

Post by rainwarrior » Sun Nov 13, 2016 7:55 pm

Not directly about incrementing, but do you know that reads from $2007 (except the palette) are buffered? There is one byte of storage between the $2007 read and the result that gets loaded into your register, so you get the byte from the previous PPU address read, not the current one.

Some info here: Wiki: PPU registers

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

Re: $2007 read help

Post by Zepper » Mon Nov 14, 2016 5:15 am

rainwarrior wrote:Not directly about incrementing, but do you know that reads from $2007 (except the palette) are buffered? There is one byte of storage between the $2007 read and the result that gets loaded into your register, so you get the byte from the previous PPU address read, not the current one.

Some info here: Wiki: PPU registers
That... and probably wrong palette mirroring.

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

Re: $2007 read help

Post by tokumaru » Mon Nov 14, 2016 5:56 am

JSBryan wrote:I know both screens are not right but it is worse if I increment vram address.
It may look worse at first glance, but you can at least make out some of the game's title, which is completely absent in the other shot.

SMB is known for reading the title screen data from the CHR-ROM, and people get wrong at first for not implementing the 1-byte delay that exists when reading $2007. When the CPU reads $2007, it gets a buffered value, and the value at the location indicated by the VRAM address register gets loaded into the buffer, so it will be returned to the CPU on the *next* read. The only exception to this is when reading from the palette area, in which case values are returned immediately (the value in the mirrored name table underneath is still loaded into the buffer, though).

Another thing this game is famous for relying on is palette mirroring. If you don't get this right, you get those black boxes around stuff.

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: $2007 read help

Post by thefox » Mon Nov 14, 2016 4:21 pm

The first one is missing the "SUPER MARIO BROS" logo, hinting that the reads are not working correctly.

Second one has a space after each character, hinting that the writes are incrementing the PPU address twice.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

JSBryan
Posts: 3
Joined: Sat Oct 08, 2016 4:13 pm

Re: $2007 read help

Post by JSBryan » Sat Nov 19, 2016 4:51 pm

Thank you all for your helps. It turns out and correct me if I am wrong. We are supposed to increment VRAM address only once PER instruction. Before the fix I incremented VRAM address after each read or write. So I actually incremented it twice in one instruction. I also fixed the palette issue and now it looks fine.
title.png

User avatar
rainwarrior
Posts: 8006
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: $2007 read help

Post by rainwarrior » Sat Nov 19, 2016 4:54 pm

Some instructions (e.g. STA (ptr), Y) do cause two increments.

Info: viewtopic.php?p=101286#p101286

Post Reply