cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

drawing.h (4947B)


      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 <jonny@q-continuum.demon.co.uk>
      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 VBL and LCD ISRs
     12    (`drawing_vbl` and `drawing_lcd`) to be installed. Changing
     13    the mode (`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*/
     64void 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*/
     75void 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*/
     81void 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*/
     99int8_t gprintf(char *fmt,...) NONBANKED;
    100
    101/** Old style plot - try @ref plot_point() */
    102void 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__ */
    105void 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. */
    110void switch_data(uint8_t x, uint8_t y, uint8_t *src, uint8_t *dst) OLDCALL;
    111
    112/** Draw a full screen image at __data__ */
    113void draw_image(uint8_t *data) OLDCALL;
    114
    115/** Draw a line in the current drawing mode and colour from __x1,y1__ to __x2,y2__ */
    116void 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) */
    120void box(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t style) OLDCALL;
    121
    122/** Draw a circle with centre at __x,y__ and __radius__ using fill mode
    123   __style__  (one of NOFILL or FILL)*/
    124void circle(uint8_t x, uint8_t y, uint8_t radius, uint8_t style) OLDCALL;
    125
    126/** Returns the current colour of the pixel at __x,y__ */
    127uint8_t getpix(uint8_t x, uint8_t y) OLDCALL;
    128
    129/** Prints the character __chr__ in the default font at the current text position.
    130
    131    The current position is advanced by 1 after the character is printed.
    132    @see gotogxy() */
    133void wrtchr(char chr) OLDCALL;
    134
    135/** Sets the current text position to __x,y__.
    136
    137    Note: __x__ and __y__ have units of tiles (8 pixels per unit)
    138    @see wrtchr() */
    139void gotogxy(uint8_t x, uint8_t y) OLDCALL;
    140
    141/** Set the current __foreground__ colour (for pixels), __background__ colour, and
    142   draw __mode__ */
    143void color(uint8_t forecolor, uint8_t backcolor, uint8_t mode) OLDCALL;
    144
    145#endif /* __DRAWING_H */