Refactoring the codebase and moving closer to decompression
This commit is contained in:
@@ -4,11 +4,19 @@
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#define BASIC_BUTTON(w) if (ImGui::Button(w))
|
||||
|
||||
#define TAB_BAR(w) if (ImGui::BeginTabBar(w)) {
|
||||
#define END_TAB_BAR() ImGui::EndTabBar(); }
|
||||
#define END_TAB_BAR() \
|
||||
ImGui::EndTabBar(); \
|
||||
}
|
||||
|
||||
#define MENU_BAR() if (ImGui::BeginMenuBar()) {
|
||||
#define END_MENU_BAR() ImGui::EndMenuBar(); }
|
||||
#define END_MENU_BAR() \
|
||||
ImGui::EndMenuBar(); \
|
||||
}
|
||||
|
||||
using byte = unsigned char;
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
@@ -20,24 +28,17 @@ using ushort = unsigned short;
|
||||
//===========================================================================================
|
||||
// Magic numbers
|
||||
//===========================================================================================
|
||||
/// <summary>
|
||||
|
||||
/// Bit set for object priority
|
||||
/// </summary>
|
||||
constexpr ushort TilePriorityBit = 0x2000;
|
||||
|
||||
/// <summary>
|
||||
/// Bit set for object hflip
|
||||
/// </summary>
|
||||
constexpr ushort TileHFlipBit = 0x4000;
|
||||
|
||||
/// <summary>
|
||||
/// Bit set for object vflip
|
||||
/// </summary>
|
||||
constexpr ushort TileVFlipBit = 0x8000;
|
||||
|
||||
/// <summary>
|
||||
/// Bits used for tile name
|
||||
/// </summary>
|
||||
constexpr ushort TileNameMask = 0x03FF;
|
||||
|
||||
constexpr int Uncompressed3BPPSize = 0x0600;
|
||||
@@ -162,7 +163,8 @@ constexpr int OWEntrancePos = 0xDBA71;
|
||||
constexpr int OWEntranceEntranceId = 0xDBB73;
|
||||
constexpr int OWHolePos = 0xDB800; //(0x13 entries, 2 bytes each) modified(less
|
||||
// 0x400) map16 coordinates for each hole
|
||||
constexpr int OWHoleArea = 0xDB826; //(0x13 entries, 2 bytes each) corresponding
|
||||
constexpr int OWHoleArea =
|
||||
0xDB826; //(0x13 entries, 2 bytes each) corresponding
|
||||
// area numbers for each hole
|
||||
constexpr int OWHoleEntrance =
|
||||
0xDB84C; //(0x13 entries, 1 byte each) corresponding entrance numbers
|
||||
@@ -290,7 +292,8 @@ constexpr int startingentrance_door = 0x15C2B; // 0x15274 1byte
|
||||
|
||||
constexpr int startingentrance_ladderbg =
|
||||
0x15C1D; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_-
|
||||
constexpr int startingentrance_scrolling = 0x15C24; // 0x1537E //1byte --h- --v-
|
||||
constexpr int startingentrance_scrolling =
|
||||
0x15C24; // 0x1537E //1byte --h- --v-
|
||||
constexpr int startingentrance_scrollquadrant = 0x15C2B; // 0x15403 1byte
|
||||
constexpr int startingentrance_exit = 0x15C32; // 0x15488 //2byte word
|
||||
constexpr int startingentrance_music = 0x15C4E; // 0x15592
|
||||
@@ -367,7 +370,8 @@ constexpr int hudPalettes = 0xDD660;
|
||||
constexpr int dungeonMapPalettes = 0xDD70A; // 21 colors
|
||||
constexpr int dungeonMainPalettes = 0xDD734; //(15*6) colors each - 20 entries
|
||||
constexpr int dungeonMapBgPalettes = 0xDE544; // 16*6
|
||||
constexpr int hardcodedGrassLW = 0x5FEA9; // Mirrored Value at 0x75645 : 0x75625
|
||||
constexpr int hardcodedGrassLW =
|
||||
0x5FEA9; // Mirrored Value at 0x75645 : 0x75625
|
||||
constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F
|
||||
constexpr int hardcodedGrassSpecial = 0x75640;
|
||||
|
||||
|
||||
@@ -41,10 +41,11 @@ static TileInfo GetTilesInfo(ushort tile) {
|
||||
void Overworld::Load(Utils::ROM rom) {
|
||||
rom_ = rom;
|
||||
for (int i = 0; i < 0x2B; i++) {
|
||||
tileLeftEntrance.push_back(
|
||||
rom_.ReadShort(Constants::overworldEntranceAllowedTilesLeft + (i * 2)));
|
||||
tileRightEntrance.push_back(rom_.ReadShort(
|
||||
Constants::overworldEntranceAllowedTilesRight + (i * 2)));
|
||||
// tileLeftEntrance.push_back(
|
||||
// rom_.ReadShort(Constants::overworldEntranceAllowedTilesLeft + (i *
|
||||
// 2)));
|
||||
// tileRightEntrance.push_back(rom_.ReadShort(
|
||||
// Constants::overworldEntranceAllowedTilesRight + (i * 2)));
|
||||
}
|
||||
|
||||
AssembleMap32Tiles();
|
||||
@@ -132,8 +133,10 @@ void Overworld::DecompressAllMapTiles() {
|
||||
<< 8) +
|
||||
(rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh +
|
||||
(int)(3 * i))]);
|
||||
p1 = rom_.SnesToPc(p1);
|
||||
|
||||
char* tmp = new char[256];
|
||||
p1 = lorom_snes_to_pc(p1, &tmp);
|
||||
std::cout << tmp << std::endl;
|
||||
int p2 = (rom_.GetRawData()[(Constants::compressedAllMap32PointersLow) + 2 +
|
||||
(int)(3 * i)]
|
||||
<< 16) +
|
||||
@@ -142,7 +145,9 @@ void Overworld::DecompressAllMapTiles() {
|
||||
<< 8) +
|
||||
(rom_.GetRawData()[(Constants::compressedAllMap32PointersLow +
|
||||
(int)(3 * i))]);
|
||||
p2 = rom_.SnesToPc(p2);
|
||||
p2 = lorom_snes_to_pc(p2, &tmp);
|
||||
std::cout << tmp << std::endl;
|
||||
delete[] tmp;
|
||||
|
||||
int ttpos = 0;
|
||||
unsigned int compressedSize1 = 0;
|
||||
@@ -168,10 +173,12 @@ void Overworld::DecompressAllMapTiles() {
|
||||
}
|
||||
}
|
||||
|
||||
auto bytes = alttp_compressor_.DecompressOverworld(
|
||||
rom_.GetRawData(), p2, 1000, &compressedSize1, &compressedLength1);
|
||||
auto bytes2 = alttp_compressor_.DecompressOverworld(
|
||||
rom_.GetRawData(), p1, 1000, &compressedSize2, &compressedLength2);
|
||||
auto bytes =
|
||||
alttp_decompress_overworld((char*)rom_.GetRawData(), p2, 1000,
|
||||
&compressedSize1, &compressedLength1);
|
||||
auto bytes2 =
|
||||
alttp_decompress_overworld((char*)rom_.GetRawData(), p1, 1000,
|
||||
&compressedSize2, &compressedLength2);
|
||||
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
@@ -295,7 +302,7 @@ void Overworld::LoadOverworldMap() {
|
||||
owactualMapBitmap->Create(&owactualMapTexture);
|
||||
|
||||
// Mode 7
|
||||
byte* ptr = overworldMapPointer;
|
||||
char* ptr = overworldMapPointer;
|
||||
|
||||
int pos = 0;
|
||||
for (int sy = 0; sy < 16; sy++) {
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <rommapping.h>
|
||||
|
||||
#include "Core/Constants.h"
|
||||
#include "Graphics/Bitmap.h"
|
||||
#include "Graphics/Tile.h"
|
||||
#include "OverworldMap.h"
|
||||
#include "Utils/Compression.h"
|
||||
|
||||
#include "Utils/ROM.h"
|
||||
|
||||
namespace yaze {
|
||||
@@ -25,18 +26,18 @@ class Overworld {
|
||||
|
||||
void Load(Utils::ROM rom);
|
||||
|
||||
byte* overworldMapPointer = new byte[0x40000];
|
||||
char* overworldMapPointer = new char[0x40000];
|
||||
Graphics::Bitmap* overworldMapBitmap;
|
||||
GLuint overworldMapTexture;
|
||||
|
||||
byte* owactualMapPointer = new byte[0x40000];
|
||||
char* owactualMapPointer = new char[0x40000];
|
||||
Graphics::Bitmap* owactualMapBitmap;
|
||||
GLuint owactualMapTexture;
|
||||
|
||||
private:
|
||||
Utils::ROM rom_;
|
||||
Utils::ALTTPCompression alttp_compressor_;
|
||||
int gameState = 1;
|
||||
bool isLoaded = false;
|
||||
byte mapParent[160];
|
||||
|
||||
ushort **allmapsTilesLW; // 64 maps * (32*32 tiles)
|
||||
@@ -49,8 +50,6 @@ class Overworld {
|
||||
|
||||
std::vector<OverworldMap> allmaps;
|
||||
|
||||
bool isLoaded = false;
|
||||
|
||||
std::vector<ushort> tileLeftEntrance;
|
||||
std::vector<ushort> tileRightEntrance;
|
||||
|
||||
@@ -58,7 +57,6 @@ class Overworld {
|
||||
Core::Constants::map32TilesTL, Core::Constants::map32TilesTR,
|
||||
Core::Constants::map32TilesBL, Core::Constants::map32TilesBR};
|
||||
|
||||
|
||||
enum Dimension {
|
||||
map32TilesTL = 0,
|
||||
map32TilesTR = 1,
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace yaze {
|
||||
namespace Application {
|
||||
namespace Editor {
|
||||
|
||||
using namespace Core;
|
||||
|
||||
Editor::Editor() {
|
||||
static bool inited = false;
|
||||
if (!inited) {
|
||||
@@ -83,13 +85,19 @@ Editor::Editor() {
|
||||
asm_editor_.SetLanguageDefinition(language65816Def);
|
||||
asm_editor_.SetPalette(TextEditor::GetDarkPalette());
|
||||
|
||||
current_set_.bpp = 3;
|
||||
current_set_.pcTilesLocation = 0x8000;
|
||||
current_set_.bpp = 4;
|
||||
current_set_.pcTilesLocation = 0x80000;
|
||||
current_set_.SNESTilesLocation = 0;
|
||||
current_set_.length = 1000;
|
||||
current_set_.pcPaletteLocation = 0;
|
||||
current_set_.length = 28672;
|
||||
current_set_.pcPaletteLocation = 0xDD326;
|
||||
current_set_.SNESPaletteLocation = 0;
|
||||
current_set_.compression = "zelda3";
|
||||
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.0f, 0.5f, 0.0f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.4f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.3f, 0.0f, 0.0f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.3f, 0.7f, 0.9f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||
}
|
||||
|
||||
void Editor::UpdateScreen() {
|
||||
@@ -136,7 +144,6 @@ void Editor::DrawYazeMenu() {
|
||||
if (ImGuiFileDialog::Instance()->IsOk()) {
|
||||
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||
title_ = ImGuiFileDialog::Instance()->GetCurrentFileName();
|
||||
rom.LoadFromFile(filePathName);
|
||||
overworld_editor_.SetRom(rom);
|
||||
rom_data_ = (void *)rom.GetRawData();
|
||||
@@ -264,7 +271,7 @@ void Editor::DrawViewMenu() {
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("View")) {
|
||||
ImGui::MenuItem("HEX Editor", nullptr, &MemoryEditor::Open);
|
||||
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
|
||||
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor);
|
||||
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
|
||||
|
||||
@@ -291,37 +298,136 @@ void Editor::DrawProjectEditor() {
|
||||
static bool inited = false;
|
||||
|
||||
if (ImGui::BeginTabItem("Project")) {
|
||||
ImGui::InputInt("PC Tile Location", ¤t_set_.pcTilesLocation);
|
||||
ImGui::InputScalar("SNES Tile Location", ImGuiDataType_U32, (void*)¤t_set_.SNESTilesLocation);
|
||||
ImGui::InputScalar("Tile Preset Length", ImGuiDataType_U32, (void*)¤t_set_.length);
|
||||
ImGui::InputScalar("Bits per Pixel", ImGuiDataType_U32, (void*)¤t_set_.bpp);
|
||||
ImGui::InputScalar("PC Palette Location", ImGuiDataType_U32, (void*)¤t_set_.pcPaletteLocation);
|
||||
ImGui::InputScalar("SNES Palette Location", ImGuiDataType_U32, (void*)¤t_set_.SNESPaletteLocation);
|
||||
|
||||
if (rom.isLoaded()) {
|
||||
if (ImGui::BeginTable("##projectTable", 2,
|
||||
ImGuiTableFlags_SizingStretchSame)) {
|
||||
ImGui::TableSetupColumn("##inputs");
|
||||
ImGui::TableSetupColumn("##outputs");
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Title: %s", rom.getTitle());
|
||||
ImGui::Text("Version: %d", rom.getVersion());
|
||||
ImGui::Text("ROM Size: %ld", rom.getSize());
|
||||
|
||||
if (!inited) {
|
||||
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.0f, 0.5f, 0.0f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.4f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.3f, 0.0f, 0.0f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.3f, 0.7f, 0.9f, 1.0f));
|
||||
current_palette_.colors.push_back(ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||
ImGui::InputInt("PC Tile Location", ¤t_set_.pcTilesLocation);
|
||||
// 1, 100, ImGuiInputTextFlags_CharsHexadecimal);
|
||||
|
||||
current_scene_.buildSurface(rom.ExtractTiles(current_set_), current_palette_, current_set_.tilesPattern);
|
||||
inited = true;
|
||||
}
|
||||
ImGui::InputScalar("SNES Tile Location", ImGuiDataType_U32,
|
||||
(void *)¤t_set_.SNESTilesLocation);
|
||||
|
||||
for (const auto & [key, value] : current_scene_.imagesCache) {
|
||||
ImGui::Image((void *)(SDL_Texture*)value, ImVec2(8, 8));
|
||||
ImGui::InputScalar("Tile Preset Length", ImGuiDataType_U32,
|
||||
(void *)¤t_set_.length);
|
||||
|
||||
ImGui::InputScalar("Bits per Pixel", ImGuiDataType_U32,
|
||||
(void *)¤t_set_.bpp);
|
||||
|
||||
ImGui::InputScalar("PC Palette Location", ImGuiDataType_U32,
|
||||
(void *)¤t_set_.pcPaletteLocation);
|
||||
|
||||
ImGui::InputScalar("SNES Palette Location", ImGuiDataType_U32,
|
||||
(void *)¤t_set_.SNESPaletteLocation);
|
||||
|
||||
BASIC_BUTTON("ExtractTiles") {
|
||||
if (rom.isLoaded()) {
|
||||
tiles_ = rom.ExtractTiles(current_set_);
|
||||
}
|
||||
}
|
||||
|
||||
BASIC_BUTTON("BuildSurface") {
|
||||
if (rom.isLoaded()) {
|
||||
current_palette_ = rom.ExtractPalette(current_set_);
|
||||
current_scene_.buildSurface(tiles_, current_palette_,
|
||||
current_set_.tilesPattern);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &[key, texture] : current_scene_.imagesCache) {
|
||||
ImGui::Image((void *)(SDL_Texture *)texture, ImVec2(8, 8));
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
static ImVector<ImVec2> points;
|
||||
static ImVec2 scrolling(0.0f, 0.0f);
|
||||
static bool opt_enable_context_menu = true;
|
||||
static bool opt_enable_grid = true;
|
||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
|
||||
ImVec2 canvas_sz = ImGui::GetContentRegionAvail();
|
||||
ImVec2 canvas_p1 =
|
||||
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||
|
||||
// Draw border and background color
|
||||
const ImGuiIO &io = ImGui::GetIO();
|
||||
ImDrawList *draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
|
||||
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
|
||||
|
||||
// This will catch our interactions
|
||||
ImGui::InvisibleButton(
|
||||
"canvas", canvas_sz,
|
||||
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||
const bool is_active = ImGui::IsItemActive(); // Held
|
||||
const ImVec2 origin(canvas_p0.x + scrolling.x,
|
||||
canvas_p0.y + scrolling.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
|
||||
io.MousePos.y - origin.y);
|
||||
|
||||
// Pan (we use a zero mouse threshold when there's no context menu)
|
||||
const float mouse_threshold_for_pan =
|
||||
opt_enable_context_menu ? -1.0f : 0.0f;
|
||||
if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right,
|
||||
mouse_threshold_for_pan)) {
|
||||
scrolling.x += io.MouseDelta.x;
|
||||
scrolling.y += io.MouseDelta.y;
|
||||
}
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
if (opt_enable_context_menu && drag_delta.x == 0.0f &&
|
||||
drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupOnItemClick("context",
|
||||
ImGuiPopupFlags_MouseButtonRight);
|
||||
if (ImGui::BeginPopup("context")) {
|
||||
ImGui::MenuItem("Placeholder");
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Draw grid + all lines in the canvas
|
||||
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
|
||||
if (opt_enable_grid) {
|
||||
const float GRID_STEP = 64.0f;
|
||||
for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x;
|
||||
x += GRID_STEP)
|
||||
draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y),
|
||||
ImVec2(canvas_p0.x + x, canvas_p1.y),
|
||||
IM_COL32(200, 200, 200, 40));
|
||||
for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y;
|
||||
y += GRID_STEP)
|
||||
draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y),
|
||||
ImVec2(canvas_p1.x, canvas_p0.y + y),
|
||||
IM_COL32(200, 200, 200, 40));
|
||||
}
|
||||
|
||||
if (current_scene_.imagesCache.size() != 0) {
|
||||
for (const auto &[key, value] : current_scene_.imagesCache) {
|
||||
const float GRID_STEP = 8.0f;
|
||||
float x = fmodf(scrolling.x, GRID_STEP);
|
||||
float y = fmodf(scrolling.y, GRID_STEP);
|
||||
draw_list->AddImage((void*)(intptr_t)value,
|
||||
ImVec2(canvas_p0.x + x, canvas_p0.y),
|
||||
ImVec2(canvas_p0.x + x, canvas_p1.y));
|
||||
x += GRID_STEP;
|
||||
if (x == 128) {
|
||||
x = 0;
|
||||
y += GRID_STEP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw_list->PopClipRect();
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#ifndef YAZE_APPLICATION_VIEW_EDITOR_H
|
||||
#define YAZE_APPLICATION_VIEW_EDITOR_H
|
||||
|
||||
#include <ImGuiColorTextEdit/TextEditor.h>
|
||||
#include <ImGuiFileDialog/ImGuiFileDialog.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_memory_editor.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Core/Constants.h"
|
||||
#include "Core/Icons.h"
|
||||
#include "ImGuiColorTextEdit/TextEditor.h"
|
||||
#include "ImGuiFileDialog/ImGuiFileDialog.h"
|
||||
#include "OverworldEditor.h"
|
||||
#include "Utils/ROM.h"
|
||||
#include "imgui/backends/imgui_impl_sdl.h"
|
||||
#include "imgui/backends/imgui_impl_sdlrenderer.h"
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/imgui_internal.h"
|
||||
#include "imgui/imgui_memory_editor.h"
|
||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
@@ -41,8 +40,6 @@ class Editor {
|
||||
void *rom_data_;
|
||||
bool isLoaded = true;
|
||||
|
||||
std::string title_ = "YAZE";
|
||||
|
||||
Utils::ROM rom;
|
||||
TextEditor asm_editor_;
|
||||
TextEditor::LanguageDefinition language65816Def;
|
||||
@@ -52,6 +49,8 @@ class Editor {
|
||||
Graphics::SNESPalette current_palette_;
|
||||
Graphics::TilePreset current_set_;
|
||||
|
||||
std::vector<tile8> tiles_;
|
||||
|
||||
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "Graphics/Palette.h"
|
||||
#include "Graphics/Scene.h"
|
||||
#include "Graphics/Tile.h"
|
||||
#include "Utils/Compression.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
@@ -37,7 +36,6 @@ class OverworldEditor {
|
||||
Utils::ROM rom_;
|
||||
Data::Overworld overworld;
|
||||
Graphics::Scene current_scene_;
|
||||
Utils::ALTTPCompression alttp_compressor_;
|
||||
Graphics::Bitmap allgfxBitmap;
|
||||
Graphics::SNESPalette palette_;
|
||||
Graphics::TilePreset current_set_;
|
||||
|
||||
@@ -1,44 +1,47 @@
|
||||
#include "Bitmap.h"
|
||||
|
||||
#include "Utils/ROM.h"
|
||||
#include "Utils/Compression.h"
|
||||
#include "rommapping.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
int GetPCGfxAddress(byte *romData, byte id) {
|
||||
char** info1, **info2,** info3, **info4;
|
||||
int GetPCGfxAddress(char *romData, char id) {
|
||||
char **info1, **info2, **info3, **info4;
|
||||
int gfxPointer1 =
|
||||
lorom_snes_to_pc((romData[Constants::gfx_1_pointer + 1] << 8) +
|
||||
(romData[Constants::gfx_1_pointer]), info1);
|
||||
(romData[Constants::gfx_1_pointer]),
|
||||
info1);
|
||||
int gfxPointer2 =
|
||||
lorom_snes_to_pc((romData[Constants::gfx_2_pointer + 1] << 8) +
|
||||
(romData[Constants::gfx_2_pointer]), info2);
|
||||
(romData[Constants::gfx_2_pointer]),
|
||||
info2);
|
||||
int gfxPointer3 =
|
||||
lorom_snes_to_pc((romData[Constants::gfx_3_pointer + 1] << 8) +
|
||||
(romData[Constants::gfx_3_pointer]), info3);
|
||||
(romData[Constants::gfx_3_pointer]),
|
||||
info3);
|
||||
|
||||
byte gfxGamePointer1 = romData[gfxPointer1 + id];
|
||||
byte gfxGamePointer2 = romData[gfxPointer2 + id];
|
||||
byte gfxGamePointer3 = romData[gfxPointer3 + id];
|
||||
char gfxGamePointer1 = romData[gfxPointer1 + id];
|
||||
char gfxGamePointer2 = romData[gfxPointer2 + id];
|
||||
char gfxGamePointer3 = romData[gfxPointer3 + id];
|
||||
|
||||
return lorom_snes_to_pc(Utils::AddressFromBytes(gfxGamePointer1, gfxGamePointer2,
|
||||
gfxGamePointer3), info4);
|
||||
return lorom_snes_to_pc(
|
||||
Utils::AddressFromBytes(gfxGamePointer1, gfxGamePointer2,
|
||||
gfxGamePointer3),
|
||||
info4);
|
||||
}
|
||||
|
||||
byte *CreateAllGfxDataRaw(byte *romData) {
|
||||
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 bytes
|
||||
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 bytes
|
||||
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 bytes
|
||||
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 bytes
|
||||
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 bytes
|
||||
char *CreateAllGfxDataRaw(char *romData) {
|
||||
// 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
|
||||
|
||||
Utils::ALTTPCompression alttp_compressor_;
|
||||
|
||||
byte *buffer = new byte[346624];
|
||||
char *buffer = new char[346624];
|
||||
int bufferPos = 0;
|
||||
byte *data = new byte[2048];
|
||||
char *data = new char[2048];
|
||||
unsigned int uncompressedSize = 0;
|
||||
unsigned int compressedSize = 0;
|
||||
|
||||
@@ -50,14 +53,14 @@ byte *CreateAllGfxDataRaw(byte *romData) {
|
||||
|
||||
// uncompressed sheets
|
||||
if (i >= 115 && i <= 126) {
|
||||
data = new byte[Constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(romData, (byte)i);
|
||||
data = new char[Constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(romData, (char)i);
|
||||
for (int j = 0; j < Constants::Uncompressed3BPPSize; j++) {
|
||||
data[j] = romData[j + startAddress];
|
||||
}
|
||||
} else {
|
||||
data = alttp_compressor_.DecompressGfx(
|
||||
romData, GetPCGfxAddress(romData, (byte)i),
|
||||
data = alttp_decompress_gfx(
|
||||
(char *)romData, GetPCGfxAddress(romData, (char)i),
|
||||
Constants::UncompressedSheetSize, &uncompressedSize, &compressedSize);
|
||||
}
|
||||
|
||||
@@ -71,11 +74,12 @@ byte *CreateAllGfxDataRaw(byte *romData) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
|
||||
byte* data = CreateAllGfxDataRaw(romData);
|
||||
byte* newData =
|
||||
new byte[0x6F800]; // NEED TO GET THE APPROPRIATE SIZE FOR THAT
|
||||
byte* mask = new byte[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
|
||||
char *data = CreateAllGfxDataRaw(romData);
|
||||
char *newData =
|
||||
new char[0x6F800]; // NEED TO GET THE APPROPRIATE SIZE FOR THAT
|
||||
unsigned char *mask =
|
||||
new unsigned char[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
int sheetPosition = 0;
|
||||
|
||||
// 8x8 tile
|
||||
@@ -88,17 +92,17 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
|
||||
for (int y = 0; y < 8; y++) // Per Pixel Line
|
||||
{
|
||||
if (isbpp3[s]) {
|
||||
byte lineBits0 =
|
||||
char lineBits0 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||
byte lineBits1 =
|
||||
char lineBits1 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
|
||||
byte lineBits2 =
|
||||
char lineBits2 =
|
||||
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
byte pixdata = 0;
|
||||
byte pixdata2 = 0;
|
||||
char pixdata = 0;
|
||||
char pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
@@ -121,18 +125,18 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(byte)((pixdata << 4) | pixdata2);
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
} else {
|
||||
byte lineBits0 =
|
||||
char lineBits0 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
|
||||
byte lineBits1 =
|
||||
char lineBits1 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
byte pixdata = 0;
|
||||
byte pixdata2 = 0;
|
||||
char pixdata = 0;
|
||||
char pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
@@ -149,7 +153,7 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(byte)((pixdata << 4) | pixdata2);
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,14 +167,14 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
byte *allgfx16Data = (byte *) allgfx16Ptr;
|
||||
char *allgfx16Data = (char *)allgfx16Ptr;
|
||||
|
||||
for (int i = 0; i < 0x6F800; i++) {
|
||||
allgfx16Data[i] = newData[i];
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(int width, int height, byte *data)
|
||||
Bitmap::Bitmap(int width, int height, char *data)
|
||||
: width_(width), height_(height), pixel_data_(data) {}
|
||||
|
||||
void Bitmap::Create(GLuint *out_texture) {
|
||||
@@ -179,7 +183,7 @@ void Bitmap::Create(GLuint *out_texture) {
|
||||
// // Create the surface from that RW stream
|
||||
// SDL_Surface* surface = SDL_LoadBMP_RW(src, SDL_FALSE);
|
||||
// GLenum mode = 0;
|
||||
// Uint8 bpp = surface->format->BytesPerPixel;
|
||||
// Uint8 bpp = surface->format->charsPerPixel;
|
||||
// Uint32 rm = surface->format->Rmask;
|
||||
// if (bpp == 3 && rm == 0x000000ff) mode = GL_RGB;
|
||||
// if (bpp == 3 && rm == 0x00ff0000) mode = GL_BGR;
|
||||
@@ -221,8 +225,7 @@ bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
|
||||
// Load from file
|
||||
int image_width = 0;
|
||||
int image_height = 0;
|
||||
if (texture_data == NULL)
|
||||
return false;
|
||||
if (texture_data == NULL) return false;
|
||||
|
||||
// Create a OpenGL texture identifier
|
||||
GLuint image_texture;
|
||||
|
||||
@@ -13,13 +13,12 @@ namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
using byte = unsigned char;
|
||||
using namespace Core;
|
||||
|
||||
class Bitmap {
|
||||
public:
|
||||
Bitmap() = default;
|
||||
Bitmap(int width, int height, byte *data);
|
||||
Bitmap(int width, int height, char *data);
|
||||
|
||||
void Create(GLuint *out_texture);
|
||||
int GetWidth();
|
||||
@@ -31,14 +30,14 @@ class Bitmap {
|
||||
private:
|
||||
int width_;
|
||||
int height_;
|
||||
byte *pixel_data_;
|
||||
char *pixel_data_;
|
||||
};
|
||||
|
||||
static bool isbpp3[Constants::NumberOfSheets];
|
||||
|
||||
int GetPCGfxAddress(byte *romData, byte id);
|
||||
byte *CreateAllGfxDataRaw(byte *romData);
|
||||
void CreateAllGfxData(byte *romData, byte *allgfx16Ptr);
|
||||
int GetPCGfxAddress(char *romData, char id);
|
||||
char *CreateAllGfxDataRaw(char *romData);
|
||||
void CreateAllGfxData(char *romData, char *allgfx16Ptr);
|
||||
|
||||
} // namespace Graphics
|
||||
} // namespace Application
|
||||
|
||||
@@ -47,8 +47,7 @@ SNESPalette::SNESPalette(uint8_t mSize) {
|
||||
}
|
||||
|
||||
SNESPalette::SNESPalette(char* data) {
|
||||
// assert((data.size() % 4 == 0) && data.size() <= 32);
|
||||
// size = data.size() / 2;
|
||||
assert((sizeof(data) % 4 == 0) && (sizeof(data) <= 32));
|
||||
size = sizeof(data) / 2;
|
||||
for (unsigned i = 0; i < sizeof(data); i += 2) {
|
||||
SNESColor col;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
@@ -34,7 +33,6 @@ class SNESPalette {
|
||||
SNESPalette(std::vector<ImVec4>);
|
||||
|
||||
char* encode();
|
||||
|
||||
SDL_Palette* GetSDL_Palette();
|
||||
|
||||
uint8_t size;
|
||||
|
||||
@@ -19,7 +19,6 @@ void Scene::buildSurface(const std::vector<tile8>& tiles, SNESPalette& mPalette,
|
||||
SDL_PixelFormat* format = newImage->format;
|
||||
format->palette = mPalette.GetSDL_Palette();
|
||||
|
||||
|
||||
char* ptr = (char*)newImage->pixels;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
|
||||
@@ -13,47 +13,17 @@ namespace yaze {
|
||||
namespace Application {
|
||||
namespace Graphics {
|
||||
|
||||
std::unordered_map<std::string, TilesPattern> TilesPattern::m_Patterns;
|
||||
|
||||
ushort TileInfo::toShort() {
|
||||
ushort value = 0;
|
||||
// vhopppcc cccccccc
|
||||
if (over_ == 1) {
|
||||
value |= 0x2000;
|
||||
};
|
||||
if (horizontal_mirror_ == 1) {
|
||||
value |= 0x4000;
|
||||
};
|
||||
if (vertical_mirror_ == 1) {
|
||||
value |= 0x8000;
|
||||
};
|
||||
value |= (ushort)((palette_ << 10) & 0x1C00);
|
||||
value |= (ushort)(id_ & 0x3FF);
|
||||
return value;
|
||||
}
|
||||
|
||||
char *hexString(const char *str, const unsigned int size) {
|
||||
char *toret = (char *)malloc(size * 3 + 1);
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
sprintf(toret + i * 3, "%02X ", (unsigned char)str[i]);
|
||||
}
|
||||
toret[size * 3] = 0;
|
||||
return toret;
|
||||
}
|
||||
|
||||
TilesPattern::TilesPattern() {
|
||||
tilesPerRow = 16;
|
||||
numberOfTiles = 16;
|
||||
transformVector.push_back(std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9,
|
||||
11, 12, 13, 14, 15, 16});
|
||||
// std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, 11, 12, 13, 14, 15, 16});
|
||||
|
||||
// transformVector.push_back(std::vector<int>{0, 1, 2, 3});
|
||||
// transformVector.push_back(std::vector<int>{4, 5, 6, 7});
|
||||
// transformVector.push_back(std::vector<int>{8, 9, 11, 12});
|
||||
// transformVector.push_back(std::vector<int>{13, 14, 15, 16});
|
||||
transformVector.push_back(std::vector<int>{0, 1, 2, 3});
|
||||
transformVector.push_back(std::vector<int>{4, 5, 6, 7});
|
||||
transformVector.push_back(std::vector<int>{8, 9, 11, 12});
|
||||
transformVector.push_back(std::vector<int>{13, 14, 15, 16});
|
||||
}
|
||||
|
||||
// [pattern]
|
||||
// name = "32x32 B (4x4)"
|
||||
// number_of_tile = 16
|
||||
@@ -97,62 +67,6 @@ void TilesPattern::default_settings() {
|
||||
std::cout << transformVector.size() << std::endl;
|
||||
}
|
||||
|
||||
// bool TilesPattern::load(std::string patternFile) {
|
||||
// QSettings pFile(patternFile, QSettings::IniFormat);
|
||||
// name = pFile.value("pattern/name").toString();
|
||||
// description = pFile.value("pattern/description").toString();
|
||||
// numberOfTiles = pFile.value("pattern/number_of_tile").toInt();
|
||||
// std::cout << name;
|
||||
// // unsigned int nbOfTile = pFile.value("_/number_of_tile").toUInt();
|
||||
// std::string patternString = pFile.value("pattern/pattern").toString();
|
||||
// std::cout << patternString;
|
||||
|
||||
// // Pattern String is a array description
|
||||
|
||||
// transformVector.clear();
|
||||
// QRegExp arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
|
||||
// int pos = 0;
|
||||
// while (arrayRegExp.indexIn(patternString, pos) != -1) {
|
||||
// std::string arrayString = arrayRegExp.cap(1);
|
||||
// std::vector<int> tmpVect;
|
||||
// // std::cout << arrayString;
|
||||
// unsigned int stringPos = 1;
|
||||
|
||||
// while (arrayString[stringPos] != ']') {
|
||||
// while (arrayString[stringPos].isSpace()) stringPos++;
|
||||
// QRegExp hex("([0-F|a-f]+)");
|
||||
// bool ok;
|
||||
// if (hex.indexIn(arrayString, stringPos) == stringPos) {
|
||||
// tmpVect.append(hex.cap(1).toInt(&ok, 16));
|
||||
// }
|
||||
// while (arrayString[stringPos].isSpace()) stringPos++;
|
||||
// stringPos++; // should be the comma
|
||||
// }
|
||||
// pos += arrayRegExp.matchedLength();
|
||||
// transformVector.append(tmpVect);
|
||||
// }
|
||||
// std::cout << transformVector.size() << transformVector;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
bool TilesPattern::loadPatterns() {
|
||||
// foreach (std::string fileName, patternDirectory.entryList(QDir::Files)) {
|
||||
// TilesPattern tp;
|
||||
// std::cout << "Loading " << fileName;
|
||||
// if (!tp.load(patternDirectory.absoluteFilePath(fileName))) return false;
|
||||
// m_Patterns[tp.name] = tp;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
TilesPattern TilesPattern::pattern(std::string name) {
|
||||
return m_Patterns[name];
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, TilesPattern> TilesPattern::Patterns() {
|
||||
return m_Patterns;
|
||||
}
|
||||
|
||||
std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
const std::vector<tile8> &tiles) const {
|
||||
unsigned int repeatOffsetY = 0;
|
||||
@@ -163,7 +77,7 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
std::vector<std::vector<tile8> > toret;
|
||||
unsigned int transPerRow = tilesPerRow / tVectWidth;
|
||||
unsigned int nbTransform = tiles.size() / numberOfTiles;
|
||||
printf("Tiles size : %d - nbtransform : %d - pattern number of tiles : %d",
|
||||
printf("Tiles size : %d\nnbtransform : %d\npattern number of tiles : %d\n",
|
||||
tiles.size(), nbTransform, numberOfTiles);
|
||||
|
||||
if (transPerRow > nbTransform)
|
||||
@@ -173,15 +87,11 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
((unsigned int)(((double)nbTransform / (double)transPerRow) + 0.5)) *
|
||||
tVectHeight);
|
||||
|
||||
std::vector<std::vector<tile8> > vec(toret);
|
||||
auto it = vec.begin();
|
||||
for (auto &each : vec) {
|
||||
for (auto &each : toret) {
|
||||
each.resize(tilesPerRow);
|
||||
}
|
||||
// while (it.hasNext()) {
|
||||
// it.next().resize(tilesPerRow);
|
||||
// }
|
||||
// std::cout << toret[0].size() << "x" << toret.size();
|
||||
|
||||
std::cout << toret[0].size() << " x " << toret.size();
|
||||
while (repeat != nbTransform) {
|
||||
std::cout << "repeat" << repeat;
|
||||
for (unsigned int j = 0; j < tVectHeight; j++) {
|
||||
@@ -190,7 +100,8 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
unsigned int posX = i + repeatOffsetX;
|
||||
unsigned int posY = j + repeatOffsetY;
|
||||
printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile);
|
||||
toret[posY][posX] = tiles[posTile];
|
||||
// toret[posY][posX] = tiles[posTile];
|
||||
toret.at(posY).at(posX) = tiles[posTile];
|
||||
}
|
||||
}
|
||||
if (repeatOffsetX + tVectWidth == tilesPerRow) {
|
||||
@@ -240,21 +151,7 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
return pattern.transform(tiles);
|
||||
}
|
||||
|
||||
std::vector<std::vector<tile8> > TilesPattern::transform(
|
||||
const std::string id, const std::vector<tile8> &tiles) {
|
||||
return m_Patterns[id].transform(tiles);
|
||||
}
|
||||
|
||||
std::vector<tile8> TilesPattern::reverse(const TilesPattern &pattern,
|
||||
const std::vector<tile8> &tiles) {
|
||||
return pattern.reverse(tiles);
|
||||
}
|
||||
|
||||
TilePreset::TilePreset() {
|
||||
name = "";
|
||||
romName = "";
|
||||
romType = "";
|
||||
|
||||
pcTilesLocation = -1;
|
||||
SNESTilesLocation = 0;
|
||||
length = 0;
|
||||
|
||||
@@ -17,6 +17,9 @@ using byte = unsigned char;
|
||||
using ushort = unsigned short;
|
||||
using uint = unsigned int;
|
||||
|
||||
// vhopppcc cccccccc
|
||||
// [0, 1]
|
||||
// [2, 3]
|
||||
class TileInfo {
|
||||
public:
|
||||
ushort id_;
|
||||
@@ -24,38 +27,24 @@ class TileInfo {
|
||||
ushort vertical_mirror_;
|
||||
ushort horizontal_mirror_;
|
||||
byte palette_;
|
||||
TileInfo() {} // vhopppcc cccccccc
|
||||
TileInfo() {}
|
||||
TileInfo(ushort id, byte palette, ushort v, ushort h, ushort o)
|
||||
: id_(id),
|
||||
palette_(palette),
|
||||
vertical_mirror_(v),
|
||||
horizontal_mirror_(h),
|
||||
over_(o) {}
|
||||
ushort toShort();
|
||||
};
|
||||
|
||||
class Tile32 {
|
||||
public:
|
||||
//[0,1]
|
||||
//[2,3]
|
||||
ushort tile0_;
|
||||
ushort tile1_;
|
||||
ushort tile2_;
|
||||
ushort tile3_;
|
||||
|
||||
Tile32(ushort tile0, ushort tile1, ushort tile2, ushort tile3)
|
||||
: tile0_(tile0), tile1_(tile1), tile2_(tile2), tile3_(tile3) {}
|
||||
|
||||
explicit Tile32(unsigned long tiles)
|
||||
: tile0_(tiles),
|
||||
tile1_(tiles >> 16),
|
||||
tile2_(tiles >> 32),
|
||||
tile3_(tiles >> 48) {}
|
||||
|
||||
unsigned long getLongValue() {
|
||||
return ((unsigned long)tile3_ << 48) | ((unsigned long)tile2_ << 32) |
|
||||
((unsigned long)tile1_ << 16) | (unsigned long)(tile0_);
|
||||
}
|
||||
Tile32(ushort t0, ushort t1, ushort t2, ushort t3)
|
||||
: tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {}
|
||||
};
|
||||
|
||||
class Tile16 {
|
||||
@@ -65,31 +54,14 @@ class Tile16 {
|
||||
TileInfo tile2_;
|
||||
TileInfo tile3_;
|
||||
std::vector<TileInfo> tiles_info;
|
||||
//[0,1]
|
||||
//[2,3]
|
||||
|
||||
Tile16(TileInfo tile0, TileInfo tile1, TileInfo tile2, TileInfo tile3)
|
||||
: tile0_(tile0), tile1_(tile1), tile2_(tile2), tile3_(tile3) {
|
||||
Tile16(TileInfo t0, TileInfo t1, TileInfo t2, TileInfo t3)
|
||||
: tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {
|
||||
tiles_info.push_back(tile0_);
|
||||
tiles_info.push_back(tile1_);
|
||||
tiles_info.push_back(tile2_);
|
||||
tiles_info.push_back(tile3_);
|
||||
}
|
||||
|
||||
explicit Tile16(unsigned long tiles) {
|
||||
// tile0_ = GFX.gettilesinfo((ushort)tiles);
|
||||
// tile1_ = GFX.gettilesinfo((ushort)(tiles >> 16));
|
||||
// tile2_ = GFX.gettilesinfo((ushort)(tiles >> 32));
|
||||
// tile3_ = GFX.gettilesinfo((ushort)(tiles >> 48));
|
||||
}
|
||||
|
||||
unsigned long getLongValue() {
|
||||
return ((unsigned long)(tile3_.toShort()) << 48) |
|
||||
((unsigned long)(tile2_.toShort()) << 32) |
|
||||
((unsigned long)(tile1_.toShort()) << 16) |
|
||||
(unsigned long)((tile0_.toShort()));
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
class TilesPattern {
|
||||
@@ -103,24 +75,15 @@ class TilesPattern {
|
||||
|
||||
void default_settings();
|
||||
|
||||
static bool loadPatterns();
|
||||
static TilesPattern pattern(std::string name);
|
||||
static std::unordered_map<std::string, TilesPattern> Patterns();
|
||||
static std::vector<std::vector<tile8> > transform(
|
||||
const TilesPattern& pattern, const std::vector<tile8>& tiles);
|
||||
static std::vector<std::vector<tile8> > transform(
|
||||
const std::string id, const std::vector<tile8>& tiles);
|
||||
static std::vector<tile8> reverse(const TilesPattern& pattern,
|
||||
const std::vector<tile8>& tiles);
|
||||
|
||||
protected:
|
||||
std::vector<std::vector<tile8> > transform(
|
||||
const std::vector<tile8>& tiles) const;
|
||||
std::vector<tile8> reverse(const std::vector<tile8>& tiles) const;
|
||||
std::vector<std::vector<int> > transformVector;
|
||||
|
||||
private:
|
||||
static std::unordered_map<std::string, TilesPattern> m_Patterns;
|
||||
};
|
||||
|
||||
class TilePreset {
|
||||
@@ -130,19 +93,15 @@ class TilePreset {
|
||||
bool save(const std::string& file);
|
||||
bool load(const std::string& file);
|
||||
|
||||
std::string name;
|
||||
std::string romName;
|
||||
std::string romType;
|
||||
TilesPattern tilesPattern;
|
||||
|
||||
unsigned int SNESTilesLocation;
|
||||
int pcTilesLocation;
|
||||
unsigned int SNESPaletteLocation;
|
||||
unsigned int pcPaletteLocation;
|
||||
bool paletteNoZeroColor;
|
||||
unsigned int length;
|
||||
int pcTilesLocation;
|
||||
uint16_t SNESTilesLocation;
|
||||
uint16_t SNESPaletteLocation;
|
||||
uint32_t pcPaletteLocation;
|
||||
uint32_t length;
|
||||
uint32_t bpp;
|
||||
|
||||
unsigned int bpp;
|
||||
TilesPattern tilesPattern;
|
||||
std::string compression;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#include "Compression.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "compressions/alttpcompression.h"
|
||||
#include "compressions/stdnintendo.h"
|
||||
|
||||
#define INITIAL_ALLOC_SIZE 1024
|
||||
|
||||
#define D_CMD_COPY 0
|
||||
#define D_CMD_BYTE_REPEAT 1
|
||||
#define D_CMD_WORD_REPEAT 2
|
||||
#define D_CMD_BYTE_INC 3
|
||||
#define D_CMD_COPY_EXISTING 4
|
||||
|
||||
#define D_MAX_NORMAL_length 32
|
||||
#define D_max_length 1024
|
||||
|
||||
#define D_NINTENDO_C_MODE1 0
|
||||
#define D_NINTENDO_C_MODE2 1
|
||||
|
||||
#define X_ std::byte {
|
||||
#define _X }
|
||||
|
||||
#define MY_BUILD_HEADER(command, length) (command << 5) + ((length)-1)
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Utils {
|
||||
|
||||
char* ALTTPCompression::DecompressGfx(const char* c_data,
|
||||
const unsigned int start,
|
||||
unsigned int max_length,
|
||||
unsigned int* uncompressed_data_size,
|
||||
unsigned int* compressed_length) {
|
||||
char* data = alttp_decompress_gfx(c_data, start, max_length,
|
||||
uncompressed_data_size, compressed_length);
|
||||
return data;
|
||||
}
|
||||
|
||||
char* ALTTPCompression::DecompressOverworld(
|
||||
const char* c_data, const unsigned int start, unsigned int max_length,
|
||||
unsigned int* uncompressed_data_size, unsigned int* compressed_length) {
|
||||
char* toret = alttp_decompress_overworld(
|
||||
c_data, start, max_length, uncompressed_data_size, compressed_length);
|
||||
return toret;
|
||||
}
|
||||
|
||||
char* ALTTPCompression::CompressGfx(const char* u_data,
|
||||
const unsigned int start,
|
||||
const unsigned int length,
|
||||
unsigned int* compressed_size) {
|
||||
return alttp_compress_gfx(u_data, start, length, compressed_size);
|
||||
}
|
||||
|
||||
char* ALTTPCompression::CompressOverworld(const char* u_data,
|
||||
const unsigned int start,
|
||||
const unsigned int length,
|
||||
unsigned int* compressed_size) {
|
||||
return alttp_compress_overworld(u_data, start, length, compressed_size);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef YAZE_APPLICATION_UTILS_COMPRESSION_H
|
||||
#define YAZE_APPLICATION_UTILS_COMPRESSION_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
namespace Utils {
|
||||
|
||||
class ALTTPCompression {
|
||||
public:
|
||||
|
||||
char* DecompressGfx(const char* c_data, const unsigned int start,
|
||||
unsigned int max_length,
|
||||
unsigned int* uncompressed_data_size,
|
||||
unsigned int* compressed_length);
|
||||
char* DecompressOverworld(const char* c_data, const unsigned int start,
|
||||
unsigned int max_length,
|
||||
unsigned int* uncompressed_data_size,
|
||||
unsigned int* compressed_length);
|
||||
|
||||
char* CompressGfx(const char* u_data, const unsigned int start,
|
||||
const unsigned int length, unsigned int* compressed_size);
|
||||
char* CompressOverworld(const char* u_data, const unsigned int start,
|
||||
const unsigned int length,
|
||||
unsigned int* compressed_size);
|
||||
|
||||
private:
|
||||
std::string compression_error_;
|
||||
std::string decompression_error_;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,7 @@ void ROM::LoadFromFile(const std::string &path) {
|
||||
// Reading data to array of unsigned chars
|
||||
file = fopen(path.c_str(), "r+");
|
||||
current_rom_ = (unsigned char *)malloc(size);
|
||||
rom_data_ = (char *) malloc(size);
|
||||
rom_data_ = (char *)malloc(size);
|
||||
fread(rom_data_, sizeof(char), size, file);
|
||||
int bytes_read = fread(current_rom_, sizeof(unsigned char), size, file);
|
||||
fclose(file);
|
||||
@@ -33,38 +33,66 @@ void ROM::LoadFromFile(const std::string &path) {
|
||||
|
||||
std::vector<tile8> ROM::ExtractTiles(TilePreset &preset) {
|
||||
std::cout << "Begin ROM::ExtractTiles" << std::endl;
|
||||
std::vector<tile8> rawTiles;
|
||||
uint filePos = 0;
|
||||
unsigned int size = preset.length;
|
||||
filePos =
|
||||
getRomPosition(preset, preset.pcTilesLocation, preset.SNESTilesLocation);
|
||||
char *data = (char *)rom_data_ + filePos;
|
||||
memcpy(data, rom_data_ + filePos, preset.length);
|
||||
|
||||
data =
|
||||
alttp_decompress_gfx(data, 0, preset.length, &size, &lastCompressedSize);
|
||||
uint filePos = 0;
|
||||
uint size_out = 0;
|
||||
uint size = preset.length;
|
||||
int tilePos = preset.pcTilesLocation;
|
||||
std::vector<tile8> rawTiles;
|
||||
|
||||
filePos = getRomPosition(preset, tilePos, preset.SNESTilesLocation);
|
||||
|
||||
// decompress the graphics
|
||||
char *data = (char *)malloc(sizeof(char) * size);
|
||||
memcpy(data, (rom_data_ + filePos), size);
|
||||
data = alttp_decompress_gfx(data, 0, size, &size_out, &lastCompressedSize);
|
||||
std::cout << "size: " << size << std::endl;
|
||||
std::cout << "lastCompressedSize: " << lastCompressedSize << std::endl;
|
||||
|
||||
if (data == NULL) {
|
||||
std:: cout << alttp_decompression_error << std::endl;
|
||||
std::cout << alttp_decompression_error << std::endl;
|
||||
return rawTiles;
|
||||
}
|
||||
|
||||
// unpack the tiles based on their depth
|
||||
unsigned tileCpt = 0;
|
||||
std::cout << "Unpacking tiles..." << std::endl;
|
||||
for (unsigned int tilePos = 0; tilePos < size; tilePos += preset.bpp * 8) {
|
||||
std::cout << "Unpacking tile..." << std::endl;
|
||||
tile8 newTile = unpack_bpp_tile(data, tilePos, preset.bpp);
|
||||
newTile.id = tileCpt;
|
||||
rawTiles.push_back(newTile);
|
||||
tileCpt++;
|
||||
}
|
||||
|
||||
free(data);
|
||||
std::cout << "End ROM::ExtractTiles" << std::endl;
|
||||
free(data);
|
||||
return rawTiles;
|
||||
}
|
||||
|
||||
SNESPalette ROM::ExtractPalette(TilePreset &preset) {
|
||||
unsigned int filePos = getRomPosition(preset, preset.pcPaletteLocation,
|
||||
preset.SNESPaletteLocation);
|
||||
std::cout << "Palette pos : " << filePos << std::endl; // TODO: make this hex
|
||||
unsigned int palette_size = pow(2, preset.bpp); // - 1;
|
||||
char *ab = (char *)malloc(sizeof(char) * (palette_size * 2));
|
||||
memcpy(ab, rom_data_ + filePos, palette_size * 2);
|
||||
|
||||
for (int i = 0; i < palette_size; i++) {
|
||||
std::cout << ab[i];
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
const char *data = ab;
|
||||
SNESPalette pal(ab);
|
||||
if (preset.paletteNoZeroColor) {
|
||||
SNESColor col;
|
||||
|
||||
col.setRgb(ImVec4(153, 153, 153, 255));
|
||||
pal.colors.push_back(col);
|
||||
pal.colors.erase(pal.colors.begin(),
|
||||
pal.colors.begin() + pal.colors.size() - 1);
|
||||
}
|
||||
return pal;
|
||||
}
|
||||
|
||||
unsigned int ROM::getRomPosition(const TilePreset &preset, int directAddr,
|
||||
unsigned int snesAddr) {
|
||||
bool romHasHeader = false; // romInfo.hasHeader
|
||||
@@ -82,14 +110,6 @@ unsigned int ROM::getRomPosition(const TilePreset &preset, int directAddr,
|
||||
return filePos;
|
||||
}
|
||||
|
||||
int ROM::SnesToPc(int addr) {
|
||||
if (addr >= 0x808000) {
|
||||
addr -= 0x808000;
|
||||
}
|
||||
int temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000);
|
||||
return (temp + 0x0);
|
||||
}
|
||||
|
||||
int AddressFromBytes(byte addr1, byte addr2, byte addr3) {
|
||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||
}
|
||||
@@ -98,38 +118,6 @@ short ROM::AddressFromBytes(byte addr1, byte addr2) {
|
||||
return (short)((addr1 << 8) | (addr2));
|
||||
}
|
||||
|
||||
void ROM::Write(int addr, byte value) { current_rom_[addr] = value; }
|
||||
|
||||
void ROM::WriteLong(int addr, int value) {
|
||||
current_rom_[addr] = (byte)(value & 0xFF);
|
||||
current_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
|
||||
current_rom_[addr + 2] = (byte)((value >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
void ROM::WriteShort(int addr, int value) {
|
||||
current_rom_[addr] = (byte)(value & 0xFF);
|
||||
current_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
int ROM::ReadLong(int addr) {
|
||||
return ((current_rom_[addr + 2] << 16) + (current_rom_[addr + 1] << 8) +
|
||||
current_rom_[addr]);
|
||||
}
|
||||
|
||||
ushort ROM::ReadShort(int addr) {
|
||||
return (ushort)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
|
||||
}
|
||||
|
||||
short ROM::ReadRealShort(int addr) {
|
||||
return (short)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
|
||||
}
|
||||
|
||||
ushort ROM::ReadByte(int addr) { return (ushort)(current_rom_[addr]); }
|
||||
|
||||
short ROM::ReadReverseShort(int addr) {
|
||||
return (short)((current_rom_[addr] << 8) + current_rom_[addr + 1]);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Compression.h"
|
||||
|
||||
#include "Core/Constants.h"
|
||||
#include "Graphics/Tile.h"
|
||||
#include "compressions/alttpcompression.h"
|
||||
@@ -32,25 +32,14 @@ class ROM {
|
||||
public:
|
||||
void LoadFromFile(const std::string& path);
|
||||
std::vector<tile8> ExtractTiles(TilePreset& preset);
|
||||
SNESPalette ExtractPalette(TilePreset& preset);
|
||||
unsigned int getRomPosition(const TilePreset& preset, int directAddr,
|
||||
unsigned int snesAddr);
|
||||
|
||||
int SnesToPc(int addr);
|
||||
short AddressFromBytes(byte addr1, byte addr2);
|
||||
ushort ReadShort(int addr);
|
||||
void Write(int addr, byte value);
|
||||
short ReadReverseShort(int addr);
|
||||
ushort ReadByte(int addr);
|
||||
short ReadRealShort(int addr);
|
||||
void WriteShort(int addr, int value);
|
||||
int ReadLong(int addr);
|
||||
void WriteLong(int addr, int value);
|
||||
inline byte* GetRawData() { return current_rom_; }
|
||||
|
||||
const unsigned char* getTitle() const { return title; }
|
||||
unsigned int getSize() const { return size; }
|
||||
char getVersion() const { return version; }
|
||||
|
||||
bool isLoaded() const { return loaded; }
|
||||
|
||||
private:
|
||||
@@ -62,14 +51,14 @@ class ROM {
|
||||
bool fastrom;
|
||||
long int size;
|
||||
enum rom_type type;
|
||||
unsigned char title[21] = "ROM Not Loaded";
|
||||
unsigned char version;
|
||||
|
||||
bool overrideHeaderInfo;
|
||||
bool overridenHeaderInfo;
|
||||
unsigned int lastUnCompressSize;
|
||||
unsigned int lastCompressedSize;
|
||||
unsigned int lastCompressSize;
|
||||
unsigned char version;
|
||||
unsigned char title[21] = "ROM Not Loaded";
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -45,7 +45,6 @@ add_executable(
|
||||
Application/Graphics/Scene.cc
|
||||
Application/Editor/Editor.cc
|
||||
Application/Editor/OverworldEditor.cc
|
||||
Application/Utils/Compression.cc
|
||||
Application/Utils/ROM.cc
|
||||
# GUI libraries
|
||||
${IMGUI_PATH}/imgui.cpp
|
||||
@@ -64,6 +63,7 @@ add_executable(
|
||||
${SNESHACKING_PATH}/tilepng.c
|
||||
${SNESHACKING_PATH}/palette.c
|
||||
${SNESHACKING_PATH}/rommapping.c
|
||||
${SNESHACKING_PATH}/mapping_lorom.c
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
|
||||
Reference in New Issue
Block a user