From 192a05c0417c137e1ef2f5d62e7c9ddb4bbf87cf Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Fri, 17 Jun 2022 23:46:18 -0400 Subject: [PATCH] turned zarby 3bpp to 8bpp code into a routine --- src/application/Data/rom.cc | 91 +++++++++++++++++++------------------ src/application/Data/rom.h | 3 ++ 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/application/Data/rom.cc b/src/application/Data/rom.cc index 2d39726b..2f0c88c0 100644 --- a/src/application/Data/rom.cc +++ b/src/application/Data/rom.cc @@ -116,51 +116,52 @@ uint32_t ROM::GetRomPosition(int direct_addr, uint snes_addr) const { return filePos; } -// unsigned char *sheetBuffer = (unsigned char *)malloc(0x1000); -// unsigned char bitmask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; -// void SNES3bppTo8bppSheet() // 128x32 -// { -// char *buffer = new char[0x800]; -// int xx = 0; // positions where we are at on the sheet -// int yy = 0; -// int pos = 0; -// int ypos = 0; -// for (int i = 0; i < 64; i++) // for each tiles //16 per lines -// { -// for (int y = 0; y < 8; y++) // for each lines -// { -// //[0] + [1] + [16] -// for (int x = 0; x < 8; x++) { -// unsigned char b1 = -// (unsigned char)((buffer[(y * 2) + (24 * pos)] & (bitmask[x]))); -// unsigned char b2 = -// (unsigned char)(buffer[((y * 2) + (24 * pos)) + 1] & -// (bitmask[x])); -// unsigned char b3 = -// (unsigned char)(buffer[(16 + y) + (24 * pos)] & (bitmask[x])); -// unsigned char b = 0; -// if (b1 != 0) { -// b |= 1; -// }; -// if (b2 != 0) { -// b |= 2; -// }; -// if (b3 != 0) { -// b |= 4; -// }; -// sheetBuffer[x + (xx) + (y * 128) + (yy * 1024)] = b; -// } -// } -// pos++; -// ypos++; -// xx += 8; -// if (ypos >= 16) { -// yy++; -// xx = 0; -// ypos = 0; -// } -// } -// } +// char *buffer = new char[0x800] AKA sheet_buffer_in 3bpp +uchar* ROM::SNES3bppTo8bppSheet(uchar *sheet_buffer_in) // 128x32 +{ + // 8bpp sheet out + uchar *sheet_buffer_out = (unsigned char *)malloc(0x1000); + int xx = 0; // positions where we are at on the sheet + int yy = 0; + int pos = 0; + int ypos = 0; + for (int i = 0; i < 64; i++) // for each tiles //16 per lines + { + for (int y = 0; y < 8; y++) // for each lines + { + //[0] + [1] + [16] + for (int x = 0; x < 8; x++) { + unsigned char b1 = + (unsigned char)((sheet_buffer_in[(y * 2) + (24 * pos)] & (bitmask[x]))); + unsigned char b2 = + (unsigned char)(sheet_buffer_in[((y * 2) + (24 * pos)) + 1] & + (bitmask[x])); + unsigned char b3 = + (unsigned char)(sheet_buffer_in[(16 + y) + (24 * pos)] & (bitmask[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; +} char *ROM::Decompress(int pos, bool reversed) { char *buffer = new char[0x800]; diff --git a/src/application/Data/rom.h b/src/application/Data/rom.h index 570fa53e..a709d93e 100644 --- a/src/application/Data/rom.h +++ b/src/application/Data/rom.h @@ -30,6 +30,7 @@ class ROM { void LoadFromFile(const std::string& path); std::vector ExtractTiles(Graphics::TilePreset& preset); Graphics::SNESPalette ExtractPalette(Graphics::TilePreset& preset); + uchar* SNES3bppTo8bppSheet(uchar *sheet_buffer_in); uint32_t GetRomPosition(int direct_addr, uint snes_addr) const; inline uchar* GetRawData() { return current_rom_; } @@ -54,6 +55,8 @@ class ROM { std::shared_ptr rom_ptr_; std::unordered_map> decompressed_sheets; + + const uchar bitmmask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; }; } // namespace Data