Homebrew Homebrew Development

  • Thread starter Thread starter aliak11
  • Start date Start date
  • Views Views 1,493,287
  • Replies Replies 6,048
  • Likes Likes 54
:yay:
But I'm pretty sure that someone, sooner or later, will use your little piece of code and will end up hating homebrew programming. :nayps3:

:rofl:

They don't need to be coding anyways if they're just going to copy/paste code without trying to understand how it works.
 
They don't need to be coding anyways if they're just going to copy/paste code without trying to understand how it works.

I don't agree, I'm using pieces of code from smealum and other (including CTULib) understanding only a little part of their work, but it helps me to learn new things.
 
Does exist a better way than simple math.random to get a random value? I need to mix an array in order to get a most random-ordered array as i can for a card game.

I actually use a LUA function like this:
Code:
function mix_table(tbl)
  for i in ipairs(tbl) do
      r = math.random(1, #tbl)
      temp = tbl[i]
      temp2 = imgcards[i]
      imgcards[i] = imgcards[r]
      imgcards[r] = temp2
      tbl[i] = tbl[r]
      tbl[r] = temp
  end
 
  return tbl
end
 
Only do exist pseudo random numbers in programming. If you randomize with the clock value ad seed, should never have two identical sequence
 
I have not been solved my problem with mic. Does someone knows if exists an homebrew which uses microphone?
According to mic.h:
Code:
Result MIC_Initialize(u32 *sharedmem, u32 sharedmem_size, u8 control, u8 recording, u8 unk0, u8 unk1, u8 unk2);//sharedmem_size = audiodata size + 4, aligned to 0x1000-bytes. The sharedmem ptr must be 0x1000-bytes aligned. The offical 3ds-sound app uses the following values for unk0-unk2: 3, 1, and 1.

I initialized MIC with sharedmem_size = audiobuf_size + 4 but in mic sample, it seems to be initialized in a different way and i'm getting my 3DS freezing (like while cycle never ends).

This is my code:
Code:
u32 mem_size = 1024*1024;
u8* audiobuf = (u8*)linearAlloc(mem_size);
    u32 audiobuf_pos = 0;
    u32* sharedmem = (u32*)memalign(0x1000, mem_size + 4);
    MIC_Initialize(sharedmem, mem_size + 4, 0x40, 0, 3, 1, 1);
    MIC_SetRecording(1);
    while (audiobuf_pos < mem_size){
    audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], mem_size-audiobuf_pos, 1);
    }
    MIC_SetRecording(0);
    MIC_Shutdown();
    free(sharedmem);
    wav* wav_file = (wav*)malloc(sizeof(wav));
    wav_file->audiobuf = audiobuf;
    wav_file->size = mem_size;
    wav_file->samplerate = 16000;
    wav_file->isPlaying = false;
    wav_file->bytepersample = 2;
 
Quick question, does the 3DS use timers? I've run into this code -
Code:
void StartTimers(void) 
{ 
   TIMER0_DATA=0; 
   TIMER1_DATA=0; 
   TIMER0_CR=TIMER_DIV_1024|TIMER_ENABLE; 
   TIMER1_CR=TIMER_CASCADE|TIMER_ENABLE;
}

in a DS project and I find myself wondering how to go about converting it to 3DS. Any ideas?
 
Are you using python 3?


Hi, i fixed the .vsh because the Aemstro change the format of opcodes, like end now is nop, and tried build the 3dscraft and gpu example, i can show the background color but 3d model not show, i don't have much ideias now, i think or is the vsh wrong or is the aemstro.
 
Guys i updated LIBCTRU 10 minutes ago. While i was trying to build 3DS Paint, console said me this things:

