Mercurial > repos > blastem
annotate cd_graphics.c @ 2075:983f57d08eff
Fix a couple of CDD bugs
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Jan 2022 19:05:54 -0800 |
parents | 598017ef4b0d |
children | c3241eff3c3a |
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 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 if (stamp_x > max || stamp_y > max) { |
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: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 tmp = pixel_y; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 pixel_y = pixel_mask - pixel_x; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 pixel_x = pixel_mask - tmp; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 case 3: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 tmp = pixel_y; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 pixel_y = pixel_mask - pixel_x; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 pixel_x = tmp; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 } |
2071
598017ef4b0d
Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents:
2069
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 switch (pixel_x & 3) |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 default: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 case 0: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 return word >> 12; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 case 1: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 return word >> 8 & 0xF; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 case 2: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 return word >> 4 & 0xF; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 case 3: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 return word & 0xF; |
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 |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 enum { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 FETCH_X, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 FETCH_Y, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 FETCH_DX, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 FETCH_DY, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 PIXEL0, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 PIXEL1, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 PIXEL2, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 PIXEL3, |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 DRAW |
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 |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 void draw_pixels(segacd_context *cd) |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 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
|
128 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 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
|
130 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
|
131 dst_address += cd->graphics_dst_x >> 2 & 1; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 dst_address += ((cd->graphics_dst_x >> 3) * cd->gate_array[GA_IMAGE_BUFFER_VCELLS]) << 4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 pixel &= src_mask_check; |
2069
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 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
|
139 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 case 0: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 //priority mode off |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 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
|
143 cd->word_ram[dst_address] |= pixel; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 case 1: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 //underwrite |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 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
|
148 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
|
149 cd->word_ram[dst_address] |= pixel; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 case 3: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 //overwrite |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 if (pixel) { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 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
|
156 cd->word_ram[dst_address] |= pixel; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
2071
598017ef4b0d
Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents:
2069
diff
changeset
|
160 cd->graphics_dst_x++; |
2069
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 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
|
163 cd->graphics_dst_y++; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 --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
|
165 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
|
166 cd->graphics_step = FETCH_X; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } else { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 cd->graphics_step = PIXEL0; |
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 |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 #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
|
173 #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
|
174 |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 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
|
176 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 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
|
178 return; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 while (cd->graphics_cycle < cycle) |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 switch (cd->graphics_step) |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 case FETCH_X: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 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
|
186 cd->graphics_cycle += 3*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 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
|
188 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 case FETCH_Y: |
2071
598017ef4b0d
Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents:
2069
diff
changeset
|
190 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
|
191 cd->graphics_cycle += 2*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 case FETCH_DX: |
2071
598017ef4b0d
Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents:
2069
diff
changeset
|
194 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
|
195 if (cd->graphics_dx & 0x8000) { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 cd->graphics_dx |= 0xFF0000; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 cd->graphics_cycle += 2*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 case FETCH_DY: |
2071
598017ef4b0d
Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents:
2069
diff
changeset
|
201 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
|
202 if (cd->graphics_dy & 0x8000) { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 cd->graphics_dy |= 0xFF0000; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 cd->graphics_cycle += 2*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 case PIXEL0: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 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
|
209 cd->graphics_cycle += 2*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 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
|
211 cd->graphics_step = DRAW; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 CHECK_ONLY; |
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; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 } else { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 case PIXEL2: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 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
|
227 cd->graphics_cycle += 2*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 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
|
229 cd->graphics_step = DRAW; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 CHECK_ONLY; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } else { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 case PIXEL3: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 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
|
236 cd->graphics_cycle += 2*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 CHECK_CYCLES; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 case DRAW: |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 draw_pixels(cd); |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 cd->graphics_cycle += 1*4; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 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
|
242 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 CHECK_ONLY; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 } |
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 } |
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 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
|
250 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 while (cd->graphics_cycle < cycle) |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 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
|
254 do_graphics(cd, cycle); |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 //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
|
256 //deal with that here for now |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 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
|
258 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 if (cd->graphics_cycle >= cd->graphics_int_cycle) { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 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
|
262 break; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 } else { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 cd->graphics_cycle = cycle; |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
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 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 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
|
270 { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 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
|
272 printf("grahpics start @ %u\n", cd->graphics_cycle); |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 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
|
274 //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
|
275 // 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
|
276 //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
|
277 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
|
278 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
|
279 uint32_t hoffset = 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
|
280 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
|
281 cd->graphics_dst_y = 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
|
282 } else { |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 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
|
284 } |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 |
8e51c0c3f2e3
Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 } |