wavelength 1.0.0
Loading...
Searching...
No Matches
AsyncFile Class Reference

File of the host or the disc file system, read and written through a buffer with non-blocking I/O. More...

#include <asyncfile.h>

Inheritance diagram for AsyncFile:
Collaboration diagram for AsyncFile:

Public Member Functions

 AsyncFile (const char *pszFile, int nMode)
 Allocate the buffer and open a file.
 ~AsyncFile () override
 Close the file and release the buffer.
int Read (void *pBuffer, int nBytes) override
 Read bytes and wait for them.
bool ReadAsync (void *pBuffer, int nBytes) override
 Start reading bytes.
int Write (const void *pBuffer, int nBytes) override
 Write bytes into the buffer, writing out each full buffer.
int Seek (int nOffset, int nOrigin) override
 Move the position, clamped to the file, and refill the buffer of a file opened to read.
int Tell () override
 Report the position.
void Flush () override
 Write out the buffer of a file opened to write, or start refilling the buffer of a file opened to read.
bool Eof () override
 Report whether the position is at the end.
bool Fail () override
 Report whether an operation failed.
int Size () override
 Report the size.
int UncompressedSize () override
 Report the size before compression.
bool ReadDone (int *pnBytes) override
 Copy what the buffer has of the read, refilling the buffer when the read needs more.
void Open (const char *pszFile, int nMode)
 Open a file, and read the size before compression of a .gz file opened to read.
void Close ()
 Write out the buffer of a file opened to write, close the file, and reset the state.
 AsyncFile (const char *name, int mode)
 Allocate the buffer and open a file.
virtual ~AsyncFile ()
 Close the file and free the buffer.
virtual int Read (void *data, int bytes)
 Read bytes and wait for them.
virtual bool ReadAsync (void *data, int bytes)
 Start reading bytes, at most up to the end of the file.
virtual int Write (const void *data, int bytes)
 Write bytes through the buffer.
virtual int Seek (int offset, int origin)
 Move the position, clamped to the file.
virtual int Tell ()
 Report the position.
virtual void Flush ()
 Write the buffer when writing, or refill it when reading.
virtual bool Eof ()
 Report whether the position is at the end.
virtual bool Fail ()
 Report whether an operation failed.
virtual int Size ()
 Report the size.
virtual int UncompressedSize ()
 Report the size a .gz file records in its last four bytes, or zero for other files.
virtual bool ReadDone (int *bytes)
 Copy buffered bytes of the read ReadAsync() started, refilling the buffer when it runs out.
void Open (const char *name, int mode)
 Open a file.
void Close ()
 Write out a written file and close it.
Public Member Functions inherited from File
virtual ~File ()
 Close the file.
virtual ~File ()
 Close the file.

Static Public Member Functions

static void Init ()
 Read the buf_size setting of the file block of the system configuration.
static void Terminate ()
 Shut the file layer down.
Static Public Member Functions inherited from File
static File * New (const char *pszPath, int nMode, int nFlags)
 Open a file.

Additional Inherited Members

Public Types inherited from File
enum  Mode { kModeRead = 1 , kModeWrite = 2 }
 Open modes of New(). More...
Static Public Attributes inherited from File
static constexpr int kFlagNoArchive = 1
 The open flags New() takes to read even a disc file through AsyncFile.

Detailed Description

File of the host or the disc file system, read and written through a buffer with non-blocking I/O.

Buffered file of the host file system.

The RTTI includes the class name and records File as the base. The size before compression of a .gz file opened to read is its last four bytes.

The RTTI records the class as deriving from File. The object is 0x44 bytes. Reads and writes go through a buffer of gAsyncBufSize bytes. The reads complete at once on this platform.

Constructor & Destructor Documentation

◆ AsyncFile() [1/2]

AsyncFile::AsyncFile ( const char * pszFile,
int nMode )

Allocate the buffer and open a file.

Parameters
pszFileThe file, relative to the root of the game files.
nModeThe open mode, one or more of File::Mode.
Ghidra address:
NTSC-U/C: 0x0028eb50
Ghidra address:
PAL: 0x00298518

◆ ~AsyncFile() [1/2]

AsyncFile::~AsyncFile ( )
override

Close the file and release the buffer.

Ghidra address:
NTSC-U/C: 0x0028ed28
Ghidra address:
PAL: 0x002986f0

◆ AsyncFile() [2/2]

AsyncFile::AsyncFile ( const char * name,
int mode )

Allocate the buffer and open a file.

Parameters
nameThe path.
modeThe open mode, a combination of FileOpenMode bits.
Ghidra address:
0x1000de10

◆ ~AsyncFile() [2/2]

virtual AsyncFile::~AsyncFile ( )
virtual

Close the file and free the buffer.

Ghidra address:
0x1000e040

Member Function Documentation

◆ Init()

void AsyncFile::Init ( )
static

Read the buf_size setting of the file block of the system configuration.

Ghidra address:
NTSC-U/C: 0x0028eaf8
Ghidra address:
PAL: 0x002984c0

◆ Terminate()

void AsyncFile::Terminate ( )
static

Shut the file layer down.

The body does nothing.

Ghidra address:
NTSC-U/C: 0x0028eb48
Ghidra address:
PAL: 0x00298510

◆ Read() [1/2]

int AsyncFile::Read ( void * pBuffer,
int nBytes )
overridevirtual

Read bytes and wait for them.

Parameters
pBufferReceives the bytes.
nBytesThe number of bytes.
Returns
The number of bytes read, or 0 after a failure.
Ghidra address:
NTSC-U/C: 0x0028ee18
Ghidra address:
PAL: 0x002987e0

Implements File.

◆ ReadAsync() [1/2]

bool AsyncFile::ReadAsync ( void * pBuffer,
int nBytes )
overridevirtual

Start reading bytes.

Parameters
pBufferReceives the bytes.
nBytesThe number of bytes, cut at the end of the file.
Returns
Whether the read started, false after a failure.
Ghidra address:
NTSC-U/C: 0x0028ee88
Ghidra address:
PAL: 0x00298850

Implements File.

◆ Write() [1/2]

int AsyncFile::Write ( const void * pBuffer,
int nBytes )
overridevirtual

Write bytes into the buffer, writing out each full buffer.

Parameters
pBufferThe bytes.
nBytesThe number of bytes.
Returns
nBytes, or 0 after a failure.
Ghidra address:
NTSC-U/C: 0x0028f050
Ghidra address:
PAL: 0x00298a18

Implements File.

◆ Seek() [1/2]

int AsyncFile::Seek ( int nOffset,
int nOrigin )
overridevirtual

Move the position, clamped to the file, and refill the buffer of a file opened to read.

Parameters
nOffsetThe offset.
nOriginThe origin of the offset. Another value leaves the position unchanged.
Returns
The new position.
Ghidra address:
NTSC-U/C: 0x0028f178
Ghidra address:
PAL: 0x00298b40

Implements File.

◆ Tell() [1/2]

int AsyncFile::Tell ( )
inlineoverridevirtual

Report the position.

Returns
The position.
Ghidra address:
NTSC-U/C: 0x0028f270
Ghidra address:
PAL: 0x00298c38

Implements File.

◆ Flush() [1/2]

void AsyncFile::Flush ( )
overridevirtual

Write out the buffer of a file opened to write, or start refilling the buffer of a file opened to read.

Ghidra address:
NTSC-U/C: 0x0028f278
Ghidra address:
PAL: 0x00298c40

Implements File.

◆ Eof() [1/2]

bool AsyncFile::Eof ( )
inlineoverridevirtual

Report whether the position is at the end.

Returns
Whether the position equals the size.
Ghidra address:
NTSC-U/C: 0x0028f340
Ghidra address:
PAL: 0x00298d08

Implements File.

◆ Fail() [1/2]

bool AsyncFile::Fail ( )
inlineoverridevirtual

Report whether an operation failed.

Returns
Whether an operation failed.
Ghidra address:
NTSC-U/C: 0x0028f358
Ghidra address:
PAL: 0x00298d20

Implements File.

◆ Size() [1/2]

int AsyncFile::Size ( )
inlineoverridevirtual

Report the size.

Returns
The size in bytes.
Ghidra address:
NTSC-U/C: 0x0028f360
Ghidra address:
PAL: 0x00298d28

Implements File.

◆ UncompressedSize() [1/2]

int AsyncFile::UncompressedSize ( )
inlineoverridevirtual

Report the size before compression.

Returns
The size in bytes, or 0 for a file that is not a .gz file opened to read.
Ghidra address:
NTSC-U/C: 0x0028f368
Ghidra address:
PAL: 0x00298d30

