comparison vdp.c @ 505:b7b7a1cab44a

The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
author Michael Pavone <pavone@retrodev.com>
date Mon, 06 Jan 2014 22:54:05 -0800
parents eee6be465c47
children 1495179d6737
comparison
equal deleted inserted replaced
504:7b0df1aaf384 505:b7b7a1cab44a
48 void init_vdp_context(vdp_context * context) 48 void init_vdp_context(vdp_context * context)
49 { 49 {
50 memset(context, 0, sizeof(*context)); 50 memset(context, 0, sizeof(*context));
51 context->vdpmem = malloc(VRAM_SIZE); 51 context->vdpmem = malloc(VRAM_SIZE);
52 memset(context->vdpmem, 0, VRAM_SIZE); 52 memset(context->vdpmem, 0, VRAM_SIZE);
53 /*context->oddbuf = context->framebuf = malloc(FRAMEBUF_ENTRIES * (render_depth() / 8)); 53 /*
54 memset(context->framebuf, 0, FRAMEBUF_ENTRIES * (render_depth() / 8));
55 context->evenbuf = malloc(FRAMEBUF_ENTRIES * (render_depth() / 8));
56 memset(context->evenbuf, 0, FRAMEBUF_ENTRIES * (render_depth() / 8));
57 */ 54 */
58 render_alloc_surfaces(context); 55 if (headless) {
56 context->oddbuf = context->framebuf = malloc(FRAMEBUF_ENTRIES * (32 / 8));
57 memset(context->framebuf, 0, FRAMEBUF_ENTRIES * (32 / 8));
58 context->evenbuf = malloc(FRAMEBUF_ENTRIES * (32 / 8));
59 memset(context->evenbuf, 0, FRAMEBUF_ENTRIES * (32 / 8));
60 context->b32 = 1;
61 } else {
62 render_alloc_surfaces(context);
63 context->b32 = render_depth() == 32;
64 }
59 context->framebuf = context->oddbuf; 65 context->framebuf = context->oddbuf;
60 context->linebuf = malloc(LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2); 66 context->linebuf = malloc(LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2);
61 memset(context->linebuf, 0, LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2); 67 memset(context->linebuf, 0, LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2);
62 context->tmp_buf_a = context->linebuf + LINEBUF_SIZE; 68 context->tmp_buf_a = context->linebuf + LINEBUF_SIZE;
63 context->tmp_buf_b = context->tmp_buf_a + SCROLL_BUFFER_SIZE; 69 context->tmp_buf_b = context->tmp_buf_a + SCROLL_BUFFER_SIZE;
64 context->sprite_draws = MAX_DRAWS; 70 context->sprite_draws = MAX_DRAWS;
65 context->fifo_write = 0; 71 context->fifo_write = 0;
66 context->fifo_read = -1; 72 context->fifo_read = -1;
67 context->b32 = render_depth() == 32; 73
68 if (!color_map_init_done) { 74 if (!color_map_init_done) {
69 uint8_t b,g,r; 75 uint8_t b,g,r;
70 for (uint16_t color = 0; color < (1 << 12); color++) { 76 for (uint16_t color = 0; color < (1 << 12); color++) {
71 if (color & FBUF_SHADOW) { 77 if (color & FBUF_SHADOW) {
72 b = levels[(color >> 9) & 0x7]; 78 b = levels[(color >> 9) & 0x7];
227 printf("\n**Misc Group**\n" 233 printf("\n**Misc Group**\n"
228 "07: %.2X | Backdrop Color: $%X\n" 234 "07: %.2X | Backdrop Color: $%X\n"
229 "0A: %.2X | H-Int Counter: %u\n" 235 "0A: %.2X | H-Int Counter: %u\n"
230 "0F: %.2X | Auto-increment: $%X\n" 236 "0F: %.2X | Auto-increment: $%X\n"
231 "10: %.2X | Scroll A/B Size: %sx%s\n", 237 "10: %.2X | Scroll A/B Size: %sx%s\n",
232 context->regs[REG_BG_COLOR], context->regs[REG_BG_COLOR] & 0x3F, 238 context->regs[REG_BG_COLOR], context->regs[REG_BG_COLOR],
233 context->regs[REG_HINT], context->regs[REG_HINT], 239 context->regs[REG_HINT], context->regs[REG_HINT],
234 context->regs[REG_AUTOINC], context->regs[REG_AUTOINC], 240 context->regs[REG_AUTOINC], context->regs[REG_AUTOINC],
235 context->regs[REG_SCROLL], sizes[context->regs[REG_SCROLL] & 0x3], sizes[context->regs[REG_SCROLL] >> 4 & 0x3]); 241 context->regs[REG_SCROLL], sizes[context->regs[REG_SCROLL] & 0x3], sizes[context->regs[REG_SCROLL] >> 4 & 0x3]);
236 printf("\n**Internal Group**\n" 242 printf("\n**Internal Group**\n"
237 "Address: %X\n" 243 "Address: %X\n"
747 uint8_t pixel; 753 uint8_t pixel;
748 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); 754 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK);
749 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); 755 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK);
750 uint32_t * colors = context->colors; 756 uint32_t * colors = context->colors;
751 src = 0; 757 src = 0;
752 uint8_t sprite_color = *sprite_buf & 0x3F; 758 pixel = context->regs[REG_BG_COLOR];
753 if (sprite_color == 0x3E || sprite_color == 0x3F) { 759 src = DBG_SRC_BG;
754 if (sprite_color == 0x3F) { 760 if (*plane_b & 0xF) {
761 pixel = *plane_b;
762 src = DBG_SRC_B;
763 }
764 if (*plane_a & 0xF && (*plane_a & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) {
765 pixel = *plane_a;
766 src = DBG_SRC_A;
767 }
768 if (*sprite_buf & 0xF) {
769 uint8_t sprite_color = *sprite_buf & 0x3F;
770 if (sprite_color == 0x3E) {
771 colors += CRAM_SIZE*2;
772 src |= DBG_HILIGHT;
773 } else if (sprite_color == 0x3F) {
755 colors += CRAM_SIZE; 774 colors += CRAM_SIZE;
756 src = DBG_SHADOW; 775 src |= DBG_SHADOW;
757 } else { 776 } else if ((*sprite_buf & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) {
758 colors += CRAM_SIZE*2;
759 src = DBG_HILIGHT;
760 }
761 if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
762 pixel = *plane_a;
763 src |= a_src;
764 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
765 pixel = *plane_b;
766 src |= DBG_SRC_B;
767 } else if (*plane_a & 0xF) {
768 pixel = *plane_a;
769 src |= a_src;
770 } else if (*plane_b & 0xF){
771 pixel = *plane_b;
772 src |= DBG_SRC_B;
773 } else {
774 pixel = context->regs[REG_BG_COLOR] & 0x3F;
775 src |= DBG_SRC_BG;
776 }
777 } else {
778 if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) {
779 pixel = *sprite_buf; 777 pixel = *sprite_buf;
780 src = DBG_SRC_S; 778 src = DBG_SRC_S;
781 } else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) { 779 if ((pixel & 0xF) == 0xE) {
782 pixel = *plane_a; 780 src |= DBG_SHADOW;
783 src = a_src;
784 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
785 pixel = *plane_b;
786 src = DBG_SRC_B;
787 } else {
788 if (!(*plane_a & BUF_BIT_PRIORITY || *plane_a & BUF_BIT_PRIORITY)) {
789 colors += CRAM_SIZE; 781 colors += CRAM_SIZE;
790 src = DBG_SHADOW;
791 } 782 }
792 if (*sprite_buf & 0xF) { 783
793 pixel = *sprite_buf;
794 if (*sprite_buf & 0xF == 0xE) {
795 colors = context->colors;
796 src = DBG_SRC_S;
797 } else {
798 src |= DBG_SRC_S;
799 }
800 } else if (*plane_a & 0xF) {
801 pixel = *plane_a;
802 src |= a_src;
803 } else if (*plane_b & 0xF){
804 pixel = *plane_b;
805 src |= DBG_SRC_B;
806 } else {
807 pixel = context->regs[REG_BG_COLOR] & 0x3F;
808 src |= DBG_SRC_BG;
809 }
810 } 784 }
785 } else if (!((*plane_a | *plane_b) & BUF_BIT_PRIORITY)) {
786 colors += CRAM_SIZE;
787 src |= DBG_SHADOW;
811 } 788 }
812 pixel &= 0x3F; 789 pixel &= 0x3F;
813 uint32_t outpixel; 790 uint32_t outpixel;
814 if (context->debug) { 791 if (context->debug) {
815 outpixel = context->debugcolors[src]; 792 outpixel = context->debugcolors[src];
823 } 800 }
824 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src; 801 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src;
825 } 802 }
826 } else { 803 } else {
827 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { 804 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) {
828 uint8_t pixel;
829 src = 0;
830 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); 805 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK);
831 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); 806 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK);
832 if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) { 807 uint8_t pixel = context->regs[REG_BG_COLOR];
808 src = DBG_SRC_BG;
809 if (*plane_b & 0xF) {
810 pixel = *plane_b;
811 src = DBG_SRC_B;
812 }
813 if (*plane_a & 0xF && (*plane_a & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) {
814 pixel = *plane_a;
815 src = DBG_SRC_A;
816 }
817 if (*sprite_buf & 0xF && (*sprite_buf & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) {
833 pixel = *sprite_buf; 818 pixel = *sprite_buf;
834 src = DBG_SRC_S; 819 src = DBG_SRC_S;
835 } else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
836 pixel = *plane_a;
837 src = a_src;
838 } else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
839 pixel = *plane_b;
840 src = DBG_SRC_B;
841 } else if (*sprite_buf & 0xF) {
842 pixel = *sprite_buf;
843 src = DBG_SRC_S;
844 } else if (*plane_a & 0xF) {
845 pixel = *plane_a;
846 src = a_src;
847 } else if (*plane_b & 0xF){
848 pixel = *plane_b;
849 src = DBG_SRC_B;
850 } else {
851 pixel = context->regs[REG_BG_COLOR] & 0x3F;
852 src = DBG_SRC_BG;
853 } 820 }
854 uint32_t outpixel; 821 uint32_t outpixel;
855 if (context->debug) { 822 if (context->debug) {
856 outpixel = context->debugcolors[src]; 823 outpixel = context->debugcolors[src];
857 } else { 824 } else {
860 if (context->b32) { 827 if (context->b32) {
861 *(dst32++) = outpixel; 828 *(dst32++) = outpixel;
862 } else { 829 } else {
863 *(dst++) = outpixel; 830 *(dst++) = outpixel;
864 } 831 }
865 //*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src; 832 }
866 } 833 }
867 }
868 } else {
869 //dst = context->framebuf + line * 320;
870 //sprite_buf = context->linebuf + col * 8;
871 //plane_a = context->tmp_buf_a + 16 - (context->hscroll_a & 0x7);
872 //plane_b = context->tmp_buf_b + 16 - (context->hscroll_b & 0x7);
873 //end = dst + 8;
874 } 834 }
875 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; 835 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK;
876 context->buf_b_off = (context->buf_b_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; 836 context->buf_b_off = (context->buf_b_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK;
877 } 837 }
878 838
1241 } 1201 }
1242 external_slot(context); 1202 external_slot(context);
1243 if (context->flags & FLAG_DMA_RUN) { 1203 if (context->flags & FLAG_DMA_RUN) {
1244 run_dma_src(context, 0); 1204 run_dma_src(context, 0);
1245 } 1205 }
1246 } else { 1206 for (int i = 0; i < 19; i++)
1247 render_sprite_cells(context); 1207 {
1248 render_sprite_cells(context); 1208 scan_sprite_table(line, context);
1249 render_sprite_cells(context); 1209 }
1250 render_sprite_cells(context); 1210 external_slot(context);
1251 } 1211 for (int i = 0; i < 21; i++)
1212 {
1213 scan_sprite_table(line, context);
1214 }
1215 //reverse context slot counter so it counts the number of sprite slots
1216 //filled rather than the number of available slots
1217 //context->slot_counter = MAX_SPRITES_LINE - context->slot_counter;
1218 context->cur_slot = MAX_SPRITES_LINE-1;
1219 context->sprite_draws = MAX_DRAWS;
1220 context->flags &= (~FLAG_CAN_MASK & ~FLAG_MASKED);
1221 for (int column = 2; column < 42; column += 8)
1222 {
1223 external_slot(context);
1224 if (context->flags & FLAG_DMA_RUN) {
1225 run_dma_src(context, 0);
1226 }
1227 read_sprite_x(line, context);
1228
1229 external_slot(context);
1230 if (context->flags & FLAG_DMA_RUN) {
1231 run_dma_src(context, 0);
1232 }
1233 read_sprite_x(line, context);
1234
1235 external_slot(context);
1236 if (context->flags & FLAG_DMA_RUN) {
1237 run_dma_src(context, 0);
1238 }
1239 read_sprite_x(line, context);
1240
1241 read_sprite_x(line, context);
1242 }
1243 external_slot(context);
1244 if (context->flags & FLAG_DMA_RUN) {
1245 run_dma_src(context, 0);
1246 }
1247 external_slot(context);
1248 return;
1249 }
1250
1251 render_sprite_cells(context);
1252 render_sprite_cells(context);
1253 render_sprite_cells(context);
1254 render_sprite_cells(context);
1252 context->sprite_index = 0x80; 1255 context->sprite_index = 0x80;
1253 context->slot_counter = MAX_SPRITES_LINE; 1256 context->slot_counter = MAX_SPRITES_LINE;
1254 for (int i = 0; i < 19; i++) 1257 for (int i = 0; i < 19; i++)
1255 { 1258 {
1256 render_sprite_cells(context); 1259 render_sprite_cells(context);
1282 render_sprite_cells(context); 1285 render_sprite_cells(context);
1283 scan_sprite_table(line, context); 1286 scan_sprite_table(line, context);
1284 render_sprite_cells(context); 1287 render_sprite_cells(context);
1285 scan_sprite_table(line, context); 1288 scan_sprite_table(line, context);
1286 1289
1287 render_sprite_cells(context);
1288 scan_sprite_table(line, context);
1289 read_map_scroll_a(0, line, context); 1290 read_map_scroll_a(0, line, context);
1290 render_sprite_cells(context); 1291 render_sprite_cells(context);
1291 scan_sprite_table(line, context); 1292 scan_sprite_table(line, context);
1292 render_map_1(context); 1293 render_map_1(context);
1293 scan_sprite_table(line, context);//Just a guess 1294 scan_sprite_table(line, context);//Just a guess
1389 starti = (line-1)*320 + x; 1390 starti = (line-1)*320 + x;
1390 } 1391 }
1391 } 1392 }
1392 if (starti >= 0) { 1393 if (starti >= 0) {
1393 if (context->b32) { 1394 if (context->b32) {
1394 uint32_t color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 1395 uint32_t color = context->colors[context->regs[REG_BG_COLOR]];
1395 uint32_t * start = context->framebuf; 1396 uint32_t * start = context->framebuf;
1396 start += starti; 1397 start += starti;
1397 for (int i = 0; i < 2; i++) { 1398 for (int i = 0; i < 2; i++) {
1398 *(start++) = color; 1399 *(start++) = color;
1399 } 1400 }
1400 } else { 1401 } else {
1401 uint16_t color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; 1402 uint16_t color = context->colors[context->regs[REG_BG_COLOR]];
1402 uint16_t * start = context->framebuf; 1403 uint16_t * start = context->framebuf;
1403 start += starti; 1404 start += starti;
1404 for (int i = 0; i < 2; i++) { 1405 for (int i = 0; i < 2; i++) {
1405 *(start++) = color; 1406 *(start++) = color;
1406 } 1407 }
1623 if (reg < (context->regs[REG_MODE_2] & BIT_MODE_5 ? VDP_REGS : 0xA)) { 1624 if (reg < (context->regs[REG_MODE_2] & BIT_MODE_5 ? VDP_REGS : 0xA)) {
1624 //printf("register %d set to %X\n", reg, value & 0xFF); 1625 //printf("register %d set to %X\n", reg, value & 0xFF);
1625 if (reg == REG_MODE_1 && (value & BIT_HVC_LATCH) && !(context->regs[reg] & BIT_HVC_LATCH)) { 1626 if (reg == REG_MODE_1 && (value & BIT_HVC_LATCH) && !(context->regs[reg] & BIT_HVC_LATCH)) {
1626 context->hv_latch = vdp_hv_counter_read(context); 1627 context->hv_latch = vdp_hv_counter_read(context);
1627 } 1628 }
1629 if (reg == REG_BG_COLOR) {
1630 value &= 0x3F;
1631 }
1628 context->regs[reg] = value; 1632 context->regs[reg] = value;
1629 if (reg == REG_MODE_4) { 1633 if (reg == REG_MODE_4) {
1630 context->double_res = (value & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES); 1634 context->double_res = (value & (BIT_INTERLACE | BIT_DOUBLE_RES)) == (BIT_INTERLACE | BIT_DOUBLE_RES);
1631 if (!context->double_res) { 1635 if (!context->double_res) {
1632 context->framebuf = context->oddbuf; 1636 context->framebuf = context->oddbuf;