Skip to content

Commit

Permalink
Merge pull request #90 from meepingsnesroms/tungstenT3Support
Browse files Browse the repository at this point in the history
Input updates
  • Loading branch information
meepingsnesroms committed Jun 7, 2019
2 parents a1fd079 + 61602de commit d0ccc71
Show file tree
Hide file tree
Showing 29 changed files with 346 additions and 194 deletions.
6 changes: 6 additions & 0 deletions bugs/fixed/T3Crash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
10:32:11: Debugging starts
mincore\com\oleaut32\dispatch\ups.cpp(2125)\OLEAUT32.dll!00007FFE26F51D23: (caller: 00007FFE26F51E9A) ReturnHr(1) tid(1870) 8002801D Library not registered.
QObject::~QObject: Timers cannot be stopped from another thread
10:32:24: Debugging has finished

Just a crash from killing the program due to a buffer overflow.
30 changes: 17 additions & 13 deletions libretroBuildSystem/build/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ EMU_PATH := $(CORE_DIR)/../src
LIBRETRO_COMM_DIR := $(CORE_DIR)/libretro-common
COREDEFINES :=

# my first make function!!!
CHECK_ALL = $(strip $(foreach v,$(2),$(if $(findstring $(v),$(1)),$(v),)))

INCFLAGS := -I$(LIBRETRO_COMM_DIR)/include

ifeq ($(DEBUG), 1)
Expand All @@ -10,12 +13,13 @@ else
COREDEFINES += -DEMU_NO_SAFETY
endif

# "unix" is not specific enough, need to know the CPU arch too
this_system = $(platform)
ifeq ($(this_system), unix)
this_system = $(shell $(CC) -dumpmachine)
# "unix" or "win" is not specific enough, need to know the CPU arch too
this_system := $(platform)
ifneq (,$(filter unix win,$(this_system)))
this_system := $(shell $(CC) -dumpmachine)
endif


ifneq (,$(findstring msvc200,$(this_system)))
INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc
endif
Expand All @@ -26,12 +30,12 @@ ifneq (,$(findstring msvc20,$(this_system)))
COREDEFINES += -Dinline=_inline -DINLINE=_inline
endif

ifneq (,$(findstring windows,$(this_system)))
ifneq (,$(call CHECK_ALL,$(this_system),windows mingw))
# Windows
ifeq (,$(findstring msvc,$(this_system)))
EMU_SUPPORT_PALM_OS5 := 1
EMU_OS := windows
ifneq (,$(filter %x64 %x86_64,$(this_system)))
ifneq (,$(call CHECK_ALL,$(this_system),x86_64 x64))
EMU_ARCH := x86_64
else
EMU_ARCH := x86_32
Expand All @@ -40,24 +44,24 @@ ifneq (,$(findstring windows,$(this_system)))
# MSVC uses its own(incompatible) ASM syntax
EMU_SUPPORT_PALM_OS5 := 0
endif
else ifneq (,$(filter %armv8% %aarch64% rpi3,$(this_system)))
else ifneq (,$(call CHECK_ALL,$(this_system),armv8 aarch64))
# ARM Linux 64
EMU_SUPPORT_PALM_OS5 := 1
EMU_ARCH := armv8
EMU_OS := linux
else ifneq (,$(filter %armv% rpi2,$(this_system)))
# ARM Linux
else ifneq (,$(call CHECK_ALL,$(this_system),armv rpi2 rpi3))
# ARM Linux(rpi3 is aarch64 but its almost always used in 32bit mode)
EMU_SUPPORT_PALM_OS5 := 1
EMU_ARCH := armv7
EMU_OS := linux
else ifneq (,$(findstring armhf,$(this_system)))
# ARM Linux ARMv5
# this needs to be before "linux%" because it will trigger the linux case
# this needs to be before "linux" because it will trigger the linux case
EMU_SUPPORT_PALM_OS5 := 0
else ifneq (,$(filter osx% linux% ,$(this_system)))
else ifneq (,$(call CHECK_ALL,$(this_system),osx linux))
# x86_* Linux
EMU_SUPPORT_PALM_OS5 := 1
ifneq (,$(filter osx %x86_64% %x64%,$(this_system)))
ifneq (,$(call CHECK_ALL,$(this_system),osx x86_64 x64))
EMU_ARCH := x86_64
else
EMU_ARCH := x86_32
Expand All @@ -78,7 +82,7 @@ endif

