From 26cda69d44439bd01efaca92b251d94687948b57 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 22 Jan 2025 13:53:01 -0500 Subject: [PATCH] Refactor common functionality into zelda3 namespace; remove references to core::common --- src/app/core/core.cmake | 1 - src/app/core/project.h | 1 - src/app/editor/code/assembly_editor.h | 1 - src/app/editor/graphics/tile16_editor.h | 1 - src/app/editor/message/message_data.cc | 1 - src/app/emu/cpu/cpu.cc | 1 - src/app/gfx/compression.cc | 15 ++++++------- src/app/rom.h | 1 - .../common.cc => zelda3/hyrule_magic.cc} | 16 ++++---------- .../{core/common.h => zelda3/hyrule_magic.h} | 21 +++++++------------ src/app/zelda3/music/tracker.cc | 5 +++-- src/app/zelda3/zelda3.cmake | 1 + src/cli/python/yaze_py.cmake | 1 - src/cli/tui.cc | 19 ++++++++++------- src/cli/z3ed.cmake | 1 - src/cli/z3ed.h | 1 - test/CMakeLists.txt | 1 - 17 files changed, 35 insertions(+), 53 deletions(-) rename src/app/{core/common.cc => zelda3/hyrule_magic.cc} (89%) rename src/app/{core/common.h => zelda3/hyrule_magic.h} (76%) diff --git a/src/app/core/core.cmake b/src/app/core/core.cmake index ba1b4140..ff2260d8 100644 --- a/src/app/core/core.cmake +++ b/src/app/core/core.cmake @@ -1,6 +1,5 @@ set( YAZE_APP_CORE_SRC - app/core/common.cc app/core/controller.cc app/emu/emulator.cc app/core/project.cc diff --git a/src/app/core/project.h b/src/app/core/project.h index 31bc0265..4e12649d 100644 --- a/src/app/core/project.h +++ b/src/app/core/project.h @@ -7,7 +7,6 @@ #include #include "absl/status/status.h" -#include "app/core/common.h" #include "app/core/platform/file_dialog.h" namespace yaze { diff --git a/src/app/editor/code/assembly_editor.h b/src/app/editor/code/assembly_editor.h index f9cac4db..9e837de7 100644 --- a/src/app/editor/code/assembly_editor.h +++ b/src/app/editor/code/assembly_editor.h @@ -3,7 +3,6 @@ #include -#include "app/core/common.h" #include "app/editor/editor.h" #include "app/gui/modules/text_editor.h" #include "app/gui/style.h" diff --git a/src/app/editor/graphics/tile16_editor.h b/src/app/editor/graphics/tile16_editor.h index f7d37d84..3de11445 100644 --- a/src/app/editor/graphics/tile16_editor.h +++ b/src/app/editor/graphics/tile16_editor.h @@ -5,7 +5,6 @@ #include #include "absl/status/status.h" -#include "app/core/common.h" #include "app/editor/graphics/palette_editor.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" diff --git a/src/app/editor/message/message_data.cc b/src/app/editor/message/message_data.cc index b488dc8b..ade910fb 100644 --- a/src/app/editor/message/message_data.cc +++ b/src/app/editor/message/message_data.cc @@ -2,7 +2,6 @@ #include -#include "app/core/common.h" #include "util/hex.h" #include "util/log.h" diff --git a/src/app/emu/cpu/cpu.cc b/src/app/emu/cpu/cpu.cc index 691c5fda..496d4493 100644 --- a/src/app/emu/cpu/cpu.cc +++ b/src/app/emu/cpu/cpu.cc @@ -6,7 +6,6 @@ #include #include -#include "app/core/common.h" #include "app/core/features.h" #include "app/emu/cpu/internal/opcodes.h" diff --git a/src/app/gfx/compression.cc b/src/app/gfx/compression.cc index bf2c0bc1..9b747a10 100644 --- a/src/app/gfx/compression.cc +++ b/src/app/gfx/compression.cc @@ -7,6 +7,7 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "app/rom.h" +#include "app/zelda3/hyrule_magic.h" #include "util/macro.h" #define DEBUG_LOG(msg) std::cout << msg << std::endl @@ -237,13 +238,13 @@ std::vector HyruleMagicDecompress(uint8_t const* src, int* const size, // rle 16-bit alternating copy - d = core::ldle16b(src); + d = zelda3::ldle16b(src); src += 2; while (c > 1) { // copy that 16-bit number c/2 times into the b2 buffer. - core::stle16b(b2 + bd, d); + zelda3::stle16b(b2 + bd, d); bd += 2; c -= 2; // hence c/2 @@ -276,7 +277,7 @@ std::vector HyruleMagicDecompress(uint8_t const* src, int* const size, if (p_big_endian) { d = (*src << 8) + src[1]; } else { - d = core::ldle16b(src); + d = zelda3::ldle16b(src); } while (c--) { @@ -459,8 +460,8 @@ void CompressionCommandAlternative(const uint8_t* rom_data, comp_accumulator = 0; } -void CheckByteRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos, - CompressionCommand& cmd) { +void CheckByteRepeatV2(const uint8_t* data, uint& src_pos, + const unsigned int last_pos, CompressionCommand& cmd) { unsigned int i = 0; while (src_pos + i < last_pos && data[src_pos] == data[src_pos + i]) { ++i; @@ -469,8 +470,8 @@ void CheckByteRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int la cmd.arguments[kCommandByteFill][0] = data[src_pos]; } -void CheckWordRepeatV2(const uint8_t* data, uint& src_pos, const unsigned int last_pos, - CompressionCommand& cmd) { +void CheckWordRepeatV2(const uint8_t* data, uint& src_pos, + const unsigned int last_pos, CompressionCommand& cmd) { if (src_pos + 2 <= last_pos && data[src_pos] != data[src_pos + 1]) { unsigned int pos = src_pos; char byte1 = data[pos]; diff --git a/src/app/rom.h b/src/app/rom.h index cb6d5fc0..8b80bc98 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -19,7 +19,6 @@ #include "absl/strings/match.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" -#include "app/core/common.h" #include "app/core/project.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" diff --git a/src/app/core/common.cc b/src/app/zelda3/hyrule_magic.cc similarity index 89% rename from src/app/core/common.cc rename to src/app/zelda3/hyrule_magic.cc index 6cd4a7a0..4e047258 100644 --- a/src/app/core/common.cc +++ b/src/app/zelda3/hyrule_magic.cc @@ -1,15 +1,7 @@ -#include "common.h" - -#include -#include -#include -#include - -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" +#include "hyrule_magic.h" namespace yaze { -namespace core { +namespace zelda3 { namespace { @@ -76,5 +68,5 @@ uint16_t ldle16b_i(uint8_t const *const p_arr, size_t const p_index) { return ldle16b(p_arr + (2 * p_index)); } -} // namespace core -} // namespace yaze +} // namespace zelda3 +} // namespace yaze \ No newline at end of file diff --git a/src/app/core/common.h b/src/app/zelda3/hyrule_magic.h similarity index 76% rename from src/app/core/common.h rename to src/app/zelda3/hyrule_magic.h index b36c7d4e..a37cf9b2 100644 --- a/src/app/core/common.h +++ b/src/app/zelda3/hyrule_magic.h @@ -1,23 +1,16 @@ -#ifndef YAZE_CORE_COMMON_H -#define YAZE_CORE_COMMON_H +#ifndef YAZE_APP_ZELDA3_HYRULE_MAGIC_H +#define YAZE_APP_ZELDA3_HYRULE_MAGIC_H -#include #include -#include -#include +#include #include +#include #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" namespace yaze { - -/** - * @namespace yaze::core - * @brief Core application logic and utilities. - */ -namespace core { - +namespace zelda3 { /** * @brief Store little endian 16-bit value using a byte pointer, offset by an * index before dereferencing @@ -37,7 +30,7 @@ uint16_t ldle16b_i(uint8_t const *const p_arr, size_t const p_index); // Load little endian halfword (16-bit) dereferenced from uint16_t ldle16b(uint8_t const *const p_arr); -} // namespace core +} // namespace zelda3 } // namespace yaze -#endif +#endif // YAZE_APP_ZELDA3_HYRULE_MAGIC_H \ No newline at end of file diff --git a/src/app/zelda3/music/tracker.cc b/src/app/zelda3/music/tracker.cc index 33b42a1a..775eafac 100644 --- a/src/app/zelda3/music/tracker.cc +++ b/src/app/zelda3/music/tracker.cc @@ -14,6 +14,7 @@ #include #include "app/rom.h" +#include "app/zelda3/hyrule_magic.h" #include "util/macro.h" namespace yaze { @@ -923,9 +924,9 @@ void Tracker::SaveSongs(Rom &rom) { q = 1; for (n = 0; n < 8; n++) { - core::stle16b_i(trtbl->buf, n, SaveSpcCommand(rom, sp->tbl[n], p, q)); + stle16b_i(trtbl->buf, n, SaveSpcCommand(rom, sp->tbl[n], p, q)); - if (core::ldle16b_i(trtbl->buf, n)) AddSpcReloc(trtbl, n << 1), q = 0; + if (ldle16b_i(trtbl->buf, n)) AddSpcReloc(trtbl, n << 1), q = 0; } sp->addr = trtbl->start; diff --git a/src/app/zelda3/zelda3.cmake b/src/app/zelda3/zelda3.cmake index a59b74d1..127aff27 100644 --- a/src/app/zelda3/zelda3.cmake +++ b/src/app/zelda3/zelda3.cmake @@ -1,5 +1,6 @@ set( YAZE_APP_ZELDA3_SRC + app/zelda3/hyrule_magic.cc app/zelda3/overworld/overworld_map.cc app/zelda3/overworld/overworld.cc app/zelda3/screen/inventory.cc diff --git a/src/cli/python/yaze_py.cmake b/src/cli/python/yaze_py.cmake index 7275029c..0e8cc8e1 100644 --- a/src/cli/python/yaze_py.cmake +++ b/src/cli/python/yaze_py.cmake @@ -7,7 +7,6 @@ add_library( py/yaze_py.cc yaze.cc app/rom.cc - app/core/common.cc app/core/labeling.cc app/zelda3/overworld/overworld_map.cc app/zelda3/overworld/overworld.cc diff --git a/src/cli/tui.cc b/src/cli/tui.cc index 219cafea..533a7d62 100644 --- a/src/cli/tui.cc +++ b/src/cli/tui.cc @@ -5,6 +5,7 @@ #include #include +#include "absl/strings/str_cat.h" #include "util/bps.h" namespace yaze { @@ -156,7 +157,8 @@ void GenerateSaveFileComponent(ftxui::ScreenInteractive &screen) { for (size_t i = 0; i < items.size(); i += 4) { auto row = Container::Horizontal({}); for (size_t j = 0; j < 4 && (i + j) < items.size(); ++j) { - row->Add(Checkbox(absl::StrCat(items[i + j], " ").data(), &values[i + j])); + row->Add( + Checkbox(absl::StrCat(items[i + j], " ").data(), &values[i + j])); } checkboxes->Add(row); } @@ -386,7 +388,8 @@ void HelpComponent(ftxui::ScreenInteractive &screen) { auto help_text = vbox({ text("z3ed") | bold | color(Color::Yellow), text("by scawful") | color(Color::Magenta), - text("The Legend of Zelda: A Link to the Past Hacking Tool") | color(Color::Red), + text("The Legend of Zelda: A Link to the Past Hacking Tool") | + color(Color::Red), separator(), hbox({ text("Command") | bold | underlined, @@ -474,7 +477,8 @@ void HelpComponent(ftxui::ScreenInteractive &screen) { auto help_text_component = Renderer([&] { return help_text; }); - auto back_button = Button("Back", [&] { SwitchComponents(screen, LayoutID::kMainMenu); }); + auto back_button = + Button("Back", [&] { SwitchComponents(screen, LayoutID::kMainMenu); }); auto container = Container::Vertical({ help_text_component, @@ -483,10 +487,11 @@ void HelpComponent(ftxui::ScreenInteractive &screen) { auto renderer = Renderer(container, [&] { return vbox({ - help_text_component->Render() | center, - separator(), - back_button->Render() | center, - }) | border; + help_text_component->Render() | center, + separator(), + back_button->Render() | center, + }) | + border; }); screen.Loop(renderer); diff --git a/src/cli/z3ed.cmake b/src/cli/z3ed.cmake index 94a2c9b6..7ecfaa36 100644 --- a/src/cli/z3ed.cmake +++ b/src/cli/z3ed.cmake @@ -19,7 +19,6 @@ add_executable( cli/handlers/patch.cc cli/handlers/tile16_transfer.cc app/rom.cc - app/core/common.cc app/core/project.cc app/core/platform/file_dialog.mm app/core/platform/file_dialog.cc diff --git a/src/cli/z3ed.h b/src/cli/z3ed.h index 20f4692e..455bb8f6 100644 --- a/src/cli/z3ed.h +++ b/src/cli/z3ed.h @@ -10,7 +10,6 @@ #include #include "absl/status/status.h" -#include "app/core/common.h" #include "app/rom.h" #include "util/macro.h" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a58ede47..7fd2bfb9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,7 +2,6 @@ set(YAZE_SRC_FILES "") foreach (file app/rom.cc - app/core/common.cc ${YAZE_APP_CORE_SRC} ${YAZE_APP_EMU_SRC} ${YAZE_APP_GFX_SRC}