yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
object_renderer.cc
Go to the documentation of this file.
2
3namespace yaze {
4namespace zelda3 {
5
6void DungeonObjectRenderer::LoadObject(uint32_t routine_ptr,
7 std::array<uint8_t, 16>& sheet_ids) {
8 vram_.sheets = sheet_ids;
9
10 rom_data_ = rom()->vector();
11 // Prepare the CPU and memory environment
12 memory_.Initialize(rom_data_);
13
14 // Configure the object based on the fetched information
16
17 // Run the CPU emulation for the object's draw routines
18 RenderObject(routine_ptr);
19}
20
22 cpu.A = 0x03D8;
23 cpu.X = 0x03D8;
24 cpu.DB = 0x7E;
25 // VRAM target destinations
26 cpu.WriteLong(0xBF, 0x7E2000);
27 cpu.WriteLong(0xCB, 0x7E2080);
28 cpu.WriteLong(0xC2, 0x7E2002);
29 cpu.WriteLong(0xCE, 0x7E2082);
30 cpu.SetAccumulatorSize(false);
31 cpu.SetIndexSize(false);
32}
33
61void DungeonObjectRenderer::RenderObject(uint32_t routine_ptr) {
62 cpu.PB = 0x01;
63
64 // Push an initial value to the stack we can read later to confirm we are
65 // done
66 cpu.PushLong(0x01 << 16 | routine_ptr);
67
68 int i = 0;
69 while (true) {
70 uint8_t opcode = cpu.ReadByte(cpu.PB << 16 | cpu.PC);
71 cpu.ExecuteInstruction(opcode);
72
73 i++;
74 }
75
77}
78
79// In the underworld, this holds a copy of the entire BG tilemap for
80// Layer 1 (BG2) in TILEMAPA
81// Layer 2 (BG1) in TILEMAPB
83 tilemap_.reserve(0x2000);
84 for (int i = 0; i < 0x2000; ++i) {
85 tilemap_.push_back(0);
86 }
87 int tilemap_offset = 0;
88
89 // Iterate over tilemap in memory to read tile IDs
90 for (int tile_index = 0; tile_index < 512; tile_index++) {
91 // Read the tile ID from memory
92 int tile_id = memory_.ReadWord(0x7E2000 + tile_index);
93 std::cout << "Tile ID: " << std::hex << tile_id << std::endl;
94
95 int sheet_number = tile_id / 32;
96 std::cout << "Sheet number: " << std::hex << sheet_number << std::endl;
97
98 int row = tile_id / 8;
99 int column = tile_id % 8;
100
101 int x = column * 8;
102 int y = row * 8;
103
104 auto sheet = GraphicsSheetManager::GetInstance().mutable_gfx_sheets()->at(vram_.sheets[sheet_number]);
105
106 // Copy the tile from VRAM using the read tile_id
107 sheet.Get8x8Tile(tile_id, x, y, tilemap_, tilemap_offset);
108 }
109
110 bitmap_.Create(256, 256, 8, tilemap_);
111}
112
113} // namespace zelda3
114} // namespace yaze
static GraphicsSheetManager & GetInstance()
Definition rom.h:271
auto rom()
Definition rom.h:383
void RenderObject(uint32_t routine_ptr)
void LoadObject(uint32_t routine_ptr, std::array< uint8_t, 16 > &sheet_ids)
Zelda 3 specific classes and functions.
Main namespace for the application.
Definition controller.cc:18