comparison blastem.c @ 198:209a37eed3e7

Add support for breaking into the debugger while game is running
author Mike Pavone <pavone@retrodev.com>
date Sun, 20 Jan 2013 19:10:29 -0800
parents 7c227a8ec53d
children 464513050c85
comparison
equal deleted inserted replaced
197:7c227a8ec53d 198:209a37eed3e7
116 context->target_cycle = context->int_cycle; 116 context->target_cycle = context->int_cycle;
117 } 117 }
118 } 118 }
119 } 119 }
120 120
121 m68k_context * sync_components(m68k_context * context) 121 int break_on_sync = 0;
122
123 m68k_context * sync_components(m68k_context * context, uint32_t address)
122 { 124 {
123 //TODO: Handle sync targets smaller than a single frame 125 //TODO: Handle sync targets smaller than a single frame
124 vdp_context * v_context = context->next_context; 126 vdp_context * v_context = context->next_context;
125 uint32_t mclks = context->current_cycle * MCLKS_PER_68K; 127 uint32_t mclks = context->current_cycle * MCLKS_PER_68K;
126 if (mclks >= MCLKS_PER_FRAME) { 128 if (mclks >= MCLKS_PER_FRAME) {
127 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks); 129 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks);
128 vdp_run_context(v_context, MCLKS_PER_FRAME); 130 vdp_run_context(v_context, MCLKS_PER_FRAME);
129 wait_render_frame(v_context); 131 break_on_sync |= wait_render_frame(v_context);
130 mclks -= MCLKS_PER_FRAME; 132 mclks -= MCLKS_PER_FRAME;
131 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); 133 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME);
132 io_adjust_cycles(&gamepad_1, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); 134 io_adjust_cycles(&gamepad_1, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K);
133 io_adjust_cycles(&gamepad_2, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K); 135 io_adjust_cycles(&gamepad_2, context->current_cycle, MCLKS_PER_FRAME/MCLKS_PER_68K);
134 context->current_cycle -= MCLKS_PER_FRAME/MCLKS_PER_68K; 136 context->current_cycle -= MCLKS_PER_FRAME/MCLKS_PER_68K;
138 } else { 140 } else {
139 //printf("running VDP for %d cycles\n", mclks - v_context->cycles); 141 //printf("running VDP for %d cycles\n", mclks - v_context->cycles);
140 vdp_run_context(v_context, mclks); 142 vdp_run_context(v_context, mclks);
141 } 143 }
142 adjust_int_cycle(context, v_context); 144 adjust_int_cycle(context, v_context);
145 if (break_on_sync && address) {
146 break_on_sync = 0;
147 debugger(context, address);
148 }
143 return context; 149 return context;
144 } 150 }
145 151
146 m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value) 152 m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value)
147 { 153 {
148 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); 154 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle);
149 sync_components(context); 155 sync_components(context, 0);
150 vdp_context * v_context = context->next_context; 156 vdp_context * v_context = context->next_context;
151 if (vdp_port < 0x10) { 157 if (vdp_port < 0x10) {
152 int blocked; 158 int blocked;
153 if (vdp_port < 4) { 159 if (vdp_port < 4) {
154 while (vdp_data_port_write(v_context, value) < 0) { 160 while (vdp_data_port_write(v_context, value) < 0) {
199 return context; 205 return context;
200 } 206 }
201 207
202 m68k_context * vdp_port_read(uint32_t vdp_port, m68k_context * context) 208 m68k_context * vdp_port_read(uint32_t vdp_port, m68k_context * context)
203 { 209 {
204 sync_components(context); 210 sync_components(context, 0);
205 vdp_context * v_context = context->next_context; 211 vdp_context * v_context = context->next_context;
206 if (vdp_port < 0x10) { 212 if (vdp_port < 0x10) {
207 if (vdp_port < 4) { 213 if (vdp_port < 4) {
208 context->value = vdp_data_port_read(v_context); 214 context->value = vdp_data_port_read(v_context);
209 } else if(vdp_port < 8) { 215 } else if(vdp_port < 8) {