From b1bc0839c3d36abac175fd1f336f834bb3a67355 Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 17 Aug 2023 20:31:02 -0400 Subject: [PATCH] cleanup ROM class --- src/app/rom.cc | 25 ------------------------- src/app/rom.h | 29 +++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/app/rom.cc b/src/app/rom.cc index a8c99ecb..36d058c0 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -27,11 +27,6 @@ namespace yaze { namespace app { -using gfx::lc_lz2::CompressionPiece; -using gfx::lc_lz2::kCommandDirectCopy; -using gfx::lc_lz2::kCommandMod; -using gfx::lc_lz2::kSnesByteMax; - namespace { int GetGraphicsAddress(const uchar* data, uint8_t offset) { @@ -378,26 +373,6 @@ gfx::SNESPalette ROM::ReadPalette(int offset, int num_colors) { // ============================================================================ -void ROM::Write(int addr, int value) { rom_data_[addr] = value; } - -void ROM::WriteShort(int addr, int value) { - rom_data_[addr] = (uchar)(value & 0xFF); - rom_data_[addr + 1] = (uchar)((value >> 8) & 0xFF); -} - -// ============================================================================ - -void ROM::WriteColor(uint32_t address, const gfx::SNESColor& color) { - uint16_t bgr = ((color.GetSNES() >> 10) & 0x1F) | - ((color.GetSNES() & 0x1F) << 10) | (color.GetSNES() & 0x7C00); - - // Write the 16-bit color value to the ROM at the specified address - rom_data_[address] = static_cast(bgr & 0xFF); - rom_data_[address + 1] = static_cast((bgr >> 8) & 0xFF); -} - -// ============================================================================ - uint32_t ROM::GetPaletteAddress(const std::string& groupName, size_t paletteIndex, size_t color_index) const { // Retrieve the base address for the palette group diff --git a/src/app/rom.h b/src/app/rom.h index 470a8696..2daf5737 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -41,6 +41,13 @@ constexpr int kTitleStringOffset = 0x7FC0; constexpr int kTitleStringLength = 20; constexpr int kSNESToPCOffset = 0x138000; +constexpr uint32_t kNumGfxSheets = 223; +constexpr uint32_t kNormalGfxSpaceStart = 0x87000; +constexpr uint32_t kNormalGfxSpaceEnd = 0xC4200; +constexpr uint32_t kPtrTableStart = 0x4F80; +constexpr uint32_t kLinkSpriteLocation = 0x80000; +constexpr uint32_t kFontSpriteLocation = 0x70000; + const absl::flat_hash_map paletteGroupAddresses = { {"ow_main", core::overworldPaletteMain}, {"ow_aux", core::overworldPaletteAuxialiary}, @@ -90,19 +97,29 @@ class ROM { gfx::SNESPalette ReadPalette(int offset, int num_colors); // Write functions - void Write(int addr, int value); - void WriteShort(int addr, int value); - void WriteColor(uint32_t address, const gfx::SNESColor& color); + void Write(int addr, int value) { rom_data_[addr] = value; } - Bytes GetGraphicsBuffer() const { return graphics_buffer_; } - gfx::BitmapTable GetGraphicsBin() const { return graphics_bin_; } + void WriteShort(int addr, int value) { + rom_data_[addr] = (uint16_t)(value & 0xFF); + rom_data_[addr + 1] = (uint16_t)((value >> 8) & 0xFF); + } + + void WriteColor(uint32_t address, const gfx::SNESColor& color) { + uint16_t bgr = ((color.GetSNES() >> 10) & 0x1F) | + ((color.GetSNES() & 0x1F) << 10) | + (color.GetSNES() & 0x7C00); + + // Write the 16-bit color value to the ROM at the specified address + WriteShort(address, bgr); + } uint32_t GetPaletteAddress(const std::string& groupName, size_t paletteIndex, size_t colorIndex) const; - gfx::PaletteGroup GetPaletteGroup(const std::string& group) { return palette_groups_[group]; } + Bytes GetGraphicsBuffer() const { return graphics_buffer_; } + gfx::BitmapTable GetGraphicsBin() const { return graphics_bin_; } auto title() const { return title_; } auto size() const { return size_; }