Ejemplo n.º 1
0
void system_cleanup() {
    mgr_save();
    mgr_exit();

    CSND_shutdown();

    fsExit();
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
}
Ejemplo n.º 2
0
int main() {
    // Initialize services
    srvInit();
    aptInit();
    hidInit(NULL);
    gfxInit();
    CSND_initialize(NULL);
    srand(osGetTime());
    //gfxSet3D(true); // uncomment if using stereoscopic 3D
    
    u8 *audiobuf = linearAlloc(sadloop_bin_size);
    int i;
    for (i=0;i<sadloop_bin_size;i++) {
        memcpy(&audiobuf[i], &sadloop_bin[i], 1);    
    }
    
    bool flip = false;
    u64 nextflip = osGetTime()+500;
    u8 *crow = linearAlloc(crow1_bin_size);
    for (i=0;i<crow1_bin_size;i++) {
        memcpy(&crow[i], &crow1_bin[i], 1);    
    }
    
    CSND_setchannel_playbackstate(0x8, 0);
    CSND_sharedmemtype0_cmdupdatestate(0);
    
    u64 nextsong = osGetTime()+68000;
    CSND_playsound(0x8, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, 22050, (u32*)audiobuf, NULL, sadloop_bin_size, 2, 0);

    char* fact;
    u64 nextfact = osGetTime()+newFact(&fact);
    
    // Main loop
    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();
        u64 now = osGetTime();
        
        
        if (now >= nextsong) {
            nextsong = now+68000;
            
            CSND_playsound(0x8, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, 22050, (u32*)audiobuf, NULL, sadloop_bin_size, 2, 0);
        }
        if (now >= nextflip) {
            nextflip = now+500;
            if (flip) {
                for (i=0;i<crow1_bin_size;i++) {
                    memcpy(&crow[i], &crow1_bin[i], 1);    
                }
                flip = false;
            } else {
                for (i=0;i<crow1_bin_size;i++) {
                    memcpy(&crow[i], &crow2_bin[i], 1);    
                }
                flip = true;
            }
        }
        if (now >= nextfact) {
            nextfact = now+newFact(&fact);
        }
        
        
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START)
            break; // break in order to return to hbmenu
        
        // Please note that the 3DS screens are sideways (thus 240x400 and 240x320)
        u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
        memset(fb, 0, 240*400*3);
        
        tsDrawWord(GFX_TOP, GFX_LEFT, "Fact Crow says:", 30, 180, 255, 255, 255);
        drawFact(fact);
        gfxDrawSprite(GFX_TOP, GFX_LEFT, crow, 37, 37, 138, 30);

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    CSND_shutdown();
    linearFree(audiobuf);
    
    // Exit services
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
    return 0;
}