diff --git a/Makefile b/Makefile index 3551552..c7bad2d 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ endif ifeq ($(strip $(DEVKITPRO)),) $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") endif +ifeq ($(strip $(WUT_ROOT)),) +$(error "Please ensure WUT_ROOT is in your environment.") +endif export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) export LIBOGC_INC := $(DEVKITPRO)/libogc/include export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii @@ -22,6 +25,8 @@ export CXX := $(PREFIX)g++ export AR := $(PREFIX)ar export OBJCOPY := $(PREFIX)objcopy +export ELF2RPL := $(WUT_ROOT)/bin/elf2rpl + #--------------------------------------------------------------------------------- # TARGET is the name of the output # BUILD is the directory where object files & intermediate files will be placed @@ -32,13 +37,17 @@ TARGET := flappy_bird BUILD := build BUILD_DBG := $(TARGET)_dbg SOURCES := src \ - src/common \ 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 \ @@ -59,7 +68,10 @@ CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ 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 +LDFLAGS := -nostartfiles -T $(WUT_ROOT)/rules/rpl.ld -pie -fPIE -z common-page-size=64 -z max-page-size=64 -lcrt \ + -Wl,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size \ + -Wl,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r \ + -Wl,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,-wrap,__eabi -Wl,--gc-sections #--------------------------------------------------------------------------------- Q := @ @@ -67,16 +79,16 @@ MAKEFLAGS += --no-print-directory #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lgcc -lgd -lpng -ljpeg -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 # include and lib #--------------------------------------------------------------------------------- LIBDIRS := $(CURDIR) \ - $(DEVKITPPC)/lib \ - $(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 - + $(DEVKITPPC)/ \ + $(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 \ + $(WUT_ROOT)/lib #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional @@ -119,14 +131,13 @@ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ # 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$(CURDIR)/$(BUILD) -I$(WUT_ROOT)/include \ -I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2 #--------------------------------------------------------------------------------- # build a list of library paths #--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)) \ -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib export OUTPUT := $(CURDIR)/$(TARGET) @@ -135,12 +146,29 @@ export OUTPUT := $(CURDIR)/$(TARGET) #--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ +# @$(Q)$(MAKE) -C sd_loader @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile #--------------------------------------------------------------------------------- -clean: +clean: clean_channel @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 + +#--------------------------------------------------------------------------------- +install_channel: $(BUILD) NUSPacker.jar encryptKeyWith + @cp $(OUTPUT).rpx channel/code/ + java -jar NUSPacker.jar -in "channel" -out "install_channel" + +NUSPacker.jar: + wget https://bitbucket.org/timogus/nuspacker/downloads/NUSPacker.jar + +encryptKeyWith: + @echo "Missing common key file \"encryptKeyWith\"! Insert the common key as string into \"encryptKeyWith\" file in the HBL Makefile path!" + @exit 1 + +clean_channel: + @rm -fr install_channel NUSPacker.jar fst.bin output tmp #--------------------------------------------------------------------------------- else @@ -150,19 +178,23 @@ DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- +$(OUTPUT).rpx: $(OUTPUT).elf $(OUTPUT).elf: $(OFILES) #--------------------------------------------------------------------------------- # This rule links in binary data with the .jpg extension #--------------------------------------------------------------------------------- -%.elf: link.ld $(OFILES) +%.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)$(LD) $^ $(LDFLAGS) -o $@ $(LIBPATHS) $(LIBS) +# $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ + +#--------------------------------------------------------------------------------- +%.rpx: %.elf +#--------------------------------------------------------------------------------- + @echo "[RPX] $(notdir $@)" + @$(ELF2RPL) $^ $@ -../data/loader.bin: - $(MAKE) -C ../loader clean - $(MAKE) -C ../loader #--------------------------------------------------------------------------------- %.a: #--------------------------------------------------------------------------------- diff --git a/README.md b/README.md index 3fa2d7c..07b280b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,23 @@ -#Flappy Bird GX2# -A GX2 Flappy Bird port for the WiiU. -Assets from Floppy Bird (HTML5 and the original Android game). +#Flappy Bird RPX# +A RPX Flappy Bird port for WiiU +Assest from floppy bird HTML5 and original android game + +#Installation# +Put the Flappy Bird folder on an SD card in the "install" folder. Use wup installer y mod to install to your NAND or USB. It is recommended to install to USB. Signature patching is required. #Usage# -Press A to begin the Game -Press A to jump -Press HOME to exit -Avoid the pipes and the flor! +Press A to begin the Game +Press A to jump +Press HOME to exit +Avoid the pipes and the floor! #Building# -In order to build this application, you need the custom liboGC and portlibs modified/created by dimok. You can find them on the loadiine_gx2 repo (https://github.com/dimok789/loadiine_gx2/releases/tag/v0.2). Simply put the files in your devkit folder and run the Makefile. +In order to build this application, you need the custom liboGC and portlibs modified/created by dimok. You can find them on the loadiine_gx2 repo (https://github.com/dimok789/loadiine_gx2/releases/tag/v0.2). Simply put the files in your devkit folder and run the Makefile. #Credits:# -**dimok** - WiiU librabries, dynamic_libs, examples, Homebrew Launcher -**Maschell** - GX2_Example and coding help -**vgmoose** - Coding help -**pwsincd** - Icon -**QuarkTheAwesome, dylon99** - Various help and testing +dimok - WiiU librabries, dynamic_libs, examples, Homebrew Launcher +Maschell - GX2_Example and coding help +vgmoose - Coding help +pwsincd - Icon +QuarkTheAwesome, dylon99 - Various help and testing +brienj - RPX build diff --git a/channel/code/app.xml b/channel/code/app.xml new file mode 100644 index 0000000..f25462b --- /dev/null +++ b/channel/code/app.xml @@ -0,0 +1,11 @@ + + + 1 + 000500101000400A + 0005000046425244 + 0000 + 20811 + 80000000 + 00004252 + 0000000000000000000000000000000000000000000000000000000000000000 + \ No newline at end of file diff --git a/channel/code/cos.xml b/channel/code/cos.xml new file mode 100644 index 0000000..aed6147 --- /dev/null +++ b/channel/code/cos.xml @@ -0,0 +1,97 @@ + + + 1 + 0 + flappy_bird.rpx + 00000000 + 00000000 + 00000001 + 40000000 + 01000000 + + + 1 + FFFFFFFFFFFFFFFF + + + + 3 + FFFFFFFFFFFFFFFF + + + + 9 + FFFFFFFFFFFFFFFF + + + + 12 + FFFFFFFFFFFFFFFF + + + + 11 + FFFFFFFFFFFFFFFF + + + + 13 + FFFFFFFFFFFFFFFF + + + + 14 + FFFFFFFFFFFFFFFF + + + + 15 + FFFFFFFFFFFFFFFF + + + + 16 + FFFFFFFFFFFFFFFF + + + + 17 + FFFFFFFFFFFFFFFF + + + + 18 + FFFFFFFFFFFFFFFF + + + + 19 + FFFFFFFFFFFFFFFF + + + + 20 + FFFFFFFFFFFFFFFF + + + + 21 + FFFFFFFFFFFFFFFF + + + + 22 + FFFFFFFFFFFFFFFF + + + + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00001000 + 00001000 + 00001000 + \ No newline at end of file diff --git a/channel/content/dummy b/channel/content/dummy new file mode 100644 index 0000000..2f259b7 --- /dev/null +++ b/channel/content/dummy @@ -0,0 +1 @@ +s \ No newline at end of file diff --git a/channel/meta/bootDrcTex.tga b/channel/meta/bootDrcTex.tga new file mode 100644 index 0000000..1564b91 Binary files /dev/null and b/channel/meta/bootDrcTex.tga differ diff --git a/channel/meta/bootLogoTex.tga b/channel/meta/bootLogoTex.tga new file mode 100644 index 0000000..944896e Binary files /dev/null and b/channel/meta/bootLogoTex.tga differ diff --git a/channel/meta/bootMovie.h264 b/channel/meta/bootMovie.h264 new file mode 100644 index 0000000..1661970 Binary files /dev/null and b/channel/meta/bootMovie.h264 differ diff --git a/channel/meta/bootSound.btsnd b/channel/meta/bootSound.btsnd new file mode 100644 index 0000000..ac07882 Binary files /dev/null and b/channel/meta/bootSound.btsnd differ diff --git a/channel/meta/bootTvTex.tga b/channel/meta/bootTvTex.tga new file mode 100644 index 0000000..02ae2f4 Binary files /dev/null and b/channel/meta/bootTvTex.tga differ diff --git a/channel/meta/iconTex.tga b/channel/meta/iconTex.tga new file mode 100644 index 0000000..1cac4f1 Binary files /dev/null and b/channel/meta/iconTex.tga differ diff --git a/channel/meta/meta.xml b/channel/meta/meta.xml new file mode 100644 index 0000000..d6ba535 --- /dev/null +++ b/channel/meta/meta.xml @@ -0,0 +1,140 @@ + + + 1 + WUP-N-RWRE + WUP + 0001 + + 0 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000004 + 00000000 + 1 + 0 + 0005000046425244 + 00004252 + 0000000000000000 + 000500101000400A + 0000000000000000 + 0000000001790000 + 0000000000000000 + 0000000000000000 + 0000000000000000 + 0 + 00000000 + 0000000000000000 + 1 + 0 + 0 + 0 + 0 + FFFFFFFF + 128 + 128 + 192 + 128 + 128 + 192 + 128 + 128 + 128 + 128 + 128 + 128 + 192 + 192 + 192 + 192 + 1 + 0 + 1 + 0 + 1 + 0 + + 0 + 1 + 1 + 0 + 0 + 00010001 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000003 + 00000000 + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + Flappy Bird + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + rw-r-r_0644 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + 00000000 + diff --git a/filelist.sh b/filelist.sh index 87cbee1..15addd3 100755 --- 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 51c01d4..8d3d2f2 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -14,24 +14,30 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . ****************************************************************************/ +#include +#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; bool Application::exitApplication = false; +bool Application::quitRequest = false; Application::Application() : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000) , bgMusic(NULL) , video(NULL) , mainWindow(NULL) + , fontSystem(NULL) , exitCode(EXIT_RELAUNCH_ON_LOAD) { controller[0] = new VPadController(GuiTrigger::CHANNEL_1); @@ -41,16 +47,18 @@ Application::Application() controller[4] = new WPadController(GuiTrigger::CHANNEL_5); //! create bgMusic - /* - bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg")); - bgMusic->SetLoop(true); - bgMusic->Play(); - bgMusic->SetVolume(50);*/ +// bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg")); +// bgMusic->SetLoop(true); +// bgMusic->Play(); +// bgMusic->SetVolume(50); exitApplication = false; + + ProcUIInit(OSSavesDone_ReadyToRelease); } -Application::~Application(){ +Application::~Application() +{ log_printf("Destroy music\n"); delete bgMusic; @@ -61,7 +69,6 @@ Application::~Application(){ delete controller[i]; log_printf("Destroy async deleter\n"); - AsyncDeleter::triggerDeleteProcess(); AsyncDeleter::destroyInstance(); log_printf("Clear resources\n"); @@ -69,9 +76,12 @@ Application::~Application(){ log_printf("Stop sound handler\n"); SoundHandler::DestroyInstance(); + + ProcUIShutdown(); } -int Application::exec(){ +int Application::exec() +{ //! start main GX2 thread resumeThread(); //! now wait for thread to finish @@ -80,7 +90,15 @@ int Application::exec(){ return exitCode; } -void Application::fadeOut(){ +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 }); for(int i = 0; i < 255; i += 10) @@ -94,9 +112,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(); @@ -105,9 +123,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(); @@ -127,36 +145,100 @@ void Application::fadeOut(){ video->drcEnable(false); } -void Application::executeThread(void){ - log_printf("Initialize video\n"); - video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_SINGLE); +bool Application::procUI(void) +{ + bool executeProcess = false; - log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); + switch(ProcUIProcessMessages(true)) + { + case PROCUI_STATUS_EXITING: + { + log_printf("PROCUI_STATUS_EXITING\n"); + exitCode = EXIT_SUCCESS; + exitApplication = true; + break; + } + case PROCUI_STATUS_RELEASE_FOREGROUND: + { + log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n"); + if(video != NULL) + { + // we can turn of the screen but we don't need to and it will display the last image + video->tvEnable(true); + video->drcEnable(true); - //! 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("delete fontSystem\n"); + delete fontSystem; + fontSystem = NULL; - log_printf("Initialize main window\n"); + log_printf("delete video\n"); + delete video; + video = NULL; - mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); + log_printf("deinitialze memory\n"); + memoryRelease(); + ProcUIDrawDoneRelease(); + } + else + { + ProcUIDrawDoneRelease(); + } + break; + } + case PROCUI_STATUS_IN_FOREGROUND: + { + if(!quitRequest) + { + if(video == NULL) + { + log_printf("PROCUI_STATUS_IN_FOREGROUND\n"); + 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; + } + break; + } + case PROCUI_STATUS_IN_BACKGROUND: + default: + break; + } + + return executeProcess; +} + +void Application::executeThread(void) +{ 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++) { if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false) continue; - if(controller[i]->data.buttons_d & VPAD_BUTTON_HOME){ - exitApplication = true; - } - //! update controller states mainWindow->update(controller[i]); } @@ -190,9 +272,24 @@ void Application::executeThread(void){ AsyncDeleter::triggerDeleteProcess(); } - fadeOut(); + //! in case we exit to a homebrew let's smoothly fade out + if(video) + { + 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 9abbafd..46dc8d9 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: @@ -50,22 +53,24 @@ public: int exec(void); void fadeOut(void); - void quit(int code) { - exitCode = code; - exitApplication = true; - } + void quit(int code); + private: Application(); virtual ~Application(); + bool procUI(void); + static Application *applicationInstance; static bool exitApplication; + static bool quitRequest; void executeThread(void); 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 7d224c8..5e353eb 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -7,8 +7,10 @@ extern "C" { #include "os_defs.h" +#define HBL_VERSION_INT 200 + #define CAFE_OS_SD_PATH "/vol/external01" -#define SD_PATH "sd:" +#define SD_PATH "fs:" #define WIIU_PATH "/wiiu" /* Macros for libs */ @@ -40,11 +42,19 @@ extern "C" { #define ELF_DATA_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x00)) #define ELF_DATA_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x04)) +#define HBL_CHANNEL_OFFSET (0x1300 + 0x08) +#define HBL_CHANNEL (*(volatile unsigned int*)(MEM_BASE + HBL_CHANNEL_OFFSET)) +#define RPX_MAX_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x0C)) +#define RPX_MAX_CODE_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x10)) #define MAIN_ENTRY_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x00)) +#define OS_FIRMWARE_OFFSET (0x1400 + 0x04) #define OS_FIRMWARE (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x04)) #define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500)) +#define MEM_AREA_TABLE ((s_mem_area*)(MEM_BASE + 0x1600)) +#define APP_BASE_MEM ((unsigned char*)(MEM_BASE + 0x2000)) + #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif 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/os_defs.h b/src/common/os_defs.h index 48a4c8f..b92c527 100644 --- a/src/common/os_defs.h +++ b/src/common/os_defs.h @@ -16,8 +16,23 @@ typedef struct _OsSpecifics unsigned int addr_KernSyscallTbl3; unsigned int addr_KernSyscallTbl4; unsigned int addr_KernSyscallTbl5; + + int (*LiWaitIopComplete)(int, int *); + int (*LiWaitIopCompleteWithInterrupts)(int, int *); + unsigned int addr_LiWaitOneChunk; + unsigned int addr_PrepareTitle_hook; + unsigned int addr_sgIsLoadingBuffer; + unsigned int addr_gDynloadInitialized; + unsigned int orig_LiWaitOneChunkInstr; } OsSpecifics; +typedef struct _s_mem_area +{ + unsigned int address; + unsigned int size; + struct _s_mem_area* next; +} s_mem_area; + #ifdef __cplusplus } #endif 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/README.md b/src/dynamic_libs/README.md deleted file mode 100644 index be82302..0000000 --- a/src/dynamic_libs/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# dynamic_libs -Dynamic libs for WiiU homebrew diff --git a/src/dynamic_libs/acp_functions.c b/src/dynamic_libs/acp_functions.c deleted file mode 100644 index eb931f8..0000000 --- a/src/dynamic_libs/acp_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" -#include "acp_functions.h" - -unsigned int acp_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(void, GetMetaXml, void * _ACPMetaXml); - -void InitAcquireACP(void) -{ - OSDynLoad_Acquire("nn_acp.rpl", &acp_handle); -} - -void InitACPFunctionPointers(void) -{ - InitAcquireACP(); - OSDynLoad_FindExport(acp_handle,0,"GetMetaXml__Q2_2nn3acpFP11_ACPMetaXml",&GetMetaXml); -} diff --git a/src/dynamic_libs/acp_functions.h b/src/dynamic_libs/acp_functions.h deleted file mode 100644 index dc1822d..0000000 --- a/src/dynamic_libs/acp_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 __ACP_FUNCTIONS_H_ -#define __ACP_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -extern unsigned int acp_handle; - -void InitACPFunctionPointers(void); -void InitAcquireACP(void); - -#ifdef __cplusplus -} -#endif - -#endif // __VPAD_FUNCTIONS_H_ diff --git a/src/dynamic_libs/aoc_functions.c b/src/dynamic_libs/aoc_functions.c deleted file mode 100644 index e74306d..0000000 --- a/src/dynamic_libs/aoc_functions.c +++ /dev/null @@ -1,58 +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 "aoc_functions.h" - -unsigned int aoc_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(s32, AOC_Initialize, void); -EXPORT_DECL(s32, AOC_Finalize, void); -EXPORT_DECL(u32, AOC_CalculateWorkBufferSize, u32 num_titles); -EXPORT_DECL(s32, AOC_ListTitle, u32 * num_titles, void * titles, u32 max_titles, void * buffer, u32 buffer_size); -EXPORT_DECL(s32, AOC_OpenTitle, char* aoc_path, void * title, void * buffer, u32 buffer_size); -EXPORT_DECL(s32, AOC_CloseTitle, void * title); -EXPORT_DECL(s32, AOC_DeleteContent, u64 title_id, u16 contentIndexes[], u32 numberOfContent, void* buffer, u32 buffer_size); -EXPORT_DECL(s32, AOC_GetPurchaseInfo, u32 * bResult, u64 title_id, u16 contentIndexes[], u32 numberOfContent, void * buffer, u32 buffer_size); - -void InitAcquireAoc(void) -{ - OSDynLoad_Acquire("nn_aoc.rpl", &aoc_handle); -} - -void InitAocFunctionPointers(void) -{ - InitAcquireAoc(); - if(aoc_handle == 0) - return; - - //! assigning those is not mandatory and it does not always work to load them - OSDynLoad_FindExport(aoc_handle, 0, "AOC_Initialize", &AOC_Initialize); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_Finalize", &AOC_Finalize); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_CalculateWorkBufferSize", &AOC_CalculateWorkBufferSize); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_ListTitle", &AOC_ListTitle); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_OpenTitle", &AOC_OpenTitle); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_CloseTitle", &AOC_CloseTitle); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_DeleteContent", &AOC_DeleteContent); - OSDynLoad_FindExport(aoc_handle, 0, "AOC_GetPurchaseInfo", &AOC_GetPurchaseInfo); -} diff --git a/src/dynamic_libs/aoc_functions.h b/src/dynamic_libs/aoc_functions.h deleted file mode 100644 index efca771..0000000 --- a/src/dynamic_libs/aoc_functions.h +++ /dev/null @@ -1,58 +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 __AOC_FUNCTIONS_H_ -#define __AOC_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern unsigned int aoc_handle; - -#define AOC_TITLE_SIZE 104 - -typedef struct { - u64 title_ID; - u32 group_ID; - u16 version; - char path[88]; -} AOC_TitleListType; - - -void InitAocFunctionPointers(void); -void InitAcquireAoc(void); - -extern s32 (* AOC_Initialize)(void); -extern s32 (* AOC_Finalize)(void); -extern u32 (* AOC_CalculateWorkBufferSize)(u32 num_titles); -extern s32 (* AOC_ListTitle)(u32 * num_titles, void * titles, u32 max_titles, void * buffer, u32 buffer_size); -extern s32 (* AOC_OpenTitle)(char* aoc_path, void * title, void * buffer, u32 buffer_size); -extern s32 (* AOC_CloseTitle)(void * title); -extern s32 (* AOC_DeleteContent)(u64 title_id, u16 contentIndexes[], u32 numberOfContent, void * buffer, u32 buffer_size); -extern s32 (* AOC_GetPurchaseInfo)(u32 * bResult, u64 title_id, u16 contentIndexes[], u32 numberOfContent, void * buffer, u32 buffer_size); -#ifdef __cplusplus -} -#endif - -#endif // __AOC_FUNCTIONS_H_ diff --git a/src/dynamic_libs/ax_functions.c b/src/dynamic_libs/ax_functions.c deleted file mode 100644 index e517f6d..0000000 --- a/src/dynamic_libs/ax_functions.c +++ /dev/null @@ -1,118 +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" -#include "ax_functions.h" - -unsigned int sound_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(void, AXInitWithParams, u32 * params); -EXPORT_DECL(void, AXInit, void); -EXPORT_DECL(void, AXQuit, void); -EXPORT_DECL(u32, AXGetInputSamplesPerSec, void); -EXPORT_DECL(u32, AXGetInputSamplesPerFrame, void); -EXPORT_DECL(s32, AXVoiceBegin, void *v); -EXPORT_DECL(s32, AXVoiceEnd, void *v); -EXPORT_DECL(void, AXSetVoiceType, void *v, u16 type); -EXPORT_DECL(void, AXSetVoiceOffsets, void *v, const void *buf); -EXPORT_DECL(void, AXSetVoiceSrcType, void *v, u32 type); -EXPORT_DECL(void, AXSetVoiceVe, void *v, const void *vol); -EXPORT_DECL(s32, AXSetVoiceDeviceMix, void *v, s32 device, u32 id, void *mix); -EXPORT_DECL(void, AXSetVoiceState, void *v, u16 state); -EXPORT_DECL(void, AXSetVoiceSrc, void *v, const void *src); -EXPORT_DECL(s32, AXSetVoiceSrcRatio, void *v,f32 ratio) -EXPORT_DECL(void *, AXAcquireVoice, u32 prio, void * callback, u32 arg); -EXPORT_DECL(void, AXFreeVoice, void *v); -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 InitAcquireAX(void) -{ - unsigned int *funcPointer = 0; - - if(OS_FIRMWARE >= 400) - { - AXInit = 0; - - OSDynLoad_Acquire("sndcore2.rpl", &sound_handle); - OS_FIND_EXPORT(sound_handle, AXInitWithParams); - OS_FIND_EXPORT(sound_handle, AXGetInputSamplesPerSec); - } - else - { - AXInitWithParams = 0; - AXGetInputSamplesPerSec = 0; - - OSDynLoad_Acquire("snd_core.rpl", &sound_handle); - OS_FIND_EXPORT(sound_handle, AXInit); - } -} - -void InitAXFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - - InitAcquireAX(); - - OS_FIND_EXPORT(sound_handle, AXQuit); - OS_FIND_EXPORT(sound_handle, AXVoiceBegin); - OS_FIND_EXPORT(sound_handle, AXVoiceEnd); - OS_FIND_EXPORT(sound_handle, AXSetVoiceType); - OS_FIND_EXPORT(sound_handle, AXSetVoiceOffsets); - OS_FIND_EXPORT(sound_handle, AXSetVoiceSrcType); - OS_FIND_EXPORT(sound_handle, AXSetVoiceVe); - OS_FIND_EXPORT(sound_handle, AXSetVoiceDeviceMix); - OS_FIND_EXPORT(sound_handle, AXSetVoiceState); - OS_FIND_EXPORT(sound_handle, AXSetVoiceSrc); - OS_FIND_EXPORT(sound_handle, AXSetVoiceSrcRatio); - OS_FIND_EXPORT(sound_handle, AXAcquireVoice); - OS_FIND_EXPORT(sound_handle, AXFreeVoice); - OS_FIND_EXPORT(sound_handle, AXRegisterFrameCallback); - OS_FIND_EXPORT(sound_handle, AXGetVoiceLoopCount); - OS_FIND_EXPORT(sound_handle, AXSetVoiceEndOffset); - OS_FIND_EXPORT(sound_handle, AXSetVoiceLoopOffset); -} - -void ProperlyEndTransitionAudio(void) -{ - bool (* check_os_audio_transition_flag_old)(void); - void (* AXInit_old)(void); - void (* AXQuit_old)(void); - - unsigned int *funcPointer = 0; - unsigned int 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); - OS_FIND_EXPORT_EX(sound_handle, AXInit, AXInit_old); - OS_FIND_EXPORT_EX(sound_handle, AXQuit, AXQuit_old); - - if (check_os_audio_transition_flag_old()) - { - AXInit_old(); - AXQuit_old(); - } -} diff --git a/src/dynamic_libs/ax_functions.h b/src/dynamic_libs/ax_functions.h deleted file mode 100644 index 086346f..0000000 --- a/src/dynamic_libs/ax_functions.h +++ /dev/null @@ -1,64 +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 __AX_FUNCTIONS_H_ -#define __AX_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -extern unsigned int sound_handle; - -void InitAXFunctionPointers(void); -void InitAcquireAX(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 - -#endif // __VPAD_FUNCTIONS_H_ diff --git a/src/dynamic_libs/curl_functions.c b/src/dynamic_libs/curl_functions.c deleted file mode 100644 index d828cdb..0000000 --- a/src/dynamic_libs/curl_functions.c +++ /dev/null @@ -1,54 +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 "curl_functions.h" - -unsigned int libcurl_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(CURLcode, n_curl_global_init, long flags); -EXPORT_DECL(CURL *, n_curl_easy_init, void); -EXPORT_DECL(CURLcode, n_curl_easy_setopt, CURL *curl, CURLoption option, ...); -EXPORT_DECL(CURLcode, n_curl_easy_perform, CURL *curl); -EXPORT_DECL(void, n_curl_easy_cleanup, CURL *curl); -EXPORT_DECL(CURLcode, n_curl_easy_getinfo, CURL *curl, CURLINFO info, ...); - -void InitAcquireCurl(void) -{ - OSDynLoad_Acquire("nlibcurl", &libcurl_handle); -} - -void InitCurlFunctionPointers(void) -{ - InitAcquireCurl(); - unsigned int *funcPointer = 0; - - OS_FIND_EXPORT_EX(libcurl_handle, curl_global_init, n_curl_global_init); - OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_init, n_curl_easy_init); - OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_setopt, n_curl_easy_setopt); - OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_perform, n_curl_easy_perform); - OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_cleanup, n_curl_easy_cleanup); - OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_getinfo, n_curl_easy_getinfo); - - n_curl_global_init(CURL_GLOBAL_ALL); -} diff --git a/src/dynamic_libs/curl_functions.h b/src/dynamic_libs/curl_functions.h deleted file mode 100644 index e40740b..0000000 --- a/src/dynamic_libs/curl_functions.h +++ /dev/null @@ -1,51 +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 __CURL_FUNCTIONS_H_ -#define __CURL_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "socket_functions.h" -typedef int socklen_t; -#include -#include - -void InitCurlFunctionPointers(void); -void InitAcquireCurl(void); - -extern CURLcode (* n_curl_global_init)(long flags); -extern CURL * (* n_curl_easy_init)(void); -extern CURLcode (* n_curl_easy_setopt)(CURL *curl, CURLoption option, ...); -extern CURLcode (* n_curl_easy_perform)(CURL *curl); -extern void (* n_curl_easy_cleanup)(CURL *curl); -extern CURLcode (* n_curl_easy_getinfo)(CURL *curl, CURLINFO info, ...); - -#ifdef __cplusplus -} -#endif - -#endif // __CURL_FUNCTIONS_H_ 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_defs.h b/src/dynamic_libs/fs_defs.h deleted file mode 100644 index 1b1bc41..0000000 --- a/src/dynamic_libs/fs_defs.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef FS_DEFS_H -#define FS_DEFS_H - -#include - -#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_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/dynamic_libs/fs_functions.c b/src/dynamic_libs/fs_functions.c deleted file mode 100644 index 08a4fb6..0000000 --- a/src/dynamic_libs/fs_functions.c +++ /dev/null @@ -1,131 +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" - -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); - -EXPORT_DECL(int, FSBindMount, void *pClient, void *pCmd, char *source, char *target, int error); -EXPORT_DECL(int, FSBindUnmount, void *pClient, void *pCmd, char *target, int error); - -EXPORT_DECL(int, FSMakeQuota, void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling); -EXPORT_DECL(int, FSMakeQuotaAsync ,void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling,const void *asyncParams); - -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); - - OS_FIND_EXPORT(coreinit_handle, FSBindMount); - OS_FIND_EXPORT(coreinit_handle, FSBindUnmount); - - OS_FIND_EXPORT(coreinit_handle, FSMakeQuota); - OS_FIND_EXPORT(coreinit_handle, FSMakeQuotaAsync); -} diff --git a/src/dynamic_libs/fs_functions.h b/src/dynamic_libs/fs_functions.h deleted file mode 100644 index d024655..0000000 --- a/src/dynamic_libs/fs_functions.h +++ /dev/null @@ -1,95 +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 -#include "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); - -extern int (* FSBindMount)(void *pClient, void *pCmd, char *source, char *target, int error); -extern int (* FSBindUnmount)(void *pClient, void *pCmd, char *target, int error); - -extern int (* FSMakeQuota)( void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling); -extern int (* FSMakeQuotaAsync)(void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling,const void *asyncParams); - - -#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 a34807e..0000000 --- a/src/dynamic_libs/gx2_functions.c +++ /dev/null @@ -1,173 +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" - -unsigned int gx2_handle __attribute__((section(".data"))) = 0; - -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, GX2SetClearDepthStencil, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value); -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*)); -EXPORT_DECL(void, GX2CopySurface, GX2Surface * srcSurface,u32 srcMip,u32 srcSlice,GX2Surface * dstSurface,u32 dstMip,u32 dstSlice ); - -EXPORT_DECL(void, GX2ClearBuffersEx, GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r, f32 g, f32 b, f32 a,f32 depthValue,u8 stencilValue,int clearFlags); - -void InitAcquireGX2(void) -{ - OSDynLoad_Acquire("gx2.rpl", &gx2_handle); -} - -void InitGX2FunctionPointers(void) -{ - unsigned int *funcPointer = 0; - InitAcquireGX2(); - - 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); - OS_FIND_EXPORT(gx2_handle, GX2CopySurface); - OS_FIND_EXPORT(gx2_handle, GX2ClearBuffersEx); - OS_FIND_EXPORT(gx2_handle, GX2SetClearDepthStencil); -} diff --git a/src/dynamic_libs/gx2_functions.h b/src/dynamic_libs/gx2_functions.h deleted file mode 100644 index 0b06826..0000000 --- a/src/dynamic_libs/gx2_functions.h +++ /dev/null @@ -1,211 +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" - -extern unsigned int gx2_handle; - -void InitGX2FunctionPointers(void); -void InitAcquireGX2(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 (* GX2SetClearDepthStencil)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value); -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*)); -extern void (* GX2CopySurface)(GX2Surface * srcSurface,u32 srcMip,u32 srcSlice,GX2Surface * dstSurface,u32 dstMip,u32 dstSlice ); -extern void (* GX2ClearBuffersEx)(GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r, f32 g, f32 b, f32 a,f32 depthValue,u8 stencilValue,int clearFlags); - -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 734e2e5..0000000 --- a/src/dynamic_libs/os_functions.c +++ /dev/null @@ -1,326 +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 __attribute__((section(".data"))) = 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); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Security functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, OSGetSecurityLevel, void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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); -EXPORT_DECL(u64, OSGetTick, void); -EXPORT_DECL(u64, OSGetTime, void); -EXPORT_DECL(void, OSTicksToCalendarTime, u64 time, OSCalendarTime * calendarTime); - - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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, OSGetArgcArgv, int* argc, char*** argv); -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, ...); -EXPORT_DECL(int *, __gh_errno_ptr, void); - -EXPORT_DECL(void, OSScreenInit, void); -EXPORT_DECL(unsigned int, OSScreenGetBufferSizeEx, unsigned int bufferNum); -EXPORT_DECL(int, OSScreenSetBufferEx, unsigned int bufferNum, void * addr); -EXPORT_DECL(int, OSScreenClearBufferEx, unsigned int bufferNum, unsigned int temp); -EXPORT_DECL(int, OSScreenFlipBuffersEx, unsigned int bufferNum); -EXPORT_DECL(int, OSScreenPutFontEx, unsigned int bufferNum, unsigned int posX, unsigned int posY, const char * buffer); -EXPORT_DECL(int, OSScreenEnableEx, unsigned int bufferNum, int enable); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! MCP functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(int, MCP_Open, void); -EXPORT_DECL(int, MCP_Close, int handle); -EXPORT_DECL(int, MCP_GetOwnTitleInfo, int handle, void * data); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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); -EXPORT_DECL(void, addr_LiWaitOneChunk, void); -EXPORT_DECL(void, addr_sgIsLoadingBuffer, void); -EXPORT_DECL(void, addr_gDynloadInitialized, void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Kernel function addresses -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(void, addr_PrepareTitle_hook, void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Other function addresses -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -EXPORT_DECL(void, DCInvalidateRange, void *buffer, uint32_t length); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Energy Saver functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//Burn-in Reduction -EXPORT_DECL(int, IMEnableDim,void); -EXPORT_DECL(int, IMDisableDim,void); -EXPORT_DECL(int, IMIsDimEnabled,int * result); -//Auto power down -EXPORT_DECL(int, IMEnableAPD,void); -EXPORT_DECL(int, IMDisableAPD,void); -EXPORT_DECL(int, IMIsAPDEnabled,int * result); -EXPORT_DECL(int, IMIsAPDEnabledBySysSettings,int * result); - -void InitAcquireOS(void) -{ - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! 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); -} - -void InitOSFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - - InitAcquireOS(); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Security functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSGetSecurityLevel); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! System functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, OSFatal); - OS_FIND_EXPORT(coreinit_handle, OSGetTitleID); - OS_FIND_EXPORT(coreinit_handle, OSGetArgcArgv); - 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); - OS_FIND_EXPORT(coreinit_handle, __gh_errno_ptr); - - OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &__Exit); - - OS_FIND_EXPORT(coreinit_handle, OSScreenInit); - OS_FIND_EXPORT(coreinit_handle, OSScreenGetBufferSizeEx); - OS_FIND_EXPORT(coreinit_handle, OSScreenSetBufferEx); - OS_FIND_EXPORT(coreinit_handle, OSScreenClearBufferEx); - OS_FIND_EXPORT(coreinit_handle, OSScreenFlipBuffersEx); - OS_FIND_EXPORT(coreinit_handle, OSScreenPutFontEx); - OS_FIND_EXPORT(coreinit_handle, OSScreenEnableEx); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! 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); - OS_FIND_EXPORT(coreinit_handle, OSGetTick); - OS_FIND_EXPORT(coreinit_handle, OSGetTime); - OS_FIND_EXPORT(coreinit_handle, OSTicksToCalendarTime); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! 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); - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! MCP functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, MCP_Open); - OS_FIND_EXPORT(coreinit_handle, MCP_Close); - OS_FIND_EXPORT(coreinit_handle, MCP_GetOwnTitleInfo); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! 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); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Other function addresses - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - OS_FIND_EXPORT(coreinit_handle, DCInvalidateRange); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Energy Saver functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //Burn-in Reduction - OS_FIND_EXPORT(coreinit_handle, IMEnableDim); - OS_FIND_EXPORT(coreinit_handle, IMDisableDim); - OS_FIND_EXPORT(coreinit_handle, IMIsDimEnabled); - //Auto power down - OS_FIND_EXPORT(coreinit_handle, IMEnableAPD); - OS_FIND_EXPORT(coreinit_handle, IMDisableAPD); - OS_FIND_EXPORT(coreinit_handle, IMIsAPDEnabled); - OS_FIND_EXPORT(coreinit_handle, IMIsAPDEnabledBySysSettings); - - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - //! Special non library functions - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - if(OS_FIRMWARE == 532 || OS_FIRMWARE == 540) - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100FFA4); // loader.elf - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100FE90); // loader.elf - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007EC); // loader.elf - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF18558); // kernel.elf - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19D00); // loader.elf - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13C3C); // loader.elf - } - else if(OS_FIRMWARE == 500 || OS_FIRMWARE == 510) - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100FBC4); - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100FAB0); - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007EC); - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF18534); - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19D00); - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13C3C); - } - else if(OS_FIRMWARE == 410) - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100F78C); - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100F678); - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007F8); - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF166DC); - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19CC0); - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13BFC); - } - else if(OS_FIRMWARE == 400) //same for 402 and 403 - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100F78C); - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100F678); - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007F8); - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF15E70); - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19CC0); - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13BFC); - } - else if(OS_FIRMWARE == 550) - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x01010180); - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0101006C); - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x0100080C); - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF184E4); - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19E80); - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13DBC); - } - else if(OS_FIRMWARE == 310) - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100C4E4); - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100C3D4); - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010004D8); - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF15A0C); - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19340); - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE1329C); - } - else if(OS_FIRMWARE == 300) - { - EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100C4E4); - EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100C3D4); - EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010004D8); - EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF15974); - - EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19340); - EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE1329C); - } - else - { - OSFatal("Missing all OS specific addresses."); - } -} diff --git a/src/dynamic_libs/os_functions.h b/src/dynamic_libs/os_functions.h deleted file mode 100644 index 347da67..0000000 --- a/src/dynamic_libs/os_functions.h +++ /dev/null @@ -1,174 +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" -#include "os_types.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); -void InitAcquireOS(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); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Security functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* OSGetSecurityLevel)(void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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); -extern u64 (* OSGetTick)(void); -extern u64 (* OSGetTime)(void); -extern void (*OSTicksToCalendarTime)(u64 time, OSCalendarTime *calendarTime); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! 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 (* OSGetArgcArgv)(int* argc, char*** argv); -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, ...); -extern int * (* __gh_errno_ptr)(void); - -extern void (*OSScreenInit)(void); -extern unsigned int (*OSScreenGetBufferSizeEx)(unsigned int bufferNum); -extern int (*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr); -extern int (*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp); -extern int (*OSScreenFlipBuffersEx)(unsigned int bufferNum); -extern int (*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, const char * buffer); -extern int (*OSScreenEnableEx)(unsigned int bufferNum, int enable); - -typedef unsigned char (*exception_callback)(void * interruptedContext); -extern void (* OSSetExceptionCallback)(u8 exceptionType, exception_callback newCallback); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! MCP functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* MCP_Open)(void); -extern int (* MCP_Close)(int handle); -extern int (* MCP_GetOwnTitleInfo)(int handle, void * data); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! LOADER functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern int (* LiWaitIopComplete)(int unknown_syscall_arg_r3, int * remaining_bytes); -extern int (* LiWaitIopCompleteWithInterrupts)(int unknown_syscall_arg_r3, int * remaining_bytes); -extern void (* addr_LiWaitOneChunk)(void); -extern void (* addr_sgIsLoadingBuffer)(void); -extern void (* addr_gDynloadInitialized)(void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Kernel function addresses -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern void (* addr_PrepareTitle_hook)(void); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Other function addresses -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -extern void (*DCInvalidateRange)(void *buffer, uint32_t length); - -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -//! Energy Saver functions -//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -////Burn-in Reduction -extern int (*IMEnableDim)(void); -extern int (*IMDisableDim)(void); -extern int (*IMIsDimEnabled)(int * result); -//Auto power down -extern int (*IMEnableAPD)(void); -extern int (*IMDisableAPD)(void); -extern int (*IMIsAPDEnabled)(int * result); -extern int (*IMIsAPDEnabledBySysSettings)(int * result); - -#ifdef __cplusplus -} -#endif - -#endif // __OS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/os_types.h b/src/dynamic_libs/os_types.h deleted file mode 100644 index aaa18fe..0000000 --- a/src/dynamic_libs/os_types.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _OS_TYPES_H_ -#define _OS_TYPES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct _OSCalendarTime { - int sec; - int min; - int hour; - int mday; - int mon; - int year; - int wday; - int yday; - int msec; - int usec; -} OSCalendarTime; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/dynamic_libs/padscore_functions.c b/src/dynamic_libs/padscore_functions.c index f7ca8e9..698ef63 100644 --- a/src/dynamic_libs/padscore_functions.c +++ b/src/dynamic_libs/padscore_functions.c @@ -21,41 +21,30 @@ * 3. This notice may not be removed or altered from any source * distribution. ***************************************************************************/ -#include "os_functions.h" +#include "exports.h" #include "padscore_functions.h" -unsigned int padscore_handle __attribute__((section(".data"))) = 0; - EXPORT_DECL(void, KPADInit, void); -EXPORT_DECL(void, WPADInit, void); EXPORT_DECL(s32, WPADProbe, s32 chan, u32 * pad_type); EXPORT_DECL(s32, WPADSetDataFormat, s32 chan, s32 format); EXPORT_DECL(void, WPADEnableURCC, s32 enable); EXPORT_DECL(void, WPADRead, s32 chan, void * data); EXPORT_DECL(s32, KPADRead, s32 chan, void * data, u32 size); -EXPORT_DECL(void,WPADSetAutoSleepTime,u8 minute); -EXPORT_DECL(void,WPADDisconnect,s32 chan); - -void InitAcquirePadScore(void) -{ - OSDynLoad_Acquire("padscore.rpl", &padscore_handle); -} void InitPadScoreFunctionPointers(void) { unsigned int *funcPointer = 0; - InitAcquirePadScore(); + OSDynLoadModule padscore_handle; + OSDynLoad_Acquire("padscore.rpl", &padscore_handle); - OS_FIND_EXPORT(padscore_handle, WPADInit); OS_FIND_EXPORT(padscore_handle, KPADInit); OS_FIND_EXPORT(padscore_handle, WPADProbe); OS_FIND_EXPORT(padscore_handle, WPADSetDataFormat); OS_FIND_EXPORT(padscore_handle, WPADEnableURCC); OS_FIND_EXPORT(padscore_handle, WPADRead); OS_FIND_EXPORT(padscore_handle, KPADRead); - OS_FIND_EXPORT(padscore_handle, WPADSetAutoSleepTime); - OS_FIND_EXPORT(padscore_handle, WPADDisconnect); KPADInit(); WPADEnableURCC(1); } + diff --git a/src/dynamic_libs/padscore_functions.h b/src/dynamic_libs/padscore_functions.h index 5b000b1..68cf989 100644 --- a/src/dynamic_libs/padscore_functions.h +++ b/src/dynamic_libs/padscore_functions.h @@ -28,11 +28,7 @@ extern "C" { #endif -#include "dynamic_libs/vpad_functions.h" - -extern unsigned int padscore_handle; - -#include +#include "common/types.h" #define WPAD_BUTTON_LEFT 0x0001 #define WPAD_BUTTON_RIGHT 0x0002 @@ -64,34 +60,8 @@ extern unsigned int padscore_handle; #define WPAD_CLASSIC_BUTTON_DOWN 0x4000 #define WPAD_CLASSIC_BUTTON_RIGHT 0x8000 -#define WPAD_PRO_BUTTON_UP 0x00000001 -#define WPAD_PRO_BUTTON_LEFT 0x00000002 -#define WPAD_PRO_TRIGGER_ZR 0x00000004 -#define WPAD_PRO_BUTTON_X 0x00000008 -#define WPAD_PRO_BUTTON_A 0x00000010 -#define WPAD_PRO_BUTTON_Y 0x00000020 -#define WPAD_PRO_BUTTON_B 0x00000040 -#define WPAD_PRO_TRIGGER_ZL 0x00000080 -#define WPAD_PRO_RESERVED 0x00000100 -#define WPAD_PRO_TRIGGER_R 0x00000200 -#define WPAD_PRO_BUTTON_PLUS 0x00000400 -#define WPAD_PRO_BUTTON_HOME 0x00000800 -#define WPAD_PRO_BUTTON_MINUS 0x00001000 -#define WPAD_PRO_TRIGGER_L 0x00002000 -#define WPAD_PRO_BUTTON_DOWN 0x00004000 -#define WPAD_PRO_BUTTON_RIGHT 0x00008000 -#define WPAD_PRO_BUTTON_STICK_R 0x00010000 -#define WPAD_PRO_BUTTON_STICK_L 0x00020000 +void InitPadScoreFunctionPointers(void); -#define WPAD_PRO_STICK_L_EMULATION_UP 0x00200000 -#define WPAD_PRO_STICK_L_EMULATION_DOWN 0x00100000 -#define WPAD_PRO_STICK_L_EMULATION_LEFT 0x00040000 -#define WPAD_PRO_STICK_L_EMULATION_RIGHT 0x00080000 - -#define WPAD_PRO_STICK_R_EMULATION_UP 0x02000000 -#define WPAD_PRO_STICK_R_EMULATION_DOWN 0x01000000 -#define WPAD_PRO_STICK_R_EMULATION_LEFT 0x00400000 -#define WPAD_PRO_STICK_R_EMULATION_RIGHT 0x00800000 typedef struct _KPADData { @@ -108,7 +78,7 @@ typedef struct _KPADData u8 device_type; u8 wpad_error; u8 pos_valid; - u8 format; + u8 unused_4[1]; union { @@ -131,38 +101,19 @@ typedef struct _KPADData f32 rtrigger; } classic; - struct - { - u32 btns_h; - u32 btns_d; - u32 btns_r; - f32 lstick_x; - f32 lstick_y; - f32 rstick_x; - f32 rstick_y; - int charging; - int wired; - } pro; - u32 unused_6[20]; }; u32 unused_7[16]; } KPADData; -void InitPadScoreFunctionPointers(void); -void InitAcquirePadScore(void); typedef void (* wpad_connect_callback_t)(s32 chan, s32 status); extern void (* KPADInit)(void); -extern void (* WPADInit)(void); extern s32 (* WPADProbe)(s32 chan, u32 * pad_type); extern s32 (* WPADSetDataFormat)(s32 chan, s32 format); extern void (* WPADEnableURCC)(s32 enable); extern void (* WPADRead)(s32 chan, void * data); extern s32 (* KPADRead)(s32 chan, void * data, u32 size); -extern s32 (* KPADReadEx)(s32 chan, KPADData * data, u32 size, s32 *error); -extern void (*WPADSetAutoSleepTime)(u8 time); -extern void (*WPADDisconnect)( s32 chan ); #ifdef __cplusplus } diff --git a/src/dynamic_libs/socket_functions.c b/src/dynamic_libs/socket_functions.c deleted file mode 100644 index de2c31f..0000000 --- a/src/dynamic_libs/socket_functions.c +++ /dev/null @@ -1,81 +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; - -unsigned int nsysnet_handle __attribute__((section(".data"))) = 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, 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, recvfrom,int sockfd, void *buf, int len, int flags,struct sockaddr *src_addr, int *addrlen); -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); - -EXPORT_DECL(int, NSSLWrite, int connection, const void* buf, int len,int * written); -EXPORT_DECL(int, NSSLRead, int connection, const void* buf, int len,int * read); -EXPORT_DECL(int, NSSLCreateConnection, int context, const char* host, int hotlen,int options,int sock,int block); - -void InitAcquireSocket(void) -{ - OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle); -} - -void InitSocketFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - - InitAcquireSocket(); - - 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, 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, recvfrom); - 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); - - OS_FIND_EXPORT(nsysnet_handle, NSSLWrite); - OS_FIND_EXPORT(nsysnet_handle, NSSLRead); - OS_FIND_EXPORT(nsysnet_handle, NSSLCreateConnection); - - socket_lib_init(); -} diff --git a/src/dynamic_libs/socket_functions.h b/src/dynamic_libs/socket_functions.h deleted file mode 100644 index 1e4df1a..0000000 --- a/src/dynamic_libs/socket_functions.h +++ /dev/null @@ -1,108 +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 - -extern unsigned int nsysnet_handle; - -#include - -#define INADDR_ANY 0 - -#define AF_INET 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 SO_RCVTIMEO 0x1006 - -#define SOL_SOCKET -1 -#define MSG_DONTWAIT 32 - -#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); -void InitAcquireSocket(void); - -extern void (*socket_lib_init)(void); -extern int (*socket)(int domain, int type, int protocol); -extern int (*socketclose)(int s); -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 (*recvfrom)(int sockfd, void *buf, int len, int flags,struct sockaddr *src_addr, int *addrlen); - -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 int (* NSSLWrite)(int connection, const void* buf, int len,int * written); -extern int (* NSSLRead)(int connection, const void* buf, int len,int * read); -extern int (* NSSLCreateConnection)(int context, const char* host, int hotlen,int options,int sock,int block); - -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 c054549..0000000 --- a/src/dynamic_libs/sys_functions.c +++ /dev/null @@ -1,49 +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" - - unsigned int sysapp_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(int, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero); -EXPORT_DECL(int, SYSRelaunchTitle, int argc, char** argv); -EXPORT_DECL(int, SYSLaunchMenu, void); -EXPORT_DECL(int, SYSCheckTitleExists, u64 titleId); -EXPORT_DECL(int, SYSLaunchTitle, u64 titleId); - -void InitAcquireSys(void) -{ - OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); -} - -void InitSysFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - InitAcquireSys(); - - OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher); - OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle); - OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu); - OS_FIND_EXPORT(sysapp_handle, SYSCheckTitleExists); - OS_FIND_EXPORT(sysapp_handle, SYSLaunchTitle); -} diff --git a/src/dynamic_libs/sys_functions.h b/src/dynamic_libs/sys_functions.h deleted file mode 100644 index 08ca21b..0000000 --- a/src/dynamic_libs/sys_functions.h +++ /dev/null @@ -1,47 +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 - -extern unsigned int sysapp_handle; - -void InitSysFunctionPointers(void); -void InitAcquireSys(void); - -extern int(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero); -extern int (* SYSRelaunchTitle)(int argc, char** argv); -extern int (* SYSLaunchMenu)(void); -extern int (* SYSCheckTitleExists)(u64 titleId); -extern int (* SYSLaunchTitle)(u64 titleId); - - -#ifdef __cplusplus -} -#endif - -#endif // __SYS_FUNCTIONS_H_ diff --git a/src/dynamic_libs/syshid_functions.c b/src/dynamic_libs/syshid_functions.c deleted file mode 100644 index 996d39d..0000000 --- a/src/dynamic_libs/syshid_functions.c +++ /dev/null @@ -1,78 +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 "syshid_functions.h" - -unsigned int syshid_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(int, HIDSetup,void); -EXPORT_DECL(int, HIDTeardown,void); - -EXPORT_DECL(int, HIDAddClient,HIDClient *p_client, HIDAttachCallback attach_callback); -EXPORT_DECL(int, HIDDelClient,HIDClient *p_client); - -EXPORT_DECL(int, HIDGetDescriptor,unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); -EXPORT_DECL(int, HIDSetDescriptor,unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); - -EXPORT_DECL(int, HIDSetProtocol,unsigned int handle,u8 interface_index,u8 protocol, HIDCallback hc, void *p_user); -EXPORT_DECL(int, HIDGetProtocol,unsigned int handle,u8 interface_index,u8 * protocol, HIDCallback hc, void *p_user); - -EXPORT_DECL(int, HIDGetReport,u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user); -EXPORT_DECL(int, HIDSetReport,u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user); - -EXPORT_DECL(int, HIDSetIdle,unsigned int handle, u8 interface_index,u8 duration, HIDCallback hc, void *p_user); - -EXPORT_DECL(int, HIDRead,unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); -EXPORT_DECL(int, HIDWrite,unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); - -void InitAcquireSysHID(void) -{ - OSDynLoad_Acquire("nsyshid.rpl", &syshid_handle); -} - -void InitSysHIDFunctionPointers(void) -{ - InitAcquireSysHID(); - - if(syshid_handle == 0){ - return; - } - - unsigned int funcPointer = 0; - - //! assigning those is not mandatory and it does not always work to load them - OS_FIND_EXPORT(syshid_handle, HIDSetup); - OS_FIND_EXPORT(syshid_handle, HIDTeardown); - OS_FIND_EXPORT(syshid_handle, HIDAddClient); - OS_FIND_EXPORT(syshid_handle, HIDDelClient); - OS_FIND_EXPORT(syshid_handle, HIDGetDescriptor); - OS_FIND_EXPORT(syshid_handle, HIDSetDescriptor); - OS_FIND_EXPORT(syshid_handle, HIDRead); - OS_FIND_EXPORT(syshid_handle, HIDWrite); - OS_FIND_EXPORT(syshid_handle, HIDSetProtocol); - OS_FIND_EXPORT(syshid_handle, HIDGetProtocol); - OS_FIND_EXPORT(syshid_handle, HIDSetIdle); - OS_FIND_EXPORT(syshid_handle, HIDGetReport); - OS_FIND_EXPORT(syshid_handle, HIDSetReport); -} diff --git a/src/dynamic_libs/syshid_functions.h b/src/dynamic_libs/syshid_functions.h deleted file mode 100644 index 08213b4..0000000 --- a/src/dynamic_libs/syshid_functions.h +++ /dev/null @@ -1,90 +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 __SYSHID_FUNCTIONS_H_ -#define __SYSHID_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern unsigned int syshid_handle; - -typedef struct -{ - unsigned int handle; - unsigned int physical_device_inst; - unsigned short vid; - unsigned short pid; - unsigned char interface_index; - unsigned char sub_class; - unsigned char protocol; - - unsigned short max_packet_size_rx; - unsigned short max_packet_size_tx; - -} HIDDevice; - -typedef struct _HIDClient HIDClient; - -#define HID_DEVICE_DETACH 0 -#define HID_DEVICE_ATTACH 1 - -typedef int (*HIDAttachCallback)(HIDClient *p_hc,HIDDevice *p_hd,unsigned int attach); - -struct _HIDClient -{ - HIDClient *next; - HIDAttachCallback attach_cb; -}; - -typedef void (*HIDCallback)(unsigned int handle,int error,unsigned char *p_buffer,unsigned int bytes_transferred,void *p_user); - -void InitSysHIDFunctionPointers(void); -void InitAcquireSysHID(void); - -extern int(*HIDSetup)(void); -extern int(*HIDTeardown)(void); - -extern int(*HIDAddClient)(HIDClient *p_client, HIDAttachCallback attach_callback); -extern int(*HIDDelClient)(HIDClient *p_client); - -extern int(*HIDGetDescriptor)(unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); -extern int(*HIDSetDescriptor)(unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); - -extern int(*HIDGetReport)(u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user); -extern int(*HIDSetReport)(u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user); - -extern int(*HIDSetIdle)(unsigned int handle, u8 interface_index,u8 duration, HIDCallback hc, void *p_user); - -extern int(* HIDSetProtocol)(unsigned int handle,u8 interface_index,u8 protocol, HIDCallback hc, void *p_user); -extern int(* HIDGetProtocol)(unsigned int handle,u8 interface_index,u8 * protocol, HIDCallback hc, void *p_user); - -extern int(*HIDRead)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); -extern int(*HIDWrite)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user); - -#ifdef __cplusplus -} -#endif - -#endif // __SYSHID_FUNCTIONS_H_ diff --git a/src/dynamic_libs/vpad_functions.c b/src/dynamic_libs/vpad_functions.c deleted file mode 100644 index 201cf34..0000000 --- a/src/dynamic_libs/vpad_functions.c +++ /dev/null @@ -1,55 +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" - -unsigned int vpad_handle __attribute__((section(".data"))) = 0; -unsigned int vpadbase_handle __attribute__((section(".data"))) = 0; - -EXPORT_DECL(void, VPADInit, void); -EXPORT_DECL(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error); -EXPORT_DECL(int, VPADGetLcdMode, int padnum, int *lcdmode); -EXPORT_DECL(int, VPADSetLcdMode, int padnum, int lcdmode); -EXPORT_DECL(int, VPADBASEGetMotorOnRemainingCount, int padnum); -EXPORT_DECL(int, VPADBASESetMotorOnRemainingCount, int padnum, int counter); - -void InitAcquireVPad(void) -{ - OSDynLoad_Acquire("vpad.rpl", &vpad_handle); - OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle); -} - -void InitVPadFunctionPointers(void) -{ - unsigned int *funcPointer = 0; - - InitAcquireVPad(); - - OS_FIND_EXPORT(vpad_handle, VPADInit); - OS_FIND_EXPORT(vpad_handle, VPADRead); - OS_FIND_EXPORT(vpad_handle, VPADGetLcdMode); - OS_FIND_EXPORT(vpad_handle, VPADSetLcdMode); - OS_FIND_EXPORT(vpadbase_handle, VPADBASEGetMotorOnRemainingCount); - OS_FIND_EXPORT(vpadbase_handle, VPADBASESetMotorOnRemainingCount); -} diff --git a/src/dynamic_libs/vpad_functions.h b/src/dynamic_libs/vpad_functions.h deleted file mode 100644 index 4fafda2..0000000 --- a/src/dynamic_libs/vpad_functions.h +++ /dev/null @@ -1,114 +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 - -extern unsigned int vpad_handle; -extern unsigned int vpadbase_handle; - -#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 - -//! Own definitions -#define VPAD_BUTTON_TOUCH 0x00080000 -#define VPAD_MASK_EMULATED_STICKS 0x7F800000 -#define VPAD_MASK_BUTTONS ~VPAD_MASK_EMULATED_STICKS - -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); -void InitAcquireVPad(void); - -extern int (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error); -extern int (* VPADGetLcdMode)(int padnum, int *lcdmode); -extern int (* VPADSetLcdMode)(int padnum, int lcdmode); -extern void (* VPADInit)(void); -extern int (* VPADBASEGetMotorOnRemainingCount)(int lcdmode); -extern int (* VPADBASESetMotorOnRemainingCount)(int lcdmode,int counter); - -#ifdef __cplusplus -} -#endif - -#endif // __VPAD_FUNCTIONS_H_ diff --git a/src/entry.c b/src/entry.c index 759cee0..ea0bfce 100644 --- a/src/entry.c +++ b/src/entry.c @@ -1,11 +1,12 @@ #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" -int __entry_menu(int argc, char **argv) +static volatile uint8_t ucRunOnce = 0; + +int main(int argc, char **argv) { //! ******************************************************************* //! * Jump to our application * diff --git a/src/fs/CFile.cpp b/src/fs/CFile.cpp index b26cbf5..161b980 100644 --- a/src/fs/CFile.cpp +++ b/src/fs/CFile.cpp @@ -2,7 +2,6 @@ #include #include "CFile.hpp" - CFile::CFile() { iFd = -1; diff --git a/src/fs/CFile.hpp b/src/fs/CFile.hpp index a95d3cd..0203162 100644 --- a/src/fs/CFile.hpp +++ b/src/fs/CFile.hpp @@ -4,9 +4,9 @@ #include #include #include -#include -#include #include +#include +#include "common/types.h" class CFile { diff --git a/src/fs/DirList.cpp b/src/fs/DirList.cpp index 147deaf..c37b504 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 maxDepth) { - this->LoadPath(path, filter, flags); + this->LoadPath(path, filter, flags, maxDepth); 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 maxDepth) { if(folder.empty()) return false; Flags = flags; Filter = filter; + Depth = maxDepth; std::string folderpath(folder); u32 length = folderpath.size(); @@ -69,6 +71,10 @@ 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); } @@ -94,14 +100,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..ea5c20c 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 maxDepth = 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 maxDepth = 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 8c4d5c8..ffadd89 100644 --- a/src/fs/fs_utils.c +++ b/src/fs/fs_utils.c @@ -3,14 +3,15 @@ #include #include #include -#include "dynamic_libs/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; @@ -20,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..c35432d 100644 --- a/src/gui/FreeTypeGX.cpp +++ b/src/gui/FreeTypeGX.cpp @@ -20,10 +20,9 @@ * along with FreeTypeGX. If not, see . */ -#include "FreeTypeGX.h" #include "video/CVideo.h" #include "video/shaders/Texture2DShader.h" -#include "utils/logger.h" +#include "FreeTypeGX.h" using namespace std; @@ -36,7 +35,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 +162,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 +234,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 +276,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 +294,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 +389,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 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/GameIcon.cpp b/src/gui/GameIcon.cpp index 2e1aa73..ca051ac 100644 --- a/src/gui/GameIcon.cpp +++ b/src/gui/GameIcon.cpp @@ -41,12 +41,12 @@ GameIcon::GameIcon(const std::string & filename, GuiImageData *preloadImage) if(posVtxs) { memcpy((f32*)posVtxs, cfGameIconPosVtxs, sizeof(cfGameIconPosVtxs)); - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, (f32*)posVtxs, sizeof(cfGameIconPosVtxs)); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (f32*)posVtxs, sizeof(cfGameIconPosVtxs)); } if(texCoords) { memcpy((f32*)texCoords, cfGameIconTexCoords, sizeof(cfGameIconTexCoords)); - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, (f32*)texCoords, sizeof(cfGameIconTexCoords)); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (f32*)texCoords, sizeof(cfGameIconTexCoords)); } //! create vertexes for the mirror frame @@ -59,7 +59,7 @@ GameIcon::GameIcon(const std::string & filename, GuiImageData *preloadImage) texCoordsMirror[i*2 + 0] = texCoords[i*2 + 0] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f); texCoordsMirror[i*2 + 1] = texCoords[i*2 + 1] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f); } - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, texCoordsMirror, sizeof(cfGameIconTexCoords)); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoordsMirror, sizeof(cfGameIconTexCoords)); } //! setup stroke of the icon @@ -67,7 +67,7 @@ GameIcon::GameIcon(const std::string & filename, GuiImageData *preloadImage) if(strokePosVtxs) { memcpy(strokePosVtxs, cfGameIconStrokeVtxs, sizeof(cfGameIconStrokeVtxs)); - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, strokePosVtxs, sizeof(cfGameIconStrokeVtxs)); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokePosVtxs, sizeof(cfGameIconStrokeVtxs)); } strokeTexCoords = (f32*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); if(strokeTexCoords) @@ -77,14 +77,14 @@ GameIcon::GameIcon(const std::string & filename, GuiImageData *preloadImage) strokeTexCoords[n] = (1.0f + strokePosVtxs[i]) * 0.5f; strokeTexCoords[n+1] = 1.0f - (1.0f + strokePosVtxs[i+1]) * 0.5f; } - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, strokeTexCoords, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeTexCoords, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); } strokeColorVtxs = (u8*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); if(strokeColorVtxs) { for(size_t i = 0; i < (cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); i++) strokeColorVtxs[i] = 0xff; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, strokeColorVtxs, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeColorVtxs, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); } } @@ -236,14 +236,14 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm:: Shader3D::instance()->setModelViewMtx(m_iconView); Shader3D::instance()->setColorIntensity(colorIntensity); Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoords); - Shader3D::instance()->draw(GX2_PRIMITIVE_QUADS, vtxCount); + Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); } if(bSelected) { strokeFractalEnable = 0; - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_DISABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL); m_strokeView = glm::scale(m_iconView, glm::vec3(selectionBlurOuterSize, selectionBlurOuterSize, 0.0f)); ShaderFractalColor::instance()->setShaders(); ShaderFractalColor::instance()->setProjectionMtx(projectionMtx); @@ -260,7 +260,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm:: ShaderFractalColor::instance()->setBlurBorder(selectionBlurInnerBorderSize); ShaderFractalColor::instance()->setColorIntensity(selectionBlurInnerColorIntensity); ShaderFractalColor::instance()->draw(); - GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL); + GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); } if(iDraw == RENDER_NORMAL && bRenderStroke) @@ -280,7 +280,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm:: ShaderFractalColor::instance()->setColorIntensity(colorIntensity); ShaderFractalColor::instance()->setAlphaFadeOut(*alphaFadeOut); ShaderFractalColor::instance()->setAttributeBuffer(cuGameIconStrokeVtxCount, strokePosVtxs, strokeTexCoords, strokeColorVtxs); - ShaderFractalColor::instance()->draw(GX2_PRIMITIVE_LINE_STRIP, cuGameIconStrokeVtxCount); + ShaderFractalColor::instance()->draw(GX2_PRIMITIVE_MODE_LINE_STRIP, cuGameIconStrokeVtxCount); } @@ -294,7 +294,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm:: Shader3D::instance()->setModelViewMtx(m_mirrorView); Shader3D::instance()->setColorIntensity(colorIntensityMirror); Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoordsMirror); - Shader3D::instance()->draw(GX2_PRIMITIVE_QUADS, vtxCount); + Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); if(bIconLast) { @@ -309,7 +309,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm:: Shader3D::instance()->setModelViewMtx(m_iconView); Shader3D::instance()->setColorIntensity(colorIntensity); Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoords); - Shader3D::instance()->draw(GX2_PRIMITIVE_QUADS, vtxCount); + Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); } //! return back normal culling diff --git a/src/gui/GridBackground.cpp b/src/gui/GridBackground.cpp index d027ab8..64f7c7e 100644 --- a/src/gui/GridBackground.cpp +++ b/src/gui/GridBackground.cpp @@ -25,7 +25,7 @@ GridBackground::GridBackground(GuiImageData *img) m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 0.0f; m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 1.0f; m_posVtxs[i++] = 0.0f; m_posVtxs[i++] = -1.0f; m_posVtxs[i++] = -1.0f; m_posVtxs[i++] = 0.0f; m_posVtxs[i++] = -1.0f; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, m_posVtxs, vtxCount * Shader3D::cuVertexAttrSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, m_posVtxs, vtxCount * Shader3D::cuVertexAttrSize); } if(m_texCoords) @@ -50,7 +50,7 @@ GridBackground::GridBackground(GuiImageData *img) m_texCoords[i*2 + 1] = texCoordVec[i][1]; } - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, m_texCoords, vtxCount * Shader3D::cuTexCoordAttrSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, m_texCoords, vtxCount * Shader3D::cuTexCoordAttrSize); } //! assign to internal variables which are const but oh well @@ -96,5 +96,5 @@ void GridBackground::draw(CVideo *pVideo, const glm::mat4 & modelView) Shader3D::instance()->setAlphaFadeOut(alphaFadeOut); Shader3D::instance()->setColorIntensity(colorIntensity); Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoords); - Shader3D::instance()->draw(GX2_PRIMITIVE_QUADS, vtxCount); + Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); } diff --git a/src/gui/GuiButton.cpp b/src/gui/GuiButton.cpp index ae05a8d..bd5c6ee 100644 --- a/src/gui/GuiButton.cpp +++ b/src/gui/GuiButton.cpp @@ -15,7 +15,6 @@ * along with this program. If not, see . ****************************************************************************/ #include "GuiButton.h" -#include "GuiTrigger.h" #include "GuiController.h" /** @@ -162,14 +161,12 @@ void GuiButton::draw(CVideo *v) return; // draw image - if((isDrawOverOnlyWhenSelected() && (isStateSet(STATE_SELECTED) && imageOver)) || - (!isDrawOverOnlyWhenSelected() && (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && imageOver))) + if(isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && imageOver) imageOver->draw(v); else if(image) image->draw(v); - if((isDrawOverOnlyWhenSelected() && (isStateSet(STATE_SELECTED) && iconOver)) || - (!isDrawOverOnlyWhenSelected() && (isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && iconOver))) + if(isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && iconOver) iconOver->draw(v); else if(icon) icon->draw(v); @@ -186,9 +183,9 @@ void GuiButton::draw(CVideo *v) void GuiButton::update(GuiController * c) { - if(!c || isStateSet(STATE_DISABLED|STATE_HIDDEN|STATE_DISABLE_INPUT, c->chan)) + if(!c || isStateSet(STATE_DISABLED, c->chan) || isStateSet(STATE_HIDDEN, c->chan)) return; - else if(parentElement && (parentElement->isStateSet(STATE_DISABLED|STATE_HIDDEN|STATE_DISABLE_INPUT, c->chan))) + else if(parentElement && (parentElement->isStateSet(STATE_DISABLED, c->chan) || parentElement->isStateSet(STATE_HIDDEN, c->chan))) return; if(selectable) @@ -239,10 +236,9 @@ void GuiButton::update(GuiController * c) // button triggers if(clickable) { + bool isClicked = trigger[i]->clicked(c); - int isClicked = trigger[i]->clicked(c); - - if( !clickedTrigger && (isClicked != GuiTrigger::CLICKED_NONE) + if( !clickedTrigger && isClicked && (trigger[i]->isClickEverywhere() || (isStateSet(STATE_SELECTED | STATE_OVER, c->chan) && trigger[i]->isSelectionClickEverywhere()) || this->isInside(c->data.x, c->data.y))) { if(soundClick) @@ -250,23 +246,16 @@ void GuiButton::update(GuiController * c) clickedTrigger = trigger[i]; - if(!isStateSet(STATE_CLICKED, c->chan)){ - if(isClicked == GuiTrigger::CLICKED_TOUCH){ - setState(STATE_CLICKED_TOUCH, c->chan); - }else{ - setState(STATE_CLICKED, c->chan); - } - } + if(!isStateSet(STATE_CLICKED, c->chan)) + setState(STATE_CLICKED, c->chan); clicked(this, c, trigger[i]); } - else if((isStateSet(STATE_CLICKED, c->chan) || isStateSet(STATE_CLICKED_TOUCH, c->chan)) && (clickedTrigger == trigger[i]) && !isStateSet(STATE_HELD, c->chan) && !trigger[i]->held(c) && ((isClicked == GuiTrigger::CLICKED_NONE) || trigger[i]->released(c))) + else if(isStateSet(STATE_CLICKED, c->chan) && (clickedTrigger == trigger[i]) && !isStateSet(STATE_HELD, c->chan) && !trigger[i]->held(c) && (!isClicked || trigger[i]->released(c))) { - if((isStateSet(STATE_CLICKED_TOUCH, c->chan) && this->isInside(c->data.x, c->data.y)) || (isStateSet(STATE_CLICKED, c->chan))){ - clickedTrigger = NULL; - clearState(STATE_CLICKED, c->chan); - released(this, c, trigger[i]); - } + clickedTrigger = NULL; + clearState(STATE_CLICKED, c->chan); + released(this, c, trigger[i]); } } diff --git a/src/gui/GuiButton.h b/src/gui/GuiButton.h index 0e08d42..7755812 100644 --- a/src/gui/GuiButton.h +++ b/src/gui/GuiButton.h @@ -85,7 +85,7 @@ class GuiButton : public GuiElement //!Constantly called to allow the GuiButton to respond to updated input data //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD void update(GuiController * c); - + sigslot::signal2 selected; sigslot::signal2 deSelected; sigslot::signal2 pointedOn; @@ -94,7 +94,7 @@ class GuiButton : public GuiElement sigslot::signal3 held; sigslot::signal3 released; protected: - static const int iMaxGuiTriggers = 10; + static const int iMaxGuiTriggers = 7; GuiImage * image; //!< Button image (default) GuiImage * imageOver; //!< Button image for STATE_SELECTED diff --git a/src/gui/GuiElement.cpp b/src/gui/GuiElement.cpp index e79253b..e1061d9 100644 --- a/src/gui/GuiElement.cpp +++ b/src/gui/GuiElement.cpp @@ -42,7 +42,6 @@ GuiElement::GuiElement() selectable = false; clickable = false; holdable = false; - drawOverOnlyWhenSelected = false; visible = true; yoffsetDyn = 0; xoffsetDyn = 0; diff --git a/src/gui/GuiElement.h b/src/gui/GuiElement.h index 6ae9261..941818a 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/GuiFrame.cpp b/src/gui/GuiFrame.cpp index ac37917..77552c8 100644 --- a/src/gui/GuiFrame.cpp +++ b/src/gui/GuiFrame.cpp @@ -51,9 +51,16 @@ void GuiFrame::append(GuiElement* e) if (e == NULL) return; - remove(e); - elements.push_back(e); - e->setParent(this); + e->setParent(this); + + ListChangeElement elem; + elem.addElement = true; + elem.position = -1; + elem.element = e; + + queueMutex.lock(); + listChangeQueue.push(elem); + queueMutex.unlock(); } void GuiFrame::insert(GuiElement* e, u32 index) @@ -61,9 +68,16 @@ void GuiFrame::insert(GuiElement* e, u32 index) if (e == NULL || (index >= elements.size())) return; - remove(e); - elements.insert(elements.begin()+index, e); - e->setParent(this); + e->setParent(this); + + ListChangeElement elem; + elem.addElement = true; + elem.position = index; + elem.element = e; + + queueMutex.lock(); + listChangeQueue.push(elem); + queueMutex.unlock(); } void GuiFrame::remove(GuiElement* e) @@ -71,14 +85,14 @@ void GuiFrame::remove(GuiElement* e) if (e == NULL) return; - for (u32 i = 0; i < elements.size(); ++i) - { - if(e == elements[i]) - { - elements.erase(elements.begin()+i); - break; - } - } + ListChangeElement elem; + elem.addElement = false; + elem.position = -1; + elem.element = e; + + queueMutex.lock(); + listChangeQueue.push(elem); + queueMutex.unlock(); } void GuiFrame::removeAll() @@ -185,34 +199,21 @@ void GuiFrame::draw(CVideo * v) void GuiFrame::updateEffects() { - if(!this->isVisible() && parentElement) - return; + if(this->isVisible() || parentElement) + { + GuiElement::updateEffects(); - GuiElement::updateEffects(); + //! render appended items next frame but allow stop of render if size is reached + u32 size = elements.size(); - //! render appended items next frame but allow stop of render if size is reached - u32 size = elements.size(); + for (u32 i = 0; i < size && i < elements.size(); ++i) + { + elements[i]->updateEffects(); + } + } - for (u32 i = 0; i < size && i < elements.size(); ++i) - { - elements[i]->updateEffects(); - } -} - -void GuiFrame::process() -{ - if(!this->isVisible() && parentElement) - return; - - GuiElement::process(); - - //! render appended items next frame but allow stop of render if size is reached - u32 size = elements.size(); - - for (u32 i = 0; i < size && i < elements.size(); ++i) - { - elements[i]->process(); - } + //! at the end of main loop which this function represents append pending elements + updateElementList(); } void GuiFrame::update(GuiController * c) @@ -228,3 +229,39 @@ void GuiFrame::update(GuiController * c) elements[i]->update(c); } } + +void GuiFrame::updateElementList(void) +{ + if(listChangeQueue.empty() == false) + { + queueMutex.lock(); + while(!listChangeQueue.empty()) + { + ListChangeElement & listChange = listChangeQueue.front(); + + for (u32 i = 0; i < elements.size(); ++i) + { + if(listChange.element == elements[i]) + { + elements.erase(elements.begin()+i); + break; + } + } + + if(listChange.addElement) + { + if(listChange.position >= 0) + { + elements.insert(elements.begin()+listChange.position, listChange.element); + } + else + { + elements.push_back(listChange.element); + } + } + listChangeQueue.pop(); + } + queueMutex.unlock(); + } + +} diff --git a/src/gui/GuiFrame.h b/src/gui/GuiFrame.h index e0a5c36..2a1eeee 100644 --- a/src/gui/GuiFrame.h +++ b/src/gui/GuiFrame.h @@ -84,8 +84,6 @@ class GuiFrame : public GuiElement virtual void exec() {} //!virtual updateEffects which is called by the main loop virtual void updateEffects(); - //!virtual process which is called by the main loop - virtual void process(); //! Signals //! On Closing sigslot::signal1 closing; @@ -93,6 +91,17 @@ class GuiFrame : public GuiElement bool dim; //! Enable/disable dim of a window only GuiFrame *parent; //!< Parent Window std::vector elements; //!< Contains all elements within the GuiFrame + + void updateElementList(void); + + struct ListChangeElement + { + bool addElement; + int position; + GuiElement *element; + }; + std::queue listChangeQueue; + CMutex queueMutex; }; #endif 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 f798997..78208b9 100644 --- a/src/gui/GuiImageAsync.cpp +++ b/src/gui/GuiImageAsync.cpp @@ -55,7 +55,7 @@ GuiImageAsync::~GuiImageAsync() if (imgData) delete imgData; - //threadExit(); + threadExit(); } void GuiImageAsync::threadAddImage(GuiImageAsync *Image) @@ -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); @@ -138,7 +138,7 @@ void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg) pInUse->imgData = NULL; } } - pInUse->imageLoaded(pInUse); + pInUse = NULL; } } @@ -159,10 +159,9 @@ void GuiImageAsync::threadInit() void GuiImageAsync::threadExit() { - if(threadRefCounter) - --threadRefCounter; + --threadRefCounter; - if(/*(threadRefCounter == 0) &&*/ (pThread != NULL)) + if((threadRefCounter == 0) && (pThread != NULL)) { bExitRequested = true; delete pThread; diff --git a/src/gui/GuiImageAsync.h b/src/gui/GuiImageAsync.h index bf2622a..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 { @@ -34,13 +33,9 @@ class GuiImageAsync : public GuiImage static void removeFromQueue(GuiImageAsync * image) { threadRemoveImage(image); } - - //! don't forget to LOCK GUI if using this asynchron call - sigslot::signal1 imageLoaded; - static void threadExit(); - private: static void threadInit(); + static void threadExit(); GuiImageData *imgData; std::string filename; diff --git a/src/gui/GuiImageData.cpp b/src/gui/GuiImageData.cpp index 7e9a790..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; @@ -87,12 +89,12 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t //! not needed for now therefore comment out to safe ELF size //! if needed uncomment, adds 200 kb to the ELF size // IMAGE_JPEG - gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img); + //gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img); } else if (img[0] == 'B' && img[1] == 'M') { // IMAGE_BMP - gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img); + //gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img); } else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G') { @@ -103,7 +105,7 @@ void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int t else if(img[0] == 0x00) { // Try loading TGA image - gdImg = gdImageCreateFromTgaPtr(imgSize, (u8*) img); + //gdImg = gdImageCreateFromTgaPtr(imgSize, (u8*) img); } if(gdImg == 0) @@ -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 e39930f..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); @@ -62,8 +62,8 @@ GuiParticleImage::GuiParticleImage(int w, int h, u32 particleCount) particles[i].position.y = getRandMinusOneToOneF32() * getHeight() * 0.5f; particles[i].position.z = 0.0f; particles[i].colors = glm::vec4(1.0f, 1.0f, 1.0f, (getRandZeroToOneF32() * 0.6f) + 0.05f); - particles[i].radius = getRandZeroToOneF32() * 30.0f + 60.0f; - particles[i].speed = (getRandZeroToOneF32() * 0.4f) + 0.6f; + particles[i].radius = getRandZeroToOneF32() * 30.0f; + particles[i].speed = (getRandZeroToOneF32() * 0.6f) + 0.2f; particles[i].direction = getRandMinusOneToOneF32(); } } @@ -97,8 +97,8 @@ void GuiParticleImage::draw(CVideo *pVideo) particles[i].position.x = getRandMinusOneToOneF32() * getWidth() * 0.5f; particles[i].position.y = -getHeight() * 0.5f - 30.0f; particles[i].colors = glm::vec4(1.0f, 1.0f, 1.0f, (getRandZeroToOneF32() * 0.6f) + 0.05f); - particles[i].radius = getRandZeroToOneF32() * 30.0f + 60.0f; - particles[i].speed = (getRandZeroToOneF32() * 0.4f) + 0.6f; + particles[i].radius = getRandZeroToOneF32() * 30.0f; + particles[i].speed = (getRandZeroToOneF32() * 0.6f) + 0.2f; particles[i].direction = getRandMinusOneToOneF32(); } if(particles[i].position.x < (-getWidth() * 0.5f - 50.0f)) @@ -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 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 5fb8acd..2aa2d5e 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.cpp b/src/gui/GuiTrigger.cpp index 74e9d05..a4a172c 100644 --- a/src/gui/GuiTrigger.cpp +++ b/src/gui/GuiTrigger.cpp @@ -107,22 +107,22 @@ bool GuiTrigger::down(const GuiController *controller) const return false; } -int GuiTrigger::clicked(const GuiController *controller) const +bool GuiTrigger::clicked(const GuiController *controller) const { if((controller->chan & chan) == 0) { - return CLICKED_NONE; + return false; } - int bResult = CLICKED_NONE; + bool bResult = false; if(controller->data.touched && controller->data.validPointer && (btns & VPAD_TOUCH) && !controller->lastData.touched) { - bResult = CLICKED_TOUCH; + bResult = true; } if(controller->data.buttons_d & btns) { - bResult = CLICKED_BUTTON; + bResult = true; } return bResult; } diff --git a/src/gui/GuiTrigger.h b/src/gui/GuiTrigger.h index ea84b67..46a50e1 100644 --- a/src/gui/GuiTrigger.h +++ b/src/gui/GuiTrigger.h @@ -17,18 +17,12 @@ #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 { public: - enum eClicked{ - CLICKED_NONE = 0x00, - CLICKED_TOUCH = 0x01, - CLICKED_BUTTON = 0x02, - }; enum eChannels { CHANNEL_1 = 0x01, CHANNEL_2 = 0x02, @@ -91,7 +85,7 @@ public: bool right(const GuiController *controller) const; bool up(const GuiController *controller) const; bool down(const GuiController *controller) const; - int clicked(const GuiController *controller) const; + bool clicked(const GuiController *controller) const; bool held(const GuiController *controller) const; bool released(const GuiController *controller) const; private: diff --git a/src/gui/VPadController.h b/src/gui/VPadController.h index 5223774..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,27 +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)/1211.0f)*width) >> 12)-30; - data.y = -(height >> 1) + ((int)(vpad.tpdata1.y * ((height)/653.0f)*height) >> 12)-35; - + 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/kernel/kernel_functions.c b/src/kernel/kernel_functions.c deleted file mode 100644 index 31f9ad0..0000000 --- a/src/kernel/kernel_functions.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include "common/common.h" -#include "common/kernel_defs.h" -#include "kernel/kernel_functions.h" -#include "kernel/syscalls.h" - -/* our retain data */ -ReducedCosAppXmlInfo cosAppXmlInfoStruct __attribute__((section(".data"))); -/* - * This function is a kernel hook function. It is called directly from kernel code at position 0xFFF18558. - */ -void my_PrepareTitle(CosAppXmlInfo *xmlKernelInfo) -{ - /** - * DBAT for access to our data region is setup at this point for the 0xC0000000 area. - */ - - //! Copy all data from the XML info - strncpy(cosAppXmlInfoStruct.rpx_name, xmlKernelInfo->rpx_name, FS_MAX_ENTNAME_SIZE); - - cosAppXmlInfoStruct.version_cos_xml = xmlKernelInfo->version_cos_xml; - cosAppXmlInfoStruct.os_version = xmlKernelInfo->os_version; - cosAppXmlInfoStruct.title_id = xmlKernelInfo->title_id; - cosAppXmlInfoStruct.app_type = xmlKernelInfo->app_type; - cosAppXmlInfoStruct.cmdFlags = xmlKernelInfo->cmdFlags; - cosAppXmlInfoStruct.max_size = xmlKernelInfo->max_size; - cosAppXmlInfoStruct.avail_size = xmlKernelInfo->avail_size; - cosAppXmlInfoStruct.codegen_size = xmlKernelInfo->codegen_size; - cosAppXmlInfoStruct.codegen_core = xmlKernelInfo->codegen_core; - cosAppXmlInfoStruct.max_codesize = xmlKernelInfo->max_codesize; - cosAppXmlInfoStruct.overlay_arena = xmlKernelInfo->overlay_arena; - cosAppXmlInfoStruct.default_stack0_size = xmlKernelInfo->default_stack0_size; - cosAppXmlInfoStruct.default_stack1_size = xmlKernelInfo->default_stack1_size; - cosAppXmlInfoStruct.default_stack2_size = xmlKernelInfo->default_stack2_size; - cosAppXmlInfoStruct.default_redzone0_size = xmlKernelInfo->default_redzone0_size; - cosAppXmlInfoStruct.default_redzone1_size = xmlKernelInfo->default_redzone1_size; - cosAppXmlInfoStruct.default_redzone2_size = xmlKernelInfo->default_redzone2_size; - cosAppXmlInfoStruct.exception_stack0_size = xmlKernelInfo->exception_stack0_size; - cosAppXmlInfoStruct.exception_stack1_size = xmlKernelInfo->exception_stack1_size; - cosAppXmlInfoStruct.exception_stack2_size = xmlKernelInfo->exception_stack2_size; - cosAppXmlInfoStruct.sdk_version = xmlKernelInfo->sdk_version; - cosAppXmlInfoStruct.title_version = xmlKernelInfo->title_version; -} - -void SetupKernelCallback(void) -{ - KernelSetupSyscalls(); -} - diff --git a/src/kernel/kernel_functions.h b/src/kernel/kernel_functions.h deleted file mode 100644 index 79b89e4..0000000 --- a/src/kernel/kernel_functions.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __KERNEL_FUNCTIONS_H_ -#define __KERNEL_FUNCTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "common/kernel_defs.h" -#include "syscalls.h" - -void SetupKernelCallback(void); - -extern ReducedCosAppXmlInfo cosAppXmlInfoStruct; - -#ifdef __cplusplus -} -#endif - -#endif // __KERNEL_FUNCTIONS_H_ diff --git a/src/kernel/kernel_hooks.S b/src/kernel/kernel_hooks.S deleted file mode 100644 index 04452c4..0000000 --- a/src/kernel/kernel_hooks.S +++ /dev/null @@ -1,136 +0,0 @@ -# Created by dimok -# This stuff may need a change in different kernel versions -# This is only needed when launched directly through browser and not SD card. - -.section ".kernel_code" - .globl SaveAndResetDataBATs_And_SRs_hook -SaveAndResetDataBATs_And_SRs_hook: - # setup CTR to the position we need to return to - mflr r5 - mtctr r5 - # set link register to its original value - mtlr r7 - # setup us a nice DBAT for our code data with same region as our code - mfspr r5, 560 - mtspr 570, r5 - mfspr r5, 561 - mtspr 571, r5 - # restore the original kernel instructions that we replaced - lwz r5, 0x34(r3) - lwz r6, 0x38(r3) - lwz r7, 0x3C(r3) - lwz r8, 0x40(r3) - lwz r9, 0x44(r3) - lwz r10, 0x48(r3) - lwz r11, 0x4C(r3) - lwz r3, 0x50(r3) - isync - mtsr 7, r5 - # jump back to the position in kernel after our patch (from LR) - bctr - -.extern my_PrepareTitle - .globl my_PrepareTitle_hook -my_PrepareTitle_hook: - # store all registers on stack to avoid issues with the call to C functions - stwu r1, -0x90(r1) - # registers for our own usage - # only need r31 and rest is from tests before, just leaving it for later tests - stw r28, 0x20(r1) - stw r29, 0x24(r1) - stw r30, 0x28(r1) - stw r31, 0x2C(r1) - - stw r3, 0x30(r1) - stw r4, 0x34(r1) - stw r5, 0x38(r1) - stw r6, 0x3C(r1) - stw r7, 0x40(r1) - stw r8, 0x44(r1) - stw r9, 0x48(r1) - stw r10, 0x4C(r1) - stw r11, 0x50(r1) - stw r12, 0x54(r1) - stw r13, 0x58(r1) - stw r14, 0x5C(r1) - stw r15, 0x60(r1) - stw r16, 0x64(r1) - stw r17, 0x68(r1) - stw r18, 0x6C(r1) - stw r19, 0x70(r1) - stw r20, 0x74(r1) - stw r21, 0x78(r1) - stw r22, 0x7C(r1) - - # save original DBAT registers - mfdbatu r28, 0 - mfdbatl r29, 0 - - # setup access to our data memory range - lis r3, 0xC000 - ori r3, r3, 0x1FFF - mtdbatu 0, r3 - lis r3, 0x3000 - ori r3, r3, 0x0012 - mtdbatl 0, r3 - - # memory barrier - eieio - isync - - # save the LR from where we came - mflr r31 - - # the cos.xml/app.xml structure is at the location 0x68 of r11 - # there are actually many places that can be hooked for it - # e.g. 0xFFF16130 and r27 points to this structure - addi r3, r11, 0x68 - - bl my_PrepareTitle - - # restore original DBAT registers - mtdbatu 0, r28 - mtdbatl 0, r29 - - # memory barrier - eieio - isync - - # setup LR to jump back to kernel code - mtlr r31 - - # restore all original values of registers from stack - lwz r28, 0x20(r1) - lwz r29, 0x24(r1) - lwz r30, 0x28(r1) - lwz r31, 0x2C(r1) - - lwz r3, 0x30(r1) - lwz r4, 0x34(r1) - lwz r5, 0x38(r1) - lwz r6, 0x3C(r1) - lwz r7, 0x40(r1) - lwz r8, 0x44(r1) - lwz r9, 0x48(r1) - lwz r10, 0x4C(r1) - lwz r11, 0x50(r1) - lwz r12, 0x54(r1) - lwz r13, 0x58(r1) - lwz r14, 0x5C(r1) - lwz r15, 0x60(r1) - lwz r16, 0x64(r1) - lwz r17, 0x68(r1) - lwz r18, 0x6C(r1) - lwz r19, 0x70(r1) - lwz r20, 0x74(r1) - lwz r21, 0x78(r1) - lwz r22, 0x7C(r1) - - # restore the stack - addi r1, r1, 0x90 - - # restore original instruction that we replaced in the kernel - clrlwi r7, r12, 0 - - # jump back - blr diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c deleted file mode 100644 index 9685e4a..0000000 --- a/src/kernel/syscalls.c +++ /dev/null @@ -1,255 +0,0 @@ -#include "common/os_defs.h" -#include "common/kernel_defs.h" -#include "common/common.h" -#include "dynamic_libs/os_functions.h" -#include "utils/utils.h" -#include "syscalls.h" - -extern void my_PrepareTitle_hook(void); - -static unsigned int origPrepareTitleInstr __attribute__((section(".data"))) = 0; - -static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len) -{ - /* - * Setup a DBAT access with cache inhibited to write through and read directly from memory - */ - unsigned int dbatu0, dbatl0, dbatu1, dbatl1; - // save the original DBAT value - asm volatile("mfdbatu %0, 0" : "=r" (dbatu0)); - asm volatile("mfdbatl %0, 0" : "=r" (dbatl0)); - asm volatile("mfdbatu %0, 1" : "=r" (dbatu1)); - asm volatile("mfdbatl %0, 1" : "=r" (dbatl1)); - - unsigned int target_dbatu0 = 0; - unsigned int target_dbatl0 = 0; - unsigned int target_dbatu1 = 0; - unsigned int target_dbatl1 = 0; - - unsigned char *dst_p = (unsigned char*)addr; - unsigned char *src_p = (unsigned char*)src; - - // we only need DBAT modification for addresses out of our own DBAT range - // as our own DBAT is available everywhere for user and supervisor - // since our own DBAT is on DBAT5 position we don't collide here - if(addr < 0x00800000 || addr >= 0x01000000) - { - target_dbatu0 = (addr & 0x00F00000) | 0xC0000000 | 0x1F; - target_dbatl0 = (addr & 0xFFF00000) | 0x32; - asm volatile("mtdbatu 0, %0" : : "r" (target_dbatu0)); - asm volatile("mtdbatl 0, %0" : : "r" (target_dbatl0)); - dst_p = (unsigned char*)((addr & 0xFFFFFF) | 0xC0000000); - } - if(src < 0x00800000 || src >= 0x01000000) - { - target_dbatu1 = (src & 0x00F00000) | 0xB0000000 | 0x1F; - target_dbatl1 = (src & 0xFFF00000) | 0x32; - - asm volatile("mtdbatu 1, %0" : : "r" (target_dbatu1)); - asm volatile("mtdbatl 1, %0" : : "r" (target_dbatl1)); - src_p = (unsigned char*)((src & 0xFFFFFF) | 0xB0000000); - } - - asm volatile("eieio; isync"); - - unsigned int i; - for(i = 0; i < len; i++) - { - // if we are on the edge to next chunk - if((target_dbatu0 != 0) && (((unsigned int)dst_p & 0x00F00000) != (target_dbatu0 & 0x00F00000))) - { - target_dbatu0 = ((addr + i) & 0x00F00000) | 0xC0000000 | 0x1F; - target_dbatl0 = ((addr + i) & 0xFFF00000) | 0x32; - dst_p = (unsigned char*)(((addr + i) & 0xFFFFFF) | 0xC0000000); - - asm volatile("eieio; isync"); - asm volatile("mtdbatu 0, %0" : : "r" (target_dbatu0)); - asm volatile("mtdbatl 0, %0" : : "r" (target_dbatl0)); - asm volatile("eieio; isync"); - } - if((target_dbatu1 != 0) && (((unsigned int)src_p & 0x00F00000) != (target_dbatu1 & 0x00F00000))) - { - target_dbatu1 = ((src + i) & 0x00F00000) | 0xB0000000 | 0x1F; - target_dbatl1 = ((src + i) & 0xFFF00000) | 0x32; - src_p = (unsigned char*)(((src + i) & 0xFFFFFF) | 0xB0000000); - - asm volatile("eieio; isync"); - asm volatile("mtdbatu 1, %0" : : "r" (target_dbatu1)); - asm volatile("mtdbatl 1, %0" : : "r" (target_dbatl1)); - asm volatile("eieio; isync"); - } - - *dst_p = *src_p; - - ++dst_p; - ++src_p; - } - - /* - * Restore original DBAT value - */ - asm volatile("eieio; isync"); - asm volatile("mtdbatu 0, %0" : : "r" (dbatu0)); - asm volatile("mtdbatl 0, %0" : : "r" (dbatl0)); - asm volatile("mtdbatu 1, %0" : : "r" (dbatu1)); - asm volatile("mtdbatl 1, %0" : : "r" (dbatl1)); - asm volatile("eieio; isync"); -} - -static void KernelReadDBATs(bat_table_t * table) -{ - u32 i = 0; - - asm volatile("eieio; isync"); - - asm volatile("mfspr %0, 536" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 537" : "=r" (table->bat[i].l)); - i++; - asm volatile("mfspr %0, 538" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 539" : "=r" (table->bat[i].l)); - i++; - asm volatile("mfspr %0, 540" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 541" : "=r" (table->bat[i].l)); - i++; - asm volatile("mfspr %0, 542" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 543" : "=r" (table->bat[i].l)); - i++; - - asm volatile("mfspr %0, 568" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 569" : "=r" (table->bat[i].l)); - i++; - asm volatile("mfspr %0, 570" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 571" : "=r" (table->bat[i].l)); - i++; - asm volatile("mfspr %0, 572" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 573" : "=r" (table->bat[i].l)); - i++; - asm volatile("mfspr %0, 574" : "=r" (table->bat[i].h)); - asm volatile("mfspr %0, 575" : "=r" (table->bat[i].l)); -} - -static void KernelWriteDBATs(bat_table_t * table) -{ - u32 i = 0; - - asm volatile("eieio; isync"); - - asm volatile("mtspr 536, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 537, %0" : : "r" (table->bat[i].l)); - i++; - asm volatile("mtspr 538, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 539, %0" : : "r" (table->bat[i].l)); - i++; - asm volatile("mtspr 540, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 541, %0" : : "r" (table->bat[i].l)); - i++; - asm volatile("mtspr 542, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 543, %0" : : "r" (table->bat[i].l)); - i++; - - asm volatile("mtspr 568, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 569, %0" : : "r" (table->bat[i].l)); - i++; - asm volatile("mtspr 570, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 571, %0" : : "r" (table->bat[i].l)); - i++; - asm volatile("mtspr 572, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 573, %0" : : "r" (table->bat[i].l)); - i++; - asm volatile("mtspr 574, %0" : : "r" (table->bat[i].h)); - asm volatile("mtspr 575, %0" : : "r" (table->bat[i].l)); - - asm volatile("eieio; isync"); -} - -/* 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" - ); -} - -void KernelSetupSyscalls(void) -{ - //! assign 1 so that this variable gets into the retained .data section - static uint8_t ucSyscallsSetupRequired = 1; - if(!ucSyscallsSetupRequired) - return; - - ucSyscallsSetupRequired = 0; - - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x36 * 4)), (unsigned int)KernelReadDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x36 * 4)), (unsigned int)KernelReadDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x36 * 4)), (unsigned int)KernelReadDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x36 * 4)), (unsigned int)KernelReadDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x36 * 4)), (unsigned int)KernelReadDBATs); - - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x37 * 4)), (unsigned int)KernelWriteDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x37 * 4)), (unsigned int)KernelWriteDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x37 * 4)), (unsigned int)KernelWriteDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x37 * 4)), (unsigned int)KernelWriteDBATs); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x37 * 4)), (unsigned int)KernelWriteDBATs); - - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x25 * 4)), (unsigned int)KernelCopyData); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x25 * 4)), (unsigned int)KernelCopyData); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x25 * 4)), (unsigned int)KernelCopyData); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x25 * 4)), (unsigned int)KernelCopyData); - kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x25 * 4)), (unsigned int)KernelCopyData); - - //! write our hook to the - u32 addr_my_PrepareTitle_hook = ((u32)my_PrepareTitle_hook) | 0x48000003; - DCFlushRange(&addr_my_PrepareTitle_hook, sizeof(addr_my_PrepareTitle_hook)); - - SC0x25_KernelCopyData((u32)&origPrepareTitleInstr, (u32)addr_PrepareTitle_hook, 4); - SC0x25_KernelCopyData((u32)addr_PrepareTitle_hook, (u32)OSEffectiveToPhysical(&addr_my_PrepareTitle_hook), 4); -} - - -void KernelRestoreInstructions(void) -{ - if(origPrepareTitleInstr != 0) - SC0x25_KernelCopyData((u32)addr_PrepareTitle_hook, (u32)&origPrepareTitleInstr, 4); -} diff --git a/src/kernel/syscalls.h b/src/kernel/syscalls.h deleted file mode 100644 index 344fa39..0000000 --- a/src/kernel/syscalls.h +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef __SYSCALLS_H_ -#define __SYSCALLS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "common/kernel_defs.h" - -void KernelSetupSyscalls(void); -void KernelRestoreInstructions(void); - -void SC0x25_KernelCopyData(unsigned int addr, unsigned int src, unsigned int len); -void SC0x36_KernelReadDBATs(bat_table_t * table); -void SC0x37_KernelWriteDBATs(bat_table_t * table); - -uint32_t __attribute__ ((noinline)) kern_read(const void *addr); -void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value); - -#ifdef __cplusplus -} -#endif - -#endif // __KERNEL_FUNCTIONS_H_ diff --git a/src/kernel/syscalls_asm.S b/src/kernel/syscalls_asm.S deleted file mode 100644 index 60bf1fa..0000000 --- a/src/kernel/syscalls_asm.S +++ /dev/null @@ -1,20 +0,0 @@ -# Created by dimok -# Syscalls for kernel that we use - - .globl SC0x36_KernelReadDBATs -SC0x36_KernelReadDBATs: - li r0, 0x3600 - sc - blr - - .globl SC0x37_KernelWriteDBATs -SC0x37_KernelWriteDBATs: - li r0, 0x3700 - sc - blr - - .globl SC0x25_KernelCopyData -SC0x25_KernelCopyData: - li r0, 0x2500 - sc - blr diff --git a/src/link.ld b/src/link.ld index 30737dc..61f4721 100644 --- a/src/link.ld +++ b/src/link.ld @@ -1,4 +1,4 @@ -OUTPUT(hidtovpad.elf); +OUTPUT(flappy_bird.elf); /* Tell linker where our application entry is so the garbage collect can work correct */ ENTRY(__entry_menu); @@ -6,10 +6,7 @@ ENTRY(__entry_menu); SECTIONS { . = 0x00802000; .text : { - *(.kernel_code*); *(.text*); - /* Tell linker to not garbage collect this section as it is not referenced anywhere */ - KEEP(*(.kernel_code*)); } .rodata : { *(.rodata*); diff --git a/src/main.cpp b/src/main.cpp index f1fd6c3..8b6624a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,65 +1,37 @@ +#include #include "Application.h" -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/gx2_functions.h" -#include "dynamic_libs/syshid_functions.h" -#include "dynamic_libs/vpad_functions.h" -#include "dynamic_libs/padscore_functions.h" -#include "dynamic_libs/socket_functions.h" -#include "dynamic_libs/sys_functions.h" -#include "dynamic_libs/ax_functions.h" -#include "dynamic_libs/fs_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" -#include "main.h" -#include "common/common.h" - -#include "utils/logger.h" - -#include "system/memory.h" - /* Entry point */ -extern "C" int Menu_Main(void){ +extern "C" int Menu_Main(void) +{ //!******************************************************************* //! Initialize function pointers * //!******************************************************************* + socket_lib_init(); //! do OS (for acquire) and sockets first so we got logging - InitOSFunctionPointers(); - InitSocketFunctionPointers(); - InitGX2FunctionPointers(); - InitSysFunctionPointers(); - InitVPadFunctionPointers(); - InitPadScoreFunctionPointers(); - InitAXFunctionPointers(); - InitFSFunctionPointers(); - log_init("192.168.1.12"); - //Otherwise apply the patches!!! - log_printf("GX2_template\n\n"); + InitPadScoreFunctionPointers(); + log_printf("Function exports loaded\n"); + + log_print("Initialize memory management\n"); + memoryInitialize(); //!******************************************************************* //! Initialize heap memory * //!******************************************************************* - log_print("Initialize memory management\n"); - memoryInitialize(); - log_printf("Mount SD partition\n"); - mount_sd_fat("sd"); log_printf("Start main application\n"); Application::instance()->exec(); Application::destroyInstance(); - log_printf("Unmount SD\n"); - unmount_sd_fat("sd"); - memoryRelease(); - - log_print("Going back to the Homebrew launcher\n"); - - log_deinit(); + + log_deinit(); + return EXIT_SUCCESS; } diff --git a/src/main.h b/src/main.h index a0fb71e..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 @@ -11,7 +10,7 @@ extern "C" { //! C wrapper for our C++ functions int Menu_Main(void); -void deInit(void); + #ifdef __cplusplus } #endif diff --git a/src/menu/MainWindow.cpp b/src/menu/MainWindow.cpp index e7f55ab..22300f5 100644 --- a/src/menu/MainWindow.cpp +++ b/src/menu/MainWindow.cpp @@ -17,8 +17,6 @@ ****************************************************************************/ #include "MainWindow.h" #include "MainWindowTV.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/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 c5646f3..6c9dd11 100644 --- a/src/resources/filelist.h +++ b/src/resources/filelist.h @@ -9,111 +9,110 @@ #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 bg_back_png[]; -extern const u32 bg_back_png_size; +extern const unsigned char bgMusic_ogg[]; +extern const unsigned int bgMusic_ogg_size; -extern const u8 bg_front_png[]; -extern const u32 bg_front_png_size; +extern const unsigned char bg_back_png[]; +extern const unsigned int bg_back_png_size; -extern const u8 bgMusic_ogg[]; -extern const u32 bgMusic_ogg_size; +extern const unsigned char bg_front_png[]; +extern const unsigned int bg_front_png_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 flappy_bird_1_png[]; -extern const u32 flappy_bird_1_png_size; +extern const unsigned char flappy_bird_1_png[]; +extern const unsigned int flappy_bird_1_png_size; -extern const u8 flappy_bird_2_png[]; -extern const u32 flappy_bird_2_png_size; +extern const unsigned char flappy_bird_2_png[]; +extern const unsigned int flappy_bird_2_png_size; -extern const u8 flappy_bird_3_png[]; -extern const u32 flappy_bird_3_png_size; +extern const unsigned char flappy_bird_3_png[]; +extern const unsigned int flappy_bird_3_png_size; -extern const u8 flappy_bird_4_png[]; -extern const u32 flappy_bird_4_png_size; +extern const unsigned char flappy_bird_4_png[]; +extern const unsigned int flappy_bird_4_png_size; -extern const u8 font_big_0_png[]; -extern const u32 font_big_0_png_size; +extern const unsigned char font_ttf[]; +extern const unsigned int font_ttf_size; -extern const u8 font_big_1_png[]; -extern const u32 font_big_1_png_size; +extern const unsigned char font_big_0_png[]; +extern const unsigned int font_big_0_png_size; -extern const u8 font_big_2_png[]; -extern const u32 font_big_2_png_size; +extern const unsigned char font_big_1_png[]; +extern const unsigned int font_big_1_png_size; -extern const u8 font_big_3_png[]; -extern const u32 font_big_3_png_size; +extern const unsigned char font_big_2_png[]; +extern const unsigned int font_big_2_png_size; -extern const u8 font_big_4_png[]; -extern const u32 font_big_4_png_size; +extern const unsigned char font_big_3_png[]; +extern const unsigned int font_big_3_png_size; -extern const u8 font_big_5_png[]; -extern const u32 font_big_5_png_size; +extern const unsigned char font_big_4_png[]; +extern const unsigned int font_big_4_png_size; -extern const u8 font_big_6_png[]; -extern const u32 font_big_6_png_size; +extern const unsigned char font_big_5_png[]; +extern const unsigned int font_big_5_png_size; -extern const u8 font_big_7_png[]; -extern const u32 font_big_7_png_size; +extern const unsigned char font_big_6_png[]; +extern const unsigned int font_big_6_png_size; -extern const u8 font_big_8_png[]; -extern const u32 font_big_8_png_size; +extern const unsigned char font_big_7_png[]; +extern const unsigned int font_big_7_png_size; -extern const u8 font_big_9_png[]; -extern const u32 font_big_9_png_size; +extern const unsigned char font_big_8_png[]; +extern const unsigned int font_big_8_png_size; -extern const u8 font_big_null_png[]; -extern const u32 font_big_null_png_size; +extern const unsigned char font_big_9_png[]; +extern const unsigned int font_big_9_png_size; -extern const u8 font_ttf[]; -extern const u32 font_ttf_size; +extern const unsigned char font_big_null_png[]; +extern const unsigned int font_big_null_png_size; -extern const u8 loose_png[]; -extern const u32 loose_png_size; +extern const unsigned char loose_png[]; +extern const unsigned int loose_png_size; -extern const u8 pipe_down_png[]; -extern const u32 pipe_down_png_size; +extern const unsigned char pipe_down_png[]; +extern const unsigned int pipe_down_png_size; -extern const u8 pipe_up_png[]; -extern const u32 pipe_up_png_size; +extern const unsigned char pipe_up_png[]; +extern const unsigned int pipe_up_png_size; -extern const u8 sfx_die_ogg[]; -extern const u32 sfx_die_ogg_size; +extern const unsigned char sfx_die_ogg[]; +extern const unsigned int sfx_die_ogg_size; -extern const u8 sfx_point_ogg[]; -extern const u32 sfx_point_ogg_size; +extern const unsigned char sfx_point_ogg[]; +extern const unsigned int sfx_point_ogg_size; -extern const u8 sfx_swooshing_ogg[]; -extern const u32 sfx_swooshing_ogg_size; +extern const unsigned char sfx_swooshing_ogg[]; +extern const unsigned int sfx_swooshing_ogg_size; -extern const u8 sfx_wing_ogg[]; -extern const u32 sfx_wing_ogg_size; +extern const unsigned char sfx_wing_ogg[]; +extern const unsigned int sfx_wing_ogg_size; -extern const u8 splash_png[]; -extern const u32 splash_png_size; +extern const unsigned char splash_png[]; +extern const unsigned int splash_png_size; static RecourceFile RecourceList[] = { + {"bgMusic.ogg", bgMusic_ogg, bgMusic_ogg_size, NULL, 0}, {"bg_back.png", bg_back_png, bg_back_png_size, NULL, 0}, {"bg_front.png", bg_front_png, bg_front_png_size, NULL, 0}, - {"bgMusic.ogg", bgMusic_ogg, bgMusic_ogg_size, NULL, 0}, {"button_click.mp3", button_click_mp3, button_click_mp3_size, NULL, 0}, {"flappy_bird_1.png", flappy_bird_1_png, flappy_bird_1_png_size, NULL, 0}, {"flappy_bird_2.png", flappy_bird_2_png, flappy_bird_2_png_size, NULL, 0}, {"flappy_bird_3.png", flappy_bird_3_png, flappy_bird_3_png_size, NULL, 0}, {"flappy_bird_4.png", flappy_bird_4_png, flappy_bird_4_png_size, NULL, 0}, + {"font.ttf", font_ttf, font_ttf_size, NULL, 0}, {"font_big_0.png", font_big_0_png, font_big_0_png_size, NULL, 0}, {"font_big_1.png", font_big_1_png, font_big_1_png_size, NULL, 0}, {"font_big_2.png", font_big_2_png, font_big_2_png_size, NULL, 0}, @@ -125,7 +124,6 @@ static RecourceFile RecourceList[] = {"font_big_8.png", font_big_8_png, font_big_8_png_size, NULL, 0}, {"font_big_9.png", font_big_9_png, font_big_9_png_size, NULL, 0}, {"font_big_null.png", font_big_null_png, font_big_null_png_size, NULL, 0}, - {"font.ttf", font_ttf, font_ttf_size, NULL, 0}, {"loose.png", loose_png, loose_png_size, NULL, 0}, {"pipe_down.png", pipe_down_png, pipe_down_png_size, NULL, 0}, {"pipe_up.png", pipe_up_png, pipe_up_png_size, NULL, 0}, 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..2d7ffad 100644 --- a/src/sounds/SoundHandler.cpp +++ b/src/sounds/SoundHandler.cpp @@ -26,7 +26,6 @@ #include #include #include "common/common.h" -#include "dynamic_libs/ax_functions.h" #include "fs/CFile.hpp" #include "SoundHandler.hpp" #include "WavDecoder.hpp" @@ -95,7 +94,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]; @@ -216,19 +219,16 @@ SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length) void SoundHandler::executeThread() { - // v2 sound lib can not properly end transition audio on old firmwares - if (OS_FIRMWARE >= 400 && OS_FIRMWARE <= 410) - { - ProperlyEndTransitionAudio(); - } - //! 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 +239,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 +266,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..ceb4ad7 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) - 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) - 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/AsyncDeleter.cpp b/src/system/AsyncDeleter.cpp index 7b69751..7776989 100644 --- a/src/system/AsyncDeleter.cpp +++ b/src/system/AsyncDeleter.cpp @@ -54,7 +54,7 @@ void AsyncDeleter::executeThread(void) while(!exitApplication) { suspendThread(); - log_printf("AsyncDeleter thread running\n"); + //! delete elements that require post process deleting //! because otherwise they would block or do invalid access on GUI thread while(!realDeleteElements.empty()) diff --git a/src/system/AsyncDeleter.h b/src/system/AsyncDeleter.h index 6cce1fa..5497ad2 100644 --- a/src/system/AsyncDeleter.h +++ b/src/system/AsyncDeleter.h @@ -26,10 +26,8 @@ class AsyncDeleter : public CThread public: static void destroyInstance() { - if(deleterInstance != NULL){ - delete deleterInstance; - deleterInstance = NULL; - } + delete deleterInstance; + deleterInstance = NULL; } class Element @@ -43,6 +41,7 @@ public: { if(!deleterInstance) deleterInstance = new AsyncDeleter; + deleterInstance->deleteElements.push(e); } 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 3fade45..81d8ac2 100644 --- a/src/system/CThread.h +++ b/src/system/CThread.h @@ -17,11 +17,9 @@ #ifndef CTHREAD_H_ #define CTHREAD_H_ -#include #include #include -#include "dynamic_libs/os_functions.h" -#include "utils/logger.h" +#include class CThread { @@ -38,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 @@ -80,17 +78,17 @@ public: //! wait for thread to finish if(pThread && !(iAttributes & eAttributeDetach)) { - while(isThreadSuspended()){ + if(isThreadSuspended()) resumeThread(); - } + OSJoinThread(pThread, NULL); } //! free the thread stack buffer - if(pThreadStack){ + if(pThreadStack) free(pThreadStack); - } if(pThread) free(pThread); + pThread = NULL; pThreadStack = NULL; } @@ -105,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 b642248..9d8a66b 100644 --- a/src/system/exception_handler.c +++ b/src/system/exception_handler.c @@ -1,6 +1,5 @@ #include -#include "dynamic_libs/os_functions.h" -#include "utils/logger.h" +#include "common/types.h" #include "exception_handler.h" #define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4 @@ -36,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 @@ -78,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. */ @@ -147,7 +147,7 @@ static unsigned char exception_cb(void * c, unsigned char exception_type) { for (i = 0; i < 8; i += 4) pos += sprintf(buf + pos, exception_print_formats[17], &(pAdd[i]),pAdd[i], pAdd[i+1], pAdd[i+2], pAdd[i+3]); //} - log_print(buf); + OSFatal(buf); return 1; } @@ -163,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/system/memory_area_table.c b/src/system/memory_area_table.c new file mode 100644 index 0000000..76bcba8 --- /dev/null +++ b/src/system/memory_area_table.c @@ -0,0 +1,397 @@ +/**************************************************************************** + * 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 "common/common.h" +#include "utils/utils.h" +#include "memory_area_table.h" + +typedef struct _memory_values_t +{ + unsigned int start_address; + unsigned int end_address; +} memory_values_t; + +static const memory_values_t mem_vals_400[] = +{ + { 0x2E573BFC, 0x2FF8F83C }, // 26735 kB + { 0x2D86D318, 0x2DFFFFFC }, // 7755 kB + { 0x2CE59830, 0x2D3794D8 }, // 5247 kB + { 0x2D3795AC, 0x2D854300 }, // 4971 kB + { 0x28FEC800, 0x293B29D0 }, // 3864 kB + { 0x29BC200C, 0x29D79B94 }, // 1758 kB + { 0x2A517A68, 0x2A6794B8 }, // 1414 kB + { 0x288C1D80, 0x28A69FA0 }, // 1696 kB + + { 0, 0 } +}; + +static const memory_values_t mem_vals_410[] = +{ +// { 0x28041760, 0x28049D0C } // 33 kB +// { 0x280608F4, 0x2806C97C } // 48 kB +// { 0x280953C8, 0x280A1324 } // 47 kB +// { 0x280A1358, 0x280AD388 } // 48 kB +// { 0x280C9040, 0x280D0ABC } // 30 kB +// { 0x280D0AD8, 0x28113FBC } // 269 kB +// { 0x2812575C, 0x2817A53C } // 339 kB +// { 0x2817A6A0, 0x281BA53C } // 255 kB +// { 0x281D571C, 0x2820253C } // 179 kB +// { 0x28234D00, 0x2824B33C } // 89 kB +// { 0x2824E300, 0x2828D7BC } // 253 kB +// { 0x282A8DF0, 0x282B63FC } // 53 kB +// { 0x282BC524, 0x282C62FC } // 39 kB +// { 0x2835A988, 0x28366804 } // 47 kB +// { 0x2836E05C, 0x28378DBC } // 43 kB +// { 0x283A735C, 0x284D2A64 } // 1197 kB (1 MB) +// { 0x284D76B0, 0x285021FC } // 170 kB +// { 0x285766A4, 0x28583E4C } // 53 kB +// { 0x28590E5C, 0x2859B248 } // 40 kB +// { 0x2859B288, 0x285AE06C } // 75 kB +// { 0x285B7108, 0x285C0A7C } // 38 kB +// { 0x285C38A0, 0x285D089C } // 52 kB +// { 0x285D0A84, 0x285DC63C } // 46 kB +// { 0x285E0A84, 0x285F089C } // 63 kB +// { 0x285F7FD0, 0x286037D8 } // 46 kB +// { 0x2860E3E4, 0x28621B00 } // 77 kB +// { 0x286287B0, 0x28638BC0 } // 65 kB +// { 0x2863F4A0, 0x2864DE00 } // 58 kB +// { 0x2864F1FC, 0x28656EE0 } // 31 kB +// { 0x2865AF44, 0x286635A0 } // 33 kB +// { 0x2866F774, 0x2867C680 } // 51 kB +// { 0x2867FAC0, 0x286A2CA0 } // 140 kB +// { 0x286B3540, 0x286C1900 } // 56 kB +// { 0x286C64A4, 0x286DDB80 } // 93 kB +// { 0x286E640C, 0x286F1DC0 } // 46 kB +// { 0x286F3884, 0x2870D3C0 } // 102 kB +// { 0x28710824, 0x28719D80 } // 37 kB +// { 0x2872A674, 0x2873B180 } // 66 kB +// { 0x287402F0, 0x28758780 } // 97 kB +// { 0x287652F0, 0x28771C00 } // 50 kB +// { 0x287F878C, 0x2880A680 } // 71 kB +// { 0x2880F4AC, 0x2881E6E0 } // 60 kB +// { 0x28821488, 0x28829A40 } // 33 kB +// { 0x2882A5D0, 0x288385BC } // 55 kB +// { 0x288385D8, 0x28854780 } // 112 kB +// { 0x28857984, 0x28864F80 } // 53 kB +// { 0x28870AC0, 0x2887CAC0 } // 48 kB +// { 0x2887CAC8, 0x28888CC8 } // 48 kB +// { 0x28888CD0, 0x28894ED0 } // 48 kB +// { 0x28894ED8, 0x288BE0DC } // 164 kB +// { 0x288C1C70, 0x28AD9ED4 } // 2144 kB (2 MB) +// { 0x28AD9F04, 0x28B66100 } // 560 kB +// { 0x28B748A8, 0x28B952E0 } // 130 kB +// { 0x28B9AB58, 0x28BA2480 } // 30 kB +// { 0x28BA3D00, 0x28BC21C0 } // 121 kB +// { 0x28BC2F08, 0x28BD9860 } // 90 kB +// { 0x28BED09C, 0x28BFDD00 } // 67 kB +// { 0x28C068F0, 0x28C2E220 } // 158 kB +// { 0x28CC4C6C, 0x28CF6834 } // 198 kB +// { 0x28D3DD64, 0x28D4BF8C } // 56 kB +// { 0x28D83C4C, 0x28DD0284 } // 305 kB +// { 0x28DDDED4, 0x28E84294 } // 664 kB +// { 0x28E99C7C, 0x28F382A4 } // 633 kB +// { 0x28F45EF4, 0x28FEC2B4 } // 664 kB +// { 0x28FEC800, 0x293B2A18 } // 3864 kB (3 MB) +// { 0x293E187C, 0x293EC7FC } // 43 kB +// { 0x295C7240, 0x295D523C } // 56 kB +// { 0x295DA8DC, 0x295E323C } // 34 kB +// { 0x295ED6C0, 0x295F6FDC } // 38 kB +// { 0x29606340, 0x2960FC5C } // 38 kB +// { 0x2964F040, 0x29657C3C } // 35 kB +// { 0x296E0EBC, 0x296EBDBC } // 43 kB +// { 0x2998DFB4, 0x2999DEE4 } // 63 kB +// { 0x2999E6A8, 0x299BE9C4 } // 128 kB +// { 0x29B8DF40, 0x29BA09DC } // 74 kB +// { 0x29BC200C, 0x29D79B94 } // 1758 kB (1 MB) +// { 0x29DA9694, 0x29DB1694 } // 32 kB +// { 0x2A3D7558, 0x2A427558 } // 320 kB +// { 0x2A42769C, 0x2A47769C } // 320 kB +// { 0x2A4777E0, 0x2A4C77E0 } // 320 kB +// { 0x2A4C7924, 0x2A517924 } // 320 kB +// { 0x2A517A68, 0x2A6794B8 } // 1414 kB (1 MB) +// { 0x2AD17528, 0x2AD4EA24 } // 221 kB +// { 0x2B038C4C, 0x2B1794C8 } // 1282 kB (1 MB) +// { 0x2BBA990C, 0x2BBB983C } // 63 kB +// { 0x2BBBA160, 0x2BC82164 } // 800 kB +// { 0x2BD0000C, 0x2BD71638 } // 453 kB +// { 0x2BD7170C, 0x2BD83B0C } // 73 kB +// { 0x2BDBA000, 0x2BDCA028 } // 64 kB +// { 0x2BDCE000, 0x2BDDE028 } // 64 kB +// { 0x2BDE2E34, 0x2BDF2D64 } // 63 kB +// { 0x2BDF35E8, 0x2BE031BC } // 62 kB +// { 0x2BE052A4, 0x2BE151D4 } // 63 kB +// { 0x2BE174AC, 0x2BE27244 } // 63 kB +// { 0x2BE3AC80, 0x2BE48C80 } // 56 kB +// { 0x2BE49EDC, 0x2BE56C7C } // 51 kB +// { 0x2BE82F70, 0x2BE92E9C } // 63 kB +// { 0x2BE9ADBC, 0x2BEA8DBC } // 56 kB +// { 0x2BEAAB7C, 0x2BEB6DBC } // 48 kB +// { 0x2BEC0F3C, 0x2BECEF3C } // 56 kB +// { 0x2BED45DC, 0x2BEDCF3C } // 34 kB +// { 0x2BEE73C0, 0x2BEF0CDC } // 38 kB +// { 0x2BF00040, 0x2BF0995C } // 38 kB +// { 0x2BF48D40, 0x2BF5193C } // 35 kB +// { 0x2BFDABBC, 0x2BFE5ABC } // 43 kB +// { 0x2C03DA40, 0x2C045D7C } // 32 kB +// { 0x2C179450, 0x2C18937C } // 63 kB +// { 0x2C1DC940, 0x2C1EA93C } // 56 kB +// { 0x2C1EABDC, 0x2C1F893C } // 55 kB +// { 0x2C239A80, 0x2C243D3C } // 40 kB +// { 0x2CE10224, 0x2CE3683C } // 153 kB +// { 0x2CE374F4, 0x2CE473A4 } // 63 kB +// { 0x2CE49830, 0x2D3794D8 } // 5311 kB (5 MB) +// { 0x2D3795AC, 0x2D854300 } // 4971 kB (4 MB) +// { 0x2D8546B0, 0x2D8602C4 } // 47 kB +// { 0x2D86D318, 0x2DFFFFFC } // 7755 kB (7 MB) +// { 0x2E2DCD60, 0x2E2E4D7C } // 32 kB +// { 0x2E33F160, 0x2E365AFC } // 154 kB +// { 0x2E37AC40, 0x2E39BB3C } // 131 kB +// { 0x2E3A6EF0, 0x2E3CA2FC } // 141 kB +// { 0x2E3D9EE0, 0x2E400B3C } // 155 kB +// { 0x2E43A8F0, 0x2E442BBC } // 32 kB +// { 0x2E46EC90, 0x2E48E27C } // 125 kB +// { 0x2E497F90, 0x2E4A147C } // 37 kB +// { 0x2E4A5B40, 0x2E4C67BC } // 131 kB +// { 0x2E4FBEF0, 0x2E52697C } // 170 kB +// { 0x2E550750, 0x2E57333C } // 138 kB +// { 0x2E573F3C, 0x2FF8F07C } // 226732 kB (26 MB) +// { 0x31000000, 0x31E1FFFC } // 614464 kB (14 MB) +// { 0x320A5D80, 0x320AEA3C } // 35 kB +// { 0x320E8670, 0x3210017C } // 94 kB +// { 0x3212609C, 0x3213187C } // 45 kB +// { 0x3219DF08, 0x321B72BC } // 100 kB +// { 0x3300ED34, 0x3301AD3C } // 48 kB +// { 0x33041760, 0x33049D0C } // 33 kB +// { 0x330608F8, 0x3306C97C } // 48 kB +// { 0x33089D80, 0x33095284 } // 45 kB +// { 0x33095470, 0x330A1324 } // 47 kB +// { 0x330A1358, 0x330ADC10 } // 50 kB +// { 0x330C9040, 0x330D0ABC } // 30 kB +// { 0x330D0AD8, 0x3311F9CC } // 315 kB +// { 0x3312575C, 0x3320A63C } // 915 kB +// { 0x33234D00, 0x3324B33C } // 89 kB +// { 0x3324E300, 0x3328D7BC } // 253 kB +// { 0x3329D134, 0x332CA324 } // 180 kB +// { 0x3332B200, 0x33340C88 } // 86 kB +// { 0x3335A440, 0x335021FC } // 1695 kB (1 MB) +// { 0x3350A778, 0x3391680C } // 4144 kB (4 MB) +// { 0x3391A444, 0x3392A25C } // 63 kB +// { 0x3392A444, 0x33939EB4 } // 62 kB +// { 0x3393A444, 0x3394A25C } // 63 kB +// { 0x339587C0, 0x33976C80 } // 121 kB +// { 0x339779C8, 0x3398E320 } // 90 kB +// { 0x3399AE74, 0x339A7D80 } // 51 kB +// { 0x339AB1C0, 0x339CE3A0 } // 140 kB +// { 0x339CEB28, 0x339DEC38 } // 64 kB +// { 0x339DEC40, 0x339ED000 } // 56 kB +// { 0x339F1BA4, 0x33A09280 } // 93 kB +// { 0x33A0C6E4, 0x33A15C40 } // 37 kB +// { 0x33A15D64, 0x33EBFFFC } // 4776 kB (4 MB) +// { 0x33F01380, 0x33F21FFC } // 131 kB +// { 0x33F44820, 0x33F6B1BC } // 154 kB +// { 0x33F80300, 0x33FA11FC } // 131 kB +// { 0x33FA4D3C, 0x33FEDAFC } // 291 kB +// { 0x33FFFFD4, 0x38FFFFFC } // 81920 kB (80 MB) + {0, 0} +}; + +static const memory_values_t mem_vals_500[] = +{ + { 0x2E605CBC, 0x2FF849BC }, // size 26733828 (26107 kB) (25 MB) + { 0x2CAE7878, 0x2D207DB4 }, // size 7472448 (7297 kB) (7 MB) + { 0x2D3B966C, 0x2D8943C0 }, // size 5090648 (4971 kB) (4 MB) + { 0x2D8AD3D8, 0x2DFFFFFC }, // size 7679016 (7499 kB) (7 MB) + // TODO: Check which of those areas are usable +// { 0x283A73DC, 0x284D2AE4 } // size 1226508 (1197 kB) (1 MB) +// { 0x29030800, 0x293F69FC } // size 3957248 (3864 kB) (3 MB) +// { 0x2970200C, 0x298B9C54 } // size 1801292 (1759 kB) (1 MB) +// { 0x2A057B68, 0x2A1B9578 } // size 1448468 (1414 kB) (1 MB) + +// { 0x29030800, 0x293F69FC } // size 3957248 (3864 kB) (3 MB) +// { 0x2970200C, 0x298B9C54 } // size 1801292 (1759 kB) (1 MB) +// { 0x2A057B68, 0x2A1B9578 } // size 1448468 (1414 kB) (1 MB) +// { 0x288EEC30, 0x28B06E94 } // size 2196072 (2144 kB) (2 MB) +// { 0x283A73DC, 0x284D2AE4 } // size 1226508 (1197 kB) (1 MB) +// { 0x3335A4C0, 0x335021FC } // size 1736000 (1695 kB) (1 MB) +// { 0x3350C1D4, 0x339182CC } // size 4243708 (4144 kB) (4 MB) +// { 0x33A14094, 0x33EBFFFC } // size 4898668 (4783 kB) (4 MB) +// { 0x33FFFFD4, 0x38FFFFFC } // size 83886124 (81920 kB) (80 MB) + {0, 0} +}; + +static const memory_values_t mem_vals_532[] = +{ + // TODO: Check which of those areas are usable +// {0x28000000 + 0x000DCC9C, 0x28000000 + 0x00174F80}, // 608 kB +// {0x28000000 + 0x00180B60, 0x28000000 + 0x001C0A00}, // 255 kB +// {0x28000000 + 0x001ECE9C, 0x28000000 + 0x00208CC0}, // 111 kB +// {0x28000000 + 0x00234180, 0x28000000 + 0x0024B444}, // 92 kB +// {0x28000000 + 0x0024D8C0, 0x28000000 + 0x0028D884}, // 255 kB +// {0x28000000 + 0x003A745C, 0x28000000 + 0x004D2B68}, // 1197 kB +// {0x28000000 + 0x004D77B0, 0x28000000 + 0x00502200}, // 170 kB +// {0x28000000 + 0x005B3A88, 0x28000000 + 0x005C6870}, // 75 kB +// {0x28000000 + 0x0061F3E4, 0x28000000 + 0x00632B04}, // 77 kB +// {0x28000000 + 0x00639790, 0x28000000 + 0x00649BC4}, // 65 kB +// {0x28000000 + 0x00691490, 0x28000000 + 0x006B3CA4}, // 138 kB +// {0x28000000 + 0x006D7BCC, 0x28000000 + 0x006EEB84}, // 91 kB +// {0x28000000 + 0x00704E44, 0x28000000 + 0x0071E3C4}, // 101 kB +// {0x28000000 + 0x0073B684, 0x28000000 + 0x0074C184}, // 66 kB +// {0x28000000 + 0x00751354, 0x28000000 + 0x00769784}, // 97 kB +// {0x28000000 + 0x008627DC, 0x28000000 + 0x00872904}, // 64 kB +// {0x28000000 + 0x008C1E98, 0x28000000 + 0x008EB0A0}, // 164 kB +// {0x28000000 + 0x008EEC30, 0x28000000 + 0x00B06E98}, // 2144 kB +// {0x28000000 + 0x00B06EC4, 0x28000000 + 0x00B930C4}, // 560 kB +// {0x28000000 + 0x00BA1868, 0x28000000 + 0x00BC22A4}, // 130 kB +// {0x28000000 + 0x00BC48F8, 0x28000000 + 0x00BDEC84}, // 104 kB +// {0x28000000 + 0x00BE3DC0, 0x28000000 + 0x00C02284}, // 121 kB +// {0x28000000 + 0x00C02FC8, 0x28000000 + 0x00C19924}, // 90 kB +// {0x28000000 + 0x00C2D35C, 0x28000000 + 0x00C3DDC4}, // 66 kB +// {0x28000000 + 0x00C48654, 0x28000000 + 0x00C6E2E4}, // 151 kB +// {0x28000000 + 0x00D04E04, 0x28000000 + 0x00D36938}, // 198 kB +// {0x28000000 + 0x00DC88AC, 0x28000000 + 0x00E14288}, // 302 kB +// {0x28000000 + 0x00E21ED4, 0x28000000 + 0x00EC8298}, // 664 kB +// {0x28000000 + 0x00EDDC7C, 0x28000000 + 0x00F7C2A8}, // 633 kB +// {0x28000000 + 0x00F89EF4, 0x28000000 + 0x010302B8}, // 664 kB +// {0x28000000 + 0x01030800, 0x28000000 + 0x013F69A0}, // 3864 kB +// {0x28000000 + 0x016CE000, 0x28000000 + 0x016E0AA0}, // 74 kB +// {0x28000000 + 0x0170200C, 0x28000000 + 0x018B9C58}, // 1759 kB +// {0x28000000 + 0x01F17658, 0x28000000 + 0x01F6765C}, // 320 kB +// {0x28000000 + 0x01F6779C, 0x28000000 + 0x01FB77A0}, // 320 kB +// {0x28000000 + 0x01FB78E0, 0x28000000 + 0x020078E4}, // 320 kB +// {0x28000000 + 0x02007A24, 0x28000000 + 0x02057A28}, // 320 kB +// {0x28000000 + 0x02057B68, 0x28000000 + 0x021B957C}, // 1414 kB +// {0x28000000 + 0x02891528, 0x28000000 + 0x028C8A28}, // 221 kB +// {0x28000000 + 0x02BBCC4C, 0x28000000 + 0x02CB958C}, // 1010 kB +// {0x28000000 + 0x0378D45C, 0x28000000 + 0x03855464}, // 800 kB +// {0x28000000 + 0x0387800C, 0x28000000 + 0x03944938}, // 818 kB +// {0x28000000 + 0x03944A08, 0x28000000 + 0x03956E0C}, // 73 kB +// {0x28000000 + 0x04A944A4, 0x28000000 + 0x04ABAAC0}, // 153 kB +// {0x28000000 + 0x04ADE370, 0x28000000 + 0x0520EAB8}, // 7361 kB // ok +// {0x28000000 + 0x053B966C, 0x28000000 + 0x058943C4}, // 4971 kB // ok +// {0x28000000 + 0x058AD3D8, 0x28000000 + 0x06000000}, // 7499 kB +// {0x28000000 + 0x0638D320, 0x28000000 + 0x063B0280}, // 139 kB +// {0x28000000 + 0x063C39E0, 0x28000000 + 0x063E62C0}, // 138 kB +// {0x28000000 + 0x063F52A0, 0x28000000 + 0x06414A80}, // 125 kB +// {0x28000000 + 0x06422810, 0x28000000 + 0x0644B2C0}, // 162 kB +// {0x28000000 + 0x064E48D0, 0x28000000 + 0x06503EC0}, // 125 kB +// {0x28000000 + 0x0650E360, 0x28000000 + 0x06537080}, // 163 kB +// {0x28000000 + 0x0653A460, 0x28000000 + 0x0655C300}, // 135 kB +// {0x28000000 + 0x0658AA40, 0x28000000 + 0x065BC4C0}, // 198 kB // ok +// {0x28000000 + 0x065E51A0, 0x28000000 + 0x06608E80}, // 143 kB // ok +// {0x28000000 + 0x06609ABC, 0x28000000 + 0x07F82C00}, // 26084 kB // ok + +// {0x30000000 + 0x000DCC9C, 0x30000000 + 0x00180A00}, // 655 kB +// {0x30000000 + 0x00180B60, 0x30000000 + 0x001C0A00}, // 255 kB +// {0x30000000 + 0x001F5EF0, 0x30000000 + 0x00208CC0}, // 75 kB +// {0x30000000 + 0x00234180, 0x30000000 + 0x0024B444}, // 92 kB +// {0x30000000 + 0x0024D8C0, 0x30000000 + 0x0028D884}, // 255 kB +// {0x30000000 + 0x003A745C, 0x30000000 + 0x004D2B68}, // 1197 kB +// {0x30000000 + 0x006D3334, 0x30000000 + 0x00772204}, // 635 kB +// {0x30000000 + 0x00789C60, 0x30000000 + 0x007C6000}, // 240 kB +// {0x30000000 + 0x00800000, 0x30000000 + 0x01E20000}, // 22876 kB // ok + { 0x2E609ABC, 0x2FF82C00 }, // 26084 kB + { 0x29030800, 0x293F69A0 }, // 3864 kB + { 0x288EEC30, 0x28B06E98 }, // 2144 kB + { 0x2D3B966C, 0x2D8943C4 }, // 4971 kB + { 0x2CAE0370, 0x2D20EAB8 }, // 7361 kB + { 0x2D8AD3D8, 0x2E000000 }, // 7499 kB + + {0, 0} +}; // total : 66mB + 25mB + +static const memory_values_t mem_vals_540[] = +{ + { 0x2E609EFC, 0x2FF82000 }, // 26083 kB + { 0x29030800, 0x293F6000 }, // 3864 kB + { 0x288EEC30, 0x28B06800 }, // 2144 kB + { 0x2D3B966C, 0x2D894000 }, // 4971 kB + { 0x2CB56370, 0x2D1EF000 }, // 6756 kB + { 0x2D8AD3D8, 0x2E000000 }, // 7499 kB + { 0x2970200C, 0x298B9800 }, // 1759 kB + { 0x2A057B68, 0x2A1B9000 }, // 1414 kB + { 0x2ABBCC4C, 0x2ACB9000 }, // 1010 kB + {0, 0} +}; + +s_mem_area * memoryGetAreaTable(void) +{ + return MEM_AREA_TABLE; +} + +static inline void memoryAddArea(int start, int end, int cur_index) +{ + // Create and copy new memory area + s_mem_area * mem_area = memoryGetAreaTable(); + mem_area[cur_index].address = start; + mem_area[cur_index].size = end - start; + mem_area[cur_index].next = 0; + + // Fill pointer to this area in the previous area + if (cur_index > 0) + { + mem_area[cur_index - 1].next = &mem_area[cur_index]; + } +} + +/* Create memory areas arrays */ +void memoryInitAreaTable() +{ + u32 ApplicationMemoryEnd = (u32)APP_BASE_MEM; + + // This one seems to be available on every firmware and therefore its our code area but also our main RPX area behind our code + // 22876 kB - our application // ok + if(OS_FIRMWARE <= 400) { + memoryAddArea(ApplicationMemoryEnd + 0x4B000000, 0x4B000000 + 0x01E20000, 0); + } + else { + memoryAddArea(ApplicationMemoryEnd + 0x30000000, 0x30000000 + 0x01E20000, 0); + } + + const memory_values_t * mem_vals = NULL; + + switch(OS_FIRMWARE) + { + case 400: { + mem_vals = mem_vals_400; + break; + } + case 500: { + mem_vals = mem_vals_500; + break; + } + case 532: { + mem_vals = mem_vals_532; + break; + } + case 540: + case 550: { + mem_vals = mem_vals_540; + break; + } + default: + return; // no known values + } + + // Fill entries + int i = 0; + while (mem_vals[i].start_address) + { + memoryAddArea(mem_vals[i].start_address, mem_vals[i].end_address, i + 1); + i++; + } +} diff --git a/src/system/memory_area_table.h b/src/system/memory_area_table.h new file mode 100644 index 0000000..70d7f2f --- /dev/null +++ b/src/system/memory_area_table.h @@ -0,0 +1,34 @@ +/**************************************************************************** + * 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 _MEMORY_AREA_TABLE_H_ +#define _MEMORY_AREA_TABLE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "common/common.h" + +void memoryInitAreaTable(); +s_mem_area * memoryGetAreaTable(void); + + +#ifdef __cplusplus +} +#endif + +#endif // _MEMORY_AREA_TABLE_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 e1e411f..90f4497 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -1,17 +1,17 @@ +#include #include #include #include #include #include -#include "dynamic_libs/os_functions.h" -#include "dynamic_libs/socket_functions.h" +#include +#include "common/common.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/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/utils/utils.h b/src/utils/utils.h index c460fa2..729e808 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -40,6 +40,8 @@ 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))) +void SC0x25_KernelCopyData(unsigned int addr, unsigned int src, unsigned int len); + #ifdef __cplusplus } #endif diff --git a/src/utils/utils_asm.S b/src/utils/utils_asm.S new file mode 100644 index 0000000..c92f838 --- /dev/null +++ b/src/utils/utils_asm.S @@ -0,0 +1,5 @@ + .globl SC0x25_KernelCopyData +SC0x25_KernelCopyData: + li r0, 0x2500 + sc + blr 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 index 7e8624c..db6579f 100644 --- a/src/video/shaders/ShaderFractalColor.cpp +++ b/src/video/shaders/ShaderFractalColor.cpp @@ -292,10 +292,10 @@ ShaderFractalColor::ShaderFractalColor() 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 }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_blur_border", GX2_SHADER_VAR_TYPE_FLOAT, 1, blurLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_fade_out_alpha", GX2_SHADER_VAR_TYPE_FLOAT4, 1, fadeOutLocation, 0xffffffff }); + pixelShader.addUniformVar((GX2UniformVar){ "unf_fract_alpha", GX2_SHADER_VAR_TYPE_INT, 1, fractalLocation, 0xffffffff }); //! create vertex shader vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs)); @@ -303,21 +303,21 @@ ShaderFractalColor::ShaderFractalColor() 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 }); + vertexShader.addUniformVar((GX2UniformVar){ "modelMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, modelMatrixLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "projectionMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 1, projectionMatrixLocation, 0xffffffff }); + vertexShader.addUniformVar((GX2UniformVar){ "viewMatrix", GX2_SHADER_VAR_TYPE_MATRIX4X4, 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 }); + vertexShader.addAttribVar((GX2AttribVar){ "attr_colors", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation }); + 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(2), colorLocation, 2, 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), texCoordLocation, 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32); + GX2InitAttribStream(vertexShader.getAttributeBuffer(2), colorLocation, 2, 0, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8); //! create fetch shader fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount()); @@ -334,20 +334,20 @@ ShaderFractalColor::ShaderFractalColor() 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); for(i = 0; i < (int)ciColorVtxsSize; i++) colorVtxs[i] = 0xff; - GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, ciColorVtxsSize); + GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVtxs, ciColorVtxsSize); } ShaderFractalColor::~ShaderFractalColor() 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;