diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d4fa03c..7ed5d062 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,23 +35,23 @@ find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) # SDL2 ------------------------------------------------------------------------ -if (UNIX) - add_subdirectory(src/lib/SDL) -else() +# if (UNIX) +# add_subdirectory(src/lib/SDL) +# else() find_package(SDL2) -endif() -set(SDL2MIXER_OPUS OFF) -set(SDL2MIXER_FLAC OFF) -set(SDL2MIXER_MOD OFF) -set(SDL2MIXER_MIDI_FLUIDSYNTH OFF) -find_library(SDL_MIXER_LIBRARY - NAMES SDL_mixer - HINTS - ENV SDLMIXERDIR - ENV SDLDIR - PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} - ) -add_subdirectory(src/lib/SDL_mixer) +# endif() +# set(SDL2MIXER_OPUS OFF) +# set(SDL2MIXER_FLAC OFF) +# set(SDL2MIXER_MOD OFF) +# set(SDL2MIXER_MIDI_FLUIDSYNTH OFF) +# find_library(SDL_MIXER_LIBRARY +# NAMES SDL_mixer +# HINTS +# ENV SDLMIXERDIR +# ENV SDLDIR +# PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} +# ) +# add_subdirectory(src/lib/SDL_mixer) # Asar ------------------------------------------------------------------------ add_subdirectory(src/lib/asar/src) @@ -71,7 +71,7 @@ set(SNES_SPC_SOURCES "../src/lib/snes_spc/demo/demo_util.c" ) include_directories(src/lib/snes_spc/snes_spc) -ADD_LIBRARY(snes_spc STATIC ${SNES_SPC_SOURCES} src/app/spc700/spc700.def) +ADD_LIBRARY(snes_spc STATIC ${SNES_SPC_SOURCES} src/app/zelda3/music/spc700.def) # ImGui ----------------------------------------------------------------------- include(cmake/imgui.cmake) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d8ed1571..84aa80dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,22 +25,22 @@ set( set( YAZE_APP_ZELDA3_SRC - app/zelda3/inventory.cc app/zelda3/overworld_map.cc app/zelda3/overworld.cc - app/zelda3/title_screen.cc - app/zelda3/sprite.cc - app/zelda3/tracker.cc + app/zelda3/screen/inventory.cc + app/zelda3/screen/title_screen.cc + app/zelda3/sprite/sprite.cc + app/zelda3/music/tracker.cc app/zelda3/dungeon/room.cc ) set( YAZE_GUI_SRC - gui/canvas.cc - gui/input.cc - gui/style.cc - gui/widgets.cc - gui/color.cc + app/gui/canvas.cc + app/gui/input.cc + app/gui/style.cc + app/gui/widgets.cc + app/gui/color.cc ) # executable creation --------------------------------------------------------- diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index e5f3da2e..5ee1496a 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -12,8 +12,8 @@ #include "absl/status/status.h" #include "absl/strings/str_format.h" #include "app/editor/master_editor.h" -#include "gui/icons.h" -#include "gui/style.h" +#include "app/gui/icons.h" +#include "app/gui/style.h" namespace yaze { namespace app { diff --git a/src/app/core/controller.h b/src/app/core/controller.h index b3dec147..e74cc8f7 100644 --- a/src/app/core/controller.h +++ b/src/app/core/controller.h @@ -11,8 +11,8 @@ #include "absl/status/status.h" #include "app/editor/master_editor.h" -#include "gui/icons.h" -#include "gui/style.h" +#include "app/gui/icons.h" +#include "app/gui/style.h" int main(int argc, char **argv); diff --git a/src/app/editor/assembly_editor.cc b/src/app/editor/assembly_editor.cc index aacdcaaa..be0979d1 100644 --- a/src/app/editor/assembly_editor.cc +++ b/src/app/editor/assembly_editor.cc @@ -1,7 +1,7 @@ #include "assembly_editor.h" #include "core/constants.h" -#include "gui/widgets.h" +#include "app/gui/widgets.h" namespace yaze { namespace app { @@ -12,8 +12,8 @@ AssemblyEditor::AssemblyEditor() { text_editor_.SetPalette(TextEditor::GetDarkPalette()); } -void AssemblyEditor::Update() { - ImGui::Begin("Assembly Editor", &file_is_loaded_); +void AssemblyEditor::Update(bool &is_loaded) { + ImGui::Begin("Assembly Editor", &is_loaded); MENU_BAR() DrawFileMenu(); DrawEditMenu(); diff --git a/src/app/editor/assembly_editor.h b/src/app/editor/assembly_editor.h index 63195aa8..3b9d975b 100644 --- a/src/app/editor/assembly_editor.h +++ b/src/app/editor/assembly_editor.h @@ -16,7 +16,7 @@ class AssemblyEditor { public: AssemblyEditor(); - void Update(); + void Update(bool &is_loaded); void InlineUpdate(); void ChangeActiveFile(const std::string &); diff --git a/src/app/editor/dungeon_editor.cc b/src/app/editor/dungeon_editor.cc index d8a8c100..fafcee24 100644 --- a/src/app/editor/dungeon_editor.cc +++ b/src/app/editor/dungeon_editor.cc @@ -1,6 +1,6 @@ #include "dungeon_editor.h" -#include "gui/icons.h" +#include "app/gui/icons.h" namespace yaze { namespace app { diff --git a/src/app/editor/dungeon_editor.h b/src/app/editor/dungeon_editor.h index a0e98474..09257ebe 100644 --- a/src/app/editor/dungeon_editor.h +++ b/src/app/editor/dungeon_editor.h @@ -3,8 +3,8 @@ #include -#include "gui/canvas.h" -#include "gui/icons.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" #include "rom.h" #include "zelda3/dungeon/room.h" diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index a9f4f39b..be01d3ea 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -15,10 +15,10 @@ #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "gui/canvas.h" -#include "gui/icons.h" -#include "gui/input.h" -#include "gui/widgets.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/gui/input.h" +#include "app/gui/widgets.h" namespace yaze { namespace app { @@ -213,6 +213,7 @@ void MasterEditor::DrawViewMenu() { static bool show_asm_editor = false; static bool show_imgui_demo = false; static bool show_memory_viewer = false; + static bool show_palette_editor = false; if (show_imgui_metrics) { ImGui::ShowMetricsWindow(&show_imgui_metrics); @@ -228,7 +229,13 @@ void MasterEditor::DrawViewMenu() { } if (show_asm_editor) { - assembly_editor_.Update(); + assembly_editor_.Update(show_asm_editor); + } + + if (show_palette_editor) { + ImGui::Begin("Palette Editor", &show_palette_editor); + palette_editor_.Update(); + ImGui::End(); } if (show_imgui_style_editor) { @@ -263,6 +270,7 @@ void MasterEditor::DrawViewMenu() { if (ImGui::BeginMenu("View")) { ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor); ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor); + ImGui::MenuItem("Palette Editor", nullptr, &show_palette_editor); ImGui::MenuItem("Memory Viewer", nullptr, &show_memory_viewer); ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo); ImGui::Separator(); diff --git a/src/app/editor/master_editor.h b/src/app/editor/master_editor.h index 42a208f0..c929aeff 100644 --- a/src/app/editor/master_editor.h +++ b/src/app/editor/master_editor.h @@ -18,9 +18,9 @@ #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "gui/canvas.h" -#include "gui/icons.h" -#include "gui/input.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/gui/input.h" namespace yaze { namespace app { diff --git a/src/app/editor/music_editor.cc b/src/app/editor/music_editor.cc index 05d26678..2d8ecfa6 100644 --- a/src/app/editor/music_editor.cc +++ b/src/app/editor/music_editor.cc @@ -5,9 +5,9 @@ #include "absl/strings/str_format.h" #include "app/editor/assembly_editor.h" -#include "gui/canvas.h" -#include "gui/icons.h" -#include "gui/input.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/gui/input.h" #include "snes_spc/demo/demo_util.h" #include "snes_spc/demo/wave_writer.h" #include "snes_spc/snes_spc/spc.h" diff --git a/src/app/editor/music_editor.h b/src/app/editor/music_editor.h index a903fae3..cb50140a 100644 --- a/src/app/editor/music_editor.h +++ b/src/app/editor/music_editor.h @@ -6,11 +6,11 @@ #include "absl/strings/str_format.h" #include "app/editor/assembly_editor.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/gui/input.h" #include "app/rom.h" -#include "app/zelda3/tracker.h" -#include "gui/canvas.h" -#include "gui/icons.h" -#include "gui/input.h" +#include "app/zelda3/music/tracker.h" #include "snes_spc/demo/demo_util.h" #include "snes_spc/demo/wave_writer.h" #include "snes_spc/snes_spc/spc.h" diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index a2ad0fc5..22245993 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -15,8 +15,8 @@ #include "app/gfx/snes_tile.h" #include "app/rom.h" #include "app/zelda3/overworld.h" -#include "gui/canvas.h" -#include "gui/icons.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" namespace yaze { namespace app { @@ -196,9 +196,8 @@ void OverworldEditor::DrawOverworldCanvas() { if (!blockset_canvas_.Points().empty()) { int x = blockset_canvas_.Points().front().x / 32; int y = blockset_canvas_.Points().front().y / 32; - // std::cout << x << " " << y << std::endl; - current_tile16_ = x + (y * 8); - // std::cout << current_tile16_ << std::endl; + current_tile16_ = x + (y * 0x10); + if (ow_map_canvas_.DrawTilePainter(tile16_individual_[current_tile16_], 16)) { // Update the overworld map. @@ -326,12 +325,12 @@ absl::Status OverworldEditor::LoadGraphics() { for (int i = 0; i < 4096; i++) { // Create a new vector for the pixel data of the current tile Bytes tile_data; - for (int j = 0; j < 32 * 32; j++) tile_data.push_back(0x00); + for (int j = 0; j < 16 * 16; j++) tile_data.push_back(0x00); // Copy the pixel data for the current tile into the vector - for (int ty = 0; ty < 32; ty++) { - for (int tx = 0; tx < 32; tx++) { - int position = (tx + (ty * 0x20)); + for (int ty = 0; ty < 16; ty++) { + for (int tx = 0; tx < 16; tx++) { + int position = (tx + (ty * 0x10)); uchar value = tile16_data[i + tx + (ty * 0x80)]; tile_data[position] = value; } @@ -343,8 +342,7 @@ absl::Status OverworldEditor::LoadGraphics() { // Render the bitmaps of each tile. for (int id = 0; id < 4096; id++) { - gfx::Bitmap new_tile16; - tile16_individual_.emplace_back(new_tile16); + tile16_individual_.emplace_back(); tile16_individual_[id].Create(0x10, 0x10, 0x80, tile16_individual_data_[id]); tile16_individual_[id].ApplyPalette(palette_); diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index b55d26c1..e90cdae0 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -16,8 +16,8 @@ #include "app/gfx/snes_tile.h" #include "app/rom.h" #include "app/zelda3/overworld.h" -#include "gui/canvas.h" -#include "gui/icons.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" namespace yaze { namespace app { diff --git a/src/app/editor/palette_editor.cc b/src/app/editor/palette_editor.cc index 11d0bd80..f234d4ab 100644 --- a/src/app/editor/palette_editor.cc +++ b/src/app/editor/palette_editor.cc @@ -4,8 +4,8 @@ #include "absl/status/status.h" #include "app/gfx/snes_palette.h" -#include "gui/canvas.h" -#include "gui/icons.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; @@ -41,17 +41,9 @@ using namespace ImGui; } // namespace void PaletteEditor::DrawPaletteGroup(int i) { - const int palettesPerRow = 4; - ImGui::BeginTable("palette_table", palettesPerRow, - ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable); - auto size = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()).size(); auto palettes = rom_.GetPaletteGroup(kPaletteGroupNames[i].data()); for (int j = 0; j < size; j++) { - if (j % palettesPerRow == 0) { - ImGui::TableNextRow(); - } - ImGui::TableSetColumnIndex(j % palettesPerRow); ImGui::Text("%d", j); auto palette = palettes[j]; @@ -106,8 +98,6 @@ void PaletteEditor::DrawPaletteGroup(int i) { ImGui::PopID(); } } - - ImGui::EndTable(); } absl::Status PaletteEditor::Update() { @@ -159,6 +149,10 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) { ImGui::SameLine(); ImGui::Text("Previous"); + if (ImGui::Button("Update Map Palette")) { + + } + ImGui::ColorButton( "##current", color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, @@ -170,6 +164,8 @@ void PaletteEditor::DisplayPalette(gfx::SNESPalette& palette, bool loaded) { ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60, 40))) color = backup_color; + + // List of Colors in Overworld Palette ImGui::Separator(); ImGui::Text("Palette"); for (int n = 0; n < IM_ARRAYSIZE(saved_palette_); n++) { diff --git a/src/app/editor/palette_editor.h b/src/app/editor/palette_editor.h index 3b62c688..7ba076f4 100644 --- a/src/app/editor/palette_editor.h +++ b/src/app/editor/palette_editor.h @@ -6,8 +6,8 @@ #include "absl/status/status.h" #include "app/gfx/snes_palette.h" #include "app/rom.h" -#include "gui/canvas.h" -#include "gui/icons.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" namespace yaze { namespace app { diff --git a/src/app/editor/screen_editor.cc b/src/app/editor/screen_editor.cc index bcf19352..e3422c39 100644 --- a/src/app/editor/screen_editor.cc +++ b/src/app/editor/screen_editor.cc @@ -15,9 +15,9 @@ #include "app/core/constants.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" -#include "gui/canvas.h" -#include "gui/icons.h" -#include "gui/input.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/gui/input.h" namespace yaze { namespace app { diff --git a/src/app/editor/screen_editor.h b/src/app/editor/screen_editor.h index 6de72848..12c5e9f4 100644 --- a/src/app/editor/screen_editor.h +++ b/src/app/editor/screen_editor.h @@ -9,11 +9,11 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" +#include "app/gui/canvas.h" +#include "app/gui/color.h" +#include "app/gui/icons.h" #include "app/rom.h" -#include "app/zelda3/inventory.h" -#include "gui/canvas.h" -#include "gui/color.h" -#include "gui/icons.h" +#include "app/zelda3/screen/inventory.h" namespace yaze { namespace app { diff --git a/src/app/gfx/snes_tile.h b/src/app/gfx/snes_tile.h index 67b6e0ca..57c68677 100644 --- a/src/app/gfx/snes_tile.h +++ b/src/app/gfx/snes_tile.h @@ -34,8 +34,23 @@ class TileInfo { vertical_mirror_(v), horizontal_mirror_(h), palette_(palette) {} - // TODO(scawful): This is not the actual value yet. - ushort ToShort() const { return id_; } + + ushort ToShort() const { + ushort result = 0; + + // Copy the id_ value + result |= id_ & 0x3FF; // ids are 10 bits + + // Set the vertical_mirror_, horizontal_mirror_, and over_ flags + result |= (vertical_mirror_ ? 1 : 0) << 10; + result |= (horizontal_mirror_ ? 1 : 0) << 11; + result |= (over_ ? 1 : 0) << 12; + + // Set the palette_ + result |= (palette_ & 0x07) << 13; // palettes are 3 bits + + return result; + } }; TileInfo GetTilesInfo(ushort tile); diff --git a/src/gui/canvas.cc b/src/app/gui/canvas.cc similarity index 100% rename from src/gui/canvas.cc rename to src/app/gui/canvas.cc diff --git a/src/gui/canvas.h b/src/app/gui/canvas.h similarity index 100% rename from src/gui/canvas.h rename to src/app/gui/canvas.h diff --git a/src/gui/color.cc b/src/app/gui/color.cc similarity index 100% rename from src/gui/color.cc rename to src/app/gui/color.cc diff --git a/src/gui/color.h b/src/app/gui/color.h similarity index 100% rename from src/gui/color.h rename to src/app/gui/color.h diff --git a/src/gui/icons.h b/src/app/gui/icons.h similarity index 100% rename from src/gui/icons.h rename to src/app/gui/icons.h diff --git a/src/gui/input.cc b/src/app/gui/input.cc similarity index 100% rename from src/gui/input.cc rename to src/app/gui/input.cc diff --git a/src/gui/input.h b/src/app/gui/input.h similarity index 100% rename from src/gui/input.h rename to src/app/gui/input.h diff --git a/src/gui/style.cc b/src/app/gui/style.cc similarity index 100% rename from src/gui/style.cc rename to src/app/gui/style.cc diff --git a/src/gui/style.h b/src/app/gui/style.h similarity index 100% rename from src/gui/style.h rename to src/app/gui/style.h diff --git a/src/gui/widgets.cc b/src/app/gui/widgets.cc similarity index 100% rename from src/gui/widgets.cc rename to src/app/gui/widgets.cc diff --git a/src/gui/widgets.h b/src/app/gui/widgets.h similarity index 100% rename from src/gui/widgets.h rename to src/app/gui/widgets.h diff --git a/src/app/zelda3/dungeon/room.cc b/src/app/zelda3/dungeon/room.cc index 90021eea..ae074b15 100644 --- a/src/app/zelda3/dungeon/room.cc +++ b/src/app/zelda3/dungeon/room.cc @@ -5,7 +5,7 @@ #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "gui/canvas.h" +#include "app/gui/canvas.h" namespace yaze { namespace app { diff --git a/src/app/zelda3/dungeon/room.h b/src/app/zelda3/dungeon/room.h index e9752a07..8b02f115 100644 --- a/src/app/zelda3/dungeon/room.h +++ b/src/app/zelda3/dungeon/room.h @@ -6,7 +6,7 @@ #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "gui/canvas.h" +#include "app/gui/canvas.h" namespace yaze { namespace app { diff --git a/src/app/spc700/spc700.def b/src/app/zelda3/music/spc700.def similarity index 100% rename from src/app/spc700/spc700.def rename to src/app/zelda3/music/spc700.def diff --git a/src/app/zelda3/tracker.cc b/src/app/zelda3/music/tracker.cc similarity index 100% rename from src/app/zelda3/tracker.cc rename to src/app/zelda3/music/tracker.cc diff --git a/src/app/zelda3/tracker.h b/src/app/zelda3/music/tracker.h similarity index 100% rename from src/app/zelda3/tracker.h rename to src/app/zelda3/music/tracker.h diff --git a/src/app/zelda3/overworld.cc b/src/app/zelda3/overworld.cc index 20469f24..2228043d 100644 --- a/src/app/zelda3/overworld.cc +++ b/src/app/zelda3/overworld.cc @@ -46,20 +46,20 @@ absl::Status Overworld::Load(ROM &rom) { for (int i = 0; i < core::kNumOverworldMaps; ++i) { futures.push_back(std::async(std::launch::async, [this, i, size]() { if (i < 64) { - return overworld_maps_[i].BuildMap( - size, game_state_, 0, map_parent_, map_tiles_.light_world); + return overworld_maps_[i].BuildMap(size, game_state_, 0, map_parent_, + map_tiles_.light_world); } else if (i < 0x80 && i >= 0x40) { - return overworld_maps_[i].BuildMap( - size, game_state_, 1, map_parent_, map_tiles_.dark_world); + return overworld_maps_[i].BuildMap(size, game_state_, 1, map_parent_, + map_tiles_.dark_world); } else { - return overworld_maps_[i].BuildMap( - size, game_state_, 2, map_parent_, map_tiles_.special_world); + return overworld_maps_[i].BuildMap(size, game_state_, 2, map_parent_, + map_tiles_.special_world); } })); } // Wait for all tasks to complete and check their results - for (auto& future : futures) { + for (auto &future : futures) { absl::Status status = future.get(); if (!status.ok()) { return status; @@ -275,110 +275,52 @@ absl::Status Overworld::SaveOverworldMaps() { // ---------------------------------------------------------------------------- -/** void Overworld::SaveMap16Tiles() { int tpos = core::map16Tiles; // 3760 for (int i = 0; i < core::NumberOfMap16; i += 1) { - rom_.WriteShort(tpos, tiles16[i].tile0_); + rom_.WriteShort(tpos, tiles16[i].tile0_.ToShort()); tpos += 2; - rom_.WriteShort(tpos, tiles16[i].tile1_); + rom_.WriteShort(tpos, tiles16[i].tile1_.ToShort()); tpos += 2; - rom_.WriteShort(tpos, tiles16[i].tile2_); + rom_.WriteShort(tpos, tiles16[i].tile2_.ToShort()); tpos += 2; - rom_.WriteShort(tpos, tiles16[i].tile3_); + rom_.WriteShort(tpos, tiles16[i].tile3_.ToShort()); tpos += 2; } } -*/ // ---------------------------------------------------------------------------- -/** void Overworld::SaveMap32Tiles() { - int index = 0; - int c = tiles32_unique_.size(); - for (int i = 0; i < c; i += 6) { - if (index >= 0x4540) // 3C87?? - { - std::cout << "Too many unique tiles!" << std::endl; + const int max_tiles = 0x4540; + const int unique_size = tiles32_unique_.size(); - break; + auto write_tiles = [&](int address, auto get_tile) { + for (int i = 0; i < unique_size && i < max_tiles; i += 4) { + for (int j = 0; j < 4; ++j) { + rom_.Write(address + i + j, (uchar)(get_tile(i + j) & 0xFF)); + } + rom_.Write(address + i + 4, (uchar)(((get_tile(i) >> 4) & 0xF0) | + ((get_tile(i + 1) >> 8) & 0x0F))); + rom_.Write(address + i + 5, (uchar)(((get_tile(i + 2) >> 4) & 0xF0) | + ((get_tile(i + 3) >> 8) & 0x0F))); } + }; - // Top Left - rom_.Write(core::map32TilesTL + (i), - (uchar)(tiles32_unique_[index].tile0 & 0xFF)); - rom_.Write(core::map32TilesTL + (i + 1), - (uchar)(tiles32_unique_[index + 1].tile0 & 0xFF)); - rom_.Write(core::map32TilesTL + (i + 2), - (uchar)(tiles32_unique_[index + 2].tile0 & 0xFF)); - rom_.Write(core::map32TilesTL + (i + 3), - (uchar)(tiles32_unique_[index + 3].tile0 & 0xFF)); + write_tiles(core::map32TilesTL, + [&](int i) { return tiles32_unique_[i].tile0_; }); + write_tiles(core::map32TilesTR, + [&](int i) { return tiles32_unique_[i].tile1_; }); + write_tiles(core::map32TilesBL, + [&](int i) { return tiles32_unique_[i].tile2_; }); + write_tiles(core::map32TilesBR, + [&](int i) { return tiles32_unique_[i].tile3_; }); - rom_.Write(core::map32TilesTL + (i + 4), - (uchar)(((tiles32_unique_[index].tile0 >> 4) & 0xF0) + - ((tiles32_unique_[index + 1].tile0 >> 8) & 0x0F))); - rom_.Write(core::map32TilesTL + (i + 5), - (uchar)(((tiles32_unique_[index + 2].tile0 >> 4) & 0xF0) + - ((tiles32_unique_[index + 3].tile0 >> 8) & 0x0F))); - - // Top Right - rom_.Write(core::map32TilesTR + (i), - (uchar)(tiles32_unique_[index].tile1 & 0xFF)); - rom_.Write(core::map32TilesTR + (i + 1), - (uchar)(tiles32_unique_[index + 1].tile1 & 0xFF)); - rom_.Write(core::map32TilesTR + (i + 2), - (uchar)(tiles32_unique_[index + 2].tile1 & 0xFF)); - rom_.Write(core::map32TilesTR + (i + 3), - (uchar)(tiles32_unique_[index + 3].tile1 & 0xFF)); - - rom_.Write(core::map32TilesTR + (i + 4), - (uchar)(((tiles32_unique_[index].tile1 >> 4) & 0xF0) | - ((tiles32_unique_[index + 1].tile1 >> 8) & 0x0F))); - rom_.Write(core::map32TilesTR + (i + 5), - (uchar)(((tiles32_unique_[index + 2].tile1 >> 4) & 0xF0) | - ((tiles32_unique_[index + 3].tile1 >> 8) & 0x0F))); - - // Bottom Left - rom_.Write(core::map32TilesBL + (i), - (uchar)(tiles32_unique_[index].tile2 & 0xFF)); - rom_.Write(core::map32TilesBL + (i + 1), - (uchar)(tiles32_unique_[index + 1].tile2 & 0xFF)); - rom_.Write(core::map32TilesBL + (i + 2), - (uchar)(tiles32_unique_[index + 2].tile2 & 0xFF)); - rom_.Write(core::map32TilesBL + (i + 3), - (uchar)(tiles32_unique_[index + 3].tile2 & 0xFF)); - - rom_.Write(core::map32TilesBL + (i + 4), - (uchar)(((tiles32_unique_[index].tile2 >> 4) & 0xF0) | - ((tiles32_unique_[index + 1].tile2 >> 8) & 0x0F))); - rom_.Write(core::map32TilesBL + (i + 5), - (uchar)(((tiles32_unique_[index + 2].tile2 >> 4) & 0xF0) | - ((tiles32_unique_[index + 3].tile2 >> 8) & 0x0F))); - - // Bottom Right - rom_.Write(core::map32TilesBR + (i), - (uchar)(tiles32_unique_[index].tile3 & 0xFF)); - rom_.Write(core::map32TilesBR + (i + 1), - (uchar)(tiles32_unique_[index + 1].tile3 & 0xFF)); - rom_.Write(core::map32TilesBR + (i + 2), - (uchar)(tiles32_unique_[index + 2].tile3 & 0xFF)); - rom_.Write(core::map32TilesBR + (i + 3), - (uchar)(tiles32_unique_[index + 3].tile3 & 0xFF)); - - rom_.Write(core::map32TilesBR + (i + 4), - (uchar)(((tiles32_unique_[index].tile3 >> 4) & 0xF0) | - ((tiles32_unique_[index + 1].tile3 >> 8) & 0x0F))); - rom_.Write(core::map32TilesBR + (i + 5), - (uchar)(((tiles32_unique_[index + 2].tile3 >> 4) & 0xF0) | - ((tiles32_unique_[index + 3].tile3 >> 8) & 0x0F))); - - index += 4; - c += 2; + if (unique_size > max_tiles) { + std::cout << "Too many unique tiles!" << std::endl; } } -*/ // ---------------------------------------------------------------------------- diff --git a/src/app/zelda3/overworld.h b/src/app/zelda3/overworld.h index 61d1daa8..61e42f06 100644 --- a/src/app/zelda3/overworld.h +++ b/src/app/zelda3/overworld.h @@ -13,7 +13,7 @@ #include "app/gfx/snes_tile.h" #include "app/rom.h" #include "app/zelda3/overworld_map.h" -#include "app/zelda3/sprite.h" +#include "app/zelda3/sprite/sprite.h" namespace yaze { namespace app { diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld_map.cc index 35ce1d22..97c6772d 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld_map.cc @@ -109,8 +109,8 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current, k = 0; for (int y = 9; y < 13; y++) { for (int x = 1; x < 16; x++) { - new_palette[x + (16 * y)] = rom.GetPaletteGroup("global_sprites")[0][k]; - k++; + new_palette[x + (16 * y)] = + rom.GetPaletteGroup("global_sprites")[0][k]; k++; } } @@ -267,210 +267,156 @@ void OverworldMap::LoadAreaInfo() { } } -void OverworldMap::LoadAreaGraphics() { - int world_index = 0x20; +void OverworldMap::LoadWorldIndex() { if (parent_ < 0x40) { - world_index = 0x20; + world_index_ = 0x20; } else if (parent_ >= 0x40 && parent_ < 0x80) { - world_index = 0x21; + world_index_ = 0x21; } else if (parent_ == 0x88) { - world_index = 0x24; + world_index_ = 0x24; } +} + +void OverworldMap::LoadSpritesBlocksets() { + int static_graphics_base = 0x73; + static_graphics_[8] = static_graphics_base + 0x00; + static_graphics_[9] = static_graphics_base + 0x01; + static_graphics_[10] = static_graphics_base + 0x06; + static_graphics_[11] = static_graphics_base + 0x07; - // Sprites Blocksets - static_graphics_[8] = 0x73 + 0x00; - static_graphics_[9] = 0x73 + 0x01; - static_graphics_[10] = 0x73 + 0x06; - static_graphics_[11] = 0x73 + 0x07; for (int i = 0; i < 4; i++) { static_graphics_[12 + i] = (rom_[core::kSpriteBlocksetPointer + (sprite_graphics_[game_state_] * 4) + i] + - 0x73); + static_graphics_base); } +} - // Main Blocksets +void OverworldMap::LoadMainBlocksets() { for (int i = 0; i < 8; i++) { static_graphics_[i] = - rom_[core::overworldgfxGroups2 + (world_index * 8) + i]; + rom_[core::overworldgfxGroups2 + (world_index_ * 8) + i]; } +} - if (rom_[core::overworldgfxGroups + (area_graphics_ * 4)] != 0) { - static_graphics_[3] = rom_[core::overworldgfxGroups + (area_graphics_ * 4)]; - } - if (rom_[core::overworldgfxGroups + (area_graphics_ * 4) + 1] != 0) { - static_graphics_[4] = - rom_[core::overworldgfxGroups + (area_graphics_ * 4) + 1]; - } - if (rom_[core::overworldgfxGroups + (area_graphics_ * 4) + 2] != 0) { - static_graphics_[5] = - rom_[core::overworldgfxGroups + (area_graphics_ * 4) + 2]; - } - if (rom_[core::overworldgfxGroups + (area_graphics_ * 4) + 3] != 0) { - static_graphics_[6] = - rom_[core::overworldgfxGroups + (area_graphics_ * 4) + 3]; +void OverworldMap::LoadAreaGraphicsBlocksets() { + for (int i = 0; i < 4; i++) { + uchar value = rom_[core::overworldgfxGroups + (area_graphics_ * 4) + i]; + if (value != 0) { + static_graphics_[3 + i] = value; + } } +} - // Hardcoded overworld GFX Values, for death mountain - if ((parent_ >= 0x03 && parent_ <= 0x07) || - (parent_ >= 0x0B && parent_ <= 0x0E)) { - static_graphics_[7] = 0x59; - } else if ((parent_ >= 0x43 && parent_ <= 0x47) || - (parent_ >= 0x4B && parent_ <= 0x4E)) { - static_graphics_[7] = 0x59; +void OverworldMap::LoadDeathMountainGFX() { + static_graphics_[7] = (((parent_ >= 0x03 && parent_ <= 0x07) || + (parent_ >= 0x0B && parent_ <= 0x0E)) || + ((parent_ >= 0x43 && parent_ <= 0x47) || + (parent_ >= 0x4B && parent_ <= 0x4E))) + ? 0x59 + : 0x5B; +} + +void OverworldMap::LoadAreaGraphics() { + LoadWorldIndex(); + LoadSpritesBlocksets(); + LoadMainBlocksets(); + LoadAreaGraphicsBlocksets(); + LoadDeathMountainGFX(); +} + +// New helper function to get a palette from the ROM. +gfx::SNESPalette OverworldMap::GetPalette(const std::string& group, int index, + int previousIndex, int limit) { + if (index == 255) { + index = rom_[core::overworldMapPaletteGroup + (previousIndex * 4)]; + } + if (index != 255) { + if (index >= limit) { + index = limit - 1; + } + return rom_.GetPaletteGroup(group)[index]; } else { - static_graphics_[7] = 0x5B; + return rom_.GetPaletteGroup(group)[0]; } } void OverworldMap::LoadPalette() { - int previousPalId = 0; - int previousSprPalId = 0; - if (index_ > 0) { - previousPalId = rom_[core::overworldMapPalette + parent_ - 1]; - previousSprPalId = rom_[core::overworldSpritePalette + parent_ - 1]; - } + int previousPalId = + index_ > 0 ? rom_[core::overworldMapPalette + parent_ - 1] : 0; + int previousSprPalId = + index_ > 0 ? rom_[core::overworldSpritePalette + parent_ - 1] : 0; - if (area_palette_ >= 0xA3) { - area_palette_ = 0xA3; - } + area_palette_ = std::min(area_palette_, 0xA3); uchar pal0 = 0; - uchar pal1 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4)]; - uchar pal2 = - rom_[core::overworldMapPaletteGroup + (area_palette_ * 4) + 1]; // aux2 - uchar pal3 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4) + - 2]; // animated - + uchar pal2 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4) + 1]; + uchar pal3 = rom_[core::overworldMapPaletteGroup + (area_palette_ * 4) + 2]; uchar pal4 = rom_[core::overworldSpritePaletteGroup + - (sprite_palette_[game_state_] * 2)]; // spr3 + (sprite_palette_[game_state_] * 2)]; uchar pal5 = rom_[core::overworldSpritePaletteGroup + - (sprite_palette_[game_state_] * 2) + 1]; // spr4 + (sprite_palette_[game_state_] * 2) + 1]; - gfx::SNESPalette aux1; - gfx::SNESPalette aux2; - gfx::SNESPalette main; - gfx::SNESPalette animated; - gfx::SNESPalette hud; - gfx::SNESPalette spr; - gfx::SNESPalette spr2; gfx::SNESColor bgr = rom_.GetPaletteGroup("grass")[0].GetColor(0); - if (pal1 == 255) { - pal1 = rom_[core::overworldMapPaletteGroup + (previousPalId * 4)]; - } - if (pal1 != 255) { - if (pal1 >= 20) { - pal1 = 19; - } - - aux1 = rom_.GetPaletteGroup("ow_aux")[pal1]; - } else { - aux1 = rom_.GetPaletteGroup("ow_aux")[0]; - } - - if (pal2 == 255) { - pal2 = rom_[core::overworldMapPaletteGroup + (previousPalId * 4) + 1]; - } - if (pal2 != 255) { - if (pal2 >= 20) { - pal2 = 19; - } - - aux2 = rom_.GetPaletteGroup("ow_aux")[pal2]; - } else { - aux2 = rom_.GetPaletteGroup("ow_aux")[0]; - } + gfx::SNESPalette aux1 = GetPalette("ow_aux", pal1, previousPalId, 20); + gfx::SNESPalette aux2 = GetPalette("ow_aux", pal2, previousPalId, 20); + // Additional handling of `pal3` and `parent_` if (pal3 == 255) { pal3 = rom_[core::overworldMapPaletteGroup + (previousPalId * 4) + 2]; } - if (parent_ < 0x40) { - // Default LW Palette - pal0 = 0; + pal0 = parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07 ? 2 : 0; bgr = rom_.GetPaletteGroup("grass")[0].GetColor(0); - if (parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07) { - pal0 = 2; - } } else if (parent_ >= 0x40 && parent_ < 0x80) { - // Default DW Palette - pal0 = 1; + pal0 = parent_ == 0x43 || parent_ == 0x45 || parent_ == 0x47 ? 3 : 1; bgr = rom_.GetPaletteGroup("grass")[0].GetColor(1); - if (parent_ == 0x43 || parent_ == 0x45 || parent_ == 0x47) { - pal0 = 3; - } } else if (parent_ >= 128 && parent_ < core::kNumOverworldMaps) { - // Default SP Palette pal0 = 0; bgr = rom_.GetPaletteGroup("grass")[0].GetColor(2); } - if (parent_ == 0x88) { pal0 = 4; } + gfx::SNESPalette main = GetPalette("ow_main", pal0, previousPalId, 255); + gfx::SNESPalette animated = + GetPalette("ow_animated", std::min((int)pal3, 13), previousPalId, 14); + gfx::SNESPalette hud = rom_.GetPaletteGroup("hud")[0]; - if (pal0 != 255) { - main = rom_.GetPaletteGroup("ow_main")[pal0]; - } else { - main = rom_.GetPaletteGroup("ow_main")[0]; - } - - if (pal3 >= 14) { - pal3 = 13; - } - animated = rom_.GetPaletteGroup("ow_animated")[(pal3)]; - - hud = rom_.GetPaletteGroup("hud")[0]; - if (pal4 == 255) { - pal4 = rom_[core::overworldSpritePaletteGroup + - (previousSprPalId * 2)]; // spr3 - } - if (pal4 == 255) { - pal4 = 0; - } - if (pal4 >= 24) { - pal4 = 23; - } - spr = rom_.GetPaletteGroup("sprites_aux3")[pal4]; - - if (pal5 == 255) { - pal5 = rom_[core::overworldSpritePaletteGroup + (previousSprPalId * 2) + - 1]; // spr3 - } - if (pal5 == 255) { - pal5 = 0; - } - if (pal5 >= 24) { - pal5 = 23; - } - spr2 = rom_.GetPaletteGroup("sprites_aux3")[pal5]; + gfx::SNESPalette spr = GetPalette("sprites_aux3", pal4, previousSprPalId, 24); + gfx::SNESPalette spr2 = + GetPalette("sprites_aux3", pal5, previousSprPalId, 24); SetColorsPalette(rom_, parent_, current_palette_, main, animated, aux1, aux2, hud, bgr, spr, spr2); } +// New helper function to process graphics buffer. +void OverworldMap::ProcessGraphicsBuffer(int index, int static_graphics_offset, + int size) { + for (int i = 0; i < size; i++) { + auto byte = all_gfx_[i + (static_graphics_offset * size)]; + switch (index) { + case 0: + case 3: + case 4: + case 5: + byte += 0x88; + break; + } + current_gfx_[(index * size) + i] = byte; + } +} + absl::Status OverworldMap::BuildTileset() { all_gfx_ = rom_.GetGraphicsBuffer(); - current_gfx_.reserve(0x10000); - for (int i = 0; i < 0x10000; i++) { - current_gfx_.push_back(0x00); - } + current_gfx_.resize(0x10000, 0x00); for (int i = 0; i < 0x10; i++) { - for (int j = 0; j < 0x1000; j++) { - auto byte = all_gfx_[j + (static_graphics_[i] * 0x1000)]; - switch (i) { - case 0: - case 3: - case 4: - case 5: - byte += 0x88; - break; - } - current_gfx_[(i * 0x1000) + j] = byte; - } + ProcessGraphicsBuffer(i, static_graphics_[i], 0x1000); } + return absl::OkStatus(); } diff --git a/src/app/zelda3/overworld_map.h b/src/app/zelda3/overworld_map.h index 31346689..d862cceb 100644 --- a/src/app/zelda3/overworld_map.h +++ b/src/app/zelda3/overworld_map.h @@ -13,6 +13,7 @@ #include "app/core/common.h" #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" +#include "app/gfx/snes_palette.h" #include "app/rom.h" namespace yaze { @@ -39,9 +40,21 @@ class OverworldMap { private: void LoadAreaInfo(); + + void LoadWorldIndex(); + void LoadSpritesBlocksets(); + void LoadMainBlocksets(); + void LoadAreaGraphicsBlocksets(); + void LoadDeathMountainGFX(); void LoadAreaGraphics(); + void LoadPalette(); + + + void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size); + gfx::SNESPalette GetPalette(const std::string& group, int index, int previousIndex, int limit); + absl::Status BuildTileset(); absl::Status BuildTiles16Gfx(int count); absl::Status BuildBitmap(OWBlockset& world_blockset); @@ -54,6 +67,8 @@ class OverworldMap { int area_palette_ = 0; int game_state_ = 0; + int world_index_ = 0; + uchar sprite_graphics_[3]; uchar sprite_palette_[3]; uchar area_music_[4]; diff --git a/src/app/zelda3/inventory.cc b/src/app/zelda3/screen/inventory.cc similarity index 95% rename from src/app/zelda3/inventory.cc rename to src/app/zelda3/screen/inventory.cc index 89198cc0..49dc7477 100644 --- a/src/app/zelda3/inventory.cc +++ b/src/app/zelda3/screen/inventory.cc @@ -3,7 +3,7 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "gui/canvas.h" +#include "app/gui/canvas.h" namespace yaze { namespace app { diff --git a/src/app/zelda3/inventory.h b/src/app/zelda3/screen/inventory.h similarity index 92% rename from src/app/zelda3/inventory.h rename to src/app/zelda3/screen/inventory.h index 4b714f8a..aa3027bf 100644 --- a/src/app/zelda3/inventory.h +++ b/src/app/zelda3/screen/inventory.h @@ -5,7 +5,7 @@ #include "app/gfx/snes_tile.h" #include "app/gfx/snes_palette.h" #include "app/rom.h" -#include "gui/canvas.h" +#include "app/gui/canvas.h" namespace yaze { namespace app { diff --git a/src/app/zelda3/title_screen.cc b/src/app/zelda3/screen/title_screen.cc similarity index 100% rename from src/app/zelda3/title_screen.cc rename to src/app/zelda3/screen/title_screen.cc diff --git a/src/app/zelda3/title_screen.h b/src/app/zelda3/screen/title_screen.h similarity index 100% rename from src/app/zelda3/title_screen.h rename to src/app/zelda3/screen/title_screen.h diff --git a/src/app/zelda3/sprite.cc b/src/app/zelda3/sprite/sprite.cc similarity index 100% rename from src/app/zelda3/sprite.cc rename to src/app/zelda3/sprite/sprite.cc diff --git a/src/app/zelda3/sprite.h b/src/app/zelda3/sprite/sprite.h similarity index 100% rename from src/app/zelda3/sprite.h rename to src/app/zelda3/sprite/sprite.h