-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheui.c
73 lines (68 loc) · 2.02 KB
/
eui.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
#include "gb.h"
#define SDL_DISABLE_IMMINTRIN_H
#include <SDL2/SDL.h>
int in;
u8 keys;
void* window;
u8* pic;
SDL_Renderer* renderer;
SDL_Texture* bitmapTex;
void
render()
{
SDL_UpdateTexture(bitmapTex, nil, pic, 160 * sizeof(u32));
SDL_RenderCopy(renderer, bitmapTex, nil, nil);
SDL_RenderPresent(renderer);
}
void
joypadevent(void*_)
{
SDL_Event evt;
addevent(&evjoypad, JOYPAD_CYCLE);
if (SDL_PollEvent(&evt) == 0)
return;
switch (evt.type) {
case SDL_KEYUP: keys = 0; break;
case SDL_KEYDOWN:
switch (evt.key.keysym.scancode) {
case SDL_SCANCODE_F1: savereq = 1; break;
case SDL_SCANCODE_F2: loadreq = 1; break;
case SDL_SCANCODE_X: keys = GB_KEY_A; break;
case SDL_SCANCODE_Z: keys = GB_KEY_B; break;
case SDL_SCANCODE_UP: keys = GB_KEY_UP; break;
case SDL_SCANCODE_DOWN: keys = GB_KEY_DOWN; break;
case SDL_SCANCODE_LEFT: keys = GB_KEY_LEFT; break;
case SDL_SCANCODE_RIGHT: keys = GB_KEY_RIGHT; break;
case SDL_SCANCODE_RETURN: keys = GB_KEY_START; break;
case SDL_SCANCODE_ESCAPE: break;
default: return;
}
break;
case SDL_QUIT: exit(1);
}
return;
}
void
initwindow(int scale)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL Initialization Fail: %s\n", SDL_GetError());
return;
}
pic = xalloc(PICH * PICW * sizeof(u32));
window = SDL_CreateWindow("gb",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
PICW * scale,
PICH * scale,
SDL_WINDOW_SHOWN);
if (!window)
panic("SDL Initialization Fail: %s\n", SDL_GetError());
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
renderer = SDL_GetRenderer(window);
bitmapTex = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
PICW,
PICH);
}