Jump to content
IGNORED

Milliseconds


flux

Recommended Posts

Is there any way to keep track of the elapsed number of milliseconds? I know I can count frames but it isn't really sufficient for what I'm trying to do. I haven't seen any references to this so maybe the Jaguar doesn't really have an internal clock that would facilitate something like this? I'm not really a hardware guy so I don't know if my guess makes any sense but I'm hoping there's some method. Won't be the end of the world if not and I'm sure I could work around it, but it would definitely be helpful.

Link to comment
Share on other sites

I have used the JPIT1 counter to measure duration of things, it increments once per tick (so about 25MHz). You can find it at the memory location

 

0xF10036

 

Read that in, do a thing, read it in again, difference between teh two is the number of system ticks that have elapsed. I have used it before for timing GPU code (https://www.u-235.co.uk/gpu-in-main-science/)

 

Hope that helps

  • Like 4
Link to comment
Share on other sites

It sounds like it should work for my purposes. I'm still new to this and I'm not sure yet the syntax for reading in a value from a memory location. My programming experience is mainly system administration stuff like python and that never really came up. I vaguely remember doing it in a c++ class a ton of years ago, but that's all basically gone. Thanks for the info though, much appreciated!

  • Like 1
Link to comment
Share on other sites

Reading the address will really depend on the language/processor you target

 

C

uint16_t *timer = (uint16_t *) 0xF10036;  // I *think* this would work
uint16_t value = *timer;

68000:

move.l #$f10036,a0
move.w (a0), d0      ; value of timer in D0

JRISC:

movei #$f10036, r0
loadw (r0), r1  ; value of timer stored in r1
  • Like 4
Link to comment
Share on other sites

It is pretty timing-critical, but apart from that, I need it tied to real world time and I'm fairly sure that the current framerate won't be maintained as I add complexity to the game and I need to maintain the same timing for any framerate.

 

In that case I'd suggest you setup a timer and have an ISR handle those timing events. The system timer I mentioned will loop fairly quickly and not be much use over several seconds. If you setup a custom interrupt you can decide what interval is best for you and have that set and solid without worry of it drifting. Plus you can have the ISR trigger whatever needs to happen at the appropriate times.

  • Like 4
Link to comment
Share on other sites

Fixed :)

(without "volatile" your compiler may not do what you expect)

 

I had always assumed that volatile was mostly for use in systems where there is Ln CPU cache ? but fair point :)

 

I have also just realised this is in the RB+ section! sorry! I just saw a post in Jaguar programming and didn't notice the sub-forum.. my bad..

  • Like 2
Link to comment
Share on other sites

I had always assumed that volatile was mostly for use in systems where there is Ln CPU cache ? but fair point :)

Nope, cache is not the only issue. You need volatile whenever memory accesses have side effects, and also when variables can be modified by something running in a different context. So things that should be declared volatile include:

* hardware registers

* data shared by main and interrupt code

* data shared by different processors

 

Not using volatile causes hard-to-debug problems - it may looks like it works fine, then start failing mysteriously after an unrelated code change (causing the compiler to apply different optimizations).

It's a common but dangerous and underknown trap, especially for embedded developers.

 

If you want to know more, this article is pretty good:

https://barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword

 

Of course, if you use rB+ you don't have to worry about it :)

  • Like 5
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...