Hi all.
Been lurking for a while, but finally decide to ask for some guide.
Long story short, I'm writing a nes emulator, and after implementing the CPU, I'm now with the PPU, rendering once every VBlank.
Running nestest rom in automated mode, my emulator reaches until (if I remember right) ilegal opcodes.
So now I'm trying to render some graphics, I succesfully render the nametables, however something is off, the test selection graphic is missing in my emulator:
Compare it with FCEUX for example:
I understand that with this very vague introduction, it might be really difficult to pinpoint the source of the problem, but does anybody know nestest enough to have an idea what might be wrong?
Trying to render nestest graphics
Moderator: Moderators
Re: Trying to render nestest graphics
The cursor state is being written every single frame to nametable addresses $2002-2202, written vertically (so each write to $2007 increments by 32 instead of 1). Your image is cutting off the top and bottom rows of the screen (you're outputting 256x224 instead of 256x240), so it's possible that you don't support vertical increment and are instead writing the cursor column horizontally along the top row you're not displaying.
If that's not it, maybe you're ignoring writes in vblank when rendering is enabled. The state of rendering doesn't matter during vblank; all writes will make it to the PPU as though rendering were disabled.
If that's not it, maybe you're ignoring writes in vblank when rendering is enabled. The state of rendering doesn't matter during vblank; all writes will make it to the PPU as though rendering were disabled.
-
- Posts: 4
- Joined: Sun Jun 26, 2022 12:27 pm
Re: Trying to render nestest graphics
I think I accidentally cropped my emulator screenshot and that's why it looks like is missing top and bottom rows.
Here it is (it includes a border to easily know the limits) Reviewing the writes to PPU CTRL (to see if I'm ingoring the vertical mode), I don't see in my logs any writes to $2000 other than 0x00, so can't see where it would enable that mode.
Also, what do you mean by "cursor state"? Do you mean my missing graphic (*)? Or the position in the screen where it's rendering?
Here it is (it includes a border to easily know the limits) Reviewing the writes to PPU CTRL (to see if I'm ingoring the vertical mode), I don't see in my logs any writes to $2000 other than 0x00, so can't see where it would enable that mode.
Also, what do you mean by "cursor state"? Do you mean my missing graphic (*)? Or the position in the screen where it's rendering?
Last edited by pherrymason on Sun Jun 26, 2022 11:23 pm, edited 2 times in total.
Re: Trying to render nestest graphics
By cursor state, I mean the position of the * alongside the left side of the list of tests.
This is the code responsible for drawing the cursor. It is run every frame:
It sets vertical increment mode, sets the PPU address to $2002, and writes the data into $2007.
This image shows what is being updated each frame. You can see on the right that the starting address is $2002, matching the above code.
This is the code responsible for drawing the cursor. It is run every frame:
Code: Select all
.. --------sub start--------
C261 A5 D7 LDA $D7
C263 18 CLC
C264 69 04 ADC #$04
C266 A8 TAY
C267 A9 84 LDA #$84
C269 8D 00 20 STA PpuControl_2000
C26C A9 20 LDA #$20
C26E 8D 06 20 STA PpuAddr_2006
C271 A9 02 LDA #$02
C273 8D 06 20 STA PpuAddr_2006
C276 A9 20 LDA #$20
C278 88 DEY
C279 C8 INY
C27A D0 02 BNE $C27E
C27C A9 2A LDA #$2A
C27E 8D 07 20 STA PpuData_2007
C281 88 DEY
C282 CA DEX
C283 D0 F1 BNE $C276
C285 A9 80 LDA #$80
C287 8D 00 20 STA PpuControl_2000
C28A 4C 94 C2 JMP $C294
This image shows what is being updated each frame. You can see on the right that the starting address is $2002, matching the above code.
-
- Posts: 4
- Joined: Sun Jun 26, 2022 12:27 pm
Re: Trying to render nestest graphics
Ok, now I see it.
My emulator never reaches that point, it gets stuck in the loop at $C28D
My emulator never reaches that point, it gets stuck in the loop at $C28D
Code: Select all
$C28D: A5 D2 LDA $D2
$C28F: C5 D2 CMP $D2
$C291: F0 FC beq C28F
Re: Trying to render nestest graphics
That typically means the code is waiting for an NMI. You may have missed an NMI enable somehow.
-
- Posts: 4
- Joined: Sun Jun 26, 2022 12:27 pm
Re: Trying to render nestest graphics
Thank you very much, that was (at least partly) the key.
I've found some bugs in my emulator that makes handling the NMI incorrectly (wrong bit shift to set the right PPUCTRL register and a wrong logic when the NMI needs to be triggered).
Will investigate again when and how NMI should be triggered and handled.
I've found some bugs in my emulator that makes handling the NMI incorrectly (wrong bit shift to set the right PPUCTRL register and a wrong logic when the NMI needs to be triggered).
Will investigate again when and how NMI should be triggered and handled.
Last edited by pherrymason on Mon Jun 27, 2022 2:43 pm, edited 1 time in total.