comparison vdp.c @ 1640:3602f3b20072

Small cleanup of vdp_context struct layout and removal of separately allocated buffers
author Michael Pavone <pavone@retrodev.com>
date Fri, 16 Nov 2018 19:56:24 -0800
parents 93518786f882
children bc9bb4e5856f
comparison
equal deleted inserted replaced
1639:93518786f882 1640:3602f3b20072
17 #define BUF_BIT_PRIORITY 0x40 17 #define BUF_BIT_PRIORITY 0x40
18 #define MAP_BIT_PRIORITY 0x8000 18 #define MAP_BIT_PRIORITY 0x8000
19 #define MAP_BIT_H_FLIP 0x800 19 #define MAP_BIT_H_FLIP 0x800
20 #define MAP_BIT_V_FLIP 0x1000 20 #define MAP_BIT_V_FLIP 0x1000
21 21
22 #define SCROLL_BUFFER_SIZE 32
23 #define SCROLL_BUFFER_MASK (SCROLL_BUFFER_SIZE-1) 22 #define SCROLL_BUFFER_MASK (SCROLL_BUFFER_SIZE-1)
24 #define SCROLL_BUFFER_DRAW (SCROLL_BUFFER_SIZE/2) 23 #define SCROLL_BUFFER_DRAW (SCROLL_BUFFER_SIZE/2)
25 24
26 #define MCLKS_SLOT_H40 16 25 #define MCLKS_SLOT_H40 16
27 #define MCLKS_SLOT_H32 20 26 #define MCLKS_SLOT_H32 20
136 } 135 }
137 } 136 }
138 137
139 static uint8_t color_map_init_done; 138 static uint8_t color_map_init_done;
140 139
141 void init_vdp_context(vdp_context * context, uint8_t region_pal) 140 vdp_context *init_vdp_context(uint8_t region_pal)
142 { 141 {
143 memset(context, 0, sizeof(*context)); 142 vdp_context *context = calloc(1, sizeof(vdp_context) + VRAM_SIZE);
144 context->vdpmem = malloc(VRAM_SIZE);
145 memset(context->vdpmem, 0, VRAM_SIZE);
146 /*
147 */
148 if (headless) { 143 if (headless) {
149 context->output = malloc(LINEBUF_SIZE * sizeof(uint32_t)); 144 context->output = malloc(LINEBUF_SIZE * sizeof(uint32_t));
150 context->output_pitch = 0; 145 context->output_pitch = 0;
151 } else { 146 } else {
152 context->cur_buffer = FRAMEBUFFER_ODD; 147 context->cur_buffer = FRAMEBUFFER_ODD;
153 context->fb = render_get_framebuffer(FRAMEBUFFER_ODD, &context->output_pitch); 148 context->fb = render_get_framebuffer(FRAMEBUFFER_ODD, &context->output_pitch);
154 } 149 }
155 context->linebuf = malloc(LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2);
156 memset(context->linebuf, 0, LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2);
157 context->tmp_buf_a = context->linebuf + LINEBUF_SIZE;
158 context->tmp_buf_b = context->tmp_buf_a + SCROLL_BUFFER_SIZE;
159 context->sprite_draws = MAX_DRAWS; 150 context->sprite_draws = MAX_DRAWS;
160 context->fifo_write = 0; 151 context->fifo_write = 0;
161 context->fifo_read = -1; 152 context->fifo_read = -1;
162 context->regs[REG_HINT] = context->hint_counter = 0xFF; 153 context->regs[REG_HINT] = context->hint_counter = 0xFF;
163 154
248 } 239 }
249 update_video_params(context); 240 update_video_params(context);
250 if (!headless) { 241 if (!headless) {
251 context->output = (uint32_t *)(((char *)context->fb) + context->output_pitch * context->border_top); 242 context->output = (uint32_t *)(((char *)context->fb) + context->output_pitch * context->border_top);
252 } 243 }
244 return context;
253 } 245 }
254 246
255 void vdp_free(vdp_context *context) 247 void vdp_free(vdp_context *context)
256 { 248 {
257 free(context->vdpmem);
258 free(context->linebuf);
259 free(context); 249 free(context);
260 } 250 }
261 251
262 static int is_refresh(vdp_context * context, uint32_t slot) 252 static int is_refresh(vdp_context * context, uint32_t slot)
263 { 253 {