# use all CPUs and optimize for the most likely outcome, Android is handled separately
# Apple broke OpenMP in there port of Clang so no Mac OS or iOS
ifneq (,$(filter %armv% windows% linux%,$(this_system)))
ifneq (,$(call CHECK_ALL,$(this_system),windows linux))
# none of libretros MSVC compilers work with these optimizations for multiple different reasons
# they dont have the library "VCOMP.lib"
# they are too old for the extension to exist
Expand Down
115 changes: 89 additions & 26 deletions libretroBuildSystem/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define JOYSTICK_DEADZONE 4000
#define JOYSTICK_MULTIPLIER 0.0001
#define SCREEN_HIRES (!(palmFramebufferWidth == 160 && palmFramebufferHeight == 220))
#define SCREEN_HIRES (!(palmFramebufferWidth == 160))


static retro_log_printf_t log_cb = NULL;
Expand All @@ -36,15 +36,29 @@ static retro_input_state_t input_state_cb = NULL;
static uint32_t emuFeatures;
#if defined(EMU_SUPPORT_PALM_OS5)
static bool useOs5;
static bool firstRetroRunCall;
#endif
static bool firstRetroRunCall;
static bool dontRenderGraffiti;
static bool useJoystickAsMouse;
static float touchCursorX;
static float touchCursorY;
static char contentPath[PATH_MAX_LENGTH];
static uint16_t mouseCursorOldArea[32 * 32];
static bool runningImgFile;
static uint16_t screenYEnd;


static void frontendGetCurrentTime(uint8_t* writeBack){
time_t rawTime;
struct tm* timeInfo;

time(&rawTime);
timeInfo = localtime(&rawTime);

writeBack[0] = timeInfo->tm_hour;
writeBack[1] = timeInfo->tm_min;
writeBack[2] = timeInfo->tm_sec;
}

static void renderMouseCursor(int16_t screenX, int16_t screenY){
if(SCREEN_HIRES){
Expand Down Expand Up @@ -151,6 +165,10 @@ static void check_variables(bool booting){
if(environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
useJoystickAsMouse = !strcmp(var.value, "enabled");

var.key = "palm_emu_disable_graffiti";
if(environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
dontRenderGraffiti = !strcmp(var.value, "enabled");

#if defined(EMU_SUPPORT_PALM_OS5)
var.key = "palm_emu_use_os5";
if(environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
Expand Down Expand Up @@ -215,22 +233,28 @@ void retro_set_environment(retro_environment_t cb){
{ "palm_emu_feature_hle_apis", "HLE API Implementations; disabled|enabled" },
{ "palm_emu_feature_durable", "Ignore Invalid Behavior; disabled|enabled" },
{ "palm_emu_use_joystick_as_mouse", "Use Left Joystick As Mouse; disabled|enabled" },
{ "palm_emu_disable_graffiti", "Disable Graffiti Area; disabled|enabled" },
#if defined(EMU_SUPPORT_PALM_OS5)
{ "palm_emu_use_os5", "Boot Apps In OS 5; disabled|enabled" },
{ "palm_emu_use_os5", "Boot Apps In OS 5(DEV ONLY); disabled|enabled" },
#endif
{ 0 }
};
struct retro_input_descriptor input_desc[] = {
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Touchscreen Mouse X" },
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Touchscreen Mouse Y" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "Touchscreen Mouse Click" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Touchscreen Mouse Click" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Dpad Up" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Dpad Down" },
#if defined(EMU_SUPPORT_PALM_OS5)
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Dpad Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Dpad Right" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Dpad Center" },
#endif
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Power" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Date Book" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Address Book" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "To Do List" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Note Pad" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Date Book" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Address Book" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "To Do List" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Note Pad" },
{ 0 }
};
bool no_rom = true;
Expand Down Expand Up @@ -283,22 +307,39 @@ void retro_reset(void){
void retro_run(void){
input_poll_cb();

#if defined(EMU_SUPPORT_PALM_OS5)
//some RetroArch functions can only be called from this function so call those if needed
if(unlikely(firstRetroRunCall)){
struct retro_game_geometry geometry;
#if defined(EMU_SUPPORT_PALM_OS5)
if(useOs5){
struct retro_game_geometry geometry;

geometry.base_width = 320;
geometry.base_height = 480;
geometry.max_width = 320;
geometry.max_height = 480;
geometry.aspect_ratio = 320.0 / 480.0;
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &geometry);
if(dontRenderGraffiti){
geometry.base_width = 320;
geometry.base_height = 320;
geometry.max_width = 320;
geometry.max_height = 480;
}
else{
geometry.base_width = 320;
geometry.base_height = 480;
}
}
else{
#endif
if(dontRenderGraffiti){
geometry.base_width = 160;
geometry.base_height = 160;
}
else{
geometry.base_width = 160;
geometry.base_height = 220;
}
#if defined(EMU_SUPPORT_PALM_OS5)
}
#endif
geometry.aspect_ratio = (float)geometry.base_width / (float)geometry.base_height;
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &geometry);
firstRetroRunCall = false;
}
#endif

//touchscreen
if(useJoystickAsMouse){
Expand All @@ -323,24 +364,31 @@ void retro_run(void){

palmInput.touchscreenX = touchCursorX / (palmFramebufferWidth - 1);
palmInput.touchscreenY = touchCursorY / (palmFramebufferHeight - 1);
palmInput.touchscreenTouched = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2);
palmInput.touchscreenTouched = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R);
}
else{
//use RetroArch internal pointer
palmInput.touchscreenX = ((float)input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X) / 0x7FFF + 1.0) / 2.0;
palmInput.touchscreenY = ((float)input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y) / 0x7FFF + 1.0) / 2.0;
palmInput.touchscreenY = ((float)input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y) / 0x7FFF + 1.0) / 2.0 * ((float)screenYEnd / palmFramebufferHeight);
palmInput.touchscreenTouched = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
}

