Advertisement
popsdeco

How to access GBA RTC

Jan 12th, 2012
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <gba_console.h>
  2. #include <gba_interrupt.h>
  3. #include <gba_systemcalls.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. void enableRTC(u16 n){*(vu16*)0x80000c8=n;}
  8. void setRTCwritemode(u16 n){*(vu16*)0x80000c6=n;}//0=read, 2=write
  9. void setRTCcommand(u8 command){
  10.     *(vu16*)0x80000c4=1; //initialize
  11.     *(vu16*)0x80000c4=5; //start sending
  12.     *(vu16*)0x80000c4=0;
  13.     int i=0;for(;i<8;i++){
  14.         *(vu16*)0x80000c4=((command>>(7-i))<<1)|1; //send from upper bit
  15.         *(vu16*)0x80000c4=0;
  16.     }
  17. }
  18. u8 getRTCbyte(){
  19.     u8 ret=0;
  20.     int i=0;for(;i<8;i++){
  21.         *(vu16*)0x80000c4=2|1;
  22.         ret|=(((u8)(*(vu16*)0x80000c4)&2)>>1) << i; //sent from lower bit
  23.         *(vu16*)0x80000c4=0;
  24.     }
  25.     return (ret/16*10)+ret%16;
  26. }
  27.  
  28. int main(){
  29.     irqInit();
  30.     irqEnable(IRQ_VBLANK);
  31.     consoleDemoInit();
  32.  
  33.     enableRTC(1);
  34.     setRTCwritemode(0);
  35.     setRTCcommand(0x65);
  36.     iprintf("---%u/%02u/%02u %d %02d:%02d:%02d---\n",getRTCbyte()+1900+100,getRTCbyte(),getRTCbyte(),getRTCbyte(),getRTCbyte(),getRTCbyte(),getRTCbyte());
  37.  
  38.     while(1){VBlankIntrWait();}
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement