refactor(core): move AsarWrapper to core directory and update includes

- Relocated AsarWrapper implementation and header files from `src/app/core/` to `src/core/` to enhance modularity and organization.
- Updated all relevant include paths across the codebase to reflect the new location of AsarWrapper.
- Adjusted CMake configurations to ensure proper compilation of the core library.

Benefits:
- Improves project structure by separating core functionalities from application-specific code.
- Facilitates easier maintenance and understanding of the codebase by clarifying the organization of core components.
This commit is contained in:
scawful
2025-10-15 17:24:05 -04:00
parent 8845bf737c
commit fd91d17ebd
19 changed files with 399 additions and 363 deletions

View File

@@ -1,210 +0,0 @@
#ifndef YAZE_APP_CORE_ASAR_WRAPPER_H
#define YAZE_APP_CORE_ASAR_WRAPPER_H
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <optional>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
namespace yaze {
namespace core {
/**
* @brief Symbol information extracted from Asar assembly
*/
struct AsarSymbol {
std::string name; // Symbol name
uint32_t address; // Memory address
std::string opcode; // Associated opcode if available
std::string file; // Source file
int line; // Line number in source
std::string comment; // Optional comment
};
/**
* @brief Asar patch result information
*/
struct AsarPatchResult {
bool success; // Whether patch was successful
std::vector<std::string> errors; // Error messages if any
std::vector<std::string> warnings; // Warning messages
std::vector<AsarSymbol> symbols; // Extracted symbols
uint32_t rom_size; // Final ROM size after patching
uint32_t crc32; // CRC32 checksum of patched ROM
};
/**
* @brief Modern C++ wrapper for Asar 65816 assembler integration
*
* This class provides a high-level interface for:
* - Patching ROMs with assembly code
* - Extracting symbol names and opcodes
* - Cross-platform compatibility (Windows, macOS, Linux)
*/
class AsarWrapper {
public:
AsarWrapper();
~AsarWrapper();
// Disable copy constructor and assignment
AsarWrapper(const AsarWrapper&) = delete;
AsarWrapper& operator=(const AsarWrapper&) = delete;
// Enable move constructor and assignment
AsarWrapper(AsarWrapper&&) = default;
AsarWrapper& operator=(AsarWrapper&&) = default;
/**
* @brief Initialize the Asar library
* @return Status indicating success or failure
*/
absl::Status Initialize();
/**
* @brief Clean up and close the Asar library
*/
void Shutdown();
/**
* @brief Check if Asar is initialized and ready
* @return True if initialized, false otherwise
*/
bool IsInitialized() const { return initialized_; }
/**
* @brief Get Asar version information
* @return Version string
*/
std::string GetVersion() const;
/**
* @brief Get Asar API version
* @return API version number
*/
int GetApiVersion() const;
/**
* @brief Apply an assembly patch to a ROM
* @param patch_path Path to the .asm patch file
* @param rom_data ROM data to patch (will be modified)
* @param include_paths Additional include paths for assembly files
* @return Patch result with status and extracted information
*/
absl::StatusOr<AsarPatchResult> ApplyPatch(
const std::string& patch_path,
std::vector<uint8_t>& rom_data,
const std::vector<std::string>& include_paths = {});
/**
* @brief Apply an assembly patch from string content
* @param patch_content Assembly source code as string
* @param rom_data ROM data to patch (will be modified)
* @param base_path Base path for resolving includes
* @return Patch result with status and extracted information
*/
absl::StatusOr<AsarPatchResult> ApplyPatchFromString(
const std::string& patch_content,
std::vector<uint8_t>& rom_data,
const std::string& base_path = "");
/**
* @brief Extract symbols from an assembly file without patching
* @param asm_path Path to the assembly file
* @param include_paths Additional include paths
* @return Vector of extracted symbols
*/
absl::StatusOr<std::vector<AsarSymbol>> ExtractSymbols(
const std::string& asm_path,
const std::vector<std::string>& include_paths = {});
/**
* @brief Get all available symbols from the last patch operation
* @return Map of symbol names to symbol information
*/
std::map<std::string, AsarSymbol> GetSymbolTable() const;
/**
* @brief Find a symbol by name
* @param name Symbol name to search for
* @return Symbol information if found
*/
std::optional<AsarSymbol> FindSymbol(const std::string& name) const;
/**
* @brief Get symbols at a specific address
* @param address Memory address to search
* @return Vector of symbols at that address
*/
std::vector<AsarSymbol> GetSymbolsAtAddress(uint32_t address) const;
/**
* @brief Reset the Asar state (clear errors, warnings, symbols)
*/
void Reset();
/**
* @brief Get the last error messages
* @return Vector of error strings
*/
std::vector<std::string> GetLastErrors() const { return last_errors_; }
/**
* @brief Get the last warning messages
* @return Vector of warning strings
*/
std::vector<std::string> GetLastWarnings() const { return last_warnings_; }
/**
* @brief Create a patch that can be applied to transform one ROM to another
* @param original_rom Original ROM data
* @param modified_rom Modified ROM data
* @param patch_path Output path for the generated patch
* @return Status indicating success or failure
*/
absl::Status CreatePatch(
const std::vector<uint8_t>& original_rom,
const std::vector<uint8_t>& modified_rom,
const std::string& patch_path);
/**
* @brief Validate an assembly file for syntax errors
* @param asm_path Path to the assembly file
* @return Status indicating validation result
*/
absl::Status ValidateAssembly(const std::string& asm_path);
private:
bool initialized_;
std::map<std::string, AsarSymbol> symbol_table_;
std::vector<std::string> last_errors_;
std::vector<std::string> last_warnings_;
/**
* @brief Process errors from Asar and store them
*/
void ProcessErrors();
/**
* @brief Process warnings from Asar and store them
*/
void ProcessWarnings();
/**
* @brief Extract symbols from the last Asar operation
*/
void ExtractSymbolsFromLastOperation();
/**
* @brief Convert Asar symbol data to AsarSymbol struct
*/
AsarSymbol ConvertAsarSymbol(const void* asar_symbol_data) const;
};
} // namespace core
} // namespace yaze
#endif // YAZE_APP_CORE_ASAR_WRAPPER_H

