2017-04-20 19:03:52 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2018-02-05 23:31:31 +00:00
|
|
|
#ifndef WIIU
|
2018-01-15 20:23:20 +00:00
|
|
|
#define AUDIO_FREQUENCY 384000
|
2018-02-05 23:31:31 +00:00
|
|
|
#else
|
|
|
|
#define AUDIO_FREQUENCY 44100
|
|
|
|
#endif
|
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
#define FRAME_RATE (0x400000 / 70224.0)
|
2017-04-20 19:03:52 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
2017-10-12 21:02:02 +00:00
|
|
|
#include <Core/gb.h>
|
2017-04-20 19:03:52 +00:00
|
|
|
#include "libretro.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2018-01-19 22:06:33 +00:00
|
|
|
static const char slash = '\\';
|
2017-04-20 19:03:52 +00:00
|
|
|
#else
|
2018-01-19 22:06:33 +00:00
|
|
|
static const char slash = '/';
|
2017-04-20 19:03:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VIDEO_WIDTH 160
|
|
|
|
#define VIDEO_HEIGHT 144
|
2018-01-27 19:59:18 +00:00
|
|
|
#define VIDEO_PIXELS (VIDEO_WIDTH * VIDEO_HEIGHT)
|
2017-04-20 19:03:52 +00:00
|
|
|
|
2018-02-05 23:17:55 +00:00
|
|
|
char battery_save_path[512];
|
2017-04-20 19:03:52 +00:00
|
|
|
char symbols_path[512];
|
|
|
|
|
2018-01-19 22:06:33 +00:00
|
|
|
enum model {
|
|
|
|
MODEL_DMG,
|
|
|
|
MODEL_CGB,
|
2018-01-27 19:46:13 +00:00
|
|
|
MODEL_AGB,
|
|
|
|
MODEL_AUTO
|
2018-01-19 22:06:33 +00:00
|
|
|
};
|
|
|
|
|
2018-01-27 19:46:13 +00:00
|
|
|
static enum model model = MODEL_AUTO;
|
|
|
|
static enum model auto_model = MODEL_CGB;
|
2018-02-01 02:13:44 +00:00
|
|
|
|
|
|
|
enum layout {
|
|
|
|
LAYOUT_TOP_DOWN,
|
|
|
|
LAYOUT_LEFT_RIGHT
|
|
|
|
};
|
2018-01-27 19:59:18 +00:00
|
|
|
|
2018-02-01 03:06:41 +00:00
|
|
|
static enum model model[2];
|
2018-01-27 19:59:18 +00:00
|
|
|
static uint32_t *frame_buf = NULL;
|
2017-04-20 19:03:52 +00:00
|
|
|
static struct retro_log_callback logging;
|
|
|
|
static retro_log_printf_t log_cb;
|
|
|
|
|
|
|
|
static retro_video_refresh_t video_cb;
|
|
|
|
static retro_audio_sample_batch_t audio_batch_cb;
|
|
|
|
static retro_input_poll_t input_poll_cb;
|
|
|
|
static retro_input_state_t input_state_cb;
|
|
|
|
|
2018-02-01 03:42:26 +00:00
|
|
|
static unsigned emulated_devices = 1;
|
2018-02-01 04:06:14 +00:00
|
|
|
static unsigned pre_init = 1;
|
2018-02-01 02:13:44 +00:00
|
|
|
static unsigned layout = 0;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
signed short soundbuf[1024 * 2];
|
2017-04-20 19:03:52 +00:00
|
|
|
|
2017-04-25 02:25:08 +00:00
|
|
|
char retro_system_directory[4096];
|
|
|
|
char retro_save_directory[4096];
|
2017-04-20 19:03:52 +00:00
|
|
|
char retro_game_path[4096];
|
|
|
|
|
2018-02-01 02:09:47 +00:00
|
|
|
GB_gameboy_t gb[2];
|
|
|
|
|
2018-01-19 22:06:33 +00:00
|
|
|
extern const unsigned char dmg_boot[], cgb_boot[], agb_boot[];
|
|
|
|
extern const unsigned dmg_boot_length, cgb_boot_length, agb_boot_length;
|
2018-01-31 20:33:46 +00:00
|
|
|
bool vblank1_occurred = false, vblank2_occurred = false;
|
2017-04-20 19:03:52 +00:00
|
|
|
|
|
|
|
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
|
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
(void)level;
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
|
|
|
vfprintf(stderr, fmt, va);
|
|
|
|
va_end(va);
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-15 23:46:37 +00:00
|
|
|
static struct retro_rumble_interface rumble;
|
|
|
|
|
2018-01-27 19:59:18 +00:00
|
|
|
static void GB_update_keys_status(GB_gameboy_t *gb, unsigned port)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
input_poll_cb();
|
2018-01-27 19:59:18 +00:00
|
|
|
|
|
|
|
GB_set_key_state(gb, GB_KEY_RIGHT,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT));
|
|
|
|
GB_set_key_state(gb, GB_KEY_LEFT, input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT));
|
|
|
|
GB_set_key_state(gb, GB_KEY_UP,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) );
|
|
|
|
GB_set_key_state(gb, GB_KEY_DOWN,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN));
|
|
|
|
GB_set_key_state(gb, GB_KEY_A,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A) );
|
|
|
|
GB_set_key_state(gb, GB_KEY_B,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B) );
|
|
|
|
GB_set_key_state(gb, GB_KEY_SELECT,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT));
|
|
|
|
GB_set_key_state(gb, GB_KEY_START,input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START) );
|
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
if (gb->rumble_state)
|
2018-01-27 19:59:18 +00:00
|
|
|
rumble.set_rumble_state(port, RETRO_RUMBLE_STRONG, 65535);
|
2018-01-15 20:23:20 +00:00
|
|
|
else
|
2018-01-27 19:59:18 +00:00
|
|
|
rumble.set_rumble_state(port, RETRO_RUMBLE_STRONG, 0);
|
|
|
|
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void audio_callback(void *gb)
|
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
size_t length = GB_apu_get_current_buffer_length(gb);
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
while (length > sizeof(soundbuf) / 4)
|
|
|
|
{
|
|
|
|
GB_apu_copy_buffer(gb, (GB_sample_t *) soundbuf, 1024);
|
|
|
|
audio_batch_cb(soundbuf, 1024);
|
|
|
|
length -= 1024;
|
|
|
|
}
|
|
|
|
if (length) {
|
|
|
|
GB_apu_copy_buffer(gb, (GB_sample_t *) soundbuf, length);
|
|
|
|
audio_batch_cb(soundbuf, length);
|
|
|
|
}
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 19:59:18 +00:00
|
|
|
static void vblank1(GB_gameboy_t *gb)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
vblank1_occurred = true;
|
2018-01-27 19:59:18 +00:00
|
|
|
GB_update_keys_status(gb, 0);
|
2018-01-15 20:23:20 +00:00
|
|
|
audio_callback(gb);
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 19:59:18 +00:00
|
|
|
static void vblank2(GB_gameboy_t *gb)
|
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
vblank2_occurred = true;
|
2018-01-27 19:59:18 +00:00
|
|
|
GB_update_keys_status(gb, 1);
|
|
|
|
//audio_callback(gb);
|
|
|
|
}
|
|
|
|
|
2018-01-31 20:33:46 +00:00
|
|
|
static uint8_t byte_to_send1 = 0xFF, byte_to_send2 = 0xFF;
|
|
|
|
|
2018-01-27 19:59:18 +00:00
|
|
|
static void serial_start1(GB_gameboy_t *gb, uint8_t byte_received)
|
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
byte_to_send1 = byte_received;
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t serial_end1(GB_gameboy_t *gb)
|
|
|
|
{
|
2018-02-01 02:09:47 +00:00
|
|
|
uint8_t ret = GB_serial_get_data(&gb[1]);
|
|
|
|
GB_serial_set_data(&gb[1], byte_to_send1);
|
2018-01-31 20:33:46 +00:00
|
|
|
return ret;
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serial_start2(GB_gameboy_t *gb, uint8_t byte_received)
|
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
byte_to_send2 = byte_received;
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t serial_end2(GB_gameboy_t *gb)
|
|
|
|
{
|
2018-02-01 02:09:47 +00:00
|
|
|
uint8_t ret = GB_serial_get_data(&gb[0]);
|
|
|
|
GB_serial_set_data(&gb[0], byte_to_send2);
|
2018-01-31 20:33:46 +00:00
|
|
|
return ret;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 03:42:26 +00:00
|
|
|
static uint32_t rgb_encode(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
|
|
|
|
{
|
|
|
|
return r<<16|g<<8|b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static retro_environment_t environ_cb;
|
|
|
|
|
|
|
|
static const struct retro_variable vars[] = {
|
2018-02-01 04:06:14 +00:00
|
|
|
{ "sameboy_link", "Link Cable (restart); disabled|enabled" },
|
2018-02-01 03:42:26 +00:00
|
|
|
{ "sameboy_link_layout", "Screen Layout; top-down|left-right" },
|
|
|
|
{ "sameboy_color_correction_mode", "Color Correction; off|correct curves|emulate hardware|preserve brightness" },
|
|
|
|
{ "sameboy_high_pass_filter_mode", "High Pass Filter; off|accurate|remove dc offset" },
|
|
|
|
{ "sameboy_model", "Emulated Model; Game Boy Color|Game Boy Advance|Game Boy" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
static const struct retro_variable vars_link[] = {
|
|
|
|
{ "sameboy_link", "Link Cable; disabled|enabled" },
|
|
|
|
{ "sameboy_link_layout", "Screen Layout; top-down|left-right" },
|
|
|
|
{ "sameboy_model_1", "Emulated Model for GB #1; Game Boy Color|Game Boy Advance|Game Boy" },
|
|
|
|
{ "sameboy_model_2", "Emulated Model for GB #2; Game Boy Color|Game Boy Advance|Game Boy" },
|
|
|
|
{ "sameboy_color_correction_mode_1", "Color Correction for GB #1; off|correct curves|emulate hardware|preserve brightness" },
|
|
|
|
{ "sameboy_color_correction_mode_2", "Color Correction for GB #2; off|correct curves|emulate hardware|preserve brightness" },
|
|
|
|
{ "sameboy_high_pass_filter_mode_1", "High Pass Filter for GB #1; off|accurate|remove dc offset" },
|
|
|
|
{ "sameboy_high_pass_filter_mode_2", "High Pass Filter for GB #2; off|accurate|remove dc offset" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2018-01-19 22:06:33 +00:00
|
|
|
static void init_for_current_model(void)
|
|
|
|
{
|
2018-01-27 19:46:13 +00:00
|
|
|
enum model effective_model = model;
|
|
|
|
if (effective_model == MODEL_AUTO) {
|
|
|
|
effective_model = auto_model;
|
|
|
|
}
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-02-01 02:13:44 +00:00
|
|
|
for (i = 0; i < emulated_devices; i++)
|
2018-02-01 02:09:47 +00:00
|
|
|
{
|
|
|
|
if (GB_is_inited(&gb[i]))
|
2018-02-01 03:06:41 +00:00
|
|
|
GB_switch_model_and_reset(&gb[i], effective_model[i] != MODEL_DMG);
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
if (effective_model[i] == MODEL_DMG)
|
2018-02-01 02:09:47 +00:00
|
|
|
GB_init(&gb[i]);
|
|
|
|
else
|
|
|
|
GB_init_cgb(&gb[i]);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
const char *model_name = (const char *[]){"dmg", "cgb", "agb"}[model[i]];
|
|
|
|
const unsigned char *boot_code = (const unsigned char *[]){dmg_boot, cgb_boot, agb_boot}[model[i]];
|
|
|
|
unsigned boot_length = (unsigned []){dmg_boot_length, cgb_boot_length, agb_boot_length}[model[i]];
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
snprintf(buf, sizeof(buf), "%s%c%s_boot.bin", retro_system_directory, slash, model_name);
|
|
|
|
log_cb(RETRO_LOG_INFO, "Loading boot image: %s\n", buf);
|
|
|
|
if (GB_load_boot_rom(&gb[i], buf))
|
|
|
|
GB_load_boot_rom_from_buffer(&gb[i], boot_code, boot_length);
|
2018-02-01 02:09:47 +00:00
|
|
|
GB_set_user_data(&gb[i], (void*)NULL);
|
|
|
|
GB_set_pixels_output(&gb[i],(unsigned int*)(frame_buf + i * VIDEO_PIXELS));
|
|
|
|
GB_set_rgb_encode_callback(&gb[i], rgb_encode);
|
|
|
|
GB_set_sample_rate(&gb[i], AUDIO_FREQUENCY);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
/* todo: attempt to make these more generic */
|
|
|
|
GB_set_vblank_callback(&gb[0], (GB_vblank_callback_t) vblank1);
|
2018-02-01 03:42:26 +00:00
|
|
|
if (emulated_devices == 2)
|
|
|
|
{
|
|
|
|
GB_set_vblank_callback(&gb[1], (GB_vblank_callback_t) vblank2);
|
|
|
|
GB_set_serial_transfer_start_callback(&gb[0], serial_start1);
|
|
|
|
GB_set_serial_transfer_end_callback(&gb[0], serial_end1);
|
|
|
|
GB_set_serial_transfer_start_callback(&gb[1], serial_start2);
|
|
|
|
GB_set_serial_transfer_end_callback(&gb[1], serial_end2);
|
|
|
|
}
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-19 22:06:33 +00:00
|
|
|
struct retro_memory_descriptor descs[7];
|
|
|
|
size_t size;
|
|
|
|
uint16_t bank;
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
/* todo: add netplay awareness for this so achievements can be granted on the respective client */
|
|
|
|
i = 0;
|
2018-01-19 22:06:33 +00:00
|
|
|
memset(descs, 0, sizeof(descs));
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[0].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_IE, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[0].start = 0xFFFF;
|
|
|
|
descs[0].len = 1;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[1].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_HRAM, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[1].start = 0xFF80;
|
|
|
|
descs[1].len = 0x0080;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[2].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_RAM, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[2].start = 0xC000;
|
|
|
|
descs[2].len = 0x2000;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[3].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_CART_RAM, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[3].start = 0xA000;
|
|
|
|
descs[3].len = 0x2000;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[4].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_VRAM, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[4].start = 0x8000;
|
|
|
|
descs[4].len = 0x2000;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[5].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_ROM, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[5].start = 0x0000;
|
|
|
|
descs[5].len = 0x4000;
|
|
|
|
descs[5].flags = RETRO_MEMDESC_CONST;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
|
|
|
descs[6].ptr = GB_get_direct_access(&gb[i], GB_DIRECT_ACCESS_OAM, &size, &bank);
|
2018-01-19 22:06:33 +00:00
|
|
|
descs[6].start = 0xFE00;
|
|
|
|
descs[6].len = 0x00A0;
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-19 22:06:33 +00:00
|
|
|
struct retro_memory_map mmaps;
|
|
|
|
mmaps.descriptors = descs;
|
|
|
|
mmaps.num_descriptors = sizeof(descs) / sizeof(descs[0]);
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &mmaps);
|
|
|
|
}
|
|
|
|
|
2018-02-01 03:06:41 +00:00
|
|
|
static void check_variables(bool link)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
struct retro_variable var = {0};
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-02-01 03:06:41 +00:00
|
|
|
if (!link)
|
2018-01-15 20:23:20 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
var.key = "sameboy_color_correction_mode";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && GB_is_cgb(&gb[0]))
|
2018-01-27 19:59:18 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
if (strcmp(var.value, "off") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_DISABLED);
|
|
|
|
else if (strcmp(var.value, "correct curves") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_CORRECT_CURVES);
|
|
|
|
else if (strcmp(var.value, "emulate hardware") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_EMULATE_HARDWARE);
|
|
|
|
else if (strcmp(var.value, "preserve brightness") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
|
|
|
|
var.key = "sameboy_high_pass_filter_mode";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
2018-01-27 19:59:18 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
if (strcmp(var.value, "off") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[0], GB_HIGHPASS_OFF);
|
|
|
|
else if (strcmp(var.value, "accurate") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[0], GB_HIGHPASS_ACCURATE);
|
|
|
|
else if (strcmp(var.value, "remove dc offset") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[0], GB_HIGHPASS_REMOVE_DC_OFFSET);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
|
|
|
|
var.key = "sameboy_model";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
2018-01-27 19:59:18 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
enum model new_model = model[0];
|
|
|
|
if (strcmp(var.value, "Game Boy") == 0)
|
|
|
|
new_model = MODEL_DMG;
|
|
|
|
else if (strcmp(var.value, "Game Boy Color") == 0)
|
|
|
|
new_model = MODEL_CGB;
|
|
|
|
else if (strcmp(var.value, "Game Boy Advance") == 0)
|
|
|
|
new_model = MODEL_AGB;
|
|
|
|
else if (strcmp(var.value, "Auto") == 0)
|
|
|
|
new_model = MODEL_AUTO;
|
|
|
|
if (GB_is_inited(&gb[0]) && new_model != model[0]) {
|
|
|
|
model[0] = new_model;
|
|
|
|
init_for_current_model();
|
|
|
|
}
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-01-15 20:23:20 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
else
|
2018-01-15 20:23:20 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
var.key = "sameboy_color_correction_mode_1";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && GB_is_cgb(&gb[0]))
|
2018-01-27 19:59:18 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
if (strcmp(var.value, "off") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_DISABLED);
|
|
|
|
else if (strcmp(var.value, "correct curves") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_CORRECT_CURVES);
|
|
|
|
else if (strcmp(var.value, "emulate hardware") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_EMULATE_HARDWARE);
|
|
|
|
else if (strcmp(var.value, "preserve brightness") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[0], GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
|
|
|
|
var.key = "sameboy_color_correction_mode_2";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && GB_is_cgb(&gb[1]))
|
2018-01-27 19:59:18 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
if (strcmp(var.value, "off") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[1], GB_COLOR_CORRECTION_DISABLED);
|
|
|
|
else if (strcmp(var.value, "correct curves") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[1], GB_COLOR_CORRECTION_CORRECT_CURVES);
|
|
|
|
else if (strcmp(var.value, "emulate hardware") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[1], GB_COLOR_CORRECTION_EMULATE_HARDWARE);
|
|
|
|
else if (strcmp(var.value, "preserve brightness") == 0)
|
|
|
|
GB_set_color_correction_mode(&gb[1], GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
|
|
|
|
var.key = "sameboy_high_pass_filter_mode_1";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
2018-01-27 19:59:18 +00:00
|
|
|
{
|
2018-02-01 03:06:41 +00:00
|
|
|
if (strcmp(var.value, "off") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[0], GB_HIGHPASS_OFF);
|
|
|
|
else if (strcmp(var.value, "accurate") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[0], GB_HIGHPASS_ACCURATE);
|
|
|
|
else if (strcmp(var.value, "remove dc offset") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[0], GB_HIGHPASS_REMOVE_DC_OFFSET);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-02-01 03:06:41 +00:00
|
|
|
var.key = "sameboy_high_pass_filter_mode_2";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "off") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[1], GB_HIGHPASS_OFF);
|
|
|
|
else if (strcmp(var.value, "accurate") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[1], GB_HIGHPASS_ACCURATE);
|
|
|
|
else if (strcmp(var.value, "remove dc offset") == 0)
|
|
|
|
GB_set_highpass_filter_mode(&gb[1], GB_HIGHPASS_REMOVE_DC_OFFSET);
|
2018-01-27 19:59:18 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
|
|
|
|
var.key = "sameboy_model_1";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
enum model new_model = model[0];
|
|
|
|
if (strcmp(var.value, "Game Boy") == 0)
|
|
|
|
new_model = MODEL_DMG;
|
|
|
|
else if (strcmp(var.value, "Game Boy Color") == 0)
|
|
|
|
new_model = MODEL_CGB;
|
|
|
|
else if (strcmp(var.value, "Game Boy Advance") == 0)
|
|
|
|
new_model = MODEL_AGB;
|
|
|
|
if (GB_is_inited(&gb[0]) && new_model != model[0]) {
|
|
|
|
model[0] = new_model;
|
|
|
|
init_for_current_model();
|
|
|
|
}
|
2018-01-19 22:06:33 +00:00
|
|
|
}
|
2018-02-01 03:06:41 +00:00
|
|
|
|
|
|
|
var.key = "sameboy_model_2";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
enum model new_model = model[0];
|
|
|
|
if (strcmp(var.value, "Game Boy") == 0)
|
|
|
|
new_model = MODEL_DMG;
|
|
|
|
else if (strcmp(var.value, "Game Boy Color") == 0)
|
|
|
|
new_model = MODEL_CGB;
|
|
|
|
else if (strcmp(var.value, "Game Boy Advance") == 0)
|
|
|
|
new_model = MODEL_AGB;
|
|
|
|
if (GB_is_inited(&gb[1]) && new_model != model[0]) {
|
|
|
|
model[0] = new_model;
|
|
|
|
init_for_current_model();
|
|
|
|
}
|
2018-01-27 19:46:13 +00:00
|
|
|
}
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-02-01 03:06:41 +00:00
|
|
|
}
|
2018-02-01 04:06:14 +00:00
|
|
|
|
2018-02-01 02:09:47 +00:00
|
|
|
var.key = "sameboy_link";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
2018-02-01 04:06:14 +00:00
|
|
|
int old_emulated_devices = emulated_devices;
|
2018-02-01 02:09:47 +00:00
|
|
|
if (strcmp(var.value, "enabled") == 0)
|
2018-02-01 02:13:44 +00:00
|
|
|
emulated_devices = 2;
|
|
|
|
else
|
2018-02-01 03:42:26 +00:00
|
|
|
emulated_devices = 1;
|
2018-02-01 04:06:14 +00:00
|
|
|
if (pre_init == 0 && emulated_devices != old_emulated_devices)
|
|
|
|
emulated_devices = old_emulated_devices;
|
2018-02-01 02:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var.key = "sameboy_link_layout";
|
|
|
|
var.value = NULL;
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
|
|
|
|
{
|
|
|
|
if (strcmp(var.value, "top-down") == 0)
|
|
|
|
layout = LAYOUT_TOP_DOWN;
|
2018-02-01 02:09:47 +00:00
|
|
|
else
|
2018-02-01 02:13:44 +00:00
|
|
|
layout = LAYOUT_LEFT_RIGHT;
|
2018-02-01 02:09:47 +00:00
|
|
|
}
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 03:42:26 +00:00
|
|
|
void retro_init(void)
|
|
|
|
{
|
|
|
|
frame_buf = (uint32_t*)malloc(2 * VIDEO_PIXELS * sizeof(uint32_t));
|
|
|
|
const char *dir = NULL;
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
|
|
|
|
snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", dir);
|
|
|
|
else
|
|
|
|
snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", ".");
|
|
|
|
|
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir)
|
|
|
|
snprintf(retro_save_directory, sizeof(retro_save_directory), "%s", dir);
|
|
|
|
else
|
|
|
|
snprintf(retro_save_directory, sizeof(retro_save_directory), "%s", ".");
|
|
|
|
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, emulated_devices == 2 ? (void *)vars_link : (void *)vars);
|
|
|
|
check_variables(emulated_devices == 2 ? true : false);
|
2018-02-01 04:06:14 +00:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, emulated_devices == 2 ? (void *)vars_link : (void *)vars);
|
2018-02-01 03:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 = "SameBoy";
|
|
|
|
#ifdef GIT_VERSION
|
|
|
|
info->library_version = SAMEBOY_CORE_VERSION GIT_VERSION;
|
|
|
|
#else
|
|
|
|
info->library_version = SAMEBOY_CORE_VERSION;
|
|
|
|
#endif
|
|
|
|
info->need_fullpath = true;
|
|
|
|
info->valid_extensions = "gb|gbc";
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_get_system_av_info(struct retro_system_av_info *info)
|
|
|
|
{
|
|
|
|
struct retro_game_geometry geom = { VIDEO_WIDTH, VIDEO_HEIGHT * 2, VIDEO_WIDTH, VIDEO_HEIGHT * 2 ,160.0 / 288.0 };
|
|
|
|
struct retro_system_timing timing = { FRAME_RATE, AUDIO_FREQUENCY };
|
|
|
|
|
|
|
|
info->geometry = geom;
|
|
|
|
info->timing = timing;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_environment(retro_environment_t cb)
|
|
|
|
{
|
|
|
|
environ_cb = cb;
|
|
|
|
|
|
|
|
if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
|
|
|
|
log_cb = logging.log;
|
|
|
|
else
|
|
|
|
log_cb = fallback_log;
|
|
|
|
|
|
|
|
static const struct retro_controller_description controllers[] = {
|
|
|
|
{ "Nintendo Gameboy", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct retro_controller_info ports[] = {
|
|
|
|
{ controllers, 1 },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
|
|
|
|
}
|
|
|
|
|
|
|
|
void retro_set_audio_sample(retro_audio_sample_t 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)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < emulated_devices; i++)
|
|
|
|
GB_reset(&gb[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-20 19:03:52 +00:00
|
|
|
void retro_run(void)
|
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
bool updated = false;
|
2018-02-01 04:06:14 +00:00
|
|
|
pre_init = 0;
|
2018-01-31 20:33:46 +00:00
|
|
|
|
|
|
|
if (!frame_buf)
|
|
|
|
return;
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-01-31 20:33:46 +00:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
|
2018-02-01 03:06:41 +00:00
|
|
|
check_variables(emulated_devices == 2 ? true : false);
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-01-31 20:33:46 +00:00
|
|
|
vblank1_occurred = vblank2_occurred = false;
|
|
|
|
signed delta = 0;
|
2018-02-01 03:42:26 +00:00
|
|
|
if (emulated_devices == 2)
|
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
while (!vblank1_occurred || !vblank2_occurred) {
|
2018-02-01 03:42:26 +00:00
|
|
|
if (delta >= 0) {
|
|
|
|
delta -= GB_run(&gb[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delta += GB_run(&gb[1]);
|
|
|
|
}
|
2018-01-31 20:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-01 03:42:26 +00:00
|
|
|
else
|
|
|
|
GB_run_frame(&gb[0]);
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-01-31 20:33:46 +00:00
|
|
|
video_cb(frame_buf, VIDEO_WIDTH, VIDEO_HEIGHT * 2, VIDEO_WIDTH * sizeof(uint32_t));
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool retro_load_game(const struct retro_game_info *info)
|
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
struct retro_input_descriptor desc[] = {
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
|
|
|
|
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
|
|
|
|
{ 0 },
|
|
|
|
};
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888;
|
|
|
|
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
|
|
|
|
{
|
|
|
|
log_cb(RETRO_LOG_INFO, "XRGB8888 is not supported.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
snprintf(retro_game_path, sizeof(retro_game_path), "%s", info->path);
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-31 21:58:17 +00:00
|
|
|
auto_model = (info->path[strlen(info->path) - 1] & ~0x20) == 'C' ? MODEL_CGB : MODEL_DMG;
|
2018-01-19 22:06:33 +00:00
|
|
|
init_for_current_model();
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-02-01 02:13:44 +00:00
|
|
|
for (int i = 0; i < emulated_devices; i++)
|
2018-02-01 02:09:47 +00:00
|
|
|
{
|
|
|
|
if (GB_load_rom(&gb[i],info->path))
|
|
|
|
{
|
|
|
|
log_cb(RETRO_LOG_INFO, "Failed to load ROM\n");
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-15 20:23:20 +00:00
|
|
|
}
|
2018-02-01 02:09:47 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
bool yes = true;
|
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS, &yes);
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
if (environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble))
|
|
|
|
log_cb(RETRO_LOG_INFO, "Rumble environment supported.\n");
|
|
|
|
else
|
|
|
|
log_cb(RETRO_LOG_INFO, "Rumble environment not supported.\n");
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-01-19 22:06:33 +00:00
|
|
|
static const struct retro_variable vars[] = {
|
2018-01-15 20:23:20 +00:00
|
|
|
{ "sameboy_color_correction_mode", "Color Correction; off|correct curves|emulate hardware|preserve brightness" },
|
|
|
|
{ "sameboy_high_pass_filter_mode", "High Pass Filter; off|accurate|remove dc offset" },
|
2018-01-27 19:46:13 +00:00
|
|
|
{ "sameboy_model", "Emulated Model; Auto|Game Boy|Game Boy Color|Game Boy Advance" },
|
2018-02-01 02:09:47 +00:00
|
|
|
{ "sameboy_link", "Link Cable; disabled|enabled" },
|
2018-02-01 02:13:44 +00:00
|
|
|
{ "sameboy_link_layout", "Screen Layout; top-down|left-right" },
|
2018-01-15 20:23:20 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
2018-02-05 23:17:55 +00:00
|
|
|
|
2018-02-01 03:06:41 +00:00
|
|
|
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, emulated_devices == 2 ? (void *)vars_link : (void *)vars);
|
|
|
|
check_variables(emulated_devices == 2 ? true : false);
|
2018-01-15 20:23:20 +00:00
|
|
|
return true;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_unload_game(void)
|
|
|
|
{
|
2018-02-01 02:13:44 +00:00
|
|
|
for (int i = 0; i < emulated_devices; i++)
|
2018-02-01 02:09:47 +00:00
|
|
|
GB_free(&gb[i]);
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned retro_get_region(void)
|
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
return RETRO_REGION_NTSC;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool retro_load_game_special(unsigned type, const struct retro_game_info *info, size_t num)
|
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
return false;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t retro_serialize_size(void)
|
|
|
|
{
|
2018-02-01 04:06:14 +00:00
|
|
|
return 2 * GB_get_save_state_size(&gb[0]);
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 17:03:51 +00:00
|
|
|
bool retro_serialize(void *data, size_t size)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-02-01 04:06:14 +00:00
|
|
|
if (pre_init == 1)
|
|
|
|
return false;
|
|
|
|
|
2018-02-01 03:42:26 +00:00
|
|
|
void* save_data[2];
|
|
|
|
for (int i = 0; i < emulated_devices; i++)
|
|
|
|
{
|
|
|
|
save_data[i] = (uint8_t*)malloc(size * sizeof(uint8_t) / emulated_devices);
|
|
|
|
GB_save_state_to_buffer(&gb[i], (uint8_t*) save_data[i]);
|
|
|
|
memcpy(data + (size * i / emulated_devices), save_data[i], size / emulated_devices);
|
|
|
|
free(save_data[i]);
|
|
|
|
}
|
2018-01-31 21:27:56 +00:00
|
|
|
|
2018-01-15 20:23:20 +00:00
|
|
|
if (data)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 17:03:51 +00:00
|
|
|
bool retro_unserialize(const void *data, size_t size)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-02-01 03:42:26 +00:00
|
|
|
void* save_data[2];
|
|
|
|
int ret;
|
2018-01-31 21:27:56 +00:00
|
|
|
|
2018-02-01 03:42:26 +00:00
|
|
|
for (int i = 0; i < emulated_devices; i++)
|
|
|
|
{
|
|
|
|
save_data[i] = (uint8_t*)malloc(size * sizeof(uint8_t)/ emulated_devices);
|
|
|
|
memcpy (save_data[i], data + (size * i / emulated_devices), size / emulated_devices);
|
|
|
|
ret = GB_load_state_from_buffer(&gb[i], save_data[i], size / emulated_devices);
|
|
|
|
free(save_data[i]);
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-31 21:27:56 +00:00
|
|
|
|
2018-02-01 03:42:26 +00:00
|
|
|
return true;
|
2018-01-31 21:27:56 +00:00
|
|
|
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 17:03:51 +00:00
|
|
|
void *retro_get_memory_data(unsigned type)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
void* data;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RETRO_MEMORY_SYSTEM_RAM:
|
2018-02-01 02:09:47 +00:00
|
|
|
data = gb[0].ram;
|
2018-01-31 20:33:46 +00:00
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_SAVE_RAM:
|
2018-02-01 02:09:47 +00:00
|
|
|
if (gb[0].cartridge_type->has_battery && gb[0].mbc_ram_size != 0)
|
2018-01-31 20:33:46 +00:00
|
|
|
{
|
2018-02-01 02:09:47 +00:00
|
|
|
data = gb[0].mbc_ram;
|
|
|
|
/* let's copy the save to gb[1] so it can save independently */
|
2018-02-01 03:42:26 +00:00
|
|
|
//memcpy(gb[1].mbc_ram, gb[0].mbc_ram, gb[0].mbc_ram_size);
|
2018-01-31 20:33:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
data = NULL;
|
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_VIDEO_RAM:
|
2018-02-01 02:09:47 +00:00
|
|
|
data = gb[0].vram;
|
2018-01-31 20:33:46 +00:00
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_RTC:
|
2018-02-01 02:09:47 +00:00
|
|
|
if(gb[0].cartridge_type->has_battery)
|
|
|
|
data = &gb[0].rtc_real;
|
2018-01-31 20:33:46 +00:00
|
|
|
else
|
|
|
|
data = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
2018-01-27 03:27:58 +00:00
|
|
|
data = NULL;
|
2018-01-15 20:23:20 +00:00
|
|
|
}
|
|
|
|
return data;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 17:03:51 +00:00
|
|
|
size_t retro_get_memory_size(unsigned type)
|
2017-04-20 19:03:52 +00:00
|
|
|
{
|
2018-01-31 20:33:46 +00:00
|
|
|
size_t size;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case RETRO_MEMORY_SYSTEM_RAM:
|
2018-02-01 02:09:47 +00:00
|
|
|
size = gb[0].ram_size;
|
2018-01-31 20:33:46 +00:00
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_SAVE_RAM:
|
2018-02-01 02:09:47 +00:00
|
|
|
if (gb[0].cartridge_type->has_battery && gb[0].mbc_ram_size != 0)
|
|
|
|
size = gb[0].mbc_ram_size;
|
2018-01-31 20:33:46 +00:00
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_VIDEO_RAM:
|
2018-02-01 02:09:47 +00:00
|
|
|
size = gb[0].vram_size;
|
2018-01-31 20:33:46 +00:00
|
|
|
break;
|
|
|
|
case RETRO_MEMORY_RTC:
|
2018-02-01 02:09:47 +00:00
|
|
|
if(gb[0].cartridge_type->has_battery)
|
|
|
|
size = sizeof (gb[0].rtc_real);
|
2018-01-31 20:33:46 +00:00
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2017-10-09 17:03:51 +00:00
|
|
|
size = 0;
|
2018-01-31 20:33:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void retro_cheat_reset(void)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void retro_cheat_set(unsigned index, bool enabled, const char *code)
|
|
|
|
{
|
2018-01-15 20:23:20 +00:00
|
|
|
(void)index;
|
|
|
|
(void)enabled;
|
|
|
|
(void)code;
|
2017-04-20 19:03:52 +00:00
|
|
|
}
|
|
|
|
|