commit 1c9f2601a86ab5009babc327a6146d00dc2b3554 Author: Joel16 Date: Mon Jul 11 23:03:30 2022 -0400 ntpsp: Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c96bc30 --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +# Prerequisites +*.d +.vscode/ + +# Object files +*.o +*.ko +*.obj +*.elf +*.SFO + +# Linker output +*.ilk +*.map + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +*.PBP + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# CMFileManager PSP Specific objects +app/NTPSP.prx +app/drivers/*.S +app/data/rtc_driver.prx diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f629479 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, Joel +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. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0da9f81 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +SUBDIRS = plugin app + +all: + @for dir in $(SUBDIRS); do $(MAKE) -C $$dir; done + +clean: + @for dir in $(SUBDIRS); do $(MAKE) clean -C $$dir; done diff --git a/app/Makefile b/app/Makefile new file mode 100755 index 0000000..60fd52a --- /dev/null +++ b/app/Makefile @@ -0,0 +1,44 @@ +TARGET = NTPSP + +SOURCES := data drivers source +CFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.c)) +SFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.S)) +CPPFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.cpp)) +FONTFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.pgf)) +GFXFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.png)) +PRXFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.prx)) + +OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(SFILES:.S=.o) $(CPPFILES:.cpp=.o) \ + $(FONTFILES:.pgf=.o) $(GFXFILES:.png=.o) $(PRXFILES:.prx=.o) + +VERSION_MAJOR := 1 +VERSION_MINOR := 0 + +INCDIR = ../libs/ ../libs/include include +CFLAGS = -Os -G0 -Wall -ffast-math -Wno-narrowing -Wno-unused-variable \ + -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -std=gnu++17 +ASFLAGS := $(CFLAGS) + +BUILD_PRX = 1 +PSP_LARGE_MEMORY = 1 + +LIBDIR = ../libs/lib +LDFLAGS = -nostdlib -nodefaultlibs +LIBS = -lpspmodinfo -lpsprtc -lvlfgui -lvlfgu -lvlfutils -lvlflibc + +EXTRA_TARGETS = EBOOT.PBP +PSP_EBOOT_TITLE = NTPSP v$(VERSION_MAJOR).$(VERSION_MINOR)$(VERSION_MICRO) +# PSP_EBOOT_ICON = ../ICON0.PNG + +PSPSDK=$(shell psp-config --pspsdk-path) +include ./build.mak + +%.o: %.pgf + bin2o -i $< $@ $(addsuffix _pgf, $(basename $(notdir $<) )) + +%.o: %.png + bin2o -i $< $@ $(addsuffix _png, $(basename $(notdir $<) )) + +%.o: %.prx + bin2o -i $< $@ $(addsuffix _prx, $(basename $(notdir $<) )) diff --git a/app/build.mak b/app/build.mak new file mode 100755 index 0000000..82f4740 --- /dev/null +++ b/app/build.mak @@ -0,0 +1,190 @@ +# PSP Software Development Kit - http://www.pspdev.org +# ----------------------------------------------------------------------- +# Licensed under the BSD license, see LICENSE in PSPSDK root for details. +# +# build.mak - Base makefile for projects using PSPSDK. +# +# Copyright (c) 2005 Marcus R. Brown +# Copyright (c) 2005 James Forshaw +# Copyright (c) 2005 John Kelley +# +# $Id: build.mak 2333 2007-10-31 19:37:40Z tyranid $ + +# Note: The PSPSDK make variable must be defined before this file is included. +ifeq ($(PSPSDK),) +$(error $$(PSPSDK) is undefined. Use "PSPSDK := $$(shell psp-config --pspsdk-path)" in your Makefile) +endif + +CC = psp-gcc +CXX = psp-g++ +AS = psp-gcc +LD = psp-gcc +AR = psp-ar +RANLIB = psp-ranlib +STRIP = psp-strip +MKSFO = mksfo +PACK_PBP = pack-pbp +FIXUP = psp-fixup-imports + +# Add in PSPSDK includes and libraries. +INCDIR := $(INCDIR) . $(PSPSDK)/include +LIBDIR := $(LIBDIR) . $(PSPSDK)/lib + +CFLAGS := $(addprefix -I,$(INCDIR)) $(CFLAGS) +CXXFLAGS := $(CFLAGS) $(CXXFLAGS) +ASFLAGS := $(CFLAGS) $(ASFLAGS) + +ifeq ($(PSP_LARGE_MEMORY),1) +MKSFO = mksfoex -d MEMSIZE=1 +endif + +ifeq ($(PSP_FW_VERSION),) +PSP_FW_VERSION=150 +endif + +CFLAGS += -D_PSP_FW_VERSION=$(PSP_FW_VERSION) +CXXFLAGS += -D_PSP_FW_VERSION=$(PSP_FW_VERSION) + +ifeq ($(BUILD_PRX),1) +LDFLAGS := $(addprefix -L,$(LIBDIR)) -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx $(LDFLAGS) +EXTRA_CLEAN += $(TARGET).elf +# Setup default exports if needed +ifdef PRX_EXPORTS +EXPORT_OBJ=$(patsubst %.exp,%.o,$(PRX_EXPORTS)) +EXTRA_CLEAN += $(EXPORT_OBJ) +else +EXPORT_OBJ=$(PSPSDK)/lib/prxexports.o +endif +else +LDFLAGS := $(addprefix -L,$(LIBDIR)) $(LDFLAGS) +endif + +# Library selection. By default we link with Newlib's libc. Allow the +# user to link with PSPSDK's libc if USE_PSPSDK_LIBC is set to 1. + +PSPSDK_LIBC_LIB = + +# Link with following default libraries. Other libraries should be specified in the $(LIBS) variable. +# TODO: This library list needs to be generated at configure time. +# +ifeq ($(USE_KERNEL_LIBS),1) +PSPSDK_LIBS = -lpspdebug -lpspdisplay_driver -lpspctrl_driver -lpspsdk +LIBS := $(LIBS) $(PSPSDK_LIBS) $(PSPSDK_LIBC_LIB) -lpspkernel +else +ifeq ($(USE_USER_LIBS),1) +PSPSDK_LIBS = -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk +LIBS := $(LIBS) $(PSPSDK_LIBS) $(PSPSDK_LIBC_LIB) -lpspnet \ + -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility \ + -lpspuser +else +PSPSDK_LIBS = -lpspdisplay -lpspge -lpspctrl -lpspsdk +LIBS := $(LIBS) $(PSPSDK_LIBS) $(PSPSDK_LIBC_LIB) -lpspnet \ + -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility \ + -lpspuser -lpspkernel +endif +endif + +# Define the overridable parameters for EBOOT.PBP +ifndef PSP_EBOOT_TITLE +PSP_EBOOT_TITLE = $(TARGET) +endif + +ifndef PSP_EBOOT_SFO +PSP_EBOOT_SFO = PARAM.SFO +endif + +ifndef PSP_EBOOT_ICON +PSP_EBOOT_ICON = NULL +endif + +ifndef PSP_EBOOT_ICON1 +PSP_EBOOT_ICON1 = NULL +endif + +ifndef PSP_EBOOT_UNKPNG +PSP_EBOOT_UNKPNG = NULL +endif + +ifndef PSP_EBOOT_PIC1 +PSP_EBOOT_PIC1 = NULL +endif + +ifndef PSP_EBOOT_SND0 +PSP_EBOOT_SND0 = NULL +endif + +ifndef PSP_EBOOT_PSAR +PSP_EBOOT_PSAR = NULL +endif + +ifndef PSP_EBOOT +PSP_EBOOT = EBOOT.PBP +endif + +ifeq ($(BUILD_PRX),1) +ifneq ($(TARGET_LIB),) +$(error TARGET_LIB should not be defined when building a prx) +else +FINAL_TARGET = $(TARGET).prx +endif +else +ifneq ($(TARGET_LIB),) +FINAL_TARGET = $(TARGET_LIB) +else +FINAL_TARGET = $(TARGET).elf +endif +endif + +all: $(EXTRA_TARGETS) $(FINAL_TARGET) + +kxploit: $(TARGET).elf $(PSP_EBOOT_SFO) + mkdir -p "$(TARGET)" + $(STRIP) $(TARGET).elf -o $(TARGET)/$(PSP_EBOOT) + mkdir -p "$(TARGET)%" + $(PACK_PBP) "$(TARGET)%/$(PSP_EBOOT)" $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON) \ + $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1) \ + $(PSP_EBOOT_SND0) NULL $(PSP_EBOOT_PSAR) + +SCEkxploit: $(TARGET).elf $(PSP_EBOOT_SFO) + mkdir -p "__SCE__$(TARGET)" + $(STRIP) $(TARGET).elf -o __SCE__$(TARGET)/$(PSP_EBOOT) + mkdir -p "%__SCE__$(TARGET)" + $(PACK_PBP) "%__SCE__$(TARGET)/$(PSP_EBOOT)" $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON) \ + $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1) \ + $(PSP_EBOOT_SND0) NULL $(PSP_EBOOT_PSAR) + +$(TARGET).elf: $(OBJS) $(EXPORT_OBJ) + $(LINK.c) $^ $(LIBS) -o $@ + $(FIXUP) $@ + +$(TARGET_LIB): $(OBJS) + $(AR) cru $@ $(OBJS) + $(RANLIB) $@ + +$(PSP_EBOOT_SFO): + $(MKSFO) '$(PSP_EBOOT_TITLE)' $@ + +ifeq ($(BUILD_PRX),1) +$(PSP_EBOOT): $(TARGET).prx $(PSP_EBOOT_SFO) + $(PACK_PBP) $(PSP_EBOOT) $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON) \ + $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1) \ + $(PSP_EBOOT_SND0) $(TARGET).prx $(PSP_EBOOT_PSAR) +else +$(PSP_EBOOT): $(TARGET).elf $(PSP_EBOOT_SFO) + $(STRIP) $(TARGET).elf -o $(TARGET)_strip.elf + $(PACK_PBP) $(PSP_EBOOT) $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON) \ + $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1) \ + $(PSP_EBOOT_SND0) $(TARGET)_strip.elf $(PSP_EBOOT_PSAR) + -rm -f $(TARGET)_strip.elf +endif + +%.prx: %.elf + psp-prxgen $< $@ + +%.c: %.exp + psp-build-exports -b $< > $@ + +clean: + -rm -f $(FINAL_TARGET) $(EXTRA_CLEAN) $(OBJS) $(PSP_EBOOT_SFO) $(PSP_EBOOT) $(EXTRA_TARGETS) + +rebuild: clean all diff --git a/app/data/intraFont.prx b/app/data/intraFont.prx new file mode 100755 index 0000000..2b5a94b Binary files /dev/null and b/app/data/intraFont.prx differ diff --git a/app/data/iop.prx b/app/data/iop.prx new file mode 100755 index 0000000..5034ce6 Binary files /dev/null and b/app/data/iop.prx differ diff --git a/app/data/logo.png b/app/data/logo.png new file mode 100755 index 0000000..bd0a4bc Binary files /dev/null and b/app/data/logo.png differ diff --git a/app/data/vlf.prx b/app/data/vlf.prx new file mode 100755 index 0000000..786647e Binary files /dev/null and b/app/data/vlf.prx differ diff --git a/app/include/log.h b/app/include/log.h new file mode 100644 index 0000000..81f6309 --- /dev/null +++ b/app/include/log.h @@ -0,0 +1,3 @@ +#pragma once + +int debug(const char *format, ...); diff --git a/app/include/net.h b/app/include/net.h new file mode 100644 index 0000000..b7c2cb3 --- /dev/null +++ b/app/include/net.h @@ -0,0 +1,4 @@ +#pragma once + +int netInit(void); +void netExit(void); diff --git a/app/include/ntp.h b/app/include/ntp.h new file mode 100644 index 0000000..df5bc32 --- /dev/null +++ b/app/include/ntp.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +int ntpGetTime(pspTime *psp_time_ntp); diff --git a/app/include/utils.h b/app/include/utils.h new file mode 100644 index 0000000..11d9f0f --- /dev/null +++ b/app/include/utils.h @@ -0,0 +1,6 @@ +#pragma once + +/// Checks whether a result code indicates success. +#define R_SUCCEEDED(res) ((res) >= 0) +/// Checks whether a result code indicates failure. +#define R_FAILED(res) ((res) < 0) diff --git a/app/source/crt0.c b/app/source/crt0.c new file mode 100755 index 0000000..49d62e7 --- /dev/null +++ b/app/source/crt0.c @@ -0,0 +1,78 @@ +#include +#include +#include + +#include + +extern unsigned char intraFont_prx_start[], iop_prx_start[], rtc_driver_prx_start[], vlf_prx_start[]; +extern unsigned int intraFont_prx_size, iop_prx_size, rtc_driver_prx_size, vlf_prx_size; + +extern int app_main(int argc, char *argv[]); + +int SetupCallbacks(void) { + int CallbackThread(SceSize args, void *argp) { + int exit_callback(int arg1, int arg2, void *common) { + sceKernelExitGame(); + return 0; + } + + int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); + sceKernelRegisterExitCallback(cbid); + sceKernelSleepThreadCB(); + return 0; + } + + int thid = sceKernelCreateThread("NTPSP_callback_thread", CallbackThread, 0x11, 0xFA0, 0, 0); + if (thid >= 0) + sceKernelStartThread(thid, 0, 0); + + return thid; +} + +void LoadStartModuleBuffer(const char *path, const void *buf, int size, SceSize args, void *argp) { + SceUID mod, out; + + sceIoRemove(path); + out = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777); + sceIoWrite(out, buf, size); + sceIoClose(out); + + mod = sceKernelLoadModule(path, 0, NULL); + mod = sceKernelStartModule(mod, args, argp, NULL, NULL); + sceIoRemove(path); +} + +int start_thread(SceSize args, void *argp) { + char *path = (char *)argp; + int last_trail = -1; + + for(int i = 0; path[i]; i++) { + if (path[i] == '/') + last_trail = i; + } + + if (last_trail >= 0) + path[last_trail] = 0; + + sceIoChdir(path); + path[last_trail] = '/'; + + LoadStartModuleBuffer("intraFont.prx", intraFont_prx_start, intraFont_prx_size, args, argp); + LoadStartModuleBuffer("iop.prx", iop_prx_start, iop_prx_size, args, argp); + LoadStartModuleBuffer("rtc_driver.prx", rtc_driver_prx_start, rtc_driver_prx_size, args, argp); + LoadStartModuleBuffer("vlf.prx", vlf_prx_start, vlf_prx_size, args, argp); + + vlfGuiInit(15000, app_main); + return sceKernelExitDeleteThread(0); +} + +int module_start(SceSize args, void *argp) { + SetupCallbacks(); + + SceUID thread = sceKernelCreateThread("NTPSP_start_thread", start_thread, 0x10, 0x4000, 0, NULL); + if (thread < 0) + return thread; + + sceKernelStartThread(thread, args, argp); + return 0; +} diff --git a/app/source/log.c b/app/source/log.c new file mode 100644 index 0000000..f1686a5 --- /dev/null +++ b/app/source/log.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +#include "utils.h" + +int debug(const char *format, ...) { + SceUID log = 0; + + if (R_SUCCEEDED(log = sceIoOpen("debug.log", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_APPEND, 0777))) { + va_list list; + char string[256] = {0}; + + va_start(list, format); + vsprintf(string, format, list); + va_end(list); + + printf("%s", string); + + int ret = 0; + if (R_FAILED(ret = sceIoWrite(log, string, strlen(string)))) + return ret; + + sceIoClose(log); + } + + return 0; +} diff --git a/app/source/main.c b/app/source/main.c new file mode 100755 index 0000000..bc0a3dc --- /dev/null +++ b/app/source/main.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#include "net.h" +#include "ntp.h" + +PSP_MODULE_INFO("NTPSP", PSP_MODULE_USER, VERSION_MAJOR, VERSION_MINOR); +PSP_MAIN_THREAD_ATTR(0); + +extern unsigned char logo_png_start[]; +extern unsigned int logo_png_size; + +static pspTime psp_time_ntp = { 0 }; +static VlfText title_text; +static VlfPicture logo, title_pic; + +static void vlfSetTitle(char *fmt, ...) { + va_list list; + char text[64]; + + va_start(list, fmt); + vsprintf(text, fmt, list); + va_end(list); + + if (title_text != NULL) + vlfGuiRemoveText(title_text); + + if (title_pic != NULL) + vlfGuiRemovePicture(title_pic); + + title_text = vlfGuiAddText(0, 0, text); + title_pic = vlfGuiAddPictureResource("ps3scan_plugin.rco", "tex_infobar_icon", 4, -2); + vlfGuiSetTitleBar(title_text, title_pic, 1, 0); +} + +int menuSelection(int selection) { + switch (selection) { + case 0: + vlfGuiNetConfDialog(); + ntpGetTime(&psp_time_ntp); + break; + + case 1: + sceKernelExitGame(); + break; + } + + return VLF_EV_RET_NOTHING; +} + +int app_main(int argc, char *argv[]) { + netInit(); + + const int num_menu_items = 2; + char *item_labels[] = { "Sync Clock", "Exit" }; + + vlfGuiSystemSetup(1, 1, 1); + vlfSetTitle("NTPSP v%d.%d", VERSION_MAJOR, VERSION_MINOR); + logo = vlfGuiAddPicture(logo_png_start, logo_png_size, 45, 36); // png's are now supported + vlfGuiLateralMenu(num_menu_items, item_labels, 0, menuSelection, 120); + + while (1) { + vlfGuiDrawFrame(); + } + + netExit(); + return 0; +} diff --git a/app/source/net.c b/app/source/net.c new file mode 100644 index 0000000..8a848c8 --- /dev/null +++ b/app/source/net.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include "log.h" +#include "utils.h" + +int netInit(void) { + int ret = 0; + + sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON); + sceUtilityLoadNetModule(PSP_NET_MODULE_INET); + + if (R_FAILED(ret = sceNetInit(128 * 1024, 42, 4 * 1024, 42, 4 * 1024))) { + debug("sceNetInit() failed: 0x%08x\n", ret); + return ret; + } + + if (R_FAILED(ret = sceNetInetInit())) { + debug("sceNetInetInit() failed: 0x%08x\n", ret); + return ret; + } + + if (R_FAILED(ret = sceNetApctlInit(0x8000, 48))) { + debug("sceNetApctlInit() failed: 0x%08x\n", ret); + return ret; + } + + return 0; +} + +void netExit(void) { + sceNetApctlTerm(); + sceNetInetTerm(); + sceNetTerm(); + sceUtilityUnloadNetModule(PSP_NET_MODULE_INET); + sceUtilityUnloadNetModule(PSP_NET_MODULE_COMMON); +} diff --git a/app/source/ntp.c b/app/source/ntp.c new file mode 100644 index 0000000..a7e7788 --- /dev/null +++ b/app/source/ntp.c @@ -0,0 +1,208 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "log.h" +#include "ntp.h" +#include "utils.h" + +#define NTP_TIMESTAMP_DELTA 2208988800ull +#define MAX_NAME 512 + +// Function defs +int sceRtcSetTime64_t(pspTime *date, const time_t time); +int pspRtcSetCurrentTick(u64 *tick); // Kernel function + +// ntp_packet structure from lettier/ntpclient https://github.com/lettier/ntpclient/blob/master/source/c/main.c#L50 +typedef struct { + u8 li_vn_mode; // Eight bits. li, vn, and mode. + // li. Two bits. Leap indicator. + // vn. Three bits. Version number of the protocol. + // mode. Three bits. Client will pick mode 3 for client. + + u8 stratum; // Eight bits. Stratum level of the local clock. + u8 poll; // Eight bits. Maximum interval between successive messages. + u8 precision; // Eight bits. Precision of the local clock. + + u32 rootDelay; // 32 bits. Total round trip delay time. + u32 rootDispersion; // 32 bits. Max error aloud from primary clock source. + u32 refId; // 32 bits. Reference clock identifier. + + u32 refTm_s; // 32 bits. Reference time-stamp seconds. + u32 refTm_f; // 32 bits. Reference time-stamp fraction of a second. + + u32 origTm_s; // 32 bits. Originate time-stamp seconds. + u32 origTm_f; // 32 bits. Originate time-stamp fraction of a second. + + u32 rxTm_s; // 32 bits. Received time-stamp seconds. + u32 rxTm_f; // 32 bits. Received time-stamp fraction of a second. + + u32 txTm_s; // 32 bits and the most important field the client cares about. Transmit time-stamp seconds. + u32 txTm_f; // 32 bits. Transmit time-stamp fraction of a second. +} ntp_packet; // Total: 384 bits or 48 bytes. + +static __inline__ unsigned int sceAllegrexWsbw(unsigned int x) { + return (((x & 0xFF)<<24) | ((x & 0xFF00)<<8) | ((x>>8) & 0xFF00) | ((x>>24) & 0xFF)); +} + +static __inline__ unsigned int sceAllegrexWsbh(unsigned int x) { + return (((x<<8) & 0xFF00FF00) | ((x>>8) & 0x00FF00FF)); +} + +static inline u32 sceNetHtonl(u32 hostlong) { + return sceAllegrexWsbw(hostlong); +} + +static inline u16 sceNetHtons(u16 hostshort) { + return sceAllegrexWsbh(hostshort); +} + +static inline u32 sceNetNtohl(u32 hostlong) { + return sceAllegrexWsbw(hostlong); +} + +// https://github.com/pspdev/pspsdk/blob/a095fcaa1f5ae28ddcae599d50a69c3a15ac1d34/src/libcglue/netdb.c#L75 +static struct hostent *sceGetHostByName(const char *name, int *h_errno) { + static struct hostent ent; + char buf[1024]; + static char sname[MAX_NAME] = ""; + static struct in_addr saddr = { 0 }; + static char *addrlist[2] = { (char *) &saddr, NULL }; + int rid; + *h_errno = NETDB_SUCCESS; + + if (sceNetInetInetAton(name, &saddr) == 0) { + int err; + + if (sceNetResolverCreate(&rid, buf, sizeof(buf)) < 0) { + *h_errno = NO_RECOVERY; + return NULL; + } + + err = sceNetResolverStartNtoA(rid, name, &saddr, 2, 3); + sceNetResolverDelete(rid); + + if (err < 0) { + *h_errno = HOST_NOT_FOUND; + return NULL; + } + } + + snprintf(sname, MAX_NAME, "%s", name); + ent.h_name = sname; + ent.h_aliases = 0; + ent.h_addrtype = AF_INET; + ent.h_length = sizeof(struct in_addr); + ent.h_addr_list = addrlist; + ent.h_addr = (char *) &saddr; + return &ent; +} + +int ntpGetTime(pspTime *psp_time_ntp) { + int ret = 0; + const char *server_name = "0.pool.ntp.org"; + const u16 port = 123; + + u64 curr_tick = 0; + if (R_FAILED(ret = sceRtcGetCurrentTick(&curr_tick))) { + debug("sceRtcGetCurrentTick failed: 0x%08x\n", ret); + return ret; + } + + pspTime curr_psp_time; + memset(&curr_psp_time, 0, sizeof(pspTime)); + if (R_FAILED(ret = sceRtcSetTick(&curr_psp_time, &curr_tick))) { + debug("sceRtcSetTick failed: 0x%08x\n", ret); + return ret; + } + + time_t curr_time; + if (R_FAILED(ret = sceRtcGetTime_t(&curr_psp_time, &curr_time))) { + debug("sceRtcGetTime_t failed: 0x%08x\n", ret); + return ret; + } + + ntp_packet packet; + memset(&packet, 0, sizeof(ntp_packet)); + packet.li_vn_mode = (0 << 6) | (4 << 3) | 3; // LI 0 | Client version 4 | Mode 3 + packet.txTm_s = sceNetHtonl(NTP_TIMESTAMP_DELTA + curr_time); // Current network time on the console + + struct sockaddr_in serv_addr; + struct hostent *server; + + int sockfd = sceNetInetSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (R_FAILED(sockfd)) { + debug("sceNetInetSocket failed: 0x%08x\n", sockfd); + sceNetInetClose(sockfd); + return sockfd; + } + + int err = 0; + if ((server = sceGetHostByName(server_name, &err)) == NULL) { + debug("sceGetHostByName failed: 0x%08x\n", err); + sceNetInetClose(sockfd); + return err; + } + + memset(&serv_addr, 0, sizeof(struct sockaddr_in)); + serv_addr.sin_family = AF_INET; + memcpy((char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr_list[0], 4); + serv_addr.sin_port = sceNetHtons(port); + + if ((ret = sceNetInetConnect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) { + debug("sceNetInetConnect failed: 0x%08x\n", ret); + sceNetInetClose(sockfd); + return -1; + } + + if ((ret = sceNetInetSend(sockfd, (char *)&packet, sizeof(ntp_packet), 0)) < 0) { + debug("sceNetInetSend failed: 0x%08x\n", ret); + sceNetInetClose(sockfd); + return -1; + } + + if ((ret = sceNetInetRecv(sockfd, (char *)&packet, sizeof(ntp_packet), 0)) < (int)sizeof(ntp_packet)) { + debug("sceNetInetRecv failed: 0x%08x\n", ret); + sceNetInetClose(sockfd); + return -1; + } + + packet.txTm_s = sceNetNtohl(packet.txTm_s); + time_t time_next = (time_t)(packet.txTm_s - NTP_TIMESTAMP_DELTA); + + pspTime psp_time_next; + memset(&psp_time_next, 0, sizeof(pspTime)); + sceRtcSetTime64_t(&psp_time_next, time_next); + debug("Time received from server -> %04d-%02d-%02d %02d:%02d:%02d %d\n", psp_time_next.year, psp_time_next.month, + psp_time_next.day, psp_time_next.hour, psp_time_next.minutes, psp_time_next.seconds, psp_time_next.microseconds); + + u64 tick_next = 0, utc_tick = 0; + if (R_FAILED(ret = sceRtcGetTick(&psp_time_next, &tick_next))) { + debug("sceRtcGetTick failed: 0x%08x\n", ret); + return ret; + } + + if (R_FAILED(ret = sceRtcConvertLocalTimeToUTC(&tick_next, &utc_tick))) { + debug("sceRtcConvertLocalTimeToUTC failed: 0x%08x\n", ret); + return ret; + } + + if (R_FAILED(ret = pspRtcSetCurrentTick(&tick_next))) { + debug("pspRtcSetCurrentTick failed: 0x%08x\n", ret); + return ret; + } + + memset(&psp_time_next, 0, sizeof(pspTime)); + sceRtcSetTick(&psp_time_next, &tick_next); + debug("After localtime to UTC conversion -> %04d-%02d-%02d %02d:%02d:%02d %d\n", psp_time_next.year, psp_time_next.month, + psp_time_next.day, psp_time_next.hour, psp_time_next.minutes, psp_time_next.seconds, psp_time_next.microseconds); + + sceNetInetClose(sockfd); + *psp_time_ntp = psp_time_next; + return 0; +} diff --git a/libs/include/vlf.h b/libs/include/vlf.h new file mode 100755 index 0000000..999f28e --- /dev/null +++ b/libs/include/vlf.h @@ -0,0 +1,2035 @@ +#ifndef __VLF_H__ +#define __VLF_H__ + +typedef struct _VlfText *VlfText; +typedef struct _VlfPicture *VlfPicture; +typedef struct _VlfShadowedPicture *VlfShadowedPicture; +typedef struct _VlfBatteryIcon *VlfBatteryIcon; +typedef struct _VlfSpin *VlfSpin; +typedef struct _VlfCheckBox *VlfCheckBox; +typedef struct _VlfProgressBar *VlfProgressBar; +typedef struct _VlfScrollBar *VlfScrollBar; +typedef struct _VlfInputBox *VlfInputBox; + + +#define VLF_DEFAULT -1 + +#define VLF_TITLEBAR_HEIGHT 22 + +#define VLF_ERROR_INVALID_INPUT (-1) +#define VLF_ERROR_INVALID_INPUT_DATA (-2) +#define VLF_ERROR_UNSUPPORTED_FORMAT (-3) +#define VLF_ERROR_OBJECT_OVERFLOW (-4) +#define VLF_ERROR_OBJECT_NOT_FOUND (-5) +#define VLF_ERROR_NO_MEMORY (-6) +#define VLF_ERROR_SYSTEM (-7) +#define VLF_ERROR_DUPLICATED (-8) + + +#define VLF_EV_RET_NOTHING 0 +#define VLF_EV_RET_REMOVE_EVENT 1 +#define VLF_EV_RET_REMOVE_OBJECTS 2 +#define VLF_EV_RET_REMOVE_HANDLERS 4 +#define VLF_EV_RET_REFRESH_ON_DELAY 8 +#define VLF_EV_RET_DELAY 0x80000000 /* Delay VLF_EV_RET_DELAY | (X << 16), 0 <= X <= 32767 milisecs */ +#define VLF_EV_RET_DELAY_FRAME (VLF_EV_RET_DELAY | 0x40000000) /* Delay VLF_EV_RET_DELAY_FRAME| (X << 16), 0 <= X <= 4095 */ + +/* Alignment */ + +enum VlfObjects +{ + VLF_TEXT = 0, + VLF_PIC = 1, + VLF_SHADOWED_PIC = 2, + VLF_PROGRESS_BAR = 3 +}; + +enum VlfTextAlignment +{ + VLF_ALIGNMENT_LEFT = 0, + VLF_ALIGNMENT_CENTER = 0x200, + VLF_ALIGNMENT_RIGHT = 0x400 +}; + +enum VlfButtonIcon +{ + VLF_ENTER = 0, + VLF_CANCEL = 1, + VLF_CROSS = 2, + VLF_CIRCLE = 3, + VLF_TRIANGLE = 4, + VLF_SQUARE = 5 +}; +/** Fade modes */ + +enum VlfFadeModesFlags +{ + VLF_FADE_MODE_IN = 1, + VLF_FADE_MODE_OUT = 2, + VLF_FADE_MODE_REPEAT = 4, +}; + +enum VlfFadeSpeed +{ + VLF_FADE_SPEED_STANDARD, + VLF_FADE_SPEED_FAST, + VLF_FADE_SPEED_VERY_FAST, + VLF_FADE_SPEED_SLOW, + VLF_FADE_SPEED_SUPER_FAST +}; + +enum VlfBatteryIconStatus +{ + VLF_BATTERY_ICON_HIGH, + VLF_BATTERY_ICON_MEDIUM, + VLF_BATTERY_ICON_LOW, + VLF_BATTERY_ICON_LOWEST +}; + +enum RCOType +{ + RCO_GRAPHIC, + RCO_OBJECT, + RCO_SOUND, + RCO_LABEL, + RCO_FILEPARAM, + RCO_ANIMPARAM +}; + +enum VLF_MDType +{ + VLF_MD_TYPE_ERROR, + VLF_MD_TYPE_NORMAL, +}; + +enum VLF_MD_Buttons +{ + VLF_MD_BUTTONS_NONE = 0, + VLF_MD_BUTTONS_YESNO = 0x10, +}; + +enum VLF_MD_InitalCursor +{ + VLF_MD_INITIAL_CURSOR_YES = 0, + VLF_MD_INITIAL_CURSOR_NO = 0x100, +}; + +enum VLF_MD_ButtonRes +{ + VLF_MD_NONE, + VLF_MD_YES, + VLF_MD_NO, + VLF_MD_BACK +}; + +enum VLF_DialogItem +{ + VLF_DI_ENTER, + VLF_DI_CANCEL, + VLF_DI_BACK, + VLF_DI_YES, + VLF_DI_NO, + VLF_DI_EDIT, +}; + +enum VLF_SpinState +{ + VLF_SPIN_STATE_NOT_FOCUS, // Spin control has not focus, buttons are not listened + VLF_SPIN_STATE_FOCUS, // Spin control text has focus but arrow is not shown, buttons are not listened + VLF_SPIN_STATE_ACTIVE, // Spin control has focus, and it is active (arrows are shown, up and down buttons are listened) +}; + +enum VLF_InputBoxType +{ + VLF_INPUTBOX_TYPE_NORMAL, + VLF_INPUTBOX_TYPE_PASSWORD +}; + +enum PspCtrlExtension +{ + PSP_CTRL_ENTER = 0x40000000, + PSP_CTRL_CANCEL = 0x80000000 +}; + +/** + * Inits VLF library + * + * @param heap_size - The heap size to be allocated. It can be negative. + * @param app_main - The program main application. +*/ +void vlfGuiInit(int heap_size, int (* app_main)(int argc, char *argv[])); + +/** + * Performs typical application initialization tasks (adding background, system model, and optionally battery icon and clock). + * + * @param battery - Inidicates if a battery icon should be added. + * @param clock - Indicates if a clock should be added. + * @param notuserwp - If user configuration is set to use a custom background and this param is 1, then the custom wallpaper won't be used. + * + * @returns 0 on success + * + * @Notes: If an user wallpaper is used, the background model ("waves") won't be added. + */ +int vlfGuiSystemSetup(int battery, int clock, int notuserwp); + +/** + * Gets language used by vlf application + * + * @returns - The language set to be used by current vlf application + * By default is initialized to user language. +*/ +int vlfGuiGetLanguage(); + +/** + * Sets language to be used by blf application + * + * @param lang - The language to be set. + * This only sets the language to be used by current vlf application, + * it doesn't overwrite user preferences in flash. + */ +void vlfGuiSetLanguage(int lang); + +/** + * Gets the button configuration used by vlf application (0 -> circle is enter, 1 -> cross is enter) + * + * @returns - The button configuration set to be used by current vlf application. + * By default is initialized with user preferences. +*/ +int vlfGuiGetButtonConfig(); + +/** + * Sets the button configuration to be used by current vlf application. + * + * @param config - The button configuration to be set (0 -> circle is enter, 1 -> cross is enter) + * This only sets the button configuration to be used by current vlf application, + * it doesn't overwrite user preferences in flash. +*/ +void vlfGuiSetButtonConfig(int config); + +/** + * Sets the directories where resources are located. + * + * @param dir - The directory that will be used to locate resources (max 256 chars including '\0') + * By default is initialized to flash0:/vsh/resource +*/ +void vlfGuiSetResourceDir(char *dir); + +/** + * Performs the draw of next frame +*/ +void vlfGuiDrawFrame(); + +/** + * Loads resources from a rco file + * + * @param rco - It can be one of following things: + * - path relative to the directory without extension (e.g. "system_plugin_bg") + * - path relative to the directory with extension (e.g. "system_plugin_bg.rco") + * - path to a file (e.g. "flash0:/vsh/resource/system_plugin_bg.rco", "ms0:/myresfile.rco") + * + * RCO param is evaluated in the order given above, so if a rco file exists in current directory with name + * "system_plugin_bg.rco", it would load the one of and not the one of current directory. (in such a case, use "./system_plugin_bg.rco") + * + * @param n - The number of resources to loads + * @param names (IN) - An array with the names of resources + * @param types (IN) - An array with the types of the resources (one of RCOType) + * @param datas (OUT) - A pointer to a variable that will receive an array of pointers to the content of each resource, + * or NULL if a specific resource has not been found. + * Pointers returned are allocated with malloc, and should be deallocated by the application. + * + * @param sizes (OUT) - It will receive the sizes of the resources + * @param pntable (OUT) - A pointer that will receive the string table. Pass NULL if no required. + * Returned pointer is allocated with malloc and should be deallocated by the application. + * + * @returns - the number of resources loaded, or < 0 if there is an error. + * + * @Example: Load battery icon pic and shadow + * + * char *names[2]; + * void *datas[2]; + * int types[2], sizes[2]; + * + * names[0] = "tex_battery"; + * names[1] = "tex_battery_shadow"; + * types[0] = types[1] = RCO_GRAPHIC; + * + * int res = vlfGuiLoadResources("system_plugin_fg", 2, names, types, datas, sizes, NULL); + * if (res != 2) // error or not all resources loaded + * { + * if (res > 0) + * { + * if (datas[0]) + * free(datas[0]); + * if (datas[1]) + * free(datas[1]); + * } + * } + * else + * { + * void *bat; + * vlfGuiAddShadowedPicture(&bat, datas[0], sizes[0], datas[1], sizes[1], 441, 4, 1, 1, 1); + * free(datas[0]); + * free(datas[1]); + * } + * +*/ +int vlfGuiLoadResources(char *rco, int n, char **names, int *types, void **datas, int *sizes, char **pntable); + +/** + * Caches a resource in RAM, so it doesn't have to be loaded from storage device anymore. + * + * @param rco - The resource. Same rules apply to this param + * + * @returns - < 0 on error. +*/ +int vlfGuiCacheResource(char *rco); + +/** + * Uncaches a resource previously cached. + * + * @param rco - The resource to be uncached. + * + * @returns - < 0 on error. +*/ +int vlfGuiUncacheResource(char *rco); + + +//int vlfGuiGetResourceSubParam(void *entry, int insize, char *ntable, char *name, void **data, int *size); + +/** + * Loads an unicode string from a resource. + * + * @param str - Buffer that receives the string + * @param rco - The resource file to load the label from. + * @param name - The name of the resource + * + * @returns - < 0 on error. +*/ +int vlfGuiLoadLabel(u16 *str, char *rco, char *name); + +/** + * Sets the background from 8888 texture data + * + * @param texture - The texture data in 8888 format + * @param width - The width of texture. Must be a power of 2. + * @param height - The height of texture. Must be multiple of 8. + * @param swizzled - Indicates if the texture is already in the psp GE fast texture format + * @param scale_x - The x scale to apply + * @param scale_y - The y scale to apply + * + * @returns 0 on success, or < 0 on error (params invalid) +*/ +int vlfGuiSetBackground(u32 *texture, int width, int height, int swizzled, float scale_x, float scale_y); + +/** + * Sets the background from a file buffer. + * Supported formats are currently: BMP, TIM, GIM and PNG, with a depth of 24 or 32 bits. + * + * @param data - The buffer with the file data + * @param size - The size of the data + * @param scale - Wether to scale the image. If it is 0, the image will be centered and filled by black. + * + * @returns - 0 on success, < 0 on error. +*/ +int vlfGuiSetBackgroundFileBuffer(void *data, int size, int scale); + +/** + * Sets the background from a file + * Supported formats are currently: BMP, TIM, GIM and PNG, with a depth of 24 or 32 bits. + * + * @param file - Path to the file. + * @param scale - Wether to scale the image. If it is 0, the image will be centered and filled by black. + * + * @returns - 0 on success, < 0 on error. +*/ +int vlfGuiSetBackgroundFile(char *file, int scale); + +/** + * Sets one of system backgrounds based on the index. + * + * @param index - The index of the background, valid values are 1-27 + * (note that 13-27 is only available on slim and will return an error on old psp) + * + * @returns 0 on success, < 0 on error +*/ +int vlfGuiSetBackgroundIndex(int index); + +/** + * Sets one of system backgrounds based on the current date + * + * @returns 0 on success, < 0 on error +*/ +int vlfGuiSetBackgroundDate(); + +/** + * Sets a background of a single color + * + * @param color - The color in XXBBGGRR format (XX is ignored). + * + * @returns - this functions always succeeds returning 0 +*/ +int vlfGuiSetBackgroundPlane(u32 color); + +/** + * Sets the background according to the system configuration + * + * @returns - 0 on success, < 0 on error. +*/ +int vlfGuiSetBackgroundSystem(int notuserwp); + +/** + * Sets the system color, used in titlebars or menus + * + * @param index - the index of the color, 1-27 +*/ +void vlfGuiSetSystemColor(int index); + +/** + * Sets the background model from a buffer. + * + * @param data - The buffer with the model in GMO format + * @param size - The size of the model + * + * @returns - 0 on success, < 0 on error. +*/ +int vlfGuiSetModel(void *data, int size); + +/** + * Sets the background model from a file. + * + * @param file - The file with the model in GMO format + * + * @returns - 0 on success, < 0 on error. +*/ +int vlfGuiSetModelFile(char *file); + +/** + * Sets the background model from a resource. + * + * @param rco - The path to the RCO file + * @param name - The name of the resource + * + * @returns - 0 on success, < 0 on error. +*/ +int vlfGuiSetModelResource(char *rco, char *name); + +/** + * Sets the background model of the system, and applies the proper world matrix to it. + * + * @returns 0 on success, < 0 on error. +*/ +int vlfGuiSetModelSystem(); + +/** + * Sets the world matrix for the model. (by default, the world matrix is the identity + * after a model has been loaded, except when calling vlfGuiSetModelSystem). + * + * @param matrix - The matrix to set. + * + * @Example: Load waves (this sample assumes the default scale of 8.5) + * + * int res = vlfGuiSetModelResource("system_plugin_bg", "mdl_bg"); + * if (res < 0) process_error; + * + * ScePspFMatrix4 matrix; + * ScePspFVector3 scale; + * + * scale.x = scale.y = scale.z = 8.5f; + * gumLoadIdentity(&matrix); + * gumScale(&matrix, &scale); + * vlfGuiSetModelWorldMatrix(&matrix); +*/ +void vlfGuiSetModelWorldMatrix(ScePspFMatrix4 *matrix); + +/** + * Gets the world matrix of the model + * + * @returns a pointer to the model world matrix +*/ +ScePspFMatrix4 *vlfGuiGetModelWorldMatrix(); + +/** + * Sets the model speed + * + * @param speed - The speed, default model speed is 1.0f/60.0f +*/ +void vlfGuiSetModelSpeed(float speed); + +/** + * Sets a title bar with the current system color. + * + * @param text - Text of the title bar. Pass NULL if no required. + * @param pic - Picture of the title bar. Pass NULL if no required. + * @param visible - If the tile bar will be visible + * @param hideobj - If 1, it will hide objects that were current added within the area of the title bar. + */ +void vlfGuiSetTitleBar(VlfText text, VlfPicture pic, int visible, int hideobj); + +/** + * Sets a title bar with the desired color. + * + * @param text - Text of the title bar. Pass NULL if no required. + * @param pic - Picture of the title bar. Pass NULL if no required. + * @param visible - If the tile bar will be visible + * @param hideobj - If 1, it will hide objects that were current added within the area of the title bar. + * @param color - The color of the title bar. +*/ +void vlfGuiSetTitleBarEx(VlfText text, VlfPicture pic, int visible, int hideobj, u32 color); + +/** + * Sets the tile bar visibility. +*/ +void vlfGuiSetTitleBarVisibility(int visible); + +/** + * Adds a new text item from an ascii string. + * + * @param x - x position + * @param y - y position + * @param string - ascii string with the desired text + * + * @returns a VlfText item on success, NULL on error. +*/ +VlfText vlfGuiAddText(int x, int y, char *string); + +/** + * Adds a new text item from an unicode string. + * + * @param x - x position + * @param y - y position + * @param string - unicode string with the desired text + * + * @returns a VlfText item on success, NULL on error. +*/ +VlfText vlfGuiAddTextW(int x, int y, u16 *string); + +/** + * Adds a new text item from a string with format + * + * @param x - x position + * @param y - y position + * @param fmt - string with format + * + * @returns a VlfText item on success, NULL on error. +*/ +VlfText vlfGuiAddTextF(int x, int y, char *fmt, ...); + +/** + * Adds a new text item from a resource label + * + * @param rco - The resource file to load the label from. + * @param name - The name of the resource. + * @param x - x position + * @param y - y position + * + * @returns a VlfText item on success, NULL on error. +*/ +VlfText vlfGuiAddTextResource(char *rco, char *name, int x, int y); + +/** + * Removes a text item. + * + * @param text - The text item to remove + * + * @returns - < 0 on error. +*/ +int vlfGuiRemoveText(VlfText text); + +/** + * Sets the text of a VlfText item from an ascii string. + * + * @param text - The text item + * @param string - The ascii string to set. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetText(VlfText text, char *string); + +/** + * Sets the text of a VlfText item from an unicode string. + * + * @param text - The text item + * @param string - The unicode string to set. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetTextW(VlfText text, u16 *string); + +/** + * Sets the text of a VlfText item from a string with format. + * + * @param text - The text item + * @param fmt - The string with format. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetTextF(VlfText text, char *fmt, ...); + +/** + * Sets the text of a VlfText item from a resource label. + * + * @param text - The text item + * @param rco - The resource file to load the label from. + * @param name - The name of the resource. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetTextResource(VlfText text, char *rco, char *name); + +/** + * Sets focus on a VlfText item. + * + * @param text - The text item to set the focus. + * + * @returns - < 0 on error. + * + * @Note: this function should only be used with a text with a single line, and + * with default font size. +*/ +int vlfGuiSetTextFocus(VlfText text); + +/** + * Removes focus on a VlfText item previously focused. + * + * @param text - The text item to remove focus. + * + * @returns - < 0 on error. +*/ +int vlfGuiRemoveTextFocus(VlfText text, int keepres); + +/** + * Sets the visibility of a VlfText item. + * + * @param text - The text item. + * @param visible - boolean for the visibility. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetTextVisibility(VlfText text, int visible); + +/** + * Makes a VlfText item to blink. + * + * @param text - The text item to set blinking. + * @param nshow - The number of frames the item will be shown. + * @param nhide - The number of frames the item wil be hidden. + * + * @returns - < 0 on error + * + * @Notes: To remove blinking, pass both params to 0. +*/ +int vlfGuiSetTextBlinking(VlfText text, u32 nshow, u32 nhide); + +/** + * Makes a VlfText item to fade. + * + * @param text - The text item to fade. + * @param mode - Whatever OR combination of VlfFadeModesFlags + * @param speed - The fade speed, one of VlfFadeSpeed + * @param direction_out - If both, VLF_FADE_MODE_IN and VLF_FADE_MODE_OUT, were specified, this param indicates + * wether to start from direction out or in. Otherwise, it is ignored. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetTextFade(VlfText text, int mode, int speed, int direction_out); + +/** + * Cancels a VlfText item fade. + * + * @param text - The text item to remove fade. + * + * @returns - < 0 on error +*/ +int vlfGuiCancelTextFade(VlfText text); + +/** + * Sets a callback to report the end of a fade. + * + * @param text - The text item fading. + * @param callback - The callback function that will be called at end of fade. + * @param param - param that will be passed to the callback function + * @param delay - The delay between the end of fade and the call to the callback + * + * @returns - < 0 on error +*/ +int vlfGuiSetTextFadeFinishCallback(VlfText text, void (* callback)(void *), void *param, int delay); + +/** + * Sets text item alignment + * + * @param text - The text item to set alignment + * @param alignment - One of VlfTextAlignment values + * + * @returns - < 0 on error +*/ +int vlfGuiSetTextAlignment(VlfText text, int alignment); + +/** + * Sets text position + * + * @param text - The text item to set position + * @param x - The x position + * @param y - The y position + * + * @returns - < 0 on error +*/ +int vlfGuiSetTextXY(VlfText text, int x, int y); + +/** + * Sets the font size of a text item + * + * @param text - The text to set font size + * @param size - The size of the font + * + * @returns - < 0 on error +*/ +int vlfGuiSetTextFontSize(VlfText text, float size); + +/** + * Returns the size of a text item. + * + * @param text - The text item yo get size from + * @param width - pointer to a variable that receives the width + * @param height - pointer to a variable that receivs the height + * + * @returns - < 0 on error +*/ +int vlfGuiGetTextSize(VlfText text, int *width, int *height); + +/** + * Sets a scrollbar in the specified text item. + * + * @param text - The text item + * @param height - The height of the scrollbar + * + * @returns - < 0 on error +*/ +int vlfGuiSetTextScrollBar(VlfText text, int height); + +/** + * Sets a scrollbar in the specified text item (with more options) + * + * @param text - The text item + * @param height - The height of the scrollbar + * @param dispx - displacement between text and scrollbar in X axis + * @param dispy - displacement between text and scrollbar in Y axis + * + * @returns - < 0 on error + */ +int vlfGuiSetTextScrollBarEx(VlfText text, int height, int dispx, int dispy); + +/** + * Removes a scrollbar of a text item + * + * @param text - The text item + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveTextScrollBar(VlfText text); + +/** + * Sets a character that will be replaced by a button icon + * + * @param ch - The character that will be replaced. + * @param button - The button used for the replacement, one of VlfButtonIcon + * + * @returns - < 0 on error +*/ +int vlfGuiChangeCharacterByButton(u16 ch, int button); + +/** + * Adds a new picture item from a buffer. + * Supported formats are GIM, TIM, BMP and PNG. + * + * @param data - The buffer with the picture + * @param size - The size of data buffer + * @param x - x position + * @param y - y position + * + * @returns - a new VlfPivture on success, NULL on error +*/ +VlfPicture vlfGuiAddPicture(void *data, int size, int x, int y); + +/** + * Adds a new picture item from a file. + * Supported formats are GIM, TIM, BMP and PNG. + * + * @param file - The file with the picture + * @param x - x position + * @param y - y position + * + * @returns - a new VlfPivture on success, NULL on error +*/ +VlfPicture vlfGuiAddPictureFile(char *file, int x, int y); + +/** + * Adds a new picture item from a resource. + * Supported formats are GIM, TIM, BMP and PNG. + * + * @param rco - The rco + * @param name - The name of the resource + * @param x - x position + * @param y - y position + * + * @returns - a new VlfPivture on success, NULL on error +*/ +VlfPicture vlfGuiAddPictureResource(char *rco, char *name, int x, int y); + +/** + * Removes a picture + * + * @param pic - The picture to remove + * + * @returns - < 0 on error. +*/ +int vlfGuiRemovePicture(VlfPicture pic); + +/** + * Sets a picture position. + * + * @param pic - The picture + * @param x - x position + * @param y - y position + * + * @returns - < 0 on error +*/ +int vlfGuiSetPictureXY(VlfPicture pic, int x, int y); + +/** + * Gets a picture size. + * + * @param pic - The picture + * @param width - pointer to a variable that receives the width + * @param height - pointer to a variable that receives the height + * + * @returns - < 0 on error +*/ +int vlfGuiGetPictureSize(VlfPicture pic, int *width, int *height); + +/** + * Sets the picture display area + * + * @param pic - The picture + * @param x - x position of the display area, relative to the top left corner of the picture. + * @param y - y position of the display area, relative to the top left corner of the picture. + * @param width - the width of the rectangle display area + * @param height - The height of the rectangle display area + * + * @returns - < 0 on error +*/ +int vlfGuiSetPictureDisplayArea(VlfPicture pic, int x, int y, int width, int height); + +/** + * Sets picture alpha blend operation. + * + * @param pic - the picture + * @param op - Blending operation (see pspgu.h) + * @param src - Blending function for source operand (see pspgu.h) + * @param dst - Blending function for dest operand (see pspgu.h) + * @param srcfix - Fix value for GU_FIX (source operand) + * @param destfix - Fix value for GU_FIX (dest operand) + * + * @returns - < 0 on error +*/ +int vlfGuiSetPictureAlphaBlend(VlfPicture pic, int op, int src, int dst, u32 srcfix, u32 dstfix); + +/** + * Clones (duplicate) a picture + * + * @param pic - The picture to clone + * @param real - If 0, then the picture is not totally copied, but only a reference. Otherwise, a total duplication is performed. + * @param x - The x position for the cloned picture + * @param y - The y position for the cloned picture + * + * @returns - The cloned picture +*/ +VlfPicture vlfGuiClonePicture(VlfPicture pic, int real, int x, int y); + +/** + * Sets picture visibility + * + * @param pic - The picture + * @param visible - boolean indicating visibility + * + * @returns - < 0 on error +*/ +int vlfGuiSetPictureVisibility(VlfPicture pic, int visible); + +/** + * Makes a picture blink + * + * @param pic - The picture to blink + * @param nshow - The number of frames the picture will be shown + * @param nhide - The number of frames the picture will be hidden + * + * @returns - < 0 on error +*/ +int vlfGuiSetPictureBlinking(VlfPicture pic, u32 nshow, u32 nhide); + +/** + * Animates a picture. + * Frames are created from rectangle areas of the picture. + * + * @param pic - The picture to animate + * @param w - The width of each frame, must be a divisor of picture width + * @param h - The height of each frame, must be a divisor of picture height + * @param frames - The number of frames each frame is drawn. + * @param vertical - If 0, animaction is created from rectangles in horizontal direction. Otherwise, from vertical direction. + * + * @returns - < 0 on error +*/ +int vlfGuiAnimatePicture(VlfPicture pic, int w, int h, int frames, int vertical); + +/** + * Makes a VlfPicture item to fade. + * + * @param pic - The picture item to fade. + * @param mode - Whatever OR combination of VlfFadeModesFlags + * @param speed - The fade speed, one of VlfFadeSpeed + * @param direction_out - If both, VLF_FADE_MODE_IN and VLF_FADE_MODE_OUT, were specified, this param indicates + * wether to start from direction out or in. Otherwise, it is ignored. + * + * @returns - < 0 on error. + */ +int vlfGuiSetPictureFade(VlfPicture pic, int mode, int effect, int direction_out); + +/** + * Cancels a VlfPicture item fade. + * + * @param pic - The picture item to remove fade. + * + * @returns - < 0 on error +*/ +int vlfGuiCancelPictureFade(VlfPicture pic); + +/** + * Sets a callback to report the end of a fade. + * + * @param pic - The picture item fading. + * @param callback - The callback function that will be called at end of fade. + * @param param - param that will be passed to the callback function + * @param delay - The delay between the end of fade and the call to the callback + * + * @returns - < 0 on error +*/ +int vlfGuiSetPictureFadeFinishCallback(VlfPicture pic, void (* callback)(void *), void *param, int delay); + +/** + * Adds a new shadowed picture from two buffers. + * + * @param pic - The buffer with the main picture + * @param pic_size - The size of the pic buffer + * @param shpic - The buffer with the shadow picture + * @param shpic_size - The size of the shpic buffer + * @param x - x position + * @param y - y position + * @param sh_offsx - distance between the main picture and the shadow (x) + * @param sh_offsy - distance between the main picture and the shadow (y) + * @param shadow_before - indicates if shadow should be painted before + * + * @returns - a new shadowed picture on success, NULL on error +*/ +VlfShadowedPicture vlfGuiAddShadowedPicture(void *pic, int pic_size, void *shpic, int shpic_size, int x, int y, int sh_offsx, int sh_offsy, int shadow_before); + +/** + * Adds a new shadowed picture from two files + * + * @param pic - The file with the main picture + * @param shpic - The file with the shadow picture + * @param x - x position + * @param y - y position + * @param sh_offsx - distance between the main picture and the shadow (x) + * @param sh_offsy - distance between the main picture and the shadow (y) + * @param shadow_before - indicates if shadow should be painted before + * + * @returns - a new shadowed picture on success, NULL on error +*/ +VlfShadowedPicture vlfGuiAddShadowedPictureFile(char *pic, char *shpic, int x, int y, int sh_offsx, int sh_offsy, int shadow_before); + +/** + * Adds a new shadowed picture from two resources. + * + * @param rco .- The resource file + * @param pic - The name of the resource with the main picture + * @param shpic - The name of the resource with the shadow picture + * @param x - x position + * @param y - y position + * @param sh_offsx - distance between the main picture and the shadow (x) + * @param sh_offsy - distance between the main picture and the shadow (y) + * @param shadow_before - indicates if shadow should be painted before + * + * @returns - a new shadowed picture on success, NULL on error +*/ +VlfShadowedPicture vlfGuiAddShadowedPictureResource(char *rco, char *pic, char *shpic, int x, int y, int sh_offsx, int sh_offsy, int shadow_before); + +/** + * Removes a shadowed picture + * + * @param sp - The shadowed picture to remove + * + * @returns - < 0 on error. +*/ +int vlfGuiRemoveShadowedPicture(VlfShadowedPicture sp); + +/** + * Sets shadowed picture visibility + * + * @param sp - The shadowed picture + * @param visible - boolean indicating visibility + * + * @returns - < 0 on error +*/ +int vlfGuiSetShadowedPictureVisibility(VlfShadowedPicture sp, int visible); + +/** + * Makes a shadowed picture blink + * + * @param sp - The shadowed picture to blink + * @param nshow - The number of frames the picture will be shown + * @param nhide - The number of frames the picture will be hidden + * + * @returns - < 0 on error +*/ +int vlfGuiSetShadowedPictureBlinking(VlfShadowedPicture sp, u32 nshow, u32 nhide); + +/** + * Animates a shadowed picture. + * Frames are created from rectangle areas of the picture. + * + * @param sp - The shadowed picture to animate + * @param w - The width of each frame of main picture, must be a divisor of main picture width + * @param h - The height of each frame of main picure, must be a divisor of main picture height + * @param ws - The width of each frame of shadow picture, must be a divisor of shadow picture width + * @param hs - The height of each frame of shadow picure, must be a divisor of shadow picture height + * @param frames - The number of frames each frame is drawn + * @param vertical - If 0, animaction is created from rectangles in horizontal direction. Otherwise, from vertical direction. + * + * @returns - < 0 on error + * + * @Example: vlfGuiAddWaitIconEx source code. Image is divided in 17x17 rectangles, each frame is drawn for 3 frames. + * + * VlfShadowedPicture vlfGuiAddWaitIconEx(int x, int y) + * { + * VlfShadowedPicture res = vlfGuiAddShadowedPictureResource("system_plugin_fg", "tex_busy", "tex_busy_shadow", x, y, 1, 1, 0); + * + * if (!res) + * return NULL; + * + * if (vlfGuiAnimateShadowedPicture(res, 17, 17, 17, 17, 3, 1) < 0) + * { + * vlfGuiRemoveShadowedPicture(res); + * return NULL; + * } + * + * return res; + * } +*/ +int vlfGuiAnimateShadowedPicture(VlfShadowedPicture sp, int w, int h, int ws, int hs, int frames, int vertical); + +/** + * Makes a VlfShadowedPicture item to fade. + * + * @param sp - The shadowed picture item to fade. + * @param mode - Whatever OR combination of VlfFadeModesFlags + * @param speed - The fade speed, one of VlfFadeSpeed + * @param direction_out - If both, VLF_FADE_MODE_IN and VLF_FADE_MODE_OUT, were specified, this param indicates + * wether to start from direction out or in. Otherwise, it is ignored. + * + * @returns - < 0 on error. + */ +int vlfGuiSetShadowedPictureFade(VlfShadowedPicture sp, int mode, int effect, int direction_out); + +/** + * Cancels a VlfShadowedPicture item fade. + * + * @param sp - The shadowed picture item to remove fade. + * + * @returns - < 0 on error + */ +int vlfGuiCancelShadowedPictureFade(VlfShadowedPicture sp); + +/** + * Sets a callback to report the end of a fade. + * + * @param sp - The shadowed picture item fading. + * @param callback - The callback function that will be called at end of fade. + * @param param - param that will be passed to the callback function + * @param delay - The delay between the end of fade and the call to the callback + * + * @returns - < 0 on error +*/ +int vlfGuiSetShadowedPictureFadeFinishCallback(VlfShadowedPicture sp, void (* callback)(void *), void *param, int delay); + +/** + * Adds a new battery icon at its default position. Icon created by this function must be manually operated by programmer. + * + * @param status - The status, one of VlfBatteryIconStatus + * @param blink - blinking flag + * + * @returns - a new VlfBatteryIcon item +*/ +VlfBatteryIcon vlfGuiAddBatteryIcon(u32 status, int blink); + +/** + * Adds a new battery icon (with more options). Icon created by this function must be manually operated by programmer. + * + * @param x - The x position + * @param y - The y position + * @param status - The status, one of VlfBatteryIconStatus + * @param blink - blinking flag + * + * @returns - a new VlfBatteryIcon item + */ +VlfBatteryIcon vlfGuiAddBatteryIconEx(int x, int y, u32 status, int blink); + +/** + * Adds a new battery icon at its default position. + * Icon created by this function is handled automatically by the library. + * + * @param timer_ms - The miliseconds the timer that checks the battery is executed. + * + * @returns - a new VlfBatteryIcon item +*/ +VlfBatteryIcon vlfGuiAddBatteryIconSystem(int timer_ms); + +/** + * Sets battery icon status. + * + * @param baticon - The battery icon + * @param status - The status, one of VlfBatteryIconStatus + * @param blink - blinking flag + * + * @returns - < 0 on error + * + * @Note: this function shouldn't be used with a battery icon created by vlfGuiAddBatteryIconSystem. +*/ +int vlfGuiSetBatteryIconStatus(VlfBatteryIcon baticon, int status, int blink); + +/** + * Removes a battery icon. + * + * @param baticon - The battery icon to remove + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveBatteryIcon(VlfBatteryIcon baticon); + +/** + * Adds a system clock. Only one clock is allowed currently + * + * @returns - < 0 on error. + * + * @Note: this function will change in future versions. +*/ +int vlfGuiAddClock(); + +/** + * Adds an animated wait icon at its default position in lower-right corner. + * + * @returns - a new wait icon. +*/ +VlfShadowedPicture vlfGuiAddWaitIcon(); + +/** + * Adds an animated wait icon at position choosed by programmer. + * + * @param x - x position + * @param y - y position + * + * @returns - a new wait icon. + */ +VlfShadowedPicture vlfGuiAddWaitIconEx(int x, int y); + +/** + * Adds a cross picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new cross picture +*/ +VlfShadowedPicture vlfGuiAddCross(int x, int y); + +/** + * Adds a circle picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new circle picture +*/ +VlfShadowedPicture vlfGuiAddCircle(int x, int y); + +/** + * Adds a triangle picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new triangle picture +*/ +VlfShadowedPicture vlfGuiAddTriangle(int x, int y); + +/** + * Adds a square picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new square picture +*/ +VlfShadowedPicture vlfGuiAddSquare(int x, int y); + +/** + * Adds an enter picture (cross or circle) + * + * @param x - x position + * @param y - y position + * + * @returns - a new enter picture +*/ +VlfShadowedPicture vlfGuiAddEnter(int x, int y); + +/** + * Adds a cancel picture (cross or circle) + * + * @param x - x position + * @param y - y position + * + * @returns - a new cancel picture +*/ +VlfShadowedPicture vlfGuiAddCancel(int x, int y); + +/** + * Adds a spinup picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new spinup picture +*/ +VlfShadowedPicture vlfGuiAddSpinUp(int x, int y); + +/** + * Adds a spindown picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new spindown picture +*/ +VlfShadowedPicture vlfGuiAddSpinDown(int x, int y); + +/** + * Adds an arrow left picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new arrow left picture +*/ +VlfShadowedPicture vlfGuiAddArrowLeft(int x, int y); + +/** + * Adds an arrow right picture. + * + * @param x - x position + * @param y - y position + * + * @returns - a new arrow right picture +*/ +VlfShadowedPicture vlfGuiAddArrowRight(int x, int y); + +/** + * Adds a new integer spin + * + * @param x - x position + * @param y - y position + * @param min - minim value of the spin + * @param max - max value of the spin + * @param cur - The initial integer value of the spin + * @param step - The step in which the value is increased/decreased + * @param loop - boolean indicating if the spin loops + * @param speed - The speed of the spin in milisecs + * @param initstate - the initial state of the spin, one of VLF_SpinState + * @param prefix - Prefix string, NULL if not needed + * @param suffix - Suffix string, NULL if not needed + * + * @returns - a new VlfSpin object on success, NULL on error +*/ +VlfSpin vlfGuiAddIntegerSpinControl(int x, int y, int min, int max, int cur, int step, int loop, int speed, int initstate, char *prefix, char *suffix); + +/** + * Removes a spin item + * + * @param spin - the spin to remove + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveSpinControl(VlfSpin spin); + +/** + * Sets spin state + * + * @param spin - the spin + * @param state - the state, one of VLF_SpinState + * + * @returns - < 0 on error +*/ +int vlfGuiSetSpinState(VlfSpin spin, int state); + +/** + * Sets integer minimum and maximum values for an integer spin + * + * @param spin - The integer spin + * @param min - the minimum value + * @param max - the maximum value + * + * @returns - < 0 on error +*/ +int vlfGuiSetIntegerSpinMinMax(VlfSpin spin, int min, int max); + +/** + * Gets the integer value of an integer spin + * + * @param spin - the integer spin + * @param value - pointer to a variable that receives the value + * + * @returns - < 0 on error +*/ +int vlfGuiGetIntegerSpinValue(VlfSpin spin, int *value); + +/** + * Sets the integer value of an integer spin + * + * @param spin - the integer spin + * @param value - the integer value to set + * + * @returns - < 0 on error +*/ +int vlfGuiSetIntegerSpinValue(VlfSpin spin, int value); + +/** + * Adds a new checkbox item + * By default the checkbox is created without focus and without check. + * When a checbox has focus, library handles automatically the press of enter button to change check state + * + * @param x - x position + * @param y - y position + * + * @returns - a new VlfCheckBox item on sucess, NULL on error +*/ +VlfCheckBox vlfGuiAddCheckBox(int x, int y); + +/** + * Removes a checkbox item + * + * @param cb - The checkbox to remove + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveCheckBox(VlfCheckBox cb); + +/** + * Sets checkbox check state + * + * @param cb - The checkbox to check/uncheck + * @param check - boolean indicating check + * + * @returns - < 0 on error +*/ +int vlfGuiSetCheckBoxCheck(VlfCheckBox cb, int check); + +/** + * Sets checkbox focus state + * + * @param cb - The checkbox + * @param focus - boolean indicating focus + * + * @returns - < 0 on error + */ +int vlfGuiSetCheckBoxFocus(VlfCheckBox cb, int focus); + +/** + * Boolean function that checks check state of a checkbox + * + * @param cb - the checkbox + * + * @returns 1 if the checkbox is checked, 0 otherwise +*/ +int vlfGuiIsCheckBoxChecked(VlfCheckBox cb); + +/** + * Boolean function that checks focus state of a checkbox + * + * @param cb - the checkbox + * + * @returns 1 if the checkbox has focus, 0 otherwise +*/ +int vlfGuiIsCheckBoxFocused(VlfCheckBox cb); + +/** + * Adds a new inputbox item with default width. + * By default the newly created inputbox is focused and of normal type. + * When a inputbox item is focused, library automatically handles press of enter button to show OSK. + * + * @param desc - description that will be shown in the OSK dialog. + * @param x - the x position + * @param y - the y position + * + * @returns - a new VlfInputBox on sucess, NULL on error +*/ +VlfInputBox vlfGuiAddInputBox(char *desc, int x, int y); + +/** + * Adds a new inputbox item. + * By default the newly created inputbox is focused and of normal type. + * When a inputbox item is focused, library automatically handles press of enter button to show OSK. + * + * @param desc - description that will be shown in the OSK dialog. + * @param x - the x position + * @param y - the y position + * @param width - width of the box + * + * @returns - a new VlfInputBox on sucess, NULL on error +*/ +VlfInputBox vlfGuiAddInputBoxEx(u16 *desc, int x, int y, int width); + +/** + * Removes an inputbox + * + * @param ib - the inputbox to remove + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveInputBox(VlfInputBox ib); + +/** + * Sets inputbox text from an ascii string + * + * @param ib - the inputbox + * @param text - the ascii string + * + * @returns - < 0 on error +*/ +int vlfGuiSetInputBoxText(VlfInputBox ib, char *text); + +/** + * Sets inputbox text from an unicode string + * + * @param ib - the inputbox + * @param text - the unicode string + * + * @returns - < 0 on error + */ +int vlfGuiSetInputBoxTextW(VlfInputBox ib, u16 *text); + +/** + * Sets inputbox text from a string with format + * + * @param ib - the inputbox + * @param fmt - the string with format + * + * @returns - < 0 on error + */ +int vlfGuiSetInputBoxTextF(VlfInputBox ib, char *fmt, ...); + +/** + * Gets inputbox text. + * + * @param ib - thei inputbox + * @param text - output buffer that receives the strig as unicode + * + * @returns - < 0 on error +*/ +int vlfGuiGetInputBoxText(VlfInputBox ib, u16 *text); + +/** + * Sets inputbox focus state + * + * @param ib - the inputbox + * @param focus - the focus state boolean + * + * @returns - < 0 on error +*/ +int vlfGuiSetInputBoxFocus(VlfInputBox ib, int focus); + +/** + * Boolean function that checks inputbox focus state + * + * @param ib - The inputbox + * + * @returns 1 if the inputbox has focus, 0 otherwise +*/ +int vlfGuiIsInputBoxFocused(VlfInputBox ib); + +/** + * Sets inputbox type (normal or password). + * + * @param ib - the inputbox + * @param type - the type to set, one of VLF_InputBoxType + * + * @returns - < 0 on error +*/ +int vlfGuiSetInputBoxType(VlfInputBox ib, int type); + +/** + * Makes a VlfInputBox item to fade. + * + * @param ib - The inputbox item to fade. + * @param mode - Whatever OR combination of VlfFadeModesFlags + * @param speed - The fade speed, one of VlfFadeSpeed + * @param direction_out - If both, VLF_FADE_MODE_IN and VLF_FADE_MODE_OUT, were specified, this param indicates + * wether to start from direction out or in. Otherwise, it is ignored. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetInputBoxFade(VlfInputBox ib, int mode, int effect, int direction_out); + +/** + * Cancels a VlfInputBox item fade. + * + * @param ib - The inputbox item to remove fade. + * + * @returns - < 0 on error +*/ +int vlfGuiCancelInputBoxFade(VlfInputBox ib); + +/** + * Sets a callback to report the end of a fade. + * + * @param ib- The inputbox item fading. + * @param callback - The callback function that will be called at end of fade. + * @param param - param that will be passed to the callback function + * @param delay - The delay between the end of fade and the call to the callback + * + * @returns - < 0 on error +*/ +int vlfGuiSetInputBoxFadeFinishCallback(VlfInputBox ib, void (* callback)(void *), void *param, int delay); + +/** + * Adds a new progressbar at default x position. + * + * @param y - y position + * + * @return - a new VlfProgressBar item on success, NULL on error +*/ +VlfProgressBar vlfGuiAddProgressBar(int y); + +/** + * Adds a new progressbar + * + * @param x - x position + * @param y - y position + * + * @return - a new VlfProgressBar item on success, NULL on error +*/ +VlfProgressBar vlfGuiAddProgressBarEx(int x, int y); + +/** + * Removes a progress bar + * + * @param pb - the progress bar to remove. + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveProgressBar(VlfProgressBar pb); + +/** + * Sets the progress of a progressbar + * + * @param pb - the progress bar + * @param perc - the percentage progress + * + * @returns - < 0 on error +*/ +int vlfGuiProgressBarSetProgress(VlfProgressBar pb, u32 perc); + +/** + * Makes a VlfProgressBar item to fade. + * + * @param pb - The progressbar item to fade. + * @param mode - Whatever OR combination of VlfFadeModesFlags + * @param speed - The fade speed, one of VlfFadeSpeed + * @param direction_out - If both, VLF_FADE_MODE_IN and VLF_FADE_MODE_OUT, were specified, this param indicates + * wether to start from direction out or in. Otherwise, it is ignored. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetProgressBarFade(VlfProgressBar pb, int mode, int effect, int direction_out); + +/** + * Cancels a VlfProgressBar item fade. + * + * @param pb - The progressbar item to remove fade. + * + * @returns - < 0 on error +*/ +int vlfGuiCancelProgressBarFade(VlfProgressBar pb); + +/** + * Sets a callback to report the end of a fade. + * + * @param pb - The progressbar item fading. + * @param callback - The callback function that will be called at end of fade. + * @param param - param that will be passed to the callback function + * @param delay - The delay between the end of fade and the call to the callback + * + * @returns - < 0 on error +*/ +int vlfGuiSetProgressBarFadeFinishCallback(VlfProgressBar pb, void (* callback)(void *), void *param, int delay); + +/** + * Adds a new scrollbar. (must be controlled by programmer) + * + * @param x - x position + * @param y - y position + * @param height - height of scrollbar + * @param sliderheight - height of slider + * + * @returns a new VlfScrollBar item on success, NULL on error +*/ +VlfScrollBar vlfGuiAddScrollBar(int x, int y, int height, int sliderheight); + +/** + * Removes a scrollbar itemm. + * + * @param sb - the scrollbar to remove + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveScrollBar(VlfScrollBar sb); + +/** + * Moves the slider of a scrollbar + * + * @param y - the new position of the slider + * + * @returns - < 0 on error +*/ +int vlfGuiMoveScrollBarSlider(VlfScrollBar sb, int y); + +/** + * Sets the height of the slider of a scrollbar + * + * @param sb - the scrollbar + * @param height - the new height for the slider + * + * @returns - < 0 on error. +*/ +int vlfGuiSetScrollBarSliderHeight(VlfScrollBar sb, int height); + +/** + * Sets the visibility of the items in a rectangle + * + * @param x - x position of rectangle + * @param y - y position of rectangle + * @param w - width of rectangle + * @param h - height of rectangle + * @param visible . boolean indicating visibility + * + * @returns - < 0 on error +*/ +int vlfGuiSetRectangleVisibility(int x, int y, int w, int h, int visible); + +/** + * Saves the visibility context in a rectangle area + * + * @param x - x position of rectangle + * @param y - y position of rectangle + * @param w - width of rectangle + * @param h - height of rectangle + * + * @returns - the visibility context. Use vlfGuiRestoreVisibilityContext to restore it, and vlfGuiFreeVisibilityContext to deallocate it. +*/ +void *vlfGuiSaveRectangleVisibilityContext(int x, int y, int w, int h); + +/** + * Restores a visibility context. + * + * @param ctx - the visibility context +*/ +void vlfGuiRestoreVisibilityContext(void *ctx); + +/** + * Deallocates memory used by a visibility context + * + * @param ctx - the visibility context +*/ +void vlfGuiFreeVisibilityContext(void *ctx); + +/** + * Makes all items within a rectangle to fade + * + * @param x - x position of rectangle + * @param y - y position of rectangle + * @param w - width of rectangle + * @param h - height of rectangle + * @param mode - Whatever OR combination of VlfFadeModesFlags + * @param speed - The fade speed, one of VlfFadeSpeed + * @param direction_out - If both, VLF_FADE_MODE_IN and VLF_FADE_MODE_OUT, were specified, this param indicates + * wether to start from direction out or in. Otherwise, it is ignored. + * + * @returns - < 0 on error. +*/ +int vlfGuiSetRectangleFade(int x, int y, int w, int h, int mode, int effect, int direction_out, void (* callback)(void *), void *param, int delay); + +/** + * Makes all items within a rectangle to blink + * + * @param x - x position of rectangle + * @param y - y position of rectangle + * @param w - width of rectangle + * @param h - height of rectangle + * @param nshow - the numbers of frames the items will be shown + * @param nhide - the numbers of frames the items will be hidden + * + * @returns - < 0 on error. + * + * @Note: currently not all kind of items can blink. This will be fixed in future. +*/ +int vlfGuiSetRectangleBlinking(int x, int y, int w, int h, u32 nshow, u32 nhide); + +/** + * Synchronizes the blinking of one item with the one of a second one + * + * @param dst - the destiny item + * @param dst_type - the type of the destiny object, one of VlfObjects + * @param src - the source item + * @param src_type - the type of source object, one of VlfObjects + * + * @returns - < 0 on error +*/ +int vlfGuiSetSynchronizedBlinking(void *dst, int dst_type, void *src, int src_type); + +/** + * Shows a message dialog. + * + * @param msg - the message dialog + * @param flags - a combination of VLF_MDType, VLF_MD_Buttons and VLF_MD_InitalCursor + * + * @returns - one of VLF_MD_ButtonRes +*/ +int vlfGuiMessageDialog(char *msg, u32 flags); + +/** + * Shows an error dialog. + * + * @param error - the system error code + * + * @returns - one of VLF_MD_ButtonRes +*/ +int vlfGuiErrorDialog(int error); + +/** + * Shows a net config dialog. + * Network libraries must be loaded before. + * + * @returns 0 if the connection was done. +*/ +int vlfGuiNetConfDialog(); + +/** + * Shows an OSK dialog. + * + * @param intext - the initial text of the OSK, NULL if no required + * @param desc - the description that will be shown in the OSK, NULL if no required + * @param outtext - the output text + * + * @returns 0 if the text was entered. +*/ +int vlfGuiOSKDialog(u16 *intext, u16 *desc, u16 *outtext); + +/** + * Shows one or two buttons with enter/cancel icons at bottom of screen. + * Button presses are handled by the library. + * + * @param button1 - a button code, one of VLF_DialogItem. < 0 if no required + * @param button2 - a button code, one of VLF_DialogItem- < 0 if no required + * @param automatic - if automatic is 0, button1 will be the left button and button2 will be right button. + * Otherwise, the buttons are rearranged automatically acording to current button configuration. + * @param enter_is_left - if automatic is 0, this button indicates which button is assigned enter. + * @param distance - the distance between the buttons, use VLF_DEFAULT for a default distance + * @param handler - the function that will be called when enter/cancel are pressed. The function shall return VLF_REMOVE_HANDLERS if it + * wants to cancel further events, VLF_REMOVE_OBJECTS to remove bottom dialog, or both to fully remove the bottom dialog. + * + * @returns - < 0 on error. +*/ +int vlfGuiBottomDialog(int button1, int button2, int automatic, int enter_is_left, int distance, int (* handler)(int enter)); + +/** + * Shows one or two buttons with enter/cancel icons at bottom of screen. + * Button presses are handled by the library. + * + * @param button1 - button string. NULL if no required + * @param button2 - button string. NULL if no required + * @param automatic - if automatic is 0, button1 will be the left button and button2 will be right button. + * Otherwise, the buttons are rearranged automatically acording to current button configuration. + * @param enter_is_left - if automatic is 0, this button indicates which button is assigned enter. + * @param distance - the distance between the buttons, use VLF_DEFAULT for a default distance + * @param handler - the function that will be called when enter/cancel are pressed, enter param indicates if enter was pressed, otherwise cancel was pressed. + * The function shall return VLF_REMOVE_HANDLERS if it wants to cancel further events, VLF_REMOVE_OBJECTS to remove buttons, + * or both to fully remove the bottom dialog. + * + * @returns - < 0 on error. + */ +int vlfGuiCustomBottomDialog(char *button1, char *button2, int automatic, int enter_is_left, int distance, int (* handler)(int enter)); + +/** + * Cancels (remove) the bottom dialog +*/ +void vlfGuiCancelBottomDialog(); + +/** + * Creates a central menu. + * Button presses of menu are automatically handled by the library + * + * @param noptions - number of options of the menu + * @param items - an array of noptions strings + * @param defaultsel- the index of the item with the initial selection + * @param handler - the function that will be called on enter button is pressed. sel param is the index of the selected item. + * The function shall return VLF_REMOVE_HANDLERS if it wants to cancel further events, VLF_REMOVE_OBJECTS to remove items, + * or both to fully remove the central menu. + * @param dispx - displacement relative to the default centered position (x) + * @param dispy - displacement relative to the default centered position (y) + * + * @returns - < 0 on error +*/ +int vlfGuiCentralMenu(int noptions, char **items, int defaultsel, int (* handler)(int sel), int dispx, int dispy); + +/** + * Cancels (remove) the central menu +*/ +void vlfGuiCancelCentralMenu(); + +/** + * Returns the current selected item of the central menu + * + * @returns - the selected item +*/ +int vlfGuiCentralMenuSelection(); + +/** + * Creates a lateral menu with current system color. + * Button presses of menu are automatically handled by the library + * + * @param noptions - number of options of the menu + * @param items - an array of noptions strings + * @param defaultsel- the index of the item with the initial selection + * @param handler - the function that will be called on enter button is pressed. sel param is the index of the selected item. + * The function shall return VLF_REMOVE_HANDLERS if it wants to cancel further events, VLF_REMOVE_OBJECTS to remove menu, + * or both to fully remove the lateral menu. + * @param y - y position of first item + * + * @returns - < 0 on error +*/ +int vlfGuiLateralMenu(int noptions, char **items, int defaultsel, int (* handler)(int sel), int y); + +/** + * Creates a lateral menu with desired color. + * Button presses of menu are automatically handled by the library + * + * @param noptions - number of options of the menu + * @param items - an array of noptions strings + * @param defaultsel- the index of the item with the initial selection + * @param handler - the function that will be called on enter button is pressed. sel param is the index of the selected item. + * The function shall return VLF_REMOVE_HANDLERS if it wants to cancel further events, VLF_REMOVE_OBJECTS to remove menu, + * or both to fully remove the lateral menu. + * @param y - y position of first item + * @param color - the color of the lateral menu + * + * @returns - < 0 on error +*/ +int vlfGuiLateralMenuEx(int noptions, char **items, int defaultsel, int (* handler)(int sel), int y, u32 color); + +/** + * Cancels (remove) the lateral menu + */ +void vlfGuiCancelLateralMenu(); + +/** + * Returns the current selected item of the lateral menu + * + * @returns - the selected item + */ +int vlfGuiLateralMenuSelection(); + +/** + * Creates a control for previous page handling. + * + * @param handler - the function that will be called when the previous button (left) is pressed. page parameter holds the page number. + * The function shall return VLF_REMOVE_HANDLERS if it wants to cancel further events, VLF_REMOVE_OBJECTS to remove control pics and text, + * or both to fully remove the control. + * + * @returns - < 0 on error +*/ +int vlfGuiPreviousPageControl(int (* handler)(int page)); + +/** + * Creates a control for next page handling. + * + * @param handler - the function that will be called when the next button (right) is pressed. page parameter holds the page number. + * The function shall return VLF_REMOVE_HANDLERS if it wants to cancel further events, VLF_REMOVE_OBJECTS to remove control pics and text, + * or both to fully remove the control. + * + * @returns - < 0 on error + */ +int vlfGuiNextPageControl(int (* handler)(int page)); + +/** + * Cancels (remove) previous page control +*/ +void vlfGuiCancelPreviousPageControl(); + +/** + * Cancels (remove) next page control + */ +void vlfGuiCancelNextPageControl(); + +/** + * Enable or disable page control.(it does not add/remove them). + * + * @param enable - enable or disable +*/ +void vlfGuiSetPageControlEnable(int enable); + +/** + * Adds a handler for an event. + * + * @param buttons - the button event, 0 if no event (will be called every frame) + * @param wait - wait for the handler to be added. Use 0 for no wait, and -1 to make this handler impossible to delay. + * @param func - the function that will be called when the event happens. + * @param param - custom param for the handler function. The function must return one or a combination of following values: + * + * VLF_EV_RET_NOTHING: normal return, it does nothing. + * VLF_EV_RET_REMOVE_EVENT: it removes the event (button press), so other handler doesn't receive it. + * VLF_EV_RET_REMOVE_HANDLERS: it removes this handler so that it won't receive more event notifications. + * VLF_EV_RET_DELAY: the event is delayed for specified number of miliseconds. VLF_EV_RET_DELAY | (X << 16), where 0 <= X <= 32727 + * VLF_EV_RET_DELAY_FRAME: the event is delayed for specified number of frames. VLF_EV_RET_DELAY_FRAME | (X << 16), where 0 <= X <= 4095 + * VLF_EV_RET_REFRESH_ON_DELAY: the event is refreshed after a delay, so that if button/s are kept pressed until after the event, it will receive it as a new event + * + * @returns - < 0 on error +*/ +int vlfGuiAddEventHandler(int buttons, int wait, int (* func)(void *), void *param); + +/** + * Adds a handler for an event. + * Unlike the previous function, this one adds the handler to the head instead of the tail. + * + * @param buttons - the button event, 0 if no event (will be called every frame) + * @param wait - wait for the handler to be added. Use 0 for no wait, and -1 to make this handler impossible to delay. + * @param func - the function that will be called when the event happens. + * @param param - custom param for the handler function. The function must return one or a combination of following values: + * + * VLF_EV_RET_NOTHING: normal return, it does nothing. + * VLF_EV_RET_REMOVE_EVENT: it removes the event (button press), so other handler doesn't receive it. + * VLF_EV_RET_REMOVE_HANDLERS: it removes this handler so that it won't receive more event notifications. + * VLF_EV_RET_DELAY: the event is delayed for specified number of miliseconds. VLF_EV_RET_DELAY | (X << 16), where 0 <= X <= 32727 + * VLF_EV_RET_DELAY_FRAME: the event is delayed for specified number of frames. VLF_EV_RET_DELAY_FRAME | (X << 16), where 0 <= X <= 4095 + * VLF_EV_RET_REFRESH_ON_DELAY: the event is refreshed after a delay, so that if button/s are kept pressed until after the event, it will receive it as a new event + * + * @returns - < 0 on error +*/ +int vlfGuiAddEventHandlerHead(int buttons, int wait, int (* func)(void *), void *param); + +/** + * Adds a handler for a negative event. + * + * @param buttons - the negative button event. For Example if you pass PSP_CTRL_CROSS, it will mean NOT PSP_CTRL_CROSS pressed. + * @param wait - wait for the handler to be added. Use 0 for no wait, and -1 to make this handler impossible to delay. + * @param func - the function that will be called when the event happens. + * @param param - custom param for the handler function. The function must return one or a combination of following values: + * + * VLF_EV_RET_NOTHING: normal return, it does nothing. + * VLF_EV_RET_REMOVE_EVENT: it removes the event (button press), so other handler doesn't receive it. + * VLF_EV_RET_REMOVE_HANDLERS: it removes this handler so that it won't receive more event notifications. + * VLF_EV_RET_DELAY: the event is delayed for specified number of miliseconds. VLF_EV_RET_DELAY | (X << 16), where 0 <= X <= 32727 + * VLF_EV_RET_DELAY_FRAME: the event is delayed for specified number of frames. VLF_EV_RET_DELAY_FRAME | (X << 16), where 0 <= X <= 4095 + * VLF_EV_RET_REFRESH_ON_DELAY: the event is refreshed after a delay, so that if button/s are kept pressed until after the event, it will receive it as a new event + * + * @returns - < 0 on error + */ +int vlfGuiAddNegativeEventHandler(int buttons, int wait, int (* func)(void *), void *param); + +/** + * Adds a handler for a negative event. + * Unlike the previous function, this one adds the handler to the head instead of the tail. + * + * @param buttons - the negative button event. For Example if you pass PSP_CTRL_CROSS, it will mean NOT PSP_CTRL_CROSS pressed. + * @param wait - wait for the handler to be added. Use 0 for no wait, and -1 to make this handler impossible to delay. + * @param func - the function that will be called when the event happens. + * @param param - custom param for the handler function. The function must return one or a combination of following values: + * + * VLF_EV_RET_NOTHING: normal return, it does nothing. + * VLF_EV_RET_REMOVE_EVENT: it removes the event (button press), so other handler doesn't receive it. + * VLF_EV_RET_REMOVE_HANDLERS: it removes this handler so that it won't receive more event notifications. + * VLF_EV_RET_DELAY: the event is delayed for specified number of miliseconds. VLF_EV_RET_DELAY | (X << 16), where 0 <= X <= 32727 + * VLF_EV_RET_DELAY_FRAME: the event is delayed for specified number of frames. VLF_EV_RET_DELAY_FRAME | (X << 16), where 0 <= X <= 4095 + * VLF_EV_RET_REFRESH_ON_DELAY: the event is refreshed after a delay, so that if button/s are kept pressed until after the event, it will receive it as a new event + * + * @returns - < 0 on error + */ +int vlfGuiAddNegativeEventHandlerHead(int buttons, int wait, int (* func)(void *), void *param); + +/** + * Removes an event handler. Use vlfGuiRemoveHandlerEx if you have used the same handler with different params. + * + * @param func - the handler function + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveEventHandler(int (* func)(void *)); + +/** + * Removes an event hnadler + * + * @param func - the handler function + * @param param - the parameter that was passed to one of the vlfGuiAddEventHandler functions. + * + * @returns - < 0 on error +*/ +int vlfGuiRemoveEventHandlerEx(int (* func)(void *), void *param); + +/** + * Boolean function that checks if a handler is registered + * + * @param func - the handler to be checked. + * + * @return - < 0 on error +*/ +int vlfGuiIsEventRegistered(int (* func)(void *)); + +/** + * Delays an event handler. Use vlfGuiSetEventDelayEx if you have used the same handler with different params. + * + * @param func - the handler function + * @param delay - the delay in milisecs + * + * @return - < 0 on error +*/ +int vlfGuiSetEventDelay(int (* func)(void *), u32 delay); + +/** + * Delays an event handler. + * + * @param func - the handler function + * @param param - the parameter that was passed to one of the vlfGuiAddEventHandler functions. + * @param delay - the delay in milisecs + * + * @return - < 0 on error + */ +int vlfGuiSetEventDelayEx(int (* func)(void *), void * param, u32 delay); + +/** + * Delays all events that can be delayed + * + * @param delay - the delay in milisecs + * + * @returns - < 0 on error +*/ +int vlfGuiDelayAllEvents(u32 delay); + + + +#endif + diff --git a/libs/lib/libvlfgu.a b/libs/lib/libvlfgu.a new file mode 100755 index 0000000..aecd297 Binary files /dev/null and b/libs/lib/libvlfgu.a differ diff --git a/libs/lib/libvlfgui.a b/libs/lib/libvlfgui.a new file mode 100755 index 0000000..583e748 Binary files /dev/null and b/libs/lib/libvlfgui.a differ diff --git a/libs/lib/libvlflibc.a b/libs/lib/libvlflibc.a new file mode 100755 index 0000000..0aa9270 Binary files /dev/null and b/libs/lib/libvlflibc.a differ diff --git a/libs/lib/libvlfutils.a b/libs/lib/libvlfutils.a new file mode 100755 index 0000000..67b548e Binary files /dev/null and b/libs/lib/libvlfutils.a differ diff --git a/plugin/Makefile b/plugin/Makefile new file mode 100644 index 0000000..10597d0 --- /dev/null +++ b/plugin/Makefile @@ -0,0 +1,27 @@ +TARGET = rtc_driver +OBJS = rtc_driver.o exports.o + +PRX_EXPORTS = exports.exp + +# Use the kernel's small inbuilt libc +USE_KERNEL_LIBC = 1 +# Use only kernel libraries +USE_KERNEL_LIBS = 1 + +INCDIR = +CFLAGS = -Os -G0 -Wall -fno-builtin-printf +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti +ASFLAGS = $(CFLAGS) + +LIBDIR = + +LDFLAGS = -nostartfiles +LIBS = -lpsprtc_driver + +PSPSDK=$(shell psp-config --pspsdk-path) +include $(PSPSDK)/lib/build_prx.mak + +all: + psp-build-exports -s $(PRX_EXPORTS) + mkdir "../app/data/"; mv rtc_driver.prx "../app/data/" + mkdir "../app/drivers/"; mv rtc_driver.S "../app/drivers/" diff --git a/plugin/exports.exp b/plugin/exports.exp new file mode 100644 index 0000000..b0abaae --- /dev/null +++ b/plugin/exports.exp @@ -0,0 +1,16 @@ +# Define the exports for the prx +PSP_BEGIN_EXPORTS + +# These four lines are mandatory (although you can add other functions like module_stop) +# syslib is a psynonym for the single mandatory export. +PSP_EXPORT_START(syslib, 0, 0x8000) +PSP_EXPORT_FUNC(module_start) +PSP_EXPORT_FUNC(module_stop) +PSP_EXPORT_VAR(module_info) +PSP_EXPORT_END + +PSP_EXPORT_START(rtc_driver, 0, 0x4001) +PSP_EXPORT_FUNC(pspRtcSetCurrentTick) +PSP_EXPORT_END + +PSP_END_EXPORTS diff --git a/plugin/rtc_driver.c b/plugin/rtc_driver.c new file mode 100644 index 0000000..26016c8 --- /dev/null +++ b/plugin/rtc_driver.c @@ -0,0 +1,21 @@ +#include + +PSP_MODULE_INFO("audio_driver", PSP_MODULE_KERNEL, 1, 3); +PSP_NO_CREATE_MAIN_THREAD(); + +int sceRtcSetCurrentTick(u64 *tick); + +int pspRtcSetCurrentTick(u64 *tick) { + u32 k1 = pspSdkSetK1(0); + int ret = sceRtcSetCurrentTick(tick); + pspSdkSetK1(k1); + return ret; +} + +int module_start(SceSize args, void *argp) { + return 0; +} + +int module_stop(void) { + return 0; +}