Merge pull request #12 from scawful/mosaic-editor

Created Script class for Mosaic Editor
This commit is contained in:
Justin Scofield
2022-08-06 13:21:51 -04:00
committed by GitHub
13 changed files with 222 additions and 32 deletions

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

View File

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

45
src/app/asm/script.cc Normal file
View 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
View 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

View File

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

View File

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

View File

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

View File

@@ -2,6 +2,15 @@
#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/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()

View File

@@ -3,6 +3,10 @@
#include <imgui/imgui.h>
#include <array>
#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<int, core::kNumOverworldMaps>;
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<int, core::kNumOverworldMaps> mosaic_tiles_;
snes_asm::Script mosaic_script_;
zelda3::Screen current_screen_;
gui::Canvas screen_canvas_;
};

View File

@@ -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()) {

View File

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