Add hex utility functions and refactor usage in editors

This commit is contained in:
scawful
2025-01-22 13:28:21 -05:00
parent 62e6157864
commit 50c9223a53
17 changed files with 174 additions and 134 deletions

View File

@@ -9,6 +9,7 @@
#include "app/gfx/compression.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "util/hex.h"
#include "util/macro.h"
namespace yaze {
@@ -572,7 +573,7 @@ absl::Status Overworld::SaveOverworldMaps() {
if ((pos + size_a) >= 0x6411F && (pos + size_a) <= 0x70000) {
core::logf("Pos set to overflow region for map %s at %s",
std::to_string(i), core::HexLong(pos));
std::to_string(i), util::HexLong(pos));
pos = kOverworldMapDataOverflow; // 0x0F8780;
}
@@ -609,7 +610,7 @@ absl::Status Overworld::SaveOverworldMaps() {
int snes_pos = core::PcToSnes(pos);
map_pointers1[i] = snes_pos;
core::logf("Saving map pointers1 and compressed data for map %s at %s",
core::HexByte(i), core::HexLong(snes_pos));
util::HexByte(i), util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
snes_pos));
@@ -618,8 +619,8 @@ absl::Status Overworld::SaveOverworldMaps() {
} else {
// Save pointer for map1
int snes_pos = map_pointers1[map_pointers1_id[i]];
core::logf("Saving map pointers1 for map %s at %s", core::HexByte(i),
core::HexLong(snes_pos));
core::logf("Saving map pointers1 for map %s at %s", util::HexByte(i),
util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
snes_pos));
@@ -631,7 +632,7 @@ absl::Status Overworld::SaveOverworldMaps() {
if ((pos + b.size()) >= 0x6411F && (pos + b.size()) <= 0x70000) {
core::logf("Pos set to overflow region for map %s at %s",
core::HexByte(i), core::HexLong(pos));
util::HexByte(i), util::HexLong(pos));
pos = kOverworldMapDataOverflow;
}
@@ -641,7 +642,7 @@ absl::Status Overworld::SaveOverworldMaps() {
int snes_pos = core::PcToSnes(pos);
map_pointers2[i] = snes_pos;
core::logf("Saving map pointers2 and compressed data for map %s at %s",
core::HexByte(i), core::HexLong(snes_pos));
util::HexByte(i), util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
snes_pos));
@@ -650,8 +651,8 @@ absl::Status Overworld::SaveOverworldMaps() {
} else {
// Save pointer for map2
int snes_pos = map_pointers2[map_pointers2_id[i]];
core::logf("Saving map pointers2 for map %s at %s", core::HexByte(i),
core::HexLong(snes_pos));
core::logf("Saving map pointers2 for map %s at %s", util::HexByte(i),
util::HexLong(snes_pos));
RETURN_IF_ERROR(rom()->WriteLong(
rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
snes_pos));
@@ -660,7 +661,7 @@ absl::Status Overworld::SaveOverworldMaps() {
// Check if too many maps data
if (pos > kOverworldCompressedOverflowPos) {
core::logf("Too many maps data %s", core::HexLong(pos));
core::logf("Too many maps data %s", util::HexLong(pos));
return absl::AbortedError("Too many maps data " + std::to_string(pos));
}

View File

@@ -8,6 +8,7 @@
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
#include "util/hex.h"
namespace yaze {
namespace zelda3 {
@@ -71,12 +72,12 @@ void OverworldMap::LoadAreaInfo() {
}
}
auto message_id = rom_.ReadWord(kOverworldMessageIds + (parent_ * 2));
auto message_id = rom_.ReadWord(kOverworldMessageIds + (parent_ * 2));
if (message_id.ok()) {
message_id_ = message_id.value();
} else {
message_id_ = 0;
core::logf("Error reading message id for map %d", parent_);
message_id_ = 0;
core::logf("Error reading message id for map %d", parent_);
}
if (index_ < kDarkWorldMapIdStart) {
@@ -405,11 +406,11 @@ void OverworldMap::LoadMainBlocksets() {
// of the 5A sheet, so this will need some special manipulation to make work
// during the BuildBitmap step (or a new one specifically for animating).
void OverworldMap::DrawAnimatedTiles() {
std::cout << "static_graphics_[6] = " << core::HexByte(static_graphics_[6])
std::cout << "static_graphics_[6] = " << util::HexByte(static_graphics_[6])
<< std::endl;
std::cout << "static_graphics_[7] = " << core::HexByte(static_graphics_[7])
std::cout << "static_graphics_[7] = " << util::HexByte(static_graphics_[7])
<< std::endl;
std::cout << "static_graphics_[8] = " << core::HexByte(static_graphics_[8])
std::cout << "static_graphics_[8] = " << util::HexByte(static_graphics_[8])
<< std::endl;
if (static_graphics_[7] == 0x5B) {
static_graphics_[7] = 0x5A;
@@ -424,7 +425,7 @@ void OverworldMap::DrawAnimatedTiles() {
void OverworldMap::LoadAreaGraphicsBlocksets() {
for (int i = 0; i < 4; i++) {
uint8_t value = rom_[rom_.version_constants().kOverworldGfxGroups1 +
(area_graphics_ * 4) + i];
(area_graphics_ * 4) + i];
if (value != 0) {
static_graphics_[3 + i] = value;
}
@@ -597,15 +598,15 @@ absl::Status OverworldMap::LoadPalette() {
uint8_t pal0 = 0;
uint8_t pal1 = rom_[rom_.version_constants().kOverworldMapPaletteGroup +
(area_palette_ * 4)];
(area_palette_ * 4)];
uint8_t pal2 = rom_[rom_.version_constants().kOverworldMapPaletteGroup +
(area_palette_ * 4) + 1];
(area_palette_ * 4) + 1];
uint8_t pal3 = rom_[rom_.version_constants().kOverworldMapPaletteGroup +
(area_palette_ * 4) + 2];
(area_palette_ * 4) + 2];
uint8_t pal4 =
rom_[kOverworldSpritePaletteGroup + (sprite_palette_[game_state_] * 2)];
uint8_t pal5 = rom_[kOverworldSpritePaletteGroup +
(sprite_palette_[game_state_] * 2) + 1];
(sprite_palette_[game_state_] * 2) + 1];
auto grass_pal_group = rom_.palette_group().grass;
ASSIGN_OR_RETURN(gfx::SnesColor bgr, grass_pal_group[0].GetColor(0));