Reorganize ROM class

This commit is contained in:
Justin Scofield
2022-07-18 19:21:19 -04:00
parent 237e4ede38
commit 6bdbf7a18f
2 changed files with 39 additions and 36 deletions

View File

@@ -54,6 +54,43 @@ void ROM::LoadFromFile(const std::string &path) {
void ROM::LoadFromPointer(uchar *data) { current_rom_ = data; } void ROM::LoadFromPointer(uchar *data) { current_rom_ = data; }
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
void ROM::LoadAllGraphicsData() {
auto buffer = new uchar[346624];
auto data = new uchar[2048];
int buffer_pos = 0;
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
// uncompressed sheets
if (i >= 115 && i <= 126) {
data = new uchar[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);
}
gfx::Bitmap tilesheet_bmp(
core::constants::kTilesheetWidth, core::constants::kTilesheetHeight,
core::constants::kTilesheetDepth, SNES3bppTo8bppSheet(data));
tilesheet_bmp.CreateTexture(sdl_renderer_);
graphics_bin_[i] = tilesheet_bmp;
for (int j = 0; j < sizeof(data); j++) {
buffer[j + buffer_pos] = data[j];
}
buffer_pos += sizeof(data);
}
}
uchar *ROM::DecompressGraphics(int pos, int size) { uchar *ROM::DecompressGraphics(int pos, int size) {
return Decompress(pos, size, false); return Decompress(pos, size, false);
} }
@@ -221,41 +258,6 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) {
return sheet_texture; return sheet_texture;
} }
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
void ROM::DrawAllGraphicsData() {
auto buffer = new uchar[346624];
auto data = new uchar[2048];
int buffer_pos = 0;
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
// uncompressed sheets
if (i >= 115 && i <= 126) {
data = new uchar[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);
}
gfx::Bitmap tilesheet_bmp(128, 32, 8, SNES3bppTo8bppSheet(data));
tilesheet_bmp.CreateTexture(sdl_renderer_);
graphics_bin_[i] = tilesheet_bmp;
for (int j = 0; j < sizeof(data); j++) {
buffer[j + buffer_pos] = data[j];
}
buffer_pos += sizeof(data);
}
}
gfx::SNESPalette ROM::ExtractPalette(uint addr, int bpp) { gfx::SNESPalette ROM::ExtractPalette(uint addr, int bpp) {
uint filePos = addr; uint filePos = addr;
uint palette_size = pow(2, bpp); uint palette_size = pow(2, bpp);

View File

@@ -30,6 +30,7 @@ class ROM {
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);
void LoadFromPointer(uchar* data); void LoadFromPointer(uchar* data);
void LoadAllGraphicsData();
uchar* DecompressGraphics(int pos, int size); uchar* DecompressGraphics(int pos, int size);
uchar* DecompressOverworld(int pos, int size); uchar* DecompressOverworld(int pos, int size);
@@ -39,7 +40,7 @@ class ROM {
int size = 0x1000); int size = 0x1000);
uint GetGraphicsAddress(uint8_t id) const; uint GetGraphicsAddress(uint8_t id) const;
SDL_Texture* DrawGraphicsSheet(int offset); SDL_Texture* DrawGraphicsSheet(int offset);
void DrawAllGraphicsData();
gfx::SNESPalette ExtractPalette(uint addr, int bpp); gfx::SNESPalette ExtractPalette(uint addr, int bpp);
uchar* data() { return current_rom_; } uchar* data() { return current_rom_; }