Mercurial > vba-linux
diff src/gba/Mode4.cpp @ 19:5e8e5083da94
brought in common and gba, fixed problems with outdated Makefile.am files in both of these packages
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 04 Mar 2012 14:33:52 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/gba/Mode4.cpp Sun Mar 04 14:33:52 2012 -0600 1.3 @@ -0,0 +1,440 @@ 1.4 +#include "GBAGfx.h" 1.5 +#include "GBAGlobals.h" 1.6 + 1.7 +void mode4RenderLine() 1.8 +{ 1.9 + u16 *palette = (u16 *)paletteRAM; 1.10 + 1.11 + if (DISPCNT & 0x0080) 1.12 + { 1.13 + for (int x = 0; x < 240; x++) 1.14 + { 1.15 + lineMix[x] = 0x7fff; 1.16 + } 1.17 + gfxLastVCOUNT = VCOUNT; 1.18 + return; 1.19 + } 1.20 + 1.21 + if (layerEnable & 0x400) 1.22 + { 1.23 + int changed = gfxBG2Changed; 1.24 + 1.25 + if (gfxLastVCOUNT > VCOUNT) 1.26 + changed = 3; 1.27 + 1.28 + gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, 1.29 + BG2PA, BG2PB, BG2PC, BG2PD, 1.30 + gfxBG2X, gfxBG2Y, changed, 1.31 + line2); 1.32 + } 1.33 + 1.34 + gfxDrawSprites(lineOBJ); 1.35 + 1.36 + u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); 1.37 + 1.38 + for (int x = 0; x < 240; x++) 1.39 + { 1.40 + u32 color = backdrop; 1.41 + u8 top = 0x20; 1.42 + 1.43 + if (line2[x] < color) 1.44 + { 1.45 + color = line2[x]; 1.46 + top = 0x04; 1.47 + } 1.48 + 1.49 + if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) 1.50 + { 1.51 + color = lineOBJ[x]; 1.52 + top = 0x10; 1.53 + } 1.54 + 1.55 + if ((top & 0x10) && (color & 0x00010000)) 1.56 + { 1.57 + // semi-transparent OBJ 1.58 + u32 back = backdrop; 1.59 + u8 top2 = 0x20; 1.60 + 1.61 + if (line2[x] < back) 1.62 + { 1.63 + back = line2[x]; 1.64 + top2 = 0x04; 1.65 + } 1.66 + 1.67 + if (top2 & (BLDMOD>>8)) 1.68 + color = gfxAlphaBlend(color, back, 1.69 + coeff[COLEV & 0x1F], 1.70 + coeff[(COLEV >> 8) & 0x1F]); 1.71 + else 1.72 + { 1.73 + switch ((BLDMOD >> 6) & 3) 1.74 + { 1.75 + case 2: 1.76 + if (BLDMOD & top) 1.77 + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); 1.78 + break; 1.79 + case 3: 1.80 + if (BLDMOD & top) 1.81 + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); 1.82 + break; 1.83 + } 1.84 + } 1.85 + } 1.86 + 1.87 + lineMix[x] = color; 1.88 + } 1.89 + gfxBG2Changed = 0; 1.90 + gfxLastVCOUNT = VCOUNT; 1.91 +} 1.92 + 1.93 +void mode4RenderLineNoWindow() 1.94 +{ 1.95 + u16 *palette = (u16 *)paletteRAM; 1.96 + 1.97 + if (DISPCNT & 0x0080) 1.98 + { 1.99 + for (int x = 0; x < 240; x++) 1.100 + { 1.101 + lineMix[x] = 0x7fff; 1.102 + } 1.103 + gfxLastVCOUNT = VCOUNT; 1.104 + return; 1.105 + } 1.106 + 1.107 + if (layerEnable & 0x400) 1.108 + { 1.109 + int changed = gfxBG2Changed; 1.110 + 1.111 + if (gfxLastVCOUNT > VCOUNT) 1.112 + changed = 3; 1.113 + 1.114 + gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, 1.115 + BG2PA, BG2PB, BG2PC, BG2PD, 1.116 + gfxBG2X, gfxBG2Y, changed, 1.117 + line2); 1.118 + } 1.119 + 1.120 + gfxDrawSprites(lineOBJ); 1.121 + 1.122 + u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); 1.123 + 1.124 + for (int x = 0; x < 240; x++) 1.125 + { 1.126 + u32 color = backdrop; 1.127 + u8 top = 0x20; 1.128 + 1.129 + if (line2[x] < color) 1.130 + { 1.131 + color = line2[x]; 1.132 + top = 0x04; 1.133 + } 1.134 + 1.135 + if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) 1.136 + { 1.137 + color = lineOBJ[x]; 1.138 + top = 0x10; 1.139 + } 1.140 + 1.141 + if (!(color & 0x00010000)) 1.142 + { 1.143 + switch ((BLDMOD >> 6) & 3) 1.144 + { 1.145 + case 0: 1.146 + break; 1.147 + case 1: 1.148 + { 1.149 + if (top & BLDMOD) 1.150 + { 1.151 + u32 back = backdrop; 1.152 + u8 top2 = 0x20; 1.153 + 1.154 + if (line2[x] < back) 1.155 + { 1.156 + if (top != 0x04) 1.157 + { 1.158 + back = line2[x]; 1.159 + top2 = 0x04; 1.160 + } 1.161 + } 1.162 + 1.163 + if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) 1.164 + { 1.165 + if (top != 0x10) 1.166 + { 1.167 + back = lineOBJ[x]; 1.168 + top2 = 0x10; 1.169 + } 1.170 + } 1.171 + 1.172 + if (top2 & (BLDMOD>>8)) 1.173 + color = gfxAlphaBlend(color, back, 1.174 + coeff[COLEV & 0x1F], 1.175 + coeff[(COLEV >> 8) & 0x1F]); 1.176 + } 1.177 + break; 1.178 + } 1.179 + case 2: 1.180 + if (BLDMOD & top) 1.181 + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); 1.182 + break; 1.183 + case 3: 1.184 + if (BLDMOD & top) 1.185 + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); 1.186 + break; 1.187 + } 1.188 + } 1.189 + else 1.190 + { 1.191 + // semi-transparent OBJ 1.192 + u32 back = backdrop; 1.193 + u8 top2 = 0x20; 1.194 + 1.195 + if (line2[x] < back) 1.196 + { 1.197 + back = line2[x]; 1.198 + top2 = 0x04; 1.199 + } 1.200 + 1.201 + if (top2 & (BLDMOD>>8)) 1.202 + color = gfxAlphaBlend(color, back, 1.203 + coeff[COLEV & 0x1F], 1.204 + coeff[(COLEV >> 8) & 0x1F]); 1.205 + else 1.206 + { 1.207 + switch ((BLDMOD >> 6) & 3) 1.208 + { 1.209 + case 2: 1.210 + if (BLDMOD & top) 1.211 + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); 1.212 + break; 1.213 + case 3: 1.214 + if (BLDMOD & top) 1.215 + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); 1.216 + break; 1.217 + } 1.218 + } 1.219 + } 1.220 + 1.221 + lineMix[x] = color; 1.222 + } 1.223 + gfxBG2Changed = 0; 1.224 + gfxLastVCOUNT = VCOUNT; 1.225 +} 1.226 + 1.227 +void mode4RenderLineAll() 1.228 +{ 1.229 + u16 *palette = (u16 *)paletteRAM; 1.230 + 1.231 + if (DISPCNT & 0x0080) 1.232 + { 1.233 + for (int x = 0; x < 240; x++) 1.234 + { 1.235 + lineMix[x] = 0x7fff; 1.236 + } 1.237 + gfxLastVCOUNT = VCOUNT; 1.238 + return; 1.239 + } 1.240 + 1.241 + bool inWindow0 = false; 1.242 + bool inWindow1 = false; 1.243 + 1.244 + if (layerEnable & 0x2000) 1.245 + { 1.246 + u8 v0 = WIN0V >> 8; 1.247 + u8 v1 = WIN0V & 255; 1.248 + inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); 1.249 + if (v1 >= v0) 1.250 + inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1); 1.251 + else 1.252 + inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); 1.253 + } 1.254 + if (layerEnable & 0x4000) 1.255 + { 1.256 + u8 v0 = WIN1V >> 8; 1.257 + u8 v1 = WIN1V & 255; 1.258 + inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); 1.259 + if (v1 >= v0) 1.260 + inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1); 1.261 + else 1.262 + inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); 1.263 + } 1.264 + 1.265 + if (layerEnable & 0x400) 1.266 + { 1.267 + int changed = gfxBG2Changed; 1.268 + 1.269 + if (gfxLastVCOUNT > VCOUNT) 1.270 + changed = 3; 1.271 + 1.272 + gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, 1.273 + BG2PA, BG2PB, BG2PC, BG2PD, 1.274 + gfxBG2X, gfxBG2Y, changed, 1.275 + line2); 1.276 + } 1.277 + 1.278 + gfxDrawSprites(lineOBJ); 1.279 + gfxDrawOBJWin(lineOBJWin); 1.280 + 1.281 + u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); 1.282 + 1.283 + u8 inWin0Mask = WININ & 0xFF; 1.284 + u8 inWin1Mask = WININ >> 8; 1.285 + u8 outMask = WINOUT & 0xFF; 1.286 + 1.287 + for (int x = 0; x < 240; x++) 1.288 + { 1.289 + u32 color = backdrop; 1.290 + u8 top = 0x20; 1.291 + u8 mask = outMask; 1.292 + 1.293 + if (!(lineOBJWin[x] & 0x80000000)) 1.294 + { 1.295 + mask = WINOUT >> 8; 1.296 + } 1.297 + 1.298 + if (inWindow1) 1.299 + { 1.300 + if (gfxInWin1[x]) 1.301 + mask = inWin1Mask; 1.302 + } 1.303 + 1.304 + if (inWindow0) 1.305 + { 1.306 + if (gfxInWin0[x]) 1.307 + { 1.308 + mask = inWin0Mask; 1.309 + } 1.310 + } 1.311 + 1.312 + if ((mask & 4) && (line2[x] < color)) 1.313 + { 1.314 + color = line2[x]; 1.315 + top = 0x04; 1.316 + } 1.317 + 1.318 + if ((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) 1.319 + { 1.320 + color = lineOBJ[x]; 1.321 + top = 0x10; 1.322 + } 1.323 + 1.324 + if (mask & 32) 1.325 + { 1.326 + if (!(color & 0x00010000)) 1.327 + { 1.328 + switch ((BLDMOD >> 6) & 3) 1.329 + { 1.330 + case 0: 1.331 + break; 1.332 + case 1: 1.333 + { 1.334 + if (top & BLDMOD) 1.335 + { 1.336 + u32 back = backdrop; 1.337 + u8 top2 = 0x20; 1.338 + 1.339 + if ((mask & 4) && line2[x] < back) 1.340 + { 1.341 + if (top != 0x04) 1.342 + { 1.343 + back = line2[x]; 1.344 + top2 = 0x04; 1.345 + } 1.346 + } 1.347 + 1.348 + if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) 1.349 + { 1.350 + if (top != 0x10) 1.351 + { 1.352 + back = lineOBJ[x]; 1.353 + top2 = 0x10; 1.354 + } 1.355 + } 1.356 + 1.357 + if (top2 & (BLDMOD>>8)) 1.358 + color = gfxAlphaBlend(color, back, 1.359 + coeff[COLEV & 0x1F], 1.360 + coeff[(COLEV >> 8) & 0x1F]); 1.361 + } 1.362 + break; 1.363 + } 1.364 + case 2: 1.365 + if (BLDMOD & top) 1.366 + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); 1.367 + break; 1.368 + case 3: 1.369 + if (BLDMOD & top) 1.370 + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); 1.371 + break; 1.372 + } 1.373 + } 1.374 + else 1.375 + { 1.376 + // semi-transparent OBJ 1.377 + u32 back = backdrop; 1.378 + u8 top2 = 0x20; 1.379 + 1.380 + if ((mask & 4) && line2[x] < back) 1.381 + { 1.382 + back = line2[x]; 1.383 + top2 = 0x04; 1.384 + } 1.385 + 1.386 + if (top2 & (BLDMOD>>8)) 1.387 + color = gfxAlphaBlend(color, back, 1.388 + coeff[COLEV & 0x1F], 1.389 + coeff[(COLEV >> 8) & 0x1F]); 1.390 + else 1.391 + { 1.392 + switch ((BLDMOD >> 6) & 3) 1.393 + { 1.394 + case 2: 1.395 + if (BLDMOD & top) 1.396 + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); 1.397 + break; 1.398 + case 3: 1.399 + if (BLDMOD & top) 1.400 + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); 1.401 + break; 1.402 + } 1.403 + } 1.404 + } 1.405 + } 1.406 + else if (color & 0x00010000) 1.407 + { 1.408 + // semi-transparent OBJ 1.409 + u32 back = backdrop; 1.410 + u8 top2 = 0x20; 1.411 + 1.412 + if ((mask & 4) && line2[x] < back) 1.413 + { 1.414 + back = line2[x]; 1.415 + top2 = 0x04; 1.416 + } 1.417 + 1.418 + if (top2 & (BLDMOD>>8)) 1.419 + color = gfxAlphaBlend(color, back, 1.420 + coeff[COLEV & 0x1F], 1.421 + coeff[(COLEV >> 8) & 0x1F]); 1.422 + else 1.423 + { 1.424 + switch ((BLDMOD >> 6) & 3) 1.425 + { 1.426 + case 2: 1.427 + if (BLDMOD & top) 1.428 + color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); 1.429 + break; 1.430 + case 3: 1.431 + if (BLDMOD & top) 1.432 + color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); 1.433 + break; 1.434 + } 1.435 + } 1.436 + } 1.437 + 1.438 + lineMix[x] = color; 1.439 + } 1.440 + gfxBG2Changed = 0; 1.441 + gfxLastVCOUNT = VCOUNT; 1.442 +} 1.443 +