comparison genesis.c @ 1775:a9fc826c6a9d mame_interp

Make refresh delay emulation play nice with Musashi
author Michael Pavone <pavone@retrodev.com>
date Wed, 13 Mar 2019 18:57:11 -0700
parents 0a26f3657295
children 5358a7126b96
comparison
equal deleted inserted replaced
1774:ddcd59a6122e 1775:a9fc826c6a9d
346 346
347 //TODO: move this inside the system context 347 //TODO: move this inside the system context
348 static uint32_t last_frame_num; 348 static uint32_t last_frame_num;
349 349
350 //My refresh emulation isn't currently good enough and causes more problems than it solves 350 //My refresh emulation isn't currently good enough and causes more problems than it solves
351 //#define REFRESH_EMULATION 351 #define REFRESH_EMULATION
352 #ifdef REFRESH_EMULATION 352 #ifdef REFRESH_EMULATION
353 #define REFRESH_INTERVAL 128 353 #define REFRESH_INTERVAL 128
354 #define REFRESH_DELAY 2 354 #define REFRESH_DELAY 2
355 uint32_t last_sync_cycle; 355 uint32_t last_sync_cycle;
356 uint32_t refresh_counter; 356 uint32_t refresh_counter;
364 { 364 {
365 genesis_context * gen = context->system; 365 genesis_context * gen = context->system;
366 vdp_context * v_context = gen->vdp; 366 vdp_context * v_context = gen->vdp;
367 z80_context * z_context = gen->z80; 367 z80_context * z_context = gen->z80;
368 #ifdef REFRESH_EMULATION 368 #ifdef REFRESH_EMULATION
369 //lame estimation of refresh cycle delay 369 if (context->current_cycle != last_sync_cycle) {
370 refresh_counter += context->current_cycle - last_sync_cycle; 370 //lame estimation of refresh cycle delay
371 if (!gen->bus_busy) { 371 refresh_counter += context->current_cycle - last_sync_cycle;
372 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); 372 if (!gen->bus_busy) {
373 } 373 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
374 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); 374 }
375 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
376 }
375 #endif 377 #endif
376 378
377 uint32_t mclks = context->current_cycle; 379 uint32_t mclks = context->current_cycle;
378 sync_z80(z_context, mclks); 380 sync_z80(z_context, mclks);
379 sync_sound(gen, mclks); 381 sync_sound(gen, mclks);
490 } 492 }
491 vdp_port &= 0x1F; 493 vdp_port &= 0x1F;
492 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); 494 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle);
493 #ifdef REFRESH_EMULATION 495 #ifdef REFRESH_EMULATION
494 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access 496 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access
495 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; 497 if (context->current_cycle - 4*MCLKS_PER_68K > last_sync_cycle) {
496 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); 498 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
497 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); 499 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
498 last_sync_cycle = context->current_cycle; 500 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
501 last_sync_cycle = context->current_cycle;
502 }
499 #endif 503 #endif
500 sync_components(context, 0); 504 sync_components(context, 0);
501 genesis_context * gen = context->system; 505 genesis_context * gen = context->system;
502 vdp_context *v_context = gen->vdp; 506 vdp_context *v_context = gen->vdp;
503 uint32_t before_cycle = v_context->cycles; 507 uint32_t before_cycle = v_context->cycles;
628 fatal_error("machine freeze due to read from address %X\n", 0xC00000 | vdp_port); 632 fatal_error("machine freeze due to read from address %X\n", 0xC00000 | vdp_port);
629 } 633 }
630 vdp_port &= 0x1F; 634 vdp_port &= 0x1F;
631 uint16_t value; 635 uint16_t value;
632 #ifdef REFRESH_EMULATION 636 #ifdef REFRESH_EMULATION
633 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access 637 if (context->current_cycle - 4*MCLKS_PER_68K > last_sync_cycle) {
634 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; 638 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access
635 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); 639 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle;
636 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); 640 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
637 last_sync_cycle = context->current_cycle; 641 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
642 last_sync_cycle = context->current_cycle;
643 }
638 #endif 644 #endif
639 sync_components(context, 0); 645 sync_components(context, 0);
640 genesis_context *gen = context->system; 646 genesis_context *gen = context->system;
641 vdp_context * v_context = gen->vdp; 647 vdp_context * v_context = gen->vdp;
642 uint32_t before_cycle = v_context->cycles; 648 uint32_t before_cycle = v_context->cycles;