Get internal clock date and time ?

cafe-alpha

Established Member
Hello,

When saving data to backup RAM, it is possible to specify backup save time, so that I would like to set it to Saturn's date and time ...

I think corresponding function may be hidden somewhere in SBL's documentation or header files, but I couldn't find it so far, so does anyone know how to retrieve local date and time without using SGL ?

PS: In advance, sorry if it was already posted on sx forums.
 
See the SPMC I/F User's Manual section of the Saturn System Library User's Guide document (ST-162-R1). You can also read the SMPC directly using the INTBACK command (see the SMPC User's Manual for details), but if you're using SBL or SGL it's best to go through them to avoid interference.
 
Any particular reason why you're avoiding SGL Cafe ?

Funny that I'm avoiding SBL at all cost right now.
laugh.gif
 
Uint8 *t;

t = PER_GET_TIM();

char my_date[60];

sprintf(my_date,"%02x%02x/%02d/%02x %02x-%02x-%02x",t[6],t[5],t[4] & 0x0F,t[3],t[2],t[1],t[0] );
 
PER_GET_TIM doesn't actually read the time, it's just a pointer to data read out by the peripheral polling system. If it's not running or you disable time polling (call PER_Init() with PER_KD_SYS or PER_KD_PER as the first parameter) it presumably won't get updated.
 
antime said:
See the SPMC I/F User's Manual section of the Saturn System Library User's Guide document (ST-162-R1). You can also read the SMPC directly using the INTBACK command (see the SMPC User's Manual for details), but if you're using SBL or SGL it's best to go through them to avoid interference.

Thank you Antime for your precious help !

Until now, I didn't know anything about SMPC, and thank to your post, I now understand a little about SMPC.

I use INTBACK in order to retrieve RTC value, and poll SMPC's status register instead of using SMPC interrupt.

(Related information can be found in ST-169-R1-072694.pdf pages 13-16)

For people interested, see the following code for usage example, or download source code here.

Code:
/* Waits for SF to be Reset. */

do { sc_usleep(1000); cntr++; if(cntr > SC_RTC_TIMEOUT) return saturn_time; } while(SF == 1);

/* Sets the Command Parameter in IREG. */

IREG0 = 0x01;

IREG1 = 0x08;

IREG2 = 0xF0;

/* Writes Command Code in COMREG. */

COMREG = 0x10;

/* Set SF. */

SF = 1;

/* Wait SF Clear. */

do { sc_usleep(1000); cntr++; if(cntr > SC_RTC_TIMEOUT) return saturn_time; } while(SF == 1);

/* Date and time can be read from OREG1~7 registers (BCD format). */

(I tested the code above under yabause and real hardware and it seems to work correctly.)

television2000 said:
Any particular reason why you're avoiding SGL Cafe ?

Funny that I'm avoiding SBL at all cost right now.
laugh.gif

The main reason I want to use SBL is that nearly all of its sources are available, which is not the case with SGL.

(SBL source code can be found in SaturnOrbit's forlder: C:\SaturnOrbit\SBL_601\SEGALIB)

However, source code related to RTC is not available >_<

vbt said:
Uint8 *t;

t = PER_GET_TIM();

char my_date[60];

sprintf(my_date,"%02x%02x/%02d/%02x %02x-%02x-%02x",t[6],t[5],t[4] & 0x0F,t[3],t[2],t[1],t[0] );

antime said:
PER_GET_TIM doesn't actually read the time, it's just a pointer to data read out by the peripheral polling system. If it's not running or you disable time polling (call PER_Init() with PER_KD_SYS or PER_KD_PER as the first parameter) it presumably won't get updated.

Thank you for your SBL example, vbt
smile.gif


RTC can actually be acquired from your code above, however, sources related to theses SBL functions are not available (only SEGA_PER.A file is available).

Since I want my project to be compilable from sources, I tried to directly use INTBACK, and it works now
smile.gif
 
Holy old post Batman.. but it figures the only information I can find on pulling the system time from the Saturn is here, haha.

I haven't fully parsed the examples above - but it appears to me that joengine has no method for pulling the Saturn system time by default? Am I missing something? That could be really useful - for example, random number generation.. or putting in Easter Eggs for specific dates. :)

Specifically I'm looking at random number generation, because the default joengine function is limited, and it's definitely not random. Or maybe I'm missing something!
 
That's perfect, thanks!

I ended up getting satisfying results from jo_random(). With more tinkering, I found and fixed several errors in my game logic, and was getting about what I would expect with a coin flip distribution wise.

I looked at the joengine source code, and the "seed" value is defined was 1 by default, so I assumed that the results were not super random (apparently that's just a flag to use system time?). Maybe I should read through the Github issues for more color - I had a hard time finding anything to explain how it works otherwise.

I think one of my problems is the limitations in the search function on the joengine website. I searched for "date" and "time", but I never thought to search for "jo_datetime". Thanks again for the great example!
 
Back
Top