Help Loading Image From SD Card [SPIDER]

Discussion in '3DS - Homebrew Development and Emulators' started by gudenau, Feb 1, 2015.

  1. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    I am attempting to load an image from the SD card into the VRAM to display on the bottom screen, but it is not working.

    Any help?

    code.c
    Code:
    #define START_SECTION __attribute__ ((section (".text.start"), naked))
     
    // make sure code is PIE
    #ifndef __PIE__
    #error "Must compile with -fPIE"
    #endif
     
    // File IO
    #define FILE_R 0x1
    #define FILE_W 0x6
     
    typedef struct file_s {
        int s;
        int pos;
        int size;
    } FILE;
     
     
    int(*IFile_Open)(FILE *this, const short *path, int flags) = (void *)0x0022FE08;
    int(*IFile_Read)(FILE *this, unsigned int *read, void *buffer, unsigned int size) = (void *)0x001686DC;
    int(*IFile_Write)(FILE *this, unsigned int *written, void *src, unsigned int len) = (void *)0x00168764;
     
    // GPU
    int(*GX_SetTextureCopy)(void *input_buffer, void *output_buffer, unsigned int size, int in_x, int in_y, int out_x, int out_y, int flags) = 0x0011DD48;
    int(*GSPGPU_FlushDataCache)(void *addr, unsigned int len) = 0x00191504;
     
    // SVC
    int(*svcSleepThread)(unsigned long long nanoseconds) = 0x0023FFE8;
     
    int main();
     
    int START_SECTION entryPoint(){
        __asm__ volatile (".word 0xE1A00000");
        main();
        __asm__ volatile ("bx lr");
    }
     
    int main(){
        int i;
        FILE *file = (void *)0x08F10000;
        int *buf = 0x18410000;
        int *read = 0x08F10020;
     
        //for (i = 0; i < 0xE100; i += 3){
        //    buf[i] = 0x0000FF00;
        //    buf[i + 1] = 0xFF0000FF;
        //    buf[i + 2] = 0x00FF0000;
        //}
     
        IFile_Open(file, L"dmc:/splash.bin", FILE_R);
        IFile_Read(file, read, buf, 0xE100);
     
        GSPGPU_FlushDataCache(buf, 0x00038400);
        GX_SetTextureCopy(buf, 0x1F48F000, 0x00038400, 0, 0, 0, 0, 8);
        svcSleepThread(0x400000LL);
        GSPGPU_FlushDataCache(buf, 0x00038400);
        GX_SetTextureCopy(buf, 0x1F4C7800, 0x00038400, 0, 0, 0, 0, 8);
        svcSleepThread(0x400000LL);
     
        svcSleepThread (0x6fc23ac00LL); // wait 30 seconds
     
        return 0;
    }
     
    int exit(int status){
        return 0;
    }
    
    SplashConvert.java
    Code:
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.nio.ByteBuffer;
     
    import javax.imageio.ImageIO;
     
     
    public class SplashConvert {
        public static void main(String[] args) throws Throwable{
            System.out.println(args[0]);
            System.out.println(args[1]);
         
            BufferedImage image = ImageIO.read(new File(args[0]));
            FileOutputStream out = new FileOutputStream(new File(args[1]));
         
            int[] data = new int[image.getWidth() * image.getHeight()];
            image.getRGB(0, 0, image.getWidth(), image.getHeight(), data, 0, image.getWidth());
            ByteBuffer buffer = ByteBuffer.allocate(data.length*4);
            buffer.asIntBuffer().put(data);
            out.write(buffer.array());
            out.close();
        }
    }
    
    Edit:
    Extra credit for a clean exit function. ;-)
     
  2. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States
    I'll take a look :)
     
  3. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States
    Mind posting splash.bin?
     
  4. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    Yes, but I will make a test one real quick.
    (Has to do with a secret project. :-P)
     
  5. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States

    Ok :P
     
  6. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    Tada!
     

    Attached Files:

  7. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    I think I am copying an extra byte per pixel...
     
  8. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    Not quite right...
    bottom.png
    20150131_184900.jpg
     
  9. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States
    Same here.
     
  10. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    What is the format of the framebuffer? (RGB, BGR, etc)
     
  11. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States

    Honestly, I'm not sure :P.
     
  12. WulfyStylez

    WulfyStylez SALT/Bemani Princess

    Member
    1,149
    2,609
    Nov 3, 2013
    United States
    Probably RGBA, 8 bits per color. Try dumping it and looking at it for reference, though.
     
  13. vaguilar

    vaguilar Newbie

    Newcomer
    6
    11
    Jan 26, 2015
    United States
    BGR, one byte for each color.
     
  14. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    Thanks!
     
  15. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    I just had weird crap happen, I think it is a little closer though.
     
  16. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States

    Mind posting/ PM'ing source? I could take a look.
     
  17. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    That is many iterations behind, my current source just copies the top screen, it works though. :-P I think my file IO might not be working correctly.

    Code:
    #define START_SECTION __attribute__ ((section (".text.start"), naked))
     
    // make sure code is PIE
    #ifndef __PIE__
    #error "Must compile with -fPIE"
    #endif
     
    // File IO
    #define FILE_R 0x1
    #define FILE_W 0x6
     
    typedef struct file_s {
        int s;
        int pos;
        int size;
    } FILE;
     
     
    int(*IFile_Open)(FILE *this, const short *path, int flags) = (void *)0x0022FE08;
    int(*IFile_Read)(FILE *this, unsigned int *read, void *buffer, unsigned int size) = (void *)0x001686DC;
    int(*IFile_Write)(FILE *this, unsigned int *written, void *src, unsigned int len) = (void *)0x00168764;
     
    // GPU
    int(*GX_SetTextureCopy)(void *input_buffer, void *output_buffer, unsigned int size, int in_x, int in_y, int out_x, int out_y, int flags) = 0x0011DD48;
    int(*GSPGPU_FlushDataCache)(void *addr, unsigned int len) = 0x00191504;
     
    // SVC
    int(*svcSleepThread)(unsigned long long nanoseconds) = 0x0023FFE8;
     
    int main();
     
    int START_SECTION entryPoint(){
        __asm__ volatile (".word 0xE1A00000");
        main();
        __asm__ volatile ("bx lr");
    }
     
    int main(){
        FILE *file = (void *)0x08F10000;
        unsigned int address;
        int *buffer = 0x18410000;
        int *read = 0x08F10020;
        int i;
        unsigned int offset;
     
        IFile_Open(file, L"dmc:/splash.bin", FILE_R);
        file->pos = 0x00;
     
        for(i = 0x1F48F000; i < 0x1F48F000 + 0x38400; i += 1000){
            file->pos = i-0x1F48F000;
            IFile_Read(file, read, buffer, 0x1000);
            svcSleepThread(0x400000LL);
            buffer += 0x1000;
        }
     
        for(i = 0; i < 0x400; i++){
            GSPGPU_FlushDataCache(0x1F1E6000, 0x38400);
            GX_SetTextureCopy(0x1F1E6000, 0x1F48F000, 0x38400, 0, 0, 0, 0, 8);
            GSPGPU_FlushDataCache(0x1F48F000, 0x38400);
       
            GSPGPU_FlushDataCache(0x1F1E6000, 0x38400);
            GX_SetTextureCopy(0x1F1E6000, 0x1F4C7800, 0x38400, 0, 0, 0, 0, 8);
            GSPGPU_FlushDataCache(0x1F4C7800, 0x38400);
        }
     
        //0x1F48F000
     
        svcSleepThread (0x6fc23ac00LL); // wait 30 seconds
     
        return 0;
    }
    
    Please do not tell anybody the part I edited out.
     
  18. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States
    Don't worry, I won't tell. I'm not the kind of guy to do that(I AM interested however. But no leaking from me :))

    Anyway, could you post a sample splash.bin(with the bgr)?
     
  19. gudenau
    OP

    gudenau Largely ignored

    Member
    GBAtemp Patron
    gudenau is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,300
    1,253
    Jul 7, 2010
    United States
    /dev/random
    Here.
     

    Attached Files:

  20. shutterbug2000

    shutterbug2000 Cubic NINJHAX!

    Member
    1,081
    2,183
    Oct 11, 2014
    United States
    Hmm. Could you check to make sure you are creating splash.bin properly? Not sure what else could be causing garbage graphics.