flux Posted September 6, 2018 Share Posted September 6, 2018 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. Quote Link to comment Share on other sites More sharing options...
LinkoVitch Posted September 6, 2018 Share Posted September 6, 2018 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 4 Quote Link to comment Share on other sites More sharing options...
flux Posted September 6, 2018 Author Share Posted September 6, 2018 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! 1 Quote Link to comment Share on other sites More sharing options...
Zerosquare Posted September 6, 2018 Share Posted September 6, 2018 Just curious: why isn't once-per-frame enough for you? Are you making a very timing-critical game? 2 Quote Link to comment Share on other sites More sharing options...
flux Posted September 6, 2018 Author Share Posted September 6, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
LinkoVitch Posted September 6, 2018 Share Posted September 6, 2018 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 4 Quote Link to comment Share on other sites More sharing options...
LinkoVitch Posted September 6, 2018 Share Posted September 6, 2018 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. 4 Quote Link to comment Share on other sites More sharing options...
Zerosquare Posted September 6, 2018 Share Posted September 6, 2018 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) 3 Quote Link to comment Share on other sites More sharing options...
ggn Posted September 6, 2018 Share Posted September 6, 2018 Or.... you can just use dpeek 4 Quote Link to comment Share on other sites More sharing options...
+CyranoJ Posted September 6, 2018 Share Posted September 6, 2018 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. 2 Quote Link to comment Share on other sites More sharing options...
LinkoVitch Posted September 6, 2018 Share Posted September 6, 2018 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.. 2 Quote Link to comment Share on other sites More sharing options...
Zerosquare Posted September 7, 2018 Share Posted September 7, 2018 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 5 Quote Link to comment Share on other sites More sharing options...
ggn Posted September 7, 2018 Share Posted September 7, 2018 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/ggnkua/bcx-basic-Jaguar/blob/master/bin/bc.bas#L13405 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.