Debian Codegraph @

tools/ds_tests/spriteblend/source/template.c

raw
1 #include <nds.h>
2 #include <nds/registers_alt.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6
7 #include "drunkenlogo.h"
8 #include "plain.h"
9
10 int main(void)
11 {
12 //---------------------------------------------------------------------------------
13 int i = 0;
14 touchPosition touch;
15
16 videoSetMode(MODE_5_2D);
17 videoSetModeSub(MODE_0_2D);
18
19 vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
20 vramSetBankB(VRAM_B_MAIN_SPRITE);
21
22 oamInit(&oamMain, SpriteMapping_1D_32, false);
23 /*oamInit(&oamSub, SpriteMapping_1D_32, false);*/
24 consoleDemoInit();
25 int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);
26 int bg2 = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 4,0);
27
28 //display bg3 above bg2. when the window effect excludes bg3, will bg2 be displayed?
29 bgSetPriority(bg3,0);
30 bgSetPriority(bg2,1);
31
32
33 dmaCopy(drunkenlogoBitmap, bgGetGfxPtr(bg3), drunkenlogoBitmapLen);
34 dmaCopy(drunkenlogoPal, BG_PALETTE, 256*2);
35 dmaCopy(plainBitmap, bgGetGfxPtr(bg2), plainBitmapLen);
36
37 u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_16x16, SpriteColorFormat_16Color);
38 /*u16* gfxSub = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_256Color);*/
39 REG_BLDCNT = (1<<11) | (1<<6);
40
41 REG_WININ = 0x3F; //display everything, including color special effects, in window 0
42 REG_WINOUT = 0x17; //display everything, excluding color special effects and BG3 outside window 0
43 REG_WIN0H = (0<<8) | 128; //window is x (0..128)
44 REG_WIN0V = (0<<8) | 128; //window is y (0..128)
45 REG_DISPCNT |= (1<<13); //enable use of window 0
46
47 for(i = 0; i < 16 * 16 / 2; i+=1)
48 {
49 gfx[i] = 0x1111;
50 }
51
52
53 SPRITE_PALETTE[1] = RGB15(31,31,31);
54
55 u8 eva = 0xf, evb = 0xf;
56
57 while(1)
58 {
59
60 scanKeys();
61 u32 keys = keysDown();
62
63 if(keysHeld() & KEY_TOUCH)
64 touchRead(&touch);
65 if(keys & KEY_LEFT && evb > 0)
66 evb--;
67 if(keys & KEY_RIGHT && evb < 0xf)
68 evb++;
69 if(keys & KEY_UP && eva > 0)
70 eva--;
71 if(keys & KEY_DOWN && eva < 0xf)
72 eva++;
73
74 consoleClear();
75 printf("eva %x evb %x\n", eva, evb);
76
77 oamSet(&oamMain, //main graphics engine context
78 0, //oam index (0 to 127)
79 touch.px, touch.py, //x and y pixle location of the sprite
80 0, //priority, lower renders last (on top)
81 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
82 SpriteSize_16x16,
83 SpriteColorFormat_16Color,
84 gfx, //pointer to the loaded graphics
85 -1, //sprite rotation data
86 false, //double the size when rotating?
87 false, //hide the sprite?
88 false, false, //vflip, hflip
89 false //apply mosaic
90 );
91
92
93 /*REG_BLDCNT = 0;*/
94 REG_BLDALPHA = evb<<8|eva;
95
96 oamMain.oamMemory[0].blendMode = OBJMODE_BLENDED;
97
98 swiWaitForVBlank();
99
100 bgUpdate();
101 oamUpdate(&oamMain);
102 }
103
104 return 0;
105 }