2 #include "drv/input/keymap.h"
4 #include "io/rgb_image.h"
7 static unsigned int frames;
9 static int button_start, button_select;
10 static int button_a, button_b;
11 static int button_down, button_up, button_left, button_right;
12 static int button_quit;
21 static struct keymap keys[] =
23 {KEY_A, &button_a, NULL, 0},
24 {KEY_S, &button_b, NULL, 0},
25 {KEY_D, &button_select, NULL, 0},
26 {KEY_F, &button_start, NULL, 0},
27 {KEY_LEFT, &button_left, NULL, 0},
28 {KEY_RIGHT, &button_right, NULL, 0},
29 {KEY_UP, &button_up, NULL, 0},
30 {KEY_DOWN, &button_down, NULL, 0},
31 {KEY_ESC, &button_quit, NULL, 0}
37 uint32_t* gb_framebuffer = 0;
39 static size_t offsetx = 0;
40 static size_t offsety = 0;
44 gb_framebuffer = kcalloc(WIDTH * HEIGHT, 4);
46 offsetx = (getScreenWidth() - WIDTH) / 2;
47 offsety = (getScreenHeight() - HEIGHT) / 2;
65 drawRect(0, 0, getScreenWidth(), getScreenHeight(), 0x00000000);
75 int chr = getCharRaw() % 128;
77 for(i = 0; i <
sizeof (keys) /
sizeof (
struct keymap); i++) {
78 if(keys[i].code != chr) {
84 if(keys[i].f && keys[i].prev == 0) {
89 keys[i].prev = *(keys[i].key);
90 *(keys[i].key) = keys[i].code == chr;
94 printf(
"frames: %d\n", frames);
101 unsigned int sdl_get_buttons(
void)
103 return (button_start << 3) | (button_select << 2) | (button_b << 1) | button_a;
106 unsigned int sdl_get_directions(
void)
108 return (button_down << 3) | (button_up << 2) | (button_left << 1) | button_right;
111 unsigned int *sdl_get_framebuffer(
void)
113 return gb_framebuffer;
116 void gb_display_helper(uint8_t* display_addr) {
117 size_t real_bpp = framebuffer_bpp >> 3;
119 for(
register int i = 0; i < HEIGHT; i++) {
120 int iy = i + offsety;
122 for(
register int j = 0; j < WIDTH; j++) {
123 uint8_t* pixels = display_addr + ((j + offsetx) * real_bpp) + iy * framebuffer_pitch;
124 uint32_t color = *(uint32_t*)(((
char*)gb_framebuffer) + PIXIDX(WIDTH * 4, j * 4, i));
126 pixels[0] = color & 255;
127 pixels[1] = (color >> 8) & 255;
128 pixels[2] = (color >> 16) & 255;
137 uint8_t* displ = (uint8_t*)getDisplayAddr();
139 gb_display_helper(displ);
146 free(gb_framebuffer);
Основные определения ядра
void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Рисуем залитый прямоугольник