public void drawSprites(Graphics back, int priority) {

		int tileBankStart = 0;
		int vidRamAddress = 0;

		// Draw sprites
		for (int i = tileBankStart; i < 40; i++) {
			int spriteX = dmgcpu.addressRead(0xFE01 + (i * 4)) - 8;
			int spriteY = dmgcpu.addressRead(0xFE00 + (i * 4)) - 16;
			int tileNum = dmgcpu.addressRead(0xFE02 + (i * 4));
			int attributes = dmgcpu.addressRead(0xFE03 + (i * 4));

			if ((attributes & 0x80) >> 7 == priority) {

				int spriteAttrib = 0;

				if (doubledSprites) {
					tileNum &= 0xFE;
				}

				if (dmgcpu.isGbcFeatures()) {
					if ((attributes & 0x08) != 0) {
						vidRamAddress = 0x2000 + (tileNum << 4);
						tileNum += 384;
						tileBankStart = 0x2000;
					} else {
						vidRamAddress = tileNum << 4;
					}
					spriteAttrib += ((attributes & 0x07) << 2) + 32;

				} else {
					vidRamAddress = tileNum << 4;
					if ((attributes & 0x10) != 0) {
						spriteAttrib |= TILE_OBJ2;
					} else {
						spriteAttrib |= TILE_OBJ1;
					}
				}

				if ((attributes & 0x20) != 0) {
					spriteAttrib |= TILE_FLIPX;
				}
				if ((attributes & 0x40) != 0) {
					spriteAttrib |= TILE_FLIPY;
				}

				if (tiles[tileNum].invalid(spriteAttrib)) {
					tiles[tileNum].validate(videoRam, vidRamAddress, spriteAttrib);
				}

				if ((spriteAttrib & TILE_FLIPY) != 0) {
					if (doubledSprites) {
						tiles[tileNum].draw(back, spriteX, spriteY + 8, spriteAttrib);
					} else {
						tiles[tileNum].draw(back, spriteX, spriteY, spriteAttrib);
					}
				} else {
					tiles[tileNum].draw(back, spriteX, spriteY, spriteAttrib);
				}

				//   back.drawString("" + tileNum, spriteX * 2, spriteY * 2);
				//   System.out.println("Sprite " + i + ": " + spriteX + ", " + spriteY);

				if (doubledSprites) {
					if (tiles[tileNum + 1].invalid(spriteAttrib)) {
						tiles[tileNum + 1].validate(videoRam, vidRamAddress + 16, spriteAttrib);
					}


					if ((spriteAttrib & TILE_FLIPY) != 0) {
						tiles[tileNum + 1].draw(back, spriteX, spriteY, spriteAttrib);
					} else {
						tiles[tileNum + 1].draw(back, spriteX, spriteY + 8, spriteAttrib);
					}
				}
			}
		}

	}