Mercurial > repos > blastem
comparison blastem.c @ 534:c641006da28e
Properly sync hardware when frame end is reached during DMA
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 13 Feb 2014 00:10:36 -0800 |
parents | 46a60bb5f785 |
children | a3afee2271ce 66cc60215e5c |
comparison
equal
deleted
inserted
replaced
533:e7df1b24394a | 534:c641006da28e |
---|---|
317 gen->bus_busy = 1; | 317 gen->bus_busy = 1; |
318 while (vdp_data_port_write(v_context, value) < 0) { | 318 while (vdp_data_port_write(v_context, value) < 0) { |
319 while(v_context->flags & FLAG_DMA_RUN) { | 319 while(v_context->flags & FLAG_DMA_RUN) { |
320 vdp_run_dma_done(v_context, mclks_per_frame); | 320 vdp_run_dma_done(v_context, mclks_per_frame); |
321 if (v_context->cycles >= mclks_per_frame) { | 321 if (v_context->cycles >= mclks_per_frame) { |
322 if (!headless) { | 322 context->current_cycle = v_context->cycles / MCLKS_PER_68K; |
323 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, v_context->cycles); | 323 if (context->current_cycle * MCLKS_PER_68K < mclks_per_frame) { |
324 wait_render_frame(v_context, frame_limit); | 324 ++context->current_cycle; |
325 } else if(exit_after){ | |
326 --exit_after; | |
327 if (!exit_after) { | |
328 exit(0); | |
329 } | |
330 } | 325 } |
331 vdp_adjust_cycles(v_context, mclks_per_frame); | 326 sync_components(context, 0); |
332 genesis_context * gen = context->system; | |
333 io_adjust_cycles(gen->ports, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); | |
334 io_adjust_cycles(gen->ports+1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); | |
335 io_adjust_cycles(gen->ports+2, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); | |
336 if (busack_cycle != CYCLE_NEVER) { | |
337 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { | |
338 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; | |
339 } else { | |
340 busack_cycle = CYCLE_NEVER; | |
341 busack = new_busack; | |
342 } | |
343 } | |
344 } | 327 } |
345 } | 328 } |
346 //context->current_cycle = v_context->cycles / MCLKS_PER_68K; | 329 //context->current_cycle = v_context->cycles / MCLKS_PER_68K; |
347 } | 330 } |
348 } else if(vdp_port < 8) { | 331 } else if(vdp_port < 8) { |
351 if (blocked) { | 334 if (blocked) { |
352 while (blocked) { | 335 while (blocked) { |
353 while(v_context->flags & FLAG_DMA_RUN) { | 336 while(v_context->flags & FLAG_DMA_RUN) { |
354 vdp_run_dma_done(v_context, mclks_per_frame); | 337 vdp_run_dma_done(v_context, mclks_per_frame); |
355 if (v_context->cycles >= mclks_per_frame) { | 338 if (v_context->cycles >= mclks_per_frame) { |
356 if (!headless) { | 339 context->current_cycle = v_context->cycles / MCLKS_PER_68K; |
357 wait_render_frame(v_context, frame_limit); | 340 if (context->current_cycle * MCLKS_PER_68K < mclks_per_frame) { |
358 } else if(exit_after){ | 341 ++context->current_cycle; |
359 --exit_after; | |
360 if (!exit_after) { | |
361 exit(0); | |
362 } | |
363 } | 342 } |
364 vdp_adjust_cycles(v_context, mclks_per_frame); | 343 sync_components(context, 0); |
365 genesis_context * gen = context->system; | |
366 io_adjust_cycles(gen->ports, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); | |
367 io_adjust_cycles(gen->ports+1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); | |
368 io_adjust_cycles(gen->ports+2, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); | |
369 if (busack_cycle != CYCLE_NEVER) { | |
370 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { | |
371 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; | |
372 } else { | |
373 busack_cycle = CYCLE_NEVER; | |
374 busack = new_busack; | |
375 } | |
376 } | |
377 } | 344 } |
378 } | 345 } |
379 if (blocked < 0) { | 346 if (blocked < 0) { |
380 blocked = vdp_control_port_write(v_context, value); | 347 blocked = vdp_control_port_write(v_context, value); |
381 } else { | 348 } else { |