dolphintest_si.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <malloc.h>
  5. #include <ogcsys.h>
  6. #include <gccore.h>
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <unistd.h>
  10. #include <fat.h>
  11. #ifdef HW_RVL
  12. #include <wiiuse/wpad.h>
  13. #include <sdcard/wiisd_io.h>
  14. #endif
  15. static void *xfb;
  16. static GXRModeObj *rmode;
  17. void Initialise();
  18. void (*reboot)() = (void(*)())0x80001800;
  19. static u32* const SI_REG = (u32*)0xCD006400;
  20. static bool haveInit = false;
  21. static int counter = 0;
  22. static bool logWritten = false;
  23. void AppendSDLog()
  24. {
  25. #ifdef HW_RVL
  26. FILE *f = fopen("sd:/si_log.txt", "a");
  27. if (f)
  28. {
  29. fprintf(f, "\n-------------------------------------\n");
  30. for (int i = 0; i < 4; i++)
  31. fprintf(f, "%i\tstatus: %x\t type:%x\n", i, SI_GetStatus(i), SI_GetType(i));
  32. u32 x = 0;
  33. fprintf(f, "-------------------------------------\n");
  34. fprintf(f, "SI_CHANNEL_0_OUT\t%08x\n", SI_REG[x++]);
  35. fprintf(f, "SI_CHANNEL_0_IN_HI\t%08x\n", SI_REG[x++]);
  36. fprintf(f, "SI_CHANNEL_0_IN_LO\t%08x\n", SI_REG[x++]);
  37. fprintf(f, "SI_CHANNEL_1_OUT\t%08x\n", SI_REG[x++]);
  38. fprintf(f, "SI_CHANNEL_1_IN_HI\t%08x\n", SI_REG[x++]);
  39. fprintf(f, "SI_CHANNEL_1_IN_LO\t%08x\n", SI_REG[x++]);
  40. fprintf(f, "SI_CHANNEL_2_OUT\t%08x\n", SI_REG[x++]);
  41. fprintf(f, "SI_CHANNEL_2_IN_HI\t%08x\n", SI_REG[x++]);
  42. fprintf(f, "SI_CHANNEL_2_IN_LO\t%08x\n", SI_REG[x++]);
  43. fprintf(f, "SI_CHANNEL_3_OUT\t%08x\n", SI_REG[x++]);
  44. fprintf(f, "SI_CHANNEL_3_IN_HI\t%08x\n", SI_REG[x++]);
  45. fprintf(f, "SI_CHANNEL_3_IN_LO\t%08x\n", SI_REG[x++]);
  46. fprintf(f, "SI_POLL\t\t\t%08x\n", SI_REG[x++]);
  47. fprintf(f, "SI_COM_CSR\t\t\t%08x\n", SI_REG[x++]);
  48. fprintf(f, "SI_STATUS_REG\t\t%08x\n", SI_REG[x++]);
  49. fprintf(f, "SI_EXI_CLOCK_COUNT\t%08x\n", SI_REG[x++]);
  50. fprintf(f, "-------------------------------------\n");
  51. fclose(f);
  52. }
  53. #endif
  54. }
  55. int main(int argc, char **argv)
  56. {
  57. Initialise();
  58. while(1) {
  59. if (haveInit) PAD_ScanPads();
  60. VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
  61. printf("\x1b[4;0H");
  62. for(int Chan = 0; Chan < 4; Chan++)
  63. printf("%i\tstatus: %x\t type:%x\n", Chan, SI_GetStatus(Chan), SI_GetType(Chan));
  64. printf("SI Regs: (cc006000)\n");
  65. for (u32 i = 0; i < 16/*num SI regs*/; ++i)
  66. {
  67. printf("%08x ", SI_REG[i]);
  68. if ((i+1)%8==0) printf("\n");
  69. }
  70. if (haveInit)
  71. printf("\nPAD_Init\n");
  72. VIDEO_WaitVSync();
  73. if (haveInit)
  74. {
  75. if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
  76. {
  77. AppendSDLog();
  78. #ifdef HW_RVL
  79. fatUnmount("sd");
  80. __io_wiisd.shutdown();
  81. #endif
  82. reboot();
  83. }
  84. }
  85. counter++;
  86. AppendSDLog();
  87. if (counter > 5 && !haveInit)
  88. {
  89. PAD_Init();
  90. haveInit = true;
  91. }
  92. else if (haveInit && !logWritten)
  93. {
  94. logWritten = true;
  95. }
  96. }
  97. return 0;
  98. }
  99. void Initialise()
  100. {
  101. // Initialise the video system
  102. VIDEO_Init();
  103. // Obtain the preferred video mode from the system
  104. // This will correspond to the settings in the Wii menu
  105. rmode = VIDEO_GetPreferredMode(NULL);
  106. // Allocate memory for the display in the uncached region
  107. xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  108. // Initialise the console, required for printf
  109. console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  110. // Set up the video registers with the chosen mode
  111. VIDEO_Configure(rmode);
  112. // Tell the video hardware where our display memory is
  113. VIDEO_SetNextFramebuffer(xfb);
  114. // Make the display visible
  115. VIDEO_SetBlack(FALSE);
  116. // Flush the video register changes to the hardware
  117. VIDEO_Flush();
  118. // Wait for Video setup to complete
  119. VIDEO_WaitVSync();
  120. if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  121. #ifdef HW_RVL
  122. // Initialize FAT so we can write to SD.
  123. __io_wiisd.startup();
  124. fatMountSimple("sd", &__io_wiisd);
  125. #endif
  126. }