diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 0016dab3..54107f5c 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -87,6 +87,18 @@ } \ type_variable_name = std::move(*error_or_value); +#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression) \ + ASSIGN_OR_LOG_ERROR_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \ + type_variable_name, expression) + +#define ASSIGN_OR_LOG_ERROR_IMPL(error_or_value, type_variable_name, \ + expression) \ + auto error_or_value = expression; \ + if (!error_or_value.ok()) { \ + std::cout << error_or_value.status().ToString() << std::endl; \ + } \ + type_variable_name = std::move(*error_or_value); + #define APPEND_NUMBER(expression, number) \ APPEND_NUMBER_INNER(expression, number) diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 4e80b72c..dd6177d4 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -138,7 +138,6 @@ void Controller::OnInput() { break; } break; - default: break; } diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index c77fb3d6..14ad3473 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -112,6 +112,8 @@ class RecentFilesManager { } // namespace +using ImGui::BeginMenu; +using ImGui::MenuItem; using ImGui::Text; void MasterEditor::SetupScreen(std::shared_ptr renderer) { @@ -275,8 +277,8 @@ void MasterEditor::DrawYazeMenu() { void MasterEditor::DrawFileMenu() { static bool save_as_menu = false; - if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("Open", "Ctrl+O")) { + if (BeginMenu("File")) { + if (MenuItem("Open", "Ctrl+O")) { if (flags()->kNewFileDialogWrapper) { auto file_name = FileDialogWrapper::ShowOpenFileDialog(); PRINT_IF_ERROR(rom()->LoadFromFile(file_name)); @@ -290,14 +292,14 @@ void MasterEditor::DrawFileMenu() { } } - if (ImGui::BeginMenu("Open Recent")) { + if (BeginMenu("Open Recent")) { static RecentFilesManager manager("recent_files.txt"); manager.Load(); if (manager.GetRecentFiles().empty()) { - ImGui::MenuItem("No Recent Files", nullptr, false, false); + MenuItem("No Recent Files", nullptr, false, false); } else { for (const auto& filePath : manager.GetRecentFiles()) { - if (ImGui::MenuItem(filePath.c_str())) { + if (MenuItem(filePath.c_str())) { status_ = rom()->LoadFromFile(filePath); } } @@ -315,8 +317,8 @@ void MasterEditor::DrawFileMenu() { ImGui::Separator(); - if (ImGui::BeginMenu("Options")) { - ImGui::MenuItem("Backup ROM", "", &backup_rom_); + if (BeginMenu("Options")) { + MenuItem("Backup ROM", "", &backup_rom_); ImGui::Separator(); Text("Experiment Flags"); ImGui::Checkbox("Enable Texture Streaming", @@ -339,7 +341,7 @@ void MasterEditor::DrawFileMenu() { ImGui::Separator(); - if (ImGui::MenuItem("Quit", "Ctrl+Q")) { + if (MenuItem("Quit", "Ctrl+Q")) { // TODO: Implement quit confirmation dialog. } @@ -363,7 +365,7 @@ void MasterEditor::DrawFileMenu() { } void MasterEditor::DrawEditMenu() { - if (ImGui::BeginMenu("Edit")) { + if (BeginMenu("Edit")) { MENU_ITEM2("Undo", "Ctrl+Z") { status_ = current_editor_->Undo(); } MENU_ITEM2("Redo", "Ctrl+Y") { status_ = current_editor_->Redo(); } ImGui::Separator(); @@ -439,23 +441,23 @@ void MasterEditor::DrawViewMenu() { ImGui::End(); } - if (ImGui::BeginMenu("View")) { - ImGui::MenuItem("Emulator", nullptr, &show_emulator); - 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::MenuItem("ImGui Metrics", nullptr, &show_imgui_metrics); + if (BeginMenu("View")) { + MenuItem("Emulator", nullptr, &show_emulator); + MenuItem("HEX Editor", nullptr, &show_memory_editor); + MenuItem("ASM Editor", nullptr, &show_asm_editor); + MenuItem("Palette Editor", nullptr, &show_palette_editor); + MenuItem("Memory Viewer", nullptr, &show_memory_viewer); + MenuItem("ImGui Demo", nullptr, &show_imgui_demo); + MenuItem("ImGui Metrics", nullptr, &show_imgui_metrics); ImGui::EndMenu(); } } void MasterEditor::DrawHelpMenu() { static bool open_rom_help = false; - if (ImGui::BeginMenu("Help")) { - if (ImGui::MenuItem("How to open a ROM")) open_rom_help = true; - if (ImGui::MenuItem("About")) about_ = true; + if (BeginMenu("Help")) { + if (MenuItem("How to open a ROM")) open_rom_help = true; + if (MenuItem("About")) about_ = true; ImGui::EndMenu(); } diff --git a/src/app/editor/modules/gfx_group_editor.cc b/src/app/editor/modules/gfx_group_editor.cc index 7ae53684..789b2605 100644 --- a/src/app/editor/modules/gfx_group_editor.cc +++ b/src/app/editor/modules/gfx_group_editor.cc @@ -62,7 +62,7 @@ absl::Status GfxGroupEditor::Update() { auto &sheet = *rom()->bitmap_manager()[sheet_id]; if (sheet_id != last_sheet_id_) { last_sheet_id_ = sheet_id; - auto palette_group = rom()->GetPaletteGroup("ow_main"); + auto palette_group = rom()->palette_group("ow_main"); auto palette = palette_group[preview_palette_id_]; sheet.ApplyPalette(palette); rom()->UpdateBitmap(&sheet); diff --git a/src/app/editor/modules/palette_editor.cc b/src/app/editor/modules/palette_editor.cc index 21e56dcd..4f020668 100644 --- a/src/app/editor/modules/palette_editor.cc +++ b/src/app/editor/modules/palette_editor.cc @@ -96,8 +96,8 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) { } const auto size = - rom()->GetPaletteGroup(kPaletteGroupNames[category].data()).size(); - auto palettes = rom()->GetPaletteGroup(kPaletteGroupNames[category].data()); + rom()->palette_group(kPaletteGroupNames[category].data()).size(); + auto palettes = rom()->palette_group(kPaletteGroupNames[category].data()); static bool edit_color = false; for (int j = 0; j < size; j++) { ImGui::Text("%d", j); diff --git a/src/app/editor/modules/tile16_editor.cc b/src/app/editor/modules/tile16_editor.cc index 4048433f..08ff7dbb 100644 --- a/src/app/editor/modules/tile16_editor.cc +++ b/src/app/editor/modules/tile16_editor.cc @@ -112,7 +112,7 @@ absl::Status Tile16Editor::UpdateBlockset() { if (notify_tile16.modified()) { current_tile16_bmp_ = tile16_individual_[notify_tile16]; current_tile16_bmp_.ApplyPalette( - rom()->GetPaletteGroup("ow_main")[current_palette_]); + rom()->palette_group("ow_main")[current_palette_]); rom()->RenderBitmap(¤t_tile16_bmp_); } } @@ -163,9 +163,9 @@ void Tile16Editor::DrawTileEditControls() { notify_palette.apply_changes(); if (notify_palette.modified()) { current_gfx_bmp_.ApplyPalette( - rom()->GetPaletteGroup("ow_main")[notify_palette.get()]); + rom()->palette_group("ow_main")[notify_palette.get()]); current_tile16_bmp_.ApplyPalette( - rom()->GetPaletteGroup("ow_main")[notify_palette.get()]); + rom()->palette_group("ow_main")[notify_palette.get()]); rom()->UpdateBitmap(¤t_gfx_bmp_); } @@ -250,7 +250,7 @@ absl::Status Tile16Editor::LoadTile8() { current_gfx_individual_.emplace_back(); current_gfx_individual_[index].Create(0x08, 0x08, 0x80, tile_data); current_gfx_individual_[index].ApplyPalette( - rom()->GetPaletteGroup("ow_main")[current_palette_]); + rom()->palette_group("ow_main")[current_palette_]); rom()->RenderBitmap(¤t_gfx_individual_[index]); }; @@ -272,7 +272,7 @@ absl::Status Tile16Editor::LoadTile8() { // for (int i = 0; i < 128; i++) { // std::vector tile_data(0x40, 0x00); - // // Copy the pixel data for the current tile into the vector + // Copy the pixel data for the current tile into the vector // for (int ty = 0; ty < 8; ty++) { // for (int tx = 0; tx < 8; tx++) { // int position = tx + (ty * 0x10); @@ -287,7 +287,7 @@ absl::Status Tile16Editor::LoadTile8() { // current_gfx_individual_.emplace_back(); // current_gfx_individual_[i].Create(0x08, 0x08, 0x80, tile_data); // current_gfx_individual_[i].ApplyPalette( - // rom()->GetPaletteGroup("ow_main")[current_palette_]); + // rom()->palette_group("ow_main")[current_palette_]); // rom()->RenderBitmap(¤t_gfx_individual_[i]); // } return absl::OkStatus(); diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index acf0071c..53598904 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -466,6 +466,8 @@ void OverworldEditor::DrawOverworldCanvas() { DrawOverworldMapSettings(); Separator(); } + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7); ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | @@ -486,6 +488,7 @@ void OverworldEditor::DrawOverworldCanvas() { ow_map_canvas_.DrawOverlay(); } ImGui::EndChild(); + ImGui::PopStyleVar(2); } // ---------------------------------------------------------------------------- diff --git a/src/app/emu/cpu/cpu.h b/src/app/emu/cpu/cpu.h index 3c410de2..04707705 100644 --- a/src/app/emu/cpu/cpu.h +++ b/src/app/emu/cpu/cpu.h @@ -342,7 +342,7 @@ class CPU : public Memory, public Loggable, public core::ExperimentFlags { void WriteWord(uint32_t address, uint16_t value) override { memory.WriteWord(address, value); } - void WriteLong(uint32_t address, uint32_t value) { + void WriteLong(uint32_t address, uint32_t value) override { memory.WriteLong(address, value); } diff --git a/src/app/rom.h b/src/app/rom.h index fd1febc1..40584152 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -279,15 +279,7 @@ class ROM : public core::ExperimentFlags { return result; } - absl::StatusOr ReadShort(int offset) { - if (offset + 1 >= rom_data_.size()) { - return absl::InvalidArgumentError("Offset out of range"); - } - auto result = (uint16_t)(rom_data_[offset] | (rom_data_[offset + 1] << 8)); - return result; - } - - absl::StatusOr ReadShortLong(int offset) { + absl::StatusOr ReadLong(int offset) { if (offset + 2 >= rom_data_.size()) { return absl::InvalidArgumentError("Offset out of range"); } @@ -312,16 +304,16 @@ class ROM : public core::ExperimentFlags { // Skip 8 bytes per tile. auto tpos = 0x78000 + (tile16_id * 0x08); gfx::Tile16 tile16; - ASSIGN_OR_RETURN(auto new_tile0, ReadShort(tpos)) + ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos)) tile16.tile0_ = gfx::WordToTileInfo(new_tile0); tpos += 2; - ASSIGN_OR_RETURN(auto new_tile1, ReadShort(tpos)) + ASSIGN_OR_RETURN(auto new_tile1, ReadWord(tpos)) tile16.tile1_ = gfx::WordToTileInfo(new_tile1); tpos += 2; - ASSIGN_OR_RETURN(auto new_tile2, ReadShort(tpos)) + ASSIGN_OR_RETURN(auto new_tile2, ReadWord(tpos)) tile16.tile2_ = gfx::WordToTileInfo(new_tile2); tpos += 2; - ASSIGN_OR_RETURN(auto new_tile3, ReadShort(tpos)) + ASSIGN_OR_RETURN(auto new_tile3, ReadWord(tpos)) tile16.tile3_ = gfx::WordToTileInfo(new_tile3); return tile16; } @@ -411,7 +403,7 @@ class ROM : public core::ExperimentFlags { return core::SnesToPc(snes_addr); } - gfx::PaletteGroup GetPaletteGroup(const std::string& group) { + gfx::PaletteGroup palette_group(const std::string& group) { return palette_groups_[group]; } auto mutable_palette_group(const std::string& group) { @@ -433,27 +425,12 @@ class ROM : public core::ExperimentFlags { auto begin() { return rom_data_.begin(); } auto end() { return rom_data_.end(); } auto data() { return rom_data_.data(); } + auto push_back(uint8_t byte) { rom_data_.push_back(byte); } auto vector() const { return rom_data_; } auto filename() const { return filename_; } auto isLoaded() const { return is_loaded_; } - auto char_data() { - return static_cast(static_cast(rom_data_.data())); - } - - auto push_back(uchar byte) { rom_data_.push_back(byte); } - auto version() const { return version_; } - void malloc(int n_bytes) { - rom_data_.clear(); - rom_data_.reserve(n_bytes); - rom_data_.resize(n_bytes); - for (int i = 0; i < n_bytes; i++) { - rom_data_.push_back(0x00); - } - size_ = n_bytes; - } - uchar& operator[](int i) { if (i > size_) { std::cout << "ROM: Index " << i << " out of bounds, size: " << size_ diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld_map.cc index 6e9ddd7e..0fd009e3 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld_map.cc @@ -92,7 +92,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current, k = 0; for (int y = 8; y < 9; y++) { for (int x = 1; x < 8; x++) { - new_palette[x + (16 * y)] = rom.GetPaletteGroup("sprites_aux1")[1][k]; + new_palette[x + (16 * y)] = rom.palette_group("sprites_aux1")[1][k]; k++; } } @@ -101,7 +101,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current, k = 0; for (int y = 8; y < 9; y++) { for (int x = 9; x < 16; x++) { - new_palette[x + (16 * y)] = rom.GetPaletteGroup("sprites_aux3")[0][k]; + new_palette[x + (16 * y)] = rom.palette_group("sprites_aux3")[0][k]; k++; } } @@ -110,7 +110,7 @@ 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]; + new_palette[x + (16 * y)] = rom.palette_group("global_sprites")[0][k]; k++; } } @@ -137,7 +137,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current, k = 0; for (int y = 15; y < 16; y++) { for (int x = 1; x < 16; x++) { - new_palette[x + (16 * y)] = rom.GetPaletteGroup("armors")[0][k]; + new_palette[x + (16 * y)] = rom.palette_group("armors")[0][k]; k++; } } @@ -337,9 +337,9 @@ gfx::SNESPalette OverworldMap::GetPalette(const std::string& group, int index, if (index >= limit) { index = limit - 1; } - return rom_.GetPaletteGroup(group)[index]; + return rom_.palette_group(group)[index]; } else { - return rom_.GetPaletteGroup(group)[0]; + return rom_.palette_group(group)[0]; } } @@ -362,7 +362,7 @@ void OverworldMap::LoadPalette() { uchar pal5 = rom_[overworldSpritePaletteGroup + (sprite_palette_[game_state_] * 2) + 1]; - gfx::SNESColor bgr = rom_.GetPaletteGroup("grass")[0].GetColor(0); + gfx::SNESColor bgr = rom_.palette_group("grass")[0].GetColor(0); gfx::SNESPalette aux1 = GetPalette("ow_aux", pal1, previousPalId, 20); gfx::SNESPalette aux2 = GetPalette("ow_aux", pal2, previousPalId, 20); @@ -374,13 +374,13 @@ void OverworldMap::LoadPalette() { } if (parent_ < 0x40) { pal0 = parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07 ? 2 : 0; - bgr = rom_.GetPaletteGroup("grass")[0].GetColor(0); + bgr = rom_.palette_group("grass")[0].GetColor(0); } else if (parent_ >= 0x40 && parent_ < 0x80) { pal0 = parent_ == 0x43 || parent_ == 0x45 || parent_ == 0x47 ? 3 : 1; - bgr = rom_.GetPaletteGroup("grass")[0].GetColor(1); + bgr = rom_.palette_group("grass")[0].GetColor(1); } else if (parent_ >= 128 && parent_ < kNumOverworldMaps) { pal0 = 0; - bgr = rom_.GetPaletteGroup("grass")[0].GetColor(2); + bgr = rom_.palette_group("grass")[0].GetColor(2); } if (parent_ == 0x88) { pal0 = 4; @@ -388,7 +388,7 @@ void OverworldMap::LoadPalette() { 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]; + gfx::SNESPalette hud = rom_.palette_group("hud")[0]; gfx::SNESPalette spr = GetPalette("sprites_aux3", pal4, previousSprPalId, 24); gfx::SNESPalette spr2 = diff --git a/src/app/zelda3/screen/inventory.cc b/src/app/zelda3/screen/inventory.cc index 91d125d6..afe41d31 100644 --- a/src/app/zelda3/screen/inventory.cc +++ b/src/app/zelda3/screen/inventory.cc @@ -79,7 +79,7 @@ absl::Status Inventory::BuildTileset() { test_.push_back(tilesheets_[i]); } tilesheets_bmp_.Create(128, 0x130, 64, test_); - palette_ = rom()->GetPaletteGroup("hud")[0]; + palette_ = rom()->palette_group("hud")[0]; tilesheets_bmp_.ApplyPalette(palette_); rom()->RenderBitmap(&tilesheets_bmp_); return absl::OkStatus();