From 16f4c85323d01d7108d2fbc07e8ab2f7d71aa286 Mon Sep 17 00:00:00 2001 From: Jonathan Campbell Date: Mon, 6 Oct 2025 23:12:32 -0700 Subject: [PATCH] DOS_ResizeMemory() compact free blocks but only those from the segment that is being resized on, as MS-DOS is documented to do --- CHANGELOG | 2 ++ src/dos/dos_memory.cpp | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cff6b3095..8650d8e6b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ Next version + - INT 21h AH=4Ah resize memory: Compact free blocks only at or after the + segment being resized, as MS-DOS is documented to do (joncampbell123). - INT 21h AH=4Ah resize memory: Fix bug where, if asked to resize a previously freed memory block and the block is not the last block in the MCB chain, and the next block in the MCB chain is also free, the MCB management code diff --git a/src/dos/dos_memory.cpp b/src/dos/dos_memory.cpp index 103f15561..a94ad81ed 100644 --- a/src/dos/dos_memory.cpp +++ b/src/dos/dos_memory.cpp @@ -386,12 +386,10 @@ bool DOS_ResizeMemory(uint16_t segment,uint16_t * blocks) { return false; } + /* MS-DOS is documented to combine free blocks at or after this block. Also to avoid combining free blocks in a way + * that might invalidate the mcb() block we just constructed. */ uint16_t total=mcb.GetSize(); - - if (*blocks > total) - DOS_CompressMemory(segment-1); - else - DOS_CompressMemory(); + DOS_CompressMemory(segment-1); /* DOS_CompressMemory() may change the MCB block size if this is a free block when it combines consecutive free blocks. * If you don't think this could be a free block, understand that there are DOS applications and games out there