nesdev.com
http://forums.nesdev.com/

My EMU is running at half the speed
http://forums.nesdev.com/viewtopic.php?f=3&t=16293
Page 1 of 1

Author:  babai [ Thu Aug 03, 2017 7:30 am ]
Post subject:  My EMU is running at half the speed

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

Author:  Dwedit [ Thu Aug 03, 2017 7:39 am ]
Post subject:  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.

Author:  thefox [ Thu Aug 03, 2017 7:54 am ]
Post subject:  Re: My EMU is running at half the speed

babai wrote:
3. Check if total no. of cycles exceed 341 if yes goto 4, else back to 2

Are those CPU cycles or PPU cycles?

Author:  babai [ Thu Aug 03, 2017 8:05 am ]
Post subject:  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

Author:  babai [ Thu Aug 03, 2017 8:06 am ]
Post subject:  Re: My EMU is running at half the speed

thefox wrote:
babai wrote:
3. Check if total no. of cycles exceed 341 if yes goto 4, else back to 2

Are those CPU cycles or PPU cycles?



those are CPU cycles * 3

Author:  babai [ Thu Aug 03, 2017 8:13 am ]
Post subject:  Re: My EMU is running at half the speed

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.


Oh, I'm not calculating sprite 0 hit at all. I'm going to do what you suggested, and report back.

And yes I'm drawing sprites 1 pixel below.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/