aboutsummaryrefslogtreecommitdiffstats
path: root/src/renderer.h
blob: a240b17a42755deb5144d7daa4eb7fad4fd335eb (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
#ifndef RENDERER_H
#define RENDERER_H

#include "gba/gba.h"

// The frontbuffer is located at the beginning of the VRAM, and requires 20KB of
// video memory for 32 * 20 tiles at 4bpp.
#define FRONTBUF ((u32*)(MEM_VRAM))

// Adjust both of these if the location of the map changes. Each screnblock
// requires less than 2KB.
#define FRONTBUF_TILEMAP ((u16*)(MEM_VRAM + KB(20)))
#define FRONTBUF_SB      10

// The backbuffer is located at the end of the VRAM. This can allow us to use
// more backgrounds but eats into the available memory for sprites. This should
// be fine for non sprite intensive applications. If more sprite memory is
// needed, the backbuffer can be located at the end of the background memory
// instead (64KB - 20KB).
#define BACKBUF  ((u32*)(MEM_VRAM + KB(96) - KB(20)))

// The font data is located at the end of the frontbuffer memory, after the tile
// map and requires 8KB for 256 8x8 characters at 4bpp. This, along with the
// tilemap information allow us to store the frontbuffer and font for a text
// background in the first 2 charblocks (32KB).
#define FONT_DATA    ((u32*)(MEM_VRAM + KB(22)))
#define FONT_TILEMAP ((u16*)(MEM_VRAM + KB(30)))
#define FONT_SB      15
#define FONT_OFFSET  192

// Draws a pixel to the given (x, y) position on the framebuffer. All drawing
// functions use paletted colors (clr: 0-15).
void draw_pixel(size_t x, size_t y, u8 clr);

// Draw a line between (x0, y0) and (x1, y1).
void draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr);

// Draw a rectangle between (x0, y0) and (x1, y1) (x0 <= x1 && y0 <= y1).
void draw_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr);

// Draw a filled rectangle between (x0, y0) and (x1, y1) (x0 <= x1 and y0 <= y1).
void draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr);

// Draw a 8x8 tile starting at the (x, y) position. If the merge parameter is
// set, colors will be added together instead of replaced. This could lead to
// some merging issues if we are not careful with the chosen colors.
void draw_tile(size_t x, size_t y, Tile *tile, bool merge);

// Fills the framebuffer with color 0.
void clear_screen(void);

// Copies the content of dirty tiles from the backbuffer into the frontbuffer.
// To be called exactly once at the beginning of the VBlank.
void flip_buffer(void);

// Initializes the renderer.
void renderer_init(void);

#endif // RENDERER__H