Implements File.

◆ ReadDone() [1/2]

bool AsyncFile::ReadDone ( int * pnBytes)
overridevirtual

Copy what the buffer has of the read, refilling the buffer when the read needs more.

Parameters
pnBytesReceives the number of bytes read so far, except when a refill starts.
Returns
Whether the read finished.
Ghidra address:
NTSC-U/C: 0x0028ef00
Ghidra address:
PAL: 0x002988c8

Implements File.

◆ Open() [1/2]

void AsyncFile::Open ( const char * pszFile,
int nMode )

Open a file, and read the size before compression of a .gz file opened to read.

Parameters
pszFileThe file, relative to the root of the game files.
nModeThe open mode.
Ghidra address:
NTSC-U/C: 0x0028ec20
Ghidra address:
PAL: 0x002985e8

◆ Close() [1/2]

void AsyncFile::Close ( )

Write out the buffer of a file opened to write, close the file, and reset the state.

Ghidra address:
NTSC-U/C: 0x0028ed98
Ghidra address:
PAL: 0x00298760

◆ Read() [2/2]

virtual int AsyncFile::Read ( void * data,
int bytes )
virtual

Read bytes and wait for them.

Parameters
dataReceives the bytes.
bytesThe number of bytes.
Returns
The number of bytes read, or zero after a failure.
Ghidra address:
0x1000e0e0

Implements File.

◆ ReadAsync() [2/2]

virtual bool AsyncFile::ReadAsync ( void * data,
int bytes )
virtual

Start reading bytes, at most up to the end of the file.

Parameters
dataReceives the bytes.
bytesThe number of bytes.
Returns
Whether the read started.
Ghidra address:
0x1000e130

Implements File.

◆ Write() [2/2]

virtual int AsyncFile::Write ( const void * data,
int bytes )
virtual

Write bytes through the buffer.

Parameters
dataThe bytes.
bytesThe number of bytes.
Returns
The number of bytes, or zero after a failure.
Ghidra address:
0x1000e2b0

Implements File.

◆ Seek() [2/2]

virtual int AsyncFile::Seek ( int offset,
int origin )
virtual

Move the position, clamped to the file.

Parameters
offsetThe offset.
originThe origin, one of BinStream::SeekType.
Returns
The new position.
Ghidra address:
0x1000e3a0

Implements File.

◆ Tell() [2/2]

virtual int AsyncFile::Tell ( )
virtual

Report the position.

Returns
The position.
Ghidra address:
0x1000e990

Implements File.

◆ Flush() [2/2]

virtual void AsyncFile::Flush ( )
virtual

Write the buffer when writing, or refill it when reading.

Ghidra address:
0x1000e430

Implements File.

◆ Eof() [2/2]

virtual bool AsyncFile::Eof ( )
virtual

Report whether the position is at the end.

Returns
Whether the end was arrived at.
Ghidra address:
0x1000e4e0

Implements File.

◆ Fail() [2/2]

virtual bool AsyncFile::Fail ( )
virtual

Report whether an operation failed.

Returns
Whether an operation failed.
Ghidra address:
0x1000e500

Implements File.

◆ Size() [2/2]

virtual int AsyncFile::Size ( )
virtual

Report the size.

Returns
The size in bytes.
Ghidra address:
0x1000e510

Implements File.

◆ UncompressedSize() [2/2]

virtual int AsyncFile::UncompressedSize ( )
virtual

Report the size a .gz file records in its last four bytes, or zero for other files.

Returns
The size in bytes.
Ghidra address:
0x1000e980

Implements File.

◆ ReadDone() [2/2]

virtual bool AsyncFile::ReadDone ( int * bytes)
virtual

Copy buffered bytes of the read ReadAsync() started, refilling the buffer when it runs out.

Parameters
bytesReceives the number of bytes read so far.
Returns
Whether the read is complete.
Ghidra address:
0x1000e1b0

Implements File.

◆ Open() [2/2]

void AsyncFile::Open ( const char * name,
int mode )

Open a file.

Parameters
nameThe path.
modeThe open mode.
Ghidra address:
0x1000df10

◆ Close() [2/2]

void AsyncFile::Close ( )

Write out a written file and close it.

Ghidra address:
0x1000e0a0

The documentation for this class was generated from the following files: