summaryrefslogtreecommitdiff
path: root/plat.h
blob: 70fdf36bef9e5a21e591fd5a18f565d148ec9c4e (plain) (blame)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef plat_h
#define plat_h

#include "error.h"
#include "memory.h"
#include "render.h"

#ifdef assert
#undef assert
#endif

#define assert(expr) \
	imp_assert( \
		expr, \
		#expr, \
		__FILE__, \
		__LINE__ \
	)

int imp_assert(
	int val,
	const char* expr,
	const char* file,
	int line
);

void print(const char* fmt, ...);
void print_err(const char* fmt, ...);
void print_war(const char* fmt, ...);
void pbreak(Error code);

typedef struct File File;

typedef enum {
	file_flags_write       = 1 << 0,
	file_flags_read        = 1 << 1,
	file_flags_read_write  = 1 << 2,
	file_flags_create      = 1 << 3
} File_Flags;

typedef enum {
	file_whence_begin,
	file_whence_end,
	file_whence_cur
} File_Whence;

File* file_open(const char* name, File_Flags flags);
void file_close(File* file);
void file_read(File* file, void* buffer, int size);
void file_write(File* file, const void* buffer, int size);
void file_seek(File* file, int offset, File_Whence whence);
int file_size(File* file);
int file_exists(const char* name);

typedef struct {
	int mpf;
	int fps;
	unsigned long pt, ct;
	unsigned long now, next;
} FPS;

void init_fps(FPS* f, int mpf);
void fps_begin(FPS* f);
void fps_end(FPS* f);
void fps_update(FPS* f);

#define key_xmacro() \
	x(key_unknown) \
	x(key_A) \
	x(key_B) \
	x(key_C) \
	x(key_D) \
	x(key_E) \
	x(key_F) \
	x(key_G) \
	x(key_H) \
	x(key_I) \
	x(key_J) \
	x(key_K) \
	x(key_L) \
	x(key_M) \
	x(key_N) \
	x(key_O) \
	x(key_P) \
	x(key_Q) \
	x(key_R) \
	x(key_S) \
	x(key_T) \
	x(key_U) \
	x(key_V) \
	x(key_W) \
	x(key_X) \
	x(key_Y) \
	x(key_Z) \
	x(key_f1) \
	x(key_f2) \
	x(key_f3) \
	x(key_f4) \
	x(key_f5) \
	x(key_f6) \
	x(key_f7) \
	x(key_f8) \
	x(key_f9) \
	x(key_f10) \
	x(key_f11) \
	x(key_f12) \
	x(key_down) \
	x(key_left) \
	x(key_right) \
	x(key_up) \
	x(key_escape) \
	x(key_return) \
	x(key_backspace) \
	x(key_tab) \
	x(key_delete) \
	x(key_home) \
	x(key_end) \
	x(key_page_up) \
	x(key_page_down) \
	x(key_insert) \
	x(key_shift) \
	x(key_control) \
	x(key_super) \
	x(key_alt) \
	x(key_space) \
	x(key_period) \
	x(key_0) \
	x(key_1) \
	x(key_2) \
	x(key_3) \
	x(key_4) \
	x(key_5) \
	x(key_6) \
	x(key_7) \
	x(key_8) \
	x(key_9) \

typedef enum {
#define x(name) name,
	key_xmacro()
#undef x
	key_count
} Key;

typedef enum {
	key_state_pressed       = 1 << 0,
	key_state_just_pressed  = 1 << 1,
	key_state_just_released = 1 << 2
} Key_State;

typedef struct {
	int w, h, s, o, mpf;
	int fps;
	int mx, my;
	int dmx, dmy;
	Error err;
	Colour* fb;
	Heap* heap;
	unsigned char key_states[key_count];
} App;

App* new_app(Heap* mem, int w, int h, const char* n);
void deinit_app(App* a);
void app_begin(App* a);
void app_end(App* a);

void cfg_mouse(App* a, int show);

#endif