gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/include/gb/drawing.h
1 /** @file gb/drawing.h
2 All Points Addressable (APA) mode drawing library.
3
4 Drawing routines originally by Pascal Felber
5 Legendary overhall by Jon Fuge : https://github.com/jf1452
6 Commenting by Michael Hope
7
8 Note: The standard text printf() and putchar() cannot be used
9 in APA mode - use gprintf() and wrtchr() instead.
10
11 Note: Using drawing.h will cause it's custom LCD ISR
12 (`drawing_lcd`) to be installed. Changing the mode
13 (`mode(M_TEXT_OUT);`) will cause them to be de-installed.
14
15 The valid coordinate ranges are from (x,y) 0,0 to 159,143.
16 There is no built-in clipping, so drawing outside valid
17 coordinates will likely produce undesired results (wrapping/etc).
18
19 ----
20
21 __Important note for the drawing API :__
22
23 The Game Boy graphics hardware is not well suited to frame-buffer
24 style graphics such as the kind provided in `drawing.h`.
25 Due to that, __most drawing functions (rectangles, circles, etc) will
26 be slow__ . When possible it's much faster and more efficient
27 to work with the tiles and tile maps that the Game Boy hardware is
28 built around.
29 */
30 #ifndef __DRAWING_H
31 #define __DRAWING_H
32
33 #include <types.h>
34 #include <stdint.h>
35
36 /** Size of the screen in pixels */
37 #define GRAPHICS_WIDTH 160
38 #define GRAPHICS_HEIGHT 144
39
40 #define SOLID 0x00 /* Overwrites the existing pixels */
41 #define OR 0x01 /* Performs a logical OR */
42 #define XOR 0x02 /* Performs a logical XOR */
43 #define AND 0x03 /* Performs a logical AND */
44
45 /** Possible drawing colours */
46 #define WHITE 0
47 #define LTGREY 1
48 #define DKGREY 2
49 #define BLACK 3
50
51 /** Possible fill styles for box() and circle() */
52 #define M_NOFILL 0
53 #define M_FILL 1
54
55 /** Possible values for signed_value in gprintln() and gprintn() */
56 #define SIGNED 1
57 #define UNSIGNED 0
58
59 #include <types.h>
60
61 /** Print the string 'str' with no interpretation
62 @see gotogxy()
63 */
64 void gprint(char *str) NONBANKED;
65
66 /** Print 16 bit __number__ in __radix__ (base) in the default font at the current text position.
67
68 @param number number to print
69 @param radix radix (base) to print with
70 @param signed_value should be set to SIGNED or UNSIGNED depending on whether the number is signed or not
71
72 The current position is advanced by the numer of characters printed.
73 @see gotogxy()
74 */
75 void gprintln(int16_t number, int8_t radix, int8_t signed_value) NONBANKED;
76
77 /** Print 8 bit __number__ in __radix__ (base) in the default font at the current text position.
78
79 @see gprintln(), gotogxy()
80 */
81 void gprintn(int8_t number, int8_t radix, int8_t signed_value) NONBANKED;
82
83 /** Print the string and arguments given by __fmt__ with arguments __...__
84
85 @param fmt The format string as per printf
86 @param ... params
87
88 Currently supported:
89 \li \%c (character)
90 \li \%u (int)
91 \li \%d (int8_t)
92 \li \%o (int8_t as octal)
93 \li \%x (int8_t as hex)
94 \li \%s (string)
95
96 @return Returns the number of items printed, or -1 if there was an error.
97 @see gotogxy()
98 */
99 int8_t gprintf(char *fmt,...) NONBANKED;
100
101 /** Old style plot - try @ref plot_point() */
102 void plot(uint8_t x, uint8_t y, uint8_t colour, uint8_t mode) OLDCALL;
103
104 /** Plot a point in the current drawing mode and colour at __x,y__ */
105 void plot_point(uint8_t x, uint8_t y) OLDCALL;
106
107 /** Exchanges the tile on screen at x,y with the tile pointed by src, original tile
108 is saved in dst. Both src and dst may be NULL - saving or copying to screen is
109 not performed in this case. */
110 void switch_data(uint8_t x, uint8_t y, uint8_t *src, uint8_t *dst) OLDCALL;
111
112 /** Draw a full screen image at __data__ */
113 void draw_image(uint8_t *data);
114
115 /** Draw a line in the current drawing mode and colour from __x1,y1__ to __x2,y2__ */
116 void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) OLDCALL;
117
118 /** Draw a box (rectangle) with corners __x1,y1__ and __x2,y2__ using fill mode
119 __style__ (one of NOFILL or FILL) */
120 void box(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t style) OLDCALL;
121
122 /** Draw a circle with center at __x,y__ and __radius__ using fill mode
123 __style__
124
125 @param x X center location in pixels
126 @param y Y center location in pixels
127 @param radius Value between 1 and 254 (no draw for values outside range)
128 @param style NOFILL or FILL
129 */
130 void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t style) OLDCALL;
131
132 /** Returns the current colour of the pixel at __x,y__ */
133 uint8_t getpix(uint8_t x, uint8_t y) OLDCALL;
134
135 /** Prints the character __chr__ in the default font at the current text position.
136
137 The current position is advanced by 1 after the character is printed.
138 @see gotogxy() */
139 void wrtchr(char chr) OLDCALL;
140
141 /** Sets the current text position to __x,y__.
142
143 Note: __x__ and __y__ have units of tiles (8 pixels per unit)
144 @see wrtchr() */
145 void gotogxy(uint8_t x, uint8_t y) OLDCALL;
146
147 /** Set the current __forecolor__ colour, __backcolor__ colour, and
148 draw __mode__
149
150 @param forecolor The primary drawing color (outlines of
151 rectangles with @ref box(), letter color
152 with @ref gprintf(), etc).
153 @param backcolor Secondary or background color where applicable
154 (fill color of rectangles with @ref box() when
155 @ref M_FILL is specifed, background color of text
156 with @ref gprintf(), etc).
157 @param mode Drawing style to use. Several settings are available
158 `SOLID`, `OR`, `XOR`, `AND`.
159
160 In order to completely overwrite existing pixels use `SOLID` for __mode__
161 */
162 void color(uint8_t forecolor, uint8_t backcolor, uint8_t mode) OLDCALL;
163
164 #endif /* __DRAWING_H */
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.