cleanup snes_palette stuff
This commit is contained in:
@@ -599,7 +599,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
||||
/*z3_load=*/false);
|
||||
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
|
||||
if (col_file_palette_group_.size() != 0) {
|
||||
col_file_palette_group_.Clear();
|
||||
col_file_palette_group_.clear();
|
||||
}
|
||||
auto col_file_palette_group_status =
|
||||
gfx::CreatePaletteGroupFromColFile(col_data_);
|
||||
|
||||
@@ -73,7 +73,7 @@ absl::Status LoadGlobalSpritePalettes(const std::vector<uint8_t>& rom_data,
|
||||
palette_groups.global_sprites.AddPalette(
|
||||
gfx::ReadPaletteFromRom(kGlobalSpritesLW, /*num_colors=*/60, data));
|
||||
palette_groups.global_sprites.AddPalette(
|
||||
gfx::ReadPaletteFromRom(globalSpritePalettesDW, /*num_colors=*/60, data));
|
||||
gfx::ReadPaletteFromRom(kGlobalSpritePalettesDW, /*num_colors=*/60, data));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ absl::Status LoadGrassColors(const std::vector<uint8_t>& rom_data,
|
||||
palette_groups.grass.AddColor(
|
||||
gfx::ReadColorFromRom(kHardcodedGrassLW, rom_data.data()));
|
||||
palette_groups.grass.AddColor(
|
||||
gfx::ReadColorFromRom(hardcodedGrassDW, rom_data.data()));
|
||||
gfx::ReadColorFromRom(kHardcodedGrassDW, rom_data.data()));
|
||||
palette_groups.grass.AddColor(
|
||||
gfx::ReadColorFromRom(hardcodedGrassSpecial, rom_data.data()));
|
||||
gfx::ReadColorFromRom(kHardcodedGrassSpecial, rom_data.data()));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ absl::Status Load3DObjectPalettes(const std::vector<uint8_t>& rom_data,
|
||||
palette_groups.object_3d.AddPalette(
|
||||
gfx::ReadPaletteFromRom(kTriforcePalette, 8, data));
|
||||
palette_groups.object_3d.AddPalette(
|
||||
gfx::ReadPaletteFromRom(crystalPalette, 8, data));
|
||||
gfx::ReadPaletteFromRom(kCrystalPalette, 8, data));
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,30 +62,34 @@ constexpr int kOverworldPaletteMain = 0xDE6C8;
|
||||
constexpr int kOverworldPaletteAux = 0xDE86C;
|
||||
constexpr int kOverworldPaletteAnimated = 0xDE604;
|
||||
constexpr int kGlobalSpritesLW = 0xDD218;
|
||||
constexpr int globalSpritePalettesDW = 0xDD290;
|
||||
// Green, Blue, Red, Bunny, Electrocuted (15 colors each)
|
||||
constexpr int kArmorPalettes = 0xDD308;
|
||||
constexpr int kGlobalSpritePalettesDW = 0xDD290;
|
||||
constexpr int kArmorPalettes =
|
||||
0xDD308; /** < Green, Blue, Red, Bunny, Electrocuted (15 colors each) */
|
||||
constexpr int kSpritesPalettesAux1 = 0xDD39E; // 7 colors each
|
||||
constexpr int kSpritesPalettesAux2 = 0xDD446; // 7 colors each
|
||||
constexpr int kSpritesPalettesAux3 = 0xDD4E0; // 7 colors each
|
||||
constexpr int kSwordPalettes = 0xDD630; // 3 colors each - 4 entries
|
||||
constexpr int kShieldPalettes = 0xDD648; // 4 colors each - 3 entries
|
||||
constexpr int kHudPalettes = 0xDD660;
|
||||
constexpr int dungeonMapPalettes = 0xDD70A; // 21 colors
|
||||
constexpr int kDungeonMainPalettes = 0xDD734; //(15*6) colors each - 20 entries
|
||||
constexpr int dungeonMapBgPalettes = 0xDE544; // 16*6
|
||||
constexpr int kDungeonMapPalettes = 0xDD70A; // 21 colors
|
||||
constexpr int kDungeonMainPalettes =
|
||||
0xDD734; // (15*6) colors each - 20 entries
|
||||
constexpr int kDungeonMapBgPalettes = 0xDE544; // 16*6
|
||||
|
||||
// Mirrored Value at 0x75645 : 0x75625
|
||||
constexpr int kHardcodedGrassLW = 0x5FEA9;
|
||||
constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F
|
||||
constexpr int hardcodedGrassSpecial = 0x75640;
|
||||
constexpr int kHardcodedGrassDW = 0x05FEB3; // 0x7564F
|
||||
constexpr int kHardcodedGrassSpecial = 0x75640;
|
||||
constexpr int kOverworldMiniMapPalettes = 0x55B27;
|
||||
constexpr int kTriforcePalette = 0x64425;
|
||||
constexpr int crystalPalette = 0xF4CD3;
|
||||
// 2 bytes for each overworld area (320)
|
||||
constexpr int customAreaSpecificBGPalette = 0x140000;
|
||||
constexpr int customAreaSpecificBGASM = 0x140150;
|
||||
constexpr int kCrystalPalette = 0xF4CD3;
|
||||
constexpr int CustomAreaSpecificBGPalette =
|
||||
0x140000; /** < 2 bytes for each overworld area (320) */
|
||||
|
||||
constexpr int CustomAreaSpecificBGASM = 0x140150;
|
||||
|
||||
// 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,
|
||||
size_t color_index);
|
||||
@@ -199,7 +203,7 @@ struct PaletteGroup {
|
||||
palettes[0].AddColor(color);
|
||||
}
|
||||
|
||||
void Clear() { palettes.clear(); }
|
||||
void clear() { palettes.clear(); }
|
||||
void SetName(const std::string& name) { name_ = name; }
|
||||
auto name() const { return name_; }
|
||||
auto size() const { return palettes.size(); }
|
||||
@@ -307,21 +311,21 @@ struct PaletteGroupMap {
|
||||
}
|
||||
|
||||
void clear() {
|
||||
overworld_main.Clear();
|
||||
overworld_aux.Clear();
|
||||
overworld_animated.Clear();
|
||||
hud.Clear();
|
||||
global_sprites.Clear();
|
||||
armors.Clear();
|
||||
swords.Clear();
|
||||
shields.Clear();
|
||||
sprites_aux1.Clear();
|
||||
sprites_aux2.Clear();
|
||||
sprites_aux3.Clear();
|
||||
dungeon_main.Clear();
|
||||
grass.Clear();
|
||||
object_3d.Clear();
|
||||
overworld_mini_map.Clear();
|
||||
overworld_main.clear();
|
||||
overworld_aux.clear();
|
||||
overworld_animated.clear();
|
||||
hud.clear();
|
||||
global_sprites.clear();
|
||||
armors.clear();
|
||||
swords.clear();
|
||||
shields.clear();
|
||||
sprites_aux1.clear();
|
||||
sprites_aux2.clear();
|
||||
sprites_aux3.clear();
|
||||
dungeon_main.clear();
|
||||
grass.clear();
|
||||
object_3d.clear();
|
||||
overworld_mini_map.clear();
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
@@ -339,7 +343,9 @@ struct PaletteGroupMap {
|
||||
absl::StatusOr<PaletteGroup> CreatePaletteGroupFromColFile(
|
||||
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(
|
||||
SnesPalette& palette, int num_colors = 8);
|
||||
|
||||
@@ -352,7 +358,8 @@ absl::StatusOr<PaletteGroup> CreatePaletteGroupFromLargePalette(
|
||||
* 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.
|
||||
|
||||
@@ -62,15 +62,15 @@ absl::StatusOr<std::vector<uint8_t>> Rom::Load2BppGraphics() {
|
||||
}
|
||||
|
||||
absl::Status Rom::LoadLinkGraphics() {
|
||||
const uint32_t link_gfx_offset = 0x80000; // $10:8000
|
||||
const uint16_t link_gfx_length = 0x800; // 0x4000 or 0x7000?
|
||||
const uint32_t kLinkGfxOffset = 0x80000; // $10:8000
|
||||
const uint16_t kLinkGfxLength = 0x800; // 0x4000 or 0x7000?
|
||||
|
||||
// Load Links graphics from the ROM
|
||||
for (int i = 0; i < kNumLinkSheets; i++) {
|
||||
ASSIGN_OR_RETURN(
|
||||
auto link_sheet_data,
|
||||
ReadByteVector(/*offset=*/link_gfx_offset + (i * link_gfx_length),
|
||||
/*length=*/link_gfx_length))
|
||||
ReadByteVector(/*offset=*/kLinkGfxOffset + (i * kLinkGfxLength),
|
||||
/*length=*/kLinkGfxLength))
|
||||
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
|
||||
link_graphics_[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||
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() {
|
||||
// Check if the ROM has a header
|
||||
constexpr size_t baseROMSize = 1048576; // 1MB
|
||||
constexpr size_t headerSize = 0x200; // 512 bytes
|
||||
if (size_ % baseROMSize == headerSize) {
|
||||
constexpr size_t kBaseRomSize = 1048576; // 1MB
|
||||
constexpr size_t kHeaderSize = 0x200; // 512 bytes
|
||||
if (size_ % kBaseRomSize == kHeaderSize) {
|
||||
auto header =
|
||||
std::vector<uchar>(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());
|
||||
|
||||
// Expand the ROM data to 2MB without changing the data in the first 1MB
|
||||
rom_data_.resize(baseROMSize * 2);
|
||||
size_ = baseROMSize * 2;
|
||||
rom_data_.resize(kBaseRomSize * 2);
|
||||
size_ = kBaseRomSize * 2;
|
||||
|
||||
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,
|
||||
gfx::SnesPalette& palette) {
|
||||
// Iterate through all colors in the palette
|
||||
for (size_t j = 0; j < palette.size(); ++j) {
|
||||
gfx::SnesColor color = palette[j];
|
||||
// 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 kNumLinkSheets = 14;
|
||||
constexpr uint32_t kTile16Ptr = 0x78000;
|
||||
constexpr uint32_t kNormalGfxSpaceStart = 0x87000;
|
||||
constexpr uint32_t kNormalGfxSpaceEnd = 0xC4200;
|
||||
constexpr uint32_t kFontSpriteLocation = 0x70000;
|
||||
@@ -219,6 +220,27 @@ class Rom : public core::ExperimentFlags {
|
||||
*/
|
||||
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() {
|
||||
if (!is_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) {
|
||||
// Skip 8 bytes per tile.
|
||||
auto tpos = 0x78000 + (tile16_id * 0x08);
|
||||
auto tpos = kTile16Ptr + (tile16_id * 0x08);
|
||||
gfx::Tile16 tile16;
|
||||
ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
|
||||
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) {
|
||||
// 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_)));
|
||||
tpos += 2;
|
||||
RETURN_IF_ERROR(WriteShort(tpos, gfx::TileInfoToWord(tile.tile1_)));
|
||||
@@ -420,16 +442,13 @@ class Rom : public core::ExperimentFlags {
|
||||
return status;
|
||||
}
|
||||
|
||||
void Expand(int size) {
|
||||
rom_data_.resize(size);
|
||||
size_ = size;
|
||||
}
|
||||
|
||||
absl::Status Close() {
|
||||
rom_data_.clear();
|
||||
size_ = 0;
|
||||
is_loaded_ = false;
|
||||
return absl::OkStatus();
|
||||
uint8_t& operator[](int i) {
|
||||
if (i > size_) {
|
||||
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_
|
||||
<< std::endl;
|
||||
return rom_data_[0];
|
||||
}
|
||||
return rom_data_[i];
|
||||
}
|
||||
|
||||
core::ResourceLabelManager* resource_label() {
|
||||
@@ -439,6 +458,14 @@ class Rom : public core::ExperimentFlags {
|
||||
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
|
||||
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 data() { return rom_data_.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_; }
|
||||
|
||||
uint8_t& operator[](int i) {
|
||||
if (i > size_) {
|
||||
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_
|
||||
<< std::endl;
|
||||
return rom_data_[0];
|
||||
}
|
||||
return rom_data_[i];
|
||||
}
|
||||
auto filename() const { return filename_; }
|
||||
auto set_filename(std::string name) { filename_ = name; }
|
||||
|
||||
std::vector<std::vector<uint8_t>> main_blockset_ids;
|
||||
std::vector<std::vector<uint8_t>> room_blockset_ids;
|
||||
|
||||
Reference in New Issue
Block a user