From a60ed65fb9c9ccc871ffa7a0ece4278f934ed47e Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 30 Sep 2017 20:02:00 +0300 Subject: [PATCH] Don't count DMA transfers as CPU idle. --- a2091.cpp | 1 + custom.cpp | 6 +++++- filesys.cpp | 23 ++++++++++++++--------- hardfile.cpp | 2 ++ include/newcpu.h | 1 + ncr9x_scsi.cpp | 8 ++++++++ newcpu.cpp | 19 ++++++++++++++----- scsi.cpp | 2 ++ 8 files changed, 47 insertions(+), 15 deletions(-) diff --git a/a2091.cpp b/a2091.cpp index 60c57d72..61c1b694 100644 --- a/a2091.cpp +++ b/a2091.cpp @@ -889,6 +889,7 @@ static bool do_dma(struct wd_state *wd) { struct scsi_data *scsi = wd->wc.scsi; wd->wc.wd_data_avail = 0; + m68k_cancel_idle(); if (scsi->direction == 0) write_log (_T("%s DMA but no data!?\n"), WD33C93); switch (wd->dmac_type) diff --git a/custom.cpp b/custom.cpp index af4f710c..79327be9 100644 --- a/custom.cpp +++ b/custom.cpp @@ -7806,7 +7806,11 @@ static void vsync_handler_pre (void) #if 1 if (currprefs.m68k_speed < 0) { if (regs.stopped) { - cpu_stopped_lines += maxvpos - cpu_last_stop_vpos; + if (cpu_last_stop_vpos >= 0) { + cpu_stopped_lines += maxvpos - cpu_last_stop_vpos; + } else { + cpu_stopped_lines = 0; + } } int mv = 12 - currprefs.cpu_idle / 15; if (mv >= 1 && mv <= 11) { diff --git a/filesys.cpp b/filesys.cpp index e0092f82..d83d8386 100644 --- a/filesys.cpp +++ b/filesys.cpp @@ -6800,6 +6800,8 @@ end: static int handle_packet(TrapContext *ctx, Unit *unit, dpacket *pck, uae_u32 msg, int isvolume) { + bool noidle = false; + int ret = 1; uae_s32 type = GET_PCK_TYPE (pck); PUT_PCK_RES2 (pck, 0); @@ -6827,13 +6829,13 @@ static int handle_packet(TrapContext *ctx, Unit *unit, dpacket *pck, uae_u32 msg case ACTION_DISK_INFO: action_disk_info (ctx, unit, pck); break; case ACTION_INFO: action_info (ctx, unit, pck); break; case ACTION_EXAMINE_OBJECT: action_examine_object (ctx, unit, pck); break; - case ACTION_EXAMINE_NEXT: action_examine_next (ctx, unit, pck, false); break; + case ACTION_EXAMINE_NEXT: noidle = true; action_examine_next (ctx, unit, pck, false); break; case ACTION_FIND_INPUT: action_find_input (ctx, unit, pck); break; case ACTION_FIND_WRITE: action_find_write (ctx, unit, pck); break; case ACTION_FIND_OUTPUT: action_find_output (ctx, unit, pck); break; case ACTION_END: action_end (ctx, unit, pck); break; - case ACTION_READ: action_read (ctx, unit, pck); break; - case ACTION_WRITE: action_write (ctx, unit, pck); break; + case ACTION_READ: noidle = true; action_read(ctx, unit, pck); break; + case ACTION_WRITE: noidle = true; action_write (ctx, unit, pck); break; case ACTION_SEEK: action_seek (ctx, unit, pck); break; case ACTION_SET_PROTECT: action_set_protect (ctx, unit, pck); break; case ACTION_SET_COMMENT: action_set_comment (ctx, unit, pck); break; @@ -6860,9 +6862,9 @@ static int handle_packet(TrapContext *ctx, Unit *unit, dpacket *pck, uae_u32 msg case ACTION_PARENT_FH: action_parent_fh (ctx, unit, pck); break; case ACTION_ADD_NOTIFY: action_add_notify (ctx, unit, pck); break; case ACTION_REMOVE_NOTIFY: action_remove_notify (ctx, unit, pck); break; - case ACTION_EXAMINE_ALL: return action_examine_all (ctx, unit, pck); - case ACTION_EXAMINE_ALL_END: return action_examine_all_end (ctx, unit, pck); - case ACTION_LOCK_RECORD: return action_lock_record (ctx, unit, pck, msg); break; + case ACTION_EXAMINE_ALL: noidle = true; ret = action_examine_all(ctx, unit, pck); break; + case ACTION_EXAMINE_ALL_END: ret = action_examine_all_end(ctx, unit, pck); break; + case ACTION_LOCK_RECORD: ret = action_lock_record (ctx, unit, pck, msg); break; case ACTION_FREE_RECORD: action_free_record (ctx, unit, pck); break; case ACTION_READ_LINK: action_read_link (ctx, unit, pck); break; case ACTION_MAKE_LINK: action_make_link (ctx, unit, pck); break; @@ -6878,9 +6880,9 @@ static int handle_packet(TrapContext *ctx, Unit *unit, dpacket *pck, uae_u32 msg case ACTION_SEEK64: action_seek64(ctx, unit, pck); break; case ACTION_SET_FILE_SIZE64: action_set_file_size64(ctx, unit, pck); break; case ACTION_EXAMINE_OBJECT64: action_examine_object64(ctx, unit, pck); break; - case ACTION_EXAMINE_NEXT64: action_examine_next(ctx, unit, pck, true); break; + case ACTION_EXAMINE_NEXT64: noidle = true; action_examine_next(ctx, unit, pck, true); break; case ACTION_EXAMINE_FH64: action_examine_fh(ctx, unit, pck, true); break; - case ACTION_LOCK_RECORD64: return action_lock_record64(ctx, unit, pck, msg); break; + case ACTION_LOCK_RECORD64: ret = action_lock_record64(ctx, unit, pck, msg); break; case ACTION_FREE_RECORD64: action_free_record64(ctx, unit, pck); break; /* unsupported packets */ @@ -6891,7 +6893,10 @@ static int handle_packet(TrapContext *ctx, Unit *unit, dpacket *pck, uae_u32 msg write_log (_T("FILESYS: UNKNOWN PACKET %x\n"), type); return 0; } - return 1; + if (noidle) { + m68k_cancel_idle(); + } + return ret; } #ifdef UAE_FILESYS_THREADS diff --git a/hardfile.cpp b/hardfile.cpp index feb3f0db..971c8801 100644 --- a/hardfile.cpp +++ b/hardfile.cpp @@ -1095,6 +1095,7 @@ int hdf_write(struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len) static uae_u64 cmd_readx(struct hardfiledata *hfd, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { + m68k_cancel_idle(); gui_flicker_led (LED_HD, hfd->unitnum, 1); return hdf_read (hfd, dataptr, offset, len); } @@ -1126,6 +1127,7 @@ static uae_u64 cmd_read(TrapContext *ctx, struct hardfiledata *hfd, uaecptr data } static uae_u64 cmd_writex(struct hardfiledata *hfd, uae_u8 *dataptr, uae_u64 offset, uae_u64 len) { + m68k_cancel_idle(); gui_flicker_led (LED_HD, hfd->unitnum, 2); return hdf_write (hfd, dataptr, offset, len); } diff --git a/include/newcpu.h b/include/newcpu.h index 464f0c2f..e3790155 100644 --- a/include/newcpu.h +++ b/include/newcpu.h @@ -595,6 +595,7 @@ extern void REGPARAM3 x_put_bitfield (uae_u32 dst, uae_u32 bdata[2], uae_u32 val extern void m68k_setstopped (void); extern void m68k_resumestopped (void); +extern void m68k_cancel_idle(void); extern uae_u32 REGPARAM3 get_disp_ea_020 (uae_u32 base, int idx) REGPARAM; extern uae_u32 REGPARAM3 get_bitfield (uae_u32 src, uae_u32 bdata[2], uae_s32 offset, int width) REGPARAM; diff --git a/ncr9x_scsi.cpp b/ncr9x_scsi.cpp index 92d60517..ab60175e 100644 --- a/ncr9x_scsi.cpp +++ b/ncr9x_scsi.cpp @@ -438,6 +438,7 @@ static int masoboshi_dma_read(void *opaque, uint8_t *buf, int len) { struct ncr9x_state *ncr = (struct ncr9x_state*)opaque; if (ncr->dma_on) { + m68k_cancel_idle(); while (len > 0) { uae_u16 v = get_word(ncr->dma_ptr & ~1); *buf++ = v >> 8; @@ -462,6 +463,7 @@ static int masoboshi_dma_write(void *opaque, uint8_t *buf, int len) { struct ncr9x_state *ncr = (struct ncr9x_state*)opaque; if (ncr->dma_on) { + m68k_cancel_idle(); while (len > 0) { uae_u16 v; v = *buf++; @@ -494,6 +496,7 @@ static int fastlane_dma_read(void *opaque, uint8_t *buf, int len) write_log(_T("fastlane_dma_read mismatched direction!\n")); return -1; } + m68k_cancel_idle(); while (len > 0) { uae_u16 v = get_word(ncr->dma_ptr & ~1); *buf++ = v >> 8; @@ -513,6 +516,7 @@ static int fastlane_dma_write(void *opaque, uint8_t *buf, int len) write_log(_T("fastlane_dma_write mismatched direction!\n")); return -1; } + m68k_cancel_idle(); while (len > 0) { uae_u16 v; v = *buf++; @@ -535,6 +539,7 @@ static int cyberstorm_mk1_mk2_dma_read(void *opaque, uint8_t *buf, int len) write_log(_T("cyberstorm_dma_read mismatched direction!\n")); return -1; } + m68k_cancel_idle(); while (len > 0) { uae_u16 v = get_word(ncr->dma_ptr & ~1); *buf++ = v >> 8; @@ -554,6 +559,7 @@ static int cyberstorm_mk1_mk2_dma_write(void *opaque, uint8_t *buf, int len) write_log(_T("cyberstorm_dma_write mismatched direction!\n")); return -1; } + m68k_cancel_idle(); while (len > 0) { uae_u16 v; v = *buf++; @@ -576,6 +582,7 @@ static int blizzard_dma_read(void *opaque, uint8_t *buf, int len) write_log(_T("blizzard_dma_read mismatched direction!\n")); return -1; } + m68k_cancel_idle(); while (len > 0) { uae_u16 v = get_word((ncr->dma_ptr & 0x7fffffff) * 2); *buf++ = v >> 8; @@ -595,6 +602,7 @@ static int blizzard_dma_write(void *opaque, uint8_t *buf, int len) write_log(_T("blizzard_dma_write mismatched direction!\n")); return -1; } + m68k_cancel_idle(); while (len > 0) { uae_u16 v; v = *buf++; diff --git a/newcpu.cpp b/newcpu.cpp index 74ab9c2f..40968df3 100644 --- a/newcpu.cpp +++ b/newcpu.cpp @@ -2593,21 +2593,30 @@ STATIC_INLINE int adjust_cycles (int cycles) return cycles + mc; } +void m68k_cancel_idle(void) +{ + cpu_last_stop_vpos = -1; +} + static void m68k_set_stop(void) { if (regs.stopped) return; regs.stopped = 1; set_special(SPCFLAG_STOP); - cpu_last_stop_vpos = vpos; + if (cpu_last_stop_vpos >= 0) { + cpu_last_stop_vpos = vpos; + } } static void m68k_unset_stop(void) { regs.stopped = 0; unset_special(SPCFLAG_STOP); - cpu_stopped_lines += vpos - cpu_last_stop_vpos; - cpu_last_stop_vpos = vpos; + if (cpu_last_stop_vpos >= 0) { + cpu_stopped_lines += vpos - cpu_last_stop_vpos; + cpu_last_stop_vpos = vpos; + } } static void activate_trace(void) @@ -4622,7 +4631,7 @@ static int do_specialties (int cycles) unset_special (SPCFLAG_END_COMPILE); /* has done its job */ #endif - while ((regs.spcflags & SPCFLAG_BLTNASTY) && dmaen (DMA_BLITTER) && cycles > 0 && !currprefs.blitter_cycle_exact) { + while ((regs.spcflags & SPCFLAG_BLTNASTY) && dmaen (DMA_BLITTER) && cycles > 0 && ((currprefs.waiting_blits && currprefs.cpu_model >= 68020) || !currprefs.blitter_cycle_exact)) { int c = blitnasty (); if (c < 0) { break; @@ -5438,8 +5447,8 @@ void cpu_halt (int id) MakeSR (); audio_deactivate (); } - set_special(SPCFLAG_CHECK); } + set_special(SPCFLAG_CHECK); } #ifdef CPUEMU_33 diff --git a/scsi.cpp b/scsi.cpp index b1bd7937..725fe270 100644 --- a/scsi.cpp +++ b/scsi.cpp @@ -1413,6 +1413,8 @@ static void dma_check(struct soft_scsi *ncr) { if (ncr->dmac_active && ncr->dma_direction) { + m68k_cancel_idle(); + if (ncr->type == NCR5380_SUPRA && ncr->subtype == 4) { if (ncr->dmac_direction != ncr->dma_direction) { write_log(_T("SUPRADMA: mismatched direction\n")); -- 2.47.3