annotate cd_graphics.c @ 2147:4cd60eecb0b1

Fix LC8951 cycle adjustment for data transfer next byte tracking
author Michael Pavone <pavone@retrodev.com>
date Sat, 26 Mar 2022 20:10:51 -0700
parents da326c32ad8f
children 3ef80963c2a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include "cd_graphics.h"
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "backend.h"
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 void cd_graphics_init(segacd_context *cd)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 cd->graphics_int_cycle = CYCLE_NEVER;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #define BIT_HFLIP 0x8000
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 static uint8_t get_src_pixel(segacd_context *cd)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 uint16_t x = cd->graphics_x >> 11;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 uint16_t y = cd->graphics_y >> 11;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 cd->graphics_x += cd->graphics_dx;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 cd->graphics_x &= 0xFFFFFF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 cd->graphics_y += cd->graphics_dy;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 cd->graphics_y &= 0xFFFFFF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 uint16_t stamp_shift, pixel_mask;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 uint16_t stamp_num_mask;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 if (cd->gate_array[GA_STAMP_SIZE] & BIT_STS) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 //32x32 stamps
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 stamp_shift = 5;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 pixel_mask = 0x1F;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 stamp_num_mask = 0x3FC;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 //16x16 stamps
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 stamp_shift = 4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 pixel_mask = 0xF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 stamp_num_mask = 0x3FF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 uint16_t stamp_x = x >> stamp_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 uint16_t stamp_y = y >> stamp_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 uint16_t max, base_mask;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 uint32_t row_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 if (cd->gate_array[GA_STAMP_SIZE] & BIT_SMS) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 max = 4096 >> stamp_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 base_mask = 0xE000 << ((5 - stamp_shift) << 1);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 //128 stamps in 32x32 mode, 256 stamps in 16x16 mode
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 row_shift = 12 - stamp_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 max = 256 >> stamp_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 base_mask = 0xFFE0 << ((5 - stamp_shift) << 1);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 //8 stamps in 32x32 mode, 16 stamps in 16x16 mode
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 row_shift = 8 - stamp_shift;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 }
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
47 if (stamp_x >= max || stamp_y >= max) {
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 if (cd->gate_array[GA_STAMP_SIZE] & BIT_RPT) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 stamp_x &= max - 1;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 stamp_y &= max - 1;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 return 0;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 uint32_t address = (cd->gate_array[GA_STAMP_MAP_BASE] & base_mask) << 1;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 address += (stamp_y << row_shift) + stamp_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 uint16_t stamp_def = cd->word_ram[address];
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 uint16_t stamp_num = stamp_def & stamp_num_mask;
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
59 if (!stamp_num) {
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
60 //manual says stamp 0 can't be used, I assume that means it's treated as transparent
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
61 return 0;
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
62 }
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 uint16_t pixel_x = x & pixel_mask;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 uint16_t pixel_y = y & pixel_mask;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 if (stamp_def & BIT_HFLIP) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 pixel_x = pixel_mask - pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 uint16_t tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 switch (stamp_def >> 13 & 3)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 case 0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 case 1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 tmp = pixel_y;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 pixel_y = pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 pixel_x = pixel_mask - tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 case 2:
2098
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
79 pixel_y = pixel_mask - pixel_y;
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
80 pixel_x = pixel_mask - pixel_x;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 case 3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 tmp = pixel_y;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 pixel_y = pixel_mask - pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 pixel_x = tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
88 uint16_t cell_x = pixel_x >> 3;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 uint32_t pixel_address = stamp_num << 6;
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
90 pixel_address += (pixel_y << 1) + (cell_x << (stamp_shift + 1)) + (pixel_x >> 2 & 1);
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 uint16_t word = cd->word_ram[pixel_address];
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 switch (pixel_x & 3)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 default:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 case 0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 return word >> 12;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 case 1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 return word >> 8 & 0xF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 case 2:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 return word >> 4 & 0xF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 case 3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 return word & 0xF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 enum {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 FETCH_X,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 FETCH_Y,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 FETCH_DX,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 FETCH_DY,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 PIXEL0,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 PIXEL1,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 PIXEL2,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 PIXEL3,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 DRAW
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 };
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 void draw_pixels(segacd_context *cd)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 uint16_t to_draw = 4 - (cd->graphics_dst_x & 3);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 uint16_t x_end = cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 if (cd->graphics_dst_x + to_draw > x_end) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 to_draw = cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3) - cd->graphics_dst_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 for(uint16_t i = 0; i < to_draw; i++)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 uint32_t dst_address = cd->gate_array[GA_IMAGE_BUFFER_START] << 1;
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
129 dst_address += cd->graphics_dst_y << 1;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 dst_address += cd->graphics_dst_x >> 2 & 1;
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
131 dst_address += ((cd->graphics_dst_x >> 3) * (cd->gate_array[GA_IMAGE_BUFFER_VCELLS] + 1)) << 4;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 uint16_t pixel_shift = 12 - 4 * (cd->graphics_dst_x & 3);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 uint16_t pixel = cd->graphics_pixels[i] << pixel_shift;
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
134 uint16_t src_mask_check = 0xF << pixel_shift;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 uint16_t src_mask_keep = ~src_mask_check;
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
136 pixel &= src_mask_check;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 switch (cd->gate_array[1] >> 3 & 3)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 case 0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 //priority mode off
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 cd->word_ram[dst_address] &= src_mask_keep;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 cd->word_ram[dst_address] |= pixel;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 case 1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 //underwrite
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 if (pixel && ! (cd->word_ram[dst_address] & src_mask_check)) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 cd->word_ram[dst_address] &= src_mask_keep;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 cd->word_ram[dst_address] |= pixel;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 break;
2098
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
151 case 2:
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 //overwrite
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 if (pixel) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 cd->word_ram[dst_address] &= src_mask_keep;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 cd->word_ram[dst_address] |= pixel;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 }
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
159 cd->graphics_dst_x++;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 if (cd->graphics_dst_x == x_end) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 cd->graphics_dst_y++;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 --cd->gate_array[GA_IMAGE_BUFFER_LINES];
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
164 cd->gate_array[GA_TRACE_VECTOR_BASE] += 2;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 cd->graphics_step = FETCH_X;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 cd->graphics_step = PIXEL0;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 #define CHECK_CYCLES cd->graphics_step++; if(cd->graphics_cycle >= cycle) break
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 #define CHECK_ONLY if(cd->graphics_cycle >= cycle) break
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 static void do_graphics(segacd_context *cd, uint32_t cycle)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 if (!cd->gate_array[GA_IMAGE_BUFFER_LINES]) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 return;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 while (cd->graphics_cycle < cycle)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 switch (cd->graphics_step)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 case FETCH_X:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 cd->graphics_x = cd->word_ram[cd->gate_array[GA_TRACE_VECTOR_BASE] << 1] << 8;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 cd->graphics_cycle += 3*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 cd->graphics_dst_x = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 case FETCH_Y:
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
189 cd->graphics_y = cd->word_ram[(cd->gate_array[GA_TRACE_VECTOR_BASE] << 1) + 1] << 8;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 case FETCH_DX:
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
193 cd->graphics_dx = cd->word_ram[(cd->gate_array[GA_TRACE_VECTOR_BASE] << 1) + 2];
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 if (cd->graphics_dx & 0x8000) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 cd->graphics_dx |= 0xFF0000;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 case FETCH_DY:
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
200 cd->graphics_dy = cd->word_ram[(cd->gate_array[GA_TRACE_VECTOR_BASE] << 1) + 3];
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 if (cd->graphics_dy & 0x8000) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 cd->graphics_dy |= 0xFF0000;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 case PIXEL0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 cd->graphics_pixels[0] = get_src_pixel(cd);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 if ((cd->graphics_dst_x & 3) == 3 || (cd->graphics_dst_x + 1 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3))) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 cd->graphics_step = DRAW;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 CHECK_ONLY;
2092
8665d8da0e1c Fix infinite loop in Sega CD graphics coprocessor code
Michael Pavone <pavone@retrodev.com>
parents: 2077
diff changeset
212 goto draw;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 case PIXEL1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 cd->graphics_pixels[1] = get_src_pixel(cd);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 if ((cd->graphics_dst_x & 3) == 2 || (cd->graphics_dst_x + 2 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3))) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 cd->graphics_step = DRAW;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 CHECK_ONLY;
2092
8665d8da0e1c Fix infinite loop in Sega CD graphics coprocessor code
Michael Pavone <pavone@retrodev.com>
parents: 2077
diff changeset
222 goto draw;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
224 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 case PIXEL2:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 cd->graphics_pixels[2] = get_src_pixel(cd);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 if ((cd->graphics_dst_x & 3) == 1 || (cd->graphics_dst_x + 3 == cd->gate_array[GA_IMAGE_BUFFER_HDOTS] + (cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3))) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 cd->graphics_step = DRAW;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 CHECK_ONLY;
2092
8665d8da0e1c Fix infinite loop in Sega CD graphics coprocessor code
Michael Pavone <pavone@retrodev.com>
parents: 2077
diff changeset
232 goto draw;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 case PIXEL3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 cd->graphics_pixels[3] = get_src_pixel(cd);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 CHECK_CYCLES;
2092
8665d8da0e1c Fix infinite loop in Sega CD graphics coprocessor code
Michael Pavone <pavone@retrodev.com>
parents: 2077
diff changeset
240 draw:
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 case DRAW:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 draw_pixels(cd);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 cd->graphics_cycle += 1*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 if (!cd->gate_array[GA_IMAGE_BUFFER_LINES]) {
2098
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
245 return;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 CHECK_ONLY;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 void cd_graphics_run(segacd_context *cd, uint32_t cycle)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 while (cd->graphics_cycle < cycle)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 if (cd->gate_array[GA_STAMP_SIZE] & BIT_GRON) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 do_graphics(cd, cycle);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
258 //end calculation and actual emulated execution time probably don't 100% line up yet
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 //deal with that here for now
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 for(; cd->graphics_cycle < cycle; cd->graphics_cycle += 4)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
263 if (cd->graphics_cycle >= cd->graphics_int_cycle) {
2098
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
264 printf("graphics end %u\n", cd->graphics_cycle);
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 cd->gate_array[GA_STAMP_SIZE] &= ~BIT_GRON;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 cd->graphics_cycle = cycle;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
272 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 void cd_graphics_start(segacd_context *cd)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
275 if (!(cd->gate_array[GA_STAMP_SIZE] & BIT_GRON)) {
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
276
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
277 cd->gate_array[GA_STAMP_SIZE] |= BIT_GRON;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
278 //Manual scan is bad, but formula appears to be
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
279 // vsize * (13 + 2 * hoffset + 9 * (hdots + hoffset - 1))
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
280 //with an additional 13? cycle setup cost per line
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281 uint32_t lines = cd->gate_array[GA_IMAGE_BUFFER_LINES];
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
282 uint32_t hdots = cd->gate_array[GA_IMAGE_BUFFER_HDOTS];
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
283 uint32_t hoffset = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] & 3;
2098
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
284 uint16_t pm = cd->gate_array[1] >> 3 & 3;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
285 cd->graphics_int_cycle = cd->graphics_cycle + 4 * lines * (13 + 2 * hoffset + 9 * (hdots + hoffset - 1));
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
286 cd->graphics_dst_y = cd->gate_array[GA_IMAGE_BUFFER_OFFSET] >> 3;
2098
da326c32ad8f Fix some bugs in the Sega CD graphics coprocessor
Michael Pavone <pavone@retrodev.com>
parents: 2092
diff changeset
287 printf("graphics start @ %u, %u lines, %u hdots, pm = %u, hoff = %u, voff = %u, addr = %X\n", cd->graphics_cycle, lines, hdots, pm, hoffset, cd->graphics_dst_y, cd->gate_array[GA_IMAGE_BUFFER_START]);
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
288 cd->graphics_step = FETCH_X;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 printf("graphics start ignored @ %u\n", cd->graphics_cycle);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
292
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
293 }