Commit 62a06c10 authored by jdgleaver's avatar jdgleaver
Browse files

Miscellaneous fixes/improvements

parent d9456ae1
DEBUG = 0
FRONTEND_SUPPORTS_RGB565 = 1
FRONTEND_SUPPORTS_XRGB8888 = 0
TARGET_NAME := handy
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
......@@ -53,6 +54,7 @@ ifeq ($(platform), unix)
fpic := -fPIC
TARGET := $(TARGET_NAME)_libretro.so
SHARED := -shared -Wl,-version-script=$(LIBRETRO_DIR)/link.T -Wl,-no-undefined
FRONTEND_SUPPORTS_XRGB8888 = 1
# OS X
else ifeq ($(platform),osx)
......@@ -522,6 +524,7 @@ else
CC ?= gcc
CXX ?= g++
SHARED := -shared -static-libgcc -static-libstdc++ -Wl,-no-undefined -Wl,-version-script=$(LIBRETRO_DIR)/link.T
FRONTEND_SUPPORTS_XRGB8888 = 1
endif
......@@ -532,7 +535,7 @@ include Makefile.common
OBJECTS := $(SOURCES_CXX:.cpp=.o)
ifeq ($(DEBUG),1)
FLAGS += -O0
FLAGS += -O0 -g
else
FLAGS += -O2 -DNDEBUG
endif
......
LIBRETRO_COMM_DIR := $(CORE_DIR)/libretro-common
INCFLAGS = -I$(CORE_DIR)/lynx \
-I$(CORE_DIR)/libretro \
-I$(CORE_DIR)
-I$(CORE_DIR) \
-I$(LIBRETRO_COMM_DIR)/include \
ifneq (,$(findstring msvc2003,$(platform)))
INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc
......@@ -10,6 +13,10 @@ ifeq ($(FRONTEND_SUPPORTS_RGB565), 1)
FLAGS += -DFRONTEND_SUPPORTS_RGB565
endif
ifeq ($(FRONTEND_SUPPORTS_XRGB8888), 1)
FLAGS += -DFRONTEND_SUPPORTS_XRGB8888
endif
SOURCES_CXX := $(CORE_DIR)/lynx/lynxdec.cpp \
$(CORE_DIR)/lynx/cart.cpp \
$(CORE_DIR)/lynx/memmap.cpp \
......
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_inline.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_INLINE_H
#define __LIBRETRO_SDK_INLINE_H
#ifndef INLINE
#if defined(_WIN32) || defined(__INTEL_COMPILER)
#define INLINE __inline
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
#define INLINE inline
#elif defined(__GNUC__)
#define INLINE __inline__
#else
#define INLINE
#endif
#endif
#endif
#include "libretro.h"
#include "libretro_core_options.h"
#include <string.h>
#include <fstream>
#include "handy.h"
static retro_log_printf_t log_cb;
......@@ -16,17 +19,6 @@ static int16_t *soundBuffer = NULL;
#define RETRO_LYNX_WIDTH 160
#define RETRO_LYNX_HEIGHT 102
#if defined(DINGUX)
/* If a display mode of width 102 (or an integer
* multiple thereof) is requested on OpenDingux
* devices, the OS crashes. This is not a user
* space error, and there is no way to capture/
* handle it - the OS simply dies (instantly).
* Thus when the Lynx display is rotated, we
* have to pad the screen 'height' to the nearest
* 'safe' value (112) */
#define RETRO_LYNX_HEIGHT_ROTATE 112
#endif
// core options
static uint8_t lynx_rot = MIKIE_NO_ROTATE;
......@@ -34,22 +26,13 @@ static uint8_t lynx_width = RETRO_LYNX_WIDTH;
static uint8_t lynx_height = RETRO_LYNX_HEIGHT;
static int RETRO_PIX_BYTES = 2;
#if defined(FRONTEND_SUPPORTS_RGB565)
static int RETRO_PIX_DEPTH = 16;
#else
static int RETRO_PIX_DEPTH = 15;
#endif
#if defined(DINGUX)
/* When the Lynx display is rotated on OpenDingux
* devices, we offset the framebuffer pointer. To
* ensure the buffer cannot overflow, increase its
* overall size by a corresponding amount (we end
* up allocating more memory than we need, but this
* is harmless...) */
static uint8_t framebuffer[
RETRO_LYNX_WIDTH *
(RETRO_LYNX_WIDTH + (RETRO_LYNX_HEIGHT_ROTATE - RETRO_LYNX_HEIGHT)) *
4];
#else
static uint8_t framebuffer[RETRO_LYNX_WIDTH*RETRO_LYNX_WIDTH*4];
#endif
static bool newFrame = false;
static bool initialized = false;
......@@ -94,7 +77,6 @@ static map btn_map_rot_90[] = {
static map* btn_map;
static bool update_video = false;
static bool libretro_supports_input_bitmasks;
static bool select_button;
......@@ -102,6 +84,9 @@ static void check_color_depth(void)
{
if (RETRO_PIX_DEPTH == 24)
{
/* If XRGB8888 support is compiled in, attempt to
* set 24 bit colour depth */
#if defined(FRONTEND_SUPPORTS_XRGB8888)
enum retro_pixel_format rgb888 = RETRO_PIXEL_FORMAT_XRGB8888;
if(!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &rgb888))
......@@ -109,8 +94,24 @@ static void check_color_depth(void)
if(log_cb) log_cb(RETRO_LOG_ERROR, "Pixel format XRGB8888 not supported by platform.\n");
RETRO_PIX_BYTES = 2;
#if defined(FRONTEND_SUPPORTS_RGB565)
RETRO_PIX_DEPTH = 16;
#else
RETRO_PIX_DEPTH = 15;
#endif
}
#else
/* XRGB8888 support is *not* compiled in.
* If we reach this point, then unforeseen
* errors have occurred - just 'reset' colour
* depth to 16 bit */
RETRO_PIX_BYTES = 2;
#if defined(FRONTEND_SUPPORTS_RGB565)
RETRO_PIX_DEPTH = 16;
#else
RETRO_PIX_DEPTH = 15;
#endif
#endif
}
if (RETRO_PIX_BYTES == 2)
......@@ -157,7 +158,6 @@ static UBYTE* lynx_display_callback(ULONG objref)
video_cb(framebuffer, lynx_width, lynx_height, RETRO_LYNX_WIDTH*RETRO_PIX_BYTES);
for(int total = 0; total < gAudioBufferPointer/4; )
total += audio_batch_cb(soundBuffer + total*2, (gAudioBufferPointer/4) - total);
gAudioBufferPointer = 0;
......@@ -165,16 +165,7 @@ static UBYTE* lynx_display_callback(ULONG objref)
newFrame = true;
#if defined(DINGUX)
/* If Lynx display is rotated, offset the framebuffer
* by half the OpenDingux padding width */
if ((lynx_rot == MIKIE_ROTATE_R) ||
(lynx_rot == MIKIE_ROTATE_L))
return (UBYTE*)(framebuffer +
(((RETRO_LYNX_HEIGHT_ROTATE - RETRO_LYNX_HEIGHT) >> 1) * RETRO_PIX_BYTES));
else
#endif
return (UBYTE*)framebuffer;
return (UBYTE*)framebuffer;
}
static void lynx_rotate()
......@@ -194,38 +185,18 @@ static void lynx_rotate()
break;
case MIKIE_ROTATE_R:
#if defined(DINGUX)
/* OpenDingux - 'width' must be padded to a
* safe value */
lynx_width = RETRO_LYNX_HEIGHT_ROTATE;
#else
lynx_width = RETRO_LYNX_HEIGHT;
#endif
lynx_height = RETRO_LYNX_WIDTH;
btn_map = btn_map_rot_90;
break;
case MIKIE_ROTATE_L:
#if defined(DINGUX)
/* OpenDingux - 'width' must be padded to a
* safe value */
lynx_width = RETRO_LYNX_HEIGHT_ROTATE;
#else
lynx_width = RETRO_LYNX_HEIGHT;
#endif
lynx_height = RETRO_LYNX_WIDTH;
btn_map = btn_map_rot_270;
break;
}
#if defined(DINGUX)
/* Since the OpenDingux framebuffer may
* contain padding, ensure that it gets
* zeroed out whenever the rotation changes
* (avoids garbage pixels) */
memset(framebuffer, 0, sizeof(framebuffer));
#endif
switch (RETRO_PIX_DEPTH)
{
case 15: lynx->DisplaySetAttributes(lynx_rot, MIKIE_PIXEL_FORMAT_16BPP_555, RETRO_LYNX_WIDTH*2, lynx_display_callback, (ULONG)0); break;
......@@ -258,36 +229,23 @@ static void check_variables(void)
lynx_rotate();
}
#if defined(DINGUX)
#if defined(FRONTEND_SUPPORTS_XRGB8888)
/* Only read colour depth setting on first run */
if (!initialized)
{
int old_value = RETRO_PIX_BYTES;
var.key = "handy_gfx_colors";
var.value = NULL;
/* Set 16bpp by default */
RETRO_PIX_BYTES = 2;
RETRO_PIX_DEPTH = 16;
if (old_value != RETRO_PIX_BYTES)
update_video = true;
}
#else
var.key = "handy_gfx_colors";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
int old_value = RETRO_PIX_BYTES;
if (strcmp(var.value, "16bit") == 0)
{
RETRO_PIX_BYTES = 2;
RETRO_PIX_DEPTH = 16;
}
else if (strcmp(var.value, "24bit") == 0)
{
RETRO_PIX_BYTES = 4;
RETRO_PIX_DEPTH = 24;
}
if (old_value != RETRO_PIX_BYTES)
update_video = true;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
if (strcmp(var.value, "24bit") == 0)
{
RETRO_PIX_BYTES = 4;
RETRO_PIX_DEPTH = 24;
}
}
#endif
}
......@@ -329,20 +287,9 @@ void retro_deinit(void)
void retro_set_environment(retro_environment_t cb)
{
static const struct retro_variable vars[] = {
{ "handy_rot", "Display rotation; None|90|270" },
#if !defined(DINGUX)
/* 24bit colour depth is too slow for
* OpenDingux devices, and toggling colour
* depths may cause a crash... */
{ "handy_gfx_colors", "Color depth; 16bit|24bit" },
#endif
{ NULL, NULL },
};
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
environ_cb = cb;
libretro_set_core_options(environ_cb);
}
void retro_set_audio_sample(retro_audio_sample_t cb)
......@@ -492,26 +439,6 @@ void retro_run(void)
lynx_input();
if (update_video /*|| update_audio*/)
{
struct retro_system_av_info system_av_info;
if (update_video)
{
memset(&system_av_info, 0, sizeof(system_av_info));
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &system_av_info);
check_color_depth();
lynx_rotate();
}
retro_get_system_av_info(&system_av_info);
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &system_av_info);
update_video = false;
//update_audio = false;
}
gAudioLastUpdateCycle = gSystemCycleCount;
while (!newFrame)
......@@ -588,9 +515,6 @@ bool retro_load_game(const struct retro_game_info *info)
btn_map = btn_map_no_rot;
lynx_rotate();
update_video = false;
//update_audio = false;
initialized = true;
return true;
......
This diff is collapsed.
#ifndef LIBRETRO_CORE_OPTIONS_H__
#define LIBRETRO_CORE_OPTIONS_H__
#include <stdlib.h>
#include <string.h>
#include <libretro.h>
#include <retro_inline.h>
#ifndef HAVE_NO_LANGEXTRA
#include "libretro_core_options_intl.h"
#endif
/*
********************************
* VERSION: 1.3
********************************
*
* - 1.3: Move translations to libretro_core_options_intl.h
* - libretro_core_options_intl.h includes BOM and utf-8
* fix for MSVC 2010-2013
* - Added HAVE_NO_LANGEXTRA flag to disable translations
* on platforms/compilers without BOM support
* - 1.2: Use core options v1 interface when
* RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION is >= 1
* (previously required RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION == 1)
* - 1.1: Support generation of core options v0 retro_core_option_value
* arrays containing options with a single value
* - 1.0: First commit
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
********************************
* Core Option Definitions
********************************
*/
/* RETRO_LANGUAGE_ENGLISH */
/* Default language:
* - All other languages must include the same keys and values
* - Will be used as a fallback in the event that frontend language
* is not available
* - Will be used as a fallback for any missing entries in
* frontend language definition */
struct retro_core_option_definition option_defs_us[] = {
{
"handy_rot",
"Display Rotation",
"Rotate the virtual console screen to achieve the correct layout of 'portrait' oriented games on a conventional (landscape) display.",
{
{ "None", "disabled" },
{ "270", "Clockwise" },
{ "90", "Anticlockwise" },
{ NULL, NULL },
},
"None"
},
#if defined(FRONTEND_SUPPORTS_XRGB8888)
{
"handy_gfx_colors",
"Color Depth (Restart)",
"Specify number of colors to display on-screen. 24-bit significantly increases performance overheads and is not available on all platforms.",
{
{ "16bit", "Thousands (16-bit)" },
{ "24bit", "Millions (24-bit)" },
{ NULL, NULL },
},
"16bit"
},
#endif
{ NULL, NULL, NULL, {{0}}, NULL },
};
/*
********************************
* Language Mapping
********************************
*/
#ifndef HAVE_NO_LANGEXTRA
struct retro_core_option_definition *option_defs_intl[RETRO_LANGUAGE_LAST] = {
option_defs_us, /* RETRO_LANGUAGE_ENGLISH */
NULL, /* RETRO_LANGUAGE_JAPANESE */
NULL, /* RETRO_LANGUAGE_FRENCH */
NULL, /* RETRO_LANGUAGE_SPANISH */
NULL, /* RETRO_LANGUAGE_GERMAN */
NULL, /* RETRO_LANGUAGE_ITALIAN */
NULL, /* RETRO_LANGUAGE_DUTCH */
NULL, /* RETRO_LANGUAGE_PORTUGUESE_BRAZIL */
NULL, /* RETRO_LANGUAGE_PORTUGUESE_PORTUGAL */
NULL, /* RETRO_LANGUAGE_RUSSIAN */
NULL, /* RETRO_LANGUAGE_KOREAN */
NULL, /* RETRO_LANGUAGE_CHINESE_TRADITIONAL */
NULL, /* RETRO_LANGUAGE_CHINESE_SIMPLIFIED */
NULL, /* RETRO_LANGUAGE_ESPERANTO */
NULL, /* RETRO_LANGUAGE_POLISH */
NULL, /* RETRO_LANGUAGE_VIETNAMESE */
NULL, /* RETRO_LANGUAGE_ARABIC */
NULL, /* RETRO_LANGUAGE_GREEK */
NULL, /* RETRO_LANGUAGE_TURKISH */
NULL, /* RETRO_LANGUAGE_SLOVAK */
NULL, /* RETRO_LANGUAGE_PERSIAN */
NULL, /* RETRO_LANGUAGE_HEBREW */
NULL, /* RETRO_LANGUAGE_ASTURIAN */
};
#endif
/*
********************************
* Functions
********************************
*/
/* Handles configuration/setting of core options.
* Should be called as early as possible - ideally inside
* retro_set_environment(), and no later than retro_load_game()
* > We place the function body in the header to avoid the
* necessity of adding more .c files (i.e. want this to
* be as painless as possible for core devs)
*/
static INLINE void libretro_set_core_options(retro_environment_t environ_cb)
{
unsigned version = 0;
if (!environ_cb)
return;
if (environ_cb(RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION, &version) && (version >= 1))
{
#ifndef HAVE_NO_LANGEXTRA
struct retro_core_options_intl core_options_intl;
unsigned language = 0;
core_options_intl.us = option_defs_us;
core_options_intl.local = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_LANGUAGE, &language) &&
(language < RETRO_LANGUAGE_LAST) && (language != RETRO_LANGUAGE_ENGLISH))
core_options_intl.local = option_defs_intl[language];
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL, &core_options_intl);
#else
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS, &option_defs_us);
#endif
}
else
{
size_t i;
size_t num_options = 0;
struct retro_variable *variables = NULL;
char **values_buf = NULL;
/* Determine number of options */
for (;;)
{
if (!option_defs_us[num_options].key)
break;
num_options++;
}
/* Allocate arrays */
variables = (struct retro_variable *)calloc(num_options + 1, sizeof(struct retro_variable));
values_buf = (char **)calloc(num_options, sizeof(char *));
if (!variables || !values_buf)
goto error;
/* Copy parameters from option_defs_us array */
for (i = 0; i < num_options; i++)
{
const char *key = option_defs_us[i].key;
const char *desc = option_defs_us[i].desc;
const char *default_value = option_defs_us[i].default_value;
struct retro_core_option_value *values = option_defs_us[i].values;
size_t buf_len = 3;
size_t default_index = 0;
values_buf[i] = NULL;
if (desc)
{
size_t num_values = 0;
/* Determine number of values */
for (;;)
{
if (!values[num_values].value)
break;
/* Check if this is the default value */
if (default_value)
if (strcmp(values[num_values].value, default_value) == 0)
default_index = num_values;
buf_len += strlen(values[num_values].value);
num_values++;
}
/* Build values string */
if (num_values > 0)
{
size_t j;
buf_len += num_values - 1;
buf_len += strlen(desc);
values_buf[i] = (char *)calloc(buf_len, sizeof(char));
if (!values_buf[i])
goto error;
strcpy(values_buf[i], desc);
strcat(values_buf[i], "; ");
/* Default value goes first */
strcat(values_buf[i], values[default_index].value);
/* Add remaining values */
for (j = 0; j < num_values; j++)
{
if (j != default_index)
{
strcat(values_buf[i], "|");
strcat(values_buf[i], values[j].value);
}
}
}
}
variables[i].key = key;
variables[i].value = values_buf[i];
}
/* Set variables */
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables);
error:
/* Clean up */
if (values_buf)
{
for (i = 0; i < num_options; i++)
{
if (values_buf[i])
{
free(values_buf[i]);
values_buf[i] = NULL;
}
}
free(values_buf);
values_buf = NULL;
}
if (variables)
{
free(variables);
variables = NULL;
}
}
}
#ifdef __cplusplus
}
#endif
#endif
#ifndef LIBRETRO_CORE_OPTIONS_INTL_H__
#define LIBRETRO_CORE_OPTIONS_INTL_H__