diff --git a/.gitmodules b/.gitmodules index d9187dcb..0fd02803 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "src/Library/ImGuiColorTextEdit"] path = src/Library/ImGuiColorTextEdit url = https://github.com/BalazsJako/ImGuiColorTextEdit.git +[submodule "src/Library/sneshacking"] + path = src/Library/sneshacking + url = https://github.com/Skarsnik/sneshacking.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 567fbce9..7e37c40c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ project(yaze VERSION 0.01) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) +set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Project Files add_subdirectory(src) diff --git a/src/Application/Core/Style.h b/src/Application/Core/Style.h index a9b2d0e7..8699df13 100644 --- a/src/Application/Core/Style.h +++ b/src/Application/Core/Style.h @@ -40,10 +40,6 @@ inline static void StyleColorsYaze() { ImVec4 allttpLightGreen = ImVec4(0.36f, 0.45f, 0.36f, 1.0f); ImVec4 allttpLightestGreen = ImVec4(0.49f, 0.57f, 0.49f, 1.0f); - ImVec4 alttpBlue = ImVec4(0.f, 0.f, 0.47f, 1.0f); - ImVec4 alttpBlueHover = ImVec4(0.f, 0.f, 0.57f, 1.0f); - ImVec4 alttpBlueActive = ImVec4(0.f, 0.f, 0.67f, 1.0f); - colors[ImGuiCol_MenuBarBg] = alttpDarkGreen; colors[ImGuiCol_TitleBg] = alttpMidGreen; diff --git a/src/Application/Data/Overworld.cc b/src/Application/Data/Overworld.cc index 1a93a9ca..cc575b7b 100644 --- a/src/Application/Data/Overworld.cc +++ b/src/Application/Data/Overworld.cc @@ -10,7 +10,7 @@ using namespace Core; using namespace Graphics; Overworld::~Overworld() { - for (int i = 0; i < tiles32.size(); i++) { + for (int i = 0; i < (int) tiles32.size(); i++) { free(allmapsTilesLW[i]); free(allmapsTilesDW[i]); free(allmapsTilesSP[i]); diff --git a/src/Application/Editor/OverworldEditor.cc b/src/Application/Editor/OverworldEditor.cc index a288e111..a47c3210 100644 --- a/src/Application/Editor/OverworldEditor.cc +++ b/src/Application/Editor/OverworldEditor.cc @@ -14,17 +14,8 @@ void OverworldEditor::Update() { if (!doneLoaded) { overworld.Load(rom_); Graphics::CreateAllGfxData(rom_.GetRawData(), allGfx16Ptr); - - // allgfxBitmap.LoadBitmapFromROM(allGfx16Ptr, allgfx_texture, - // &allgfx_width, - // &allgfx_height); doneLoaded = true; } - // Graphics::tile8 all_tiles; - // all_tiles.id = 1; - // all_tiles.data = - // Graphics::export_tile_to_png(tile8 rawtile, const r_palette pal, const - // char *filename) } if (show_changelist_) { @@ -279,11 +270,10 @@ void OverworldEditor::DrawTileSelector() { void OverworldEditor::DrawChangelist() { if (!ImGui::Begin("Changelist")) { - + ImGui::End(); } - - + ImGui::Text("Test"); ImGui::End(); } diff --git a/src/Application/Graphics/Bitmap.h b/src/Application/Graphics/Bitmap.h index 0498b144..1fe30514 100644 --- a/src/Application/Graphics/Bitmap.h +++ b/src/Application/Graphics/Bitmap.h @@ -2,11 +2,11 @@ #define YAZE_APPLICATION_UTILS_BITMAP_H #include -// #include +#include #include -#include "GL/glew.h" +// #include "GL/glew.h" #include "Utils/ROM.h" namespace yaze { @@ -17,7 +17,7 @@ using byte = unsigned char; using namespace Core; class Bitmap { -public: + public: Bitmap() = default; Bitmap(int width, int height, byte *data); @@ -28,7 +28,7 @@ public: bool LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture, int *out_width, int *out_height); -private: + private: int width_; int height_; byte *pixel_data_; @@ -36,12 +36,12 @@ private: static bool isbpp3[Constants::NumberOfSheets]; -int GetPCGfxAddress(byte* romData, byte id); -byte* CreateAllGfxDataRaw(byte* romData); -void CreateAllGfxData(byte* romData, byte* allgfx16Ptr); +int GetPCGfxAddress(byte *romData, byte id); +byte *CreateAllGfxDataRaw(byte *romData); +void CreateAllGfxData(byte *romData, byte *allgfx16Ptr); -} // namespace Graphics -} // namespace Application -} // namespace yaze +} // namespace Graphics +} // namespace Application +} // namespace yaze #endif \ No newline at end of file diff --git a/src/Application/Graphics/Tile.cc b/src/Application/Graphics/Tile.cc index c3ddf726..48feb04c 100644 --- a/src/Application/Graphics/Tile.cc +++ b/src/Application/Graphics/Tile.cc @@ -1,12 +1,12 @@ #include "Tile.h" -#include - #include #include #include #include +#include "png.h" + namespace yaze { namespace Application { namespace Graphics { @@ -39,6 +39,56 @@ char *hexString(const char *str, const unsigned int size) { return toret; } +void export_all_gfx_to_png(byte *tiledata) { + + auto tile = unpack_bpp3_tile(tiledata, 0); + Graphics::r_palette *pal = palette_create(8, 0); + + for (unsigned int i = 0; i < 8; i++) { + pal->colors[i].red = i * 30; + pal->colors[i].blue = i * 30; + pal->colors[i].green = i * 30; + } + + FILE *fp = fopen("test.png", "wb"); + png_structp png_ptr = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_infop info_ptr = png_create_info_struct(png_ptr); + png_init_io(png_ptr, fp); + png_set_strip_alpha(png_ptr); + png_read_update_info(png_ptr, info_ptr); + + png_color *png_palette = + (png_color *)png_malloc(png_ptr, pal->size * sizeof(png_color)); + + for (unsigned int i = 0; i < pal->size; i++) { + png_palette[i].blue = pal->colors[i].blue; + png_palette[i].green = pal->colors[i].green; + png_palette[i].red = pal->colors[i].red; + } + png_set_IHDR(png_ptr, info_ptr, 8, 8, 8, PNG_COLOR_TYPE_PALETTE, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); + png_set_PLTE(png_ptr, info_ptr, png_palette, pal->size); + + png_write_info(png_ptr, info_ptr); + png_set_packing(png_ptr); + + png_byte *row_pointers[8]; + for (unsigned int i = 0; i < 8; i++) { + row_pointers[i] = (png_byte *)png_malloc(png_ptr, sizeof(png_byte)); + memcpy(row_pointers[i], tile.data + i * 8, 8); + } + + png_write_image(png_ptr, row_pointers); + + png_write_end(png_ptr, info_ptr); + png_destroy_write_struct(&png_ptr, &info_ptr); + + png_free(png_ptr, png_palette); + png_free(png_ptr, row_pointers); +} + void export_tile_to_png(tile8 rawtile, const r_palette pal, const char *filename) { FILE *fp = fopen(filename, "wb"); @@ -80,37 +130,37 @@ void export_tile_to_png(tile8 rawtile, const r_palette pal, png_free(png_ptr, row_pointers); } -tile8 unpack_bpp1_tile(const char *data, const unsigned int offset) { +tile8 unpack_bpp1_tile(const byte *data, const unsigned int offset) { return (unpack_bpp_tile(data, offset, 1)); } -tile8 unpack_bpp2_tile(const char *data, const unsigned int offset) { +tile8 unpack_bpp2_tile(const byte *data, const unsigned int offset) { return (unpack_bpp_tile(data, offset, 2)); } -tile8 unpack_bpp3_tile(const char *data, const unsigned int offset) { +tile8 unpack_bpp3_tile(const byte *data, const unsigned int offset) { return (unpack_bpp_tile(data, offset, 3)); } -tile8 unpack_bpp4_tile(const char *data, const unsigned int offset) { +tile8 unpack_bpp4_tile(const byte *data, const unsigned int offset) { return (unpack_bpp_tile(data, offset, 4)); } -tile8 unpack_bpp8_tile(const char *data, const unsigned int offset) { +tile8 unpack_bpp8_tile(const byte *data, const unsigned int offset) { return (unpack_bpp_tile(data, offset, 8)); } -tile8 unpack_mode7_tile(const char *data, const unsigned int offset) { +tile8 unpack_mode7_tile(const byte *data, const unsigned int offset) { tile8 tile; memcpy(tile.data, data + offset, 64); return tile; } -tile8 unpack_bpp_tile(const char *data, const unsigned int offset, +tile8 unpack_bpp_tile(const byte *data, const unsigned int offset, const unsigned bpp) { tile8 tile; assert(bpp >= 1 && bpp <= 8); - unsigned int bpp_pos[8]; // More for conveniance and readibility + unsigned int bpp_pos[8]; // More for conveniance and readibility for (int col = 0; col < 8; col++) { for (int row = 0; row < 8; row++) { if (bpp == 1) { @@ -189,17 +239,14 @@ byte *pack_bpp_tile(tile8 tile, const unsigned int bpp, unsigned int *size) { for (unsigned int col = 0; col < 8; col++) { for (unsigned int row = 0; row < 8; row++) { byte color = tile.data[col * 8 + row]; - if (color > maxcolor) - return NULL; + if (color > maxcolor) return NULL; - if (bpp == 1) - output[col] += (byte)((color & 1) << (7 - row)); + if (bpp == 1) output[col] += (byte)((color & 1) << (7 - row)); if (bpp >= 2) { output[col * 2] += (byte)((color & 1) << (7 - row)); output[col * 2 + 1] += (byte)(((color & 2) == 2) << (7 - row)); } - if (bpp == 3) - output[16 + col] += (byte)(((color & 4) == 4) << (7 - row)); + if (bpp == 3) output[16 + col] += (byte)(((color & 4) == 4) << (7 - row)); if (bpp >= 4) { output[16 + col * 2] += (byte)(((color & 4) == 4) << (7 - row)); output[16 + col * 2 + 1] += (byte)(((color & 8) == 8) << (7 - row)); @@ -216,6 +263,6 @@ byte *pack_bpp_tile(tile8 tile, const unsigned int bpp, unsigned int *size) { return output; } -} // namespace Graphics -} // namespace Application -} // namespace yaze +} // namespace Graphics +} // namespace Application +} // namespace yaze diff --git a/src/Application/Graphics/Tile.h b/src/Application/Graphics/Tile.h index 2234fd4f..3928af30 100644 --- a/src/Application/Graphics/Tile.h +++ b/src/Application/Graphics/Tile.h @@ -18,17 +18,17 @@ extern "C" { typedef struct { unsigned int id; - char data[64]; + byte data[64]; unsigned int palette_id; } tile8; -tile8 unpack_bpp8_tile(const char* data, const unsigned int offset); -tile8 unpack_bpp4_tile(const char* data, const unsigned int offset); -tile8 unpack_bpp3_tile(const char* data, const unsigned int offset); -tile8 unpack_bpp2_tile(const char* data, const unsigned int offset); -tile8 unpack_bpp1_tile(const char* data, const unsigned int offset); +tile8 unpack_bpp8_tile(const byte* data, const unsigned int offset); +tile8 unpack_bpp4_tile(const byte* data, const unsigned int offset); +tile8 unpack_bpp3_tile(const byte* data, const unsigned int offset); +tile8 unpack_bpp2_tile(const byte* data, const unsigned int offset); +tile8 unpack_bpp1_tile(const byte* data, const unsigned int offset); -tile8 unpack_bpp_tile(const char* data, const unsigned int offset, +tile8 unpack_bpp_tile(const byte* data, const unsigned int offset, const unsigned int bpp); byte* pack_bpp1_tile(const tile8 tile); @@ -40,6 +40,8 @@ byte* pack_bpp8_tile(const tile8 tile); byte* pack_bpp_tile(const tile8 tile, const unsigned int bpp, unsigned int* size); +void export_all_gfx_to_png(byte* tiledata); + void export_tile_to_png(tile8 rawtile, const r_palette pal, const char* filename); } diff --git a/src/Application/Utils/Compression.cc b/src/Application/Utils/Compression.cc index 5c4359d9..03985b9b 100644 --- a/src/Application/Utils/Compression.cc +++ b/src/Application/Utils/Compression.cc @@ -10,6 +10,9 @@ #include #include +#include "compressions/stdnintendo.h" +#include "compressions/alttpcompression.h" + #define INITIAL_ALLOC_SIZE 1024 #define D_CMD_COPY 0 @@ -38,6 +41,7 @@ unsigned char* ALTTPCompression::DecompressGfx(const unsigned char* c_data, unsigned int max_length, unsigned int* uncompressed_data_size, unsigned int* compressed_length) { + char* data = alttp_decompress_gfx((char*) c_data, start, max_length, uncompressed_data_size, compressed_length); unsigned char* toret = std_nintendo_.Decompress(c_data, start, max_length, uncompressed_data_size, compressed_length, D_NINTENDO_C_MODE2); diff --git a/src/Application/Utils/ROM.cc b/src/Application/Utils/ROM.cc index cb9954dc..1bfa88f8 100644 --- a/src/Application/Utils/ROM.cc +++ b/src/Application/Utils/ROM.cc @@ -14,33 +14,29 @@ char *rommapping_error_text; /* * LoRoM is quite easy */ -int lorom_snes_to_pc(const unsigned int snes_addr, char** info) -{ - unsigned char bank = snes_addr >> 16; - unsigned int offset = snes_addr & 0x00FFFF; - //printf("snes_addr: %X - Bank: %X - Offset: %X\n", snes_addr, bank, offset); - +int lorom_snes_to_pc(const unsigned int snes_addr, char **info) { + unsigned char bank = snes_addr >> 16; + unsigned int offset = snes_addr & 0x00FFFF; + // printf("snes_addr: %X - Bank: %X - Offset: %X\n", snes_addr, bank, offset); + // 80-FD is a mirror to the start if (bank >= 0x80 && bank <= 0xFD) bank -= 0x80; - if (bank >= 0x00 && bank <= 0x3F && offset < 0x8000 && offset >= 0x2000) - { + if (bank >= 0x00 && bank <= 0x3F && offset < 0x8000 && offset >= 0x2000) { *info = "SNES Reserved"; return ROMMAPPING_LOCATION_SNES_RESERVED; } - if ((((bank >= 0x70 && bank <= 0x7D) || bank == 0xFE || bank == 0xFF) && offset < 0x8000)) - { + if ((((bank >= 0x70 && bank <= 0x7D) || bank == 0xFE || bank == 0xFF) && + offset < 0x8000)) { *info = "SRAM"; return ROMMAPPING_LOCATION_SRAM; } - if (bank == 0x7E || bank == 0x7F || - (bank >= 0x00 && bank <= 0x3F && offset < 0x2000) - ) - { + if (bank == 0x7E || bank == 0x7F || + (bank >= 0x00 && bank <= 0x3F && offset < 0x2000)) { *info = "WRAM section"; return ROMMAPPING_LOCATION_WRAM; } - + if (bank >= 0x40 && bank <= 0x6F && offset < 0x8000) return bank * 0x8000 + offset; if (bank == 0xFE || bank == 0xFF) // this work as if 7E was regular bank @@ -48,35 +44,30 @@ int lorom_snes_to_pc(const unsigned int snes_addr, char** info) return bank * 0x8000 + (offset - 0x8000); } -int hirom_snes_to_pc(const unsigned int snes_addr, char **info) -{ - unsigned char bank = snes_addr >> 16; - unsigned int offset = snes_addr & 0x00FFFF; - +int hirom_snes_to_pc(const unsigned int snes_addr, char **info) { + unsigned char bank = snes_addr >> 16; + unsigned int offset = snes_addr & 0x00FFFF; + // 80-FD is a mirror to the start if (bank >= 0x80 && bank <= 0xFD) bank -= 0x80; - + if ((bank >= 0x00 && bank <= 0x1F && offset < 0x8000 && offset >= 0x2000) || - (bank >= 0x20 && bank <= 0x3F && offset < 0x6000 && offset >= 0x2000) - ) - { + (bank >= 0x20 && bank <= 0x3F && offset < 0x6000 && offset >= 0x2000)) { *info = "SNES Reserved"; return ROMMAPPING_LOCATION_SNES_RESERVED; } - if (bank >= 0x20 && bank <= 0x3F && offset >= 0x6000 && offset < 0x8000) - { + if (bank >= 0x20 && bank <= 0x3F && offset >= 0x6000 && offset < 0x8000) { *info = "SRAM"; return ROMMAPPING_LOCATION_SRAM; } if ((bank == 0x7E || bank == 0x7F) || - (bank >= 0x00 && bank <= 0x3F && offset < 0x2000)) - { + (bank >= 0x00 && bank <= 0x3F && offset < 0x2000)) { *info = "WRAM Section"; return ROMMAPPING_LOCATION_WRAM; } -/*#include - printf("%02X:%04X\n", bank, offset);*/ + /*#include + printf("%02X:%04X\n", bank, offset);*/ if (bank >= 0xFE) bank -= 0xFE - 0x3E; if (bank >= 0x40 && bank <= 0x7D) @@ -84,93 +75,86 @@ int hirom_snes_to_pc(const unsigned int snes_addr, char **info) return (bank << 16) + offset; } -int hirom_pc_to_snes(const unsigned int pc_addr) -{ +int hirom_pc_to_snes(const unsigned int pc_addr) { unsigned int bank = pc_addr >> 16; unsigned int offset = pc_addr & 0x00FFFF; - //printf("%02X:%04X\n", bank, offset); + // printf("%02X:%04X\n", bank, offset); if (bank <= 0x3F && offset >= 0x8000) - return pc_addr; + return pc_addr; if (bank <= 0x3D) - return pc_addr + 0x400000; + return pc_addr + 0x400000; return pc_addr + 0xFE0000; } -int hirom_sram_snes_to_pc(const unsigned int snes_addr) -{ - unsigned int bank = snes_addr >> 16; - unsigned int offset = snes_addr & 0x00FFFF; +int hirom_sram_snes_to_pc(const unsigned int snes_addr) { + unsigned int bank = snes_addr >> 16; + unsigned int offset = snes_addr & 0x00FFFF; - if (bank >= 0x20 && bank <= 0x3F && offset >= 0x6000 && offset < 0x8000) - return (bank - 0x20) * 0x2000 + (offset - 0x6000); + if (bank >= 0x20 && bank <= 0x3F && offset >= 0x6000 && offset < 0x8000) + return (bank - 0x20) * 0x2000 + (offset - 0x6000); + return -1; +} + +int hirom_sram_pc_to_snes(const unsigned int pc_addr) { + unsigned int chuck_nb = pc_addr / 0x2000; + unsigned int rest = pc_addr % 0x2000; + + return ((0x20 + chuck_nb) << 16) + 0x6000 + rest; +} + +int lorom_pc_to_snes(const unsigned int pc_addr) { + + unsigned int bank = pc_addr / 0x8000; + unsigned int offset = pc_addr % 0x8000 + 0x8000; + + // printf("pc_addr: %X - Bank: %X - Offset: %X\n", pc_addr, bank, offset); + + return (bank << 16) + offset; +} + +int lorom_sram_pc_to_snes(const unsigned int pc_addr) { + int chuck_nb = pc_addr / 0x8000; + int rest = pc_addr % 0x8000; + + if (chuck_nb <= 0xD) + return ((0x70 + chuck_nb) << 16) + rest; + if (chuck_nb == 0xE || chuck_nb == 0xF) + return ((0xF0 + chuck_nb) << 16) + rest; + return -1; +} + +int lorom_sram_snes_to_pc(const unsigned int snes_addr) { + unsigned char bank = snes_addr >> 16; + unsigned int offset = snes_addr & 0x00FFFF; + + // F0-FD are mirror of 70-7D + if (bank >= 0xF0 && bank <= 0xFD) + bank -= 0x80; + if (bank >= 0x70 && bank <= 0x7D && offset < 0x8000) + return (bank - 0x70) * 0x8000 + offset; + if ((bank == 0xFE || bank == 0xFF) && offset < 0x8000) + return ((bank - 0xFE) + 0xE) * 0x8000 + offset; + return -1; +} + +int rommapping_snes_to_pc(const unsigned int snes_addr, enum rom_type rom_type, + bool header) { + int pc_addr; + char *info; + switch (rom_type) { + case LoROM: + pc_addr = lorom_snes_to_pc(snes_addr, &info); + break; + case HiROM: + pc_addr = hirom_snes_to_pc(snes_addr, &info); + break; + default: return -1; -} - -int hirom_sram_pc_to_snes(const unsigned int pc_addr) -{ - unsigned int chuck_nb = pc_addr / 0x2000; - unsigned int rest = pc_addr % 0x2000; - - return ((0x20 + chuck_nb) << 16) + 0x6000 + rest; -} - -int lorom_pc_to_snes(const unsigned int pc_addr) -{ - - unsigned int bank = pc_addr / 0x8000; - unsigned int offset = pc_addr % 0x8000 + 0x8000; - - //printf("pc_addr: %X - Bank: %X - Offset: %X\n", pc_addr, bank, offset); - - return (bank << 16) + offset; -} - -int lorom_sram_pc_to_snes(const unsigned int pc_addr) -{ - int chuck_nb = pc_addr / 0x8000; - int rest = pc_addr % 0x8000; - - if (chuck_nb <= 0xD) - return ((0x70 + chuck_nb) << 16) + rest; - if (chuck_nb == 0xE || chuck_nb == 0xF) - return ((0xF0 + chuck_nb) << 16) + rest; - return -1; -} - -int lorom_sram_snes_to_pc(const unsigned int snes_addr) -{ - unsigned char bank = snes_addr >> 16; - unsigned int offset = snes_addr & 0x00FFFF; - - // F0-FD are mirror of 70-7D - if (bank >= 0xF0 && bank <= 0xFD) - bank -= 0x80; - if (bank >= 0x70 && bank <= 0x7D && offset < 0x8000) - return (bank - 0x70) * 0x8000 + offset; - if ((bank == 0xFE || bank == 0xFF) && offset < 0x8000) - return ((bank - 0xFE) + 0xE) * 0x8000 + offset; - return -1; -} - -int rommapping_snes_to_pc(const unsigned int snes_addr, enum rom_type rom_type, bool header) -{ - int pc_addr; - char *info; - switch (rom_type) - { - case LoROM: - pc_addr = lorom_snes_to_pc(snes_addr, &info); - break; - case HiROM: - pc_addr = hirom_snes_to_pc(snes_addr, &info); - break; - default: - return -1; } if (pc_addr < 0) { - rommapping_error_text = (char *) malloc(strlen(info) + 1); + rommapping_error_text = (char *)malloc(strlen(info) + 1); strcpy(rommapping_error_text, info); return pc_addr; } @@ -179,98 +163,92 @@ int rommapping_snes_to_pc(const unsigned int snes_addr, enum rom_type rom_type, return pc_addr; } -int rommapping_pc_to_snes(const unsigned int pc_addr, enum rom_type rom_type, bool header) -{ +int rommapping_pc_to_snes(const unsigned int pc_addr, enum rom_type rom_type, + bool header) { int snes_addr; - - switch (rom_type) - { - case LoROM: - snes_addr = lorom_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); - break; - case HiROM: - snes_addr = hirom_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); - break; - default: - return -1; + + switch (rom_type) { + case LoROM: + snes_addr = lorom_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); + break; + case HiROM: + snes_addr = hirom_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); + break; + default: + return -1; } return snes_addr; } - -int rommapping_sram_snes_to_pc(const unsigned int snes_addr, enum rom_type rom_type, bool header) -{ +int rommapping_sram_snes_to_pc(const unsigned int snes_addr, + enum rom_type rom_type, bool header) { int pc_addr; - switch (rom_type) - { - case LoROM: - pc_addr = lorom_sram_snes_to_pc(snes_addr); - break; - case HiROM: - pc_addr = hirom_sram_snes_to_pc(snes_addr); - break; - default: - return -1; + switch (rom_type) { + case LoROM: + pc_addr = lorom_sram_snes_to_pc(snes_addr); + break; + case HiROM: + pc_addr = hirom_sram_snes_to_pc(snes_addr); + break; + default: + return -1; } if (header) pc_addr += 0x200; return pc_addr; } -int rommapping_sram_pc_to_snes(const unsigned int pc_addr, enum rom_type rom_type, bool header) -{ +int rommapping_sram_pc_to_snes(const unsigned int pc_addr, + enum rom_type rom_type, bool header) { int snes_addr; - - switch (rom_type) - { - case LoROM: - snes_addr = lorom_sram_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); - break; - case HiROM: - snes_addr = hirom_sram_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); - break; - default: - return -1; + + switch (rom_type) { + case LoROM: + snes_addr = lorom_sram_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); + break; + case HiROM: + snes_addr = hirom_sram_pc_to_snes(header ? pc_addr - 0x200 : pc_addr); + break; + default: + return -1; } return snes_addr; } -void ROM::LoadFromFile(const std::string& path) { +void ROM::LoadFromFile(const std::string &path) { - FILE * file = fopen(path.c_str(), "r+"); - if (file == NULL) return; + FILE *file = fopen(path.c_str(), "r+"); + if (file == NULL) + return; fseek(file, 0, SEEK_END); size = ftell(file); fclose(file); // Reading data to array of unsigned chars file = fopen(path.c_str(), "r+"); - current_rom_ = (unsigned char *) malloc(size); + current_rom_ = (unsigned char *)malloc(size); int bytes_read = fread(current_rom_, sizeof(unsigned char), size, file); fclose(file); - memcpy(title, current_rom_, 21); - + memcpy(title, current_rom_ + 32704, 21); + type = LoROM; fastrom = (current_rom_[21] & 0b00110000) == 0b00110000; if (current_rom_[21] & 1) - type = HiROM; + type = HiROM; if ((current_rom_[21] & 0b00000111) == 0b00000111) - type = ExHiROM; + type = ExHiROM; sram_size = 0x400 << current_rom_[24]; - creator_id = (current_rom_[26] << 8) | current_rom_[25]; + creator_id = (current_rom_[26] << 8) | current_rom_[25]; version = current_rom_[27]; checksum_comp = (current_rom_[29] << 8) | current_rom_[28]; checksum = (current_rom_[31] << 8) | current_rom_[30]; make_sense = false; if ((checksum ^ checksum_comp) == 0xFFFF) - make_sense = true; + make_sense = true; loaded = true; - - - } int ROM::SnesToPc(int addr) { @@ -293,8 +271,8 @@ int ROM::PcToSnes(int addr) { b[1] += 0x80; } - //return BitConverter.ToInt32(b, 0); - // snes always have + 0x8000 no matter what, the bank on pc is always / 2 + // return BitConverter.ToInt32(b, 0); + // snes always have + 0x8000 no matter what, the bank on pc is always / 2 return ((addr * 2) & 0xFF0000) + (addr & 0x7FFF) + 0x8000; } @@ -339,6 +317,6 @@ short ROM::ReadReverseShort(int addr) { return (short)((current_rom_[addr] << 8) + current_rom_[addr + 1]); } -} // namespace Utils -} // namespace Application -} // namespace yaze \ No newline at end of file +} // namespace Utils +} // namespace Application +} // namespace yaze \ No newline at end of file diff --git a/src/Application/Utils/ROM.h b/src/Application/Utils/ROM.h index b41d04ea..723ae2f3 100644 --- a/src/Application/Utils/ROM.h +++ b/src/Application/Utils/ROM.h @@ -1,8 +1,6 @@ #ifndef YAZE_APPLICATION_UTILS_ROM_H #define YAZE_APPLICATION_UTILS_ROM_H -#include - #include #include #include @@ -73,9 +71,6 @@ class ROM { bool isLoaded() const { return loaded; } private: - std::vector original_rom_; - std::vector working_rom_; - bool loaded = false; byte* current_rom_; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ffefb96..4de287a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ # SDL libraries -------------------------------------------------------------------------------------------------- find_package(SDL2 REQUIRED) +find_package(PNG REQUIRED) find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) @@ -27,6 +28,10 @@ target_include_directories(ImGuiColorTextEdit PUBLIC ${IMGUI_PATH}) target_include_directories(ImGuiColorTextEdit PUBLIC ${SDL2_INCLUDE_DIR}) target_compile_definitions(ImGuiColorTextEdit PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) +set(SNESHACKING_PATH "Library/sneshacking/src") +file(GLOB SNESHACKING_SOURCES ${SNESHACKING_PATH}/*.c) +add_library("NintendoCompression" STATIC ${SNESHACKING_SOURCES}) + # Executable Linkage -------------------------------------------------------------------------------------- add_executable( yaze @@ -38,6 +43,7 @@ add_executable( Application/Data/OverworldMap.cc Application/Graphics/Bitmap.cc Application/Graphics/Tile.cc + Application/Graphics/Palette.cc Application/Editor/Editor.cc Application/Editor/OverworldEditor.cc Application/Events/Event.cc @@ -53,6 +59,8 @@ add_executable( ${IMGUI_PATH}/misc/cpp/imgui_stdlib.cpp ${IMGUI_FILE_DLG_PATH}/ImGuiFileDialog.cpp ${IMGUI_COLOR_TEXT_EDIT_PATH}/TextEditor.cpp + ${SNESHACKING_PATH}/compressions/alttpcompression.c + ${SNESHACKING_PATH}/compressions/stdnintendo.c ) target_include_directories( @@ -60,17 +68,25 @@ target_include_directories( Library/ Application/ Resources/ + "C:/msys64/mingw64/include/libpng16" + "C:/msys64/mingw64/include/SDL2" + "C:/msys64/mingw64/include" + ${SNESHACKING_PATH} + ${PNG_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS} ) target_link_libraries( - yaze + yaze + libstdc++ + SDL2main + ${PNG_LIBRARIES} ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES} - png ImGui + NintendoCompression ) set (source "${CMAKE_SOURCE_DIR}/assets") diff --git a/src/Library/sneshacking b/src/Library/sneshacking new file mode 160000 index 00000000..3cf5ab86 --- /dev/null +++ b/src/Library/sneshacking @@ -0,0 +1 @@ +Subproject commit 3cf5ab8681839e37c0aa7b8209821b809f47e9c7