Mercurial > repos > blastem
comparison cd_graphics.c @ 2416:a1afe26a8ef0
Fix mask for CD graphics destination horizontal offset
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 15 Jan 2024 17:30:40 -0800 |
parents | 3ef80963c2a7 |
children | da2e06c42d16 |
comparison
equal
deleted
inserted
replaced
2415:23052186705a | 2416:a1afe26a8ef0 |
---|---|
118 }; | 118 }; |
119 | 119 |
120 void draw_pixels(segacd_context *cd) | 120 void draw_pixels(segacd_context *cd) |
121 { | 121 { |
122 uint16_t to_draw = 4 - (cd->graphics_dst_x & 3); | 122 uint16_t to_draw = 4 - (cd->graphics_dst_x & 3); |
123 uint16_t x_end = cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3); | 123 uint16_t x_end = cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7); |
124 if (cd->graphics_dst_x + to_draw > x_end) { | 124 if (cd->graphics_dst_x + to_draw > x_end) { |
125 to_draw = cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3) - cd->graphics_dst_x; | 125 to_draw = cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7) - cd->graphics_dst_x; |
126 } | 126 } |
127 for(uint16_t i = 0; i < to_draw; i++) | 127 for(uint16_t i = 0; i < to_draw; i++) |
128 { | 128 { |
129 uint32_t dst_address = cd->gate_array[GA_IMAGE_BUFFER_START] << 1; | 129 uint32_t dst_address = cd->gate_array[GA_IMAGE_BUFFER_START] << 1; |
130 dst_address += cd->graphics_dst_y << 1; | 130 dst_address += cd->graphics_dst_y << 1; |
182 switch (cd->graphics_step) | 182 switch (cd->graphics_step) |
183 { | 183 { |
184 case FETCH_X: | 184 case FETCH_X: |
185 cd->graphics_x = cd->word_ram[cd->gate_array[GA_TRACE_VECTOR_BASE] << 1] << 8; | 185 cd->graphics_x = cd->word_ram[cd->gate_array[GA_TRACE_VECTOR_BASE] << 1] << 8; |
186 cd->graphics_cycle += 3*4; | 186 cd->graphics_cycle += 3*4; |
187 cd->graphics_dst_x = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3; | 187 cd->graphics_dst_x = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7; |
188 CHECK_CYCLES; | 188 CHECK_CYCLES; |
189 case FETCH_Y: | 189 case FETCH_Y: |
190 cd->graphics_y = cd->word_ram[(cd->gate_array[GA_TRACE_VECTOR_BASE] << 1) + 1] << 8; | 190 cd->graphics_y = cd->word_ram[(cd->gate_array[GA_TRACE_VECTOR_BASE] << 1) + 1] << 8; |
191 cd->graphics_cycle += 2*4; | 191 cd->graphics_cycle += 2*4; |
192 CHECK_CYCLES; | 192 CHECK_CYCLES; |
205 cd->graphics_cycle += 2*4; | 205 cd->graphics_cycle += 2*4; |
206 CHECK_CYCLES; | 206 CHECK_CYCLES; |
207 case PIXEL0: | 207 case PIXEL0: |
208 cd->graphics_pixels[0] = get_src_pixel(cd); | 208 cd->graphics_pixels[0] = get_src_pixel(cd); |
209 cd->graphics_cycle += 2*4; | 209 cd->graphics_cycle += 2*4; |
210 if ((cd->graphics_dst_x & 3) == 3 || (cd->graphics_dst_x + 1 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3))) { | 210 if ((cd->graphics_dst_x & 3) == 3 || (cd->graphics_dst_x + 1 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7))) { |
211 cd->graphics_step = DRAW; | 211 cd->graphics_step = DRAW; |
212 CHECK_ONLY; | 212 CHECK_ONLY; |
213 goto draw; | 213 goto draw; |
214 } else { | 214 } else { |
215 CHECK_CYCLES; | 215 CHECK_CYCLES; |
216 } | 216 } |
217 case PIXEL1: | 217 case PIXEL1: |
218 cd->graphics_pixels[1] = get_src_pixel(cd); | 218 cd->graphics_pixels[1] = get_src_pixel(cd); |
219 cd->graphics_cycle += 2*4; | 219 cd->graphics_cycle += 2*4; |
220 if ((cd->graphics_dst_x & 3) == 2 || (cd->graphics_dst_x + 2 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3))) { | 220 if ((cd->graphics_dst_x & 3) == 2 || (cd->graphics_dst_x + 2 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7))) { |
221 cd->graphics_step = DRAW; | 221 cd->graphics_step = DRAW; |
222 CHECK_ONLY; | 222 CHECK_ONLY; |
223 goto draw; | 223 goto draw; |
224 } else { | 224 } else { |
225 CHECK_CYCLES; | 225 CHECK_CYCLES; |
226 } | 226 } |
227 case PIXEL2: | 227 case PIXEL2: |
228 cd->graphics_pixels[2] = get_src_pixel(cd); | 228 cd->graphics_pixels[2] = get_src_pixel(cd); |
229 cd->graphics_cycle += 2*4; | 229 cd->graphics_cycle += 2*4; |
230 if ((cd->graphics_dst_x & 3) == 1 || (cd->graphics_dst_x + 3 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3))) { | 230 if ((cd->graphics_dst_x & 3) == 1 || (cd->graphics_dst_x + 3 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7))) { |
231 cd->graphics_step = DRAW; | 231 cd->graphics_step = DRAW; |
232 CHECK_ONLY; | 232 CHECK_ONLY; |
233 goto draw; | 233 goto draw; |
234 } else { | 234 } else { |
235 CHECK_CYCLES; | 235 CHECK_CYCLES; |
341 //Manual scan is bad, but formula appears to be | 341 //Manual scan is bad, but formula appears to be |
342 // vsize * (13 + 2 * hoffset + 9 * (hdots + hoffset - 1)) | 342 // vsize * (13 + 2 * hoffset + 9 * (hdots + hoffset - 1)) |
343 //with an additional 13? cycle setup cost per line | 343 //with an additional 13? cycle setup cost per line |
344 uint32_t lines = cd->gate_array[GA_IMAGE_BUFFER_LINES]; | 344 uint32_t lines = cd->gate_array[GA_IMAGE_BUFFER_LINES]; |
345 uint32_t hdots = cd->gate_array[GA_IMAGE_BUFFER_HDOTS]; | 345 uint32_t hdots = cd->gate_array[GA_IMAGE_BUFFER_HDOTS]; |
346 uint32_t hoffset = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3; | 346 uint32_t hoffset = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 7; |
347 uint16_t pm = cd->gate_array[1] >> 3 & 3; | 347 uint16_t pm = cd->gate_array[1] >> 3 & 3; |
348 cd->graphics_int_cycle = cd->graphics_cycle + 4 * lines * (13 + 2 * hoffset + 9 * (hdots + hoffset - 1)); | 348 cd->graphics_int_cycle = cd->graphics_cycle + 4 * lines * (13 + 2 * hoffset + 9 * (hdots + hoffset - 1)); |
349 cd->graphics_dst_y = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] >> 3; | 349 cd->graphics_dst_y = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] >> 3; |
350 printf("graphics start @ %u, %u lines, %u hdots, pm = %u, hoff = %u, voff = %u, addr = %X\n", cd->graphics_cycle, lines, hdots, pm, hoffset, cd->graphics_dst_y, cd->gate_array[GA_IMAGE_BUFFER_START]); | 350 printf("graphics start @ %u, %u lines, %u hdots, pm = %u, hoff = %u, voff = %u, addr = %X\n", cd->graphics_cycle, lines, hdots, pm, hoffset, cd->graphics_dst_y, cd->gate_array[GA_IMAGE_BUFFER_START]); |
351 cd->graphics_step = FETCH_X; | 351 cd->graphics_step = FETCH_X; |