-
Notifications
You must be signed in to change notification settings - Fork 0
/
apoman.c
107 lines (96 loc) · 2.9 KB
/
apoman.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @file apoman.c
* @author Lukas Nejezchleb (nejezluk@fel.cvut.cz), Petr Kucera (kucerp28@fel.cvut.cz)
* @brief Module housing peripherals initialisation, necessary dynamic allocation of memory. Creates thread listening to the terminal input. Calls run init game menu().
* @version 0.1
* @date 2021-05-04
*
* @copyright Copyright (c) 2021
*
*/
#define _POSIX_C_SOURCE 200112L
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include "mzapo_parlcd.h"
#include "mzapo_phys.h"
#include "mzapo_regs.h"
#include "data_structures.h"
#include "font_types.h"
#include "map_template.h"
#include "map_from_template.h"
#include "map_to_fb.h"
#include "update_peripherals.h"
#include "text_fb.h"
#include "draw_shapes.h"
#include "game.h"
#include "menu_utilities.h"
#include "terminal_read.h"
#include "pacman.h"
#include "final_score.h"
#define LED_MAX_VAL 6
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 320
pthread_mutex_t mtx;
pthread_cond_t character_has_been_read;
read_thread_data_type read_thread_data;
/**
* @brief The main program function
*
* @param argc the count of arguments
* @param argv program arguments
* @return int program status
*/
int main(int argc, char *argv[])
{
unsigned char *led_mem_base;
led_mem_base = map_phys_address(SPILED_REG_BASE_PHYS, SPILED_REG_SIZE, 0);
if (led_mem_base == NULL)
{
exit(1);
}
unsigned char *lcd_mem_base;
lcd_mem_base = map_phys_address(PARLCD_REG_BASE_PHYS, PARLCD_REG_SIZE, 0);
if (lcd_mem_base == NULL)
{
exit(1);
}
// terminal read
pthread_mutex_init(&mtx, NULL); // initialize mutex with default attributes
pthread_cond_init(&character_has_been_read, NULL);
read_thread_data.quit = false;
read_thread_data.last_read = ' ';
pthread_t threads[1];
pthread_create(&threads[0], NULL, input_thread, &read_thread_data);
// frame buffer
fb_data fb;
fb.fb = malloc(sizeof(uint16_t) * SCREEN_WIDTH * SCREEN_HEIGHT);
fb.width = SCREEN_WIDTH;
fb.height = SCREEN_HEIGHT;
if (fb.fb == NULL)
{
exit(1);
}
// init display
parlcd_hx8357_init(lcd_mem_base);
font_descriptor_t *font = &font_winFreeSystem14x16;
peripherals_data_t peripherals = {.led_mem_base = led_mem_base, .lcd_mem_base = lcd_mem_base, .lcd_h = SCREEN_HEIGHT, .lcd_w = SCREEN_WIDTH};
// call game method
run_init_game_menu(&fb, lcd_mem_base, font, peripherals);
// program termination
set_background(&fb, 0);
draw_text_center(&fb, "KONEC", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 10, font, 0xffff);
lcd_from_fb(&fb, lcd_mem_base);
// free allocated memory
free(fb.fb);
fb.fb = NULL;
pthread_mutex_lock(&mtx);
read_thread_data.quit = true;
pthread_mutex_unlock(&mtx);
pthread_join(threads[0], NULL); //wait for thread to join
pthread_mutex_destroy(&mtx);
return 0;
}