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.
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).
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.
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)
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.
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.
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.
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.