View File

@@ -1,6 +1,6 @@
set(
YAZE_APP_CORE_SRC
app/core/asar_wrapper.cc
core/asar_wrapper.cc
app/core/controller.cc
app/core/project.cc
app/core/window.cc

View File

@@ -14,7 +14,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "app/core/asar_wrapper.h"
#include "core/asar_wrapper.h"
#include "app/core/features.h"
#include "app/editor/overworld/map_properties.h"
#include "app/editor/overworld/entity.h"

View File

@@ -10,7 +10,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "app/core/asar_wrapper.h"
#include "core/asar_wrapper.h"
#include "app/gfx/debug/performance/performance_profiler.h"
#include "app/core/window.h"
#include "app/editor/overworld/entity.h"

View File

@@ -361,10 +361,6 @@ void UICoordinator::DrawSessionIndicator() {
// TODO: [EditorManagerRefactor] Implement session indicator in menu bar
}
void UICoordinator::DrawVersionInfo() {
// TODO: [EditorManagerRefactor] Implement version info display (currently in menu bar extras)
}
void UICoordinator::DrawSessionTabs() {
// TODO: [EditorManagerRefactor] Implement session tabs UI
}
@@ -393,16 +389,6 @@ void UICoordinator::DrawMaterialButton(const std::string& text, const std::strin
}
}
void UICoordinator::DrawMaterialCard(const std::string& title, const std::string& content) {
// TODO: [EditorManagerRefactor] Implement Material Design card component
// Use ThemeManager for consistent Material Design styling
}
void UICoordinator::DrawMaterialDialog(const std::string& title, std::function<void()> content) {
// TODO: [EditorManagerRefactor] Implement Material Design dialog component
// Use ThemeManager for consistent Material Design styling
}
// Layout and positioning helpers
void UICoordinator::CenterWindow(const std::string& window_name) {
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
@@ -446,80 +432,6 @@ void UICoordinator::ApplyEditorTheme(EditorType type) {
// Use ThemeManager to push/pop style colors based on editor type
}
// Session UI helpers (delegated to SessionCoordinator)
void UICoordinator::DrawSessionList() {
// TODO: [EditorManagerRefactor] Implement session list UI
// Or delegate to SessionCoordinator
}
void UICoordinator::DrawSessionControls() {
// TODO: [EditorManagerRefactor] Implement session control buttons
// Or delegate to SessionCoordinator
}
void UICoordinator::DrawSessionInfo() {
// TODO: [EditorManagerRefactor] Implement session info display
// Or delegate to SessionCoordinator
}
void UICoordinator::DrawSessionStatus() {
// TODO: [EditorManagerRefactor] Implement session status indicators
// Or delegate to SessionCoordinator
}
// Popup helpers (delegated to PopupManager)
void UICoordinator::DrawHelpMenuPopups() {
// TODO: [EditorManagerRefactor] Coordinate help menu popup display
// Popups are managed by PopupManager
}
void UICoordinator::DrawSettingsPopups() {
// TODO: [EditorManagerRefactor] Coordinate settings popup display
// Popups are managed by PopupManager
}
void UICoordinator::DrawProjectPopups() {
// TODO: [EditorManagerRefactor] Coordinate project popup display
// Popups are managed by PopupManager
}
void UICoordinator::DrawSessionPopups() {
// TODO: [EditorManagerRefactor] Coordinate session popup display
// Popups are managed by PopupManager
}
// Window management helpers (delegated to WindowDelegate/WorkspaceManager)
void UICoordinator::DrawWindowControls() {
// TODO: [EditorManagerRefactor] Implement window visibility controls
// Delegate to WindowDelegate
}
void UICoordinator::DrawLayoutControls() {
// TODO: [EditorManagerRefactor] Implement layout management controls
// Delegate to LayoutManager and WorkspaceManager
}
void UICoordinator::DrawDockingControls() {
// TODO: [EditorManagerRefactor] Implement docking configuration controls
// Use ImGui::DockBuilder API
}
// Performance and debug UI (delegated to specialized components)
void UICoordinator::DrawPerformanceUI() {
// TODO: [EditorManagerRefactor] Coordinate performance dashboard display
// Performance dashboard is managed separately (PerformanceDashboard::Get())
}
void UICoordinator::DrawDebugUI() {
// TODO: [EditorManagerRefactor] Coordinate debug UI display
// Debug windows (ImGui Demo, Metrics) managed by EditorManager
}
void UICoordinator::DrawTestingUI() {
// TODO: [EditorManagerRefactor] Coordinate test dashboard display
// Test dashboard managed by TestManager
}
void UICoordinator::DrawCommandPalette() {
if (!show_command_palette_) return;
@@ -643,7 +555,7 @@ void UICoordinator::DrawCommandPalette() {
}
}
EndTable();
gui::LayoutHelpers::EndTableWithTheming();
}
EndTabItem();
}

