Advertisement
Guest User

Untitled

a guest
May 5th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <gccore.h>
  4. #include <wiiuse/wpad.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <network.h>
  8. #include <ogc/machine/processor.h>
  9.  
  10. static void *xfb = NULL;
  11. static GXRModeObj *rmode = NULL;
  12.  
  13. #define FAILURE(x) printf("\33[31mError: %d\n\33[39m", x)
  14. #define SUCCESS printf("\33[32msuccess\n\33[39m")
  15.  
  16. void init_crap() {
  17.     VIDEO_Init();
  18.     WPAD_Init();
  19.     PAD_Init();
  20.  
  21.     // Obtain the preferred video mode from the system
  22.     // This will correspond to the settings in the Wii menu
  23.     rmode = VIDEO_GetPreferredMode(NULL);
  24.  
  25.     // Allocate memory for the display in the uncached region
  26.     xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  27.  
  28.     // Initialise the console, required for printf
  29.     console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  30.  
  31.     // Set up the video registers with the chosen mode
  32.     VIDEO_Configure(rmode);
  33.  
  34.     // Tell the video hardware where our display memory is
  35.     VIDEO_SetNextFramebuffer(xfb);
  36.  
  37.     // Make the display visible
  38.     VIDEO_SetBlack(FALSE);
  39.  
  40.     // Flush the video register changes to the hardware
  41.     VIDEO_Flush();
  42.  
  43.     // Wait for Video setup to complete
  44.     VIDEO_WaitVSync();
  45.     if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  46. }
  47.  
  48. void end() {
  49.     int columns = 0, rows = 0;
  50.     CON_GetMetrics(&columns, &rows);
  51.     printf("\x1b[%i;0H",rows);
  52.     printf("Done... press Home/Start to exit.");
  53.     while(1) {
  54.         WPAD_ScanPads(); PAD_ScanPads();
  55.         if ((WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) || (PAD_ButtonsDown(0) & PAD_BUTTON_START))
  56.             exit(0);
  57.         VIDEO_WaitVSync();
  58.     }
  59. }
  60.  
  61. void do_bt_stuff() {
  62.     s32 ret, fd;
  63.     ioctlv vec[1];
  64.     STACK_ALIGN(char, buffer, 32, 32);
  65.     int x = 0;
  66.    
  67.     //udp_init();
  68.  
  69.     printf("Opening /dev/usb/oh1/57e/305...");
  70.     do {
  71.         ret = IOS_Open("/dev/usb/oh1/57e/305", 0);
  72.         if (ret < 0) {
  73.             sleep(1);
  74.             printf(".");
  75.             ++x;
  76.         }
  77.     }   while (ret == -6 && x < 10);
  78.     if (ret < 0) {
  79.         if (x >= 10)
  80.             printf("\33[31mTimed out.\n\33[39m");
  81.         else
  82.             FAILURE(ret);
  83.         goto deinit;
  84.     }
  85.     SUCCESS;
  86.     fd = ret;
  87.        
  88.     printf("Calling IOS_Ioctlv...");
  89.     memset(buffer, 0, 32);
  90.     buffer[0] = 0x12; buffer[1] = 0x34; buffer[2] = 0x56;   buffer[3] = 0x78;
  91.     buffer[4] = 0x12; buffer[5] = 0x34; buffer[6] = 0x56;   buffer[7] = 0x78;
  92.     buffer[8] = 0x12; buffer[9] = 0x34; buffer[10] = 0x56;  buffer[11] = 0x78;
  93.     buffer[12] = 0x12; buffer[13] = 0x34;   buffer[14] = 0x56;  buffer[15] = 0x78;
  94.     buffer[16] = 0x12; buffer[17] = 0x34;   buffer[18] = 0x56;  buffer[19] = 0x78;
  95.     buffer[20] = 0x12; buffer[21] = 0x34;   buffer[22] = 0x56;  buffer[23] = 0x78;
  96.     buffer[24] = 0x12; buffer[25] = 0x34;   buffer[26] = 0x56;  buffer[27] = 0x78;
  97.     buffer[28] = 0x12; buffer[29] = 0x34;   buffer[30] = 0x56;  buffer[31] = 0x78;
  98.     vec[0].data = buffer;
  99.     vec[0].len = 32;
  100.     ret = IOS_Ioctlv(fd, 3, 0, 1, vec);
  101.     if (ret < 0) {
  102.         FAILURE(ret);
  103.     } else {
  104.         int i;
  105.         printf("\33[32mReturned %d\n\33[39m", ret);
  106.         for (i = 0; i < 32; i++)
  107.             printf("%02x ", buffer[i]);
  108.         printf("\n");
  109.         //udp_printf("IOS_Ioctlv, size=%x", ret);
  110.         //udp_send(buffer, 32);
  111.     }
  112.    
  113.     deinit:
  114.  
  115.     printf("De-Initializing Network...");
  116.     //udp_deinit();
  117.     SUCCESS;
  118. }
  119.  
  120. int main(int argc, char **argv) {
  121.     init_crap();
  122.  
  123.     do_bt_stuff();
  124.    
  125.     end();
  126.  
  127.     return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement