Skip to content

Commit

Permalink
butano: green_swap_mode added (thanks sono!)
Browse files Browse the repository at this point in the history
  • Loading branch information
GValiente committed Dec 27, 2024
1 parent 25bc6e8 commit 67499d9
Show file tree
Hide file tree
Showing 29 changed files with 829 additions and 17 deletions.
21 changes: 18 additions & 3 deletions butano/hw/include/bn_hw_bgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

namespace bn::hw::bgs
{
#define BG_GREEN_SWAP_MODE_MASK (16 + 32)
#define BG_GREEN_SWAP_MODE_SHIFT 4
#define BG_GREEN_SWAP_MODE(n) ((n)<<BG_GREEN_SWAP_MODE_SHIFT)

struct alignas(int) regular_offset
{

Expand Down Expand Up @@ -62,13 +66,14 @@ namespace bn::hw::bgs

inline void setup_regular(const regular_bg_builder& builder, uint16_t& cnt)
{
cnt = uint16_t(BG_PRIO(builder.priority()) | (builder.mosaic_enabled() << 6));
cnt = uint16_t(BG_PRIO(builder.priority()) | (int(builder.green_swap_mode()) << 4) |
(builder.mosaic_enabled() << 6));
}

inline void setup_affine(const affine_bg_builder& builder, uint16_t& cnt)
{
cnt = uint16_t(BG_PRIO(builder.priority()) | (builder.mosaic_enabled() << 6) |
(builder.wrapping_enabled() << 13) | BG_8BPP);
cnt = uint16_t(BG_PRIO(builder.priority()) | (int(builder.green_swap_mode()) << 4) |
(builder.mosaic_enabled() << 6) | (builder.wrapping_enabled() << 13) | BG_8BPP);
}

inline void set_tiles_cbb(int tiles_cbb, uint16_t& cnt)
Expand Down Expand Up @@ -150,6 +155,16 @@ namespace bn::hw::bgs
}
}

[[nodiscard]] inline bn::green_swap_mode green_swap_mode(uint16_t cnt)
{
return bn::green_swap_mode(BN_BFN_GET(cnt, BG_GREEN_SWAP_MODE));
}

inline void set_green_swap_mode(bn::green_swap_mode green_swap_mode, uint16_t& cnt)
{
BN_BFN_SET(cnt, int(green_swap_mode), BG_GREEN_SWAP_MODE);
}

inline void commit(const commit_data& data, bool use_dma)
{
auto destination = reinterpret_cast<void*>(REG_BASE + 0x0008);
Expand Down
49 changes: 49 additions & 0 deletions butano/include/bn_affine_bg_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
namespace bn
{

enum class green_swap_mode : uint8_t;

/**
* @brief Manages the attributes to commit to the GBA register of an affine background.
*
Expand All @@ -40,6 +42,21 @@ class affine_bg_attributes
*/
affine_bg_attributes(const affine_bg_map_ptr& map, int priority, bool wrapping_enabled, bool mosaic_enabled);

/**
* @brief Constructor.
* @param map affine_bg_map_ptr of an affine background to copy.
* @param priority Priority of an affine background relative to sprites and other backgrounds,
* in the range [0..3].
*
* Backgrounds with higher priority are drawn first
* (and therefore can be covered by later sprites and backgrounds).
* @param wrapping_enabled Indicates if an affine background wraps around at the edges or not.
* @param mosaic_enabled Indicates if the mosaic effect is applied to an affine background or not.
* @param green_swap_mode Indicates how an affine background must be displayed when green swap is enabled.
*/
affine_bg_attributes(const affine_bg_map_ptr& map, int priority, bool wrapping_enabled, bool mosaic_enabled,
bn::green_swap_mode green_swap_mode);

/**
* @brief Constructor.
* @param map affine_bg_map_ptr of an affine background to move.
Expand All @@ -53,6 +70,21 @@ class affine_bg_attributes
*/
affine_bg_attributes(affine_bg_map_ptr&& map, int priority, bool wrapping_enabled, bool mosaic_enabled);

/**
* @brief Constructor.
* @param map affine_bg_map_ptr of an affine background to move.
* @param priority Priority of an affine background relative to sprites and other backgrounds,
* in the range [0..3].
*
* Backgrounds with higher priority are drawn first
* (and therefore can be covered by later sprites and backgrounds).
* @param wrapping_enabled Indicates if an affine background wraps around at the edges or not.
* @param mosaic_enabled Indicates if the mosaic effect is applied to an affine background or not.
* @param green_swap_mode Indicates how an affine background must be displayed when green swap is enabled.
*/
affine_bg_attributes(affine_bg_map_ptr&& map, int priority, bool wrapping_enabled, bool mosaic_enabled,
bn::green_swap_mode green_swap_mode);

/**
* @brief Returns the affine_bg_map_ptr of an affine background.
*/
Expand Down Expand Up @@ -132,6 +164,22 @@ class affine_bg_attributes
_mosaic_enabled = mosaic_enabled;
}

/**
* @brief Indicates how an affine background must be displayed when green swap is enabled.
*/
[[nodiscard]] bn::green_swap_mode green_swap_mode() const
{
return _green_swap_mode;
}

/**
* @brief Sets how an affine background must be displayed when green swap is enabled.
*/
void set_green_swap_mode(bn::green_swap_mode green_swap_mode)
{
_green_swap_mode = green_swap_mode;
}

/**
* @brief Default equal operator.
*/
Expand All @@ -142,6 +190,7 @@ class affine_bg_attributes
int8_t _priority;
bool _wrapping_enabled;
bool _mosaic_enabled;
bn::green_swap_mode _green_swap_mode;
};

}
Expand Down
23 changes: 22 additions & 1 deletion butano/include/bn_affine_bg_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "bn_camera_ptr.h"
#include "bn_affine_bg_item.h"
#include "bn_green_swap_mode.h"
#include "bn_affine_bg_map_ptr.h"
#include "bn_affine_mat_attributes.h"

