/* Avance à la part suivante ************************************************** * ------------------------- ******************************************************************************/ void DemoAdvancePart(void) { if(CurrentPart < NbParts) { if(CurrentPart >= 0) { /* Deinit la part courante */ if(DemoParts[CurrentPart].deinit != NULL) { DemoParts[CurrentPart].deinit(); } /* Unregister le handler de synchro */ mmSetEventHandler(NULL); } CurrentPart++; // Avance if(CurrentPart < NbParts) { /* Init la prochaine part */ if(DemoParts[CurrentPart].init != NULL) { DemoParts[CurrentPart].init(); } if(DemoParts[CurrentPart].sync != NULL) { /* Register le nouveau handler de synchro */ mmSetEventHandler(DemoParts[CurrentPart].sync); } /* Initialise le temps de début de la part */ DemoParts[CurrentPart].start_time = TimerMillis; } } }
/* Exécute la demo ************************************************************ * --------------- ******************************************************************************/ void DemoPlay(void) { mmStart(0, MM_PLAY_LOOP); //CurrentPart = -1; //DemoAdvancePart(); CurrentPart = 0; DemoParts[0].init(); mmSetEventHandler(DemoParts[CurrentPart].sync); DemoParts[0].start_time = TimerMillis; while(1) { if(CurrentPart < NbParts) { DemoParts[CurrentPart].exec(TimerMillis - DemoParts[CurrentPart].start_time); if(DemoParts[CurrentPart].duration != 0) { if((TimerMillis - DemoParts[CurrentPart].start_time) >= DemoParts[CurrentPart].duration) { //DemoAdvancePart(); DemoParts[CurrentPart].deinit(); mmSetEventHandler(NULL); CurrentPart++; if(CurrentPart == NbParts) { ledBlink(PM_LED_BLINK); return; } DemoParts[CurrentPart].init(); mmSetEventHandler(DemoParts[CurrentPart].sync); DemoParts[CurrentPart].start_time = TimerMillis; } } } else { ledBlink(PM_LED_BLINK); return; } } }
// Program entrypoint int main() { if (!mmIsARM7Loaded()) { printf("Couldn't load Maxmod!\n"); return 1; } // Init Maxmod with default settings (loading from FAR) mmInitDefaultFAR(hFar, "/soundbank.bin"); FeOS_DirectMode(); videoSetMode(MODE_0_2D); videoSetModeSub(0); vramSetBankA(VRAM_A_MAIN_SPRITE); // Initialize the sprite engine with 1D mapping 128 byte boundary // aand no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); int i; for (i = 0; i < 5; i ++) { // Allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); // Fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords(((i+1) << 8) | (i+1), sprites[i].gfx, 32*32); } // Set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); mmSetEventHandler(myEventHandler); mmLoad(MOD_EXAMPLE2); mmStart(MOD_EXAMPLE2, MM_PLAY_LOOP); for(;;) { swiWaitForVBlank(); if (keysDown() & KEY_START) break; for (i = 0; i < 5; i ++) { // Constantly increase the sprite's y velocity sprites[i].dy += 1; // Update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // Clamp the sprite's y position if (sprites[i].y<72) sprites[i].y = 72; if (sprites[i].y>96) sprites[i].y = 96; oamSet(&oamMain, // Main graphics engine context i, // OAM index (0 to 127) sprites[i].x, // X and Y pixel location of the sprite sprites[i].y, 0, // Priority, lower renders last (on top) sprites[i].paletteAlpha, // Palette index sprites[i].size, sprites[i].format, sprites[i].gfx, // Pointer to the loaded graphics sprites[i].rotationIndex, // Sprite rotation data false, // Double the size when rotating? false, // Hide the sprite? false, false, // VFlip, HFlip false); // Apply mosaic } } mmStop(); mmUnload(MOD_EXAMPLE2); mmUnloadSoundbank(); FeOS_ConsoleMode(); return 0; }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; videoSetMode(MODE_0_2D); videoSetModeSub(0); // not using subscreen lcdMainOnBottom(); //initialize the sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamMain, SpriteMapping_1D_32, false); vramSetBankA(VRAM_A_MAIN_SPRITE); for (i = 0; i < 5; i++) { //allocate some space for the sprite graphics sprites[i].gfx = oamAllocateGfx(&oamMain, sprites[i].size, sprites[i].format); //fill each sprite with a different index (2 pixels at a time) dmaFillHalfWords( ((i+1)<<8)|(i+1), sprites[i].gfx, 32*32); } //set indexes to different colours SPRITE_PALETTE[1] = RGB15(31,0,0); SPRITE_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3] = RGB15(0,0,31); SPRITE_PALETTE[4] = RGB15(31,0,31); SPRITE_PALETTE[5] = RGB15(0,31,31); // initialise maxmod using default settings, and enable interface for soundbank that is loaded into memory mmInitDefaultMem( (mm_addr)mmsolution_bin ); // setup maxmod to use the song event handler mmSetEventHandler( myEventHandler ); // load song // values for this function are in the solution header mmLoad( MOD_EXAMPLE2 ); // start song playing mmStart( MOD_EXAMPLE2, MM_PLAY_LOOP ); while(1) { for (i=0; i < 5; i++) { // constantly increase the sprite's y velocity sprites[i].dy += 1; // update the sprite's y position with its y velocity sprites[i].y += sprites[i].dy; // clamp the sprite's y position if ( sprites[i].y<72 ) sprites[i].y = 72; if ( sprites[i].y>96 ) sprites[i].y = 96; oamSet( &oamMain, //main graphics engine context i, //oam index (0 to 127) sprites[i].x, //x and y pixel location of the sprite sprites[i].y, 0, //priority, lower renders last (on top) sprites[i].paletteAlpha, //palette index sprites[i].size, sprites[i].format, sprites[i].gfx, //pointer to the loaded graphics sprites[i].rotationIndex, //sprite rotation data false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); } swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamMain); } return 0; }