Mercurial > sdl-ios-xcode
comparison src/video/nds/SDL_ndsvideo.c @ 2688:71c56e900f8b gsoc2008_nds
Cleaning up the renderer code to hopefully squish any problems. Starting to incorporate sprites, as well
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Fri, 15 Aug 2008 10:17:07 +0000 |
parents | f7594fc66bda |
children | ca01c20274c0 |
comparison
equal
deleted
inserted
replaced
2687:5166b19b6808 | 2688:71c56e900f8b |
---|---|
29 */ | 29 */ |
30 | 30 |
31 #include <stdio.h> | 31 #include <stdio.h> |
32 #include <stdlib.h> | 32 #include <stdlib.h> |
33 #include <nds.h> | 33 #include <nds.h> |
34 #include <nds/arm9/sprite.h> | |
35 #include <nds/arm9/trig_lut.h> | |
36 #include <nds/arm9/video.h> | 34 #include <nds/arm9/video.h> |
37 | 35 |
38 #include "SDL_video.h" | 36 #include "SDL_video.h" |
39 #include "SDL_mouse.h" | 37 #include "SDL_mouse.h" |
40 #include "../SDL_sysvideo.h" | 38 #include "../SDL_sysvideo.h" |
49 | 47 |
50 /* Initialization/Query functions */ | 48 /* Initialization/Query functions */ |
51 static int NDS_VideoInit(_THIS); | 49 static int NDS_VideoInit(_THIS); |
52 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); | 50 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); |
53 static void NDS_VideoQuit(_THIS); | 51 static void NDS_VideoQuit(_THIS); |
54 | |
55 /* NDS sprite-related functions */ | |
56 | |
57 #define SPRITE_DMA_CHANNEL 3 | |
58 #define SPRITE_ANGLE_MASK 0x01FF | |
59 | |
60 void | |
61 NDS_OAM_Update(tOAM *oam) | |
62 { | |
63 DC_FlushAll(); | |
64 dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer, OAM, | |
65 SPRITE_COUNT * sizeof(SpriteEntry)); | |
66 } | |
67 | |
68 void | |
69 NDS_OAM_RotateSprite(SpriteRotation *spriteRotation, u16 angle) | |
70 { | |
71 s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4; | |
72 s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4; | |
73 | |
74 spriteRotation->hdx = c; | |
75 spriteRotation->hdy = s; | |
76 spriteRotation->vdx = -s; | |
77 spriteRotation->vdy = c; | |
78 } | |
79 | |
80 void | |
81 NDS_OAM_Init(tOAM *oam) | |
82 { | |
83 int i; | |
84 for(i = 0; i < SPRITE_COUNT; i++) { | |
85 oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED; | |
86 oam->spriteBuffer[i].attribute[1] = 0; | |
87 oam->spriteBuffer[i].attribute[2] = 0; | |
88 } | |
89 for(i = 0; i < MATRIX_COUNT; i++) { | |
90 NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0); | |
91 } | |
92 swiWaitForVBlank(); | |
93 NDS_OAM_Update(oam); | |
94 } | |
95 | |
96 void | |
97 NDS_OAM_HideSprite(SpriteEntry *spriteEntry) | |
98 { | |
99 spriteEntry->isRotoscale = 0; | |
100 spriteEntry->isHidden = 1; | |
101 } | |
102 | |
103 void | |
104 NDS_OAM_ShowSprite(SpriteEntry *spriteEntry, int affine, int double_bound) | |
105 { | |
106 if (affine) { | |
107 spriteEntry->isRotoscale = 1; | |
108 spriteEntry->rsDouble = double_bound; | |
109 } else { | |
110 spriteEntry->isHidden = 0; | |
111 } | |
112 } | |
113 | 52 |
114 | 53 |
115 /* SDL NDS driver bootstrap functions */ | 54 /* SDL NDS driver bootstrap functions */ |
116 static int | 55 static int |
117 NDS_Available(void) | 56 NDS_Available(void) |
167 NDS_VideoInit(_THIS) | 106 NDS_VideoInit(_THIS) |
168 { | 107 { |
169 SDL_DisplayMode mode; | 108 SDL_DisplayMode mode; |
170 int i; | 109 int i; |
171 | 110 |
172 printf("+NDS_VideoInit\n"); | 111 printf("+NDS_VideoInit\n"); |
173 /* simple 256x192x16x60 for now */ | 112 /* simple 256x192x16x60 for now */ |
174 mode.w = 256; | 113 mode.w = 256; |
175 mode.h = 192; | 114 mode.h = 192; |
176 mode.format = SDL_PIXELFORMAT_ABGR1555; | 115 mode.format = SDL_PIXELFORMAT_ABGR1555; |
177 mode.refresh_rate = 60; | 116 mode.refresh_rate = 60; |
188 /* hackish stuff to get things up and running for now, and for a console */ | 127 /* hackish stuff to get things up and running for now, and for a console */ |
189 powerON(POWER_ALL_2D); | 128 powerON(POWER_ALL_2D); |
190 irqInit(); | 129 irqInit(); |
191 irqEnable(IRQ_VBLANK); | 130 irqEnable(IRQ_VBLANK); |
192 NDS_SetDisplayMode(_this, &mode); | 131 NDS_SetDisplayMode(_this, &mode); |
193 printf("-NDS_VideoInit\n"); | 132 printf("-NDS_VideoInit\n"); |
194 return 0; | 133 return 0; |
195 } | 134 } |
196 | 135 |
197 static int | 136 static int |
198 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) | 137 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) |
199 { | 138 { |
200 printf("+NDS_SetDisplayMode\n"); | 139 printf("+NDS_SetDisplayMode\n"); |
201 /* right now this function is just hard-coded for 256x192 ABGR1555 */ | 140 /* right now this function is just hard-coded for 256x192 ABGR1555 */ |
202 videoSetMode(MODE_5_2D | | 141 videoSetMode(MODE_5_2D | |
203 DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | | 142 DISPLAY_BG2_ACTIVE | |
204 DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE); /* display on main core */ | 143 DISPLAY_BG3_ACTIVE | |
205 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */ | 144 DISPLAY_BG_EXT_PALETTE | |
206 vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, | 145 DISPLAY_SPR_1D_LAYOUT | |
207 VRAM_C_SUB_BG_0x06200000, VRAM_D_MAIN_BG_0x06040000); | 146 DISPLAY_SPR_ACTIVE | |
147 DISPLAY_SPR_EXT_PALETTE); /* display on main core | |
148 with lots of flags set for | |
149 flexibility/capacity to render */ | |
150 | |
151 /* hopefully these cover all the various things we might need to do */ | |
152 vramSetBankA(VRAM_A_MAIN_BG_0x06000000); | |
153 vramSetBankB(VRAM_B_MAIN_BG_0x06020000); | |
154 vramSetBankC(VRAM_C_SUB_BG_0x06200000); | |
155 vramSetBankD(VRAM_D_MAIN_BG_0x06040000); /* not a typo. vram d can't sub */ | |
208 vramSetBankE(VRAM_E_MAIN_SPRITE); | 156 vramSetBankE(VRAM_E_MAIN_SPRITE); |
209 /* set up console for debug text 'n stuff */ | 157 vramSetBankF(VRAM_F_OBJ_EXT_PALETTE); |
210 SUB_BG0_CR = BG_MAP_BASE(31); | 158 vramSetBankG(VRAM_G_BG_EXT_PALETTE); |
211 BG_PALETTE_SUB[255] = RGB15(31, 31, 31); | 159 vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); |
212 /* debugging purposes, uncomment this later. then remove it & add 2screen. | 160 vramSetBankI(VRAM_I_SUB_SPRITE); |
213 consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31), | 161 |
214 (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);*/ | 162 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub |
215 printf("-NDS_SetDisplayMode\n"); | 163 TODO: this will change |
164 when multi-head is | |
165 introduced in render */ | |
166 | |
167 printf("-NDS_SetDisplayMode\n"); | |
216 return 0; | 168 return 0; |
217 } | 169 } |
218 | 170 |
219 void | 171 void |
220 NDS_VideoQuit(_THIS) | 172 NDS_VideoQuit(_THIS) |
221 { | 173 { |
222 printf("+NDS_VideoQuit\n"); | 174 printf("+NDS_VideoQuit\n"); |
223 videoSetMode(DISPLAY_SCREEN_OFF); | 175 videoSetMode(DISPLAY_SCREEN_OFF); |
224 videoSetModeSub(DISPLAY_SCREEN_OFF); | 176 videoSetModeSub(DISPLAY_SCREEN_OFF); |
225 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); | 177 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); |
226 printf("-NDS_VideoQuit\n"); | 178 vramSetBankE(VRAM_E_LCD); |
179 vramSetBankF(VRAM_F_LCD); | |
180 vramSetBankG(VRAM_G_LCD); | |
181 vramSetBankH(VRAM_H_LCD); | |
182 vramSetBankI(VRAM_I_LCD); | |
183 printf("-NDS_VideoQuit\n"); | |
227 } | 184 } |
228 | 185 |
229 /* vi: set ts=4 sw=4 expandtab: */ | 186 /* vi: set ts=4 sw=4 expandtab: */ |