Scanline Counting

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Roth
Posts: 400
Joined: Wed Aug 03, 2005 3:15 pm
Contact:

Scanline Counting

Post by Roth »

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).
User avatar
never-obsolete
Posts: 403
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ
Contact:

Post by never-obsolete »

I use the 6502 simulator on the main page. There's a cycle counter on the debugger.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

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.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Scanline Counting

Post by tepples »

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)
bunnyboy
Posts: 449
Joined: Thu Oct 27, 2005 1:44 pm
Location: CA
Contact:

Post by bunnyboy »

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.
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

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.
Roth
Posts: 400
Joined: Wed Aug 03, 2005 3:15 pm
Contact:

Post by Roth »

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 ; )
User avatar
Memblers
Site Admin
Posts: 3901
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

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.
Post Reply