Mercurial > repos > simple16
changeset 23:a085f17b79e9
Implement hflip
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 30 Mar 2016 20:31:04 -0700 |
parents | 407725d9a02f |
children | 4c9dbfa30a66 |
files | src/vdp.c src/vdp.h |
diffstat | 2 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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) {