Expand Down Expand Up @@ -640,6 +641,25 @@ class affine_bg_builder
return *this;
}

/**
* @brief Indicates how the affine backgrounds to generate must be displayed when green swap is enabled.
*/
[[nodiscard]] bn::green_swap_mode green_swap_mode() const
{
return _green_swap_mode;
}

/**
* @brief Sets how the affine backgrounds to generate must be displayed when green swap is enabled.
* @param green_swap_mode Green swap mode.
* @return Reference to this.
*/
affine_bg_builder& set_green_swap_mode(bn::green_swap_mode green_swap_mode)
{
_green_swap_mode = green_swap_mode;
return *this;
}

/**
* @brief Indicates if the affine backgrounds to generate must be committed to the GBA or not.
*/
Expand Down Expand Up @@ -784,10 +804,11 @@ class affine_bg_builder
fixed_point _position;
fixed_point _pivot_position;
int _map_index = 0;
int _priority = 3;
int _z_order = 0;
optional<affine_bg_map_ptr> _map;
optional<camera_ptr> _camera;
bn::green_swap_mode _green_swap_mode = green_swap_mode::DEFAULT;
uint8_t _priority = 3;
bool _wrapping_enabled = true;
bool _mosaic_enabled = false;
bool _blending_top_enabled = false;
Expand Down
11 changes: 11 additions & 0 deletions butano/include/bn_affine_bg_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class affine_bg_tiles_item;
class affine_bg_attributes;
class affine_mat_attributes;
class affine_bg_mat_attributes;
enum class green_swap_mode : uint8_t;

/**
* @brief std::shared_ptr like smart pointer that retains shared ownership of an affine background.
Expand Down Expand Up @@ -737,6 +738,16 @@ class affine_bg_ptr
*/
void set_blending_bottom_enabled(bool blending_bottom_enabled);

/**
* @brief Indicates how this affine background must be displayed when green swap is enabled.
*/
[[nodiscard]] bn::green_swap_mode green_swap_mode() const;

/**
* @brief Sets how this affine background must be displayed when green swap is enabled.
*/
void set_green_swap_mode(bn::green_swap_mode green_swap_mode);

/**
* @brief Indicates if this affine background must be committed to the GBA or not.
*/
Expand Down
36 changes: 36 additions & 0 deletions butano/include/bn_green_swap_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020-2024 Gustavo Valiente [email protected]
* zlib License, see LICENSE file.
*/

#ifndef BN_GREEN_SWAP_MODE_H
#define BN_GREEN_SWAP_MODE_H

/**
* @file
* bn::green_swap_mode header file.
*
* @ingroup green_swap
*/

#include "bn_common.h"

namespace bn
{

/**
* @brief Specifies how a layer must be displayed when green swap is enabled.
*
* @ingroup green_swap
*/
enum class green_swap_mode : uint8_t
{
DEFAULT, //!< The default green swap dirt effect.
HALF_TRANSPARENT_A, //!< Half of the columns are hidden.
HALF_TRANSPARENT_B, //!< The other half of the columns are hidden.
DUPLICATED //!< Pixels are duplicated
};

}

