From b4820d1d327878d3054ec952c059ce777bbbff6e Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 30 Nov 2023 02:13:31 -0500 Subject: [PATCH] Housekeeping --- docs/infrastructure.md | 2 +- src/app/CMakeLists.txt | 1 + src/app/rom.cc | 4 +- src/app/zelda3/dungeon/room.cc | 82 +--------------------------- src/app/zelda3/dungeon/room.h | 31 ++++++++--- src/app/zelda3/dungeon/room_object.h | 15 ++--- 6 files changed, 34 insertions(+), 101 deletions(-) diff --git a/docs/infrastructure.md b/docs/infrastructure.md index a7d47899..b066f30f 100644 --- a/docs/infrastructure.md +++ b/docs/infrastructure.md @@ -31,7 +31,7 @@ For developers to reference. - [Constants](../src/app/core/constants.h) - [Controller](../src/app/core/controller.h) - [Editor](../src/app/core/editor.h) - - [Pipeline](../src/app/core/pipeline.h) + - [Pipeline](../src/app/gui/pipeline.h) - **Editor Namespace**: - Editors are responsible for representing the GUI view and handling user input. - These classes are all controlled by [MasterEditor](../src/app/editor/master_editor.h) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index d902c823..b17e6f4d 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable( app/emu/audio/dsp.cc app/emu/video/ppu.cc app/emu/memory/dma.cc + app/emu/memory/memory.cc app/emu/cpu.cc app/emu/snes.cc ${YAZE_APP_CORE_SRC} diff --git a/src/app/rom.cc b/src/app/rom.cc index e247649f..6b5563c0 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -203,7 +203,7 @@ absl::StatusOr ROM::Load2BppGraphics() { } absl::Status ROM::LoadLinkGraphics() { - const auto link_gfx_offset = 81920; // $10:8000 + const auto link_gfx_offset = 81920; // $10:8000 const auto link_gfx_length = 0x800; // Load Links graphics from the ROM @@ -248,6 +248,8 @@ absl::Status ROM::LoadAllGraphicsData() { graphics_manager_.LoadBitmap(i, converted_sheet, core::kTilesheetWidth, core::kTilesheetHeight, core::kTilesheetDepth); + graphics_manager_[i]->ApplyPaletteWithTransparent( + palette_groups_["dungeon_main"][0], 0); graphics_manager_[i]->CreateTexture(renderer_); } graphics_bin_[i] = diff --git a/src/app/zelda3/dungeon/room.cc b/src/app/zelda3/dungeon/room.cc index 7c52cf34..1287db63 100644 --- a/src/app/zelda3/dungeon/room.cc +++ b/src/app/zelda3/dungeon/room.cc @@ -18,66 +18,6 @@ namespace app { namespace zelda3 { namespace dungeon { -void DrawDungeonRoomBG1(std::vector& tiles_bg1_buffer, - std::vector& current_gfx16, - std::vector& room_bg1_data) { - for (int yy = 0; yy < 64; ++yy) { - for (int xx = 0; xx < 64; ++xx) { - if (tiles_bg1_buffer[xx + (yy * 64)] != 0xFFFF) { - auto t = gfx::GetTilesInfo(tiles_bg1_buffer[xx + (yy * 64)]); - for (int yl = 0; yl < 8; ++yl) { - for (int xl = 0; xl < 4; ++xl) { - int mx = xl * (1 - t.horizontal_mirror_) + - (3 - xl) * t.horizontal_mirror_; - int my = - yl * (1 - t.vertical_mirror_) + (7 - yl) * t.vertical_mirror_; - - int ty = (t.id_ / 16) * 512; - int tx = (t.id_ % 16) * 4; - uint8_t pixel = current_gfx16[(tx + ty) + (yl * 64) + xl]; - - int index = (xx * 8) + (yy * 4096) + ((mx * 2) + (my * 512)); - room_bg1_data[index + t.horizontal_mirror_ ^ 1] = - static_cast((pixel & 0x0F) + t.palette_ * 16); - room_bg1_data[index + t.horizontal_mirror_] = - static_cast(((pixel >> 4) & 0x0F) + t.palette_ * 16); - } - } - } - } - } -} - -void DrawDungeonRoomBG2(std::vector& tiles_bg2_buffer, - std::vector& current_gfx16, - std::vector& room_bg2_data) { - for (int yy = 0; yy < 64; ++yy) { - for (int xx = 0; xx < 64; ++xx) { - if (tiles_bg2_buffer[xx + (yy * 64)] != 0xFFFF) { - auto t = gfx::GetTilesInfo(tiles_bg2_buffer[xx + (yy * 64)]); - for (int yl = 0; yl < 8; ++yl) { - for (int xl = 0; xl < 4; ++xl) { - int mx = xl * (1 - t.horizontal_mirror_) + - (3 - xl) * t.horizontal_mirror_; - int my = - yl * (1 - t.vertical_mirror_) + (7 - yl) * t.vertical_mirror_; - - int ty = (t.id_ / 16) * 512; - int tx = (t.id_ % 16) * 4; - uint8_t pixel = current_gfx16[(tx + ty) + (yl * 64) + xl]; - - int index = (xx * 8) + (yy * 4096) + ((mx * 2) + (my * 512)); - room_bg2_data[index + t.horizontal_mirror_ ^ 1] = - static_cast((pixel & 0x0F) + t.palette_ * 16); - room_bg2_data[index + t.horizontal_mirror_] = - static_cast(((pixel >> 4) & 0x0F) + t.palette_ * 16); - } - } - } - } - } -} - void Room::LoadHeader() { // Address of the room header int header_pointer = (rom()->data()[kRoomHeaderPointer + 2] << 16) + @@ -106,30 +46,12 @@ void Room::LoadHeader() { // tag1 = (TagKey)((rom()->data()[header_location + 5])); // tag2 = (TagKey)((rom()->data()[header_location + 6])); - // holewarpPlane = ((rom()->data()[header_location + 7]) & 0x03); staircase_plane[0] = ((rom()->data()[header_location + 7] >> 2) & 0x03); staircase_plane[1] = ((rom()->data()[header_location + 7] >> 4) & 0x03); staircase_plane[2] = ((rom()->data()[header_location + 7] >> 6) & 0x03); staircase_plane[3] = ((rom()->data()[header_location + 8]) & 0x03); - // if (holewarpPlane == 2) { - // Console::WriteLine("Room Index Plane 1 : Used in room id = " + - // index.ToString("X2")); - // } else if (staircasePlane[0] == 2) { - // Console::WriteLine("Room Index Plane 1 : Used in room id = " + - // index.ToString("X2")); - // } else if (staircasePlane[1] == 2) { - // Console::WriteLine("Room Index Plane 1 : Used in room id = " + - // index.ToString("X2")); - // } else if (staircasePlane[2] == 2) { - // Console::WriteLine("Room Index Plane 1 : Used in room id = " + - // index.ToString("X2")); - // } else if (staircasePlane[3] == 2) { - // Console::WriteLine("Room Index Plane 1 : Used in room id = " + - // index.ToString("X2")); - // } - - // holewarp = (rom()->data()[header_location + 9]); + holewarp = (rom()->data()[header_location + 9]); staircase_rooms[0] = (rom()->data()[header_location + 10]); staircase_rooms[1] = (rom()->data()[header_location + 11]); staircase_rooms[2] = (rom()->data()[header_location + 12]); @@ -495,4 +417,4 @@ void Room::LoadRoomFromROM() { } // namespace dungeon } // namespace zelda3 } // namespace app -} // namespace yaze \ No newline at end of file +} // namespace yaze diff --git a/src/app/zelda3/dungeon/room.h b/src/app/zelda3/dungeon/room.h index 55d8f16c..6619d98a 100644 --- a/src/app/zelda3/dungeon/room.h +++ b/src/app/zelda3/dungeon/room.h @@ -20,6 +20,26 @@ namespace app { namespace zelda3 { namespace dungeon { +// public static int room_object_layout_pointer = 0x882D; +// public static int room_object_pointer = 0x874C; // Long pointer +// oh eh +// in bank 01 ? lol +// those are pointer of pointers +// 0x882D -> readlong() -> 2FEF04 (04EF2F -> toPC->026F2F) -> +// that's all the layout "room" pointers + +// 47EF04 ; layout00 ptr +// AFEF04 ; layout01 ptr +// F0EF04 ; layout02 ptr +// 4CF004 ; layout03 ptr +// A8F004 ; layout04 ptr +// ECF004 ; layout05 ptr +// 48F104 ; layout06 ptr +// A4F104 ; layout07 ptr +// also they are not exactly the same as rooms +// the object array is terminated by a 0xFFFF there's no layers +// in normal room when you encounter a 0xFFFF it goes to the next layer + constexpr int entrance_gfx_group = 0x5D97; constexpr int dungeons_main_bg_palette_pointers = 0xDEC4B; // JP Same constexpr int dungeons_palettes = 0xDD734; @@ -45,7 +65,6 @@ constexpr int torches_length_pointer = 0x88C1; constexpr int sprite_blockset_pointer = 0x5B57; constexpr int sprites_data = 0x4D8B0; - constexpr int sprites_data_empty_room = 0x4D8AE; constexpr int sprites_end_data = 0x4EC9E; constexpr int pit_pointer = 0x394AB; @@ -67,14 +86,6 @@ constexpr int dungeon_spr_ptrs = 0x090000; constexpr ushort stairsObjects[] = {0x139, 0x138, 0x13B, 0x12E, 0x12D}; -void DrawDungeonRoomBG1(std::vector& tiles_bg1_buffer, - std::vector& current_gfx16, - std::vector& room_bg1_ptr); - -void DrawDungeonRoomBG2(std::vector& tiles_bg2_buffer, - std::vector& current_gfx16, - std::vector& room_bg2_ptr); - class DungeonDestination { public: DungeonDestination() = default; @@ -139,6 +150,7 @@ class Room : public SharedROM { uint8_t spriteset = 0; uint8_t palette = 0; uint8_t layout = 0; + uint8_t holewarp = 0; uint16_t message_id_ = 0; @@ -170,6 +182,7 @@ class Room : public SharedROM { std::array blocks_; std::array ChestList; + std::array background_bmps_; std::vector sprites_; std::vector staircaseRooms; diff --git a/src/app/zelda3/dungeon/room_object.h b/src/app/zelda3/dungeon/room_object.h index 3e609871..68d9d111 100644 --- a/src/app/zelda3/dungeon/room_object.h +++ b/src/app/zelda3/dungeon/room_object.h @@ -47,6 +47,8 @@ class DungeonObjectRenderer : public SharedROM { } gfx::Bitmap* bitmap() { return &bitmap_; } + auto memory() { return memory_; } + auto mutable_memory() { return memory_.data(); } private: struct SubtypeInfo { @@ -67,11 +69,7 @@ class DungeonObjectRenderer : public SharedROM { info.subtypePtr = core::subtype1_tiles + (objectId & 0xFF) * 2; info.routinePtr = core::subtype1_tiles + 0x200 + (objectId & 0xFF) * 2; std::cout << "Subtype 1 " << std::hex << info.subtypePtr << std::endl; - info.routinePtr = - memory_.ReadWord(core::MapBankToWordAddress(0x01, info.routinePtr)); std::cout << "Subtype 1 " << std::hex << info.routinePtr << std::endl; - std::cout << "Subtype 1 " << std::hex << core::SnesToPc(info.routinePtr) - << std::endl; break; case 2: // Subtype 2 info.subtypePtr = core::subtype2_tiles + (objectId & 0x7F) * 2; @@ -97,6 +95,8 @@ class DungeonObjectRenderer : public SharedROM { void ConfigureObject(const SubtypeInfo& info) { cpu.A = 0x00; cpu.X = 0x00; + cpu.SetAccumulatorSize(false); + cpu.SetIndexSize(false); // Might need to set the height and width manually? } @@ -142,8 +142,8 @@ class DungeonObjectRenderer : public SharedROM { */ void RenderObject(const SubtypeInfo& info) { - cpu.PC = info.routinePtr; cpu.PB = 0x01; + cpu.PC = cpu.ReadWord(0x01 << 16 | info.routinePtr); int i = 0; while (true) { @@ -151,11 +151,6 @@ class DungeonObjectRenderer : public SharedROM { cpu.ExecuteInstruction(opcode); cpu.HandleInterrupts(); - // Check if the end of the routine is reached - if (opcode == 0x60) { // RTS opcode - break; - } - if (i > 50) { break; }