Libretro core

This commit is contained in:
Emery Hemingway 2018-08-02 12:56:06 +02:00 committed by Peter De Wachter
parent e3a4195a2f
commit 62b409c084
6 changed files with 3359 additions and 0 deletions

7
.gitignore vendored
View File

@ -1,2 +1,9 @@
risc
*.img
/Libretro/libretro.o
/Libretro/oberon_libretro.so
/src/disk.o
/src/pclink.o
/src/raw-serial.o
/src/risc-fp.o
/src/risc.o

515
Libretro/Makefile Normal file
View File

@ -0,0 +1,515 @@
DEBUG = 0
HAVE_EXCEPTIONS = 0
LAGFIX=1
HAVE_STRINGS_H = 1
SPACE :=
SPACE := $(SPACE) $(SPACE)
BACKSLASH :=
BACKSLASH := \$(BACKSLASH)
filter_out1 = $(filter-out $(firstword $1),$1)
filter_out2 = $(call filter_out1,$(call filter_out1,$1))
ifeq ($(platform),)
platform = unix
ifeq ($(shell uname -s),)
platform = win
else ifneq ($(findstring MINGW,$(shell uname -s)),)
platform = win
else ifneq ($(findstring Darwin,$(shell uname -s)),)
platform = osx
arch = intel
ifeq ($(shell uname -p),powerpc)
arch = ppc
endif
else ifneq ($(findstring win,$(shell uname -s)),)
platform = win
endif
else ifneq (,$(findstring armv,$(platform)))
override platform += unix
else ifneq (,$(findstring rpi,$(platform)))
override platform += unix
endif
TARGET_NAME = oberon
ifneq ($(platform), genode)
ifeq (,$(findstring msvc,$(platform)))
LIBS += -lm
endif
endif
CORE_DIR := ..
GIT_VERSION := " $(shell cd $(CORE_DIR); git log -1 --pretty='%cd %h' --date=short || echo unknown)"
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
ifeq ($(LAGFIX),1)
CFLAGS += -DLAGFIX
endif
# Genode
ifeq ($(platform), genode)
TARGET := $(TARGET_NAME)_libretro.lib.so
PKG_CONFIG_LIBS := genode-lib genode-libc
CFLAGS += -D__GENODE__
CFLAGS += $(shell pkg-config --cflags $(PKG_CONFIG_LIBS))
LDFLAGS += -shared --version-script=link.T
LDFLAGS += $(shell pkg-config --libs $(PKG_CONFIG_LIBS))
CC = /usr/local/genode-gcc/bin/genode-x86-gcc
LD = /usr/local/genode-gcc/bin/genode-x86-ld
AR = /usr/local/genode-gcc/bin/genode-x86-ar -rcs
RANLIB = /usr/local/genode-gcc/bin/genode-x86-ranlib
# Unix
else ifneq (,$(findstring unix,$(platform)))
TARGET := $(TARGET_NAME)_libretro.so
fpic := -fPIC
ifneq ($(findstring SunOS,$(shell uname -a)),)
CC = gcc
SHARED := -shared -z defs
else
SHARED := -shared --version-script=link.T
endif
ifneq ($(findstring Haiku,$(shell uname -a)),)
LIBS :=
endif
# ARM
ifneq (,$(findstring armv,$(platform)))
CFLAGS += -DARM
# Raspberry Pi
else ifneq (,$(findstring rpi,$(platform)))
CFLAGS += -DARM
endif
# OS X
else ifeq ($(platform), osx)
TARGET := $(TARGET_NAME)_libretro.dylib
fpic := -fPIC
SHARED := -dynamiclib
arch = intel
ifeq ($(shell uname -p),powerpc)
arch = ppc
endif
ifeq ($(arch),ppc)
CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
endif
OSXVER = `sw_vers -productVersion | cut -d. -f 2`
OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
fpic += -mmacosx-version-min=10.1
# iOS
else ifneq (,$(findstring ios,$(platform)))
TARGET := $(TARGET_NAME)_libretro_ios.dylib
fpic := -fPIC
SHARED := -dynamiclib
ifeq ($(IOSSDK),)
IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
endif
ifeq ($(platform),ios-arm64)
CC = clang -arch arm64 -isysroot $(IOSSDK)
else
CC = clang -arch armv7 -isysroot $(IOSSDK)
endif
CFLAGS += -DIOS
CFLAGS += -DARM
ifeq ($(platform),$(filter $(platform),ios9 ios-arm64))
CC += -miphoneos-version-min=8.0
CFLAGS += -miphoneos-version-min=8.0
else
CC += -miphoneos-version-min=5.0
CFLAGS += -miphoneos-version-min=5.0
endif
# Theos
else ifeq ($(platform), theos_ios)
DEPLOYMENT_IOSVERSION = 5.0
TARGET = iphone:latest:$(DEPLOYMENT_IOSVERSION)
ARCHS = armv7 armv7s
TARGET_IPHONEOS_DEPLOYMENT_VERSION=$(DEPLOYMENT_IOSVERSION)
THEOS_BUILD_DIR := objs
include $(THEOS)/makefiles/common.mk
LIBRARY_NAME = $(TARGET_NAME)_libretro_ios
# QNX
else ifeq ($(platform), qnx)
TARGET := $(TARGET_NAME)_libretro_$(platform).so
fpic := -fPIC
SHARED := -shared --version-script=link.T
CC = qcc -Vgcc_notarmv7le
AR = QCC -Vgcc_ntoarmv7le
CFLAGS += -D__BLACKBERRY_QNX__
CFLAGS += -DARM
# Vita
else ifeq ($(platform), vita)
TARGET := $(TARGET_NAME)_libretro_$(platform).so
fpic := -fPIC
CC = arm-vita-eabi-gcc$(EXE_EXT)
AR = arm-vita-eabi-ar$(EXE_EXT)
CFLAGS += -DVITA
# PS3
else ifneq (,$(filter $(platform), ps3 sncps3 psl1ght))
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__
STATIC_LINKING = 1
HAVE_STRINGS_H = 0
# sncps3
ifneq (,$(findstring sncps3,$(platform)))
TARGET := $(TARGET_NAME)_libretro_ps3.a
CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
# PS3
else ifneq (,$(findstring ps3,$(platform)))
CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe
AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
# Lightweight PS3 Homebrew SDK
else ifneq (,$(findstring psl1ght,$(platform)))
CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT)
endif
# Xbox 360
else ifeq ($(platform), xenon)
TARGET := $(TARGET_NAME)_libretro_xenon360.a
CC = xenon-gcc$(EXE_EXT)
AR = xenon-ar$(EXE_EXT)
CFLAGS += -D__LIBXENON__ -m32 -D__ppc__
STATIC_LINKING = 1
# Nintendo Game Cube / Wii / WiiU
else ifneq (,$(filter $(platform), ngc wii wiiu))
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
CFLAGS += -mcpu=750 -meabi -mhard-float -DBLARGG_BIG_ENDIAN=1 -D__ppc__
CFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
STATIC_LINKING = 1
# Nintendo WiiU
ifneq (,$(findstring wiiu,$(platform)))
CFLAGS += -mwup
# Nintendo Wii
else ifneq (,$(findstring wii,$(platform)))
CFLAGS += -DGEKKO -mrvl
# Nintendo Game Cube
else ifneq (,$(findstring ngc,$(platform)))
CFLAGS += -DGEKKO -mrvl
endif
# Emscripten
else ifeq ($(platform), emscripten)
TARGET := $(TARGET_NAME)_libretro_$(platform).bc
STATIC_LINKING = 1
# Windows MSVC 2003 Xbox 1
else ifeq ($(platform), xbox1_msvc2003)
CFLAGS += -D__WIN32__
TARGET := $(TARGET_NAME)_libretro_xdk1.lib
MSVCBINDIRPREFIX = $(XDK)/xbox/bin/vc71
CC = "$(MSVCBINDIRPREFIX)/CL.exe"
LD = "$(MSVCBINDIRPREFIX)/lib.exe"
export INCLUDE := $(XDK)/xbox/include
export LIB := $(XDK)/xbox/lib
PSS_STYLE :=2
CFLAGS += -D_XBOX -D_XBOX1
STATIC_LINKING=1
HAS_GCC := 0
# Windows MSVC 2010 Xbox 360
else ifeq ($(platform), xbox360_msvc2010)
CFLAGS += -D__WIN32__
TARGET := $(TARGET_NAME)_libretro_xdk360.lib
MSVCBINDIRPREFIX = $(XEDK)/bin/win32
CC = "$(MSVCBINDIRPREFIX)/cl.exe"
LD = "$(MSVCBINDIRPREFIX)/lib.exe"
export INCLUDE := $(XEDK)/include/xbox
export LIB := $(XEDK)/lib/xbox
PSS_STYLE :=2
CFLAGS += -D_XBOX -D_XBOX360
STATIC_LINKING=1
HAS_GCC := 0
# Windows MSVC 2017 all architectures
else ifneq (,$(findstring windows_msvc2017,$(platform)))
CFLAGS += -D__WIN32__
PlatformSuffix = $(subst windows_msvc2017_,,$(platform))
ifneq (,$(findstring desktop,$(PlatformSuffix)))
WinPartition = desktop
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP
LDFLAGS += -MANIFEST -LTCG:incremental -NXCOMPAT -DYNAMICBASE -DEBUG -OPT:REF -INCREMENTAL:NO -SUBSYSTEM:WINDOWS -MANIFESTUAC:"level='asInvoker' uiAccess='false'" -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1
LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
else ifneq (,$(findstring uwp,$(PlatformSuffix)))
WinPartition = uwp
MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -ZW:nostdlib -EHsc
LDFLAGS += -APPCONTAINER -NXCOMPAT -DYNAMICBASE -MANIFEST:NO -LTCG -OPT:REF -SUBSYSTEM:CONSOLE -MANIFESTUAC:NO -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 -DEBUG:FULL -WINMD:NO
LIBS += WindowsApp.lib
endif
# Specific to this core
MSVC2017CompileFlags += -D__WIN32__
CFLAGS += $(MSVC2017CompileFlags)
TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))
CC = cl.exe
reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul)))
fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))
ProgramFiles86w := $(shell cmd /c "echo %PROGRAMFILES(x86)%")
ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0)
WindowsSdkDir := $(WindowsSdkDir)
WindowsSDKVersion ?= $(firstword $(foreach folder,$(subst $(subst \,/,$(WindowsSdkDir)Include/),,$(wildcard $(call fix_path,$(WindowsSdkDir)Include\*))),$(if $(wildcard $(call fix_path,$(WindowsSdkDir)Include/$(folder)/um/Windows.h)),$(folder),)))$(BACKSLASH)
WindowsSDKVersion := $(WindowsSDKVersion)
VsInstallBuildTools = $(ProgramFiles86)/Microsoft Visual Studio/2017/BuildTools
VsInstallEnterprise = $(ProgramFiles86)/Microsoft Visual Studio/2017/Enterprise
VsInstallProfessional = $(ProgramFiles86)/Microsoft Visual Studio/2017/Professional
VsInstallCommunity = $(ProgramFiles86)/Microsoft Visual Studio/2017/Community
VsInstallRoot ?= $(shell if [ -d "$(VsInstallBuildTools)" ]; then echo "$(VsInstallBuildTools)"; fi)
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallEnterprise)" ]; then echo "$(VsInstallEnterprise)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallProfessional)" ]; then echo "$(VsInstallProfessional)"; fi)
endif
ifeq ($(VsInstallRoot), )
VsInstallRoot = $(shell if [ -d "$(VsInstallCommunity)" ]; then echo "$(VsInstallCommunity)"; fi)
endif
VsInstallRoot := $(VsInstallRoot)
VcCompilerToolsVer := $(shell cat "$(VsInstallRoot)/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | grep -o '[0-9\.]*')
VcCompilerToolsDir := $(VsInstallRoot)/VC/Tools/MSVC/$(VcCompilerToolsVer)
WindowsSDKSharedIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\shared")
WindowsSDKUCRTIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\ucrt")
WindowsSDKUMIncludeDir := $(shell cygpath -w "$(WindowsSdkDir)\Include\$(WindowsSDKVersion)\um")
WindowsSDKUCRTLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\ucrt\$(TargetArchMoniker)")
WindowsSDKUMLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib\$(WindowsSDKVersion)\um\$(TargetArchMoniker)")
# For some reason the HostX86 compiler doesn't like compiling for x64
# ("no such file" opening a shared library), and vice-versa.
# Work around it for now by using the strictly x86 compiler for x86, and x64 for x64.
# NOTE: What about ARM?
ifneq (,$(findstring x64,$(TargetArchMoniker)))
VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX64
else
VCCompilerToolsBinDir := $(VcCompilerToolsDir)\bin\HostX86
endif
PATH := $(shell IFS=$$'\n'; cygpath "$(VCCompilerToolsBinDir)/$(TargetArchMoniker)"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VsInstallRoot)/Common7/IDE")
INCLUDE := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/include")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VcCompilerToolsDir)/lib/$(TargetArchMoniker)")
ifneq (,$(findstring uwp,$(PlatformSuffix)))
LIB := $(shell IFS=$$'\n'; cygpath -w "$(LIB)/store")
endif
export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir)
export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir)
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL
# Windows MSVC 2010 x64
else ifeq ($(platform), windows_msvc2010_x64)
CFLAGS += -D__WIN32__
CC = cl.exe
PATH := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/bin/amd64"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../IDE")
LIB := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/lib/amd64")
INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/include")
WindowsSdkDir := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')lib/x64
WindowsSdkDir ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')lib/x64
WindowsSdkDirInc := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
WindowsSdkDirInc ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
INCFLAGS_PLATFORM = -I"$(WindowsSdkDirInc)"
export INCLUDE := $(INCLUDE)
export LIB := $(LIB);$(WindowsSdkDir)
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL
LIBS :=
# Windows MSVC 2010 x86
else ifeq ($(platform), windows_msvc2010_x86)
CFLAGS += -D__WIN32__
CC = cl.exe
PATH := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/bin"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../IDE")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VS100COMNTOOLS)../../VC/lib")
INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS100COMNTOOLS)../../VC/include")
WindowsSdkDir := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')lib
WindowsSdkDir ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')lib
WindowsSdkDirInc := $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
WindowsSdkDirInc ?= $(shell reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" -v "InstallationFolder" | grep -o '[A-Z]:\\.*')Include
INCFLAGS_PLATFORM = -I"$(WindowsSdkDirInc)"
export INCLUDE := $(INCLUDE)
export LIB := $(LIB);$(WindowsSdkDir)
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL
LIBS :=
# Windows MSVC 2003 x86
else ifeq ($(platform), windows_msvc2003_x86)
CFLAGS += -D__WIN32__
CC = cl.exe
PATH := $(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../../Vc7/bin"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../IDE")
INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../../Vc7/include")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VS71COMNTOOLS)../../Vc7/lib")
BIN := $(shell IFS=$$'\n'; cygpath "$(VS71COMNTOOLS)../../Vc7/bin")
WindowsSdkDir := $(INETSDK)
export INCLUDE := $(INCLUDE);$(INETSDK)/Include;src/drivers/libretro/msvc/msvc-2005
export LIB := $(LIB);$(WindowsSdkDir);$(INETSDK)/Lib
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL
CFLAGS += -D_CRT_SECURE_NO_DEPRECATE
# Windows MSVC 2005 x86
else ifeq ($(platform), windows_msvc2005_x86)
CFLAGS += -D__WIN32__
CC = cl.exe
PATH := $(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../../VC/bin"):$(PATH)
PATH := $(PATH):$(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../IDE")
INCLUDE := $(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../../VC/include")
LIB := $(shell IFS=$$'\n'; cygpath -w "$(VS80COMNTOOLS)../../VC/lib")
BIN := $(shell IFS=$$'\n'; cygpath "$(VS80COMNTOOLS)../../VC/bin")
WindowsSdkDir := $(INETSDK)
export INCLUDE := $(INCLUDE);$(INETSDK)/Include;libretro-common/include/compat/msvc
export LIB := $(LIB);$(WindowsSdkDir);$(INETSDK)/Lib
TARGET := $(TARGET_NAME)_libretro.dll
PSS_STYLE :=2
LDFLAGS += -DLL
CFLAGS += -D_CRT_SECURE_NO_DEPRECATE
# Windows
else
TARGET := $(TARGET_NAME)_libretro.dll
CC =? gcc
SHARED := -shared -static-libgcc -s --version-script=link.T
endif
ifeq ($(DEBUG), 1)
ifneq (,$(findstring msvc,$(platform)))
CFLAGS += -Od -Zi -DDEBUG -D_DEBUG
ifeq ($(STATIC_LINKING),1)
CFLAGS += -MTd
else
CFLAGS += -MDd
endif
else
CFLAGS += -O0 -g -DDEBUG
endif
else
CFLAGS += -O2 -DNDEBUG
ifneq (,$(findstring msvc,$(platform)))
ifeq ($(STATIC_LINKING),1)
CFLAGS += -MT
else
CFLAGS += -MD
endif
endif
endif
include Makefile.common
OBJECTS := $(SOURCES_C:.c=.o)
ifeq ($(platform), sncps3)
WARNINGS_DEFINES =
CODE_DEFINES =
else ifneq (,$(findstring msvc,$(platform)))
WARNINGS_DEFINES =
CODE_DEFINES =
else
WARNINGS_DEFINES = -Wall -W -Wno-unused-parameter
CODE_DEFINES = -fomit-frame-pointer
endif
CFLAGS += $(CODE_DEFINES) $(WARNINGS_DEFINES) $(fpic)
CFLAGS += -DRIGHTSHIFT_IS_SAR -D__LIBRETRO__ -DALLOW_CPU_OVERCLOCK
CFLAGS += -DHAVE_STDINT_H
ifeq (,$(findstring msvc,$(platform)))
ifeq ($(HAVE_STRINGS_H), 1)
CFLAGS += -DHAVE_STRINGS_H
endif
CFLAGS += -pedantic
endif
OBJOUT = -o
LINKOUT = -o
ifneq (,$(findstring msvc,$(platform)))
OBJOUT = -Fo
LINKOUT = -out:
ifeq ($(STATIC_LINKING),1)
LD ?= lib.exe
STATIC_LINKING=0
else
LD = link.exe
endif
endif
INCFLAGS += $(INCFLAGS_PLATFORM)
ifeq ($(platform), theos_ios)
COMMON_FLAGS := -DIOS -DARM $(COMMON_DEFINES) $(INCFLAGS) -I$(THEOS_INCLUDE_PATH) -Wno-error
$(LIBRARY_NAME)_CFLAGS += $(CFLAGS) $(COMMON_FLAGS)
${LIBRARY_NAME}_FILES = $(SOURCES_CXX) $(SOURCES_C)
include $(THEOS_MAKE_PATH)/library.mk
else
all: $(TARGET)
$(TARGET): $(OBJECTS)
ifeq ($(STATIC_LINKING), 1)
$(AR) rcs $@ $(OBJECTS)
else
$(LD) $(fpic) $(SHARED) $(LINKOUT)$@ $(OBJECTS) $(LDFLAGS) $(LIBS)
endif
%.o: %.c
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $(OBJOUT)$@ $<
clean:
rm -f $(OBJECTS) $(TARGET)
endif

9
Libretro/Makefile.common Normal file
View File

@ -0,0 +1,9 @@
INCFLAGS := -I$(CORE_DIR)/src
SOURCES_C := \
$(CORE_DIR)/Libretro/libretro.c \
$(CORE_DIR)/src/risc.c \
$(CORE_DIR)/src/risc-fp.c \
$(CORE_DIR)/src/disk.c \
$(CORE_DIR)/src/pclink.c \
$(CORE_DIR)/src/raw-serial.c \

431
Libretro/libretro.c Normal file
View File

@ -0,0 +1,431 @@
#include "libretro.h"
#include "risc.h"
#include "disk.h"
#include "pclink.h"
#include "raw-serial.h"
#include "sdl-ps2.h"
#include <stdlib.h>
#include <stdio.h>
static int clamp(int x, int min, int max) {
if (x < min) return min;
if (x > max) return max;
return x;
}
#define CPU_HZ 25000000
#define FPS 30
static uint16_t FOR = 0x0000, AFT = 0xFFFF;
unsigned retro_api_version(void) {
return RETRO_API_VERSION; }
void retro_get_system_info(struct retro_system_info *info)
{
info->library_name = "Oberon";
info->library_version = GIT_VERSION;
info->valid_extensions = "dsk";
info->need_fullpath = true;
info->block_extract = false;
}
void dummy_log(enum retro_log_level level, const char *fmt, ...) { }
static retro_log_printf_t _log_cb;
static retro_environment_t _environ_cb;
static retro_video_refresh_t _video_cb;
static retro_input_poll_t _input_poll_cb;
static retro_input_state_t _input_state_cb;
static struct RISC *_risc = NULL;
static struct RISC_SPI *_spi_disk = NULL;
static uint32_t _ms_counter;
static int _mouse_x, _mouse_y;
enum k_type {
K_UNKNOWN = 0,
K_NORMAL,
K_EXTENDED,
K_NUMLOCK_HACK,
K_SHIFT_HACK,
};
struct k_info {
uint8_t code;
uint8_t type;
};
static struct k_info _keymap[RETROK_LAST];
static struct retro_framebuffer _framebuffer;
void _keyboard_cb(bool down, unsigned keycode,
uint32_t character, uint16_t key_modifiers)
{
uint8_t buf[MAX_PS2_CODE_LEN];
int i = 0;
struct k_info info = _keymap[keycode];
switch (info.type) {
case K_UNKNOWN:
printf("unknown Libretro keycode %d\n", keycode);
break;
case K_NORMAL:
if (!down)
buf[i++] = 0xf0;
buf[i++] = info.code;
break;
case K_EXTENDED:
buf[i++] = 0xe0;
if (!down)
buf[i++] = 0xf0;
buf[i++] = info.code;
break;
case K_NUMLOCK_HACK:
// This assumes Num Lock is always active
if (down) {
// fake shift press
buf[i++] = 0xe0;
buf[i++] = 0x12;
buf[i++] = 0xe0;
buf[i++] = info.code;
} else {
buf[i++] = 0xe0;
buf[i++] = 0xf0;
buf[i++] = info.code;
// fake shift release
buf[i++] = 0xe0;
buf[i++] = 0xf0;
buf[i++] = 0x12;
}
break;
case K_SHIFT_HACK:
if (down) {
// fake shift release
if (key_modifiers & RETROKMOD_SHIFT) {
buf[i++] = 0xe0;
buf[i++] = 0xf0;
buf[i++] = 0x12;
}
buf[i++] = 0xe0;
buf[i++] = info.code;
} else {
buf[i++] = 0xe0;
buf[i++] = 0xf0;
buf[i++] = info.code;
// fake shift press
if (key_modifiers & RETROKMOD_SHIFT) {
buf[i++] = 0xE0;
buf[i++] = 0x59;
}
}
break;
}
risc_keyboard_input(_risc, buf, i);
}
void retro_set_environment(retro_environment_t cb) {
_environ_cb = cb; }
void retro_set_video_refresh(retro_video_refresh_t cb) {
_video_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_audio_sample(retro_audio_sample_t cb) { }
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { }
void retro_init(void)
{
_risc = risc_new();
risc_set_serial(_risc, &pclink);
struct retro_log_callback log_callback;
_log_cb = _environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log_callback)
? log_callback.log
: dummy_log;
}
void retro_deinit(void)
{
if (_risc) {
free(_risc);
_risc = NULL;
}
}
void retro_set_controller_port_device(unsigned port, unsigned device) { }
void retro_reset(void) {
_ms_counter = 1;
risc_reset(_risc);
}
size_t retro_serialize_size(void) { return 0; }
bool retro_serialize( void *data, size_t size) { return false; }
bool retro_unserialize(const void *data, size_t size) { return false; }
void retro_cheat_reset(void) { }
void retro_cheat_set(unsigned index, bool enabled, const char *code) { }
/* Loads a game. */
bool retro_load_game(const struct retro_game_info *game)
{
struct retro_keyboard_callback callback = { _keyboard_cb };
if (!_environ_cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, &callback)) {
_log_cb(RETRO_LOG_ERROR, "core requires keyboard callback support\n");
return false;
}
if (game->path)
_spi_disk = disk_new(game->path);
if (!_spi_disk) {
_log_cb(RETRO_LOG_ERROR, "failed to load disk image\n");
return false;
}
risc_set_spi(_risc, 1, _spi_disk);
risc_set_serial(_risc, raw_serial_new("/dev/null", "/dev/null"));
enum retro_pixel_format pf = RETRO_PIXEL_FORMAT_RGB565;
_environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &pf);
/* if this fails then its still 0RGB1555 */
if (!_environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &_framebuffer)) {
_framebuffer.width = RISC_FRAMEBUFFER_WIDTH;
_framebuffer.height = RISC_FRAMEBUFFER_HEIGHT;
}
_framebuffer.width = _framebuffer.width & ~31U;
if (_framebuffer.width < 32)
_framebuffer.width = 32;
if (_framebuffer.height < 32)
_framebuffer.height = 32;
_framebuffer.data = malloc(
_framebuffer.width *
_framebuffer.height *
sizeof(uint16_t));
risc_screen_size_hack(_risc, _framebuffer.width, _framebuffer.height);
_ms_counter = 1;
_mouse_x = 0;
_mouse_y = _framebuffer.height;
return true;
}
void retro_get_system_av_info(struct retro_system_av_info *info)
{
info->geometry.base_width =
info->geometry.max_width = _framebuffer.width;
info->geometry.base_height =
info->geometry.max_height = _framebuffer.height;
info->geometry.aspect_ratio = 0.0;
info->timing.fps = FPS;
info->timing.sample_rate = 0;
}
bool retro_load_game_special(
unsigned game_type,
const struct retro_game_info *info, size_t num_info
) { return false; }
/* Unloads a currently loaded game. */
void retro_unload_game(void)
{
if (!_risc && _spi_disk) {
free(_spi_disk);
_spi_disk = NULL;
}
}
unsigned retro_get_region(void) { return ~0U; }
void *retro_get_memory_data(unsigned id) { return NULL; }
size_t retro_get_memory_size(unsigned id) { return 0; }
void retro_run(void)
{
_input_poll_cb();
int mx = _mouse_x + _input_state_cb(
0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
int my = _mouse_y - _input_state_cb(
0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
_mouse_x = clamp(mx, 0, _framebuffer.width);
_mouse_y = clamp(my, 0, _framebuffer.height);
risc_mouse_moved(_risc, _mouse_x, _mouse_y);
risc_mouse_button(_risc, 1,
_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT));
risc_mouse_button(_risc, 2,
_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_MIDDLE));
risc_mouse_button(_risc, 3,
_input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT));
risc_set_time(_risc, _ms_counter);
_ms_counter += 1000 / FPS;
risc_run(_risc, CPU_HZ / FPS);
struct Damage damage = risc_get_framebuffer_damage(_risc);
if (damage.y1 <= damage.y2) {
uint32_t *in = risc_get_framebuffer_ptr(_risc);
uint16_t *out = _framebuffer.data;
uint16_t colors[] = { AFT, FOR };
for (int line = damage.y2; line >= damage.y1; line--) {
int in_line = line * (_framebuffer.width / 32);
int out_idx = ((_framebuffer.height-line) * _framebuffer.width)
+ damage.x1 * 32;
for (int col = damage.x1; col <= damage.x2; col++) {
uint32_t chunk = in[in_line + col];
for (int b = 0; b < 32; b++) {
out[out_idx] = colors[chunk&1];
chunk >>= 1;
out_idx++;
}
}
}
}
_video_cb(
_framebuffer.data,
_framebuffer.width,
_framebuffer.height,
_framebuffer.width << 1);
}
static struct k_info _keymap[RETROK_LAST] = {
[ RETROK_BACKSPACE ] = { 0x66, K_NORMAL },
[ RETROK_TAB ] = { 0x0d, K_NORMAL },
[ RETROK_RETURN ] = { 0x5a, K_NORMAL },
[ RETROK_QUOTE ] = { 0x52, K_NORMAL },
[ RETROK_ESCAPE ] = { 0x76, K_NORMAL },
[ RETROK_SPACE ] = { 0x29, K_NORMAL },
[ RETROK_COMMA ] = { 0x41, K_NORMAL },
[ RETROK_MINUS ] = { 0x4e, K_NORMAL },
[ RETROK_PERIOD ] = { 0x49, K_NORMAL },
[ RETROK_SLASH ] = { 0x4a, K_NORMAL },
[ RETROK_0 ] = { 0x45, K_NORMAL },
[ RETROK_1 ] = { 0x16, K_NORMAL },
[ RETROK_2 ] = { 0x1e, K_NORMAL },
[ RETROK_3 ] = { 0x26, K_NORMAL },
[ RETROK_4 ] = { 0x25, K_NORMAL },
[ RETROK_5 ] = { 0x2e, K_NORMAL },
[ RETROK_6 ] = { 0x36, K_NORMAL },
[ RETROK_7 ] = { 0x3d, K_NORMAL },
[ RETROK_8 ] = { 0x3e, K_NORMAL },
[ RETROK_9 ] = { 0x46, K_NORMAL },
[ RETROK_SEMICOLON ] = { 0x4c, K_NORMAL },
[ RETROK_EQUALS ] = { 0x55, K_NORMAL },
[ RETROK_LEFTBRACKET ] = { 0x54, K_NORMAL },
[ RETROK_BACKSLASH ] = { 0x5d, K_NORMAL },
[ RETROK_RIGHTBRACKET ] = { 0x5b, K_NORMAL },
[ RETROK_BACKQUOTE ] = { 0x0e, K_NORMAL },
[ RETROK_a ] = { 0x1c, K_NORMAL },
[ RETROK_b ] = { 0x32, K_NORMAL },
[ RETROK_c ] = { 0x21, K_NORMAL },
[ RETROK_d ] = { 0x23, K_NORMAL },
[ RETROK_e ] = { 0x24, K_NORMAL },
[ RETROK_f ] = { 0x2b, K_NORMAL },
[ RETROK_g ] = { 0x34, K_NORMAL },
[ RETROK_h ] = { 0x33, K_NORMAL },
[ RETROK_i ] = { 0x43, K_NORMAL },
[ RETROK_j ] = { 0x3b, K_NORMAL },
[ RETROK_k ] = { 0x42, K_NORMAL },
[ RETROK_l ] = { 0x4b, K_NORMAL },
[ RETROK_m ] = { 0x3a, K_NORMAL },
[ RETROK_n ] = { 0x31, K_NORMAL },
[ RETROK_o ] = { 0x44, K_NORMAL },
[ RETROK_p ] = { 0x4d, K_NORMAL },
[ RETROK_q ] = { 0x15, K_NORMAL },
[ RETROK_r ] = { 0x2d, K_NORMAL },
[ RETROK_s ] = { 0x1b, K_NORMAL },
[ RETROK_t ] = { 0x2c, K_NORMAL },
[ RETROK_u ] = { 0x3c, K_NORMAL },
[ RETROK_v ] = { 0x2a, K_NORMAL },
[ RETROK_w ] = { 0x1d, K_NORMAL },
[ RETROK_x ] = { 0x22, K_NORMAL },
[ RETROK_y ] = { 0x35, K_NORMAL },
[ RETROK_z ] = { 0x1a, K_NORMAL },
[ RETROK_LEFTBRACE ] = { 123, K_NORMAL },
[ RETROK_BAR ] = { 124, K_NORMAL },
[ RETROK_RIGHTBRACE ] = { 125, K_NORMAL },
[ RETROK_TILDE ] = { 126, K_NORMAL },
[ RETROK_DELETE ] = { 127, K_NORMAL },
[ RETROK_KP0 ] = { 0x70, K_NORMAL },
[ RETROK_KP1 ] = { 0x69, K_NORMAL },
[ RETROK_KP2 ] = { 0x72, K_NORMAL },
[ RETROK_KP3 ] = { 0x7a, K_NORMAL },
[ RETROK_KP4 ] = { 0x6b, K_NORMAL },
[ RETROK_KP5 ] = { 0x73, K_NORMAL },
[ RETROK_KP6 ] = { 0x74, K_NORMAL },
[ RETROK_KP7 ] = { 0x6c, K_NORMAL },
[ RETROK_KP8 ] = { 0x75, K_NORMAL },
[ RETROK_KP9 ] = { 0x7d, K_NORMAL },
[ RETROK_KP_PERIOD ] = { 0x71, K_NORMAL },
[ RETROK_KP_DIVIDE ] = { 0x4a, K_SHIFT_HACK },
[ RETROK_KP_MULTIPLY ] = { 0x7c, K_NORMAL },
[ RETROK_KP_MINUS ] = { 0x7b, K_NORMAL },
[ RETROK_KP_PLUS ] = { 0x79, K_NORMAL },
[ RETROK_KP_ENTER ] = { 0x5A, K_EXTENDED },
[ RETROK_UP ] = { 0x75, K_NUMLOCK_HACK },
[ RETROK_DOWN ] = { 0x72, K_NUMLOCK_HACK },
[ RETROK_RIGHT ] = { 0x74, K_NUMLOCK_HACK },
[ RETROK_LEFT ] = { 0x6b, K_NUMLOCK_HACK },
[ RETROK_INSERT ] = { 0x70, K_NUMLOCK_HACK },
[ RETROK_HOME ] = { 0x6c, K_NUMLOCK_HACK },
[ RETROK_END ] = { 0x69, K_NUMLOCK_HACK },
[ RETROK_PAGEUP ] = { 0x7d, K_NUMLOCK_HACK },
[ RETROK_PAGEDOWN ] = { 0x7a, K_NUMLOCK_HACK },
[ RETROK_F1 ] = { 0x05, K_NORMAL },
[ RETROK_F2 ] = { 0x06, K_NORMAL },
[ RETROK_F3 ] = { 0x04, K_NORMAL },
[ RETROK_F4 ] = { 0x0c, K_NORMAL },
[ RETROK_F5 ] = { 0x03, K_NORMAL },
[ RETROK_F6 ] = { 0x0b, K_NORMAL },
[ RETROK_F7 ] = { 0x83, K_NORMAL },
[ RETROK_F8 ] = { 0x0a, K_NORMAL },
[ RETROK_F9 ] = { 0x01, K_NORMAL },
[ RETROK_F10 ] = { 0x09, K_NORMAL },
[ RETROK_F11 ] = { 0x78, K_NORMAL },
[ RETROK_F12 ] = { 0x07, K_NORMAL },
[ RETROK_RSHIFT ] = { 0x59, K_EXTENDED },
[ RETROK_LSHIFT ] = { 0x12, K_NORMAL },
[ RETROK_RCTRL ] = { 0x14, K_EXTENDED },
[ RETROK_LCTRL ] = { 0x14, K_NORMAL },
[ RETROK_RALT ] = { 0x11, K_EXTENDED },
[ RETROK_LALT ] = { 0x11, K_NORMAL },
[ RETROK_MENU ] = { 0x27, K_EXTENDED },
};

2392
Libretro/libretro.h Normal file

File diff suppressed because it is too large Load Diff

5
Libretro/link.T Normal file
View File

@ -0,0 +1,5 @@
{
global: retro_*;
local: *;
};