Refactor common functionality into zelda3 namespace; remove references to core::common

This commit is contained in:
scawful
2025-01-22 13:53:01 -05:00
parent 43fc52dec7
commit 26cda69d44
17 changed files with 35 additions and 53 deletions

View File

@@ -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

View File

@@ -7,7 +7,6 @@
#include <vector>
#include "absl/status/status.h"
#include "app/core/common.h"
#include "app/core/platform/file_dialog.h"
namespace yaze {

View File

@@ -3,7 +3,6 @@
#include <string>
#include "app/core/common.h"
#include "app/editor/editor.h"
#include "app/gui/modules/text_editor.h"
#include "app/gui/style.h"

View File

@@ -5,7 +5,6 @@
#include <vector>
#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"

View File

@@ -2,7 +2,6 @@
#include <string>
#include "app/core/common.h"
#include "util/hex.h"
#include "util/log.h"

View File

@@ -6,7 +6,6 @@
#include <sstream>
#include <vector>
#include "app/core/common.h"
#include "app/core/features.h"
#include "app/emu/cpu/internal/opcodes.h"

View File

@@ -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<uint8_t> 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<uint8_t> 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];

View File

@@ -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"

View File

@@ -1,15 +1,7 @@
#include "common.h"
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#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

View File

@@ -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 <chrono>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#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

View File

@@ -14,6 +14,7 @@
#include <vector>
#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;

View File

@@ -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

View File

@@ -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

View File

@@ -5,6 +5,7 @@
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
#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);

View File

@@ -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

View File

@@ -10,7 +10,6 @@
#include <vector>
#include "absl/status/status.h"
#include "app/core/common.h"
#include "app/rom.h"
#include "util/macro.h"

View File

@@ -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}