Exemple #1
0
Sound::Sound()
{
  mmInitDefaultMem((mm_addr)soundbank_bin);
  mmLoad(MOD_CASTLE_MUSIC);
  mmStart(MOD_CASTLE_MUSIC, MM_PLAY_LOOP);

  initEffects();
}
Exemple #2
0
/* Initialisation ************************************************************* 
 * --------------
 * Paramètres :
 * - parts : les parts qui devront être jouées
 * - nb_parts : le nombre de parts
 ******************************************************************************/
void DemoInit(T_Part* parts, int nb_parts)
{
	TimerMillis = 0;

	DemoParts = parts;
	NbParts = nb_parts;
	CurrentPart = 0;

	mmInitDefaultMem( (mm_addr)soundbank_bin );
	mmSelectMode(MM_MODE_C);
	mmLoad(0);

	// Initialisation du timer
	// Millisecond Timer refresh IRQ
    TIMER1_CR = 0;
    TIMER1_DATA = TIMER_FREQ(0x409);
    TIMER1_CR = TIMER_ENABLE | TIMER_DIV_1 | TIMER_IRQ_REQ;

	irqEnable(IRQ_TIMER1);
    irqSet(IRQ_TIMER1, _TimerMillisInterrupt);
    
    glInit();
}
Exemple #3
0
int main(void) 
{
	mmInitDefaultMem((mm_addr)soundbank_bin);

	//set video mode and map vram to the background
	videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE | 
                 DISPLAY_SPR_1D_LAYOUT | 
                 DISPLAY_SPR_ACTIVE);
    
	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    vramSetBankB(VRAM_B_MAIN_SPRITE);

	//set video mode and map vram to the background
	videoSetModeSub(MODE_1_2D | DISPLAY_BG1_ACTIVE | 
                 DISPLAY_SPR_1D_LAYOUT | 
                 DISPLAY_SPR_ACTIVE);

	vramSetBankD(VRAM_D_MAIN_BG_0x06000000);
    vramSetBankE(VRAM_E_MAIN_SPRITE);

    lcdMainOnBottom();

#ifdef BBDEBUG
    consoleDemoInit();
#endif

    sound s;
    s.load_bank(0);

    sprites spr;
	machine m(&s);
    machine_view mv(&spr);
#ifndef BBDEBUG
    thread_view tv;
