ROM housekeeping

This commit is contained in:
Justin Scofield
2022-07-25 09:33:59 -04:00
parent 6011d1e6af
commit 8da0ac3219
2 changed files with 22 additions and 21 deletions

View File

@@ -145,11 +145,11 @@ absl::StatusOr<Bytes> ROM::Decompress(int offset, int size, bool reversed) {
ushort s2 = ((rom_data_[offset] & 0xFF)); ushort s2 = ((rom_data_[offset] & 0xFF));
if (reversed) { // Reversed byte order for overworld maps if (reversed) { // Reversed byte order for overworld maps
auto addr = (rom_data_[offset + 2]) | ((rom_data_[offset + 1]) << 8); auto addr = (rom_data_[offset + 2]) | ((rom_data_[offset + 1]) << 8);
if (addr > buffer_pos) { if (addr > offset) {
return absl::InternalError(absl::StrFormat( return absl::InternalError(absl::StrFormat(
"DecompressOverworldV2: Offset for command copy exceeds " "DecompressOverworldV2: Offset for command copy exceeds "
"current position (Offset : %#04x | Pos : %#06x)\n", "current position (Offset : %#04x | Pos : %#06x)\n",
addr, buffer_pos)); addr, offset));
} }
if (buffer_pos + length >= size) { if (buffer_pos + length >= size) {
size *= 2; size *= 2;
@@ -214,13 +214,10 @@ absl::StatusOr<Bytes> ROM::Convert3bppTo8bppSheet(Bytes sheet, int size) {
} }
uint ROM::GetGraphicsAddress(uint8_t offset) const { uint ROM::GetGraphicsAddress(uint8_t offset) const {
uint snes_address = 0; auto snes_address = (uint)((((rom_data_[0x4F80 + offset]) << 16) |
uint pc_address = 0;
snes_address = (uint)((((rom_data_[0x4F80 + offset]) << 16) |
((rom_data_[0x505F + offset]) << 8) | ((rom_data_[0x505F + offset]) << 8) |
((rom_data_[0x513E + offset])))); ((rom_data_[0x513E + offset]))));
pc_address = core::SnesToPc(snes_address); return core::SnesToPc(snes_address);
return pc_address;
} }
} // namespace app } // namespace app

View File

@@ -1,6 +1,7 @@
#ifndef YAZE_APP_ROM_H #ifndef YAZE_APP_ROM_H
#define YAZE_APP_ROM_H #define YAZE_APP_ROM_H
#include <array>
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <filesystem> #include <filesystem>
@@ -32,10 +33,12 @@ constexpr int kCommandRepeatingBytes = 4;
constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10, constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
0x08, 0x04, 0x02, 0x01}; 0x08, 0x04, 0x02, 0x01};
static constexpr int kTile32Num = 4432;
using OWBlockset = std::vector<std::vector<ushort>>;
struct OWMapTiles { struct OWMapTiles {
std::vector<std::vector<ushort>> light_world; // 64 maps * (32*32 tiles) OWBlockset light_world; // 64 maps
std::vector<std::vector<ushort>> dark_world; // 64 maps * (32*32 tiles) OWBlockset dark_world; // 64 maps
std::vector<std::vector<ushort>> special_world; // 32 maps * (32*32 tiles) OWBlockset special_world; // 32 maps
} typedef OWMapTiles; } typedef OWMapTiles;
class ROM { class ROM {
@@ -57,11 +60,9 @@ class ROM {
auto GetSize() const { return size_; } auto GetSize() const { return size_; }
auto GetTitle() const { return title; } auto GetTitle() const { return title; }
auto GetGraphicsBin() const { return graphics_bin_; } auto GetGraphicsBin() const { return graphics_bin_; }
auto GetMasterGraphicsBin() const { return master_gfx_bin_; }
auto GetVRAM() const { return pseudo_vram_; } auto GetVRAM() const { return pseudo_vram_; }
auto GetBytes() const { return rom_data_; } auto GetBytes() const { return rom_data_; }
auto data() { return rom_data_.data(); }
auto isLoaded() const { return is_loaded_; } auto isLoaded() const { return is_loaded_; }
auto Renderer() { return renderer_; } auto Renderer() { return renderer_; }
@@ -70,25 +71,28 @@ class ROM {
} }
uchar& operator[](int i) { uchar& operator[](int i) {
if (i > size_) { if (i > size_) {
std::cout << "Index out of bounds" << std::endl; std::cout << "ROM: Index out of bounds" << std::endl;
return rom_data_[0]; return rom_data_[0];
} }
return rom_data_[i]; return rom_data_[i];
} }
uchar& operator+(int i) {
if (i > size_) {
std::cout << "ROM: Index out of bounds" << std::endl;
return rom_data_[0];
}
return rom_data_[i];
}
const uchar* operator&() { return rom_data_.data(); }
private: private:
int num_sheets_ = 0; int num_sheets_ = 0;
long size_ = 0; long size_ = 0;
uchar* current_rom_;
uchar* master_gfx_bin_;
uchar title[21] = "ROM Not Loaded"; uchar title[21] = "ROM Not Loaded";
bool is_loaded_ = false; bool is_loaded_ = false;
ImVec4 display_palette_[8];
gfx::pseudo_vram pseudo_vram_;
Bytes rom_data_; Bytes rom_data_;
gfx::pseudo_vram pseudo_vram_;
std::shared_ptr<SDL_Renderer> renderer_; std::shared_ptr<SDL_Renderer> renderer_;
absl::flat_hash_map<int, gfx::Bitmap> graphics_bin_; absl::flat_hash_map<int, gfx::Bitmap> graphics_bin_;
}; };