├── .github
└── workflows
│ └── compilation.yml
├── .gitignore
├── .travis.yml
├── Makefile
├── Makefile.eeglobal
├── README.md
├── VTSPS2-CRC32.c
├── VTSPS2-HBDL.TXT
├── VTSPS2-HBDL.c
├── VTSPS2-HBDL.h
├── checksum.h
├── crc32.c
├── gfx
├── background.png
├── background2.png
└── logo.png
├── gui.c
├── include
├── gui.h
├── menu.h
├── pad.h
└── textures.h
├── makelog
├── menu.c
├── misc.c
├── pad.c
├── ps2ipc.c
├── strings.h
├── tab
└── gentab32.inc
└── textures.c
/.github/workflows/compilation.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | pull_request:
6 | repository_dispatch:
7 | types: [run_build]
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | container: ps2dev/ps2dev:v1.2.0
13 | steps:
14 | - name: Install dependencies
15 | run: |
16 | apk add bash build-base git nano make mpc mpc1 mpfr4 gmp wget zip
17 | - uses: actions/checkout@v2
18 | - run: |
19 | git config --global --add safe.directory /__w/VTSPS2-HBDL/VTSPS2-HBDL
20 | git fetch --prune --unshallow
21 | - name: Compile HBDL
22 | run: |
23 | make
24 |
25 | - name: Get short SHA
26 | id: slug
27 | run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"
28 |
29 | - name: Upload artifacts
30 | if: ${{ success() }}
31 | uses: actions/upload-artifact@v2
32 | with:
33 | name: HomeBrewDownloader-${{ steps.slug.outputs.sha8 }}
34 | path: VTSPS2-HBDL.elf
35 |
36 | - name: Create release
37 | if: github.ref == 'refs/heads/master'
38 | uses: marvinpinto/action-automatic-releases@latest
39 | with:
40 | repo_token: "${{ secrets.GITHUB_TOKEN }}"
41 | automatic_release_tag: "latest"
42 | title: "Latest development build"
43 | files: VTSPS2-HBDL.elf
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.bak
3 | *.elf
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 |
3 | sudo: required
4 |
5 | services:
6 | - docker
7 |
8 | script:
9 | - docker run -it --rm -v "$PWD:/src" basedskid/ps2dev-sdk-ci make
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | VERSION = 0.34
2 | NAME = VTSPS2-HBDL
3 | EE_BIN = $(NAME).elf
4 | EE_BIN_PACKED = $(NAME)-packed.elf
5 | EE_BIN_STRIPPED = $(NAME)-stripped.elf
6 |
7 | ####
8 | # C File Objects
9 | EE_OBJS = $(NAME).o ps2ipc.o gui.o menu.o pad.o textures.o background_png.o background2_png.o logo_png.o
10 | # SW Module Objects
11 | EE_OBJS += freesio2.o iomanX.o freepad.o mcman.o mcsrv.o
12 | # Network Module
13 | EE_OBJS += ps2dev9.o ps2ip-nm.o ps2ips.o netman.o smap.o ps2http.o
14 | # Other IRX
15 | EE_OBJS += poweroff.o usbd.o usbhdfsd.o misc.o crc32.o VTSPS2-CRC32.o
16 | # SBV Shit
17 | EE_INCS = -I$(PS2SDK)/ports/include -I$(PS2SDK)/sbv/include
18 | EE_LDFLAGS = -L$(PS2SDK)/sbv/lib
19 | ####
20 | EE_LIBS = -lc -ldebug -lpatches -Xlinker --start-group $(EE_LIBS_EXTRA) -lpadx -lmtap -lmc -lkernel -lpoweroff -lnetman -lps2ips -lfileXio -laudsrv -lelf-loader
21 | EE_LIBS += -lgskit_toolkit -lgskit -ldmakit -L$(PS2SDK)/ports/lib -lpng -ljpeg -lz -Xlinker --end-group
22 |
23 | EE_INCS += -I$(GSKIT)/include -I$(GSKIT)/ee/dma/include -I$(GSKIT)/ee/gs/include -I$(GSKIT)/ee/toolkit/include
24 | # linker flags
25 | EE_LIB_DIRS += -L$(GSKIT)/lib
26 | EE_LIB_DIRS += -L$(PS2SDK)/ee/lib
27 | EE_LDFLAGS += $(EE_LIB_DIRS)
28 |
29 | all:
30 | @echo "======================================="
31 | @echo "=== Building $(NAME) v$(VERSION) ==="
32 | @echo "======================================="
33 | $(MAKE) $(EE_BIN_PACKED)
34 |
35 | clean:
36 | rm -f *.elf *.o *.s
37 |
38 | #poweroff Module
39 |
40 | poweroff.s:
41 | bin2s $(PS2SDK)/iop/irx/poweroff.irx poweroff.s poweroff
42 |
43 | #IRX Modules
44 |
45 | freesio2.s:
46 | bin2s $(PS2SDK)/iop/irx/freesio2.irx freesio2.s freesio2
47 |
48 | iomanX.s:
49 | bin2s $(PS2SDK)/iop/irx/iomanX.irx iomanX.s iomanX
50 |
51 | fileXio.s:
52 | bin2s $(PS2SDK)/iop/irx/fileXio.irx fileXio.s fileXio
53 |
54 | freepad.s:
55 | bin2s $(PS2SDK)/iop/irx/freepad.irx freepad.s freepad
56 |
57 | mcman.s:
58 | bin2s $(PS2SDK)/iop/irx/mcman.irx mcman.s mcman
59 |
60 | mcsrv.s:
61 | bin2s $(PS2SDK)/iop/irx/mcserv.irx mcsrv.s mcserv
62 |
63 | ps2dev9.s:
64 | bin2s $(PS2SDK)/iop/irx/ps2dev9.irx ps2dev9.s ps2dev9
65 |
66 | ps2ip-nm.s:
67 | bin2s $(PS2SDK)/iop/irx/ps2ip-nm.irx ps2ip-nm.s ps2ipnm
68 |
69 | ps2ips.s:
70 | bin2s $(PS2SDK)/iop/irx/ps2ips.irx ps2ips.s ps2ips
71 |
72 | netman.s:
73 | bin2s $(PS2SDK)/iop/irx/netman.irx netman.s netman
74 |
75 | smap.s:
76 | bin2s $(PS2SDK)/iop/irx/smap.irx smap.s smap
77 |
78 | ps2http.s:
79 | bin2s $(PS2SDK)/iop/irx/ps2http.irx ps2http.s ps2http
80 |
81 | #thx KrahJohlito
82 | usbd.s:
83 | bin2s $(PS2SDK)/iop/irx/usbd.irx usbd.s usbd
84 |
85 | usbhdfsd.s:
86 | bin2s $(PS2SDK)/iop/irx/usbhdfsd.irx usbhdfsd.s usbhdfsd
87 |
88 | background_png.s: gfx/background.png
89 | bin2s $< $@ background_png
90 |
91 | background2_png.s: gfx/background2.png
92 | bin2s $< $@ background2_png
93 |
94 | logo_png.s: gfx/logo.png
95 | bin2s $< $@ logo_png
96 |
97 | crc32.o: crc32.c checksum.h
98 | ee-gcc -c $< -o $@
99 |
100 | misc.o: misc.c
101 | ee-gcc $(EE_INCS) -c $< -o $@
102 |
103 | VTSPS2-CRC32.o: VTSPS2-CRC32.c VTSPS2-HBDL.h
104 | ee-gcc $(EE_INCS) -c $< -o $@
105 |
106 | run: $(EE_BIN)
107 | ps2client execee host:$(EE_BIN)
108 |
109 | reset:
110 | ps2client reset
111 |
112 | $(EE_BIN_STRIPPED): $(EE_BIN)
113 | $(EE_STRIP) -o $@ $<
114 |
115 | $(EE_BIN_PACKED): $(EE_BIN_STRIPPED)
116 | ps2-packer $(EE_BIN) $(EE_BIN_PACKED)
117 | chmod +x $(EE_BIN_PACKED)
118 |
119 | include $(PS2SDK)/samples/Makefile.pref
120 | include $(PS2SDK)/samples/Makefile.eeglobal
121 |
--------------------------------------------------------------------------------
/Makefile.eeglobal:
--------------------------------------------------------------------------------
1 | # _____ ___ ____ ___ ____
2 | # ____| | ____| | | |____|
3 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4 | #-----------------------------------------------------------------------
5 | # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
6 | # Licenced under Academic Free License version 2.0
7 | # Review ps2sdk README & LICENSE files for further details.
8 |
9 | # Include directories
10 | EE_INCS := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I. $(EE_INCS)
11 |
12 | # C compiler flags
13 | EE_CFLAGS := -D_EE -O2 -G0 -Wall $(EE_CFLAGS)
14 |
15 | # C++ compiler flags
16 | EE_CXXFLAGS := -D_EE -O2 -G0 -Wall $(EE_CXXFLAGS)
17 |
18 | # Linker flags
19 | EE_LDFLAGS := -L$(PS2SDK)/ee/lib $(EE_LDFLAGS)
20 |
21 | # Assembler flags
22 | EE_ASFLAGS := -G0 $(EE_ASFLAGS)
23 |
24 | # Externally defined variables: EE_BIN, EE_OBJS, EE_LIB
25 |
26 | # These macros can be used to simplify certain build rules.
27 | EE_C_COMPILE = $(EE_CC) $(EE_CFLAGS) $(EE_INCS)
28 | EE_CXX_COMPILE = $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS)
29 |
30 | %.o: %.c
31 | $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
32 |
33 | %.o: %.cc
34 | $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@
35 |
36 | %.o: %.cpp
37 | $(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@
38 |
39 | %.o: %.S
40 | $(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
41 |
42 | %.o: %.s
43 | $(EE_AS) $(EE_ASFLAGS) $< -o $@
44 |
45 | $(EE_BIN): $(EE_OBJS)
46 | $(EE_CC) -o $(EE_BIN) $(EE_OBJS) $(EE_LDFLAGS) $(EE_LIBS)
47 | @echo "================="
48 | @echo "=== Stripping ==="
49 | @echo "================="
50 | $(EE_STRIP) -o $(EE_BIN_STRIPPED) $(EE_BIN)
51 | # Uncomment to compress ELF. Adjust path to match your environment
52 | @echo "==================="
53 | @echo "=== Compressing ==="
54 | @echo "==================="
55 | ps2-packer -v $(EE_BIN) $(EE_BIN_PACKED)
56 | rm -f *.o *.s
57 |
58 | $(EE_ERL): $(EE_OBJS)
59 | $(EE_CC) -mno-crt0 -o $(EE_ERL) $(EE_OBJS) $(EE_CFLAGS) $(EE_LDFLAGS) -Wl,-r -Wl,-d
60 | $(EE_STRIP) --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment $(EE_ERL)
61 |
62 | $(EE_LIB): $(EE_OBJS)
63 | $(EE_AR) cru $(EE_LIB) $(EE_OBJS)
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | VTSPS2-HBDL v0.34
6 | HomeBrew DownLoader
7 |
8 | Forked from iLaunchELF by VTSTech
9 |
10 | Rather stable right now. Almost feature complete. Works in testing on real hardware. Writes to either MC or USB based on user selection.
11 | Do not use on SCPH-9XXXX with 2.30 BIOS. Extensively tested on SCPH-70001. Working reports from SCPH-5XXXX as well.
12 |
13 | * Fully functional in PCSX2
14 | * Downloading works on Real PS2.
15 | * Checking works on Real PS2
16 | * Overwriting works on Real PS2
17 | * Creating folders works on Real PS2
18 | * Launching mostly works on Real PS2 (WLE, OPL, GSM launch, a few others don't)
19 | * USB Support, Sequential Downloads
20 |
21 | Credits:
22 | Original iLaunchELF Created by krHACKen & Based_Skid
23 | GUI written by KrahJohlito
24 | crc32.c written by Lammert Bies, (c) 1999-2016 Lammert Bies. File is licensed under the MIT License
25 | Packed with PS2-Packer v1.1.0 by Nicolas "Pixel" Noble
26 | Thanks to krHACKen, Based_Skid, HWC & TnA on Discord for helping me debug issues
27 | Big Thanks to fjtrujy for their PS2 Port of RetroArch
28 |
29 |
30 | Changelog:
31 | v0.31 2020-10-17 11:59PM
32 | file_crc32() updates
33 | Code cleanup
34 |
35 | v0.30 2020-10-13 12:49AM
36 | Now POSIX compliant
37 | No longer using fio/fileXio calls
38 | Updated wLaunchELF to v4.43A Commit 970ca992
39 | Removed some verbosity from Download()
40 |
41 | v0.29 2020-10-09 11:02PM
42 | Added LBFN v0.07.19 WIP by Nika Mod by HWC
43 | Updated ESR to R10F DVD Direct
44 | Updated OPL to 1562-Beta CI-compile #85: Commit 41f7cf0
45 | Updated RetroArch to v1.9.0
46 | Now supports 27 HomeBrews
47 |
48 | v0.28 2020-06-09 1:26AM
49 | Now downloads HomeBrew List upon start.
50 | Added DOSBox, PS2DOOM
51 | Removed some verbosity from Download()
52 | Added some verbosity to DownloadList()
53 | Now supports 26 HomeBrews
54 |
55 | v0.27 2020-06-08 5:10AM
56 | No longer using loader.elf
57 | Using LoadElf() from MPLUS-LOADER3
58 | Now displays remote filesize
59 | Now displays remote version
60 | Reorganized menu to accommodate new items
61 | Menu now dynamically aligns itself
62 | Added 'Aura for Laura' Demo
63 | Added ZoneLoader
64 | Updated RetroArch, OPL, SNES9X, PSMS
65 | Now supports 24 Homebrews
66 |
67 | v0.26 2020-06-07 10:15AM
68 | Renamed ESDL to PS2ESDL
69 | Now supports downloading multiple files per homebrew!
70 | Added NEOCD
71 | Added PGEN
72 | Added PSMS
73 | Added PVCS
74 | Added SNES9X
75 | Fixed bug reading CRC's when entire filename was present in two homebrews.
76 | Now supports 22 Homebrews
77 |
78 | v0.25 2020-06-06 1:05AM
79 | Now supports USB!
80 | 2 more Homebrews added
81 | (VTSPS2-EJECT & VTSPS2-TESTMODE)
82 | Now supports 17 total Homebrews
83 | No longer in ALPHA, First BETA release.
84 |
85 | v0.24 2020-06-05 6:29AM
86 | Now displays Remote CRC32
87 | Local CRC32 defaults to 'unchecked'
88 | Checking for files that don't exist tentatively working.
89 | 00000000 is File Not Exist
90 |
91 | v0.23 06-03-2020 8:29PM
92 | Added INFOGB, PS2SX
93 | Now Supports 15 Total Homebrews
94 | Now using 8.3 Filename standard.
95 | Current CRC32 List now distributed with binary releases.
96 |
97 | v0.22 06-02-2020 9:45PM
98 | Added support for more homebrew
99 | Added HTTP Mirror support.
100 | Added Cuban mirror. Thanks HWC!
101 | Added missing 'Push Start to Exit' to menu
102 | Added ESDL.ELF, 2048.ELF, FCEU.ELF, PICO.ELF
103 | Launching Homebrew now partially functions.
104 | Launches WLE/OPL in real hardware testing .. but not Pico/FCEU
105 |
106 | v0.21 06-02-2020 4:45PM
107 | New Menu
108 | Now displays IP on main screen
109 | Supports many more homebrews.
110 | Fully functional in PCSX2
111 | Tentatively fully working on Real PS2
112 | -Checking
113 | -Downloading+Overwrite
114 | -Downloading+Creating Folder
115 | All work on my SCPH-70001 with this build.
116 | Code cleanup.
117 | Removed delays/debug output.
118 |
119 | v0.2 05-30-2020 10:15PM
120 | First functional release.
121 |
122 | Supports OPL, WLE, HDL, ESR
123 | CRC32 is displayed but not compared currently.
124 | Tested on real hardware (SCPH-70001).
125 | Overwrites existing files correctly.
126 | Only writing to MC0 for now.
127 |
128 | v0.1 05-26-2020 01:44AM
129 | Initial Fork
130 |
131 |
132 | ## Notice
133 | This Program Was Built with The PS2DEV SDK (Compiled May 28th 2020, Commit: ec0cbfd) and has utilized sample code from it https://github.com/ps2dev/ps2sdk
134 |
135 | This Program Utilizes the HTTP Client File System from the PS2DEV sdk
136 |
137 | ## Warranty
138 | This Application Has No Warranty. The Creators of this app cannot be held Responsible for any damage
139 |
--------------------------------------------------------------------------------
/VTSPS2-CRC32.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "checksum.h"
4 |
5 | void substring(char s[], char sub[], int p, int l)
6 | {
7 | int c = 0;
8 | while (c < l) {
9 | sub[c] = s[p+c-1];
10 | c++;
11 | }
12 | sub[c] = '\0';
13 | }
14 |
15 | static char f_crc32[16];
16 |
17 | char *file_crc32(char device[], char path[], char fn[])
18 | {
19 | char tmp[32];
20 | uint32_t t_crc32 = 0xffffffffL;
21 | char full_path[256];
22 | //int chunks_curr = 1;
23 | int bytes_read;
24 | //Build full_path string
25 | snprintf(full_path, sizeof(full_path), "%s%s%s", device, path, fn);
26 | FILE *fp = fopen(full_path, "rb");
27 | if (!fp)
28 | {
29 | printf("ERROR: Unable to open %s for reading \n", full_path);
30 | return("ERROR: Unable to open file for reading \n");
31 | }
32 | //read file, store length in len
33 | fseek(fp,0,SEEK_END);
34 | long len = ftell(fp);
35 | long fsize = len;
36 | fseek(fp,0,SEEK_SET);
37 | printf("Filesize: %lu bytes \n", fsize);
38 | //4MB File Buffer. If less than that read entire into buf
39 | if (len <= 4194304) {
40 | char buf[len];
41 | while((fread(buf, 1, len, fp)) > 0){
42 | printf("%lu bytes read \n", len);
43 | }
44 | //Close the file
45 | fclose(fp);
46 |
47 | //Use sprintf to store crc_32() return value in tmp
48 | //If file is larger than buffer, update_crc_32() will
49 | //need to be looped to get large file CRC32
50 | sprintf(tmp,"%lX", crc_32(buf, len));
51 | //4MB File Buffer. If more than that read byte by byte into ch
52 | //Calling update_crc_32 and passing the old CRC32 and new byte each time.
53 | } else {
54 | char buf[1];
55 | int ch;
56 | ch=fgetc(fp);
57 | t_crc32 = update_crc_32(t_crc32,(unsigned char) ch);
58 | sprintf(tmp,"%lX", t_crc32);
59 | bytes_read = sizeof(buf);
60 | while((ch=fgetc(fp)) != EOF){
61 | t_crc32 = update_crc_32(t_crc32, (unsigned char) ch);
62 | bytes_read++;
63 | //chunks_curr++;
64 | }
65 | //Close the file.
66 | fclose(fp);
67 |
68 | //crc lib requires this operation be preformed on final value
69 | t_crc32 ^= 0xffffffffL;
70 | //Copy the final CRC32 to tmp
71 | sprintf(tmp,"%lX",t_crc32);
72 | }
73 |
74 | //scr_printf("Debug: %s\n", tmp);
75 | //We only need the last 8 bytes of crc_32 return value
76 | //Sometimes it is twice as long preceded by 0xffffffff
77 | //copy processed value to f_crc32
78 | //scr_printf("Debug (tmp): %lx \n", tmp);
79 | if (strlen(tmp)>=9){
80 | substring(tmp,f_crc32,9,8);
81 | } else if (strlen(tmp)<=7) {
82 | if (strlen(tmp) == 7) {
83 | sprintf(f_crc32,"0%s",tmp);
84 | } else if (strlen(tmp) == 6) {
85 | sprintf(f_crc32,"00%s",tmp);
86 | } else if (strlen(tmp) == 5) {
87 | sprintf(f_crc32,"000%s",tmp);
88 | } else if (strlen(tmp) == 4) {
89 | sprintf(f_crc32,"0000%s",tmp);
90 | } else if (strlen(tmp) == 3) {
91 | sprintf(f_crc32,"00000%s",tmp);
92 | } else if (strlen(tmp) == 2) {
93 | sprintf(f_crc32,"000000%s",tmp);
94 | } else if (strlen(tmp) == 1) {
95 | sprintf(f_crc32,"0000000%s",tmp);
96 | }
97 | //substring(tmp,f_crc32,0,8);
98 | } else {
99 | substring(tmp,f_crc32,1,8);
100 | }
101 | //Display CRC32
102 | //scr_printf("CRC32: %s \n",f_crc32);
103 | return f_crc32;
104 | }
105 |
--------------------------------------------------------------------------------
/VTSPS2-HBDL.TXT:
--------------------------------------------------------------------------------
1 | ;v0.33
2 | ;2019-12-22 AURA.ELF 4.87MB 'Aura For Laura' Demo by soopadoopa
3 | ;2015-09-21 DOSBOX.ELF 3.71MB DOSBox v0.74
4 | ;2020-06-05 EJECT.ELF 0.03MB VTSPS2-Eject v0.6
5 | ;2020-07-21 ESR.ELF 0.01MB ESR R10F DVD Direct
6 | ;2020-10-14 FRUITY.ELF 0.70MB Fruity v1.0 by RetroGuru, PS2 Port by nop90
7 | ;2019-04-16 GSM.ELF 0.09MB GSM v0.38
8 | ;2008-01-26 HDL.ELF 0.60MB HDL v0.8C
9 | ;2020-08-06 HERMES.ELF 0.95MB Hermes v1.10 by RetroGuru, PS2 Port by nop90
10 | ;2010-10-05 INFOGB.ELF 0.54MB InfoGB v0.5K
11 | ;2020-07-31 LBFN.ELF 0.54MB LbFn v0.07.19 WIP by Nika, Mod by HWC
12 | ;2005-09-06 NEOCD.ELF 0.32MB NeoCD v0.6c
13 | ;2020-08-20 OPL.ELF 1.12MB OPL 1562-Beta CI-compile #87: Commit 41f7cf0
14 | ;2010-04-29 PGEN.ELF 2.90MB PGen v1.5.1S
15 | ;2010-03-21 PS2DOOM.ELF 5.12MB PS2DOOM v1.0.5.0
16 | ;2011-02-02 PS2ESDL.ELF 0.18MB PS2ESDL v0.810 BETA
17 | ;2014-10-29 PS2SX.ELF 0.05MB PS2SX v1.3
18 | ;2018-06-24 PSMS.ELF 0.23MB PSMS v0.6.3 Reloaded
19 | ;2008-03-04 PVCS.ELF 0.87MB PVCS v0.3 Reloaded
20 | ;2020-08-11 RA_2048.ELF 0.85MB RetroArch v1.9.0 2048
21 | ;2020-08-11 RA_FCEU.ELF 0.99MB RetroArch v1.9.0 FCEUmm
22 | ;2020-08-11 RA_MGBA.ELF 1.03MB RetroArch v1.9.0 mGBA
23 | ;2020-08-11 RA_PICO.ELF 1.00MB RetroArch v1.9.0 PicoDrive
24 | ;2020-08-11 RA_QNES.ELF 0.92MB RetroArch v1.9.0 QuickNES
25 | ;2019-05-06 SMS.ELF 1.36MB SMS v2.9 REV4
26 | ;2011-01-23 SNES9X.ELF 3.65MB SNES9x v1.53 (2011)
27 | ;2016-11-23 SNESSTN.ELF 0.83MB SNESStation v0.26C
28 | ;2020-06-05 TESTMODE.ELF 0.03MB VTSPS2-TEST v0.3
29 | ;2020-08-07 WLE.ELF 0.40MB wLaunchELF v4.43A Commit 970ca992
30 | ;2020-10-29 XUMP.ELF 0.64MB XUMP v1.10 by RetroGuru, PS2 Port by nop90
31 | ;2007-09-26 ZONELDR.ELF 0.13MB ZoneLoader v0.5 BETA
32 | AURA.ELF D9BAD19B
33 | DOSBOX.ELF F620AC3C
34 | EJECT.ELF 0B9903A0
35 | ESR.ELF B1412FD9
36 | FRUITY.ELF DCD20CAF
37 | GSM.ELF 226DA7F1
38 | HDL.ELF FE304CCA
39 | HERMES.ELF AEF89770
40 | INFOGB.ELF A517AA23
41 | LBFN.ELF 753606B8
42 | NEOCD.ELF C8F75FFB
43 | OPL.ELF 56E7CB6C
44 | PGEN.ELF 11FED222
45 | PS2DOOM.ELF 7FE0F069
46 | PS2ESDL.ELF 8BDC61A0
47 | PS2SX.ELF 1900928A
48 | PSMS.ELF 394854B1
49 | PVCS.ELF 6BE80222
50 | RA_2048.ELF D927087A
51 | RA_FCEU.ELF 7524407A
52 | RA_MGBA.ELF 9B783792
53 | RA_PICO.ELF 6E5FA6F4
54 | RA_QNES.ELF 5E02203C
55 | SMS.ELF 453A409F
56 | SNES9X.ELF 0C44D5AF
57 | SNESSTN.ELF 7D5AFAF2
58 | TESTMODE.ELF 13D238E0
59 | WLE.ELF A010B3B7
60 | XUMP.ELF 1FA2D467
61 | ZONELDR.ELF 2B1F284C
--------------------------------------------------------------------------------
/VTSPS2-HBDL.c:
--------------------------------------------------------------------------------
1 | /*
2 | VTSPS2-HBDL by VTSTech
3 | Based on iLaunchELF by krHACKen & Based_Skid
4 | */
5 |
6 | #include "VTSPS2-HBDL.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 |
16 | #include "include/gui.h"
17 | #include "include/menu.h"
18 | #include "include/textures.h"
19 | #include "include/pad.h"
20 |
21 | #define DBSIZE 61 //lines in VTSPS2-HBDL.TXT
22 |
23 | //0.32-GUI
24 | static char localcrc[9];
25 | static char CRC32DB[DBSIZE][128];
26 | char mirror[2][128];
27 |
28 | char action[32], device[32], path[256], fn[16]; //there are better ways to do this
29 |
30 | static int Download(char *urll, char *full_path)
31 | {
32 | int fd, target;
33 | int size = 0;
34 | char buf[5600000];
35 |
36 | fd = open(urll, O_RDONLY);
37 | if (fd >= 0) {
38 | target = open(full_path, O_RDWR | O_CREAT);
39 | if(target >= 0) {
40 | size = lseek(fd, 0, SEEK_END);
41 | lseek(fd, 0, SEEK_SET);
42 |
43 | read(fd, buf, size);
44 | write(target, buf, size);
45 |
46 | sprintf(localcrc, file_crc32(device, path, fn));
47 | close(fd);
48 | close(target);
49 | } else
50 | printf("Download Error! Debug: %d %d %d", fd, target, size);
51 | }
52 |
53 | return size;
54 | }
55 |
56 | static void DownloadList(char *device, char *path, char *fn)
57 | {
58 | char arg0[256], arg1[256], arg2[256], arg3[256], arg4[256], arg5[256], arg6[256], arg7[256], arg8[256];
59 | char *exec_args[9] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
60 | int argc = 0;
61 | int y = 0;
62 | int z = 0;
63 | int ret = 0;
64 | int fd = 0;
65 | int size = 0;
66 | char full_path[256];
67 | char str[256];
68 | int terminate = 0;
69 | int opsDone = 0;
70 | //patches.ppi
71 |
72 | while (!terminate) {
73 | guiDrawTerminal();
74 |
75 | if (http_mirror == 0)
76 | strcpy(str,"* Mirror 1 Selected... \n");
77 | else if (http_mirror == 1)
78 | strcpy(str,"* Mirror 2 Selected... \n");
79 |
80 | drawFont(35, 117, 0.32f, WhiteFont, str);
81 | drawFont(35, 134, 0.32f, WhiteFont, "* Building Download List... \n");
82 |
83 | if (strstr("DOSBOX.ELF",fn)) {
84 | drawFont(35, 151, 0.32f, WhiteFont, "* DOSBox ... \n");
85 |
86 | if (!opsDone) {
87 | argc = 4;
88 | for (y = 0; y <= argc; y++)
89 | strcpy(exec_args[y], mirror[http_mirror]);
90 |
91 | strcat(exec_args[0],fn);
92 | strcpy(exec_args[1],fn);
93 | strcat(exec_args[2],"dosbox.bin");
94 | strcpy(exec_args[3],"dosbox.conf");
95 | }
96 | } else if (strstr("PS2DOOM.ELF",fn)) {
97 | drawFont(35, 151, 0.32f, WhiteFont, "* PS2Doom ... \n");
98 |
99 | if (!opsDone) {
100 | argc = 6;
101 | for (y = 0; y <= argc; y++)
102 | strcpy(exec_args[y], mirror[http_mirror]);
103 |
104 | strcat(exec_args[0],fn);
105 | strcpy(exec_args[1],fn);
106 | strcat(exec_args[2],"ps2doom.bin");
107 | strcpy(exec_args[3],"ps2doom.config");
108 | strcat(exec_args[4],"doom1.wad");
109 | strcpy(exec_args[5],"doom1.wad");
110 | }
111 | } else if (strstr("PS2ESDL.ELF",fn)) {
112 | drawFont(35, 151, 0.32f, WhiteFont, "* PS2ESDL ... \n");
113 |
114 | if (!opsDone) {
115 | argc = 4;
116 | for (y = 0; y <= argc; y++)
117 | strcpy(exec_args[y], mirror[http_mirror]);
118 |
119 | strcat(exec_args[0],fn);
120 | strcpy(exec_args[1],fn);
121 | strcat(exec_args[2],"patches.ppi");
122 | strcpy(exec_args[3],"patches.ppi");
123 | }
124 | }
125 |
126 | int y = 151;
127 | int spacing = 17;
128 | for (z = 0; z < argc; z = z+2) {
129 | memset(full_path, 0, sizeof(full_path));
130 | snprintf(full_path, sizeof(full_path), "%s%s%s", device, path, exec_args[z+1]);
131 | drawFont(35, y += spacing, 0.32f, WhiteFont, "* Downloading...\n");
132 | sprintf(str,"* URL: %s\n", exec_args[z]);
133 | drawFont(35, y += spacing, 0.32f, WhiteFont, str);
134 | sprintf(str,"* Path: %s\n", full_path);
135 | drawFont(35, y += spacing, 0.32f, WhiteFont, str);
136 |
137 | if (!opsDone) {
138 | ret = Download(exec_args[z], full_path);
139 | if(ret <= 0) {
140 | printf("* Error! Could not open the file\n");
141 | } else {
142 | fd = open(full_path, O_RDONLY);
143 | size = lseek(fd, 0, SEEK_END);
144 | lseek(fd, 0, SEEK_SET);
145 | close(fd);
146 | }
147 | }
148 |
149 | if (size >= 1) {
150 | sprintf(str,"* %s Download Complete!\n", full_path);
151 | drawFont(35, y += spacing, 0.32f, GreenFont, str);
152 | } else {
153 | sprintf(str,"* %s Download Failed!\n", full_path);
154 | drawFont(35, y += spacing, 0.32f, RedFont, str);
155 | }
156 | }
157 |
158 | drawFont(35, 380, 0.32f, WhiteFont, "Press X or O to continue.\n");
159 |
160 | guiRender();
161 | opsDone = 1;
162 |
163 | buttonStatts(0, 0);
164 | if ((new_pad & PAD_CROSS) || (new_pad & PAD_CIRCLE))
165 | terminate = 1;
166 | }
167 | }
168 |
169 | void DoTask(int task, int id)
170 | {
171 | int ret = 0, launching, downloading, checking;
172 | char arg0[256], arg1[256], arg2[256], arg3[256], arg4[256], arg5[256], arg6[256], arg7[256], arg8[256];
173 | char *exec_args[9] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
174 | int argc = 0;
175 | int fd = 0;
176 | int size = 0;
177 | char full_path[256];
178 | char str[256];
179 | /*
180 | exec_args[0] == the target ELF's URI. loader.elf will load that ELF.
181 | exec_args[1] to exec_args[8] == arguments to be passed to the target ELF.
182 | */
183 |
184 | launching = 0;
185 | downloading = 0;
186 | checking = 0;
187 |
188 | //read pad 0
189 | buttonStatts(0, 0);
190 |
191 | if (task != 0)
192 | {
193 | if (task != 3) {
194 | guiClear();
195 | guiDrawTerminal();
196 | }
197 |
198 | if (task == 1)
199 | {
200 | checking = 1;
201 | snprintf(full_path, sizeof(full_path), "%s%s%s", device, path, fn);
202 | drawFont(35, 100, 0.35f, WhiteFont, "Checking...\n");
203 | guiRender();
204 | }
205 | else if (task == 2)
206 | {
207 | downloading = 1;
208 | drawFont(35, 100, 0.35f, WhiteFont, "Downloading...\n");
209 | guiRender();
210 |
211 | sprintf(exec_args[0], "%s%s", mirror[http_mirror], fn);
212 | snprintf(full_path, sizeof(full_path), "%s%s", device, path);
213 |
214 | //remove trailing / for MkDir
215 | char make_path[256];
216 | substring(full_path, make_path, 1, strlen(full_path) - 1);
217 | mkdir(make_path, 0777);
218 |
219 | strcat(full_path, fn);
220 | argc = 1;
221 | }
222 | if (task == 3)
223 | {
224 | launching = 1;
225 | snprintf(full_path, sizeof(full_path), "%s%s%s", device, path, fn);
226 | strcpy(exec_args[0], full_path);
227 | argc = 1;
228 | }
229 | } else asm volatile("break\n"); // OUT OF BOUNDS, UNDEFINED ITEM!
230 |
231 | int terminate = 0;
232 | int opsDone = 0;
233 |
234 | if (downloading == 1) {
235 | if (strstr("PS2ESDL.ELF",fn))
236 | DownloadList(device,path,"PS2ESDL.ELF");
237 | else if (strstr("PS2DOOM.ELF",fn))
238 | DownloadList(device,path,"PS2DOOM.ELF");
239 | else if (strstr("DOSBOX.ELF",fn))
240 | DownloadList(device,path,"DOSBOX.ELF");
241 | else {
242 | while (!terminate) { //a bit crude but it works..good enough for now
243 | guiDrawTerminal();
244 |
245 | sprintf(str,"* URL: %s \n", exec_args[0]);
246 | drawFont(35, 117, 0.32f, WhiteFont, str);
247 |
248 | sprintf(str,"* Path: %s \n", full_path);
249 | drawFont(35, 134, 0.32f, WhiteFont, str);
250 |
251 | if (!opsDone)
252 | ret = Download(exec_args[0],full_path);
253 | if (ret <= 0) {
254 | drawFont(35, 151, 0.32f, RedFont, "! Download Error!\n");
255 | } else {
256 | sprintf(str,"* File Size: %d bytes \n", ret);
257 | drawFont(35, 151, 0.32f, WhiteFont, str);
258 |
259 | if (!opsDone) {
260 | fd = open(full_path, O_RDONLY);
261 | size = lseek(fd, 0, SEEK_END);
262 | lseek(fd, 0, SEEK_SET);
263 | close(fd);
264 | }
265 |
266 | if (size >= 1) {
267 | sprintf(str,"* %s Exists! \n", full_path);
268 | drawFont(35, 168, 0.32f, WhiteFont, str);
269 | } else {
270 | sprintf(str,"* %s Does Not Exist! \n", full_path);
271 | drawFont(35, 168, 0.32f, RedFont, str);
272 | }
273 | }
274 |
275 | if (strstr(localcrc, downloadableApps[id].rcrc) != 0)
276 | drawFont(35, 185, 0.32f, RedFont, "Local and Remote CRC32 do not match!\n");
277 | else {
278 | sprintf(str, "CRC32 Verified! %s\n", localcrc);
279 | drawFont(35, 185, 0.32f, GreenFont, str);
280 | }
281 | drawFont(35, 380, 0.32f, WhiteFont, "Press X or O to continue.\n");
282 |
283 | guiRender();
284 | opsDone = 1;
285 |
286 | buttonStatts(0, 0);
287 | if ((new_pad & PAD_CROSS) || (new_pad & PAD_CIRCLE))
288 | terminate = 1;
289 | }
290 | }
291 | }
292 |
293 | if (checking == 1) {
294 | while (!terminate) {
295 | guiDrawTerminal();
296 |
297 | if (!opsDone) {
298 | snprintf(full_path, sizeof(full_path), "%s%s%s", device, path, fn);
299 | fd = open(full_path, O_RDONLY);
300 | }
301 | if (fd < 0) {
302 | sprintf(str,"! %s Does Not Exist!\n", full_path);
303 | drawFont(35, 117, 0.32f, RedFont, str);
304 | } else {
305 | sprintf(str,"* Local File Opened... %d \n", fd);
306 | drawFont(35, 117, 0.32f, GreenFont, str);
307 | }
308 |
309 | if (!opsDone) {
310 | size = lseek(fd, 0, SEEK_END);
311 | lseek(fd, 0, SEEK_SET);
312 | }
313 |
314 | if (size >= 1) {
315 | sprintf(str,"* File Size... %d \n", size);
316 | drawFont(35, 134, 0.32f, GreenFont, str);
317 |
318 | sprintf(str,"* Calculating CRC32 %s \n", full_path);
319 | drawFont(35, 151, 0.32f, GreenFont, str);
320 | } else
321 | sprintf(localcrc, "00000000");
322 |
323 | if (!opsDone) {
324 | strcpy(localcrc, file_crc32(device,path,fn));
325 | close(fd);
326 | }
327 |
328 | sprintf(str,"Local CRC32: %s\n", localcrc);
329 | drawFont(35, 168, 0.32f, GreenFont, str);
330 | drawFont(35, 380, 0.32f, WhiteFont, "Press X or O to continue.\n");
331 |
332 | guiRender();
333 | opsDone = 1;
334 |
335 | buttonStatts(0, 0);
336 | if ((new_pad & PAD_CROSS) || (new_pad & PAD_CIRCLE))
337 | terminate = 1;
338 | }
339 | }
340 |
341 | if (launching == 1) {
342 | //check file exists then launch
343 | fd = open(full_path, O_RDONLY);
344 | if (fd >= 0) {
345 | close(fd);
346 | deinit(0);
347 | LoadELFFromFile(full_path, argc, exec_args);
348 | }
349 | }
350 | }
351 |
352 | static char hbdl_path[256];
353 |
354 | static char *set_hbdl_path(void)
355 | {
356 | getcwd(hbdl_path, 256); //uncomment for release
357 | strcat(hbdl_path,"VTSPS2-HBDL.TXT");
358 |
359 | return hbdl_path;
360 | }
361 |
362 | static void readcrc()
363 | {
364 | //hardcoded path during dev. cwd is 'host' in PCSX2
365 | //char fname[25] = "mc0:APPS/VTSPS2-HBDL.TXT";
366 |
367 | char hbdl_path[256];
368 | getcwd(hbdl_path, 256); //uncomment for release builds
369 | strcat(hbdl_path, "VTSPS2-HBDL.TXT"); //uncomment for release builds
370 |
371 | int i = 0;
372 | char *tmp = NULL;
373 | size_t len = 0;
374 | ssize_t read;
375 |
376 | FILE *fp = fopen(hbdl_path, "r"); //fname dev, hbdl_path rls
377 | if (fp >= 0) {
378 | while((read = getline(&tmp, &len, fp)) != -1)
379 | strcpy(CRC32DB[i++], tmp);
380 |
381 | fclose(fp);
382 | } else
383 | printf("readcrc() error");
384 |
385 | char hbsize[7];
386 | char hbver[64];
387 | char hbrcrc[16];
388 | int j = NUM_APPS;
389 |
390 | i = 1; // first line in DB is HDBL version, skip it
391 | while(i <= j) {
392 | int fnsize = (strlen(downloadableApps[i - 1].elfName));
393 | int len = strlen(CRC32DB[i]);
394 |
395 | substring(CRC32DB[i], hbsize, (fnsize + 14), 6);
396 | downloadableApps[i - 1].size = (char *)malloc((6 + 1) * sizeof(char));
397 | snprintf(downloadableApps[i - 1].size, 6 + 1, hbsize);
398 |
399 | substring(CRC32DB[i], hbver, (fnsize + 21), len);
400 | downloadableApps[i - 1].version = (char *)malloc((63 + 1) * sizeof(char));
401 | snprintf(downloadableApps[i - 1].version, 63 + 1, hbver);
402 |
403 | i++;
404 | }
405 |
406 | j = 0;
407 | while(i < DBSIZE) {
408 | substring(CRC32DB[i++], hbrcrc,(strlen(downloadableApps[j].elfName) + 2), 9);
409 | downloadableApps[j].rcrc = (char *)malloc((15 + 1) * sizeof(char));
410 | snprintf(downloadableApps[j].rcrc, 15 + 1, hbrcrc);
411 |
412 | j++;
413 | }
414 | }
415 |
416 | static void setDefaults(void)
417 | {
418 | snprintf(action, sizeof(action), "CHECK");
419 | snprintf(device, sizeof(device), "mc0:/");
420 | snprintf(path, sizeof(path), "APPS/");
421 | snprintf(fn, sizeof(fn), downloadableApps[0].elfName);
422 |
423 | snprintf(mirror[0], sizeof(mirror[0]), "http://hbdl.vts-tech.org/");
424 | snprintf(mirror[1], sizeof(mirror[1]), "http://www.hwc.nat.cu/ps2-vault/ps2hbdl/");
425 | sprintf(localcrc, "00000001");
426 |
427 | http_mirror = 0;
428 | }
429 |
430 | int main(int argc, char *argv[])
431 | {
432 | // initialize
433 | init();
434 |
435 | guiInit();
436 |
437 | guiDrawLogo();
438 | drawFont(70, 171, 0.32f, TealFont, "Modules Loaded. Obtaining an IP Address ... \n");
439 | guiRender();
440 |
441 | dhcpmain(); // Setup Network Config With DHCP
442 | guiClear();
443 |
444 | guiDrawLogo();
445 | drawFont(70, 171, 0.32f, TealFont, "IP Address obtained. Downloading homebrew list from hbdl.vts-tech.org ... \n");
446 | guiRender();
447 |
448 | Download("http://hbdl.vts-tech.org/VTSPS2-HBDL.BIN", set_hbdl_path());
449 |
450 | setDefaults();
451 |
452 | menuInitMenu();
453 | readcrc(); //populates CRC32DB[]
454 | guiClear();
455 |
456 | while (1)
457 | {
458 | guiDrawMenu();
459 | guiRender();
460 | menuHandleInput();
461 | }
462 | }
463 |
--------------------------------------------------------------------------------
/VTSPS2-HBDL.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | //ps2ip.c
6 | int dhcpmain();
7 | char *getIpAddress(void);
8 |
9 | //VTSPS2-CRC32.c
10 | char *file_crc32(char device[], char path[], char fn[]);
11 |
12 | //misc.c
13 | void substring(char s[], char sub[], int p, int l);
14 | ssize_t getline(char **lineptr, size_t *n, FILE *stream);
15 |
16 | void init(void);
17 | void deinit(int browser);
18 |
19 | void DoTask(int task, int id);
20 |
21 | int http_mirror;
22 |
--------------------------------------------------------------------------------
/checksum.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Library: libcrc
3 | * File: include/checksum.h
4 | * Author: Lammert Bies
5 | *
6 | * This file is licensed under the MIT License as stated below
7 | *
8 | * Copyright (c) 1999-2018 Lammert Bies
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy
11 | * of this software and associated documentation files (the "Software"), to deal
12 | * in the Software without restriction, including without limitation the rights
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | * copies of the Software, and to permit persons to whom the Software is
15 | * furnished to do so, subject to the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included in all
18 | * copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 | * SOFTWARE.
27 | *
28 | * Description
29 | * -----------
30 | * The headerfile include/checksum.h contains the definitions and prototypes
31 | * for routines that can be used to calculate several kinds of checksums.
32 | */
33 |
34 | #ifndef DEF_LIBCRC_CHECKSUM_H
35 | #define DEF_LIBCRC_CHECKSUM_H
36 |
37 | #include
38 | #include
39 |
40 | /*
41 | * #define CRC_POLY_xxxx
42 | *
43 | * The constants of the form CRC_POLY_xxxx define the polynomials for some well
44 | * known CRC calculations.
45 | */
46 |
47 | #define CRC_POLY_16 0xA001
48 | #define CRC_POLY_32 0xEDB88320ul
49 | #define CRC_POLY_64 0x42F0E1EBA9EA3693ull
50 | #define CRC_POLY_CCITT 0x1021
51 | #define CRC_POLY_DNP 0xA6BC
52 | #define CRC_POLY_KERMIT 0x8408
53 | #define CRC_POLY_SICK 0x8005
54 |
55 | /*
56 | * #define CRC_START_xxxx
57 | *
58 | * The constants of the form CRC_START_xxxx define the values that are used for
59 | * initialization of a CRC value for common used calculation methods.
60 | */
61 |
62 | #define CRC_START_8 0x00
63 | #define CRC_START_16 0x0000
64 | #define CRC_START_MODBUS 0xFFFF
65 | #define CRC_START_XMODEM 0x0000
66 | #define CRC_START_CCITT_1D0F 0x1D0F
67 | #define CRC_START_CCITT_FFFF 0xFFFF
68 | #define CRC_START_KERMIT 0x0000
69 | #define CRC_START_SICK 0x0000
70 | #define CRC_START_DNP 0x0000
71 | #define CRC_START_32 0xFFFFFFFFul
72 | #define CRC_START_64_ECMA 0x0000000000000000ull
73 | #define CRC_START_64_WE 0xFFFFFFFFFFFFFFFFull
74 |
75 | /*
76 | * Prototype list of global functions
77 | */
78 |
79 | unsigned char * checksum_NMEA( const unsigned char *input_str, unsigned char *result );
80 | uint8_t crc_8( const unsigned char *input_str, size_t num_bytes );
81 | uint16_t crc_16( const unsigned char *input_str, size_t num_bytes );
82 | uint32_t crc_32( const unsigned char *input_str, size_t num_bytes );
83 | uint64_t crc_64_ecma( const unsigned char *input_str, size_t num_bytes );
84 | uint64_t crc_64_we( const unsigned char *input_str, size_t num_bytes );
85 | uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes );
86 | uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes );
87 | uint16_t crc_dnp( const unsigned char *input_str, size_t num_bytes );
88 | uint16_t crc_kermit( const unsigned char *input_str, size_t num_bytes );
89 | uint16_t crc_modbus( const unsigned char *input_str, size_t num_bytes );
90 | uint16_t crc_sick( const unsigned char *input_str, size_t num_bytes );
91 | uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes );
92 | uint8_t update_crc_8( uint8_t crc, unsigned char c );
93 | uint16_t update_crc_16( uint16_t crc, unsigned char c );
94 | uint32_t update_crc_32( uint32_t crc, unsigned char c );
95 | uint64_t update_crc_64_ecma( uint64_t crc, unsigned char c );
96 | uint16_t update_crc_ccitt( uint16_t crc, unsigned char c );
97 | uint16_t update_crc_dnp( uint16_t crc, unsigned char c );
98 | uint16_t update_crc_kermit( uint16_t crc, unsigned char c );
99 | uint16_t update_crc_sick( uint16_t crc, unsigned char c, unsigned char prev_byte );
100 |
101 | /*
102 | * Global CRC lookup tables
103 | */
104 |
105 | extern const uint32_t crc_tab32[];
106 | extern const uint64_t crc_tab64[];
107 |
108 | #endif // DEF_LIBCRC_CHECKSUM_H
109 |
--------------------------------------------------------------------------------
/crc32.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Library: libcrc
3 | * File: src/crc32.c
4 | * Author: Lammert Bies
5 | *
6 | * This file is licensed under the MIT License as stated below
7 | *
8 | * Copyright (c) 1999-2016 Lammert Bies
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy
11 | * of this software and associated documentation files (the "Software"), to deal
12 | * in the Software without restriction, including without limitation the rights
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | * copies of the Software, and to permit persons to whom the Software is
15 | * furnished to do so, subject to the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included in all
18 | * copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 | * SOFTWARE.
27 | *
28 | * Description
29 | * -----------
30 | * The source file src/crc32.c contains the routines which are needed to
31 | * calculate a 32 bit CRC value of a sequence of bytes.
32 | */
33 |
34 | #include
35 | #include
36 | #include "checksum.h"
37 |
38 | /*
39 | * Include the lookup table for the CRC 32 calculation
40 | */
41 |
42 | #include "./tab/gentab32.inc"
43 |
44 | /*
45 | * uint32_t crc_32( const unsigned char *input_str, size_t num_bytes );
46 | *
47 | * The function crc_32() calculates in one pass the common 32 bit CRC value for
48 | * a byte string that is passed to the function together with a parameter
49 | * indicating the length.
50 | */
51 |
52 | uint32_t crc_32( const unsigned char *input_str, size_t num_bytes ) {
53 |
54 | uint32_t crc;
55 | const unsigned char *ptr;
56 | size_t a;
57 |
58 | crc = CRC_START_32;
59 | ptr = input_str;
60 |
61 | if ( ptr != NULL ) for (a=0; a> 8) ^ crc_tab32[ (crc ^ (uint32_t) *ptr++) & 0x000000FFul ];
64 | }
65 |
66 | return (crc ^ 0xFFFFFFFFul);
67 |
68 | } /* crc_32 */
69 |
70 | /*
71 | * uint32_t update_crc_32( uint32_t crc, unsigned char c );
72 | *
73 | * The function update_crc_32() calculates a new CRC-32 value based on the
74 | * previous value of the CRC and the next byte of the data to be checked.
75 | */
76 |
77 | uint32_t update_crc_32( uint32_t crc, unsigned char c ) {
78 |
79 | return (crc >> 8) ^ crc_tab32[ (crc ^ (uint32_t) c) & 0x000000FFul ];
80 |
81 | } /* update_crc_32 */
82 |
--------------------------------------------------------------------------------
/gfx/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VTSTech/VTSPS2-HBDL/b80611413ae9e05a49d5af3356c737a5143d7ceb/gfx/background.png
--------------------------------------------------------------------------------
/gfx/background2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VTSTech/VTSPS2-HBDL/b80611413ae9e05a49d5af3356c737a5143d7ceb/gfx/background2.png
--------------------------------------------------------------------------------
/gfx/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VTSTech/VTSPS2-HBDL/b80611413ae9e05a49d5af3356c737a5143d7ceb/gfx/logo.png
--------------------------------------------------------------------------------
/gui.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "include/gui.h"
6 | #include "include/menu.h"
7 | #include "include/textures.h"
8 | #include "include/pad.h"
9 |
10 | #include "VTSPS2-HBDL.h"
11 |
12 | const u64 Black = GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00);
13 | const u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
14 | const u64 Blue = GS_SETREG_RGBAQ(0x01,0x50,0xA9,0x80,0x00);
15 |
16 | const u64 WhiteFont = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x80,0x00);
17 | const u64 RedFont = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x80,0x00);
18 | const u64 GreenFont = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x80,0x00);
19 | const u64 TealFont = GS_SETREG_RGBAQ(0x00,0xFF,0xFF,0x80,0x00);
20 | const u64 YellowFont = GS_SETREG_RGBAQ(0xFF,0xFF,0x00,0x80,0x00);
21 |
22 | targets_t downloadableApps[NUM_APPS] = {
23 | {"AURA.ELF", "Aura For Laura"},
24 | {"DOSBOX.ELF", "DosBox"},
25 | {"EJECT.ELF", "Eject"},
26 | {"ESR.ELF", "ESR"},
27 | {"FRUITY.ELF", "Fruity"},
28 | {"GSM.ELF", "GSM"},
29 | {"HDL.ELF", "HDL"},
30 | {"HERMES.ELF", "Hermes"},
31 | {"INFOGB.ELF", "InfoGB"},
32 | {"LBFN.ELF", "Lbfn"},
33 | {"NEOCD.ELF", "NeoCD"},
34 | {"OPL.ELF", "Open PS2 Loader"},
35 | {"PGEN.ELF", "PGEN"},
36 | {"PS2DOOM.ELF", "PS2 Doom"},
37 | {"PS2ESDL.ELF", "PS2ESDL"},
38 | {"PS2SX.ELF", "PS2SX"},
39 | {"PSMS.ELF", "PSMS"},
40 | {"PVCS.ELF", "PVCS"},
41 | {"RA_2048.ELF", "RetroArch 2048"},
42 | {"RA_FCEU.ELF", "RetroArch FCEUmm"},
43 | {"RA_MGBA.ELF", "RetroArch mGBA"},
44 | {"RA_PICO.ELF", "RetroArch PicoDrive"},
45 | {"RA_QNES.ELF", "RetroArch QuickNES"},
46 | {"SMS.ELF", "Simple Media System (SMS)"},
47 | {"SNES9X.ELF", "SNES9X"},
48 | {"SNESSTN.ELF", "SNES Station"},
49 | {"TESTMODE.ELF", "Test Mode"},
50 | {"WLE.ELF", "wLaunch Elf"},
51 | {"XUMP.ELF", "XUMP"},
52 | {"ZONELDR.ELF", "ZONELDR"}
53 | };
54 |
55 | // CLEAN UP vv
56 | extern char action[32], device[32], path[256], fn[16];
57 | extern char mirror[2][128];
58 | // CLEAN UP ^^
59 |
60 | static GSGLOBAL *gsGlobal;
61 | static GSFONTM *gsFontM;
62 | static GSTEXTURE gsTexture[TEXTURES_COUNT];
63 |
64 | static int callbackId;
65 | static int semaId;
66 |
67 | static int guiCallback(void)
68 | {
69 | ee_sema_t sema;
70 | iReferSemaStatus(semaId, &sema);
71 | if(sema.count < sema.max_count)
72 | iSignalSema(semaId);
73 |
74 | ExitHandler();
75 | return 0;
76 | }
77 |
78 | void guiInit(void)
79 | {
80 | dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
81 | D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
82 |
83 | // Initialize the DMAC
84 | dmaKit_chan_init(DMA_CHANNEL_GIF);
85 |
86 | // Initialize the GS
87 | gsGlobal = gsKit_init_global();
88 |
89 | // Force NTSC (cause I cbf dealing with various screenHeights)
90 | gsGlobal->Mode = GS_MODE_NTSC;
91 | gsGlobal->Width = 640;
92 | gsGlobal->Height = 448;
93 | gsGlobal->Interlace = GS_INTERLACED;
94 | gsGlobal->Field = GS_FIELD;
95 | gsGlobal->PSM = GS_PSM_CT24;
96 |
97 | gsGlobal->PrimAAEnable = GS_SETTING_ON;
98 | gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
99 | gsGlobal->DoubleBuffering = GS_SETTING_ON;
100 | gsGlobal->ZBuffering = GS_SETTING_OFF;
101 |
102 | gsFontM = gsKit_init_fontm();
103 | gsKit_fontm_upload(gsGlobal, gsFontM);
104 | gsFontM->Spacing = 0.95f;
105 |
106 | ee_sema_t sema;
107 | sema.init_count = 0;
108 | sema.max_count = 1;
109 | sema.attr = sema.option = 0;
110 | semaId = CreateSema(&sema);
111 |
112 | callbackId = gsKit_add_vsync_handler(&guiCallback);
113 | gsKit_init_screen(gsGlobal);
114 | gsKit_mode_switch(gsGlobal, GS_ONESHOT);
115 |
116 | gsKit_set_test(gsGlobal, GS_ZTEST_OFF);
117 | gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
118 | gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00,0x00,0x00,0x80,0x00));
119 | gsKit_sync_flip(gsGlobal);
120 |
121 | // Load all textures
122 | int i;
123 | for (i = 0; i < TEXTURES_COUNT; i++)
124 | {
125 | gsTexture[i].Delayed = 1;
126 | texPngLoad(&gsTexture[i], i);
127 | gsTexture[i].Filter = GS_FILTER_LINEAR;
128 | }
129 | }
130 |
131 | void drawFont(float x, float y, float scale, u64 colour, char *text)
132 | {
133 | gsKit_fontm_print_scaled(gsGlobal, gsFontM, x, y, 3, scale, colour, text);
134 | }
135 |
136 | static void drawBackground(GSTEXTURE *gsTexture)
137 | {
138 | u64 texCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
139 |
140 | gsKit_TexManager_bind(gsGlobal, gsTexture);
141 |
142 | gsKit_prim_sprite_texture(gsGlobal, gsTexture,
143 | 0.0f, // X1
144 | 0.0f, // Y2
145 | 0.0f, // U1
146 | 0.0f, // V1
147 | gsGlobal->Width, // X2
148 | gsGlobal->Height, // Y2
149 | gsGlobal->Width, // U2
150 | gsGlobal->Height, // V2
151 | 2,
152 | texCol);
153 | }
154 |
155 | static void drawTexture(GSTEXTURE *gsTexture, float fx, float fy)
156 | {
157 | u64 texCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
158 |
159 | gsKit_TexManager_bind(gsGlobal, gsTexture);
160 |
161 | gsKit_prim_sprite_texture(gsGlobal, gsTexture,
162 | fx, // X1
163 | fy - gsTexture->Height, // Y2
164 | 0.0f, // U1
165 | 0.0f, // V1
166 | fx + gsTexture->Width, // X2
167 | fy, // Y2
168 | gsTexture->Width, // U2
169 | gsTexture->Height, // V2
170 | 2,
171 | texCol);
172 | }
173 |
174 | void guiDrawLogo(void)
175 | {
176 | drawTexture(&gsTexture[LOGO], 70, 150);
177 | }
178 |
179 | void guiDrawMenu(void)
180 | {
181 | char str[256];
182 |
183 | drawBackground(&gsTexture[BACKGROUND]);
184 |
185 | sprintf(str, "IP Address: %s\n", getIpAddress());
186 | drawFont(35, 23, 0.38f, TealFont, str);
187 |
188 | sprintf(str, "Mirror: %s\n", mirror[http_mirror]);
189 | drawFont(37, 32, 0.38f, TealFont, str);
190 |
191 | sprintf(str,"Mode: %s", action);
192 | drawFont(35, 52, 0.32f, TealFont, str);
193 |
194 | sprintf(str,"Device: %s", device);
195 | drawFont(265, 52, 0.32f, TealFont, str);
196 |
197 | sprintf(str,"Path: %s", path);
198 | drawFont(485, 52, 0.32f, TealFont, str);
199 |
200 | menuRender();
201 | }
202 |
203 | void guiDrawTerminal(void)
204 | {
205 | char *appName = "VTSPS2-HBDL HomeBrew DownLoader v0.35 2022-06-17 Build #TBD\n";
206 | char *appAuthor = "Written by VTSTech github.com/Veritas83/VTSPS2-HBDL\nBased on iLaunchElf By: krHACKen, Based_Skid, Copyright \xa9 2018 \nGUI written by KrahJohlito\n";
207 | /*char *appVer = "";
208 | char *appNotice = "Notice: This App Contains Code from uLaunchELF \n";*/
209 |
210 | drawBackground(&gsTexture[BACKGROUND2]);
211 |
212 | drawFont(35, 20, 0.34f, YellowFont, appName);
213 | drawFont(35, 35, 0.34f, YellowFont, appAuthor);
214 | }
215 |
216 | void guiClear(void)
217 | {
218 | gsKit_clear(gsGlobal, Black);
219 | }
220 |
221 | void guiRender(void)
222 | {
223 | gsKit_set_finish(gsGlobal);
224 | gsKit_queue_exec(gsGlobal);
225 | gsKit_finish();
226 |
227 | if(!gsGlobal->FirstFrame)
228 | {
229 | // Wait for vsync...
230 | PollSema(semaId);
231 | WaitSema(semaId);
232 |
233 | if (gsGlobal->DoubleBuffering == GS_SETTING_ON)
234 | {
235 | GS_SET_DISPFB2(gsGlobal->ScreenBuffer[gsGlobal->ActiveBuffer & 1] / 8192,
236 | gsGlobal->Width / 64, gsGlobal->PSM, 0, 0);
237 |
238 | gsGlobal->ActiveBuffer ^= 1;
239 | }
240 | }
241 |
242 | gsKit_setactive(gsGlobal);
243 | gsKit_TexManager_nextFrame(gsGlobal);
244 | }
245 |
246 | void guiEnd(void)
247 | {
248 | DeleteSema(semaId);
249 | }
250 |
--------------------------------------------------------------------------------
/include/gui.h:
--------------------------------------------------------------------------------
1 | #ifndef __GUI_H
2 | #define __GUI_H
3 |
4 | #include
5 |
6 | #define NUM_APPS 30
7 |
8 | typedef struct
9 | {
10 | char *elfName;
11 | char *longName;
12 | char *version;
13 | char *size;
14 | char *rcrc;
15 | } targets_t;
16 |
17 | targets_t downloadableApps[NUM_APPS];
18 |
19 | const u64 Black;
20 | const u64 White;
21 | const u64 Blue;
22 |
23 | const u64 WhiteFont;
24 | const u64 RedFont;
25 | const u64 GreenFont;
26 | const u64 TealFont;
27 | const u64 YellowFont;
28 |
29 | void drawFont(float x, float y, float scale, u64 colour, char *text);
30 |
31 | void guiInit(void);
32 | void guiEnd(void);
33 |
34 | void guiDrawLogo(void);
35 | void guiDrawMenu(void);
36 | void guiDrawTerminal(void);
37 |
38 | void guiClear(void);
39 | void guiRender(void);
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/include/menu.h:
--------------------------------------------------------------------------------
1 | #ifndef __MENU_H
2 | #define __MENU_H
3 |
4 | void menuRender(void);
5 | void menuInitMenu(void);
6 | void menuEnd(void);
7 | void menuHandleInput(void);
8 |
9 | #endif
10 |
--------------------------------------------------------------------------------
/include/pad.h:
--------------------------------------------------------------------------------
1 | #ifndef __PAD_H
2 | #define __PAD_H
3 |
4 | #include "libpad.h"
5 |
6 | void pad_init(void);
7 | void buttonStatts(int port, int slot);
8 | void checkPadConnected(void);
9 |
10 | char padBuf[256] __attribute__((aligned(64)));
11 | u32 old_pad;
12 | u32 new_pad;
13 | int port, slot;
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/include/textures.h:
--------------------------------------------------------------------------------
1 | #ifndef __TEXTURES_H
2 | #define __TEXTURES_H
3 |
4 | #include
5 |
6 | enum INTERNAL_TEXTURE {
7 | BACKGROUND = 0,
8 | BACKGROUND2,
9 | LOGO,
10 |
11 | TEXTURES_COUNT
12 | };
13 |
14 | int texPngLoad(GSTEXTURE *texture, int texID);
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/makelog:
--------------------------------------------------------------------------------
1 | ee-gcc -D_EE -O2 -G0 -Wall -D_EE -O2 -G0 -Wall -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/ps2dev/ps2sdk/common/include -I. -I/usr/local/ps2dev/ps2sdk/ports/include -I/usr/local/ps2dev/ps2sdk/sbv/include -I/homebrew/gsKit/ee/gs/include -I/homebrew/gsKit/ee/dma/include -I/homebrew/gsKit/ee/toolkit/include -c VTSPS2-HBDL.c -o VTSPS2-HBDL.o
2 | ee-gcc -D_EE -O2 -G0 -Wall -D_EE -O2 -G0 -Wall -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/ps2dev/ps2sdk/common/include -I. -I/usr/local/ps2dev/ps2sdk/ports/include -I/usr/local/ps2dev/ps2sdk/sbv/include -I/homebrew/gsKit/ee/gs/include -I/homebrew/gsKit/ee/dma/include -I/homebrew/gsKit/ee/toolkit/include -c ps2ipc.c -o ps2ipc.o
3 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/freesio2.irx freesio2.s freesio2
4 | ee-as -G0 -G0 freesio2.s -o freesio2.o
5 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/iomanX.irx iomanX.s iomanX
6 | ee-as -G0 -G0 iomanX.s -o iomanX.o
7 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/freepad.irx freepad.s freepad
8 | ee-as -G0 -G0 freepad.s -o freepad.o
9 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/mcman.irx mcman.s mcman
10 | ee-as -G0 -G0 mcman.s -o mcman.o
11 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/mcserv.irx mcsrv.s mcserv
12 | ee-as -G0 -G0 mcsrv.s -o mcsrv.o
13 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/ps2dev9.irx ps2dev9.s ps2dev9
14 | ee-as -G0 -G0 ps2dev9.s -o ps2dev9.o
15 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/ps2ip-nm.irx ps2ip-nm.s ps2ipnm
16 | ee-as -G0 -G0 ps2ip-nm.s -o ps2ip-nm.o
17 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/ps2ips.irx ps2ips.s ps2ips
18 | ee-as -G0 -G0 ps2ips.s -o ps2ips.o
19 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/netman.irx netman.s netman
20 | ee-as -G0 -G0 netman.s -o netman.o
21 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/smap.irx smap.s smap
22 | ee-as -G0 -G0 smap.s -o smap.o
23 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/ps2http.irx ps2http.s ps2http
24 | ee-as -G0 -G0 ps2http.s -o ps2http.o
25 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/poweroff.irx poweroff.s poweroff
26 | ee-as -G0 -G0 poweroff.s -o poweroff.o
27 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/usbd.irx usbd.s usbd
28 | ee-as -G0 -G0 usbd.s -o usbd.o
29 | bin2s /usr/local/ps2dev/ps2sdk/iop/irx/usbhdfsd.irx usbhdfsd.s usbhdfsd
30 | ee-as -G0 -G0 usbhdfsd.s -o usbhdfsd.o
31 | ee-gcc -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/ps2dev/ps2sdk/common/include -I. -I/usr/local/ps2dev/ps2sdk/ports/include -I/usr/local/ps2dev/ps2sdk/sbv/include -I/homebrew/gsKit/ee/gs/include -I/homebrew/gsKit/ee/dma/include -I/homebrew/gsKit/ee/toolkit/include -c misc.c -o misc.o
32 | ee-gcc -c crc32.c -o crc32.o
33 | ee-gcc -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/ps2dev/ps2sdk/common/include -I. -I/usr/local/ps2dev/ps2sdk/ports/include -I/usr/local/ps2dev/ps2sdk/sbv/include -I/homebrew/gsKit/ee/gs/include -I/homebrew/gsKit/ee/dma/include -I/homebrew/gsKit/ee/toolkit/include -c VTSPS2-CRC32.c -o VTSPS2-CRC32.o
34 | ee-gcc -o VTSPS2-HBDL.elf VTSPS2-HBDL.o ps2ipc.o freesio2.o iomanX.o freepad.o mcman.o mcsrv.o ps2dev9.o ps2ip-nm.o ps2ips.o netman.o smap.o ps2http.o poweroff.o usbd.o usbhdfsd.o misc.o crc32.o VTSPS2-CRC32.o -L/usr/local/ps2dev/ps2sdk/ee/lib -L/usr/local/ps2dev/ps2sdk/sbv/lib -L/usr/local/ps2dev/gsKit/lib -L/usr/local/ps2dev/ps2sdk/ee/lib -lc -ldebug -lpatches -Xlinker --start-group -lpadx -lmtap -lmc -lkernel -lpoweroff -lnetman -lps2ips -lfileXio -lgskit_toolkit -lgskit -ldmakit -Xlinker --end-group
35 |
--------------------------------------------------------------------------------
/menu.c:
--------------------------------------------------------------------------------
1 | #include "VTSPS2-HBDL.h"
2 | #include
3 | #include
4 | #include
5 |
6 | #include "include/gui.h"
7 | #include "include/menu.h"
8 | #include "include/pad.h"
9 |
10 | typedef struct menu_item
11 | {
12 | char *text;
13 | int id;
14 | } menu_item_t;
15 |
16 | typedef struct menu_list
17 | {
18 | struct menu_item item;
19 |
20 | struct menu_list *prev, *next, *current, *pagestart;
21 | } menu_list_t;
22 |
23 | static menu_list_t *menu;
24 |
25 | // CLEAN UP vv
26 | extern char action[32], device[32], path[256], fn[16];
27 |
28 | static char ELF_NO_EXT[128];
29 | static char PATH_ELF[256];
30 | static char PATH_APP[256];
31 | // CLEAN UP ^^
32 |
33 | static menu_list_t *menuAllocItem(char *text, int id)
34 | {
35 | menu_list_t *it = (menu_list_t *)malloc(sizeof(menu_list_t));
36 |
37 | it->prev = NULL;
38 | it->next = NULL;
39 | it->item.text = text;
40 | it->item.id = id;
41 |
42 | return it;
43 | }
44 |
45 | static menu_list_t *menuAddItem(menu_list_t **menu, char *text, int id)
46 | {
47 | if (*menu == NULL) {
48 | *menu = menuAllocItem(text, id);
49 | return *menu;
50 | }
51 |
52 | menu_list_t *cur = *menu;
53 |
54 | // traverse till the end
55 | while (cur->next)
56 | cur = cur->next;
57 |
58 | // create new item
59 | menu_list_t *newitem = menuAllocItem(text, id);
60 |
61 | // link
62 | cur->next = newitem;
63 | newitem->prev = cur;
64 |
65 | return newitem;
66 | }
67 |
68 | static void menuDestroy(menu_list_t **menu)
69 | {
70 | int i;
71 | menu_list_t *cur = *menu;
72 |
73 | for (i = 0; i < NUM_APPS; i++) {
74 | free(downloadableApps[i].size);
75 | free(downloadableApps[i].version);
76 | free(downloadableApps[i].rcrc);
77 | }
78 |
79 | while (cur) {
80 | menu_list_t *td = cur;
81 | cur = cur->next;
82 |
83 | free(td);
84 | }
85 |
86 | *menu = NULL;
87 | }
88 |
89 | void menuInitMenu(void)
90 | {
91 | int i;
92 |
93 | for (i = 0; i < NUM_APPS; i++)
94 | menuAddItem(&menu, downloadableApps[i].longName, i);
95 |
96 | menu->current = menu;
97 | menu->pagestart = menu->current;
98 | }
99 |
100 | void menuEnd(void)
101 | {
102 | if (menu)
103 | menuDestroy(&menu);
104 | }
105 |
106 | void menuRender(void)
107 | {
108 | menu_list_t *ps = menu->pagestart;
109 | u64 color;
110 | int others = 0;
111 | int spacing = 20;
112 | int y = 96;
113 |
114 | while (ps && (others++ < 15))
115 | {
116 | if (ps == menu->current)
117 | color = Blue;
118 | else
119 | color = WhiteFont;
120 |
121 | drawFont(35, y, 0.45f, color, downloadableApps[ps->item.id].longName);
122 | drawFont(315, y, 0.45f, color, downloadableApps[ps->item.id].version);
123 | drawFont(535, y, 0.45f, color, downloadableApps[ps->item.id].size);
124 |
125 | y += spacing;
126 | ps = ps->next;
127 | }
128 | }
129 |
130 | static void menuNavDown(void)
131 | {
132 | menu_list_t *cur = menu->current;
133 |
134 | if (cur && cur->next) {
135 | menu->current = cur->next;
136 |
137 | // if the current item is beyond the page start, move the page start one page down
138 | cur = menu->pagestart;
139 | int itms = 15 + 1;
140 | while (--itms && cur)
141 | if (menu->current == cur)
142 | return;
143 | else
144 | cur = cur->next;
145 |
146 | menu->pagestart = menu->current;
147 | }
148 | }
149 |
150 | static void menuNavUp(void)
151 | {
152 | menu_list_t *cur = menu->current;
153 |
154 | if (cur && cur->prev) {
155 | menu->current = cur->prev;
156 |
157 | // if the current item is on the page start, move the page start one page up
158 | if (menu->pagestart == cur) {
159 | int itms = 15 + 1; // +1 because the selection will move as well
160 | while (--itms && menu->pagestart->prev)
161 | menu->pagestart = menu->pagestart->prev;
162 | }
163 | }
164 | }
165 |
166 | void menuHandleInput(void)
167 | {
168 | //check to see if the pad is still connected
169 | checkPadConnected();
170 | //read pad 0
171 | buttonStatts(0, 0);
172 |
173 | if(new_pad & PAD_SQUARE) {
174 | if (strcmp(action,"CHECK") == 0) {
175 | strcpy(action, "DOWNLOAD");
176 | } else if (strcmp(action,"DOWNLOAD") == 0) {
177 | strcpy(action, "LAUNCH");
178 | } else if (strcmp(action,"LAUNCH") == 0) {
179 | strcpy(action, "CHECK");
180 | }
181 | }
182 |
183 | if (new_pad & PAD_UP)
184 | menuNavUp();
185 |
186 | if (new_pad & PAD_DOWN)
187 | menuNavDown();
188 |
189 | if(new_pad & PAD_CIRCLE) {
190 | int id = menu->current->item.id;
191 | strcpy(fn, downloadableApps[id].elfName);
192 |
193 | if (strcmp(path,"APPS/") == 0) {
194 | substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
195 | sprintf(path,"APP_%s/",ELF_NO_EXT);
196 | strcpy(PATH_APP,path);
197 | } else if (strcmp(path,PATH_APP) == 0) {
198 | substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
199 | sprintf(path,"%s/",ELF_NO_EXT);
200 | strcpy(PATH_ELF,path);
201 | } else if ((strcmp(path,PATH_ELF) == 0) && (strcmp(fn,"BOOT.ELF") != 0)) {
202 | //substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
203 | //sprintf(path,"%s/",ELF_NO_EXT);
204 | strcpy(path,"BOOT/");
205 | } else if (strcmp(path,"BOOT/") == 0) {
206 | strcpy(path,"APPS/");
207 | } else if (strcmp(path,PATH_ELF) == 0) {
208 | substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
209 | strcpy(path,"APPS/");
210 | } else {
211 | strcpy(path,"APPS/");
212 | }
213 | }
214 |
215 | if(new_pad & PAD_TRIANGLE) {
216 | if (strcmp(device,"mc0:/") == 0) {
217 | strcpy(device,"mc1:/");
218 | } else if (strcmp(device,"mc1:/") == 0) {
219 | strcpy(device,"mass:/");
220 | } else {
221 | strcpy(device,"mc0:/");
222 | }
223 | }
224 |
225 | if (new_pad & PAD_R1)
226 | deinit(1);
227 |
228 | if (new_pad & PAD_L1) {
229 | if (http_mirror == 0) {
230 | http_mirror = 1;
231 | } else if (http_mirror == 1) {
232 | http_mirror = 0;
233 | }
234 | }
235 |
236 | if (new_pad & PAD_CROSS) {
237 | int id = menu->current->item.id;
238 | strcpy(fn, downloadableApps[id].elfName);
239 |
240 | if (strcmp(action,"CHECK") == 0) {
241 | DoTask(1, id);
242 | } else if (strcmp(action,"DOWNLOAD") == 0) {
243 | DoTask(2, id);
244 | } else if (strcmp(action,"LAUNCH") == 0) {
245 | DoTask(3, id);
246 | }
247 | }
248 | }
249 |
--------------------------------------------------------------------------------
/misc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "malloc.h"
6 | #include "VTSPS2-HBDL.h"
7 | #include "include/pad.h"
8 |
9 | // Modules
10 | extern unsigned char freesio2[];
11 | extern unsigned int size_freesio2;
12 |
13 | extern unsigned char iomanX[];
14 | extern unsigned int size_iomanX;
15 |
16 | extern unsigned char fileXio[];
17 | extern unsigned int size_fileXio;
18 |
19 | extern unsigned char freepad[];
20 | extern unsigned int size_freepad;
21 |
22 | extern unsigned char poweroff[];
23 | extern unsigned int size_poweroff;
24 |
25 | extern unsigned char mcman[];
26 | extern unsigned int size_mcman;
27 |
28 | extern unsigned char mcserv[];
29 | extern unsigned int size_mcserv;
30 |
31 | extern unsigned char ps2dev9[];
32 | extern unsigned int size_ps2dev9;
33 |
34 | extern unsigned char netman[];
35 | extern unsigned int size_netman;
36 |
37 | extern unsigned char smap[];
38 | extern unsigned int size_smap;
39 |
40 | extern unsigned char ps2ipnm[];
41 | extern unsigned int size_ps2ipnm;
42 |
43 | extern unsigned char ps2ips[];
44 | extern unsigned int size_ps2ips;
45 |
46 | extern unsigned char ps2http[];
47 | extern unsigned int size_ps2http;
48 |
49 | extern unsigned char usbd[];
50 | extern unsigned int size_usbd;
51 |
52 | extern unsigned char usbhdfsd[];
53 | extern unsigned int size_usbhdfsd;
54 |
55 | static void ResetIOP()
56 | {
57 | SifInitRpc(0); //Initialize SIFRPC and SIFCMD. Although seemingly unimportant, this will update the addresses on the EE, which can prevent a crash from happening around the IOP reboot.
58 | while(!SifIopReset("", 0)){}; //Reboot IOP with default modules (empty command line)
59 | while(!SifIopSync()){} //Wait for IOP to finish rebooting.
60 | SifInitRpc(0); //Initialize SIFRPC and SIFCMD.
61 | SifLoadFileInit(); //Initialize LOADFILE RPC.
62 | // SBV Patches Are Not part of a Normal IOP Reset.
63 | sbv_patch_enable_lmb(); //SBV Patches
64 | sbv_patch_disable_prefix_check(); //SBV Patch Load Executable IRX And ELF Files From User-Writable Storage
65 | //sbv_patch_user_mem_clear(0x00100000); // You Can Specify a Starting Address for the Wipe
66 | //sbv_patch_user_mem_clear(0x02000000); // Disable Clear Memory With LoadExecPS2() when 0x02000000 is passed as an arg
67 | }
68 |
69 | static void gotoOSDSYS(void)
70 | {
71 | ResetIOP();
72 | LoadExecPS2("rom0:OSDSYS", 0, NULL);
73 | }
74 |
75 | // might be better off immediatley returning and exiting if certain modules don't load idk but this looks neater.. for now..
76 | int loadModules(void)
77 | {
78 | int ret;
79 |
80 | ret = SifExecModuleBuffer(&freesio2, size_freesio2, 0, NULL, NULL);
81 | if (ret < 0)
82 | printf("Failed to Load freesio2 sw module");
83 |
84 | ret = SifExecModuleBuffer(&iomanX, size_iomanX, 0, NULL, NULL);
85 | if (ret < 0)
86 | printf("Failed to Load iomanx sw module");
87 |
88 | ret = SifExecModuleBuffer(&freepad, size_freepad, 0, NULL, NULL);
89 | if (ret < 0)
90 | printf("Failed to Load freepad sw module");
91 |
92 | ret = SifExecModuleBuffer(&mcman, size_mcman, 0, NULL, NULL);
93 | if (ret < 0)
94 | printf("Failed to Load mcman sw module");
95 |
96 | ret = SifExecModuleBuffer(&mcserv, size_mcserv, 0, NULL, NULL);
97 | if (ret < 0)
98 | printf("Failed to Load mcserv sw module");
99 |
100 | ret = SifExecModuleBuffer(&ps2dev9, size_ps2dev9, 0, NULL, NULL);
101 | if (ret < 0)
102 | printf(" Could not load ps2dev9.IRX! %d\n", ret);
103 |
104 | ret = SifExecModuleBuffer(&netman, size_netman, 0, NULL, NULL);
105 | if (ret < 0)
106 | printf(" Could not load netman.IRX! %d\n", ret);
107 |
108 | ret = SifExecModuleBuffer(&smap, size_smap, 0, NULL, NULL);
109 | if (ret < 0)
110 | printf(" Could not load smap.IRX! %d\n", ret);
111 |
112 | ret = SifExecModuleBuffer(&ps2ipnm, size_ps2ipnm, 0, NULL, NULL);
113 | if (ret < 0)
114 | printf(" Could not load ps2ip.IRX! %d\n", ret);
115 |
116 | ret = SifExecModuleBuffer(&ps2ips, size_ps2ips, 0, NULL, NULL);
117 | if (ret < 0)
118 | printf(" Could not load ps2ips.IRX! %d\n", ret);
119 |
120 | ps2ip_init(); //interesting place to put it..
121 |
122 | ret = SifExecModuleBuffer(&ps2http, size_ps2http, 0, NULL, NULL);
123 | if (ret < 0)
124 | printf(" Could not load ps2http.IRX! %d\n", ret);
125 |
126 | ret = SifExecModuleBuffer(&usbd, size_usbd, 0, NULL, NULL);
127 | if (ret < 0)
128 | printf(" Could not load usbd.IRX! %d\n", ret);
129 |
130 | ret = SifExecModuleBuffer(&usbhdfsd, size_usbhdfsd, 0, NULL, NULL);
131 | if (ret < 0)
132 | printf(" Could not load usbhdfsd.IRX! %d\n", ret);
133 |
134 | return ret;
135 | }
136 |
137 | void init(void)
138 | {
139 | int ret;
140 |
141 | ResetIOP();
142 |
143 | ret = loadModules();
144 | if (ret < 0)
145 | gotoOSDSYS();
146 |
147 | pad_init();
148 | }
149 |
150 | void deinit(int browser)
151 | {
152 | menuEnd();
153 | guiEnd();
154 |
155 | if (browser)
156 | gotoOSDSYS();
157 | }
158 |
159 | // This function is public domain -- Will Hartung 4/9/09 */
160 | // Modifications, public domain as well, by Antti Haapala, 11/10/17
161 | // - Switched to getc on 5/23/19 */
162 |
163 | // if typedef doesn't exist (msvc, blah)
164 | //typedef intptr_t ssize_t;
165 | ssize_t getline(char **lineptr, size_t *n, FILE *stream)
166 | {
167 | size_t pos;
168 | int c;
169 |
170 | if (lineptr == NULL || stream == NULL || n == NULL) {
171 | errno = EINVAL;
172 | return -1;
173 | }
174 |
175 | c = getc(stream);
176 | if (c == EOF) {
177 | return -1;
178 | }
179 |
180 | if (*lineptr == NULL) {
181 | *lineptr = malloc(128);
182 | if (*lineptr == NULL) {
183 | return -1;
184 | }
185 | *n = 128;
186 | }
187 |
188 | pos = 0;
189 | while(c != EOF) {
190 | if (pos + 1 >= *n) {
191 | size_t new_size = *n + (*n >> 2);
192 | if (new_size < 128) {
193 | new_size = 128;
194 | }
195 | char *new_ptr = realloc(*lineptr, new_size);
196 | if (new_ptr == NULL) {
197 | return -1;
198 | }
199 | *n = new_size;
200 | *lineptr = new_ptr;
201 | }
202 |
203 | ((unsigned char *)(*lineptr))[pos ++] = c;
204 | if (c == '\n') {
205 | break;
206 | }
207 | c = getc(stream);
208 | }
209 |
210 | (*lineptr)[pos] = '\0';
211 | return pos;
212 | }
213 |
--------------------------------------------------------------------------------
/pad.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "libpad.h"
6 | #include "include/pad.h"
7 |
8 | /////////////////////////////////////////////////////////////////////
9 | //waitPadReady
10 | /////////////////////////////////////////////////////////////////////
11 | static int waitPadReady(int port, int slot)
12 | {
13 | int state;
14 | int lastState;
15 | char stateString[16];
16 |
17 | state = padGetState(port, slot);
18 | lastState = -1;
19 | while ((state != PAD_STATE_STABLE) && (state != PAD_STATE_FINDCTP1)) {
20 | if (state != lastState) {
21 | padStateInt2String(state, stateString);
22 | }
23 | lastState = state;
24 | state = padGetState(port, slot);
25 | }
26 | // Were the pad ever 'out of sync'?
27 | if (lastState != -1) {
28 |
29 | }
30 | return 0;
31 | }
32 |
33 | /////////////////////////////////////////////////////////////////////
34 | //initalizePad
35 | /////////////////////////////////////////////////////////////////////
36 | static int initializePad(int port, int slot)
37 | {
38 |
39 | int actuators, modes, ret, i;
40 | char actAlign[6];
41 |
42 | waitPadReady(port, slot);
43 | modes = padInfoMode(port, slot, PAD_MODETABLE, -1);
44 | if (modes > 0) {
45 | for (i = 0; i < modes; i++) {
46 | }
47 |
48 | }
49 | if (modes == 0) {
50 | return 1;
51 | }
52 |
53 | i = 0;
54 | do {
55 | if (padInfoMode(port, slot, PAD_MODETABLE, i) == PAD_TYPE_DUALSHOCK)
56 | break;
57 | i++;
58 | } while (i < modes);
59 | if (i >= modes) {
60 | return 1;
61 | }
62 |
63 | ret = padInfoMode(port, slot, PAD_MODECUREXID, 0);
64 | if (ret == 0) {
65 | return 1;
66 | }
67 | padSetMainMode(port, slot, PAD_MMODE_DUALSHOCK, PAD_MMODE_LOCK);
68 |
69 | waitPadReady(port, slot);
70 | padInfoPressMode(port, slot);
71 |
72 | waitPadReady(port, slot);
73 | padEnterPressMode(port, slot);
74 |
75 | waitPadReady(port, slot);
76 | actuators = padInfoAct(port, slot, -1, 0);
77 |
78 | if (actuators != 0) {
79 | actAlign[0] = 0;
80 | actAlign[1] = 1;
81 | actAlign[2] = 0xff;
82 | actAlign[3] = 0xff;
83 | actAlign[4] = 0xff;
84 | actAlign[5] = 0xff;
85 |
86 | waitPadReady(port, slot);
87 |
88 | padSetActAlign(port, slot, actAlign);
89 | }
90 | else {
91 | }
92 | return 1;
93 | }
94 |
95 | /////////////////////////////////////////////////////////////////////
96 | //buttonStatts
97 | /////////////////////////////////////////////////////////////////////
98 | void buttonStatts(int port, int slot)
99 | {
100 | int ret;
101 | u32 paddata;
102 | struct padButtonStatus buttons;
103 |
104 | ret = padRead(port, slot, &buttons);
105 |
106 | if (ret != 0) {
107 | paddata = 0xffff ^ buttons.btns;
108 |
109 | new_pad = paddata & ~old_pad;
110 | old_pad = paddata;
111 | }
112 | }
113 |
114 | /////////////////////////////////////////////////////////////////////
115 | //checkPadConnected
116 | /////////////////////////////////////////////////////////////////////
117 | void checkPadConnected(void)
118 | {
119 | int ret, i;
120 | ret = padGetState(0, 0);
121 | while ((ret != PAD_STATE_STABLE) && (ret != PAD_STATE_FINDCTP1)) {
122 | if (ret == PAD_STATE_DISCONN) {
123 | #if defined DEBUG
124 | scr_printf("Controller(%d, %d) is disconnected\n", 0, 0);
125 | #endif
126 | }
127 | ret = padGetState(0, 0);
128 | }
129 | if (i == 1) {
130 | }
131 | }
132 |
133 | /////////////////////////////////////////////////////////////////////
134 | //pad_wat_button - unused?
135 | /////////////////////////////////////////////////////////////////////
136 | /*static void pad_wait_button(u32 button)
137 | {
138 | while (1)
139 | {
140 | buttonStatts(0, 0);
141 | if (new_pad & button) return;
142 | }
143 | }*/
144 |
145 | void pad_init(void)
146 | {
147 | int ret;
148 |
149 | padInit(0);
150 |
151 | port = 0; // 0 -> Connector 1, 1 -> Connector 2
152 | slot = 0; // Always zero if not using multitap
153 |
154 | printf("PortMax: %d\n", padGetPortMax());
155 | printf("SlotMax: %d\n", padGetSlotMax(port));
156 |
157 |
158 | if((ret = padPortOpen(port, slot, padBuf)) == 0) {
159 | printf("padOpenPort failed: %d\n", ret);
160 | SleepThread();
161 | }
162 |
163 | if(!initializePad(port, slot)) {
164 | printf("pad initalization failed!\n");
165 | SleepThread();
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/ps2ipc.c:
--------------------------------------------------------------------------------
1 | /*
2 | # _____ ___ ____ ___ ____
3 | # ____| | ____| | | |____|
4 | # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 | #-----------------------------------------------------------------------
6 | # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 | # Licenced under Academic Free License version 2.0
8 | # Review ps2sdk README & LICENSE files for further details.
9 | #
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | static int ethApplyNetIFConfig(int mode)
18 | {
19 | int result;
20 | //By default, auto-negotiation is used.
21 | static int CurrentMode = NETMAN_NETIF_ETH_LINK_MODE_AUTO;
22 |
23 | if(CurrentMode != mode)
24 | { //Change the setting, only if different.
25 | if((result = NetManSetLinkMode(mode)) == 0)
26 | CurrentMode = mode;
27 | }else
28 | result = 0;
29 |
30 | return result;
31 | }
32 |
33 | static void EthStatusCheckCb(s32 alarm_id, u16 time, void *common)
34 | {
35 | iWakeupThread(*(int*)common);
36 | }
37 |
38 | static int WaitValidNetState(int (*checkingFunction)(void))
39 | {
40 | int ThreadID, retry_cycles;
41 |
42 | // Wait for a valid network status;
43 | ThreadID = GetThreadId();
44 | for(retry_cycles = 0; checkingFunction() == 0; retry_cycles++)
45 | { //Sleep for 1000ms.
46 | SetAlarm(1000 * 16, &EthStatusCheckCb, &ThreadID);
47 | SleepThread();
48 |
49 | if(retry_cycles >= 10) //10s = 10*1000ms
50 | return -1;
51 | }
52 |
53 | return 0;
54 | }
55 |
56 | static int ethGetNetIFLinkStatus(void)
57 | {
58 | return(NetManIoctl(NETMAN_NETIF_IOCTL_GET_LINK_STATUS, NULL, 0, NULL, 0) == NETMAN_NETIF_ETH_LINK_STATE_UP);
59 | }
60 |
61 | static int ethWaitValidNetIFLinkState(void)
62 | {
63 | return WaitValidNetState(ðGetNetIFLinkStatus);
64 | }
65 |
66 | static int ethGetDHCPStatus(void)
67 | {
68 | t_ip_info ip_info;
69 | int result;
70 |
71 | if ((result = ps2ip_getconfig("sm0", &ip_info)) >= 0)
72 | { //Check for a successful state if DHCP is enabled.
73 | if (ip_info.dhcp_enabled)
74 | result = (ip_info.dhcp_status == DHCP_STATE_BOUND || (ip_info.dhcp_status == DHCP_STATE_OFF));
75 | else
76 | result = -1;
77 | }
78 |
79 | return result;
80 | }
81 |
82 | static int ethWaitValidDHCPState(void)
83 | {
84 | return WaitValidNetState(ðGetDHCPStatus);
85 | }
86 |
87 | static int ethApplyIPConfig(int use_dhcp, const struct ip4_addr *ip, const struct ip4_addr *netmask, const struct ip4_addr *gateway, const struct ip4_addr *dns)
88 | {
89 | t_ip_info ip_info;
90 | const ip_addr_t *dns_curr;
91 | int result;
92 |
93 | //SMAP is registered as the "sm0" device to the TCP/IP stack.
94 | if ((result = ps2ip_getconfig("sm0", &ip_info)) >= 0)
95 | {
96 | //Obtain the current DNS server settings.
97 | dns_curr = dns_getserver(0);
98 |
99 | //Check if it's the same. Otherwise, apply the new configuration.
100 | if ((use_dhcp != ip_info.dhcp_enabled)
101 | || (!use_dhcp &&
102 | (!ip_addr_cmp(ip, (struct ip4_addr *)&ip_info.ipaddr) ||
103 | !ip_addr_cmp(netmask, (struct ip4_addr *)&ip_info.netmask) ||
104 | !ip_addr_cmp(gateway, (struct ip4_addr *)&ip_info.gw) ||
105 | !ip_addr_cmp(dns, dns_curr))))
106 | {
107 | if (use_dhcp)
108 | {
109 | ip_info.dhcp_enabled = 1;
110 | }
111 | else
112 | { //Copy over new settings if DHCP is not used.
113 | ip_addr_set((struct ip4_addr *)&ip_info.ipaddr, ip);
114 | ip_addr_set((struct ip4_addr *)&ip_info.netmask, netmask);
115 | ip_addr_set((struct ip4_addr *)&ip_info.gw, gateway);
116 |
117 | ip_info.dhcp_enabled = 0;
118 | }
119 |
120 | //Update settings.
121 | //dns_setserver(0, dns);
122 | result = ps2ip_setconfig(&ip_info);
123 | if (!use_dhcp)
124 | dns_setserver(0, (struct ip4_addr *)dns);
125 | }
126 | else
127 | result = 0;
128 | }
129 |
130 | return result;
131 | }
132 |
133 | static char ipAddress[16];
134 |
135 | char *getIpAddress(void)
136 | {
137 | return ipAddress;
138 | }
139 |
140 | static void ethPrintIPConfig(void)
141 | {
142 | t_ip_info ip_info;
143 | const ip_addr_t *dns_curr;
144 | u8 ip_address[4], netmask[4], gateway[4], dns[4];
145 | //SMAP is registered as the "sm0" device to the TCP/IP stack.
146 | if (ps2ip_getconfig("sm0", &ip_info) >= 0)
147 | {
148 | //Obtain the current DNS server settings.
149 | dns_curr = dns_getserver(0);
150 |
151 | ip_address[0] = ip4_addr1((struct ip4_addr *)&ip_info.ipaddr);
152 | ip_address[1] = ip4_addr2((struct ip4_addr *)&ip_info.ipaddr);
153 | ip_address[2] = ip4_addr3((struct ip4_addr *)&ip_info.ipaddr);
154 | ip_address[3] = ip4_addr4((struct ip4_addr *)&ip_info.ipaddr);
155 |
156 | netmask[0] = ip4_addr1((struct ip4_addr *)&ip_info.netmask);
157 | netmask[1] = ip4_addr2((struct ip4_addr *)&ip_info.netmask);
158 | netmask[2] = ip4_addr3((struct ip4_addr *)&ip_info.netmask);
159 | netmask[3] = ip4_addr4((struct ip4_addr *)&ip_info.netmask);
160 |
161 | gateway[0] = ip4_addr1((struct ip4_addr *)&ip_info.gw);
162 | gateway[1] = ip4_addr2((struct ip4_addr *)&ip_info.gw);
163 | gateway[2] = ip4_addr3((struct ip4_addr *)&ip_info.gw);
164 | gateway[3] = ip4_addr4((struct ip4_addr *)&ip_info.gw);
165 |
166 | dns[0] = ip4_addr1(dns_curr);
167 | dns[1] = ip4_addr2(dns_curr);
168 | dns[2] = ip4_addr3(dns_curr);
169 | dns[3] = ip4_addr4(dns_curr);
170 |
171 | printf( "IP:\t%d.%d.%d.%d\n"
172 | "NM:\t%d.%d.%d.%d\n"
173 | "GW:\t%d.%d.%d.%d\n"
174 | "DNS:\t%d.%d.%d.%d\n",
175 | ip_address[0], ip_address[1], ip_address[2], ip_address[3],
176 | netmask[0], netmask[1], netmask[2], netmask[3],
177 | gateway[0], gateway[1], gateway[2], gateway[3],
178 | dns[0], dns[1], dns[2], dns[3]);
179 | sprintf(ipAddress,"%d.%d.%d.%d",ip_address[0], ip_address[1], ip_address[2], ip_address[3]);
180 | }
181 | else
182 | {
183 | printf("Unable to read IP address.\n");
184 | }
185 | }
186 |
187 | static void ethPrintLinkStatus(void)
188 | {
189 | int mode;
190 |
191 | //SMAP is registered as the "sm0" device to the TCP/IP stack.
192 | printf("Link:\t");
193 | if (NetManIoctl(NETMAN_NETIF_IOCTL_GET_LINK_STATUS, NULL, 0, NULL, 0) == NETMAN_NETIF_ETH_LINK_STATE_UP)
194 | printf("Up\n");
195 | else
196 | printf("Down\n");
197 |
198 | printf("Mode:\t");
199 | mode = NetManIoctl(NETMAN_NETIF_IOCTL_ETH_GET_LINK_MODE, NULL, 0, NULL, 0);
200 |
201 | //NETMAN_NETIF_ETH_LINK_DISABLE_PAUSE is a flag, so file it off first.
202 | switch((mode & ~NETMAN_NETIF_ETH_LINK_DISABLE_PAUSE))
203 | {
204 | case NETMAN_NETIF_ETH_LINK_MODE_10M_HDX:
205 | printf("10M HDX");
206 | break;
207 | case NETMAN_NETIF_ETH_LINK_MODE_10M_FDX:
208 | printf("10M FDX");
209 | break;
210 | case NETMAN_NETIF_ETH_LINK_MODE_100M_HDX:
211 | printf("100M HDX");
212 | break;
213 | case NETMAN_NETIF_ETH_LINK_MODE_100M_FDX:
214 | printf("100M FDX");
215 | break;
216 | default:
217 | printf("Unknown");
218 | }
219 | if(mode & NETMAN_NETIF_ETH_LINK_DISABLE_PAUSE)
220 | printf(" with ");
221 | else
222 | printf(" without ");
223 | printf("Flow Control\n");
224 | }
225 |
226 | int dhcpmain(int argc, char *argv[])
227 | {
228 | struct ip4_addr IP, NM, GW, DNS;
229 | int EthernetLinkMode;
230 |
231 | //Initialize NETMAN
232 | NetManInit();
233 |
234 | //The network interface link mode/duplex can be set.
235 | EthernetLinkMode = NETMAN_NETIF_ETH_LINK_MODE_AUTO;
236 |
237 | do{
238 | //Wait for the link to become ready before changing the setting.
239 | if(ethWaitValidNetIFLinkState() != 0) {
240 | printf("Error: failed to get valid link status.\n");
241 | goto end;
242 | }
243 |
244 | //Attempt to apply the new link setting.
245 | } while(ethApplyNetIFConfig(EthernetLinkMode) != 0);
246 |
247 | //Initialize IP address.
248 | //In this example, DHCP is enabled, hence the IP, NM, GW and DNS fields are cleared to 0..
249 | ip4_addr_set_zero(&IP);
250 | ip4_addr_set_zero(&NM);
251 | ip4_addr_set_zero(&GW);
252 | ip4_addr_set_zero(&DNS);
253 |
254 | //Initialize the TCP/IP protocol stack.
255 | //ps2ipInit(&IP, &NM, &GW);
256 |
257 | //Before enabling DHCP, wait for a valid link status.
258 | if(ethWaitValidNetIFLinkState() != 0)
259 | {
260 | printf("Failed to get valid link status.\n");
261 | goto end;
262 | }
263 |
264 | //Enable DHCP
265 | ethApplyIPConfig(1, &IP, &NM, &GW, &DNS);
266 |
267 | printf("Waiting for DHCP lease...");
268 | //Wait for DHCP to initialize, if DHCP is enabled.
269 | if (ethWaitValidDHCPState() != 0)
270 | {
271 | printf("DHCP failed\n.");
272 | goto end;
273 | }
274 | // Uncomment the lines below to Force Cloudflare DNS
275 | // IP4_ADDR(&DNS, 1, 1, 1, 1);
276 | // dns_setserver(0, &DNS);
277 | printf("done!\n");
278 |
279 | printf("Initialized:\n");
280 | ethPrintLinkStatus();
281 | ethPrintIPConfig();
282 | //sleep(5);
283 | //At this point, network support has been initialized and the PS2 can be pinged.
284 | //SleepThread();
285 |
286 | end:
287 | //To cleanup, just call these functions.
288 | // printf("Failed to Obtain IP Address");
289 | //ps2ipDeinit();
290 | // NetManDeinit();
291 |
292 |
293 | return 0;
294 | }
295 |
--------------------------------------------------------------------------------
/strings.h:
--------------------------------------------------------------------------------
1 | //Strings
2 | char *appName = "VTSPS2-HBDL HomeBrew DownLoader";
3 | char *appVer = " v0.35 2022-06-17 (Commit: ???????)\n";
4 | char *appAuthor = "Forked from iLaunchElf by VTSTech github.com/Veritas83/VTSPS2-HBDL\nOriginal iLaunchElf By: krHACKen, Based_Skid, Copyright \xa9 2018 \n \n";
5 | char *appNotice = "Notice: This App Contains Code from uLaunchELF \n";
6 | //char *osdmsg = "Exiting to OSDSYS\n";
7 | //char *appFail = "Application Failure!\n";
8 | //char *modloadfail = "Failed to load module: ";
9 |
10 | // Menu Option Text
11 | //char *txtcrossBtn = "-Press X to Check WLE.ELF\n";
12 | //char *txtsqrBtn = "-Press Square to Check HDL.ELF\n";
13 | //char *txtcirBtn = "-Press Circle to Check OPL.ELF\n";
14 | //char *txttriBtn = "-Press Triangle to Check ESR.ELF\n";
15 | //char *txtR1Btn = "-Press R1 to Update WLE.ELF\n";
16 | //char *txtL1Btn = "-Press L1 to Update HDL.ELF\n";
17 | //char *txtR2Btn = "-Press R2 to Update OPL.ELF\n";
18 | //char *txtL2Btn = "-Press L2 to Update ESR.ELF\n";
19 | //char *txtselBtn = "-Press Select to unused...\n";
20 | //char *txtstrtBtn = "-Press Start to Reboot PS2.\n";
21 | //char *txtL3Btn = "-Press L3 to Start WLE.ELF.\n";
22 |
23 | char *devices[] = {"mc0:/", "mc1:/", "mass:/"};
24 | char *paths[] = {"APPS/", "APP_$ELF/", "$ELF/", "BOOT/"};
25 | char *actions[] = {"CHECK", "DOWNLOAD", "LAUNCH"};
26 | char *targets[]= {"AURA.ELF", "DOSBOX.ELF", "EJECT.ELF", "ESR.ELF", "FRUITY.ELF", "GSM.ELF", "HDL.ELF", "HERMES.ELF", "INFOGB.ELF", "LBFN.ELF", "NEOCD.ELF", "OPL.ELF", "PGEN.ELF", "PS2DOOM.ELF", "PS2ESDL.ELF", "PS2SX.ELF", "PSMS.ELF", "PVCS.ELF", "RA_2048.ELF", "RA_FCEU.ELF", "RA_MGBA.ELF", "RA_PICO.ELF", "RA_QNES.ELF", "SMS.ELF", "SNES9X.ELF", "SNESSTN.ELF", "TESTMODE.ELF", "WLE.ELF", "XUMP.ELF", "ZONELDR.ELF"};
27 | //char ELF_NO_EXT[] = "";
28 | //char PATH_ELF[] = "";
29 | //char PATH_APP[] = "";
30 | char make_path[] = "";
31 | char action[32], device[32], path[256], fn[16], ofn[16];
32 | char url[] = "";
33 | char mirror0[] = "http://hbdl.vts-tech.org/";
34 | char mirror1[] = "http://www.hwc.nat.cu/ps2-vault/ps2hbdl/";
35 |
--------------------------------------------------------------------------------
/tab/gentab32.inc:
--------------------------------------------------------------------------------
1 | /*
2 | * Library: libcrc
3 | * File: tab/gentab32.inc
4 | * Author: Auto generated by the precalc program
5 | *
6 | * PLEASE DO NOT CHANGE THIS FILE!
7 | * ===============================
8 | * This file was automatically generated and will be overwritten whenever the
9 | * library is recompiled. All manually added changes will be lost in that case.
10 | */
11 |
12 | const uint32_t crc_tab32[256] = {
13 | 0x00000000ul,
14 | 0x77073096ul,
15 | 0xEE0E612Cul,
16 | 0x990951BAul,
17 | 0x076DC419ul,
18 | 0x706AF48Ful,
19 | 0xE963A535ul,
20 | 0x9E6495A3ul,
21 | 0x0EDB8832ul,
22 | 0x79DCB8A4ul,
23 | 0xE0D5E91Eul,
24 | 0x97D2D988ul,
25 | 0x09B64C2Bul,
26 | 0x7EB17CBDul,
27 | 0xE7B82D07ul,
28 | 0x90BF1D91ul,
29 | 0x1DB71064ul,
30 | 0x6AB020F2ul,
31 | 0xF3B97148ul,
32 | 0x84BE41DEul,
33 | 0x1ADAD47Dul,
34 | 0x6DDDE4EBul,
35 | 0xF4D4B551ul,
36 | 0x83D385C7ul,
37 | 0x136C9856ul,
38 | 0x646BA8C0ul,
39 | 0xFD62F97Aul,
40 | 0x8A65C9ECul,
41 | 0x14015C4Ful,
42 | 0x63066CD9ul,
43 | 0xFA0F3D63ul,
44 | 0x8D080DF5ul,
45 | 0x3B6E20C8ul,
46 | 0x4C69105Eul,
47 | 0xD56041E4ul,
48 | 0xA2677172ul,
49 | 0x3C03E4D1ul,
50 | 0x4B04D447ul,
51 | 0xD20D85FDul,
52 | 0xA50AB56Bul,
53 | 0x35B5A8FAul,
54 | 0x42B2986Cul,
55 | 0xDBBBC9D6ul,
56 | 0xACBCF940ul,
57 | 0x32D86CE3ul,
58 | 0x45DF5C75ul,
59 | 0xDCD60DCFul,
60 | 0xABD13D59ul,
61 | 0x26D930ACul,
62 | 0x51DE003Aul,
63 | 0xC8D75180ul,
64 | 0xBFD06116ul,
65 | 0x21B4F4B5ul,
66 | 0x56B3C423ul,
67 | 0xCFBA9599ul,
68 | 0xB8BDA50Ful,
69 | 0x2802B89Eul,
70 | 0x5F058808ul,
71 | 0xC60CD9B2ul,
72 | 0xB10BE924ul,
73 | 0x2F6F7C87ul,
74 | 0x58684C11ul,
75 | 0xC1611DABul,
76 | 0xB6662D3Dul,
77 | 0x76DC4190ul,
78 | 0x01DB7106ul,
79 | 0x98D220BCul,
80 | 0xEFD5102Aul,
81 | 0x71B18589ul,
82 | 0x06B6B51Ful,
83 | 0x9FBFE4A5ul,
84 | 0xE8B8D433ul,
85 | 0x7807C9A2ul,
86 | 0x0F00F934ul,
87 | 0x9609A88Eul,
88 | 0xE10E9818ul,
89 | 0x7F6A0DBBul,
90 | 0x086D3D2Dul,
91 | 0x91646C97ul,
92 | 0xE6635C01ul,
93 | 0x6B6B51F4ul,
94 | 0x1C6C6162ul,
95 | 0x856530D8ul,
96 | 0xF262004Eul,
97 | 0x6C0695EDul,
98 | 0x1B01A57Bul,
99 | 0x8208F4C1ul,
100 | 0xF50FC457ul,
101 | 0x65B0D9C6ul,
102 | 0x12B7E950ul,
103 | 0x8BBEB8EAul,
104 | 0xFCB9887Cul,
105 | 0x62DD1DDFul,
106 | 0x15DA2D49ul,
107 | 0x8CD37CF3ul,
108 | 0xFBD44C65ul,
109 | 0x4DB26158ul,
110 | 0x3AB551CEul,
111 | 0xA3BC0074ul,
112 | 0xD4BB30E2ul,
113 | 0x4ADFA541ul,
114 | 0x3DD895D7ul,
115 | 0xA4D1C46Dul,
116 | 0xD3D6F4FBul,
117 | 0x4369E96Aul,
118 | 0x346ED9FCul,
119 | 0xAD678846ul,
120 | 0xDA60B8D0ul,
121 | 0x44042D73ul,
122 | 0x33031DE5ul,
123 | 0xAA0A4C5Ful,
124 | 0xDD0D7CC9ul,
125 | 0x5005713Cul,
126 | 0x270241AAul,
127 | 0xBE0B1010ul,
128 | 0xC90C2086ul,
129 | 0x5768B525ul,
130 | 0x206F85B3ul,
131 | 0xB966D409ul,
132 | 0xCE61E49Ful,
133 | 0x5EDEF90Eul,
134 | 0x29D9C998ul,
135 | 0xB0D09822ul,
136 | 0xC7D7A8B4ul,
137 | 0x59B33D17ul,
138 | 0x2EB40D81ul,
139 | 0xB7BD5C3Bul,
140 | 0xC0BA6CADul,
141 | 0xEDB88320ul,
142 | 0x9ABFB3B6ul,
143 | 0x03B6E20Cul,
144 | 0x74B1D29Aul,
145 | 0xEAD54739ul,
146 | 0x9DD277AFul,
147 | 0x04DB2615ul,
148 | 0x73DC1683ul,
149 | 0xE3630B12ul,
150 | 0x94643B84ul,
151 | 0x0D6D6A3Eul,
152 | 0x7A6A5AA8ul,
153 | 0xE40ECF0Bul,
154 | 0x9309FF9Dul,
155 | 0x0A00AE27ul,
156 | 0x7D079EB1ul,
157 | 0xF00F9344ul,
158 | 0x8708A3D2ul,
159 | 0x1E01F268ul,
160 | 0x6906C2FEul,
161 | 0xF762575Dul,
162 | 0x806567CBul,
163 | 0x196C3671ul,
164 | 0x6E6B06E7ul,
165 | 0xFED41B76ul,
166 | 0x89D32BE0ul,
167 | 0x10DA7A5Aul,
168 | 0x67DD4ACCul,
169 | 0xF9B9DF6Ful,
170 | 0x8EBEEFF9ul,
171 | 0x17B7BE43ul,
172 | 0x60B08ED5ul,
173 | 0xD6D6A3E8ul,
174 | 0xA1D1937Eul,
175 | 0x38D8C2C4ul,
176 | 0x4FDFF252ul,
177 | 0xD1BB67F1ul,
178 | 0xA6BC5767ul,
179 | 0x3FB506DDul,
180 | 0x48B2364Bul,
181 | 0xD80D2BDAul,
182 | 0xAF0A1B4Cul,
183 | 0x36034AF6ul,
184 | 0x41047A60ul,
185 | 0xDF60EFC3ul,
186 | 0xA867DF55ul,
187 | 0x316E8EEFul,
188 | 0x4669BE79ul,
189 | 0xCB61B38Cul,
190 | 0xBC66831Aul,
191 | 0x256FD2A0ul,
192 | 0x5268E236ul,
193 | 0xCC0C7795ul,
194 | 0xBB0B4703ul,
195 | 0x220216B9ul,
196 | 0x5505262Ful,
197 | 0xC5BA3BBEul,
198 | 0xB2BD0B28ul,
199 | 0x2BB45A92ul,
200 | 0x5CB36A04ul,
201 | 0xC2D7FFA7ul,
202 | 0xB5D0CF31ul,
203 | 0x2CD99E8Bul,
204 | 0x5BDEAE1Dul,
205 | 0x9B64C2B0ul,
206 | 0xEC63F226ul,
207 | 0x756AA39Cul,
208 | 0x026D930Aul,
209 | 0x9C0906A9ul,
210 | 0xEB0E363Ful,
211 | 0x72076785ul,
212 | 0x05005713ul,
213 | 0x95BF4A82ul,
214 | 0xE2B87A14ul,
215 | 0x7BB12BAEul,
216 | 0x0CB61B38ul,
217 | 0x92D28E9Bul,
218 | 0xE5D5BE0Dul,
219 | 0x7CDCEFB7ul,
220 | 0x0BDBDF21ul,
221 | 0x86D3D2D4ul,
222 | 0xF1D4E242ul,
223 | 0x68DDB3F8ul,
224 | 0x1FDA836Eul,
225 | 0x81BE16CDul,
226 | 0xF6B9265Bul,
227 | 0x6FB077E1ul,
228 | 0x18B74777ul,
229 | 0x88085AE6ul,
230 | 0xFF0F6A70ul,
231 | 0x66063BCAul,
232 | 0x11010B5Cul,
233 | 0x8F659EFFul,
234 | 0xF862AE69ul,
235 | 0x616BFFD3ul,
236 | 0x166CCF45ul,
237 | 0xA00AE278ul,
238 | 0xD70DD2EEul,
239 | 0x4E048354ul,
240 | 0x3903B3C2ul,
241 | 0xA7672661ul,
242 | 0xD06016F7ul,
243 | 0x4969474Dul,
244 | 0x3E6E77DBul,
245 | 0xAED16A4Aul,
246 | 0xD9D65ADCul,
247 | 0x40DF0B66ul,
248 | 0x37D83BF0ul,
249 | 0xA9BCAE53ul,
250 | 0xDEBB9EC5ul,
251 | 0x47B2CF7Ful,
252 | 0x30B5FFE9ul,
253 | 0xBDBDF21Cul,
254 | 0xCABAC28Aul,
255 | 0x53B39330ul,
256 | 0x24B4A3A6ul,
257 | 0xBAD03605ul,
258 | 0xCDD70693ul,
259 | 0x54DE5729ul,
260 | 0x23D967BFul,
261 | 0xB3667A2Eul,
262 | 0xC4614AB8ul,
263 | 0x5D681B02ul,
264 | 0x2A6F2B94ul,
265 | 0xB40BBE37ul,
266 | 0xC30C8EA1ul,
267 | 0x5A05DF1Bul,
268 | 0x2D02EF8Dul
269 | };
270 |
271 |
--------------------------------------------------------------------------------
/textures.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "include/textures.h"
5 |
6 | extern void *background_png;
7 | extern void *background2_png;
8 | extern void *logo_png;
9 |
10 | typedef struct
11 | {
12 | int id;
13 | void **texture;
14 | } texture_t;
15 |
16 | static texture_t internalTexture[TEXTURES_COUNT] = {
17 | {BACKGROUND, &background_png},
18 | {BACKGROUND2, &background2_png},
19 | {LOGO, &logo_png}
20 | };
21 |
22 | static int texSizeValidate(int width, int height, short psm)
23 | {
24 | if (width > 1024 || height > 1024)
25 | return -1;
26 |
27 | if (gsKit_texture_size(width, height, psm) > 720*512*4)
28 | return -1;
29 |
30 | return 0;
31 | }
32 |
33 | typedef struct
34 | {
35 | u8 red;
36 | u8 green;
37 | u8 blue;
38 | u8 alpha;
39 | } png_clut_t;
40 |
41 | typedef struct
42 | {
43 | png_colorp palette;
44 | int numPalette;
45 | int numTrans;
46 | png_bytep trans;
47 | png_clut_t *clut;
48 | } png_texture_t;
49 |
50 | static png_texture_t pngTexture;
51 |
52 | static int texPngEnd(png_structp pngPtr, png_infop infoPtr, int status)
53 | {
54 | if (infoPtr != NULL)
55 | png_destroy_read_struct(&pngPtr, &infoPtr, (png_infopp)NULL);
56 |
57 | return status;
58 | }
59 |
60 | static void texPngReadMemFunction(png_structp pngPtr, png_bytep data, png_size_t length)
61 | {
62 | void **PngBufferPtr = png_get_io_ptr(pngPtr);
63 |
64 | memcpy(data, *PngBufferPtr, length);
65 | *PngBufferPtr = (u8 *)(*PngBufferPtr) + length;
66 | }
67 |
68 | static void texPngReadPixels4(GSTEXTURE *texture, png_bytep *rowPointers)
69 | {
70 | unsigned char *pixel = (unsigned char *)texture->Mem;
71 | png_clut_t *clut = (png_clut_t *)texture->Clut;
72 |
73 | int i, j, k = 0;
74 |
75 | for (i = pngTexture.numPalette; i < 16; i++) {
76 | memset(&clut[i], 0, sizeof(clut[i]));
77 | }
78 |
79 | for (i = 0; i < pngTexture.numPalette; i++) {
80 | clut[i].red = pngTexture.palette[i].red;
81 | clut[i].green = pngTexture.palette[i].green;
82 | clut[i].blue = pngTexture.palette[i].blue;
83 | clut[i].alpha = 0x80;
84 | }
85 |
86 | for (i = 0; i < pngTexture.numTrans; i++)
87 | clut[i].alpha = pngTexture.trans[i] >> 1;
88 |
89 | for (i = 0; i < texture->Height; i++) {
90 | for (j = 0; j < texture->Width / 2; j++) {
91 | memcpy(&pixel[k], &rowPointers[i][1 * j], 1);
92 | pixel[k] = (pixel[k] << 4) | (pixel[k] >> 4);
93 | k++;
94 | }
95 | }
96 | }
97 |
98 | static void texPngReadPixels8(GSTEXTURE *texture, png_bytep *rowPointers)
99 | {
100 | unsigned char *pixel = (unsigned char *)texture->Mem;
101 | png_clut_t *clut = (png_clut_t *)texture->Clut;
102 |
103 | int i, j, k = 0;
104 |
105 | for (i = pngTexture.numPalette; i < 256; i++) {
106 | memset(&clut[i], 0, sizeof(clut[i]));
107 | }
108 |
109 | for (i = 0; i < pngTexture.numPalette; i++) {
110 | clut[i].red = pngTexture.palette[i].red;
111 | clut[i].green = pngTexture.palette[i].green;
112 | clut[i].blue = pngTexture.palette[i].blue;
113 | clut[i].alpha = 0x80;
114 | }
115 |
116 | for (i = 0; i < pngTexture.numTrans; i++)
117 | clut[i].alpha = pngTexture.trans[i] >> 1;
118 |
119 | // rotate clut
120 | for (i = 0; i < pngTexture.numPalette; i++) {
121 | if ((i&0x18) == 8) {
122 | png_clut_t tmp = clut[i];
123 | clut[i] = clut[i+8];
124 | clut[i+8] = tmp;
125 | }
126 | }
127 |
128 | for (i = 0; i < texture->Height; i++) {
129 | for (j = 0; j < texture->Width; j++) {
130 | memcpy(&pixel[k++], &rowPointers[i][1 * j], 1);
131 | }
132 | }
133 | }
134 |
135 | static void texPngReadPixels24(GSTEXTURE *texture, png_bytep *rowPointers)
136 | {
137 | struct pixel3
138 | {
139 | unsigned char r, g, b;
140 | };
141 | struct pixel3 *Pixels = (struct pixel3 *)texture->Mem;
142 |
143 | int i, j, k = 0;
144 | for (i = 0; i < texture->Height; i++) {
145 | for (j = 0; j < texture->Width; j++) {
146 | memcpy(&Pixels[k++], &rowPointers[i][4 * j], 3);
147 | }
148 | }
149 | }
150 |
151 | static void texPngReadPixels32(GSTEXTURE *texture, png_bytep *rowPointers)
152 | {
153 | struct pixel
154 | {
155 | unsigned char r, g, b, a;
156 | };
157 | struct pixel *Pixels = (struct pixel *)texture->Mem;
158 |
159 | int i, j, k = 0;
160 | for (i = 0; i < texture->Height; i++) {
161 | for (j = 0; j < texture->Width; j++) {
162 | memcpy(&Pixels[k], &rowPointers[i][4 * j], 3);
163 | Pixels[k++].a = rowPointers[i][4 * j + 3] >> 1;
164 | }
165 | }
166 | }
167 |
168 | static void texPngReadData(GSTEXTURE *texture, png_structp pngPtr, png_infop infoPtr,
169 | void (*texPngReadPixels)(GSTEXTURE *texture, png_bytep *rowPointers))
170 | {
171 | int row, rowBytes = png_get_rowbytes(pngPtr, infoPtr);
172 | size_t size = gsKit_texture_size_ee(texture->Width, texture->Height, texture->PSM);
173 | texture->Mem = memalign(128, size);
174 |
175 | // failed allocation
176 | if (!texture->Mem) {
177 | printf("TEXTURES PngReadData: Failed to allocate %d bytes\n", size);
178 | return;
179 | }
180 |
181 | png_bytep *rowPointers = calloc(texture->Height, sizeof(png_bytep));
182 | for (row = 0; row < texture->Height; row++) {
183 | rowPointers[row] = malloc(rowBytes);
184 | }
185 | png_read_image(pngPtr, rowPointers);
186 |
187 | texPngReadPixels(texture, rowPointers);
188 |
189 | for (row = 0; row < texture->Height; row++)
190 | free(rowPointers[row]);
191 |
192 | free(rowPointers);
193 |
194 | png_read_end(pngPtr, NULL);
195 | }
196 |
197 | int texPngLoad(GSTEXTURE *texture, int texID)
198 | {
199 | png_structp pngPtr = NULL;
200 | png_infop infoPtr = NULL;
201 | png_voidp readData = NULL;
202 | png_rw_ptr readFunction = NULL;
203 | void **PngFileBufferPtr;
204 |
205 | texture->ClutPSM = 0;
206 | texture->Filter = GS_FILTER_LINEAR;
207 | texture->Mem = NULL;
208 | texture->Vram = 0;
209 | texture->VramClut = 0;
210 | texture->Clut = NULL;
211 |
212 | if (!internalTexture[texID].texture)
213 | return -1;
214 |
215 | PngFileBufferPtr = internalTexture[texID].texture;
216 | readData = &PngFileBufferPtr;
217 | readFunction = &texPngReadMemFunction;
218 |
219 | pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL);
220 | if (!pngPtr)
221 | return texPngEnd(pngPtr, infoPtr, -2);
222 |
223 | infoPtr = png_create_info_struct(pngPtr);
224 | if (!infoPtr)
225 | return texPngEnd(pngPtr, infoPtr, -3);
226 |
227 | if (setjmp(png_jmpbuf(pngPtr)))
228 | return texPngEnd(pngPtr, infoPtr, -4);
229 |
230 | png_set_read_fn(pngPtr, readData, readFunction);
231 |
232 | unsigned int sigRead = 0;
233 | png_set_sig_bytes(pngPtr, sigRead);
234 | png_read_info(pngPtr, infoPtr);
235 |
236 | png_uint_32 pngWidth, pngHeight;
237 | int bitDepth, colorType, interlaceType;
238 | png_get_IHDR(pngPtr, infoPtr, &pngWidth, &pngHeight, &bitDepth, &colorType, &interlaceType, NULL, NULL);
239 | texture->Width = pngWidth;
240 | texture->Height = pngHeight;
241 |
242 | if (colorType == PNG_COLOR_TYPE_GRAY)
243 | png_set_expand(pngPtr);
244 |
245 | if (bitDepth == 16)
246 | png_set_strip_16(pngPtr);
247 |
248 | png_set_filler(pngPtr, 0x80, PNG_FILLER_AFTER);
249 | png_read_update_info(pngPtr, infoPtr);
250 |
251 | void (*texPngReadPixels)(GSTEXTURE * texture, png_bytep * rowPointers);
252 | switch (png_get_color_type(pngPtr, infoPtr)) {
253 | case PNG_COLOR_TYPE_RGB_ALPHA:
254 | texture->PSM = GS_PSM_CT32;
255 | texPngReadPixels = &texPngReadPixels32;
256 | break;
257 | case PNG_COLOR_TYPE_RGB:
258 | texture->PSM = GS_PSM_CT24;
259 | texPngReadPixels = &texPngReadPixels24;
260 | break;
261 | case PNG_COLOR_TYPE_PALETTE:
262 | pngTexture.palette = NULL;
263 | pngTexture.numPalette = 0;
264 | pngTexture.trans = NULL;
265 | pngTexture.numTrans = 0;
266 |
267 | png_get_PLTE(pngPtr, infoPtr, &pngTexture.palette, &pngTexture.numPalette);
268 | png_get_tRNS(pngPtr, infoPtr, &pngTexture.trans, &pngTexture.numTrans, NULL);
269 | texture->ClutPSM = GS_PSM_CT32;
270 |
271 | if (bitDepth == 4) {
272 | texture->PSM = GS_PSM_T4;
273 | texture->Clut = memalign(128, gsKit_texture_size_ee(8, 2, GS_PSM_CT32));
274 | memset(texture->Clut, 0, gsKit_texture_size_ee(8, 2, GS_PSM_CT32));
275 |
276 | texPngReadPixels = &texPngReadPixels4;
277 | }
278 | else {
279 | texture->PSM = GS_PSM_T8;
280 | texture->Clut = memalign(128, gsKit_texture_size_ee(16, 16, GS_PSM_CT32));
281 | memset(texture->Clut, 0, gsKit_texture_size_ee(16, 16, GS_PSM_CT32));
282 |
283 | texPngReadPixels = &texPngReadPixels8;
284 | }
285 | break;
286 | default:
287 | return texPngEnd(pngPtr, infoPtr, -6);
288 | }
289 |
290 | if (texSizeValidate(texture->Width, texture->Height, texture->PSM) < 0) {
291 | if (texture->Clut) {
292 | free(texture->Clut);
293 | texture->Clut = NULL;
294 | }
295 |
296 | return texPngEnd(pngPtr, infoPtr, -7);
297 | }
298 |
299 | texPngReadData(texture, pngPtr, infoPtr, texPngReadPixels);
300 |
301 | return texPngEnd(pngPtr, infoPtr, 0);
302 | }
303 |
--------------------------------------------------------------------------------