Homebrew Help Loading Image From SD Card [SPIDER]

gudenau

Largely ignored
OP
Member
Joined
Jul 7, 2010
Messages
3,834
Trophies
2
Location
/dev/random
Website
www.gudenau.net
XP
4,277
Country
United States
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. ;-)
 

gudenau

Largely ignored
OP
Member
Joined
Jul 7, 2010
Messages
3,834
Trophies
2
Location
/dev/random
Website
www.gudenau.net
XP
4,277
Country
United States
Not quite right...
bottom.png

20150131_184900.jpg
 

gudenau

Largely ignored
OP
Member
Joined
Jul 7, 2010
Messages
3,834
Trophies
2
Location
/dev/random
Website
www.gudenau.net
XP
4,277
Country
United States
Mind posting/ PM'ing source? I could take a look.

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.
 

shutterbug2000

Cubic NINJHAX!
Member
Joined
Oct 11, 2014
Messages
1,088
Trophies
0
Age
27
XP
4,740
Country
United States
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.

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)?
 

You may also like...

General chit-chat
Help Users
    K3N1 @ K3N1: https://youtu.be/ec_PoNcsgcY