Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "loader.h"
- void _start()
- {
- /****************************> Clean up everything <****************************/
- //Load a good stack
- asm(
- "lis %r1, 0x1ab5 ;"
- "ori %r1, %r1, 0xd138 ;"
- );
- //Get a handle on coreinit
- uint32_t coreinit_handle;
- OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
- //IM Shutdown functions
- int (*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
- int (*IM_Close)(int fd);
- int (*IM_Open)(void);
- //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 Shutdown functions
- OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);
- OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
- OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
- //OS Memory functions
- OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
- OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
- //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--) ;
- /****************************> Get Handles <****************************/
- //Get a handle to coreinit.rpl
- OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
- //Get a handle to vpad.rpl
- uint32_t vpad_handle;
- OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
- //Get a handle to nsysnet.rpl
- uint32_t nsysnet_handle;
- OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
- //Get a handle to gx2.rpl
- uint32_t gx2_handle;
- OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
- /****************************> External Prototypes <****************************/
- //OSScreen functions
- void (*OSScreenInit)(void);
- uint32_t (*OSScreenGetBufferSizeEx)(uint32_t bufferNum);
- uint32_t (*OSScreenSetBufferEx)(uint32_t bufferNum, void *addr);
- //Misc functions
- uint32_t (*OSGetSystemTick)(void);
- void (*OSSleepTicks)(uint32_t ticks);
- void (*DCFlushRange)(const void *addr, uint32_t length);
- void (*GX2WaitForVsync)(void);
- //VPAD functions
- int (*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *error);
- // Socket functions
- int (*socket)(int family, int type, int proto);
- int (*connect)(int fd, struct sockaddr *addr, int addrlen);
- int (*send)(int fd, const void *buffer, int len, int flags);
- int (*recv)(int fd, void *buffer, int len, int flags);
- void(*socket_lib_init)(void);
- //OS functions
- void (*_Exit)();
- /****************************> Exports <****************************/
- //OSScreen functions
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSGetSystemTick", &OSGetSystemTick);
- OSDynLoad_FindExport(coreinit_handle, 0, "OSSleepTicks", &OSSleepTicks);
- OSDynLoad_FindExport(gx2_handle, 0, "GX2WaitForVsync", &GX2WaitForVsync);
- //VPAD functions
- OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead);
- //Socket functions
- OSDynLoad_FindExport(nsysnet_handle, 0, "socket", &socket);
- OSDynLoad_FindExport(nsysnet_handle, 0, "connect", &connect);
- OSDynLoad_FindExport(nsysnet_handle, 0, "recv", &recv);
- OSDynLoad_FindExport(nsysnet_handle, 0, "send", &send);
- OSDynLoad_FindExport(nsysnet_handle, 0, "socket_lib_init", &socket_lib_init);
- //OS functions
- OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
- /****************************> Initial Setup <****************************/
- //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);
- //Clear both framebuffers.
- int ii = 0;
- for (ii; ii < 2; ii++)
- {
- fillScreen(0,0,0,0);
- flipBuffers();
- }
- VPADData vpad_data;
- uint32_t error;
- socket_lib_init();
- /* Set up our socket address structure */
- struct sockaddr sin;
- sin.sin_family = AF_INET;
- sin.sin_port = 42069;
- sin.sin_addr.s_addr = PC_IP;
- int i, j;
- for (i = 0; i < 8; i++) sin.sin_zero[i] = 0;
- int clr01 = 0xFFFFFFFF;
- int clr02 = 0x500000FF;
- int clr03 = 0xF84070FF;
- int clr04 = 0xF8D870FF;
- int clr05 = 0xB02860FF;
- int clr06 = 0xD8A038FF;
- int clr07 = 0xF8F8F8FF;
- int clr08 = 0x000000FF;
- int clr09 = 0xF8D0C0FF;
- int clr10 = 0x885818FF;
- int clr11 = 0xF87068FF;
- int clr12 = 0x408098FF;
- int clr13 = 0x80D8C8FF;
- int clr14 = 0x203088FF;
- int mario[20][14] = {
- {clr01, clr01, clr01, clr01, clr01, clr01, clr02, clr02, clr02, clr02, clr02, clr01, clr01, clr01},
- {clr01, clr01, clr01, clr01, clr02, clr02, clr03, clr03, clr03, clr04, clr03, clr02, clr01, clr01},
- {clr01, clr01, clr01, clr02, clr03, clr03, clr05, clr05, clr06, clr04, clr07, clr02, clr01, clr01},
- {clr01, clr01, clr02, clr05, clr03, clr05, clr05, clr08, clr08, clr08, clr08, clr08, clr08, clr01},
- {clr01, clr02, clr05, clr05, clr05, clr08, clr08, clr08, clr08, clr08, clr08, clr08, clr08, clr08},
- {clr01, clr02, clr09, clr08, clr08, clr08, clr11, clr08, clr11, clr08, clr11, clr01, clr01, clr01},
- {clr02, clr09, clr10, clr09, clr08, clr11, clr09, clr08, clr09, clr08, clr09, clr10, clr10, clr01},
- {clr02, clr11, clr10, clr09, clr08, clr08, clr09, clr09, clr09, clr09, clr09, clr09, clr09, clr10},
- {clr02, clr08, clr11, clr09, clr08, clr09, clr09, clr08, clr11, clr11, clr11, clr11, clr11, clr10},
- {clr01, clr08, clr08, clr11, clr11, clr09, clr08, clr08, clr08, clr08, clr08, clr08, clr08, clr01},
- {clr01, clr01, clr08, clr10, clr10, clr11, clr11, clr11, clr08, clr08, clr08, clr08, clr01, clr01},
- {clr01, clr01, clr01, clr02, clr05, clr10, clr10, clr10, clr10, clr14, clr01, clr01, clr01, clr01},
- {clr01, clr01, clr02, clr05, clr05, clr03, clr12, clr12, clr13, clr13, clr14, clr01, clr01, clr01},
- {clr01, clr01, clr02, clr10, clr10, clr10, clr12, clr07, clr07, clr13, clr07, clr14, clr01, clr01},
- {clr01, clr01, clr10, clr07, clr07, clr07, clr10, clr07, clr07, clr13, clr07, clr14, clr01, clr01},
- {clr01, clr01, clr10, clr07, clr07, clr10, clr12, clr12, clr12, clr13, clr13, clr14, clr01, clr01},
- {clr01, clr01, clr10, clr07, clr07, clr10, clr12, clr12, clr14, clr12, clr14, clr01, clr01, clr01},
- {clr01, clr01, clr01, clr10, clr10, clr10, clr10, clr08, clr10, clr08, clr01, clr01, clr01, clr01},
- {clr01, clr01, clr01, clr08, clr10, clr10, clr10, clr04, clr08, clr04, clr08, clr01, clr01, clr01},
- {clr01, clr01, clr01, clr08, clr08, clr08, clr08, clr08, clr08, clr08, clr08, clr01, clr01, clr01}
- };
- int enabled = 0;
- int x = 0, y = 0;
- int ticksPerFrame = 1035937;
- uint32_t time0, time1;
- while (1)
- {
- VPADRead(0, &vpad_data, 1, &error);
- if (vpad_data.btn_trigger & BUTTON_A) {
- /* Connect to the PC */
- /*for (i = 0; i < 20; i++) {
- for (j = 0; j < 14; j++) {
- makeBigPixel(j, i, mario[i][j]);
- }
- }*/
- /*uint32_t buffer[1];
- uint32_t *screen = (void *) 0xF4000000;
- int count = 0, red = 0;
- for (i = 0;i < buf0_size / 8; i++) {
- buffer[0] = ((red << 24) | (256 << 16) | (0 << 8) | (256 << 4));
- memcpy(screen, buffer, 4);
- DCFlushRange(screen, 16);
- screen += 1; count += 1;
- if (i % width == 0) red += 1;
- }*/
- /*int rpc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- int status = connect(rpc, &sin, 0x10);
- if (status) break;
- uint32_t *screen = (void *) 0xF4000000;
- uint32_t buffer[256 * height * 5];
- int pos = 0;*/
- /*for (i = 0; i < height * 5; i++) {
- recv(rpc, (void*)buffer+(i*0x400), 0x400, 0);
- for (j = 0; j < 256; j++) {
- memcpy(screen, (void*)buffer+(j*4), 4);
- DCFlushRange(screen, 16);
- screen += 1;
- }
- }*/
- /*int rpc = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- int status = connect(rpc, &sin, 0x10);
- if (status) break;
- char *screen = (void *)0xF4000000;
- char buffer[0x400];
- int width = 1280;
- int x = 0, y = 0;
- for (i = 0; i < (0x384000 / 0x400); i++) {
- recv(rpc,(void*)buffer, 0x400, 0);
- for (j = 0; j < 256; j++) {
- uint32_t v=((x*2+y*2)*width);
- screen[v+0] = buffer[j*4];
- screen[v+1] = buffer[j*4+1];
- screen[v+2] = buffer[j*4+2];
- screen[v+3] = buffer[j*4+3];
- x += 1;
- if (x == width) {x = 0; y += 1;}
- }
- }*/
- }
- if (vpad_data.btn_hold & BUTTON_RIGHT) {
- time0 = OSGetSystemTick();
- x += 1;
- for (i = 0; i < 20; i++) {
- for (j = 0; j < 14; j++) {
- makeBigPixel(j + x, i + y, mario[i][j]);
- }
- }
- time1 = OSGetSystemTick();
- OSSleepTicks(ticksPerFrame - (time1 - time0));
- }
- if (vpad_data.btn_hold & BUTTON_DOWN) {
- time0 = OSGetSystemTick();
- x += 1;
- for (i = 0; i < 20; i++) {
- for (j = 0; j < 14; j++) {
- makeBigPixel(j + x, i + y, mario[i][j]);
- }
- }
- time1 = OSGetSystemTick();
- OSSleepTicks(ticksPerFrame - (time1 - time0));
- }
- if (vpad_data.btn_trigger & BUTTON_HOME) break;
- }
- //WARNING: DO NOT CHANGE THIS. YOU MUST CLEAR THE FRAMEBUFFERS AND IMMEDIATELY CALL EXIT FROM THIS FUNCTION. RETURNING TO LOADER CAUSES FREEZE.
- for(ii=0;ii<2;ii++)
- {
- fillScreen(0, 0, 0, 0);
- flipBuffers();
- }
- _Exit();
- }
- void makeBigPixel(int x, int y, int color) {
- int width = 1280;
- int height = 720;
- int i, j;
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 4; j++) {
- makePixel((x * 4) + i, (y * 4) + j, color);
- }
- }
- }
- void makePixel(int x, int y, int color) {
- unsigned int coreinit_handle;
- OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
- void (*DCFlushRange)(void *buffer, uint32_t length);
- OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange);
- int width = 1280;
- int height = 720;
- uint32_t buffer[1];
- uint32_t *screen = (void *) 0xF4000000;
- buffer[0] = color;
- screen += (x + (y * width));
- memcpy(screen, buffer, 4);
- DCFlushRange(screen, 16);
- }
- void* memcpy(void* dst, void* src, uint32_t size)
- {
- uint32_t i;
- for (i = 0; i < size; i++)
- ((uint8_t*) dst)[i] = ((const uint8_t*) src)[i];
- return dst;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement