cleanup snes_palette stuff
This commit is contained in:
@@ -599,7 +599,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
|||||||
/*z3_load=*/false);
|
/*z3_load=*/false);
|
||||||
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
|
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
|
||||||
if (col_file_palette_group_.size() != 0) {
|
if (col_file_palette_group_.size() != 0) {
|
||||||
col_file_palette_group_.Clear();
|
col_file_palette_group_.clear();
|
||||||
}
|
}
|
||||||
auto col_file_palette_group_status =
|
auto col_file_palette_group_status =
|
||||||
gfx::CreatePaletteGroupFromColFile(col_data_);
|
gfx::CreatePaletteGroupFromColFile(col_data_);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ absl::Status LoadGlobalSpritePalettes(const std::vector<uint8_t>& rom_data,
|
|||||||
palette_groups.global_sprites.AddPalette(
|
palette_groups.global_sprites.AddPalette(
|
||||||
gfx::ReadPaletteFromRom(kGlobalSpritesLW, /*num_colors=*/60, data));
|
gfx::ReadPaletteFromRom(kGlobalSpritesLW, /*num_colors=*/60, data));
|
||||||
palette_groups.global_sprites.AddPalette(
|
palette_groups.global_sprites.AddPalette(
|
||||||
gfx::ReadPaletteFromRom(globalSpritePalettesDW, /*num_colors=*/60, data));
|
gfx::ReadPaletteFromRom(kGlobalSpritePalettesDW, /*num_colors=*/60, data));
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,9 +152,9 @@ absl::Status LoadGrassColors(const std::vector<uint8_t>& rom_data,
|
|||||||
palette_groups.grass.AddColor(
|
palette_groups.grass.AddColor(
|
||||||
gfx::ReadColorFromRom(kHardcodedGrassLW, rom_data.data()));
|
gfx::ReadColorFromRom(kHardcodedGrassLW, rom_data.data()));
|
||||||
palette_groups.grass.AddColor(
|
palette_groups.grass.AddColor(
|
||||||
gfx::ReadColorFromRom(hardcodedGrassDW, rom_data.data()));
|
gfx::ReadColorFromRom(kHardcodedGrassDW, rom_data.data()));
|
||||||
palette_groups.grass.AddColor(
|
palette_groups.grass.AddColor(
|
||||||
gfx::ReadColorFromRom(hardcodedGrassSpecial, rom_data.data()));
|
gfx::ReadColorFromRom(kHardcodedGrassSpecial, rom_data.data()));
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ absl::Status Load3DObjectPalettes(const std::vector<uint8_t>& rom_data,
|
|||||||
palette_groups.object_3d.AddPalette(
|
palette_groups.object_3d.AddPalette(
|
||||||
gfx::ReadPaletteFromRom(kTriforcePalette, 8, data));
|
gfx::ReadPaletteFromRom(kTriforcePalette, 8, data));
|
||||||
palette_groups.object_3d.AddPalette(
|
palette_groups.object_3d.AddPalette(
|
||||||
gfx::ReadPaletteFromRom(crystalPalette, 8, data));
|
gfx::ReadPaletteFromRom(kCrystalPalette, 8, data));
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,30 +62,34 @@ constexpr int kOverworldPaletteMain = 0xDE6C8;
|
|||||||
constexpr int kOverworldPaletteAux = 0xDE86C;
|
constexpr int kOverworldPaletteAux = 0xDE86C;
|
||||||
constexpr int kOverworldPaletteAnimated = 0xDE604;
|
constexpr int kOverworldPaletteAnimated = 0xDE604;
|
||||||
constexpr int kGlobalSpritesLW = 0xDD218;
|
constexpr int kGlobalSpritesLW = 0xDD218;
|
||||||
constexpr int globalSpritePalettesDW = 0xDD290;
|
constexpr int kGlobalSpritePalettesDW = 0xDD290;
|
||||||
// Green, Blue, Red, Bunny, Electrocuted (15 colors each)
|
constexpr int kArmorPalettes =
|
||||||
constexpr int kArmorPalettes = 0xDD308;
|
0xDD308; /** < Green, Blue, Red, Bunny, Electrocuted (15 colors each) */
|
||||||
constexpr int kSpritesPalettesAux1 = 0xDD39E; // 7 colors each
|
constexpr int kSpritesPalettesAux1 = 0xDD39E; // 7 colors each
|
||||||
constexpr int kSpritesPalettesAux2 = 0xDD446; // 7 colors each
|
constexpr int kSpritesPalettesAux2 = 0xDD446; // 7 colors each
|
||||||
constexpr int kSpritesPalettesAux3 = 0xDD4E0; // 7 colors each
|
constexpr int kSpritesPalettesAux3 = 0xDD4E0; // 7 colors each
|
||||||
constexpr int kSwordPalettes = 0xDD630; // 3 colors each - 4 entries
|
constexpr int kSwordPalettes = 0xDD630; // 3 colors each - 4 entries
|
||||||
constexpr int kShieldPalettes = 0xDD648; // 4 colors each - 3 entries
|
constexpr int kShieldPalettes = 0xDD648; // 4 colors each - 3 entries
|
||||||
constexpr int kHudPalettes = 0xDD660;
|
constexpr int kHudPalettes = 0xDD660;
|
||||||
constexpr int dungeonMapPalettes = 0xDD70A; // 21 colors
|
constexpr int kDungeonMapPalettes = 0xDD70A; // 21 colors
|
||||||
constexpr int kDungeonMainPalettes = 0xDD734; //(15*6) colors each - 20 entries
|
constexpr int kDungeonMainPalettes =
|
||||||
constexpr int dungeonMapBgPalettes = 0xDE544; // 16*6
|
0xDD734; // (15*6) colors each - 20 entries
|
||||||
|
constexpr int kDungeonMapBgPalettes = 0xDE544; // 16*6
|
||||||
|
|
||||||
// Mirrored Value at 0x75645 : 0x75625
|
// Mirrored Value at 0x75645 : 0x75625
|
||||||
constexpr int kHardcodedGrassLW = 0x5FEA9;
|
constexpr int kHardcodedGrassLW = 0x5FEA9;
|
||||||
constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F
|
constexpr int kHardcodedGrassDW = 0x05FEB3; // 0x7564F
|
||||||
constexpr int hardcodedGrassSpecial = 0x75640;
|
constexpr int kHardcodedGrassSpecial = 0x75640;
|
||||||
constexpr int kOverworldMiniMapPalettes = 0x55B27;
|
constexpr int kOverworldMiniMapPalettes = 0x55B27;
|
||||||
constexpr int kTriforcePalette = 0x64425;
|
constexpr int kTriforcePalette = 0x64425;
|
||||||
constexpr int crystalPalette = 0xF4CD3;
|
constexpr int kCrystalPalette = 0xF4CD3;
|
||||||
// 2 bytes for each overworld area (320)
|
constexpr int CustomAreaSpecificBGPalette =
|
||||||
constexpr int customAreaSpecificBGPalette = 0x140000;
|
0x140000; /** < 2 bytes for each overworld area (320) */
|
||||||
constexpr int customAreaSpecificBGASM = 0x140150;
|
|
||||||
|
constexpr int CustomAreaSpecificBGASM = 0x140150;
|
||||||
|
|
||||||
// 1 byte, not 0 if enabled
|
// 1 byte, not 0 if enabled
|
||||||
constexpr int customAreaSpecificBGEnabled = 0x140140;
|
constexpr int kCustomAreaSpecificBGEnabled = 0x140140;
|
||||||
|
|
||||||
uint32_t GetPaletteAddress(const std::string& group_name, size_t palette_index,
|
uint32_t GetPaletteAddress(const std::string& group_name, size_t palette_index,
|
||||||
size_t color_index);
|
size_t color_index);
|
||||||
@@ -199,7 +203,7 @@ struct PaletteGroup {
|
|||||||
palettes[0].AddColor(color);
|
palettes[0].AddColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear() { palettes.clear(); }
|
void clear() { palettes.clear(); }
|
||||||
void SetName(const std::string& name) { name_ = name; }
|
void SetName(const std::string& name) { name_ = name; }
|
||||||
auto name() const { return name_; }
|
auto name() const { return name_; }
|
||||||
auto size() const { return palettes.size(); }
|
auto size() const { return palettes.size(); }
|
||||||
@@ -307,21 +311,21 @@ struct PaletteGroupMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
overworld_main.Clear();
|
overworld_main.clear();
|
||||||
overworld_aux.Clear();
|
overworld_aux.clear();
|
||||||
overworld_animated.Clear();
|
overworld_animated.clear();
|
||||||
hud.Clear();
|
hud.clear();
|
||||||
global_sprites.Clear();
|
global_sprites.clear();
|
||||||
armors.Clear();
|
armors.clear();
|
||||||
swords.Clear();
|
swords.clear();
|
||||||
shields.Clear();
|
shields.clear();
|
||||||
sprites_aux1.Clear();
|
sprites_aux1.clear();
|
||||||
sprites_aux2.Clear();
|
sprites_aux2.clear();
|
||||||
sprites_aux3.Clear();
|
sprites_aux3.clear();
|
||||||
dungeon_main.Clear();
|
dungeon_main.clear();
|
||||||
grass.Clear();
|
grass.clear();
|
||||||
object_3d.Clear();
|
object_3d.clear();
|
||||||
overworld_mini_map.Clear();
|
overworld_mini_map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() {
|
bool empty() {
|
||||||
@@ -339,7 +343,9 @@ struct PaletteGroupMap {
|
|||||||
absl::StatusOr<PaletteGroup> CreatePaletteGroupFromColFile(
|
absl::StatusOr<PaletteGroup> CreatePaletteGroupFromColFile(
|
||||||
std::vector<SnesColor>& colors);
|
std::vector<SnesColor>& colors);
|
||||||
|
|
||||||
// Take a SNESPalette with N many colors and divide it into palettes of 8 colors
|
/**
|
||||||
|
* @brief Take a SNESPalette, divide it into palettes of 8 colors
|
||||||
|
*/
|
||||||
absl::StatusOr<PaletteGroup> CreatePaletteGroupFromLargePalette(
|
absl::StatusOr<PaletteGroup> CreatePaletteGroupFromLargePalette(
|
||||||
SnesPalette& palette, int num_colors = 8);
|
SnesPalette& palette, int num_colors = 8);
|
||||||
|
|
||||||
@@ -352,7 +358,8 @@ absl::StatusOr<PaletteGroup> CreatePaletteGroupFromLargePalette(
|
|||||||
* groups.
|
* groups.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
absl::Status LoadAllPalettes(const std::vector<uint8_t>& rom_data, PaletteGroupMap& groups);
|
absl::Status LoadAllPalettes(const std::vector<uint8_t>& rom_data,
|
||||||
|
PaletteGroupMap& groups);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents a set of palettes used in a SNES graphics system.
|
* @brief Represents a set of palettes used in a SNES graphics system.
|
||||||
|
|||||||
@@ -62,15 +62,15 @@ absl::StatusOr<std::vector<uint8_t>> Rom::Load2BppGraphics() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
absl::Status Rom::LoadLinkGraphics() {
|
absl::Status Rom::LoadLinkGraphics() {
|
||||||
const uint32_t link_gfx_offset = 0x80000; // $10:8000
|
const uint32_t kLinkGfxOffset = 0x80000; // $10:8000
|
||||||
const uint16_t link_gfx_length = 0x800; // 0x4000 or 0x7000?
|
const uint16_t kLinkGfxLength = 0x800; // 0x4000 or 0x7000?
|
||||||
|
|
||||||
// Load Links graphics from the ROM
|
// Load Links graphics from the ROM
|
||||||
for (int i = 0; i < kNumLinkSheets; i++) {
|
for (int i = 0; i < kNumLinkSheets; i++) {
|
||||||
ASSIGN_OR_RETURN(
|
ASSIGN_OR_RETURN(
|
||||||
auto link_sheet_data,
|
auto link_sheet_data,
|
||||||
ReadByteVector(/*offset=*/link_gfx_offset + (i * link_gfx_length),
|
ReadByteVector(/*offset=*/kLinkGfxOffset + (i * kLinkGfxLength),
|
||||||
/*length=*/link_gfx_length))
|
/*length=*/kLinkGfxLength))
|
||||||
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
|
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
|
||||||
link_graphics_[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
link_graphics_[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||||
gfx::kTilesheetDepth, link_sheet_8bpp);
|
gfx::kTilesheetDepth, link_sheet_8bpp);
|
||||||
@@ -205,9 +205,9 @@ absl::Status Rom::LoadFromPointer(uchar* data, size_t length, bool z3_load) {
|
|||||||
|
|
||||||
absl::Status Rom::LoadZelda3() {
|
absl::Status Rom::LoadZelda3() {
|
||||||
// Check if the ROM has a header
|
// Check if the ROM has a header
|
||||||
constexpr size_t baseROMSize = 1048576; // 1MB
|
constexpr size_t kBaseRomSize = 1048576; // 1MB
|
||||||
constexpr size_t headerSize = 0x200; // 512 bytes
|
constexpr size_t kHeaderSize = 0x200; // 512 bytes
|
||||||
if (size_ % baseROMSize == headerSize) {
|
if (size_ % kBaseRomSize == kHeaderSize) {
|
||||||
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);
|
||||||
@@ -231,8 +231,8 @@ absl::Status Rom::LoadZelda3() {
|
|||||||
RETURN_IF_ERROR(LoadGfxGroups());
|
RETURN_IF_ERROR(LoadGfxGroups());
|
||||||
|
|
||||||
// Expand the ROM data to 2MB without changing the data in the first 1MB
|
// Expand the ROM data to 2MB without changing the data in the first 1MB
|
||||||
rom_data_.resize(baseROMSize * 2);
|
rom_data_.resize(kBaseRomSize * 2);
|
||||||
size_ = baseROMSize * 2;
|
size_ = kBaseRomSize * 2;
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
@@ -349,7 +349,6 @@ absl::Status Rom::SaveToFile(bool backup, bool save_new, std::string filename) {
|
|||||||
|
|
||||||
absl::Status Rom::SavePalette(int index, const std::string& group_name,
|
absl::Status Rom::SavePalette(int index, const std::string& group_name,
|
||||||
gfx::SnesPalette& palette) {
|
gfx::SnesPalette& palette) {
|
||||||
// Iterate through all colors in the palette
|
|
||||||
for (size_t j = 0; j < palette.size(); ++j) {
|
for (size_t j = 0; j < palette.size(); ++j) {
|
||||||
gfx::SnesColor color = palette[j];
|
gfx::SnesColor color = palette[j];
|
||||||
// If the color is modified, save the color to the ROM
|
// If the color is modified, save the color to the ROM
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ static const std::map<Z3_Version, VersionConstants> kVersionConstantsMap = {
|
|||||||
|
|
||||||
constexpr uint32_t kNumGfxSheets = 223;
|
constexpr uint32_t kNumGfxSheets = 223;
|
||||||
constexpr uint32_t kNumLinkSheets = 14;
|
constexpr uint32_t kNumLinkSheets = 14;
|
||||||
|
constexpr uint32_t kTile16Ptr = 0x78000;
|
||||||
constexpr uint32_t kNormalGfxSpaceStart = 0x87000;
|
constexpr uint32_t kNormalGfxSpaceStart = 0x87000;
|
||||||
constexpr uint32_t kNormalGfxSpaceEnd = 0xC4200;
|
constexpr uint32_t kNormalGfxSpaceEnd = 0xC4200;
|
||||||
constexpr uint32_t kFontSpriteLocation = 0x70000;
|
constexpr uint32_t kFontSpriteLocation = 0x70000;
|
||||||
@@ -219,6 +220,27 @@ class Rom : public core::ExperimentFlags {
|
|||||||
*/
|
*/
|
||||||
absl::Status SaveAllPalettes();
|
absl::Status SaveAllPalettes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Expand the Rom data to a specified size.
|
||||||
|
*/
|
||||||
|
void Expand(int size) {
|
||||||
|
rom_data_.resize(size);
|
||||||
|
size_ = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close the Rom file.
|
||||||
|
*/
|
||||||
|
absl::Status Close() {
|
||||||
|
rom_data_.clear();
|
||||||
|
size_ = 0;
|
||||||
|
is_loaded_ = false;
|
||||||
|
return absl::OkStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Precondition check for reading and writing to the Rom.
|
||||||
|
*/
|
||||||
absl::Status ReadWritePreconditions() {
|
absl::Status ReadWritePreconditions() {
|
||||||
if (!is_loaded_) {
|
if (!is_loaded_) {
|
||||||
return absl::FailedPreconditionError("ROM file not loaded");
|
return absl::FailedPreconditionError("ROM file not loaded");
|
||||||
@@ -277,7 +299,7 @@ class Rom : public core::ExperimentFlags {
|
|||||||
|
|
||||||
absl::StatusOr<gfx::Tile16> ReadTile16(uint32_t tile16_id) {
|
absl::StatusOr<gfx::Tile16> ReadTile16(uint32_t tile16_id) {
|
||||||
// Skip 8 bytes per tile.
|
// Skip 8 bytes per tile.
|
||||||
auto tpos = 0x78000 + (tile16_id * 0x08);
|
auto tpos = kTile16Ptr + (tile16_id * 0x08);
|
||||||
gfx::Tile16 tile16;
|
gfx::Tile16 tile16;
|
||||||
ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
|
ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
|
||||||
tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
|
tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
|
||||||
@@ -295,7 +317,7 @@ class Rom : public core::ExperimentFlags {
|
|||||||
|
|
||||||
absl::Status WriteTile16(int tile16_id, const gfx::Tile16& tile) {
|
absl::Status WriteTile16(int tile16_id, const gfx::Tile16& tile) {
|
||||||
// Skip 8 bytes per tile.
|
// Skip 8 bytes per tile.
|
||||||
auto tpos = 0x78000 + (tile16_id * 0x08);
|
auto tpos = kTile16Ptr + (tile16_id * 0x08);
|
||||||
RETURN_IF_ERROR(WriteShort(tpos, gfx::TileInfoToWord(tile.tile0_)));
|
RETURN_IF_ERROR(WriteShort(tpos, gfx::TileInfoToWord(tile.tile0_)));
|
||||||
tpos += 2;
|
tpos += 2;
|
||||||
RETURN_IF_ERROR(WriteShort(tpos, gfx::TileInfoToWord(tile.tile1_)));
|
RETURN_IF_ERROR(WriteShort(tpos, gfx::TileInfoToWord(tile.tile1_)));
|
||||||
@@ -420,16 +442,13 @@ class Rom : public core::ExperimentFlags {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Expand(int size) {
|
uint8_t& operator[](int i) {
|
||||||
rom_data_.resize(size);
|
if (i > size_) {
|
||||||
size_ = size;
|
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_
|
||||||
}
|
<< std::endl;
|
||||||
|
return rom_data_[0];
|
||||||
absl::Status Close() {
|
}
|
||||||
rom_data_.clear();
|
return rom_data_[i];
|
||||||
size_ = 0;
|
|
||||||
is_loaded_ = false;
|
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core::ResourceLabelManager* resource_label() {
|
core::ResourceLabelManager* resource_label() {
|
||||||
@@ -439,6 +458,14 @@ class Rom : public core::ExperimentFlags {
|
|||||||
return kVersionConstantsMap.at(version_);
|
return kVersionConstantsMap.at(version_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto is_loaded() const {
|
||||||
|
if (!absl::StrContains(filename_, ".sfc") &&
|
||||||
|
!absl::StrContains(filename_, ".smc")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return is_loaded_;
|
||||||
|
}
|
||||||
|
|
||||||
// Full graphical data for the game
|
// Full graphical data for the game
|
||||||
std::vector<uint8_t> graphics_buffer() const { return graphics_buffer_; }
|
std::vector<uint8_t> graphics_buffer() const { return graphics_buffer_; }
|
||||||
|
|
||||||
@@ -461,25 +488,9 @@ class Rom : public core::ExperimentFlags {
|
|||||||
auto end() { return rom_data_.end(); }
|
auto end() { return rom_data_.end(); }
|
||||||
auto data() { return rom_data_.data(); }
|
auto data() { return rom_data_.data(); }
|
||||||
auto vector() const { return rom_data_; }
|
auto vector() const { return rom_data_; }
|
||||||
auto filename() const { return filename_; }
|
|
||||||
auto is_loaded() const {
|
|
||||||
if (!absl::StrContains(filename_, ".sfc") &&
|
|
||||||
!absl::StrContains(filename_, ".smc")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return is_loaded_;
|
|
||||||
}
|
|
||||||
auto set_filename(std::string name) { filename_ = name; }
|
|
||||||
auto version() const { return version_; }
|
auto version() const { return version_; }
|
||||||
|
auto filename() const { return filename_; }
|
||||||
uint8_t& operator[](int i) {
|
auto set_filename(std::string name) { filename_ = name; }
|
||||||
if (i > size_) {
|
|
||||||
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_
|
|
||||||
<< std::endl;
|
|
||||||
return rom_data_[0];
|
|
||||||
}
|
|
||||||
return rom_data_[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::vector<uint8_t>> main_blockset_ids;
|
std::vector<std::vector<uint8_t>> main_blockset_ids;
|
||||||
std::vector<std::vector<uint8_t>> room_blockset_ids;
|
std::vector<std::vector<uint8_t>> room_blockset_ids;
|
||||||
|
|||||||
Reference in New Issue
Block a user