PPU rendering?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

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

Re: PPU rendering?

Post by tokumaru » Mon Aug 31, 2020 6:39 pm

Quietust wrote:
Mon Aug 31, 2020 6:21 pm
The reason they do it is for reasons of efficiency
Exactly. On real hardware, the logic for in_visible_frame_and_rendering is evaluated on every cycle.

Since you accused me of not knowing what I was talking about for not reading emulator sources, I went and checked Mesen's source code. Writes to $2001 appear to be processed by the SetMaskRegister method, which does check the sprite and background bits but doesn't check the scanline and doesn't modify the _renderingEnabled flag, it merely signals the need to update the PPU's state, which's done in the UpdateState, called from the Exec method.

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

Re: PPU rendering?

Post by tokumaru » Mon Aug 31, 2020 6:52 pm

Zepper wrote:
Mon Aug 31, 2020 6:26 pm
I'm working on this emulator since 1998 (and perhaps a bit before on my 33.6k dialup modem).
And I've written my first NES program around that time too, but what does that have to do with anything?
I'm not talking from (6502 ASM) software perspective.
Of course not, but it's not because I'm looking at the system from the other end that I don't know how it works. I won't be able to tell you about timing details of obscure edge cases and stuff like that, but something basic like the rules for rendering are very clear to me. I was just trying to help, but for some reason you decided to be rude to me (saying I didn't know what I was talking about), and even accused me of "disrupting the thread" or something to that effect. In the end you thanked Quietust, who basically confirmed what I said before (the flag is updated continuously, not on writes). I don't know what your beef with me is, but that will teach me to stay away from your posts.

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

Re: PPU rendering?

Post by Zepper » Mon Aug 31, 2020 7:26 pm

Quietust wrote:
Mon Aug 31, 2020 6:21 pm
The reason they do it is for reasons of efficiency - rather than checking if ((Reg2001 & 0x18) && (Scanline < 240)) before every single PPU cycle, they cache the result of that expression in a variable, updating it whenever any of the inputs change (i.e. whenever the scanline number changes or whenever the CPU writes to $2001).
It's updated in 3 cases:
1 - on cycle 0 of the pre-rendered scanline (checks last value written to $2001);
2 - on cycle 0 of the dummy scanline (sets the value to FALSE);
3 - on writes to $2001 (checks if BG/SPR enable bits + scanline between -1 and 240);

On case 3, I said that SMB3 never writes to $2001 during lines -1 to 240, making the value always set to FALSE. In fact, the game writes $00, then $1E various times for some reason. So, I took the conclusion that checking the state at $2001 write would be invalid/wrong time. At anyway, yes, it was only one game. :roll:

Post Reply