diff --git a/assets/asm/mosaic_change.asm b/assets/asm/mosaic_change.asm new file mode 100644 index 00000000..ab7ff135 --- /dev/null +++ b/assets/asm/mosaic_change.asm @@ -0,0 +1,53 @@ + + JML AreaCheck + +AreaCheck: +{ + PHB : PHK : PLB + + TAX + LDA .pool, X + + BEQ .noMosaic1 + PLB + JML $02AAE5 + + .noMosaic1 + + LDX $8A + LDA .pool, X + + BEQ .noMosaic2 + PLB + JML $02AAE5 + + .noMosaic2 + + PLB + JML $02AAF4 + + .pool + ;LW + db $01, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + ;DW + db $01, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + ;SP + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 + db $00, $00, $00, $00, $00, $00, $00, $00 +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8bed4879..cd190498 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(lib/cmake) - # gui libraries --------------------------------------------------------------- set(IMGUI_PATH "lib/imgui") file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp) @@ -23,9 +21,23 @@ target_include_directories(ImGuiColorTextEdit PUBLIC ${IMGUI_PATH}) target_compile_definitions(ImGuiColorTextEdit PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) -# asar assembly --------------------------------------------------------------- +set( + IMGUI_SRC + ${IMGUI_PATH}/imgui.cpp + ${IMGUI_PATH}/imgui_demo.cpp + ${IMGUI_PATH}/imgui_draw.cpp + ${IMGUI_PATH}/imgui_widgets.cpp + ${IMGUI_PATH}/backends/imgui_impl_sdl.cpp + ${IMGUI_PATH}/backends/imgui_impl_sdlrenderer.cpp + ${IMGUI_PATH}/misc/cpp/imgui_stdlib.cpp + ${IMGUI_FILE_DLG_PATH}/ImGuiFileDialog.cpp + ${IMGUI_COLOR_TEXT_EDIT_PATH}/TextEditor.cpp +) + +# Asar Assembly --------------------------------------------------------------- +add_subdirectory(lib/asar/src) get_target_property(ASAR_INCLUDE_DIR asar-static INCLUDE_DIRECTORIES) -include_directories(${ASAR_INCLUDE_DIR}) +add_definitions(-Dstricmp=strcasecmp) # executable linkage ---------------------------------------------------------- @@ -60,34 +72,36 @@ set( app/zelda3/screen.cc ) -add_executable( - yaze - yaze.cc - ${YAZE_APP_CORE_SRC} - ${YAZE_APP_EDITOR_SRC} - ${YAZE_APP_GFX_SRC} - ${YAZE_APP_ZELDA3_SRC} - app/rom.cc - gui/canvas.cc - gui/input.cc - gui/style.cc - gui/widgets.cc - # GUI libraries - ${IMGUI_PATH}/imgui.cpp - ${IMGUI_PATH}/imgui_demo.cpp - ${IMGUI_PATH}/imgui_draw.cpp - ${IMGUI_PATH}/imgui_widgets.cpp - ${IMGUI_PATH}/backends/imgui_impl_sdl.cpp - ${IMGUI_PATH}/backends/imgui_impl_sdlrenderer.cpp - ${IMGUI_PATH}/misc/cpp/imgui_stdlib.cpp - ${IMGUI_FILE_DLG_PATH}/ImGuiFileDialog.cpp - ${IMGUI_COLOR_TEXT_EDIT_PATH}/TextEditor.cpp +set( + YAZE_APP_ASM_SRC + app/asm/script.cc ) +set( + YAZE_GUI_SRC + gui/canvas.cc + gui/input.cc + gui/style.cc + gui/widgets.cc +) + +add_executable( + yaze + yaze.cc + app/rom.cc + ${YAZE_APP_ASM_SRC} + ${YAZE_APP_CORE_SRC} + ${YAZE_APP_EDITOR_SRC} + ${YAZE_APP_GFX_SRC} + ${YAZE_APP_ZELDA3_SRC} + ${YAZE_GUI_SRC} + ${IMGUI_SRC} + target_include_directories( yaze PUBLIC lib/ app/ + ${ASAR_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/ ${PNG_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} diff --git a/src/app/asm/script.cc b/src/app/asm/script.cc new file mode 100644 index 00000000..6bf86938 --- /dev/null +++ b/src/app/asm/script.cc @@ -0,0 +1,45 @@ +#include "script.h" + +#include + +#include +#include +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "app/core/constants.h" +#include "app/rom.h" + +namespace yaze { +namespace app { +namespace snes_asm { + +absl::Status Script::ApplyPatchToROM(ROM& rom) { + if (!asar_patch(patch_filename_, rom_.data(), patch_size_, rom_.size())) { + return absl::InternalError("Unable to apply patch"); + } + return absl::OkStatus(); +} + +absl::StatusOr Script::GenerateMosaicChangeAssembly( + std::array mosaic_tiles) { + std::fstream file("assets/asm/mosaic_change.asm", + std::ios::out | std::ios::in); + if (!file.is_open()) { + return absl::InvalidArgumentError( + "Couldn't open mosaic change template file"); + } + std::stringstream assembly; + assembly << "org "; + assembly << kDefaultMosaicHook; + assembly << file.rdbuf(); + + file.close(); + return assembly.str(); +} + +} // namespace snes_asm +} // namespace app +} // namespace yaze \ No newline at end of file diff --git a/src/app/asm/script.h b/src/app/asm/script.h new file mode 100644 index 00000000..6d131551 --- /dev/null +++ b/src/app/asm/script.h @@ -0,0 +1,41 @@ +#ifndef YAZE_APP_ASM_SCRIPT_H +#define YAZE_APP_ASM_SCRIPT_H + +#include + +#include +#include +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "app/core/constants.h" +#include "app/rom.h" + +namespace yaze { +namespace app { +namespace snes_asm { + +constexpr char kDefaultMosaicHook[] = "$02AADB"; + +class Script { + public: + Script() = default; + + absl::Status ApplyPatchToROM(ROM& rom); + + absl::StatusOr GenerateMosaicChangeAssembly( + std::array mosaic_tiles); + + private: + int64_t patch_size_; + std::string patch_filename_; + std::string patch_contents_; +}; + +} // namespace snes_asm +} // namespace app +} // namespace yaze + +#endif \ No newline at end of file diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 55a0e640..54eba4c7 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -89,10 +89,10 @@ constexpr int NumberOfSheets = 223; constexpr int LimitOfMap32 = 8864; constexpr int NumberOfRooms = 296; -constexpr int NumberOfOWMaps = 160; +constexpr int kNumOverworldMaps = 160; constexpr int Map32PerScreen = 256; constexpr int NumberOfMap16 = 3752; // 4096 -constexpr int NumberOfMap32 = Map32PerScreen * NumberOfOWMaps; +constexpr int NumberOfMap32 = Map32PerScreen * kNumOverworldMaps; constexpr int NumberOfOWSprites = 352; constexpr int NumberOfColors = 3143; diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index e76d4d5b..8005f8a9 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -11,6 +11,7 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" +#include "app/rom.h" #include "app/zelda3/overworld.h" #include "gui/canvas.h" #include "gui/icons.h" diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index 48aca883..fe5f4407 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -11,6 +11,7 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" +#include "app/rom.h" #include "app/zelda3/overworld.h" #include "gui/canvas.h" #include "gui/icons.h" diff --git a/src/app/editor/screen_editor.cc b/src/app/editor/screen_editor.cc index 7dfd72d0..14e533fb 100644 --- a/src/app/editor/screen_editor.cc +++ b/src/app/editor/screen_editor.cc @@ -2,6 +2,15 @@ #include +#include +#include +#include +#include +#include + +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "app/asm/script.h" #include "app/core/common.h" #include "app/core/constants.h" #include "app/gfx/bitmap.h" @@ -16,6 +25,7 @@ ScreenEditor::ScreenEditor() { screen_canvas_.SetCanvasSize(ImVec2(512, 512)); } void ScreenEditor::Update() { TAB_BAR("##TabBar") + DrawMosaicEditor(); DrawTitleScreenEditor(); DrawNamingScreenEditor(); DrawOverworldMapEditor(); @@ -25,6 +35,20 @@ void ScreenEditor::Update() { END_TAB_BAR() } +void ScreenEditor::DrawMosaicEditor() { + TAB_ITEM("Mosaic Transitions") + if (ImGui::Button("GenerateMosaicChangeAssembly")) { + auto mosaic = mosaic_script_.GenerateMosaicChangeAssembly(mosaic_tiles_); + if (!mosaic.ok()) { + std::cout << "Failed to generate mosaic change assembly"; + } else { + std::cout << "Successfully generated mosaic change assembly"; + std::cout << mosaic.value(); + } + } + END_TAB_ITEM() +} + void ScreenEditor::DrawTitleScreenEditor() { TAB_ITEM("Title Screen") END_TAB_ITEM() diff --git a/src/app/editor/screen_editor.h b/src/app/editor/screen_editor.h index 23a56c4b..bd9a900c 100644 --- a/src/app/editor/screen_editor.h +++ b/src/app/editor/screen_editor.h @@ -3,6 +3,10 @@ #include +#include + +#include "app/asm/script.h" +#include "app/core/constants.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" #include "app/zelda3/screen.h" @@ -12,12 +16,15 @@ namespace yaze { namespace app { namespace editor { +using MosaicArray = std::array; + class ScreenEditor { public: ScreenEditor(); void Update(); private: + void DrawMosaicEditor(); void DrawTitleScreenEditor(); void DrawNamingScreenEditor(); void DrawOverworldMapEditor(); @@ -28,6 +35,8 @@ class ScreenEditor { void DrawCanvas(); void DrawToolset(); + std::array mosaic_tiles_; + snes_asm::Script mosaic_script_; zelda3::Screen current_screen_; gui::Canvas screen_canvas_; }; diff --git a/src/app/zelda3/overworld.cc b/src/app/zelda3/overworld.cc index ac323edd..6cad4655 100644 --- a/src/app/zelda3/overworld.cc +++ b/src/app/zelda3/overworld.cc @@ -18,13 +18,13 @@ absl::Status Overworld::Load(ROM &rom, uchar *ow_blockset) { return decompression_status; } - for (int map_index = 0; map_index < core::NumberOfOWMaps; ++map_index) + for (int map_index = 0; map_index < core::kNumOverworldMaps; ++map_index) overworld_maps_.emplace_back(map_index, rom_, tiles16); FetchLargeMaps(); auto size = tiles16.size(); - for (int i = 0; i < core::NumberOfOWMaps; ++i) { + for (int i = 0; i < core::kNumOverworldMaps; ++i) { auto map_status = overworld_maps_[i].BuildMapV2(size, game_state_, map_parent_); if (!map_status.ok()) { diff --git a/src/lib/SDL b/src/lib/SDL index adb3e1a2..5858c7df 160000 --- a/src/lib/SDL +++ b/src/lib/SDL @@ -1 +1 @@ -Subproject commit adb3e1a21d381cc1e62a12ae41cc7e5585c72a92 +Subproject commit 5858c7dfce80b0854b04475dde97996692ce9200 diff --git a/src/lib/abseil-cpp b/src/lib/abseil-cpp index 701185db..0c923304 160000 --- a/src/lib/abseil-cpp +++ b/src/lib/abseil-cpp @@ -1 +1 @@ -Subproject commit 701185dbce17a2f49334027ca3cb5788a5d06c6d +Subproject commit 0c92330442d6b1be934e0407115c8084250ef347 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index aa049b21..66023f68 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable( yaze_test.cc rom_test.cc ../src/app/rom.cc + ../src/app/asm/script.cc ../src/app/gfx/bitmap.cc ../src/app/gfx/snes_tile.cc ../src/app/gfx/snes_palette.cc @@ -43,6 +44,7 @@ target_link_libraries( absl::raw_logging_internal SDL2::SDL2 ${OPENGL_LIBRARIES} + asar-static gmock_main gmock gtest_main