It is currently Mon Aug 21, 2017 10:49 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Aug 03, 2017 7:30 am 
Offline

Joined: Thu Aug 03, 2017 7:15 am
Posts: 4
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


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 7:39 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3913
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.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 7:54 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2924
Location: Tampere, Finland
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?

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 8:05 am 
Offline

Joined: Thu Aug 03, 2017 7:15 am
Posts: 4
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


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 8:06 am 
Offline

Joined: Thu Aug 03, 2017 7:15 am
Posts: 4
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


Top
 Profile  
 
PostPosted: Thu Aug 03, 2017 8:13 am 
Offline

Joined: Thu Aug 03, 2017 7:15 am
Posts: 4
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group