Always use MemRead and MemWrite to read/write memory.


svn path=/trunk/; revision=67082
This commit is contained in:
Aleksandar Andrejevic 2015-04-07 04:00:54 +00:00
parent 81c9b448c8
commit 7f52cff19b

View file

@ -12,6 +12,7 @@
#define NDEBUG #define NDEBUG
#include "emulator.h" #include "emulator.h"
#include "../../memory.h"
#include "dos.h" #include "dos.h"
#include "dos/dem.h" #include "dos/dem.h"
@ -409,9 +410,16 @@ WORD DosReadFile(WORD FileHandle,
if (SftEntry->Type == DOS_SFT_ENTRY_WIN32) if (SftEntry->Type == DOS_SFT_ENTRY_WIN32)
{ {
DWORD BytesRead32 = 0; DWORD BytesRead32 = 0;
LPVOID LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count);
ASSERT(LocalBuffer != NULL);
/* Read the file */ /* Read the file */
if (!ReadFile(SftEntry->Handle, FAR_POINTER(Buffer), Count, &BytesRead32, NULL)) if (ReadFile(SftEntry->Handle, LocalBuffer, Count, &BytesRead32, NULL))
{
/* Write to the memory */
MemWrite(TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), LocalBuffer, LOWORD(BytesRead32));
}
else
{ {
/* Store the error code */ /* Store the error code */
Result = (WORD)GetLastError(); Result = (WORD)GetLastError();
@ -419,6 +427,7 @@ WORD DosReadFile(WORD FileHandle,
/* The number of bytes read is always 16-bit */ /* The number of bytes read is always 16-bit */
*BytesRead = LOWORD(BytesRead32); *BytesRead = LOWORD(BytesRead32);
RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
} }
else if (SftEntry->Type == DOS_SFT_ENTRY_DEVICE) else if (SftEntry->Type == DOS_SFT_ENTRY_DEVICE)
{ {
@ -457,9 +466,14 @@ WORD DosWriteFile(WORD FileHandle,
if (SftEntry->Type == DOS_SFT_ENTRY_WIN32) if (SftEntry->Type == DOS_SFT_ENTRY_WIN32)
{ {
DWORD BytesWritten32 = 0; DWORD BytesWritten32 = 0;
LPVOID LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count);
ASSERT(LocalBuffer != NULL);
/* Read from the memory */
MemRead(TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), LocalBuffer, Count);
/* Write the file */ /* Write the file */
if (!WriteFile(SftEntry->Handle, FAR_POINTER(Buffer), Count, &BytesWritten32, NULL)) if (!WriteFile(SftEntry->Handle, LocalBuffer, Count, &BytesWritten32, NULL))
{ {
/* Store the error code */ /* Store the error code */
Result = (WORD)GetLastError(); Result = (WORD)GetLastError();
@ -467,6 +481,7 @@ WORD DosWriteFile(WORD FileHandle,
/* The number of bytes written is always 16-bit */ /* The number of bytes written is always 16-bit */
*BytesWritten = LOWORD(BytesWritten32); *BytesWritten = LOWORD(BytesWritten32);
RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
} }
else if (SftEntry->Type == DOS_SFT_ENTRY_DEVICE) else if (SftEntry->Type == DOS_SFT_ENTRY_DEVICE)
{ {