Revert "Convert more defines to static constexpr."

This reverts commit 58382db331.

Mistakenly checked in debug code for another part of the codebase.
This commit is contained in:
Stephen Anthony 2022-12-01 19:08:27 -03:30
parent 58382db331
commit 61d6d89a21
5 changed files with 79 additions and 71 deletions

View File

@ -36,11 +36,11 @@ FSNodeZIP::FSNodeZIP(const string& p)
_zipFile = p.substr(0, pos+4);
// Expand '~' to the users 'home' directory
if(_zipFile[0] == '~')
if (_zipFile[0] == '~')
{
#if defined(BSPF_UNIX) || defined(BSPF_MACOS)
const char* const home = std::getenv("HOME"); // NOLINT (not thread safe)
if(home != nullptr)
if (home != nullptr)
_zipFile.replace(0, 1, home);
#elif defined(BSPF_WINDOWS)
_zipFile.replace(0, 1, HomeFinder::getHomePath());
@ -267,24 +267,12 @@ size_t FSNodeZIP::write(const stringstream& buffer) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AbstractFSNodePtr FSNodeZIP::getParent() const
{
cerr << "zip : " << _zipFile << endl
<< "vp : " << _virtualPath << endl
<< "path: " << _path << endl
<< "name: " << _name << endl;
if(_virtualPath.empty())
{
if(_realNode)
cerr << "parent: " << _realNode->getParent()->getPath();
else
cerr << "parent: nullptr";
cerr << "\n\n\n";
return _realNode ? _realNode->getParent() : nullptr;
}
const char* const start = _path.c_str();
const char* const end = lastPathComponent(_path);
cerr << "new zip: " << string(start, end - start - 1) << "\n\n\n";
return make_unique<FSNodeZIP>(string(start, end - start - 1));
}

View File

@ -51,7 +51,14 @@ void ZipHandler::open(const string& filename)
// Open the file and initialize it
if(!ptr->open())
throw runtime_error(errorMessage(ZipError::FILE_ERROR));
ptr->initialize();
try
{
ptr->initialize();
}
catch(...)
{
throw;
}
myZip = std::move(ptr);
@ -93,7 +100,7 @@ std::tuple<string, size_t> ZipHandler::next()
{
if(hasNext())
{
const ZipHeader* const header = myZip->nextFile();
const ZipHeader* header = myZip->nextFile();
if(!header)
throw runtime_error(errorMessage(ZipError::FILE_CORRUPT));
else if(header->uncompressedLength == 0)
@ -200,8 +207,8 @@ void ZipHandler::addToCache()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ZipHandler::ZipFile::ZipFile(const string& filename)
: myFilename{filename},
myBuffer{make_unique<uInt8[]>(DECOMPRESS_BUFSIZE)}
: myFilename(filename),
myBuffer(make_unique<uInt8[]>(DECOMPRESS_BUFSIZE))
{
std::fill(myBuffer.get(), myBuffer.get() + DECOMPRESS_BUFSIZE, 0);
}
@ -226,26 +233,33 @@ bool ZipHandler::ZipFile::open()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ZipHandler::ZipFile::initialize()
{
// Read ecd data
readEcd();
try
{
// Read ecd data
readEcd();
// Verify that we can work with this zipfile (no disk spanning allowed)
if(myEcd.diskNumber != myEcd.cdStartDiskNumber ||
myEcd.cdDiskEntries != myEcd.cdTotalEntries)
throw runtime_error(errorMessage(ZipError::UNSUPPORTED));
// Verify that we can work with this zipfile (no disk spanning allowed)
if(myEcd.diskNumber != myEcd.cdStartDiskNumber ||
myEcd.cdDiskEntries != myEcd.cdTotalEntries)
throw runtime_error(errorMessage(ZipError::UNSUPPORTED));
// Allocate memory for the central directory
myCd = make_unique<uInt8[]>(myEcd.cdSize + 1);
if(myCd == nullptr)
throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY));
// Allocate memory for the central directory
myCd = make_unique<uInt8[]>(myEcd.cdSize + 1);
if(myCd == nullptr)
throw runtime_error(errorMessage(ZipError::OUT_OF_MEMORY));
// Read the central directory
uInt64 read_length = 0;
const bool success = readStream(myCd, myEcd.cdStartDiskOffset, myEcd.cdSize, read_length);
if(!success)
throw runtime_error(errorMessage(ZipError::FILE_ERROR));
else if(read_length != myEcd.cdSize)
throw runtime_error(errorMessage(ZipError::FILE_TRUNCATED));
// Read the central directory
uInt64 read_length = 0;
const bool success = readStream(myCd, myEcd.cdStartDiskOffset, myEcd.cdSize, read_length);
if(!success)
throw runtime_error(errorMessage(ZipError::FILE_ERROR));
else if(read_length != myEcd.cdSize)
throw runtime_error(errorMessage(ZipError::FILE_TRUNCATED));
}
catch(...)
{
throw;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -292,7 +306,7 @@ void ZipHandler::ZipFile::readEcd()
if(offset >= 0)
{
// Extract ECD info
const EcdReader reader(buffer.get() + offset);
EcdReader const reader(buffer.get() + offset);
myEcd.diskNumber = reader.thisDiskNo();
myEcd.cdStartDiskNumber = reader.dirStartDisk();
myEcd.cdDiskEntries = reader.dirDiskEntries();
@ -334,7 +348,7 @@ const ZipHandler::ZipHeader* ZipHandler::ZipFile::nextFile()
{
// Make sure we have enough data
// If we're at or past the end, we're done
const CentralDirEntryReader reader(myCd.get() + myCdPos);
CentralDirEntryReader const reader(myCd.get() + myCdPos);
if(!reader.signatureCorrect() || ((myCdPos + reader.totalLength()) > myEcd.cdSize))
return nullptr;
@ -366,26 +380,33 @@ void ZipHandler::ZipFile::decompress(const ByteBuffer& out, uInt64 length)
if(myHeader.startDiskNumber != myEcd.diskNumber)
throw runtime_error(errorMessage(ZipError::UNSUPPORTED));
// Get the compressed data offset
const uInt64 offset = getCompressedDataOffset();
// Handle compression types
switch(myHeader.compression)
try
{
case 0:
decompressDataType0(offset, out, length);
break;
// Get the compressed data offset
const uInt64 offset = getCompressedDataOffset();
case 8:
decompressDataType8(offset, out, length);
break;
// Handle compression types
switch(myHeader.compression)
{
case 0:
decompressDataType0(offset, out, length);
break;
case 14:
// FIXME - LZMA format not yet supported
throw runtime_error(errorMessage(ZipError::LZMA_UNSUPPORTED));
case 8:
decompressDataType8(offset, out, length);
break;
default:
throw runtime_error(errorMessage(ZipError::UNSUPPORTED));
case 14:
// FIXME - LZMA format not yet supported
throw runtime_error(errorMessage(ZipError::LZMA_UNSUPPORTED));
default:
throw runtime_error(errorMessage(ZipError::UNSUPPORTED));
}
}
catch(...)
{
throw;
}
}
@ -393,7 +414,7 @@ void ZipHandler::ZipFile::decompress(const ByteBuffer& out, uInt64 length)
uInt64 ZipHandler::ZipFile::getCompressedDataOffset()
{
// Don't support a number of features
const GeneralFlagReader flags(myHeader.bitFlag);
GeneralFlagReader const flags(myHeader.bitFlag);
if(myHeader.startDiskNumber != myEcd.diskNumber ||
myHeader.versionNeeded > 63 || flags.patchData() ||
flags.encrypted() || flags.strongEncryption())
@ -441,7 +462,7 @@ void ZipHandler::ZipFile::decompressDataType8(
stream.opaque = Z_NULL;
stream.avail_in = 0;
stream.next_out = reinterpret_cast<Bytef *>(out.get());
stream.avail_out = static_cast<uInt32>(length);
stream.avail_out = static_cast<uInt32>(length); // TODO - use zip64
// Initialize the decompressor
int zerr = inflateInit2(&stream, -MAX_WBITS);
@ -471,7 +492,7 @@ void ZipHandler::ZipFile::decompressDataType8(
// Fill out the input data
stream.next_in = myBuffer.get();
stream.avail_in = static_cast<uInt32>(read_length);
stream.avail_in = static_cast<uInt32>(read_length); // TODO - use zip64
input_remaining -= read_length;
// Add a dummy byte at end of compressed data

View File

@ -300,7 +300,7 @@ class ZipHandler
private:
static constexpr size_t DECOMPRESS_BUFSIZE = 128_KB;
static constexpr size_t CACHE_SIZE = 64; // number of open files to cache
static constexpr size_t CACHE_SIZE = 16; // number of open files to cache
ZipFilePtr myZip;
std::array<ZipFilePtr, CACHE_SIZE> myZipCache;

View File

@ -274,7 +274,7 @@ void Thumbulator::dump_counters() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Thumbulator::dump_regs()
{
for(int cnt = 0; cnt <= 12; ++cnt)
for (int cnt = 0; cnt <= 12; cnt++)
{
statusMsg << "R" << std::dec << std::setfill(' ') << std::setw(2) << std::left << cnt
<< "= " << Base::HEX8 << reg_norm[cnt];

View File

@ -34,6 +34,17 @@ class Cartridge;
#define UNSAFE_OPTIMIZATIONS
#endif
#define ROMADDMASK 0x7FFFF
#define RAMADDMASK 0x7FFF
#define ROMSIZE (ROMADDMASK+1) // 512KB
#define RAMSIZE (RAMADDMASK+1) // 32KB
#define CPSR_N (1u<<31)
#define CPSR_Z (1u<<30)
#define CPSR_C (1u<<29)
#define CPSR_V (1u<<28)
#ifdef DEBUGGER_SUPPORT
#define THUMB_CYCLE_COUNT
#define COUNT_OPS
@ -324,19 +335,7 @@ class Thumbulator
ConfigureFor configuration;
Cartridge* myCartridge{nullptr};
static constexpr uInt32
ROMADDMASK = 0x7FFFF,
RAMADDMASK = 0x7FFF,
ROMSIZE = ROMADDMASK + 1, // 512KB
RAMSIZE = RAMADDMASK + 1, // 32KB
CPSR_N = 1u << 31,
CPSR_Z = 1u << 30,
CPSR_C = 1u << 29,
CPSR_V = 1u << 28;
Cartridge* myCartridge;
private:
// Following constructors and assignment operators not supported