forked from RobLoach/libretro-dolphin-launcher
-
Notifications
You must be signed in to change notification settings - Fork 6
/
libretro-bash-launcher.c
206 lines (171 loc) · 4.06 KB
/
libretro-bash-launcher.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <libretro.h>
static uint32_t *frame_buf;
static struct retro_log_callback logging;
static retro_log_printf_t log_cb;
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
(void)level;
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}
void retro_init(void)
{
frame_buf = calloc(320 * 240, sizeof(uint32_t));
}
void retro_deinit(void)
{
free(frame_buf);
frame_buf = NULL;
}
unsigned retro_api_version(void)
{
return RETRO_API_VERSION;
}
void retro_set_controller_port_device(unsigned port, unsigned device)
{
log_cb(RETRO_LOG_INFO, "Plugging device %u into port %u.\n", device, port);
}
void retro_get_system_info(struct retro_system_info *info)
{
memset(info, 0, sizeof(*info));
info->library_name = "Bash Launcher";
info->library_version = "1.0.4";
info->need_fullpath = true;
info->valid_extensions = "sh|bsh|script";
}
static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
void retro_get_system_av_info(struct retro_system_av_info *info)
{
float aspect = 4.0f / 3.0f;
float sampling_rate = 30000.0f;
info->timing = (struct retro_system_timing) {
.fps = 60.0,
.sample_rate = sampling_rate,
};
info->geometry = (struct retro_game_geometry) {
.base_width = 320,
.base_height = 240,
.max_width = 320,
.max_height = 240,
.aspect_ratio = aspect,
};
}
void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
bool no_content = true;
cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_content);
if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
log_cb = logging.log;
else
log_cb = fallback_log;
}
void retro_set_audio_sample(retro_audio_sample_t cb)
{
audio_cb = cb;
}
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb)
{
audio_batch_cb = cb;
}
void retro_set_input_poll(retro_input_poll_t cb)
{
input_poll_cb = cb;
}
void retro_set_input_state(retro_input_state_t cb)
{
input_state_cb = cb;
}
void retro_set_video_refresh(retro_video_refresh_t cb)
{
video_cb = cb;
}
void retro_reset(void)
{
// Nothing needs to happen when the game is reset.
}
/**
* libretro callback; Called every game tick.
*
* Once the core has run, we will attempt to exit, since Bash is done.
*/
void retro_run(void)
{
// Clear the display.
unsigned stride = 320;
video_cb(frame_buf, 320, 240, stride << 2);
// Shutdown the environment now that Bash has loaded and quit.
environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL);
}
/**
* libretro callback; Called when a game is to be loaded.
*/
bool retro_load_game(const struct retro_game_info *info)
{
// TODO: Find where "bash" lives.
// Construct the command to run Bash.
char command[512] = "bash";
// Check if there is content to load.
if (info != NULL && info->path != NULL && info->path[0] != '\0') {
sprintf(command, "%s \"%s\"", command, info->path);
}
// Run Bash.
return system(command) != -1;
}
void retro_unload_game(void)
{
// Nothing needs to happen when the game unloads.
}
unsigned retro_get_region(void)
{
return RETRO_REGION_NTSC;
}
bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
{
return retro_load_game(info);
}
size_t retro_serialize_size(void)
{
return 0;
}
bool retro_serialize(void *data_, size_t size)
{
return true;
}
bool retro_unserialize(const void *data_, size_t size)
{
return true;
}
void *retro_get_memory_data(unsigned id)
{
(void)id;
return NULL;
}
size_t retro_get_memory_size(unsigned id)
{
(void)id;
return 0;
}
void retro_cheat_reset(void)
{
// Nothing.
}
void retro_cheat_set(unsigned index, bool enabled, const char *code)
{
(void)index;
(void)enabled;
(void)code;
}