From da0c958f2bf269baa00665384b5f5c6837babad1 Mon Sep 17 00:00:00 2001 From: yz70s Date: Sun, 17 Jan 2016 12:53:31 +0100 Subject: [PATCH] atapihle.cpp: try to fix a problem when m_buffer_size is not a multiple of sector size (nw) When reading sectors using the packet command, if the "Byte count limit" is not a multiple of the sector size, only a subset of the data will be transferred. It happens sometimes with the xbox. --- src/devices/machine/atapihle.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/devices/machine/atapihle.cpp b/src/devices/machine/atapihle.cpp index 993b1739018..c2802d51229 100644 --- a/src/devices/machine/atapihle.cpp +++ b/src/devices/machine/atapihle.cpp @@ -97,9 +97,13 @@ void atapi_hle_device::fill_buffer() { m_buffer_size = m_data_size; } - else if (m_buffer_size & 1) + else { - m_buffer_size--; + if (m_buffer_size & 1) + m_buffer_size--; + // if it is transferring less than the remaining data, make sure the size is a multiple of the sector size, otherwise data will be lost + if (m_buffer_size % m_sector_bytes) + m_buffer_size = m_buffer_size - (m_buffer_size % m_sector_bytes); } m_cylinder_low = m_buffer_size & 0xff;