Bunch of updates refactoring adding some sneshacking code some gui stuff
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -19,8 +19,8 @@ Overworld::~Overworld() {
|
|||||||
free(allmapsTilesDW);
|
free(allmapsTilesDW);
|
||||||
free(allmapsTilesSP);
|
free(allmapsTilesSP);
|
||||||
|
|
||||||
delete overworldMapPointer;
|
delete[] overworldMapPointer;
|
||||||
delete owactualMapPointer;
|
delete[] owactualMapPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TileInfo GetTilesInfo(ushort tile) {
|
static TileInfo GetTilesInfo(ushort tile) {
|
||||||
|
|||||||
@@ -22,20 +22,10 @@ void Editor::UpdateScreen() {
|
|||||||
|
|
||||||
DrawYazeMenu();
|
DrawYazeMenu();
|
||||||
|
|
||||||
if (isLoaded) {
|
|
||||||
if (!doneLoaded) {
|
|
||||||
overworld.Load(rom);
|
|
||||||
overworld_texture = &overworld.owactualMapTexture;
|
|
||||||
doneLoaded = true;
|
|
||||||
}
|
|
||||||
// ImGui::Image((void*)(intptr_t)overworld_texture,
|
|
||||||
// ImVec2(overworld.overworldMapBitmap->GetWidth(),
|
|
||||||
// overworld.overworldMapBitmap->GetHeight()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::BeginTabBar("##TabBar")) {
|
if (ImGui::BeginTabBar("##TabBar")) {
|
||||||
DrawOverworldEditor();
|
DrawOverworldEditor();
|
||||||
DrawDungeonEditor();
|
DrawDungeonEditor();
|
||||||
|
DrawSpriteEditor();
|
||||||
DrawScreenEditor();
|
DrawScreenEditor();
|
||||||
DrawROMInfo();
|
DrawROMInfo();
|
||||||
ImGui::EndTabBar();
|
ImGui::EndTabBar();
|
||||||
@@ -50,6 +40,7 @@ void Editor::DrawYazeMenu() {
|
|||||||
DrawFileMenu();
|
DrawFileMenu();
|
||||||
DrawEditMenu();
|
DrawEditMenu();
|
||||||
DrawViewMenu();
|
DrawViewMenu();
|
||||||
|
DrawHelpMenu();
|
||||||
ImGui::EndMenuBar();
|
ImGui::EndMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +51,8 @@ void Editor::DrawYazeMenu() {
|
|||||||
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||||
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
||||||
rom.LoadFromFile(filePathName);
|
rom.LoadFromFile(filePathName);
|
||||||
isLoaded = true;
|
owEditor.SetRom(rom);
|
||||||
|
rom_data_ = (void *)rom.GetRawData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// close
|
// close
|
||||||
@@ -137,10 +129,16 @@ void Editor::DrawEditMenu() const {
|
|||||||
void Editor::DrawViewMenu() const {
|
void Editor::DrawViewMenu() const {
|
||||||
static bool show_imgui_metrics = false;
|
static bool show_imgui_metrics = false;
|
||||||
static bool show_imgui_style_editor = false;
|
static bool show_imgui_style_editor = false;
|
||||||
|
static bool show_memory_editor = false;
|
||||||
if (show_imgui_metrics) {
|
if (show_imgui_metrics) {
|
||||||
ImGui::ShowMetricsWindow(&show_imgui_metrics);
|
ImGui::ShowMetricsWindow(&show_imgui_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (show_memory_editor) {
|
||||||
|
static MemoryEditor mem_edit;
|
||||||
|
mem_edit.DrawWindow("Memory Editor", rom_data_, rom.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
if (show_imgui_style_editor) {
|
if (show_imgui_style_editor) {
|
||||||
ImGui::Begin("Style Editor (ImGui)", &show_imgui_style_editor);
|
ImGui::Begin("Style Editor (ImGui)", &show_imgui_style_editor);
|
||||||
ImGui::ShowStyleEditor();
|
ImGui::ShowStyleEditor();
|
||||||
@@ -154,6 +152,8 @@ void Editor::DrawViewMenu() const {
|
|||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (ImGui::BeginMenu("GUI Tools")) {
|
if (ImGui::BeginMenu("GUI Tools")) {
|
||||||
ImGui::MenuItem("Metrics (ImGui)", nullptr, &show_imgui_metrics);
|
ImGui::MenuItem("Metrics (ImGui)", nullptr, &show_imgui_metrics);
|
||||||
@@ -165,6 +165,14 @@ void Editor::DrawViewMenu() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::DrawHelpMenu() const {
|
||||||
|
if (ImGui::BeginMenu("Help")) {
|
||||||
|
if (ImGui::MenuItem("About")) {
|
||||||
|
}
|
||||||
|
ImGui::EndMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// first step would be to decompress all graphics data from the game
|
// first step would be to decompress all graphics data from the game
|
||||||
// (in alttp that's easy they're all located in the same location all the
|
// (in alttp that's easy they're all located in the same location all the
|
||||||
// same sheet size 128x32) have a code that convert PC address to SNES and
|
// same sheet size 128x32) have a code that convert PC address to SNES and
|
||||||
@@ -235,6 +243,12 @@ void Editor::DrawDungeonEditor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::DrawSpriteEditor() {
|
||||||
|
if (ImGui::BeginTabItem("Sprites")) {
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::DrawScreenEditor() {
|
void Editor::DrawScreenEditor() {
|
||||||
if (ImGui::BeginTabItem("Screens")) {
|
if (ImGui::BeginTabItem("Screens")) {
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
@@ -243,7 +257,7 @@ void Editor::DrawScreenEditor() {
|
|||||||
|
|
||||||
void Editor::DrawROMInfo() {
|
void Editor::DrawROMInfo() {
|
||||||
if (ImGui::BeginTabItem("ROM Info")) {
|
if (ImGui::BeginTabItem("ROM Info")) {
|
||||||
if (isLoaded) {
|
if (rom.isLoaded()) {
|
||||||
ImGui::Text("Title: %s", rom.getTitle());
|
ImGui::Text("Title: %s", rom.getTitle());
|
||||||
ImGui::Text("Version: %d", rom.getVersion());
|
ImGui::Text("Version: %d", rom.getVersion());
|
||||||
ImGui::Text("ROM Size: %ld", rom.getSize());
|
ImGui::Text("ROM Size: %ld", rom.getSize());
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "Core/Icons.h"
|
#include "Core/Icons.h"
|
||||||
#include "Data/Overworld.h"
|
|
||||||
#include "OverworldEditor.h"
|
#include "OverworldEditor.h"
|
||||||
#include "ImGuiFileDialog/ImGuiFileDialog.h"
|
#include "ImGuiFileDialog/ImGuiFileDialog.h"
|
||||||
#include "Utils/ROM.h"
|
#include "Utils/ROM.h"
|
||||||
@@ -13,6 +12,7 @@
|
|||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/imgui_internal.h"
|
#include "imgui/imgui_internal.h"
|
||||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||||
|
#include "imgui/imgui_memory_editor.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace Application {
|
namespace Application {
|
||||||
@@ -27,20 +27,20 @@ class Editor {
|
|||||||
void DrawFileMenu() const;
|
void DrawFileMenu() const;
|
||||||
void DrawEditMenu() const;
|
void DrawEditMenu() const;
|
||||||
void DrawViewMenu() const;
|
void DrawViewMenu() const;
|
||||||
|
void DrawHelpMenu() const;
|
||||||
|
|
||||||
void DrawOverworldEditor();
|
void DrawOverworldEditor();
|
||||||
void DrawDungeonEditor();
|
void DrawDungeonEditor();
|
||||||
|
void DrawSpriteEditor();
|
||||||
void DrawScreenEditor();
|
void DrawScreenEditor();
|
||||||
void DrawROMInfo();
|
void DrawROMInfo();
|
||||||
|
|
||||||
bool isLoaded = false;
|
OverworldEditor owEditor;
|
||||||
bool doneLoaded = false;
|
|
||||||
GLuint *overworld_texture;
|
|
||||||
Data::Overworld overworld;
|
|
||||||
::yaze::Application::Editor::OverworldEditor owEditor;
|
|
||||||
Utils::ROM rom;
|
Utils::ROM rom;
|
||||||
|
|
||||||
|
void* rom_data_;
|
||||||
|
|
||||||
|
bool isLoaded = true;
|
||||||
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "OverworldEditor.h"
|
#include "OverworldEditor.h"
|
||||||
#include "Core/Icons.h"
|
#include "Core/Icons.h"
|
||||||
|
#include "Graphics/Bitmap.h"
|
||||||
|
#include "Graphics/Tile.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@@ -7,6 +9,28 @@ namespace yaze {
|
|||||||
namespace Application {
|
namespace Application {
|
||||||
namespace Editor {
|
namespace Editor {
|
||||||
void OverworldEditor::Update() {
|
void OverworldEditor::Update() {
|
||||||
|
|
||||||
|
if (rom_.isLoaded()) {
|
||||||
|
if (!doneLoaded) {
|
||||||
|
overworld.Load(rom_);
|
||||||
|
Graphics::CreateAllGfxData(rom_.GetRawData(), allGfx16Ptr);
|
||||||
|
|
||||||
|
// allgfxBitmap.LoadBitmapFromROM(allGfx16Ptr, allgfx_texture,
|
||||||
|
// &allgfx_width,
|
||||||
|
// &allgfx_height);
|
||||||
|
doneLoaded = true;
|
||||||
|
}
|
||||||
|
// Graphics::tile8 all_tiles;
|
||||||
|
// all_tiles.id = 1;
|
||||||
|
// all_tiles.data =
|
||||||
|
// Graphics::export_tile_to_png(tile8 rawtile, const r_palette pal, const
|
||||||
|
// char *filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (show_changelist_) {
|
||||||
|
DrawChangelist();
|
||||||
|
}
|
||||||
|
|
||||||
DrawToolset();
|
DrawToolset();
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (ImGui::BeginTable("#owEditTable", 2, ow_edit_flags, ImVec2(0, 0))) {
|
if (ImGui::BeginTable("#owEditTable", 2, ow_edit_flags, ImVec2(0, 0))) {
|
||||||
@@ -21,7 +45,7 @@ void OverworldEditor::Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OverworldEditor::DrawToolset() {
|
void OverworldEditor::DrawToolset() {
|
||||||
if (ImGui::BeginTable("Toolset", 12, toolset_table_flags, ImVec2(0, 0))) {
|
if (ImGui::BeginTable("Toolset", 14, toolset_table_flags, ImVec2(0, 0))) {
|
||||||
|
|
||||||
ImGui::TableSetupColumn("#undoTool");
|
ImGui::TableSetupColumn("#undoTool");
|
||||||
ImGui::TableSetupColumn("#redoTool");
|
ImGui::TableSetupColumn("#redoTool");
|
||||||
@@ -31,10 +55,12 @@ void OverworldEditor::DrawToolset() {
|
|||||||
ImGui::TableSetupColumn("#zoomInTool");
|
ImGui::TableSetupColumn("#zoomInTool");
|
||||||
ImGui::TableSetupColumn("#separator");
|
ImGui::TableSetupColumn("#separator");
|
||||||
ImGui::TableSetupColumn("#history");
|
ImGui::TableSetupColumn("#history");
|
||||||
ImGui::TableSetupColumn("#entranceExitTool");
|
ImGui::TableSetupColumn("#entranceTool");
|
||||||
|
ImGui::TableSetupColumn("#exitTool");
|
||||||
ImGui::TableSetupColumn("#itemTool");
|
ImGui::TableSetupColumn("#itemTool");
|
||||||
ImGui::TableSetupColumn("#spriteTool");
|
ImGui::TableSetupColumn("#spriteTool");
|
||||||
ImGui::TableSetupColumn("#transportTool");
|
ImGui::TableSetupColumn("#transportTool");
|
||||||
|
ImGui::TableSetupColumn("#musicTool");
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Button(ICON_MD_UNDO);
|
ImGui::Button(ICON_MD_UNDO);
|
||||||
@@ -43,7 +69,12 @@ void OverworldEditor::DrawToolset() {
|
|||||||
ImGui::Button(ICON_MD_REDO);
|
ImGui::Button(ICON_MD_REDO);
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Button(ICON_MD_MANAGE_HISTORY);
|
if (ImGui::Button(ICON_MD_MANAGE_HISTORY)) {
|
||||||
|
if (!show_changelist_)
|
||||||
|
show_changelist_ = true;
|
||||||
|
else
|
||||||
|
show_changelist_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text(ICON_MD_MORE_VERT);
|
ImGui::Text(ICON_MD_MORE_VERT);
|
||||||
@@ -61,7 +92,10 @@ void OverworldEditor::DrawToolset() {
|
|||||||
ImGui::Button(ICON_MD_DRAW);
|
ImGui::Button(ICON_MD_DRAW);
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Button(ICON_MD_SENSOR_DOOR);
|
ImGui::Button(ICON_MD_DOOR_FRONT);
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Button(ICON_MD_DOOR_BACK);
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Button(ICON_MD_GRASS);
|
ImGui::Button(ICON_MD_GRASS);
|
||||||
@@ -72,6 +106,9 @@ void OverworldEditor::DrawToolset() {
|
|||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Button(ICON_MD_ADD_LOCATION);
|
ImGui::Button(ICON_MD_ADD_LOCATION);
|
||||||
|
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Button(ICON_MD_MUSIC_NOTE);
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,8 +158,8 @@ void OverworldEditor::DrawOverworldMapSettings() {
|
|||||||
ImGui::Text("Msg ID");
|
ImGui::Text("Msg ID");
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(50.f);
|
ImGui::SetNextItemWidth(50.f);
|
||||||
ImGui::InputText("##msgid", spr_palette_, kMessageIdSize);
|
ImGui::InputText("##msgid", spr_palette_, kMessageIdSize);
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Checkbox("Show grid", &opt_enable_grid);
|
ImGui::Checkbox("Show grid", &opt_enable_grid);
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
@@ -222,18 +259,35 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
}
|
}
|
||||||
void OverworldEditor::DrawTileSelector() {
|
void OverworldEditor::DrawTileSelector() {
|
||||||
if (ImGui::BeginTabBar("##TabBar")) {
|
if (ImGui::BeginTabBar("##TabBar")) {
|
||||||
|
if (ImGui::BeginTabItem("Tile8")) {
|
||||||
|
if (rom_.isLoaded()) {
|
||||||
|
ImGui::Image((void *)(intptr_t)overworld_texture,
|
||||||
|
ImVec2(overworld.overworldMapBitmap->GetWidth(),
|
||||||
|
overworld.overworldMapBitmap->GetHeight()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndTabItem();
|
||||||
|
}
|
||||||
if (ImGui::BeginTabItem("Tile16")) {
|
if (ImGui::BeginTabItem("Tile16")) {
|
||||||
|
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
}
|
}
|
||||||
if (ImGui::BeginTabItem("Tile8")) {
|
|
||||||
|
|
||||||
ImGui::EndTabItem();
|
|
||||||
}
|
|
||||||
ImGui::EndTabBar();
|
ImGui::EndTabBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OverworldEditor::DrawChangelist() {
|
||||||
|
if (!ImGui::Begin("Changelist")) {
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::Text("Test");
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Editor
|
} // namespace Editor
|
||||||
} // namespace Application
|
} // namespace Application
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
@@ -2,25 +2,50 @@
|
|||||||
#define YAZE_APPLICATION_EDITOR_OVERWORLDEDITOR_H
|
#define YAZE_APPLICATION_EDITOR_OVERWORLDEDITOR_H
|
||||||
|
|
||||||
#include "Core/Icons.h"
|
#include "Core/Icons.h"
|
||||||
|
#include "Data/Overworld.h"
|
||||||
|
#include "Utils/Compression.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/misc/cpp/imgui_stdlib.h"
|
#include "imgui/misc/cpp/imgui_stdlib.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace Application {
|
namespace Application {
|
||||||
namespace Editor {
|
namespace Editor {
|
||||||
|
|
||||||
|
using byte = unsigned char;
|
||||||
|
|
||||||
class OverworldEditor {
|
class OverworldEditor {
|
||||||
public:
|
public:
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
void SetRom(Utils::ROM & rom) { rom_ = rom; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DrawToolset();
|
void DrawToolset();
|
||||||
void DrawOverworldMapSettings();
|
void DrawOverworldMapSettings();
|
||||||
void DrawOverworldCanvas();
|
void DrawOverworldCanvas();
|
||||||
void DrawTileSelector();
|
void DrawTileSelector();
|
||||||
|
|
||||||
|
void DrawChangelist();
|
||||||
|
|
||||||
|
bool show_changelist_ = false;
|
||||||
|
|
||||||
|
Utils::ROM rom_;
|
||||||
|
Data::Overworld overworld;
|
||||||
|
Utils::ALTTPCompression alttp_compressor_;
|
||||||
|
Graphics::Bitmap allgfxBitmap;
|
||||||
|
int allgfx_width = 0;
|
||||||
|
int allgfx_height = 0;
|
||||||
|
GLuint *allgfx_texture = nullptr;
|
||||||
|
|
||||||
|
byte* allGfx16Ptr = new byte[(128 * 7136) / 2];
|
||||||
|
|
||||||
|
GLuint *overworld_texture;
|
||||||
|
|
||||||
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
|
||||||
ImGuiTableFlags ow_map_settings_flags = ImGuiTableFlags_Borders;
|
ImGuiTableFlags ow_map_settings_flags = ImGuiTableFlags_Borders;
|
||||||
ImGuiTableFlags ow_edit_flags = ImGuiTableFlags_Reorderable | ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingStretchSame;
|
ImGuiTableFlags ow_edit_flags = ImGuiTableFlags_Reorderable |
|
||||||
|
ImGuiTableFlags_Resizable |
|
||||||
|
ImGuiTableFlags_SizingStretchSame;
|
||||||
|
|
||||||
float canvas_table_ratio = 30.f;
|
float canvas_table_ratio = 30.f;
|
||||||
|
|
||||||
@@ -32,6 +57,9 @@ private:
|
|||||||
|
|
||||||
int current_world_ = 0;
|
int current_world_ = 0;
|
||||||
|
|
||||||
|
bool isLoaded = false;
|
||||||
|
bool doneLoaded = false;
|
||||||
|
|
||||||
constexpr static int kByteSize = 3;
|
constexpr static int kByteSize = 3;
|
||||||
constexpr static int kMessageIdSize = 5;
|
constexpr static int kMessageIdSize = 5;
|
||||||
constexpr static float kInputFieldSize = 30.f;
|
constexpr static float kInputFieldSize = 30.f;
|
||||||
|
|||||||
@@ -1,16 +1,181 @@
|
|||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
|
#include "Utils/ROM.h"
|
||||||
|
#include "Utils/Compression.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace Application {
|
namespace Application {
|
||||||
namespace Graphics {
|
namespace Graphics {
|
||||||
|
|
||||||
Bitmap::Bitmap(int width, int height, byte* data)
|
int GetPCGfxAddress(byte *romData, byte id) {
|
||||||
|
char** info1, **info2,** info3, **info4;
|
||||||
|
int gfxPointer1 =
|
||||||
|
Utils::lorom_snes_to_pc((romData[Constants::gfx_1_pointer + 1] << 8) +
|
||||||
|
(romData[Constants::gfx_1_pointer]), info1);
|
||||||
|
int gfxPointer2 =
|
||||||
|
Utils::lorom_snes_to_pc((romData[Constants::gfx_2_pointer + 1] << 8) +
|
||||||
|
(romData[Constants::gfx_2_pointer]), info2);
|
||||||
|
int gfxPointer3 =
|
||||||
|
Utils::lorom_snes_to_pc((romData[Constants::gfx_3_pointer + 1] << 8) +
|
||||||
|
(romData[Constants::gfx_3_pointer]), info3);
|
||||||
|
|
||||||
|
byte gfxGamePointer1 = romData[gfxPointer1 + id];
|
||||||
|
byte gfxGamePointer2 = romData[gfxPointer2 + id];
|
||||||
|
byte gfxGamePointer3 = romData[gfxPointer3 + id];
|
||||||
|
|
||||||
|
return Utils::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
|
||||||
|
|
||||||
|
Utils::ALTTPCompression alttp_compressor_;
|
||||||
|
|
||||||
|
byte *buffer = new byte[346624];
|
||||||
|
int bufferPos = 0;
|
||||||
|
byte *data = new byte[2048];
|
||||||
|
unsigned int uncompressedSize = 0;
|
||||||
|
unsigned int compressedSize = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < Constants::NumberOfSheets; i++) {
|
||||||
|
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
|
||||||
|
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
|
||||||
|
(i >= 127 && i <= 217) // Compressed 3bpp sprites
|
||||||
|
);
|
||||||
|
|
||||||
|
// uncompressed sheets
|
||||||
|
if (i >= 115 && i <= 126) {
|
||||||
|
data = new byte[Constants::Uncompressed3BPPSize];
|
||||||
|
int startAddress = GetPCGfxAddress(romData, (byte)i);
|
||||||
|
for (int j = 0; j < Constants::Uncompressed3BPPSize; j++) {
|
||||||
|
data[j] = romData[j + startAddress];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data = alttp_compressor_.DecompressGfx(
|
||||||
|
romData, GetPCGfxAddress(romData, (byte)i),
|
||||||
|
Constants::UncompressedSheetSize, &uncompressedSize, &compressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < sizeof(data); j++) {
|
||||||
|
buffer[j + bufferPos] = data[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferPos += sizeof(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
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};
|
||||||
|
int sheetPosition = 0;
|
||||||
|
|
||||||
|
// 8x8 tile
|
||||||
|
for (int s = 0; s < Constants::NumberOfSheets; s++) // Per Sheet
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 4; j++) // Per Tile Line Y
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 16; i++) // Per Tile Line X
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 8; y++) // Per Pixel Line
|
||||||
|
{
|
||||||
|
if (isbpp3[s]) {
|
||||||
|
byte lineBits0 =
|
||||||
|
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||||
|
byte lineBits1 =
|
||||||
|
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
|
||||||
|
byte 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;
|
||||||
|
|
||||||
|
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||||
|
pixdata += 1;
|
||||||
|
}
|
||||||
|
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||||
|
pixdata += 2;
|
||||||
|
}
|
||||||
|
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||||
|
pixdata += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||||
|
pixdata2 += 1;
|
||||||
|
}
|
||||||
|
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||||
|
pixdata2 += 2;
|
||||||
|
}
|
||||||
|
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||||
|
pixdata2 += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||||
|
(byte)((pixdata << 4) | pixdata2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
byte lineBits0 =
|
||||||
|
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
|
||||||
|
byte 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;
|
||||||
|
|
||||||
|
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||||
|
pixdata += 1;
|
||||||
|
}
|
||||||
|
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||||
|
pixdata += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||||
|
pixdata2 += 1;
|
||||||
|
}
|
||||||
|
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||||
|
pixdata2 += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||||
|
(byte)((pixdata << 4) | pixdata2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isbpp3[s]) {
|
||||||
|
sheetPosition += Constants::Uncompressed3BPPSize;
|
||||||
|
} else {
|
||||||
|
sheetPosition += Constants::UncompressedSheetSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte *allgfx16Data = (byte *) allgfx16Ptr;
|
||||||
|
|
||||||
|
for (int i = 0; i < 0x6F800; i++) {
|
||||||
|
allgfx16Data[i] = newData[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap::Bitmap(int width, int height, byte *data)
|
||||||
: width_(width), height_(height), pixel_data_(data) {}
|
: width_(width), height_(height), pixel_data_(data) {}
|
||||||
|
|
||||||
void Bitmap::Create(GLuint* out_texture) {
|
void Bitmap::Create(GLuint *out_texture) {
|
||||||
// // Read the pixel data from the ROM
|
// // Read the pixel data from the ROM
|
||||||
// SDL_RWops * src = SDL_RWFromMem(pixel_data_, 0);
|
// SDL_RWops * src = SDL_RWFromMem(pixel_data_, 0);
|
||||||
// // Create the surface from that RW stream
|
// // Create the surface from that RW stream
|
||||||
// SDL_Surface* surface = SDL_LoadBMP_RW(src, SDL_FALSE);
|
// SDL_Surface* surface = SDL_LoadBMP_RW(src, SDL_FALSE);
|
||||||
// GLenum mode = 0;
|
// GLenum mode = 0;
|
||||||
// Uint8 bpp = surface->format->BytesPerPixel;
|
// Uint8 bpp = surface->format->BytesPerPixel;
|
||||||
@@ -45,21 +210,18 @@ void Bitmap::Create(GLuint* out_texture) {
|
|||||||
*out_texture = image_texture;
|
*out_texture = image_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bitmap::GetWidth() {
|
int Bitmap::GetWidth() { return width_; }
|
||||||
return width_;
|
int Bitmap::GetHeight() { return height_; }
|
||||||
}
|
|
||||||
int Bitmap::GetHeight() {
|
|
||||||
return height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simple helper function to load an image into a OpenGL texture with common
|
// Simple helper function to load an image into a OpenGL texture with common
|
||||||
// settings
|
// settings
|
||||||
bool Bitmap::LoadBitmapFromROM(unsigned char* texture_data, GLuint* out_texture,
|
bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
|
||||||
int* out_width, int* out_height) {
|
int *out_width, int *out_height) {
|
||||||
// Load from file
|
// Load from file
|
||||||
int image_width = 0;
|
int image_width = 0;
|
||||||
int image_height = 0;
|
int image_height = 0;
|
||||||
if (texture_data == NULL) return false;
|
if (texture_data == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Create a OpenGL texture identifier
|
// Create a OpenGL texture identifier
|
||||||
GLuint image_texture;
|
GLuint image_texture;
|
||||||
@@ -70,9 +232,9 @@ bool Bitmap::LoadBitmapFromROM(unsigned char* texture_data, GLuint* out_texture,
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||||
GL_CLAMP_TO_EDGE); // This is required on WebGL for non
|
GL_CLAMP_TO_EDGE); // This is required on WebGL for non
|
||||||
// power-of-two textures
|
// power-of-two textures
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
|
||||||
|
|
||||||
// Upload pixels into texture
|
// Upload pixels into texture
|
||||||
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
||||||
@@ -88,6 +250,6 @@ bool Bitmap::LoadBitmapFromROM(unsigned char* texture_data, GLuint* out_texture,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
} // namespace Application
|
} // namespace Application
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Application {
|
|||||||
namespace Graphics {
|
namespace Graphics {
|
||||||
|
|
||||||
using byte = unsigned char;
|
using byte = unsigned char;
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
class Bitmap {
|
class Bitmap {
|
||||||
public:
|
public:
|
||||||
@@ -31,8 +32,14 @@ private:
|
|||||||
int width_;
|
int width_;
|
||||||
int height_;
|
int height_;
|
||||||
byte *pixel_data_;
|
byte *pixel_data_;
|
||||||
SDL_PixelFormat pixel_format_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool isbpp3[Constants::NumberOfSheets];
|
||||||
|
|
||||||
|
int GetPCGfxAddress(byte* romData, byte id);
|
||||||
|
byte* CreateAllGfxDataRaw(byte* romData);
|
||||||
|
void CreateAllGfxData(byte* romData, byte* allgfx16Ptr);
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
} // namespace Application
|
} // namespace Application
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ ushort TileInfo::toShort() {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* hexString(const char* str, const unsigned int size) {
|
char *hexString(const char *str, const unsigned int size) {
|
||||||
char* toret = (char*)malloc(size * 3 + 1);
|
char *toret = (char *)malloc(size * 3 + 1);
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
@@ -40,8 +40,8 @@ char* hexString(const char* str, const unsigned int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void export_tile_to_png(tile8 rawtile, const r_palette pal,
|
void export_tile_to_png(tile8 rawtile, const r_palette pal,
|
||||||
const char* filename) {
|
const char *filename) {
|
||||||
FILE* fp = fopen(filename, "wb");
|
FILE *fp = fopen(filename, "wb");
|
||||||
png_structp png_ptr =
|
png_structp png_ptr =
|
||||||
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||||
@@ -49,8 +49,8 @@ void export_tile_to_png(tile8 rawtile, const r_palette pal,
|
|||||||
png_set_strip_alpha(png_ptr);
|
png_set_strip_alpha(png_ptr);
|
||||||
png_read_update_info(png_ptr, info_ptr);
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
png_color* png_palette =
|
png_color *png_palette =
|
||||||
(png_color*)png_malloc(png_ptr, pal.size * sizeof(png_color));
|
(png_color *)png_malloc(png_ptr, pal.size * sizeof(png_color));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < pal.size; i++) {
|
for (unsigned int i = 0; i < pal.size; i++) {
|
||||||
png_palette[i].blue = pal.colors[i].blue;
|
png_palette[i].blue = pal.colors[i].blue;
|
||||||
@@ -65,9 +65,9 @@ void export_tile_to_png(tile8 rawtile, const r_palette pal,
|
|||||||
png_write_info(png_ptr, info_ptr);
|
png_write_info(png_ptr, info_ptr);
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
|
||||||
png_byte* row_pointers[8];
|
png_byte *row_pointers[8];
|
||||||
for (unsigned int i = 0; i < 8; i++) {
|
for (unsigned int i = 0; i < 8; i++) {
|
||||||
row_pointers[i] = (png_byte*)png_malloc(png_ptr, sizeof(png_byte));
|
row_pointers[i] = (png_byte *)png_malloc(png_ptr, sizeof(png_byte));
|
||||||
memcpy(row_pointers[i], rawtile.data + i * 8, 8);
|
memcpy(row_pointers[i], rawtile.data + i * 8, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,37 +80,37 @@ void export_tile_to_png(tile8 rawtile, const r_palette pal,
|
|||||||
png_free(png_ptr, row_pointers);
|
png_free(png_ptr, row_pointers);
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_bpp1_tile(const char* data, const unsigned int offset) {
|
tile8 unpack_bpp1_tile(const char *data, const unsigned int offset) {
|
||||||
return (unpack_bpp_tile(data, offset, 1));
|
return (unpack_bpp_tile(data, offset, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_bpp2_tile(const char* data, const unsigned int offset) {
|
tile8 unpack_bpp2_tile(const char *data, const unsigned int offset) {
|
||||||
return (unpack_bpp_tile(data, offset, 2));
|
return (unpack_bpp_tile(data, offset, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_bpp3_tile(const char* data, const unsigned int offset) {
|
tile8 unpack_bpp3_tile(const char *data, const unsigned int offset) {
|
||||||
return (unpack_bpp_tile(data, offset, 3));
|
return (unpack_bpp_tile(data, offset, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_bpp4_tile(const char* data, const unsigned int offset) {
|
tile8 unpack_bpp4_tile(const char *data, const unsigned int offset) {
|
||||||
return (unpack_bpp_tile(data, offset, 4));
|
return (unpack_bpp_tile(data, offset, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_bpp8_tile(const char* data, const unsigned int offset) {
|
tile8 unpack_bpp8_tile(const char *data, const unsigned int offset) {
|
||||||
return (unpack_bpp_tile(data, offset, 8));
|
return (unpack_bpp_tile(data, offset, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_mode7_tile(const char* data, const unsigned int offset) {
|
tile8 unpack_mode7_tile(const char *data, const unsigned int offset) {
|
||||||
tile8 tile;
|
tile8 tile;
|
||||||
memcpy(tile.data, data + offset, 64);
|
memcpy(tile.data, data + offset, 64);
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile8 unpack_bpp_tile(const char* data, const unsigned int offset,
|
tile8 unpack_bpp_tile(const char *data, const unsigned int offset,
|
||||||
const unsigned bpp) {
|
const unsigned bpp) {
|
||||||
tile8 tile;
|
tile8 tile;
|
||||||
assert(bpp >= 1 && bpp <= 8);
|
assert(bpp >= 1 && bpp <= 8);
|
||||||
unsigned int bpp_pos[8]; // More for conveniance and readibility
|
unsigned int bpp_pos[8]; // More for conveniance and readibility
|
||||||
for (int col = 0; col < 8; col++) {
|
for (int col = 0; col < 8; col++) {
|
||||||
for (int row = 0; row < 8; row++) {
|
for (int row = 0; row < 8; row++) {
|
||||||
if (bpp == 1) {
|
if (bpp == 1) {
|
||||||
@@ -155,33 +155,33 @@ tile8 unpack_bpp_tile(const char* data, const unsigned int offset,
|
|||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* pack_bpp1_tile(const tile8 tile) {
|
byte *pack_bpp1_tile(const tile8 tile) {
|
||||||
unsigned int p = 1;
|
unsigned int p = 1;
|
||||||
return pack_bpp_tile(tile, 1, &p);
|
return pack_bpp_tile(tile, 1, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* pack_bpp2_tile(const tile8 tile) {
|
byte *pack_bpp2_tile(const tile8 tile) {
|
||||||
unsigned int p = 1;
|
unsigned int p = 1;
|
||||||
return pack_bpp_tile(tile, 2, &p);
|
return pack_bpp_tile(tile, 2, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* pack_bpp3_tile(const tile8 tile) {
|
byte *pack_bpp3_tile(const tile8 tile) {
|
||||||
unsigned int p = 1;
|
unsigned int p = 1;
|
||||||
return pack_bpp_tile(tile, 3, &p);
|
return pack_bpp_tile(tile, 3, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* pack_bpp4_tile(const tile8 tile) {
|
byte *pack_bpp4_tile(const tile8 tile) {
|
||||||
unsigned int p = 1;
|
unsigned int p = 1;
|
||||||
return pack_bpp_tile(tile, 4, &p);
|
return pack_bpp_tile(tile, 4, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* pack_bpp8_tile(const tile8 tile) {
|
byte *pack_bpp8_tile(const tile8 tile) {
|
||||||
unsigned int p = 1;
|
unsigned int p = 1;
|
||||||
return pack_bpp_tile(tile, 8, &p);
|
return pack_bpp_tile(tile, 8, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* pack_bpp_tile(tile8 tile, const unsigned int bpp, unsigned int* size) {
|
byte *pack_bpp_tile(tile8 tile, const unsigned int bpp, unsigned int *size) {
|
||||||
byte* output = (byte*)malloc(bpp * 8);
|
byte *output = (byte *)malloc(bpp * 8);
|
||||||
memset(output, 0, bpp * 8);
|
memset(output, 0, bpp * 8);
|
||||||
unsigned maxcolor = 2 << bpp;
|
unsigned maxcolor = 2 << bpp;
|
||||||
*size = 0;
|
*size = 0;
|
||||||
@@ -189,14 +189,17 @@ byte* pack_bpp_tile(tile8 tile, const unsigned int bpp, unsigned int* size) {
|
|||||||
for (unsigned int col = 0; col < 8; col++) {
|
for (unsigned int col = 0; col < 8; col++) {
|
||||||
for (unsigned int row = 0; row < 8; row++) {
|
for (unsigned int row = 0; row < 8; row++) {
|
||||||
byte color = tile.data[col * 8 + row];
|
byte color = tile.data[col * 8 + row];
|
||||||
if (color > maxcolor) return NULL;
|
if (color > maxcolor)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (bpp == 1) output[col] += (byte)((color & 1) << (7 - row));
|
if (bpp == 1)
|
||||||
|
output[col] += (byte)((color & 1) << (7 - row));
|
||||||
if (bpp >= 2) {
|
if (bpp >= 2) {
|
||||||
output[col * 2] += (byte)((color & 1) << (7 - row));
|
output[col * 2] += (byte)((color & 1) << (7 - row));
|
||||||
output[col * 2 + 1] += (byte)(((color & 2) == 2) << (7 - row));
|
output[col * 2 + 1] += (byte)(((color & 2) == 2) << (7 - row));
|
||||||
}
|
}
|
||||||
if (bpp == 3) output[16 + col] += (byte)(((color & 4) == 4) << (7 - row));
|
if (bpp == 3)
|
||||||
|
output[16 + col] += (byte)(((color & 4) == 4) << (7 - row));
|
||||||
if (bpp >= 4) {
|
if (bpp >= 4) {
|
||||||
output[16 + col * 2] += (byte)(((color & 4) == 4) << (7 - row));
|
output[16 + col * 2] += (byte)(((color & 4) == 4) << (7 - row));
|
||||||
output[16 + col * 2 + 1] += (byte)(((color & 8) == 8) << (7 - row));
|
output[16 + col * 2 + 1] += (byte)(((color & 8) == 8) << (7 - row));
|
||||||
@@ -213,6 +216,6 @@ byte* pack_bpp_tile(tile8 tile, const unsigned int bpp, unsigned int* size) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Graphics
|
} // namespace Graphics
|
||||||
} // namespace Application
|
} // namespace Application
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ void ROM::LoadFromFile(const std::string& path) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
memcpy(title, current_rom_, 21);
|
memcpy(title, current_rom_, 21);
|
||||||
|
|
||||||
type = LoROM;
|
type = LoROM;
|
||||||
fastrom = (current_rom_[21] & 0b00110000) == 0b00110000;
|
fastrom = (current_rom_[21] & 0b00110000) == 0b00110000;
|
||||||
if (current_rom_[21] & 1)
|
if (current_rom_[21] & 1)
|
||||||
@@ -265,6 +266,11 @@ void ROM::LoadFromFile(const std::string& path) {
|
|||||||
make_sense = false;
|
make_sense = false;
|
||||||
if ((checksum ^ checksum_comp) == 0xFFFF)
|
if ((checksum ^ checksum_comp) == 0xFFFF)
|
||||||
make_sense = true;
|
make_sense = true;
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ROM::SnesToPc(int addr) {
|
int ROM::SnesToPc(int addr) {
|
||||||
@@ -293,7 +299,7 @@ int ROM::PcToSnes(int addr) {
|
|||||||
return ((addr * 2) & 0xFF0000) + (addr & 0x7FFF) + 0x8000;
|
return ((addr * 2) & 0xFF0000) + (addr & 0x7FFF) + 0x8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ROM::AddressFromBytes(byte addr1, byte addr2, byte addr3) {
|
int AddressFromBytes(byte addr1, byte addr2, byte addr3) {
|
||||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,12 @@ int hirom_pc_to_snes(const unsigned int pc_addr);
|
|||||||
int hirom_sram_pc_to_snes(const unsigned int pc_addr);
|
int hirom_sram_pc_to_snes(const unsigned int pc_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AddressFromBytes(byte addr1, byte addr2, byte addr3);
|
||||||
|
|
||||||
class ROM {
|
class ROM {
|
||||||
public:
|
public:
|
||||||
int SnesToPc(int addr);
|
int SnesToPc(int addr);
|
||||||
int PcToSnes(int addr);
|
int PcToSnes(int addr);
|
||||||
int AddressFromBytes(byte addr1, byte addr2, byte addr3);
|
|
||||||
short AddressFromBytes(byte addr1, byte addr2);
|
short AddressFromBytes(byte addr1, byte addr2);
|
||||||
ushort ReadShort(int addr);
|
ushort ReadShort(int addr);
|
||||||
void Write(int addr, byte value);
|
void Write(int addr, byte value);
|
||||||
@@ -69,10 +70,14 @@ class ROM {
|
|||||||
unsigned int getSize() const { return size; }
|
unsigned int getSize() const { return size; }
|
||||||
char getVersion() const { return version; }
|
char getVersion() const { return version; }
|
||||||
|
|
||||||
|
bool isLoaded() const { return loaded; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<char> original_rom_;
|
std::vector<char> original_rom_;
|
||||||
std::vector<char> working_rom_;
|
std::vector<char> working_rom_;
|
||||||
|
|
||||||
|
bool loaded = false;
|
||||||
|
|
||||||
byte* current_rom_;
|
byte* current_rom_;
|
||||||
|
|
||||||
enum rom_type type;
|
enum rom_type type;
|
||||||
|
|||||||
Reference in New Issue
Block a user