libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
graphics.h File Reference
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  c8_display_t
 

Macros

#define C8_LOW_DISPLAY_WIDTH   64
 
#define C8_LOW_DISPLAY_HEIGHT   32
 
#define C8_HIGH_DISPLAY_WIDTH   128
 
#define C8_HIGH_DISPLAY_HEIGHT   64
 
#define C8_DEFAULT_WINDOW_WIDTH   800
 
#define C8_DEFAULT_WINDOW_HEIGHT   400
 
#define C8_WINDOW_SCALE_X   (C8_DEFAULT_WINDOW_WIDTH / C8_LOW_DISPLAY_WIDTH)
 
#define C8_WINDOW_SCALE_Y   (C8_DEFAULT_WINDOW_HEIGHT / C8_LOW_DISPLAY_HEIGHT)
 
#define C8_DISPLAYMODE_LOW   0
 
#define C8_DISPLAYMODE_HIGH   1
 

Functions

uint8_t * c8_get_pixel (c8_display_t *, int, int)
 Get the value of (x,y) from display
 
void c8_beep (void)
 Play sound.
 
void c8_deinit_graphics (void)
 Deinitialize graphics system.
 
uint8_t c8_init_graphics (void)
 Initialize graphics system.
 
void c8_render (c8_display_t *, int *)
 Render graphics.
 
int c8_tick (int *)
 Grab current keypresses and delay execution to match clockspeed.
 

Detailed Description

Function declarations for graphics display are here.

Only get_pixel is strongly defined in graphics.c. Declarations are library agnostic so a different graphics backend can be used.

Macro Definition Documentation

◆ C8_DEFAULT_WINDOW_HEIGHT

#define C8_DEFAULT_WINDOW_HEIGHT   400

◆ C8_DEFAULT_WINDOW_WIDTH

#define C8_DEFAULT_WINDOW_WIDTH   800

◆ C8_DISPLAYMODE_HIGH

#define C8_DISPLAYMODE_HIGH   1

◆ C8_DISPLAYMODE_LOW

#define C8_DISPLAYMODE_LOW   0

◆ C8_HIGH_DISPLAY_HEIGHT

#define C8_HIGH_DISPLAY_HEIGHT   64

◆ C8_HIGH_DISPLAY_WIDTH

#define C8_HIGH_DISPLAY_WIDTH   128

◆ C8_LOW_DISPLAY_HEIGHT

#define C8_LOW_DISPLAY_HEIGHT   32

◆ C8_LOW_DISPLAY_WIDTH

#define C8_LOW_DISPLAY_WIDTH   64

◆ C8_WINDOW_SCALE_X

#define C8_WINDOW_SCALE_X   (C8_DEFAULT_WINDOW_WIDTH / C8_LOW_DISPLAY_WIDTH)

◆ C8_WINDOW_SCALE_Y

#define C8_WINDOW_SCALE_Y   (C8_DEFAULT_WINDOW_HEIGHT / C8_LOW_DISPLAY_HEIGHT)

Function Documentation

◆ c8_beep()

void c8_beep ( void  )

Play sound.

This function is weak and is overridden by internal/graphics_sdl.c by default. This can also be overridden by the user when compiling without SDL2 support.

◆ c8_deinit_graphics()

void c8_deinit_graphics ( void  )

Deinitialize graphics system.

This function is weak and is overridden by internal/graphics_sdl.c by default. This can also be overridden by the user when compiling without SDL2 support.

Deinitialize graphics system.

◆ c8_get_pixel()

uint8_t * c8_get_pixel ( c8_display_t display,
int  x,
int  y 
)

Get the value of (x,y) from display

Parameters
displaydisplay_t to get pixel from
xthe x value
ythe y value
Returns
pointer to value of (x,y) in display

◆ c8_init_graphics()

uint8_t c8_init_graphics ( void  )

Initialize graphics system.

This function is weak and is overridden by internal/graphics_sdl.c by default. This can also be overridden by the user when compiling without SDL2 support.

Initialize graphics system.

Returns
1 if successful, 0 otherwise.

◆ c8_render()

void c8_render ( c8_display_t display,
int *  colors 
)

Render graphics.

This function is weak and is overridden by internal/graphics_sdl.c by default. This can also be overridden by the user when compiling without SDL2 support.

Render the given display to the SDL2 window.

Parameters
displaydisplay_t to render
colorscolors to render

◆ c8_tick()

int c8_tick ( int *  key)

Grab current keypresses and delay execution to match clockspeed.

This function is weak and is overridden by internal/graphics_sdl.c by default. This can also be overridden by the user when compiling without SDL2 support.

Grab current keypresses and delay execution to match clockspeed.

If a relevant key is pressed or released (see keyMap in this file), this function will update key accordingly.

Parameters
keypointer to int arr of keys
Returns
-2 if quitting, -1 if no key was pressed/released, else returns value of key pressed/released.