From a662d26e2957acdcd506f641cd0983e99bfc576f Mon Sep 17 00:00:00 2001 From: fulivi Date: Sun, 21 May 2017 19:24:11 +0200 Subject: [PATCH] floppy: Fix for a segfault when emulating HP9895 drive [F.Ulivi] --- src/devices/imagedev/floppy.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index cacd4b6bda5..313ecc6ceb5 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -737,7 +737,14 @@ uint32_t floppy_image_device::find_position(attotime &base, const attotime &when base -= rev_time; } - return (delta*floppy_ratio_1).as_ticks(1000000000/1000); + uint32_t res = (delta*floppy_ratio_1).as_ticks(1000000000/1000); + if (res > 200000000) { + // Due to rounding errors in the previous operation, + // 'res' sometimes overflows 2E+8 + res -= 200000000; + base += rev_time; + } + return res; } attotime floppy_image_device::get_next_index_time(std::vector &buf, int index, int delta, attotime base)