Jump to content

Photo

Milliseconds


12 replies to this topic

#1 flux OFFLINE  

flux

    Space Invader

  • 48 posts

Posted Thu Sep 6, 2018 11:08 AM

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.



#2 LinkoVitch OFFLINE  

LinkoVitch

    River Patroller

  • 2,633 posts
  • Location:Manchester UK

Posted Thu Sep 6, 2018 11:23 AM

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...n-main-science/)

 

Hope that helps



#3 flux OFFLINE  

flux

    Space Invader

  • Topic Starter
  • 48 posts

Posted Thu Sep 6, 2018 11:31 AM

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!


  • ggn likes this

#4 Zerosquare OFFLINE  

Zerosquare

    River Patroller

  • 2,755 posts
  • Location:France

Posted Thu Sep 6, 2018 11:38 AM

Just curious: why isn't once-per-frame enough for you? Are you making a very timing-critical game?

#5 flux OFFLINE  

flux

    Space Invader

  • Topic Starter
  • 48 posts

Posted Thu Sep 6, 2018 11:48 AM

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.


  • ggn likes this

#6 LinkoVitch OFFLINE  

LinkoVitch

    River Patroller

  • 2,633 posts
  • Location:Manchester UK

Posted Thu Sep 6, 2018 11:52 AM

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


#7 LinkoVitch OFFLINE  

LinkoVitch

    River Patroller

  • 2,633 posts
  • Location:Manchester UK

Posted Thu Sep 6, 2018 11:54 AM

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.



#8 Zerosquare OFFLINE  

Zerosquare

    River Patroller

  • 2,755 posts
  • Location:France

Posted Thu Sep 6, 2018 12:34 PM

C

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

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

#9 ggn OFFLINE  

ggn

    Stargunner

  • 1,452 posts
  • Location:Athens, Greece

Posted Thu Sep 6, 2018 1:40 PM

Or.... you can just use dpeek :)

#10 CyranoJ ONLINE  

CyranoJ

    RAPTOR Wrangler

  • 5,694 posts
  • reBOOTed
  • Location:Adelaide, SA

Posted Thu Sep 6, 2018 3:43 PM

the raptor 'ticks' counter is exposed in the API, you'd need to add an extern to see it from rB+ - that will be a rock stead 50/60hz counter depending on region, regardless of what your own code does.



#11 LinkoVitch OFFLINE  

LinkoVitch

    River Patroller

  • 2,633 posts
  • Location:Manchester UK

Posted Thu Sep 6, 2018 3:58 PM

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



#12 Zerosquare OFFLINE  

Zerosquare

    River Patroller

  • 2,755 posts
  • Location:France

Posted Fri Sep 7, 2018 6:30 AM

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.co...olatile-Keyword

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

#13 ggn OFFLINE  

ggn

    Stargunner

  • 1,452 posts
  • Location:Athens, Greece

Posted Fri Sep 7, 2018 6:41 AM

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


Oh yes, my previous post was a bit cryptic, so... https://github.com/g...n/bc.bas#L13405



Reply to this topic



  


0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users