summaryrefslogtreecommitdiff
path: root/include/framebuffer.h
blob: fe4838551f8d9bab89764e3badfb88a6ab9a4420 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
   3dsspec - Nintendo 3DS Spectrum emulator.

   Copyright (C) 2021  Ian Cowburn <ianc@noddybox.co.uk>
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 3
   of the License, or (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.
  
   $Id: framebuffer.h 43 2007-03-12 00:59:51Z ianc $
*/
#ifndef DSSPEC_FRAMEBUFFER_H
#define DSSPEC_FRAMEBUFFER_H

#include <3ds.h>

/* Predefined colours.
*/
typedef enum 
{
    COL_TRANSPARENT	= -1,
    COL_BLACK		= 0,
    COL_WHITE		= 1,
    COL_RED		= 2,
    COL_GREEN		= 3,
    COL_BLUE		= 4,
    COL_GUISELECT	= 5,
    COL_GREY		= 6,
    COL_LIGHTGREY	= 7,
    COL_DARKGREY	= 8,
    COL_YELLOW		= 9
} FB_Colour;

/* Predefined images
*/
typedef enum
{
    IMG_KEYBOARD,
    IMG_SPLASH
} FB_Image;

/* A framebuffer or image
*/
typedef struct
{
    u16 *buffer;
    u16 width;
    u16 height;
} Framebuffer;

/* Macro to get the address of a framebuffer pixel
*/
#define FB_ADDR(fb,x,y)         (fb)->buffer[(x) * (fb)->height + (y)]

/* Macro to plot a framebuffer pixel safely clippped
*/
#define FB_PLOT_CLIPPED(fb,x,y,c)                                       \
                                do                                      \
                                {                                       \
                                    if ((x) >= 0 && (x) < (fb)->width &&\
                                        (y) >= 0 && (y) < (fb)->height) \
                                    {                                   \
                                        FB_ADDR(fb, x, y) = c;          \
                                    }                                   \
                                } while(0)

/* Initialise framebuffer code.  
*/
void	FB_Init(void);

/* Start a frame and setup the framebuffers.  This can be called multiple times
   per frame.  Either pointer can be NULL if you're not interested in it.
*/
void    FB_StartFrame(Framebuffer *upper, Framebuffer *lower);

/* Convenience function to flush the framebuffers, wait for a vsync and scan
   HID input
*/
void    FB_EndFrame(void);

/* Get the encoded value for a colour
*/
u16     FB_GetColour(FB_Colour col);

/* Print the text into the framebuffer.  The text is inverted if the character
   '\001' is found.
*/
void	FB_Print(Framebuffer *fb, const char *text, int x, int y,
		 FB_Colour colour, FB_Colour paper);
void	FB_Centre(Framebuffer *fb, const char *text, int y, 
		  FB_Colour colour, FB_Colour paper);
void	FB_printf(Framebuffer *fb, int x, int y,
                  FB_Colour colour, FB_Colour paper, const char *format, ...);

/* Lines and boxes.
*/
void	FB_HLine(Framebuffer *fb, u16 x1, u16 x2, u16 y, FB_Colour colour);
void	FB_VLine(Framebuffer *fb, u16 x, u16 y1, u16 y2, FB_Colour colour);
void	FB_Box(Framebuffer *fb, u16 x, u16 y, u16 w, u16 h, FB_Colour colour);
void	FB_FillBox(Framebuffer *fb, u16 x, u16 y, u16 w, u16 h,
                   FB_Colour colour);

/* Clear to colour
*/
void	FB_Clear(Framebuffer *fb, FB_Colour col);

/* Draw the image.
*/
void	FB_Blit(Framebuffer *fb, FB_Image img, u16 x, u16 y);

#endif	/* DSSPEC_FRAMEBUFFER_H */