resonance 1.0.1
Loading...
Searching...
No Matches
ACircBuff Class Reference

Ring buffer the movie stream reads its file through. More...

#include <acircbuff.h>

Public Member Functions

 ACircBuff (char *pBuff, int nSize)
 Take over a buffer of nSize bytes with both pointers at its start.
int Avail ()
 Report how many bytes can be written before the write pointer meets the read pointer.
int IsRoom (int nBytes)
 Report whether nBytes fit in one contiguous write.
void WrapWriteIfOk ()
 Move the write pointer back to mBuff once it has reached mWrap, unless the read pointer is still at mBuff.
char * AdvanceRead (int nBytes)
 Consume nBytes, wrapping the read pointer past mWrap.
int FullyRead (const char *pStart, int nBytes) const
 Report whether the write pointer lies outside the nBytes starting at pStart.
int WillWriteWrap (int nBytes) const
 Clamp nBytes to the space between the write pointer and mWrap.
char * AdvanceWrite (int nBytes)
 Commit nBytes written at the write pointer.
int Write (const void *pSrc, int nBytes)
 Copy nBytes into the buffer in one piece.
int Write (int nFile, int nBytes)
 Read nBytes from a file into the buffer in one piece.
void Dump (const char *pszLabel) const
 Log the pointers and the size under a label.

Public Attributes

char * mBuff
int mBuffSize
char * mWrite
char * mRead
char * mWrap

Detailed Description

Ring buffer the movie stream reads its file through.

The class is not polymorphic and emits no RTTI. Its name comes from the debugging symbols of the North American demo release. Its dump routine prints "circbuff:" and the member names pRead, pWrite, pWrap, pBuff, and buffsz. The movie stream's chunk error message calls the same object "pCircBuff". The buffer memory belongs to the caller, and the class never frees it.

Bytes are written at mWrite and consumed at mRead. mWrap marks the end of the usable region, and a pointer that reaches it wraps back to mBuff. A write pointer equal to the read pointer reports no free space rather than an empty buffer.

Constructor & Destructor Documentation

◆ ACircBuff()

ACircBuff::ACircBuff ( char * pBuff,
int nSize )

Take over a buffer of nSize bytes with both pointers at its start.

Parameters
pBuffThe buffer.
nSizeThe buffer size in bytes.
Ghidra address:
NTSC-U/C: 0x0060e8b0
Ghidra address:
PAL: 0x0064f520

Member Function Documentation

◆ Avail()

int ACircBuff::Avail ( )

Report how many bytes can be written before the write pointer meets the read pointer.

One byte is always held back. A write pointer equal to the read pointer reports zero.

Returns
The free space in bytes.
Ghidra address:
NTSC-U/C: 0x0060e930
Ghidra address:
PAL: 0x0064f5a0

◆ IsRoom()

int ACircBuff::IsRoom ( int nBytes)

Report whether nBytes fit in one contiguous write.

The routine has no caller.

Parameters
nBytesThe size to test.
Returns
Non-zero when the bytes fit.
Ghidra address:
NTSC-U/C: 0x0060e998
Ghidra address:
PAL: 0x0064f608

◆ WrapWriteIfOk()

void ACircBuff::WrapWriteIfOk ( )

Move the write pointer back to mBuff once it has reached mWrap, unless the read pointer is still at mBuff.

Ghidra address:
NTSC-U/C: 0x0060ea20
Ghidra address:
PAL: 0x0064f690

◆ AdvanceRead()

char * ACircBuff::AdvanceRead ( int nBytes)

Consume nBytes, wrapping the read pointer past mWrap.

Parameters
nBytesThe number of bytes consumed.
Returns
The new read pointer.
Ghidra address:
NTSC-U/C: 0x0060ea50
Ghidra address:
PAL: 0x0064f6c0

◆ FullyRead()

int ACircBuff::FullyRead ( const char * pStart,
int nBytes ) const

Report whether the write pointer lies outside the nBytes starting at pStart.

The range wraps past mWrap to mBuff.

Parameters
pStartThe start of the range.
nBytesThe length of the range.
Returns
Non-zero when the write pointer is outside the range.
Ghidra address:
NTSC-U/C: 0x0060ea80
Ghidra address:
PAL: 0x0064f6f0

◆ WillWriteWrap()

int ACircBuff::WillWriteWrap ( int nBytes) const

Clamp nBytes to the space between the write pointer and mWrap.

Parameters
nBytesThe size requested.
Returns
The size that can be written without wrapping.
Ghidra address:
NTSC-U/C: 0x0060eaf0
Ghidra address:
PAL: 0x0064f760

◆ AdvanceWrite()

char * ACircBuff::AdvanceWrite ( int nBytes)

Commit nBytes written at the write pointer.

The write pointer wraps to mBuff once it reaches mWrap, unless the read pointer is still at mBuff.

Parameters
nBytesThe number of bytes written.
Returns
The new write pointer.
Ghidra address:
NTSC-U/C: 0x0060eb18
Ghidra address:
PAL: 0x0064f788

◆ Write() [1/2]

int ACircBuff::Write ( const void * pSrc,
int nBytes )

Copy nBytes into the buffer in one piece.

The routine has no caller.

The bytes go at the write pointer, or at mBuff when they do not fit before mWrap. Nothing is copied unless they fit short of the read pointer.

Parameters
pSrcThe bytes to copy.
nBytesThe number of bytes.
Returns
nBytes, or 0 when nothing was copied.
Ghidra address:
NTSC-U/C: 0x0060eb48
Ghidra address:
PAL: 0x0064f7b8

◆ Write() [2/2]

int ACircBuff::Write ( int nFile,
int nBytes )

Read nBytes from a file into the buffer in one piece.

The routine has no caller.

The placement rule is the one the other Write() uses. The count read() returns is ignored, and the write pointer advances by nBytes regardless.

Parameters
nFileThe file to read.
nBytesThe number of bytes.
Returns
nBytes, or 0 when nothing was read.
Ghidra address:
NTSC-U/C: 0x0060ec08
Ghidra address:
PAL: 0x0064f878

◆ Dump()

void ACircBuff::Dump ( const char * pszLabel) const

Log the pointers and the size under a label.

Parameters
pszLabelThe label printed first.
Ghidra address:
NTSC-U/C: 0x0060ecd0
Ghidra address:
PAL: 0x0064f940

Member Data Documentation

◆ mBuff

char* ACircBuff::mBuff

Start of the buffer. +0x00

◆ mBuffSize

int ACircBuff::mBuffSize

Size of the buffer in bytes. +0x04

◆ mWrite

char* ACircBuff::mWrite

Where the next byte is written. +0x08

◆ mRead

char* ACircBuff::mRead

Where the next byte is consumed. +0x0c

◆ mWrap

char* ACircBuff::mWrap

End of the usable region, mBuff plus mBuffSize. +0x10


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