Homebrew Homebrew Development

  • Thread starter Thread starter aliak11
  • Start date Start date
  • Views Views 1,493,318
  • Replies Replies 6,048
  • Likes Likes 54
Uhm, yes please!

It is weird though. I load up my homebrew that has all the text and what not, and even when I remove the sound stuff, it now crashes. I guess something updated and something I am using is outdated? Anyway, I'll try to do it from scratch and see where the problem is.

Edit: Also, would you happen to know how to convert wav files to bin? I've been googling and I can't seem to find a way to do it. I figured it would be a lot easier to do my idea for a homebrew with .bin files instead of using wav files loaded from the SD.

the .bin file is just the data segment of the .wav file.
just cut that segment (minus the header) into a new file with a hex editor and that should be fine.
 
Hello,
When I develop a 3DS homebrew, I build it quite often, and I want to test it on my 3DS regularly.
To do so, I used to use ftPONY/ftBRONY and nowadays I use latest version of hbmenu's "netcat" feature, and I have a problem:
hbmenu crashes randomly after 2 or 3 tests. I have to reboot my 3DS to be able to try again.
(the problem happens with both the ftp and the netcat solutions, on 3DS and new3DS)
The homebrews I test don't do anything CPU/memory-intensive, and don't leak memory: they are just very simple programs displaying a few pixels on the screen.
So do you know why this happens? Do you have the same problem? How do YOU do to test your work regularly? Is it a hbmenu bug? Will it be fixed soon?
Thanks for your advice :)
 
the .bin file is just the data segment of the .wav file.
just cut that segment (minus the header) into a new file with a hex editor and that should be fine.
And that worked perfectly after I figured out how big the header is ^^ (Normally 44 bytes, but it can be different)

Now, I love having condensed code. I have a code that I know that can be condenced more, I'm just not sure how to do it. If this was Javascript I would do it easily, buuuttt it's not. I was thinking about either using Array's or functions so that I can easily add more lines if need be.

Code:
    u8 *Ab4 = linearAlloc(piano_Ab4_bin_size);
    u8 *A4 = linearAlloc(piano_A4_bin_size);
    u8 *Bb4 = linearAlloc(piano_Bb4_bin_size);
    u8 *B4 = linearAlloc(piano_B4_bin_size);
    u8 *C4 = linearAlloc(piano_C4_bin_size);
    int a, b, c, d, e;
    for (a=0;a<piano_Ab4_bin_size;a++){
        memcpy(&Ab4[a], &piano_Ab4_bin[a], 1);
    }
    for (b=0;b<piano_A4_bin_size;b++){
        memcpy(&A4[b], &piano_A4_bin[b], 1);
    }
    for (c=0;c<piano_Bb4_bin_size;c++){
        memcpy(&Bb4[c], &piano_Bb4_bin[c], 1);
    }
    for (d=0;d<piano_B4_bin_size;d++){
        memcpy(&B4[d], &piano_B4_bin[d], 1);
    }
    for (e=0;e<piano_C4_bin_size;e++){
        memcpy(&C4[e], &piano_C4_bin[e], 1);
    }
 
  • Like
Reactions: YourNerdyJoe
And that worked perfectly after I figured out how big the header is ^^ (Normally 44 bytes, but it can be different)

Now, I love having condensed code. I have a code that I know that can be condenced more, I'm just not sure how to do it. If this was Javascript I would do it easily, buuuttt it's not. I was thinking about either using Array's or functions so that I can easily add more lines if need be.

Code:
    u8 *Ab4 = linearAlloc(piano_Ab4_bin_size);
    u8 *A4 = linearAlloc(piano_A4_bin_size);
    u8 *Bb4 = linearAlloc(piano_Bb4_bin_size);
    u8 *B4 = linearAlloc(piano_B4_bin_size);
    u8 *C4 = linearAlloc(piano_C4_bin_size);
    int a, b, c, d, e;
    for (a=0;a<piano_Ab4_bin_size;a++){
        memcpy(&Ab4[a], &piano_Ab4_bin[a], 1);
    }
    for (b=0;b<piano_A4_bin_size;b++){
        memcpy(&A4[b], &piano_A4_bin[b], 1);
    }
    for (c=0;c<piano_Bb4_bin_size;c++){
        memcpy(&Bb4[c], &piano_Bb4_bin[c], 1);
    }
    for (d=0;d<piano_B4_bin_size;d++){
        memcpy(&B4[d], &piano_B4_bin[d], 1);
    }
    for (e=0;e<piano_C4_bin_size;e++){
        memcpy(&C4[e], &piano_C4_bin[e], 1);
    }

