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