Files
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

153 lines
3.2 KiB
C++

#include <munga.hpp>
#pragma hdrstop
#if !defined(FILESTRM_HPP)
# include <filestrm.hpp>
#endif
//#############################################################################
//########################### FileStream ################################
//#############################################################################
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
FileStream::FileStream(
const char* file_name,
Logical writable
):
MemoryStream(NULL, 0)
{
Open(file_name, writable);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
FileStream::Open(
const char* file_name,
Logical writable
)
{
readOnly = !writable;
fileHandle = -1;
currentPosition = streamStart = NULL;
streamSize = 0;
if (file_name)
{
Check_Pointer(file_name);
fileHandle = OpenImplementation(file_name, readOnly);
}
if (fileHandle != -1)
{
if (readOnly)
{
streamSize = SeekImplementation(fileHandle, 0, True);
SeekImplementation(fileHandle, 0);
}
else
{
streamSize = 0xFFFFFFFFU;
}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
FileStream::Close()
{
Check(this);
//
//---------------------------------
// If the file was opened, close it
//---------------------------------
//
if (fileHandle != -1)
{
CloseImplementation(fileHandle);
}
fileHandle = -1;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
FileStream::SetPointer(size_t index)
{
Check(this);
Verify(fileHandle != -1);
currentPosition = (char*)SeekImplementation(fileHandle, index);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream&
FileStream::AdvancePointer(size_t index)
{
Check(this);
Verify(fileHandle != -1);
currentPosition =
(char*)SeekImplementation(fileHandle, (size_t)currentPosition + index);
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream&
FileStream::RewindPointer(size_t index)
{
Check(this);
Verify(fileHandle != -1);
currentPosition =
(char*)SeekImplementation(fileHandle, (size_t)currentPosition + index);
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream&
FileStream::ReadBytes(
void *ptr,
size_t number_of_bytes
)
{
Check(this);
Verify(fileHandle != -1);
Verify(readOnly);
size_t read = ReadImplementation(fileHandle, ptr, number_of_bytes);
Verify(read == number_of_bytes);
currentPosition += read;
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MemoryStream&
FileStream::WriteBytes(
const void *ptr,
size_t number_of_bytes
)
{
Check(this);
Verify(fileHandle != -1);
Verify(!readOnly);
size_t written = WriteImplementation(fileHandle, ptr, number_of_bytes);
Verify(written == number_of_bytes);
currentPosition += written;
return *this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Logical
FileStream::TestInstance() const
{
return True;
}