[Q] Does an APT app jump exit the app that it's called from?

Discussion in '3DS - Homebrew Development and Emulators' started by LeifEricson, Nov 2, 2015.

  1. LeifEricson
    OP

    LeifEricson Coming Soon™

    Member
    214
    166
    Jun 22, 2012
    United States
    New York, USA
    I'm trying to make an application that will run and be able to perform functions while the game in the gamecard slot is running. I've stumbled upon APT_DoAppJump as well as as the NS service's app launch (whose call I don't remember.)

    Do either of these allow the original homebrew to continue running while the game is running after the function calls, or does it exit the original app? If not, would I have to do something like multi-threading to get that to work?
     
  2. BurningDesire

    BurningDesire GBAtemp Psycho!

    Member
    4,964
    5,825
    Jan 27, 2015
    United States
    Behind a screen reading news
    I wish i could give you the correct response. I am where wondering what you doing now... :P From the sounds of it you'd have to do ns services then doappjump after that. However don't quote be on that. Its just my common sense!
     
  3. LeifEricson
    OP

    LeifEricson Coming Soon™

    Member
    214
    166
    Jun 22, 2012
    United States
    New York, USA
    I'm trying to make a screen recorder by taking screenshots every frame (inefficient, slow, I know. I've considered all of the limitations).

    Could you perhaps help me out and tell me what my code should look like?
     
  4. cpasjuste

    cpasjuste GBAtemp Fan

    Member
    441
    643
    Aug 27, 2015
    France
    Hi,

    I wanted to do something like this (for debugging purpose), I didn't investigate a lot but I think there's no know (public) way of doing that. I think for now your best option would be to write an ntr plugin (which isn't as easy as I think it need arm9 code).
     
    Last edited by cpasjuste, Nov 2, 2015
  5. Rinnegatamante

    Rinnegatamante GBAtemp Psycho!

    Member
    3,127
    3,271
    Nov 24, 2014
    Italy
    Bologna
    When i was working on the launchGamecard for lpp-3ds, i noticed that the app jump takes at least some time when you can execute code after its execution. To "fix" it i added an infinite loop after the app jump call ( https://github.com/Rinnegatamante/lpp-3ds/blob/master/source/luaSystem.cpp#L1238 ).
    Don't know if it's only a delay from APP service or if the program still runs in background but maybe it could help you understand how it works.
     
  6. LeifEricson
    OP

    LeifEricson Coming Soon™

    Member
    214
    166
    Jun 22, 2012
    United States
    New York, USA
    Hey thanks, you're just the person I was hoping would see this. So, if I put an infinite loop after the app jump call, I can continue running code, or the loop prevents it? I want to be able to trigger the recording when wanted, because if it started running from launch it would lag unbearably.

    Also, my app jump code is just causing a black screen anyways. Is there something I'm forgetting to do before/after the app jump call that I'm missing?

    Code:
    // Rinnegatamante's de-luafied launch card function
    void startcard() {
        amInit();
        char product_id[16];
        AM_GetTitleProductCode(mediatype_GAMECARD, 0, product_id);
        amExit();
        if (product_id[0] == 'C' and product_id[1] == 'T' and product_id[2] == 'R'){
            u8 buf0[0x300];
            u8 buf1[0x20];
            memset(buf0, 0, 0x300);
            memset(buf1, 0, 0x20);
            aptOpenSession();
            APT_PrepareToDoAppJump(NULL, 0, 0, mediatype_GAMECARD);
            APT_DoAppJump(NULL, 0x300, 0x20, buf0, buf1);
            aptCloseSession();
        }else{
            nsInit();
            NS_RebootToTitle(mediatype_GAMECARD,0);
            nsExit();
        }
        for (;;){} // Does this loop *prevent* further code execution, or allow it?
    }
    
    int main() {
        srand(time(NULL));
        fsInit();
        gfxInitDefault();
        startcard(); //...Or does this need to be moved?
    
        while (aptMainLoop()) {
            gspWaitForVBlank();
            hidScanInput();
            keys_down = hidKeysDown();
            keys_up = hidKeysUp();
    
            if (keys_down & KEY_A & KEY_B & KEY_START) break;
    
            framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
            framebuf_bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
    
            if (keys_down & KEY_UP & KEY_X & KEY_Y) {
                if (!recording) recording = true;
                else recording = false;
            }
    
            if (recording) {
                screenshot(frambuf_top, 0, 400, 240, frame);
                screenshot(framebuf_bot, 1, 320, 240, frame);
                ++frame;
            }
    
            startcard(); // I've also tried it here (but not both calls at the same time)
    
            gfxFlushBuffers();
            gfxSwapBuffers();
            ++sysframe;
        }
        gfxExit();
        fsExit();
        return 0;
    }
     
    Last edited by LeifEricson, Nov 2, 2015
  7. filfat

    filfat Musician, Developer & Entrepreneur

    Member
    1,231
    858
    Nov 24, 2012
    ^ startcode(void) will never return since you for(;;) executes forever.
    Maybe try and see if multithreading work, prehaps thread 2 won't get killed (don't know since I haven't test myself).

    I'll see if I can get an example (if needed) , I don't prommise anything though :P
     
  8. cpasjuste

    cpasjuste GBAtemp Fan

    Member
    441
    643
    Aug 27, 2015
    France
    I tried that some time ago and all threads were killed too. But maybe i didn't did it right.
     
  9. filfat

    filfat Musician, Developer & Entrepreneur

    Member
    1,231
    858
    Nov 24, 2012
    As I excpected then :/ You'll need to work a bit with the arm9 cpu which I have no experience with.
     
  10. naivegirl2411

    naivegirl2411 GBAtemp Regular

    Member
    225
    42
    Oct 29, 2015
  11. norips

    norips Member

    Newcomer
    32
    38
    Aug 13, 2012
    France
    Capture video from camera yes. But not from the screen itself