//dpad
palmInput.buttonUp = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
palmInput.buttonDown = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
#if defined(EMU_SUPPORT_PALM_OS5)
if(useOs5){
palmInput.buttonLeft = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT);
palmInput.buttonRight = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT);
palmInput.buttonCenter = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT);
}
#endif

//app buttons
palmInput.buttonCalendar = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
palmInput.buttonAddress = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
palmInput.buttonTodo = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);
palmInput.buttonNotes = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
palmInput.buttonCalendar = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);
palmInput.buttonAddress = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
palmInput.buttonTodo = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
palmInput.buttonNotes = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);

//special buttons
palmInput.buttonPower = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
Expand All @@ -352,7 +400,7 @@ void retro_run(void){
if(useJoystickAsMouse)
renderMouseCursor(touchCursorX, touchCursorY);

video_cb(palmFramebuffer, palmFramebufferWidth, palmFramebufferHeight, palmFramebufferWidth * sizeof(uint16_t));
video_cb(palmFramebuffer, palmFramebufferWidth, screenYEnd, palmFramebufferWidth * sizeof(uint16_t));
audio_cb(palmAudio, AUDIO_SAMPLES_PER_FRAME);
if(led_cb)
led_cb(0, palmMisc.powerButtonLed);
Expand Down Expand Up @@ -562,13 +610,28 @@ bool retro_load_game(const struct retro_game_info *info){
return false;
}

//set the time callback
palmGetRtcFromHost = frontendGetCurrentTime;

//set mouse position
touchCursorX = palmFramebufferWidth / 2;
touchCursorY = palmFramebufferHeight / 2;

//make touches land on the correct spot and screen render the correct size when the graffiti area is off
if(dontRenderGraffiti){
#if defined(EMU_SUPPORT_PALM_OS5)
firstRetroRunCall = true;
if(useOs5)
screenYEnd = 320;
else
#endif
screenYEnd = 160;
}
else{
screenYEnd = palmFramebufferHeight;
}

//used to resize things properly
firstRetroRunCall = true;

return true;
}
Expand Down
16 changes: 8 additions & 8 deletions libretroBuildSystem/overlay/palm.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ overlay0_desc2 = "up,0.504283,0.802938,radial,0.06852,0.04479"
overlay0_desc2_overlay = "X1_wswan.png"
overlay0_desc3 = "down,0.504283,0.964221,radial,0.06852,0.04479"
overlay0_desc3_overlay = "X3_wswan.png"
overlay0_desc4 = "a,0.0821626,0.960563,radial,0.07407,0.04167"
overlay0_desc4_overlay = "A.png"
overlay0_desc5 = "b,0.234211,0.960563,radial,0.07407,0.04167"
overlay0_desc5_overlay = "B.png"
overlay0_desc6 = "x,0.918421,0.960563,radial,0.07407,0.04167"
overlay0_desc6_overlay = "X.png"
overlay0_desc7 = "y,0.770469,0.960563,radial,0.07407,0.04167"
overlay0_desc7_overlay = "Y.png"
overlay0_desc4 = "y,0.0821626,0.960563,radial,0.07407,0.04167"
overlay0_desc4_overlay = "Y.png"
overlay0_desc5 = "x,0.234211,0.960563,radial,0.07407,0.04167"
overlay0_desc5_overlay = "X.png"
overlay0_desc6 = "a,0.918421,0.960563,radial,0.07407,0.04167"
overlay0_desc6_overlay = "A.png"
overlay0_desc7 = "b,0.770469,0.960563,radial,0.07407,0.04167"
overlay0_desc7_overlay = "B.png"
overlay0_desc8 = "start,0.860359,0.810741,rect,0.07037,0.03958"
overlay0_desc8_overlay = "start.png"
overlay0_desc9 = "menu_toggle,0.0552632,0.801573,radial,0.046296,0.02604"
Expand Down
28 changes: 18 additions & 10 deletions qtBuildSystem/Mu/emuwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string>
#include <stdint.h>
#include <string.h>
#include <time.h>

