chore: Update ReadWritePreconditions for empty data but loaded file

This commit is contained in:
scawful
2024-08-14 19:55:57 -04:00
parent 1234510d29
commit 97dda2bfd9
2 changed files with 14 additions and 10 deletions

View File

@@ -208,11 +208,6 @@ absl::Status Rom::LoadZelda3() {
constexpr size_t baseROMSize = 1048576; // 1MB constexpr size_t baseROMSize = 1048576; // 1MB
constexpr size_t headerSize = 0x200; // 512 bytes constexpr size_t headerSize = 0x200; // 512 bytes
if (size_ % baseROMSize == headerSize) { if (size_ % baseROMSize == headerSize) {
has_header_ = true;
}
// Remove header if present
if (has_header_) {
auto header = auto header =
std::vector<uchar>(rom_data_.begin(), rom_data_.begin() + 0x200); std::vector<uchar>(rom_data_.begin(), rom_data_.begin() + 0x200);
rom_data_.erase(rom_data_.begin(), rom_data_.begin() + 0x200); rom_data_.erase(rom_data_.begin(), rom_data_.begin() + 0x200);

View File

@@ -212,7 +212,11 @@ class Rom : public core::ExperimentFlags {
absl::Status ReadWritePreconditions() { absl::Status ReadWritePreconditions() {
if (!is_loaded_) { if (!is_loaded_) {
return absl::FailedPreconditionError("ROM not loaded"); return absl::FailedPreconditionError("ROM file not loaded");
}
if (rom_data_.empty() || size_ == 0) {
return absl::FailedPreconditionError(
"File was loaded, but ROM data was empty.");
} }
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -499,7 +503,6 @@ class Rom : public core::ExperimentFlags {
} }
auto error_message = absl::StrFormat("Invalid write argument type: %s", auto error_message = absl::StrFormat("Invalid write argument type: %s",
typeid(action.value).name()); typeid(action.value).name());
throw std::runtime_error(error_message);
return absl::InvalidArgumentError(error_message); return absl::InvalidArgumentError(error_message);
} }
@@ -522,10 +525,16 @@ class Rom : public core::ExperimentFlags {
absl::Status LoadGfxGroups(); absl::Status LoadGfxGroups();
absl::Status SaveGroupsToRom(); absl::Status SaveGroupsToRom();
long size_ = 0; // ROM file loaded flag
bool is_loaded_ = false; bool is_loaded_ = false;
bool has_header_ = false;
std::string title_ = "ROM Not Loaded"; // Size of the ROM data.
unsigned long size_ = 0;
// Title of the ROM loaded from the header
std::string title_ = "ROM not loaded";
// Filename of the ROM
std::string filename_ = ""; std::string filename_ = "";
// Full contiguous rom space // Full contiguous rom space