Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- #include <ogcsys.h>
- #include <gccore.h>
- #include <wiiuse/wpad.h>
- #include <jpeg/jpgogc.h>
- #include <unistd.h>
- #include <MLlib.h>
- ML_Image backgroundData;
- ML_Background background;
- static void *xfb = NULL;
- static GXRModeObj *rmode = NULL;
- //extern char picdata[];
- //extern int piclength;
- //JPEGIMG plaatje;
- //
- //extern char picdata1[];
- //extern int piclength1;
- //JPEGIMG arrow;
- // Wiimote IR
- ir_t ir;
- void menuScherm()
- {
- ML_LoadBackgroundFromFile(&backgroundData, &background, "../include/Eiland.png", 640, 480);
- }
- void Initialise()
- {
- ML_Init();
- // ML_InitFAT();
- // Initialise the video system
- VIDEO_Init();
- // This function initialises the attached controllers
- WPAD_Init();
- WPAD_SetVRes(0, 640, 480);
- WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
- // Obtain the preferred video mode from the system
- // This will correspond to the settings in the Wii menu
- rmode = VIDEO_GetPreferredMode(NULL);
- // Allocate memory for the display in the uncached region
- xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
- // Initialise the console, required for printf
- console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth
- * VI_DISPLAY_PIX_SZ);
- // Set up the video registers with the chosen mode
- VIDEO_Configure(rmode);
- // Tell the video hardware where our display memory is
- VIDEO_SetNextFramebuffer(xfb);
- // Make the display visible
- VIDEO_SetBlack(FALSE);
- // Flush the video register changes to the hardware
- VIDEO_Flush();
- // Wait for Video setup to complete
- VIDEO_WaitVSync();
- if (rmode->viTVMode & VI_NON_INTERLACE)
- VIDEO_WaitVSync();
- }
- void DrawHLine(int x1, int x2, int y, int color)
- {
- int i;
- y = 320 * y;
- x1 >>= 1;
- x2 >>= 1;
- for (i = x1; i <= x2; i++)
- {
- u32 *tmpfb = (u32*) xfb;
- //u32 *tempfb = xfb
- //(u32*) is geadd zodat het van een void naar een u32
- tmpfb[y + i] = color;
- }
- }
- void DrawVLine(int x, int y1, int y2, int color)
- {
- int i;
- x >>= 1;
- for (i = y1; i <= y2; i++)
- {
- u32 *tmpfb = (u32*) xfb;
- tmpfb[x + (640 * i) / 2] = color;
- }
- }
- void DrawBox(int x1, int y1, int x2, int y2, int color)
- {
- DrawHLine(x1, x2, y1, color);
- DrawHLine(x1, x2, y2, color);
- DrawVLine(x1, y1, y2, color);
- DrawVLine(x2, y1, y2, color);
- }
- void display_jpeg(JPEGIMG jpeg, int x, int y)
- {
- unsigned int *jpegout = (unsigned int *) jpeg.outbuffer;
- int i, j;
- int height = jpeg.height;
- int width = jpeg.width - (jpeg.width / 2);
- u32 *tmpfb = (u32*) xfb;
- for (i = 0; i <= width; i++)
- for (j = 0; j <= height - 2; j++)
- tmpfb[(i + x) + 320 * (j + 16 + y)] = jpegout[i + width * j];
- free(jpeg.outbuffer);
- }
- //void initAFB()
- //{
- // //assign memory aan 'plaatje'
- // memset(&plaatje, 0, sizeof(JPEGIMG));
- // //haal wat dingen uit picture.s
- // plaatje.inbuffer = picdata;
- // plaatje.inbufferlength = piclength;
- // //decompress plaatje
- // JPEG_Decompress(&plaatje);
- //
- // //assign memory aan 'plaatje'
- // memset(&arrow, 0, sizeof(JPEGIMG));
- // //haal wat dingen uit picture.s
- // arrow.inbuffer = picdata1;
- // arrow.inbufferlength = piclength1;
- // //decompress plaatje
- // JPEG_Decompress(&arrow);
- //}
- int main(int argc, char **argv)
- {
- //---------------------------------------------------------------------------------
- // initAFB();
- Initialise();
- // The console understands VT terminal escape codes
- // This positions the cursor on row 2, column 0
- // we can use variables for this with format codes too
- // e.g. printf ("\x1b[%d;%dH", row, column );
- printf("\x1b[2;0H");
- printf("Mattie's test dinges");
- while (1)
- {
- // Call WPAD_ScanPads each loop, this reads the latest controller states
- WPAD_ScanPads();
- // WPAD_ButtonsDown tells us which buttons were pressed in this loop
- // this is a "one shot" state which will not fire again until the button has been released
- u32 pressed = WPAD_ButtonsDown(0);
- // IR Movement
- WPAD_IR(0, &ir);
- if (pressed & WPAD_BUTTON_1)
- {
- WPAD_Rumble(0, 1);
- usleep(200000);
- WPAD_Rumble(0, 0);
- WPAD_Rumble(0, 1);
- usleep(500000);
- WPAD_Rumble(0, 0);
- }
- if (pressed & WPAD_BUTTON_2)
- {
- WPAD_Rumble(0, 0);
- }
- if (pressed & WPAD_BUTTON_A)
- {
- printf("\x1b[0;0H");
- printf("bla bla bla");
- }
- // We return to the launcher application via exit
- if (pressed & WPAD_BUTTON_HOME)
- exit(0);
- VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
- DrawBox(ir.x, ir.y, ir.x + 5, ir.y + 5, COLOR_WHITE);
- ML_DrawBackground(&background); // Draws the background on the screen
- // display_jpeg(plaatje, 0, 0);
- // display_jpeg(arrow, ir.x, ir.y);
- // Wait for the next frame
- VIDEO_WaitVSync();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment