Fix with how DOS_Execute allocates memory to comply with the memory allocation strategy for UMB...now, it will allocate and execute in UMB if there is enough memory for the minimum allocation of the executable

This commit is contained in:
Cimarron Mittelsteadt
2021-07-21 19:13:20 -07:00
parent 30f654c492
commit c3f5637e0e
3 changed files with 44 additions and 17 deletions

View File

@@ -16,8 +16,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <algorithm>
#include "dosbox.h"
#include "dosbox.h"
#include "logging.h"
#include "mem.h"
#include "bios.h"
@@ -153,6 +154,31 @@ void DOS_zeromem(uint16_t seg,uint16_t para) {
}
}
static uint16_t GetMaximumMCBFreeSize(uint16_t mcb_segment)
{
uint16_t largestSize = 0;
DOS_MCB mcb(mcb_segment);
for (bool endOfChain = false; !endOfChain; mcb.SetPt(mcb_segment))
{
auto size = mcb.GetSize();
if (mcb.GetPSPSeg()==MCB_FREE) largestSize = std::max(largestSize, size);
endOfChain = DOS_MCB::MCBType(mcb.GetType())==DOS_MCB::MCBType::LastBlock;
mcb_segment += size+1;
}
return largestSize;
}
uint16_t DOS_GetMaximumFreeSize(uint16_t minBlocks)
{
uint16_t umbFreeSize = 0;
if (memAllocStrategy & 0xc0)
{
umbFreeSize = GetMaximumMCBFreeSize(dos_infoblock.GetStartOfUMBChain());
if (memAllocStrategy & 0x40 || umbFreeSize >= minBlocks) return umbFreeSize;
}
return GetMaximumMCBFreeSize(dos.firstMCB);
}
bool DOS_AllocateMemory(uint16_t * segment,uint16_t * blocks) {
DOS_CompressMemory();
uint16_t bigsize=0;