Jump to content
IGNORED

Cycle counting


danwinslow

Recommended Posts

I'd like to find out how many CPU cycles my deferred VBI is taking. Are there ways to do that semi-accurately on real hardware? Maybe by finding out where the raster is?

 

Also, I figure its possible on altirra, but I would also appreciate a clue or two on how to do that.

Edited by danwinslow
Link to comment
Share on other sites

You could take VCOUNT readings at the start and end. Possible chance it could wraparound so you'd need to consider that as well as Pal/NTSC difference - Pal less likely to wraparound in a shortish routine.

 

Alternatively you could use one of the PADDLE registers on Pokey. They should reset to 0 during VBLANK and conveniently count up by exactly 1 per scanline. By the time your routine starts they could well be nonzero already.

 

Such methods could be inaccurate to near 2 scanlines (paddles) or 4 for VCount.

 

In Altirra, probably easiest to use a memory access breakpoint or two. Either set to that part of the program or (easier) put an instruction in that does some unique access and use it as a trigger. Favourite one for me is just put a STA $D700 - most configs have the D7 page not in use so it's a dummy write which you can trap and be 100% sure nothing else will trigger.

 

Put a store instruction at the start and end of your routine, when it trips Altirra should give output in the debug window with PC/register states as well as the scanline and cycle on the line where the stop occurred.

  • Thanks 1
Link to comment
Share on other sites

In Altirra:

  1. Debug -> Profile... -> Profile View
  2. In Profile View window click on pull down and select Call graph sampling
  3. Click on play button, wait for a few seconds, click on stop button
  4. Top-level tree items will be Main, IRQ, NMI (DLI) and NMI (VBI)

For example:

 

post-21021-0-65941500-1413212857_thumb.png

 

This is for X:8 which doesn't happen to use VBI interrupts, but if it did there would be a non-zero number of cycles and percentage on that row. You can expand the tree to see how much CPU time each of your functions takes.

  • Like 3
Link to comment
Share on other sites

In Altirra, the history pane can also be used for this. Right-click, change timestamp mode to unhalted cycles, then right-click again on the start of your routine and set timestamp origin. Delta cycles from the start will then be displayed, not counting DMA cycles.

  • Like 5
Link to comment
Share on other sites

In Altirra:

  1. Debug -> Profile... -> Profile View

...

 

Oh FFS!!!! The more I read about Altirra the better that it gets!!!

 

I probably use 10% of the debugging functionality and the more I get to know, I realise more and more what power it has.

 

The only frustrating thing is that I didn't learn all of this functionality before! :)

Link to comment
Share on other sites

In Altirra, the history pane can also be used for this. Right-click, change timestamp mode to unhalted cycles, then right-click again on the start of your routine and set timestamp origin. Delta cycles from the start will then be displayed, not counting DMA cycles.

 

I've just used this and ... it is truly amazing. How this is all done in real-time I do not know.

Link to comment
Share on other sites

 

I've just used this and ... it is truly amazing. How this is all done in real-time I do not know.

 

I'm telling ya, Altirra is the single most valuable piece of debugging equipment I've ever seen. It's done in real time because he emulates everything, every single instruction cycle, so it's relatively trivial to record them and then provide reports and so forth. The hard part was getting the emulation to be so exact in the first place, and he's really done an amazing job.

  • Like 3
Link to comment
Share on other sites

yup... for upcoming projects I am using Altirra's debugger and single step functionality to check cycles, flags and registers... I love to step breakpoints in Eclipse source... jump into debugger... single step... run/skip subroutines which are needed by hitting one key... then single step again...

 

history view is cool, too to see where code is getting interrupted which then can have a hint, wenn interrupt going mad or vice verser... and all at source code label level...

 

only pain is...when assembling passing code back to an already running Altirra... it runs in monitor view... but all my code has console key checks at the beginning (to have a "real random number" in 53770)... I did not managed to press START with F2... so not sure how to get the console keys in debug window...

 

ah... and by accident I realised (always missing Atari800win's F9 = Warp mode)... that F1 is the Warp mode as long as press the key... RTFM ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...