Hi everyone,
Like many here, I am developing an NES emulator and I am now going forward with my PPU implementation (only BG for now). First of all, I would like to thank the
nesdev wiki contributors for the excellent work!
From my understanding, there are two 16-bit registers and two 8-bit shift registers used during background rendering:
1) One 16-bit reg which contains only high BG tile information with lower 8 bits to be rendered first
2) One 16-bit reg which contains only low BG tile information with lower 8 bits to be render first
3) One 8-bit shift reg containing the attributes of the first tile to be rendered
4) One 8-bit shift reg containing the attributes of the second tile to be rendered
I am not sure whether the above description is correct and would like some feedback.
Also, I am having trouble with some PPU timings, and I would like to check if my understanding is correct. I am following this great diagram as a reference:
http://wiki.nesdev.com/w/images/d/d1/Ntsc_timing.png
For the first tile, here's what happens:
- At cycle 321, an NT byte is placed in an internal latch
- At cycle 323, an AT byte is placed in an internal latch
- At cycle 325, low BG tile byte is placed in an internal latch
- At cycle 327, high BG tile byte is placed in an internal latch
- At cycle 329 (8 cycles later than first NT fetch), the AT byte and both low and high BG tiles are placed in corresponding shift registers (higher 8 bits for BG data).
While all this is happening, the existing contents of shift registers are shifted by one every cycle. Please correct me if I'm wrong.
Now the process continues for the second tile:
- Still at cycle 329, an NT byte is placed in an internal latch
- At cycle 331, an AT byte is placed in an internal latch
- At cycle 333, low BG tile byte is placed in an internal latch
- At cycle 335, high BG tile byte is placed in an internal latch
- At cycle 337 (8 cycles later than NT fetch), the AT byte and both low and high BG tiles are placed in corresponding shift registers (higher 8 bits for BG data).
As the first tile has been entirely shifted by then, the contents for the first tile are now present in the lower byte of the 16-bit register, and contents for the second one are placed on the higher bytes of these 16-bit registers. Again, I would like to verify if this is correct or not.
We now have data corresponding to the two first tiles to be drawn first on the next scanline. Do the shift registers STOP shifting at that point? As there are two unused fetches happening right after, I would assume they stop otherwise on-screen pixel data would be lost. Are the shifters only "shifting" between cycle 2 and cycle 256? Are they even shifting during cycles 321-336 or are the shift registers purely loaded during that time frame? The wiki (http://wiki.nesdev.com/w/index.php/PPU_rendering) mentions that every cycle, a bit is fetched from the 4 background shift registers in order to create a pixel on screen. The wiki also says that afterwards, the shift registers are shifted once, to the data for the next pixel. Every 8 cycles/shifts, new data is loaded into these registers. This information is a bit misleading to me, and I assume that shifting is not happening all the time, but I would like somebody to confirm when shifting exactly happens. I'm generally pretty confused also as to why the two 8-bit AT registers are shift register in the first place - are these also shifted by 1 bit every cycle? The diagram at the beginning of the PPU rendering wiki page is not perfectly straight-forward to me.
Now, regarding drawing - why would "4 background shift registers" (mentioned in the wiki) be needed for drawing one pixel? I assume only three would be needed (low BG, high BG, and one AT byte corresponding to the tile pixel you are rendering). Is this correct?
I think that's all the questions I have for now! I'm sorry for the long post, I just want to make sure I follow the original design as close as I can. Looking forward to your replies.
Regards,
Sebastien
Like many here, I am developing an NES emulator and I am now going forward with my PPU implementation (only BG for now). First of all, I would like to thank the
nesdev wiki contributors for the excellent work!
From my understanding, there are two 16-bit registers and two 8-bit shift registers used during background rendering:
1) One 16-bit reg which contains only high BG tile information with lower 8 bits to be rendered first
2) One 16-bit reg which contains only low BG tile information with lower 8 bits to be render first
3) One 8-bit shift reg containing the attributes of the first tile to be rendered
4) One 8-bit shift reg containing the attributes of the second tile to be rendered
I am not sure whether the above description is correct and would like some feedback.
Also, I am having trouble with some PPU timings, and I would like to check if my understanding is correct. I am following this great diagram as a reference:
http://wiki.nesdev.com/w/images/d/d1/Ntsc_timing.png
For the first tile, here's what happens:
- At cycle 321, an NT byte is placed in an internal latch
- At cycle 323, an AT byte is placed in an internal latch
- At cycle 325, low BG tile byte is placed in an internal latch
- At cycle 327, high BG tile byte is placed in an internal latch
- At cycle 329 (8 cycles later than first NT fetch), the AT byte and both low and high BG tiles are placed in corresponding shift registers (higher 8 bits for BG data).
While all this is happening, the existing contents of shift registers are shifted by one every cycle. Please correct me if I'm wrong.
Now the process continues for the second tile:
- Still at cycle 329, an NT byte is placed in an internal latch
- At cycle 331, an AT byte is placed in an internal latch
- At cycle 333, low BG tile byte is placed in an internal latch
- At cycle 335, high BG tile byte is placed in an internal latch
- At cycle 337 (8 cycles later than NT fetch), the AT byte and both low and high BG tiles are placed in corresponding shift registers (higher 8 bits for BG data).
As the first tile has been entirely shifted by then, the contents for the first tile are now present in the lower byte of the 16-bit register, and contents for the second one are placed on the higher bytes of these 16-bit registers. Again, I would like to verify if this is correct or not.
We now have data corresponding to the two first tiles to be drawn first on the next scanline. Do the shift registers STOP shifting at that point? As there are two unused fetches happening right after, I would assume they stop otherwise on-screen pixel data would be lost. Are the shifters only "shifting" between cycle 2 and cycle 256? Are they even shifting during cycles 321-336 or are the shift registers purely loaded during that time frame? The wiki (http://wiki.nesdev.com/w/index.php/PPU_rendering) mentions that every cycle, a bit is fetched from the 4 background shift registers in order to create a pixel on screen. The wiki also says that afterwards, the shift registers are shifted once, to the data for the next pixel. Every 8 cycles/shifts, new data is loaded into these registers. This information is a bit misleading to me, and I assume that shifting is not happening all the time, but I would like somebody to confirm when shifting exactly happens. I'm generally pretty confused also as to why the two 8-bit AT registers are shift register in the first place - are these also shifted by 1 bit every cycle? The diagram at the beginning of the PPU rendering wiki page is not perfectly straight-forward to me.
Now, regarding drawing - why would "4 background shift registers" (mentioned in the wiki) be needed for drawing one pixel? I assume only three would be needed (low BG, high BG, and one AT byte corresponding to the tile pixel you are rendering). Is this correct?
I think that's all the questions I have for now! I'm sorry for the long post, I just want to make sure I follow the original design as close as I can. Looking forward to your replies.
Regards,
Sebastien