Skip to content

Commit

Permalink
cleanup dungeon room constants
Browse files Browse the repository at this point in the history
  • Loading branch information
scawful committed Nov 20, 2023
1 parent 72ef0d0 commit 4ef2540
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 195 deletions.
59 changes: 0 additions & 59 deletions src/app/core/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,65 +165,6 @@ constexpr int kTilesheetWidth = 128;
constexpr int kTilesheetHeight = 32;
constexpr int kTilesheetDepth = 8;

// ============================================================================
// Dungeon Related Variables
// ============================================================================

// That could be turned into a pointer :
constexpr int dungeons_palettes_groups = 0x75460; // JP 0x67DD0
constexpr int dungeons_main_bg_palette_pointers = 0xDEC4B; // JP Same
constexpr int dungeons_palettes =
0xDD734; // JP Same (where all dungeons palettes are)

// That could be turned into a pointer :
constexpr int room_items_pointers = 0xDB69; // JP 0xDB67

constexpr int rooms_sprite_pointer = 0x4C298; // JP Same //2byte bank 09D62E
constexpr int room_header_pointer = 0xB5DD; // LONG
constexpr int room_header_pointers_bank = 0xB5E7; // JP Same

constexpr int gfx_groups_pointer = 0x6237;
constexpr int room_object_layout_pointer = 0x882D;

constexpr int room_object_pointer = 0x874C; // Long pointer

constexpr int chests_length_pointer = 0xEBF6;
constexpr int chests_data_pointer1 = 0xEBFB;
// constexpr int chests_data_pointer2 = 0xEC0A; //Disabled for now could be used
// for expansion constexpr int chests_data_pointer3 = 0xEC10; //Disabled for now
// could be used for expansion

constexpr int blocks_length = 0x8896; // word value
constexpr int blocks_pointer1 = 0x15AFA;
constexpr int blocks_pointer2 = 0x15B01;
constexpr int blocks_pointer3 = 0x15B08;
constexpr int blocks_pointer4 = 0x15B0F;

constexpr int torch_data = 0x2736A; // JP 0x2704A
constexpr int torches_length_pointer = 0x88C1;

constexpr int sprites_data =
0x4D8B0; // It use the unused pointers to have more space //Save purpose
constexpr int sprites_data_empty_room = 0x4D8AE;
constexpr int sprites_end_data = 0x4EC9E;

constexpr int pit_pointer = 0x394AB;
constexpr int pit_count = 0x394A6;

constexpr int doorPointers = 0xF83C0;

// doors
constexpr int door_gfx_up = 0x4D9E;
constexpr int door_gfx_down = 0x4E06;
constexpr int door_gfx_cavexit_down = 0x4E06;
constexpr int door_gfx_left = 0x4E66;
constexpr int door_gfx_right = 0x4EC6;

constexpr int door_pos_up = 0x197E;
constexpr int door_pos_down = 0x1996;
constexpr int door_pos_left = 0x19AE;
constexpr int door_pos_right = 0x19C6;

