Homebrew Homebrew Development

  • Thread starter Thread starter aliak11
  • Start date Start date
  • Views Views 1,475,016
  • Replies Replies 6,048
  • Likes Likes 54
For what i'm creating is not necessary checking if the image exists cause it always exists.

I would suggest you read more about pointers in C language because it does not seem you understand what you are doing.

A pointer is more or less the same as a memory address.
When you want to declare an object (here a "Bitmap" type object) in memory , you need to allocate it first.
This is what the "malloc" function does.
That function returns a memory address if it was able to allocate memory for that object and NULL if there wasn't enough memory left for it.

So yes, it's necessary to check the return value after calling malloc, it has nothing to do with "checking the image exists" (whatever that means) but is checking that memory was properly allocated for the Bitmap object before attempting to write to it.

Writing to an uninitialized pointer is like trying to write to address zero in memory, which generally causes a crash.

I give you another question: http://gbatemp.net/attachments/libjpeg_example-zip.14595/
The code i wrote is inspired from this sample.
Then why it works and mine not?

The sample code in that link (main.c) does not use a pointer to a "Bitmap" type object.
Your code wants to return a pointer to a "Bitmap" type object but never allocates memory for that object.
That's the difference and the reason it crashes, as explained already to you several times now.
 
  • Like
Reactions: ernilos
I would suggest you read more about pointers in C language because it does not seem you understand what you are doing.

A pointer is more or less the same as a memory address.
When you want to declare an object (here a "Bitmap" type object) in memory , you need to allocate it first.
This is what the "malloc" function does.
That function returns a memory address if it was able to allocate memory for that object and NULL if there wasn't enough memory left for it.

So yes, it's necessary to check the return value after calling malloc, it has nothing to do with "checking the image exists" (whatever that means) but is checking that memory was properly allocated for the Bitmap object before attempting to write to it.

Writing to an uninitialized pointer is like trying to write to address zero in memory, which generally causes a crash.



The sample code in that link (main.c) does not use a pointer to a "Bitmap" type object.
Your code wants to return a pointer to a "Bitmap" type object but never allocates memory for that object.
That's the difference and the reason it crashes, as explained already to you several times now.

I know what a pointer is, i only mismatched your words but also adding a malloc, result not changes, it still crash.
 
I can't find anymore the tool to convert a bmp to a raw bin file to be memcopyed in a framebuffer, and i'm too lazy to code again it myself.

Frow what I remember it was on smealum github, but don't remember in what repo.

Someone can be so kind to remember me how to find it?
 
  • Like
Reactions: AlbertoSONIC
If anyone is looking to quickly deploy and test CIA files while developing homebrew, I just added support for installing CIA files over the network to my CIA installer, FBI. You'll need to build sockfile in order to send CIA files to it. Once both are set up, you can press Y to open FBI for connections, run "sockfile <ip> <file>" on your PC, and confirm the transmission to install a CIA file.

I've tested it a few times with small CIAs, so it should work fine with those. I haven't tested larger CIAs yet, but they should work as well.

Very nice work.
 
Oh come on, I was just excited. I've never developed any homebrew for anything before, you know.
I'm just messing with you. It's great that you're trying stuff out. That's how I got into it.

3DS homebrew has a very different style than Wii homebrew, but they use the same language. I add plenty of notes to my Wii source code so people looking to learn can do so from it. You might want to check it out.
 
  • Like
Reactions: Kelton2
I'm trying to add BCWAV support to lpp-3ds but i have one question.
For my tests i'm using this file: https://github.com/YourNerdyJoe/Chip8-CTRU/blob/master/res/default.bcwav