#endif
    cursor c(&m,&spr);
    pointer p(&spr);
    iprintf("%d\n",list::unit_test());

    int frame=0;
    int x=0;
    int y=0;
    int tx=0;
    int ty=0;
    int dx=0;
    int dy=0;
    int touchedlast=0;

    int tempo=2;
    int bank=0;
    u8 flip=0;
    u8 flip_count=1;
	irqEnable( IRQ_VCOUNT );

	while(1)
	{
		// wait until line 0
		swiIntrWait( 0, IRQ_VCOUNT);

        u32 t=tempo;
        //t=t/(flip+1);
        //iprintf("%d\n",t);
        
        if (tempo==0 || frame%t==0) 
        {
            m.run();
            /*    flip_count--;
            if (flip_count==0)
            {
                flip_count=4;
                if (flip) flip=0;
                else flip=1;
                }*/
        }
		scanKeys();
        frame++;
        touchPosition touch;
        touchRead(&touch);

        if (keysDown() & KEY_UP) m.slow_down_closest(c.get_cursor_addr());
        if (keysDown() & KEY_DOWN) m.speed_up_closest(c.get_cursor_addr());
        if (tempo<0) tempo=0;

        if (keysDown() & KEY_L) sound_check(m);

        if (keysDown() & KEY_LEFT) { bank--; s.load_bank(bank); }
        if (keysDown() & KEY_RIGHT) { bank++; s.load_bank(bank); }
 
        if(keysDown() & KEY_TOUCH)
        {
            tx=touch.px;
            ty=touch.py;
            if (!c.touch(tx,ty,&p))
            {
                touchedlast=1;
            }
        }
        else if(keysHeld() & KEY_TOUCH)
		{				
            if (!c.menu_shown() &&
                !c.drag(touch.px+x,touch.py+y,(touch.px+x)/16,(touch.py+y)/16))
            {
                if (touchedlast>0) touchedlast++;
                x+=tx-touch.px;
                y+=ty-touch.py;
                tx=touch.px;
                ty=touch.py;
            }
        }

        if (keysUp() & KEY_TOUCH)
        {
            if (touchedlast>0 && touchedlast<5)
            {
                int lx=(tx+x)/16;
                int ly=(ty+y)/16;
                c.set_pos(lx,ly,lx*16,ly*16);
            }
            touchedlast=0;
        }       

        if (keysUp() & KEY_A)
        {
            for (u32 i=0; i<HEAP_SIZE; i++)
            {
                m.poke(i,rand());
            }
        }
        
        c.update(x,y);
        if (c.menu_shown()) 
        {
            dx=c.get_x()-128;
            dy=c.get_y()-82;
            if (dx!=x) x+=(dx-x)*0.1;
            if (dy!=y) y+=(dy-y)*0.1; 
        }

        p.update(x,y,&m);
        REG_BG0HOFS = x;
        REG_BG0VOFS = y;
        spr.update();
        mv.update(x,y,&m);
        s.update();
#ifndef BBDEBUG
        tv.update(&m);
#endif
        BG_PALETTE_SUB[0]=13<<10;
		swiWaitForVBlank();
        BG_PALETTE_SUB[0]=31;

	}
		
	return 0;
}
Exemple #4
0
void initSprites(mySprite * sprites) {
	int defaultX = (SCREEN_WIDTH/2) - 32;
	int defaultY = (SCREEN_HEIGHT/2) - 32;
	mmInitDefaultMem((mm_addr)soundbank_bin);
	
	oamInit(&oamMain, SpriteMapping_1D_64, false);
	mySprite leftButtonOff = {0, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 0, 0, defaultY};
	mySprite leftButtonOn = {1, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 1, 0, defaultY};
	mySprite rightButtonOff = {2, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 0, (256-64), defaultY};
	mySprite rightButtonOn = {3, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 1, (256-64), defaultY};
	leftButtonOff.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	leftButtonOn.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	rightButtonOff.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	rightButtonOn.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(leftButtonOffPal, &SPRITE_PALETTE[leftButtonOff.id * 16], leftButtonOffPalLen);
	dmaCopy(leftButtonOnPal, &SPRITE_PALETTE[leftButtonOn.id * 16], leftButtonOnPalLen);
	dmaCopy((u8*)leftButtonOffTiles, leftButtonOff.gfx, 2048);
	dmaCopy((u8*)leftButtonOnTiles, leftButtonOn.gfx, 2048);
	dmaCopy((u8*)rightButtonOffTiles, rightButtonOff.gfx, 2048);
	dmaCopy((u8*)rightButtonOnTiles, rightButtonOn.gfx, 2048);
	sprites[leftButtonOff.id] = leftButtonOff;
	sprites[leftButtonOn.id] = leftButtonOn;
	sprites[rightButtonOff.id] = rightButtonOff;
	sprites[rightButtonOn.id] = rightButtonOn;
	SPRITECOUNT += 4;
	
	// mySprite {id, gfxPtr, SpriteSize, SpriteColorFormat, rotationIndex, paletteAlpha, x, y}
	//
	// gong
	mmLoadEffect(SFX_GONG);
	mm_sound_effect gongSFX = { {SFX_GONG}, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char gongDesc[] = "An ancient gong from the hills of China.";
	mySprite gong = {4, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 4, defaultX, defaultY, gongSFX, gongDesc};
	gong.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(gongPal, &SPRITE_PALETTE[gong.id * 16], gongPalLen);
	dmaCopy((u8*)gongTiles, gong.gfx, 2048);
	sprites[gong.id] = gong;
	SPRITECOUNT++;
	
	// duck
	mmLoadEffect(SFX_DUCK);
	mm_sound_effect duckSFX = { { SFX_DUCK }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char duckDesc[] = "A mild-mannered duck.";
	mySprite duck = {5, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 5, defaultX, defaultY, duckSFX, duckDesc};
	duck.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color); 
	dmaCopy(duckPal, &SPRITE_PALETTE[duck.id * 16], buttheadPalLen);
	dmaCopy((u8*)duckTiles, duck.gfx, 2048);
	sprites[duck.id] = duck;
	SPRITECOUNT++;	// should be 6 now
	
	// butthead
	mmLoadEffect(SFX_BUTTHEAD);
	mm_sound_effect buttheadSFX = { { SFX_BUTTHEAD }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char buttheadDesc[] = "Butt-head.";
	mySprite butthead = {6, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 6, defaultX, defaultY, buttheadSFX, buttheadDesc};
	butthead.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color); 
	dmaCopy(buttheadPal, &SPRITE_PALETTE[butthead.id * 16], buttheadPalLen);
	dmaCopy((u8*)buttheadTiles, butthead.gfx, 2048);
	sprites[butthead.id] = butthead;
	SPRITECOUNT++;
	
	//bluesbrothers
	mmLoadEffect(SFX_BLUESBROTHERS);
	mm_sound_effect bluesbrothersSFX = { { SFX_BLUESBROTHERS }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char bluesbrothersDesc[] = "Jake and Elwood.";
	mySprite bluesbrothers = {7, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 7, defaultX, defaultY, bluesbrothersSFX, bluesbrothersDesc};
	bluesbrothers.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(bluesbrothersPal, &SPRITE_PALETTE[bluesbrothers.id * 16], bluesbrothersPalLen);
	dmaCopy((u8*)bluesbrothersTiles, bluesbrothers.gfx, 2048);
	sprites[bluesbrothers.id] = bluesbrothers;
	SPRITECOUNT++;

	//bttf
	mmLoadEffect(SFX_BTTF);
	mm_sound_effect bttfSFX = { { SFX_BTTF }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char bttfDesc[] = "88 mph.";
	mySprite bttf = {8, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 8, defaultX, defaultY, bttfSFX, bttfDesc};
	bttf.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(bttfPal, &SPRITE_PALETTE[bttf.id * 16], bttfPalLen);
	dmaCopy((u8*)bttfTiles, bttf.gfx, 2048);
	sprites[bttf.id] = bttf;
	SPRITECOUNT++;

	//chewbacca
	mmLoadEffect(SFX_CHEWBACCA);
	mm_sound_effect chewbaccaSFX = { { SFX_CHEWBACCA }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char chewbaccaDesc[] = "Chewie.";
	mySprite chewbacca = {9, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 9, defaultX, defaultY, chewbaccaSFX, chewbaccaDesc};
	chewbacca.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(chewbaccaPal, &SPRITE_PALETTE[chewbacca.id * 16], chewbaccaPalLen);
	dmaCopy((u8*)chewbaccaTiles, chewbacca.gfx, 2048);
	sprites[chewbacca.id] = chewbacca;
	SPRITECOUNT++;

	//dsotm
	mmLoadEffect(SFX_DSOTM);
	mm_sound_effect dsotmSFX = { { SFX_DSOTM }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char dsotmDesc[] = "1973.";
	mySprite dsotm = {10, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 10, defaultX, defaultY, dsotmSFX, dsotmDesc};
	dsotm.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(dsotmPal, &SPRITE_PALETTE[dsotm.id * 16], dsotmPalLen);
	dmaCopy((u8*)dsotmTiles, dsotm.gfx, 2048);
	sprites[dsotm.id] = dsotm;
	SPRITECOUNT++;

	//eastwood
	mmLoadEffect(SFX_EASTWOOD);
	mm_sound_effect eastwoodSFX = { { SFX_EASTWOOD }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char eastwoodDesc[] = "-_-";
	mySprite eastwood = {11, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 11, defaultX, defaultY, eastwoodSFX, eastwoodDesc};
	eastwood.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(eastwoodPal, &SPRITE_PALETTE[eastwood.id * 16], eastwoodPalLen);
	dmaCopy((u8*)eastwoodTiles, eastwood.gfx, 2048);
	sprites[eastwood.id] = eastwood;
	SPRITECOUNT++;

	//mario
	mmLoadEffect(SFX_MARIO);
	mm_sound_effect marioSFX = { { SFX_MARIO }, (int)(1.0f * (1<<10)), 0, 255, 128, };
	char marioDesc[] = "An Italian Plumber.";
	mySprite mario = {12, 0, SpriteSize_64x64, SpriteColorFormat_16Color, 0, 12, defaultX, defaultY, marioSFX, marioDesc};
	mario.gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_16Color);
	dmaCopy(marioPal, &SPRITE_PALETTE[mario.id * 16], marioPalLen);
	dmaCopy((u8*)marioTiles, mario.gfx, 2048);
	sprites[mario.id] = mario;
	SPRITECOUNT++;
}
//---------------------------------------------------------------------------------
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;
}
Exemple #6
0
int main() {
    /* Turn on the 2D graphics core. */
    powerOn(POWER_ALL_2D);

    /*
     *  Configure the VRAM and background control registers.
     *
     *  Place the main screen on the bottom physical screen. Then arrange the
     *  VRAM banks. Next, confiure the background control registers.
     */
    lcdMainOnBottom();
    initVideo();
    initBackgrounds();

    /* Initialize maxmod using the memory based soundbank set up. */
    mmInitDefaultMem((mm_addr)soundbank_bin);

    /* Set up a few sprites. */
    SpriteInfo spriteInfo[SPRITE_COUNT];
    OAMTable *oam = new OAMTable();
    initOAM(oam);
    initSprites(oam, spriteInfo);

    /* Display the backgrounds. */
    displayStarField();
    displayPlanet();
    displaySplash();

    /*************************************************************************/

    /* Keep track of the touch screen coordinates. */
    touchPosition touch;

    /* Make the ship object. */
    static const int SHUTTLE_OAM_ID = 0;
    SpriteEntry * shipEntry = &oam->oamBuffer[SHUTTLE_OAM_ID];
    SpriteRotation * shipRotation = &oam->matrixBuffer[SHUTTLE_OAM_ID];
    Ship * ship = new Ship(&spriteInfo[SHUTTLE_OAM_ID]);

    /* Make the moon. */
    static const int MOON_OAM_ID = 1;
    SpriteEntry * moonEntry = &oam->oamBuffer[MOON_OAM_ID];
    SpriteInfo * moonInfo = &spriteInfo[MOON_OAM_ID];
    MathVector2D<int> * moonPos = new MathVector2D<int>();
    moonPos->x = moonEntry->x;
    moonPos->y = moonEntry->y;

    /* Set up sound data. */
    mmLoadEffect(SFX_THRUST);

    for (;;) {
        /* Update the game state. */
        updateInput(&touch);
        handleInput(ship, moonPos, moonInfo, &touch);
        ship->moveShip();

        /* Update ship sprite attributes. */
        MathVector2D<float> position = ship->getPosition();
        shipEntry->x = (int)position.x;
        shipEntry->y = (int)position.y;
        rotateSprite(shipRotation, -ship->getAngleDeg());
        /* Update moon sprite attributes. */
        moonEntry->x = (int)moonPos->x;
        moonEntry->y = (int)moonPos->y;

        /*
         *  Update the OAM.
         *
         *  We have to copy our copy of OAM data into the actual OAM during
         *  VBlank (writes to it are locked during other times).
         */
        swiWaitForVBlank();
        updateOAM(oam);
    }

    return 0;
}