// TEXT EDITOR RELATED CONSTANTS
constexpr int gfx_font = 0x70000; // 2bpp format
constexpr int text_data = 0xE0000;
Expand Down
33 changes: 14 additions & 19 deletions src/app/editor/dungeon_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace yaze {
namespace app {
namespace editor {

void DungeonEditor::Update() {
absl::Status DungeonEditor::Update() {
if (!is_loaded_ && rom()->isLoaded()) {
for (int i = 0; i < 0x100; i++) {
rooms_.emplace_back(zelda3::dungeon::Room(i));
rooms_[i].LoadHeader();
// rooms_[i].LoadRoomGraphics(rooms_[i].blockset);
rooms_[i].LoadRoomGraphics(rooms_[i].blockset);
}
is_loaded_ = true;
}
Expand Down Expand Up @@ -59,20 +59,14 @@ void DungeonEditor::Update() {
DrawTileSelector();
ImGui::EndTable();
}
return absl::OkStatus();
}

// Using ImGui Custom Tabs show each individual room the user selects from the
// Buttons above to open a canvas for each individual room.
void DungeonEditor::DrawDungeonTabView() {
static int next_tab_id = 0;

// TabItemButton() and Leading/Trailing flags are distinct features which we
// will demo together. (It is possible to submit regular tabs with
// Leading/Trailing flags, or TabItemButton tabs without Leading/Trailing
// flags... but they tend to make more sense together)
static bool show_trailing_button = true;
ImGui::Checkbox("Show Trailing TabItemButton()", &show_trailing_button);

// Expose some other flags which are useful to showcase how they interact with
// Leading/Trailing tabs
static ImGuiTabBarFlags tab_bar_flags =
Expand All @@ -92,14 +86,11 @@ void DungeonEditor::DrawDungeonTabView() {
ImGuiTabBarFlags_FittingPolicyScroll);

if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags)) {
// Demo Trailing Tabs: click the "+" button to add a new tab (in your app
// you may want to use a font icon instead of the "+") Note that we submit
// it before the regular tabs, but because of the ImGuiTabItemFlags_Trailing
// flag it will always appear at the end.
if (show_trailing_button)
if (ImGui::TabItemButton(
"+", ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip))
active_rooms_.push_back(next_tab_id++); // Add new tab
// TODO: Manage the room that is being added to the tab bar.
if (ImGui::TabItemButton(
"+", ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip)) {
active_rooms_.push_back(next_tab_id++); // Add new tab
}

// Submit our regular tabs
for (int n = 0; n < active_rooms_.Size;) {
Expand Down Expand Up @@ -168,10 +159,14 @@ void DungeonEditor::DrawToolset() {
ImGui::TableSetupColumn("#spriteTool");

ImGui::TableNextColumn();
ImGui::Button(ICON_MD_UNDO);
if (ImGui::Button(ICON_MD_UNDO)) {
PRINT_IF_ERROR(Undo());
}

ImGui::TableNextColumn();
ImGui::Button(ICON_MD_REDO);
if (ImGui::Button(ICON_MD_REDO)) {
PRINT_IF_ERROR(Redo());
}

ImGui::TableNextColumn();
ImGui::Button(ICON_MD_MANAGE_HISTORY);
Expand Down
11 changes: 9 additions & 2 deletions src/app/editor/dungeon_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <imgui/imgui.h>

#include "app/core/common.h"
#include "app/core/editor.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/rom.h"
Expand All @@ -14,9 +15,14 @@ namespace yaze {
namespace app {
namespace editor {

class DungeonEditor : public SharedROM {
class DungeonEditor : public Editor, public SharedROM {
public:
void Update();
absl::Status Update() override;
absl::Status Cut() override { return absl::OkStatus(); }
absl::Status Copy() override { return absl::OkStatus(); }
absl::Status Paste() override { return absl::OkStatus(); }
absl::Status Undo() override { return absl::OkStatus(); }
absl::Status Redo() override { return absl::OkStatus(); }

private:
void DrawToolset();
Expand All @@ -26,6 +32,7 @@ class DungeonEditor : public SharedROM {
void DrawRoomGraphics();
void DrawTileSelector();

uint16_t current_room_id_ = 0;
bool is_loaded_ = false;

gfx::Bitmap room_gfx_bmp_;
Expand Down
32 changes: 23 additions & 9 deletions src/app/rom.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum class Z3_Version {

// Define a struct to hold the version-specific constants
struct VersionConstants {
uint32_t kGgxAnimatedPointer;
uint32_t kGfxAnimatedPointer;
uint32_t kOverworldGfxGroups1;
uint32_t kOverworldGfxGroups2;
uint32_t kCompressedAllMap32PointersHigh;
Expand All @@ -68,13 +68,14 @@ struct VersionConstants {
uint32_t kMap32TileBL;
uint32_t kMap32TileBR;
uint32_t kSpriteBlocksetPointer;
uint32_t kDungeonPalettesGroups;
};

// Define a map to hold the version constants for each version
static const std::map<Z3_Version, VersionConstants> kVersionConstantsMap = {
{Z3_Version::US,
{
0x10275, // kGgxAnimatedPointer
0x10275, // kGfxAnimatedPointer
0x5D97, // kOverworldGfxGroups1
0x6073, // kOverworldGfxGroups2
0x1794D, // kCompressedAllMap32PointersHigh
Expand All @@ -91,10 +92,11 @@ static const std::map<Z3_Version, VersionConstants> kVersionConstantsMap = {
0x20000, // kMap32TileBL
0x23400, // kMap32TileBR
0x5B57, // kSpriteBlocksetPointer
0x75460, // kDungeonPalettesGroups
}},
{Z3_Version::JP,
{
0x10624, // kGgxAnimatedPointer
0x10624, // kGfxAnimatedPointer
0x5DD7, // kOverworldGfxGroups1
0x60B3, // kOverworldGfxGroups2
0x176B1, // kCompressedAllMap32PointersHigh
Expand All @@ -111,6 +113,7 @@ static const std::map<Z3_Version, VersionConstants> kVersionConstantsMap = {
0x20000, // kMap32TileBL
0x233C0, // kMap32TileBR
0x5B97, // kSpriteBlocksetPointer
0x67DD0, // kDungeonPalettesGroups
}}};

// Define some constants used throughout the ROM class
Expand All @@ -125,6 +128,7 @@ constexpr uint32_t kNormalGfxSpaceStart = 0x87000;
constexpr uint32_t kNormalGfxSpaceEnd = 0xC4200;
constexpr uint32_t kLinkSpriteLocation = 0x80000;
constexpr uint32_t kFontSpriteLocation = 0x70000;
constexpr uint32_t gfx_groups_pointer = 0x6237;

struct WriteAction {
int address;
Expand Down Expand Up @@ -283,6 +287,15 @@ class ROM : public core::ExperimentFlags {
return result;
}

absl::StatusOr<uint32_t> ReadShortLong(int offset) {
if (offset + 2 >= rom_data_.size()) {
return absl::InvalidArgumentError("Offset out of range");
}
auto result = (uint32_t)(rom_data_[offset] | (rom_data_[offset + 1] << 8) |
(rom_data_[offset + 2] << 16));
return result;
}

absl::StatusOr<std::vector<uint8_t>> ReadByteVector(uint32_t offset,
uint32_t length) {
if (offset + length > rom_data_.size()) {
Expand Down Expand Up @@ -477,8 +490,8 @@ class ROM : public core::ExperimentFlags {
spriteset_ids.resize(144, std::vector<uint8_t>(4));
paletteset_ids.resize(72, std::vector<uint8_t>(4));

int gfxPointer = (rom_data_[core::gfx_groups_pointer + 1] << 8) +
rom_data_[core::gfx_groups_pointer];
int gfxPointer = (rom_data_[gfx_groups_pointer + 1] << 8) +
rom_data_[gfx_groups_pointer];
gfxPointer = core::SnesToPc(gfxPointer);

for (int i = 0; i < 37; i++) {
Expand All @@ -505,14 +518,15 @@ class ROM : public core::ExperimentFlags {
for (int i = 0; i < 72; i++) {
for (int j = 0; j < 4; j++) {
paletteset_ids[i][j] =
rom_data_[core::dungeons_palettes_groups + (i * 4) + j];
rom_data_[GetVersionConstants().kDungeonPalettesGroups + (i * 4) +
j];
}
}
}

bool SaveGroupsToROM() {
int gfxPointer = (rom_data_[core::gfx_groups_pointer + 1] << 8) +
rom_data_[core::gfx_groups_pointer];
int gfxPointer = (rom_data_[gfx_groups_pointer + 1] << 8) +
rom_data_[gfx_groups_pointer];
gfxPointer = core::SnesToPc(gfxPointer);

for (int i = 0; i < 37; i++) {
Expand All @@ -537,7 +551,7 @@ class ROM : public core::ExperimentFlags {

for (int i = 0; i < 72; i++) {
for (int j = 0; j < 4; j++) {
rom_data_[core::dungeons_palettes_groups + (i * 4) + j] =
rom_data_[GetVersionConstants().kDungeonPalettesGroups + (i * 4) + j] =
paletteset_ids[i][j];
}
}
Expand Down
Loading

0 comments on commit 4ef2540

Please sign in to comment.