@@ -5323,13 +5323,15 @@ static INLINE void video_driver_scanline_before_frame(video_driver_state_t *vide
53235323 uint16_t frame_time_target ,
53245324 uint16_t core_run_time )
53255325{
5326- uint16_t video_height = video_st -> height ;
5327- int16_t scanline_next = video_st -> scanline [SCANLINE_NEXT ];
5328- int16_t scanline_hold = video_st -> scanline [SCANLINE_HOLD ];
5329- int16_t scanline = video_driver_scanline_get ();
5326+ uint16_t video_height = video_st -> height ;
5327+ int16_t scanline_next = video_st -> scanline [SCANLINE_NEXT ];
5328+ int16_t scanline_hold = video_st -> scanline [SCANLINE_HOLD ];
5329+ int16_t scanline_blank = video_st -> scanline [SCANLINE_TOTAL ] - video_height ;
5330+ int16_t scanline = video_driver_scanline_get ();
53305331
5331- /* Assume at least some usage in menu */
5332- core_run_time = core_run_time < 1000 ? 1000 : core_run_time ;
5332+ /* Minimum usage is vblank */
5333+ uint16_t min_run_time = (scanline_blank > 0 ) ? (double )scanline_blank / (double )video_height * (double )frame_time_target : 1000 ;
5334+ core_run_time = (core_run_time < min_run_time ) ? min_run_time : core_run_time ;
53335335
53345336 /* Disable if unsupported */
53355337 if (scanline < 0 )
@@ -5357,8 +5359,7 @@ static INLINE void video_driver_scanline_before_frame(video_driver_state_t *vide
53575359 /* Allow change */
53585360 if (!scanline_hold )
53595361 {
5360- int16_t scanline_blank = video_st -> scanline [SCANLINE_TOTAL ] - video_height ;
5361- int16_t corelines = video_height * ((double )core_run_time / (double )frame_time_target );
5362+ int16_t corelines = video_height * ((double )core_run_time / (double )frame_time_target );
53625363
53635364 /* Fine-tuning */
53645365 if ( scanline > - scanline_blank
@@ -5400,7 +5401,9 @@ static INLINE void video_driver_scanline_after_frame(video_driver_state_t *video
54005401 uint16_t video_height = video_st -> height ;
54015402 int16_t scanline_next = video_st -> scanline [SCANLINE_NEXT ];
54025403 int16_t scanline_total = video_st -> scanline [SCANLINE_TOTAL ];
5404+ int16_t scanline_blank = video_st -> scanline [SCANLINE_TOTAL ] - video_height ;
54035405 int16_t scanline_target = (scanline_next < 0 ) ? video_height + scanline_next : scanline_next ;
5406+ uint16_t min_run_time = (scanline_blank > 0 ) ? (double )scanline_blank / (double )video_height * (double )frame_time_target : 1000 ;
54045407 bool init = (!scanline_total ) ? true : false;
54055408 bool wait = true;
54065409
@@ -5412,6 +5415,9 @@ static INLINE void video_driver_scanline_after_frame(video_driver_state_t *video
54125415 if (scanline_next == 1 )
54135416 scanline_target = video_height - 1 ;
54145417
5418+ /* Minimum usage is vblank */
5419+ core_run_time = (core_run_time < min_run_time ) ? min_run_time : core_run_time ;
5420+
54155421 /* Use CPU friendlier sleep as much as possible */
54165422 if (wait && frame_time_target > core_run_time )
54175423 {
0 commit comments