libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_lcd.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuLcd display circuit + back-end rendering signals
3 * \ingroup peripherals
4 *
5 * Encompasses the API for rendering to and reading from the VMU's
6 * liquid crystal display screen. The API offers:
7 * - reading from and writing to pixels
8 * - enabling and disabling icons
9 * - enabling and disabling filters and effects
10 * - enabling and disabling screen refresh
11 * - changing screen refresh rate
12 * - synchronous event-driven callbacks for back-end drawing
13 *
14 * \todo
15 * - Pixel ghosting still needs some work
16 * - update screen when in sleep mode
17 * - access/control XRAM bank
18 *
19 * \author 2023 Falco Girgis
20 * \copyright MIT License
21 */
22#ifndef EVMU_LCD_H
23#define EVMU_LCD_H
24
25#include "../types/evmu_peripheral.h"
26#include <gimbal/meta/signals/gimbal_signal.h>
27
28/*! \name Type System
29 * \brief Type UUID and cast operators
30 * @{
31 */
32#define EVMU_LCD_TYPE (GBL_TYPEID(EvmuLcd)) //!< Type UUID for EvmuLcd
33#define EVMU_LCD(self) (GBL_CAST(EvmuLcd, self)) //!< Casts GblInstance to EvmuLcd
34#define EVMU_LCD_CLASS(klass) (GBL_CLASS_CAST(EvmuLcd, klass)) //!< Casts GblClass to EvmuLcdClass
35#define EVMU_LCD_GET_CLASS(self) (GBL_CLASSOF(EvmuLcd, self)) //!< Get EvmuLcdClass from GblInstance
36//! @}
37
38#define EVMU_LCD_NAME "lcd" //!< Peripheral GblObject name
39
40/*! \name Display Constants
41 * \brief Constants used to define display characteristics
42 * @{
43 */
44#define EVMU_LCD_PIXEL_WIDTH 48 //!< Screen resolution (width/rows)
45#define EVMU_LCD_PIXEL_HEIGHT 32 //!< Screen resolution (height/columns)
46#define EVMU_LCD_ICON_COUNT 4 //!< Number of icons
47//! @}
48
49/*! \name Emulator Settings
50 * \brief Constants used to define emulation behavior
51 * @{
52 */
53#define EVMU_LCD_GHOSTING_FRAMES 100 //!< Frame duration for pixel ghosting effect
54#define EVMU_LCD_SCREEN_REFRESH_DIVISOR 199 //!< Number of physical refreshes to skip before redrawing
55//! @}
56
57#define GBL_SELF_TYPE EvmuLcd
58
59GBL_DECLS_BEGIN
60
61GBL_FORWARD_DECLARE_STRUCT(EvmuLcd);
62
63//! Refresh rate for the LCD Screen
64GBL_DECLARE_ENUM(EVMU_LCD_REFRESH_RATE) {
65 EVMU_LCD_REFRESH_83HZ, //!< 83Hz Refresh rate
66 EVMU_LCD_REFRESH_166HZ //!< 166Hz Refresh rate
67};
68
69//! XRAM Bank Numbers
70GBL_DECLARE_ENUM(EVMU_XRAM_BANK) {
71 EVMU_XRAM_BANK_LCD_TOP, //!< Top (0) Bank
72 EVMU_XRAM_BANK_LCD_BOTTOM, //!< Bottom (1) Bank
73 EVMU_XRAM_BANK_ICON //!< Icon (2) Bank
74};
75
76//! LCD Screen Icons
77GBL_DECLARE_FLAGS(EVMU_LCD_ICONS) {
78 EVMU_LCD_ICONS_NONE = 0x0, //!< No Icon
79 EVMU_LCD_ICON_FILE = 0x1, //!< File Icon (Notepad)
80 EVMU_LCD_ICON_GAME = 0x2, //!< Game Icon (Card)
81 EVMU_LCD_ICON_CLOCK = 0x4, //!< Clock Icon (Analog Clock)
82 EVMU_LCD_ICON_FLASH = 0x8, //!< Flash Icon (!)
83 EVMU_LCD_ICONS_ALL = 0xf //!< All Icons
84};
85
86/*! \struct EvmuLcdClass
87 * \extends EvmuPeripheralClass
88 * \brief GblClass for EvmuLcd
89 *
90 * EvmuLcdClass contains a single overridable virtual method
91 * for triggering a renderer back-end to redraw the framebuffer.
92 * This will only be called in the event that a pixel has actually
93 * changed, and will be synchronized with the refresh rate.
94 *
95 * \note
96 * The default implementation simply emits the "screenRefresh" signal.
97 *
98 * \sa EvmuLcd
99 */
100GBL_CLASS_DERIVE(EvmuLcd, EvmuPeripheral)
101 EVMU_RESULT (*pFnRefreshScreen)(GBL_SELF); //!< Called when screen updates
102GBL_CLASS_END
103
104/*! \struct EvmuLcd
105 * \extends EvmuPeripheral
106 * \ingroup peripherals
107 * \brief EvmuLcd screen and framebuffer peripheral
108 *
109 * EvmuLcd is the instance structure providing an API around the VMU's
110 * LCD screen.
111 *
112 * \sa EvmuLcdClass
113 */
114GBL_INSTANCE_DERIVE(EvmuLcd, EvmuPeripheral)
115 size_t screenRefreshDivisor; //!< How many hardware refreshes before software refresh
116 uint32_t screenChanged : 1; //!< User-driven toggle for knowing when to redraw
117 uint32_t ghostingEnabled : 1; //!< Emulate pixel ghosting/fade effect
118 uint32_t filterEnabled : 1; //!< Enable linear filtering
119 uint32_t invertColors : 1; //!< Swap black and white pixel values
120GBL_INSTANCE_END
121
122//! \cond
123GBL_PROPERTIES(EvmuLcd,
124 (screenEnabled, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
125 (refreshEnabled, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
126 (refreshRate, GBL_GENERIC, (READ, WRITE), GBL_ENUM_TYPE),
127 (ghostingEnabled, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
128 (filterEnabled, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
129 (invertColors, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
130 (icons, GBL_GENERIC, (READ, WRITE), GBL_FLAGS_TYPE)
131)
132
133GBL_SIGNALS(EvmuLcd,
134 (screenRefresh, (GBL_INSTANCE_TYPE, pReceiver)),
135 (screenToggle, (GBL_INSTANCE_TYPE, pReceiver), (GBL_BOOL_TYPE, enabled)),
136 (iconsChange, (GBL_INSTANCE_TYPE, pReceiver), (GBL_FLAGS_TYPE, flags))
137)
138//! \endcond
139
140//! Returns the GblType UUID associated with EvmuLcd
141EVMU_EXPORT GblType EvmuLcd_type (void) GBL_NOEXCEPT;
142
143/*! \name Configuration
144 * \brief Methods for querying the display configuration
145 * \relatesalso EvmuLcd
146 * @{
147 */
148//! Returns GBL_TRUE if the display is enabled/powered, GBL_FALSE otherwise
150//! Returns GBL_TRUE if screen refreshing is currently enabled for the display, GBL_FALSE otherwise
152//! Returns the refresh rate configuration for how frequently the display updates
154 EvmuLcd_refreshRate (GBL_CSELF) GBL_NOEXCEPT;
155//! Returns the refresh rate / update time of the LCD screen in milliseconds
157//! @}
158
159/*! \name Configuring
160 * \brief Methods for setting and altering the display configuration
161 * \relatesalso EvmuLcd
162 * @{
163 */
164//! Enables or disables the VMU's LCD display, depending on the value of \p enabled
165EVMU_EXPORT void EvmuLcd_setScreenEnabled (GBL_SELF, GblBool enabled) GBL_NOEXCEPT;
166//! Enables or disables automatic screen refreshing for the display, depending on the value of \p enabled
167EVMU_EXPORT void EvmuLcd_setRefreshEnabled (GBL_SELF, GblBool enabled) GBL_NOEXCEPT;
168//! Sets the refresh rate of the LCD screen to the given \p rate value
170//! @}
171
172/*! \name Display Reading
173 * \brief Methods to retrieve display values for rendering
174 * \relatesalso EvmuLcd
175 * @{
176 */
177//! Returns a value containing the bitmasks of all of the enabled icons OR'd together
179 EvmuLcd_icons (GBL_CSELF) GBL_NOEXCEPT;
180//! Returns the raw pixel value for the given screen coordinate, GBL_TRUE being black and GBL_FALSE being white
181EVMU_EXPORT GblBool EvmuLcd_pixel (GBL_CSELF, size_t row, size_t col) GBL_NOEXCEPT;
182//! Retrieves the decorated pixel value for the given screen coordinate, with all effects enabled
183EVMU_EXPORT uint8_t EvmuLcd_decoratedPixel (GBL_CSELF, size_t row, size_t col) GBL_NOEXCEPT;
184//! @}
185
186/*! \name Display Rendering
187 * \brief Methods to set and modify display values
188 * \relatesalso EvmuLcd
189 * @{
190 */
191//! Sets the active icons to the mask given by \p icons, which has individual icon masks OR'd together
192EVMU_EXPORT void EvmuLcd_setIcons (GBL_SELF, EVMU_LCD_ICONS icons) GBL_NOEXCEPT;
193//! Sets the raw pixel value for the given screen coordinate, with \p enabled signifying a black pixel
194EVMU_EXPORT void EvmuLcd_setPixel (GBL_SELF, size_t row, size_t col, GblBool enabled) GBL_NOEXCEPT;
195//! @}
196
197GBL_DECLS_END
198
199#undef GBL_SELF_TYPE
200
201#endif // EVMU_LCD_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
EVMU_XRAM_BANK
Definition evmu_lcd.h:70
@ EVMU_XRAM_BANK_LCD_BOTTOM
Bottom (1) Bank.
Definition evmu_lcd.h:72
@ EVMU_XRAM_BANK_ICON
Icon (2) Bank.
Definition evmu_lcd.h:73
@ EVMU_XRAM_BANK_LCD_TOP
Top (0) Bank.
Definition evmu_lcd.h:71
EVMU_LCD_REFRESH_RATE
Definition evmu_lcd.h:64
@ EVMU_LCD_REFRESH_166HZ
166Hz Refresh rate
Definition evmu_lcd.h:66
@ EVMU_LCD_REFRESH_83HZ
83Hz Refresh rate
Definition evmu_lcd.h:65
EVMU_LCD_ICONS
Definition evmu_lcd.h:77
@ EVMU_LCD_ICON_FLASH
Flash Icon (!)
Definition evmu_lcd.h:82
@ EVMU_LCD_ICON_CLOCK
Clock Icon (Analog Clock)
Definition evmu_lcd.h:81
@ EVMU_LCD_ICON_GAME
Game Icon (Card)
Definition evmu_lcd.h:80
@ EVMU_LCD_ICON_FILE
File Icon (Notepad)
Definition evmu_lcd.h:79
@ EVMU_LCD_ICONS_ALL
All Icons.
Definition evmu_lcd.h:83
@ EVMU_LCD_ICONS_NONE
No Icon.
Definition evmu_lcd.h:78
GblType EvmuLcd_type(void)
Returns the GblType UUID associated with EvmuLcd.
uint64_t EvmuTicks
Represents a delta time in milliseconds.
#define GBL_ENUM_TYPE
#define GBL_FLAGS_TYPE
#define GBL_BOOL_TYPE
#define GBL_PROPERTIES(object,...)
uint8_t GblBool
uintptr_t GblType
EvmuLcd screen and framebuffer peripheral.
Definition evmu_lcd.h:114
EVMU_LCD_REFRESH_RATE EvmuLcd_refreshRate(const EvmuLcd *pSelf)
Returns the refresh rate configuration for how frequently the display updates.
EvmuTicks EvmuLcd_refreshRateTicks(const EvmuLcd *pSelf)
Returns the refresh rate / update time of the LCD screen in milliseconds.
uint32_t invertColors
Swap black and white pixel values.
Definition evmu_lcd.h:119
uint32_t filterEnabled
Enable linear filtering.
Definition evmu_lcd.h:118
GblBool EvmuLcd_refreshEnabled(const EvmuLcd *pSelf)
Returns GBL_TRUE if screen refreshing is currently enabled for the display, GBL_FALSE otherwise.
GblBool EvmuLcd_pixel(const EvmuLcd *pSelf, size_t row, size_t col)
Returns the raw pixel value for the given screen coordinate, GBL_TRUE being black and GBL_FALSE being...
void EvmuLcd_setPixel(EvmuLcd *pSelf, size_t row, size_t col, GblBool enabled)
Sets the raw pixel value for the given screen coordinate, with enabled signifying a black pixel.
void EvmuLcd_setScreenEnabled(EvmuLcd *pSelf, GblBool enabled)
Enables or disables the VMU's LCD display, depending on the value of enabled.
EVMU_LCD_ICONS EvmuLcd_icons(const EvmuLcd *pSelf)
Returns a value containing the bitmasks of all of the enabled icons OR'd together.
uint32_t ghostingEnabled
Emulate pixel ghosting/fade effect.
Definition evmu_lcd.h:117
void EvmuLcd_setRefreshRate(EvmuLcd *pSelf, EVMU_LCD_REFRESH_RATE rate)
Sets the refresh rate of the LCD screen to the given rate value.
void EvmuLcd_setIcons(EvmuLcd *pSelf, EVMU_LCD_ICONS icons)
Sets the active icons to the mask given by icons, which has individual icon masks OR'd together.
uint32_t screenChanged
User-driven toggle for knowing when to redraw.
Definition evmu_lcd.h:116
size_t screenRefreshDivisor
How many hardware refreshes before software refresh.
Definition evmu_lcd.h:115
uint8_t EvmuLcd_decoratedPixel(const EvmuLcd *pSelf, size_t row, size_t col)
Retrieves the decorated pixel value for the given screen coordinate, with all effects enabled.
void EvmuLcd_setRefreshEnabled(EvmuLcd *pSelf, GblBool enabled)
Enables or disables automatic screen refreshing for the display, depending on the value of enabled.
GblBool EvmuLcd_screenEnabled(const EvmuLcd *pSelf)
Returns GBL_TRUE if the display is enabled/powered, GBL_FALSE otherwise.
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)