comparison vdp.c @ 437:afbea09d7fb4

Restore one of the VDP debugging modes
author Mike Pavone <pavone@retrodev.com>
date Mon, 15 Jul 2013 23:07:45 -0700
parents e341fd5aa996
children b3cee2fe690b
comparison
equal deleted inserted replaced
436:e341fd5aa996 437:afbea09d7fb4
28 #define HBLANK_CLEAR_H40 (MCLK_WEIRD_END+61*4) 28 #define HBLANK_CLEAR_H40 (MCLK_WEIRD_END+61*4)
29 #define HBLANK_CLEAR_H32 (HSYNC_END_H32 + 46*5) 29 #define HBLANK_CLEAR_H32 (HSYNC_END_H32 + 46*5)
30 30
31 int32_t color_map[1 << 12]; 31 int32_t color_map[1 << 12];
32 uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255}; 32 uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255};
33
34 uint8_t debug_base[][3] = {
35 {127, 127, 127}, //BG
36 {0, 0, 127}, //A
37 {127, 0, 0}, //Window
38 {0, 127, 0}, //B
39 {127, 0, 127} //Sprites
40 };
33 41
34 uint8_t color_map_init_done; 42 uint8_t color_map_init_done;
35 43
36 void init_vdp_context(vdp_context * context) 44 void init_vdp_context(vdp_context * context)
37 { 45 {
67 r = levels[color & 0xE]; 75 r = levels[color & 0xE];
68 } 76 }
69 color_map[color] = render_map_color(r, g, b); 77 color_map[color] = render_map_color(r, g, b);
70 } 78 }
71 color_map_init_done = 1; 79 color_map_init_done = 1;
80 }
81 for (uint8_t color = 0; color < (1 << (3 + 1 + 1 + 1)); color++)
82 {
83 uint8_t src = color & DBG_SRC_MASK;
84 if (src > DBG_SRC_S) {
85 context->debugcolors[color] = 0;
86 } else {
87 uint8_t r,g,b;
88 b = debug_base[src][0];
89 g = debug_base[src][1];
90 r = debug_base[src][2];
91 if (color & DBG_PRIORITY)
92 {
93 if (b) {
94 b += 48;
95 }
96 if (g) {
97 g += 48;
98 }
99 if (r) {
100 r += 48;
101 }
102 }
103 if (color & DBG_SHADOW) {
104 b /= 2;
105 g /= 2;
106 r /=2 ;
107 }
108 if (color & DBG_HILIGHT) {
109 if (b) {
110 b += 72;
111 }
112 if (g) {
113 g += 72;
114 }
115 if (r) {
116 r += 72;
117 }
118 }
119 context->debugcolors[color] = render_map_color(r, g, b);
120 }
72 } 121 }
73 } 122 }
74 123
75 void render_sprite_cells(vdp_context * context) 124 void render_sprite_cells(vdp_context * context)
76 { 125 {
685 } else { 734 } else {
686 dst = context->framebuf; 735 dst = context->framebuf;
687 dst += line * 320 + col * 8; 736 dst += line * 320 + col * 8;
688 } 737 }
689 sprite_buf = context->linebuf + col * 8; 738 sprite_buf = context->linebuf + col * 8;
690 uint16_t a_src; 739 uint8_t a_src, src;
691 if (context->flags & FLAG_WINDOW) { 740 if (context->flags & FLAG_WINDOW) {
692 plane_a_off = context->buf_a_off; 741 plane_a_off = context->buf_a_off;
693 //a_src = FBUF_SRC_W; 742 a_src = DBG_SRC_W;
694 } else { 743 } else {
695 plane_a_off = context->buf_a_off - (context->hscroll_a & 0xF); 744 plane_a_off = context->buf_a_off - (context->hscroll_a & 0xF);
696 //a_src = FBUF_SRC_A; 745 a_src = DBG_SRC_A;
697 } 746 }
698 plane_b_off = context->buf_b_off - (context->hscroll_b & 0xF); 747 plane_b_off = context->buf_b_off - (context->hscroll_b & 0xF);
699 uint16_t src;
700 //printf("A | tmp_buf offset: %d\n", 8 - (context->hscroll_a & 0x7)); 748 //printf("A | tmp_buf offset: %d\n", 8 - (context->hscroll_a & 0x7));
701 749
702 if (context->regs[REG_MODE_4] & BIT_HILIGHT) { 750 if (context->regs[REG_MODE_4] & BIT_HILIGHT) {
703 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { 751 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) {
704 uint8_t pixel; 752 uint8_t pixel;
705 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); 753 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK);
706 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); 754 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK);
755 uint32_t * colors = context->colors;
707 src = 0; 756 src = 0;
708 uint8_t sprite_color = *sprite_buf & 0x3F; 757 uint8_t sprite_color = *sprite_buf & 0x3F;
709 if (sprite_color == 0x3E || sprite_color == 0x3F) { 758 if (sprite_color == 0x3E || sprite_color == 0x3F) {
710 if (sprite_color == 0x3F) { 759 if (sprite_color == 0x3F) {
711 src = CRAM_SIZE;//FBUF_SHADOW; 760 colors += CRAM_SIZE;
761 src = DBG_SHADOW;
712 } else { 762 } else {
713 src = CRAM_SIZE*2;//FBUF_HILIGHT; 763 colors += CRAM_SIZE*2;
764 src = DBG_HILIGHT;
714 } 765 }
715 if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) { 766 if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
716 pixel = *plane_a; 767 pixel = *plane_a;
717 //src |= a_src; 768 src |= a_src;
718 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) { 769 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
719 pixel = *plane_b; 770 pixel = *plane_b;
720 //src |= FBUF_SRC_B; 771 src |= DBG_SRC_B;
721 } else if (*plane_a & 0xF) { 772 } else if (*plane_a & 0xF) {
722 pixel = *plane_a; 773 pixel = *plane_a;
723 //src |= a_src; 774 src |= a_src;
724 } else if (*plane_b & 0xF){ 775 } else if (*plane_b & 0xF){
725 pixel = *plane_b; 776 pixel = *plane_b;
726 //src |= FBUF_SRC_B; 777 src |= DBG_SRC_B;
727 } else { 778 } else {
728 pixel = context->regs[REG_BG_COLOR] & 0x3F; 779 pixel = context->regs[REG_BG_COLOR] & 0x3F;
729 //src |= FBUF_SRC_BG; 780 src |= DBG_SRC_BG;
730 } 781 }
731 } else { 782 } else {
732 if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) { 783 if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) {
733 pixel = *sprite_buf; 784 pixel = *sprite_buf;
734 //src = FBUF_SRC_S; 785 src = DBG_SRC_S;
735 } else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) { 786 } else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
736 pixel = *plane_a; 787 pixel = *plane_a;
737 //src = a_src; 788 src = a_src;
738 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) { 789 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
739 pixel = *plane_b; 790 pixel = *plane_b;
740 //src = FBUF_SRC_B; 791 src = DBG_SRC_B;
741 } else { 792 } else {
742 if (!(*plane_a & BUF_BIT_PRIORITY || *plane_a & BUF_BIT_PRIORITY)) { 793 if (!(*plane_a & BUF_BIT_PRIORITY || *plane_a & BUF_BIT_PRIORITY)) {
743 src = CRAM_SIZE;//FBUF_SHADOW; 794 colors += CRAM_SIZE;
795 src = DBG_SHADOW;
744 } 796 }
745 if (*sprite_buf & 0xF) { 797 if (*sprite_buf & 0xF) {
746 pixel = *sprite_buf; 798 pixel = *sprite_buf;
747 if (*sprite_buf & 0xF == 0xE) { 799 if (*sprite_buf & 0xF == 0xE) {
748 src = 0;//FBUF_SRC_S; 800 colors = context->colors;
749 } /*else { 801 src = DBG_SRC_S;
750 src |= FBUF_SRC_S; 802 } else {
751 }*/ 803 src |= DBG_SRC_S;
804 }
752 } else if (*plane_a & 0xF) { 805 } else if (*plane_a & 0xF) {
753 pixel = *plane_a; 806 pixel = *plane_a;
754 //src |= a_src; 807 src |= a_src;
755 } else if (*plane_b & 0xF){ 808 } else if (*plane_b & 0xF){
756 pixel = *plane_b; 809 pixel = *plane_b;
757 //src |= FBUF_SRC_B; 810 src |= DBG_SRC_B;
758 } else { 811 } else {
759 pixel = context->regs[REG_BG_COLOR] & 0x3F; 812 pixel = context->regs[REG_BG_COLOR] & 0x3F;
760 //src |= FBUF_SRC_BG; 813 src |= DBG_SRC_BG;
761 } 814 }
762 } 815 }
763 } 816 }
764 pixel &= 0x3F; 817 pixel &= 0x3F;
765 pixel += src; 818 uint32_t outpixel;
819 if (context->debug) {
820 outpixel = context->debugcolors[src];
821 } else {
822 outpixel = colors[pixel];
823 }
766 if (context->b32) { 824 if (context->b32) {
767 *(dst32++) = context->colors[pixel]; 825 *(dst32++) = outpixel;
768 } else { 826 } else {
769 *(dst++) = context->colors[pixel]; 827 *(dst++) = outpixel;
770 } 828 }
771 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src; 829 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src;
772 } 830 }
773 } else { 831 } else {
774 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { 832 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) {
775 uint8_t pixel; 833 uint8_t pixel;
834 src = 0;
776 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); 835 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK);
777 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); 836 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK);
778 if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) { 837 if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) {
779 pixel = *sprite_buf; 838 pixel = *sprite_buf;
780 //src = FBUF_SRC_S; 839 src = DBG_SRC_S;
781 } else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) { 840 } else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
782 pixel = *plane_a; 841 pixel = *plane_a;
783 //src = a_src; 842 src = a_src;
784 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) { 843 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
785 pixel = *plane_b; 844 pixel = *plane_b;
786 //src = FBUF_SRC_B; 845 src = DBG_SRC_B;
787 } else if (*sprite_buf & 0xF) { 846 } else if (*sprite_buf & 0xF) {
788 pixel = *sprite_buf; 847 pixel = *sprite_buf;
789 //src = FBUF_SRC_S; 848 src = DBG_SRC_S;
790 } else if (*plane_a & 0xF) { 849 } else if (*plane_a & 0xF) {
791 pixel = *plane_a; 850 pixel = *plane_a;
792 //src = a_src; 851 src = a_src;
793 } else if (*plane_b & 0xF){ 852 } else if (*plane_b & 0xF){
794 pixel = *plane_b; 853 pixel = *plane_b;
795 //src = FBUF_SRC_B; 854 src = DBG_SRC_B;
796 } else { 855 } else {
797 pixel = context->regs[REG_BG_COLOR] & 0x3F; 856 pixel = context->regs[REG_BG_COLOR] & 0x3F;
798 //src = FBUF_SRC_BG; 857 src = DBG_SRC_BG;
858 }
859 uint32_t outpixel;
860 if (context->debug) {
861 outpixel = context->debugcolors[src];
862 } else {
863 outpixel = context->colors[pixel & 0x3F];
799 } 864 }
800 if (context->b32) { 865 if (context->b32) {
801 *(dst32++) = context->colors[pixel & 0x3F]; 866 *(dst32++) = outpixel;
802 } else { 867 } else {
803 *(dst++) = context->colors[pixel & 0x3F]; 868 *(dst++) = outpixel;
804 } 869 }
805 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src; 870 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src;
806 } 871 }
807 } 872 }
808 } else { 873 } else {