mirror of
https://github.com/joel16/NTPSP.git
synced 2024-11-26 20:50:31 +00:00
ntpsp: Initial commit
This commit is contained in:
commit
1c9f2601a8
58
.gitignore
vendored
Normal file
58
.gitignore
vendored
Normal file
@ -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
|
29
LICENSE
Normal file
29
LICENSE
Normal file
@ -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.
|
7
Makefile
Normal file
7
Makefile
Normal file
@ -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
|
44
app/Makefile
Executable file
44
app/Makefile
Executable file
@ -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 $<) ))
|
190
app/build.mak
Executable file
190
app/build.mak
Executable file
@ -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 <mrbrown@ocgnet.org>
|
||||
# Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
|
||||
# Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
|
||||
#
|
||||
# $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
|
BIN
app/data/intraFont.prx
Executable file
BIN
app/data/intraFont.prx
Executable file
Binary file not shown.
BIN
app/data/iop.prx
Executable file
BIN
app/data/iop.prx
Executable file
Binary file not shown.
BIN
app/data/logo.png
Executable file
BIN
app/data/logo.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
app/data/vlf.prx
Executable file
BIN
app/data/vlf.prx
Executable file
Binary file not shown.
3
app/include/log.h
Normal file
3
app/include/log.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
int debug(const char *format, ...);
|
4
app/include/net.h
Normal file
4
app/include/net.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
int netInit(void);
|
||||
void netExit(void);
|
5
app/include/ntp.h
Normal file
5
app/include/ntp.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <psprtc.h>
|
||||
|
||||
int ntpGetTime(pspTime *psp_time_ntp);
|
6
app/include/utils.h
Normal file
6
app/include/utils.h
Normal file
@ -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)
|
78
app/source/crt0.c
Executable file
78
app/source/crt0.c
Executable file
@ -0,0 +1,78 @@
|
||||
#include <pspsdk.h>
|
||||
#include <pspkernel.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vlf.h>
|
||||
|
||||
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;
|
||||
}
|
29
app/source/log.c
Normal file
29
app/source/log.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <pspiofilemgr.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
70
app/source/main.c
Executable file
70
app/source/main.c
Executable file
@ -0,0 +1,70 @@
|
||||
#include <pspkernel.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <vlf.h>
|
||||
|
||||
#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;
|
||||
}
|
40
app/source/net.c
Normal file
40
app/source/net.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <pspkernel.h>
|
||||
#include <pspnet.h>
|
||||
#include <pspnet_apctl.h>
|
||||
#include <pspnet_inet.h>
|
||||
#include <psputility.h>
|
||||
|
||||
#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);
|
||||
}
|
208
app/source/ntp.c
Normal file
208
app/source/ntp.c
Normal file
@ -0,0 +1,208 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pspkernel.h>
|
||||
#include <pspnet_inet.h>
|
||||
#include <pspnet_resolver.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
2035
libs/include/vlf.h
Executable file
2035
libs/include/vlf.h
Executable file
File diff suppressed because it is too large
Load Diff
BIN
libs/lib/libvlfgu.a
Executable file
BIN
libs/lib/libvlfgu.a
Executable file
Binary file not shown.
BIN
libs/lib/libvlfgui.a
Executable file
BIN
libs/lib/libvlfgui.a
Executable file
Binary file not shown.
BIN
libs/lib/libvlflibc.a
Executable file
BIN
libs/lib/libvlflibc.a
Executable file
Binary file not shown.
BIN
libs/lib/libvlfutils.a
Executable file
BIN
libs/lib/libvlfutils.a
Executable file
Binary file not shown.
27
plugin/Makefile
Normal file
27
plugin/Makefile
Normal file
@ -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/"
|
16
plugin/exports.exp
Normal file
16
plugin/exports.exp
Normal file
@ -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
|
21
plugin/rtc_driver.c
Normal file
21
plugin/rtc_driver.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <pspsdk.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user