Register

RTC syscalls

Discuss anything related to calculators. For specific help on certain games/programs check the Released Projects subforum.
Junior Member
Posts: 5
Joined: Thu Jul 03, 2014 3:32 pm
Calculators: Casio fx-9750GII

RTC syscalls

Postby TheProg » Thu Jul 03, 2014 3:43 pm

Hi Casiopeia,
I'm from Planete Casio and i have a question for you. I don't know if this website is really actif but you're my last chance :shifty: (sorry if my topic is'nt was in the great gategory and if my english is a little bit bad :mrgreen: )
Then, I've seen this in your website and I want to know how this fuck*** syscall "RTC_GetTime()" is working. In the document of SimLo, I think ther is a mistake because the code at the end of this post didn't work...
Then, if you can help me, I will be very happy :clap:
You can find my french topic here

Code: Select all
#include "fxlib.h"
#include <stdio.h>
#include <stdlib.h>

// PROTO FONCTIONS
int RTC_getTicks();
int SYS_call();
void RTC_getTime(unsigned int *hours, unsigned int *mins, unsigned int *secs, unsigned int *msecs);

// VARIABLES
static int SysCallCode[] = {0xD201422B,0x60F20000,0x80010070}; // déclaration des adresses
static int (*SysCall)(int R4, int R5, int R6, int R7, int FNo ) = (void*)&SysCallCode; // et des registres (en global)


int AddIn_main(int isAppli, unsigned short OptionNum)
{
    unsigned int key;
    unsigned int hours, mins, secs, msecs;
    char buffer[60];
   
    Bdisp_AllClr_DDVRAM();
    RTC_getTicks();
    RTC_getTime(&hours, &mins, &secs, &msecs);
   
    sprintf(buffer, "%d-%d-%d", hours, mins, secs);
    PrintMini(1,1,buffer,0);

    while(1){
        GetKey(&key);
    }

    return 1;
}

int RTC_getTicks()
{
     return (*SysCall)(0, 0, 0, 0, 0x3B); // on déclare la fonction voulue selon son numéro (ici 0x3B)
}

void RTC_getTime(unsigned int *hours, unsigned int *mins, unsigned int *secs, unsigned int *msecs)
{
     (*SysCall)(0, 0, 0, 0, 0x03A);
}

int SYS_call(void)
{
     return (*SysCall)(0, 0, 0, 0, 0x42);
}


#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum){return INIT_ADDIN_APPLICATION(isAppli, OptionNum);}
#pragma section

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

Re: RTC syscalls

Postby helder7 » Fri Jul 04, 2014 4:28 pm

Hi,

You're welcome. I took a look at your code and put it to work. I that that the problem is in the definition of the syscalls.
I defined the syscalls in a syscalls.src file, is simpler:

Code: Select all
   .SECTION P,CODE,ALIGN=4
   .MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop
   .export \SYSCALLNAME'
\SYSCALLNAME'
   mov.l #h'\FUNO, r0
   mov.l #H'80010070, r2
   jmp @r2
   \TAIL'
   .ENDM

   SYSCALL 003A,   _RTC_GetTime
   SYSCALL 003B,   _RTC_GetTicks

   .end


And I made a small change in the code (sprintf...), to display the time correctly...
Code: Select all
#include "fxlib.h"
#include <stdio.h>
#include <stdlib.h>

// PROTO FONCTIONS
void RTC_GetTime(unsigned int *hours, unsigned int *mins, unsigned int *secs, unsigned int *msecs);

int AddIn_main(int isAppli, unsigned short OptionNum)
{
    unsigned int key;
    unsigned int hours, mins, secs, msecs;
    char buffer[60];
   
    Bdisp_AllClr_DDVRAM();
    RTC_GetTime(&hours, &mins, &secs, &msecs);
    sprintf(buffer, "%xh %xm %xs", hours, mins, secs);
    PrintXY(1,1,(unsigned char*)"Time right now:",0);
    PrintXY(1,12,buffer,0);
    Bdisp_PutDisp_DD();

    while(1){
        GetKey(&key);
    }

    return 1;
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum){return INIT_ADDIN_APPLICATION(isAppli, OptionNum);}
#pragma section
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Junior Member
Posts: 5
Joined: Thu Jul 03, 2014 3:32 pm
Calculators: Casio fx-9750GII

Re: RTC syscalls