According to its header ( http://3dbrew.org/wiki/BCWAV ) it seems to be encoded as Big Endian but data in INFO chunk seems to be encoded as Little Endian. Does endianess change only for DATA chunk?

Also what about bitpersample?
Actually that file is in LE order. The 3DS is a Little Endian system, so when you read the two bytes referring to the endianess in the header, the first byte is the least significant one. So if you have FF FE (like in this case) it actually represents 0xFEFF (which means that the whole file is in LE order).
 
  • Like
Reactions: Rinnegatamante
Actually that file is in LE order. The 3DS is a Little Endian system, so when you read the two bytes referring to the endianess in the header, the first byte is the least significant one. So if you have FF FE (like in this case) it actually represents 0xFEFF (which means that the whole file is in LE order).

Does exist a BCWAV player? (Or just a converter to a playable format?)
 
This crashes after the third line printed out, Am i using "gfxFlushBuffers();" and "gfxSwapBuffers();" wrong?
Code:
#include <stdio.h>
#include <string.h>
#include <3ds.h>
 
 
void writeLine(char* zin) {
    printf(zin);
    printf("\n");
    gfxFlushBuffers();
    gfxSwapBuffers();
}
int main()
{
    aptInit();
    gfxInitDefault();
    consoleInit(GFX_BOTTOM, NULL);
    hidInit(NULL);
 
    writeLine("Hello World");
    writeLine("Press B to exit");
    //Flushes the buffer
 
    while(aptMainLoop()) //Always have the main code loop in here
    {
            hidScanInput(); //Checks which keys are pressed
 
            u32 button = hidKeysDown(); // Checks which keys are up and which ones are down
            if(button & KEY_A) {
                writeLine("You pressed A");
            }
            if(button & KEY_X) {
                writeLine("You pressed X");
            }
            if(button & KEY_Y) {
                writeLine("You pressed Y");
            }
           
            if(button & KEY_B) break;
    }
 
    // Exit services
    aptExit();
    gfxExit();
    hidExit();
    return 0;
}
 
This crashes after the third line printed out, Am i using "gfxFlushBuffers();" and "gfxSwapBuffers();" wrong?
You should copy "gspWaitForVBlank();" to the top or the bottom of the while loop. It waits for the next frame so that the application has a set speed at 60 FPS.
 
I abandoned BCWAV tests and started working BCSTM files.
For now, i'm trying to reproduce a simple mono BCSTM file but i'm having some issues with playback.
When i start playback, main sound is a noise and as background sound there is the real music of BCSTM file but with low volume and deformed audio (like if you use an equalizator).

This is my actual code, any ideas? (maybe, i'm wrong with offsets or encoding i'm using for CSND_playsound?)
Code:
static int lua_openbcstm(lua_State *L)
{
    int argc = lua_gettop(L);
    if ((argc != 1) && (argc != 2)) return luaL_error(L, "wrong number of arguments");
    const char *file_tbo = luaL_checkstring(L, 1);
    u32 mem_size = 0;
    if (argc == 2) mem_size = luaL_checkint(L, 2);
    Handle fileHandle;
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, file_tbo);
    Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    if(ret) return luaL_error(L, "error opening file");
    u32 magic,samplerate,bytesRead;
    FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
    if (magic == 0x4D545343){   
    wav *wav_file = (wav*)malloc(sizeof(wav));
    strcpy(wav_file->author,"");
    wav_file->encoding = CSND_ENCODING_IMA_ADPCM;
    strcpy(wav_file->title,"");
    u16 pos,pos2;
    FSFILE_Read(fileHandle, &bytesRead, 6, &pos, 2);
    //INFO chunk
    FSFILE_Read(fileHandle, &bytesRead, pos+4, &pos2, 2);
    FSFILE_Read(fileHandle, &bytesRead, pos+0x24, &wav_file->samplerate, 4);
    wav_file->bytepersample = 2;
    //DATA chunk
    pos2 = pos2 + pos;
    u64 size;
    FSFILE_GetSize(fileHandle, &size);
    wav_file->mem_size = mem_size;
    if (mem_size > 0){ //Set up streaming
    wav_file->moltiplier = 1;
    wav_file->isPlaying = false;
    wav_file->mem_size = (size-(pos2+8))/mem_size;
    wav_file->sourceFile = fileHandle;
    wav_file->audiobuf = (u8*)linearAlloc((size-(pos2+8))/mem_size);
    wav_file->startRead = (pos2+8);
    FSFILE_Read(fileHandle, &bytesRead, wav_file->startRead, wav_file->audiobuf, (size-(pos2+8))/mem_size);
    wav_file->audiobuf2 = NULL;
    wav_file->size = size;
    }else{ //Direct reproduction
    wav_file->audiobuf = (u8*)linearAlloc(size-(pos2+8));
    FSFILE_Read(fileHandle, &bytesRead, pos2+8, wav_file->audiobuf, size-(pos2+8));
    wav_file->audiobuf2 = NULL;
    wav_file->size = size-(pos2+8);
    wav_file->startRead = 0;
    }
    lua_pushnumber(L,(u32)wav_file);
    }
    if (mem_size == 0){
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
    }
    return 1;
}
 
Rinnegatamante's bcwav question reminded me of something I meant to release back in July.
https://github.com/YourNerdyJoe/debanner
Nothing big, just separates the CBMD and BCWAV files from a banner file.
I believe I got the default.bcwav from the banner.bin that came with makerom using this.
 
  • Like
Reactions: hippy dave
Mhhh seems to be buggy the IMA_ADPCM decoder. I tried to encode a WAV file with IMA_ADPCM codec with ffmpeg and i get crappy bugged sound.
Maybe it could be too high samplerate? (But with WMP it works fine...).
 
Could someone post an example where they give a background color?
Whatever i try, i just got a green, red, blue, red line, over and over again.
 
This is the code where i draw the background, i got only stripes on my screen, and not the color i selected.

Code:
    union{ u32 color; struct{ u8 a, b, g, r; } rgba; } rgbaColor;
    rgbaColor.color = color;
 
    int i;
    for (i = 0; i<fbWidth*fbHeight; i++)
    {
        *(fbAdr++) = (u8)(rgbaColor.rgba.b);
        *(fbAdr++) = (u8)(rgbaColor.rgba.g);
        *(fbAdr++) = (u8)(rgbaColor.rgba.r);
    }
 

Site & Scene News

Popular threads in this forum