void DSGM_LoadSpriteFull(u8 screen, DSGM_Sprite *sprite) { int i; switch(screen) { case DSGM_TOP: //sprite->topTiles = DSGM_TrackedAlloc((void **)&sprite->topTiles, sizeof(u16 *) * sprite->frames); sprite->topTiles = malloc(sizeof(u16 *) * sprite->frames); for(i = 0; i < sprite->frames; i++) { sprite->topTiles[i] = oamAllocateGfx(&oamMain, sprite->size, SpriteColorFormat_256Color); if(DSGM_SpriteIsNitro(sprite)) { DSGM_ReadFileManual(sprite->topTiles[i], i * (DSGM_GetSpriteWidth(sprite) * DSGM_GetSpriteHeight(sprite)), DSGM_GetSpriteWidth(sprite) * DSGM_GetSpriteHeight(sprite)/*32 * 32*//*DSGM_AUTO_LENGTH*/, sprite->nitroFilename); } else { dmaCopy(sprite->tiles + (i * DSGM_GetSpriteWidth(sprite) * DSGM_GetSpriteHeight(sprite)), sprite->topTiles[i], *sprite->tilesLength); } } break; case DSGM_BOTTOM: //sprite->bottomTiles = DSGM_TrackedAlloc((void **)&sprite->bottomTiles, sizeof(u16 *) * sprite->frames); sprite->bottomTiles = malloc(sizeof(u16 *) * sprite->frames); for(i = 0; i < sprite->frames; i++) { sprite->bottomTiles[i] = oamAllocateGfx(&oamSub, sprite->size, SpriteColorFormat_256Color); if(DSGM_SpriteIsNitro(sprite)) { DSGM_ReadFileManual(sprite->bottomTiles[i], i * (DSGM_GetSpriteWidth(sprite) * DSGM_GetSpriteHeight(sprite)), DSGM_GetSpriteWidth(sprite) * DSGM_GetSpriteHeight(sprite)/*DSGM_AUTO_LENGTH*/, sprite->nitroFilename); } else { dmaCopy(sprite->tiles + (i * DSGM_GetSpriteWidth(sprite) * DSGM_GetSpriteHeight(sprite)), sprite->bottomTiles[i], *sprite->tilesLength); } } break; } }
void TextButton::init_vram( const void* source, u16*& vram_dest ) { vram_dest = oamAllocateGfx( this->get_oam(), this->sprite_size, SpriteColorFormat_Bmp ); DC_FlushRange( source, SPRITE_SIZE_PIXELS(this->sprite_size)*2 ); dmaCopy( source, vram_dest, SPRITE_SIZE_PIXELS(this->sprite_size)*2 ); set_16bpp_sprite_opague( vram_dest, SPRITE_SIZE_PIXELS(this->sprite_size)*2 ); }
// returns the offset for the gfxAsset in video memory. DMA copies if needed uint16 *assets::getGfx(gfxAsset *gfx) { // Don't do anything if passed a NULL pointer if (!gfx) return 0; // If it's already loaded, just return its offset if (gfx->vmLoaded) return gfx->offset; // If the gfx isn't in main memory (which it should be), run loadGfx() if (!gfx->mmLoaded) loadGfx(gfx); // It would appear that the gfx is in main memory, but video memory. // So load it up! // Allocate video memory for the gfx uint16 *mem = oamAllocateGfx(oam, gfx->size, SpriteColorFormat_16Color); gfx->offset = mem; gfx->vmLoaded = true; // Start copying asynchronously uint16 length = gfx->length; DC_FlushRange(gfx->data, length); dmaCopyHalfWordsAsynch(3, gfx->data, mem, length); //iprintf("gfx vmLoaded -> %x\n", (unsigned int) gfx->offset); return mem; }
SpriteScraperRect *HwSpriteScraper::allocRect(OamState *oam) { /* * Look for a free sprite rect */ for (int i=0; i < NUM_SPRITES; i++) { SpriteScraperRect *rect = &rects[i]; if (rect->buffer == NULL) { rect->oam = oam; rect->buffer = oamAllocateGfx(oam, SpriteSize_64x64, SpriteColorFormat_16Color); /* * Do one full clear/render cycle before showing a frame. * Until that cycle is finished, we'll show a blank sprite. */ rect->live = true; rect->livePrev = false; dmaFillHalfWords(0, rect->buffer, rect->width * rect->height / 2); return rect; } } sassert(false, "Out of SpriteScraperRects"); return NULL; }
// Loading a sprite Sprite::Sprite(u8 screen, const unsigned int* tiles, u8 palette, SpriteSize spriteSize, u8 frames){ u16 memorySize = 0; switch(spriteSize){ case SpriteSize_8x8 : memorySize = 64; break; case SpriteSize_8x16 : case SpriteSize_16x8 : memorySize = 128; break; case SpriteSize_32x8 : case SpriteSize_8x32 : case SpriteSize_16x16: memorySize = 256; break; case SpriteSize_32x16: case SpriteSize_16x32: memorySize = 512; break; case SpriteSize_32x32: memorySize = 1024; break; case SpriteSize_64x32: case SpriteSize_32x64: memorySize = 2048; break; case SpriteSize_64x64: memorySize = 4096; break; } oam = (screen == 1 ? &oamMain : &oamSub); palNumber = palette; this->frames = frames; gfxMem = new u16*[frames]; this->spriteSize = spriteSize; for (u8 i = 0; i < frames; ++i){ gfxMem[i] = oamAllocateGfx(oam, spriteSize, SpriteColorFormat_256Color); dmaCopy((u8*)tiles + (i * memorySize), gfxMem[i], memorySize); } }
Sprite::Sprite(int i, SpriteSize size, SpriteColorFormat format, s16 x, s16 y, OamState* oam) { s_oam = oam; s_size = size; s_format = format; s_x = x; s_y = y; s_gfx = oamAllocateGfx(s_oam, s_size, s_format); // Allocate memory space for sprite gfx s_i = i; }
void iconTitleInit (void) { // initialize video mode videoSetMode(MODE_4_2D); // initialize VRAM banks vramSetPrimaryBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_LCD, VRAM_D_LCD); // initialize bg2 as a rotation background and bg3 as a bmp background // http://mtheall.com/vram.html#T2=3&RNT2=96&MB2=3&TB2=0&S2=2&T3=6&MB3=1&S3=1 bg2 = bgInit(2, BgType_Rotation, BgSize_R_512x512, 3, 0); bg3 = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 1, 0); // initialize rotate, scale, and scroll bgSetRotateScale(bg3, 0, 1<<8, 1<<8); bgSetScroll(bg3, 0, 0); bgSetRotateScale(bg2, 0, 8*(1<<8)/6, 1<<8); bgSetScroll(bg2, -TITLE_POS_X, -TITLE_POS_Y); // clear bg2's map: 512x512 pixels is 64x64 tiles is 4KB dmaFillHalfWords(0, bgGetMapPtr(bg2), 4096); // load compressed font into bg2's tile data decompress(font6x8Tiles, bgGetGfxPtr(bg2), LZ77Vram); // load compressed bitmap into bg3 decompress(hbmenu_bannerBitmap, bgGetGfxPtr(bg3), LZ77Vram); // load font palette dmaCopy(font6x8Pal, BG_PALETTE, font6x8PalLen); // apply the bg changes bgUpdate(); // initialize OAM oamInit(&oamMain, SpriteMapping_1D_128, false); sprite = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_16Color); dmaFillHalfWords(0, sprite, sizeof(banner.icon)); oamSet(&oamMain, 0, ICON_POS_X, ICON_POS_Y, 0, 0, SpriteSize_32x32, SpriteColorFormat_16Color, sprite, -1, 0, 0, 0, 0, 0); // oam can only be updated during vblank swiWaitForVBlank(); oamUpdate(&oamMain); // everything's ready :) writeRow (0,"...initializing..."); writeRow (1,"===>>> HBMenu+ <<<==="); writeRow (2,"(this text should disappear..."); writeRow (3,"...otherwise, trouble!)"); }
void blu_impl::GFX_LDSprite(bluSprite* bsp){ if(bsp->init == 0){ u16* gfx; oamInit(&oamMain, bsp->sm, false); gfx = oamAllocateGfx(&oamMain, bsp->sz, bsp->sfmt); bsp->gfx = gfx; bsp->init = 1; } dmaCopy(bsp->tiles, bsp->gfx, bsp->tlen); dmaCopy(bsp->pal, SPRITE_PALETTE, bsp->plen); }
void Sprite2D::Assign(sImage* img) { size = GetSpriteSize(img->width, img->height); gfx = oamAllocateGfx(&oamSub, size, SpriteColorFormat_256Color); format = SpriteColorFormat_256Color; // Sprite initialisation /*for(int i = 0; i < 256; i++) SPRITE_PALETTE_SUB[i] = img->palette[i];*/ for(int i = 0; i < (img->width*img->height)>>1; i++) gfx[i] = img->image.data16[i]; //dmaCopy(img->image.data16, gfx, 32*16); //swiCopy(img->image.data16, gfx, ((sz & 0xFFF) << 4) | COPY_MODE_FILL); }
void bomb::setSprite() { spriteSize = SpriteSize_8x8; // oamAllocateGfx allocates memory for the object-sprite gfx = oamAllocateGfx(&oamMain, spriteSize, SpriteColorFormat_256Color); // This copies the sprite into the object memcpy(this->gfx, sprite, sizeof(sprite)); center.x = BOMB_CENTER_X; center.y = BOMB_CENTER_Y; height = BOMB_HEIGHT; width = BOMB_WIDTH; radius.x = BOMB_RADIUS_X; radius.y = BOMB_RADIUS_Y; //XXX places the bomb on the screen setXY(20 * (id + 1), 15); }
//Initializes a button and its related VRAM space. void initbutton(BUTTON *butt, u8 *gfx, const char *name, const unsigned int x, const unsigned int y, const unsigned int w, const unsigned int h, void (*callback)(void), const unsigned short int initstate) { strncpy(butt->name, name, sizeof(butt->name)); butt->x = x; butt->y = y; butt->w = w; butt->h = h; butt->state = initstate; butt->callback = callback; butt->sprite_gfx_mem = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color); butt->frame_gfx = gfx; }
void TextButton::init_text_layer( FreetypeRenderer& freetype_renderer ) { if( this->text.length() && this->owns_text_vram ) { // allocate VRAM for 8bpp text layer this->text_vram = oamAllocateGfx( this->get_oam(), this->text_sprite_size, SpriteColorFormat_256Color ); RenderScreenBuffer button_text( this->text_width, this->text_height ); RenderStyle render_style; render_style.center_x = true; freetype_renderer.render( button_text, this->text, this->face, this->font_size, 0, 1, &render_style ); // convert 8bpp sprite data for use in 16bpp mode // FIXME: currently needs ram buffering, as vram supports 16bit operations only u8 conversion_buffer[ SPRITE_SIZE_PIXELS(this->text_sprite_size) ]; tile_8bpp_sprite( (u8*)(button_text.base_address), conversion_buffer, this->text_width, this->text_height ); //DC_FlushRange( conversion_buffer, SPRITE_SIZE_PIXELS(this->sprite_size)*1 ); //dmaCopy( conversion_buffer, this->text_vram, SPRITE_SIZE_PIXELS(this->sprite_size)*1 ); memcpy( this->text_vram, conversion_buffer, SPRITE_SIZE_PIXELS(this->text_sprite_size)*1 ); } }
//a sprite constructor void createSprite(mySprite* s, int x, int y, int z, SpriteSize size, SpriteColorFormat format, int dx, int dy) { s->alive = true; s->x = x; s->y = y; s->z = z; s->dx = dx; s->dy = dy; s->size = size; s->format = format; //api: allocate a chunk of sprite graphics memory s->gfx = oamAllocateGfx(oam, size, format); allocationCount++; if(s->gfx) { spriteMemoryUsage += (size & 0xFFF) << 5; oom = false; } else { oom = true; //only a failure of the allocator if there was enough room if(spriteMemoryUsage + ((size & 0xFFF) << 5) < spriteMemSize) oomCount++; } }
int main(int argc, char** argv) { //three sprites of differing color format MySprite sprites[] = { {0, SpriteSize_32x32, SpriteColorFormat_Bmp, 0, 15, 20, 15}, {0, SpriteSize_32x32, SpriteColorFormat_256Color, -1, 0, 20, 80}, {0, SpriteSize_32x32, SpriteColorFormat_16Color, -1, 1, 20, 136} }; videoSetModeSub(MODE_0_2D); consoleDemoInit(); //initialize the sub sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false); vramSetBankD(VRAM_D_SUB_SPRITE); //allocate some space for the sprite graphics for(int i = 0; i < 3; i++) sprites[i].gfx = oamAllocateGfx(&oamSub, sprites[i].size, sprites[i].format); //ugly positional printf iprintf("\x1b[1;1HDirect Bitmap:"); iprintf("\x1b[9;1H256 color:"); iprintf("\x1b[16;1H16 color:"); //fill bmp sprite with the color red dmaFillHalfWords(ARGB16(1,31,0,0), sprites[0].gfx, 32*32*2); //fill the 256 color sprite with index 1 (2 pixels at a time) dmaFillHalfWords((1<<8)|1, sprites[1].gfx, 32*32); //fill the 16 color sprite with index 1 (4 pixels at a time) dmaFillHalfWords((1<<12)|(1<<8)|(1<<4)|1, sprites[2].gfx, 32*32 / 2); //set index 1 to blue...this will be the 256 color sprite SPRITE_PALETTE_SUB[1] = RGB15(0,31,0); //set index 17 to green...this will be the 16 color sprite SPRITE_PALETTE_SUB[16 + 1] = RGB15(0,0,31); int angle = 0; while(1) { for(int i = 0; i < 3; i++) { oamSet( &oamSub, //sub display i, //oam entry to set sprites[i].x, sprites[i].y, //position 0, //priority sprites[i].paletteAlpha, //palette for 16 color sprite or alpha for bmp sprite sprites[i].size, sprites[i].format, sprites[i].gfx, sprites[i].rotationIndex, true, //double the size of rotated sprites false, //don't hide the sprite false, false, //vflip, hflip false //apply mosaic ); } oamRotateScale(&oamSub, 0, angle, (1 << 8), (1<<8)); angle += 64; swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamSub); } return 0; }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- int i = 0; int angle = 0; videoSetMode(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_SPRITE); oamInit(&oamMain, SpriteMapping_1D_32, false); u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color); /* This is where we load the image. * In this case we're doing a really simple striped pattern, * but we could also load a bitmap. */ for(i = 0; i < 32 * 32 / 2; i++) { //gfx[i] = 1 | (1 << 8); gfx[i] = 0x201; // alternating red and yellow } SPRITE_PALETTE[1] = RGB15(31,0,0); // full red SPRITE_PALETTE[2] = RGB15(28,28,0); // bright yellow while(1) { scanKeys(); /* Slow down the rotate if the left trigger is pressed * I'd like to do a fixed-point here, but I don't know how */ float inc = (keysHeld() & KEY_L)? 0.05 : 0.3; if(keysHeld() & KEY_LEFT) angle += degreesToAngle(inc); if(keysHeld() & KEY_RIGHT) angle -= degreesToAngle(inc); //------------------------------------------------------------------------- // Set the first rotation/scale matrix // // There are 32 rotation/scale matricies that can store sprite rotations // Any number of sprites can share a sprite rotation matrix or each sprite // (up to 32) can utilize a seperate rotation. Because this sprite is doubled // in size we have to adjust its position by subtracting half of its height and // width (20 - 16, 20 - 16, ) //------------------------------------------------------------------------- oamRotateScale(&oamMain, 0, angle, intToFixed(1, 8), intToFixed(1, 8)); oamSet(&oamMain, //main graphics engine context 0, //oam index (0 to 127) 20 - 16, 20 - 16, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index true, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); //------------------------------------------------------------------------- // Because the sprite below has size double set to false it can never be larger than // 32x32 causing it to clip as it rotates. //------------------------------------------------------------------------- oamSet(&oamMain, //main graphics engine context 1, //oam index (0 to 127) 204, 20, //x and y pixle location of the sprite 0, //priority, lower renders last (on top) 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite SpriteSize_32x32, SpriteColorFormat_256Color, gfx, //pointer to the loaded graphics 0, //sprite rotation/scale matrix index false, //double the size when rotating? false, //hide the sprite? false, false, //vflip, hflip false //apply mosaic ); swiWaitForVBlank(); oamUpdate(&oamMain); } return 0; }
void memoriaErreserbatu() { gfx_beltza= oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_256Color); }
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++; }
//--------------------------------------------------------------------- // Initializing hero requires little work, allocate room for one frame // and set the frame gfx pointer //--------------------------------------------------------------------- void zombieType::init() { sprite_gfx_mem = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color); frame_gfx = (u8*)zombieTiles-32*32; //needs to shift left one frame...dunno why }
// 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; }