-
Notifications
You must be signed in to change notification settings - Fork 3
/
platform.h
105 lines (81 loc) · 2.42 KB
/
platform.h
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
#ifndef PLATFORM_H
#define PLATFORM_H
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#ifdef N64
#include <libdragon.h>
#define BE16(x) (x)
#define BE32(x) (x)
#ifndef __LIBDRAGON_DEBUG_H
#include <assert.h>
#include <stdio.h>
#define debugf(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__)
#define assertf(cond, msg, ...) ({ \
if (!(cond)) { \
fprintf(stderr, "ASSERTION FAILED:\n"); \
fprintf(stderr, msg "\n", ##__VA_ARGS__); \
assert(cond); \
} \
})
#endif
enum {
PLAT_KEY_P1_UP = 1,
PLAT_KEY_P1_DOWN = 2,
PLAT_KEY_P1_LEFT = 3,
PLAT_KEY_P1_RIGHT = 4,
PLAT_KEY_P1_A = 5,
PLAT_KEY_P1_B = 6,
PLAT_KEY_P1_C = 7,
PLAT_KEY_P1_D = 8,
PLAT_KEY_P1_START = 9,
PLAT_KEY_P1_SELECT = 10,
PLAT_KEY_COIN_1 = 50,
PLAT_KEY_COIN_2 = 51,
PLAT_KEY_COIN_3 = 52,
PLAT_KEY_COIN_4 = 53,
PLAT_KEY_SERVICE = 54,
};
extern uint8_t keystate[256];
#else
#include <assert.h>
#include <stdio.h>
#include <SDL.h>
#define BE16(x) __builtin_bswap16(x)
#define BE32(x) __builtin_bswap32(x)
#define debugf(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__)
#define assertf(cond, msg, ...) ({ \
if (!(cond)) { \
fprintf(stderr, "ASSERTION FAILED:\n"); \
fprintf(stderr, msg "\n", ##__VA_ARGS__); \
assert(cond); \
} \
})
#define PLAT_KEY_P1_UP SDL_SCANCODE_UP
#define PLAT_KEY_P1_DOWN SDL_SCANCODE_DOWN
#define PLAT_KEY_P1_LEFT SDL_SCANCODE_LEFT
#define PLAT_KEY_P1_RIGHT SDL_SCANCODE_RIGHT
#define PLAT_KEY_P1_A SDL_SCANCODE_Z
#define PLAT_KEY_P1_B SDL_SCANCODE_X
#define PLAT_KEY_P1_C SDL_SCANCODE_C
#define PLAT_KEY_P1_D SDL_SCANCODE_V
#define PLAT_KEY_P1_START SDL_SCANCODE_RETURN
#define PLAT_KEY_P1_SELECT SDL_SCANCODE_RSHIFT
#define PLAT_KEY_COIN_1 SDL_SCANCODE_1
#define PLAT_KEY_COIN_2 SDL_SCANCODE_2
#define PLAT_KEY_COIN_3 SDL_SCANCODE_3
#define PLAT_KEY_COIN_4 SDL_SCANCODE_4
#define PLAT_KEY_SERVICE SDL_SCANCODE_0
extern const uint8_t *keystate;
#endif
extern uint8_t *g_screen_ptr;
extern int g_screen_pitch;
void plat_init(int audiofreq, int fps);
int plat_poll(void);
void plat_enable_audio(int enable);
void plat_enable_video(int enable);
void plat_save_screenshot(const char *fn);
void plat_beginframe(void);
void plat_endframe(void);
void plat_beginaudio(int16_t **buf, int *nsamples);
void plat_endaudio(void);
#endif