From 9c62fe8db26ee9fe834d44691de8a72298739550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Wed, 20 Jul 2005 19:20:23 +0000 Subject: [PATCH] bug when dos mem resize is used to shrink memory blocks (QuickBasic, fixes Shard of Spring) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2244 --- src/dos/dos_memory.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/dos/dos_memory.cpp b/src/dos/dos_memory.cpp index 55972ac3..8ffc6926 100644 --- a/src/dos/dos_memory.cpp +++ b/src/dos/dos_memory.cpp @@ -138,6 +138,24 @@ bool DOS_ResizeMemory(Bit16u segment,Bit16u * blocks) { DOS_MCB mcb(segment-1); Bit16u total=mcb.GetSize(); DOS_MCB mcb_next(segment+total); + if (*blocks<=total) { + if (GCC_UNLIKELY(*blocks==total)) { + /* Nothing to do */ + return true; + } + /* Shrinking MCB */ + DOS_MCB mcb_new_next(segment+(*blocks)); + mcb.SetSize(*blocks); + mcb_new_next.SetType(mcb.GetType()); + if (mcb.GetType()==0x5a) { + /* Further blocks follow */ + mcb.SetType(0x4d); + } + + mcb_new_next.SetSize(total-*blocks-1); + mcb_new_next.SetPSPSeg(MCB_FREE); + return true; + } if (mcb.GetType()!=0x5a) { if (mcb_next.GetPSPSeg()==MCB_FREE) { total+=mcb_next.GetSize()+1;