Postby TheProg » Fri Jul 04, 2014 10:06 pm

Thank you so much helder7 !
It work pretty good :)

src files are assembleur files ?
and do you know how use the RTC_SetDateTime syscall because I don't understand what argument is need ?

Senior Member
Posts: 369
Joined: Tue Jan 03, 2012 11:24 pm
Calculators: Casio Afx 1.0, Casio fx-9860GII SD, Casio Classpad 330, Casio fx-CG20, Casio Classpad fx-CP400

Re: RTC syscalls

Postby helder7 » Sat Jul 05, 2014 1:25 am

Yes.

I think that the difficult of RTC_SetDateTime syscall is just in understand how to convert from int to BCD.

with a int2bcd function:
Code: Select all
int int2bcd(int val) {return (((val / 10) << 4) + (val % 10));}


is not hard...
SiO2 + CaCO3 ----------> CaSiO3 + CO2

Junior Member
Posts: 5
Joined: Thu Jul 03, 2014 3:32 pm
Calculators: Casio fx-9750GII

Re: RTC syscalls

Postby TheProg » Sat Jul 05, 2014 12:05 pm

Ok thanks and a last question,
Do you know how get the year and the date with the day (for exemple: 25/05/2005) because the RTC_GetTime just returns the time but in the Menno's add-in, we can see the date...

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: RTC syscalls

Postby SimonLothar » Sun Jul 06, 2014 8:54 am

With the fx-9860-OSes no syscall exists to retrieve the RTC-date. It is necessary to access the corresponding MPU-registers (alas they are MPU-type-dependent).

Code: Select all
typedef struct{
              unsigned char     R128CNT;
              unsigned char     gap1;
              unsigned char     RSECCNT;
              unsigned char     gap2;
              unsigned char     RMINCNT;
              unsigned char     gap3;
              unsigned char     RHOURCNT;
              unsigned char     gap4;
              unsigned char     RWEEKCNT;
              unsigned char     gap5;
              unsigned char     RDAYCNT;
              unsigned char     gap6;
              unsigned char     RMONCNT;
              unsigned char     gap7;
              unsigned short    RYEARCNT;
} TRTC;

//
void RTC_GetDateTime( unsigned char time[ 8 ] ){
volatile TRTC*pRTC;

   switch( GetMPU() ){
      case mpu7305 :
      case mpu7724 :
         pRTC = (TRTC*)0xA413FEC0;
         break;
      case mpu7337 :
      case mpu7355 :
      case mpu7705 :
         pRTC = (TRTC*)0xFFFFFEC0;
         break;
      default :
         pRTC = 0;
         break;
   }
   
   if ( pRTC ){
      time[YEAR_HI] = (*pRTC).RYEARCNT >> 8;
      time[YEAR_LO] = (*pRTC).RYEARCNT & 0x00FF;
      time[MONTH] = (*pRTC).RMONCNT;
      time[DAY] = (*pRTC).RDAYCNT;
      time[HOUR] = (*pRTC).RHOURCNT;
      time[MINUTE] = (*pRTC).RMINCNT;
      time[SECOND] = (*pRTC).RSECCNT;
      time[7] = 0;
   } else memset( time, 0, sizeof( time ) );
}


To detect the MPU-type, you could use the OS Version (2.02+ => 7305 else 7337/7355) or the following code

Code: Select all
enum TMPU { mpuUnknown, mpu7705, mpu7724, mpu7337, mpu7355, mpu7305 };

TMPU GetMPU( void ){
TMPU mpu;
unsigned char s[30];
unsigned int key;
unsigned char savevalue;
   mpu = mpuUnknown;
   savevalue = *(unsigned short*)0xA4000114;
   *(unsigned short*)0xA4000114 = 0xFFFF;
   switch ( *(unsigned short*)0xA4000114 ){
      case 0x0FFF :
         mpu = mpu7355;
         break;
         
      case 0x00FF :
         mpu = mpu7337;
         break;
         
      default :
         switch ( *(unsigned int*)0xFF000030 & 0xFFFFFF00 ){
            case 0x10300B00 :
               switch ( *(unsigned int*)0xFF000044 & 0xFFFFFFF0 ){
                  case 0x00002C00 :
                     mpu = mpu7305;
                     break;
                  
                  case 0x00002200 :
                     mpu = mpu7724;   // just for reference
                     break;
               };
               break;
         };
         break;
   };      
   *(unsigned short*)0xA4000114 = savevalue;
   
   return mpu;
}

