Mattie

Untitled

Apr 4th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.76 KB | None | 0 0
  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 <wiiuse/wpad.h>
  8. #include <jpeg/jpgogc.h>
  9. #include <unistd.h>
  10. #include <MLlib.h>
  11.  
  12. ML_Image backgroundData;
  13. ML_Background background;
  14.  
  15.  
  16. static void *xfb = NULL;
  17. static GXRModeObj *rmode = NULL;
  18.  
  19. //extern char picdata[];
  20. //extern int piclength;
  21. //JPEGIMG plaatje;
  22. //
  23. //extern char picdata1[];
  24. //extern int piclength1;
  25. //JPEGIMG arrow;
  26.  
  27. // Wiimote IR
  28. ir_t ir;
  29.  
  30. void menuScherm()
  31. {
  32.     ML_LoadBackgroundFromFile(&backgroundData, &background, "../include/Eiland.png", 640, 480);
  33. }
  34.  
  35. void Initialise()
  36. {
  37.     ML_Init();
  38. //  ML_InitFAT();
  39.  
  40.     // Initialise the video system
  41.     VIDEO_Init();
  42.  
  43.     // This function initialises the attached controllers
  44.     WPAD_Init();
  45.  
  46.     WPAD_SetVRes(0, 640, 480);
  47.  
  48.     WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
  49.  
  50.     // Obtain the preferred video mode from the system
  51.     // This will correspond to the settings in the Wii menu
  52.     rmode = VIDEO_GetPreferredMode(NULL);
  53.  
  54.     // Allocate memory for the display in the uncached region
  55.     xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  56.  
  57.     // Initialise the console, required for printf
  58.     console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth
  59.             * VI_DISPLAY_PIX_SZ);
  60.  
  61.     // Set up the video registers with the chosen mode
  62.     VIDEO_Configure(rmode);
  63.  
  64.     // Tell the video hardware where our display memory is
  65.     VIDEO_SetNextFramebuffer(xfb);
  66.  
  67.     // Make the display visible
  68.     VIDEO_SetBlack(FALSE);
  69.  
  70.     // Flush the video register changes to the hardware
  71.     VIDEO_Flush();
  72.  
  73.     // Wait for Video setup to complete
  74.     VIDEO_WaitVSync();
  75.     if (rmode->viTVMode & VI_NON_INTERLACE)
  76.         VIDEO_WaitVSync();
  77. }
  78.  
  79. void DrawHLine(int x1, int x2, int y, int color)
  80. {
  81.     int i;
  82.  
  83.     y = 320 * y;
  84.     x1 >>= 1;
  85.     x2 >>= 1;
  86.     for (i = x1; i <= x2; i++)
  87.     {
  88.         u32 *tmpfb = (u32*) xfb;
  89.         //u32 *tempfb = xfb
  90.         //(u32*) is geadd zodat het van een void naar een u32
  91.         tmpfb[y + i] = color;
  92.     }
  93. }
  94.  
  95. void DrawVLine(int x, int y1, int y2, int color)
  96. {
  97.     int i;
  98.     x >>= 1;
  99.     for (i = y1; i <= y2; i++)
  100.     {
  101.         u32 *tmpfb = (u32*) xfb;
  102.         tmpfb[x + (640 * i) / 2] = color;
  103.     }
  104. }
  105.  
  106. void DrawBox(int x1, int y1, int x2, int y2, int color)
  107. {
  108.     DrawHLine(x1, x2, y1, color);
  109.     DrawHLine(x1, x2, y2, color);
  110.     DrawVLine(x1, y1, y2, color);
  111.     DrawVLine(x2, y1, y2, color);
  112. }
  113.  
  114. void display_jpeg(JPEGIMG jpeg, int x, int y)
  115. {
  116.  
  117.     unsigned int *jpegout = (unsigned int *) jpeg.outbuffer;
  118.  
  119.     int i, j;
  120.     int height = jpeg.height;
  121.     int width = jpeg.width - (jpeg.width / 2);
  122.     u32 *tmpfb = (u32*) xfb;
  123.     for (i = 0; i <= width; i++)
  124.         for (j = 0; j <= height - 2; j++)
  125.             tmpfb[(i + x) + 320 * (j + 16 + y)] = jpegout[i + width * j];
  126.  
  127.     free(jpeg.outbuffer);
  128.  
  129. }
  130.  
  131. //void initAFB()
  132. //{
  133. //  //assign memory aan 'plaatje'
  134. //  memset(&plaatje, 0, sizeof(JPEGIMG));
  135. //  //haal wat dingen uit picture.s
  136. //  plaatje.inbuffer = picdata;
  137. //  plaatje.inbufferlength = piclength;
  138. //  //decompress plaatje
  139. //  JPEG_Decompress(&plaatje);
  140. //
  141. //  //assign memory aan 'plaatje'
  142. //  memset(&arrow, 0, sizeof(JPEGIMG));
  143. //  //haal wat dingen uit picture.s
  144. //  arrow.inbuffer = picdata1;
  145. //  arrow.inbufferlength = piclength1;
  146. //  //decompress plaatje
  147. //  JPEG_Decompress(&arrow);
  148. //}
  149.  
  150. int main(int argc, char **argv)
  151. {
  152.     //---------------------------------------------------------------------------------
  153. //  initAFB();
  154.  
  155.     Initialise();
  156.  
  157.     // The console understands VT terminal escape codes
  158.     // This positions the cursor on row 2, column 0
  159.     // we can use variables for this with format codes too
  160.     // e.g. printf ("\x1b[%d;%dH", row, column );
  161.     printf("\x1b[2;0H");
  162.     printf("Mattie's test dinges");
  163.  
  164.     while (1)
  165.     {
  166.  
  167.         // Call WPAD_ScanPads each loop, this reads the latest controller states
  168.         WPAD_ScanPads();
  169.  
  170.         // WPAD_ButtonsDown tells us which buttons were pressed in this loop
  171.         // this is a "one shot" state which will not fire again until the button has been released
  172.         u32 pressed = WPAD_ButtonsDown(0);
  173.  
  174.         // IR Movement
  175.         WPAD_IR(0, &ir);
  176.  
  177.         if (pressed & WPAD_BUTTON_1)
  178.         {
  179.             WPAD_Rumble(0, 1);
  180.             usleep(200000);
  181.             WPAD_Rumble(0, 0);
  182.             WPAD_Rumble(0, 1);
  183.             usleep(500000);
  184.             WPAD_Rumble(0, 0);
  185.         }
  186.         if (pressed & WPAD_BUTTON_2)
  187.         {
  188.             WPAD_Rumble(0, 0);
  189.         }
  190.  
  191.         if (pressed & WPAD_BUTTON_A)
  192.         {
  193.             printf("\x1b[0;0H");
  194.             printf("bla bla bla");
  195.         }
  196.  
  197.         // We return to the launcher application via exit
  198.         if (pressed & WPAD_BUTTON_HOME)
  199.             exit(0);
  200.  
  201.         VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
  202.  
  203.         DrawBox(ir.x, ir.y, ir.x + 5, ir.y + 5, COLOR_WHITE);
  204.  
  205.         ML_DrawBackground(&background); // Draws the background on the screen
  206.  
  207. //      display_jpeg(plaatje, 0, 0);
  208.  
  209. //      display_jpeg(arrow, ir.x, ir.y);
  210.  
  211.         // Wait for the next frame
  212.         VIDEO_WaitVSync();
  213.     }
  214.  
  215.     return 0;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment