comparison vdp.c @ 2244:e6bad7bd8751

merge
author Michael Pavone <pavone@retrodev.com>
date Tue, 22 Nov 2022 23:07:41 -0800
parents 0d1d5dccdd28 48f718126099
children 1e626d0ecf9c
comparison
equal deleted inserted replaced
2243:0d1d5dccdd28 2244:e6bad7bd8751
115 //Undo forced INACTIVE state due to neither Mode 4 nor Mode 5 being active 115 //Undo forced INACTIVE state due to neither Mode 4 nor Mode 5 being active
116 if (context->vcounter < context->inactive_start) { 116 if (context->vcounter < context->inactive_start) {
117 context->state = ACTIVE; 117 context->state = ACTIVE;
118 } else if (context->vcounter == 0x1FF) { 118 } else if (context->vcounter == 0x1FF) {
119 context->state = PREPARING; 119 context->state = PREPARING;
120 memset(context->compositebuf, 0, sizeof(context->compositebuf));
120 } 121 }
121 } 122 }
122 } else { 123 } else {
123 context->inactive_start = MODE4_INACTIVE_START; 124 context->inactive_start = MODE4_INACTIVE_START;
124 if (context->flags2 & FLAG2_REGION_PAL) { 125 if (context->flags2 & FLAG2_REGION_PAL) {
135 if (context->vcounter < context->inactive_start) { 136 if (context->vcounter < context->inactive_start) {
136 context->state = ACTIVE; 137 context->state = ACTIVE;
137 } 138 }
138 else if (context->vcounter == 0x1FF) { 139 else if (context->vcounter == 0x1FF) {
139 context->state = PREPARING; 140 context->state = PREPARING;
141 memset(context->compositebuf, 0, sizeof(context->compositebuf));
140 } 142 }
141 } 143 }
142 } 144 }
143 context->border_top = calc_crop(top_crop, border_top); 145 context->border_top = calc_crop(top_crop, border_top);
144 context->top_offset = border_top - context->border_top; 146 context->top_offset = border_top - context->border_top;
188 } 190 }
189 context->color_map[color] = render_map_color(r, g, b); 191 context->color_map[color] = render_map_color(r, g, b);
190 } 192 }
191 193
192 if (!static_table_init_done) { 194 if (!static_table_init_done) {
193 195
194 for (uint16_t mode4_addr = 0; mode4_addr < 0x4000; mode4_addr++) 196 for (uint16_t mode4_addr = 0; mode4_addr < 0x4000; mode4_addr++)
195 { 197 {
196 uint16_t mode5_addr = mode4_addr & 0x3DFD; 198 uint16_t mode5_addr = mode4_addr & 0x3DFD;
197 mode5_addr |= mode4_addr << 8 & 0x200; 199 mode5_addr |= mode4_addr << 8 & 0x200;
198 mode5_addr |= mode4_addr >> 8 & 2; 200 mode5_addr |= mode4_addr >> 8 & 2;
2349 if ((*src & 0x3F) | test_layer) {\ 2351 if ((*src & 0x3F) | test_layer) {\
2350 *(dst++) = context->colors[*(src++)];\ 2352 *(dst++) = context->colors[*(src++)];\
2351 } else {\ 2353 } else {\
2352 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\ 2354 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\
2353 }\ 2355 }\
2354 if (slot != (BG_START_SLOT + LINEBUF_SIZE/2)) {\ 2356 if (slot == (BG_START_SLOT + LINEBUF_SIZE/2)) {\
2357 context->done_composite = NULL;\
2358 } else {\
2355 if ((*src & 0x3F) | test_layer) {\ 2359 if ((*src & 0x3F) | test_layer) {\
2356 *(dst++) = context->colors[*(src++)];\ 2360 *(dst++) = context->colors[*(src++)];\
2357 } else {\ 2361 } else {\
2358 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\ 2362 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\
2359 }\ 2363 }\
2366 if ((*src & 0x3F) | test_layer) {\ 2370 if ((*src & 0x3F) | test_layer) {\
2367 *(dst++) = context->colors[*(src++)];\ 2371 *(dst++) = context->colors[*(src++)];\
2368 } else {\ 2372 } else {\
2369 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\ 2373 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\
2370 }\ 2374 }\
2371 if (slot != (BG_START_SLOT + (256+HORIZ_BORDER)/2)) {\ 2375 if (slot == (BG_START_SLOT + (256+HORIZ_BORDER)/2)) {\
2376 context->done_composite = NULL;\
2377 } else {\
2372 if ((*src & 0x3F) | test_layer) {\ 2378 if ((*src & 0x3F) | test_layer) {\
2373 *(dst++) = context->colors[*(src++)];\ 2379 *(dst++) = context->colors[*(src++)];\
2374 } else {\ 2380 } else {\
2375 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\ 2381 *(dst++) = context->colors[(*(src++) & 0xC0) | bgindex];\
2376 }\ 2382 }\
3524 active_line = 0x200; 3530 active_line = 0x200;
3525 } 3531 }
3526 } 3532 }
3527 uint32_t *dst; 3533 uint32_t *dst;
3528 uint8_t *debug_dst; 3534 uint8_t *debug_dst;
3529 if (context->output && context->hslot >= BG_START_SLOT && context->hslot < bg_end_slot) { 3535 if (context->output && context->hslot >= BG_START_SLOT && context->hslot <= bg_end_slot) {
3530 dst = context->output + 2 * (context->hslot - BG_START_SLOT); 3536 dst = context->output + 2 * (context->hslot - BG_START_SLOT);
3531 debug_dst = context->layer_debug_buf + 2 * (context->hslot - BG_START_SLOT); 3537 debug_dst = context->layer_debug_buf + 2 * (context->hslot - BG_START_SLOT);
3532 } else { 3538 } else {
3533 dst = NULL; 3539 dst = NULL;
3534 } 3540 }
3539 { 3545 {
3540 check_switch_inactive(context, is_h40); 3546 check_switch_inactive(context, is_h40);
3541 if (context->hslot == BG_START_SLOT && context->output) { 3547 if (context->hslot == BG_START_SLOT && context->output) {
3542 dst = context->output + (context->hslot - BG_START_SLOT) * 2; 3548 dst = context->output + (context->hslot - BG_START_SLOT) * 2;
3543 debug_dst = context->layer_debug_buf + 2 * (context->hslot - BG_START_SLOT); 3549 debug_dst = context->layer_debug_buf + 2 * (context->hslot - BG_START_SLOT);
3544 } else if (context->hslot == bg_end_slot) {
3545 advance_output_line(context);
3546 dst = NULL;
3547 } 3550 }
3548 //this will need some tweaking to properly interact with 128K mode, 3551 //this will need some tweaking to properly interact with 128K mode,
3549 //but this should be good enough for now 3552 //but this should be good enough for now
3550 context->serial_address += 1024; 3553 context->serial_address += 1024;
3551 if (test_layer) { 3554 if (test_layer) {
3619 } 3622 }
3620 } else { 3623 } else {
3621 *(dst++) = bg_color; 3624 *(dst++) = bg_color;
3622 *(debug_dst++) = DBG_SRC_BG; 3625 *(debug_dst++) = DBG_SRC_BG;
3623 } 3626 }
3624 if (context->done_composite) { 3627 if (context->hslot != bg_end_slot) {
3625 uint8_t pixel = context->compositebuf[dst-context->output];
3626 if (!(pixel & 0x3F | test_layer)) {
3627 pixel = pixel & 0xC0 | bg_index;
3628 }
3629 *(dst++) = context->colors[pixel];
3630 if ((dst - context->output) == (context->done_composite - context->compositebuf)) {
3631 context->done_composite = NULL;
3632 memset(context->compositebuf, 0, sizeof(context->compositebuf));
3633 }
3634 } else {
3635 *(dst++) = bg_color;
3636 *(debug_dst++) = DBG_SRC_BG;
3637 }
3638
3639 if (context->hslot == (bg_end_slot-1)) {
3640 if (context->done_composite) { 3628 if (context->done_composite) {
3641 uint8_t pixel = context->compositebuf[dst-context->output]; 3629 uint8_t pixel = context->compositebuf[dst-context->output];
3642 if (!(pixel & 0x3F | test_layer)) { 3630 if (!(pixel & 0x3F | test_layer)) {
3643 pixel = pixel & 0xC0 | bg_index; 3631 pixel = pixel & 0xC0 | bg_index;
3644 } 3632 }
3651 *(dst++) = bg_color; 3639 *(dst++) = bg_color;
3652 *(debug_dst++) = DBG_SRC_BG; 3640 *(debug_dst++) = DBG_SRC_BG;
3653 } 3641 }
3654 } 3642 }
3655 } 3643 }
3644 if (context->hslot == bg_end_slot) {
3645 advance_output_line(context);
3646 dst = NULL;
3647 }
3656 3648
3657 if (!is_refresh(context, context->hslot)) { 3649 if (!is_refresh(context, context->hslot)) {
3658 external_slot(context); 3650 external_slot(context);
3659 if (context->flags & FLAG_DMA_RUN && !is_refresh(context, context->hslot)) { 3651 if (context->flags & FLAG_DMA_RUN && !is_refresh(context, context->hslot)) {
3660 run_dma_src(context, context->hslot); 3652 run_dma_src(context, context->hslot);
3677 } 3669 }
3678 if (context->hslot == line_change) { 3670 if (context->hslot == line_change) {
3679 vdp_advance_line(context); 3671 vdp_advance_line(context);
3680 if (context->vcounter == active_line) { 3672 if (context->vcounter == active_line) {
3681 context->state = PREPARING; 3673 context->state = PREPARING;
3674 memset(context->compositebuf, 0, sizeof(context->compositebuf));
3682 return; 3675 return;
3683 } 3676 }
3684 } 3677 }
3685 } 3678 }
3686 } 3679 }