diff src/gb/gbCheats.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 --- a/src/gb/gbCheats.cpp	Sat Mar 03 12:06:10 2012 -0600
     1.2 +++ b/src/gb/gbCheats.cpp	Sun Mar 04 14:33:52 2012 -0600
     1.3 @@ -21,457 +21,457 @@
     1.4  
     1.5  void gbCheatUpdateMap()
     1.6  {
     1.7 -	memset(gbCheatMap, 0, 0x10000);
     1.8 +  memset(gbCheatMap, 0, 0x10000);
     1.9  
    1.10 -	for (int i = 0; i < gbCheatNumber; i++)
    1.11 -	{
    1.12 -		if (gbCheatList[i].enabled)
    1.13 -			gbCheatMap[gbCheatList[i].address] = true;
    1.14 -	}
    1.15 +  for (int i = 0; i < gbCheatNumber; i++)
    1.16 +    {
    1.17 +      if (gbCheatList[i].enabled)
    1.18 +	gbCheatMap[gbCheatList[i].address] = true;
    1.19 +    }
    1.20  }
    1.21  
    1.22  void gbCheatsSaveGame(gzFile gzFile)
    1.23  {
    1.24 -	utilWriteInt(gzFile, gbCheatNumber);
    1.25 -	if (gbCheatNumber)
    1.26 -		utilGzWrite(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber);
    1.27 +  utilWriteInt(gzFile, gbCheatNumber);
    1.28 +  if (gbCheatNumber)
    1.29 +    utilGzWrite(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber);
    1.30  }
    1.31  
    1.32  void gbCheatsReadGame(gzFile gzFile, int version)
    1.33  {
    1.34 -	if (version <= 8)
    1.35 +  if (version <= 8)
    1.36 +    {
    1.37 +      int gbGgOn = utilReadInt(gzFile);
    1.38 +
    1.39 +      if (gbGgOn)
    1.40  	{
    1.41 -		int gbGgOn = utilReadInt(gzFile);
    1.42 -
    1.43 -		if (gbGgOn)
    1.44 -		{
    1.45 -			int       n = utilReadInt(gzFile);
    1.46 -			gbXxCheat tmpCheat;
    1.47 -			for (int i = 0; i < n; i++)
    1.48 -			{
    1.49 -				utilGzRead(gzFile, &tmpCheat, sizeof(gbXxCheat));
    1.50 -				gbAddGgCheat(tmpCheat.cheatCode, tmpCheat.cheatDesc);
    1.51 -			}
    1.52 -		}
    1.53 -
    1.54 -		int gbGsOn = utilReadInt(gzFile);
    1.55 -
    1.56 -		if (gbGsOn)
    1.57 -		{
    1.58 -			int       n = utilReadInt(gzFile);
    1.59 -			gbXxCheat tmpCheat;
    1.60 -			for (int i = 0; i < n; i++)
    1.61 -			{
    1.62 -				utilGzRead(gzFile, &tmpCheat, sizeof(gbXxCheat));
    1.63 -				gbAddGsCheat(tmpCheat.cheatCode, tmpCheat.cheatDesc);
    1.64 -			}
    1.65 -		}
    1.66 -	}
    1.67 -	else
    1.68 -	{
    1.69 -		gbCheatNumber = utilReadInt(gzFile);
    1.70 -
    1.71 -		if (gbCheatNumber)
    1.72 -		{
    1.73 -			utilGzRead(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber);
    1.74 -		}
    1.75 +	  int       n = utilReadInt(gzFile);
    1.76 +	  gbXxCheat tmpCheat;
    1.77 +	  for (int i = 0; i < n; i++)
    1.78 +	    {
    1.79 +	      utilGzRead(gzFile, &tmpCheat, sizeof(gbXxCheat));
    1.80 +	      gbAddGgCheat(tmpCheat.cheatCode, tmpCheat.cheatDesc);
    1.81 +	    }
    1.82  	}
    1.83  
    1.84 -	gbCheatUpdateMap();
    1.85 +      int gbGsOn = utilReadInt(gzFile);
    1.86 +
    1.87 +      if (gbGsOn)
    1.88 +	{
    1.89 +	  int       n = utilReadInt(gzFile);
    1.90 +	  gbXxCheat tmpCheat;
    1.91 +	  for (int i = 0; i < n; i++)
    1.92 +	    {
    1.93 +	      utilGzRead(gzFile, &tmpCheat, sizeof(gbXxCheat));
    1.94 +	      gbAddGsCheat(tmpCheat.cheatCode, tmpCheat.cheatDesc);
    1.95 +	    }
    1.96 +	}
    1.97 +    }
    1.98 +  else
    1.99 +    {
   1.100 +      gbCheatNumber = utilReadInt(gzFile);
   1.101 +
   1.102 +      if (gbCheatNumber)
   1.103 +	{
   1.104 +	  utilGzRead(gzFile, &gbCheatList[0], sizeof(gbCheat)*gbCheatNumber);
   1.105 +	}
   1.106 +    }
   1.107 +
   1.108 +  gbCheatUpdateMap();
   1.109  }
   1.110  
   1.111  void gbCheatsSaveCheatList(const char *file)
   1.112  {
   1.113 -	if (gbCheatNumber == 0)
   1.114 -		return;
   1.115 -	FILE *f = fopen(file, "wb");
   1.116 -	if (f == NULL)
   1.117 -		return;
   1.118 -	int version = 1;
   1.119 -	fwrite(&version, 1, sizeof(version), f);
   1.120 -	int type = 1;
   1.121 -	fwrite(&type, 1, sizeof(type), f);
   1.122 -	fwrite(&gbCheatNumber, 1, sizeof(gbCheatNumber), f);
   1.123 -	fwrite(gbCheatList, 1, sizeof(gbCheatList), f);
   1.124 -	fclose(f);
   1.125 +  if (gbCheatNumber == 0)
   1.126 +    return;
   1.127 +  FILE *f = fopen(file, "wb");
   1.128 +  if (f == NULL)
   1.129 +    return;
   1.130 +  int version = 1;
   1.131 +  fwrite(&version, 1, sizeof(version), f);
   1.132 +  int type = 1;
   1.133 +  fwrite(&type, 1, sizeof(type), f);
   1.134 +  fwrite(&gbCheatNumber, 1, sizeof(gbCheatNumber), f);
   1.135 +  fwrite(gbCheatList, 1, sizeof(gbCheatList), f);
   1.136 +  fclose(f);
   1.137  }
   1.138  
   1.139  bool gbCheatsLoadCheatList(const char *file)
   1.140  {
   1.141 -	gbCheatNumber = 0;
   1.142 +  gbCheatNumber = 0;
   1.143  
   1.144 -	gbCheatUpdateMap();
   1.145 +  gbCheatUpdateMap();
   1.146  
   1.147 -	int count = 0;
   1.148 +  int count = 0;
   1.149  
   1.150 -	FILE *f = fopen(file, "rb");
   1.151 +  FILE *f = fopen(file, "rb");
   1.152  
   1.153 -	if (f == NULL)
   1.154 -		return false;
   1.155 +  if (f == NULL)
   1.156 +    return false;
   1.157  
   1.158 -	int version = 0;
   1.159 +  int version = 0;
   1.160  
   1.161 -	if (fread(&version, 1, sizeof(version), f) != sizeof(version))
   1.162 -	{
   1.163 -		fclose(f);
   1.164 -		return false;
   1.165 -	}
   1.166 +  if (fread(&version, 1, sizeof(version), f) != sizeof(version))
   1.167 +    {
   1.168 +      fclose(f);
   1.169 +      return false;
   1.170 +    }
   1.171  
   1.172 -	if (version != 1)
   1.173 -	{
   1.174 -		systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_VERSION,
   1.175 -		              N_("Unsupported cheat list version %d"), version);
   1.176 -		fclose(f);
   1.177 -		return false;
   1.178 -	}
   1.179 +  if (version != 1)
   1.180 +    {
   1.181 +      systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_VERSION,
   1.182 +		    N_("Unsupported cheat list version %d"), version);
   1.183 +      fclose(f);
   1.184 +      return false;
   1.185 +    }
   1.186  
   1.187 -	int type = 0;
   1.188 -	if (fread(&type, 1, sizeof(type), f) != sizeof(type))
   1.189 -	{
   1.190 -		fclose(f);
   1.191 -		return false;
   1.192 -	}
   1.193 +  int type = 0;
   1.194 +  if (fread(&type, 1, sizeof(type), f) != sizeof(type))
   1.195 +    {
   1.196 +      fclose(f);
   1.197 +      return false;
   1.198 +    }
   1.199  
   1.200 -	if (type != 1)
   1.201 -	{
   1.202 -		systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE,
   1.203 -		              N_("Unsupported cheat list type %d"), type);
   1.204 -		fclose(f);
   1.205 -		return false;
   1.206 -	}
   1.207 +  if (type != 1)
   1.208 +    {
   1.209 +      systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE,
   1.210 +		    N_("Unsupported cheat list type %d"), type);
   1.211 +      fclose(f);
   1.212 +      return false;
   1.213 +    }
   1.214  
   1.215 -	if (fread(&count, 1, sizeof(count), f) != sizeof(count))
   1.216 -	{
   1.217 -		fclose(f);
   1.218 -		return false;
   1.219 -	}
   1.220 +  if (fread(&count, 1, sizeof(count), f) != sizeof(count))
   1.221 +    {
   1.222 +      fclose(f);
   1.223 +      return false;
   1.224 +    }
   1.225  
   1.226 -	if (fread(gbCheatList, 1, sizeof(gbCheatList), f) != sizeof(gbCheatList))
   1.227 -	{
   1.228 -		fclose(f);
   1.229 -		return false;
   1.230 -	}
   1.231 +  if (fread(gbCheatList, 1, sizeof(gbCheatList), f) != sizeof(gbCheatList))
   1.232 +    {
   1.233 +      fclose(f);
   1.234 +      return false;
   1.235 +    }
   1.236  
   1.237 -	fclose(f);
   1.238 -	gbCheatNumber = count;
   1.239 -	gbCheatUpdateMap();
   1.240 +  fclose(f);
   1.241 +  gbCheatNumber = count;
   1.242 +  gbCheatUpdateMap();
   1.243  
   1.244 -	return true;
   1.245 +  return true;
   1.246  }
   1.247  
   1.248  bool gbVerifyGsCode(const char *code)
   1.249  {
   1.250 -	int len = strlen(code);
   1.251 +  int len = strlen(code);
   1.252  
   1.253 -	if (len == 0)
   1.254 -		return true;
   1.255 +  if (len == 0)
   1.256 +    return true;
   1.257  
   1.258 -	if (len != 8)
   1.259 -		return false;
   1.260 +  if (len != 8)
   1.261 +    return false;
   1.262  
   1.263 -	for (int i = 0; i < 8; i++)
   1.264 -		if (!GBCHEAT_IS_HEX(code[i]))
   1.265 -			return false;
   1.266 +  for (int i = 0; i < 8; i++)
   1.267 +    if (!GBCHEAT_IS_HEX(code[i]))
   1.268 +      return false;
   1.269  
   1.270 -	int address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
   1.271 -	              GBCHEAT_HEX_VALUE(code[7]) << 8 |
   1.272 -	              GBCHEAT_HEX_VALUE(code[4]) << 4 |
   1.273 -	              GBCHEAT_HEX_VALUE(code[5]);
   1.274 +  int address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
   1.275 +    GBCHEAT_HEX_VALUE(code[7]) << 8 |
   1.276 +    GBCHEAT_HEX_VALUE(code[4]) << 4 |
   1.277 +    GBCHEAT_HEX_VALUE(code[5]);
   1.278  
   1.279 -	if (address < 0xa000 ||
   1.280 -	    address > 0xdfff)
   1.281 -		return false;
   1.282 +  if (address < 0xa000 ||
   1.283 +      address > 0xdfff)
   1.284 +    return false;
   1.285  
   1.286 -	return true;
   1.287 +  return true;
   1.288  }
   1.289  
   1.290  void gbAddGsCheat(const char *code, const char *desc)
   1.291  {
   1.292 -	if (gbCheatNumber > 99)
   1.293 -	{
   1.294 -		systemMessage(MSG_MAXIMUM_NUMBER_OF_CHEATS,
   1.295 -		              N_("Maximum number of cheats reached."));
   1.296 -		return;
   1.297 -	}
   1.298 +  if (gbCheatNumber > 99)
   1.299 +    {
   1.300 +      systemMessage(MSG_MAXIMUM_NUMBER_OF_CHEATS,
   1.301 +		    N_("Maximum number of cheats reached."));
   1.302 +      return;
   1.303 +    }
   1.304  
   1.305 -	if (!gbVerifyGsCode(code))
   1.306 -	{
   1.307 -		systemMessage(MSG_INVALID_GAMESHARK_CODE,
   1.308 -		              N_("Invalid GameShark code: %s"), code);
   1.309 -		return;
   1.310 -	}
   1.311 +  if (!gbVerifyGsCode(code))
   1.312 +    {
   1.313 +      systemMessage(MSG_INVALID_GAMESHARK_CODE,
   1.314 +		    N_("Invalid GameShark code: %s"), code);
   1.315 +      return;
   1.316 +    }
   1.317  
   1.318 -	int i = gbCheatNumber;
   1.319 +  int i = gbCheatNumber;
   1.320  
   1.321 -	strcpy(gbCheatList[i].cheatCode, code);
   1.322 -	strcpy(gbCheatList[i].cheatDesc, desc);
   1.323 +  strcpy(gbCheatList[i].cheatCode, code);
   1.324 +  strcpy(gbCheatList[i].cheatDesc, desc);
   1.325  
   1.326 -	gbCheatList[i].code = GBCHEAT_HEX_VALUE(code[0]) << 4 |
   1.327 -	                      GBCHEAT_HEX_VALUE(code[1]);
   1.328 +  gbCheatList[i].code = GBCHEAT_HEX_VALUE(code[0]) << 4 |
   1.329 +    GBCHEAT_HEX_VALUE(code[1]);
   1.330  
   1.331 -	gbCheatList[i].value = GBCHEAT_HEX_VALUE(code[2]) << 4 |
   1.332 -	                       GBCHEAT_HEX_VALUE(code[3]);
   1.333 +  gbCheatList[i].value = GBCHEAT_HEX_VALUE(code[2]) << 4 |
   1.334 +    GBCHEAT_HEX_VALUE(code[3]);
   1.335  
   1.336 -	gbCheatList[i].address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
   1.337 -	                         GBCHEAT_HEX_VALUE(code[7]) << 8 |
   1.338 -	                         GBCHEAT_HEX_VALUE(code[4]) << 4 |
   1.339 -	                         GBCHEAT_HEX_VALUE(code[5]);
   1.340 +  gbCheatList[i].address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
   1.341 +    GBCHEAT_HEX_VALUE(code[7]) << 8 |
   1.342 +    GBCHEAT_HEX_VALUE(code[4]) << 4 |
   1.343 +    GBCHEAT_HEX_VALUE(code[5]);
   1.344  
   1.345 -	gbCheatList[i].compare = 0;
   1.346 +  gbCheatList[i].compare = 0;
   1.347  
   1.348 -	gbCheatList[i].enabled = true;
   1.349 +  gbCheatList[i].enabled = true;
   1.350  
   1.351 -	gbCheatMap[gbCheatList[i].address] = true;
   1.352 +  gbCheatMap[gbCheatList[i].address] = true;
   1.353  
   1.354 -	gbCheatNumber++;
   1.355 +  gbCheatNumber++;
   1.356  }
   1.357  
   1.358  bool gbVerifyGgCode(const char *code)
   1.359  {
   1.360 -	int len = strlen(code);
   1.361 +  int len = strlen(code);
   1.362  
   1.363 -	if (len != 11 &&
   1.364 -	    len != 7 &&
   1.365 -	    len != 6 &&
   1.366 -	    len != 0)
   1.367 -		return false;
   1.368 +  if (len != 11 &&
   1.369 +      len != 7 &&
   1.370 +      len != 6 &&
   1.371 +      len != 0)
   1.372 +    return false;
   1.373  
   1.374 -	if (len == 0)
   1.375 -		return true;
   1.376 +  if (len == 0)
   1.377 +    return true;
   1.378  
   1.379 -	if (!GBCHEAT_IS_HEX(code[0]))
   1.380 -		return false;
   1.381 -	if (!GBCHEAT_IS_HEX(code[1]))
   1.382 -		return false;
   1.383 -	if (!GBCHEAT_IS_HEX(code[2]))
   1.384 -		return false;
   1.385 -	if (code[3] != '-')
   1.386 -		return false;
   1.387 -	if (!GBCHEAT_IS_HEX(code[4]))
   1.388 -		return false;
   1.389 -	if (!GBCHEAT_IS_HEX(code[5]))
   1.390 -		return false;
   1.391 -	if (!GBCHEAT_IS_HEX(code[6]))
   1.392 -		return false;
   1.393 -	if (code[7] != 0)
   1.394 +  if (!GBCHEAT_IS_HEX(code[0]))
   1.395 +    return false;
   1.396 +  if (!GBCHEAT_IS_HEX(code[1]))
   1.397 +    return false;
   1.398 +  if (!GBCHEAT_IS_HEX(code[2]))
   1.399 +    return false;
   1.400 +  if (code[3] != '-')
   1.401 +    return false;
   1.402 +  if (!GBCHEAT_IS_HEX(code[4]))
   1.403 +    return false;
   1.404 +  if (!GBCHEAT_IS_HEX(code[5]))
   1.405 +    return false;
   1.406 +  if (!GBCHEAT_IS_HEX(code[6]))
   1.407 +    return false;
   1.408 +  if (code[7] != 0)
   1.409 +    {
   1.410 +      if (code[7] != '-')
   1.411 +	return false;
   1.412 +      if (code[8] != 0)
   1.413  	{
   1.414 -		if (code[7] != '-')
   1.415 -			return false;
   1.416 -		if (code[8] != 0)
   1.417 -		{
   1.418 -			if (!GBCHEAT_IS_HEX(code[8]))
   1.419 -				return false;
   1.420 -			if (!GBCHEAT_IS_HEX(code[9]))
   1.421 -				return false;
   1.422 -			if (!GBCHEAT_IS_HEX(code[10]))
   1.423 -				return false;
   1.424 -		}
   1.425 +	  if (!GBCHEAT_IS_HEX(code[8]))
   1.426 +	    return false;
   1.427 +	  if (!GBCHEAT_IS_HEX(code[9]))
   1.428 +	    return false;
   1.429 +	  if (!GBCHEAT_IS_HEX(code[10]))
   1.430 +	    return false;
   1.431  	}
   1.432 +    }
   1.433  
   1.434 -	//  int replace = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
   1.435 -	//    GBCHEAT_HEX_VALUE(code[1]);
   1.436 +  //  int replace = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
   1.437 +  //    GBCHEAT_HEX_VALUE(code[1]);
   1.438  
   1.439 -	int address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
   1.440 -	              (GBCHEAT_HEX_VALUE(code[4]) << 4) +
   1.441 -	              (GBCHEAT_HEX_VALUE(code[5])) +
   1.442 -	              ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
   1.443 +  int address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
   1.444 +    (GBCHEAT_HEX_VALUE(code[4]) << 4) +
   1.445 +    (GBCHEAT_HEX_VALUE(code[5])) +
   1.446 +    ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
   1.447  
   1.448 -	if (address >= 0x8000 && address <= 0x9fff)
   1.449 -		return false;
   1.450 +  if (address >= 0x8000 && address <= 0x9fff)
   1.451 +    return false;
   1.452  
   1.453 -	if (address >= 0xc000)
   1.454 -		return false;
   1.455 +  if (address >= 0xc000)
   1.456 +    return false;
   1.457  
   1.458 -	if (code[7] == 0 || code[8] == '0')
   1.459 -		return true;
   1.460 +  if (code[7] == 0 || code[8] == '0')
   1.461 +    return true;
   1.462  
   1.463 -	int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
   1.464 -	              (GBCHEAT_HEX_VALUE(code[10]));
   1.465 -	compare  = compare ^ 0xff;
   1.466 -	compare  = (compare >> 2) | ((compare << 6) & 0xc0);
   1.467 -	compare ^= 0x45;
   1.468 +  int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
   1.469 +    (GBCHEAT_HEX_VALUE(code[10]));
   1.470 +  compare  = compare ^ 0xff;
   1.471 +  compare  = (compare >> 2) | ((compare << 6) & 0xc0);
   1.472 +  compare ^= 0x45;
   1.473  
   1.474 -	int cloak = (GBCHEAT_HEX_VALUE(code[8])) ^ (GBCHEAT_HEX_VALUE(code[9]));
   1.475 +  int cloak = (GBCHEAT_HEX_VALUE(code[8])) ^ (GBCHEAT_HEX_VALUE(code[9]));
   1.476  
   1.477 -	if (cloak >= 1 && cloak <= 7)
   1.478 -		return false;
   1.479 +  if (cloak >= 1 && cloak <= 7)
   1.480 +    return false;
   1.481  
   1.482 -	return true;
   1.483 +  return true;
   1.484  }
   1.485  
   1.486  void gbAddGgCheat(const char *code, const char *desc)
   1.487  {
   1.488 -	if (gbCheatNumber > 99)
   1.489 -	{
   1.490 -		systemMessage(MSG_MAXIMUM_NUMBER_OF_CHEATS,
   1.491 -		              N_("Maximum number of cheats reached."));
   1.492 -		return;
   1.493 -	}
   1.494 +  if (gbCheatNumber > 99)
   1.495 +    {
   1.496 +      systemMessage(MSG_MAXIMUM_NUMBER_OF_CHEATS,
   1.497 +		    N_("Maximum number of cheats reached."));
   1.498 +      return;
   1.499 +    }
   1.500  
   1.501 -	if (!gbVerifyGgCode(code))
   1.502 -	{
   1.503 -		systemMessage(MSG_INVALID_GAMEGENIE_CODE,
   1.504 -		              N_("Invalid GameGenie code: %s"), code);
   1.505 -		return;
   1.506 -	}
   1.507 +  if (!gbVerifyGgCode(code))
   1.508 +    {
   1.509 +      systemMessage(MSG_INVALID_GAMEGENIE_CODE,
   1.510 +		    N_("Invalid GameGenie code: %s"), code);
   1.511 +      return;
   1.512 +    }
   1.513  
   1.514 -	int i = gbCheatNumber;
   1.515 +  int i = gbCheatNumber;
   1.516  
   1.517 -	int len = strlen(code);
   1.518 +  int len = strlen(code);
   1.519  
   1.520 -	strcpy(gbCheatList[i].cheatCode, code);
   1.521 -	strcpy(gbCheatList[i].cheatDesc, desc);
   1.522 +  strcpy(gbCheatList[i].cheatCode, code);
   1.523 +  strcpy(gbCheatList[i].cheatDesc, desc);
   1.524  
   1.525 -	gbCheatList[i].code  = 1;
   1.526 -	gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
   1.527 -	                       GBCHEAT_HEX_VALUE(code[1]);
   1.528 +  gbCheatList[i].code  = 1;
   1.529 +  gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
   1.530 +    GBCHEAT_HEX_VALUE(code[1]);
   1.531  
   1.532 -	gbCheatList[i].address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
   1.533 -	                         (GBCHEAT_HEX_VALUE(code[4]) << 4) +
   1.534 -	                         (GBCHEAT_HEX_VALUE(code[5])) +
   1.535 -	                         ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
   1.536 +  gbCheatList[i].address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
   1.537 +    (GBCHEAT_HEX_VALUE(code[4]) << 4) +
   1.538 +    (GBCHEAT_HEX_VALUE(code[5])) +
   1.539 +    ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
   1.540  
   1.541 -	gbCheatList[i].compare = 0;
   1.542 +  gbCheatList[i].compare = 0;
   1.543  
   1.544 -	if (len != 7 && len != 8)
   1.545 -	{
   1.546 -		int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
   1.547 -		              (GBCHEAT_HEX_VALUE(code[10]));
   1.548 -		compare  = compare ^ 0xff;
   1.549 -		compare  = (compare >> 2) | ((compare << 6) & 0xc0);
   1.550 -		compare ^= 0x45;
   1.551 +  if (len != 7 && len != 8)
   1.552 +    {
   1.553 +      int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
   1.554 +	(GBCHEAT_HEX_VALUE(code[10]));
   1.555 +      compare  = compare ^ 0xff;
   1.556 +      compare  = (compare >> 2) | ((compare << 6) & 0xc0);
   1.557 +      compare ^= 0x45;
   1.558  
   1.559 -		gbCheatList[i].compare = compare;
   1.560 -		gbCheatList[i].code    = 0;
   1.561 -	}
   1.562 +      gbCheatList[i].compare = compare;
   1.563 +      gbCheatList[i].code    = 0;
   1.564 +    }
   1.565  
   1.566 -	gbCheatList[i].enabled = true;
   1.567 +  gbCheatList[i].enabled = true;
   1.568  
   1.569 -	gbCheatMap[gbCheatList[i].address] = true;
   1.570 +  gbCheatMap[gbCheatList[i].address] = true;
   1.571  
   1.572 -	gbCheatNumber++;
   1.573 +  gbCheatNumber++;
   1.574  }
   1.575  
   1.576  void gbCheatRemove(int i)
   1.577  {
   1.578 -	if (i < 0 || i >= gbCheatNumber)
   1.579 -	{
   1.580 -		systemMessage(MSG_INVALID_CHEAT_TO_REMOVE,
   1.581 -		              N_("Invalid cheat to remove %d"), i);
   1.582 -		return;
   1.583 -	}
   1.584 +  if (i < 0 || i >= gbCheatNumber)
   1.585 +    {
   1.586 +      systemMessage(MSG_INVALID_CHEAT_TO_REMOVE,
   1.587 +		    N_("Invalid cheat to remove %d"), i);
   1.588 +      return;
   1.589 +    }
   1.590  
   1.591 -	if ((i+1) <  gbCheatNumber)
   1.592 -	{
   1.593 -		memcpy(&gbCheatList[i], &gbCheatList[i+1], sizeof(gbCheat)*
   1.594 -		       (gbCheatNumber-i-1));
   1.595 -	}
   1.596 +  if ((i+1) <  gbCheatNumber)
   1.597 +    {
   1.598 +      memcpy(&gbCheatList[i], &gbCheatList[i+1], sizeof(gbCheat)*
   1.599 +	     (gbCheatNumber-i-1));
   1.600 +    }
   1.601  
   1.602 -	gbCheatNumber--;
   1.603 +  gbCheatNumber--;
   1.604  
   1.605 -	gbCheatUpdateMap();
   1.606 +  gbCheatUpdateMap();
   1.607  }
   1.608  
   1.609  void gbCheatRemoveAll()
   1.610  {
   1.611 -	gbCheatNumber = 0;
   1.612 -	gbCheatUpdateMap();
   1.613 +  gbCheatNumber = 0;
   1.614 +  gbCheatUpdateMap();
   1.615  }
   1.616  
   1.617  void gbCheatEnable(int i)
   1.618  {
   1.619 -	if (i >= 0 && i < gbCheatNumber)
   1.620 +  if (i >= 0 && i < gbCheatNumber)
   1.621 +    {
   1.622 +      if (!gbCheatList[i].enabled)
   1.623  	{
   1.624 -		if (!gbCheatList[i].enabled)
   1.625 -		{
   1.626 -			gbCheatList[i].enabled = true;
   1.627 -			gbCheatUpdateMap();
   1.628 -		}
   1.629 +	  gbCheatList[i].enabled = true;
   1.630 +	  gbCheatUpdateMap();
   1.631  	}
   1.632 +    }
   1.633  }
   1.634  
   1.635  void gbCheatDisable(int i)
   1.636  {
   1.637 -	if (i >= 0 && i < gbCheatNumber)
   1.638 +  if (i >= 0 && i < gbCheatNumber)
   1.639 +    {
   1.640 +      if (gbCheatList[i].enabled)
   1.641  	{
   1.642 -		if (gbCheatList[i].enabled)
   1.643 -		{
   1.644 -			gbCheatList[i].enabled = false;
   1.645 -			gbCheatUpdateMap();
   1.646 -		}
   1.647 +	  gbCheatList[i].enabled = false;
   1.648 +	  gbCheatUpdateMap();
   1.649  	}
   1.650 +    }
   1.651  }
   1.652  
   1.653  bool gbCheatReadGSCodeFile(const char *fileName)
   1.654  {
   1.655 -	FILE *file = fopen(fileName, "rb");
   1.656 +  FILE *file = fopen(fileName, "rb");
   1.657  
   1.658 -	if (!file)
   1.659 -		return false;
   1.660 +  if (!file)
   1.661 +    return false;
   1.662  
   1.663 -	fseek(file, 0x18, SEEK_SET);
   1.664 -	int count = 0;
   1.665 -	fread(&count, 1, 2, file);
   1.666 -	int dummy = 0;
   1.667 -	gbCheatRemoveAll();
   1.668 -	char desc[13];
   1.669 -	char code[9];
   1.670 -	int  i;
   1.671 -	for (i = 0; i < count; i++)
   1.672 -	{
   1.673 -		fread(&dummy, 1, 2, file);
   1.674 -		fread(desc, 1, 12, file);
   1.675 -		desc[12] = 0;
   1.676 -		fread(code, 1, 8, file);
   1.677 -		code[8] = 0;
   1.678 -		gbAddGsCheat(code, desc);
   1.679 -	}
   1.680 +  fseek(file, 0x18, SEEK_SET);
   1.681 +  int count = 0;
   1.682 +  fread(&count, 1, 2, file);
   1.683 +  int dummy = 0;
   1.684 +  gbCheatRemoveAll();
   1.685 +  char desc[13];
   1.686 +  char code[9];
   1.687 +  int  i;
   1.688 +  for (i = 0; i < count; i++)
   1.689 +    {
   1.690 +      fread(&dummy, 1, 2, file);
   1.691 +      fread(desc, 1, 12, file);
   1.692 +      desc[12] = 0;
   1.693 +      fread(code, 1, 8, file);
   1.694 +      code[8] = 0;
   1.695 +      gbAddGsCheat(code, desc);
   1.696 +    }
   1.697  
   1.698 -	for (i = 0; i < gbCheatNumber; i++)
   1.699 -		gbCheatDisable(i);
   1.700 +  for (i = 0; i < gbCheatNumber; i++)
   1.701 +    gbCheatDisable(i);
   1.702  
   1.703 -	fclose(file);
   1.704 -	return true;
   1.705 +  fclose(file);
   1.706 +  return true;
   1.707  }
   1.708  
   1.709  u8 gbCheatRead(u16 address)
   1.710  {
   1.711 -	if (!cheatsEnabled)
   1.712 -		return gbReadMemoryQuick(address);
   1.713 +  if (!cheatsEnabled)
   1.714 +    return gbReadMemoryQuick(address);
   1.715  
   1.716 -	for (int i = 0; i < gbCheatNumber; i++)
   1.717 +  for (int i = 0; i < gbCheatNumber; i++)
   1.718 +    {
   1.719 +      if (gbCheatList[i].enabled && gbCheatList[i].address == address)
   1.720  	{
   1.721 -		if (gbCheatList[i].enabled && gbCheatList[i].address == address)
   1.722 +	  switch (gbCheatList[i].code)
   1.723 +	    {
   1.724 +	    case 0x100: // GameGenie support
   1.725 +	      if (gbReadMemoryQuick(address) == gbCheatList[i].compare)
   1.726 +		return gbCheatList[i].value;
   1.727 +	      break;
   1.728 +	    case 0x00:
   1.729 +	    case 0x01:
   1.730 +	    case 0x80:
   1.731 +	      return gbCheatList[i].value;
   1.732 +	    case 0x90:
   1.733 +	    case 0x91:
   1.734 +	    case 0x92:
   1.735 +	    case 0x93:
   1.736 +	    case 0x94:
   1.737 +	    case 0x95:
   1.738 +	    case 0x96:
   1.739 +	    case 0x97:
   1.740 +	      if (address >= 0xd000 && address < 0xe000)
   1.741  		{
   1.742 -			switch (gbCheatList[i].code)
   1.743 -			{
   1.744 -			case 0x100: // GameGenie support
   1.745 -				if (gbReadMemoryQuick(address) == gbCheatList[i].compare)
   1.746 -					return gbCheatList[i].value;
   1.747 -				break;
   1.748 -			case 0x00:
   1.749 -			case 0x01:
   1.750 -			case 0x80:
   1.751 -				return gbCheatList[i].value;
   1.752 -			case 0x90:
   1.753 -			case 0x91:
   1.754 -			case 0x92:
   1.755 -			case 0x93:
   1.756 -			case 0x94:
   1.757 -			case 0x95:
   1.758 -			case 0x96:
   1.759 -			case 0x97:
   1.760 -				if (address >= 0xd000 && address < 0xe000)
   1.761 -				{
   1.762 -					if (((gbMemoryMap[0x0d] - gbWram)/0x1000) ==
   1.763 -					    (gbCheatList[i].code - 0x90))
   1.764 -						return gbCheatList[i].value;
   1.765 -				}
   1.766 -				else
   1.767 -					return gbCheatList[i].value;
   1.768 -			}
   1.769 +		  if (((gbMemoryMap[0x0d] - gbWram)/0x1000) ==
   1.770 +		      (gbCheatList[i].code - 0x90))
   1.771 +		    return gbCheatList[i].value;
   1.772  		}
   1.773 +	      else
   1.774 +		return gbCheatList[i].value;
   1.775 +	    }
   1.776  	}
   1.777 -	return gbReadMemoryQuick(address);
   1.778 +    }
   1.779 +  return gbReadMemoryQuick(address);
   1.780  }
   1.781