mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-21 15:21:15 +00:00
**Known problems:** - The Open function uses a `movzx` instruction on the value of parameter `fdwOpen` before pushing to OpenFile from the kernel. You can force this to appear by casting to `unsigned short`, but this disturbs the instructions for the rest of the file. To get the "best" overall match I decided to leave this out. - Flush, Advance, and Descend differ only in the order of operands on a `cmp` instruction. - This entire file is honestly pretty ugly. The main reason is all the nested ifs; we are constrained by returning a result value from each function, but only at the very end instead of bailing out with a `return`. By far the worst offender is the do/while loop in the Descend function. **Design considerations:** - We are casting the file handle from MMIOINFO to `HFILE` everywhere it is used, so I decided to just change the type. While doing that, I figured I might as well just pull out the members from the struct so we don't have `m_info` all over the place. - Without using a struct member, we have the issue of the obvious `memset` used to zero out the values in the constructor. I changed this to work on the object itself, which would not be valid in most cases, but seems fine here since we have no virtual methods. There is a lot of repeated code here, namely the call to `_llseek` to reset `m_lDiskOffset` based on the current file position. You could move this to an inline function, but maybe that's not appropriate. There are probably strides to be made on code clarity and comments (if needed or wanted) here. I'm open to any suggestions.
51 lines
2.0 KiB
C++
51 lines
2.0 KiB
C++
#ifndef MXIOINFO_H
|
|
#define MXIOINFO_H
|
|
|
|
#include <windows.h>
|
|
|
|
#include "mmsystem.h"
|
|
|
|
class MXIOINFO
|
|
{
|
|
public:
|
|
MXIOINFO();
|
|
__declspec(dllexport) ~MXIOINFO();
|
|
|
|
unsigned short Open(const char *filename, DWORD fdwOpen);
|
|
unsigned short Close(long arg);
|
|
LONG Seek(LONG lOffset, int iOrigin);
|
|
unsigned long Read(HPSTR pch, LONG cch);
|
|
unsigned short SetBuffer(LPSTR pchBuffer, LONG cchBuffer, LONG unk);
|
|
unsigned short Flush(UINT);
|
|
unsigned short Advance(UINT);
|
|
unsigned short Descend(MMCKINFO *pmmcki, const MMCKINFO *pmmckiParent, unsigned short fuDescend);
|
|
|
|
// The following is the MMIOINFO struct but with h_mmio set to type HFILE.
|
|
|
|
/* general fields */
|
|
DWORD m_dwFlags; /* 0 general status flags */
|
|
FOURCC m_fccIOProc; /* 4 pointer to I/O procedure */
|
|
LPMMIOPROC m_pIOProc; /* 8 pointer to I/O procedure */
|
|
UINT m_wErrorRet; /* c place for error to be returned */
|
|
HTASK m_htask; /* 10 alternate local task */
|
|
|
|
/* fields maintained by MMIO functions during buffered I/O */
|
|
LONG m_cchBuffer; /* 14 size of I/O buffer (or 0L) */
|
|
HPSTR m_pchBuffer; /* 18 start of I/O buffer (or NULL) */
|
|
HPSTR m_pchNext; /* 1c pointer to next byte to read/write */
|
|
HPSTR m_pchEndRead; /* 20 pointer to last valid byte to read */
|
|
HPSTR m_pchEndWrite; /* 24 pointer to last byte to write */
|
|
LONG m_lBufOffset; /* 28 disk offset of start of buffer */
|
|
|
|
/* fields maintained by I/O procedure */
|
|
LONG m_lDiskOffset; /* 2c disk offset of next read or write */
|
|
DWORD m_adwInfo[3]; /* 30 data specific to type of MMIOPROC */
|
|
|
|
/* other fields maintained by MMIO */
|
|
DWORD m_dwReserved1; /* 3c reserved for MMIO use */
|
|
DWORD m_dwReserved2; /* 40 reserved for MMIO use */
|
|
HFILE m_hmmio; /* 44 handle to open file */
|
|
};
|
|
|
|
#endif // MXIOINFO_H
|