comparison vdp.c @ 1378:71c8b97eb962

Get H32 in sync with H40 with regards to borders and test register support. Minor cleanup to H40 border rendering
author Michael Pavone <pavone@retrodev.com>
date Mon, 29 May 2017 17:30:40 -0700
parents e587f16e7d3d
children 9a5352a2f57a
comparison
equal deleted inserted replaced
1377:e587f16e7d3d 1378:71c8b97eb962
1937 #define SPRITE_RENDER_H32(slot) \ 1937 #define SPRITE_RENDER_H32(slot) \
1938 case slot:\ 1938 case slot:\
1939 if ((slot) == BG_START_SLOT + (256+HORIZ_BORDER)/2) {\ 1939 if ((slot) == BG_START_SLOT + (256+HORIZ_BORDER)/2) {\
1940 advance_output_line(context);\ 1940 advance_output_line(context);\
1941 }\ 1941 }\
1942 if (slot == 136 || slot == 247 || slot == 248) {\
1943 render_border_garbage(\
1944 context,\
1945 context->sprite_draw_list[context->cur_slot].address,\
1946 context->tmp_buf_b,\
1947 context->buf_b_off + (slot == 247 ? 0 : 8),\
1948 slot == 247 ? context->col_1 : context->col_2\
1949 );\
1950 if (slot == 248) {\
1951 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK;\
1952 context->buf_b_off = (context->buf_b_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK;\
1953 }\
1954 } else if (slot == 137) {\
1955 draw_right_border(context);\
1956 }\
1942 render_sprite_cells( context);\ 1957 render_sprite_cells( context);\
1943 scan_sprite_table(context->vcounter, context);\ 1958 scan_sprite_table(context->vcounter, context);\
1944 if (context->flags & FLAG_DMA_RUN) { run_dma_src(context, -1); } \ 1959 if (context->flags & FLAG_DMA_RUN) { run_dma_src(context, -1); } \
1945 if (slot == 147) {\ 1960 if (slot == 147) {\
1946 context->hslot = 233;\ 1961 context->hslot = 233;\
1999 for (;;) 2014 for (;;)
2000 { 2015 {
2001 case 165: 2016 case 165:
2002 if (context->state == PREPARING) { 2017 if (context->state == PREPARING) {
2003 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2018 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2004 uint32_t *dst; 2019 uint32_t *dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2005 dst = ((uint32_t *)(((char *)context->fb) + context->output_pitch * (context->border_top - 2)))
2006 + (context->hslot - BG_START_SLOT) * 2;
2007 if (dst >= context->done_output) { 2020 if (dst >= context->done_output) {
2008 *dst = bg_color; 2021 *dst = bg_color;
2009 } 2022 }
2010 dst++; 2023 dst++;
2011 if (dst >= context->done_output) { 2024 if (dst >= context->done_output) {
2017 } 2030 }
2018 CHECK_LIMIT 2031 CHECK_LIMIT
2019 case 166: 2032 case 166:
2020 if (context->state == PREPARING) { 2033 if (context->state == PREPARING) {
2021 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2034 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2022 uint32_t *dst; 2035 uint32_t *dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2023 dst = ((uint32_t *)(((char *)context->fb) + context->output_pitch * (context->border_top - 2)))
2024 + (context->hslot - BG_START_SLOT) * 2;
2025 if (dst >= context->done_output) { 2036 if (dst >= context->done_output) {
2026 *dst = bg_color; 2037 *dst = bg_color;
2027 } 2038 }
2028 dst++; 2039 dst++;
2029 if (dst >= context->done_output) { 2040 if (dst >= context->done_output) {
2041 CHECK_LIMIT 2052 CHECK_LIMIT
2042 //sprite attribute table scan starts 2053 //sprite attribute table scan starts
2043 case 167: 2054 case 167:
2044 if (context->state == PREPARING) { 2055 if (context->state == PREPARING) {
2045 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2056 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2046 uint32_t *dst; 2057 uint32_t *dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2047 dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2048 for (int i = 0; i < LINEBUF_SIZE - 2 * (context->hslot - BG_START_SLOT); i++, dst++) 2058 for (int i = 0; i < LINEBUF_SIZE - 2 * (context->hslot - BG_START_SLOT); i++, dst++)
2049 { 2059 {
2050 if (dst >= context->done_output) { 2060 if (dst >= context->done_output) {
2051 *dst = bg_color; 2061 *dst = bg_color;
2052 } 2062 }
2058 context, 2068 context,
2059 context->sprite_draw_list[context->cur_slot].address, 2069 context->sprite_draw_list[context->cur_slot].address,
2060 context->tmp_buf_b, context->buf_b_off, 2070 context->tmp_buf_b, context->buf_b_off,
2061 context->col_1 2071 context->col_1
2062 ); 2072 );
2063 render_sprite_cells( context); 2073 render_sprite_cells(context);
2064 scan_sprite_table(context->vcounter, context); 2074 scan_sprite_table(context->vcounter, context);
2065 CHECK_LIMIT 2075 CHECK_LIMIT
2066 SPRITE_RENDER_H40(168) 2076 SPRITE_RENDER_H40(168)
2067 SPRITE_RENDER_H40(169) 2077 SPRITE_RENDER_H40(169)
2068 SPRITE_RENDER_H40(170) 2078 SPRITE_RENDER_H40(170)
2221 for (;;) 2231 for (;;)
2222 { 2232 {
2223 case 133: 2233 case 133:
2224 if (context->state == PREPARING) { 2234 if (context->state == PREPARING) {
2225 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2235 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2226 uint32_t *dst; 2236 uint32_t *dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2227 if (headless) { 2237 if (dst >= context->done_output) {
2228 dst = context->output; 2238 *dst = bg_color;
2229 } else { 2239 }
2230 dst = ((uint32_t *)(((char *)context->fb) + context->output_pitch * (context->border_top - 2))) 2240 dst++;
2231 + (context->hslot - BG_START_SLOT) * 2; 2241 if (dst >= context->done_output) {
2232 } 2242 *dst = bg_color;
2233 *(dst++) = bg_color; 2243 }
2234 *dst = bg_color;
2235 external_slot(context); 2244 external_slot(context);
2236 } else { 2245 } else {
2237 render_sprite_cells(context); 2246 render_sprite_cells(context);
2238 } 2247 }
2239 CHECK_LIMIT 2248 CHECK_LIMIT
2240 case 134: 2249 case 134:
2241 if (context->state == PREPARING) { 2250 if (context->state == PREPARING) {
2242 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2251 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2243 uint32_t *dst; 2252 uint32_t *dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2244 if (headless) { 2253 if (dst >= context->done_output) {
2245 dst = context->output; 2254 *dst = bg_color;
2246 } else { 2255 }
2247 dst = ((uint32_t *)(((char *)context->fb) + context->output_pitch * (context->border_top - 2))) 2256 dst++;
2248 + (context->hslot - BG_START_SLOT) * 2; 2257 if (dst >= context->done_output) {
2249 } 2258 *dst = bg_color;
2250 *(dst++) = bg_color; 2259 }
2251 *dst = bg_color;
2252 external_slot(context); 2260 external_slot(context);
2253 } else { 2261 } else {
2254 render_sprite_cells(context); 2262 render_sprite_cells(context);
2255 } 2263 }
2256 if (context->vcounter == context->inactive_start) { 2264 if (context->vcounter == context->inactive_start) {
2258 context->cycles += slot_cycles; 2266 context->cycles += slot_cycles;
2259 return; 2267 return;
2260 } 2268 }
2261 CHECK_LIMIT 2269 CHECK_LIMIT
2262 //sprite attribute table scan starts 2270 //sprite attribute table scan starts
2263 case 135: //FIXME - Here 2271 case 135:
2264 if (context->state == PREPARING) { 2272 if (context->state == PREPARING) {
2265 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2273 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2266 uint32_t *dst; 2274 uint32_t *dst = context->output + (context->hslot - BG_START_SLOT) * 2;
2267 if (headless) {
2268 dst = context->output;
2269 } else {
2270 dst = ((uint32_t *)(((char *)context->fb) + context->output_pitch * (context->border_top - 2)))
2271 + (context->hslot - BG_START_SLOT) * 2;
2272 }
2273 for (int i = 0; i < (256+HORIZ_BORDER) - 2 * (context->hslot - BG_START_SLOT); i++) 2275 for (int i = 0; i < (256+HORIZ_BORDER) - 2 * (context->hslot - BG_START_SLOT); i++)
2274 { 2276 {
2275 *(dst++) = bg_color; 2277 if (dst >= context->done_output) {
2278 *(dst++) = bg_color;
2279 }
2276 } 2280 }
2277 } 2281 }
2278 context->sprite_index = 0x80; 2282 context->sprite_index = 0x80;
2279 context->slot_counter = 0; 2283 context->slot_counter = 0;
2280 render_sprite_cells( context); 2284 render_border_garbage(
2285 context,
2286 context->sprite_draw_list[context->cur_slot].address,
2287 context->tmp_buf_b, context->buf_b_off,
2288 context->col_1
2289 );
2290 render_sprite_cells(context);
2281 scan_sprite_table(context->vcounter, context); 2291 scan_sprite_table(context->vcounter, context);
2282 CHECK_LIMIT 2292 CHECK_LIMIT
2283 SPRITE_RENDER_H32(136) 2293 SPRITE_RENDER_H32(136)
2284 SPRITE_RENDER_H32(137) 2294 SPRITE_RENDER_H32(137)
2285 SPRITE_RENDER_H32(138) 2295 SPRITE_RENDER_H32(138)
2305 SPRITE_RENDER_H32(240) 2315 SPRITE_RENDER_H32(240)
2306 SPRITE_RENDER_H32(241) 2316 SPRITE_RENDER_H32(241)
2307 SPRITE_RENDER_H32(242) 2317 SPRITE_RENDER_H32(242)
2308 case 243: 2318 case 243:
2309 external_slot(context); 2319 external_slot(context);
2320 //provides "garbage" for border when plane A selected
2321 render_border_garbage(
2322 context,
2323 context->sprite_draw_list[context->cur_slot].address,
2324 context->tmp_buf_a,
2325 context->buf_a_off,
2326 context->col_1
2327 );
2310 CHECK_LIMIT 2328 CHECK_LIMIT
2311 case 244: 2329 case 244:
2312 address = (context->regs[REG_HSCROLL] & 0x3F) << 10; 2330 address = (context->regs[REG_HSCROLL] & 0x3F) << 10;
2313 mask = 0; 2331 mask = 0;
2314 if (context->regs[REG_MODE_3] & 0x2) { 2332 if (context->regs[REG_MODE_3] & 0x2) {
2315 mask |= 0xF8; 2333 mask |= 0xF8;
2316 } 2334 }
2317 if (context->regs[REG_MODE_3] & 0x1) { 2335 if (context->regs[REG_MODE_3] & 0x1) {
2318 mask |= 0x7; 2336 mask |= 0x7;
2319 } 2337 }
2338 render_border_garbage(context, address, context->tmp_buf_a, context->buf_a_off+8, context->col_2);
2320 address += (context->vcounter & mask) * 4; 2339 address += (context->vcounter & mask) * 4;
2321 context->hscroll_a = context->vdpmem[address] << 8 | context->vdpmem[address+1]; 2340 context->hscroll_a = context->vdpmem[address] << 8 | context->vdpmem[address+1];
2322 context->hscroll_b = context->vdpmem[address+2] << 8 | context->vdpmem[address+3]; 2341 context->hscroll_b = context->vdpmem[address+2] << 8 | context->vdpmem[address+3];
2323 //printf("%d: HScroll A: %d, HScroll B: %d\n", context->vcounter, context->hscroll_a, context->hscroll_b); 2342 //printf("%d: HScroll A: %d, HScroll B: %d\n", context->vcounter, context->hscroll_a, context->hscroll_b);
2324 CHECK_LIMIT 2343 CHECK_LIMIT //provides "garbage" for border when plane A selected
2325 SPRITE_RENDER_H32(245) 2344 SPRITE_RENDER_H32(245)
2326 SPRITE_RENDER_H32(246) 2345 SPRITE_RENDER_H32(246)
2327 SPRITE_RENDER_H32(247) 2346 SPRITE_RENDER_H32(247) //provides "garbage" for border when plane B selected
2328 SPRITE_RENDER_H32(248) 2347 SPRITE_RENDER_H32(248) //provides "garbage" for border when plane B selected
2329 //!HSYNC high 2348 //!HSYNC high
2330 case 249: 2349 case 249:
2331 read_map_scroll_a(0, context->vcounter, context); 2350 read_map_scroll_a(0, context->vcounter, context);
2332 CHECK_LIMIT 2351 CHECK_LIMIT
2333 SPRITE_RENDER_H32(250) 2352 SPRITE_RENDER_H32(250)
2379 case 129: 2398 case 129:
2380 external_slot(context); 2399 external_slot(context);
2381 CHECK_LIMIT 2400 CHECK_LIMIT
2382 case 130: { 2401 case 130: {
2383 external_slot(context); 2402 external_slot(context);
2384 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];
2385 for (int i = 256+BORDER_LEFT; i < 256+HORIZ_BORDER; i++)
2386 {
2387 context->output[i] = bg_color;
2388 }
2389 CHECK_LIMIT 2403 CHECK_LIMIT
2390 } 2404 }
2391 //sprite render to line buffer starts 2405 //sprite render to line buffer starts
2392 case 131: 2406 case 131:
2393 context->cur_slot = MAX_DRAWS_H32-1; 2407 context->cur_slot = MAX_DRAWS_H32-1;
2394 memset(context->linebuf, 0, LINEBUF_SIZE); 2408 memset(context->linebuf, 0, LINEBUF_SIZE);
2409 render_border_garbage(
2410 context,
2411 context->sprite_draw_list[context->cur_slot].address,
2412 context->tmp_buf_a, context->buf_a_off,
2413 context->col_1
2414 );
2395 render_sprite_cells(context); 2415 render_sprite_cells(context);
2396 CHECK_LIMIT 2416 CHECK_LIMIT
2397 case 132: 2417 case 132:
2418 render_border_garbage(
2419 context,
2420 context->sprite_draw_list[context->cur_slot].address,
2421 context->tmp_buf_a, context->buf_a_off + 8,
2422 context->col_2
2423 );
2398 render_sprite_cells(context); 2424 render_sprite_cells(context);
2399 if (context->flags & FLAG_DMA_RUN) { 2425 if (context->flags & FLAG_DMA_RUN) {
2400 run_dma_src(context, -1); 2426 run_dma_src(context, -1);
2401 } 2427 }
2402 context->hslot++; 2428 context->hslot++;