comparison blastem.c @ 149:139e5dcd6aa3

Make writes to control and data port block when DMA is in progress
author Mike Pavone <pavone@retrodev.com>
date Tue, 01 Jan 2013 07:06:57 -0800
parents 177ba1a5af9c
children 42c031184e8a
comparison
equal deleted inserted replaced
148:4a400aec81bb 149:139e5dcd6aa3
113 { 113 {
114 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); 114 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle);
115 sync_components(context); 115 sync_components(context);
116 vdp_context * v_context = context->next_context; 116 vdp_context * v_context = context->next_context;
117 if (vdp_port < 0x10) { 117 if (vdp_port < 0x10) {
118 int blocked;
118 if (vdp_port < 4) { 119 if (vdp_port < 4) {
119 vdp_data_port_write(v_context, value); 120 while (vdp_data_port_write(v_context, value) < 0) {
120 } else if(vdp_port < 8) {
121 int blocked = vdp_control_port_write(v_context, value);
122 if (blocked) {
123 while(v_context->flags & FLAG_DMA_RUN) { 121 while(v_context->flags & FLAG_DMA_RUN) {
124 vdp_run_dma_done(v_context, MCLKS_PER_FRAME); 122 vdp_run_dma_done(v_context, MCLKS_PER_FRAME);
125 if (v_context->cycles >= MCLKS_PER_FRAME) { 123 if (v_context->cycles >= MCLKS_PER_FRAME) {
126 wait_render_frame(v_context); 124 wait_render_frame(v_context);
127 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME); 125 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME);
128 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); 126 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K);
129 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K); 127 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K);
128 }
129 }
130 context->current_cycle = v_context->cycles / MCLKS_PER_68K;
131 }
132 } else if(vdp_port < 8) {
133 blocked = vdp_control_port_write(v_context, value);
134 if (blocked) {
135 while (blocked) {
136 while(v_context->flags & FLAG_DMA_RUN) {
137 vdp_run_dma_done(v_context, MCLKS_PER_FRAME);
138 if (v_context->cycles >= MCLKS_PER_FRAME) {
139 wait_render_frame(v_context);
140 vdp_adjust_cycles(v_context, MCLKS_PER_FRAME);
141 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K);
142 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, MCLKS_PER_FRAME/MCLKS_PER_68K);
143 }
144 }
145 if (blocked < 0) {
146 blocked = vdp_control_port_write(v_context, value);
147 } else {
148 blocked = 0;
130 } 149 }
131 } 150 }
132 context->current_cycle = v_context->cycles / MCLKS_PER_68K; 151 context->current_cycle = v_context->cycles / MCLKS_PER_68K;
133 } else { 152 } else {
134 if (v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) { 153 if (v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) {