Mercurial > repos > simple16
comparison src/vdp.c @ 23:a085f17b79e9
Implement hflip
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 30 Mar 2016 20:31:04 -0700 |
parents | 407725d9a02f |
children | 083347ccd508 |
comparison
equal
deleted
inserted
replaced
22:407725d9a02f | 23:a085f17b79e9 |
---|---|
46 context->current_draw = 0; | 46 context->current_draw = 0; |
47 } | 47 } |
48 if (context->draw_counter) { | 48 if (context->draw_counter) { |
49 context->draw_counter--; | 49 context->draw_counter--; |
50 uint16_t pixels = context->vram[context->draw_source++]; | 50 uint16_t pixels = context->vram[context->draw_source++]; |
51 for (int i = 0; i < 4; i++) | 51 for (int i = context->hflip ? 0 : 12; i >= 0 && i < 16; i+= context->hflip ? 4 : -4) |
52 { | 52 { |
53 uint8_t pixel = ((pixels >> ((3-i) * 4)) & 0xF) | context->palpriority; | 53 uint8_t pixel = ((pixels >> i) & 0xF) | context->palpriority; |
54 context->drawbuffer[context->draw_dest++] = pixel; | 54 context->drawbuffer[context->draw_dest ^ (context->hflip << 2)] = pixel; |
55 context->draw_dest++; | |
55 } | 56 } |
56 } else { | 57 } else { |
57 //00VV VVVV VVHH HHHH | 58 //00VV VVVV VVHH HHHH |
58 uint16_t vpos = (context->vscroll & 0x7FF) + context->vcounter - 16; | 59 uint16_t vpos = (context->vscroll & 0x7FF) + context->vcounter - 16; |
59 uint16_t vmask = (context->vscroll >> 2) & 0x3E00; | 60 uint16_t vmask = (context->vscroll >> 2) & 0x3E00; |
69 } else { | 70 } else { |
70 context->draw_source += vfine * 2; | 71 context->draw_source += vfine * 2; |
71 } | 72 } |
72 context->palpriority = entry >> 9 & 0x70; | 73 context->palpriority = entry >> 9 & 0x70; |
73 context->draw_counter = 2; | 74 context->draw_counter = 2; |
74 //TODO: handle horizontal flip | 75 context->hflip = (entry & 0x800) != 0; |
75 } | 76 } |
76 if (context->status & VDP_STATUS_SPRITE_SCAN) { | 77 if (context->status & VDP_STATUS_SPRITE_SCAN) { |
77 context->status |= VDP_STATUS_SRAM; | 78 context->status |= VDP_STATUS_SRAM; |
78 uint16_t pos = context->sram[context->hcounter]; | 79 uint16_t pos = context->sram[context->hcounter]; |
79 uint16_t y = pos & 0xFF; | 80 uint16_t y = pos & 0xFF; |
97 if (size == 16) { | 98 if (size == 16) { |
98 context->sprite_draws[context->current_draw].source = address + 32; | 99 context->sprite_draws[context->current_draw].source = address + 32; |
99 context->sprite_draws[context->current_draw].x = x + 8; | 100 context->sprite_draws[context->current_draw].x = x + 8; |
100 context->sprite_draws[context->current_draw].hflip = (atts & 0x800) != 0; | 101 context->sprite_draws[context->current_draw].hflip = (atts & 0x800) != 0; |
101 context->sprite_draws[context->current_draw].palpriority = 0x80 | (atts >> 9 & 0x50); | 102 context->sprite_draws[context->current_draw].palpriority = 0x80 | (atts >> 9 & 0x50); |
103 if (context->sprite_draws[context->current_draw].hflip) { | |
104 context->sprite_draws[context->current_draw].x -= 8; | |
105 context->sprite_draws[context->current_draw-1].x += 8; | |
106 } | |
102 } | 107 } |
103 context->current_draw++; | 108 context->current_draw++; |
104 if (context->current_draw == 40) { | 109 if (context->current_draw == 40) { |
105 //no more rendering capacity | 110 //no more rendering capacity |
106 context->status &= ~VDP_STATUS_SPRITE_SCAN; | 111 context->status &= ~VDP_STATUS_SPRITE_SCAN; |
117 sprite_draw *draw = context->sprite_draws + (context->current_draw >> 1); | 122 sprite_draw *draw = context->sprite_draws + (context->current_draw >> 1); |
118 if (draw->palpriority) { | 123 if (draw->palpriority) { |
119 context->status |= VDP_STATUS_VRAM; | 124 context->status |= VDP_STATUS_VRAM; |
120 uint16_t pixels = context->vram[draw->source + (context->current_draw & 1)]; | 125 uint16_t pixels = context->vram[draw->source + (context->current_draw & 1)]; |
121 uint16_t x = draw->x - 16 + (context->hscroll & 7); | 126 uint16_t x = draw->x - 16 + (context->hscroll & 7); |
122 for (int i = 0; i < 4; i++, x++) | 127 for (int i = draw->hflip ? 0 : 12; i >= 0 && i < 16; i+= draw->hflip ? 4 : -4, x++) |
123 { | 128 { |
124 //TODO: handle horizontal flip | 129 uint8_t pixel = (pixels >> i) & 0xF; |
125 uint8_t pixel = (pixels >> ((3-i) * 4)) & 0xF; | |
126 if (pixel && x < 328 && ((draw->palpriority & 0x40) || !(context->drawbuffer[x] & 0x40))) { | 130 if (pixel && x < 328 && ((draw->palpriority & 0x40) || !(context->drawbuffer[x] & 0x40))) { |
127 context->drawbuffer[x] = pixel | draw->palpriority; | 131 context->drawbuffer[x ^ (draw->hflip << 2)] = pixel | draw->palpriority; |
128 } | 132 } |
129 } | 133 } |
130 if (context->current_draw & 1) { | 134 if (context->current_draw & 1) { |
131 draw->palpriority = 0; | 135 draw->palpriority = 0; |
132 } else { | 136 } else { |