def draw_sprites
      0.step(SPRITES_COUNT - 1, 4) do |base_sprite_ram_address|
        y_for_sprite = read_from_sprite_ram(base_sprite_ram_address)
        pattern_index = read_from_sprite_ram(base_sprite_ram_address + 1)
        sprite_attribute_byte = read_from_sprite_ram(base_sprite_ram_address + 2)
        x_for_sprite = read_from_sprite_ram(base_sprite_ram_address + 3)

        palette_id = sprite_attribute_byte & 0b11
        reversed_horizontally = sprite_attribute_byte[6] == 1
        reversed_vertically = sprite_attribute_byte[7] == 1

        TILE_HEIGHT.times do |y_in_pattern|
          pattern_line_low_byte_address = TILE_HEIGHT * 2 * pattern_index + y_in_pattern
          pattern_line_low_byte = read_sprite_pattern_line(pattern_line_low_byte_address)
          pattern_line_high_byte = read_sprite_pattern_line(pattern_line_low_byte_address + TILE_HEIGHT)
          TILE_WIDTH.times do |x_in_pattern|
            index_in_pattern_line_byte = TILE_WIDTH - 1 - x_in_pattern
            sprite_palette_index = pattern_line_low_byte[index_in_pattern_line_byte] | (pattern_line_high_byte[index_in_pattern_line_byte] << 1) | (palette_id << 2)
            if sprite_palette_index % 4 != 0
              color_id = read_color_id(sprite_palette_index)
              y_in_pattern = TILE_HEIGHT - 1 - y_in_pattern if reversed_vertically
              x_in_pattern = TILE_WIDTH - 1 - x_in_pattern if reversed_horizontally
              @image.write(
                value: ::Rnes::Ppu::COLORS[color_id],
                x: x_for_sprite + x_in_pattern,
                y: y_for_sprite + y_in_pattern,
              )
            end
          end
        end
      end
    end
def draw_sprites
      0.step(SPRITES_COUNT - 1, 4) do |base_sprite_ram_address|
        y_for_sprite = read_from_sprite_ram(base_sprite_ram_address)
        pattern_index = read_from_sprite_ram(base_sprite_ram_address + 1)
        sprite_attribute_byte = read_from_sprite_ram(base_sprite_ram_address + 2)
        x_for_sprite = read_from_sprite_ram(base_sprite_ram_address + 3)

        palette_id = sprite_attribute_byte & 0b11
        reversed_horizontally = sprite_attribute_byte[6] == 1
        reversed_vertically = sprite_attribute_byte[7] == 1

        TILE_HEIGHT.times do |y_in_pattern|
          pattern_line_low_byte_address = TILE_HEIGHT * 2 * pattern_index + y_in_pattern
          pattern_line_low_byte = read_sprite_pattern_line(pattern_line_low_byte_address)
          pattern_line_high_byte = read_sprite_pattern_line(pattern_line_low_byte_address + TILE_HEIGHT)
          TILE_WIDTH.times do |x_in_pattern|
            index_in_pattern_line_byte = TILE_WIDTH - 1 - x_in_pattern
            sprite_palette_index = pattern_line_low_byte[index_in_pattern_line_byte] | (pattern_line_high_byte[index_in_pattern_line_byte] << 1) | (palette_id << 2)
            if sprite_palette_index % 4 != 0
              color_id = read_color_id(sprite_palette_index)
              y_in_pattern = TILE_HEIGHT - 1 - y_in_pattern if reversed_vertically
              x_in_pattern = TILE_WIDTH - 1 - x_in_pattern if reversed_horizontally
              @image.write(
                value: ::Rnes::Ppu::COLORS[color_id],
                x: x_for_sprite + x_in_pattern,
                y: y_for_sprite + y_in_pattern,
              )
            end
          end
        end
      end
    end
@note
   struct Sprite {
     U8 y;
     U8 tile;
     U8 attr;
     U8 x;
   }

 attr 76543210
      |||   `+- palette
      ||`------ priority (0: front, 1: back)
      |`------- horizontal flip
      `-------- vertical flip