From 9f3f64e3868215416dbf86e674ade7bb8de5ff40 Mon Sep 17 00:00:00 2001 From: acmeplus Date: Tue, 30 May 2023 20:11:35 +0000 Subject: [PATCH] First RG35xx version --- src/simplemenu-beta/Makefile.rg35xx | 67 ++++ src/simplemenu-beta/src/logic/control.c | 6 +- .../src/logic/control_rg35xx.c | 371 ++++++++++++++++++ src/simplemenu-beta/src/logic/graphics.c | 25 +- src/simplemenu-beta/src/logic/logic.c | 14 +- src/simplemenu-beta/src/logic/screen.c | 4 +- src/simplemenu-beta/src/logic/simplemenu.c | 5 +- .../src/logic/system_logic_rg35xx.c | 178 +++++++++ 8 files changed, 648 insertions(+), 22 deletions(-) create mode 100644 src/simplemenu-beta/Makefile.rg35xx create mode 100644 src/simplemenu-beta/src/logic/control_rg35xx.c create mode 100644 src/simplemenu-beta/src/logic/system_logic_rg35xx.c diff --git a/src/simplemenu-beta/Makefile.rg35xx b/src/simplemenu-beta/Makefile.rg35xx new file mode 100644 index 00000000..be38a2ef --- /dev/null +++ b/src/simplemenu-beta/Makefile.rg35xx @@ -0,0 +1,67 @@ +# Software Name +TARGET = simplemenu + +CROSS_COMPILE = /opt/cdata/rg35xx/batocera.linux/buildroot/output/host/bin/arm-buildroot-linux-gnueabihf- + +#Flags +MM_NOQUIT = 1 # Controls if we show Quit option in Session menu on Miyoo Mini. In that device there is no optional startup script. The closest is /mnt/SDCARD/.tmp_update/updater but we can't count on it because it is used by most distributions, so we control the quit menu manually by mean of this flag. +NOLOADING = 1 # Controls whether the 'LOADING...' message is displayed at the bottom right of the screen during some slow processes. + +# Compiler +CC = $(CROSS_COMPILE)gcc +LINKER = $(CROSS_COMPILE)gcc +CFLAGS = -DTARGET_RG35XX -O3 -DUSE_GZIP -Ofast -fdata-sections -ffunction-sections -fPIC -flto -Wall -Wextra -std=gnu99 +ifeq ($(MM_NOQUIT), 1) + CFLAGS += -DMM_NOQUIT +endif +ifeq ($(NOLOADING), 1) + CFLAGS += -DNOLOADING +endif + +LIBS += -lSDL -lasound -lSDL_image -lSDL_ttf -L../../../libini/ -lini -lz -lpthread -lm + +# You can use Ofast too but it can be more prone to bugs, careful. +CFLAGS += -g3 -I. +LDFLAGS = -Wl,--start-group $(LIBS) -Wl,--end-group -Wl,--as-needed -Wl,--gc-sections -flto + +DEBUG=NO + +#ifeq ($(DEBUG), NO) +# CFLAGS += -DDEBUG -g3 +#else +# LDFLAGS += -s -lm +#endif + +SRCDIR = src/logic +OBJDIR = src/obj +BINDIR = output +SOURCES := $(wildcard $(SRCDIR)/*.c) +SOURCES := $(filter-out src/logic/control_rfw.c, $(SOURCES)) +SOURCES := $(filter-out src/logic/control_bittboy.c, $(SOURCES)) +SOURCES := $(filter-out src/logic/control_od.c, $(SOURCES)) +SOURCES := $(filter-out src/logic/system_logic_rfw.c, $(SOURCES)) +SOURCES := $(filter-out src/logic/system_logic_bittboy.c, $(SOURCES)) +SOURCES := $(filter-out src/logic/system_logic_od.c, $(SOURCES)) +SOURCES := $(filter-out src/logic/system_logic_mmiyoo.c, $(SOURCES)) + +OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) + +rm = rm -f + +$(BINDIR)/$(TARGET): $(OBJECTS) + @$(LINKER) $(OBJECTS) $(LDFLAGS) -o $@ + @echo "Linking complete!" + +$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c + @$(CC) $(CFLAGS) -c $< -o $@ + @echo "Compiled "$<" successfully!" + +.PHONY: clean +clean: + @$(rm) $(OBJECTS) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/src/simplemenu-beta/src/logic/control.c b/src/simplemenu-beta/src/logic/control.c index 8b9842dc..c69ad23c 100644 --- a/src/simplemenu-beta/src/logic/control.c +++ b/src/simplemenu-beta/src/logic/control.c @@ -976,12 +976,12 @@ void performSystemSettingsChoosingAction() { } } else if (chosenSetting==BRIGHTNESS_OPTION) { if (keys[BTN_LEFT]) { - if (brightnessValue>1) { - brightnessValue-=1; + if (brightnessValue>50) { + brightnessValue-=50; } } else { if (brightnessValue +#include "../headers/config.h" +#include "../headers/control.h" +#include "../headers/definitions.h" +#include "../headers/globals.h" +#include "../headers/graphics.h" +#include "../headers/logic.h" +#include "../headers/screen.h" +#include "../headers/utils.h" +#include "../headers/system_logic.h" + +int performAction(struct Node *node) { + struct Rom *rom; + if (node!=NULL) { + rom = node->data; + } else { + rom = NULL; + } + if((!alternateControls&¤tState==SELECTING_SECTION)||(alternateControls&&(currentState==CHOOSING_GROUP||currentState==SELECTING_SECTION))) { + if (keys[BTN_A]) { + if (CURRENT_SECTION.backgroundSurface==NULL) { + logMessage("INFO","performAction","Loading system background"); + CURRENT_SECTION.backgroundSurface = IMG_Load(CURRENT_SECTION.background); + logMessage("INFO","performAction","Loading system picture"); + CURRENT_SECTION.systemPictureSurface = IMG_Load(CURRENT_SECTION.systemPicture); + } + logMessage("INFO","performAction","Loading game list"); + if (currentSectionNumber!=favoritesSectionNumber) { + loadGameList(0); + } else { + loadFavoritesSectionGameList(); + } + if(CURRENT_SECTION.gameCount>0) { + scrollToGame(CURRENT_SECTION.realCurrentGameNumber); + } + pushEvent(); + currentState=BROWSING_GAME_LIST; + return 1; + } + if (keys[BTN_START]) { + chosenSetting=0; + previousState=currentState; + currentState=SETTINGS_SCREEN; + chosenSetting=SHUTDOWN_OPTION; + themeChanged = activeTheme; + selectedShutDownOption=0; + currRawtime = time(NULL); + currTime = localtime(&currRawtime); + lastMin=currTime->tm_min; + lastChargeLevel = getBatteryLevel(); + return 1; + } + } + if (rom!=NULL&&keys[BTN_R2]) { + hideFullScreenModeMenu(); + if(currentSectionNumber!=favoritesSectionNumber) { + logMessage("INFO","performAction","Not Favs, loading game list"); + loadGameList(1); + return(1); + } else { + loadFavoritesSectionGameList(); + return(1); + } + } + if(itsStoppedBecauseOfAnError&&!keys[BTN_A]) { + return(0); + } + if(keys[BTN_B]&&!(currentState==SELECTING_SECTION)) { + hotKeyPressed=1; + if (currentState==BROWSING_GAME_LIST) { + if (rom!=NULL&&keys[BTN_A]) { + launchEmulator(rom); + aKeyComboWasPressed=1; + return 1; + } + if (rom!=NULL&&keys[BTN_X]) { + if (!isPicModeMenuHidden) { + resetPicModeHideMenuTimer(); + } + callDeleteGame(rom); + aKeyComboWasPressed=1; + return 1; + } + + if (rom!=NULL&&keys[BTN_SELECT]) { + int flag = 0; + const int GAME_FPS=60; + const int FRAME_DURATION_IN_MILLISECONDS = 1000/GAME_FPS; + Uint32 start_time; + for(int i=0;i<25;i++) { + selectRandomGame(); + if (fullscreenMode==0) { + fullscreenMode=1; + flag = 1; + } + updateScreen(CURRENT_SECTION.currentGameNode); + refreshScreen(); + int timeSpent = SDL_GetTicks()-start_time; + if(timeSpent < FRAME_DURATION_IN_MILLISECONDS) { + //Wait the remaining time until one frame completes + SDL_Delay(FRAME_DURATION_IN_MILLISECONDS-timeSpent); + } + } + saveFavorites(); + if (flag == 1) { + fullscreenMode=0; + } + launchGame(CURRENT_SECTION.currentGameNode->data); + } + if (rom!=NULL&&keys[BTN_RIGHT]) { + hotKeyPressed=1; + CURRENT_SECTION.alphabeticalPaging=1; + advancePage(rom); + if(fullscreenMode) { + resetPicModeHideMenuTimer(); + } + aKeyComboWasPressed=1; + return 0; + } + if (rom!=NULL&&keys[BTN_LEFT]) { + hotKeyPressed=1; + CURRENT_SECTION.alphabeticalPaging=1; + rewindPage(rom); + if(fullscreenMode) { + resetPicModeHideMenuTimer(); + } + aKeyComboWasPressed=1; + return 0; + } + } + if (currentState == BROWSING_GAME_LIST) { + if(keys[BTN_DOWN]) { + hotKeyPressed=0; + int advanced = advanceSection(); + if(advanced) { + if (CURRENT_SECTION.backgroundSurface == NULL) { + logMessage("INFO","performAction","Loading system background"); + CURRENT_SECTION.backgroundSurface = IMG_Load(CURRENT_SECTION.background); + resizeSectionBackground(&CURRENT_SECTION); + CURRENT_SECTION.systemPictureSurface = IMG_Load(CURRENT_SECTION.systemPicture); + } + logMessage("INFO","performAction","Advanced, loading game list"); + if(currentSectionNumber==favoritesSectionNumber) { + loadFavoritesSectionGameList(); + } else { + loadGameList(0); + } + } + if(CURRENT_SECTION.gameCount>0) { + scrollToGame(CURRENT_SECTION.realCurrentGameNumber); + } + aKeyComboWasPressed=1; + return 0; + } + if(keys[BTN_UP]) { + hotKeyPressed=0; + int rewinded = rewindSection(); + if(rewinded) { + if (CURRENT_SECTION.backgroundSurface == NULL) { + logMessage("INFO","performAction","Loading system background"); + CURRENT_SECTION.backgroundSurface = IMG_Load(CURRENT_SECTION.background); + logMessage("INFO","performAction","Loading system picture"); + CURRENT_SECTION.systemPictureSurface = IMG_Load(CURRENT_SECTION.systemPicture); + } + logMessage("INFO","performAction","Rewinded, loading game list"); + if(currentSectionNumber==favoritesSectionNumber) { + loadFavoritesSectionGameList(); + } else { + loadGameList(0); + } + } + if(CURRENT_SECTION.gameCount>0) { + scrollToGame(CURRENT_SECTION.realCurrentGameNumber); + } + aKeyComboWasPressed=1; + return 0; + } + } + } + if (keys[BTN_SELECT]&¤tSectionNumber!=favoritesSectionNumber&&!(currentState==SELECTING_SECTION)) { + currentState=SELECTING_EMULATOR; + chosenChoosingOption=0; + launchAtBoot=isLaunchAtBoot(CURRENT_SECTION.currentGameNode->data->name); + drawTransparentRectangleToScreen(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, (int[]) {0,0,0},180); + loadRomPreferences(CURRENT_SECTION.currentGameNode->data); + return 0; + } + if(!alternateControls) { + if((currentState==SELECTING_SECTION&&(keys[BTN_UP]))) { + if (menuSectionCounter>1) { + if (currentSectionNumber!=favoritesSectionNumber) { + returnTo=currentSectionNumber; + } + currentState=SELECTING_SECTION; + hotKeyPressed=0; + rewindSection(); + } + } + } else { + if(keys[BTN_L1]) { + if (menuSectionCounter>1) { + if (currentSectionNumber!=favoritesSectionNumber) { + returnTo=currentSectionNumber; + } + currentState=SELECTING_SECTION; + hotKeyPressed=0; + rewindSection(); + } + } + } + + if(!alternateControls) { + if((currentState==SELECTING_SECTION&&(keys[BTN_DOWN]))) { + if (currentSectionNumber!=favoritesSectionNumber) { + returnTo=currentSectionNumber; + } + currentState=SELECTING_SECTION; + hotKeyPressed=0; + advanceSection(); +// } + return 0; + } + } else { + if(keys[BTN_R1]) { + if (currentSectionNumber!=favoritesSectionNumber) { + returnTo=currentSectionNumber; + } +// if (currentSectionNumber!=favoritesSectionNumber) { + currentState=SELECTING_SECTION; + hotKeyPressed=0; + advanceSection(); +// } + return 0; + } + } + + if (currentState!=SELECTING_EMULATOR&&!hotKeyPressed) { + if (keys[BTN_Y]) { + if(!isFavoritesSectionSelected()) { + // loadFavoritesSectionGameList(); + if(FAVORITES_SECTION.gameCount>0) { + showOrHideFavorites(); + } + } else { + currentSectionNumber=returnTo; + if (CURRENT_SECTION.gameCount==0) { + CURRENT_SECTION.gameCount=theSectionHasGames(&CURRENT_SECTION); + } + currentState=SELECTING_SECTION; + if (CURRENT_SECTION.systemLogoSurface == NULL) { + CURRENT_SECTION.systemLogoSurface = IMG_Load(CURRENT_SECTION.systemLogo); + } + } + return 0; + } + } + + if (currentState!=SELECTING_EMULATOR&&!hotKeyPressed&&!(currentState==SELECTING_SECTION)) { + + if (rom!=NULL&&keys[BTN_X]) { + if(!isPicModeMenuHidden) { + resetPicModeHideMenuTimer(); + } + if (currentSectionNumber!=favoritesSectionNumber) { + markAsFavorite(rom); + } else { + removeFavorite(); + if(favoritesSize==0) { + currentState = SELECTING_SECTION; + currentSectionNumber=returnTo; + if(CURRENT_SECTION.gameCount==0) { + int advanced = advanceSection(); + if (!advanced) { + currentSectionNumber=0; + } + } + } + } + return 0; + } + if (keys[BTN_START]) { + chosenSetting=SHUTDOWN_OPTION; + selectedShutDownOption=0; + previousState=currentState; + currentState=SETTINGS_SCREEN; + themeChanged=activeTheme; + lastChargeLevel = getBatteryLevel(); + return 0; + } + if (rom!=NULL&&keys[BTN_A]) { + if(itsStoppedBecauseOfAnError) { + if(thereIsACriticalError) { + #ifndef TARGET_PC + running=0; + #else + freeResources(); + saveLastState(); + saveFavorites(); + exit(0); + #endif + } + itsStoppedBecauseOfAnError=0; + return 0; + } + if (countGamesInPage()>0) { + saveFavorites(); + launchGame(rom); + } + return 0; + } + if(!alternateControls) { + if (keys[BTN_R1]) { + int number = CURRENT_GAME_NUMBER; + if (fullscreenMode) { + fullscreenMode=0; + ITEMS_PER_PAGE=MENU_ITEMS_PER_PAGE; + } else { + fullscreenMode=1; + ITEMS_PER_PAGE=FULLSCREEN_ITEMS_PER_PAGE; + } + if (CURRENT_SECTION.gameCount>0) { + scrollToGame(number); + } + } + } else { + if (keys[BTN_L2]) { + int number = CURRENT_GAME_NUMBER; + if (fullscreenMode) { + fullscreenMode=0; + ITEMS_PER_PAGE=MENU_ITEMS_PER_PAGE; + } else { + fullscreenMode=1; + ITEMS_PER_PAGE=FULLSCREEN_ITEMS_PER_PAGE; + } + if (CURRENT_SECTION.gameCount>0) { + scrollToGame(number); + } + } + } + if (rom!=NULL&&keys[BTN_DOWN]) { + if(fullscreenMode) { + resetPicModeHideMenuTimer(); + } + scrollDown(); + return 1; + } + if(rom!=NULL&&keys[BTN_UP]) { + if(fullscreenMode) { + resetPicModeHideMenuTimer(); + } + scrollUp(); + return 1; + } + if(rom!=NULL&&keys[BTN_RIGHT]) { + if(fullscreenMode) { + resetPicModeHideMenuTimer(); + } + advancePage(rom); + return 1; + } + if(rom!=NULL&&keys[BTN_LEFT]) { + if(fullscreenMode) { + resetPicModeHideMenuTimer(); + } + rewindPage(rom); + return 1; + } + } + return 0; +} diff --git a/src/simplemenu-beta/src/logic/graphics.c b/src/simplemenu-beta/src/logic/graphics.c index d8d44ae6..3c57f5b0 100644 --- a/src/simplemenu-beta/src/logic/graphics.c +++ b/src/simplemenu-beta/src/logic/graphics.c @@ -293,7 +293,7 @@ void drawTransparentRectangleToScreen(int w, int h, int x, int y, int rgbColor[] rectangleDest.h = h; rectangleDest.x = x; rectangleDest.y = y; - transparentrectangle = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 16, 0, 0, 0, 0); + transparentrectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 16, 0, 0, 0, 0); SDL_FillRect(transparentrectangle, &rectangleOrig, SDL_MapRGB(transparentrectangle->format, rgbColor[0], rgbColor[1], rgbColor[2])); SDL_SetAlpha(transparentrectangle, SDL_SRCALPHA, opacity); SDL_BlitSurface(transparentrectangle, &rectangleOrig, screen, &rectangleDest); @@ -472,8 +472,9 @@ int displayCenteredImageOnScreen(char *fileName, char *fallBackText, int scaleTo void initializeDisplay(int w, int h) { int depth=16; -#if defined(TARGET_PC) || defined(MIYOOMINI) - Uint32 pcflags = SDL_HWSURFACE|SDL_NOFRAME; +#if defined(TARGET_PC) || defined(MIYOOMINI) || defined(TARGET_RG35XX) + Uint32 pcflags = SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN;//SDL_NOFRAME; + //Uint32 pcflags = SDL_HWSURFACE | SDL_TRIPLEBUF | SDL_NOFRAME; #else Uint32 flags = SDL_SWSURFACE|SDL_NOFRAME; #endif @@ -522,7 +523,7 @@ void initializeDisplay(int w, int h) { fprintf(fp,"0"); fclose(fp); #endif -#if defined(TARGET_PC) || defined(MIYOOMINI) +#if defined(TARGET_PC) || defined(MIYOOMINI) || defined(TARGET_RG35XX) SCREEN_HEIGHT = h; SCREEN_WIDTH = w; char msg[1000]; @@ -530,14 +531,14 @@ void initializeDisplay(int w, int h) { logMessage("INFO", "initializeDisplay", msg); SCREEN_RATIO = (double)SCREEN_WIDTH/SCREEN_HEIGHT; screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, depth, pcflags); - char tempString[1000]; - snprintf(tempString, sizeof(tempString), "%s/.simplemenu/resources/loading.png", getenv("HOME")); - SDL_Surface* image; - image = IMG_Load(tempString); - SDL_BlitSurface(image, NULL, screen, NULL); - SDL_Flip(screen); - SDL_FreeSurface(image); - image = NULL; + // char tempString[1000]; +// snprintf(tempString, sizeof(tempString), "%s/.simplemenu/resources/loading.png", getenv("HOME")); +// SDL_Surface* image; +// image = IMG_Load(tempString); +// SDL_BlitSurface(image, NULL, screen, NULL); +// SDL_Flip(screen); +// SDL_FreeSurface(image); +// image = NULL; #else char res[20]; sprintf(res, "resolution: %dx%d", w, h); diff --git a/src/simplemenu-beta/src/logic/logic.c b/src/simplemenu-beta/src/logic/logic.c index 1c56ee9e..ed07c038 100644 --- a/src/simplemenu-beta/src/logic/logic.c +++ b/src/simplemenu-beta/src/logic/logic.c @@ -9,7 +9,9 @@ #include #include #include +#ifndef TARGET_RG35XX #include "opk.h" +#endif #include #if defined(TARGET_NPG) || defined(TARGET_OD) || defined TARGET_OD_BETA @@ -88,7 +90,7 @@ char* getRomRealName(char *romName) { } int getOPK(char *package_path, struct OPKDesktopFile *desktopFiles) { -#ifndef TARGET_BITTBOY +#if !defined(TARGET_BITTBOY) && !defined(TARGET_RG35XX) struct OPK *opk = opk_open(package_path); if (opk == NULL) { return 0; @@ -99,7 +101,7 @@ int getOPK(char *package_path, struct OPKDesktopFile *desktopFiles) { char *terminal; int i = 0; -#ifndef TARGET_BITTBOY +#if !defined(TARGET_BITTBOY) && !defined(TARGET_RG35XX) while (1) { const char *metadata_name; if (opk_open_metadata(opk, &metadata_name) <= 0) { @@ -297,10 +299,12 @@ int checkIfEmulatorExists(char *path, char *executable) { } void resetFrameBuffer1() { +#ifndef TARGET_RG35XX int ret = system("./scripts/reset_fb"); if (ret == -1) { generateError("FATAL ERROR", 1); } +#endif } void executeCommand(char *emulatorFolder, char *executable, char *fileToBeExecutedWithFullPath, int consoleApp, int frequency) { @@ -358,11 +362,13 @@ void executeCommand(char *emulatorFolder, char *executable, char *fileToBeExecut SDL_putenv("SDL_VIDEO_KMSDRM_SCALING_MODE"); //3: not set } #endif +#ifndef TARGET_RG35XX fp = fopen("/sys/class/graphics/fb0/device/allow_downscaling", "w"); if (fp != NULL) { fprintf(fp, "%d", 1); fclose(fp); } +#endif logMessage("INFO", "executeCommand", emulatorFolder); logMessage("INFO", "executeCommand", exec); @@ -396,10 +402,10 @@ void executeCommand(char *emulatorFolder, char *executable, char *fileToBeExecut #endif if(consoleApp) { - execlp("./invoker.dge", "invoker.dge", emulatorFolder, exec, + execlp("invoker.dge", "invoker.dge", emulatorFolder, exec, fileToBeExecutedWithFullPath1, NULL); } else { - execlp("./invoker.dge", "invoker.dge", emulatorFolder, exec, + execlp("invoker.dge", "invoker.dge", emulatorFolder, exec, fileToBeExecutedWithFullPath, NULL); } diff --git a/src/simplemenu-beta/src/logic/screen.c b/src/simplemenu-beta/src/logic/screen.c index 9ba973e0..863c111e 100644 --- a/src/simplemenu-beta/src/logic/screen.c +++ b/src/simplemenu-beta/src/logic/screen.c @@ -387,7 +387,7 @@ void drawTextOnHeader() { void initializeSettingsFonts() { logMessage("INFO","initializeSettingsFonts","Initializing Settings Fonts"); - char *akashi = "resources/akashi.ttf"; + char *akashi = ".simplemenu/resources/akashi.ttf"; settingsfont = TTF_OpenFont(akashi, calculateProportionalSizeOrDistance1(14)); settingsHeaderFont = TTF_OpenFont(akashi, calculateProportionalSizeOrDistance1(27)); settingsStatusFont = TTF_OpenFont(akashi, calculateProportionalSizeOrDistance1(14)); @@ -397,7 +397,7 @@ void initializeSettingsFonts() { void initializeFonts() { TTF_Init(); - char *akashi = "resources/akashi.ttf"; + char *akashi = ".simplemenu/resources/akashi.ttf"; font = TTF_OpenFont(menuFont, fontSize); outlineFont = TTF_OpenFont(menuFont, fontSize); diff --git a/src/simplemenu-beta/src/logic/simplemenu.c b/src/simplemenu-beta/src/logic/simplemenu.c index ecfa29d1..715b136c 100644 --- a/src/simplemenu-beta/src/logic/simplemenu.c +++ b/src/simplemenu-beta/src/logic/simplemenu.c @@ -40,10 +40,12 @@ void initializeGlobals() { } void resetFrameBuffer () { +#ifndef TARGET_RG35XX int ret = system("./scripts/reset_fb"); if (ret==-1) { generateError("FATAL ERROR", 1); } +#endif logMessage("INFO","resetFrameBuffer","Reset Framebuffer"); } @@ -150,6 +152,7 @@ void processEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { if(event.type==getKeyDown()){ + printf("EVENT KEY: %d\n",event.key.keysym.sym); if (!isSuspended) { switch (currentState) { case BROWSING_GAME_LIST: @@ -279,7 +282,7 @@ void processEvents() { logMessage("INFO","main","Setup 1"); #ifdef TARGET_PC initialSetup(atoi(argv[1]), atoi(argv[2])); -#elif defined MIYOOMINI +#elif defined MIYOOMINI || defined TARGET_RG35XX initialSetup(640,480); #else initialSetup(320,240); diff --git a/src/simplemenu-beta/src/logic/system_logic_rg35xx.c b/src/simplemenu-beta/src/logic/system_logic_rg35xx.c new file mode 100644 index 00000000..51052528 --- /dev/null +++ b/src/simplemenu-beta/src/logic/system_logic_rg35xx.c @@ -0,0 +1,178 @@ +#include +#include +#include +#include +#include +#include +#include +#include "../headers/logic.h" +#include "../headers/system_logic.h" +#include "../headers/globals.h" +#include "../headers/utils.h" + +#if defined TARGET_OD_BETA +#define SYSFS_CPUFREQ_DIR "/sys/devices/system/cpu/cpu0/cpufreq" +#define SYSFS_CPUFREQ_LIST SYSFS_CPUFREQ_DIR "/scaling_available_frequencies" +#define SYSFS_CPUFREQ_SET SYSFS_CPUFREQ_DIR "/scaling_setspeed" +#define SYSFS_CPUFREQ_CUR SYSFS_CPUFREQ_DIR "/scaling_cur_freq" +#endif + +volatile uint32_t *memregs; +int32_t memdev = 0; +int oldCPU; + +void to_string(char str[], int num) +{ + int i, rem, len = 0, n; + + n = num; + while (n != 0) + { + len++; + n /= 10; + } + for (i = 0; i < len; i++) + { + rem = num % 10; + num = num / 10; + str[len - (i + 1)] = rem + '0'; + } + str[len] = '\0'; +} + +void setCPU(uint32_t mhz) +{ + currentCPU = mhz; + #if defined TARGET_OD_BETA + char strMhz[10]; + int fd = open(SYSFS_CPUFREQ_SET, O_RDWR); + to_string(strMhz, (mhz * 1000)); + ssize_t ret = write(fd, strMhz, strlen(strMhz)); + if (ret==-1) { + logMessage("ERROR", "setCPU", "Error writting to file"); + } + close(fd); + char temp[300]; + snprintf(temp,sizeof(temp),"CPU speed set: %d",currentCPU); + logMessage("INFO","setCPU",temp); + #endif +} + +void turnScreenOnOrOff(int state) { + const char *path = "/sys/class/graphics/fb0/blank"; + const char *blank = state ? "0" : "1"; + int fd = open(path, O_RDWR); + int ret = write(fd, blank, strlen(blank)); + if (ret==-1) { + generateError("FATAL ERROR", 1); + } + close(fd); +} + +void clearTimer() { + if (timeoutTimer != NULL) { + SDL_RemoveTimer(timeoutTimer); + } + timeoutTimer = NULL; +} + +uint32_t suspend() { + if(timeoutValue!=0&&hdmiEnabled==0) { + clearTimer(); + oldCPU=currentCPU; + turnScreenOnOrOff(0); + isSuspended=1; + } + return 0; +}; + +void resetScreenOffTimer() { +#ifndef TARGET_PC + if(isSuspended) { + turnScreenOnOrOff(1); + currentCPU=oldCPU; + isSuspended=0; + } + clearTimer(); + timeoutTimer=SDL_AddTimer(timeoutValue * 1e3, suspend, NULL); +#endif +} + +void initSuspendTimer() { + timeoutTimer=SDL_AddTimer(timeoutValue * 1e3, suspend, NULL); + isSuspended=0; + logMessage("INFO","initSuspendTimer","Suspend timer initialized"); +} + +void HW_Init() +{ + logMessage("INFO","HW_Init","HW Initialized"); +} + +void rumble() { +// add moto support + +} + +int getBatteryLevel() { + int charge=30; + int charging=0; + +/* FILE *f = fopen("/sys/class/power_supply/battery/capacity", "r"); + fscanf(f, "%i", &charge); + fclose(f); +*/ + // f = fopen("/sys/class/power_supply/battery/charger_online", "r"); + // fscanf(f, "%i", &charging); + // fclose(f); + + if (charge<=20) return 1; + else if (charge<=40) return 2; + else if (charge<=60) return 3; + else if (charge<=80) return 4; + else if (charge<=100) return 5; + else return 6; +} + +int getCurrentBrightness() { + int level; + FILE *f = fopen("/sys/class/backlight/backlight.2/brightness", "r"); + if (f==NULL) { + logMessage("INFO","getCurrentBrightness","Error, file not found"); + return 12; + } else { + int ret = fscanf(f, "%i", &level); + if(ret==-1) { + logMessage("INFO","getCurrentBrightness","Error reading file"); + return 12; + } + fclose(f); + } + return level; +} + +int getMaxBrightness() { + int level; + FILE *f = fopen("/sys/class/backlight/backlight.2/max_brightness", "r"); + if (f==NULL) { + logMessage("INFO","getMaxBrightness","Error, file not found"); + return 12; + } else { + int ret = fscanf(f, "%i", &level); + if(ret==-1) { + logMessage("INFO","getMaxBrightness","Error reading file"); + return 12; + } + fclose(f); + } + return level; +} + +void setBrightness(int value) { + FILE *f = fopen("/sys/class/backlight/backlight.2/brightness", "w"); + if (f!=NULL) { + fprintf(f, "%d", value); + fclose(f); + } +} +