yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_layer_registers.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_ROOM_LAYER_REGISTERS_H
2#define YAZE_ZELDA3_DUNGEON_ROOM_LAYER_REGISTERS_H
3
4#include <cstdint>
5#include <vector>
6
8
9namespace yaze::zelda3 {
10
11// The PPU layer settings the game uses for a room right after it loads, from
12// its WRAM shadows: TM ($1C, main screen layers), TS ($1D, sub screen layers)
13// and CGADSUB ($9A, color math). Bit 0 of TM/TS is hardware BG1, which shows
14// the lower tilemap TILEMAPB ($7E4000, yaze's BG2 buffers); bit 1 is hardware
15// BG2, the upper tilemap TILEMAPA ($7E2000, yaze's BG1 buffers)
16// (Intro_InitializeBackgroundSettings: BG1SC=$13, BG2SC=$03).
18 uint8_t tm = 0x16;
19 uint8_t ts = 0x00;
20 uint8_t cgadsub = 0x20;
21
22 // yaze's BG2 buffers (TILEMAPB) appear on screen at all.
23 bool LowerTilemapShown() const { return ((tm | ts) & 0x01) != 0; }
24 // Both tilemaps are on the main screen and interleave by tile priority,
25 // with the lower tilemap (hardware BG1) winning ties.
26 bool TilemapsShareMainScreen() const { return (tm & 0x03) == 0x03; }
27 // Upper-tilemap pixels (hardware BG2, CGADSUB bit 1) are blended with the
28 // sub screen, i.e. the lower tilemap, through color math. Where the upper
29 // tilemap is transparent the lower one shows normally either way, because
30 // the backdrop (CGADSUB bit 5) adds the sub screen (confirmed on room 0x001
31 // against a Mesen frame).
32 bool UpperTilemapBlended() const {
33 return (ts & 0x01) != 0 && (cgadsub & 0x02) != 0;
34 }
35 bool BlendSubtracts() const { return (cgadsub & 0x80) != 0; }
36 bool BlendHalves() const { return (cgadsub & 0x40) != 0; }
37};
38
39// Derives the settings from the room header, as Underworld_LoadHeader,
40// Module06_UnderworldLoad and Underworld_ResetTorchBackgroundAndPlayer do:
41// - bgact: header byte 0 bits 7-5 ($0414);
42// - dark: header byte 0 bit 0 (subtractive color math, $9A = $B3);
43// - effect: header byte 4 ($AD); tag2: header byte 6 ($AF);
44// - room_flags: the room's persistent word ($7EF000 + 2*room), 0 for a room
45// as first entered;
46// - objects whose draw routines clear $0414 in that state:
47// 0xDA RoomDraw_WaterOverlayB when the water flag is clear, 0xD8
48// RoomDraw_WaterOverlayA when it is set, and the dam-gate merged stairs
49// 0x133 (North_MergedLayer_B) and 0xFB3 (South_MergedLayer) when tag2 is
50// 0x1B and flag 0x0100 is clear.
51// This is the state on entering through an entrance, with torches unlit and
52// no lamp; Underworld_HandleLayerEffect can change it every frame afterwards.
53RoomLayerRegisters DeriveRoomLayerRegisters(
54 uint8_t bgact, bool dark, int effect, int tag2,
55 const std::vector<RoomObject>& objects, uint16_t room_flags = 0);
56
57} // namespace yaze::zelda3
58
59#endif // YAZE_ZELDA3_DUNGEON_ROOM_LAYER_REGISTERS_H
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)