diff --git a/src/app/rom.cc b/src/app/rom.cc index 16d28aae..4c3dde18 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -67,13 +67,12 @@ uchar *ROM::Decompress(int pos, int size, bool reversed) { length = (ushort)(((current_rom_[pos] << 8) | current_rom_[pos + 1]) & 0x3FF); pos += 2; // Advance 2 bytes in ROM - } else { // Normal Command cmd = (uchar)((databyte >> 5) & 0x07); length = (uchar)(databyte & 0x1F); pos += 1; // Advance 1 byte in ROM } - length += 1; // Every commands are at least 1 size even if 00 + length += 1; // each commands is at least of size 1 even if index 00 switch (cmd) { case 00: // Direct Copy (Could be replaced with a MEMCPY) @@ -108,6 +107,9 @@ uchar *ROM::Decompress(int pos, int size, bool reversed) { ushort s1 = ((current_rom_[pos + 1] & 0xFF) << 8); ushort s2 = ((current_rom_[pos] & 0xFF)); auto Addr = (ushort)(s1 | s2); + if (reversed) { + Addr = (ushort)(s2 | s1); + } for (int i = 0; i < length; i++) { buffer[buffer_pos] = buffer[Addr + i]; buffer_pos++; @@ -210,12 +212,30 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) { return sheet_texture; } -gfx::SNESPalette ROM::ExtractPalette(uint addr, int bpp) { - uint filePos = addr; - uint palette_size = pow(2, bpp); - auto palette_data = (char *)SDL_malloc(sizeof(char) * (palette_size * 2)); - memcpy(palette_data, current_rom_ + filePos, palette_size * 2); - return gfx::SNESPalette(palette_data); +void ROM::DrawAllGraphicsData() { + auto buffer = (uchar*) SDL_malloc(346624); + auto data = (uchar *)SDL_malloc(2048); + int buffer_pos = 0; + + for (int i = 0; i < core::constants::NumberOfSheets; i++) { + // uncompressed sheets + if (i >= 115 && i <= 126) { + data = new char[core::constants::Uncompressed3BPPSize]; + int startAddress = GetGraphicsAddress(i); + for (int j = 0; j < core::constants::Uncompressed3BPPSize; j++) { + data[j] = current_rom_[j + startAddress]; + } + } else { + auto gfx_addr = GetGraphicsAddress(i); + data = Decompress(gfx_addr, core::constants::UncompressedSheetSize); + } + + for (int j = 0; j < sizeof(data); j++) { + buffer[j + buffer_pos] = data[j]; + } + + buffer_pos += sizeof(data); + } } // 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars @@ -260,5 +280,13 @@ char *ROM::CreateAllGfxDataRaw() { return buffer; } +gfx::SNESPalette ROM::ExtractPalette(uint addr, int bpp) { + uint filePos = addr; + uint palette_size = pow(2, bpp); + auto palette_data = (char *)SDL_malloc(sizeof(char) * (palette_size * 2)); + memcpy(palette_data, current_rom_ + filePos, palette_size * 2); + return gfx::SNESPalette(palette_data); +} + } // namespace app } // namespace yaze \ No newline at end of file diff --git a/src/app/rom.h b/src/app/rom.h index fe65e613..e83364f8 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -27,16 +27,16 @@ class ROM { public: void Close(); void SetupRenderer(std::shared_ptr renderer); - void LoadFromFile(const std::string& path); + uchar* Decompress(int pos, int size = 0x800, bool reversed = false); uchar* SNES3bppTo8bppSheet(uchar* buffer_in, int sheet_id = 0, int size = 0x1000); uint GetGraphicsAddress(uint8_t id) const; SDL_Texture* DrawGraphicsSheet(int offset); - gfx::SNESPalette ExtractPalette(uint addr, int bpp); - + void DrawAllGraphicsData(); char* CreateAllGfxDataRaw(); + gfx::SNESPalette ExtractPalette(uint addr, int bpp); uchar* data() { return current_rom_; } auto Renderer() { return sdl_renderer_; } @@ -52,7 +52,7 @@ class ROM { uint compressed_size_; uchar* current_rom_; uchar title[21] = "ROM Not Loaded"; - enum rom_type type_ = LoROM; + enum rom_type type_ = LoROM; bool isbpp3[core::constants::NumberOfSheets]; std::shared_ptr rom_ptr_;