SuperH-based fx calculators
fx legacy: battery

0x0469: int Battery_DisplayLowStatus( int delayflag );
Displays the message
"Low Main Batteries! Please Replace"
if the main battery-level is below the first threshhold (see 0x049C).
returns 1 if below else 0.
delayflag is passed to Battery_GetStatus (see 0x049C)

0x0476: int Battery_IsLow( void );
calls 0x0492 with delayflag
0 returns 1 if the main battery-level is below the second threshhold (see 0x049C)
else 0.

0x0492: int Battery_IsLow( int delayflag );
returns 1 if the main battery-level is below the second threshhold (see 0x049C)
else 0.
delayflag is passed to Battery_GetStatus (see 0x049C)

0x0495: int Battery_DisplayLowStatus( int delayflag );
Displays the message
"Low Main Batteries! Please Replace"
if the main battery-level is below the second threshhold (see 0x049C).
returns 1 if below else 0.
delayflag is passed to Battery_GetStatus (see 0x049C)

0x049C: int Battery_GetStatus( int delayflag );
The function uses channel C of the build-in AD converter to check the main battery voltage.
With delayflag = 1 a delay is performed before accessing the AD converter.
returns 0 if voltage OK
returns 1 if voltage below level one (0x17F with OS 1.03)
returns 2 if voltage below level two (0x16d with OS 1.03)

Reading the battery voltage

There seems to be no syscall, to read the actual voltage level.
Hence, an OS version dependent function pointer has to be used.

//
int GetMainBatteryVoltagePointer(){
unsigned int ea;
unsigned int j;
    ea = *(unsigned int*)0x8001007C;
    ea = ea + 0x049C*4;
    ea = *(unsigned int*)( ea );
    while ( *(unsigned short*)( ea ) != 0xE464 ){
      ea = ea + 2;
    };
    ea = ea + 2;
    j = *(unsigned char*)( ea + 1 );
    j = 4*j;
    j = ( ea + j + 4 ) & 0xFFFFFFFC;
    return *(unsigned int*)( j );
}
// battery == 1 : main (ADC channel C)
// battery != 1 : possibly the backup battery (ADC channel B)
// firstlevel: warning level
// secondlevel: shutdown level
 

int GetBatteryStatus( int battery, int*firstlevel, int*secondlevel ){
int (*iGBS)( int ) = 0; // declare an int function pointer
int*battconfig = (int*)0x80000334;
*firstlevel = 0x17F;
*secondlevel = 0x16D;

iGBS = (int(*)(int))GetMainBatteryVoltagePointer();

switch ( OSVersionAsInt() ){
    case OS102 : break;
    case OS103 : break;
    case OS104 :
    case OS105 :
        if ( *battconfig==0x43444844 ){
            *firstlevel = 0x1A5;
            *secondlevel = 0x191;
        };
        break;
    case OS1051 :
        if ( *battconfig==0x43444844 ){
            *firstlevel = 0x1A5;
            *secondlevel = 0x191;
        };
        break;
    case OS110 :
        *firstlevel = 0x2AA;
        *secondlevel = 0x288;
        break;
    case OS111 :
        *firstlevel = 0x2AA;
        *secondlevel = 0x288;
        break;
    case OS200 :
        if ( *battconfig==0x43444844 ){
            *firstlevel = 0x1A5;
            *secondlevel = 0x191;
        };
        break;
    case OS200GII :
        break;
    case OS200slim :
        *firstlevel = 0x2AA;
        *secondlevel = 0x288;
        break;
};
if (IsSlim()){
    *firstlevel = 0x2AA;
    *secondlevel = 0x288;
}

if (iGBS!=0) return (*iGBS)( battery );
else return 0;

}
 

(29.05.2012 11:15:03)