Tutorial.14 特殊効果 モザイク †今回はGBAで利用できる特殊効果のうち、モザイク機能を使います。 効果は、使用することを選択したBGやスプライト1個づつに対して、 400004Ch - MOSAIC - Mosaic Size (W) The Mosaic function can be separately enabled/disabled for BG0-BG3 by BG0CNT-BG3CNT Registers, as well as for each OBJ0-127 by OBJ attributes in OAM memory. Also, setting all of the bits below to zero effectively disables the mosaic function. Bit Expl. 0-3 BG Mosaic H-Size (minus 1) 4-7 BG Mosaic V-Size (minus 1) 8-11 OBJ Mosaic H-Size (minus 1) 12-15 OBJ Mosaic V-Size (minus 1) 16-31 Not used Example: When setting H-Size to 5, then pixels 0-5 of each display row are colorized as pixel 0, pixels 6-11 as pixel 6, pixels 12-17 as pixel 12, and so on. #define REG_MOSAIC *(volatile u32*)0x400004C #define MOSAIC_BG_H(x) ((x)<<0) #define MOSAIC_BG_V(x) ((x)<<4) #define MOSAIC_OBJ_H(x) ((x)<<8) #define MOSAIC_OBJ_V(x) ((x)<<12) I/OレジスタはREG_MOSAICで、そのほかのマクロは横と縦のサイズを指定します。 設定する値はそれぞれ0-15の範囲で、(数値+1)の範囲をモザイクの最小単位とします。 モザイク機能を使用するには モザイクの表示例 †#include "lib/gba.h" #include "res.h" //--------------------------------------------------------------------------- void WaitForVsync(void) { while(*(vu16*)0x4000006 >= 160) {}; while(*(vu16*)0x4000006 < 160) {}; } //--------------------------------------------------------------------------- void Mode3DrawImage(u16* img) { u16* ScreenBuffer = (u16*)0x6000000; u32 x, y; for(y=0; y<160; y++) { for(x=0; x<240; x++) { ScreenBuffer[y*240+x] = img[y*240+x]; } } } //--------------------------------------------------------------------------- int main(void) { SetMode(MODE_3 | BG2_ENABLE); REG_DMA3SAD = (u32)&imageBitmap; REG_DMA3DAD = (u32)VRAM; REG_DMA3CNT = (u32)(240*160) | (DMA_SRC_INC | DMA_DST_INC | DMA16 | DMA_ENABLE); // BG2でモザイクを使用可能にします REG_BG2CNT = BG_MOSAIC; // モザイクのパラメータ設定 u16 cx = 5; u16 cy = 5; REG_MOSAIC = MOSAIC_BG_H(cx) | MOSAIC_BG_V(cy); for(;;) { WaitForVsync(); } } 動作画面 †![]() 履歴 †
|