-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdl.h
72 lines (62 loc) · 1.47 KB
/
sdl.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
//
// sdl.h
// rnes
//
#pragma once
#include <cstdint>
class SDL_Surface;
class SDL_Window;
class SDL_Renderer;
class SDL_Texture;
namespace Rnes {
class Sdl {
public:
enum {
BUTTON_UP,
BUTTON_DOWN,
BUTTON_LEFT,
BUTTON_RIGHT,
BUTTON_START,
BUTTON_SELECT,
BUTTON_A,
BUTTON_B,
BUTTON_SAVE,
BUTTON_RESTORE,
BUTTON_COUNT,
};
private:
SDL_Surface *display = nullptr;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
uint32_t *image;
static constexpr int dispMultiple = 4;
static constexpr int renderWidth = 256;
static constexpr int renderHeight = 240;
static constexpr int displayHeight = dispMultiple * renderHeight;
static constexpr int displayWidth = dispMultiple * renderWidth;
//static constexpr int bitsPerPixel;
bool buttonState[BUTTON_COUNT] = {false};
typedef void(Callback)(void *data, uint8_t *stream, int len);
Callback *audioCallback;
void *callbackData;
uint32_t audioFreq;
uint32_t audioBufferSize;
public:
Sdl();
int initAudio();
int initDisplay();
~Sdl();
// Video functions
void setPixel(int x, int y, uint8_t r, uint8_t g, uint8_t b);
void renderSync();
void parseInput();
bool getButtonState(int button);
// Audio functions
void callbackWrapper(uint8_t *stream, int len);
void registerAudioCallback(Callback *audioCallback, void *data);
void unregisterAudioCallback();
uint32_t getSampleRate();
uint32_t getChunkSize();
};
}; // namespace Rnes