On the C64, a very easy way to "profile" code is to change the border color at the start and end of different sections of code. That way, you can see how many scanlines your code is taking in real time.
Is there a similar trick available on the NES? Near as I can see, there are no registers for setting "border" color on the PPU?
Or (maybe better?) are there any tools which can statically analyze a subroutine to count worst-case cycles?
Thanks in advance..
simple way to see visualize code timing?
Moderator: Moderators
Re: simple way to see visualize code timing?
The simplest equivalent would be to turn on the Color Emphasis bits in the PPU, since those take effect immediately and there are 7 different combinations you can use (red, green, blue, magenta, yellow, cyan, and gray). Granted, on an NTSC/PAL PPU they might not be as easy to see, but with an RGB PPU they will be extremely visible.ninja_kun wrote: ↑Sat Jun 18, 2022 6:40 am On the C64, a very easy way to "profile" code is to change the border color at the start and end of different sections of code. That way, you can see how many scanlines your code is taking in real time.
Is there a similar trick available on the NES? Near as I can see, there are no registers for setting "border" color on the PPU?
Or (maybe better?) are there any tools which can statically analyze a subroutine to count worst-case cycles?
Thanks in advance..
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
P.S. If you don't get this note, let me know and I'll write you another.
Re: simple way to see visualize code timing?
I toggle the monochrome flag (bit 0 of $2001) for a single scanline to do this, it's very easy to see unless your background uses a lot of white, grey or other bright colors, in that case the emphasis flags may be better to pick a color that is easier to see in your case.
Yeah there is no border color on the PPU, only the backdrop color.
Yeah there is no border color on the PPU, only the backdrop color.
Re: simple way to see visualize code timing?
If you have an oscilloscope, you could toggle OUT2. You can trigger and take real measurements this way. You can include M2 on the scope so you can specifically count the cycles as well. This will also work for things in V-Blank, h-blank, and things not synchronized to the video. You could even include the video output on the scope; this lets you see your signal relative to V-blank. But there is some small amount of setup involved to use a scope and it requires real hardware.
Another option is to emulate and use breakpoints. This will count cycles for you VERY nicely, and not adding any overhead from toggling a signal (or toggling background color, etc.).
Another option is to emulate and use breakpoints. This will count cycles for you VERY nicely, and not adding any overhead from toggling a signal (or toggling background color, etc.).
- rainwarrior
- Posts: 8734
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: simple way to see visualize code timing?
I've found using the monochrome bit + colour emphasis to be quite useful.
The monochrome flag is really helpful for making the emphasis colours more easily distinguishable, plus it turns black into grey so empty areas of the screen can still have a colour to emphasize.
I've used this for on-hardware profiling in a few of my projects. Article with example of how it looks.
Alternatively, the Mesen emulator has an "event viewer" debug feature that can display events or arbitrary breakpoints against the rendered picture in real-time. It also has a separate "performance profiler" tool that automatically gathers stats on a per-function-call basis.
Emulators with Lua support also give you a lot of options for writing something custom for measuring performance.
The monochrome flag is really helpful for making the emphasis colours more easily distinguishable, plus it turns black into grey so empty areas of the screen can still have a colour to emphasize.
I've used this for on-hardware profiling in a few of my projects. Article with example of how it looks.
Alternatively, the Mesen emulator has an "event viewer" debug feature that can display events or arbitrary breakpoints against the rendered picture in real-time. It also has a separate "performance profiler" tool that automatically gathers stats on a per-function-call basis.
Emulators with Lua support also give you a lot of options for writing something custom for measuring performance.
Re: simple way to see visualize code timing?
Thanks everyone, these are all great ideas!