From 8cac0b71b4ca6778fbdb01ad91149b04bc3dc9d9 Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 3 Aug 2023 19:24:17 -0400 Subject: [PATCH] add push_back to ROM and cleanup some stuff --- src/app/editor/graphics_editor.cc | 58 ++++++++++++++----------------- src/app/editor/screen_editor.h | 1 - src/app/gfx/snes_tile.cc | 2 +- src/app/rom.h | 2 ++ src/app/viewer/cgx_viewer.cc | 10 ++---- 5 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/app/editor/graphics_editor.cc b/src/app/editor/graphics_editor.cc index 61cd976d..35cd9d66 100644 --- a/src/app/editor/graphics_editor.cc +++ b/src/app/editor/graphics_editor.cc @@ -91,22 +91,21 @@ absl::Status GraphicsEditor::DrawCgxImport() { ImGui::InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_)); ImGui::SameLine(); - core::FileDialogPipeline( - "ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [&]() -> auto { - strncpy(cgx_file_path_, - ImGuiFileDialog::Instance()->GetFilePathName().c_str(), - sizeof(cgx_file_path_)); - strncpy(cgx_file_name_, - ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(), - sizeof(cgx_file_name_)); - status_ = temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false); - is_open_ = true; - cgx_loaded_ = true; - }); - core::ButtonPipe("Copy File Path", - [&]() -> auto { ImGui::SetClipboardText(cgx_file_path_); }); + core::FileDialogPipeline("ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [this]() { + strncpy(cgx_file_path_, + ImGuiFileDialog::Instance()->GetFilePathName().c_str(), + sizeof(cgx_file_path_)); + strncpy(cgx_file_name_, + ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(), + sizeof(cgx_file_name_)); + status_ = temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false); + is_open_ = true; + cgx_loaded_ = true; + }); + core::ButtonPipe("Copy CGX Path", + [this]() { ImGui::SetClipboardText(cgx_file_path_); }); - core::ButtonPipe("Decompress CGX Data", [&]() -> auto { + core::ButtonPipe("Decompress CGX Data", [this]() { cgx_viewer_.LoadCgx(temp_rom_); auto all_tiles_data = cgx_viewer_.GetCgxData(); cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth, @@ -127,17 +126,15 @@ absl::Status GraphicsEditor::DrawFileImport() { ImGui::InputText("##ROMFile", file_path_, sizeof(file_path_)); ImGui::SameLine(); - core::FileDialogPipeline( - "ImportDlgKey", ".bin,.hex\0", "Open BIN", [&]() -> auto { - strncpy(file_path_, - ImGuiFileDialog::Instance()->GetFilePathName().c_str(), - sizeof(file_path_)); - status_ = temp_rom_.LoadFromFile(file_path_); - is_open_ = true; - }); + core::FileDialogPipeline("ImportDlgKey", ".bin,.hex\0", "Open BIN", [this]() { + strncpy(file_path_, ImGuiFileDialog::Instance()->GetFilePathName().c_str(), + sizeof(file_path_)); + status_ = temp_rom_.LoadFromFile(file_path_); + is_open_ = true; + }); core::ButtonPipe("Copy File Path", - [&]() -> auto { ImGui::SetClipboardText(file_path_); }); + [this]() { ImGui::SetClipboardText(file_path_); }); gui::InputHex("BIN Offset", ¤t_offset_); gui::InputHex("BIN Size", &bin_size_); @@ -160,7 +157,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() { ImGui::SameLine(); core::FileDialogPipeline( - "ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [&]() -> auto { + "ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [this]() { strncpy(col_file_path_, ImGuiFileDialog::Instance()->GetFilePathName().c_str(), sizeof(col_file_path_)); @@ -187,8 +184,8 @@ absl::Status GraphicsEditor::DrawPaletteControls() { is_open_ = true; }); - core::ButtonPipe("Copy File Path", - [&]() -> auto { ImGui::SetClipboardText(col_file_path_); }); + core::ButtonPipe("Copy COL Path", + [this]() { ImGui::SetClipboardText(col_file_path_); }); if (rom_.isLoaded()) { gui::TextWithSeparators("ROM Palette"); @@ -206,7 +203,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() { absl::Status GraphicsEditor::DrawClipboardImport() { gui::TextWithSeparators("Clipboard Import"); - core::ButtonPipe("Paste from Clipboard", [&]() -> auto { + core::ButtonPipe("Paste from Clipboard", [this]() { const char* text = ImGui::GetClipboardText(); if (text) { const auto clipboard_data = Bytes(text, text + strlen(text)); @@ -220,7 +217,7 @@ absl::Status GraphicsEditor::DrawClipboardImport() { gui::InputHex("Size", &clipboard_size_); gui::InputHex("Num Sheets", &num_sheets_to_load_); - core::ButtonPipe("Decompress Clipboard Data", [&]() -> auto { + core::ButtonPipe("Decompress Clipboard Data", [this]() { if (temp_rom_.isLoaded()) { status_ = DecompressImportData(0x40000); } else { @@ -230,9 +227,6 @@ absl::Status GraphicsEditor::DrawClipboardImport() { } }); - int import_size = 0; - int num_sheets = 0; - return absl::OkStatus(); } diff --git a/src/app/editor/screen_editor.h b/src/app/editor/screen_editor.h index 12c5e9f4..65ba9a34 100644 --- a/src/app/editor/screen_editor.h +++ b/src/app/editor/screen_editor.h @@ -20,7 +20,6 @@ namespace app { namespace editor { using MosaicArray = std::array; -static int overworldCustomMosaicASM = 0x1301D0; class ScreenEditor { public: diff --git a/src/app/gfx/snes_tile.cc b/src/app/gfx/snes_tile.cc index 6c099acc..35b98d6a 100644 --- a/src/app/gfx/snes_tile.cc +++ b/src/app/gfx/snes_tile.cc @@ -89,7 +89,7 @@ Bytes BPP8SNESToIndexed(Bytes data, uint64_t bpp) { for (int x = 0; x < 8; x++) { const uint16_t bitmask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; - auto b1 = ((data[(y * 2) + ((bpp * 8) * pos)] & (bitmask[x]))); + auto b1 = (data[(y * 2) + ((bpp * 8) * pos)] & (bitmask[x])); auto b2 = (data[((y * 2) + ((bpp * 8) * pos)) + 1] & (bitmask[x])); auto b3 = (data[(y * 2) + ((bpp * 8) * pos) + 16] & (bitmask[x])); auto b4 = (data[(y * 2) + ((bpp * 8) * pos) + 17] & (bitmask[x])); diff --git a/src/app/rom.h b/src/app/rom.h index f7662190..243f1f96 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -126,6 +126,8 @@ class ROM { auto isLoaded() const { return is_loaded_; } auto char_data() { return reinterpret_cast(rom_data_.data()); } + auto push_back(uchar byte) { rom_data_.push_back(byte); } + void malloc(int n_bytes) { rom_data_.clear(); rom_data_.reserve(n_bytes); diff --git a/src/app/viewer/cgx_viewer.cc b/src/app/viewer/cgx_viewer.cc index d2a9d53e..80616d3b 100644 --- a/src/app/viewer/cgx_viewer.cc +++ b/src/app/viewer/cgx_viewer.cc @@ -17,16 +17,12 @@ constexpr int kMatchedBytes[] = {0x4E, 0x41, 0x4B, 0x31, 0x39, 0x38, 0x39}; constexpr int kOffsetFromMatchedBytesEnd = 0x1D; void CgxViewer::LoadCgx(ROM &cgx_rom) { - std::cout << "Loading CGX" << std::endl; - raw_data_.malloc(0x40000); - all_tiles_data_.malloc(0x40000); - int matching_position = -1; bool matched = false; for (int i = 0; i < cgx_rom.size() - sizeof(kMatchedBytes) - kOffsetFromMatchedBytesEnd; i++) { - raw_data_[i] = cgx_rom[i]; + raw_data_.push_back(cgx_rom[i]); bool is_match = std::equal(std::begin(kMatchedBytes), std::end(kMatchedBytes), &cgx_rom[i]); if (is_match) { @@ -41,7 +37,7 @@ void CgxViewer::LoadCgx(ROM &cgx_rom) { matching_position + sizeof(kMatchedBytes) + kOffsetFromMatchedBytesEnd; int bpp_marker = cgx_rom[bpp_marker_position]; std::string bpp_type = (bpp_marker == 0x31) ? "8bpp" : "4bpp"; - int current_selection_ = (bpp_type == "8bpp") ? 8 : 4; + current_selection_ = (bpp_type == "8bpp") ? 0 : 2; label1_text = absl::StrCat( "CGX In Folder L : ", absl::StrFormat("%X4", matching_position), " BPP Type : ", bpp_type); @@ -108,7 +104,7 @@ void CgxViewer::LoadGfx(int combo_bpp) { Bytes decomp_sheet = gfx::BPP8SNESToIndexed(raw_data_.vector(), bpp_); for (int i = 0; i < decomp_sheet.size(); i++) { - all_tiles_data_[i] = decomp_sheet[i]; + all_tiles_data_.push_back(decomp_sheet[i]); } RefreshPalettes();