annotate cd_graphics.c @ 2077:c3241eff3c3a

Sega CD graphics processor output now looks correct for some operations
author Michael Pavone <pavone@retrodev.com>
date Mon, 31 Jan 2022 22:07:51 -0800
parents 598017ef4b0d
children 8665d8da0e1c
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
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
61 //printf("src pixel (%u, %u = BLANK) stamp (%u, %u = %X), def %X\n", x, y, stamp_x, stamp_y, address, stamp_def);
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
62 return 0;
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
63 }
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 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
65 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
66 if (stamp_def & BIT_HFLIP) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 pixel_x = pixel_mask - pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 uint16_t tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 switch (stamp_def >> 13 & 3)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 case 0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 case 1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 tmp = pixel_y;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 pixel_y = pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 pixel_x = pixel_mask - tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 case 2:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 tmp = pixel_y;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 pixel_y = pixel_mask - pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 pixel_x = pixel_mask - tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 case 3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 tmp = pixel_y;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 pixel_y = pixel_mask - pixel_x;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 pixel_x = tmp;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
90 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
91 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
92 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
93 uint16_t word = cd->word_ram[pixel_address];
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
94 //printf("src pixel (%u, %u = %X) stamp (%u, %u = %X), def %X\n", x, y, pixel_address, stamp_x, stamp_y, address, stamp_def);
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 switch (pixel_x & 3)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 default:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 case 0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 return word >> 12;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 case 1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 return word >> 8 & 0xF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 case 2:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 return word >> 4 & 0xF;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 case 3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 return word & 0xF;
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 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 enum {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 FETCH_X,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 FETCH_Y,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 FETCH_DX,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 FETCH_DY,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 PIXEL0,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 PIXEL1,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 PIXEL2,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 PIXEL3,
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 DRAW
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
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 void draw_pixels(segacd_context *cd)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 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
125 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
126 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
127 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
128 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 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
130 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 pixel &= src_mask_check;
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
140 //printf("dst (%u, %u = %X)\n", cd->graphics_dst_x, cd->graphics_dst_y, dst_address);
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 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
142 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 case 0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 //priority mode off
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 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
146 cd->word_ram[dst_address] |= pixel;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 case 1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 //underwrite
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 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
151 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
152 cd->word_ram[dst_address] |= pixel;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 case 3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 //overwrite
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 if (pixel) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 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
159 cd->word_ram[dst_address] |= pixel;
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 break;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 }
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
163 cd->graphics_dst_x++;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 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
166 cd->graphics_dst_y++;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 --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
168 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
169 cd->graphics_step = FETCH_X;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 cd->graphics_step = PIXEL0;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
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
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 #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
176 #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
177
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 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
179 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 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
181 return;
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 while (cd->graphics_cycle < cycle)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 switch (cd->graphics_step)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 case FETCH_X:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 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
189 cd->graphics_cycle += 3*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 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
191 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 case FETCH_Y:
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
193 cd->graphics_y = cd->word_ram[(cd->gate_array[GA_TRACE_VECTOR_BASE] << 1) + 1] << 8;
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
194 //printf("Fetching line start (%u, %u) from %X for dst y %u, %u lines remain\n", cd->graphics_x, cd->graphics_y, cd->gate_array[GA_TRACE_VECTOR_BASE] << 1, cd->graphics_dst_y, cd->gate_array[GA_IMAGE_BUFFER_LINES]);
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 case FETCH_DX:
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
198 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
199 if (cd->graphics_dx & 0x8000) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 cd->graphics_dx |= 0xFF0000;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 case FETCH_DY:
2071
598017ef4b0d Fix a few sega cd graphics processor bugs
Michael Pavone <pavone@retrodev.com>
parents: 2069
diff changeset
205 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
206 if (cd->graphics_dy & 0x8000) {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 cd->graphics_dy |= 0xFF0000;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 }
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 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 case PIXEL0:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 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
213 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 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
215 cd->graphics_step = DRAW;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 CHECK_ONLY;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 case PIXEL1:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 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
222 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 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
224 cd->graphics_step = DRAW;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 CHECK_ONLY;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 case PIXEL2:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 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
231 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 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
233 cd->graphics_step = DRAW;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 CHECK_ONLY;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 }
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 case PIXEL3:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 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
240 cd->graphics_cycle += 2*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 CHECK_CYCLES;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 case DRAW:
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 draw_pixels(cd);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 cd->graphics_cycle += 1*4;
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 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
246 break;
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 CHECK_ONLY;
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
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 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
254 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 while (cd->graphics_cycle < cycle)
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 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
258 do_graphics(cd, cycle);
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 //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
260 //deal with that here for now
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 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
262 {
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 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
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;
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
284 printf("graphics start @ %u, %u lines, %u hdots\n", cd->graphics_cycle, lines, hdots);
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;
2077
c3241eff3c3a Sega CD graphics processor output now looks correct for some operations
Michael Pavone <pavone@retrodev.com>
parents: 2071
diff changeset
287 cd->graphics_step = FETCH_X;
2069
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
288 } else {
8e51c0c3f2e3 Initial attempt at implementing the Sega CD graphics hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 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
290 }
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 }