Wav Header file is easily calculable:
Code:
u32 pos = 16;
while (chunk != 0x61746164){
FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
pos=pos+4+jump;
FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
pos=pos+4;
}
With this simple portion of code, at the end of the process you will have the data chunk size address to pos and the begin of data chunk at pos+4. (So to get raw audiobuff, you simple have to do size-(pos+4))
 
Cyan, how did you find wave before I said anything. Even after posting it here and having it on the wiki page, I still cannot find it with a Google search.
 
I looked at contributor's list in currently known homebrew on Git, and following each user's projects to find contributors, etc.
I also searched "3DS" in the git search engine, and it displayed a lot of unknown project or developers, sometime even empty git place like the lynx emulator.

I probably missed some, and didn't look on googlecode yet, but most of them should be listed on wiki now.
I hoped to contribute more to the wiki, but it took more time than I thought to properly reference all homebrew (detail, changelog, uploading files when needed, pictures, finding all info on developers and links, etc.) so it's currently a little empty.
only the list of homebrew and utilities are maintained.

I just hope dev will now create a page for their projects too (even if it's only the page creation + minimal info box : name, dev, link).
No need to fill it will pictures/info/controls/etc.

I'm leaving for a week, but I don't expect big releases or new project to be announced. if it happen I'll add them when I'll be back.


I have a question:
I still want to create a game (a port from another little game, I have sources in another language, I'll port it to C++).
I read smealum is updating GFX/aemstro, so it will probably change soon.
I looked at GFX example, and it's using textures.
How are created the textures? which tools are used to convert them?
Can I paint models with plain color instead of texturing them?
Thank you :)
 
I looked at GFX example, and it's using textures.
How are created the textures? which tools are used to convert it?
Can I paint models with plain color instead of texturing them?
Thank you :)
3dscraft has a python script to convert png files to the proper block encoded format - texconv.py
the format is fairly simple so converting it to C is trivial.
I have had issues getting the 3d samples working with the current ctrulib/aemstro on github. hopefully you will have better luck.
 
Forgive the double post, I'm trying to simple place an image on the screen, from what I understand, images are drawn to the back buffer then need to be swapped.
I'm calling this function every frame in an attempt to redraw the screen, but I'm getting flickering as if the image is only drawn to the buffer once and is switching between the image and a blank screen each frame.

Code:
void UpdateScreens(){
    
    if(BGLoaded){
        memcpy( tflb, imgbuf, 240*400*3);
    }
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
 
}

Am I going about this the right way?
 
Forgive the double post, I'm trying to simple place an image on the screen, from what I understand, images are drawn to the back buffer then need to be swapped.
I'm calling this function every frame in an attempt to redraw the screen, but I'm getting flickering as if the image is only drawn to the buffer once and is switching between the image and a blank screen each frame.

Code:
void UpdateScreens(){
   
    if(BGLoaded){
        memcpy( tflb, imgbuf, 240*400*3);
    }
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
 
}

Am I going about this the right way?


if tflb is your top screen's framebuffer, and your image is 240x400 and encoded in BGR binary, so yeah, you're doing things well.

The flickering you see is on real hardware or on an emulator?
 
if tflb is your top screen's framebuffer, and your image is 240x400 and encoded in BGR binary, so yeah, you're doing things well.

The flickering you see is on real hardware or on an emulator?


Real hardware, it's as if the image is only written to one buffer(back?/front?) so flipping is switching between the image and a blank screen.
 
1- are you drawing on both top screens or only the left or the right? (you may draw on both OR disable stereoscopy)
2 - isn't your main() fnction already doing the swap job? (gfxFlushBuffers(); gfxSwapBuffers(); gspWaitForVBlank(); ) Because this should be done only once per frame, and if your main() and your updateScreens() both do it, than you're doing once too much.
 
1- are you drawing on both top screens or only the left or the right? (you may draw on both OR disable stereoscopy)
2 - isn't your main() fnction already doing the swap job? (gfxFlushBuffers(); gfxSwapBuffers(); gspWaitForVBlank(); ) Because this should be done only once per frame, and if your main() and your updateScreens() both do it, than you're doing once too much.


