yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_layer_registers.cc
Go to the documentation of this file.
2
3#include <array>
4
5namespace yaze::zelda3 {
6namespace {
7
8// Underworld_SubscreenEnable (usdasm bank_02): TS per BGACT; $FF moves the
9// lower tilemap to the main screen instead (TM=$17, TS=0).
10constexpr std::array<uint8_t, 8> kSubscreenEnable = {0x00, 0x01, 0x01, 0xFF,
11 0x01, 0x01, 0x01, 0x01};
12
13} // namespace
14
16 uint8_t bgact, bool dark, int effect, int tag2,
17 const std::vector<RoomObject>& objects, uint16_t room_flags) {
18 // $0403 bit 3 (the room word's low-byte bit 7): water drained/filled.
19 const bool water_flag = (room_flags & 0x0080) != 0;
20 const bool dam_gate_open = (room_flags & 0x0100) != 0;
21 for (const RoomObject& object : objects) {
22 const bool clears =
23 (object.id_ == 0xDA && !water_flag) || // $01:9684
24 (object.id_ == 0xD8 && water_flag) || // $01:9568
25 ((object.id_ == 0x133 || object.id_ == 0xFB3) && tag2 == 0x1B &&
26 !dam_gate_open); // AutoStairsNorthMergedStart, BecomeMultiC
27 if (clears) {
28 bgact = 0;
29 }
30 }
31 bgact &= 0x07;
32
33 RoomLayerRegisters registers;
34 const uint8_t subscreen = kSubscreenEnable[bgact];
35 if (subscreen == 0xFF) {
36 registers.tm = 0x17;
37 registers.ts = 0x00;
38 } else {
39 registers.tm = 0x16;
40 registers.ts = bgact == 2 ? 0x03 : subscreen;
41 }
42
43 // Module06_UnderworldLoad ($02:82D2-82F8).
44 if (bgact == 7) {
45 registers.cgadsub = 0x32; // full add
46 } else if (bgact == 4) {
47 registers.cgadsub = 0x62; // half add
48 } else {
49 registers.cgadsub = 0x20;
50 }
51 if (dark) {
52 registers.cgadsub = 0xB3; // subtract: the room is unlit
53 }
54
55 // Underworld_HandleLayerEffect state on the first frames after load.
56 switch (effect) {
57 case 5: // Agahnim 2
58 case 6: // invisible floor
59 registers.ts = 0x02;
60 break;
61 case 7: // Ganon, torches unlit
62 registers.ts = 0x00;
63 registers.cgadsub = 0x70;
64 break;
65 default:
66 break;
67 }
68 return registers;
69}
70
71} // namespace yaze::zelda3
Zelda 3 specific classes and functions.
RoomLayerRegisters DeriveRoomLayerRegisters(uint8_t bgact, bool dark, int effect, int tag2, const std::vector< RoomObject > &objects, uint16_t room_flags)