added formal ui test code for zarby decompression, surface building not supported yet

This commit is contained in:
Justin Scofield
2022-06-18 00:26:50 -04:00
parent 664263ac32
commit 011f89acc3
3 changed files with 37 additions and 11 deletions

View File

@@ -55,7 +55,6 @@ std::vector<tile8> ROM::ExtractTiles(Graphics::TilePreset &preset) {
std::cout << alttp_decompression_error << std::endl; std::cout << alttp_decompression_error << std::endl;
return rawTiles; return rawTiles;
} }
// data = Decompress(filePos);
// unpack the tiles based on their depth // unpack the tiles based on their depth
unsigned tileCpt = 0; unsigned tileCpt = 0;
@@ -116,11 +115,18 @@ uint32_t ROM::GetRomPosition(int direct_addr, uint snes_addr) const {
return filePos; return filePos;
} }
// char *buffer = new char[0x800] AKA sheet_buffer_in 3bpp uchar* ROM::LoadGraphicsSheet(int offset) {
uchar* ROM::SNES3bppTo8bppSheet(uchar *sheet_buffer_in) // 128x32 auto tilesheet_position = Core::Constants::gfx_1_pointer +
(offset * Core::Constants::UncompressedSheetSize);
auto data = Decompress(tilesheet_position);
return SNES3bppTo8bppSheet(data);
}
// char *buffer = new char[0x800] AKA sheet_buffer_in 3bpp
uchar *ROM::SNES3bppTo8bppSheet(uchar *sheet_buffer_in) // 128x32
{ {
// 8bpp sheet out // 8bpp sheet out
const uchar bitmask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; const uchar bitmask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
uchar *sheet_buffer_out = (unsigned char *)malloc(0x1000); uchar *sheet_buffer_out = (unsigned char *)malloc(0x1000);
int xx = 0; // positions where we are at on the sheet int xx = 0; // positions where we are at on the sheet
int yy = 0; int yy = 0;
@@ -132,13 +138,14 @@ uchar* ROM::SNES3bppTo8bppSheet(uchar *sheet_buffer_in) // 128x32
{ {
//[0] + [1] + [16] //[0] + [1] + [16]
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
unsigned char b1 = unsigned char b1 = (unsigned char)((
(unsigned char)((sheet_buffer_in[(y * 2) + (24 * pos)] & (bitmask[x]))); sheet_buffer_in[(y * 2) + (24 * pos)] & (bitmask[x])));
unsigned char b2 = unsigned char b2 =
(unsigned char)(sheet_buffer_in[((y * 2) + (24 * pos)) + 1] & (unsigned char)(sheet_buffer_in[((y * 2) + (24 * pos)) + 1] &
(bitmask[x])); (bitmask[x]));
unsigned char b3 = unsigned char b3 =
(unsigned char)(sheet_buffer_in[(16 + y) + (24 * pos)] & (bitmask[x])); (unsigned char)(sheet_buffer_in[(16 + y) + (24 * pos)] &
(bitmask[x]));
unsigned char b = 0; unsigned char b = 0;
if (b1 != 0) { if (b1 != 0) {
b |= 1; b |= 1;

View File

@@ -29,14 +29,16 @@ class ROM {
void LoadFromFile(const std::string& path); void LoadFromFile(const std::string& path);
std::vector<tile8> ExtractTiles(Graphics::TilePreset& preset); std::vector<tile8> ExtractTiles(Graphics::TilePreset& preset);
Graphics::SNESPalette ExtractPalette(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; uint32_t GetRomPosition(int direct_addr, uint snes_addr) const;
inline uchar* GetRawData() { return current_rom_; } inline uchar* GetRawData() { return current_rom_; }
const uchar* getTitle() const { return title; } const uchar* getTitle() const { return title; }
long int getSize() const { return size_; } long int getSize() const { return size_; }
char getVersion() const { return version_; } char getVersion() const { return version_; }
bool isLoaded() const { return loaded; } bool isLoaded() const { return loaded; }
uchar* LoadGraphicsSheet(int offset);
uchar* SNES3bppTo8bppSheet(uchar *sheet_buffer_in);
char* Decompress(int pos, bool reversed = false); char* Decompress(int pos, bool reversed = false);
private: private:

View File

@@ -317,6 +317,23 @@ void Editor::DrawProjectEditor() {
yaze::Gui::InputHex("SNES Palette Location", yaze::Gui::InputHex("SNES Palette Location",
&current_set_.SNESPaletteLocation); &current_set_.SNESPaletteLocation);
static bool loaded_image = false;
static uchar* image_data = nullptr;
ImGui::Text("Zarby Retrieval Code");
BASIC_BUTTON("Retrieve Graphics") {
if (rom_.isLoaded()) {
if (!loaded_image) {
image_data = rom_.LoadGraphicsSheet(current_set.pc_tiles_location_);
loaded_image = true;
} else {
// TODO: build the sdl surface from the tilesheet data
}
}
}
ImGui::Separator();
ImGui::Text("Skarsnik Retrieval Code");
BASIC_BUTTON("ExtractTiles") { BASIC_BUTTON("ExtractTiles") {
if (rom_.isLoaded()) { if (rom_.isLoaded()) {
tiles_ = rom_.ExtractTiles(current_set_); tiles_ = rom_.ExtractTiles(current_set_);