This repository was archived by the owner on Nov 1, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathrender.h
More file actions
112 lines (82 loc) · 2.69 KB
/
Copy pathrender.h
File metadata and controls
112 lines (82 loc) · 2.69 KB
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
// .h
// OS Graphics Rendering Functions
// by Kyle Furey
#ifndef HLOS_RENDER_H
#define HLOS_RENDER_H
#include "types.h"
/** Whether pixel rendering is enabled (otherwise uses text rendering). */
#define PIXEL_RENDERING 0
/** Pixel Buffer Array index port. */
#define PBA_INDEX_PORT 0x3C8
/** Pixel Buffer Array color port. */
#define PBA_COLOR_PORT 0x3C9
/** Converts an X and Y value into a Pixel Buffer Array index. */
#define PBA_INDEX(x, y) ((x) + ((y) * PBA_WIDTH))
/** Converts a color to a Pixel Buffer Array color. */
#define COLOR_TO_PBA(r, g, b) ((((r) >> 5) << 5) | (((g) >> 5) << 2) | ((b) >> 6))
/** Converts a Pixel Buffer Array color into a color. */
#define PBA_TO_COLOR(i) ((color_t) { (((i) >> 5) * 255) / 7, (((i) >> 2) * 255) / 7, (((i) & 3) * 255) / 3, 255, })
/** Constructs a color. */
#define COLOR(...) (color_t) { __VA_ARGS__ }
/** Constructs a point. */
#define POINT(...) (point_t) { __VA_ARGS__ }
/** Pixel Buffer Array sizes. */
typedef enum PBA_size {
PBA_WIDTH = 320,
PBA_HEIGHT = 200,
PBA_SIZE = PBA_WIDTH * PBA_HEIGHT,
GLYPH_HEIGHT = 8,
GLYPH_WIDTH = 8,
GLYPH_SIZE = GLYPH_WIDTH * GLYPH_HEIGHT,
} PBA_size_t;
/** Represents a single pixel's color in the Pixel Buffer Array. */
typedef byte_t PBA_color_t;
/** Data for the state of the Pixel Buffer Array. */
typedef struct PBA {
/** The address of the Pixel Buffer Array. */
volatile PBA_color_t *const array;
/** The next frame buffer of the Pixel Buffer Array. */
PBA_color_t next[PBA_SIZE];
} PBA_t;
/** Represents a 32-bit color. */
typedef struct color {
/** Red. */
byte_t r;
/** Green. */
byte_t g;
/** Blue. */
byte_t b;
/** Alpha. */
byte_t a;
} color_t;
/** A 2D point. */
typedef struct point {
/** X. */
ushort_t x;
/** Y. */
ushort_t y;
} point_t;
#ifdef __cplusplus
extern "C" {
#endif
/** The Pixel Buffer Array. */
extern PBA_t PBA;
/** Renders the frame buffer to the Pixel Buffer Array. */
void render();
/** Sets the color of the Pixel Buffer Array pixel at <point>. */
void pixel(point_t point, color_t color);
/** Sets the color of an array of pixels in the Pixel Buffer Array. */
void pixels(uint_t size, const point_t *points, color_t color);
/** Sets the color of each pixel in the Pixel Buffer Array. */
void fill(color_t color);
/** Fills a square of pixels from <start> to <end> with a color in the Pixel Buffer Array. */
void square(point_t start, point_t end, color_t color);
/**
* Prints an 8 x 8 colored glyph in the Pixel Buffer Array starting at <point>.
* <glyph> must be of size GLYPH_HEIGHT.
*/
void glyph(point_t point, const byte_t *glyph, color_t color);
#ifdef __cplusplus
}
#endif
#endif // HLOS_RENDER_H