Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Loads framebuffer from sd card
- //Parameters: Specify top screen or bottom screen. The origin (x,y) cordinates. The (width,height) cordinates., Filepath in sd card to use.
- void loadFramebufferFromSDCard()
- {
- fsInit(); //needed for filesystem stuff
- u8* buffer;
- u32 size;
- u32 bytesRead;
- Handle fileHandle;
- //setup SDMC archive
- FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
- //create file path struct (note : FS_makePath actually only supports PATH_CHAR, it will change in the future)
- FS_path filePath=FS_makePath(PATH_CHAR, "/test.bin");
- //open file
- Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
- //check for errors : exit if there is one
- if(ret)goto exit;
- //get screen size
- size=320*240*3; // RELYS: x resolution * y resolution * 3 colors per pixel
- //allocate a buffer on linear heap (could just be a malloc fwiw)
- buffer=linearAlloc(size);
- if(!buffer)goto exit;
- //read contents to framebuffer
- ret=FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
- if(ret || size!=bytesRead)goto exit;
- //copy buffer to lower famebuffer
- memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size);
- //close the file because we like being nice and tidy
- ret=FSFILE_Close(fileHandle);
- if(ret)goto exit;
- //cleanup and return
- //returning from main() returns to hbmenu when run under ninjhax
- exit:
- //closing all handles is super important
- svcCloseHandle(fileHandle);
- }
- //Saves framebuffer to sd card
- //Parameters: Specify top screen or bottom screen. The origin (x,y) cordinates. The (width,height) cordinates., Filepath in sd card to use.
- void saveFramebufferToSDCard()
- {
- fsInit(); //needed for filesystem stuff
- u8* buffer;
- u32 size;
- u32 bytesWritten;
- Handle fileHandle;
- //setup SDMC archive
- FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
- //create file path struct (note : FS_makePath actually only supports PATH_CHAR, it will change in the future)
- FS_path filePath=FS_makePath(PATH_CHAR, "/test.bin");
- //open file
- Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_CREATE, FS_ATTRIBUTE_NONE); //RELYS: Changed FS_OPEN_READ to FS_OPEN_CREATE. Not sure if FS_ATTRIBUTE_NONE needs to be changed to FS_ATTRIBUTE_ARCHIVE
- //check for errors : exit if there is one
- if(ret)goto exit;
- //get screen size
- size=320*240*3; // RELYS: x resolution * y resolution * 3 colors per pixel
- //allocate a buffer on linear heap (could just be a malloc fwiw)
- buffer=linearAlloc(size);
- if(!buffer)goto exit;
- //copy lower screen to buffer
- memcpy(buffer,gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), size);
- //Write contents
- ret=FSFILE_Write(fileHandle, &bytesWritten, 0x0, buffer,size,FS_WRITE_FLUSH); //RELYS: Not sure if we want to use FS_WRITE_FLUSH or FS_WRITE_NOFLUSH
- if(ret || size!=bytesWritten)goto exit;
- //close the file because we like being nice and tidy
- ret=FSFILE_Close(fileHandle);
- if(ret)goto exit;
- //cleanup and return
- //returning from main() returns to hbmenu when run under ninjhax
- exit:
- //closing all handles is super important
- svcCloseHandle(fileHandle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement