It is currently Tue Jan 23, 2018 1:20 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Scanline Counting
PostPosted: Tue Jun 09, 2009 10:11 pm 
Offline
User avatar

Joined: Wed Aug 03, 2005 3:15 pm
Posts: 394
In this post Celius wrote:
It uses 12 scanlines...

So, I have been wondering for awhile about this kind of thing. I see people talking like "my routine takes X amount of scanlines," or "if you do X routine for X amount of scanlines," etc.

How exactly do you guys figure the amount of scanlines? Do you count as you step through a debugger? Do you count how many cycles the code takes, or even just guesstimate it? I'm just not sure how it gets figured up.

Thanks for any answers fellas (and/or ladies, should you be around).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 09, 2009 10:35 pm 
Offline
User avatar

Joined: Wed Sep 07, 2005 9:55 am
Posts: 309
Location: Phoenix, AZ
I use the 6502 simulator on the main page. There's a cycle counter on the debugger.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 09, 2009 11:48 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2146
Location: Minneapolis, Minnesota, United States
I do guesstimate lots of times, if I turn off the screen at one point, execute a peice of code, then enable it and just eye the amount of scanlines that are blanked. If I do that then it's an estimate. However, for something like my extended Vblank code I count the amount of cycles it takes, and divide by 113.3333.


Top
 Profile  
 
 Post subject: Re: Scanline Counting
PostPosted: Wed Jun 10, 2009 6:45 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19498
Location: NE Indiana, USA (NTSC)
Roth wrote:
How exactly do you guys figure the amount of scanlines? Do you count as you step through a debugger?

As never-obsolete pointed out, some debuggers can display the elapsed CPU cycles. I seem to remember that Nintendulator's debugger even gives (x, y) coordinates of the raster position. So put a breakpoint at the beginning and end of the subroutine, run it, subtract, and convert to your preferred unit.

Other techniques work even on the NES hardware, which lacks a cycle-counting debugger:
  • Celius' technique: Put a "ruler" (repeating pattern) on screen, start the code at a particular scanline, trigger a raster effect, and eyeball how many scanlines have elapsed (I've done this on the GBA)
  • Load the code into a mapper with a readable scanline counter or CPU cycle timer, start the code at a particular scanline, run it, and read the counter when it's done (I've done this on the GBA too)
  • Run the code in a loop and see how many iterations finish between NMIs (that's called a benchmark, and it's common even on PCs)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 10, 2009 6:57 am 
Offline

Joined: Thu Oct 27, 2005 1:44 pm
Posts: 449
Location: CA
One trick I have done is use the grayscale bit. Turn grayscale on, run code, turn grayscale off. Usually I am not looking for exactly how many scanlines so I don't have a ruler pattern. Just care about how long into the frame my game engine takes so I want to see a gap of non gray at the bottom of the screen. Biggest benefit is it only takes a couple lines of code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 10, 2009 3:11 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3501
Location: Indianapolis
Usually the greyscale bit (if you've seen my macros file it's MONO and COLOR). When in greyscale mode, you can also get away with using color emphasis bits (all 3 independently, even).

Somewhere on my computer I have a custom version of VirtuaNES that has some extra registers for benchmarking code (I believe it could show the maximum # of cycles taken too, for different iterations). I could find and upload that if it'd be useful to anyone.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 11, 2009 11:37 am 
Offline
User avatar

Joined: Wed Aug 03, 2005 3:15 pm
Posts: 394
Thanks for all the tips on this, I'll be checking some of this out. Thanks!

Memblers wrote:
Somewhere on my computer I have a custom version of VirtuaNES that has some extra registers for benchmarking code (I believe it could show the maximum # of cycles taken too, for different iterations). I could find and upload that if it'd be useful to anyone.

I don't see how it could hurt ; )


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 11, 2009 5:16 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3501
Location: Indianapolis
Roth wrote:
Thanks for all the tips on this, I'll be checking some of this out. Thanks!

Memblers wrote:
Somewhere on my computer I have a custom version of VirtuaNES that has some extra registers for benchmarking code (I believe it could show the maximum # of cycles taken too, for different iterations). I could find and upload that if it'd be useful to anyone.

I don't see how it could hurt ; )


Here it is. I can't easily find the email with the instructions on how to use it (Norix sent it to me at my request), but going from memory I believe the registers were just above $4017 and there were 2 of them. Try $4018 and $4019.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 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