Hello All,
This is my first post @ nesdev. I'm building my first emulator,and have finished the 6502 CPU core & a very basic sprite renderer. Below is the flow I'm taking:
1. Start:
2. Run the CPU
3. Check if total no. of cycles exceed 341 if yes goto 4, else back to 2
4. Render one scanline by the ppu
5. Adjust any excess cycles the cpu has rendered by adding excess cycles to step 3.
6. Go back to 2 if 262 scanlines haven't been rendered
6. Once all 262 scanlines have been rendered complete the frame.
7. render the frame
8. Stop
Loop the above 60 times a second
But I see the sprite animations that are happening are roughly at half the actual rate.
I counted the no. of avg CPU cycles I'm doing per frame and its coming as 29870 which I think is close to the actual NES.
Can anyone suggest what wrong I could be doing?
Thanks,
Babai
My EMU is running at half the speed
Moderator: Moderators
Re: My EMU is running at half the speed
Do you have the basic frame timing correct?
262 total scanlines:
* 20 vblank scanlines (Trigger NMI at start of this time, set vblank flag)
* 1 prerender scanline (clear vblank, sprite 0 hit, sprite overflow at start of this time)
* 240 visible scalines
* 1 postrender/pre-vblank scanline
If games are getting messed up by lack of sprite 0 hit, you can temporarily cheat and use the timing of Sprite 0's pixels appearing on the screen as the trigger for that instead.
Also note that sprites are drawn one pixel below their Y coordinate.
262 total scanlines:
* 20 vblank scanlines (Trigger NMI at start of this time, set vblank flag)
* 1 prerender scanline (clear vblank, sprite 0 hit, sprite overflow at start of this time)
* 240 visible scalines
* 1 postrender/pre-vblank scanline
If games are getting messed up by lack of sprite 0 hit, you can temporarily cheat and use the timing of Sprite 0's pixels appearing on the screen as the trigger for that instead.
Also note that sprites are drawn one pixel below their Y coordinate.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Re: My EMU is running at half the speed
Are those CPU cycles or PPU cycles?babai wrote:3. Check if total no. of cycles exceed 341 if yes goto 4, else back to 2
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Re: My EMU is running at half the speed
Below is order I'm doing it:
scanline 0 - 239:
render sprites
render background //stub for now
post render scanline 240:
I'm doing nothing
scanline 241-260:
@ line 241 set Vblank in PPUSTATUS, and serve "NMI" ISR
for the rest lines, I'm doing nothing
scanline 261:
Clear PPUSTATUS Vblank and sprite hit & overflow
scanline 0 - 239:
render sprites
render background //stub for now
post render scanline 240:
I'm doing nothing
scanline 241-260:
@ line 241 set Vblank in PPUSTATUS, and serve "NMI" ISR
for the rest lines, I'm doing nothing
scanline 261:
Clear PPUSTATUS Vblank and sprite hit & overflow
Re: My EMU is running at half the speed
thefox wrote:Are those CPU cycles or PPU cycles?babai wrote:3. Check if total no. of cycles exceed 341 if yes goto 4, else back to 2
those are CPU cycles * 3
Re: My EMU is running at half the speed
Oh, I'm not calculating sprite 0 hit at all. I'm going to do what you suggested, and report back.Dwedit wrote:Do you have the basic frame timing correct?
262 total scanlines:
* 20 vblank scanlines (Trigger NMI at start of this time, set vblank flag)
* 1 prerender scanline (clear vblank, sprite 0 hit, sprite overflow at start of this time)
* 240 visible scalines
* 1 postrender/pre-vblank scanline
If games are getting messed up by lack of sprite 0 hit, you can temporarily cheat and use the timing of Sprite 0's pixels appearing on the screen as the trigger for that instead.
Also note that sprites are drawn one pixel below their Y coordinate.
And yes I'm drawing sprites 1 pixel below.