Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. //Loads framebuffer from sd card
  2. //Parameters: Specify top screen or bottom screen. The origin (x,y) cordinates. The (width,height) cordinates., Filepath in sd card to use.
  3. void loadFramebufferFromSDCard()
  4. {
  5.  
  6. fsInit(); //needed for filesystem stuff
  7. u8* buffer;
  8. u32 size;
  9. u32 bytesRead;
  10. Handle fileHandle;
  11. //setup SDMC archive
  12. FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
  13. //create file path struct (note : FS_makePath actually only supports PATH_CHAR, it will change in the future)
  14. FS_path filePath=FS_makePath(PATH_CHAR, "/test.bin");
  15.  
  16. //open file
  17. Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
  18.  
  19. //check for errors : exit if there is one
  20. if(ret)goto exit;
  21.  
  22. //get screen size
  23. size=320*240*3; // RELYS: x resolution * y resolution * 3 colors per pixel
  24.  
  25. //allocate a buffer on linear heap (could just be a malloc fwiw)
  26. buffer=linearAlloc(size);
  27. if(!buffer)goto exit;
  28.  
  29. //read contents to framebuffer
  30. ret=FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
  31.  
  32. if(ret || size!=bytesRead)goto exit;
  33.  
  34. //copy buffer to lower famebuffer
  35. memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size);
  36.  
  37. //close the file because we like being nice and tidy
  38. ret=FSFILE_Close(fileHandle);
  39. if(ret)goto exit;
  40.  
  41. //cleanup and return
  42. //returning from main() returns to hbmenu when run under ninjhax
  43. exit:
  44. //closing all handles is super important
  45. svcCloseHandle(fileHandle);
  46.  
  47. }
  48.  
  49. //Saves framebuffer to sd card
  50. //Parameters: Specify top screen or bottom screen. The origin (x,y) cordinates. The (width,height) cordinates., Filepath in sd card to use.
  51. void saveFramebufferToSDCard()
  52. {
  53. fsInit(); //needed for filesystem stuff
  54. u8* buffer;
  55. u32 size;
  56. u32 bytesWritten;
  57. Handle fileHandle;
  58. //setup SDMC archive
  59. FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
  60. //create file path struct (note : FS_makePath actually only supports PATH_CHAR, it will change in the future)
  61. FS_path filePath=FS_makePath(PATH_CHAR, "/test.bin");
  62.  
  63. //open file
  64. 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
  65. //check for errors : exit if there is one
  66. if(ret)goto exit;
  67.  
  68. //get screen size
  69. size=320*240*3; // RELYS: x resolution * y resolution * 3 colors per pixel
  70.  
  71. //allocate a buffer on linear heap (could just be a malloc fwiw)
  72. buffer=linearAlloc(size);
  73. if(!buffer)goto exit;
  74.  
  75. //copy lower screen to buffer
  76. memcpy(buffer,gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), size);
  77.  
  78. //Write contents
  79. 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
  80. if(ret || size!=bytesWritten)goto exit;
  81.  
  82. //close the file because we like being nice and tidy
  83. ret=FSFILE_Close(fileHandle);
  84. if(ret)goto exit;
  85.  
  86. //cleanup and return
  87. //returning from main() returns to hbmenu when run under ninjhax
  88. exit:
  89. //closing all handles is super important
  90. svcCloseHandle(fileHandle);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement