Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void _start()
- {
- /****************************> Fix Stack <****************************/
- //Load a good stack
- asm(
- "lis %r1, 0x1ab5 ;"
- "ori %r1, %r1, 0xd138 ;"
- );
- /****************************> Get Handles <****************************/
- //Get a handle to coreinit.rpl
- unsigned int coreinit_handle;
- OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
- /****************************> External Prototypes <****************************/
- //OSScreen functions
- void(*OSScreenInit)();
- unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
- unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);
- //OS Memory functions
- void*(*memset)(void * dest, uint32_t value, uint32_t bytes);
- void*(*OSAllocFromSystem)(uint32_t size, int align);
- void(*OSFreeToSystem)(void *ptr);
- //IM functions
- int(*IM_Open)();
- int(*IM_Close)(int fd);
- int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
- /****************************> Exports <****************************/
- //OSScreen functions
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
- //OS Memory functions
- OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
- //IM functions
- OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
- OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
- OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);
- /****************************> Initial Setup <****************************/
- //Restart system to get lib access
- int fd = IM_Open();
- void *mem = OSAllocFromSystem(0x100, 64);
- memset(mem, 0, 0x100);
- //set restart flag to force quit browser
- IM_SetDeviceState(fd, mem, 3, 0, 0);
- IM_Close(fd);
- OSFreeToSystem(mem);
- //wait a bit for browser end
- unsigned int t1 = 0x1FFFFFFF;
- while(t1--) ;
- //Call the Screen initilzation function.
- OSScreenInit();
- //Grab the buffer size for each screen (TV and gamepad)
- int buf0_size = OSScreenGetBufferSizeEx(0);
- int buf1_size = OSScreenGetBufferSizeEx(1);
- //Set the buffer area.
- OSScreenSetBufferEx(0, (void *)0xF4000000);
- OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);
- unsigned int(*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp);
- unsigned int(*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int line, void * buffer);
- void(*DCFlushRange)(void *buffer, unsigned int length);
- unsigned int(*OSScreenFlipBuffersEx)(unsigned int bufferNum);
- unsigned int(*OSScreenPutPixelEx)(unsigned int buffer, unsigned int x, unsigned int y, unsigned int colour);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenPutFontEx", &OSScreenPutFontEx);
- OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenPutPixelEx", &OSScreenPutPixelEx);
- //Clear both framebuffers.
- int ii = 0;
- for (ii; ii < 2; ii++)
- {
- OSScreenClearBufferEx(0, 0x000000FF); // Make sure that the TV screen's frame buffer is full of black (0x000000FF is equivalent to red=0, green=0, blue=0, alpha=255)
- DCFlushRange((void *)0xF4000000, buf0_size); // Flush the TV buffer's cache before finally...
- OSScreenFlipBuffersEx(0); // Rendering the changes to the TV screen only!
- OSScreenClearBufferEx(1, 0x000000FF); // Do the same for the GamePad screen. (above, the 0 represents buffer 0 - or the TV screen, the 1 here represents buffer 1 - the first GamePad)
- DCFlushRange((void *)0xF4000000 + buf0_size, buf1_size);
- OSScreenFlipBuffersEx(1);
- }
- int x = 0, y = 0; // Variables for drawing squares to the screen.
- /* Now, let's start our rendering! (to the TV screen, obviously) */
- OSScreenClearBufferEx(0, 0xFF0000FF); // Make the TV screen red (red=255, green=0, blue=0, alpha=255)
- for(x = 0; x < 50; x++) {
- for(y = 0; y < 50; y++) {
- OSScreenPutPixelEx(0, x, y, 0x0000FFFF); // Insert a blue pixel at the x and y coordinates (r=0 g=0 b=255 a=255)
- }
- }
- OSScreenPutFontEx(0, 3, 2, "This is the TV Screen."); // Write text to the TV
- DCFlushRange((void *)0xF4000000, buf0_size); // Flush the buffer cache
- OSScreenFlipBuffersEx(0); // Render changes
- /* Render to the GamePad screen, now. */
- OSScreenClearBufferEx(1, 0x00FF00FF); // Green background (you get the hang of hex colors eventually)
- for(x = 100; x < 150; x++) {
- for(y = 100; y < 150; y++) {
- OSScreenPutPixelEx(1, x, y, 0x0000FFFF);
- }
- }
- OSScreenPutFontEx(1, 5, 4, "This is the Wii U GamePad Screen.");
- DCFlushRange((void *)0xF4000000 + buf0_size, buf1_size);
- OSScreenFlipBuffersEx(1);
- /* Wait a few seconds before exiting... */
- t1 = 0xF0000000; // Approximately eight seconds (maybe?)
- while(t1--);
- for (ii; ii < 2; ii++)
- {
- OSScreenClearBufferEx(0, 0x000000FF); // Make sure that the TV screen's frame buffer is full of black (0x000000FF is equivalent to red=0, green=0, blue=0, alpha=255)
- DCFlushRange((void *)0xF4000000, buf0_size); // Flush the TV buffer's cache before finally...
- OSScreenFlipBuffersEx(0); // Rendering the changes to the TV screen only!
- OSScreenClearBufferEx(1, 0x000000FF); // Do the same for the GamePad screen. (above, the 0 represents buffer 0 - or the TV screen, the 1 here represents buffer 1 - the first GamePad)
- DCFlushRange((void *)0xF4000000 + buf0_size, buf1_size);
- OSScreenFlipBuffersEx(1);
- }
- _Exit(); // Return to HOME Menu
- }
Add Comment
Please, Sign In to add comment