mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 09:32:52 +00:00
194 lines
3.7 KiB
C
194 lines
3.7 KiB
C
#include "../libretro.h"
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <GL/gl.h>
|
|
#include <GL/glext.h>
|
|
|
|
static uint16_t *frame_buf;
|
|
|
|
void retro_init(void)
|
|
{
|
|
frame_buf = calloc(320 * 240, sizeof(uint16_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)
|
|
{
|
|
(void)port;
|
|
(void)device;
|
|
}
|
|
|
|
void retro_get_system_info(struct retro_system_info *info)
|
|
{
|
|
memset(info, 0, sizeof(*info));
|
|
info->library_name = "TestCore GL";
|
|
info->library_version = "v1";
|
|
info->need_fullpath = false;
|
|
info->valid_extensions = NULL; // Anything is fine, we don't care.
|
|
}
|
|
|
|
void retro_get_system_av_info(struct retro_system_av_info *info)
|
|
{
|
|
info->timing = (struct retro_system_timing) {
|
|
.fps = 60.0,
|
|
.sample_rate = 30000.0,
|
|
};
|
|
|
|
info->geometry = (struct retro_game_geometry) {
|
|
.base_width = 320,
|
|
.base_height = 240,
|
|
.max_width = 320,
|
|
.max_height = 240,
|
|
.aspect_ratio = 4.0 / 3.0,
|
|
};
|
|
}
|
|
|
|
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_set_environment(retro_environment_t cb)
|
|
{
|
|
environ_cb = cb;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
static struct retro_hw_render_callback hw_render;
|
|
|
|
void retro_run(void)
|
|
{
|
|
input_poll_cb();
|
|
static unsigned frame_count = 0;
|
|
frame_count = (frame_count + 1) % 60;
|
|
glBindFramebuffer(GL_FRAMEBUFFER, hw_render.get_current_framebuffer());
|
|
glViewport(0, 0, 320, 240);
|
|
glClearColor(frame_count / 120.0, frame_count / 60.0, frame_count / 60.0, 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
video_cb(RETRO_HW_FRAME_BUFFER_VALID, 320, 240, 0);
|
|
}
|
|
|
|
|
|
static void context_reset(void)
|
|
{
|
|
fprintf(stderr, "Context reset!\n");
|
|
}
|
|
|
|
bool retro_load_game(const struct retro_game_info *info)
|
|
{
|
|
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888;
|
|
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
|
|
{
|
|
fprintf(stderr, "XRGB8888 is not supported.\n");
|
|
return false;
|
|
}
|
|
|
|
hw_render.context_type = RETRO_HW_CONTEXT_OPENGL;
|
|
hw_render.context_reset = context_reset;
|
|
if (!environ_cb(RETRO_ENVIRONMENT_SET_HW_RENDER, &hw_render))
|
|
return false;
|
|
|
|
(void)info;
|
|
return true;
|
|
}
|
|
|
|
void retro_unload_game(void)
|
|
{}
|
|
|
|
unsigned retro_get_region(void)
|
|
{
|
|
return RETRO_REGION_NTSC;
|
|
}
|
|
|
|
bool retro_load_game_special(unsigned type, const struct retro_game_info *info, size_t num)
|
|
{
|
|
(void)type;
|
|
(void)info;
|
|
(void)num;
|
|
return false;
|
|
}
|
|
|
|
size_t retro_serialize_size(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
bool retro_serialize(void *data, size_t size)
|
|
{
|
|
(void)data;
|
|
(void)size;
|
|
return false;
|
|
}
|
|
|
|
bool retro_unserialize(const void *data, size_t size)
|
|
{
|
|
(void)data;
|
|
(void)size;
|
|
return false;
|
|
}
|
|
|
|
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_reset(void)
|
|
{}
|
|
|
|
void retro_cheat_reset(void)
|
|
{}
|
|
|
|
void retro_cheat_set(unsigned index, bool enabled, const char *code)
|
|
{
|
|
(void)index;
|
|
(void)enabled;
|
|
(void)code;
|
|
}
|
|
|