GBDK 2020 Docs API Documentation for GBDK 2020

Macros | Functions
drawing.h File Reference
`#include <types.h>`

Go to the source code of this file.

## Macros
#define | GRAPHICS_WIDTH 160
#define | GRAPHICS_HEIGHT 144
#define | SOLID 0x00 /* Overwrites the existing pixels */
#define | OR 0x01 /* Performs a logical OR */
#define | XOR 0x02 /* Performs a logical XOR */
#define | AND 0x03 /* Performs a logical AND */
#define | WHITE 0
#define | LTGREY 1
#define | DKGREY 2
#define | BLACK 3
#define | M_NOFILL 0
#define | M_FILL 1
#define | SIGNED 1
#define | UNSIGNED 0

## Functions
void | gprint (char *str) NONBANKED
void | gprintln (INT16 number, INT8 radix, INT8 signed_value)
void | gprintn (INT8 number, INT8 radix, INT8 signed_value)
INT8 | gprintf (char *fmt,...) NONBANKED
void | plot (UINT8 x, UINT8 y, UINT8 colour, UINT8 mode)
void | plot_point (UINT8 x, UINT8 y)
void | switch_data (UINT8 x, UINT8 y, unsigned char *src, unsigned char *dst) NONBANKED
void | draw_image (unsigned char *data) NONBANKED
void | line (UINT8 x1, UINT8 y1, UINT8 x2, UINT8 y2)
void | box (UINT8 x1, UINT8 y1, UINT8 x2, UINT8 y2, UINT8 style)
void | circle (UINT8 x, UINT8 y, UINT8 radius, UINT8 style)
UINT8 | getpix (UINT8 x, UINT8 y)
void | wrtchr (char chr)
void | gotogxy (UINT8 x, UINT8 y)
void | color (UINT8 forecolor, UINT8 backcolor, UINT8 mode)

## Detailed Description

All Points Addressable (APA) mode drawing library.

Drawing routines originally by Pascal Felber Legendary overhall by Jon Fuge jonny.nosp@m.@q-c.nosp@m.ontin.nosp@m.uum..nosp@m.demon.nosp@m..co..nosp@m.uk Commenting by Michael Hope

Note: The standard text printf() and putchar() cannot be used in APA mode - use gprintf() and wrtchr() instead.

Note: Using drawing.h will cause it's custom VBL and LCD ISRs (`drawing_vbl` and `drawing_lcd`) to be installed.

Important note for the drawing API :

    The Game Boy graphics hardware is not well suited to frame-buffer

style graphics such as the kind provided in `drawing.h`. Due to that, most drawing functions (rectangles, circles, etc) will be slow . When possible it's much faster and more efficient to work with the tiles and tile maps that the Game Boy hardware is built around.

## Macro Definition Documentation

## ◆ GRAPHICS_WIDTH

#define GRAPHICS_WIDTH 160

Size of the screen in pixels

## ◆ GRAPHICS_HEIGHT

#define GRAPHICS_HEIGHT 144

## ◆ SOLID

#define SOLID 0x00 /* Overwrites the existing pixels */

Possible drawing modes

## ◆ OR

#define OR 0x01 /* Performs a logical OR */

## ◆ XOR

#define XOR 0x02 /* Performs a logical XOR */

## ◆ AND

#define AND 0x03 /* Performs a logical AND */

## ◆ WHITE

#define WHITE 0

Possible drawing colours

## ◆ LTGREY

#define LTGREY 1

## ◆ DKGREY

#define DKGREY 2

## ◆ BLACK

#define BLACK 3

## ◆ M_NOFILL

#define M_NOFILL 0

Possible fill styles for box() and circle()

## ◆ M_FILL

#define M_FILL 1

## ◆ SIGNED

#define SIGNED 1

Possible values for signed_value in gprintln() and gprintn()

## ◆ UNSIGNED

#define UNSIGNED 0

## Function Documentation

## ◆ gprint()

void gprint | ( | char * | str | ) |

Print the string 'str' with no interpretation

See also
  gotogxy()

## ◆ gprintln()

void gprintln | ( | INT16 | number,
|  | INT8 | radix,
|  | INT8 | signed_value
| ) |  |

Print 16 bit number in radix (base) in the default font at the current text position.

Parameters

  number | number to print
  radix | radix (base) to print with
  signed_value | should be set to SIGNED or UNSIGNED depending on whether the number is signed or not

The current position is advanced by the numer of characters printed.

See also
  gotogxy()

## ◆ gprintn()

void gprintn | ( | INT8 | number,
|  | INT8 | radix,
|  | INT8 | signed_value
| ) |  |

Print 8 bit number in radix (base) in the default font at the current text position.

See also
  gprintln(), gotogxy()

## ◆ gprintf()

INT8 gprintf | ( | char * | fmt,
|  |  | ...
| ) |  |

Print the string and arguments given by fmt with arguments __...__

Parameters

  fmt | The format string as per printf
  ... | params

Currently supported:

- %c (character)
- %u (int)
- %d (INT8)
- %o (INT8 as octal)
- %x (INT8 as hex)
- %s (string)

Returns
  Returns the number of items printed, or -1 if there was an error.

See also
  gotogxy()

## ◆ plot()

void plot | ( | UINT8 | x,
|  | UINT8 | y,
|  | UINT8 | colour,
|  | UINT8 | mode
| ) |  |

Old style plot - try plot_point()

## ◆ plot_point()

void plot_point | ( | UINT8 | x,
|  | UINT8 | y
| ) |  |

Plot a point in the current drawing mode and colour at x,y

## ◆ switch_data()

void switch_data | ( | UINT8 | x,
|  | UINT8 | y,
|  | unsigned char * | src,
|  | unsigned char * | dst
| ) |  |

Exchanges the tile on screen at x,y with the tile pointed by src, original tile is saved in dst. Both src and dst may be NULL - saving or copying to screen is not performed in this case.

## ◆ draw_image()

void draw_image | ( | unsigned char * | data | ) |

Draw a full screen image at data

## ◆ line()

void line | ( | UINT8 | x1,
|  | UINT8 | y1,
|  | UINT8 | x2,
|  | UINT8 | y2
| ) |  |

Draw a line in the current drawing mode and colour from x1,y1 to x2,y2

## ◆ box()

void box | ( | UINT8 | x1,
|  | UINT8 | y1,
|  | UINT8 | x2,
|  | UINT8 | y2,
|  | UINT8 | style
| ) |  |

Draw a box (rectangle) with corners x1,y1 and x2,y2 using fill mode style (one of NOFILL or FILL)

## ◆ circle()

void circle | ( | UINT8 | x,
|  | UINT8 | y,
|  | UINT8 | radius,
|  | UINT8 | style
| ) |  |

Draw a circle with centre at x,y and radius using fill mode style (one of NOFILL or FILL)

## ◆ getpix()

UINT8 getpix | ( | UINT8 | x,
|  | UINT8 | y
| ) |  |

Returns the current colour of the pixel at x,y

## ◆ wrtchr()

void wrtchr | ( | char | chr | ) |

Prints the character chr in the default font at the current text position.

The current position is advanced by 1 after the character is printed.

See also
  gotogxy()

## ◆ gotogxy()

void gotogxy | ( | UINT8 | x,
|  | UINT8 | y
| ) |  |

Sets the current text position to x,y.

Note: x and y have units of tiles (8 pixels per unit)

See also
  wrtchr()

## ◆ color()

void color | ( | UINT8 | forecolor,
|  | UINT8 | backcolor,
|  | UINT8 | mode
| ) |  |

Set the current foreground colour (for pixels), background colour, and draw mode