Merge pull request #12 from scawful/mosaic-editor
Created Script class for Mosaic Editor
This commit is contained in:
53
assets/asm/mosaic_change.asm
Normal file
53
assets/asm/mosaic_change.asm
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
include_directories(lib/cmake)
|
|
||||||
|
|
||||||
# gui libraries ---------------------------------------------------------------
|
# gui libraries ---------------------------------------------------------------
|
||||||
set(IMGUI_PATH "lib/imgui")
|
set(IMGUI_PATH "lib/imgui")
|
||||||
file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp)
|
file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp)
|
||||||
@@ -23,9 +21,23 @@ target_include_directories(ImGuiColorTextEdit PUBLIC ${IMGUI_PATH})
|
|||||||
target_compile_definitions(ImGuiColorTextEdit PUBLIC
|
target_compile_definitions(ImGuiColorTextEdit PUBLIC
|
||||||
IMGUI_IMPL_OPENGL_LOADER_CUSTOM=<SDL2/SDL_opengl.h> GL_GLEXT_PROTOTYPES=1)
|
IMGUI_IMPL_OPENGL_LOADER_CUSTOM=<SDL2/SDL_opengl.h> 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)
|
get_target_property(ASAR_INCLUDE_DIR asar-static INCLUDE_DIRECTORIES)
|
||||||
include_directories(${ASAR_INCLUDE_DIR})
|
add_definitions(-Dstricmp=strcasecmp)
|
||||||
|
|
||||||
# executable linkage ----------------------------------------------------------
|
# executable linkage ----------------------------------------------------------
|
||||||
|
|
||||||
@@ -60,34 +72,36 @@ set(
|
|||||||
app/zelda3/screen.cc
|
app/zelda3/screen.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(
|
set(
|
||||||
yaze
|
YAZE_APP_ASM_SRC
|
||||||
yaze.cc
|
app/asm/script.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_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(
|
target_include_directories(
|
||||||
yaze PUBLIC
|
yaze PUBLIC
|
||||||
lib/
|
lib/
|
||||||
app/
|
app/
|
||||||
|
${ASAR_INCLUDE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}/src/
|
${CMAKE_SOURCE_DIR}/src/
|
||||||
${PNG_INCLUDE_DIRS}
|
${PNG_INCLUDE_DIRS}
|
||||||
${SDL2_INCLUDE_DIR}
|
${SDL2_INCLUDE_DIR}
|
||||||
|
|||||||
45
src/app/asm/script.cc
Normal file
45
src/app/asm/script.cc
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "script.h"
|
||||||
|
|
||||||
|
#include <interface-lib.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#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<absl::string_view> Script::GenerateMosaicChangeAssembly(
|
||||||
|
std::array<int, core::kNumOverworldMaps> 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
|
||||||
41
src/app/asm/script.h
Normal file
41
src/app/asm/script.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef YAZE_APP_ASM_SCRIPT_H
|
||||||
|
#define YAZE_APP_ASM_SCRIPT_H
|
||||||
|
|
||||||
|
#include <interface-lib.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#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<absl::string_view> GenerateMosaicChangeAssembly(
|
||||||
|
std::array<int, core::kNumOverworldMaps> mosaic_tiles);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int64_t patch_size_;
|
||||||
|
std::string patch_filename_;
|
||||||
|
std::string patch_contents_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace snes_asm
|
||||||
|
} // namespace app
|
||||||
|
} // namespace yaze
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -89,10 +89,10 @@ constexpr int NumberOfSheets = 223;
|
|||||||
constexpr int LimitOfMap32 = 8864;
|
constexpr int LimitOfMap32 = 8864;
|
||||||
constexpr int NumberOfRooms = 296;
|
constexpr int NumberOfRooms = 296;
|
||||||
|
|
||||||
constexpr int NumberOfOWMaps = 160;
|
constexpr int kNumOverworldMaps = 160;
|
||||||
constexpr int Map32PerScreen = 256;
|
constexpr int Map32PerScreen = 256;
|
||||||
constexpr int NumberOfMap16 = 3752; // 4096
|
constexpr int NumberOfMap16 = 3752; // 4096
|
||||||
constexpr int NumberOfMap32 = Map32PerScreen * NumberOfOWMaps;
|
constexpr int NumberOfMap32 = Map32PerScreen * kNumOverworldMaps;
|
||||||
constexpr int NumberOfOWSprites = 352;
|
constexpr int NumberOfOWSprites = 352;
|
||||||
constexpr int NumberOfColors = 3143;
|
constexpr int NumberOfColors = 3143;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
|
#include "app/rom.h"
|
||||||
#include "app/zelda3/overworld.h"
|
#include "app/zelda3/overworld.h"
|
||||||
#include "gui/canvas.h"
|
#include "gui/canvas.h"
|
||||||
#include "gui/icons.h"
|
#include "gui/icons.h"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
|
#include "app/rom.h"
|
||||||
#include "app/zelda3/overworld.h"
|
#include "app/zelda3/overworld.h"
|
||||||
#include "gui/canvas.h"
|
#include "gui/canvas.h"
|
||||||
#include "gui/icons.h"
|
#include "gui/icons.h"
|
||||||
|
|||||||
@@ -2,6 +2,15 @@
|
|||||||
|
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
#include "app/asm/script.h"
|
||||||
#include "app/core/common.h"
|
#include "app/core/common.h"
|
||||||
#include "app/core/constants.h"
|
#include "app/core/constants.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
@@ -16,6 +25,7 @@ ScreenEditor::ScreenEditor() { screen_canvas_.SetCanvasSize(ImVec2(512, 512)); }
|
|||||||
|
|
||||||
void ScreenEditor::Update() {
|
void ScreenEditor::Update() {
|
||||||
TAB_BAR("##TabBar")
|
TAB_BAR("##TabBar")
|
||||||
|
DrawMosaicEditor();
|
||||||
DrawTitleScreenEditor();
|
DrawTitleScreenEditor();
|
||||||
DrawNamingScreenEditor();
|
DrawNamingScreenEditor();
|
||||||
DrawOverworldMapEditor();
|
DrawOverworldMapEditor();
|
||||||
@@ -25,6 +35,20 @@ void ScreenEditor::Update() {
|
|||||||
END_TAB_BAR()
|
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() {
|
void ScreenEditor::DrawTitleScreenEditor() {
|
||||||
TAB_ITEM("Title Screen")
|
TAB_ITEM("Title Screen")
|
||||||
END_TAB_ITEM()
|
END_TAB_ITEM()
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "app/asm/script.h"
|
||||||
|
#include "app/core/constants.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "app/zelda3/screen.h"
|
#include "app/zelda3/screen.h"
|
||||||
@@ -12,12 +16,15 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
|
using MosaicArray = std::array<int, core::kNumOverworldMaps>;
|
||||||
|
|
||||||
class ScreenEditor {
|
class ScreenEditor {
|
||||||
public:
|
public:
|
||||||
ScreenEditor();
|
ScreenEditor();
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void DrawMosaicEditor();
|
||||||
void DrawTitleScreenEditor();
|
void DrawTitleScreenEditor();
|
||||||
void DrawNamingScreenEditor();
|
void DrawNamingScreenEditor();
|
||||||
void DrawOverworldMapEditor();
|
void DrawOverworldMapEditor();
|
||||||
@@ -28,6 +35,8 @@ class ScreenEditor {
|
|||||||
void DrawCanvas();
|
void DrawCanvas();
|
||||||
void DrawToolset();
|
void DrawToolset();
|
||||||
|
|
||||||
|
std::array<int, core::kNumOverworldMaps> mosaic_tiles_;
|
||||||
|
snes_asm::Script mosaic_script_;
|
||||||
zelda3::Screen current_screen_;
|
zelda3::Screen current_screen_;
|
||||||
gui::Canvas screen_canvas_;
|
gui::Canvas screen_canvas_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ absl::Status Overworld::Load(ROM &rom, uchar *ow_blockset) {
|
|||||||
return decompression_status;
|
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);
|
overworld_maps_.emplace_back(map_index, rom_, tiles16);
|
||||||
|
|
||||||
FetchLargeMaps();
|
FetchLargeMaps();
|
||||||
|
|
||||||
auto size = tiles16.size();
|
auto size = tiles16.size();
|
||||||
for (int i = 0; i < core::NumberOfOWMaps; ++i) {
|
for (int i = 0; i < core::kNumOverworldMaps; ++i) {
|
||||||
auto map_status =
|
auto map_status =
|
||||||
overworld_maps_[i].BuildMapV2(size, game_state_, map_parent_);
|
overworld_maps_[i].BuildMapV2(size, game_state_, map_parent_);
|
||||||
if (!map_status.ok()) {
|
if (!map_status.ok()) {
|
||||||
|
|||||||
Submodule src/lib/SDL updated: adb3e1a21d...5858c7dfce
Submodule src/lib/abseil-cpp updated: 701185dbce...0c92330442
@@ -15,6 +15,7 @@ add_executable(
|
|||||||
yaze_test.cc
|
yaze_test.cc
|
||||||
rom_test.cc
|
rom_test.cc
|
||||||
../src/app/rom.cc
|
../src/app/rom.cc
|
||||||
|
../src/app/asm/script.cc
|
||||||
../src/app/gfx/bitmap.cc
|
../src/app/gfx/bitmap.cc
|
||||||
../src/app/gfx/snes_tile.cc
|
../src/app/gfx/snes_tile.cc
|
||||||
../src/app/gfx/snes_palette.cc
|
../src/app/gfx/snes_palette.cc
|
||||||
@@ -43,6 +44,7 @@ target_link_libraries(
|
|||||||
absl::raw_logging_internal
|
absl::raw_logging_internal
|
||||||
SDL2::SDL2
|
SDL2::SDL2
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
|
asar-static
|
||||||
gmock_main
|
gmock_main
|
||||||
gmock
|
gmock
|
||||||
gtest_main
|
gtest_main
|
||||||
|
|||||||
Reference in New Issue
Block a user