Homebrew Homebrew Development

NCDyson

Hello Boys...
Member
Joined
Nov 9, 2009
Messages
278
Trophies
1
XP
319
Country
United States
If you're talking about Gateway, no arguments are passed?

I'm not 100% sure, but as I don't see normal 3ds games needing arguments passed to them, I doubt that gateway would pass any.
You can do a quick and dirty test yourself by checking if argc == 0, and if not, print out the arguments to the screen using whatever text display functions you have available.
If you don't have a gateway, I can do that test myself, but I have to fix my build environment first, apparently I destroyed it, again. Seems like if I had a superpower it would be that.
 

Agent Moose

Well-Known Member
Member
Joined
Dec 6, 2014
Messages
407
Trophies
0
Age
33
XP
552
Country
United States
Your OpenWav function has no type for WavFile, you must type it as a char* (or a char array and cast it).

Make your OpenWav returning address for audiobuf and write another function to free buffer.
Does "OpenWav("/canary.wav");" not do the same thing? I have the WavFile variable set at "const char *file_tbo = WavFile;".
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
You have no definition of WavFile in function prototype.
Code:
void OpenWav(WavFile){

You must do something like this:
Code:
u8* OpenWav(const char* WavFile){
    Handle fileHandle;
   
    //Open wav file
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, WavFile);
    Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    u32 magic,samplerate,bytesRead,jump,chunk=0x00000000;
    FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
    if (magic == 0x46464952){
        u64 size;
        u32 pos = 16;
        while (chunk != 0x61746164){
            FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
            pos=pos+jump;
            FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
            pos=pos+4;
        }
        FSFILE_GetSize(fileHandle, &size);
        u8* audiobuf = (u8*)linearAlloc(size-(pos+4));
        FSFILE_Read(fileHandle, &bytesRead, 24, &samplerate, 4);
        FSFILE_Read(fileHandle, &bytesRead, pos+4, audiobuf, size-(pos+4));
    }
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
    CSND_initialize(NULL);
    CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
    return audiobuf;
};

So you can call OpenWav in this way:
Code:
my_file = OpenWav("/file.wav")
and you can free buffer with this:
Code:
linearFree(my_file);
 

Agent Moose

Well-Known Member
Member
Joined
Dec 6, 2014
Messages
407
Trophies
0
Age
33
XP
552
Country
United States
Woah. Quite a bit of errors. Mainly from undeclared variables. I'm sorry for not really knowing what I am doing apparently. >.<
Code:
/Users/AgentMoose/3DS/Text/source/rawr.c:61:9: error: 'Wav' undeclared (first use in this function)
         Wav = OpenWav("/canary.wav");
 
/Users/AgentMoose/3DS/Text/source/rawr.c:61:9: note: each undeclared identifier is reported only once for each function it appears in
/Users/AgentMoose/3DS/Text/source/rawr.c:61:9: warning: implicit declaration of function 'OpenWav' [-Wimplicit-function-declaration]
/Users/AgentMoose/3DS/Text/source/rawr.c: At top level:
/Users/AgentMoose/3DS/Text/source/rawr.c:74:5: error: conflicting types for 'OpenWav'
 u8* OpenWav(const char* WavFile){
 
/Users/AgentMoose/3DS/Text/source/rawr.c:61:15: note: previous implicit declaration of 'OpenWav' was here
         Wav = OpenWav("/canary.wav");

/Users/AgentMoose/3DS/Text/source/rawr.c: In function 'OpenWav':
/Users/AgentMoose/3DS/Text/source/rawr.c:100:84: error: 'audiobuf' undeclared (first use in this function)
     CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);

/Users/AgentMoose/3DS/Text/source/rawr.c:100:100: error: 'size' undeclared (first use in this function)
     CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
\
/Users/AgentMoose/3DS/Text/source/rawr.c:100:106: error: 'pos' undeclared (first use in this function)
     CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
\
/Users/AgentMoose/3DS/Text/source/rawr.c:80:12: warning: unused variable 'ret' [-Wunused-variable]
     Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
            ^
/Users/AgentMoose/3DS/Text/source/rawr.c:102:1: warning: control reaches end of non-void function [-Wreturn-type]
 }

All the undeclared things, I just need to declare at the begining of the function, correct?

But what about "control reaches end of non-void function"?
 

Agent Moose

