comparison vdp.h @ 2053:3414a4423de1 segacd

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 15 Jan 2022 13:15:21 -0800
parents a61b47d5489e
children 01ff005b08f6
comparison
equal deleted inserted replaced
1692:5dacaef602a7 2053:3414a4423de1
14 #define VDP_REGS 24 14 #define VDP_REGS 24
15 #define CRAM_SIZE 64 15 #define CRAM_SIZE 64
16 #define SHADOW_OFFSET CRAM_SIZE 16 #define SHADOW_OFFSET CRAM_SIZE
17 #define HIGHLIGHT_OFFSET (SHADOW_OFFSET+CRAM_SIZE) 17 #define HIGHLIGHT_OFFSET (SHADOW_OFFSET+CRAM_SIZE)
18 #define MODE4_OFFSET (HIGHLIGHT_OFFSET+CRAM_SIZE) 18 #define MODE4_OFFSET (HIGHLIGHT_OFFSET+CRAM_SIZE)
19 #define VSRAM_SIZE 40 19 #define MIN_VSRAM_SIZE 40
20 #define MAX_VSRAM_SIZE 64
20 #define VRAM_SIZE (64*1024) 21 #define VRAM_SIZE (64*1024)
21 #define BORDER_LEFT 13 22 #define BORDER_LEFT 13
22 #define BORDER_RIGHT 14 23 #define BORDER_RIGHT 14
23 #define HORIZ_BORDER (BORDER_LEFT+BORDER_RIGHT) 24 #define HORIZ_BORDER (BORDER_LEFT+BORDER_RIGHT)
24 #define LINEBUF_SIZE (320+HORIZ_BORDER) //H40 + full border 25 #define LINEBUF_SIZE (320+HORIZ_BORDER) //H40 + full border
25 #define SCROLL_BUFFER_SIZE 32 26 #define SCROLL_BUFFER_SIZE 32
26 #define BORDER_BOTTOM 13 //TODO: Replace with actual value 27 #define BORDER_BOTTOM 13 //TODO: Replace with actual value
27 #define MAX_DRAWS 40
28 #define MAX_DRAWS_H32 32
29 #define MAX_DRAWS_H32_MODE4 8 28 #define MAX_DRAWS_H32_MODE4 8
30 #define MAX_SPRITES_LINE 20 29 #define MAX_SPRITES_LINE 20
31 #define MAX_SPRITES_LINE_H32 16 30 #define MAX_SPRITES_LINE_H32 16
32 #define MAX_SPRITES_FRAME 80 31 #define MAX_SPRITES_FRAME 80
33 #define MAX_SPRITES_FRAME_H32 64 32 #define MAX_SPRITES_FRAME_H32 64
53 #define FLAG_MASKED 0x04 52 #define FLAG_MASKED 0x04
54 #define FLAG_WINDOW 0x08 53 #define FLAG_WINDOW 0x08
55 #define FLAG_PENDING 0x10 54 #define FLAG_PENDING 0x10
56 #define FLAG_READ_FETCHED 0x20 55 #define FLAG_READ_FETCHED 0x20
57 #define FLAG_DMA_RUN 0x40 56 #define FLAG_DMA_RUN 0x40
58 #define FLAG_DMA_PROG 0x80 57 #define FLAG_WINDOW_EDGE 0x80
59 58
60 #define FLAG2_VINT_PENDING 0x01 59 #define FLAG2_VINT_PENDING 0x01
61 #define FLAG2_HINT_PENDING 0x02 60 #define FLAG2_HINT_PENDING 0x02
62 #define FLAG2_READ_PENDING 0x04 61 #define FLAG2_READ_PENDING 0x04
63 #define FLAG2_SPRITE_COLLIDE 0x08 62 #define FLAG2_SPRITE_COLLIDE 0x08
90 REG_WINDOW_V, 89 REG_WINDOW_V,
91 REG_DMALEN_L, 90 REG_DMALEN_L,
92 REG_DMALEN_H, 91 REG_DMALEN_H,
93 REG_DMASRC_L, 92 REG_DMASRC_L,
94 REG_DMASRC_M, 93 REG_DMASRC_M,
95 REG_DMASRC_H 94 REG_DMASRC_H,
96 } vdp_regs; 95 REG_KMOD_CTRL=29,
96 REG_KMOD_MSG,
97 REG_KMOD_TIMER
98 };
97 99
98 //Mode reg 1 100 //Mode reg 1
99 #define BIT_VSCRL_LOCK 0x80 101 #define BIT_VSCRL_LOCK 0x80
100 #define BIT_HSCRL_LOCK 0x40 102 #define BIT_HSCRL_LOCK 0x40
101 #define BIT_COL0_MASK 0x20 103 #define BIT_COL0_MASK 0x20
114 #define BIT_PAL 0x08 116 #define BIT_PAL 0x08
115 #define BIT_MODE_5 0x04 117 #define BIT_MODE_5 0x04
116 #define BIT_SPRITE_SZ 0x02 118 #define BIT_SPRITE_SZ 0x02
117 119
118 //Mode reg 3 120 //Mode reg 3
119 #define BIT_EINT_EN 0x10 121 #define BIT_EINT_EN 0x08
120 #define BIT_VSCROLL 0x04 122 #define BIT_VSCROLL 0x04
121 123
122 //Mode reg 4 124 //Mode reg 4
123 #define BIT_H40 0x01 125 #define BIT_H40 0x01
124 #define BIT_HILIGHT 0x8 126 #define BIT_HILIGHT 0x8
131 typedef struct { 133 typedef struct {
132 uint16_t address; 134 uint16_t address;
133 int16_t x_pos; 135 int16_t x_pos;
134 uint8_t pal_priority; 136 uint8_t pal_priority;
135 uint8_t h_flip; 137 uint8_t h_flip;
138 uint8_t width;
139 uint8_t height;
136 } sprite_draw; 140 } sprite_draw;
137 141
138 typedef struct { 142 typedef struct {
139 uint8_t size; 143 uint8_t size;
140 uint8_t index; 144 uint8_t index;
161 165
162 typedef struct { 166 typedef struct {
163 system_header *system; 167 system_header *system;
164 //pointer to current line in framebuffer 168 //pointer to current line in framebuffer
165 uint32_t *output; 169 uint32_t *output;
166 uint32_t *done_output;
167 //pointer to current framebuffer 170 //pointer to current framebuffer
168 uint32_t *fb; 171 uint32_t *fb;
172 uint8_t *done_composite;
169 uint32_t *debug_fbs[VDP_NUM_DEBUG_TYPES]; 173 uint32_t *debug_fbs[VDP_NUM_DEBUG_TYPES];
174 char *kmod_msg_buffer;
175 uint32_t kmod_buffer_storage;
176 uint32_t kmod_buffer_length;
177 uint32_t timer_start_cycle;
170 uint32_t output_pitch; 178 uint32_t output_pitch;
171 uint32_t debug_fb_pitch[VDP_NUM_DEBUG_TYPES]; 179 uint32_t debug_fb_pitch[VDP_NUM_DEBUG_TYPES];
172 fifo_entry fifo[FIFO_SIZE]; 180 fifo_entry fifo[FIFO_SIZE];
173 int32_t fifo_write; 181 int32_t fifo_write;
174 int32_t fifo_read; 182 int32_t fifo_read;
175 uint32_t address; 183 uint32_t address;
184 uint32_t address_latch;
176 uint32_t serial_address; 185 uint32_t serial_address;
177 uint32_t colors[CRAM_SIZE*4]; 186 uint32_t colors[CRAM_SIZE*4];
178 uint32_t debugcolors[1 << (3 + 1 + 1 + 1)];//3 bits for source, 1 bit for priority, 1 bit for shadow, 1 bit for hilight 187 uint32_t debugcolors[1 << (3 + 1 + 1 + 1)];//3 bits for source, 1 bit for priority, 1 bit for shadow, 1 bit for hilight
179 uint16_t cram[CRAM_SIZE]; 188 uint16_t cram[CRAM_SIZE];
180 uint32_t frame; 189 uint32_t frame;
190 uint32_t vsram_size;
181 uint8_t cd; 191 uint8_t cd;
192 uint8_t cd_latch;
182 uint8_t flags; 193 uint8_t flags;
183 uint8_t regs[VDP_REGS]; 194 uint8_t regs[VDP_REGS];
184 //cycle count in MCLKs 195 //cycle count in MCLKs
185 uint32_t cycles; 196 uint32_t cycles;
186 uint32_t pending_vint_start; 197 uint32_t pending_vint_start;
187 uint32_t pending_hint_start; 198 uint32_t pending_hint_start;
188 uint16_t vsram[VSRAM_SIZE]; 199 uint32_t top_offset;
200 uint16_t vsram[MAX_VSRAM_SIZE];
189 uint16_t vscroll_latch[2]; 201 uint16_t vscroll_latch[2];
190 uint16_t vcounter; 202 uint16_t vcounter;
191 uint16_t inactive_start; 203 uint16_t inactive_start;
192 uint16_t border_top; 204 uint16_t border_top;
193 uint16_t border_bot; 205 uint16_t border_bot;
194 uint16_t hscroll_a; 206 uint16_t hscroll_a;
207 uint16_t hscroll_a_fine;
195 uint16_t hscroll_b; 208 uint16_t hscroll_b;
209 uint16_t hscroll_b_fine;
196 uint16_t h40_lines; 210 uint16_t h40_lines;
197 uint16_t output_lines; 211 uint16_t output_lines;
198 sprite_draw sprite_draw_list[MAX_DRAWS]; 212 sprite_draw sprite_draw_list[MAX_SPRITES_LINE];
199 sprite_info sprite_info_list[MAX_SPRITES_LINE]; 213 sprite_info sprite_info_list[MAX_SPRITES_LINE];
200 uint8_t sat_cache[SAT_CACHE_SIZE]; 214 uint8_t sat_cache[SAT_CACHE_SIZE];
201 uint16_t col_1; 215 uint16_t col_1;
202 uint16_t col_2; 216 uint16_t col_2;
203 uint16_t hv_latch; 217 uint16_t hv_latch;
204 uint16_t prefetch; 218 uint16_t prefetch;
205 uint16_t test_port; 219 uint16_t test_port;
206 //stores 2-bit palette + 4-bit palette index + priority for current sprite line 220 //stores 2-bit palette + 4-bit palette index + priority for current sprite line
207 uint8_t linebuf[LINEBUF_SIZE]; 221 uint8_t linebuf[LINEBUF_SIZE];
222 uint8_t compositebuf[LINEBUF_SIZE];
208 uint8_t layer_debug_buf[LINEBUF_SIZE]; 223 uint8_t layer_debug_buf[LINEBUF_SIZE];
209 uint8_t hslot; //hcounter/2 224 uint8_t hslot; //hcounter/2
210 uint8_t sprite_index; 225 uint8_t sprite_index;
211 uint8_t sprite_draws; 226 uint8_t sprite_draws;
212 int8_t slot_counter; 227 int8_t slot_counter;
213 int8_t cur_slot; 228 int8_t cur_slot;
229 uint8_t sprite_x_offset;
214 uint8_t max_sprites_frame; 230 uint8_t max_sprites_frame;
215 uint8_t max_sprites_line; 231 uint8_t max_sprites_line;
216 uint8_t fetch_tmp[2]; 232 uint8_t fetch_tmp[2];
217 uint8_t v_offset; 233 uint8_t v_offset;
218 uint8_t hint_counter; 234 uint8_t hint_counter;
226 uint8_t tmp_buf_a[SCROLL_BUFFER_SIZE]; 242 uint8_t tmp_buf_a[SCROLL_BUFFER_SIZE];
227 uint8_t tmp_buf_b[SCROLL_BUFFER_SIZE]; 243 uint8_t tmp_buf_b[SCROLL_BUFFER_SIZE];
228 uint8_t enabled_debuggers; 244 uint8_t enabled_debuggers;
229 uint8_t debug_fb_indices[VDP_NUM_DEBUG_TYPES]; 245 uint8_t debug_fb_indices[VDP_NUM_DEBUG_TYPES];
230 uint8_t debug_modes[VDP_NUM_DEBUG_TYPES]; 246 uint8_t debug_modes[VDP_NUM_DEBUG_TYPES];
247 uint8_t pushed_frame;
231 uint8_t vdpmem[]; 248 uint8_t vdpmem[];
232 } vdp_context; 249 } vdp_context;
233 250
234 251
235 252
236 vdp_context *init_vdp_context(uint8_t region_pal); 253 vdp_context *init_vdp_context(uint8_t region_pal, uint8_t has_max_vsram);
237 void vdp_free(vdp_context *context); 254 void vdp_free(vdp_context *context);
238 void vdp_run_context_full(vdp_context * context, uint32_t target_cycles); 255 void vdp_run_context_full(vdp_context * context, uint32_t target_cycles);
239 void vdp_run_context(vdp_context * context, uint32_t target_cycles); 256 void vdp_run_context(vdp_context * context, uint32_t target_cycles);
240 //runs from current cycle count to VBLANK for the current mode, returns ending cycle count 257 //runs from current cycle count to VBLANK for the current mode, returns ending cycle count
241 uint32_t vdp_run_to_vblank(vdp_context * context); 258 uint32_t vdp_run_to_vblank(vdp_context * context);
251 uint16_t vdp_control_port_read(vdp_context * context); 268 uint16_t vdp_control_port_read(vdp_context * context);
252 uint16_t vdp_data_port_read(vdp_context * context); 269 uint16_t vdp_data_port_read(vdp_context * context);
253 uint8_t vdp_data_port_read_pbc(vdp_context * context); 270 uint8_t vdp_data_port_read_pbc(vdp_context * context);
254 void vdp_latch_hv(vdp_context *context); 271 void vdp_latch_hv(vdp_context *context);
255 uint16_t vdp_hv_counter_read(vdp_context * context); 272 uint16_t vdp_hv_counter_read(vdp_context * context);
256 uint16_t vdp_test_port_read(vdp_context * context);
257 void vdp_adjust_cycles(vdp_context * context, uint32_t deduction); 273 void vdp_adjust_cycles(vdp_context * context, uint32_t deduction);
258 uint32_t vdp_next_hint(vdp_context * context); 274 uint32_t vdp_next_hint(vdp_context * context);
259 uint32_t vdp_next_vint(vdp_context * context); 275 uint32_t vdp_next_vint(vdp_context * context);
260 uint32_t vdp_next_vint_z80(vdp_context * context); 276 uint32_t vdp_next_vint_z80(vdp_context * context);
261 uint32_t vdp_next_nmi(vdp_context *context); 277 uint32_t vdp_next_nmi(vdp_context *context);
274 void vdp_force_update_framebuffer(vdp_context *context); 290 void vdp_force_update_framebuffer(vdp_context *context);
275 void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type); 291 void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type);
276 void vdp_inc_debug_mode(vdp_context *context); 292 void vdp_inc_debug_mode(vdp_context *context);
277 //to be implemented by the host system 293 //to be implemented by the host system
278 uint16_t read_dma_value(uint32_t address); 294 uint16_t read_dma_value(uint32_t address);
295 void vdp_replay_event(vdp_context *context, uint8_t event, event_reader *reader);
279 296
280 #endif //VDP_H_ 297 #endif //VDP_H_