diff options
Diffstat (limited to 'include/framebuffer.h')
-rw-r--r-- | include/framebuffer.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/include/framebuffer.h b/include/framebuffer.h new file mode 100644 index 0000000..871bd85 --- /dev/null +++ b/include/framebuffer.h @@ -0,0 +1,124 @@ +/* + 3ds81 - Nintendo 3DS ZX81 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 DS81_FRAMEBUFFER_H +#define DS81_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_CITY_PATROL_INLAY, + IMG_3D_MONSTER_MAZE_INLAY, + IMG_SABOTAGE_INLAY, + IMG_MAZOGS_INLAY, + 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 /* DS81_FRAMEBUFFER_H */ |