imported revision 35 of HBF to GIT
184
Makefile
Normal file
@ -0,0 +1,184 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
# Clear the implicit built in rules
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITPPC)),)
|
||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||
endif
|
||||
|
||||
include $(DEVKITPPC)/wii_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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 := boot
|
||||
BUILD := build
|
||||
SOURCES := source \
|
||||
source/BootHomebrew \
|
||||
source/DiskOperations \
|
||||
source/libwiigui \
|
||||
source/Prompts \
|
||||
source/Menus \
|
||||
source/Network \
|
||||
source/Tools \
|
||||
../svnrev
|
||||
INCLUDES := source
|
||||
DATA := data/fonts \
|
||||
data/sounds \
|
||||
data/images \
|
||||
data/images/design \
|
||||
data/binary
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
|
||||
CXXFLAGS = -save-temps -Xassembler -aln=$@.lst $(CFLAGS)
|
||||
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--section-start,.init=0x81230000
|
||||
#LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -ldi -lpng -lz -lfat -lntfs -lwiiuse -lbte -lasnd -logc -lvorbisidec -lfreetype -lmxml
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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 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)))
|
||||
TTFFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ttf)))
|
||||
PNGFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.png)))
|
||||
OGGFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.ogg)))
|
||||
PCMFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.pcm)))
|
||||
WAVFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.wav)))
|
||||
DOLFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.dol)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# 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) \
|
||||
$(TTFFILES:.ttf=.ttf.o) $(PNGFILES:.png=.png.o) \
|
||||
$(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o) \
|
||||
$(WAVFILES:.wav=.wav.o) \
|
||||
$(addsuffix .o,$(DOLFILES)) \
|
||||
$(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/freetype2
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of library paths
|
||||
#---------------------------------------------------------------------------------
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
|
||||
-L$(LIBOGC_LIB)
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
.PHONY: $(BUILD) clean
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
run:
|
||||
wiiload $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
reload:
|
||||
wiiload -r $(OUTPUT).dol
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).dol: $(OUTPUT).elf
|
||||
$(OUTPUT).elf: $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# This rule links in binary data with .ttf, .png, and .mp3 extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
%.elf.o : %.elf
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.dol.o : %.dol
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.ttf.o : %.ttf
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.png.o : %.png
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.ogg.o : %.ogg
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.pcm.o : %.pcm
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.wav.o : %.wav
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
%.bin.o : %.bin
|
||||
@echo $(notdir $<)
|
||||
@bin2s -a 32 $< | $(AS) -o $(@)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
BIN
data/binary/banner.bin
Normal file
BIN
data/binary/stub.bin
Normal file
BIN
data/fonts/font.ttf
Normal file
BIN
data/fonts/symbol.ttf
Normal file
BIN
data/images/LogoHomebrewFilter.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
data/images/bg_options.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
data/images/button_large.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
data/images/button_large_over.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
data/images/design/apps_grid.png
Normal file
After Width: | Height: | Size: 729 B |
BIN
data/images/design/apps_grid_hover.png
Normal file
After Width: | Height: | Size: 809 B |
BIN
data/images/design/apps_list.png
Normal file
After Width: | Height: | Size: 845 B |
BIN
data/images/design/apps_list_hover.png
Normal file
After Width: | Height: | Size: 950 B |
BIN
data/images/design/apps_minus.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
data/images/design/apps_minus_hover.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
data/images/design/apps_next.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
data/images/design/apps_next_hover.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
data/images/design/apps_plus.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
data/images/design/apps_plus_hover.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
data/images/design/apps_previous.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
data/images/design/apps_previous_hover.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
data/images/design/background.png
Normal file
After Width: | Height: | Size: 165 KiB |
BIN
data/images/design/bg_options.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
data/images/design/bg_options_entry.png
Normal file
After Width: | Height: | Size: 833 B |
BIN
data/images/design/button.png
Normal file
After Width: | Height: | Size: 931 B |
BIN
data/images/design/button_focus.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
data/images/design/button_small.png
Normal file
After Width: | Height: | Size: 897 B |
BIN
data/images/design/button_small_focus.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
data/images/design/button_square.png
Normal file
After Width: | Height: | Size: 828 B |
BIN
data/images/design/button_square_focus.png
Normal file
After Width: | Height: | Size: 989 B |
BIN
data/images/design/button_tiny.png
Normal file
After Width: | Height: | Size: 866 B |
BIN
data/images/design/button_tiny_focus.png
Normal file
After Width: | Height: | Size: 1001 B |
BIN
data/images/design/cancel_active.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
data/images/design/cancel_inactive.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
data/images/design/choice.png
Normal file
After Width: | Height: | Size: 809 B |
BIN
data/images/design/dialog_background.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
data/images/design/edit_active.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
data/images/design/edit_inactive.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
data/images/design/gc_active.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
data/images/design/gc_inactive.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
data/images/design/grid_active.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
data/images/design/grid_inactive.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
data/images/design/network_active.png
Normal file
After Width: | Height: | Size: 388 B |
BIN
data/images/design/network_inactive.png
Normal file
After Width: | Height: | Size: 358 B |
BIN
data/images/design/normal_active.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
data/images/design/normal_inactive.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
data/images/design/player_grab.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
data/images/design/player_point.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
data/images/design/power_active.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
data/images/design/power_inactive.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
data/images/design/progress.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
data/images/design/recycle_bin.png
Normal file
After Width: | Height: | Size: 764 B |
BIN
data/images/design/scrollbar.png
Normal file
After Width: | Height: | Size: 403 B |
BIN
data/images/design/scrollbar_arrowdown.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
data/images/design/scrollbar_arrowdown_over.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
data/images/design/scrollbar_arrowup.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
data/images/design/scrollbar_arrowup_over.png
Normal file
After Width: | Height: | Size: 727 B |
BIN
data/images/design/sd_active.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
data/images/design/sd_inactive.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
data/images/design/sd_usb_active.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
data/images/design/sd_usb_inactive.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
data/images/design/settings_active.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
data/images/design/settings_inactive.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
data/images/design/throbber.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
data/images/design/usb_active.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
data/images/design/usb_inactive.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
data/images/design/wii_active.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
data/images/design/wii_gc_active.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
data/images/design/wii_gc_inactive.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
data/images/design/wii_inactive.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
data/images/hbc_icon.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
data/images/keyboard_key.png
Normal file
After Width: | Height: | Size: 494 B |
BIN
data/images/keyboard_key_over.png
Normal file
After Width: | Height: | Size: 495 B |
BIN
data/images/keyboard_largekey.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
data/images/keyboard_largekey_over.png
Normal file
After Width: | Height: | Size: 874 B |
BIN
data/images/keyboard_mediumkey.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
data/images/keyboard_mediumkey_over.png
Normal file
After Width: | Height: | Size: 845 B |
BIN
data/images/keyboard_textbox.png
Normal file
After Width: | Height: | Size: 628 B |
BIN
data/images/scrollbar_box.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
data/images/scrollbar_box_over.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
data/images/textpointer_img.png
Normal file
After Width: | Height: | Size: 296 B |
BIN
data/sounds/button_click.ogg
Normal file
235
source/BootHomebrew/BootHomebrew.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ogc/machine/processor.h>
|
||||
#include <wiiuse/wpad.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sys/dir.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "dolloader.h"
|
||||
#include "elfloader.h"
|
||||
#include "filelist.h"
|
||||
#include "DiskOperations/di2.h"
|
||||
#include "Tools/load_channel.h"
|
||||
#include "Tools/parser.h"
|
||||
|
||||
#define BLOCKSIZE 70*1024 //70KB
|
||||
#define MAX_CMDLINE 4096
|
||||
#define MAX_ARGV 1000
|
||||
|
||||
#define GC_DOL_MAGIC "gchomebrew dol"
|
||||
#define GC_MAGIC_BUF (char *) 0x807FFFE0
|
||||
#define GC_DOL_BUF (u8 *)0x80800000
|
||||
#define BC 0x0000000100000100ULL
|
||||
|
||||
struct __argv args;
|
||||
char cmdline[MAX_CMDLINE];
|
||||
char *a_argv[MAX_ARGV];
|
||||
char *meta_buf = NULL;
|
||||
static u8 *homebrewbuffer = (u8 *) 0x92000000;
|
||||
static u32 homebrewsize = 0;
|
||||
std::string filepath;
|
||||
|
||||
void arg_init()
|
||||
{
|
||||
memset(&args, 0, sizeof(args));
|
||||
memset(cmdline, 0, sizeof(cmdline));
|
||||
memset(a_argv, 0, sizeof(a_argv));
|
||||
args.argvMagic = ARGV_MAGIC;
|
||||
args.length = 1; // double \0\0
|
||||
args.argc = 0;
|
||||
args.commandLine = cmdline;
|
||||
args.argv = a_argv;
|
||||
args.endARGV = a_argv;
|
||||
}
|
||||
|
||||
char* strcopy(char *dest, const char *src, int size)
|
||||
{
|
||||
strncpy(dest,src,size);
|
||||
dest[size-1] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
int arg_add(const char *arg)
|
||||
{
|
||||
int len = strlen(arg);
|
||||
if (args.argc >= MAX_ARGV) return -1;
|
||||
if (args.length + len + 1 > MAX_CMDLINE) return -1;
|
||||
strcopy(cmdline + args.length - 1, arg, len+1);
|
||||
args.length += len + 1; // 0 term.
|
||||
cmdline[args.length - 1] = 0; // double \0\0
|
||||
args.argc++;
|
||||
args.endARGV = args.argv + args.argc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* FileSize
|
||||
*
|
||||
* Get filesize in bytes. u64 for files bigger than 4GB
|
||||
***************************************************************************/
|
||||
u64 FileSize(const char * filepath)
|
||||
{
|
||||
struct stat filestat;
|
||||
|
||||
if (stat(filepath, &filestat) != 0)
|
||||
return 0;
|
||||
|
||||
return filestat.st_size;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFileToMem
|
||||
*
|
||||
* Load up the file into a block of memory
|
||||
***************************************************************************/
|
||||
int LoadFileToMem(const char *filepath, u8 **inbuffer, u64 *size)
|
||||
{
|
||||
int ret = -1;
|
||||
u64 filesize = FileSize(filepath);
|
||||
char * filename = strrchr(filepath, '/');
|
||||
if(filename)
|
||||
filename++;
|
||||
|
||||
*inbuffer = NULL;
|
||||
*size = 0;
|
||||
|
||||
FILE *file = fopen(filepath, "rb");
|
||||
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
|
||||
u8 *buffer = (u8 *) malloc(filesize);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
fclose(file);
|
||||
return -2;
|
||||
}
|
||||
|
||||
u64 done = 0;
|
||||
u32 blocksize = BLOCKSIZE;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if(blocksize > filesize-done)
|
||||
blocksize = filesize-done;
|
||||
|
||||
ret = fread(buffer+done, 1, blocksize, file);
|
||||
if(ret < 0)
|
||||
{
|
||||
free(buffer);
|
||||
fclose(file);
|
||||
return -3;
|
||||
}
|
||||
else if(ret == 0)
|
||||
{
|
||||
//we are done
|
||||
break;
|
||||
}
|
||||
|
||||
done += ret;
|
||||
|
||||
}
|
||||
while(done < filesize);
|
||||
|
||||
fclose(file);
|
||||
|
||||
if (done != filesize)
|
||||
{
|
||||
free(buffer);
|
||||
return -3;
|
||||
}
|
||||
|
||||
*inbuffer = buffer;
|
||||
*size = filesize;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len)
|
||||
{
|
||||
homebrewsize += len;
|
||||
memcpy((homebrewbuffer)+pos, temp, len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LoadHomebrew(const char * path)
|
||||
{
|
||||
filepath = path;
|
||||
u8 *buffer = NULL;
|
||||
u64 filesize = 0;
|
||||
int ret = LoadFileToMem(path, &buffer, &filesize);
|
||||
if(ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = CopyHomebrewMemory(buffer, 0, filesize);
|
||||
if(buffer) {
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int BootHomebrew()
|
||||
{
|
||||
if(homebrewsize == 0)
|
||||
return -1;
|
||||
|
||||
entrypoint entry;
|
||||
u32 cpu_isr;
|
||||
|
||||
arg_init();
|
||||
arg_add(filepath.c_str()); // argv[0] = filepath
|
||||
while(parser(Settings.forwarder_arg, "<arg>", "</arg>") != "")
|
||||
{
|
||||
arg_add(parser(Settings.forwarder_arg, "<arg>", "</arg>").c_str());
|
||||
Settings.forwarder_arg.erase(0, Settings.forwarder_arg.find("</arg>") +1);
|
||||
}
|
||||
|
||||
if ( valid_elf_image(homebrewbuffer) == 1 )
|
||||
entry = (entrypoint) load_elf_image(homebrewbuffer);
|
||||
else
|
||||
entry = (entrypoint) load_dol(homebrewbuffer, &args);
|
||||
|
||||
if (!entry)
|
||||
return -1;
|
||||
|
||||
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
||||
_CPU_ISR_Disable (cpu_isr);
|
||||
__exception_closeall();
|
||||
entry();
|
||||
_CPU_ISR_Restore (cpu_isr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BootGameCubeHomebrew()
|
||||
{
|
||||
if(homebrewsize == 0)
|
||||
return -1;
|
||||
|
||||
static tikview view ATTRIBUTE_ALIGN(32);
|
||||
|
||||
DI2_Init();
|
||||
DI2_Reset();
|
||||
DI2_ReadDiscID((u64 *) 0x80000000);
|
||||
DI2_Mount();
|
||||
|
||||
strcpy(GC_MAGIC_BUF, GC_DOL_MAGIC);
|
||||
DCFlushRange(GC_MAGIC_BUF, 32);
|
||||
memcpy(GC_DOL_BUF, homebrewbuffer, homebrewsize);
|
||||
DCFlushRange(GC_DOL_BUF, homebrewsize);
|
||||
*(vu32 *) 0xCC003024 |= 0x07;
|
||||
|
||||
ES_GetTicketViews(BC, &view, 1);
|
||||
int ret = ES_LaunchTitle(BC, &view);
|
||||
if(ret < 0)
|
||||
LoadHBC();
|
||||
|
||||
return ret;
|
||||
}
|
10
source/BootHomebrew/BootHomebrew.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _BOOTHOMEBREW_H_
|
||||
#define _BOOTHOMEBREW_H_
|
||||
|
||||
int BootHomebrew();
|
||||
int BootGameCubeHomebrew();
|
||||
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len);
|
||||
void AddBootArgument(const char * arg);
|
||||
int LoadHomebrew(const char * filepath);
|
||||
|
||||
#endif
|
62
source/BootHomebrew/dolloader.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ogc/machine/processor.h>
|
||||
#include <gccore.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dolloader.h"
|
||||
|
||||
typedef struct _dolheader {
|
||||
u32 text_pos[7];
|
||||
u32 data_pos[11];
|
||||
u32 text_start[7];
|
||||
u32 data_start[11];
|
||||
u32 text_size[7];
|
||||
u32 data_size[11];
|
||||
u32 bss_start;
|
||||
u32 bss_size;
|
||||
u32 entry_point;
|
||||
} dolheader;
|
||||
|
||||
u32 load_dol(const void *dolstart, struct __argv *argv)
|
||||
{
|
||||
u32 i;
|
||||
dolheader *dolfile;
|
||||
|
||||
if (dolstart)
|
||||
{
|
||||
dolfile = (dolheader *) dolstart;
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100))
|
||||
continue;
|
||||
|
||||
VIDEO_WaitVSync();
|
||||
memmove((void *) dolfile->text_start[i], dolstart + dolfile->text_pos[i], dolfile->text_size[i]);
|
||||
DCFlushRange ((void *) dolfile->text_start[i], dolfile->text_size[i]);
|
||||
ICInvalidateRange((void *) dolfile->text_start[i], dolfile->text_size[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 11; i++)
|
||||
{
|
||||
if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100))
|
||||
continue;
|
||||
|
||||
VIDEO_WaitVSync();
|
||||
memmove((void *) dolfile->data_start[i], dolstart + dolfile->data_pos[i], dolfile->data_size[i]);
|
||||
DCFlushRange((void *) dolfile->data_start[i],
|
||||
dolfile->data_size[i]);
|
||||
}
|
||||
|
||||
if (argv && argv->argvMagic == ARGV_MAGIC)
|
||||
{
|
||||
void *new_argv = (void *) (dolfile->entry_point + 8);
|
||||
memmove(new_argv, argv, sizeof(*argv));
|
||||
DCFlushRange(new_argv, sizeof(*argv));
|
||||
}
|
||||
return dolfile->entry_point;
|
||||
}
|
||||
return 0;
|
||||
}
|
17
source/BootHomebrew/dolloader.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _DOLLOADER_H_
|
||||
#define _DOLLOADER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void __exception_closeall();
|
||||
typedef void (*entrypoint) (void);
|
||||
|
||||
u32 load_dol(const void *dolstart, struct __argv *argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
594
source/BootHomebrew/elf_abi.h
Normal file
@ -0,0 +1,594 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
/*
|
||||
* This version doesn't work for 64-bit ABIs - Erik.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These typedefs need to be handled better.
|
||||
*/
|
||||
typedef u32 Elf32_Addr; /* Unsigned program address */
|
||||
typedef u32 Elf32_Off; /* Unsigned file offset */
|
||||
typedef s32 Elf32_Sword; /* Signed large integer */
|
||||
typedef u32 Elf32_Word; /* Unsigned large integer */
|
||||
typedef u16 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 ELFCLASS32 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 */
|
||||
|
88
source/BootHomebrew/elfloader.c
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2001 William L. Pitts
|
||||
* Modifications (c) 2004 Felix Domke
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are freely
|
||||
* permitted provided that the above copyright notice and this
|
||||
* paragraph and the following disclaimer are duplicated in all
|
||||
* such forms.
|
||||
*
|
||||
* This software is provided "AS IS" and without any express or
|
||||
* implied warranties, including, without limitation, the implied
|
||||
* warranties of merchantability and fitness for a particular
|
||||
* purpose.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gccore.h>
|
||||
|
||||
#include "elf_abi.h"
|
||||
|
||||
|
||||
/* ======================================================================
|
||||
* Determine if a valid ELF image exists at the given memory location.
|
||||
* First looks at the ELF header magic field, the makes sure that it is
|
||||
* executable and makes sure that it is for a PowerPC.
|
||||
* ====================================================================== */
|
||||
s32 valid_elf_image (void *addr) {
|
||||
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
|
||||
ehdr = (Elf32_Ehdr *) addr;
|
||||
if (!IS_ELF (*ehdr))
|
||||
return 0;
|
||||
if (ehdr->e_type != ET_EXEC)
|
||||
return -1;
|
||||
if (ehdr->e_machine != EM_PPC)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================================
|
||||
* A very simple elf loader, assumes the image is valid, returns the
|
||||
* entry point address.
|
||||
* ====================================================================== */
|
||||
u32 load_elf_image (void *addr)
|
||||
{
|
||||
Elf32_Ehdr *ehdr;
|
||||
Elf32_Shdr *shdr;
|
||||
u8 *strtab = 0;
|
||||
u8 *image;
|
||||
int i;
|
||||
|
||||
ehdr = (Elf32_Ehdr *) addr;
|
||||
/* Find the section header string table for output info */
|
||||
shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff +
|
||||
(ehdr->e_shstrndx * sizeof (Elf32_Shdr)));
|
||||
|
||||
if (shdr->sh_type == SHT_STRTAB)
|
||||
strtab = (u8 *) (addr + shdr->sh_offset);
|
||||
|
||||
/* Load each appropriate section */
|
||||
for (i = 0; i < ehdr->e_shnum; ++i) {
|
||||
shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff +
|
||||
(i * sizeof (Elf32_Shdr)));
|
||||
|
||||
if (!(shdr->sh_flags & SHF_ALLOC)
|
||||
|| shdr->sh_addr == 0 || shdr->sh_size == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
shdr->sh_addr &= 0x3FFFFFFF;
|
||||
shdr->sh_addr |= 0x80000000;
|
||||
|
||||
if (shdr->sh_type == SHT_NOBITS) {
|
||||
memset ((void *) shdr->sh_addr, 0, shdr->sh_size);
|
||||
} else {
|
||||
image = (u8 *) addr + shdr->sh_offset;
|
||||
memcpy ((void *) shdr->sh_addr,
|
||||
(const void *) image,
|
||||
shdr->sh_size);
|
||||
}
|
||||
DCFlushRangeNoSync ((void *) shdr->sh_addr, shdr->sh_size);
|
||||
}
|
||||
return (ehdr->e_entry & 0x3FFFFFFF) | 0x80000000;
|
||||
}
|
||||
|
17
source/BootHomebrew/elfloader.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _ELF_H_
|
||||
#define _ELF_H_
|
||||
|
||||
#include <gctypes.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
s32 valid_elf_image (void *addr);
|
||||
u32 load_elf_image (void *addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
1148
source/DiskOperations/di2.c
Normal file
96
source/DiskOperations/di2.h
Normal file
@ -0,0 +1,96 @@
|
||||
/*-------------------------------------------------------------
|
||||
|
||||
di2.h -- Drive Interface library
|
||||
|
||||
Written by rodries
|
||||
Modified from (and supplemental to) original libdi library:
|
||||
|
||||
Team Twiizers
|
||||
Copyright (C) 2008
|
||||
|
||||
Erant
|
||||
marcan
|
||||
|
||||
|
||||
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.
|
||||
|
||||
-------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
All buffers in this document need to be 32-byte aligned!
|
||||
*/
|
||||
|
||||
#ifndef __DI2_H__
|
||||
#define __DI2_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <ogc/ipc.h>
|
||||
#include <ogc/disc_io.h>
|
||||
#include <di/di.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
FUNCTION PROTOTYPES GO HERE!
|
||||
*/
|
||||
|
||||
int DI2_Init();
|
||||
void DI2_Mount();
|
||||
void DI2_Close();
|
||||
int DI2_GetStatus();
|
||||
|
||||
int DI2_Identify(DI_DriveID* id);
|
||||
int DI2_ReadDiscID(u64 *id);
|
||||
int DI2_GetError(uint32_t* error);
|
||||
int DI2_GetCoverRegister(uint32_t* status);
|
||||
int DI2_Reset();
|
||||
|
||||
int DI2_StopMotor();
|
||||
int DI2_Eject();
|
||||
int DI2_KillDrive();
|
||||
|
||||
int DI2_ReadDVD(void* buf, uint32_t len, uint32_t lba);
|
||||
int DI2_ReadDVDAsync(void* buf, uint32_t len, uint32_t lba, ipccallback ipc_cb);
|
||||
|
||||
int DI2_Read(void *buf, u32 size, u32 offset);
|
||||
int DI2_UnencryptedRead(void *buf, u32 size, u32 offset);
|
||||
|
||||
int DI2_ReadDVDConfig(uint32_t* val, uint32_t flag);
|
||||
int DI2_ReadDVDCopyright(uint32_t* copyright);
|
||||
int DI2_ReadDVDDiscKey(void* buf);
|
||||
int DI2_ReadDVDPhysical(void* buf);
|
||||
int DI2_ReportKey(int keytype, uint32_t lba, void* buf);
|
||||
|
||||
int DI2_OpenPartition(u32 offset);
|
||||
int DI2_ClosePartition(void);
|
||||
|
||||
void DI2_SetDVDMotorStopSecs(int secs);
|
||||
unsigned int DI2_GetDVDMotorStopSecs(void);
|
||||
bool DI2_IsMotorRunning();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
597
source/FreeTypeGX.cpp
Normal file
@ -0,0 +1,597 @@
|
||||
/*
|
||||
* 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, 2010
|
||||
*
|
||||
* This file is part of FreeTypeGX.
|
||||
*
|
||||
* FreeTypeGX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* FreeTypeGX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with FreeTypeGX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FreeTypeGX.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* 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* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for the FreeTypeGX class for WiiXplorer.
|
||||
*/
|
||||
FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize)
|
||||
{
|
||||
ftPointSize = 0;
|
||||
|
||||
FT_Init_FreeType(&ftLibrary);
|
||||
FT_New_Memory_Face(ftLibrary, (FT_Byte *)fontBuffer, bufferSize, 0, &ftFace);
|
||||
|
||||
setVertexFormat(GX_VTXFMT1);
|
||||
ftKerningEnabled = FT_HAS_KERNING(ftFace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default destructor for the FreeTypeGX class.
|
||||
*/
|
||||
FreeTypeGX::~FreeTypeGX()
|
||||
{
|
||||
unloadFont();
|
||||
FT_Done_Face(ftFace);
|
||||
FT_Done_FreeType(ftLibrary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the vertex attribute formats for the glyph textures.
|
||||
*
|
||||
* This function sets up the vertex format for the glyph texture on the specified vertex format index.
|
||||
* Note that this function should not need to be called except if the vertex formats are cleared or the specified
|
||||
* vertex format index is modified.
|
||||
*
|
||||
* @param vertexIndex Vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file.
|
||||
*/
|
||||
void FreeTypeGX::setVertexFormat(uint8_t vertexInd)
|
||||
{
|
||||
vertexIndex = vertexInd;
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
||||
GX_SetVtxAttrFmt(vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
if(this->fontData.size() == 0)
|
||||
return;
|
||||
|
||||
map<int16_t, map<wchar_t, ftgxCharData> >::iterator itr;
|
||||
map<wchar_t, ftgxCharData>::iterator itr2;
|
||||
|
||||
for(itr = fontData.begin(); itr != fontData.end(); itr++)
|
||||
{
|
||||
for(itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++)
|
||||
free(itr2->second.glyphDataTexture);
|
||||
|
||||
itr->second.clear();
|
||||
}
|
||||
|
||||
fontData.clear();
|
||||
ftgxAlign.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, map<wchar_t, ftgxCharData> >::iterator itr;
|
||||
map<wchar_t, ftgxCharData>::iterator itr2;
|
||||
|
||||
itr = fontData.find(pixelSize);
|
||||
if(itr != fontData.end())
|
||||
{
|
||||
itr2 = itr->second.find(charCode);
|
||||
|
||||
if(itr2 != itr->second.end())
|
||||
{
|
||||
return &itr2->second;
|
||||
}
|
||||
}
|
||||
|
||||
FT_UInt gIndex;
|
||||
uint16_t textureWidth = 0, textureHeight = 0;
|
||||
|
||||
if(ftPointSize != pixelSize)
|
||||
{
|
||||
ftPointSize = pixelSize;
|
||||
FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize);
|
||||
|
||||
//!Cache ascender and decender as well
|
||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(ftPointSize);
|
||||
if(itrAlign == ftgxAlign.end())
|
||||
{
|
||||
ftgxAlign[ftPointSize].ascender = (int16_t) ftFace->size->metrics.ascender>>6;
|
||||
ftgxAlign[ftPointSize].descender = (int16_t) ftFace->size->metrics.descender>>6;
|
||||
ftgxAlign[ftPointSize].max = 0;
|
||||
ftgxAlign[ftPointSize].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 = glyphBitmap->width + (4 - glyphBitmap->width % 4) % 4;
|
||||
textureHeight = glyphBitmap->rows + (4 - glyphBitmap->rows % 4) % 4;
|
||||
|
||||
fontData[pixelSize][charCode].renderOffsetX = (int16_t) ftFace->glyph->bitmap_left;
|
||||
fontData[pixelSize][charCode].glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6);
|
||||
fontData[pixelSize][charCode].glyphIndex = (uint32_t) gIndex;
|
||||
fontData[pixelSize][charCode].textureWidth = (uint16_t) textureWidth;
|
||||
fontData[pixelSize][charCode].textureHeight = (uint16_t) textureHeight;
|
||||
fontData[pixelSize][charCode].renderOffsetY = (int16_t) ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].renderOffsetMax = (int16_t) ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].renderOffsetMin = (int16_t) glyphBitmap->rows - ftFace->glyph->bitmap_top;
|
||||
fontData[pixelSize][charCode].glyphDataTexture = NULL;
|
||||
|
||||
loadGlyphData(glyphBitmap, &fontData[pixelSize][charCode]);
|
||||
|
||||
return &fontData[pixelSize][charCode];
|
||||
}
|
||||
}
|
||||
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.
|
||||
*
|
||||
*
|
||||
* Optimized for RGBA8 use by Dimok.
|
||||
*/
|
||||
void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData)
|
||||
{
|
||||
int length = ((((charData->textureWidth+3)>>2)*((charData->textureHeight+3)>>2)*32*2 + 31) & ~31);
|
||||
|
||||
uint8_t * glyphData = (uint8_t *) memalign(32, length);
|
||||
if(!glyphData)
|
||||
return;
|
||||
|
||||
memset(glyphData, 0x00, length);
|
||||
|
||||
uint8_t *src = (uint8_t *)bmp->buffer;
|
||||
uint32_t offset;
|
||||
|
||||
for (int imagePosY = 0; imagePosY < bmp->rows; ++imagePosY)
|
||||
{
|
||||
for (int imagePosX = 0; imagePosX < bmp->width; ++imagePosX)
|
||||
{
|
||||
offset = ((((imagePosY >> 2) * (charData->textureWidth >> 2) + (imagePosX >> 2)) << 5) + ((imagePosY & 3) << 2) + (imagePosX & 3)) << 1;
|
||||
glyphData[offset] = *src;
|
||||
glyphData[offset+1] = *src;
|
||||
glyphData[offset+32] = *src;
|
||||
glyphData[offset+33] = *src;
|
||||
++src;
|
||||
}
|
||||
}
|
||||
DCFlushRange(glyphData, length);
|
||||
|
||||
charData->glyphDataTexture = glyphData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
map<int16_t, ftgxDataOffset>::iterator itrAlign = ftgxAlign.find(pixelSize);
|
||||
if(itrAlign == ftgxAlign.end())
|
||||
return 0;
|
||||
|
||||
switch(format & FTGX_ALIGN_MASK)
|
||||
{
|
||||
case FTGX_ALIGN_TOP:
|
||||
return itrAlign->second.ascender;
|
||||
|
||||
case FTGX_ALIGN_MIDDLE:
|
||||
default:
|
||||
return (itrAlign->second.ascender + itrAlign->second.descender + 1) >> 1;
|
||||
|
||||
case FTGX_ALIGN_BOTTOM:
|
||||
return itrAlign->second.descender;
|
||||
|
||||
case FTGX_ALIGN_BASELINE:
|
||||
return 0;
|
||||
|
||||
case FTGX_ALIGN_GLYPH_TOP:
|
||||
return itrAlign->second.max;
|
||||
|
||||
case FTGX_ALIGN_GLYPH_MIDDLE:
|
||||
return (itrAlign->second.max + itrAlign->second.min + 1) >> 1;
|
||||
|
||||
case FTGX_ALIGN_GLYPH_BOTTOM:
|
||||
return itrAlign->second.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(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color, uint16_t textStyle, uint16_t textWidth, uint16_t widthLimit)
|
||||
{
|
||||
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;
|
||||
GXTexObj glyphTexture;
|
||||
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])
|
||||
{
|
||||
if(widthLimit > 0 && (x_pos-x) > widthLimit)
|
||||
break;
|
||||
|
||||
ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize);
|
||||
|
||||
if (glyphData != NULL)
|
||||
{
|
||||
if (ftKerningEnabled && i > 0)
|
||||
{
|
||||
FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, &pairDelta);
|
||||
x_pos += pairDelta.x >> 6;
|
||||
}
|
||||
|
||||
GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, glyphData->textureHeight, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
||||
copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, z, color);
|
||||
|
||||
x_pos += glyphData->glyphAdvanceX;
|
||||
++printed;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if(textStyle & FTGX_STYLE_MASK)
|
||||
{
|
||||
getOffset(text, pixelSize, widthLimit);
|
||||
drawTextFeature(x + x_offset, y + y_offset, z, pixelSize, fullTextWidth, &ftgxAlign[pixelSize], textStyle, color);
|
||||
}
|
||||
|
||||
return printed;
|
||||
}
|
||||
|
||||
void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color)
|
||||
{
|
||||
uint16_t featureHeight = pixelSize >> 4 > 0 ? pixelSize >> 4 : 1;
|
||||
|
||||
if (format & FTGX_STYLE_UNDERLINE)
|
||||
this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, z, color);
|
||||
|
||||
if (format & FTGX_STYLE_STRIKE)
|
||||
this->copyFeatureToFramebuffer(width, featureHeight, x, y - ((offsetData->max) >> 1), z, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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][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][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 ftgxAlign[pixelSize].max - ftgxAlign[pixelSize].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(ftgxAlign.find(pixelSize) != ftgxAlign.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);
|
||||
}
|
||||
|
||||
ftgxAlign[pixelSize].ascender = ftFace->size->metrics.ascender>>6;
|
||||
ftgxAlign[pixelSize].descender = ftFace->size->metrics.descender>>6;
|
||||
ftgxAlign[pixelSize].max = strMax;
|
||||
ftgxAlign[pixelSize].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(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, int16_t screenZ, GXColor color)
|
||||
{
|
||||
GX_LoadTexObj(texObj, GX_TEXMAP0);
|
||||
GX_InvalidateTexAll();
|
||||
|
||||
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
|
||||
GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
|
||||
|
||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||
GX_Position3s16(screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(0.0f, 0.0f);
|
||||
|
||||
GX_Position3s16(texWidth + screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(1.0f, 0.0f);
|
||||
|
||||
GX_Position3s16(texWidth + screenX, texHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(1.0f, 1.0f);
|
||||
|
||||
GX_Position3s16(screenX, texHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_TexCoord2f32(0.0f, 1.0f);
|
||||
GX_End();
|
||||
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a feature quad to the EFB.
|
||||
*
|
||||
* This function creates a simple quad for displaying underline or strikeout text styling.
|
||||
*
|
||||
* @param featureWidth The pixel width of the quad.
|
||||
* @param featureHeight The pixel height of the quad.
|
||||
* @param screenX The screen X coordinate at which to output the quad.
|
||||
* @param screenY The screen Y coordinate at which to output the quad.
|
||||
* @param color Color to apply to the texture.
|
||||
*/
|
||||
void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, int16_t screenZ, GXColor color)
|
||||
{
|
||||
GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);
|
||||
|
||||
GX_Begin(GX_QUADS, this->vertexIndex, 4);
|
||||
GX_Position3s16(screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
|
||||
GX_Position3s16(featureWidth + screenX, screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
|
||||
GX_Position3s16(featureWidth + screenX, featureHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
|
||||
GX_Position3s16(screenX, featureHeight + screenY, screenZ);
|
||||
GX_Color4u8(color.r, color.g, color.b, color.a);
|
||||
GX_End();
|
||||
|
||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||
GX_SetVtxDesc(GX_VA_TEX0, GX_NONE);
|
||||
}
|
142
source/FreeTypeGX.h
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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, 2010
|
||||
*
|
||||
* 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 <gccore.h>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_BITMAP_H
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <map>
|
||||
|
||||
/*! \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. */
|
||||
uint32_t glyphIndex; /**< Charachter glyph index in the font face. */
|
||||
|
||||
uint16_t textureWidth; /**< Texture width in pixels/bytes. */
|
||||
uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */
|
||||
|
||||
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. */
|
||||
|
||||
uint8_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */
|
||||
} 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
|
||||
|
||||
const GXColor ftgxWhite = (GXColor){0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */
|
||||
|
||||
wchar_t* charToWideChar(const char* p);
|
||||
|
||||
/*! \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. */
|
||||
std::map<int16_t, std::map<wchar_t, ftgxCharData> > fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */
|
||||
std::map<int16_t, ftgxDataOffset> ftgxAlign; /**< Map which holds the ascender and decender for different sizes. */
|
||||
|
||||
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 setDefaultMode();
|
||||
|
||||
void drawTextFeature(int16_t x, int16_t y,int16_t z, int16_t pixelSize, uint16_t width, ftgxDataOffset *offsetData, uint16_t format, GXColor color);
|
||||
void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, int16_t screenZ, GXColor color);
|
||||
void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, int16_t screenZ, GXColor color);
|
||||
|
||||
public:
|
||||
FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize);
|
||||
~FreeTypeGX();
|
||||
|
||||
void setVertexFormat(uint8_t vertexIndex);
|
||||
|
||||
uint16_t drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color = ftgxWhite, uint16_t textStyling = FTGX_NULL, uint16_t textWidth = 0, uint16_t widthLimit = 0);
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
#endif /* FREETYPEGX_H_ */
|
184
source/Menus/menu_childlock.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "main.h"
|
||||
#include "menu.h"
|
||||
#include "Prompts/prompts.h"
|
||||
|
||||
#include "Network/update.h"
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* MenuSettings
|
||||
***************************************************************************/
|
||||
int MenuSettingsChildlock()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
GuiTrigger trigHome;
|
||||
trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, PAD_BUTTON_START);
|
||||
|
||||
GuiText titleTxt(tr("Childlock"), 30, (GXColor){Theme.title_1, Theme.title_2, Theme.title_3, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(0,30);
|
||||
|
||||
// normale Buttons
|
||||
GuiImageData btn(Theme.button);
|
||||
GuiImage btn1Img(&btn);
|
||||
GuiImage btn2Img(&btn);
|
||||
GuiImage backBtnImg(&btn);
|
||||
|
||||
// normale Buttons over
|
||||
GuiImageData btn_over(Theme.button_focus);
|
||||
GuiImage btn1ImgOver(&btn_over);
|
||||
GuiImage btn2ImgOver(&btn_over);
|
||||
GuiImage backBtnImgOver(&btn_over);
|
||||
|
||||
GuiText btn1Txt(tr("Activate"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton btn1(btn.GetWidth(), btn.GetHeight());
|
||||
btn1.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
btn1.SetPosition(0, 160);
|
||||
btn1.SetLabel(&btn1Txt);
|
||||
btn1.SetImage(&btn1Img);
|
||||
btn1.SetImageOver(&btn1ImgOver);
|
||||
btn1.SetTrigger(&trigA);
|
||||
if(strcasecmp(Options.temp_code,"NULL") != 0 )
|
||||
{
|
||||
btn1Txt.SetText(tr("Deactivate"));
|
||||
btn1.SetPosition(0, 110);
|
||||
}
|
||||
|
||||
GuiText btn2Txt(tr("Change Code"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton btn2(btn.GetWidth(), btn.GetHeight());
|
||||
btn2.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
btn2.SetPosition(0, 210);
|
||||
btn2.SetLabel(&btn2Txt);
|
||||
btn2.SetImage(&btn2Img);
|
||||
btn2.SetImageOver(&btn2ImgOver);
|
||||
btn2.SetTrigger(&trigA);
|
||||
|
||||
GuiText backBtnTxt(tr("Back"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton backBtn(btn.GetWidth(), btn.GetHeight());
|
||||
backBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
backBtn.SetPosition(0, 260);
|
||||
if(strcasecmp(Options.temp_code,"NULL") != 0 )
|
||||
backBtn.SetPosition(0, 310);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetImage(&backBtnImg);
|
||||
backBtn.SetImageOver(&backBtnImgOver);
|
||||
backBtn.SetTrigger(&trigA);
|
||||
backBtn.SetTrigger(&trigHome);
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&btn1);
|
||||
if(strcasecmp(Options.temp_code,"NULL") != 0 )
|
||||
w.Append(&btn2);
|
||||
w.Append(&backBtn);
|
||||
|
||||
mainWindow->Append(&w);
|
||||
|
||||
ResumeGui();
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
||||
if(btn1.GetState() == STATE_CLICKED)
|
||||
{
|
||||
btn1.ResetState();
|
||||
char buffer[5];
|
||||
if(strcasecmp(Options.temp_code,"NULL") != 0 )
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
for(int i = 0; i < (signed)strlen(buffer); i++)
|
||||
buffer[i] = '\0';
|
||||
|
||||
OnScreenCodeboard(buffer, 4);
|
||||
// wenn eingabe richtig
|
||||
if(strcasecmp(buffer, Options.temp_code) == 0 )
|
||||
{
|
||||
sprintf (Options.temp_code, "NULL");
|
||||
break;
|
||||
}
|
||||
// wenn eingabe abgebrochen
|
||||
else if(strcasecmp(buffer, "NULL") == 0 )
|
||||
break;
|
||||
// wenn eingabe falsch
|
||||
else
|
||||
WindowPrompt(NULL, tr("Error"), tr("Back"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// neuen code eingeben
|
||||
buffer[0] = '\0';
|
||||
OnScreenCodeboard(buffer, 4);
|
||||
if(strcasecmp(buffer,"NULL") != 0 )
|
||||
sprintf (Options.temp_code, buffer);
|
||||
}
|
||||
|
||||
menu = MENU_SETTINGS_CHILDLOCK;
|
||||
}
|
||||
else if(btn2.GetState() == STATE_CLICKED)
|
||||
{
|
||||
btn2.ResetState();
|
||||
char buffer[5];
|
||||
while(1)
|
||||
{
|
||||
for(int i = 0; i < (signed)strlen(buffer); i++)
|
||||
buffer[i] = '\0';
|
||||
|
||||
// alten code eingeben
|
||||
WindowPrompt(tr("Info"), tr("Old Code"), tr("Back"));
|
||||
OnScreenCodeboard(buffer, 4);
|
||||
// wenn eingabe richtig
|
||||
if(strcasecmp(buffer, Options.temp_code) == 0 )
|
||||
{
|
||||
for(int i = 0; i < (signed)strlen(buffer); i++)
|
||||
buffer[i] = '\0';
|
||||
// neuen code eingeben
|
||||
WindowPrompt(tr("Info"), tr("New Code"), tr("Back"));
|
||||
OnScreenCodeboard(buffer, 4);
|
||||
if(strcasecmp(buffer,"NULL") != 0 )
|
||||
{
|
||||
sprintf (Options.temp_code, buffer);
|
||||
break;
|
||||
}
|
||||
// wenn eingabe abgebrochen
|
||||
else
|
||||
break;;
|
||||
}
|
||||
// wenn eingabe abgebrochen
|
||||
else if(strcasecmp(buffer, "NULL") == 0 )
|
||||
break;
|
||||
// wenn eingabe falsch
|
||||
else
|
||||
WindowPrompt(NULL, tr("Error"), tr("Back"));
|
||||
}
|
||||
}
|
||||
else if(backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
HaltGui();
|
||||
mainWindow->Remove(&w);
|
||||
return menu;
|
||||
}
|
||||
|
1106
source/Menus/menu_main.cpp
Normal file
276
source/Menus/menu_settings.cpp
Normal file
@ -0,0 +1,276 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "main.h"
|
||||
#include "menu.h"
|
||||
#include "Prompts/prompts.h"
|
||||
|
||||
#include "Network/update.h"
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
extern bool boot_buffer;
|
||||
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* MenuSettings
|
||||
***************************************************************************/
|
||||
int MenuSettings()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
GuiTrigger trigHome;
|
||||
trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, PAD_BUTTON_START);
|
||||
|
||||
GuiText titleTxt(tr("Settings"), 30, (GXColor){Theme.title_1, Theme.title_2, Theme.title_3, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(0,30);
|
||||
|
||||
// normale Buttons
|
||||
GuiImageData btn(Theme.button);
|
||||
GuiImage categoryCreateBtnImg(&btn);
|
||||
GuiImage categoryEraseBtnImg(&btn);
|
||||
GuiImage infoBtnImg(&btn);
|
||||
GuiImage optionsBtnImg(&btn);
|
||||
GuiImage updateBtnImg(&btn);
|
||||
GuiImage backBtnImg(&btn);
|
||||
|
||||
// normale Buttons over
|
||||
GuiImageData btn_over(Theme.button_focus);
|
||||
GuiImage categoryCreateBtnImgOver(&btn_over);
|
||||
GuiImage categoryEraseBtnImgOver(&btn_over);
|
||||
GuiImage infoBtnImgOver(&btn_over);
|
||||
GuiImage optionsBtnImgOver(&btn_over);
|
||||
GuiImage updateBtnImgOver(&btn_over);
|
||||
GuiImage backBtnImgOver(&btn_over);
|
||||
|
||||
GuiText categoryCreateBtnTxt(tr("Create Category"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton categoryCreateBtn(btn.GetWidth(), btn.GetHeight());
|
||||
categoryCreateBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
categoryCreateBtn.SetPosition(0, 80);
|
||||
categoryCreateBtn.SetLabel(&categoryCreateBtnTxt);
|
||||
categoryCreateBtn.SetImage(&categoryCreateBtnImg);
|
||||
categoryCreateBtn.SetImageOver(&categoryCreateBtnImgOver);
|
||||
categoryCreateBtn.SetTrigger(&trigA);
|
||||
|
||||
GuiText categoryEraseBtnTxt(tr("Delete Category"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton categoryEraseBtn(btn.GetWidth(), btn.GetHeight());
|
||||
categoryEraseBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
categoryEraseBtn.SetPosition(0, 140);
|
||||
categoryEraseBtn.SetLabel(&categoryEraseBtnTxt);
|
||||
categoryEraseBtn.SetImage(&categoryEraseBtnImg);
|
||||
categoryEraseBtn.SetImageOver(&categoryEraseBtnImgOver);
|
||||
categoryEraseBtn.SetTrigger(&trigA);
|
||||
|
||||
GuiText optionsBtnTxt(tr("Options"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton optionsBtn(btn.GetWidth(), btn.GetHeight());
|
||||
optionsBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
optionsBtn.SetPosition(0, 200);
|
||||
optionsBtn.SetLabel(&optionsBtnTxt);
|
||||
optionsBtn.SetImage(&optionsBtnImg);
|
||||
optionsBtn.SetImageOver(&optionsBtnImgOver);
|
||||
optionsBtn.SetTrigger(&trigA);
|
||||
|
||||
GuiText infoBtnTxt(tr("Info"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton infoBtn(btn.GetWidth(), btn.GetHeight());
|
||||
infoBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
infoBtn.SetPosition(0, 260);
|
||||
infoBtn.SetLabel(&infoBtnTxt);
|
||||
infoBtn.SetImage(&infoBtnImg);
|
||||
infoBtn.SetImageOver(&infoBtnImgOver);
|
||||
infoBtn.SetTrigger(&trigA);
|
||||
|
||||
GuiText updateBtnTxt(tr("Update"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton updateBtn(btn.GetWidth(), btn.GetHeight());
|
||||
updateBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
updateBtn.SetPosition(0, 320);
|
||||
updateBtn.SetLabel(&updateBtnTxt);
|
||||
updateBtn.SetImage(&updateBtnImg);
|
||||
updateBtn.SetImageOver(&updateBtnImgOver);
|
||||
updateBtn.SetTrigger(&trigA);
|
||||
|
||||
GuiText backBtnTxt(tr("Back"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton backBtn(btn.GetWidth(), btn.GetHeight());
|
||||
backBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
backBtn.SetPosition(0, 380);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetImage(&backBtnImg);
|
||||
backBtn.SetImageOver(&backBtnImgOver);
|
||||
backBtn.SetTrigger(&trigA);
|
||||
backBtn.SetTrigger(&trigHome);
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&categoryCreateBtn);
|
||||
w.Append(&categoryEraseBtn);
|
||||
w.Append(&optionsBtn);
|
||||
w.Append(&infoBtn);
|
||||
w.Append(&updateBtn);
|
||||
w.Append(&backBtn);
|
||||
|
||||
mainWindow->Append(&w);
|
||||
|
||||
ResumeGui();
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
||||
// kinderschutz aus
|
||||
if(strcasecmp(Settings.code,"NULL") == 0 )
|
||||
{
|
||||
categoryCreateBtn.SetClickable(true);
|
||||
categoryEraseBtn.SetClickable(true);
|
||||
updateBtn.SetClickable(true);
|
||||
}
|
||||
// kinderschutz an
|
||||
else
|
||||
{
|
||||
categoryCreateBtn.SetClickable(false);
|
||||
categoryEraseBtn.SetClickable(false);
|
||||
updateBtn.SetClickable(false);
|
||||
}
|
||||
|
||||
if(categoryCreateBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
categoryCreateBtn.ResetState();
|
||||
|
||||
char new_category_name[256];
|
||||
sprintf (new_category_name, tr(Settings.new_category_name));
|
||||
OnScreenKeyboard(new_category_name, 256, false);
|
||||
|
||||
if(strcasecmp(new_category_name,"NULL") != 0 )
|
||||
KategorieEinfuegen(new_category_name);
|
||||
}
|
||||
else if(categoryEraseBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
categoryEraseBtn.ResetState();
|
||||
if(AvailableCategory.categories.size() > 1)
|
||||
{
|
||||
string entferne_kategorie = eraseCategory();
|
||||
|
||||
if( entferne_kategorie != "NULL" )
|
||||
{
|
||||
int choice = WindowPrompt(entferne_kategorie.c_str(), tr("Really remove?"), tr("Yes"), tr("No"));
|
||||
if(choice == 1)
|
||||
{
|
||||
KategorieEntfernen(entferne_kategorie);
|
||||
Settings.current_category = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(optionsBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(strcasecmp(Settings.code,"NULL") != 0 )
|
||||
{
|
||||
char buffer[5];
|
||||
while(1)
|
||||
{
|
||||
for(int i = 0; i < (signed)strlen(buffer); i++)
|
||||
buffer[i] = '\0';
|
||||
|
||||
OnScreenCodeboard(buffer, 4);
|
||||
// wenn eingabe richtig
|
||||
if(strcasecmp(buffer, Settings.code) == 0 )
|
||||
{
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
break;
|
||||
}
|
||||
// wenn eingabe abgebrochen
|
||||
else if(strcasecmp(buffer, "NULL") == 0 )
|
||||
break;
|
||||
// wenn eingabe falsch
|
||||
else
|
||||
WindowPrompt(NULL, tr("Error"), tr("Back"));
|
||||
}
|
||||
}
|
||||
else
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
else if(infoBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
infoBtn.ResetState();
|
||||
infoPrompt();
|
||||
}
|
||||
else if(updateBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
updateBtn.ResetState();
|
||||
|
||||
string revnumber = checkUpdatePrompt();
|
||||
|
||||
if(revnumber != "NULL")
|
||||
{
|
||||
char title[100];
|
||||
if(revnumber == "Beta")
|
||||
sprintf(title, "%s ( rev.%i %s Beta )", tr("Update"), SvnRev(), "»");
|
||||
else
|
||||
sprintf(title, "%s ( rev.%i %s rev.%s )", tr("Update"), SvnRev(), "»", revnumber.c_str());
|
||||
|
||||
// auflisten
|
||||
string version_text = NewVersionsText();
|
||||
vector <string> versions_text;
|
||||
|
||||
int strpos = version_text.find("//rev");
|
||||
while(strpos != -1)
|
||||
{
|
||||
version_text.erase(0, strpos +2);
|
||||
int strpos2 = version_text.find("//rev");
|
||||
if(strpos2 != -1)
|
||||
{
|
||||
versions_text.push_back(version_text.substr(0, strpos2 -2));
|
||||
version_text.erase(0, strpos2 -2);
|
||||
}
|
||||
else
|
||||
versions_text.push_back(version_text.substr(0, version_text.find("end") -2));
|
||||
|
||||
strpos = version_text.find("//rev");
|
||||
}
|
||||
|
||||
char revinfo[10];
|
||||
if(revnumber == "Beta")
|
||||
sprintf(revinfo, "rev_Beta");
|
||||
else
|
||||
sprintf(revinfo, "rev%i", atoi(revnumber.c_str()));
|
||||
|
||||
string text;
|
||||
|
||||
for(int i=0; i < (signed)versions_text.size(); i++)
|
||||
{
|
||||
if(strcasecmp(versions_text[i].substr(0, versions_text[i].find(":")).c_str(), revinfo) == 0)
|
||||
{
|
||||
versions_text[i].erase(0, versions_text[i].find(":") +2);
|
||||
text = versions_text[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
revtext(text.c_str());
|
||||
|
||||
// anzeigen
|
||||
int choice = WindowPrompt(title, tr("Do you want to update now ?"), tr("Yes"), tr("No"));
|
||||
if(choice == 1)
|
||||
{
|
||||
updatePrompt(revnumber);
|
||||
if(boot_buffer)
|
||||
menu = MENU_EXIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(backBtn.GetState() == STATE_CLICKED)
|
||||
menu = MENU_MAIN;
|
||||
}
|
||||
|
||||
HaltGui();
|
||||
mainWindow->Remove(&w);
|
||||
return menu;
|
||||
}
|
||||
|
402
source/Menus/menu_settings_display.cpp
Normal file
@ -0,0 +1,402 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "main.h"
|
||||
#include "menu.h"
|
||||
#include "menus.h"
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
|
||||
/****************************************************************************
|
||||
* MenuSettings
|
||||
***************************************************************************/
|
||||
int MenuSettingsDisplay()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
|
||||
int top = Settings.top;
|
||||
int bottom = Settings.bottom;
|
||||
int left = Settings.left;
|
||||
int right = Settings.right;
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
GuiTrigger trigHome;
|
||||
trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0);
|
||||
|
||||
GuiText titleTxt(tr("Display"), 30, (GXColor){Theme.title_1, Theme.title_2, Theme.title_3, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(0,30);
|
||||
|
||||
// Buttons Data
|
||||
GuiImageData textBtn(keyboard_textbox_png);
|
||||
|
||||
GuiImageData btn(Theme.button_small);
|
||||
GuiImageData btn_over(Theme.button_small_focus);
|
||||
|
||||
GuiImageData plusBtnData(Theme.scrollbar_arrowup);
|
||||
GuiImageData plusBtnOverData(Theme.scrollbar_arrowup_over);
|
||||
GuiImageData minusBtnData(Theme.scrollbar_arrowdown);
|
||||
GuiImageData minusBtnOverData(Theme.scrollbar_arrowdown_over);
|
||||
|
||||
// Buttons
|
||||
GuiImage backBtnImg(&btn);
|
||||
GuiImage backBtnImgOver(&btn_over);
|
||||
GuiImage saveBtnImg(&btn);
|
||||
GuiImage saveBtnImgOver(&btn_over);
|
||||
|
||||
GuiImage plusTopBtnImg(&plusBtnData);
|
||||
GuiImage plusTopBtnImgOver(&plusBtnOverData);
|
||||
GuiImage minusTopBtnImg(&minusBtnData);
|
||||
GuiImage minusTopBtnImgOver(&minusBtnOverData);
|
||||
GuiImage plusBottomBtnImg(&plusBtnData);
|
||||
GuiImage plusBottomBtnImgOver(&plusBtnOverData);
|
||||
GuiImage minusBottomBtnImg(&minusBtnData);
|
||||
GuiImage minusBottomBtnImgOver(&minusBtnOverData);
|
||||
GuiImage plusLeftBtnImg(&plusBtnData);
|
||||
GuiImage plusLeftBtnImgOver(&plusBtnOverData);
|
||||
GuiImage minusLeftBtnImg(&minusBtnData);
|
||||
GuiImage minusLeftBtnImgOver(&minusBtnOverData);
|
||||
GuiImage plusRightBtnImg(&plusBtnData);
|
||||
GuiImage plusRightBtnImgOver(&plusBtnOverData);
|
||||
GuiImage minusRightBtnImg(&minusBtnData);
|
||||
GuiImage minusRightBtnImgOver(&minusBtnOverData);
|
||||
|
||||
|
||||
char number[4];
|
||||
int y = 130;
|
||||
|
||||
// oben
|
||||
GuiImage textTopBtnImg(&textBtn);
|
||||
textTopBtnImg.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
textTopBtnImg.SetPosition(0, y);
|
||||
|
||||
GuiText topTxt("g g", 30, (GXColor){0, 0, 0, 255});
|
||||
topTxt.SetFont(symbol_ttf, symbol_ttf_size);
|
||||
topTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
topTxt.SetPosition(0, y +3);
|
||||
|
||||
GuiButton plusTopBtn(plusBtnData.GetWidth(), plusBtnData.GetHeight());
|
||||
plusTopBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
plusTopBtn.SetPosition(80, y);
|
||||
plusTopBtn.SetImage(&plusTopBtnImg);
|
||||
plusTopBtn.SetImageOver(&plusTopBtnImgOver);
|
||||
plusTopBtn.SetTrigger(&trigA);
|
||||
|
||||
sprintf(number, "%i", top);
|
||||
GuiText topNr(number, 30, (GXColor){0, 0, 0, 255});
|
||||
topNr.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
topNr.SetPosition(0, y +10);
|
||||
|
||||
GuiButton minusTopBtn(minusBtnData.GetWidth(), minusBtnData.GetHeight());
|
||||
minusTopBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
minusTopBtn.SetPosition(-80, y);
|
||||
minusTopBtn.SetImage(&minusTopBtnImg);
|
||||
minusTopBtn.SetImageOver(&minusTopBtnImgOver);
|
||||
minusTopBtn.SetTrigger(&trigA);
|
||||
|
||||
y += 50;
|
||||
|
||||
// unten
|
||||
GuiImage textBottomBtnImg(&textBtn);
|
||||
textBottomBtnImg.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
textBottomBtnImg.SetPosition(0, y);
|
||||
|
||||
GuiText bottomTxt("h h", 30, (GXColor){0, 0, 0, 255});
|
||||
bottomTxt.SetFont(symbol_ttf, symbol_ttf_size);
|
||||
bottomTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
bottomTxt.SetPosition(0, y +7);
|
||||
|
||||
GuiButton plusBottomBtn(plusBtnData.GetWidth(), plusBtnData.GetHeight());
|
||||
plusBottomBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
plusBottomBtn.SetPosition(80, y);
|
||||
plusBottomBtn.SetImage(&plusBottomBtnImg);
|
||||
plusBottomBtn.SetImageOver(&plusBottomBtnImgOver);
|
||||
plusBottomBtn.SetTrigger(&trigA);
|
||||
|
||||
sprintf(number, "%i", bottom);
|
||||
GuiText bottomNr(number, 30, (GXColor){0, 0, 0, 255});
|
||||
bottomNr.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
bottomNr.SetPosition(0, y +10);
|
||||
|
||||
GuiButton minusBottomBtn(minusBtnData.GetWidth(), minusBtnData.GetHeight());
|
||||
minusBottomBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
minusBottomBtn.SetPosition(-80, y);
|
||||
minusBottomBtn.SetImage(&minusBottomBtnImg);
|
||||
minusBottomBtn.SetImageOver(&minusBottomBtnImgOver);
|
||||
minusBottomBtn.SetTrigger(&trigA);
|
||||
|
||||
y += 50;
|
||||
|
||||
// links
|
||||
GuiImage textLeftBtnImg(&textBtn);
|
||||
textLeftBtnImg.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
textLeftBtnImg.SetPosition(0, y);
|
||||
|
||||
GuiText lefttTxt("e e", 30, (GXColor){0, 0, 0, 255});
|
||||
lefttTxt.SetFont(symbol_ttf, symbol_ttf_size);
|
||||
lefttTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
lefttTxt.SetPosition(0, y +5);
|
||||
|
||||
GuiButton plusLeftBtn(plusBtnData.GetWidth(), plusBtnData.GetHeight());
|
||||
plusLeftBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
plusLeftBtn.SetPosition(80, y);
|
||||
plusLeftBtn.SetImage(&plusLeftBtnImg);
|
||||
plusLeftBtn.SetImageOver(&plusLeftBtnImgOver);
|
||||
plusLeftBtn.SetTrigger(&trigA);
|
||||
|
||||
sprintf(number, "%i", left);
|
||||
GuiText leftNr(number, 30, (GXColor){0, 0, 0, 255});
|
||||
leftNr.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
leftNr.SetPosition(0, y +10);
|
||||
|
||||
GuiButton minusLeftBtn(minusBtnData.GetWidth(), minusBtnData.GetHeight());
|
||||
minusLeftBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
minusLeftBtn.SetPosition(-80, y);
|
||||
minusLeftBtn.SetImage(&minusLeftBtnImg);
|
||||
minusLeftBtn.SetImageOver(&minusLeftBtnImgOver);
|
||||
minusLeftBtn.SetTrigger(&trigA);
|
||||
|
||||
y += 50;
|
||||
|
||||
// rechts
|
||||
GuiImage textRightBtnImg(&textBtn);
|
||||
textRightBtnImg.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
textRightBtnImg.SetPosition(0, y);
|
||||
|
||||
GuiText rightTxt("f f", 30, (GXColor){0, 0, 0, 255});
|
||||
rightTxt.SetFont(symbol_ttf, symbol_ttf_size);
|
||||
rightTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
rightTxt.SetPosition(0, y +5);
|
||||
|
||||
GuiButton plusRightBtn(plusBtnData.GetWidth(), plusBtnData.GetHeight());
|
||||
plusRightBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
plusRightBtn.SetPosition(80, y);
|
||||
plusRightBtn.SetImage(&plusRightBtnImg);
|
||||
plusRightBtn.SetImageOver(&plusRightBtnImgOver);
|
||||
plusRightBtn.SetTrigger(&trigA);
|
||||
|
||||
sprintf(number, "%i", right);
|
||||
GuiText rightNr(number, 30, (GXColor){0, 0, 0, 255});
|
||||
rightNr.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
rightNr.SetPosition(0, y +10);
|
||||
|
||||
GuiButton minusRightBtn(minusBtnData.GetWidth(), minusBtnData.GetHeight());
|
||||
minusRightBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
minusRightBtn.SetPosition(-80, y);
|
||||
minusRightBtn.SetImage(&minusRightBtnImg);
|
||||
minusRightBtn.SetImageOver(&minusRightBtnImgOver);
|
||||
minusRightBtn.SetTrigger(&trigA);
|
||||
|
||||
GuiText backBtnTxt(tr("Stop"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton backBtn(btn.GetWidth(), btn.GetHeight());
|
||||
backBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
backBtn.SetPosition(-100, -35);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetImage(&backBtnImg);
|
||||
backBtn.SetImageOver(&backBtnImgOver);
|
||||
backBtn.SetTrigger(&trigA);
|
||||
backBtn.SetTrigger(&trigHome);
|
||||
backBtn.SetEffectGrow();
|
||||
|
||||
GuiText saveBtnTxt(tr("Save"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiButton saveBtn(btn.GetWidth(), btn.GetHeight());
|
||||
saveBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
saveBtn.SetPosition(100, -35);
|
||||
saveBtn.SetLabel(&saveBtnTxt);
|
||||
saveBtn.SetImage(&saveBtnImg);
|
||||
saveBtn.SetImageOver(&saveBtnImgOver);
|
||||
saveBtn.SetTrigger(&trigA);
|
||||
saveBtn.SetEffectGrow();
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&titleTxt);
|
||||
|
||||
w.Append(&textTopBtnImg);
|
||||
w.Append(&topTxt);
|
||||
w.Append(&plusTopBtn);
|
||||
w.Append(&topNr);
|
||||
w.Append(&minusTopBtn);
|
||||
|
||||
w.Append(&textBottomBtnImg);
|
||||
w.Append(&bottomTxt);
|
||||
w.Append(&plusBottomBtn);
|
||||
w.Append(&bottomNr);
|
||||
w.Append(&minusBottomBtn);
|
||||
|
||||
w.Append(&textLeftBtnImg);
|
||||
w.Append(&lefttTxt);
|
||||
w.Append(&plusLeftBtn);
|
||||
w.Append(&leftNr);
|
||||
w.Append(&minusLeftBtn);
|
||||
|
||||
w.Append(&textRightBtnImg);
|
||||
w.Append(&rightTxt);
|
||||
w.Append(&plusRightBtn);
|
||||
w.Append(&rightNr);
|
||||
w.Append(&minusRightBtn);
|
||||
|
||||
w.Append(&backBtn);
|
||||
w.Append(&saveBtn);
|
||||
|
||||
mainWindow->Append(&w);
|
||||
|
||||
ResumeGui();
|
||||
|
||||
int display = DISPLAY_NONE;
|
||||
bool add = -1;
|
||||
int temp_number = 0;
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
||||
// oben
|
||||
if(plusTopBtn.GetState() == STATE_CLICKED || minusTopBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(plusTopBtn.GetState() == STATE_CLICKED)
|
||||
add = true;
|
||||
else
|
||||
add = false;
|
||||
|
||||
plusTopBtn.ResetState();
|
||||
minusTopBtn.ResetState();
|
||||
display = DISPLAY_TOP;
|
||||
temp_number = top;
|
||||
}
|
||||
|
||||
// unten
|
||||
if(plusBottomBtn.GetState() == STATE_CLICKED || minusBottomBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(plusBottomBtn.GetState() == STATE_CLICKED)
|
||||
add = true;
|
||||
else
|
||||
add = false;
|
||||
|
||||
plusBottomBtn.ResetState();
|
||||
minusBottomBtn.ResetState();
|
||||
display = DISPLAY_BOTTOM;
|
||||
temp_number = bottom;
|
||||
}
|
||||
|
||||
// links
|
||||
if(plusLeftBtn.GetState() == STATE_CLICKED || minusLeftBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(plusLeftBtn.GetState() == STATE_CLICKED)
|
||||
add = true;
|
||||
else
|
||||
add = false;
|
||||
|
||||
plusLeftBtn.ResetState();
|
||||
minusLeftBtn.ResetState();
|
||||
display = DISPLAY_LEFT;
|
||||
temp_number = left;
|
||||
}
|
||||
|
||||
// rechts
|
||||
if(plusRightBtn.GetState() == STATE_CLICKED || minusRightBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
if(plusRightBtn.GetState() == STATE_CLICKED)
|
||||
add = true;
|
||||
else
|
||||
add = false;
|
||||
|
||||
plusRightBtn.ResetState();
|
||||
minusRightBtn.ResetState();
|
||||
display = DISPLAY_RIGHT;
|
||||
temp_number = right;
|
||||
}
|
||||
|
||||
if(display != DISPLAY_NONE)
|
||||
{
|
||||
while(WPAD_ButtonsHeld(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A) || PAD_ButtonsHeld(0) & PAD_BUTTON_A)
|
||||
{
|
||||
if(add)
|
||||
temp_number++;
|
||||
else
|
||||
temp_number--;
|
||||
|
||||
sprintf(number, "%i", temp_number);
|
||||
|
||||
switch (display)
|
||||
{
|
||||
case DISPLAY_TOP:
|
||||
top = temp_number;
|
||||
topNr.SetText(number);
|
||||
break;
|
||||
|
||||
case DISPLAY_BOTTOM:
|
||||
bottom = temp_number;
|
||||
bottomNr.SetText(number);
|
||||
break;
|
||||
|
||||
case DISPLAY_LEFT:
|
||||
left = temp_number;
|
||||
leftNr.SetText(number);
|
||||
break;
|
||||
|
||||
case DISPLAY_RIGHT:
|
||||
right = temp_number;
|
||||
rightNr.SetText(number);
|
||||
break;
|
||||
}
|
||||
|
||||
stretch(top, bottom, left, right);
|
||||
|
||||
if(temp_number == 0)
|
||||
usleep(500000);
|
||||
else
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
if(add && display == DISPLAY_TOP)
|
||||
plusTopBtn.SetState(STATE_SELECTED);
|
||||
else if(!add && display == DISPLAY_TOP)
|
||||
minusTopBtn.SetState(STATE_SELECTED);
|
||||
else if(add && display == DISPLAY_BOTTOM)
|
||||
plusBottomBtn.SetState(STATE_SELECTED);
|
||||
else if(!add && display == DISPLAY_BOTTOM)
|
||||
minusBottomBtn.SetState(STATE_SELECTED);
|
||||
else if(add && display == DISPLAY_LEFT)
|
||||
plusLeftBtn.SetState(STATE_SELECTED);
|
||||
else if(!add && display == DISPLAY_LEFT)
|
||||
minusLeftBtn.SetState(STATE_SELECTED);
|
||||
else if(add && display == DISPLAY_RIGHT)
|
||||
plusRightBtn.SetState(STATE_SELECTED);
|
||||
else if(!add && display == DISPLAY_RIGHT)
|
||||
minusRightBtn.SetState(STATE_SELECTED);
|
||||
|
||||
display = DISPLAY_NONE;
|
||||
}
|
||||
|
||||
if(backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
stretch(Settings.top, Settings.bottom, Settings.left, Settings.right);
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
if(saveBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
Settings.top = top;
|
||||
Settings.bottom = bottom;
|
||||
Settings.left = left;
|
||||
Settings.right = right;
|
||||
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
HaltGui();
|
||||
mainWindow->Remove(&w);
|
||||
return menu;
|
||||
}
|
||||
|
472
source/Menus/menu_settings_file.cpp
Normal file
@ -0,0 +1,472 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "main.h"
|
||||
#include "menu.h"
|
||||
#include "menus.h"
|
||||
#include "Tools/FontSystem.h"
|
||||
#include "Tools/save.h"
|
||||
#include "Tools/theme.h"
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
extern GuiImageData * pointer;
|
||||
extern GuiImage * bgImg;
|
||||
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
extern void HaltResumeGui();
|
||||
|
||||
int temp_last_category;
|
||||
int temp_slide_effect;
|
||||
int temp_apps;
|
||||
bool temp_quick_start;
|
||||
int temp_device_icon;
|
||||
bool temp_navigation;
|
||||
string temp_device_dat;
|
||||
|
||||
/****************************************************************************
|
||||
* MenuSettingsFile
|
||||
***************************************************************************/
|
||||
|
||||
int MenuSettingsFile()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
int ret, ret2;
|
||||
int i = 0;
|
||||
bool firstRun = true;
|
||||
int focus = 0;
|
||||
|
||||
int last_category = Options.last_category;
|
||||
bool quick_start = Options.quick_start;
|
||||
int device_icon = Options.device_icon;
|
||||
bool childlock;
|
||||
if(strcasecmp(Settings.code,"NULL") == 0 )
|
||||
childlock = 0;
|
||||
else
|
||||
childlock = 1;
|
||||
bool navigation = Options.navigation;
|
||||
|
||||
string device_dat;
|
||||
if(Settings.device_dat == "sd1")
|
||||
device_dat = "SD";
|
||||
else if(Settings.device_dat == "usb1")
|
||||
device_dat = "USB";
|
||||
|
||||
OptionList options;
|
||||
sprintf(options.name[i++], tr("Theme"));
|
||||
sprintf(options.name[i++], tr("Language"));
|
||||
sprintf(options.name[i++], tr("Font"));
|
||||
sprintf(options.name[i++], tr("Slide Effect"));
|
||||
sprintf(options.name[i++], tr("Category remember"));
|
||||
sprintf(options.name[i++], tr("Number of Apps"));
|
||||
sprintf(options.name[i++], tr("Quick Start"));
|
||||
sprintf(options.name[i++], tr("Storage Device"));
|
||||
sprintf(options.name[i++], tr("Device icon"));
|
||||
sprintf(options.name[i++], tr("Childlock"));
|
||||
sprintf(options.name[i++], tr("Navigation key exchange"));
|
||||
sprintf(options.name[i++], tr("Display"));
|
||||
sprintf(options.name[i++], tr("Network Settings"));
|
||||
options.length = i;
|
||||
|
||||
GuiText titleTxt(tr("Options"), 28, (GXColor){Theme.title_1, Theme.title_2, Theme.title_3, 255});
|
||||
titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
titleTxt.SetPosition(50,50);
|
||||
|
||||
GuiImageData btnOutline(Theme.button_small);
|
||||
GuiImageData btnOutlineOver(Theme.button_small_focus);
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
GuiTrigger trigHome;
|
||||
trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0);
|
||||
|
||||
GuiText backBtnTxt(tr("Stop"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage backBtnImg(&btnOutline);
|
||||
GuiImage backBtnImgOver(&btnOutlineOver);
|
||||
GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
backBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
backBtn.SetPosition(-100, -35);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetImage(&backBtnImg);
|
||||
backBtn.SetImageOver(&backBtnImgOver);
|
||||
backBtn.SetTrigger(&trigA);
|
||||
backBtn.SetTrigger(&trigHome);
|
||||
backBtn.SetEffectGrow();
|
||||
|
||||
GuiText saveBtnTxt(tr("Save"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage saveBtnImg(&btnOutline);
|
||||
GuiImage saveBtnImgOver(&btnOutlineOver);
|
||||
GuiButton saveBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
saveBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
saveBtn.SetPosition(100, -35);
|
||||
saveBtn.SetLabel(&saveBtnTxt);
|
||||
saveBtn.SetImage(&saveBtnImg);
|
||||
saveBtn.SetImageOver(&saveBtnImgOver);
|
||||
saveBtn.SetTrigger(&trigA);
|
||||
saveBtn.SetEffectGrow();
|
||||
|
||||
GuiOptionBrowser optionBrowser(552, 248, &options);
|
||||
optionBrowser.SetPosition(0, 108);
|
||||
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
optionBrowser.SetCol2Position(280);
|
||||
optionBrowser.Col2Scroll(280);
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&backBtn);
|
||||
w.Append(&saveBtn);
|
||||
mainWindow->Append(&optionBrowser);
|
||||
mainWindow->Append(&w);
|
||||
ResumeGui();
|
||||
|
||||
int change = 0;
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
||||
ret = optionBrowser.GetChangedOption();
|
||||
ret2 = optionBrowser.GetClickedOption();
|
||||
|
||||
if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT) || PAD_ButtonsDown(0) & PAD_BUTTON_RIGHT)
|
||||
{
|
||||
change = 0;
|
||||
switch (ret)
|
||||
{
|
||||
case SLIDE_EFFECT:
|
||||
change = atoi(options.value[ret]);
|
||||
change++;
|
||||
if(change > 5)
|
||||
change = 5;
|
||||
sprintf (options.value[ret], "%i", change);
|
||||
break;
|
||||
|
||||
case CATEGORY_REMEMBER:
|
||||
change = last_category;
|
||||
change++;
|
||||
if(change > (signed)AvailableCategory.categories.size())
|
||||
change = AvailableCategory.categories.size();
|
||||
last_category = change;
|
||||
break;
|
||||
|
||||
case NUMBER_OF_APPS:
|
||||
change = atoi(options.value[ret]);
|
||||
change++;
|
||||
if(change > 5)
|
||||
change = 5;
|
||||
sprintf (options.value[ret], "%i", change);
|
||||
break;
|
||||
|
||||
case QUICK_START:
|
||||
quick_start = 1;
|
||||
break;
|
||||
|
||||
case DEVICE_ICON:
|
||||
change = device_icon;
|
||||
change++;
|
||||
if(change > 3)
|
||||
change = 3;
|
||||
device_icon = change;
|
||||
break;
|
||||
|
||||
case STORAGE_DEVICE:
|
||||
device_dat = "USB";
|
||||
sprintf (options.value[STORAGE_DEVICE], device_dat.c_str());
|
||||
break;
|
||||
|
||||
case NAVIGATION:
|
||||
navigation = 1;
|
||||
break;
|
||||
}
|
||||
HaltResumeGui();
|
||||
optionBrowser.TriggerUpdate();
|
||||
}
|
||||
|
||||
if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT) || PAD_ButtonsDown(0) & PAD_BUTTON_LEFT)
|
||||
{
|
||||
change = 0;
|
||||
switch (ret)
|
||||
{
|
||||
case SLIDE_EFFECT:
|
||||
change = atoi(options.value[ret]);
|
||||
change--;
|
||||
if(change < 0)
|
||||
change = 0;
|
||||
sprintf (options.value[ret], "%i", change);
|
||||
break;
|
||||
|
||||
case CATEGORY_REMEMBER:
|
||||
change = last_category;
|
||||
change--;
|
||||
if(change < 0)
|
||||
change = 0;
|
||||
last_category = change;
|
||||
break;
|
||||
|
||||
case NUMBER_OF_APPS:
|
||||
change = atoi(options.value[ret]);
|
||||
change--;
|
||||
if(change < 4)
|
||||
change = 4;
|
||||
sprintf (options.value[ret], "%i", change);
|
||||
break;
|
||||
|
||||
case QUICK_START:
|
||||
quick_start = 0;
|
||||
break;
|
||||
|
||||
case DEVICE_ICON:
|
||||
change = device_icon;
|
||||
change--;
|
||||
if(change < 0)
|
||||
change = 0;
|
||||
device_icon = change;
|
||||
break;
|
||||
|
||||
case STORAGE_DEVICE:
|
||||
device_dat = "SD";
|
||||
sprintf (options.value[STORAGE_DEVICE], device_dat.c_str());
|
||||
break;
|
||||
|
||||
case NAVIGATION:
|
||||
navigation = 0;
|
||||
break;
|
||||
}
|
||||
HaltResumeGui();
|
||||
optionBrowser.TriggerUpdate();
|
||||
}
|
||||
|
||||
if(ret2 != -1)
|
||||
{
|
||||
// einstellungen temporär speichern
|
||||
/******************************************************************************/
|
||||
Options.temp_theme = options.value[THEME];
|
||||
Options.temp_language = options.value[LANGUAGE];
|
||||
Options.temp_font = options.value[FONT];
|
||||
temp_slide_effect = atoi(options.value[SLIDE_EFFECT]);
|
||||
temp_last_category = last_category;
|
||||
temp_apps = atoi(options.value[NUMBER_OF_APPS]);
|
||||
temp_quick_start = quick_start;
|
||||
temp_device_icon = device_icon;
|
||||
temp_device_dat = device_dat;
|
||||
temp_navigation = navigation;
|
||||
/******************************************************************************/
|
||||
|
||||
// in weitere einstellungen gehen
|
||||
switch (ret2)
|
||||
{
|
||||
case THEME:
|
||||
menu = MENU_SETTINGS_THEME;
|
||||
break;
|
||||
|
||||
case LANGUAGE:
|
||||
menu = MENU_SETTINGS_LANGUAGE;
|
||||
break;
|
||||
|
||||
case FONT:
|
||||
menu = MENU_SETTINGS_FONT;
|
||||
break;
|
||||
|
||||
case CHILDLOCK:
|
||||
menu = MENU_SETTINGS_CHILDLOCK;
|
||||
break;
|
||||
|
||||
case DISPLAY:
|
||||
menu = MENU_SETTINGS_DISPLAY;
|
||||
break;
|
||||
|
||||
case NETWORK:
|
||||
menu = MENU_SETTINGS_NETWORK;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(firstRun)
|
||||
{
|
||||
firstRun = false;
|
||||
|
||||
if(Options.temp_last_setting == 1)
|
||||
{
|
||||
sprintf (options.value[THEME], Options.temp_theme.c_str());
|
||||
sprintf (options.value[LANGUAGE], Options.temp_language.c_str());
|
||||
sprintf (options.value[FONT], Options.temp_font.c_str());
|
||||
sprintf (options.value[SLIDE_EFFECT], "%i", temp_slide_effect);
|
||||
sprintf (options.value[NUMBER_OF_APPS], "%i", temp_apps);
|
||||
sprintf (options.value[STORAGE_DEVICE], temp_device_dat.c_str());
|
||||
sprintf (options.value[DISPLAY], " ");
|
||||
sprintf (options.value[NETWORK], " ");
|
||||
|
||||
last_category = temp_last_category;
|
||||
quick_start = temp_quick_start;
|
||||
device_icon = temp_device_icon;
|
||||
if(strcasecmp(Options.temp_code,"NULL") == 0 )
|
||||
childlock = 0;
|
||||
else
|
||||
childlock = 1;
|
||||
navigation = temp_navigation;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (options.value[THEME], Options.theme);
|
||||
sprintf (options.value[LANGUAGE], Options.language);
|
||||
sprintf (options.value[FONT], Options.font);
|
||||
sprintf (options.value[SLIDE_EFFECT], "%i", Options.slide_effect);
|
||||
sprintf (options.value[NUMBER_OF_APPS], "%i", Options.apps);
|
||||
sprintf (options.value[STORAGE_DEVICE], device_dat.c_str());
|
||||
sprintf (options.value[DISPLAY], " ");
|
||||
sprintf (options.value[NETWORK], " ");
|
||||
}
|
||||
}
|
||||
|
||||
if(change != -1)
|
||||
{
|
||||
change = -1;
|
||||
|
||||
if(!last_category)
|
||||
sprintf (options.value[CATEGORY_REMEMBER], tr("last"));
|
||||
else
|
||||
sprintf (options.value[CATEGORY_REMEMBER], AvailableCategory.categories[last_category - 1].c_str());
|
||||
|
||||
if(!quick_start)
|
||||
sprintf (options.value[QUICK_START], tr("No"));
|
||||
else
|
||||
sprintf (options.value[QUICK_START], tr("Yes"));
|
||||
|
||||
if(!childlock)
|
||||
sprintf (options.value[CHILDLOCK], tr("No"));
|
||||
else
|
||||
sprintf (options.value[CHILDLOCK], tr("Yes"));
|
||||
|
||||
if(device_icon == 0)
|
||||
sprintf (options.value[DEVICE_ICON], tr("Off"));
|
||||
else if(device_icon == 1)
|
||||
sprintf (options.value[DEVICE_ICON], tr("Menu"));
|
||||
else if(device_icon == 2)
|
||||
sprintf (options.value[DEVICE_ICON], tr("Dialog box"));
|
||||
else if(device_icon == 3)
|
||||
sprintf (options.value[DEVICE_ICON], tr("All"));
|
||||
|
||||
if(!navigation)
|
||||
sprintf (options.value[NAVIGATION], tr("No"));
|
||||
else
|
||||
sprintf (options.value[NAVIGATION], tr("Yes"));
|
||||
|
||||
optionBrowser.TriggerUpdate();
|
||||
}
|
||||
|
||||
if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) || PAD_ButtonsDown(0) & PAD_BUTTON_B)
|
||||
{
|
||||
if(focus == 0)
|
||||
{
|
||||
focus = 1;
|
||||
mainWindow->ChangeFocus(&w);
|
||||
}
|
||||
else
|
||||
{
|
||||
focus = 0;
|
||||
mainWindow->ChangeFocus(&optionBrowser);
|
||||
}
|
||||
HaltResumeGui();
|
||||
}
|
||||
|
||||
if(backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
strcpy (Options.temp_code, Settings.code);
|
||||
Options.temp_network = Options.network;
|
||||
Options.temp_newrevtext = Options.newrevtext;
|
||||
menu = MENU_SETTINGS;
|
||||
}
|
||||
|
||||
if(saveBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
// Theme ändern
|
||||
if(stricmp(Options.theme, options.value[THEME]) != 0 || GetMenuSettingsThemeDL())
|
||||
{
|
||||
sprintf (Options.theme, options.value[THEME]);
|
||||
DefaultTheme();
|
||||
if(stricmp(Options.theme, tr("STANDARD")) != 0)
|
||||
theme(Settings.device_dat + ":/config/Homebrew Filter/themes/" + Options.theme + "/");
|
||||
// Cursor und Hintergrund ändern
|
||||
#ifdef HW_RVL
|
||||
pointer = new GuiImageData(Theme.player_point);
|
||||
#endif
|
||||
|
||||
mainWindow->Remove(bgImg);
|
||||
bgImg = new GuiImage(new GuiImageData(Theme.background));
|
||||
mainWindow->Append(bgImg);
|
||||
}
|
||||
|
||||
// Schriftart ändern
|
||||
if(stricmp(Options.font, options.value[FONT]) != 0 || GetMenuSettingsFontDL())
|
||||
{
|
||||
sprintf(Options.font, options.value[FONT]);
|
||||
// change font
|
||||
HaltGui();
|
||||
SetFont();
|
||||
ResumeGui();
|
||||
}
|
||||
|
||||
strcpy(Settings.code, Options.temp_code);
|
||||
Options.slide_effect = atoi(options.value[SLIDE_EFFECT]);
|
||||
Options.last_category = last_category;
|
||||
Options.apps = atoi(options.value[NUMBER_OF_APPS]);
|
||||
Options.quick_start = quick_start;
|
||||
Options.device_icon = device_icon;
|
||||
device_dat = options.value[STORAGE_DEVICE];
|
||||
Options.navigation = navigation;
|
||||
Options.network = Options.temp_network;
|
||||
Options.newrevtext = Options.temp_newrevtext;
|
||||
|
||||
if(device_dat == "SD")
|
||||
Settings.device_dat = "sd1";
|
||||
else if(device_dat == "USB")
|
||||
Settings.device_dat = "usb1";
|
||||
|
||||
// Sprache ändern zum schluss wegen STANDARD
|
||||
if(stricmp(Options.language, options.value[LANGUAGE]) != 0 || GetMenuSettingsLanguageDL())
|
||||
{
|
||||
sprintf (Options.language, options.value[LANGUAGE]);
|
||||
|
||||
bool theme = 0, language = 0, font = 0;
|
||||
if(stricmp(Options.theme, tr("STANDARD")) == 0)
|
||||
theme = 1;
|
||||
|
||||
if(stricmp(Options.language, tr("STANDARD")) == 0)
|
||||
language = 1;
|
||||
|
||||
if(stricmp(Options.font, tr("STANDARD")) == 0)
|
||||
font = 1;
|
||||
|
||||
/*********************************************************************/
|
||||
if(stricmp(Options.language, tr("STANDARD")) == 0)
|
||||
translate();
|
||||
else
|
||||
ini_Open(check_path(Settings.device_dat + ":/config/Homebrew Filter/languages/") + Options.language + ".lang");
|
||||
/*********************************************************************/
|
||||
|
||||
AvailableCategory.categories[0] = tr(Settings.category_name_all);
|
||||
|
||||
if(theme)
|
||||
sprintf(Options.theme, tr("STANDARD"));
|
||||
|
||||
if(language)
|
||||
sprintf(Options.language, tr("STANDARD"));
|
||||
|
||||
if(font)
|
||||
sprintf(Options.font, tr("STANDARD"));
|
||||
}
|
||||
|
||||
menu = MENU_SETTINGS;
|
||||
}
|
||||
}
|
||||
HaltGui();
|
||||
Options.temp_last_setting = 0;
|
||||
|
||||
mainWindow->Remove(&optionBrowser);
|
||||
mainWindow->Remove(&w);
|
||||
return menu;
|
||||
}
|
225
source/Menus/menu_settings_font.cpp
Normal file
@ -0,0 +1,225 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "main.h"
|
||||
#include "menu.h"
|
||||
#include "Prompts/prompts.h"
|
||||
#include "Tools/FontSystem.h"
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
extern void HaltResumeGui();
|
||||
|
||||
bool font_dl = false;
|
||||
|
||||
/****************************************************************************
|
||||
* MenuSettingsFile
|
||||
***************************************************************************/
|
||||
|
||||
int MenuSettingsFont()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
|
||||
int ret = -1;
|
||||
int activated = -1;
|
||||
int i = 0;
|
||||
int focus = 0;
|
||||
|
||||
OptionList options;
|
||||
|
||||
sprintf(options.name[i], tr("STANDARD"));
|
||||
if(stricmp(Options.temp_font.c_str(), tr("STANDARD")) == 0)
|
||||
{
|
||||
sprintf (options.value[i], tr("activated"));
|
||||
activated = i;
|
||||
}
|
||||
else
|
||||
sprintf (options.value[i], " ");
|
||||
|
||||
i++;
|
||||
|
||||
DIR *dirHandle;
|
||||
struct dirent * dirEntry;
|
||||
dirHandle = opendir(check_path(Settings.device_dat + ":/config/Homebrew Filter/Fonts").c_str());
|
||||
if (dirHandle) {
|
||||
while (0 != (dirEntry = readdir(dirHandle)))
|
||||
{
|
||||
if(stricmp(dirEntry->d_name, ".") != 0 && stricmp(dirEntry->d_name, "..") != 0)
|
||||
{
|
||||
string temp = dirEntry->d_name;
|
||||
if(temp.length() > 3 && stricmp(temp.substr(temp.length() -4, 4).c_str(), ".ttf") == 0)
|
||||
{
|
||||
sprintf(options.name[i], temp.c_str());
|
||||
|
||||
if(stricmp(Options.temp_font.c_str(), temp.c_str()) == 0)
|
||||
{
|
||||
sprintf (options.value[i], tr("activated"));
|
||||
activated = i;
|
||||
}
|
||||
else
|
||||
sprintf (options.value[i], " ");
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirHandle);
|
||||
}
|
||||
|
||||
options.length = i;
|
||||
|
||||
GuiImageData bgImgData(Theme.background);
|
||||
GuiImageData btnOutline(Theme.button_small);
|
||||
GuiImageData btnOutlineOver(Theme.button_small_focus);
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
GuiImage bgImg(&bgImgData);
|
||||
|
||||
GuiText titleTxt(tr("Fonts"), 28, (GXColor){Theme.title_1, Theme.title_2, Theme.title_3, 255});
|
||||
titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
titleTxt.SetPosition(50,50);
|
||||
|
||||
GuiText downloadBtnTxt(tr("Download"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage downloadBtnImg(&btnOutline);
|
||||
GuiImage downloadBtnImgOver(&btnOutlineOver);
|
||||
GuiButton downloadBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
downloadBtn.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
downloadBtn.SetPosition(-100, 38);
|
||||
downloadBtn.SetLabel(&downloadBtnTxt);
|
||||
downloadBtn.SetImage(&downloadBtnImg);
|
||||
downloadBtn.SetImageOver(&downloadBtnImgOver);
|
||||
downloadBtn.SetTrigger(&trigA);
|
||||
downloadBtn.SetEffectGrow();
|
||||
|
||||
GuiText okBtnTxt(tr("OK"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage okBtnImg(&btnOutline);
|
||||
GuiImage okBtnImgOver(&btnOutlineOver);
|
||||
GuiButton okBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
okBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
okBtn.SetPosition(100, -35);
|
||||
okBtn.SetLabel(&okBtnTxt);
|
||||
okBtn.SetImage(&okBtnImg);
|
||||
okBtn.SetImageOver(&okBtnImgOver);
|
||||
okBtn.SetTrigger(&trigA);
|
||||
okBtn.SetEffectGrow();
|
||||
|
||||
GuiText backBtnTxt(tr("Stop"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage backBtnImg(&btnOutline);
|
||||
GuiImage backBtnImgOver(&btnOutlineOver);
|
||||
GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
backBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
backBtn.SetPosition(-100, -35);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetImage(&backBtnImg);
|
||||
backBtn.SetImageOver(&backBtnImgOver);
|
||||
backBtn.SetTrigger(&trigA);
|
||||
backBtn.SetEffectGrow();
|
||||
|
||||
GuiOptionBrowser optionBrowser(552, 248, &options);
|
||||
optionBrowser.SetPosition(0, 108);
|
||||
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
optionBrowser.SetCol2Position(340);
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&bgImg);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&downloadBtn);
|
||||
w.Append(&okBtn);
|
||||
w.Append(&backBtn);
|
||||
mainWindow->Append(&w);
|
||||
mainWindow->Append(&optionBrowser);
|
||||
|
||||
mainWindow->ChangeFocus(&optionBrowser);
|
||||
ResumeGui();
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
||||
ret = optionBrowser.GetClickedOption();
|
||||
|
||||
if(ret != -1)
|
||||
{
|
||||
for(i=0; i < options.length; i++)
|
||||
{
|
||||
if(i == ret)
|
||||
{
|
||||
sprintf (options.value[i], tr("activated"));
|
||||
activated = i;
|
||||
}
|
||||
else
|
||||
sprintf (options.value[i], " ");
|
||||
}
|
||||
optionBrowser.TriggerUpdate();
|
||||
}
|
||||
|
||||
if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) || PAD_ButtonsDown(0) & PAD_BUTTON_B)
|
||||
{
|
||||
if(focus == 0)
|
||||
{
|
||||
focus = 1;
|
||||
mainWindow->ChangeFocus(&w);
|
||||
}
|
||||
else
|
||||
{
|
||||
focus = 0;
|
||||
mainWindow->ChangeFocus(&optionBrowser);
|
||||
}
|
||||
HaltResumeGui();
|
||||
}
|
||||
|
||||
if(downloadBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
downloadBtn.ResetState();
|
||||
string fontdownload = checkFontsPrompt();
|
||||
|
||||
if(fontdownload != "NULL")
|
||||
{
|
||||
if(font_folder_exists())
|
||||
{
|
||||
fontDownload(fontdownload);
|
||||
menu = MENU_SETTINGS_FONT;
|
||||
font_dl = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(okBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
Options.temp_font = options.name[activated];
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
|
||||
if(backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
}
|
||||
HaltGui();
|
||||
mainWindow->Remove(&optionBrowser);
|
||||
mainWindow->Remove(&w);
|
||||
return menu;
|
||||
}
|
||||
|
||||
bool GetMenuSettingsFontDL()
|
||||
{
|
||||
return font_dl;
|
||||
}
|
||||
|
||||
void SetMenuSettingsFontDL(bool dl)
|
||||
{
|
||||
font_dl = dl;
|
||||
}
|
223
source/Menus/menu_settings_language.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "libwiigui/gui.h"
|
||||
#include "menu.h"
|
||||
#include "main.h"
|
||||
#include "Prompts/prompts.h"
|
||||
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
extern void HaltResumeGui();
|
||||
|
||||
bool language_dl = false;
|
||||
|
||||
/****************************************************************************
|
||||
* MenuSettingsFile
|
||||
***************************************************************************/
|
||||
|
||||
int MenuSettingsLanguage()
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
|
||||
int ret = -1;
|
||||
int activated = -1;
|
||||
int i = 0;
|
||||
int focus = 0;
|
||||
|
||||
OptionList options;
|
||||
|
||||
sprintf(options.name[i], tr("STANDARD"));
|
||||
if(stricmp(Options.temp_language.c_str(), tr("STANDARD")) == 0)
|
||||
{
|
||||
sprintf (options.value[i], tr("activated"));
|
||||
activated = i;
|
||||
}
|
||||
else
|
||||
sprintf (options.value[i], " ");
|
||||
|
||||
i++;
|
||||
|
||||
DIR *dirHandle;
|
||||
struct dirent * dirEntry;
|
||||
|
||||
dirHandle = opendir(check_path(Settings.device_dat + ":/config/Homebrew Filter/Languages").c_str());
|
||||
if (dirHandle)
|
||||
{
|
||||
while (0 != (dirEntry = readdir(dirHandle)))
|
||||
{
|
||||
if(stricmp(dirEntry->d_name, ".") != 0 && stricmp(dirEntry->d_name, "..") != 0)
|
||||
{
|
||||
string temp = dirEntry->d_name;
|
||||
if(temp.length() > 4 && stricmp(temp.substr(temp.length() -5, 5).c_str(), ".lang") == 0)
|
||||
{
|
||||
temp.erase(temp.length() -5, 5); // endung entfernen
|
||||
sprintf(options.name[i], temp.c_str());
|
||||
|
||||
if(stricmp(Options.temp_language.c_str(), temp.c_str()) == 0)
|
||||
{
|
||||
sprintf (options.value[i], tr("activated"));
|
||||
activated = i;
|
||||
}
|
||||
else
|
||||
sprintf (options.value[i], " ");
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirHandle);
|
||||
}
|
||||
|
||||
options.length = i;
|
||||
|
||||
GuiImageData bgImgData(Theme.background);
|
||||
GuiImageData btnOutline(Theme.button_small);
|
||||
GuiImageData btnOutlineOver(Theme.button_small_focus);
|
||||
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
GuiImage bgImg(&bgImgData);
|
||||
|
||||
GuiText titleTxt(tr("Languages"), 28, (GXColor){Theme.title_1, Theme.title_2, Theme.title_3, 255});
|
||||
titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
titleTxt.SetPosition(50,50);
|
||||
|
||||
GuiText downloadBtnTxt(tr("Download"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage downloadBtnImg(&btnOutline);
|
||||
GuiImage downloadBtnImgOver(&btnOutlineOver);
|
||||
GuiButton downloadBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
downloadBtn.SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
|
||||
downloadBtn.SetPosition(-100, 38);
|
||||
downloadBtn.SetLabel(&downloadBtnTxt);
|
||||
downloadBtn.SetImage(&downloadBtnImg);
|
||||
downloadBtn.SetImageOver(&downloadBtnImgOver);
|
||||
downloadBtn.SetTrigger(&trigA);
|
||||
downloadBtn.SetEffectGrow();
|
||||
|
||||
GuiText okBtnTxt(tr("OK"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage okBtnImg(&btnOutline);
|
||||
GuiImage okBtnImgOver(&btnOutlineOver);
|
||||
GuiButton okBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
okBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
|
||||
okBtn.SetPosition(100, -35);
|
||||
okBtn.SetLabel(&okBtnTxt);
|
||||
okBtn.SetImage(&okBtnImg);
|
||||
okBtn.SetImageOver(&okBtnImgOver);
|
||||
okBtn.SetTrigger(&trigA);
|
||||
okBtn.SetEffectGrow();
|
||||
|
||||
GuiText backBtnTxt(tr("Stop"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
|
||||
GuiImage backBtnImg(&btnOutline);
|
||||
GuiImage backBtnImgOver(&btnOutlineOver);
|
||||
GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
|
||||
backBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
|
||||
backBtn.SetPosition(-100, -35);
|
||||
backBtn.SetLabel(&backBtnTxt);
|
||||
backBtn.SetImage(&backBtnImg);
|
||||
backBtn.SetImageOver(&backBtnImgOver);
|
||||
backBtn.SetTrigger(&trigA);
|
||||
backBtn.SetEffectGrow();
|
||||
|
||||
GuiOptionBrowser optionBrowser(552, 248, &options);
|
||||
optionBrowser.SetPosition(0, 108);
|
||||
optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
optionBrowser.SetCol2Position(340);
|
||||
|
||||
HaltGui();
|
||||
GuiWindow w(screenwidth, screenheight);
|
||||
w.Append(&bgImg);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&downloadBtn);
|
||||
w.Append(&okBtn);
|
||||
w.Append(&backBtn);
|
||||
mainWindow->Append(&w);
|
||||
mainWindow->Append(&optionBrowser);
|
||||
|
||||
mainWindow->ChangeFocus(&optionBrowser);
|
||||
ResumeGui();
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
usleep(100);
|
||||
|
||||
ret = optionBrowser.GetClickedOption();
|
||||
|
||||
if(ret != -1)
|
||||
{
|
||||
for(i=0; i < options.length; i++)
|
||||
{
|
||||
if(i == ret)
|
||||
{
|
||||
sprintf (options.value[i], tr("activated"));
|
||||
activated = i;
|
||||
}
|
||||
else
|
||||
sprintf (options.value[i], " ");
|
||||
}
|
||||
optionBrowser.TriggerUpdate();
|
||||
}
|
||||
|
||||
if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) || PAD_ButtonsDown(0) & PAD_BUTTON_B)
|
||||
{
|
||||
if(focus == 0)
|
||||
{
|
||||
focus = 1;
|
||||
mainWindow->ChangeFocus(&w);
|
||||
}
|
||||
else
|
||||
{
|
||||
focus = 0;
|
||||
mainWindow->ChangeFocus(&optionBrowser);
|
||||
}
|
||||
HaltResumeGui();
|
||||
}
|
||||
|
||||
if(downloadBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
downloadBtn.ResetState();
|
||||
string languagedownload = checkLanguagesPrompt();
|
||||
|
||||
if(languagedownload != "NULL" && language_folder_exists())
|
||||
{
|
||||
languageDownload(languagedownload);
|
||||
menu = MENU_SETTINGS_LANGUAGE;
|
||||
language_dl = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(okBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
Options.temp_language = options.name[activated];
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
|
||||
if(backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
Options.temp_last_setting = 1;
|
||||
menu = MENU_SETTINGS_FILE;
|
||||
}
|
||||
}
|
||||
HaltGui();
|
||||
mainWindow->Remove(&optionBrowser);
|
||||
mainWindow->Remove(&w);
|
||||
return menu;
|
||||
}
|
||||
|
||||
bool GetMenuSettingsLanguageDL()
|
||||
{
|
||||
return language_dl;
|
||||
}
|
||||
|
||||
void SetMenuSettingsLanguageDL(bool dl)
|
||||
{
|
||||
language_dl = dl;
|
||||
}
|