Well-Known Member
Member
Joined
Dec 6, 2014
Messages
407
Trophies
0
Age
33
XP
552
Country
United States
Code:
#include <stdio.h>
#include <3ds.h>
#include "rawr.h"
#include "draw.h"

u8* screenBottom = 0;
u8* screenTopLeft = 0;
u8* screenTopRight = 0;

void Rawr(){
    TopScreen();
    BottomScreen();
    Render();
}

void TopText(char* Text, int x, int y, char r, char g, char b){
    char a[100];
    sprintf(a, Text);
    drawString(a, x, y, r, g, b, screenTopLeft, GFX_LEFT);
    drawString(a, x, y, r, g, b, screenTopRight, GFX_LEFT);
}

void BottomText(char* Text, int x, int y, char r, char g, char b){
    char a[100];
    sprintf(a, Text);
    drawString(a, x, y, r, g, b, screenBottom, GFX_BOTTOM);
}

void TopScreen(){
    screenTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    screenTopRight = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    clearScreen(screenTopLeft, GFX_LEFT);
    clearScreen(screenTopRight, GFX_LEFT);
    
    drawFillRect(0, 0, 400, 240, 255, 255, 255, screenTopLeft);
    drawFillRect(0, 0, 400, 240, 255, 255, 255, screenTopRight);
    
    TopText("I'm Troy!<3", 10, 180, 0, 0, 0);
    TopText("Meep", 50, 50, 0, 0, 0);
}

void BottomScreen(){
    screenBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
    clearScreen(screenBottom, GFX_BOTTOM);
    
    drawFillRect(0, 0, 30, 240, 255, 255, 255, screenBottom);
    
    BottomText("Love me?  I do.", 120, 100, 0, 0, 255);
    BottomText("Woosh!", 20, 10, 255, 255, 255);
    Notes();
}

void Notes(){
    touchPosition myTouchPosition;
    hidTouchRead(&myTouchPosition);
    u16 posX = myTouchPosition.px;
    u16 posY = myTouchPosition.py;
    if((posX > 0 && posX <= 30) && (posY > 0 && posY <= 240)){
        BottomText("Hehe, that tickles!", 100, 100, 255, 255, 255);
        Wav = OpenWav("/canary.wav");
    }
}

void Render(){
    gfxFlushBuffers();
    gfxSwapBuffers();
    screenBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
    screenTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    screenTopRight = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
};

u8* OpenWav(const char* WavFile){
    Handle fileHandle;
    
    //Open wav file
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, WavFile);
    Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    u32 magic,samplerate,bytesRead,jump,chunk=0x00000000;
    FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
    if (magic == 0x46464952){
        u64 size;
        u32 pos = 16;
        while (chunk != 0x61746164){
            FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
            pos=pos+jump;
            FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
            pos=pos+4;
        }
        FSFILE_GetSize(fileHandle, &size);
        u8* audiobuf = (u8*)linearAlloc(size-(pos+4));
        FSFILE_Read(fileHandle, &bytesRead, 24, &samplerate, 4);
        FSFILE_Read(fileHandle, &bytesRead, pos+4, audiobuf, size-(pos+4));
    }
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
    CSND_initialize(NULL);
    CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
    return audiobuf;
}
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
Code:
u8* OpenWav(const char* WavFile){
    Handle fileHandle;
 
    //Open wav file
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, WavFile);
    FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    u32 magic,samplerate,bytesRead,jump,chunk=0x00000000;
    FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
    u8* audiobuf = NULL;
    if (magic == 0x46464952){
        u64 size;
        u32 pos = 16;
        while (chunk != 0x61746164){
            FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
            pos=pos+jump;
            FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
            pos=pos+4;
        }
        FSFILE_GetSize(fileHandle, &size);
        audiobuf = (u8*)linearAlloc(size-(pos+4));
        FSFILE_Read(fileHandle, &bytesRead, 24, &samplerate, 4);
        FSFILE_Read(fileHandle, &bytesRead, pos+4, audiobuf, size-(pos+4));
        CSND_initialize(NULL);
        CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
    }
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
    return audiobuf;
};

When you call function obviously you have to type variable you use:
Code:
u8* my_file = OpenWav("/file.wav")
 

NCDyson

