PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
jvld.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 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#include <accore.h>
12#include <irx_imports.h>
13
14#define MODNAME "JV_loader"
15IRX_ID(MODNAME, 1, 1);
16// Text section hash:
17// f0b629a31e9fcde972afce3df69d5342
18// Known titles:
19// NM00017
20// NM00018
21// NM00019
22// NM00021
23// NM00024
24// NM00027
25// NM00029
26// NM00030
27// NM00032
28// NM00034
29// NM00035
30// NM00037
31// NM00040
32// NM00042
33// NM00043
34// NM00048
35// NM00052
36// Path strings:
37// /home/kyota/fs16/psalmT/psalm-0.2.8/jvld-iop-0.2.2/src/
38
39typedef char *(*jvld_strop_t)(char *name);
40
41static char *jvld_path(char *name);
42static char *jvld_basename(char *name);
43
44static jvld_strop_t ops_8[2] = {&jvld_path, &jvld_basename};
45static char buf_13[8192];
46
47static char *jvld_path(char *name)
48{
49 char *str;
50
51 str = strchr(name, ':');
52 if ( str == 0 )
53 return name;
54 return str + 1;
55}
56
57static char *jvld_basename(char *name)
58{
59 char *str;
60 char *str_v3;
61 char *str_v4;
62 char *str_v5;
63 char *str_v6;
64
65 str = strchr(name, ':');
66 if ( str == 0 )
67 return name;
68 str_v3 = str + 1;
69 str_v4 = strrchr(str_v3, '/');
70 if ( str_v4 == 0 )
71 {
72 str_v6 = strrchr(str_v3, '\\');
73 if ( str_v6 == 0 )
74 return str_v3;
75 str_v5 = str_v6 + 1;
76 }
77 else
78 {
79 str_v5 = str_v4 + 1;
80 }
81 return str_v5;
82}
83
84#define acJvLoader _start
85
86int acJvLoader(int argc, char **argv)
87{
88 char *prog;
89 int ret;
90 char *name;
91 int fd;
92
93 prog = 0;
94 if ( argv )
95 prog = *argv;
96 if ( argc < 2 )
97 {
98 ret = -22;
99 return 4 * ret + 1;
100 }
101 name = argv[1];
102 if ( jvld_path(name) == name )
103 {
104 fd = -6;
105 }
106 else
107 {
108 fd = open(name, 1);
109 if ( fd < 0 && prog )
110 {
111 int index;
112
113 index = 0;
114 while ( (unsigned int)index < 2 )
115 {
116 jvld_strop_t op;
117 const char *v9;
118
119 op = ops_8[index];
120 v9 = (char *)op(prog);
121 if ( v9 != prog )
122 {
123 memcpy(buf_13, prog, v9 - prog);
124 strcpy(&buf_13[v9 - prog], op(name));
125 fd = open(buf_13, 1);
126 if ( fd >= 0 )
127 break;
128 }
129 index += 1;
130 }
131 }
132 }
133 if ( fd < 0 )
134 {
135 printf("acjvld:open: error %d\n", fd);
136 ret = fd;
137 }
138 else
139 {
140 volatile acUint16 *ret_v10;
141 int sent;
142
143 *((volatile acUint16 *)0xB2416000) = 0;
144 ret_v10 = (volatile acUint16 *)0xB2400000;
145 sent = 0;
146 while ( 1 )
147 {
148 int c448;
149 const unsigned char *ptr;
150 int ret_v15;
151
152 c448 = read(fd, buf_13, 0x2000);
153 if ( c448 <= 0 )
154 break;
155 ptr = (unsigned char *)buf_13;
156 sent += c448;
157 ret_v15 = c448 - 1;
158 while ( ret_v15 >= 0 )
159 {
160 --ret_v15;
161 *ret_v10++ = *ptr++;
162 }
163 }
164 if ( sent != lseek(fd, 0, 2) )
165 {
166 ret = -5;
167 }
168 else
169 {
170 ret = sent;
171 if ( !sent )
172 {
173 ret = -8;
174 }
175 }
176 close(fd);
177 }
178 if ( ret >= 0 )
179 return 1;
180 return 4 * ret + 1;
181}