Code:
draw.c
arm-none-eabi-gcc -MMD -MP -MF /c/devkitPro/Projects/3DS/3DS_Paint/build/draw.d
-g -Wall -O2 -mword-relocations -fomit-frame-pointer -ffast-math -march=armv6k -
mtune=mpcore -mfloat-abi=softfp -I/c/devkitPro/Projects/3DS/3DS_Paint/include -I
/c/devkitPro/libctru/include -I/c/devkitPro/Projects/3DS/3DS_Paint/build -DARM11
-D_3DS -c /c/devkitPro/Projects/3DS/3DS_Paint/source/draw.c -o draw.o
c:/devkitPro/Projects/3DS/3DS_Paint/source/draw.c: In function 'drawString':
c:/devkitPro/Projects/3DS/3DS_Paint/source/draw.c:75:2: warning: implicit declar
ation of function 'strlen' [-Wimplicit-function-declaration]
  for (i = 0; i <strlen(word); i++){
  ^
c:/devkitPro/Projects/3DS/3DS_Paint/source/draw.c:75:17: warning: incompatible i
mplicit declaration of built-in function 'strlen'
  for (i = 0; i <strlen(word); i++){
                ^

Has printing code changed? How can i fix this?
 
Unnecessary includes for standard library header files were removed from ctrulib. Just include string.h in draw.c and the warning will go away.

...it is causing me physical pain to see strlen in the condition of the for loop. I feel a little better now. Thanks.
 
Hi, i fixed the .vsh because the Aemstro change the format of opcodes, like end now is nop, and tried build the 3dscraft and gpu example, i can show the background color but 3d model not show, i don't have much ideias now, i think or is the vsh wrong or is the aemstro.
I was not able to get the gpu example to work with the new ctrulib even with the old aemstro.
 
Guys i need your help. This is my main.c:
Code:
#include <3ds.h>
#include "app.h"
#include "input.h"
 
int main()
{
    // Initialize services
    srvInit();
    aptInit();
    hidInit(NULL);
    gfxInit();
 
 
    // Main loop
    while (aptMainLoop())
    {
        //Gets input (keys and touch)
        getInput();
 
        //Prints the GUI
        renderGUI();
 
        //Do stuff
        app();
 
        //Jumps to the required mode (menu or paint) or exit
        if (input & KEY_START || mode==5)
            break;
 
        //Wait for VBlank
        gspWaitForVBlank();
 
        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }
 
    // Exit services
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
    return 0;
}

And i want to print something using my renderGUI() function, which is:
Code:
void renderGUI()
{
    //render the GUI
    printGUI();
    screenRender();
    printGUI();
    screenRender();
}

It prints printGUI twice as it should be (3ds paint works in this way).

screenRender is:
Code:
void screenRender()
{
    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);
}

and printGUI is:
Code:
void printGUI()
{
            char buffer[100];
            drawFillRect(79, 163, 264, 239, 0, 0, 0, screenTopLeft);
            drawFillRect(79, 163, 264, 239, 0, 0, 0, screenTopRight);
 
            sprintf(buffer, "mode= %d      state= %d", mode, state);
            drawString(buffer, 85, 171, 255, 255, 255, screenTopLeft, GFX_LEFT);
            drawString(buffer, 85, 171, 255, 255, 255, screenTopRight, GFX_LEFT);
 
            sprintf(buffer, "color= %d    debug= %d", color, debug);
            drawString(buffer, 85, 181, 255, 255, 255, screenTopLeft, GFX_LEFT);
            drawString(buffer, 85, 181, 255, 255, 255, screenTopRight, GFX_LEFT);
 
            sprintf(buffer, "rendered= %d  warn= %d", rendered, warn);
            drawString(buffer, 85, 191, 255, 255, 255, screenTopLeft, GFX_LEFT);
            drawString(buffer, 85, 191, 255, 255, 255, screenTopRight, GFX_LEFT);
 
            sprintf(buffer, "Touch posX= %d", debugX);
            drawString(buffer, 85, 211, 255, 255, 255, screenTopLeft, GFX_LEFT);
            drawString(buffer, 85, 211, 255, 255, 255, screenTopRight, GFX_LEFT);
 
            sprintf(buffer, "Touch posY= %d", debugY);
            drawString(buffer, 85, 221, 255, 255, 255, screenTopLeft, GFX_LEFT);
            drawString(buffer, 85, 221, 255, 255, 255, screenTopRight, GFX_LEFT);
}

And it crashes. Can you help me? If i remove renderGUI from main.c, it doesn't crash anymore.

P.S. It crashes also if i print GUI one time only (by removing rendergui and using printgui in main.c)

P.S.2. 3Dmoo crashes with this log:
mem_Write8: trying to write8 unmapped addr fffffffe, w=dd
arm11_Dump: Reg dump:
arm11_Dump: r00: 00000000 r01: 00000000 r02: 00000190 r03: 000000f0
arm11_Dump: r04: 000000a6 r05: 000000dd r06: 000000ee r07: 00000000
arm11_Dump: r08: fffffd2d r09: 000000a6 r10: 00000000 r11: 0011aa30
arm11_Dump: r12: fffffd30 r13: 0fffff30 r14: fffffd2d r15: 00103a7c
arm11_Dump: current pc
arm11_Dump: current lr
arm11_Dump: 0FFFFF30 00165dec
arm11_Dump: 0FFFFF34 0011aa08
arm11_Dump: 0FFFFF38 00000000
arm11_Dump: 0FFFFF3C 000000dd
arm11_Dump: 0FFFFF40 000000ee
arm11_Dump: 0FFFFF44 001001f4
arm11_Dump: 0FFFFF48 000000a6
arm11_Dump: 0FFFFF4C 000000dd
arm11_Dump: 0FFFFF50 000000ee
arm11_Dump: 0FFFFF54 00000000
arm11_Dump: 0FFFFF58 00000000
arm11_Dump: 0FFFFF5C 00000000
arm11_Dump: 0FFFFF60 00000000
arm11_Dump: 0FFFFF64 00109168
arm11_Dump: 0FFFFF68 00000000
arm11_Dump: 0FFFFF6C 00000000
arm11_Dump:
 
Your code should crashes because the first time you call drawstring your framebuffer variables are not initialized, and you are trying to write to mem 0 (or to some random addresses).

Put screenRender before RenderGUI, or beter merge the two funcs putting the gfxGetFramebuffer calls before the drawString ones

There are also some other things to be fixed to make your code looking better:
- you don't need at all calling printGUI() and screenRender() twice.
- Delete gfxFlushBuffers() and gfxSwapBuffers() inside the rendering funcs, and leave them at the end of main cicle. This way your main loop is much faster. Put screenrender before RenderGUI, or beter merge the two funcs putting the gfxGetFramebuffer calls before the drawString ones

I can see other things that are not bugs yet, but may cause you troubles as your app grows if you don't figure out very well how they works; but I leave to you to find and fix them :P

Alberto, it's so weird spending ten minutes to write this in English, when we're both italians and I could have write it in half a minute in our language :lol: . I hope my bad english is clear anough!
 

Site & Scene News

Popular threads in this forum