Fixed a bug where SameBoy freezes for a while after leaving turbo mode

This commit is contained in:
Lior Halphon 2018-03-27 23:33:31 +03:00
parent fd2e169dc9
commit 4cf78139a8
1 changed files with 3 additions and 2 deletions

View File

@ -61,8 +61,9 @@ void GB_timing_sync(GB_gameboy_t *gb)
uint64_t target_nanoseconds = gb->cycles_since_last_sync * 1000000000LL / 2 / GB_get_clock_rate(gb); /* / 2 because we use 8MHz units */ uint64_t target_nanoseconds = gb->cycles_since_last_sync * 1000000000LL / 2 / GB_get_clock_rate(gb); /* / 2 because we use 8MHz units */
int64_t nanoseconds = get_nanoseconds(); int64_t nanoseconds = get_nanoseconds();
if (labs((signed long)(nanoseconds - gb->last_sync)) < target_nanoseconds ) { int64_t time_to_sleep = target_nanoseconds + gb->last_sync - nanoseconds;
nsleep(target_nanoseconds + gb->last_sync - nanoseconds); if (time_to_sleep > 0 && time_to_sleep < LCDC_PERIOD * 1000000000LL / GB_get_clock_rate(gb)) {
nsleep(time_to_sleep);
gb->last_sync += target_nanoseconds; gb->last_sync += target_nanoseconds;
} }
else { else {