diff src/gba/Mode2.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/Mode2.cpp	Sun Mar 04 14:33:52 2012 -0600
     1.3 @@ -0,0 +1,530 @@
     1.4 +#include "GBAGfx.h"
     1.5 +#include "GBAGlobals.h"
     1.6 +
     1.7 +void mode2RenderLine()
     1.8 +{
     1.9 +	u16 *palette = (u16 *)paletteRAM;
    1.10 +
    1.11 +	if (DISPCNT & 0x80)
    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 & 0x0400)
    1.22 +	{
    1.23 +		int changed = gfxBG2Changed;
    1.24 +		if (gfxLastVCOUNT > VCOUNT)
    1.25 +			changed = 3;
    1.26 +
    1.27 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
    1.28 +		                 BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
    1.29 +		                 changed, line2);
    1.30 +	}
    1.31 +
    1.32 +	if (layerEnable & 0x0800)
    1.33 +	{
    1.34 +		int changed = gfxBG3Changed;
    1.35 +		if (gfxLastVCOUNT > VCOUNT)
    1.36 +			changed = 3;
    1.37 +
    1.38 +		gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
    1.39 +		                 BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
    1.40 +		                 changed, line3);
    1.41 +	}
    1.42 +
    1.43 +	gfxDrawSprites(lineOBJ);
    1.44 +
    1.45 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
    1.46 +
    1.47 +	for (int x = 0; x < 240; x++)
    1.48 +	{
    1.49 +		u32 color = backdrop;
    1.50 +		u8  top   = 0x20;
    1.51 +
    1.52 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
    1.53 +		{
    1.54 +			color = line2[x];
    1.55 +			top   = 0x04;
    1.56 +		}
    1.57 +
    1.58 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24))
    1.59 +		{
    1.60 +			color = line3[x];
    1.61 +			top   = 0x08;
    1.62 +		}
    1.63 +
    1.64 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
    1.65 +		{
    1.66 +			color = lineOBJ[x];
    1.67 +			top   = 0x10;
    1.68 +		}
    1.69 +
    1.70 +		if ((top & 0x10) && (color & 0x00010000))
    1.71 +		{
    1.72 +			// semi-transparent OBJ
    1.73 +			u32 back = backdrop;
    1.74 +			u8  top2 = 0x20;
    1.75 +
    1.76 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
    1.77 +			{
    1.78 +				back = line2[x];
    1.79 +				top2 = 0x04;
    1.80 +			}
    1.81 +
    1.82 +			if ((u8)(line3[x]>>24) < (u8)(back >> 24))
    1.83 +			{
    1.84 +				back = line3[x];
    1.85 +				top2 = 0x08;
    1.86 +			}
    1.87 +
    1.88 +			if (top2 & (BLDMOD>>8))
    1.89 +				color = gfxAlphaBlend(color, back,
    1.90 +				                      coeff[COLEV & 0x1F],
    1.91 +				                      coeff[(COLEV >> 8) & 0x1F]);
    1.92 +			else
    1.93 +			{
    1.94 +				switch ((BLDMOD >> 6) & 3)
    1.95 +				{
    1.96 +				case 2:
    1.97 +					if (BLDMOD & top)
    1.98 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
    1.99 +					break;
   1.100 +				case 3:
   1.101 +					if (BLDMOD & top)
   1.102 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
   1.103 +					break;
   1.104 +				}
   1.105 +			}
   1.106 +		}
   1.107 +
   1.108 +		lineMix[x] = color;
   1.109 +	}
   1.110 +	gfxBG2Changed = 0;
   1.111 +	gfxBG3Changed = 0;
   1.112 +	gfxLastVCOUNT = VCOUNT;
   1.113 +}
   1.114 +
   1.115 +void mode2RenderLineNoWindow()
   1.116 +{
   1.117 +	u16 *palette = (u16 *)paletteRAM;
   1.118 +
   1.119 +	if (DISPCNT & 0x80)
   1.120 +	{
   1.121 +		for (int x = 0; x < 240; x++)
   1.122 +		{
   1.123 +			lineMix[x] = 0x7fff;
   1.124 +		}
   1.125 +		gfxLastVCOUNT = VCOUNT;
   1.126 +		return;
   1.127 +	}
   1.128 +
   1.129 +	if (layerEnable & 0x0400)
   1.130 +	{
   1.131 +		int changed = gfxBG2Changed;
   1.132 +		if (gfxLastVCOUNT > VCOUNT)
   1.133 +			changed = 3;
   1.134 +
   1.135 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
   1.136 +		                 BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
   1.137 +		                 changed, line2);
   1.138 +	}
   1.139 +
   1.140 +	if (layerEnable & 0x0800)
   1.141 +	{
   1.142 +		int changed = gfxBG3Changed;
   1.143 +		if (gfxLastVCOUNT > VCOUNT)
   1.144 +			changed = 3;
   1.145 +
   1.146 +		gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
   1.147 +		                 BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
   1.148 +		                 changed, line3);
   1.149 +	}
   1.150 +
   1.151 +	gfxDrawSprites(lineOBJ);
   1.152 +
   1.153 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
   1.154 +
   1.155 +	for (int x = 0; x < 240; x++)
   1.156 +	{
   1.157 +		u32 color = backdrop;
   1.158 +		u8  top   = 0x20;
   1.159 +
   1.160 +		if ((u8)(line2[x]>>24) < (u8)(color >> 24))
   1.161 +		{
   1.162 +			color = line2[x];
   1.163 +			top   = 0x04;
   1.164 +		}
   1.165 +
   1.166 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24))
   1.167 +		{
   1.168 +			color = line3[x];
   1.169 +			top   = 0x08;
   1.170 +		}
   1.171 +
   1.172 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
   1.173 +		{
   1.174 +			color = lineOBJ[x];
   1.175 +			top   = 0x10;
   1.176 +		}
   1.177 +
   1.178 +		if (!(color & 0x00010000))
   1.179 +		{
   1.180 +			switch ((BLDMOD >> 6) & 3)
   1.181 +			{
   1.182 +			case 0:
   1.183 +				break;
   1.184 +			case 1:
   1.185 +			{
   1.186 +				if (top & BLDMOD)
   1.187 +				{
   1.188 +					u32 back = backdrop;
   1.189 +					u8  top2 = 0x20;
   1.190 +
   1.191 +					if ((u8)(line2[x]>>24) < (u8)(back >> 24))
   1.192 +					{
   1.193 +						if (top != 0x04)
   1.194 +						{
   1.195 +							back = line2[x];
   1.196 +							top2 = 0x04;
   1.197 +						}
   1.198 +					}
   1.199 +
   1.200 +					if ((u8)(line3[x]>>24) < (u8)(back >> 24))
   1.201 +					{
   1.202 +						if (top != 0x08)
   1.203 +						{
   1.204 +							back = line3[x];
   1.205 +							top2 = 0x08;
   1.206 +						}
   1.207 +					}
   1.208 +
   1.209 +					if ((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
   1.210 +					{
   1.211 +						if (top != 0x10)
   1.212 +						{
   1.213 +							back = lineOBJ[x];
   1.214 +							top2 = 0x10;
   1.215 +						}
   1.216 +					}
   1.217 +
   1.218 +					if (top2 & (BLDMOD>>8))
   1.219 +						color = gfxAlphaBlend(color, back,
   1.220 +						                      coeff[COLEV & 0x1F],
   1.221 +						                      coeff[(COLEV >> 8) & 0x1F]);
   1.222 +				}
   1.223 +				break;
   1.224 +			}
   1.225 +			case 2:
   1.226 +				if (BLDMOD & top)
   1.227 +					color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
   1.228 +				break;
   1.229 +			case 3:
   1.230 +				if (BLDMOD & top)
   1.231 +					color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
   1.232 +				break;
   1.233 +			}
   1.234 +		}
   1.235 +		else
   1.236 +		{
   1.237 +			// semi-transparent OBJ
   1.238 +			u32 back = backdrop;
   1.239 +			u8  top2 = 0x20;
   1.240 +
   1.241 +			if ((u8)(line2[x]>>24) < (u8)(back >> 24))
   1.242 +			{
   1.243 +				back = line2[x];
   1.244 +				top2 = 0x04;
   1.245 +			}
   1.246 +
   1.247 +			if ((u8)(line3[x]>>24) < (u8)(back >> 24))
   1.248 +			{
   1.249 +				back = line3[x];
   1.250 +				top2 = 0x08;
   1.251 +			}
   1.252 +
   1.253 +			if (top2 & (BLDMOD>>8))
   1.254 +				color = gfxAlphaBlend(color, back,
   1.255 +				                      coeff[COLEV & 0x1F],
   1.256 +				                      coeff[(COLEV >> 8) & 0x1F]);
   1.257 +			else
   1.258 +			{
   1.259 +				switch ((BLDMOD >> 6) & 3)
   1.260 +				{
   1.261 +				case 2:
   1.262 +					if (BLDMOD & top)
   1.263 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
   1.264 +					break;
   1.265 +				case 3:
   1.266 +					if (BLDMOD & top)
   1.267 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
   1.268 +					break;
   1.269 +				}
   1.270 +			}
   1.271 +		}
   1.272 +
   1.273 +		lineMix[x] = color;
   1.274 +	}
   1.275 +	gfxBG2Changed = 0;
   1.276 +	gfxBG3Changed = 0;
   1.277 +	gfxLastVCOUNT = VCOUNT;
   1.278 +}
   1.279 +
   1.280 +void mode2RenderLineAll()
   1.281 +{
   1.282 +	u16 *palette = (u16 *)paletteRAM;
   1.283 +
   1.284 +	if (DISPCNT & 0x80)
   1.285 +	{
   1.286 +		for (int x = 0; x < 240; x++)
   1.287 +		{
   1.288 +			lineMix[x] = 0x7fff;
   1.289 +		}
   1.290 +		gfxLastVCOUNT = VCOUNT;
   1.291 +		return;
   1.292 +	}
   1.293 +
   1.294 +	bool inWindow0 = false;
   1.295 +	bool inWindow1 = false;
   1.296 +
   1.297 +	if (layerEnable & 0x2000)
   1.298 +	{
   1.299 +		u8 v0 = WIN0V >> 8;
   1.300 +		u8 v1 = WIN0V & 255;
   1.301 +		inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
   1.302 +		if (v1 >= v0)
   1.303 +			inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
   1.304 +		else
   1.305 +			inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
   1.306 +	}
   1.307 +	if (layerEnable & 0x4000)
   1.308 +	{
   1.309 +		u8 v0 = WIN1V >> 8;
   1.310 +		u8 v1 = WIN1V & 255;
   1.311 +		inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
   1.312 +		if (v1 >= v0)
   1.313 +			inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
   1.314 +		else
   1.315 +			inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
   1.316 +	}
   1.317 +
   1.318 +	if (layerEnable & 0x0400)
   1.319 +	{
   1.320 +		int changed = gfxBG2Changed;
   1.321 +		if (gfxLastVCOUNT > VCOUNT)
   1.322 +			changed = 3;
   1.323 +
   1.324 +		gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
   1.325 +		                 BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
   1.326 +		                 changed, line2);
   1.327 +	}
   1.328 +
   1.329 +	if (layerEnable & 0x0800)
   1.330 +	{
   1.331 +		int changed = gfxBG3Changed;
   1.332 +		if (gfxLastVCOUNT > VCOUNT)
   1.333 +			changed = 3;
   1.334 +
   1.335 +		gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
   1.336 +		                 BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
   1.337 +		                 changed, line3);
   1.338 +	}
   1.339 +
   1.340 +	gfxDrawSprites(lineOBJ);
   1.341 +	gfxDrawOBJWin(lineOBJWin);
   1.342 +
   1.343 +	u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
   1.344 +
   1.345 +	u8 inWin0Mask = WININ & 0xFF;
   1.346 +	u8 inWin1Mask = WININ >> 8;
   1.347 +	u8 outMask    = WINOUT & 0xFF;
   1.348 +
   1.349 +	for (int x = 0; x < 240; x++)
   1.350 +	{
   1.351 +		u32 color = backdrop;
   1.352 +		u8  top   = 0x20;
   1.353 +		u8  mask  = outMask;
   1.354 +
   1.355 +		if (!(lineOBJWin[x] & 0x80000000))
   1.356 +		{
   1.357 +			mask = WINOUT >> 8;
   1.358 +		}
   1.359 +
   1.360 +		if (inWindow1)
   1.361 +		{
   1.362 +			if (gfxInWin1[x])
   1.363 +				mask = inWin1Mask;
   1.364 +		}
   1.365 +
   1.366 +		if (inWindow0)
   1.367 +		{
   1.368 +			if (gfxInWin0[x])
   1.369 +			{
   1.370 +				mask = inWin0Mask;
   1.371 +			}
   1.372 +		}
   1.373 +
   1.374 +		if (line2[x] < color && (mask & 4))
   1.375 +		{
   1.376 +			color = line2[x];
   1.377 +			top   = 0x04;
   1.378 +		}
   1.379 +
   1.380 +		if ((u8)(line3[x]>>24) < (u8)(color >> 24) && (mask & 8))
   1.381 +		{
   1.382 +			color = line3[x];
   1.383 +			top   = 0x08;
   1.384 +		}
   1.385 +
   1.386 +		if ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16))
   1.387 +		{
   1.388 +			color = lineOBJ[x];
   1.389 +			top   = 0x10;
   1.390 +		}
   1.391 +
   1.392 +		if (mask & 32)
   1.393 +		{
   1.394 +			if (!(color & 0x00010000))
   1.395 +			{
   1.396 +				switch ((BLDMOD >> 6) & 3)
   1.397 +				{
   1.398 +				case 0:
   1.399 +					break;
   1.400 +				case 1:
   1.401 +				{
   1.402 +					if (top & BLDMOD)
   1.403 +					{
   1.404 +						u32 back = backdrop;
   1.405 +						u8  top2 = 0x20;
   1.406 +
   1.407 +						if ((mask & 4) && line2[x] < back)
   1.408 +						{
   1.409 +							if (top != 0x04)
   1.410 +							{
   1.411 +								back = line2[x];
   1.412 +								top2 = 0x04;
   1.413 +							}
   1.414 +						}
   1.415 +
   1.416 +						if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
   1.417 +						{
   1.418 +							if (top != 0x08)
   1.419 +							{
   1.420 +								back = line3[x];
   1.421 +								top2 = 0x08;
   1.422 +							}
   1.423 +						}
   1.424 +
   1.425 +						if ((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
   1.426 +						{
   1.427 +							if (top != 0x10)
   1.428 +							{
   1.429 +								back = lineOBJ[x];
   1.430 +								top2 = 0x10;
   1.431 +							}
   1.432 +						}
   1.433 +
   1.434 +						if (top2 & (BLDMOD>>8))
   1.435 +							color = gfxAlphaBlend(color, back,
   1.436 +							                      coeff[COLEV & 0x1F],
   1.437 +							                      coeff[(COLEV >> 8) & 0x1F]);
   1.438 +					}
   1.439 +					break;
   1.440 +				}
   1.441 +				case 2:
   1.442 +					if (BLDMOD & top)
   1.443 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
   1.444 +					break;
   1.445 +				case 3:
   1.446 +					if (BLDMOD & top)
   1.447 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
   1.448 +					break;
   1.449 +				}
   1.450 +			}
   1.451 +			else
   1.452 +			{
   1.453 +				// semi-transparent OBJ
   1.454 +				u32 back = backdrop;
   1.455 +				u8  top2 = 0x20;
   1.456 +
   1.457 +				if ((mask & 4) && line2[x] < back)
   1.458 +				{
   1.459 +					back = line2[x];
   1.460 +					top2 = 0x04;
   1.461 +				}
   1.462 +
   1.463 +				if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
   1.464 +				{
   1.465 +					back = line3[x];
   1.466 +					top2 = 0x08;
   1.467 +				}
   1.468 +
   1.469 +				if (top2 & (BLDMOD>>8))
   1.470 +					color = gfxAlphaBlend(color, back,
   1.471 +					                      coeff[COLEV & 0x1F],
   1.472 +					                      coeff[(COLEV >> 8) & 0x1F]);
   1.473 +				else
   1.474 +				{
   1.475 +					switch ((BLDMOD >> 6) & 3)
   1.476 +					{
   1.477 +					case 2:
   1.478 +						if (BLDMOD & top)
   1.479 +							color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
   1.480 +						break;
   1.481 +					case 3:
   1.482 +						if (BLDMOD & top)
   1.483 +							color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
   1.484 +						break;
   1.485 +					}
   1.486 +				}
   1.487 +			}
   1.488 +		}
   1.489 +		else if (color & 0x00010000)
   1.490 +		{
   1.491 +			// semi-transparent OBJ
   1.492 +			u32 back = backdrop;
   1.493 +			u8  top2 = 0x20;
   1.494 +
   1.495 +			if ((mask & 4) && line2[x] < back)
   1.496 +			{
   1.497 +				back = line2[x];
   1.498 +				top2 = 0x04;
   1.499 +			}
   1.500 +
   1.501 +			if ((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
   1.502 +			{
   1.503 +				back = line3[x];
   1.504 +				top2 = 0x08;
   1.505 +			}
   1.506 +
   1.507 +			if (top2 & (BLDMOD>>8))
   1.508 +				color = gfxAlphaBlend(color, back,
   1.509 +				                      coeff[COLEV & 0x1F],
   1.510 +				                      coeff[(COLEV >> 8) & 0x1F]);
   1.511 +			else
   1.512 +			{
   1.513 +				switch ((BLDMOD >> 6) & 3)
   1.514 +				{
   1.515 +				case 2:
   1.516 +					if (BLDMOD & top)
   1.517 +						color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
   1.518 +					break;
   1.519 +				case 3:
   1.520 +					if (BLDMOD & top)
   1.521 +						color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
   1.522 +					break;
   1.523 +				}
   1.524 +			}
   1.525 +		}
   1.526 +
   1.527 +		lineMix[x] = color;
   1.528 +	}
   1.529 +	gfxBG2Changed = 0;
   1.530 +	gfxBG3Changed = 0;
   1.531 +	gfxLastVCOUNT = VCOUNT;
   1.532 +}
   1.533 +