#endif
47 changes: 47 additions & 0 deletions butano/include/bn_regular_bg_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
namespace bn
{

enum class green_swap_mode : uint8_t;

/**
* @brief Manages the attributes to commit to the GBA register of a regular background.
*
Expand All @@ -39,6 +41,20 @@ class regular_bg_attributes
*/
regular_bg_attributes(const regular_bg_map_ptr& map, int priority, bool mosaic_enabled);

/**
* @brief Constructor.
* @param map regular_bg_map_ptr of a regular background to copy.
* @param priority Priority of a regular background relative to sprites and other backgrounds,
* in the range [0..3].
*
* Backgrounds with higher priority are drawn first
* (and therefore can be covered by later sprites and backgrounds).
* @param mosaic_enabled Indicates if the mosaic effect is applied to a regular background or not.
* @param green_swap_mode Indicates how a regular background must be displayed when green swap is enabled.
*/
regular_bg_attributes(const regular_bg_map_ptr& map, int priority, bool mosaic_enabled,
bn::green_swap_mode green_swap_mode);

/**
* @brief Constructor.
* @param map regular_bg_map_ptr of a regular background to move.
Expand All @@ -51,6 +67,20 @@ class regular_bg_attributes
*/
regular_bg_attributes(regular_bg_map_ptr&& map, int priority, bool mosaic_enabled);

/**
* @brief Constructor.
* @param map regular_bg_map_ptr of a regular background to move.
* @param priority Priority of a regular background relative to sprites and other backgrounds,
* in the range [0..3].
*
* Backgrounds with higher priority are drawn first
* (and therefore can be covered by later sprites and backgrounds).
* @param mosaic_enabled Indicates if the mosaic effect is applied to a regular background or not.
* @param green_swap_mode Indicates how a regular background must be displayed when green swap is enabled.
*/
regular_bg_attributes(regular_bg_map_ptr&& map, int priority, bool mosaic_enabled,
bn::green_swap_mode green_swap_mode);

/**
* @brief Returns the regular_bg_map_ptr of a regular background.
*/
Expand Down Expand Up @@ -114,6 +144,22 @@ class regular_bg_attributes
_mosaic_enabled = mosaic_enabled;
}

/**
* @brief Indicates how a regular background must be displayed when green swap is enabled.
*/
[[nodiscard]] bn::green_swap_mode green_swap_mode() const
{
return _green_swap_mode;
}

/**
* @brief Sets how a regular background must be displayed when green swap is enabled.
*/
void set_green_swap_mode(bn::green_swap_mode green_swap_mode)
{
_green_swap_mode = green_swap_mode;
}

/**
* @brief Default equal operator.
*/
Expand All @@ -123,6 +169,7 @@ class regular_bg_attributes
regular_bg_map_ptr _map;
int8_t _priority;
bool _mosaic_enabled;
bn::green_swap_mode _green_swap_mode;
};

}
Expand Down
23 changes: 22 additions & 1 deletion butano/include/bn_regular_bg_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "bn_camera_ptr.h"
#include "bn_green_swap_mode.h"
#include "bn_regular_bg_item.h"
#include "bn_regular_bg_map_ptr.h"

Expand Down Expand Up @@ -342,6 +343,25 @@ class regular_bg_builder
return *this;
}

/**
* @brief Indicates how the regular backgrounds to generate must be displayed when green swap is enabled.
*/
[[nodiscard]] bn::green_swap_mode green_swap_mode() const
{
return _green_swap_mode;
}

/**
* @brief Sets how the regular backgrounds to generate must be displayed when green swap is enabled.
* @param green_swap_mode Green swap mode.
* @return Reference to this.
*/
regular_bg_builder& set_green_swap_mode(bn::green_swap_mode green_swap_mode)
{
_green_swap_mode = green_swap_mode;
return *this;
}

/**
* @brief Indicates if the regular backgrounds to generate must be committed to the GBA or not.
*/
Expand Down Expand Up @@ -484,10 +504,11 @@ class regular_bg_builder
optional<regular_bg_item> _item;
fixed_point _position;
int _map_index = 0;
int _priority = 3;
int _z_order = 0;
optional<regular_bg_map_ptr> _map;
optional<camera_ptr> _camera;
bn::green_swap_mode _green_swap_mode = green_swap_mode::DEFAULT;
uint8_t _priority = 3;
bool _mosaic_enabled = false;
bool _blending_top_enabled = false;
bool _blending_bottom_enabled = true;
Expand Down
11 changes: 11 additions & 0 deletions butano/include/bn_regular_bg_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class regular_bg_map_item;
class regular_bg_tiles_ptr;
class regular_bg_tiles_item;
class regular_bg_attributes;
enum class green_swap_mode : uint8_t;

/**
* @brief std::shared_ptr like smart pointer that retains shared ownership of a regular background.
Expand Down Expand Up @@ -604,6 +605,16 @@ class regular_bg_ptr
*/
void set_blending_bottom_enabled(bool blending_bottom_enabled);

/**
* @brief Indicates how this regular background must be displayed when green swap is enabled.
*/
[[nodiscard]] bn::green_swap_mode green_swap_mode() const;

/**
* @brief Sets how this regular background must be displayed when green swap is enabled.
*/
void set_green_swap_mode(bn::green_swap_mode green_swap_mode);

/**
* @brief Indicates if this regular background must be committed to the GBA or not.
*/
Expand Down
Loading

0 comments on commit 67499d9

Please sign in to comment.