Advertisement
Reisyukaku

ARM9 thread w/ ScreenShot

Jul 1st, 2015
1,782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include "lib.h"
  2. #include "FS.h"
  3. #include <wchar.h>
  4. #include <stdio.h>
  5.  
  6. #define VRAM (unsigned char*)0x18000000
  7. #define FCRAM (unsigned char*)0x20000000
  8. #define ARM9_RAM (unsigned char*)0x8000000
  9. #define TOP_FRAME 0
  10. #define BOT_FRAME 1
  11.  
  12. unsigned char handle[32];
  13. unsigned char bmpHead[] = {
  14.     0x42, 0x4D, 0x36, 0x65, 0x04, 0x00, 0x00, 0x00,
  15.     0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
  16.     0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00,
  17.     0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
  18.     0x00, 0x00, 0x00, 0x65, 0x04, 0x00, 0x00, 0x00,
  19.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  20.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  21. };
  22.  
  23. void memdump(wchar_t* filename, unsigned char* buf, unsigned int size){
  24.     unsigned int br = 0;
  25.     memset(&handle, 0, 32);
  26.     fopen9(&handle, filename, 6);
  27.     fwrite9(&handle, &br, buf, size);
  28.     fclose9(&handle);
  29.     for(int i = 0; i < 0x46500; i++) *(VRAM+0x1E6000 + i) = 0xFF;
  30. }
  31.  
  32. void transpose (void * dst, const void * src, unsigned dim1, unsigned dim2, unsigned item_length) {
  33.   char * ptr_write;
  34.   const char * ptr_read;
  35.   unsigned x, y, z;
  36.   for (x = 0; x < dim1; x ++) for (y = 0; y < dim2; y ++) {
  37.     ptr_write = ((char *) dst) + item_length * (y * dim1 + x);
  38.     ptr_read = ((const char *) src) + item_length * (x * dim2 + y);
  39.     for (z = 0; z < item_length; z ++) *(ptr_write ++) = *(ptr_read ++);
  40.   }
  41. }
  42.  
  43. void screenShot(int frame){
  44.     unsigned int br;
  45.     short width = frame == 0 ? 400 : 320;
  46.     short height = 240;
  47.     int frameOff = frame == 0 ? 0x300000 : 0; //0x1E6000 : 0x48F000;  //<- Defaults
  48.     int length = frame == 0 ? 0x46500 : 0x38400;
  49.    
  50.     memset(&handle, 0, 32);
  51.     fopen9(&handle, frame == 0 ? L"sdmc:/screen_top.bmp" : L"sdmc:/screen_bot.bmp", 6);
  52.     transpose(FCRAM+0xF80000, VRAM+frameOff, width, height, 3);
  53.     bmpHead[18] = frame == 0 ? 0x90 : 0x40;
  54.     fwrite9(&handle, &br, bmpHead, 0x36);
  55.     fwrite9(&handle, &br, FCRAM+0xF80000, length);
  56.     fclose9(&handle);
  57.     for(int i = 0; i < length; i++) *(VRAM+frameOff + i) = 0xFF;
  58. }
  59.  
  60. void myThread(){
  61.     while(1){
  62.         if(getHID() & BUTTON_SELECT){
  63.                  screenShot(TOP_FRAME);
  64.                     screenShot(BOT_FRAME);
  65.         }
  66.             if(getHID() & BUTTON_START) memdump(L"sdmc:/VRAM.bin", VRAM, 0x00600000);
  67.     }
  68.     __asm("SVC 0x09");
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement