refactor Rom class and constants
This commit is contained in:
@@ -142,23 +142,9 @@ constexpr float kYazeVersion = 0.2;
|
|||||||
// Magic numbers
|
// Magic numbers
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
/// Bit set for object priority
|
|
||||||
constexpr ushort TilePriorityBit = 0x2000;
|
|
||||||
|
|
||||||
/// Bit set for object hflip
|
|
||||||
constexpr ushort TileHFlipBit = 0x4000;
|
|
||||||
|
|
||||||
/// Bit set for object vflip
|
|
||||||
constexpr ushort TileVFlipBit = 0x8000;
|
|
||||||
|
|
||||||
/// Bits used for tile name
|
|
||||||
constexpr ushort TileNameMask = 0x03FF;
|
|
||||||
|
|
||||||
constexpr int Uncompressed3BPPSize = 0x0600;
|
|
||||||
constexpr int UncompressedSheetSize = 0x0800;
|
constexpr int UncompressedSheetSize = 0x0800;
|
||||||
|
|
||||||
constexpr int NumberOfRooms = 296;
|
constexpr int NumberOfRooms = 296;
|
||||||
|
|
||||||
constexpr int NumberOfColors = 3143;
|
constexpr int NumberOfColors = 3143;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -179,15 +165,6 @@ constexpr int kTilesheetWidth = 128;
|
|||||||
constexpr int kTilesheetHeight = 32;
|
constexpr int kTilesheetHeight = 32;
|
||||||
constexpr int kTilesheetDepth = 8;
|
constexpr int kTilesheetDepth = 8;
|
||||||
|
|
||||||
// TEXT EDITOR RELATED CONSTANTS
|
|
||||||
constexpr int gfx_font = 0x70000; // 2bpp format
|
|
||||||
constexpr int text_data = 0xE0000;
|
|
||||||
constexpr int text_data2 = 0x75F40;
|
|
||||||
constexpr int pointers_dictionaries = 0x74703;
|
|
||||||
constexpr int characters_width = 0x74ADF;
|
|
||||||
|
|
||||||
constexpr int entrance_gfx_group = 0x5D97;
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Gravestones related variables
|
// Gravestones related variables
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -218,7 +195,6 @@ static const std::string RoomEffect[] = {"Nothing",
|
|||||||
"Ganon's Darkness"};
|
"Ganon's Darkness"};
|
||||||
|
|
||||||
static const std::string RoomTag[] = {"Nothing",
|
static const std::string RoomTag[] = {"Nothing",
|
||||||
|
|
||||||
"NW Kill Enemy to Open",
|
"NW Kill Enemy to Open",
|
||||||
"NE Kill Enemy to Open",
|
"NE Kill Enemy to Open",
|
||||||
"SW Kill Enemy to Open",
|
"SW Kill Enemy to Open",
|
||||||
@@ -287,18 +263,6 @@ static const std::string RoomTag[] = {"Nothing",
|
|||||||
"Light Torches for Chest",
|
"Light Torches for Chest",
|
||||||
"Kill Boss Again"};
|
"Kill Boss Again"};
|
||||||
|
|
||||||
static const std::string SecretItemNames[] = {
|
|
||||||
"Nothing", "Green Rupee", "Rock hoarder", "Bee", "Health pack",
|
|
||||||
"Bomb", "Heart ", "Blue Rupee",
|
|
||||||
|
|
||||||
"Key", "Arrow", "Bomb", "Heart", "Magic",
|
|
||||||
"Full Magic", "Cucco", "Green Soldier", "Bush Stal", "Blue Soldier",
|
|
||||||
|
|
||||||
"Landmine", "Heart", "Fairy", "Heart",
|
|
||||||
"Nothing ", // 22
|
|
||||||
|
|
||||||
"Hole", "Warp", "Staircase", "Bombable", "Switch"};
|
|
||||||
|
|
||||||
static const std::string TileTypeNames[] = {
|
static const std::string TileTypeNames[] = {
|
||||||
"$00 Nothing (standard floor)",
|
"$00 Nothing (standard floor)",
|
||||||
"$01 Collision",
|
"$01 Collision",
|
||||||
|
|||||||
@@ -9,6 +9,18 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
|
// Bit set for object priority
|
||||||
|
constexpr ushort TilePriorityBit = 0x2000;
|
||||||
|
|
||||||
|
// Bit set for object hflip
|
||||||
|
constexpr ushort TileHFlipBit = 0x4000;
|
||||||
|
|
||||||
|
// Bit set for object vflip
|
||||||
|
constexpr ushort TileVFlipBit = 0x8000;
|
||||||
|
|
||||||
|
// Bits used for tile name
|
||||||
|
constexpr ushort TileNameMask = 0x03FF;
|
||||||
|
|
||||||
tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
tile8 UnpackBppTile(const Bytes& data, const uint32_t offset,
|
||||||
const uint32_t bpp) {
|
const uint32_t bpp) {
|
||||||
tile8 tile;
|
tile8 tile;
|
||||||
@@ -337,28 +349,28 @@ uint16_t TileInfoToShort(TileInfo tile_info) {
|
|||||||
uint16_t value = 0;
|
uint16_t value = 0;
|
||||||
// vhopppcc cccccccc
|
// vhopppcc cccccccc
|
||||||
if (tile_info.over_) {
|
if (tile_info.over_) {
|
||||||
value |= core::TilePriorityBit;
|
value |= TilePriorityBit;
|
||||||
}
|
}
|
||||||
if (tile_info.horizontal_mirror_) {
|
if (tile_info.horizontal_mirror_) {
|
||||||
value |= core::TileHFlipBit;
|
value |= TileHFlipBit;
|
||||||
}
|
}
|
||||||
if (tile_info.vertical_mirror_) {
|
if (tile_info.vertical_mirror_) {
|
||||||
value |= core::TileVFlipBit;
|
value |= TileVFlipBit;
|
||||||
}
|
}
|
||||||
value |= (uint16_t)((tile_info.palette_ << 10) & 0x1C00);
|
value |= (uint16_t)((tile_info.palette_ << 10) & 0x1C00);
|
||||||
value |= (uint16_t)(tile_info.id_ & core::TileNameMask);
|
value |= (uint16_t)(tile_info.id_ & TileNameMask);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileInfo GetTilesInfo(uint16_t tile) {
|
TileInfo GetTilesInfo(uint16_t tile) {
|
||||||
// vhopppcc cccccccc
|
// vhopppcc cccccccc
|
||||||
uint16_t tid = (uint16_t)(tile & core::TileNameMask);
|
uint16_t tid = (uint16_t)(tile & TileNameMask);
|
||||||
uint8_t p = (uint8_t)((tile >> 10) & 0x07);
|
uint8_t p = (uint8_t)((tile >> 10) & 0x07);
|
||||||
|
|
||||||
bool o = ((tile & core::TilePriorityBit) == core::TilePriorityBit);
|
bool o = ((tile & TilePriorityBit) == TilePriorityBit);
|
||||||
bool h = ((tile & core::TileHFlipBit) == core::TileHFlipBit);
|
bool h = ((tile & TileHFlipBit) == TileHFlipBit);
|
||||||
bool v = ((tile & core::TileVFlipBit) == core::TileVFlipBit);
|
bool v = ((tile & TileVFlipBit) == TileVFlipBit);
|
||||||
|
|
||||||
return TileInfo(tid, p, v, h, o);
|
return TileInfo(tid, p, v, h, o);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,17 @@
|
|||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
|
constexpr int Uncompressed3BPPSize = 0x0600;
|
||||||
|
constexpr int kEntranceGfxGroup = 0x5D97;
|
||||||
|
|
||||||
|
int Rom::GetGraphicsAddress(const uchar* data, uint8_t addr) {
|
||||||
|
auto part_one = data[version_constants().kOverworldGfxPtr1 + addr] << 16;
|
||||||
|
auto part_two = data[version_constants().kOverworldGfxPtr2 + addr] << 8;
|
||||||
|
auto part_three = data[version_constants().kOverworldGfxPtr3 + addr];
|
||||||
|
auto snes_addr = (part_one | part_two | part_three);
|
||||||
|
return core::SnesToPc(snes_addr);
|
||||||
|
}
|
||||||
|
|
||||||
absl::StatusOr<Bytes> Rom::Load2BppGraphics() {
|
absl::StatusOr<Bytes> Rom::Load2BppGraphics() {
|
||||||
Bytes sheet;
|
Bytes sheet;
|
||||||
const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
|
const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
|
||||||
@@ -77,9 +88,9 @@ absl::Status Rom::LoadAllGraphicsData() {
|
|||||||
|
|
||||||
for (int i = 0; i < kNumGfxSheets; i++) {
|
for (int i = 0; i < kNumGfxSheets; i++) {
|
||||||
if (i >= 115 && i <= 126) { // uncompressed sheets
|
if (i >= 115 && i <= 126) { // uncompressed sheets
|
||||||
sheet.resize(core::Uncompressed3BPPSize);
|
sheet.resize(Uncompressed3BPPSize);
|
||||||
auto offset = GetGraphicsAddress(data(), i);
|
auto offset = GetGraphicsAddress(data(), i);
|
||||||
for (int j = 0; j < core::Uncompressed3BPPSize; j++) {
|
for (int j = 0; j < Uncompressed3BPPSize; j++) {
|
||||||
sheet[j] = rom_data_[j + offset];
|
sheet[j] = rom_data_[j + offset];
|
||||||
}
|
}
|
||||||
bpp3 = true;
|
bpp3 = true;
|
||||||
@@ -384,8 +395,7 @@ void Rom::LoadGfxGroups() {
|
|||||||
|
|
||||||
for (int i = 0; i < 82; i++) {
|
for (int i = 0; i < 82; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
room_blockset_ids[i][j] =
|
room_blockset_ids[i][j] = rom_data_[kEntranceGfxGroup + (i * 4) + j];
|
||||||
rom_data_[core::entrance_gfx_group + (i * 4) + j];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,8 +427,7 @@ void Rom::SaveGroupsToRom() {
|
|||||||
|
|
||||||
for (int i = 0; i < 82; i++) {
|
for (int i = 0; i < 82; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
rom_data_[core::entrance_gfx_group + (i * 4) + j] =
|
rom_data_[kEntranceGfxGroup + (i * 4) + j] = room_blockset_ids[i][j];
|
||||||
room_blockset_ids[i][j];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,27 +203,6 @@ class Rom : public core::ExperimentFlags {
|
|||||||
*/
|
*/
|
||||||
absl::Status SaveAllPalettes();
|
absl::Status SaveAllPalettes();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Updates a color in a specified palette group.
|
|
||||||
*
|
|
||||||
* This function updates the color at the specified `colorIndex` in the
|
|
||||||
* palette at `palette_index` within the palette group with the given
|
|
||||||
* `group_name`. If the group, palette, or color indices are invalid, an error
|
|
||||||
* is returned.
|
|
||||||
*
|
|
||||||
* @param group_name The name of the palette group to update.
|
|
||||||
* @param palette_index The index of the palette within the group to update.
|
|
||||||
* @param colorIndex The index of the color within the palette to update.
|
|
||||||
* @param newColor The new color value to set.
|
|
||||||
*
|
|
||||||
* @return An `absl::Status` indicating whether the update was successful.
|
|
||||||
* Returns `absl::OkStatus()` if successful, or an error status if the
|
|
||||||
* group, palette, or color indices are invalid.
|
|
||||||
*/
|
|
||||||
absl::Status UpdatePaletteColor(const std::string& group_name,
|
|
||||||
size_t palette_index, size_t colorIndex,
|
|
||||||
const gfx::SnesColor& newColor);
|
|
||||||
|
|
||||||
// Read functions
|
// Read functions
|
||||||
absl::StatusOr<uint8_t> ReadByte(int offset) {
|
absl::StatusOr<uint8_t> ReadByte(int offset) {
|
||||||
if (offset >= rom_data_.size()) {
|
if (offset >= rom_data_.size()) {
|
||||||
@@ -433,13 +412,7 @@ class Rom : public core::ExperimentFlags {
|
|||||||
return kVersionConstantsMap.at(version_);
|
return kVersionConstantsMap.at(version_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetGraphicsAddress(const uchar* data, uint8_t addr) const {
|
int GetGraphicsAddress(const uchar* data, uint8_t addr);
|
||||||
auto part_one = data[version_constants().kOverworldGfxPtr1 + addr] << 16;
|
|
||||||
auto part_two = data[version_constants().kOverworldGfxPtr2 + addr] << 8;
|
|
||||||
auto part_three = data[version_constants().kOverworldGfxPtr3 + addr];
|
|
||||||
auto snes_addr = (part_one | part_two | part_three);
|
|
||||||
return core::SnesToPc(snes_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto palette_group() { return palette_groups_; }
|
auto palette_group() { return palette_groups_; }
|
||||||
auto mutable_palette_group() { return &palette_groups_; }
|
auto mutable_palette_group() { return &palette_groups_; }
|
||||||
|
|||||||
Reference in New Issue
Block a user