-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframework.c
More file actions
104 lines (80 loc) · 2.77 KB
/
framework.c
File metadata and controls
104 lines (80 loc) · 2.77 KB
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
#include <stdint.h>
#define BASE_COLOR_GROUP 205
// subtick ops
__attribute__((noinline, regparm(2))) void gd_draw_pixel_simplified(int32_t p, int32_t color);
__attribute__((noinline, regparm(1))) int32_t gd_get_pixel_simplified(int32_t p);
__attribute__((noinline)) int32_t gd_a_pressed();
__attribute__((noinline)) int32_t gd_w_pressed();
__attribute__((noinline)) int32_t gd_d_pressed();
__attribute__((noinline)) int32_t gd_left_pressed();
__attribute__((noinline)) int32_t gd_up_pressed();
__attribute__((noinline)) int32_t gd_right_pressed();
__attribute__((noinline)) void gd_waitnextframe();
__attribute__((noinline, regparm(1))) int32_t gd_randint(int32_t max);
// ...
#ifdef GD_GET_PIXEL
int32_t gd_get_pixel(int32_t x, int32_t y){
return gd_get_pixel_simplified(x + 80 * y);
}
#endif
#ifdef GD_DRAW_TEXT
#include "gd_font_meta.inc"
#include "gd_font_points.inc"
#define gd_font_init(); \
__asm__ __volatile__( \
GD_FONT_META_PUSHES \
"movl %esp, %esi\n" \
GD_FONT_POINTS_PUSHES \
"movl %esp, %edi\n" \
);
void gd_draw_text(int32_t x, int32_t y, int32_t *s, int32_t len, int32_t c){
int32_t *meta_base;
int32_t *points_base;
__asm__ __volatile__(
"movl %%esi, %0\n"
"movl %%edi, %1\n"
: "=r"(meta_base), "=r"(points_base)
);
int32_t (*meta)[2] = (int32_t (*)[2])meta_base;
int32_t (*points)[2] = (int32_t (*)[2])points_base;
int32_t color = c + BASE_COLOR_GROUP;
int32_t base_x = x;
for (int32_t i = 0; i < len; ++i) {
int32_t code = s[i];
int32_t start = meta[code][0];
int32_t count = meta[code][1];
for (int32_t k = 0; k < count; ++k) {
int32_t dx = points[start + k][0];
int32_t dy = points[start + k][1];
gd_draw_pixel_simplified(base_x + dx + 80 * (y + dy), color);
}
base_x += 3 + 1;
}
}
#endif
#ifdef GD_DRAW_PIXEL
void gd_draw_pixel(int32_t x, int32_t y, int32_t c){
int32_t color = c + BASE_COLOR_GROUP;
gd_draw_pixel_simplified(x + 80 * y, color);
}
#endif
#ifdef GD_DRAW_RECT
void gd_draw_rect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t c){
int32_t color = c + BASE_COLOR_GROUP;
for (int i = 0; i < w; i++){
for (int j = 0; j < h; j++){
gd_draw_pixel_simplified(x + i + 80 * (y + j), color);
}
}
}
#endif
#ifdef GD_DRAW_SCREEN
void gd_draw_screen(int32_t c){
int32_t color = c + BASE_COLOR_GROUP;
for (int i = 0; i < 80; i++){
for (int j = 0; j < 50; j++){
gd_draw_pixel_simplified(i + 80 * j, color);
}
}
}
#endif