From 3b24ce11d0d11ed6fbaeeb826a21034c6484bcd7 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:38:55 -0400 Subject: [PATCH 01/24] chore: cleanup files and move common method --- src/app/asm/script.cc | 14 +++----------- src/app/core/common.cc | 12 +++++++++++- src/app/core/common.h | 3 +++ src/app/editor/palette_editor.cc | 1 - src/app/rom.h | 2 +- src/gui/input.cc | 2 +- src/gui/input.h | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/app/asm/script.cc b/src/app/asm/script.cc index 6203353f..e7bc30b0 100644 --- a/src/app/asm/script.cc +++ b/src/app/asm/script.cc @@ -12,6 +12,7 @@ #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" +#include "app/core/common.h" #include "app/core/constants.h" #include "app/rom.h" @@ -19,15 +20,6 @@ namespace yaze { namespace app { namespace snes_asm { -static auto string_replace(std::string &str, const std::string &from, - const std::string &to) -> bool { - size_t start = str.find(from); - if (start == std::string::npos) return false; - - str.replace(start, from.length(), to); - return true; -} - std::string GenerateBytePool(char mosaic_tiles[core::kNumOverworldMaps]) { std::string to_return = ""; int column = 0; @@ -89,12 +81,12 @@ absl::Status Script::GenerateMosaicChangeAssembly( file.close(); auto assembly_string = assembly.str(); - if (!string_replace(assembly_string, "", kMosaicChangeOffset)) { + if (!core::StringReplace(assembly_string, "", kMosaicChangeOffset)) { return absl::InternalError( "Mosaic template did not have proper `` to replace."); } - if (!string_replace( + if (!core::StringReplace( assembly_string, "", absl::StrFormat("$%x", routine_offset + kSNESToPCOffset))) { return absl::InternalError( diff --git a/src/app/core/common.cc b/src/app/core/common.cc index 1a280333..a8d0ee85 100644 --- a/src/app/core/common.cc +++ b/src/app/core/common.cc @@ -1,6 +1,7 @@ #include "common.h" #include +#include namespace yaze { namespace app { @@ -19,7 +20,7 @@ int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) { } // hextodec has been imported from SNESDisasm to parse hex numbers -int HexToDec(char* input, int length) { +int HexToDec(char *input, int length) { int result = 0; int value; int ceiling = length - 1; @@ -48,6 +49,15 @@ int HexToDec(char* input, int length) { return result; } +bool StringReplace(std::string &str, const std::string &from, + const std::string &to) { + size_t start = str.find(from); + if (start == std::string::npos) return false; + + str.replace(start, from.length(), to); + return true; +} + } // namespace core } // namespace app } // namespace yaze diff --git a/src/app/core/common.h b/src/app/core/common.h index 5217f66f..4a6969a5 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -2,6 +2,7 @@ #define YAZE_CORE_COMMON_H #include +#include namespace yaze { namespace app { @@ -10,6 +11,8 @@ namespace core { unsigned int SnesToPc(unsigned int addr); int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3); int HexToDec(char *input, int length); +bool StringReplace(std::string &str, const std::string &from, + const std::string &to); } // namespace core } // namespace app diff --git a/src/app/editor/palette_editor.cc b/src/app/editor/palette_editor.cc index bee5abb4..e22f88a6 100644 --- a/src/app/editor/palette_editor.cc +++ b/src/app/editor/palette_editor.cc @@ -14,7 +14,6 @@ namespace editor { absl::Status PaletteEditor::Update() { for (const auto &name : kPaletteCategoryNames) { if (ImGui::TreeNode(name.data())) { - ImGui::SameLine(); if (ImGui::SmallButton("button")) { } diff --git a/src/app/rom.h b/src/app/rom.h index 9f95f8a2..3039664f 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -114,9 +114,9 @@ class ROM { private: long size_ = 0; - std::string filename_; uchar title[21] = "ROM Not Loaded"; bool is_loaded_ = false; + std::string filename_; Bytes rom_data_; std::shared_ptr renderer_; diff --git a/src/gui/input.cc b/src/gui/input.cc index 2596d423..ccbe6870 100644 --- a/src/gui/input.cc +++ b/src/gui/input.cc @@ -21,5 +21,5 @@ bool InputHexShort(const char* label, int* data) { ImGuiInputTextFlags_CharsHexadecimal); } -} // namespace Gui +} // namespace gui } // namespace yaze diff --git a/src/gui/input.h b/src/gui/input.h index f99c2884..c5704258 100644 --- a/src/gui/input.h +++ b/src/gui/input.h @@ -13,7 +13,7 @@ namespace gui { IMGUI_API bool InputHex(const char* label, int* data); IMGUI_API bool InputHexShort(const char* label, int* data); -} // namespace Gui +} // namespace gui } // namespace yaze #endif \ No newline at end of file From 4d90f21e9e59bb1aff5875b7c9ed2caa9cac98c0 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:39:26 -0400 Subject: [PATCH 02/24] chore: Remove OpenGL flag from SDL_Window * Was causing a bug with surface creation on macOS. --- src/app/core/controller.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 4930d166..9994226f 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -156,7 +156,7 @@ absl::Status Controller::CreateWindow() { SDL_WINDOWPOS_UNDEFINED, // initial y position 1200, // width, in pixels 800, // height, in pixels - SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL), + SDL_WINDOW_RESIZABLE), sdl_deleter()); if (window_ == nullptr) { return absl::InternalError( From ebf6666ef608d34831a98a187a8f057b55824be2 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:40:21 -0400 Subject: [PATCH 03/24] chore: Remove Canvas::Update --- src/app/editor/dungeon_editor.cc | 5 +- src/gui/canvas.cc | 83 -------------------------------- src/gui/canvas.h | 2 - 3 files changed, 4 insertions(+), 86 deletions(-) diff --git a/src/app/editor/dungeon_editor.cc b/src/app/editor/dungeon_editor.cc index 43b0230c..a8700ad6 100644 --- a/src/app/editor/dungeon_editor.cc +++ b/src/app/editor/dungeon_editor.cc @@ -8,7 +8,10 @@ namespace editor { void DungeonEditor::Update() { DrawToolset(); - canvas_.Update(); + canvas_.DrawBackground(); + canvas_.UpdateContext(); + canvas_.DrawGrid(); + canvas_.DrawOverlay(); } void DungeonEditor::DrawToolset() { diff --git a/src/gui/canvas.cc b/src/gui/canvas.cc index 92062803..c7b237e1 100644 --- a/src/gui/canvas.cc +++ b/src/gui/canvas.cc @@ -8,89 +8,6 @@ namespace yaze { namespace gui { -void Canvas::Update() { - ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); - if (!custom_canvas_size_) canvas_sz_ = ImGui::GetContentRegionAvail(); - - auto canvas_p1 = - ImVec2(canvas_p0.x + canvas_sz_.x, canvas_p0.y + canvas_sz_.y); - - // Draw border and background color - const ImGuiIO &io = ImGui::GetIO(); - ImDrawList *draw_list = ImGui::GetWindowDrawList(); - draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255)); - draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255)); - - // This will catch our interactions - ImGui::InvisibleButton( - "canvas", canvas_sz_, - ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); - const bool is_hovered = ImGui::IsItemHovered(); // Hovered - const bool is_active = ImGui::IsItemActive(); // Held - const ImVec2 origin(canvas_p0.x + scrolling_.x, - canvas_p0.y + scrolling_.y); // Lock scrolled origin - const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x, - io.MousePos.y - origin.y); - - // Add first and second point - if (is_hovered && !dragging_select_ && - ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { - points_.push_back(mouse_pos_in_canvas); - points_.push_back(mouse_pos_in_canvas); - dragging_select_ = true; - } - if (dragging_select_) { - points_.back() = mouse_pos_in_canvas; - if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) dragging_select_ = false; - } - - // Pan (we use a zero mouse threshold when there's no context menu) - const float mouse_threshold_for_pan = enable_context_menu_ ? -1.0f : 0.0f; - if (is_active && - ImGui::IsMouseDragging(ImGuiMouseButton_Right, mouse_threshold_for_pan)) { - scrolling_.x += io.MouseDelta.x; - scrolling_.y += io.MouseDelta.y; - } - - // Context menu (under default mouse threshold) - ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right); - if (enable_context_menu_ && drag_delta.x == 0.0f && drag_delta.y == 0.0f) - ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); - if (ImGui::BeginPopup("context")) { - if (dragging_select_) points_.resize(points_.size() - 2); - dragging_select_ = false; - if (ImGui::MenuItem("Remove all", nullptr, false, points_.Size > 0)) { - points_.clear(); - } - ImGui::EndPopup(); - } - - // Draw grid + all lines in the canvas - draw_list->PushClipRect(canvas_p0, canvas_p1, true); - if (enable_grid_) { - const float GRID_STEP = 64.0f; - for (float x = fmodf(scrolling_.x, GRID_STEP); x < canvas_sz_.x; - x += GRID_STEP) - draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y), - ImVec2(canvas_p0.x + x, canvas_p1.y), - IM_COL32(200, 200, 200, 40)); - for (float y = fmodf(scrolling_.y, GRID_STEP); y < canvas_sz_.y; - y += GRID_STEP) - draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y), - ImVec2(canvas_p1.x, canvas_p0.y + y), - IM_COL32(200, 200, 200, 40)); - } - - for (int n = 0; n < points_.Size; n += 2) { - draw_list->AddRect( - ImVec2(origin.x + points_[n].x, origin.y + points_[n].y), - ImVec2(origin.x + points_[n + 1].x, origin.y + points_[n + 1].y), - IM_COL32(255, 255, 255, 255), 1.0f); - } - - draw_list->PopClipRect(); -} - void Canvas::DrawBackground(ImVec2 canvas_size) { canvas_p0_ = ImGui::GetCursorScreenPos(); if (!custom_canvas_size_) canvas_sz_ = ImGui::GetContentRegionAvail(); diff --git a/src/gui/canvas.h b/src/gui/canvas.h index 31b09714..dda7e970 100644 --- a/src/gui/canvas.h +++ b/src/gui/canvas.h @@ -15,8 +15,6 @@ class Canvas { Canvas(ImVec2 canvas_size) : custom_canvas_size_(true), canvas_sz_(canvas_size) {} - void Update(); - void DrawBackground(ImVec2 canvas_size = ImVec2(0, 0)); void UpdateContext(); void DrawGrid(float grid_step = 64.0f); From c86a7d0f01828ad680380be7eeaad3870cc7e4a2 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:40:46 -0400 Subject: [PATCH 04/24] chore: Remove unused OW functions --- src/app/zelda3/overworld.cc | 2 +- src/app/zelda3/overworld_map.cc | 132 +++++--------------------------- src/app/zelda3/overworld_map.h | 15 +--- 3 files changed, 23 insertions(+), 126 deletions(-) diff --git a/src/app/zelda3/overworld.cc b/src/app/zelda3/overworld.cc index 6cad4655..61ee7faf 100644 --- a/src/app/zelda3/overworld.cc +++ b/src/app/zelda3/overworld.cc @@ -26,7 +26,7 @@ absl::Status Overworld::Load(ROM &rom, uchar *ow_blockset) { auto size = tiles16.size(); for (int i = 0; i < core::kNumOverworldMaps; ++i) { auto map_status = - overworld_maps_[i].BuildMapV2(size, game_state_, map_parent_); + overworld_maps_[i].BuildMap(size, game_state_, map_parent_); if (!map_status.ok()) { return map_status; } diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld_map.cc index 3fe99d03..b57475de 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld_map.cc @@ -102,55 +102,8 @@ void OverworldMap::LoadAreaInfo() { } } -void OverworldMap::BuildMap(int count, int game_state, uchar* map_parent, - uchar* ow_blockset, OWMapTiles& map_tiles) { - if (large_map_) { - parent_ = map_parent[index_]; - if (parent_ != index_ && !initialized_) { - if (index_ >= 0x80 && index_ <= 0x8A && index_ != 0x88) { - area_graphics_ = rom_[core::overworldSpecialGFXGroup + (parent_ - 128)]; - area_palette_ = rom_[core::overworldSpecialPALGroup + 1]; - } else if (index_ == 0x88) { - area_graphics_ = 81; - area_palette_ = 0; - } else { - area_graphics_ = rom_[core::mapGfx + parent_]; - area_palette_ = rom_[core::overworldMapPalette + parent_]; - } - - initialized_ = true; - } - } - - if (!BuildTileset(game_state).ok()) { - std::cout << "BuildTileset failed" << std::endl; - } - BuildTiles16Gfx(count, ow_blockset); // build on GFX.mapgfx16Ptr - - // int world = 0; - // if (index_ < 64) { - // map_tiles_ = map_tiles.light_world; - // } else if (index_ < 128 && index_ >= 64) { - // map_tiles_ = map_tiles.dark_world; - // world = 1; - // } else { - // map_tiles_ = map_tiles.special_world; - // world = 2; - // } - - // int superY = ((index_ - (world * 64)) / 8); - // int superX = index_ - (world * 64) - (superY * 8); - // for (int y = 0; y < 32; y++) { - // for (int x = 0; x < 32; x++) { - // auto xt = x + (superX * 32); - // auto yt = y + (superY * 32); - // CopyTile8bpp16((x * 16), (y * 16), map_tiles_[xt][yt], ow_blockset); - // } - // } -} - -absl::Status OverworldMap::BuildMapV2(int count, int game_state, - uchar* map_parent) { +absl::Status OverworldMap::BuildMap(int count, int game_state, + uchar* map_parent) { if (large_map_) { parent_ = map_parent[index_]; if (parent_ != index_ && !initialized_) { @@ -174,12 +127,25 @@ absl::Status OverworldMap::BuildMapV2(int count, int game_state, return tileset_status; } + // int world = 0; // if (index_ < 64) { - // world_ = 0; + // map_tiles_ = map_tiles.light_world; // } else if (index_ < 128 && index_ >= 64) { - // world_ = 1; + // map_tiles_ = map_tiles.dark_world; + // world = 1; // } else { - // world_ = 2; + // map_tiles_ = map_tiles.special_world; + // world = 2; + // } + + // int superY = ((index_ - (world * 64)) / 8); + // int superX = index_ - (world * 64) - (superY * 8); + // for (int y = 0; y < 32; y++) { + // for (int x = 0; x < 32; x++) { + // auto xt = x + (superX * 32); + // auto yt = y + (superY * 32); + // CopyTile8bpp16((x * 16), (y * 16), map_tiles_[xt][yt], ow_blockset); + // } // } return absl::OkStatus(); @@ -246,40 +212,7 @@ absl::Status OverworldMap::BuildTileset(int game_state) { return absl::OkStatus(); } -void OverworldMap::BuildTiles16Gfx(int count, uchar* ow_blockset) { - auto gfx_tile16_data = ow_blockset; - auto gfx_tile8_data = nullptr; // rom_.GetMasterGraphicsBin(); - - int offsets[] = {0, 8, 1024, 1032}; - auto yy = 0; - auto xx = 0; - - // number of tiles16 3748? - for (auto i = 0; i < count; i++) { - // 8x8 tile draw - // gfx8 = 4bpp so everyting is /2F - auto tiles = tiles16_[i]; - - for (auto tile = 0; tile < 4; tile++) { - gfx::TileInfo info = tiles16_[i].tiles_info[tile]; - int offset = offsets[tile]; - - for (auto y = 0; y < 8; y++) { - for (auto x = 0; x < 4; x++) { - CopyTile(x, y, xx, yy, offset, info, gfx_tile16_data, gfx_tile8_data); - } - } - } - - xx += 16; - if (xx >= 128) { - yy += 2048; - xx = 0; - } - } -} - -absl::Status OverworldMap::BuildTiles16GfxV2(int count) { +absl::Status OverworldMap::BuildTiles16Gfx(int count) { auto gfx_tile8_data = nullptr; // rom_.GetMasterGraphicsBin(); int offsets[] = {0, 8, 1024, 1032}; @@ -354,33 +287,6 @@ void OverworldMap::CopyTile8bpp16(int x, int y, int tile, uchar* ow_blockset) { } } -// EXPERIMENTAL ---------------------------------------------------------------- - -// map,current -void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset, - gfx::TileInfo tile, uchar* gfx16Pointer, - uchar* gfx8Pointer) { - int mx = x; - int my = y; - uchar r = 0; - - if (tile.horizontal_mirror_ != 0) { - mx = 3 - x; - r = 1; - } - - if (tile.vertical_mirror_ != 0) { - my = 7 - y; - } - - int tx = ((tile.id_ / 16) * 512) + ((tile.id_ - ((tile.id_ / 16) * 16)) * 4); - auto index = xx + (yy * 512) + offset + (mx * 2) + (my * 512); - auto pixel = gfx8Pointer[tx + (y * 64) + x]; - - gfx16Pointer[index + r ^ 1] = (uchar)((pixel & 0x0F) + tile.palette_ * 16); - gfx16Pointer[index + r] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16); -} - } // namespace zelda3 } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/zelda3/overworld_map.h b/src/app/zelda3/overworld_map.h index 6019f8ae..dd5cdddb 100644 --- a/src/app/zelda3/overworld_map.h +++ b/src/app/zelda3/overworld_map.h @@ -24,10 +24,7 @@ class OverworldMap { public: OverworldMap(int index, ROM& rom, const std::vector& tiles16); - void BuildMap(int count, int game_state, uchar* map_parent, - uchar* ow_blockset, OWMapTiles& map_tiles); - - absl::Status BuildMapV2(int count, int game_state, uchar* map_parent); + absl::Status BuildMap(int count, int game_state, uchar* map_parent); auto GetBitmap() { return bitmap_; } auto GetCurrentGraphicsSet() { return current_graphics_sheet_set; } @@ -36,21 +33,15 @@ class OverworldMap { private: void LoadAreaInfo(); - void BuildTiles16Gfx(int count, uchar* ow_blockset); absl::Status BuildTileset(int game_state); - absl::Status BuildTiles16GfxV2(int count); + absl::Status BuildTiles16Gfx(int count); + // TODO: Find the SDL_Surface way to do this. void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile, uchar* gfx16Pointer, uchar* gfx8Pointer); - void CopyTile8bpp16(int x, int y, int tile, uchar* ow_blockset); - void CopyTileToMap(int x, int y, int xx, int yy, int offset, - gfx::TileInfo tile, uchar* gfx16Pointer, - uchar* gfx8Pointer); - void CopyTile8bpp16From8(int xP, int yP, int tileID, uchar* destbmpPtr); - int parent_ = 0; int index_ = 0; int world_ = 0; From 33ac97fb56d012f3be0cb63c85b3f1de183b6ae3 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:40:57 -0400 Subject: [PATCH 05/24] chore: cleanup editors --- src/app/editor/master_editor.cc | 10 +++++----- src/app/editor/overworld_editor.h | 5 ++++- src/app/editor/screen_editor.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index 871c2d34..7c608e0a 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -188,12 +188,12 @@ void MasterEditor::DrawFileMenu() const { void MasterEditor::DrawEditMenu() { if (ImGui::BeginMenu("Edit")) { - MENU_ITEM2("Undo", "Ctrl+Z") {} - MENU_ITEM2("Redo", "Ctrl+Y") {} + MENU_ITEM2("Undo", "Ctrl+Z") { status_ = overworld_editor_.Undo(); } + MENU_ITEM2("Redo", "Ctrl+Y") { status_ = overworld_editor_.Redo(); } ImGui::Separator(); - MENU_ITEM2("Cut", "Ctrl+X") {} - MENU_ITEM2("Copy", "Ctrl+C") {} - MENU_ITEM2("Paste", "Ctrl+V") {} + MENU_ITEM2("Cut", "Ctrl+X") { status_ = overworld_editor_.Cut(); } + MENU_ITEM2("Copy", "Ctrl+C") { status_ = overworld_editor_.Copy(); } + MENU_ITEM2("Paste", "Ctrl+V") { status_ = overworld_editor_.Paste(); } ImGui::Separator(); MENU_ITEM2("Find", "Ctrl+F") {} ImGui::Separator(); diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index fe5f4407..a5259def 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -41,8 +41,11 @@ class OverworldEditor { public: void SetupROM(ROM &rom); absl::Status Update(); - absl::Status Undo() { return absl::UnimplementedError("Undo"); } + absl::Status Redo() { return absl::UnimplementedError("Redo"); } + absl::Status Cut() { return absl::UnimplementedError("Cut"); } + absl::Status Copy() { return absl::UnimplementedError("Copy"); } + absl::Status Paste() { return absl::UnimplementedError("Paste"); } private: absl::Status DrawToolset(); diff --git a/src/app/editor/screen_editor.h b/src/app/editor/screen_editor.h index 413e8d4b..a6a363e1 100644 --- a/src/app/editor/screen_editor.h +++ b/src/app/editor/screen_editor.h @@ -23,8 +23,8 @@ static int overworldCustomMosaicArray = 0x1301F0; class ScreenEditor { public: - void SetupROM(ROM &rom) { rom_ = rom; } ScreenEditor(); + void SetupROM(ROM &rom) { rom_ = rom; } void Update(); private: From 2bb72a602742e081fb954f0fb068a8b19db2970e Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:41:21 -0400 Subject: [PATCH 06/24] chore: update SDL gitmodule --- src/lib/SDL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/SDL b/src/lib/SDL index dd2e3182..198d62d8 160000 --- a/src/lib/SDL +++ b/src/lib/SDL @@ -1 +1 @@ -Subproject commit dd2e3182116c9b0e07a157adb0ef286a49708fda +Subproject commit 198d62d813f352a57dd4d70d0591dc873e25a59b From 21e79445674d20c0bd4b49066818931737dd3ab8 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 12:46:53 -0400 Subject: [PATCH 07/24] chore: disable unnecessary Asar cmake components --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 85fdf01d..431f63a5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,11 @@ set( # Asar Assembly --------------------------------------------------------------- add_subdirectory(lib/asar/src) +set(ASAR_GEN_EXE OFF) +set(ASAR_GEN_DLL ON) +set(ASAR_GEN_LIB OFF) +set(ASAR_GEN_EXE_TEST OFF) +set(ASAR_GEN_DLL_TEST OFF) # yaze source files ----------------------------------------------------------- set( From 1f6ce1123c7a4e4c5e9ff61395e7300d0659c9d2 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:01:39 -0400 Subject: [PATCH 08/24] chore: link cmake dl libs --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 431f63a5..352c51bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -142,7 +142,8 @@ target_link_libraries( ${SDL_TARGETS} ${PNG_LIBRARIES} ${GLEW_LIBRARIES} - ${OPENGL_LIBRARIES} + ${OPENGL_LIBRARIES} + ${CMAKE_DL_LIBS} ImGui ) From 10668ee2e5f4d63c21a75b57a7520bf94e425ac8 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:06:11 -0400 Subject: [PATCH 09/24] docs: windows developer guide --- docs/dev-setup-windows.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/dev-setup-windows.md diff --git a/docs/dev-setup-windows.md b/docs/dev-setup-windows.md new file mode 100644 index 00000000..8688b3f9 --- /dev/null +++ b/docs/dev-setup-windows.md @@ -0,0 +1,17 @@ + +For VSCode users, use the following CMake extensions with MinGW-w64 + +https://marketplace.visualstudio.com/items?itemName=twxs.cmake +https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools + +https://www.msys2.org/ + +Add to environment variables `C:\msys64\mingw64\bin` + +Install the following packages using `pacman -S ` + +`mingw-w64-x86_64-gcc` +`mingw-w64-x86_64-gcc-libs` +`mingw-w64-x86_64-cmake` +`mingw-w64-x86_64-glew` +`mingw-w64-x86_64-lib-png` \ No newline at end of file From fb209223fe817e49088d1ea1888858f30c5011e3 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:08:55 -0400 Subject: [PATCH 10/24] chore: include asar path in test cmakelists --- test/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 66023f68..e3226d8a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,6 +20,7 @@ add_executable( ../src/app/gfx/snes_tile.cc ../src/app/gfx/snes_palette.cc ../src/app/core/common.cc + ../src/lib/asar/src/asar-dll-bindings/c/asardll.c ) target_include_directories( @@ -27,6 +28,7 @@ target_include_directories( ../src/lib/ ../src/ ${SDL_INCLUDE_DIRS} + ../src/lib/asar/src/asar-dll-bindings/c ) target_link_libraries( From 6c08ce8078a6305b50444a7a35f84c221396529f Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:18:31 -0400 Subject: [PATCH 11/24] chore: link cmake dl libs with test --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e3226d8a..e07853dd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -46,6 +46,7 @@ target_link_libraries( absl::raw_logging_internal SDL2::SDL2 ${OPENGL_LIBRARIES} + ${CMAKE_DL_LIBS} asar-static gmock_main gmock From 0d72cfcaddd74f98b43e0537b3b6fddca1ca92d7 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:21:52 -0400 Subject: [PATCH 12/24] chore: move absl_targets cmake def up a level --- CMakeLists.txt | 15 +++++++++++++++ src/CMakeLists.txt | 16 ---------------- test/CMakeLists.txt | 17 +++-------------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 319d028e..60a96e32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,21 @@ set(ABSL_PROPAGATE_CXX_STD ON) set(ABSL_CXX_STANDARD 17) set(ABSL_USE_GOOGLETEST_HEAD ON) set(ABSL_ENABLE_INSTALL ON) +set( + ABSL_TARGETS + absl::strings + absl::flags + absl::status + absl::statusor + absl::examine_stack + absl::stacktrace + absl::base + absl::config + absl::core_headers + absl::raw_logging_internal + absl::failure_signal_handler + absl::flat_hash_map +) # Video Libraries ------------------------------------------------------------- find_package(PNG REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 352c51bd..bd7b2ee1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,22 +113,6 @@ target_include_directories( lib/asar/src/asar-dll-bindings/c ) -set( - ABSL_TARGETS - absl::strings - absl::flags - absl::status - absl::statusor - absl::examine_stack - absl::stacktrace - absl::base - absl::config - absl::core_headers - absl::raw_logging_internal - absl::failure_signal_handler - absl::flat_hash_map -) - set(SDL_TARGETS SDL2::SDL2) if(WIN32 OR MINGW) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e07853dd..0b83417e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,29 +25,18 @@ add_executable( target_include_directories( yaze_test PUBLIC - ../src/lib/ ../src/ - ${SDL_INCLUDE_DIRS} + ../src/lib/ ../src/lib/asar/src/asar-dll-bindings/c + ${SDL_INCLUDE_DIRS} ) target_link_libraries( yaze_test - absl::strings - absl::flags - absl::status - absl::statusor - absl::failure_signal_handler - absl::examine_stack - absl::stacktrace - absl::base - absl::config - absl::core_headers - absl::raw_logging_internal SDL2::SDL2 + ${ABSL_TARGETS} ${OPENGL_LIBRARIES} ${CMAKE_DL_LIBS} - asar-static gmock_main gmock gtest_main From b510ad3fc662b300fd7a0c5ccd3d451163c15ba3 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:25:34 -0400 Subject: [PATCH 13/24] feat: add initial hook parameter with default val * untested --- src/app/asm/script.cc | 19 +++++++++++++++---- src/app/asm/script.h | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/app/asm/script.cc b/src/app/asm/script.cc index 6203353f..e65c94c6 100644 --- a/src/app/asm/script.cc +++ b/src/app/asm/script.cc @@ -76,7 +76,8 @@ absl::Status Script::ApplyPatchToROM(ROM &rom) { } absl::Status Script::GenerateMosaicChangeAssembly( - ROM &rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset) { + ROM &rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset, + int hook_offset) { std::fstream file("assets/asm/mosaic_change.asm", std::ios::out | std::ios::in); if (!file.is_open()) { @@ -89,9 +90,19 @@ absl::Status Script::GenerateMosaicChangeAssembly( file.close(); auto assembly_string = assembly.str(); - if (!string_replace(assembly_string, "", kMosaicChangeOffset)) { - return absl::InternalError( - "Mosaic template did not have proper `` to replace."); + + if (!hook_offset) { + // TODO: TESTME + if (!string_replace(assembly_string, "", + absl::StrFormat("$%06x", hook_offset))) { + return absl::InternalError( + "Mosaic template did not have proper `` to replace."); + } + } else { + if (!string_replace(assembly_string, "", kMosaicChangeOffset)) { + return absl::InternalError( + "Mosaic template did not have proper `` to replace."); + } } if (!string_replace( diff --git a/src/app/asm/script.h b/src/app/asm/script.h index e5edcfe9..c0eb30ac 100644 --- a/src/app/asm/script.h +++ b/src/app/asm/script.h @@ -28,7 +28,8 @@ class Script { Script() { asar_init_with_dll_path("assets/libasar.dll"); } absl::Status GenerateMosaicChangeAssembly( - ROM& rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset); + ROM& rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset, + int hook_offset = 0); private: absl::Status ApplyPatchToROM(ROM& rom); From 713edac333530e728874ded9890c65e3f965f1de Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:46:44 -0400 Subject: [PATCH 14/24] chore: add error checking to ApplyPatchToROM --- src/app/asm/script.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/asm/script.cc b/src/app/asm/script.cc index e65c94c6..2affd9b1 100644 --- a/src/app/asm/script.cc +++ b/src/app/asm/script.cc @@ -64,6 +64,10 @@ std::string GenerateBytePool(char mosaic_tiles[core::kNumOverworldMaps]) { } absl::Status Script::ApplyPatchToROM(ROM &rom) { + if (patch_contents_.empty() || patch_filename_.empty()) { + return absl::InvalidArgumentError("No patch loaded!"); + } + char *data = (char *)rom.data(); int size = rom.GetSize(); int count = 0; From 513b2d1034bd10446a23f73847363d97f20f7b21 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:46:58 -0400 Subject: [PATCH 15/24] feat: Create virtual class for mock testing --- src/app/asm/script.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/asm/script.h b/src/app/asm/script.h index c0eb30ac..61be3609 100644 --- a/src/app/asm/script.h +++ b/src/app/asm/script.h @@ -23,17 +23,21 @@ namespace snes_asm { const std::string kMosaicChangeOffset = "$02AADB"; constexpr int kSNESToPCOffset = 0x138000; -class Script { +class ScriptTemplate { + public: + virtual absl::Status ApplyPatchToROM(ROM& rom) = 0; +}; + +class Script : public ScriptTemplate { public: Script() { asar_init_with_dll_path("assets/libasar.dll"); } + absl::Status ApplyPatchToROM(ROM& rom) override; absl::Status GenerateMosaicChangeAssembly( ROM& rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset, int hook_offset = 0); private: - absl::Status ApplyPatchToROM(ROM& rom); - int64_t patch_size_; std::string patch_filename_; std::string patch_contents_; From 1db18b1d2ad623fde14ce76a3c54655c229e960b Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:47:16 -0400 Subject: [PATCH 16/24] test: add asm_test for snes_asm::Script --- test/CMakeLists.txt | 5 ++++- test/asm_test.cc | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/asm_test.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 66023f68..76c7c061 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,18 +14,21 @@ add_executable( yaze_test yaze_test.cc rom_test.cc + asm_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 ../src/app/core/common.cc + ../src/lib/asar/src/asar-dll-bindings/c/asardll.c ) target_include_directories( yaze_test PUBLIC - ../src/lib/ ../src/ + ../src/lib/ + ../src/lib/asar/src/asar-dll-bindings/c ${SDL_INCLUDE_DIRS} ) diff --git a/test/asm_test.cc b/test/asm_test.cc new file mode 100644 index 00000000..cff67106 --- /dev/null +++ b/test/asm_test.cc @@ -0,0 +1,48 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" +#include "app/asm/script.h" +#include "app/core/constants.h" +#include "app/rom.h" + +namespace yaze_test { +namespace asm_test { + +using yaze::app::ROM; +using yaze::app::snes_asm::Script; + +using ::testing::_; +using ::testing::ElementsAreArray; +using ::testing::Return; +using ::testing::TypedEq; + +class MockScript : public Script { + public: + MOCK_METHOD(absl::Status, ApplyPatchToROM, (ROM & rom)); +}; + +TEST(ASMTest, NoPatchLoadedError) { + ROM rom; + MockScript script; + EXPECT_CALL(script, ApplyPatchToROM(_)) + .WillOnce(Return(absl::InvalidArgumentError("No patch loaded!"))); + + EXPECT_THAT(script.ApplyPatchToROM(rom), + absl::InvalidArgumentError("No patch loaded!")); +} + +TEST(ASMTest, ApplyPatchOk) {} + +} // namespace asm_test +} // namespace yaze_test \ No newline at end of file From 1a6c82ec89a1d06cdf7109b5c0433fd173bcb00b Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:51:04 -0400 Subject: [PATCH 17/24] fix: save patch contents when generated --- src/app/asm/script.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/asm/script.cc b/src/app/asm/script.cc index 2affd9b1..ee0687e0 100644 --- a/src/app/asm/script.cc +++ b/src/app/asm/script.cc @@ -117,6 +117,7 @@ absl::Status Script::GenerateMosaicChangeAssembly( } assembly_string += GenerateBytePool(mosaic_tiles); + patch_contents_ = assembly_string; patch_filename_ = "assets/asm/mosaic_change_generated.asm"; std::ofstream new_file(patch_filename_, std::ios::out); if (new_file.is_open()) { From 395ec4887ccf6077ed71a9ecf4abdb3103d90d1c Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 14:45:37 -0400 Subject: [PATCH 18/24] test: add mosaic generation sanity test --- test/asm_test.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/asm_test.cc b/test/asm_test.cc index cff67106..6ce8cfcc 100644 --- a/test/asm_test.cc +++ b/test/asm_test.cc @@ -24,14 +24,34 @@ using yaze::app::snes_asm::Script; using ::testing::_; using ::testing::ElementsAreArray; +using ::testing::Eq; using ::testing::Return; -using ::testing::TypedEq; class MockScript : public Script { public: MOCK_METHOD(absl::Status, ApplyPatchToROM, (ROM & rom)); + MOCK_METHOD(absl::Status, GenerateMosaicChangeAssembly, + (ROM & rom, char mosaic_tiles[yaze::app::core::kNumOverworldMaps], + int routine_offset, int hook_offset)); }; +TEST(ASMTest, ApplyMosaicChangePatchOk) { + ROM rom; + MockScript script; + char mosaic_tiles[yaze::app::core::kNumOverworldMaps]; + + EXPECT_CALL(script, GenerateMosaicChangeAssembly(_, Eq(mosaic_tiles), + Eq(0x1301D0 + 0x138000), 0)) + .WillOnce(Return(absl::OkStatus())); + + EXPECT_CALL(script, ApplyPatchToROM(_)).WillOnce(Return(absl::OkStatus())); + + EXPECT_THAT(script.GenerateMosaicChangeAssembly(rom, mosaic_tiles, + 0x1301D0 + 0x138000, 0), + absl::OkStatus()); + EXPECT_THAT(script.ApplyPatchToROM(rom), absl::OkStatus()); +} + TEST(ASMTest, NoPatchLoadedError) { ROM rom; MockScript script; @@ -42,7 +62,5 @@ TEST(ASMTest, NoPatchLoadedError) { absl::InvalidArgumentError("No patch loaded!")); } -TEST(ASMTest, ApplyPatchOk) {} - } // namespace asm_test } // namespace yaze_test \ No newline at end of file From c6b6eb74bb22846981a865a99435c9f067ca3b96 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 7 Aug 2022 14:46:26 -0400 Subject: [PATCH 19/24] chore: add virtual method for mock test --- src/app/asm/script.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/asm/script.h b/src/app/asm/script.h index 61be3609..4b8e4a7c 100644 --- a/src/app/asm/script.h +++ b/src/app/asm/script.h @@ -26,6 +26,9 @@ constexpr int kSNESToPCOffset = 0x138000; class ScriptTemplate { public: virtual absl::Status ApplyPatchToROM(ROM& rom) = 0; + virtual absl::Status GenerateMosaicChangeAssembly( + ROM& rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset, + int hook_offset = 0) = 0; }; class Script : public ScriptTemplate { @@ -35,7 +38,7 @@ class Script : public ScriptTemplate { absl::Status ApplyPatchToROM(ROM& rom) override; absl::Status GenerateMosaicChangeAssembly( ROM& rom, char mosaic_tiles[core::kNumOverworldMaps], int routine_offset, - int hook_offset = 0); + int hook_offset = 0) override; private: int64_t patch_size_; From fb4dc48add6939a9eb63c177f55c169f31154648 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Mon, 8 Aug 2022 08:31:02 -0400 Subject: [PATCH 20/24] chore: make window dimensions a constant --- src/app/core/constants.h | 7 +++++++ src/app/core/controller.cc | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 54eba4c7..9cb5e80f 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -39,6 +39,13 @@ namespace yaze { namespace app { namespace core { +//=========================================================================================== +// Window Variables +//=========================================================================================== + +constexpr int kScreenWidth = 1200; +constexpr int kScreenHeight = 800; + //=========================================================================================== // 65816 LanguageDefinition //=========================================================================================== diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 4930d166..cd7fcf11 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -154,8 +154,8 @@ absl::Status Controller::CreateWindow() { SDL_CreateWindow("Yet Another Zelda3 Editor", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position - 1200, // width, in pixels - 800, // height, in pixels + kScreenWidth, // width, in pixels + kScreenHeight, // height, in pixels SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL), sdl_deleter()); if (window_ == nullptr) { From 4c2786be0eddb513599bdc09256087875f01be65 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Mon, 8 Aug 2022 08:35:05 -0400 Subject: [PATCH 21/24] chore: cleanup garbage in constants --- src/app/core/constants.h | 102 +++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 9cb5e80f..df2d8256 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -26,8 +26,8 @@ #define MENU_ITEM2(w, v) if (ImGui::MenuItem(w, v)) #define CHECK_STATUS(w) \ - if (!w.ok()) { \ - return w; \ + if (!w.ok()) { \ + return w; \ } using ushort = unsigned short; @@ -39,16 +39,16 @@ namespace yaze { namespace app { namespace core { -//=========================================================================================== -// Window Variables -//=========================================================================================== +// ============================================================================ +// Window Variables +// ============================================================================ constexpr int kScreenWidth = 1200; constexpr int kScreenHeight = 800; -//=========================================================================================== +// ============================================================================ // 65816 LanguageDefinition -//=========================================================================================== +// ============================================================================ static const char *const kKeywords[] = { "ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE", @@ -73,9 +73,9 @@ static const char *const kIdentifiers[] = { "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper"}; -//=========================================================================================== +// ============================================================================ // Magic numbers -//=========================================================================================== +// ============================================================================ /// Bit set for object priority constexpr ushort TilePriorityBit = 0x2000; @@ -103,9 +103,9 @@ constexpr int NumberOfMap32 = Map32PerScreen * kNumOverworldMaps; constexpr int NumberOfOWSprites = 352; constexpr int NumberOfColors = 3143; -// =========================================================================================== -// gfx -// =========================================================================================== +// ============================================================================ +// Game Graphics +// ============================================================================ constexpr int tile_address = 0x1B52; // JP = Same constexpr int tile_address_floor = 0x1B5A; // JP = Same @@ -114,8 +114,9 @@ constexpr int subtype2_tiles = 0x83F0; // JP = Same constexpr int subtype3_tiles = 0x84F0; // JP = Same constexpr int gfx_animated_pointer = 0x10275; // JP 0x10624 //long pointer constexpr int overworldgfxGroups2 = 0x6073; // 0x60B3 -constexpr int gfx_1_pointer = - 0x6790; // 2byte pointer bank 00 pc -> 0x4320 CF80 ; 004F80 + +// 2 byte pointer bank 00 pc -> 0x4320 +constexpr int gfx_1_pointer = 0x6790; // CF80 ; 004F80 constexpr int gfx_2_pointer = 0x6795; // D05F ; 00505F constexpr int gfx_3_pointer = 0x679A; // D13E ; 00513E constexpr int hud_palettes = 0xDD660; @@ -125,9 +126,9 @@ constexpr int kTilesheetWidth = 128; constexpr int kTilesheetHeight = 32; constexpr int kTilesheetDepth = 8; -// =========================================================================================== +// ============================================================================ // Overworld Related Variables -// =========================================================================================== +// ============================================================================ constexpr int compressedAllMap32PointersHigh = 0x1794D; constexpr int compressedAllMap32PointersLow = 0x17B2D; @@ -164,7 +165,6 @@ constexpr int overlayPointersBank = 0x0E; constexpr int overworldTilesType = 0x71459; constexpr int overworldMessages = 0x3F51D; -// TODO: constexpr int overworldMusicBegining = 0x14303; constexpr int overworldMusicZelda = 0x14303 + 0x40; constexpr int overworldMusicMasterSword = 0x14303 + 0x80; @@ -174,10 +174,11 @@ constexpr int overworldMusicDW = 0x14403; constexpr int overworldEntranceAllowedTilesLeft = 0xDB8C1; constexpr int overworldEntranceAllowedTilesRight = 0xDB917; -constexpr int overworldMapSize = 0x12844; // 0x00 = small maps, 0x20 = large - // maps -constexpr int overworldMapSizeHighByte = - 0x12884; // 0x01 = small maps, 0x03 = large maps +// 0x00 = small maps, 0x20 = large maps +constexpr int overworldMapSize = 0x12844; + +// 0x01 = small maps, 0x03 = large maps +constexpr int overworldMapSizeHighByte = 0x12884; // relative to the WORLD + 0x200 per map // large map that are not == parent id = same position as their parent! @@ -191,9 +192,9 @@ constexpr int overworldTransitionPositionX = 0x12944; constexpr int overworldScreenSize = 0x1788D; -//=========================================================================================== +// ============================================================================ // Overworld Exits/Entrances Variables -//=========================================================================================== +// ============================================================================ constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences // 105C2 Ending maps // 105E2 Sprite Group Table for Ending @@ -233,9 +234,10 @@ constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91 constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3 constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94 -//=========================================================================================== +// ============================================================================ // Dungeon Related Variables -//=========================================================================================== +// ============================================================================ + // That could be turned into a pointer : constexpr int dungeons_palettes_groups = 0x75460; // JP 0x67DD0 constexpr int dungeons_main_bg_palette_pointers = 0xDEC4B; // JP Same @@ -282,7 +284,6 @@ constexpr int doorPointers = 0xF83C0; // doors constexpr int door_gfx_up = 0x4D9E; -// constexpr int door_gfx_down = 0x4E06; constexpr int door_gfx_cavexit_down = 0x4E06; constexpr int door_gfx_left = 0x4E66; @@ -300,14 +301,17 @@ constexpr int text_data2 = 0x75F40; constexpr int pointers_dictionaries = 0x74703; constexpr int characters_width = 0x74ADF; -//=========================================================================================== +// ============================================================================ // Dungeon Entrances Related Variables -//=========================================================================================== -constexpr int entrance_room = 0x14813; // 0x14577 //word value for each room +// ============================================================================ + +// 0x14577 word value for each room +constexpr int entrance_room = 0x14813; + // 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR constexpr int entrance_scrolledge = 0x1491D; // 0x14681 -constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 //2bytes each room -constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 //2bytes +constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 2 bytes each room +constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 2 bytes constexpr int entrance_yposition = 0x14F59; // 0x14CBD 2bytes constexpr int entrance_xposition = 0x15063; // 0x14DC7 2bytes constexpr int entrance_camerayposition = 0x1516D; // 0x14ED1 2bytes @@ -318,15 +322,17 @@ constexpr int entrance_blockset = 0x15381; // 0x150E5 1byte constexpr int entrance_floor = 0x15406; // 0x1516A 1byte constexpr int entrance_dungeon = 0x1548B; // 0x151EF 1byte (dungeon id) constexpr int entrance_door = 0x15510; // 0x15274 1byte -// 1 byte, ---b ---a b = bg2, a = need to check -_- + +// 1 byte, ---b ---a b = bg2, a = need to check constexpr int entrance_ladderbg = 0x15595; // 0x152F9 -constexpr int entrance_scrolling = 0x1561A; // 0x1537E //1byte --h- --v- +constexpr int entrance_scrolling = 0x1561A; // 0x1537E 1byte --h- --v- constexpr int entrance_scrollquadrant = 0x1569F; // 0x15403 1byte -constexpr int entrance_exit = 0x15724; // 0x15488 //2byte word +constexpr int entrance_exit = 0x15724; // 0x15488 2byte word constexpr int entrance_music = 0x1582E; // 0x15592 // word value for each room constexpr int startingentrance_room = 0x15B6E; // 0x158D2 + // 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR constexpr int startingentrance_scrolledge = 0x15B7C; // 0x158E0 constexpr int startingentrance_yscroll = 0x15BB4; // 0x14AA9 //2bytes each room @@ -342,7 +348,7 @@ constexpr int startingentrance_dungeon = 0x15C16; // 0x151EF 1byte (dungeon id) constexpr int startingentrance_door = 0x15C2B; // 0x15274 1byte -// 1 byte, ---b ---a b = bg2, a = need to check -_- +// 1 byte, ---b ---a b = bg2, a = need to check constexpr int startingentrance_ladderbg = 0x15C1D; // 0x152F9 // 1byte --h- --v- constexpr int startingentrance_scrolling = 0x15C24; // 0x1537E @@ -372,24 +378,23 @@ constexpr int dungeons_endrooms = 0x792D; constexpr int dungeons_bossrooms = 0x10954; // short value // Bed Related Values (Starting location) - constexpr int bedPositionX = 0x039A37; // short value constexpr int bedPositionY = 0x039A32; // short value // short value (on 2 different bytes) constexpr int bedPositionResetXLow = 0x02DE53; -constexpr int bedPositionResetXHigh = 0x02DE58; //^^^^^^ +constexpr int bedPositionResetXHigh = 0x02DE58; // short value (on 2 different bytes) constexpr int bedPositionResetYLow = 0x02DE5D; -constexpr int bedPositionResetYHigh = 0x02DE62; //^^^^^^ +constexpr int bedPositionResetYHigh = 0x02DE62; constexpr int bedSheetPositionX = 0x0480BD; // short value constexpr int bedSheetPositionY = 0x0480B8; // short value -//=========================================================================================== +// ============================================================================ // Gravestones related variables -//=========================================================================================== +// ============================================================================ constexpr int GravesYTilePos = 0x49968; // short (0x0F entries) constexpr int GravesXTilePos = 0x49986; // short (0x0F entries) @@ -403,9 +408,9 @@ constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries constexpr int GraveLinkSpecialHole = 0x46DD9; // short constexpr int GraveLinkSpecialStairs = 0x46DE0; // short -//=========================================================================================== +// ============================================================================ // Palettes Related Variables - This contain all the palettes of the game -//=========================================================================================== +// ============================================================================ constexpr int overworldPaletteMain = 0xDE6C8; constexpr int overworldPaletteAuxialiary = 0xDE86C; constexpr int overworldPaletteAnimated = 0xDE604; @@ -427,19 +432,23 @@ constexpr int hardcodedGrassLW = 0x5FEA9; constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F constexpr int hardcodedGrassSpecial = 0x75640; -//=========================================================================================== +// ============================================================================ // Dungeon Map Related Variables -//=========================================================================================== +// ============================================================================ + constexpr int dungeonMap_rooms_ptr = 0x57605; // 14 pointers of map data constexpr int dungeonMap_floors = 0x575D9; // 14 words values constexpr int dungeonMap_gfx_ptr = 0x57BE4; // 14 pointers of gfx data + // data start for floors/gfx MUST skip 575D9 to 57621 (pointers) constexpr int dungeonMap_datastart = 0x57039; + // IF Byte = 0xB9 dungeon maps are not expanded constexpr int dungeonMap_expCheck = 0x56652; constexpr int dungeonMap_tile16 = 0x57009; constexpr int dungeonMap_tile16Exp = 0x109010; + // 14 words values 0x000F = no boss constexpr int dungeonMap_bossrooms = 0x56807; constexpr int triforceVertices = 0x04FFD2; // group of 3, X, Y ,Z @@ -447,9 +456,10 @@ constexpr int TriforceFaces = 0x04FFE4; // group of 5 constexpr int crystalVertices = 0x04FF98; -//=========================================================================================== +// ============================================================================ // Names -//=========================================================================================== +// ============================================================================ + static const absl::string_view RoomEffect[] = {"Nothing", "Nothing", "Moving Floor", From 48ee66665690ab141107238f4ee62a158493788f Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Mon, 8 Aug 2022 15:16:20 -0400 Subject: [PATCH 22/24] chore: made ROM title offset a constant --- src/app/rom.cc | 6 +++++- src/app/rom.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/rom.cc b/src/app/rom.cc index c53f32c6..0369b4bd 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -576,6 +576,7 @@ absl::Status ROM::LoadFromFile(const absl::string_view& filename) { return absl::InternalError( absl::StrCat("Could not open ROM file: ", filename)); } + size_ = std::filesystem::file_size(filename); rom_data_.resize(size_); for (auto i = 0; i < size_; ++i) { @@ -583,9 +584,12 @@ absl::Status ROM::LoadFromFile(const absl::string_view& filename) { file.read(&byte_to_read, sizeof(char)); rom_data_[i] = byte_to_read; } + + // copy ROM title + memcpy(title, rom_data_.data() + kTitleStringOffset, kTitleStringLength); + file.close(); is_loaded_ = true; - memcpy(title, rom_data_.data() + 32704, 20); // copy ROM title return absl::OkStatus(); } diff --git a/src/app/rom.h b/src/app/rom.h index 9f95f8a2..c0976072 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -36,6 +36,8 @@ constexpr int kMaxLengthCompression = 1024; constexpr int kNintendoMode1 = 0; constexpr int kNintendoMode2 = 1; constexpr int kTile32Num = 4432; +constexpr int kTitleStringOffset = 0x7FC0; +constexpr int kTitleStringLength = 20; constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; From f59e3b46c295c3720d951f653c3cee5f137e291f Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:04:55 -0400 Subject: [PATCH 23/24] Move yaze main --- src/CMakeLists.txt | 2 +- src/{ => app}/yaze.cc | 4 +++- src/yaze.h | 12 ------------ 3 files changed, 4 insertions(+), 14 deletions(-) rename src/{ => app}/yaze.cc (92%) delete mode 100644 src/yaze.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd7b2ee1..502d057d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,7 +89,7 @@ set( add_executable( yaze - yaze.cc + app/yaze.cc app/rom.cc ${YAZE_APP_ASM_SRC} ${YAZE_APP_CORE_SRC} diff --git a/src/yaze.cc b/src/app/yaze.cc similarity index 92% rename from src/yaze.cc rename to src/app/yaze.cc index 5c780550..a6b7e20b 100644 --- a/src/yaze.cc +++ b/src/app/yaze.cc @@ -1,4 +1,6 @@ -#include "yaze.h" +#if defined(_WIN32) +#define main SDL_main +#endif #include "absl/debugging/failure_signal_handler.h" #include "absl/debugging/symbolize.h" diff --git a/src/yaze.h b/src/yaze.h deleted file mode 100644 index 2969582e..00000000 --- a/src/yaze.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef YAZE_H -#define YAZE_H - -#if defined(_WIN32) -#define main SDL_main -#endif - -#include "absl/debugging/failure_signal_handler.h" -#include "absl/debugging/symbolize.h" -#include "app/core/controller.h" - -#endif /* YAZE_H */ \ No newline at end of file From d2675ee59d3c1b992a72fa8b30b66dce00f7808b Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:05:09 -0400 Subject: [PATCH 24/24] update modules --- src/lib/ImGuiFileDialog | 2 +- src/lib/SDL | 2 +- src/lib/abseil-cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/ImGuiFileDialog b/src/lib/ImGuiFileDialog index 25780cf7..7654d521 160000 --- a/src/lib/ImGuiFileDialog +++ b/src/lib/ImGuiFileDialog @@ -1 +1 @@ -Subproject commit 25780cf76e9899c0f5a43d274ca0b0639ab7c9f6 +Subproject commit 7654d521db314c6605757cd8d19dca4f2179f952 diff --git a/src/lib/SDL b/src/lib/SDL index 198d62d8..0cc8dfdb 160000 --- a/src/lib/SDL +++ b/src/lib/SDL @@ -1 +1 @@ -Subproject commit 198d62d813f352a57dd4d70d0591dc873e25a59b +Subproject commit 0cc8dfdb58b60e1ffc285025b7f1ed884a378601 diff --git a/src/lib/abseil-cpp b/src/lib/abseil-cpp index 0c923304..59cba2b5 160000 --- a/src/lib/abseil-cpp +++ b/src/lib/abseil-cpp @@ -1 +1 @@ -Subproject commit 0c92330442d6b1be934e0407115c8084250ef347 +Subproject commit 59cba2b50dd689010f338c63db95ca164f195798