Mercurial > repos > blastem
comparison vdp.c @ 2569:80606ebec74c
Add sprite "plane" to VDP plane debugger
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 01 Feb 2025 23:22:13 -0800 |
parents | e5de445e2cf0 |
children | 882ceef923e0 |
comparison
equal
deleted
inserted
replaced
2566:e5de445e2cf0 | 2569:80606ebec74c |
---|---|
2276 hscroll_mask = 0x7F; | 2276 hscroll_mask = 0x7F; |
2277 v_mul = 256; | 2277 v_mul = 256; |
2278 break; | 2278 break; |
2279 } | 2279 } |
2280 uint16_t table_address; | 2280 uint16_t table_address; |
2281 switch(context->debug_modes[DEBUG_PLANE] % 3) | 2281 switch(context->debug_modes[DEBUG_PLANE] & 3) |
2282 { | 2282 { |
2283 case 0: | 2283 case 0: |
2284 table_address = context->regs[REG_SCROLL_A] << 10 & 0xE000; | 2284 table_address = context->regs[REG_SCROLL_A] << 10 & 0xE000; |
2285 break; | 2285 break; |
2286 case 1: | 2286 case 1: |
2299 } | 2299 } |
2300 vscroll_mask = 0x1F; | 2300 vscroll_mask = 0x1F; |
2301 break; | 2301 break; |
2302 } | 2302 } |
2303 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR & 0x3F]]; | 2303 uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR & 0x3F]]; |
2304 uint16_t num_rows; | 2304 if ((context->debug_modes[DEBUG_PLANE] & 3) == 3) { |
2305 int num_lines; | 2305 //clear a single alpha channel bit so we can distinguish between actual bg color and sprite |
2306 if (context->double_res) { | 2306 //pixels that just happen to be the same color |
2307 num_rows = 64; | 2307 bg_color &= 0xFEFFFFFF; |
2308 num_lines = 16; | 2308 uint32_t *line = fb; |
2309 uint32_t border_line = render_map_color(0, 0, 255); | |
2310 uint32_t sprite_outline = render_map_color(255, 0, 255); | |
2311 int right_border = 256 + ((context->h40_lines > context->output_lines / 2) ? 640 : 512); | |
2312 for (int y = 0; y < 1024; y++) | |
2313 { | |
2314 uint32_t *cur = line; | |
2315 if (y != 256 && y != 256+context->inactive_start*2) { | |
2316 for (int x = 0; x < 255; x++) | |
2317 { | |
2318 *(cur++) = bg_color; | |
2319 } | |
2320 *(cur++) = border_line; | |
2321 for (int x = 256; x < right_border; x++) | |
2322 { | |
2323 *(cur++) = bg_color; | |
2324 } | |
2325 *(cur++) = border_line; | |
2326 for (int x = right_border + 1; x < 1024; x++) | |
2327 { | |
2328 *(cur++) = bg_color; | |
2329 } | |
2330 } else { | |
2331 for (int x = 0; x < 1024; x++) | |
2332 { | |
2333 *(cur++) = border_line; | |
2334 } | |
2335 } | |
2336 line += pitch / sizeof(uint32_t); | |
2337 } | |
2338 for (int i = 0, index = 0; i < context->max_sprites_frame; i++) | |
2339 { | |
2340 uint32_t y = (context->sat_cache[index] & 3) << 8 | context->sat_cache[index + 1]; | |
2341 if (!context->double_res) { | |
2342 y &= 0x1FF; | |
2343 y <<= 1; | |
2344 } | |
2345 uint8_t tile_width = ((context->sat_cache[index+2] >> 2) & 0x3); | |
2346 uint32_t pixel_width = (tile_width + 1) * 16; | |
2347 uint8_t height = ((context->sat_cache[index+2] & 3) + 1) * 16; | |
2348 uint16_t col_offset = height * (context->double_res ? 4 : 2); | |
2349 uint16_t att_addr = mode5_sat_address(context) + index * 2 + 4; | |
2350 uint16_t tileinfo = (context->vdpmem[att_addr] << 8) | context->vdpmem[att_addr+1]; | |
2351 uint16_t tile_addr; | |
2352 if (context->double_res) { | |
2353 tile_addr = (tileinfo & 0x3FF) << 6; | |
2354 } else { | |
2355 tile_addr = (tileinfo & 0x7FF) << 5; | |
2356 } | |
2357 uint8_t pal = (tileinfo >> 9) & 0x30; | |
2358 uint16_t hflip = tileinfo & MAP_BIT_H_FLIP; | |
2359 uint16_t vflip = tileinfo & MAP_BIT_V_FLIP; | |
2360 uint32_t x = (((context->vdpmem[att_addr+ 2] & 0x3) << 8 | context->vdpmem[att_addr + 3]) & 0x1FF) * 2; | |
2361 uint32_t *line = fb + y * pitch / sizeof(uint32_t) + x; | |
2362 uint32_t *cur = line; | |
2363 for (uint32_t cx = x, x2 = x + pixel_width; cx < x2; cx++) | |
2364 { | |
2365 *(cur++) = sprite_outline; | |
2366 } | |
2367 uint8_t advance_source = 1; | |
2368 uint32_t y2 = y + height - 1; | |
2369 if (y2 > 1024) { | |
2370 y2 = 1024; | |
2371 } | |
2372 uint16_t line_offset = 4; | |
2373 if (vflip) { | |
2374 tile_addr += col_offset - 4; | |
2375 line_offset = -line_offset; | |
2376 } | |
2377 if (hflip) { | |
2378 tile_addr += col_offset * tile_width + 3; | |
2379 col_offset = -col_offset; | |
2380 } | |
2381 for (; y < y2; y++) | |
2382 { | |
2383 line += pitch / sizeof(uint32_t); | |
2384 cur = line; | |
2385 *(cur++) = sprite_outline; | |
2386 uint16_t line_addr = tile_addr; | |
2387 for (uint8_t tx = 0; tx <= tile_width; tx++) | |
2388 { | |
2389 uint16_t cur_addr = line_addr; | |
2390 for (uint8_t cx = 0; cx < 4; cx++) | |
2391 { | |
2392 uint8_t pair = context->vdpmem[cur_addr]; | |
2393 uint32_t left, right; | |
2394 if (hflip) { | |
2395 right = pair >> 4; | |
2396 left = pair & 0xF; | |
2397 cur_addr--; | |
2398 } else { | |
2399 left = pair >> 4; | |
2400 right = pair & 0xF; | |
2401 cur_addr++; | |
2402 } | |
2403 left = left ? context->colors[pal | left] : bg_color; | |
2404 right = right ? context->colors[pal | right] : bg_color; | |
2405 if (*cur == bg_color) { | |
2406 *(cur) = left; | |
2407 } | |
2408 cur++; | |
2409 if (cx | tx) { | |
2410 if (*cur == bg_color) { | |
2411 *(cur) = left; | |
2412 } | |
2413 cur++; | |
2414 } | |
2415 if (*cur == bg_color) { | |
2416 *(cur) = right; | |
2417 } | |
2418 cur++; | |
2419 if (cx != 3 || tx != tile_width) { | |
2420 if (*cur == bg_color) { | |
2421 *(cur) = right; | |
2422 } | |
2423 cur++; | |
2424 } | |
2425 } | |
2426 line_addr += col_offset; | |
2427 } | |
2428 | |
2429 *(cur++) = sprite_outline; | |
2430 if (advance_source || context->double_res) { | |
2431 tile_addr += line_offset; | |
2432 } | |
2433 advance_source = !advance_source; | |
2434 } | |
2435 if (y2 != 1024) { | |
2436 line += pitch / sizeof(uint32_t); | |
2437 cur = line; | |
2438 for (uint32_t cx = x, x2 = x + pixel_width; cx < x2; cx++) | |
2439 { | |
2440 *(cur++) = sprite_outline; | |
2441 } | |
2442 } | |
2443 index = context->sat_cache[index+3] * 4; | |
2444 if (!index) { | |
2445 break; | |
2446 } | |
2447 } | |
2309 } else { | 2448 } else { |
2310 num_rows = 128; | 2449 |
2311 num_lines = 8; | 2450 uint16_t num_rows; |
2312 } | 2451 int num_lines; |
2313 for (uint16_t row = 0; row < num_rows; row++) | 2452 if (context->double_res) { |
2314 { | 2453 num_rows = 64; |
2315 uint16_t row_address = table_address + (row & vscroll_mask) * v_mul; | 2454 num_lines = 16; |
2316 for (uint16_t col = 0; col < 128; col++) | 2455 } else { |
2456 num_rows = 128; | |
2457 num_lines = 8; | |
2458 } | |
2459 for (uint16_t row = 0; row < num_rows; row++) | |
2317 { | 2460 { |
2318 uint16_t address = row_address + (col & hscroll_mask) * 2; | 2461 uint16_t row_address = table_address + (row & vscroll_mask) * v_mul; |
2319 //pccv hnnn nnnn nnnn | 2462 for (uint16_t col = 0; col < 128; col++) |
2320 // | |
2321 uint16_t entry = context->vdpmem[address] << 8 | context->vdpmem[address + 1]; | |
2322 uint8_t pal = entry >> 9 & 0x30; | |
2323 | |
2324 uint32_t *dst = fb + (row * pitch * num_lines / sizeof(uint32_t)) + col * 8; | |
2325 if (context->double_res) { | |
2326 address = (entry & 0x3FF) * 64; | |
2327 } else { | |
2328 address = (entry & 0x7FF) * 32; | |
2329 } | |
2330 int y_diff = 4; | |
2331 if (entry & 0x1000) { | |
2332 y_diff = -4; | |
2333 address += (num_lines - 1) * 4; | |
2334 } | |
2335 int x_diff = 1; | |
2336 if (entry & 0x800) { | |
2337 x_diff = -1; | |
2338 address += 3; | |
2339 } | |
2340 for (int y = 0; y < num_lines; y++) | |
2341 { | 2463 { |
2342 uint16_t trow_address = address; | 2464 uint16_t address = row_address + (col & hscroll_mask) * 2; |
2343 uint32_t *row_dst = dst; | 2465 //pccv hnnn nnnn nnnn |
2344 for (int x = 0; x < 4; x++) | 2466 // |
2467 uint16_t entry = context->vdpmem[address] << 8 | context->vdpmem[address + 1]; | |
2468 uint8_t pal = entry >> 9 & 0x30; | |
2469 | |
2470 uint32_t *dst = fb + (row * pitch * num_lines / sizeof(uint32_t)) + col * 8; | |
2471 if (context->double_res) { | |
2472 address = (entry & 0x3FF) * 64; | |
2473 } else { | |
2474 address = (entry & 0x7FF) * 32; | |
2475 } | |
2476 int y_diff = 4; | |
2477 if (entry & 0x1000) { | |
2478 y_diff = -4; | |
2479 address += (num_lines - 1) * 4; | |
2480 } | |
2481 int x_diff = 1; | |
2482 if (entry & 0x800) { | |
2483 x_diff = -1; | |
2484 address += 3; | |
2485 } | |
2486 for (int y = 0; y < num_lines; y++) | |
2345 { | 2487 { |
2346 uint8_t byte = context->vdpmem[trow_address]; | 2488 uint16_t trow_address = address; |
2347 trow_address += x_diff; | 2489 uint32_t *row_dst = dst; |
2348 uint8_t left, right; | 2490 for (int x = 0; x < 4; x++) |
2349 if (x_diff > 0) { | 2491 { |
2350 left = byte >> 4; | 2492 uint8_t byte = context->vdpmem[trow_address]; |
2351 right = byte & 0xF; | 2493 trow_address += x_diff; |
2352 } else { | 2494 uint8_t left, right; |
2353 left = byte & 0xF; | 2495 if (x_diff > 0) { |
2354 right = byte >> 4; | 2496 left = byte >> 4; |
2497 right = byte & 0xF; | |
2498 } else { | |
2499 left = byte & 0xF; | |
2500 right = byte >> 4; | |
2501 } | |
2502 *(row_dst++) = left ? context->colors[left|pal] : bg_color; | |
2503 *(row_dst++) = right ? context->colors[right|pal] : bg_color; | |
2355 } | 2504 } |
2356 *(row_dst++) = left ? context->colors[left|pal] : bg_color; | 2505 address += y_diff; |
2357 *(row_dst++) = right ? context->colors[right|pal] : bg_color; | 2506 dst += pitch / sizeof(uint32_t); |
2358 } | 2507 } |
2359 address += y_diff; | |
2360 dst += pitch / sizeof(uint32_t); | |
2361 } | 2508 } |
2362 } | 2509 } |
2363 } | 2510 } |
2364 render_framebuffer_updated(context->debug_fb_indices[DEBUG_PLANE], 1024); | 2511 render_framebuffer_updated(context->debug_fb_indices[DEBUG_PLANE], 1024); |
2365 } | 2512 } |