Skip to content

Commit

Permalink
Fix sprite masks
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Aug 19, 2024
1 parent 1616885 commit 71dd491
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
21 changes: 11 additions & 10 deletions platforms/shared/desktop/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,26 +493,27 @@ static void update_debug_sprites(void)
{
HuC6260* huc6260 = geargrafx->GetHuC6260();
HuC6270* huc6270 = geargrafx->GetHuC6270();
HuC6270::HuC6270_State* huc6270_state = huc6270->GetState();
u16* vram = huc6270->GetVRAM();
u16* sat = huc6270->GetSAT();
u16* color_table = huc6260->GetColorTable();

for (int i = 0; i < 64; i++)
{
u16 sprite_data = sat[(i * 4) + 2] & 0x07FF;
u16 sprite_address = sprite_data << 5;
u16 sprite_flags = sat[(i * 4) + 3] & 0xB98F;

int width = k_huc6270_sprite_width[(sprite_flags >> 8) & 0x01];
int height = k_huc6270_sprite_height[(sprite_flags >> 12) & 0x03];
int palette = sprite_flags & 0x0F;
int sprite_offset = i << 2;
u16 flags = sat[sprite_offset + 3] & 0xB98F;
int palette = flags & 0x0F;
int cgx = (flags >> 8) & 0x01;
int cgy = (flags >> 12) & 0x03;
int width = k_huc6270_sprite_width[cgx];
int height = k_huc6270_sprite_height[cgy];
u16 pattern = (sat[sprite_offset + 2] >> 1) & 0x3FF;
pattern &= k_huc6270_sprite_mask_width[cgx];
pattern &= k_huc6270_sprite_mask_height[cgy];
u16 sprite_address = pattern << 6;

emu_debug_sprite_widths[i] = width;
emu_debug_sprite_heights[i] = height;

int total_tiles_x = width >> 4;

for (int y = 0; y < height; y++)
{
int tile_y = y >> 4;
Expand Down
15 changes: 9 additions & 6 deletions src/huc6270.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ void HuC6270::FetchSprites()
int sprite_offset = i << 2;
int sprite_y = (m_sat[sprite_offset + 0] & 0x3FF) - 64;
u16 flags = m_sat[sprite_offset + 3];
u16 height = k_huc6270_sprite_height[(flags >> 12) & 0x03];
int cgy = (flags >> 12) & 0x03;
u16 height = k_huc6270_sprite_height[cgy];

if ((sprite_y <= m_raster_line) && ((sprite_y + height) > m_raster_line))
{
Expand All @@ -466,19 +467,21 @@ void HuC6270::FetchSprites()
break;
}

int cgx = (flags >> 8) & 0x01;
u16 width = k_huc6270_sprite_width[cgx];
u16 sprite_x = m_sat[sprite_offset + 1] & 0x3FF;
u16 pattern = m_sat[sprite_offset + 2] & 0x3FF;
u16 sprite_address = pattern << 5;
u16 pattern = (m_sat[sprite_offset + 2] >> 1) & 0x3FF;
pattern &= k_huc6270_sprite_mask_width[cgx];
pattern &= k_huc6270_sprite_mask_height[cgy];
u16 sprite_address = pattern << 6;
u16 palette = (flags & 0x0F) << 4;
u16 width = k_huc6270_sprite_width[(flags >> 8) & 0x01];
int total_tiles_x = width >> 4;
bool x_flip = (flags & 0x0800);

if(flags & 0x8000)
y = height - 1 - y;

int tile_y = y >> 4;
int tile_line_offset = tile_y * 2 * 64;
int tile_line_offset = tile_y * 128;
int offset_y = y & 0xF;

if (width == 16)
Expand Down
2 changes: 2 additions & 0 deletions src/huc6270.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ static const int k_huc6270_screen_size_y_pixels[8] = { 32 * 8, 32 * 8, 32 * 8, 3
static const int k_huc6270_read_write_increment[4] = { 0x01, 0x20, 0x40, 0x80 };
static const int k_huc6270_sprite_width[2] = { 16, 32 };
static const int k_huc6270_sprite_height[4] = { 16, 32, 64, 64 };
static const int k_huc6270_sprite_mask_width[2] = { 0xFFFF, 0xFFFE };
static const int k_huc6270_sprite_mask_height[4] = { 0xFFFF, 0xFFFD, 0xFFF9, 0xFFF9 };

static const char* const k_register_names_aligned[20] = {
"MAWR ", "MARR ", "VWR ", "??? ", "??? ",
Expand Down

0 comments on commit 71dd491

Please sign in to comment.