#include "emuwrapper.h"
#include "../../src/emulator.h"
Expand Down Expand Up @@ -58,6 +59,18 @@ void frontendHandleDebugPrint(){
}
}

static void frontendGetCurrentTime(uint8_t* writeBack){
time_t rawTime;
struct tm* timeInfo;

time(&rawTime);
timeInfo = localtime(&rawTime);

writeBack[0] = timeInfo->tm_hour;
writeBack[1] = timeInfo->tm_min;
writeBack[2] = timeInfo->tm_sec;
}


EmuWrapper::EmuWrapper(){
if(alreadyExists == true)
Expand Down Expand Up @@ -162,6 +175,7 @@ uint32_t EmuWrapper::init(const QString& assetPath, bool useOs5, uint32_t featur
if(error == EMU_ERROR_NONE){
QTime now = QTime::currentTime();

palmGetRtcFromHost = frontendGetCurrentTime;
emulatorSetRtc(QDate::currentDate().day(), now.hour(), now.minute(), now.second());

if(ramFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
Expand Down Expand Up @@ -257,7 +271,6 @@ uint32_t EmuWrapper::bootFromFile(const QString& mainPath){
QFile ramFile(mainPath + "." + emuOsName + ".ram");
QFile sdCardFile(mainPath + "." + emuOsName + ".sd.img");
QString suffix = QFileInfo(mainPath).suffix().toLower();
uint32_t appId;
bool hasSaveRam;
bool hasSaveSdCard;

Expand Down Expand Up @@ -314,20 +327,15 @@ uint32_t EmuWrapper::bootFromFile(const QString& mainPath){
if(error != EMU_ERROR_NONE)
goto errorOccurred;
}
appId = launcherGetAppId((uint8_t*)fileBuffer.data(), fileBuffer.size());
error = launcherExecute(launcherGetAppId((uint8_t*)fileBuffer.data(), fileBuffer.size()));
if(error != EMU_ERROR_NONE)
goto errorOccurred;
}
}

//img files just boot to the homescreen
if(suffix != "img"){
error = launcherExecute(appId);
if(error != EMU_ERROR_NONE)
goto errorOccurred;
}

//everything worked, set output save files
emuRamFilePath = mainPath + "." + emuOsName + ".ram";
emuSdCardFilePath = mainPath + "." + emuOsName + ".sd.img";
emuSdCardFilePath = suffix != "img" ? mainPath + "." + emuOsName + ".sd.img" : "";//dont duplicate booted SD card images
emuSaveStatePath = mainPath + "." + emuOsName + ".states";

//make the place to store the saves
Expand Down
Loading

0 comments on commit d0ccc71

Please sign in to comment.