/* INCLUDES *******************************************************************/
+#define NDEBUG
+
#include "dos.h"
#include "bios.h"
#include "emulator.h"
WORD Segment = BlockData - 1, ReturnSize = 0, NextSegment;
PDOS_MCB Mcb = SEGMENT_TO_MCB(Segment), NextMcb;
+ DPRINT("DosResizeMemory: BlockData 0x%04X, NewSize 0x%04X\n",
+ BlockData,
+ NewSize);
+
/* Make sure this is a valid, allocated block */
if ((Mcb->BlockType != 'M' && Mcb->BlockType != 'Z') || Mcb->OwnerPsp == 0)
{
Success = FALSE;
- DosLastError = ERROR_INVALID_PARAMETER;
+ DosLastError = ERROR_INVALID_HANDLE;
goto Done;
}
/* Make sure the next segment is free */
if (NextMcb->OwnerPsp != 0)
{
+ DPRINT("Cannot expand memory block: next segment is not free!\n");
DosLastError = ERROR_NOT_ENOUGH_MEMORY;
Success = FALSE;
goto Done;
/* Check if the block is larger than requested */
if (Mcb->Size > NewSize)
{
+ DPRINT("Block too large, reducing size from 0x%04X to 0x%04X\n",
+ Mcb->Size,
+ NewSize);
+
/* It is, split it into two blocks */
NextMcb = SEGMENT_TO_MCB(Segment + NewSize + 1);
}
else if (NewSize < Mcb->Size)
{
+ DPRINT("Shrinking block from 0x%04X to 0x%04X\n",
+ Mcb->Size,
+ NewSize);
+
/* Just split the block */
NextMcb = SEGMENT_TO_MCB(Segment + NewSize + 1);
NextMcb->BlockType = Mcb->BlockType;
/* Check if the operation failed */
if (!Success)
{
+ DPRINT("DosResizeMemory FAILED. Maximum available: 0x%04X\n",
+ ReturnSize);
+
/* Return the maximum possible size */
if (MaxAvailable) *MaxAvailable = ReturnSize;
}
{
PDOS_MCB Mcb = SEGMENT_TO_MCB(BlockData - 1);
+ DPRINT("DosFreeMemory: BlockData 0x%04X\n", BlockData);
+
/* Make sure the MCB is valid */
- if (Mcb->BlockType != 'M' && Mcb->BlockType != 'Z') return FALSE;
+ if (Mcb->BlockType != 'M' && Mcb->BlockType != 'Z')
+ {
+ DPRINT("MCB block type '%c' not valid!\n", Mcb->BlockType);
+ return FALSE;
+ }
/* Mark the block as free */
Mcb->OwnerPsp = 0;
DWORD Segment = FIRST_MCB_SEGMENT;
PDOS_MCB Mcb = SEGMENT_TO_MCB(Segment);
+ DPRINT("Linking UMB\n");
+
/* Check if UMBs are already linked */
if (DosUmbLinked) return FALSE;
DWORD Segment = FIRST_MCB_SEGMENT;
PDOS_MCB Mcb = SEGMENT_TO_MCB(Segment);
+ DPRINT("Unlinking UMB\n");
+
/* Check if UMBs are already unlinked */
if (!DosUmbLinked) return FALSE;
HANDLE FileHandle;
WORD DosHandle;
+ DPRINT("DosCreateFile: FilePath \"%s\", Attributes 0x%04X\n",
+ FilePath,
+ Attributes);
+
/* Create the file */
FileHandle = CreateFileA(FilePath,
GENERIC_READ | GENERIC_WRITE,
ACCESS_MASK Access = 0;
WORD DosHandle;
+ DPRINT("DosOpenFile: FilePath \"%s\", AccessMode 0x%04X\n",
+ FilePath,
+ AccessMode);
+
/* Parse the access mode */
switch (AccessMode & 3)
{
DWORD BytesRead32 = 0;
HANDLE Handle = DosGetRealHandle(FileHandle);
+ DPRINT("DosReadFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, Count);
+
/* Make sure the handle is valid */
- if (Handle == INVALID_HANDLE_VALUE) return ERROR_INVALID_PARAMETER;
+ if (Handle == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE;
/* Read the file */
if (!ReadFile(Handle, Buffer, Count, &BytesRead32, NULL))
DWORD BytesWritten32 = 0;
HANDLE Handle = DosGetRealHandle(FileHandle);
+ DPRINT("DosWriteFile: FileHandle 0x%04X, Count 0x%04X\n",
+ FileHandle,
+ Count);
+
/* Make sure the handle is valid */
- if (Handle == INVALID_HANDLE_VALUE) return ERROR_INVALID_PARAMETER;
+ if (Handle == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE;
/* Write the file */
if (!WriteFile(Handle, Buffer, Count, &BytesWritten32, NULL))
PDOS_PSP PspBlock;
LPBYTE HandleTable;
+ DPRINT("DosCloseHandle: DosHandle 0x%04X\n", DosHandle);
+
/* The system PSP has no handle table */
if (CurrentPsp == SYSTEM_PSP) return FALSE;
PDWORD RelocationTable;
PWORD RelocWord;
+ DPRINT("DosCreateProcess: CommandLine \"%s\", EnvBlock 0x%04X\n",
+ CommandLine,
+ EnvBlock);
+
/* Save a copy of the command line */
strcpy(CommandLineCopy, CommandLine);
LPDWORD IntVecTable = (LPDWORD)((ULONG_PTR)BaseAddress);
PDOS_PSP PspBlock = SEGMENT_TO_PSP(Psp);
+ DPRINT("DosTerminateProcess: Psp 0x%04X, ReturnCode 0x%02X\n",
+ Psp,
+ ReturnCode);
+
/* Check if this PSP is it's own parent */
if (PspBlock->ParentPsp == Psp) goto Done;
/* Return the error code in AX */
EmulatorSetRegister(EMULATOR_REG_AX,
- (Eax & 0xFFFF0000) | ERROR_INVALID_PARAMETER);
+ (Eax & 0xFFFF0000) | ERROR_INVALID_HANDLE);
}
break;