# HG changeset patch # User Michael Pavone # Date 1459395064 25200 # Node ID a085f17b79e9daa9b4eddec6d60658ebd5dd7340 # Parent 407725d9a02f925976e574700e07ef9c9badef2b Implement hflip diff -r 407725d9a02f -r a085f17b79e9 src/vdp.c --- a/src/vdp.c Wed Mar 30 19:55:48 2016 -0700 +++ b/src/vdp.c Wed Mar 30 20:31:04 2016 -0700 @@ -48,10 +48,11 @@ if (context->draw_counter) { context->draw_counter--; uint16_t pixels = context->vram[context->draw_source++]; - for (int i = 0; i < 4; i++) + for (int i = context->hflip ? 0 : 12; i >= 0 && i < 16; i+= context->hflip ? 4 : -4) { - uint8_t pixel = ((pixels >> ((3-i) * 4)) & 0xF) | context->palpriority; - context->drawbuffer[context->draw_dest++] = pixel; + uint8_t pixel = ((pixels >> i) & 0xF) | context->palpriority; + context->drawbuffer[context->draw_dest ^ (context->hflip << 2)] = pixel; + context->draw_dest++; } } else { //00VV VVVV VVHH HHHH @@ -71,7 +72,7 @@ } context->palpriority = entry >> 9 & 0x70; context->draw_counter = 2; - //TODO: handle horizontal flip + context->hflip = (entry & 0x800) != 0; } if (context->status & VDP_STATUS_SPRITE_SCAN) { context->status |= VDP_STATUS_SRAM; @@ -99,6 +100,10 @@ context->sprite_draws[context->current_draw].x = x + 8; context->sprite_draws[context->current_draw].hflip = (atts & 0x800) != 0; context->sprite_draws[context->current_draw].palpriority = 0x80 | (atts >> 9 & 0x50); + if (context->sprite_draws[context->current_draw].hflip) { + context->sprite_draws[context->current_draw].x -= 8; + context->sprite_draws[context->current_draw-1].x += 8; + } } context->current_draw++; if (context->current_draw == 40) { @@ -119,12 +124,11 @@ context->status |= VDP_STATUS_VRAM; uint16_t pixels = context->vram[draw->source + (context->current_draw & 1)]; uint16_t x = draw->x - 16 + (context->hscroll & 7); - for (int i = 0; i < 4; i++, x++) + for (int i = draw->hflip ? 0 : 12; i >= 0 && i < 16; i+= draw->hflip ? 4 : -4, x++) { - //TODO: handle horizontal flip - uint8_t pixel = (pixels >> ((3-i) * 4)) & 0xF; + uint8_t pixel = (pixels >> i) & 0xF; if (pixel && x < 328 && ((draw->palpriority & 0x40) || !(context->drawbuffer[x] & 0x40))) { - context->drawbuffer[x] = pixel | draw->palpriority; + context->drawbuffer[x ^ (draw->hflip << 2)] = pixel | draw->palpriority; } } if (context->current_draw & 1) { diff -r 407725d9a02f -r a085f17b79e9 src/vdp.h --- a/src/vdp.h Wed Mar 30 19:55:48 2016 -0700 +++ b/src/vdp.h Wed Mar 30 20:31:04 2016 -0700 @@ -39,6 +39,7 @@ uint8_t fifo_dest; uint8_t draw_counter; + uint8_t hflip; uint8_t palpriority; uint8_t current_draw; } vdp;