I'll be back!

Junior Member
Posts: 5
Joined: Thu Jul 03, 2014 3:32 pm
Calculators: Casio fx-9750GII

Re: RTC syscalls

Postby TheProg » Mon Aug 04, 2014 12:27 pm

Hi I'm back with new problems :mrgreen:
I use your help to made a game (here) but I've got some problem (with the function you gave me ?) with some models (System Error).
here is the part of the code:
Code: Select all
   typedef struct{
      unsigned char  R128CNT;
      unsigned char  gap1;
      unsigned char  RSECCNT;
      unsigned char  gap2;
      unsigned char  RMINCNT;
      unsigned char  gap3;
      unsigned char  RHOURCNT;
      unsigned char  gap4;
      unsigned char  RWEEKCNT;
      unsigned char  gap5;
      unsigned char  RDAYCNT;
      unsigned char  gap6;
      unsigned char  RMONCNT;
      unsigned char  gap7;
      unsigned short RYEARCNT;
   } TRTC;
   int GetMPU();
   void RTC_GetDateTime(unsigned char *time);

void RTC_GetDateTime(unsigned char *time)
{
   volatile TRTC*pRTC;

   switch(MPU){
      case 3 :
      case 4 :
         pRTC = (TRTC*)0xA413FEC0;
         break;
      case 2 :
      case 1 :
      case 5 : // mpu7705 ?
         pRTC = (TRTC*)0xFFFFFEC0;
         break;
      default :
         pRTC = 0;
         break;
   }
   
   if ( pRTC ){
      time[0] = (*pRTC).RYEARCNT >> 8;
      time[1] = (*pRTC).RYEARCNT & 0x00FF;
      time[2] = (*pRTC).RMONCNT;
      time[3] = (*pRTC).RDAYCNT;
      time[4] = (*pRTC).RHOURCNT;
      time[5] = (*pRTC).RMINCNT;
      time[6] = (*pRTC).RSECCNT;
      time[7] = 0;
   } else memset( time, 0, sizeof( time ) );
}

int GetMPU()
{
   int mpu;
   unsigned char s[30];
   unsigned int key;
   unsigned char savevalue;
   mpu = 0;
   savevalue = *(unsigned short*)0xA4000114;
   *(unsigned short*)0xA4000114 = 0xFFFF;
   switch ( *(unsigned short*)0xA4000114 ){
      case 0x0FFF :
         mpu = 1;
         break;
         
      case 0x00FF :
         mpu = 2;
         break;
         
      default :
         switch ( *(unsigned int*)0xFF000030 & 0xFFFFFF00 ){
            case 0x10300B00 :
               switch ( *(unsigned int*)0xFF000044 & 0xFFFFFFF0 ){
                  case 0x00002C00 :
                     mpu = 3;
                     break;
                  
                  case 0x00002200 :
                     mpu = 4;   // just for reference
                     break;
         };
         break;
      };
      break;
   };      
   *(unsigned short*)0xA4000114 = savevalue;
   
   return mpu;
}

I delete the enum because it cause some problem, I don't know why.

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: RTC syscalls

Postby SimonLothar » Mon Aug 04, 2014 5:30 pm

With which machines does the problem occur?
You could replace the MPU-detection with an OS-version detection.
Or perhaps this: After a reset or a battery failure, the RTC is in an unreliable state.
If the RTC returns an unreasonable date or time (f. i. an hour of 0x45 or day of 0xA4), the RTC has to be set to some proper values once.

BTW:
"memset( time, 0, sizeof( time ) );" is a wrong approach (in my example code as well).
Even with a declaration "unsigned char time[ 8 ]" sizeof( time ) always returns 4, the size of the pointer, not the size of the buffer.
Though it is unlikely that "memset( time, 0, sizeof( time ) );" will ever be reached.
I'll be back!

Junior Member
Posts: 5
Joined: Thu Jul 03, 2014 3:32 pm
Calculators: Casio fx-9750GII

Re: RTC syscalls

Postby TheProg » Wed Aug 06, 2014 11:51 am

I don't understand everything but finally, I found an other problem wich made a SE ...
GetMpu() is probably good :silent:
sry

Return to General

Who is online

Users browsing this forum: No registered users and 54 guests