comparison vdp.c @ 2700:1cfd000dc750 default tip

WIP display screen border in plane debugger
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Jun 2025 23:38:56 -0700
parents 46dba737b931
children
comparison
equal deleted inserted replaced
2699:89c06782589f 2700:1cfd000dc750
2458 address += y_diff; 2458 address += y_diff;
2459 dst += pitch / sizeof(pixel_t); 2459 dst += pitch / sizeof(pixel_t);
2460 } 2460 }
2461 } 2461 }
2462 } 2462 }
2463 if (context->debug_flags & DEBUG_FLAG_PLANE_BORDER) {
2464 pixel_t border_line = render_map_color(255, 0, 255);
2465 if ((context->debug_modes[DEBUG_PLANE] & 3) < 2) {
2466 uint16_t hscroll_base = (context->regs[REG_HSCROLL] & 0x3F) << 10;
2467 hscroll_base += (context->debug_modes[DEBUG_PLANE] & 1) * 2;
2468 uint16_t hscroll_mask = 0;
2469 if (context->regs[REG_MODE_3] & 0x2) {
2470 hscroll_mask |= 0xF8;
2471 }
2472 if (context->regs[REG_MODE_3] & 0x1) {
2473 hscroll_mask |= 0x7;
2474 }
2475 uint16_t hscroll = 1023 - (context->vdpmem[hscroll_base] << 8 | context->vdpmem[hscroll_base+1]) & 1023;
2476 uint16_t width = (context->regs[REG_MODE_4] & BIT_H40) ? 320 : 256;
2477 if (context->regs[REG_MODE_3] & BIT_VSCROLL) {
2478 //2-column vscroll
2479 uint16_t num_cols = width >> 4;
2480 for (int y_off = -2; y_off; y_off++)
2481 {
2482 for (uint16_t col = 0; col < num_cols; col++)
2483 {
2484 uint16_t vscroll = context->vsram[col * 2 + (context->debug_modes[DEBUG_PLANE] & 1)] & 1023;
2485 int y = (vscroll + y_off) & 1023;
2486 pixel_t *line = fb + y * pitch / sizeof(pixel_t);
2487 for (int x = col ? hscroll + col * 16 : hscroll - 2, x_end = col == num_cols-1 ? hscroll + width + 2 : x + (col ? 16 : 18); x < x_end; x++)
2488 {
2489 line[x & 1023] = border_line;
2490 }
2491 }
2492 }
2493 for (int y = context->vsram[context->debug_modes[DEBUG_PLANE] & 1], y_end = y + context->inactive_start; y < y_end; y++)
2494 {
2495 pixel_t *line = fb + (y & 1023) * pitch / sizeof(pixel_t);
2496 line[(hscroll - 2) & 1023] = border_line;
2497 line[(hscroll - 1) & 1023] = border_line;
2498 uint16_t hscroll_addr = hscroll_base + ((y - (y_end - context->inactive_start)) & hscroll_mask) * 4;
2499 hscroll = 1024 - (context->vdpmem[hscroll_addr] << 8 | context->vdpmem[hscroll_addr+1]) & 1023;
2500 }
2501 for (int y = context->vsram[19 * 2 + (context->debug_modes[DEBUG_PLANE] & 1)], y_end = y + context->inactive_start; y < y_end; y++)
2502 {
2503 pixel_t *line = fb + (y & 1023) * pitch / sizeof(pixel_t);
2504 line[(hscroll + width) & 1023] = border_line;
2505 line[(hscroll + width + 1) & 1023] = border_line;
2506 uint16_t hscroll_addr = hscroll_base + ((y - (y_end - context->inactive_start)) & hscroll_mask) * 4;
2507 hscroll = 1024 - (context->vdpmem[hscroll_addr] << 8 | context->vdpmem[hscroll_addr+1]) & 1023;
2508 }
2509 for (int y_off = context->inactive_start; y_off < context->inactive_start + 2; y_off++)
2510 {
2511 for (uint16_t col = 0; col < num_cols; col++)
2512 {
2513 uint16_t vscroll = context->vsram[col * 2 + (context->debug_modes[DEBUG_PLANE] & 1)] & 1023;
2514 int y = (vscroll + y_off) & 1023;
2515 pixel_t *line = fb + y * pitch / sizeof(pixel_t);
2516 for (int x = col ? hscroll + col * 16 : hscroll - 2, x_end = col == num_cols-1 ? hscroll + width + 2 : x + (col ? 16 : 18); x < x_end; x++)
2517 {
2518 line[x & 1023] = border_line;
2519 }
2520 }
2521 }
2522 } else {
2523 //full screen vscroll
2524 uint16_t vscroll = context->vsram[context->debug_modes[DEBUG_PLANE] & 1] & 1023;
2525 int y = (vscroll - 2) & 1023;
2526 pixel_t *line = fb + y * pitch / sizeof(pixel_t);
2527 for (int x = hscroll - 2, x_end = hscroll + width + 2; x < x_end; x++)
2528 {
2529 line[x & 1023] = border_line;
2530 }
2531 y = (y + 1) & 1023;
2532 line = fb + y * pitch / sizeof(pixel_t);
2533 for (int x = hscroll - 1, x_end = hscroll + width + 1; x < x_end; x++)
2534 {
2535 line[x & 1023] = border_line;
2536 }
2537 int y_end = y + context->inactive_start + 1;
2538 for (y++; y < y_end; y++)
2539 {
2540 line = fb + (y & 1023) * pitch / sizeof(pixel_t);
2541 line[(hscroll - 2) & 1023] = border_line;
2542 line[(hscroll - 1) & 1023] = border_line;
2543 line[(hscroll + width) & 1023] = border_line;
2544 line[(hscroll + width + 1) & 1023] = border_line;
2545 uint16_t hscroll_last = hscroll;
2546 uint16_t hscroll_addr = hscroll_base + ((y - vscroll) & hscroll_mask) * 4;
2547 hscroll = 1024 - (context->vdpmem[hscroll_addr] << 8 | context->vdpmem[hscroll_addr+1]) & 1023;
2548 if (abs(hscroll - hscroll_last) > 512) {
2549 //handle wraparound
2550 if (hscroll > hscroll_last) {
2551 hscroll_last += 1024;
2552 } else {
2553 hscroll += 1024;
2554 }
2555 }
2556 if (hscroll_last < hscroll) {
2557 for (int x = hscroll_last + width + 2, x_end = hscroll + width; x < x_end; x++)
2558 {
2559 line[x & 1023] = border_line;
2560 }
2561 line = fb + ((y+1) & 1023) * pitch / sizeof(pixel_t);
2562 for (int x = hscroll_last, x_end = hscroll; x < x_end; x++)
2563 {
2564 line[x & 1023] = border_line;
2565 }
2566 } else if (hscroll_last > hscroll) {
2567 for (int x = hscroll, x_end = hscroll_last; x < x_end; x++)
2568 {
2569 line[x & 1023] = border_line;
2570 }
2571 line = fb + ((y+1) & 1023) * pitch / sizeof(pixel_t);
2572 for (int x = hscroll + width + 2, x_end = hscroll_last + width; x < x_end; x++)
2573 {
2574 line[x & 1023] = border_line;
2575 }
2576 }
2577 }
2578 line = fb + (y_end & 1023) * pitch / sizeof(pixel_t);
2579 for (int x = hscroll - 2, x_end = hscroll + width + 2; x < x_end; x++)
2580 {
2581 line[x & 1023] = border_line;
2582 }
2583 line = fb + ((y_end + 1) & 1023) * pitch / sizeof(pixel_t);
2584 for (int x = hscroll - 2, x_end = hscroll + width + 2; x < x_end; x++)
2585 {
2586 line[x & 1023] = border_line;
2587 }
2588 }
2589 }
2590 }
2463 } 2591 }
2464 2592
2465 static void sprite_debug_mode5(pixel_t *fb, uint32_t pitch, vdp_context *context) 2593 static void sprite_debug_mode5(pixel_t *fb, uint32_t pitch, vdp_context *context)
2466 { 2594 {
2467 pixel_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 2595 pixel_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];