Skip to content

Commit

Permalink
comment and formate all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkucerak committed Apr 24, 2021
1 parent 0b7fb64 commit 5c8c91a
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 54 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"draw_shapes.h": "c",
"data_structures.h": "c"
}
}
20 changes: 15 additions & 5 deletions data_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ typedef struct {
int y;
} coords;

// place where is the coin drawn, pacman can walk accross it
/**
* place where is the coin drawn, pacman can walk accross it
*/
#define COIN 3

// black place on the map, pacman is allowed to walk there
/**
* black place on the map, pacman is allowed to walk there
*/
#define PASSAGE 1

// place that will be drawn in color to show where the wall is
/**
* place that will be drawn in color to show where the wall is
*/
#define WALL 2

// black place on the map, pacman is not allowed there
/**
* black place on the map, pacman is not allowed there
*/
#define BLOCKED 0

// place where is the supercoin drawn, pacman can walk accross it
/**
* place where is the supercoin drawn, pacman can walk accross it
*/
#define SUPERCOIN 4

#endif
3 changes: 2 additions & 1 deletion draw_shapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


#include "draw_shapes.h"

int pixel_dist_squared(int x1, int y1, int x2, int y2){
return ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
Expand Down Expand Up @@ -42,7 +43,7 @@ void draw_rectangle(fb_data *frame, int x, int y, int width, int height, uint16_
{
if ((y + j >= 0) && (y + j < frame->height))
{
//place on the screen
// place on the screen
frame->fb[(y + j) * frame->width + x + i] = color;
}
}
Expand Down
14 changes: 10 additions & 4 deletions draw_shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@
#define DRAW_SHAPES_H
#include "data_structures.h"

//function to draw circle to fb_data frame at x,y with radius and color
void draw_circle(fb_data *frame, int x, int y, int radius, uint16_t color);
/**
* function to draw circle to fb_data frame at x,y with radius and color
*/
void draw_circle(fb_data *frame, int x, int y, int radius, uint16_t color);

//function to draw rectangle to fb_data frame at x,y with width and height and color
/**
* function to draw rectangle to fb_data frame at x,y with width and height and color
*/
void draw_rectangle(fb_data *frame, int x, int y, int width, int height, uint16_t color);

//sets background to certain color
/**
* sets background to certain color
*/
void set_background(fb_data *frame, uint16_t color);
#endif
40 changes: 21 additions & 19 deletions font_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,34 @@
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

typedef uint16_t font_bits_t;
typedef uint16_t font_bits_t;

/* builtin C-based proportional/fixed font structure*/
typedef struct {
char * name; /* font name*/
int maxwidth; /* max width in pixels*/
unsigned int height; /* height in pixels*/
int ascent; /* ascent (baseline) height*/
int firstchar; /* first character in bitmap*/
int size; /* font size in characters*/
const font_bits_t *bits; /* 16-bit right-padded bitmap data*/
const uint32_t *offset; /* offsets into bitmap data*/
const unsigned char *width; /* character widths or 0 if fixed*/
int defaultchar;/* default char (not glyph index)*/
int32_t bits_size; /* # words of MWIMAGEBITS bits*/
} font_descriptor_t;
/* builtin C-based proportional/fixed font structure*/
typedef struct
{
char *name; /* font name*/
int maxwidth; /* max width in pixels*/
unsigned int height; /* height in pixels*/
int ascent; /* ascent (baseline) height*/
int firstchar; /* first character in bitmap*/
int size; /* font size in characters*/
const font_bits_t *bits; /* 16-bit right-padded bitmap data*/
const uint32_t *offset; /* offsets into bitmap data*/
const unsigned char *width; /* character widths or 0 if fixed*/
int defaultchar; /* default char (not glyph index)*/
int32_t bits_size; /* # words of MWIMAGEBITS bits*/
} font_descriptor_t;

extern font_descriptor_t font_winFreeSystem14x16;
extern font_descriptor_t font_winFreeSystem14x16;

extern font_descriptor_t font_rom8x16;
extern font_descriptor_t font_rom8x16;

#ifdef __cplusplus
} /* extern "C"*/
#endif

#endif /*FONT_TYPES_H*/
#endif /*FONT_TYPES_H*/
8 changes: 6 additions & 2 deletions map_from_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
#include "data_structures.h"
#include "map_template.h"

//given map template returns dynamically allocated map for the whole screen
/**
* given map template returns dynamically allocated map for the whole screen
*/
map_data *create_map_data(int screen_w, int screen_h, map_template *template);

//fiven coords in template returns coords on the actual map
/**
* fiven coords in template returns coords on the actual map
*/
coords get_coords_from_template(int row, int col, map_template *template, int screen_w, int screen_h);
#endif
26 changes: 13 additions & 13 deletions map_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@

typedef struct
{
char *name; /* name of the map*/
int pacman_spawn_x; /*spawning location of pacman*/
int pacman_spawn_y; /*spawning location of pacman*/
int ghost_spawn_x; /*spawning location of ghost*/
int ghost_spawn_y; /*spawning location of ghost*/
int width; /*width of the map*/
int height; /*height of the map*/
char *board; /*actual data about the content of map*/
const int coin; /*value used to describe coin*/
const int wall; /*value used to describe wall*/
const int special; /*value used to describe special coin*/
const int blank; /*value used to describe place without coin*/
char *name; /* name of the map */
int pacman_spawn_x; /* spawning location of pacman */
int pacman_spawn_y; /* spawning location of pacman */
int ghost_spawn_x; /* spawning location of ghost */
int ghost_spawn_y; /* spawning location of ghost */
int width; /* width of the map */
int height; /* height of the map */
char *board; /* actual data about the content of map */
const int coin; /* value used to describe coin */
const int wall; /* value used to describe wall */
const int special; /* value used to describe special coin */
const int blank; /* value used to describe place without coin */
} map_template;

//first map
// first map
extern map_template map_circles;

#endif
1 change: 1 addition & 0 deletions map_to_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "map_from_template.h"
#include "text_fb.h"
#include "draw_shapes.h"

bool render_map(map_data *data, fb_data *frame_buff){
set_background(frame_buff, 0);
for(int i=0; i<frame_buff->width*frame_buff->height; ++i){
Expand Down
5 changes: 4 additions & 1 deletion map_to_fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include <stdbool.h>
#define WALL_COLOR 0x1f
#define PATH_COLOR 0
//given map_data draws the map to frame buffer

/**
* given map_data draws the map to frame buffer
*/
bool render_map(map_data *data, fb_data *frame_buff);


Expand Down
20 changes: 15 additions & 5 deletions text_fb.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@
#include "data_structures.h"
#include "font_types.h"

//function to draw char, left upper edge is at x, y
/**
* function to draw char, left upper edge is at x, y
*/
void draw_char(fb_data *frame, char letter, int x, int y, int scale, font_descriptor_t *font, uint16_t color);

//returns width of character
/**
* returns width of character
*/
int char_width(font_descriptor_t *fdes, int letter);

//returns offset in font bitmap data
/**
* returns offset in font bitmap data
*/
uint32_t char_offset(font_descriptor_t *fdes, char letter);

//draws text to frame buffer, left upper edge is at x, y
/**
* draws text to frame buffer, left upper edge is at x, y
*/
void draw_text(fb_data *frame, char* text, int x, int y, int scale, font_descriptor_t *font, uint16_t color);

//draws text to frame buffer, centre of text is at x, y
/**
* draws text to frame buffer, centre of text is at x, y
*/
void draw_text_center(fb_data *frame, char *text, int x, int y, int scale, font_descriptor_t *font, uint16_t color);
#endif
16 changes: 12 additions & 4 deletions update_peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
#include <stdint.h>
#include "data_structures.h"

//function that updates the LCD from frame buffer. LCD has to be initialised
/**
* function that updates the LCD from frame buffer. LCD has to be initialised
*/
void lcd_from_fb(const fb_data* frame_buff, unsigned char *parlcd_mem_base);

//function that shows nr on the ledstrip
/**
* function that shows nr on the ledstrip
*/
void led_strip_number(unsigned char *led_mem_base, int max_nr, int nr);

//sets left RGB to particular color
/**
* sets left RGB to particular color
*/
void set_left_RGB(unsigned char *led_mem_base, uint8_t r, uint8_t g, uint8_t b);

//sets right RGB to particular color
/**
* sets right RGB to particular color
*/
void set_right_RGB(unsigned char *led_mem_base, uint8_t r, uint8_t g, uint8_t b);
#endif

0 comments on commit 5c8c91a

Please sign in to comment.