Added Google Abseil library

This commit is contained in:
Justin Scofield
2022-07-23 16:33:52 -04:00
parent 8aa19eae7e
commit 9655b35363
12 changed files with 376 additions and 144 deletions

View File

@@ -1,18 +1,29 @@
# CMake Specifications ------------------------------------------------------------------------------------------- # CMake Specifications --------------------------------------------------------
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
# Yet Another Zelda3 Editor # Yet Another Zelda3 Editor
# by scawful # by scawful
project(yaze VERSION 0.01) project(yaze VERSION 0.01)
# C++ Standard Specifications ------------------------------------------------------------------------------------ # C++ Standard Specifications -------------------------------------------------
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MODULE_LINKER_FLAGS \"-Wl,--no-undefined -Wl,--no-undefined\")
set(BUILD_SHARED_LIBS ON)
# Abseil Standard Specifications ----------------------------------------------
set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_CXX_STANDARD 17)
set(ABSL_USE_GOOGLETEST_HEAD ON)
set(ABSL_ENABLE_INSTALL ON)
add_subdirectory(src/lib/abseil-cpp)
# Project Files # Project Files
add_subdirectory(src) add_subdirectory(src)

View File

@@ -36,26 +36,25 @@ target_include_directories(NintendoCompression PUBLIC "/usr/local/Cellar/libpng/
add_executable( add_executable(
yaze yaze
yaze.cc yaze.cc
app/core/common.cc
app/core/controller.cc
app/editor/assembly_editor.cc
app/editor/dungeon_editor.cc
app/editor/master_editor.cc
app/editor/overworld_editor.cc
app/editor/screen_editor.cc
app/gfx/bitmap.cc
app/gfx/pseudo_vram.cc
app/gfx/snes_palette.cc
app/gfx/snes_tile.cc
app/zelda3/overworld_map.cc
app/zelda3/overworld.cc
app/zelda3/screen.cc
app/rom.cc
gui/canvas.cc
gui/input.cc gui/input.cc
gui/style.cc gui/style.cc
gui/widgets.cc gui/widgets.cc
gui/canvas.cc
app/editor/master_editor.cc
app/editor/assembly_editor.cc
app/editor/dungeon_editor.cc
app/editor/overworld_editor.cc
app/editor/screen_editor.cc
app/rom.cc
app/core/common.cc
app/core/constants.cc
app/core/controller.cc
app/gfx/bitmap.cc
app/gfx/pseudo_vram.cc
app/gfx/snes_tile.cc
app/gfx/snes_palette.cc
app/zelda3/overworld.cc
app/zelda3/overworld_map.cc
app/zelda3/screen.cc
# GUI libraries # GUI libraries
${IMGUI_PATH}/imgui.cpp ${IMGUI_PATH}/imgui.cpp
${IMGUI_PATH}/imgui_demo.cpp ${IMGUI_PATH}/imgui_demo.cpp
@@ -80,9 +79,6 @@ target_include_directories(
${CMAKE_SOURCE_DIR}/src/ ${CMAKE_SOURCE_DIR}/src/
lib/ lib/
app/ app/
"C:/msys64/mingw64/include/libpng16"
"C:/msys64/mingw64/include/SDL2"
"C:/msys64/mingw64/include"
${SNESHACKING_PATH} ${SNESHACKING_PATH}
${PNG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}
${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR}
@@ -91,6 +87,10 @@ target_include_directories(
target_link_libraries( target_link_libraries(
yaze yaze
absl::strings
absl::flags
absl::status
absl::statusor
SDL2main SDL2main
${PNG_LIBRARIES} ${PNG_LIBRARIES}
${SDL2_LIBRARIES} ${SDL2_LIBRARIES}

View File

@@ -1 +0,0 @@
#include "app/core/constants.h"

View File

@@ -1,8 +1,9 @@
#ifndef YAZE_APP_CORE_CONSTANTS_H #ifndef YAZE_APP_CORE_CONSTANTS_H
#define YAZE_APP_CORE_CONSTANTS_H #define YAZE_APP_CORE_CONSTANTS_H
#include <array> #include <vector>
#include <string>
#include "absl/strings/string_view.h"
#define BASIC_BUTTON(w) if (ImGui::Button(w)) #define BASIC_BUTTON(w) if (ImGui::Button(w))
@@ -24,6 +25,7 @@
using ushort = unsigned short; using ushort = unsigned short;
using uint = unsigned int; using uint = unsigned int;
using uchar = unsigned char; using uchar = unsigned char;
using Bytes = std::vector<uchar>;
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -433,86 +435,86 @@ constexpr int crystalVertices = 0x04FF98;
//=========================================================================================== //===========================================================================================
// Names // Names
//=========================================================================================== //===========================================================================================
static const std::string RoomEffect[] = {"Nothing", static const absl::string_view RoomEffect[] = {"Nothing",
"Nothing", "Nothing",
"Moving Floor", "Moving Floor",
"Moving Water", "Moving Water",
"Trinexx Shell", "Trinexx Shell",
"Red Flashes", "Red Flashes",
"Light Torch to See Floor", "Light Torch to See Floor",
"Ganon's Darkness"}; "Ganon's Darkness"};
static const std::string RoomTag[] = {"Nothing", static const absl::string_view RoomTag[] = {"Nothing",
"NW Kill Enemy to Open", "NW Kill Enemy to Open",
"NE Kill Enemy to Open", "NE Kill Enemy to Open",
"SW Kill Enemy to Open", "SW Kill Enemy to Open",
"SE Kill Enemy to Open", "SE Kill Enemy to Open",
"W Kill Enemy to Open", "W Kill Enemy to Open",
"E Kill Enemy to Open", "E Kill Enemy to Open",
"N Kill Enemy to Open", "N Kill Enemy to Open",
"S Kill Enemy to Open", "S Kill Enemy to Open",
"Clear Quadrant to Open", "Clear Quadrant to Open",
"Clear Full Tile to Open", "Clear Full Tile to Open",
"NW Push Block to Open", "NW Push Block to Open",
"NE Push Block to Open", "NE Push Block to Open",
"SW Push Block to Open", "SW Push Block to Open",
"SE Push Block to Open", "SE Push Block to Open",
"W Push Block to Open", "W Push Block to Open",
"E Push Block to Open", "E Push Block to Open",
"N Push Block to Open", "N Push Block to Open",
"S Push Block to Open", "S Push Block to Open",
"Push Block to Open", "Push Block to Open",
"Pull Lever to Open", "Pull Lever to Open",
"Collect Prize to Open", "Collect Prize to Open",
"Hold Switch Open Door", "Hold Switch Open Door",
"Toggle Switch to Open Door", "Toggle Switch to Open Door",
"Turn off Water", "Turn off Water",
"Turn on Water", "Turn on Water",
"Water Gate", "Water Gate",
"Water Twin", "Water Twin",
"Moving Wall Right", "Moving Wall Right",
"Moving Wall Left", "Moving Wall Left",
"Crash", "Crash",
"Crash", "Crash",
"Push Switch Exploding Wall", "Push Switch Exploding Wall",
"Holes 0", "Holes 0",
"Open Chest (Holes 0)", "Open Chest (Holes 0)",
"Holes 1", "Holes 1",
"Holes 2", "Holes 2",
"Defeat Boss for Dungeon Prize", "Defeat Boss for Dungeon Prize",
"SE Kill Enemy to Push Block", "SE Kill Enemy to Push Block",
"Trigger Switch Chest", "Trigger Switch Chest",
"Pull Lever Exploding Wall", "Pull Lever Exploding Wall",
"NW Kill Enemy for Chest", "NW Kill Enemy for Chest",
"NE Kill Enemy for Chest", "NE Kill Enemy for Chest",
"SW Kill Enemy for Chest", "SW Kill Enemy for Chest",
"SE Kill Enemy for Chest", "SE Kill Enemy for Chest",
"W Kill Enemy for Chest", "W Kill Enemy for Chest",
"E Kill Enemy for Chest", "E Kill Enemy for Chest",
"N Kill Enemy for Chest", "N Kill Enemy for Chest",
"S Kill Enemy for Chest", "S Kill Enemy for Chest",
"Clear Quadrant for Chest", "Clear Quadrant for Chest",
"Clear Full Tile for Chest", "Clear Full Tile for Chest",
"Light Torches to Open", "Light Torches to Open",
"Holes 3", "Holes 3",
"Holes 4", "Holes 4",
"Holes 5", "Holes 5",
"Holes 6", "Holes 6",
"Agahnim Room", "Agahnim Room",
"Holes 7", "Holes 7",
"Holes 8", "Holes 8",
"Open Chest for Holes 8", "Open Chest for Holes 8",
"Push Block for Chest", "Push Block for Chest",
"Clear Room for Triforce Door", "Clear Room for Triforce Door",
"Light Torches for Chest", "Light Torches for Chest",
"Kill Boss Again"}; "Kill Boss Again"};
static const std::string SecretItemNames[] = { static const absl::string_view SecretItemNames[] = {
"Nothing", "Green Rupee", "Rock hoarder", "Bee", "Health pack", "Nothing", "Green Rupee", "Rock hoarder", "Bee", "Health pack",
"Bomb", "Heart ", "Blue Rupee", "Bomb", "Heart ", "Blue Rupee",
@@ -524,7 +526,7 @@ static const std::string SecretItemNames[] = {
"Hole", "Warp", "Staircase", "Bombable", "Switch"}; "Hole", "Warp", "Staircase", "Bombable", "Switch"};
static const std::string Type1RoomObjectNames[] = { static const absl::string_view Type1RoomObjectNames[] = {
"Ceiling ↔", "Ceiling ↔",
"Wall (top, north) ↔", "Wall (top, north) ↔",
"Wall (top, south) ↔", "Wall (top, south) ↔",
@@ -775,7 +777,7 @@ static const std::string Type1RoomObjectNames[] = {
"Nothing", "Nothing",
}; };
static const std::string Type2RoomObjectNames[] = { static const absl::string_view Type2RoomObjectNames[] = {
"Corner (top, concave) ▛", "Corner (top, concave) ▛",
"Corner (top, concave) ▙", "Corner (top, concave) ▙",
"Corner (top, concave) ▜", "Corner (top, concave) ▜",
@@ -842,7 +844,7 @@ static const std::string Type2RoomObjectNames[] = {
"Magic bat altar", "Magic bat altar",
}; };
static const std::string Type3RoomObjectNames[] = { static const absl::string_view Type3RoomObjectNames[] = {
"Waterfall face (empty)", "Waterfall face (empty)",
"Waterfall face (short)", "Waterfall face (short)",
"Waterfall face (long)", "Waterfall face (long)",
@@ -973,7 +975,7 @@ static const std::string Type3RoomObjectNames[] = {
"Nothing", "Nothing",
}; };
static const std::string TileTypeNames[] = { static const absl::string_view TileTypeNames[] = {
"$00 Nothing (standard floor)", "$00 Nothing (standard floor)",
"$01 Collision", "$01 Collision",
"$02 Collision", "$02 Collision",

View File

@@ -6,6 +6,7 @@
#include <imgui/imgui_memory_editor.h> #include <imgui/imgui_memory_editor.h>
#include <imgui/misc/cpp/imgui_stdlib.h> #include <imgui/misc/cpp/imgui_stdlib.h>
#include "absl/status/status.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/editor/assembly_editor.h" #include "app/editor/assembly_editor.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
@@ -22,15 +23,6 @@ namespace yaze {
namespace app { namespace app {
namespace editor { namespace editor {
MasterEditor::MasterEditor() {
for (int i = 0; i < 8; i++) {
current_palette_[i].x = (i * 0.21f);
current_palette_[i].y = (i * 0.21f);
current_palette_[i].z = (i * 0.21f);
current_palette_[i].w = 1.f;
}
}
MasterEditor::~MasterEditor() { rom_.Close(); } MasterEditor::~MasterEditor() { rom_.Close(); }
void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) { void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
@@ -59,6 +51,10 @@ void MasterEditor::UpdateScreen() {
DrawScreenEditor(); DrawScreenEditor();
END_TAB_BAR() END_TAB_BAR()
if (!status_.ok()) {
gui::widgets::DisplayStatus(status_);
}
ImGui::End(); ImGui::End();
} }
@@ -75,6 +71,7 @@ void MasterEditor::DrawYazeMenu() {
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
rom_.LoadFromFile(filePathName); rom_.LoadFromFile(filePathName);
status_ = rom_.OpenFromFile(filePathName);
overworld_editor_.SetupROM(rom_); overworld_editor_.SetupROM(rom_);
} }
ImGuiFileDialog::Instance()->Close(); ImGuiFileDialog::Instance()->Close();

View File

@@ -7,6 +7,7 @@
#include <imgui/imgui_memory_editor.h> #include <imgui/imgui_memory_editor.h>
#include <imgui/misc/cpp/imgui_stdlib.h> #include <imgui/misc/cpp/imgui_stdlib.h>
#include "absl/status/status.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/editor/assembly_editor.h" #include "app/editor/assembly_editor.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
@@ -25,7 +26,6 @@ namespace editor {
class MasterEditor { class MasterEditor {
public: public:
MasterEditor();
~MasterEditor(); ~MasterEditor();
void SetupScreen(std::shared_ptr<SDL_Renderer> renderer); void SetupScreen(std::shared_ptr<SDL_Renderer> renderer);
void UpdateScreen(); void UpdateScreen();
@@ -48,6 +48,8 @@ class MasterEditor {
DungeonEditor dungeon_editor_; DungeonEditor dungeon_editor_;
ScreenEditor screen_editor_; ScreenEditor screen_editor_;
absl::Status status_;
ImVec4 current_palette_[8]; ImVec4 current_palette_[8];
ImGuiWindowFlags main_editor_flags_ = ImGuiWindowFlags main_editor_flags_ =

View File

@@ -198,26 +198,26 @@ void OverworldEditor::DrawOverworldCanvas() {
overworld_map_canvas_.DrawBackground(); overworld_map_canvas_.DrawBackground();
overworld_map_canvas_.UpdateContext(); overworld_map_canvas_.UpdateContext();
overworld_map_canvas_.DrawGrid(64.f); overworld_map_canvas_.DrawGrid(64.f);
if (all_gfx_loaded_) { // if (all_gfx_loaded_) {
static bool tiles_made = false; // static bool tiles_made = false;
static std::vector<gfx::Bitmap> tiles; // static std::vector<gfx::Bitmap> tiles;
if (!tiles_made) { // if (!tiles_made) {
tiles = graphics_bin_.at(0).CreateTiles(); // tiles = graphics_bin_.at(0).CreateTiles();
auto renderer = rom_.Renderer(); // auto renderer = rom_.Renderer();
for (auto &tile : tiles) { // for (auto &tile : tiles) {
tile.CreateTexture(renderer); // tile.CreateTexture(renderer);
} // }
} // }
overworld_map_canvas_.GetDrawList()->AddImage( // overworld_map_canvas_.GetDrawList()->AddImage(
(void *)tiles[0].GetTexture(), // (void *)tiles[0].GetTexture(),
ImVec2(overworld_map_canvas_.GetZeroPoint().x + 2, // ImVec2(overworld_map_canvas_.GetZeroPoint().x + 2,
overworld_map_canvas_.GetZeroPoint().y + 2), // overworld_map_canvas_.GetZeroPoint().y + 2),
ImVec2( // ImVec2(
overworld_map_canvas_.GetZeroPoint().x + (tiles[0].GetWidth() * 2), // overworld_map_canvas_.GetZeroPoint().x + (tiles[0].GetWidth() *
overworld_map_canvas_.GetZeroPoint().y + // 2), overworld_map_canvas_.GetZeroPoint().y +
(tiles[0].GetHeight() * 2))); // (tiles[0].GetHeight() * 2)));
} // }
overworld_map_canvas_.DrawOverlay(); overworld_map_canvas_.DrawOverlay();
} }
@@ -309,6 +309,13 @@ void OverworldEditor::DrawAreaGraphics() {
} }
void OverworldEditor::LoadGraphics() { void OverworldEditor::LoadGraphics() {
for (int i = 0; i < 8; i++) {
current_palette_[i].x = (i * 0.21f);
current_palette_[i].y = (i * 0.21f);
current_palette_[i].z = (i * 0.21f);
current_palette_[i].w = 1.f;
}
rom_.LoadAllGraphicsData(); rom_.LoadAllGraphicsData();
graphics_bin_ = rom_.GetGraphicsBin(); graphics_bin_ = rom_.GetGraphicsBin();
tile16_blockset_bmp_.Create(128 * 2, 8192 * 2, 8, 1048576); tile16_blockset_bmp_.Create(128 * 2, 8192 * 2, 8, 1048576);

View File

@@ -9,6 +9,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/gfx/pseudo_vram.h" #include "app/gfx/pseudo_vram.h"
@@ -17,6 +22,24 @@
namespace yaze { namespace yaze {
namespace app { namespace app {
absl::Status ROM::OpenFromFile(const absl::string_view &filename) {
std::ifstream file(filename.data(), std::ios::binary);
if (!file.is_open()) {
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) {
char byte_to_read = ' ';
file.read(&byte_to_read, sizeof(char));
rom_data_[i] = byte_to_read;
}
file.close();
is_loaded_ = true;
return absl::OkStatus();
}
void ROM::Close() { void ROM::Close() {
if (is_loaded_) { if (is_loaded_) {
delete[] current_rom_; delete[] current_rom_;
@@ -187,6 +210,137 @@ uchar *ROM::Decompress(int pos, int size, bool reversed) {
return buffer; return buffer;
} }
absl::StatusOr<Bytes> ROM::DecompressV2(int offset, int size, bool reversed) {
Bytes buffer(size);
uint length = 0;
uint buffer_pos = 0;
uchar cmd = 0;
uchar databyte = rom_data_[offset];
while (databyte != 0xFF) { // End of decompression
databyte = rom_data_[offset];
// Expanded Command
if ((databyte & 0xE0) == 0xE0) {
cmd = ((databyte >> 2) & 0x07);
length = (((rom_data_[offset] << 8) | rom_data_[offset + 1]) & 0x3FF);
offset += 2; // Advance 2 bytes in ROM
} else { // Normal Command
cmd = ((databyte >> 5) & 0x07);
length = (databyte & 0x1F);
offset += 1; // Advance 1 byte in ROM
}
length += 1; // each commands is at least of size 1 even if index 00
switch (cmd) {
case kCommandDirectCopy:
for (int i = 0; i < length; i++) {
buffer[buffer_pos++] = rom_data_[offset++];
}
// Do not advance in the ROM
break;
case kCommandByteFill:
for (int i = 0; i < length; i++) {
buffer[buffer_pos++] = rom_data_[offset];
}
offset += 1; // Advance 1 byte in the ROM
break;
case kCommandWordFill:
for (int i = 0; i < length; i += 2) {
buffer[buffer_pos++] = rom_data_[offset];
buffer[buffer_pos++] = rom_data_[offset + 1];
}
offset += 2; // Advance 2 byte in the ROM
break;
case kCommandIncreasingFill: {
uchar inc_byte = rom_data_[offset];
for (int i = 0; i < length; i++) {
buffer[buffer_pos++] = inc_byte++;
}
offset += 1; // Advance 1 byte in the ROM
} break;
case kCommandRepeatingBytes: {
ushort s1 = ((rom_data_[offset + 1] & 0xFF) << 8);
ushort s2 = ((rom_data_[offset] & 0xFF));
// Reversed byte order for overworld maps
if (reversed) {
auto addr = (rom_data_[offset + 2]) | ((rom_data_[offset + 1]) << 8);
if (addr > buffer_pos) {
return absl::InternalError(
absl::StrFormat("DecompressOverworldV2: Offset for command "
"copy existing is larger than the current "
"position (Offset : %#04x | Pos %#06x\n",
addr, buffer_pos));
}
if (buffer_pos + length >= size) {
size *= 2;
buffer.resize(size);
std::cout << "DecompressOverworldV2: Reallocating buffer";
}
memcpy(buffer.data() + buffer_pos, rom_data_.data() + offset, length);
offset += 2;
} else {
auto addr = (ushort)(s1 | s2);
for (int i = 0; i < length; i++) {
buffer[buffer_pos] = buffer[addr + i];
buffer_pos++;
}
offset += 2; // Advance 2 bytes in the ROM
}
} break;
default: {
return absl::InternalError(
"DecompressV2: Invalid command in the header for decompression");
}
}
}
return buffer;
}
absl::StatusOr<Bytes> ROM::Convert3bppTo8bppSheet(Bytes sheet, int size) {
Bytes sheet_buffer_out(size);
int xx = 0; // positions where we are at on the sheet
int yy = 0;
int pos = 0;
int ypos = 0;
// for each tiles, 16 per line
for (int i = 0; i < 64; i++) {
// for each line
for (int y = 0; y < 8; y++) {
//[0] + [1] + [16]
for (int x = 0; x < 8; x++) {
auto b1 = ((sheet[(y * 2) + (24 * pos)] & (kGraphicsBitmap[x])));
auto b2 = (sheet[((y * 2) + (24 * pos)) + 1] & (kGraphicsBitmap[x]));
auto b3 = (sheet[(16 + y) + (24 * pos)] & (kGraphicsBitmap[x]));
unsigned char b = 0;
if (b1 != 0) {
b |= 1;
}
if (b2 != 0) {
b |= 2;
}
if (b3 != 0) {
b |= 4;
}
sheet_buffer_out[x + (xx) + (y * 128) + (yy * 1024)] = b;
}
}
pos++;
ypos++;
xx += 8;
if (ypos >= 16) {
yy++;
xx = 0;
ypos = 0;
}
}
return sheet_buffer_out;
}
// 128x32 // 128x32
uchar *ROM::SNES3bppTo8bppSheet(uchar *buffer_in, int sheet_id, int size) { uchar *ROM::SNES3bppTo8bppSheet(uchar *buffer_in, int sheet_id, int size) {
// 8bpp sheet out // 8bpp sheet out

View File

@@ -10,6 +10,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/gfx/pseudo_vram.h" #include "app/gfx/pseudo_vram.h"
@@ -18,12 +23,6 @@
namespace yaze { namespace yaze {
namespace app { namespace app {
struct OWMapTiles {
std::vector<std::vector<ushort>> light_world; // 64 maps * (32*32 tiles)
std::vector<std::vector<ushort>> dark_world; // 64 maps * (32*32 tiles)
std::vector<std::vector<ushort>> special_world; // 32 maps * (32*32 tiles)
} typedef OWMapTiles;
constexpr int kCommandDirectCopy = 0; constexpr int kCommandDirectCopy = 0;
constexpr int kCommandByteFill = 1; constexpr int kCommandByteFill = 1;
constexpr int kCommandWordFill = 2; constexpr int kCommandWordFill = 2;
@@ -31,8 +30,17 @@ constexpr int kCommandIncreasingFill = 3;
constexpr int kCommandRepeatingBytes = 4; constexpr int kCommandRepeatingBytes = 4;
constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10, constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
0x08, 0x04, 0x02, 0x01}; 0x08, 0x04, 0x02, 0x01};
struct OWMapTiles {
std::vector<std::vector<ushort>> light_world; // 64 maps * (32*32 tiles)
std::vector<std::vector<ushort>> dark_world; // 64 maps * (32*32 tiles)
std::vector<std::vector<ushort>> special_world; // 32 maps * (32*32 tiles)
} typedef OWMapTiles;
class ROM { class ROM {
public: public:
absl::Status OpenFromFile(const absl::string_view& filename);
void Close(); void Close();
void SetupRenderer(std::shared_ptr<SDL_Renderer> renderer); void SetupRenderer(std::shared_ptr<SDL_Renderer> renderer);
void LoadFromFile(const std::string& path); void LoadFromFile(const std::string& path);
@@ -44,6 +52,11 @@ class ROM {
uchar* DecompressGraphics(int pos, int size); uchar* DecompressGraphics(int pos, int size);
uchar* DecompressOverworld(int pos, int size); uchar* DecompressOverworld(int pos, int size);
uchar* Decompress(int pos, int size = 0x800, bool reversed = false); uchar* Decompress(int pos, int size = 0x800, bool reversed = false);
absl::StatusOr<Bytes> DecompressV2(int offset, int size = 0x800,
bool reversed = false);
absl::StatusOr<Bytes> Convert3bppTo8bppSheet(Bytes sheet, int size = 0x1000);
uchar* SNES3bppTo8bppSheet(uchar* buffer_in, int sheet_id = 0, uchar* SNES3bppTo8bppSheet(uchar* buffer_in, int sheet_id = 0,
int size = 0x1000); int size = 0x1000);
@@ -69,6 +82,8 @@ class ROM {
ImVec4 display_palette_[8]; ImVec4 display_palette_[8];
gfx::pseudo_vram pseudo_vram_; gfx::pseudo_vram pseudo_vram_;
std::vector<uchar> rom_data_;
std::vector<uchar*> decompressed_graphic_sheets_; std::vector<uchar*> decompressed_graphic_sheets_;
std::vector<uchar*> converted_graphic_sheets_; std::vector<uchar*> converted_graphic_sheets_;
std::shared_ptr<SDL_Renderer> sdl_renderer_; std::shared_ptr<SDL_Renderer> sdl_renderer_;

View File

@@ -1,15 +1,53 @@
#include "widgets.h" #include "widgets.h"
#include <ImGuiColorTextEdit/TextEditor.h>
#include "absl/status/status.h"
#include "app/core/constants.h" #include "app/core/constants.h"
namespace yaze { namespace yaze {
namespace gui { namespace gui {
namespace widgets { namespace widgets {
bool BeginCentered(const char *name) {
ImGuiIO &io = ImGui::GetIO();
ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGuiWindowFlags flags = ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_AlwaysAutoResize;
return ImGui::Begin(name, nullptr, flags);
}
void DisplayStatus(const absl::Status &status) {
static bool display_open = true;
if (display_open) {
auto title = absl::StrCat("StatusWindow_", status.ToString()).data();
if (BeginCentered(title)) {
ImGui::Text(status.ToString().data());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(270);
// click ok when finished adjusting
if (ImGui::Button("OK", ImVec2(200, 0))) {
display_open = false;
}
ImGui::End();
}
}
}
TextEditor::LanguageDefinition GetAssemblyLanguageDef() { TextEditor::LanguageDefinition GetAssemblyLanguageDef() {
TextEditor::LanguageDefinition language_65816; TextEditor::LanguageDefinition language_65816;
for (auto &k : app::core::kKeywords) for (auto &k : app::core::kKeywords) language_65816.mKeywords.emplace(k);
language_65816.mKeywords.emplace(k);
for (auto &k : app::core::kIdentifiers) { for (auto &k : app::core::kIdentifiers) {
TextEditor::Identifier id; TextEditor::Identifier id;

View File

@@ -3,13 +3,18 @@
#include <ImGuiColorTextEdit/TextEditor.h> #include <ImGuiColorTextEdit/TextEditor.h>
#include "absl/status/status.h"
#include "app/core/constants.h"
namespace yaze { namespace yaze {
namespace gui { namespace gui {
namespace widgets { namespace widgets {
void DisplayStatus(const absl::Status& status);
TextEditor::LanguageDefinition GetAssemblyLanguageDef(); TextEditor::LanguageDefinition GetAssemblyLanguageDef();
} } // namespace widgets
} // namespace gui } // namespace gui
} // namespace yaze } // namespace yaze

View File

@@ -4,12 +4,12 @@ FetchContent_Declare(
googletest googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
) )
# For Windows: Prevent overriding the parent project's compiler/linker settings # For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest) FetchContent_MakeAvailable(googletest)
enable_testing() enable_testing()
find_package(PNG REQUIRED)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
set(SNESHACKING_PATH "../src/lib/sneshacking/src") set(SNESHACKING_PATH "../src/lib/sneshacking/src")
@@ -26,7 +26,6 @@ add_executable(
${SNESHACKING_PATH}/compressions/alttpcompression.c ${SNESHACKING_PATH}/compressions/alttpcompression.c
${SNESHACKING_PATH}/compressions/stdnintendo.c ${SNESHACKING_PATH}/compressions/stdnintendo.c
${SNESHACKING_PATH}/tile.c ${SNESHACKING_PATH}/tile.c
${SNESHACKING_PATH}/tilepng.c
${SNESHACKING_PATH}/palette.c ${SNESHACKING_PATH}/palette.c
${SNESHACKING_PATH}/rommapping.c ${SNESHACKING_PATH}/rommapping.c
${SNESHACKING_PATH}/mapping_lorom.c ${SNESHACKING_PATH}/mapping_lorom.c
@@ -42,7 +41,10 @@ target_include_directories(
target_link_libraries( target_link_libraries(
yaze_test yaze_test
${PNG_LIBRARIES} absl::strings
absl::flags
absl::status
absl::statusor
${SDL2_LIBRARIES} ${SDL2_LIBRARIES}
${OPENGL_LIBRARIES} ${OPENGL_LIBRARIES}
NintendoCompression NintendoCompression