I'm drawing on only the left, my main loop is not swapping anything.
Code:
while (1)
{
        hidScanInput();
        keysPressed = hidKeysHeld();
 
        if ((keysPressed & KEY_X) && !(lastKeysPressed & KEY_X)){
            QuitGame = 1;
        }
      
        UpdateScreens();
        
        lastKeysPressed = keysPressed;
        if(QuitGame==1) break;
}
 
Can you try the "normal" way? (use the same functions as ctrulib examples do)

Ctrulib also has a function to detect buttons pressed since last frame, let me give you a complete example that I use everyday, and try to adapt it to your needs

Code:
#include <stdio.h>
#include <string.h>
#include <3ds.h>
 
int main()
{
  // Initializations
  srvInit();        // services
  aptInit();        // applets
  hidInit(NULL);    // input
  gfxInit();        // graphics
  gfxSet3D(false); // stereoscopy (true/false == on/off)
  u32 kDown;        // keys down
  u32 kHeld;          // keys pressed
  u32 kUp;            // keys up
  u8* fbTopLeft;    // top left screen's framebuffer
  u8* fbTopRight;  // top right screen's framebuffer
  u8* fbBottom;    // bottom screen's framebuffer
   
  // Main loop
  while (aptMainLoop())
  {
 
    // Wait for next frame
    gspWaitForVBlank();
 
    // Read which buttons are currently pressed or not
    hidScanInput();
    kDown = hidKeysDown();
    kHeld = hidKeysHeld();
    kUp = hidKeysUp();
 
    // If START button is pressed, break loop and quit
    if (kDown & KEY_START){
      break;
    }
   
    // Reset framebuffers
    fbTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    fbTopRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL);
    fbBottom = gfxGetFramebuffer(GFX_BOTTOM, 0, NULL, NULL);
    memset(fbTopLeft, 0, 240 * 400 * 3);
    memset(fbTopRight, 0, 240 * 400 * 3);
    memset(fbBottom, 0, 240 * 320 * 3);
 
 
    /** Your code goes here **/
 
   
 
    // Flush and swap framebuffers
    gfxFlushBuffers();
    gfxSwapBuffers();
  }
 
  // Exit
  gfxExit();
  hidExit();
  aptExit();
  srvExit();
 
  // Return to hbmenu
  return 0;
}
 
Real hardware, it's as if the image is only written to one buffer(back?/front?) so flipping is switching between the image and a blank screen.

afrer swapping buffers you have to get the new pointer to back buffer, otherwise you always write on the same buffer and the second remain empty (black).

Worst of all, if you go to main menu and then return to the app, the buffers change. You have to always update back buffers pointer at the beginning of the mail loop.
 
afrer swapping buffers you have to get the new pointer to back buffer, otherwise you always write on the same buffer and the second remain empty (black).

Worst of all, if you go to main menu and then return to the app, the buffers change. You have to always update back buffers pointer at the beginning of the mail loop.


Bingo!
 
I'm having problem listing a directory, this is my code:

Code:
static int lua_listdir(lua_State *L){
    int argc = lua_gettop(L);
    if (argc != 1) return luaL_error(L, "wrong number of arguments");
    const char *path = luaL_checkstring(L, 1);
    Handle dirHandle;
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path dirPath=FS_makePath(PATH_CHAR, path);
    FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
    u32 entriesRead;
    lua_newtable(L);
    int i = 1;
    static char name[1024];
    do{
        static FS_dirent entry;
        memset(&entry,0,sizeof(FS_dirent));
        entriesRead=0;
        FSDIR_Read(dirHandle, &entriesRead, 1, &entry);
        if (entriesRead){
            lua_pushnumber(L, i++);
            lua_newtable(L);
            lua_pushstring(L, "name");
            unicodeToChar(&name[0],entry.name);
            DrawScreenText(0,0+(i*15),name,0xFFFFFF,0,0); //Debug Print
            lua_pushstring(L, name);
            lua_settable(L, -3);
            lua_pushstring(L, "size");
            lua_pushnumber(L, entry.fileSize);
            lua_settable(L, -3);
            lua_pushstring(L, "directory");
            lua_pushboolean(L, entry.isDirectory);
            lua_settable(L, -3);
            lua_settable(L, -3);
        }
    }while(entriesRead);
    FSDIR_Close(dirHandle);
    return 1;
}

When i pass through LUA stack the string "/", i got a nil result (and nothing printed by debug print.

Does someone knows why?
 

Site & Scene News

Popular threads in this forum