INT 21h DOS resize: If asked to resize a memory block, and the memory block was previously freed, compact free memory blocks and then read the memory block size, instead of reading the memory block size and then compacting. This fixes an MCB chain truncation bug involving Tandy graphics and California Games II

This commit is contained in:
Jonathan Campbell
2025-10-06 20:43:54 -07:00
parent 2c21434ebc
commit 213f7ba443
2 changed files with 12 additions and 1 deletions

View File

@@ -1,4 +1,11 @@
Next version
- 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
would correctly compact free blocks but then allocate according to the
old size of the freed MCB block, causing truncation of the MCB chain.
Fix for MCB chain truncation caused by California Games II DOS memory
management when running in Tandy graphics mode. (joncampbell123).
- Add dosbox.conf option, disabled by default, where if the MCB memory
chain is corrupted anywhere past the running program's memory block,
and it does anything to cause allocation, a new free memory block is

View File

@@ -393,7 +393,11 @@ bool DOS_ResizeMemory(uint16_t segment,uint16_t * blocks) {
else
DOS_CompressMemory();
total=mcb.GetSize(); /* DOS_CompressMemory() may change the MCB block size if this is a free block */
/* 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
* that like to allocate memory by resizing a previously freed block. The Tandy version of California Games II
* does this, for example, as does (noted behlow) some Demoscene code. */
total=mcb.GetSize();
DOS_MCB mcb_next(segment+total);
if (*blocks<=total) {