for (int i = 0; i<4; i++)
int i; for (i = 0; i<4; i++)
int cheatsCheckKeys(u32 keys, u32 extended){	bool onoff = true;  int ticks = 0;  for (int i = 0; i<4; i++)	  if (rompatch2addr [i] != 0){		  CHEAT_PATCH_ROM_16BIT(rompatch2addr [i],rompatch2oldval [i]);		  rompatch2addr [i] = 0;	  }  for(i = 0; i < cheatsNumber; i++) {    if(!cheatsList[i].enabled) {      // make sure we skip other lines in this code      i += getCodeLength(i)-1;      continue;    }    switch(cheatsList[i].size) {	case GSA_CODES_ON:		onoff = true;	break;    case GSA_SLOWDOWN:      // check if button was pressed and released, if so toggle our state      if((cheatsList[i].status & 4) && !(extended & 4))        cheatsList[i].status ^= 1;      if(extended & 4)        cheatsList[i].status |= 4;      else        cheatsList[i].status &= ~4;            if(cheatsList[i].status & 1)        ticks += 2*256*((cheatsList[i].value >> 8) & 255);      break;    case GSA_8_BIT_SLIDE:      i++;      if(i < cheatsNumber) {        u32 addr = cheatsList[i-1].value;        u8 value = cheatsList[i].address;        int vinc = (cheatsList[i].value >> 24) & 255;        int count = (cheatsList[i].value >> 16) & 255;        int ainc = (cheatsList[i].value & 0xffff);        while(count > 0) {          CPUWriteByte(addr, value);          value += vinc;          addr += ainc;          count--;        }      }      break;    case GSA_16_BIT_SLIDE:      i++;      if(i < cheatsNumber) {        u32 addr = cheatsList[i-1].value;        u16 value = cheatsList[i].address;        int vinc = (cheatsList[i].value >> 24) & 255;        int count = (cheatsList[i].value >> 16) & 255;        int ainc = (cheatsList[i].value & 0xffff)*2;        while(count > 0) {          CPUWriteHalfWord(addr, value);          value += vinc;          addr += ainc;          count--;        }      }      break;    case GSA_32_BIT_SLIDE:      i++;      if(i < cheatsNumber) {        u32 addr = cheatsList[i-1].value;        u32 value = cheatsList[i].address;        int vinc = (cheatsList[i].value >> 24) & 255;        int count = (cheatsList[i].value >> 16) & 255;        int ainc = (cheatsList[i].value & 0xffff)*4;        while(count > 0) {          CPUWriteMemory(addr, value);          value += vinc;          addr += ainc;          count--;        }      }break;    case GSA_8_BIT_GS_WRITE2:      i++;      if(i < cheatsNumber) {        if(extended & 4) {          CPUWriteByte(cheatsList[i-1].value, cheatsList[i].address);        }      }      break;    case GSA_16_BIT_GS_WRITE2:      i++;      if(i < cheatsNumber) {        if(extended & 4) {          CPUWriteHalfWord(cheatsList[i-1].value, cheatsList[i].address);        }      }      break;    case GSA_32_BIT_GS_WRITE2:      i++;      if(i < cheatsNumber) {        if(extended & 4) {          CPUWriteMemory(cheatsList[i-1].value, cheatsList[i].address);        }      }      break;    case GSA_16_BIT_ROM_PATCH2C:      i++;      if((i < cheatsNumber) && (cheatsList[i].status & 1) == 0) {		  rompatch2addr [0] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000;		  rompatch2oldval [0] = CPUReadHalfWord(rompatch2addr [0]);		  rompatch2val [0] = cheatsList[i].address & 0xFFFF;      }      break;    case GSA_16_BIT_ROM_PATCH2D:      i++;      if((i < cheatsNumber) && (cheatsList[i].status & 1) == 0) {		  rompatch2addr [1] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000;		  rompatch2oldval [1] = CPUReadHalfWord(rompatch2addr [1]);		  rompatch2val [1] = cheatsList[i].address & 0xFFFF;      }      break;    case GSA_16_BIT_ROM_PATCH2E:      i++;      if((i < cheatsNumber) && (cheatsList[i].status & 1) == 0) {		  rompatch2addr [2] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000;		  rompatch2oldval [2] = CPUReadHalfWord(rompatch2addr [2]);		  rompatch2val [2] = cheatsList[i].address & 0xFFFF;      }      break;    case GSA_16_BIT_ROM_PATCH2F:      i++;      if((i < cheatsNumber) && (cheatsList[i].status & 1) == 0) {		  rompatch2addr [3] = ((cheatsList[i-1].value & 0x00FFFFFF) << 1) + 0x8000000;		  rompatch2oldval [3] = CPUReadHalfWord(rompatch2addr [3]);		  rompatch2val [3] = cheatsList[i].address & 0xFFFF;      }      break;	  }		if (onoff) {			switch(cheatsList[i].size) {    case INT_8_BIT_WRITE:      CPUWriteByte(cheatsList[i].address, cheatsList[i].value);      break;    case INT_16_BIT_WRITE:      CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value);      break;    case INT_32_BIT_WRITE:      CPUWriteMemory(cheatsList[i].address, cheatsList[i].value);      break;    case GSA_16_BIT_ROM_PATCH:      if((cheatsList[i].status & 1) == 0) {        if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) {          cheatsList[i].oldValue = CPUReadHalfWord(cheatsList[i].address);          cheatsList[i].status |= 1;          CHEAT_PATCH_ROM_16BIT(cheatsList[i].address, cheatsList[i].value);        }      }      break;    case GSA_8_BIT_GS_WRITE:      if(extended & 4) {        CPUWriteByte(cheatsList[i].address, cheatsList[i].value);      }      break;    case GSA_16_BIT_GS_WRITE:      if(extended & 4) {        CPUWriteHalfWord(cheatsList[i].address, cheatsList[i].value);         }      break;    case GSA_32_BIT_GS_WRITE:      if(extended & 4) {        CPUWriteMemory(cheatsList[i].address, cheatsList[i].value);           }      break;    case CBA_IF_KEYS_PRESSED:      {        u16 value = cheatsList[i].value;        u32 addr = cheatsList[i].address;        if((addr & 0x30) == 0x20) {          if((keys & value) != value) {            i++;          }        } else if((addr & 0x30) == 0x10) {          if((keys & value) == value) {            i++;          }        }      }      break;    case CBA_IF_TRUE:      if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) {        i++;      }      break;    case CBA_SLIDE_CODE:      {        u32 address = cheatsList[i].address;        u16 value = cheatsList[i].value;        i++;        if(i < cheatsNumber) {          int count = (cheatsList[i].address & 0xFFFF);          u16 vinc = (cheatsList[i].address >> 16) & 0xFFFF;          int inc = cheatsList[i].value;          for(int x = 0; x < count; x++) {            CPUWriteHalfWord(address, value);            address += inc;            value += vinc;          }        }      }      break;    case CBA_IF_FALSE:      if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) {        i++;      }      break;    case CBA_AND:      CPUWriteHalfWord(cheatsList[i].address,                       CPUReadHalfWord(cheatsList[i].address) &                       cheatsList[i].value);      break;    case GSA_8_BIT_IF_TRUE:      if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) {        i++;      }      break;    case GSA_32_BIT_IF_TRUE:      if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) {        i++;      }      break;    case GSA_8_BIT_IF_FALSE:      if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) {        i++;      }      break;    case GSA_32_BIT_IF_FALSE:      if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) {        i++;      }      break;    case GSA_8_BIT_FILL:      {        u32 addr = cheatsList[i].address;        u8 v = cheatsList[i].value & 0xff;        u32 end = addr + (cheatsList[i].value >> 8);        do {          CPUWriteByte(addr, v);          addr++;        } while (addr <= end);      }      break;    case GSA_16_BIT_FILL:      {        u32 addr = cheatsList[i].address;        u16 v = cheatsList[i].value & 0xffff;        u32 end = addr + ((cheatsList[i].value >> 16) << 1);        do {          CPUWriteHalfWord(addr, v);          addr+=2;        } while (addr <= end);      }      break;    case GSA_8_BIT_IF_TRUE2:      if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) {        i+=2;      }      break;    case GSA_16_BIT_IF_TRUE2:      if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) {        i+=2;      }      break;    case GSA_32_BIT_IF_TRUE2:      if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) {        i+=2;      }      break;    case GSA_8_BIT_IF_FALSE2:      if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) {        i+=2;      }      break;    case GSA_16_BIT_IF_FALSE2:      if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) {        i+=2;      }      break;    case GSA_32_BIT_IF_FALSE2:      if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) {        i+=2;      }      break;    case CBA_ADD:      CPUWriteHalfWord(cheatsList[i].address,                        CPUReadHalfWord(cheatsList[i].address) +                       (u16)cheatsList[i].value);      break;    case CBA_OR:      CPUWriteHalfWord(cheatsList[i].address,                       CPUReadHalfWord(cheatsList[i].address) |                       cheatsList[i].value);      break;    case CBA_LT:      if(CPUReadHalfWord(cheatsList[i].address) >= cheatsList[i].value)        i++;      break;    case CBA_GT:      if(CPUReadHalfWord(cheatsList[i].address) <= cheatsList[i].value)        i++;      break;    case CBA_SUPER:      {        int count = 2*cheatsList[i].value;        u32 address = cheatsList[i].address;        for(int x = 0; x < count; x++) {          u8 b;          int res = x % 6;          if(res < 4)            b = (cheatsList[i].address >> (24-8*res)) & 0xFF;          else            b = (cheatsList[i].value >> (8 - 8*(res-4))) & 0x0FF;          CPUWriteByte(address, b);          address++;          if(x && !res)            i++;        }        if(count % 6)          i++;      }      break;    case GSA_8_BIT_POINTER :		if ((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000) ||			(CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000))		{      CPUWriteByte(CPUReadMemory(cheatsList[i].address)+((cheatsList[i].value & 0xFFFFFF00) >> 8),						(cheatsList[i].value & 0xFF));		}      break;    case GSA_16_BIT_POINTER :		if ((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000) ||			(CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000))		{      CPUWriteHalfWord(CPUReadMemory(cheatsList[i].address)+((cheatsList[i].value & 0xFFFF0000) >> 15),						(cheatsList[i].value & 0xFFFF));		}		break;    case GSA_32_BIT_POINTER :		if ((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000) ||			(CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000))		{      CPUWriteMemory(CPUReadMemory(cheatsList[i].address),						cheatsList[i].value);		}		break;    case GSA_8_BIT_ADD :		{      CPUWriteByte(cheatsList[i].address ,				  (cheatsList[i].value & 0xFF) + CPUReadMemory(cheatsList[i].address) & 0xFF);		}      break;    case GSA_16_BIT_ADD :		{      CPUWriteHalfWord(cheatsList[i].address ,				  (cheatsList[i].value & 0xFFFF) + CPUReadMemory(cheatsList[i].address) & 0xFFFF);		}		break;    case GSA_32_BIT_ADD :		{      CPUWriteMemory(cheatsList[i].address ,				  cheatsList[i].value + CPUReadMemory(cheatsList[i].address) & 0xFFFFFFFF);		}		break;    case GSA_8_BIT_IF_LOWER_U:      if (!(CPUReadByte(cheatsList[i].address) < (cheatsList[i].value & 0xFF))) {        i++;      }      break;    case GSA_16_BIT_IF_LOWER_U:      if (!(CPUReadHalfWord(cheatsList[i].address) < (cheatsList[i].value & 0xFFFF))) {        i++;      }      break;    case GSA_32_BIT_IF_LOWER_U:      if (!(CPUReadMemory(cheatsList[i].address) < cheatsList[i].value)) {        i++;      }      break;    case GSA_8_BIT_IF_HIGHER_U:      if (!(CPUReadByte(cheatsList[i].address) > (cheatsList[i].value & 0xFF))) {        i++;      }      break;    case GSA_16_BIT_IF_HIGHER_U:      if (!(CPUReadHalfWord(cheatsList[i].address) > (cheatsList[i].value & 0xFFFF))) {        i++;      }      break;    case GSA_32_BIT_IF_HIGHER_U:      if (!(CPUReadMemory(cheatsList[i].address) > cheatsList[i].value)) {        i++;      }      break;    case GSA_8_BIT_IF_AND:      if (!(CPUReadByte(cheatsList[i].address) & (cheatsList[i].value & 0xFF))) {        i++;      }      break;    case GSA_16_BIT_IF_AND:      if (!(CPUReadHalfWord(cheatsList[i].address) & (cheatsList[i].value & 0xFFFF))) {        i++;      }      break;    case GSA_32_BIT_IF_AND:      if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) {        i++;      }      break;    case GSA_8_BIT_IF_LOWER_U2:      if (!(CPUReadByte(cheatsList[i].address) < (cheatsList[i].value & 0xFF))) {        i+=2;      }      break;    case GSA_16_BIT_IF_LOWER_U2:      if (!(CPUReadHalfWord(cheatsList[i].address) < (cheatsList[i].value & 0xFFFF))) {        i+=2;      }      break;    case GSA_32_BIT_IF_LOWER_U2:      if (!(CPUReadMemory(cheatsList[i].address) < cheatsList[i].value)) {        i+=2;      }      break;    case GSA_8_BIT_IF_HIGHER_U2:      if (!(CPUReadByte(cheatsList[i].address) > (cheatsList[i].value & 0xFF))) {        i+=2;      }      break;    case GSA_16_BIT_IF_HIGHER_U2:      if (!(CPUReadHalfWord(cheatsList[i].address) > (cheatsList[i].value & 0xFFFF))) {        i+=2;      }      break;    case GSA_32_BIT_IF_HIGHER_U2:      if (!(CPUReadMemory(cheatsList[i].address) > cheatsList[i].value)) {        i+=2;      }      break;    case GSA_8_BIT_IF_AND2:      if (!(CPUReadByte(cheatsList[i].address) & (cheatsList[i].value & 0xFF))) {        i+=2;      }      break;    case GSA_16_BIT_IF_AND2:      if (!(CPUReadHalfWord(cheatsList[i].address) & (cheatsList[i].value & 0xFFFF))) {        i+=2;      }      break;    case GSA_32_BIT_IF_AND2:      if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) {        i+=2;      }      break;    case GSA_ALWAYS:		{        i++;		}      break;    case GSA_ALWAYS2:		{        i+=2;		}      break;    case GSA_8_BIT_IF_LOWER_S:      if (!((s8)CPUReadByte(cheatsList[i].address) < ((s8)cheatsList[i].value & 0xFF))) {        i++;      }      break;    case GSA_16_BIT_IF_LOWER_S:      if (!((s16)CPUReadHalfWord(cheatsList[i].address) < ((s16)cheatsList[i].value & 0xFFFF))) {        i++;      }      break;    case GSA_32_BIT_IF_LOWER_S:      if (!((s32)CPUReadMemory(cheatsList[i].address) < (s32)cheatsList[i].value)) {        i++;      }      break;    case GSA_8_BIT_IF_HIGHER_S:      if (!((s8)CPUReadByte(cheatsList[i].address) > ((s8)cheatsList[i].value & 0xFF))) {        i++;      }      break;    case GSA_16_BIT_IF_HIGHER_S:      if (!((s16)CPUReadHalfWord(cheatsList[i].address) > ((s16)cheatsList[i].value & 0xFFFF))) {        i++;      }      break;    case GSA_32_BIT_IF_HIGHER_S:      if (!((s32)CPUReadMemory(cheatsList[i].address) > (s32)cheatsList[i].value)) {        i++;      }      break;    case GSA_8_BIT_IF_LOWER_S2:      if (!((s8)CPUReadByte(cheatsList[i].address) < ((s8)cheatsList[i].value & 0xFF))) {        i+=2;      }      break;    case GSA_16_BIT_IF_LOWER_S2:      if (!((s16)CPUReadHalfWord(cheatsList[i].address) < ((s16)cheatsList[i].value & 0xFFFF))) {        i+=2;      }      break;    case GSA_32_BIT_IF_LOWER_S2:      if (!((s32)CPUReadMemory(cheatsList[i].address) < (s32)cheatsList[i].value)) {        i+=2;      }      break;    case GSA_8_BIT_IF_HIGHER_S2:      if (!((s8)CPUReadByte(cheatsList[i].address) > ((s8)cheatsList[i].value & 0xFF))) {        i+=2;      }      break;    case GSA_16_BIT_IF_HIGHER_S2:      if (!((s16)CPUReadHalfWord(cheatsList[i].address) > ((s16)cheatsList[i].value & 0xFFFF))) {        i+=2;      }      break;    case GSA_32_BIT_IF_HIGHER_S2:      if (!((s32)CPUReadMemory(cheatsList[i].address) > (s32)cheatsList[i].value)) {        i+=2;      }      break;    case GSA_16_BIT_WRITE_IOREGS:		if ((cheatsList[i].address <= 0x3FF) && (cheatsList[i].address != 0x6) && (cheatsList[i].address != 0x130))       ioMem[cheatsList[i].address & 0x3FE]=cheatsList[i].value & 0xFFFF;      break;    case GSA_32_BIT_WRITE_IOREGS:		if (cheatsList[i].address<=0x3FF)  		{			if (((cheatsList[i].address & 0x3FC) != 0x6) && ((cheatsList[i].address & 0x3FC) != 0x130))				ioMem[cheatsList[i].address & 0x3FC]= (cheatsList[i].value & 0xFFFF);			if ((((cheatsList[i].address & 0x3FC)+2) != 0x6) && ((cheatsList[i].address & 0x3FC) +2) != 0x130)				ioMem[(cheatsList[i].address & 0x3FC) + 2 ]= ((cheatsList[i].value>>16 ) & 0xFFFF);		}      break;    case GSA_8_BIT_IF_TRUE3:      if(CPUReadByte(cheatsList[i].address) != cheatsList[i].value) {        onoff=false;      }      break;    case GSA_16_BIT_IF_TRUE3:      if(CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) {        onoff=false;      }      break;    case GSA_32_BIT_IF_TRUE3:      if(CPUReadMemory(cheatsList[i].address) != cheatsList[i].value) {        onoff=false;      }      break;    case GSA_8_BIT_IF_FALSE3:      if(CPUReadByte(cheatsList[i].address) == cheatsList[i].value) {        onoff=false;      }      break;    case GSA_16_BIT_IF_FALSE3:      if(CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) {        onoff=false;      }      break;    case GSA_32_BIT_IF_FALSE3:      if(CPUReadMemory(cheatsList[i].address) == cheatsList[i].value) {        onoff=false;      }      break;    case GSA_8_BIT_IF_LOWER_S3:      if (!((s8)CPUReadByte(cheatsList[i].address) < ((s8)cheatsList[i].value & 0xFF))) {        onoff=false;      }      break;    case GSA_16_BIT_IF_LOWER_S3:      if (!((s16)CPUReadHalfWord(cheatsList[i].address) < ((s16)cheatsList[i].value & 0xFFFF))) {        onoff=false;      }      break;    case GSA_32_BIT_IF_LOWER_S3:      if (!((s32)CPUReadMemory(cheatsList[i].address) < (s32)cheatsList[i].value)) {        onoff=false;      }      break;    case GSA_8_BIT_IF_HIGHER_S3:      if (!((s8)CPUReadByte(cheatsList[i].address) > ((s8)cheatsList[i].value & 0xFF))) {        onoff=false;      }      break;    case GSA_16_BIT_IF_HIGHER_S3:      if (!((s16)CPUReadHalfWord(cheatsList[i].address) > ((s16)cheatsList[i].value & 0xFFFF))) {        onoff=false;      }      break;    case GSA_32_BIT_IF_HIGHER_S3:      if (!((s32)CPUReadMemory(cheatsList[i].address) > (s32)cheatsList[i].value)) {        onoff=false;      }      break;    case GSA_8_BIT_IF_LOWER_U3:      if (!(CPUReadByte(cheatsList[i].address) < (cheatsList[i].value & 0xFF))) {        onoff=false;      }      break;    case GSA_16_BIT_IF_LOWER_U3:      if (!(CPUReadHalfWord(cheatsList[i].address) < (cheatsList[i].value & 0xFFFF))) {        onoff=false;      }      break;    case GSA_32_BIT_IF_LOWER_U3:      if (!(CPUReadMemory(cheatsList[i].address) < cheatsList[i].value)) {        onoff=false;      }      break;    case GSA_8_BIT_IF_HIGHER_U3:      if (!(CPUReadByte(cheatsList[i].address) > (cheatsList[i].value & 0xFF))) {        onoff=false;      }      break;    case GSA_16_BIT_IF_HIGHER_U3:      if (!(CPUReadHalfWord(cheatsList[i].address) > (cheatsList[i].value & 0xFFFF))) {        onoff=false;      }      break;    case GSA_32_BIT_IF_HIGHER_U3:      if (!(CPUReadMemory(cheatsList[i].address) > cheatsList[i].value)) {        onoff=false;      }      break;    case GSA_8_BIT_IF_AND3:      if (!(CPUReadByte(cheatsList[i].address) & (cheatsList[i].value & 0xFF))) {        onoff=false;      }      break;    case GSA_16_BIT_IF_AND3:      if (!(CPUReadHalfWord(cheatsList[i].address) & (cheatsList[i].value & 0xFFFF))) {        onoff=false;      }      break;    case GSA_32_BIT_IF_AND3:      if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) {        onoff=false;      }      break;    case GSA_ALWAYS3:      if (!(CPUReadMemory(cheatsList[i].address) & cheatsList[i].value)) {        onoff=false;      }      break;	  }    }  }  for (i = 0; i<4; i++)	  if (rompatch2addr [i] != 0)		  CHEAT_PATCH_ROM_16BIT(rompatch2addr [i],rompatch2val [i]);  return ticks;}