Hello Boys...
Member
Joined
Nov 9, 2009
Messages
278
Trophies
1
XP
319
Country
United States
Currentyl, my 3DS is on 9.2 firmware so i have to wait GW update to test it. :(

Got my build environment re-set up.

neither .3ds nor .cia appear to have any arguments passed (argc = 0 in both cases). Though it kind of makes sense. There's not really anything that could be passed, .3ds homebrew is run from the gateway microsd card, which as far as I know we don't have filesystem access to, and .cia is stored on the 3ds sdcard, but it would either use a romfs or it's own folders.

Not really sure how to work around it for your case, since you're using the location to find the main script...
 
  • Like
Reactions: Rinnegatamante

Agent Moose

Well-Known Member
Member
Joined
Dec 6, 2014
Messages
407
Trophies
0
Age
33
XP
552
Country
United States
So the code runs, but it freezes though. Not sure when it freezes though. I added the variables to the top so that they all are declared first.

I also added an if elseif statement to the Notes function so that if the certain area is touched it will initialize the filesystem and run the OpenWav, else if it isn't pressed and fsInit is there, it will close the service as well as do the linearFree function.

Code:
#include <stdio.h>
#include <3ds.h>
#include "rawr.h"
#include "draw.h"

u8* screenBottom = 0;
u8* screenTopLeft = 0;
u8* screenTopRight = 0;
u8* Wav;
u64 size;
u32 pos = 16;
u8* audiobuf;
Handle fileHandle;

void Rawr(){
    TopScreen();
    BottomScreen();
    Render();
}

void TopText(char* Text, int x, int y, char r, char g, char b){
    char a[100];
    sprintf(a, Text);
    drawString(a, x, y, r, g, b, screenTopLeft, GFX_LEFT);
    drawString(a, x, y, r, g, b, screenTopRight, GFX_LEFT);
}

void BottomText(char* Text, int x, int y, char r, char g, char b){
    char a[100];
    sprintf(a, Text);
    drawString(a, x, y, r, g, b, screenBottom, GFX_BOTTOM);
}

void TopScreen(){
    screenTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    screenTopRight = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    clearScreen(screenTopLeft, GFX_LEFT);
    clearScreen(screenTopRight, GFX_LEFT);
    
    drawFillRect(0, 0, 400, 240, 255, 255, 255, screenTopLeft);
    drawFillRect(0, 0, 400, 240, 255, 255, 255, screenTopRight);
    
    TopText("I'm Troy!<3", 10, 180, 0, 0, 0);
    TopText("Meep", 50, 50, 0, 0, 0);
}

void BottomScreen(){
    screenBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
    clearScreen(screenBottom, GFX_BOTTOM);
    
    drawFillRect(0, 0, 30, 240, 255, 255, 255, screenBottom);
    
    BottomText("Love me?  I do.", 120, 100, 0, 0, 255);
    BottomText("Woosh!", 20, 10, 255, 255, 255);
    Notes();
}

void Render(){
    gfxFlushBuffers();
    gfxSwapBuffers();
    screenBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
    screenTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
    screenTopRight = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
}

void Notes(){
    touchPosition myTouchPosition;
    hidTouchRead(&myTouchPosition);
    u16 posX = myTouchPosition.px;
    u16 posY = myTouchPosition.py;
    if((posX > 0 && posX <= 30) && (posY > 0 && posY <= 240)){
        BottomText("Hehe, that tickles!", 100, 100, 255, 255, 255);
        fsInit();
        u8* Wav = OpenWav("/canary.wav");
    }else if(fsInit()){
        linearFree(Wav);
        svcCloseHandle(fileHandle);
        fsExit();
    }
}

u8* OpenWav(const char* WavFile){
    //Open wav file
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, WavFile);
    Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    u32 magic,samplerate,bytesRead,jump,chunk=0x00000000;
    FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
    if (magic == 0x46464952){
        while (chunk != 0x61746164){
            FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
            pos=pos+jump;
            FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
            pos=pos+4;
        }
        FSFILE_GetSize(fileHandle, &size);
        u8* audiobuf = (u8*)linearAlloc(size-(pos+4));
        FSFILE_Read(fileHandle, &bytesRead, 24, &samplerate, 4);
        FSFILE_Read(fileHandle, &bytesRead, pos+4, audiobuf, size-(pos+4));
    }
    FSFILE_Close(fileHandle);
    svcCloseHandle(fileHandle);
    CSND_initialize(NULL);
    CSND_playsound(0x08, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
    return audiobuf;
}
 

ChrisRX

Well-Known Member
Member
Joined
Nov 8, 2006
Messages
490
Trophies
0
Website
Visit site
XP
420
Country
Guys, I'm having a very dumb problem. I'm trying to write a drawPixel function that accepts a framebuffer, x, y coordinates, and r, g, b values.

EDIT: I tried this in my main loop, without using a function, and it fails too (it draws 3 coloured pixels but not at the right place):

Code:
u16 pos = 3*(100+100*240);
fb[pos] = 0xFF;
fb[pos+1] = 0xFF;
fb[pos+2] = 0xFF;

Damn, what am I doing wrong?


The maximum value of a u16 is 65535. 3*(100+100*240) = 72300 so the value will wrap around to 0 and be set to (72300 - 65535).

Just change that u16 to a u32 and you're good to go.
 
  • Like
Reactions: xem

jonthedit

Well-Known Member
Member
Joined
May 30, 2011
Messages
1,682
Trophies
0
XP
1,010
Country
Bangladesh
How do I setup to build my on my Windows OS with Netbeans?
I've installed DevkitARM (and downloaded the latest ctrulib for the examples)
The latest Python3
and Netbeans C/C++ IDE.

All the "guides" I have found seem to skip the setting up process.
The Environment Variables are updated automatically right? I've found Python listed and DevKitPro, but I do not know if it is correct.

Any help is appreciated, willing to Teamview too
 

Agent Moose

Well-Known Member
Member
Joined
Dec 6, 2014
Messages
407
Trophies
0
Age
33
XP
552
Country
United States
So this is what I decided to try. I went down to the bare bones of what I believe I need for the sound. It's just the filesystem read and the CSND functions to play the file. It still freezes, but I only get one error in the terminal, and that's the fact that "ret" is an unused variable.

Code:
#include <string.h>

#include <3ds.h>

u8* audiobuf;

int main()
{
    // Initialize services
    srvInit();
    aptInit();
    hidInit(NULL);
    gfxInit();
    fsInit();
    //gfxSet3D(true); // uncomment if using stereoscopic 3D
    
    
    u64 size;
    u32 magic, samplerate = 44100, bytesRead, jump, chunk=0x00000000;
    u32 pos = 16;
    const char *file_tbo = "/canary.wav";
    Handle fileHandle;
    
    //Open wav file
    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);
    FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
    if (magic == 0x46464952){
        while (chunk != 0x61746164){
            FSFILE_Read(fileHandle, &bytesRead, pos, &jump, 4);
            pos=pos+jump;
            FSFILE_Read(fileHandle, &bytesRead, pos, &chunk, 4);
            pos=pos+4;
        }
        FSFILE_GetSize(fileHandle, &size);
        u8* audiobuf = (u8*)linearAlloc(size-(pos+4));
        FSFILE_Read(fileHandle, &bytesRead, 24, &samplerate, 4);
        FSFILE_Read(fileHandle, &bytesRead, pos+4, audiobuf, size-(pos+4));
    }
    FSFILE_Close(fileHandle);

    // Main loop
    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();

        // Your code goes here

        u32 kDown = hidKeysDown();
        if (kDown & KEY_START)
            break; // break in order to return to hbmenu

        //Start wav file
        CSND_initialize(NULL);
        CSND_playsound(0x8, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, samplerate, (u32*)audiobuf, NULL, size-(pos+4), 2, 0);
        
        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }
    linearFree(audiobuf);
    CSND_shutdown();
    svcCloseHandle(fileHandle);
    // Exit services
    fsExit();
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
    return 0;
}
 

Cyan

GBATemp's lurking knight
Former Staff
Joined
Oct 27, 2002
Messages
23,749
Trophies
4
Age
46
Location
Engine room, learning
XP
15,662
Country
France
if you install devkitpro using the automated installer, it will set up everything correctly.
Don't install devkitARM alone, in devkitPro select to install DevkitARM and libctru, and you will be fine. nothing else is required.
 

jonthedit

Well-Known Member
Member
Joined
May 30, 2011
Messages
1,682
Trophies
0
XP
1,010
Country
Bangladesh
if you install devkitpro using the automated installer, it will set up everything correctly.
Don't install devkitARM alone, in devkitPro select to install DevkitARM and libctru, and you will be fine. nothing else is required.

._.
Yes... I got that much.
The various tutorials that mention Netbeans specifically just assume you are on Linux or already have it configured.
What I don't understand is how to configure the Netbeans IDE (I am used to eclipse) to see DevkitARM and Python 3.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    D @ diamondsofmayhem: The only link I've been able to find for my version is here...