From b0357a79c1c33c6fcdd043a02fa5b6deebc4ccdb Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Mon, 16 Dec 2024 13:14:19 -0700 Subject: [PATCH] Use SDL IOStream in for MXIOINFO --- LEGO1/LegoOmni.def | 1 - LEGO1/LegoOmni.mingw.def | 1 - LEGO1/omni/include/mxdsfile.h | 8 +- LEGO1/omni/include/mxdssource.h | 4 +- LEGO1/omni/include/mxio.h | 84 +++++++++-- LEGO1/omni/include/mxomni.h | 1 + LEGO1/omni/include/mxstring.h | 1 + LEGO1/omni/src/common/mxstring.cpp | 20 +++ LEGO1/omni/src/common/mxutilities.cpp | 7 +- .../omni/src/stream/mxdiskstreamprovider.cpp | 2 +- LEGO1/omni/src/stream/mxdsfile.cpp | 11 +- LEGO1/omni/src/stream/mxio.cpp | 142 +++++++++--------- 12 files changed, 181 insertions(+), 101 deletions(-) diff --git a/LEGO1/LegoOmni.def b/LEGO1/LegoOmni.def index 2807bea9..238bb6f2 100644 --- a/LEGO1/LegoOmni.def +++ b/LEGO1/LegoOmni.def @@ -98,7 +98,6 @@ EXPORTS ?RemoveAll@ViewManager@@QAEXPAVViewROI@@@Z ?RemoveWorld@LegoOmni@@QAEXABVMxAtomId@@J@Z ?Save@LegoGameState@@QAEJK@Z -?Seek@MxDSFile@@UAEJJH@Z ?SerializePlayersInfo@LegoGameState@@QAEXF@Z ?SerializeScoreHistory@LegoGameState@@QAEXF@Z ?SetCD@MxOmni@@SAXPBD@Z diff --git a/LEGO1/LegoOmni.mingw.def b/LEGO1/LegoOmni.mingw.def index 2d19d114..dbd07f3e 100644 --- a/LEGO1/LegoOmni.mingw.def +++ b/LEGO1/LegoOmni.mingw.def @@ -146,7 +146,6 @@ _ZN8MxDSFile13GetBufferSizeEv _ZN8MxDSFile19GetStreamBuffersNumEv _ZN8MxDSFile4OpenEj _ZN8MxDSFile4ReadEPhj -_ZN8MxDSFile4SeekEii _ZN8MxDSFile5CloseEv _ZN8MxDSFileC1EPKcj _ZN8MxDSFileC2EPKcj diff --git a/LEGO1/omni/include/mxdsfile.h b/LEGO1/omni/include/mxdsfile.h index 09772b68..4ddfaf3c 100644 --- a/LEGO1/omni/include/mxdsfile.h +++ b/LEGO1/omni/include/mxdsfile.h @@ -6,8 +6,6 @@ #include "mxstring.h" #include "mxtypes.h" -#include - // VTABLE: LEGO1 0x100dc890 // VTABLE: BETA10 0x101c2418 // SIZE 0x7c @@ -43,14 +41,14 @@ class MxDSFile : public MxDSSource { MxResult Open(MxULong) override; // vtable+0x14 MxResult Close() override; // vtable+0x18 MxResult Read(unsigned char*, MxULong) override; // vtable+0x20 - MxResult Seek(MxLong, int) override; // vtable+0x24 + MxResult Seek(MxLong, SDL_IOWhence) override; // vtable+0x24 MxULong GetBufferSize() override; // vtable+0x28 MxULong GetStreamBuffersNum() override; // vtable+0x2c // FUNCTION: BETA10 0x1015e110 void SetFileName(const char* p_filename) { m_filename = p_filename; } - MxS32 CalcFileSize() { return GetFileSize(m_io.m_info.hmmio, NULL); } + MxS32 CalcFileSize() { return SDL_GetIOSize(m_io.m_file); } // SYNTHETIC: LEGO1 0x100c01e0 // SYNTHETIC: BETA10 0x10148e40 @@ -63,7 +61,7 @@ class MxDSFile : public MxDSSource { MxS16 m_majorVersion; // 0x00 MxS16 m_minorVersion; // 0x02 - MxULong m_bufferSize; // 0x04 + MxU32 m_bufferSize; // 0x04 MxS16 m_streamBuffersNum; // 0x08 MxS16 m_reserved; // 0x0a }; diff --git a/LEGO1/omni/include/mxdssource.h b/LEGO1/omni/include/mxdssource.h index 352ee2c5..6dd03a83 100644 --- a/LEGO1/omni/include/mxdssource.h +++ b/LEGO1/omni/include/mxdssource.h @@ -3,6 +3,8 @@ #include "mxcore.h" +#include + class MxDSBuffer; // VTABLE: LEGO1 0x100dc8c8 @@ -31,7 +33,7 @@ class MxDSSource : public MxCore { virtual MxLong Close() = 0; // vtable+0x18 virtual MxResult ReadToBuffer(MxDSBuffer* p_buffer); // vtable+0x1c virtual MxResult Read(unsigned char*, MxULong) = 0; // vtable+0x20 - virtual MxLong Seek(MxLong, int) = 0; // vtable+0x24 + virtual MxLong Seek(MxLong, SDL_IOWhence) = 0; // vtable+0x24 virtual MxULong GetBufferSize() = 0; // vtable+0x28 virtual MxULong GetStreamBuffersNum() = 0; // vtable+0x2c virtual MxLong GetLengthInDWords(); // vtable+0x30 diff --git a/LEGO1/omni/include/mxio.h b/LEGO1/omni/include/mxio.h index 64461d6a..4a549ecd 100644 --- a/LEGO1/omni/include/mxio.h +++ b/LEGO1/omni/include/mxio.h @@ -3,15 +3,70 @@ #include "mxtypes.h" -// mmsystem.h requires inclusion of windows.h before -// clang-format off -#include -#include -// clang-format on +#include -#if defined(_M_IX86) || defined(__i386__) -#define MXIO_MINFO_MFILE -#endif +// [library:filesystem] +// We define the bare minimum constants and structures to be compatible with the code in mxio.cpp +// This is mostly copy-pasted from the MMSYSTEM.H Windows header. + +/* MMIO error return values */ +#define MMIOERR_BASE 256 +#define MMIOERR_OUTOFMEMORY (MMIOERR_BASE + 2) /* out of memory */ +#define MMIOERR_CANNOTOPEN (MMIOERR_BASE + 3) /* cannot open */ +#define MMIOERR_CANNOTREAD (MMIOERR_BASE + 5) /* cannot read */ +#define MMIOERR_CANNOTWRITE (MMIOERR_BASE + 6) /* cannot write */ +#define MMIOERR_CANNOTSEEK (MMIOERR_BASE + 7) /* cannot seek */ +#define MMIOERR_CHUNKNOTFOUND (MMIOERR_BASE + 9) /* chunk not found */ +#define MMIOERR_UNBUFFERED (MMIOERR_BASE + 10) /* */ + +/* bit field masks */ +#define MMIO_RWMODE 0x00000003 /* open file for reading/writing/both */ + +/* constants for dwFlags field of MMIOINFO */ +#define MMIO_ALLOCBUF 0x00010000 /* mmioOpen() should allocate a buffer */ +#define MMIO_DIRTY 0x10000000 /* I/O buffer is dirty */ + +/* read/write mode numbers (bit field MMIO_RWMODE) */ +#define MMIO_READ 0x00000000 /* open file for reading only */ +#define MMIO_WRITE 0x00000001 /* open file for writing only */ +#define MMIO_READWRITE 0x00000002 /* open file for reading and writing */ + +/* MMIO macros */ +#define mmioFOURCC(ch0, ch1, ch2, ch3) FOURCC(ch0, ch1, ch2, ch3) + +/* standard four character codes */ +#define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F') +#define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T') + +/* various MMIO flags */ +#define MMIO_FINDRIFF 0x0020 /* mmioDescend: find a LIST chunk */ +#define MMIO_FINDLIST 0x0040 /* mmioDescend: find a RIFF chunk */ + +/* general MMIO information data structure */ +typedef struct _ISLE_MMIOINFO { + /* general fields */ + MxU32 dwFlags; /* general status flags */ + + /* fields maintained by MMIO functions during buffered I/O */ + Sint64 cchBuffer; /* size of I/O buffer (or 0L) */ + char* pchBuffer; /* start of I/O buffer (or NULL) */ + char* pchNext; /* pointer to next byte to read/write */ + char* pchEndRead; /* pointer to last valid byte to read */ + char* pchEndWrite; /* pointer to last byte to write */ + Sint64 lBufOffset; /* disk offset of start of buffer */ + + /* fields maintained by I/O procedure */ + Sint64 lDiskOffset; /* disk offset of next read or write */ +} ISLE_MMIOINFO; + +/* RIFF chunk information data structure */ +typedef struct _ISLE_MMCKINFO { + MxU32 ckid; /* chunk ID */ + MxU32 cksize; /* chunk size */ + MxU32 fccType; /* form type or list type */ + MxU32 dwDataOffset; /* offset of data portion of chunk */ + MxU32 dwFlags; /* flags used by MMIO functions */ +} ISLE_MMCKINFO; // SIZE 0x48 class MXIOINFO { @@ -23,19 +78,18 @@ class MXIOINFO { MxU16 Close(MxLong); MxLong Read(void*, MxLong); MxLong Write(void*, MxLong); - MxLong Seek(MxLong, MxLong); + MxLong Seek(MxLong, SDL_IOWhence); MxU16 SetBuffer(char*, MxLong, MxLong); MxU16 Flush(MxU16); MxU16 Advance(MxU16); - MxU16 Descend(MMCKINFO*, const MMCKINFO*, MxU16); - MxU16 Ascend(MMCKINFO*, MxU16); + MxU16 Descend(ISLE_MMCKINFO*, const ISLE_MMCKINFO*, MxU16); + MxU16 Ascend(ISLE_MMCKINFO*, MxU16); // NOTE: In MXIOINFO, the `hmmio` member of MMIOINFO is used like // an HFILE (int) instead of an HMMIO (WORD). - MMIOINFO m_info; -#ifndef MXIO_MINFO_MFILE - HFILE m_file; -#endif + ISLE_MMIOINFO m_info; + // [library:filesystem] This handle is always used instead of the `hmmio` member in m_info. + SDL_IOStream* m_file; }; #endif // MXIO_H diff --git a/LEGO1/omni/include/mxomni.h b/LEGO1/omni/include/mxomni.h index 4ac59916..6b2a7537 100644 --- a/LEGO1/omni/include/mxomni.h +++ b/LEGO1/omni/include/mxomni.h @@ -36,6 +36,7 @@ class MxOmni : public MxCore { static void SetCD(const char* p_cd); static void SetHD(const char* p_hd); static void SetSound3D(MxBool p_use3dSound); + static void NormalizePath(char* p_path); MxOmni(); ~MxOmni() override; diff --git a/LEGO1/omni/include/mxstring.h b/LEGO1/omni/include/mxstring.h index 477c821c..79bab68c 100644 --- a/LEGO1/omni/include/mxstring.h +++ b/LEGO1/omni/include/mxstring.h @@ -25,6 +25,7 @@ class MxString : public MxCore { MxString& operator+=(const char* p_str); static void CharSwap(char* p_a, char* p_b); + static void NormalizePath(char* p_path); // FUNCTION: BETA10 0x10017c50 char* GetData() const { return m_data; } diff --git a/LEGO1/omni/src/common/mxstring.cpp b/LEGO1/omni/src/common/mxstring.cpp index b33a7f10..d7f8093c 100644 --- a/LEGO1/omni/src/common/mxstring.cpp +++ b/LEGO1/omni/src/common/mxstring.cpp @@ -2,6 +2,7 @@ #include "decomp.h" +#include #include #include @@ -185,3 +186,22 @@ void MxString::CharSwap(char* p_a, char* p_b) *p_a = *p_b; *p_b = t; } + +void MxString::NormalizePath(char* p_path) +{ + // [library:filesystem] + // This function is used to build a consistent path that will eventually be used to read a file. + // The input may come with Windows path separators, i.e. \lego\scripts\infocntr\infomain + // We have to replace the backslashes with forward slashes to be able to access the files + // on non-Windows systems +#if !defined(SDL_PLATFORM_WINDOWS) + char* path = p_path; + while (*path) { + if (*path == '\\') { + *path = '/'; + } + + path++; + } +#endif +} diff --git a/LEGO1/omni/src/common/mxutilities.cpp b/LEGO1/omni/src/common/mxutilities.cpp index fe45327e..9be9150c 100644 --- a/LEGO1/omni/src/common/mxutilities.cpp +++ b/LEGO1/omni/src/common/mxutilities.cpp @@ -77,6 +77,9 @@ void MakeSourceName(char* p_output, const char* p_input) if (extLoc) { *extLoc = 0; } + + // [library:filesystem] Normalize this name since it will be part of a path. + MxString::NormalizePath(p_output); } // FUNCTION: LEGO1 0x100b7050 @@ -164,9 +167,9 @@ void FUN_100b7220(MxDSAction* p_action, MxU32 p_newFlags, MxBool p_setFlags) MxDSObject* CreateStreamObject(MxDSFile* p_file, MxS16 p_ofs) { MxU8* buf; - _MMCKINFO tmpChunk; + ISLE_MMCKINFO tmpChunk; - if (p_file->Seek(((MxLong*) p_file->GetBuffer())[p_ofs], 0)) { + if (p_file->Seek(((MxLong*) p_file->GetBuffer())[p_ofs], SDL_IO_SEEK_SET)) { return NULL; } diff --git a/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp b/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp index 7c96befd..d1835501 100644 --- a/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp +++ b/LEGO1/omni/src/stream/mxdiskstreamprovider.cpp @@ -245,7 +245,7 @@ void MxDiskStreamProvider::PerformWork() buffer = streamingAction->GetUnknowna0(); if (m_pFile->GetPosition() == streamingAction->GetBufferOffset() || - m_pFile->Seek(streamingAction->GetBufferOffset(), 0) == 0) { + m_pFile->Seek(streamingAction->GetBufferOffset(), SDL_IO_SEEK_SET) == 0) { buffer->SetUnknown14(m_pFile->GetPosition()); if (m_pFile->ReadToBuffer(buffer) == SUCCESS) { diff --git a/LEGO1/omni/src/stream/mxdsfile.cpp b/LEGO1/omni/src/stream/mxdsfile.cpp index 0f3b5227..2c5b5247 100644 --- a/LEGO1/omni/src/stream/mxdsfile.cpp +++ b/LEGO1/omni/src/stream/mxdsfile.cpp @@ -3,6 +3,7 @@ #include "decomp.h" #include "mxdebug.h" +#include #include #define SI_MAJOR_VERSION 2 @@ -41,7 +42,7 @@ MxResult MxDSFile::Open(MxULong p_uStyle) Close(); } else { - Seek(0, 0); + Seek(0, SDL_IO_SEEK_SET); } return result; @@ -51,8 +52,8 @@ MxResult MxDSFile::Open(MxULong p_uStyle) // FUNCTION: BETA10 0x1015dd18 MxResult MxDSFile::ReadChunks() { - _MMCKINFO topChunk; - _MMCKINFO childChunk; + ISLE_MMCKINFO topChunk; + ISLE_MMCKINFO childChunk; char tempBuffer[80]; topChunk.fccType = FOURCC('O', 'M', 'N', 'I'); @@ -70,7 +71,7 @@ MxResult MxDSFile::ReadChunks() m_io.Read(&m_header, 0x0c); if ((m_header.m_majorVersion != SI_MAJOR_VERSION) || (m_header.m_minorVersion != SI_MINOR_VERSION)) { sprintf(tempBuffer, "Wrong SI file version. %d.%d expected.", SI_MAJOR_VERSION, SI_MINOR_VERSION); - MessageBoxA(NULL, tempBuffer, NULL, MB_ICONERROR); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "LEGO® Island Error", tempBuffer, NULL); return FAILURE; } @@ -116,7 +117,7 @@ MxResult MxDSFile::Read(unsigned char* p_buf, MxULong p_nbytes) // FUNCTION: LEGO1 0x100cc7b0 // FUNCTION: BETA10 0x1015dfee -MxResult MxDSFile::Seek(MxLong p_lOffset, MxS32 p_iOrigin) +MxResult MxDSFile::Seek(MxLong p_lOffset, SDL_IOWhence p_iOrigin) { m_position = m_io.Seek(p_lOffset, p_iOrigin); if (m_position == -1) { diff --git a/LEGO1/omni/src/stream/mxio.cpp b/LEGO1/omni/src/stream/mxio.cpp index 3b7c9b6d..1bc7e8ba 100644 --- a/LEGO1/omni/src/stream/mxio.cpp +++ b/LEGO1/omni/src/stream/mxio.cpp @@ -3,21 +3,16 @@ #include "decomp.h" #include +#include // This class should be 72 bytes in size, same as the MMIOINFO struct. // The current implementation has MMIOINFO as the only member of the class, // but this assert will enforce the size if we decide to change that. DECOMP_SIZE_ASSERT(MXIOINFO, sizeof(MMIOINFO)); -#ifdef MXIO_MINFO_MFILE -#define ASSIGN_M_FILE(X) m_info.hmmio = (HMMIO) (X) -#define M_FILE (HFILE)(m_info.hmmio) -#define RAW_M_FILE m_info.hmmio -#else #define ASSIGN_M_FILE(X) m_file = (X) #define M_FILE (m_file) #define RAW_M_FILE m_file -#endif // FUNCTION: LEGO1 0x100cc800 // FUNCTION: BETA10 0x1015e140 @@ -33,25 +28,32 @@ MXIOINFO::~MXIOINFO() Close(0); } +#include // FUNCTION: LEGO1 0x100cc830 // FUNCTION: BETA10 0x1015e189 MxU16 MXIOINFO::Open(const char* p_filename, MxULong p_flags) { - OFSTRUCT unused; + OutputDebugString("OPENING -> "); + OutputDebugString(p_filename); + OutputDebugString("\n"); + + // [library:filesystem] p_flags is always 0 (OF_READ) + assert(p_flags == 0); + MxU16 result = 0; m_info.lDiskOffset = m_info.lBufOffset = 0; // DECOMP: Cast of p_flags to u16 forces the `movzx` instruction // original: m_info.hmmio = OpenFile(p_filename, &unused, (MxU16) p_flags); - ASSIGN_M_FILE(OpenFile(p_filename, &unused, (MxU16) p_flags)); + ASSIGN_M_FILE(SDL_IOFromFile(p_filename, "rb")); - if (M_FILE != HFILE_ERROR) { + if (M_FILE != NULL) { m_info.dwFlags = p_flags; if (m_info.dwFlags & MMIO_ALLOCBUF) { // Default buffer length of 8k if none specified - MxLong len = m_info.cchBuffer; + Sint64 len = m_info.cchBuffer; if (len == 0) { len = 8192; } @@ -66,7 +68,7 @@ MxU16 MXIOINFO::Open(const char* p_filename, MxULong p_flags) } else { m_info.cchBuffer = len; - m_info.pchBuffer = (HPSTR) buf; + m_info.pchBuffer = buf; } m_info.pchNext = m_info.pchEndRead = m_info.pchBuffer; @@ -88,7 +90,7 @@ MxU16 MXIOINFO::Close(MxLong p_unused) if (RAW_M_FILE) { result = Flush(0); - _lclose(M_FILE); + SDL_CloseIO(M_FILE); ASSIGN_M_FILE(0); if (m_info.dwFlags & MMIO_ALLOCBUF) { @@ -106,11 +108,11 @@ MxU16 MXIOINFO::Close(MxLong p_unused) // FUNCTION: BETA10 0x1015e3b2 MxLong MXIOINFO::Read(void* p_buf, MxLong p_len) { - MxLong bytesRead = 0; + Sint64 bytesRead = 0; if (m_info.pchBuffer) { - MxLong bytesLeft = m_info.pchEndRead - m_info.pchNext; + Sint64 bytesLeft = m_info.pchEndRead - m_info.pchNext; while (p_len > 0) { if (bytesLeft > 0) { @@ -139,11 +141,11 @@ MxLong MXIOINFO::Read(void* p_buf, MxLong p_len) } } else if (RAW_M_FILE && p_len > 0) { - bytesRead = _hread(M_FILE, p_buf, p_len); + bytesRead = SDL_ReadIO(M_FILE, p_buf, p_len); - if (bytesRead == -1) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { bytesRead = 0; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesRead; @@ -156,11 +158,11 @@ MxLong MXIOINFO::Read(void* p_buf, MxLong p_len) // FUNCTION: BETA10 0x1015e4fc MxLong MXIOINFO::Write(void* p_buf, MxLong p_len) { - MxLong bytesWritten = 0; + Sint64 bytesWritten = 0; if (m_info.pchBuffer) { - MxLong bytesLeft = m_info.pchEndWrite - m_info.pchNext; + Sint64 bytesLeft = m_info.pchEndWrite - m_info.pchNext; while (p_len > 0) { if (bytesLeft > 0) { @@ -192,11 +194,11 @@ MxLong MXIOINFO::Write(void* p_buf, MxLong p_len) } } else if (RAW_M_FILE && p_len > 0) { - bytesWritten = _hwrite(M_FILE, (const char*) p_buf, p_len); + bytesWritten = SDL_WriteIO(M_FILE, p_buf, p_len); - if (bytesWritten == -1) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { bytesWritten = 0; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesWritten; @@ -212,30 +214,30 @@ MxLong MXIOINFO::Write(void* p_buf, MxLong p_len) // FUNCTION: LEGO1 0x100cca00 // FUNCTION: BETA10 0x1015e6c4 -MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) +MxLong MXIOINFO::Seek(MxLong p_offset, SDL_IOWhence p_origin) { MxLong result = -1; - MxLong bytesRead; + Sint64 bytesRead; // If buffered I/O if (m_info.pchBuffer) { - if (p_origin == SEEK_CUR) { + if (p_origin == SDL_IO_SEEK_CUR) { if (!p_offset) { // don't seek at all and just return where we are. return m_info.lBufOffset + (m_info.pchNext - m_info.pchBuffer); } - // With SEEK_CUR, p_offset is a relative offset. - // Get the absolute position instead and use SEEK_SET. + // With SDL_IO_SEEK_CUR, p_offset is a relative offset. + // Get the absolute position instead and use SDL_IO_SEEK_SET. p_offset += m_info.lBufOffset + (m_info.pchNext - m_info.pchBuffer); - p_origin = SEEK_SET; + p_origin = SDL_IO_SEEK_SET; } - else if (p_origin == SEEK_END) { + else if (p_origin == SDL_IO_SEEK_END) { // not possible with buffered I/O return -1; } - // else p_origin == SEEK_SET. + // else p_origin == SDL_IO_SEEK_SET. // is p_offset between the start and end of the buffer? // i.e. can we do the seek without reading more from disk? @@ -246,10 +248,10 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) else { // we have to read another chunk from disk. if (RAW_M_FILE && !Flush(0)) { - m_info.lDiskOffset = _llseek(M_FILE, p_offset, p_origin); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, p_offset, p_origin); if (m_info.lDiskOffset == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { @@ -259,10 +261,10 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) // do we need to seek again? // (i.e. are we already aligned to buffer size?) if (p_offset != m_info.lBufOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); if (m_info.lDiskOffset == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } } @@ -270,10 +272,10 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) // is the file open for writing only? if ((m_info.dwFlags & MMIO_RWMODE) == 0 || (m_info.dwFlags & MMIO_RWMODE) == MMIO_READWRITE) { // We can read from the file. Fill the buffer. - bytesRead = _hread(M_FILE, m_info.pchBuffer, m_info.cchBuffer); + bytesRead = SDL_ReadIO(M_FILE, m_info.pchBuffer, m_info.cchBuffer); - if (bytesRead == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesRead; @@ -297,16 +299,16 @@ MxLong MXIOINFO::Seek(MxLong p_offset, MxLong p_origin) else if (RAW_M_FILE) { // No buffer so just seek the file directly (if we have a valid handle) // i.e. if we just want to get the current file position - if (p_origin == SEEK_CUR && p_offset == 0) { + if (p_origin == SDL_IO_SEEK_CUR && p_offset == 0) { return m_info.lDiskOffset; } - m_info.lDiskOffset = _llseek(M_FILE, p_offset, p_origin); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, p_offset, p_origin); result = m_info.lDiskOffset; if (result == -1) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } } @@ -338,7 +340,7 @@ MxU16 MXIOINFO::SetBuffer(char* p_buf, MxLong p_len, MxLong p_unused) MxU16 MXIOINFO::Flush(MxU16 p_unused) { MxU16 result = 0; - MxLong bytesWritten; + Sint64 bytesWritten; // if buffer is dirty if (m_info.dwFlags & MMIO_DIRTY) { @@ -350,20 +352,20 @@ MxU16 MXIOINFO::Flush(MxU16 p_unused) MxLong cchBuffer = m_info.cchBuffer; if (cchBuffer > 0) { if (m_info.lBufOffset != m_info.lDiskOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); } // Was the previous seek (if required) successful? if (m_info.lBufOffset != m_info.lDiskOffset) { result = MMIOERR_CANNOTSEEK; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { - bytesWritten = _hwrite(M_FILE, m_info.pchBuffer, cchBuffer); + bytesWritten = SDL_WriteIO(M_FILE, m_info.pchBuffer, cchBuffer); - if (bytesWritten == -1 || bytesWritten != cchBuffer) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR || bytesWritten != cchBuffer) { result = MMIOERR_CANNOTWRITE; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesWritten; @@ -393,8 +395,8 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) MxULong rwmode = m_info.dwFlags & MMIO_RWMODE; if (m_info.pchBuffer) { - MxLong cch = m_info.cchBuffer; - MxLong bytesCounter; + Sint64 cch = m_info.cchBuffer; + Sint64 bytesCounter; // If we can and should write to the file, // if we are being asked to write to the file, @@ -403,19 +405,19 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) ((p_option & MMIO_WRITE) || (rwmode == MMIO_READWRITE)) && cch > 0) { if (m_info.lBufOffset != m_info.lDiskOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); } if (m_info.lBufOffset != m_info.lDiskOffset) { result = MMIOERR_CANNOTSEEK; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { - bytesCounter = _hwrite(M_FILE, m_info.pchBuffer, cch); + bytesCounter = SDL_WriteIO(M_FILE, m_info.pchBuffer, cch); - if (bytesCounter == -1 || bytesCounter != cch) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR || bytesCounter != cch) { result = MMIOERR_CANNOTWRITE; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesCounter; @@ -429,20 +431,20 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) m_info.lBufOffset += cch; if ((!rwmode || rwmode == MMIO_READWRITE) && cch > 0) { if (m_info.lBufOffset != m_info.lDiskOffset) { - m_info.lDiskOffset = _llseek(M_FILE, m_info.lBufOffset, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, m_info.lBufOffset, SDL_IO_SEEK_SET); } // if previous seek failed if (m_info.lBufOffset != m_info.lDiskOffset) { result = MMIOERR_CANNOTSEEK; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { - bytesCounter = _hread(M_FILE, m_info.pchBuffer, cch); + bytesCounter = SDL_ReadIO(M_FILE, m_info.pchBuffer, cch); - if (bytesCounter == -1) { + if (SDL_GetIOStatus(M_FILE) == SDL_IO_STATUS_ERROR) { result = MMIOERR_CANNOTREAD; - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); } else { m_info.lDiskOffset += bytesCounter; @@ -461,11 +463,11 @@ MxU16 MXIOINFO::Advance(MxU16 p_option) // FUNCTION: LEGO1 0x100cce60 // FUNCTION: BETA10 0x1015edef -MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU16 p_descend) +MxU16 MXIOINFO::Descend(ISLE_MMCKINFO* p_chunkInfo, const ISLE_MMCKINFO* p_parentInfo, MxU16 p_descend) { MxU16 result = 0; MxULong ofs; - BOOL readOk; + MxU32 readOk; if (!p_chunkInfo) { return MMIOERR_BASE; // ? @@ -491,15 +493,15 @@ MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU } } else { - ofs = MAXLONG; + ofs = LONG_MAX; if (p_parentInfo) { ofs = p_parentInfo->cksize + p_parentInfo->dwDataOffset; } - BOOL running = TRUE; + MxU32 running = TRUE; readOk = FALSE; - MMCKINFO tmp; + ISLE_MMCKINFO tmp; tmp.dwFlags = 0; while (running) { @@ -533,7 +535,7 @@ MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU else if (p_chunkInfo->ckid == tmp.ckid) { running = FALSE; } - else if (Seek((tmp.cksize & 1) + tmp.cksize, SEEK_CUR) == -1) { + else if (Seek((tmp.cksize & 1) + tmp.cksize, SDL_IO_SEEK_CUR) == -1) { result = MMIOERR_CANNOTSEEK; running = FALSE; } @@ -550,7 +552,7 @@ MxU16 MXIOINFO::Descend(MMCKINFO* p_chunkInfo, const MMCKINFO* p_parentInfo, MxU } // FUNCTION: BETA10 0x1015f08b -MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) +MxU16 MXIOINFO::Ascend(ISLE_MMCKINFO* p_chunkInfo, MxU16 p_ascend) { MxLong ofs; MxULong size; @@ -585,11 +587,11 @@ MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) m_info.dwFlags |= MMIO_DIRTY; } else { - m_info.lDiskOffset = _llseek(M_FILE, ofs, SEEK_SET); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, ofs, SDL_IO_SEEK_SET); if (m_info.lDiskOffset == ofs) { - if (_lwrite(M_FILE, (char*) &size, 4) != 4) { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + if (SDL_WriteIO(M_FILE, (char*) &size, 4) != 4) { + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); result = MMIOERR_CANNOTWRITE; } else { @@ -597,7 +599,7 @@ MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) } } else { - m_info.lDiskOffset = _llseek(M_FILE, 0, SEEK_CUR); + m_info.lDiskOffset = SDL_SeekIO(M_FILE, 0, SDL_IO_SEEK_CUR); result = MMIOERR_CANNOTSEEK; } } @@ -606,7 +608,7 @@ MxU16 MXIOINFO::Ascend(MMCKINFO* p_chunkInfo, MxU16 p_ascend) // Seek past the end of the chunk (plus optional pad byte if size is odd) if (result == 0 && - Seek((p_chunkInfo->cksize & 1) + p_chunkInfo->cksize + p_chunkInfo->dwDataOffset, SEEK_SET) == -1) { + Seek((p_chunkInfo->cksize & 1) + p_chunkInfo->cksize + p_chunkInfo->dwDataOffset, SDL_IO_SEEK_SET) == -1) { result = MMIOERR_CANNOTSEEK; }