filfat

Wii U Console Output Example

Apr 9th, 2015
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. #include "coreinit.h"
  2. #define snprintf __os_snprintf
  3.  
  4. struct vector2D {
  5.     unsigned int x,y;
  6. };
  7.  
  8. //Fills the screen with a flat blue colour
  9. void clearScreen(unsigned int core_handle) {
  10.     unsigned int(*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp);
  11.     OSDynLoad_FindExport(core_handle, 0, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
  12.     unsigned int colour = (37 << 24) | (164 << 16) | (214 << 8) | 255;
  13.     OSScreenClearBufferEx(0, colour);
  14.     OSScreenClearBufferEx(1, colour);
  15. }
  16.  
  17. //Flip the buffers
  18. void flipBuffers(unsigned int core_handle) {
  19.     /* taken from Relys's libwiiu as i'm go lazy to re-code it :P */
  20.     void(*DCFlushRange)(void *buffer, unsigned int length);
  21.     unsigned int(*OSScreenFlipBuffersEx)(unsigned int bufferNum);
  22.     OSDynLoad_FindExport(core_handle, 0, "DCFlushRange", &DCFlushRange);
  23.     OSDynLoad_FindExport(core_handle, 0, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
  24.     unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
  25.     OSDynLoad_FindExport(core_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
  26.     int buf0_size = OSScreenGetBufferSizeEx(0);
  27.     int buf1_size = OSScreenGetBufferSizeEx(1);
  28.     DCFlushRange((void *)0xF4000000 + buf0_size, buf1_size);
  29.     DCFlushRange((void *)0xF4000000, buf0_size);
  30.     OSScreenFlipBuffersEx(0);
  31.     OSScreenFlipBuffersEx(1);
  32. }
  33.  
  34. void exit(char* log);
  35. void console(unsigned int core_handle, char* output, char* consoleBuffer, struct vector2D consoleCursor);
  36.  
  37. void _start() {
  38.    
  39.     /* Load a good stack */
  40.     asm(
  41.         "lis %r1, 0x1ab5 ;"
  42.         "ori %r1, %r1, 0xd138 ;"
  43.     );
  44.    
  45.     struct vector2D consoleCursor = {0,0};
  46.  
  47.     unsigned int net_handle;
  48.     unsigned int core_handle;
  49.     char consoleBuffer[20048];
  50.      
  51.     char debug[256];
  52.     OSDynLoad_Acquire("nlibcurl.rpl", &net_handle);
  53.     OSDynLoad_Acquire("coreinit.rpl", &core_handle);
  54.    
  55.     snprintf(debug, 255, "Console Demo By @filfat");
  56.     console(core_handle, debug, consoleBuffer, consoleCursor);
  57.    
  58.     //CURL* (*curl_easy_init)(void);
  59.     char* (*curl_version)(void);
  60.    
  61.     //OSDynLoad_FindExport(net_handle, 0, "curl_easy_init", &curl_easy_init);
  62.     OSDynLoad_FindExport(net_handle, 0, "curl_version", &curl_version);
  63.    
  64.     snprintf(debug, 255, "The cURL version of this console is: %s\n", curl_version());
  65.     console(core_handle, debug, consoleBuffer, consoleCursor);
  66.    
  67.     while(1){
  68.        
  69.     }
  70.     exit("You shouldn't be here\nGo back to the loop gwad damn it! :P");
  71. }
  72.  
  73. void console(unsigned int core_handle, char* output, char* consoleBuffer, struct vector2D consoleCursor) {
  74.     flipBuffers(core_handle);
  75.     clearScreen(core_handle);
  76.     unsigned int (*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, void* buffer);
  77.     OSDynLoad_FindExport(core_handle, 0, "OSScreenPutFontEx", &OSScreenPutFontEx);
  78.     snprintf(consoleBuffer,20048,"%s%s",consoleBuffer, output);
  79.     OSScreenPutFontEx(0, consoleCursor.x, consoleCursor.y, consoleBuffer);
  80.     OSScreenPutFontEx(1, consoleCursor.x, consoleCursor.y, consoleBuffer);
  81.     //consoleCursor.y += 25;
  82. }
  83.  
  84. void exit(char* log) {
  85.     //Let's Print the output and halt the system
  86.     OSFatal(log);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment