KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
vmu_fb.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/vmu_fb.h
4 Copyright (C) 2023 Paul Cercueil
5
6*/
7
8#ifndef __DC_VMU_FB_H
9#define __DC_VMU_FB_H
10
11/** \file dc/vmu_fb.h
12 \brief VMU framebuffer.
13 \ingroup vmu_fb
14
15 This file provides an API that can be used to compose a 48x32 image that can
16 then be displayed on the VMUs connected to the system.
17
18 \author Paul Cercueil
19*/
20
21#include <sys/cdefs.h>
22__BEGIN_DECLS
23
24#include <dc/maple.h>
25#include <dc/maple/vmu.h>
26#include <stdint.h>
27#include <stdarg.h>
28
29/** \defgroup vmu_fb Framebuffer
30 * \ingroup vmu
31 *
32 * This API provides a virtual framebuffer abstraction for the VMU with a
33 * series of convenient methods for drawing complex and dynamic content.
34 *
35 * @{
36*/
37
38/** \brief Virtual framebuffer for the VMU
39
40 This object contains a 48x32 monochrome framebuffer. It can be painted to,
41 or displayed on one the VMUs connected to the system, using the API below.
42 */
43typedef struct vmufb {
44 uint32_t data[VMU_SCREEN_WIDTH]; /**< Private framebuffer pixel data */
45} vmufb_t;
46
47/** \brief VMU framebuffer font meta-data.
48
49 This structure describes a font, including character sizes,
50 layout, and a pointer to the raw font data.
51 */
52typedef struct vmufb_font {
53 unsigned int id; /**< Font id */
54 unsigned int w; /**< Character width in pixels */
55 unsigned int h; /**< Character height in pixels */
56 size_t stride; /**< Size of one character in bytes */
57 const char *fontdata; /**< Pointer to the font data */
59
60/** \brief Render into the VMU framebuffer
61
62 This function will paint the provided pixel data into the VMU framebuffer,
63 into the rectangle provided by the x, y, w and h values.
64
65 \param fb A pointer to the vmufb_t to paint to.
66 \param x The horizontal position of the top-left corner of
67 the drawing area, in pixels
68 \param y The vertical position of the top-left corner of the
69 drawing area, in pixels
70 \param w The width of the drawing area, in pixels
71 \param h The height of the drawing area, in pixels
72 \param data A pointer to the pixel data that will be painted
73 into the drawing area.
74 */
76 unsigned int x, unsigned int y,
77 unsigned int w, unsigned int h,
78 const char *data);
79
80/** \brief Clear a specific area of the VMU framebuffer
81
82 This function clears the area of the VMU framebuffer designated by the
83 x, y, w and h values.
84
85 \param fb A pointer to the vmufb_t to paint to.
86 \param x The horizontal position of the top-left corner of
87 the drawing area, in pixels
88 \param y The vertical position of the top-left corner of the
89 drawing area, in pixels
90 \param w The width of the drawing area, in pixels
91 \param h The height of the drawing area, in pixels
92 */
94 unsigned int x, unsigned int y,
95 unsigned int w, unsigned int h);
96
97/** \brief Clear the VMU framebuffer
98
99 This function clears the whole VMU framebuffer.
100
101 \param fb A pointer to the vmufb_t to paint to.
102 */
104
105/** \brief Present the VMU framebuffer to a VMU
106
107 This function presents the previously rendered VMU framebuffer to the
108 VMU identified by the dev argument.
109
110 \param fb A pointer to the vmufb_t to paint to.
111 \param dev The maple device of the VMU to present to
112 */
114
115/** \brief Render a string into the VMU framebuffer
116
117 This function uses the provided font to render text into the VMU
118 framebuffer.
119
120 \param fb A pointer to the vmufb_t to paint to.
121 \param font A pointer to the vmufb_font_t that will be used for
122 painting the text (or NULL to use the default)
123 \param x The horizontal position of the top-left corner of
124 the drawing area, in pixels
125 \param y The vertical position of the top-left corner of the
126 drawing area, in pixels
127 \param w The width of the drawing area, in pixels
128 \param h The height of the drawing area, in pixels
129 \param line_spacing Specify the number of empty lines that should
130 separate two lines of text
131 \param str The text to render
132 */
134 const vmufb_font_t *font,
135 unsigned int x, unsigned int y,
136 unsigned int w, unsigned int h,
137 unsigned int line_spacing,
138 const char *str);
139
140/** \brief Render a string into the VMU framebuffer
141
142 Simplified version of vmufb_print_string_into(). This is the same as calling
143 vmufb_print_string_into with x=0, y=0, w=48, h=32, line_spacing=0.
144
145 \param fb A pointer to the vmufb_t to paint to.
146 \param font A pointer to the vmufb_font_t that will be used for
147 painting the text (or NULL to use the default)
148 \param str The text to render
149 */
150static __inline__
152 const char *str) {
153 vmufb_print_string_into(fb, font, 0, 0,
155}
156
157/** \brief Render a string to attached VMUs using the built-in font
158
159 Uses the built-in VMU font to render a string to all VMUs connected to the
160 system.
161
162 \note
163 The font currently set as the default font will be used.
164
165 \param fmt The format string, optionally followed by extra
166 arguments.
167
168 \sa vmu_set_font()
169 */
170void vmu_printf(const char *fmt, ...) __printflike(1, 2);
171
172/** \brief Sets the default font for drawing text to the VMU.
173
174 This function allows you to set a custom font for drawing text
175 to the VMU screen. If the \p font parameter is set to `NULL`,
176 the built-in VMU font will be used as the default.
177
178 \warning
179 The API does not take ownership of or copy \p font, so
180 the given pointer must remain valid as long as it is set
181 as the default!
182
183 \param font Pointer to the font to set as default
184 \returns Pointer to the previous default font
185
186 \sa vmu_get_font()
187 */
189
190/** \brief Returns the default font used to draw text to the VMU.
191
192 \returns Pointer to the font currently set as the default
193
194 \sa vmu_set_font()
195 */
197
198/** @} */
199
200__END_DECLS
201
202#endif /* __DC_VMU_FB_H */
#define VMU_SCREEN_WIDTH
Pixel width of a standard VMU screen.
Definition vmu.h:236
#define VMU_SCREEN_HEIGHT
Pixel height of a standard VMU screen.
Definition vmu.h:242
#define __printflike(fmtarg, firstvararg)
Identify a function as accepting formatting like printf().
Definition cdefs.h:132
void vmufb_present(const vmufb_t *fb, maple_device_t *dev)
Present the VMU framebuffer to a VMU.
void vmufb_print_string_into(vmufb_t *fb, const vmufb_font_t *font, unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int line_spacing, const char *str)
Render a string into the VMU framebuffer.
void vmufb_clear_area(vmufb_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
Clear a specific area of the VMU framebuffer.
void vmufb_paint_area(vmufb_t *fb, unsigned int x, unsigned int y, unsigned int w, unsigned int h, const char *data)
Render into the VMU framebuffer.
static __inline__ void vmufb_print_string(vmufb_t *fb, const vmufb_font_t *font, const char *str)
Render a string into the VMU framebuffer.
Definition vmu_fb.h:151
void vmu_printf(const char *fmt,...) __printflike(1
Render a string to attached VMUs using the built-in font.
void vmufb_clear(vmufb_t *fb)
Clear the VMU framebuffer.
void const vmufb_font_t * vmu_set_font(const vmufb_font_t *font)
Sets the default font for drawing text to the VMU.
const vmufb_font_t * vmu_get_font(void)
Returns the default font used to draw text to the VMU.
Maple Bus driver interface.
One maple device.
Definition maple.h:270
VMU framebuffer font meta-data.
Definition vmu_fb.h:52
unsigned int h
Character height in pixels.
Definition vmu_fb.h:55
unsigned int id
Font id.
Definition vmu_fb.h:53
const char * fontdata
Pointer to the font data.
Definition vmu_fb.h:57
size_t stride
Size of one character in bytes.
Definition vmu_fb.h:56
unsigned int w
Character width in pixels.
Definition vmu_fb.h:54
Virtual framebuffer for the VMU.
Definition vmu_fb.h:43
Definitions for using the VMU device.