View File

@@ -176,15 +176,12 @@ class UICoordinator {
// Helper methods for drawing operations
void DrawSessionIndicator();
void DrawVersionInfo();
void DrawSessionTabs();
void DrawSessionBadges();
// Material Design component helpers
void DrawMaterialButton(const std::string& text, const std::string& icon,
std::function<void()> callback, bool enabled = true);
void DrawMaterialCard(const std::string& title, const std::string& content);
void DrawMaterialDialog(const std::string& title, std::function<void()> content);
// Layout and positioning helpers
void CenterWindow(const std::string& window_name);
@@ -196,27 +193,6 @@ class UICoordinator {
std::string GetColorForEditor(EditorType type) const;
void ApplyEditorTheme(EditorType type);
// Session UI helpers
void DrawSessionList();
void DrawSessionControls();
void DrawSessionInfo();
void DrawSessionStatus();
// Popup helpers
void DrawHelpMenuPopups();
void DrawSettingsPopups();
void DrawProjectPopups();
void DrawSessionPopups();
// Window management helpers
void DrawWindowControls();
void DrawLayoutControls();
void DrawDockingControls();
// Performance and debug UI
void DrawPerformanceUI();
void DrawDebugUI();
void DrawTestingUI();
};
} // namespace editor

View File

@@ -95,6 +95,14 @@ bool LayoutHelpers::BeginTableWithTheming(const char* str_id, int columns,
return ImGui::BeginTable(str_id, columns, flags, outer_size, inner_width);
}
void LayoutHelpers::EndTableWithTheming() {
ImGui::EndTable();
// Pop style colors (5 colors pushed in BeginTableWithTheming)
ImGui::PopStyleColor(5);
// Pop style var if it was pushed (CellPadding)
ImGui::PopStyleVar(1);
}
void LayoutHelpers::BeginCanvasPanel(const char* label, ImVec2* canvas_size) {
const auto& theme = GetTheme();

View File

@@ -36,6 +36,7 @@ class LayoutHelpers {
ImGuiTableFlags flags = 0,
const ImVec2& outer_size = ImVec2(0, 0),
float inner_width = 0.0f);
static void EndTableWithTheming();
static void EndTable() { ImGui::EndTable(); }
static void BeginCanvasPanel(const char* label, ImVec2* canvas_size = nullptr);

View File

@@ -4,7 +4,7 @@
#include <ftxui/component/screen_interactive.hpp>
#include "cli/tui/tui.h"
#include "app/core/asar_wrapper.h"
#include "core/asar_wrapper.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"

View File

@@ -11,7 +11,7 @@
#include "absl/strings/str_format.h"
#include "util/bps.h"
#include "util/file_util.h"
#include "app/core/asar_wrapper.h"
#include "core/asar_wrapper.h"
#include "cli/cli.h"
#include "cli/tui/unified_layout.h"
#include "cli/z3ed_ascii_logo.h"
@@ -329,7 +329,7 @@ void ApplyAsarPatchComponent(ftxui::ScreenInteractive &screen) {
try {
// TODO: Use new CommandHandler system for AsarPatch
// Reference: src/app/core/asar_wrapper.cc (AsarWrapper class)
// Reference: src/core/asar_wrapper.cc (AsarWrapper class)
output_message = "❌ AsarPatch not yet implemented in new CommandHandler system";
output_color = Color::Red;
} catch (const std::exception& e) {

View File

@@ -1,9 +1,9 @@
#include "app/core/asar_wrapper.h"
#include "core/asar_wrapper.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
@@ -85,7 +85,7 @@ absl::StatusOr<AsarPatchResult> AsarWrapper::ApplyPatch(
int buffer_size = std::max(rom_size, 16 * 1024 * 1024); // At least 16MB buffer
// Resize ROM data if needed
if (rom_data.size() < buffer_size) {
if (rom_data.size() < static_cast<size_t>(buffer_size)) {
rom_data.resize(buffer_size, 0);
}
@@ -132,39 +132,45 @@ absl::StatusOr<AsarPatchResult> AsarWrapper::ApplyPatchFromString(
std::vector<uint8_t>& rom_data,
const std::string& base_path) {
// Create temporary file for patch content
std::string temp_path = "/tmp/yaze_temp_patch.asm";
if (!base_path.empty()) {
// Ensure directory exists
std::filesystem::create_directories(base_path);
temp_path = base_path + "/temp_patch.asm";
if (!initialized_) {
return absl::FailedPreconditionError("Asar not initialized");
}
std::ofstream temp_file(temp_path);
if (!temp_file) {
return absl::InternalError(absl::StrFormat(
"Failed to create temporary patch file at: %s", temp_path));
}
temp_file << patch_content;
temp_file.close();
// Reset previous state
Reset();
// Write patch content to temporary file
std::filesystem::path temp_patch_path =
std::filesystem::temp_directory_path() / "yaze_asar_temp.asm";
std::ofstream temp_patch_file(temp_patch_path);
if (!temp_patch_file) {
return absl::InternalError("Failed to create temporary patch file");
}
temp_patch_file << patch_content;
temp_patch_file.close();
// Apply patch using temporary file
auto patch_result = ApplyPatch(temp_patch_path.string(), rom_data, {base_path});
auto result = ApplyPatch(temp_path, rom_data);
// Clean up temporary file
std::remove(temp_path.c_str());
return result;
std::error_code ec;
std::filesystem::remove(temp_patch_path, ec);
return patch_result;
}
absl::StatusOr<std::vector<AsarSymbol>> AsarWrapper::ExtractSymbols(
const std::string& asm_path,
const std::vector<std::string>& include_paths) {
if (!initialized_) {
return absl::FailedPreconditionError("Asar not initialized");
}
// Reset state before extraction
Reset();
// Create a dummy ROM for symbol extraction
std::vector<uint8_t> dummy_rom(1024 * 1024, 0); // 1MB dummy ROM

108
src/core/asar_wrapper.h Normal file
View File

@@ -0,0 +1,108 @@
#ifndef YAZE_CORE_ASAR_WRAPPER_H
#define YAZE_CORE_ASAR_WRAPPER_H
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
namespace yaze {
namespace core {
/**
* @brief Symbol information extracted from Asar assembly
*/
struct AsarSymbol {
std::string name; // Symbol name
uint32_t address; // Memory address
std::string opcode; // Associated opcode if available
std::string file; // Source file
int line; // Line number in source
std::string comment; // Optional comment
};
/**
* @brief Asar patch result information
*/
struct AsarPatchResult {
bool success; // Whether patch was successful
std::vector<std::string> errors; // Error messages if any
std::vector<std::string> warnings; // Warning messages
std::vector<AsarSymbol> symbols; // Extracted symbols
uint32_t rom_size; // Final ROM size after patching
uint32_t crc32; // CRC32 checksum of patched ROM
};
/**
* @brief Modern C++ wrapper for Asar 65816 assembler integration.
*
* Provides a high-level interface for:
* - Patching ROMs with assembly code
* - Extracting symbol names and opcodes
* - Cross-platform compatibility (Windows, macOS, Linux)
*/
class AsarWrapper {
public:
AsarWrapper();
~AsarWrapper();
AsarWrapper(const AsarWrapper&) = delete;
AsarWrapper& operator=(const AsarWrapper&) = delete;
AsarWrapper(AsarWrapper&&) = default;
AsarWrapper& operator=(AsarWrapper&&) = default;
absl::Status Initialize();
void Shutdown();
bool IsInitialized() const { return initialized_; }
std::string GetVersion() const;
int GetApiVersion() const;
absl::StatusOr<AsarPatchResult> ApplyPatch(
const std::string& patch_path, std::vector<uint8_t>& rom_data,
const std::vector<std::string>& include_paths = {});
absl::StatusOr<AsarPatchResult> ApplyPatchFromString(
const std::string& patch_content, std::vector<uint8_t>& rom_data,
const std::string& base_path = "");
absl::StatusOr<std::vector<AsarSymbol>> ExtractSymbols(
const std::string& asm_path,
const std::vector<std::string>& include_paths = {});
std::map<std::string, AsarSymbol> GetSymbolTable() const;
std::optional<AsarSymbol> FindSymbol(const std::string& name) const;
std::vector<AsarSymbol> GetSymbolsAtAddress(uint32_t address) const;
void Reset();
std::vector<std::string> GetLastErrors() const { return last_errors_; }
std::vector<std::string> GetLastWarnings() const { return last_warnings_; }
absl::Status CreatePatch(const std::vector<uint8_t>& original_rom,
const std::vector<uint8_t>& modified_rom,
const std::string& patch_path);
absl::Status ValidateAssembly(const std::string& asm_path);
private:
bool initialized_;
std::map<std::string, AsarSymbol> symbol_table_;
std::vector<std::string> last_errors_;
std::vector<std::string> last_warnings_;
void ProcessErrors();
void ProcessWarnings();
void ExtractSymbolsFromLastOperation();
AsarSymbol ConvertAsarSymbol(const void* asar_symbol_data) const;
};
} // namespace core
} // namespace yaze
#endif // YAZE_CORE_ASAR_WRAPPER_H