dragonbane

VC Power/Reset Stuff

Nov 9th, 2021 (edited)
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. (void)OSSetPowerCallback( PowerCallback );
  2.  
  3.  
  4. static void PowerCallback()
  5. {
  6. s_shutdown = TRUE;
  7. }
  8.  
  9.  
  10. static void CheckSystemButton()
  11. {
  12. if( s_shutdown )
  13. {
  14. OSReport("Power button was pushed.\n");
  15. OSShutdownSystem();
  16. }
  17. if (OSGetResetButtonState())
  18. {
  19. OSReport("Reset button was pushed.\n");
  20. OSRebootSystem();
  21. }
  22. }
  23.  
  24. In main loop:
  25. CheckSystemButton();
  26.  
  27.  
  28.  
  29.  
  30. Other:
  31. static void ResetCallback();
  32. static void PowerCallback();
  33. static bool reset_called,power_called;
  34.  
  35. OSSetResetCallback(ResetCallback);
  36. OSSetPowerCallback(PowerCallback);
  37.  
  38. reset_called = false;
  39. power_called = false;
  40.  
  41. static void ResetCallback()
  42. {
  43. reset_called = true;
  44. }
  45.  
  46. static void PowerCallback()
  47. {
  48. power_called = true;
  49. }
  50.  
  51.  
  52. /* Process executed when returning from the HOME Menu */
  53. switch( HBMGetSelectBtnNum() )
  54. {
  55. case HBM_SELECT_HOMEBTN:
  56. break;
  57. /* Move to the Wii Menu */
  58. case HBM_SELECT_BTN1:
  59. OSReport( "Return to WiiMenu.\n" );
  60. OSReturnToMenu();
  61. break;
  62. /* Reset */
  63. case HBM_SELECT_BTN2:
  64. OSReport( "Reset.\n" );
  65. OSRestart( 0 );
  66. break;
  67. case 3:
  68.  
  69. break;
  70. default:
  71. break;
  72. }
  73.  
  74.  
  75. /* Process executed when the RESET or Power Button is pressed */
  76. if(reset_called)
  77. {
  78. /*When other than the HOME Menu, go straight on to reset */
  79. if( homeBtnSwitch == OFF )
  80. {
  81. OSRestart(0);
  82. }
  83. /* If the HOME Menu is running, reset after black-out */
  84. else
  85. {
  86. HBMStartBlackOut();
  87. }
  88. reset_called = false;
  89. }
  90.  
  91. if(power_called)
  92. {
  93. OSReturnToMenu();
  94. }
  95.  
  96.  
  97. Need to handle/hook:
  98. -OSReturnToMenu(); //Returns to the system menu
  99. -OSRestart(0); //Restarts the application.
  100. -OSRebootSystem(); //Reboots the entire system.
  101. -OSShutdownSystem(); //Shuts down the system
  102.  
  103. void OSRebootSystem ( void );
  104. void OSShutdownSystem ( void );
  105. void OSRestart ( u32 resetCode );
  106. void OSReturnToMenu ( void );
  107. ?? void OSReturnToDataManager ( void ); ??
  108.  
  109.  
  110. OSResetCallback OldResetCallback;
  111. OSPowerCallback OldPowerCallback;
  112.  
  113. /* Set up callback functions */
  114. OldResetCallback = OSSetResetCallback(ResetCallback);
  115. OldPowerCallback = OSSetPowerCallback(PowerCallback);
  116. reset_called = FALSE;
  117. power_called = FALSE;
  118.  
  119.  
  120. OSResetSW.h
  121. typedef void (*OSResetCallback)(void);
  122. typedef void (*OSPowerCallback)(void);
  123.  
  124. BOOL OSGetResetButtonState( void ); //Checks the current state of the RESET Button.
  125.  
  126. OSResetCallback OSSetResetCallback ( OSResetCallback callback );
  127. OSPowerCallback OSSetPowerCallback ( OSPowerCallback callback );
  128.  
  129.  
  130. typedef BOOL (* OSShutdownFunction )( BOOL final, u32 event );
  131. typedef struct OSShutdownFunctionInfo OSShutdownFunctionInfo;
  132.  
  133. struct OSShutdownFunctionInfo
  134. {
  135. // public
  136. OSShutdownFunction func;
  137. u32 priority;
  138.  
  139. // private
  140. OSShutdownFunctionInfo* next;
  141. OSShutdownFunctionInfo* prev;
  142. };
  143.  
  144. void OSRegisterShutdownFunction ( OSShutdownFunctionInfo* info );
  145. void OSUnregisterShutdownFunction ( OSShutdownFunctionInfo* info );
  146.  
  147.  
  148. Flow:
  149. Disable interrupts when doing critical processing:
  150. BOOL interruptLevel = OSDisableInterrupts();
  151. OSRestoreInterrupts(interruptLevel);
Add Comment
Please, Sign In to add comment