1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 234
6#include "sce/libcdvd.h"
16#include "clothread.hpp"
17#include "dataalloc.hpp"
20#include "framevu1.hpp"
60static char CurrentDir[256] =
"y:/ps2/dc_data/";
63static u_int *packfile_buff;
67static int data_sector;
69static int start_vsync;
72static u_char header_buff[0x50000];
74static u_char header_buff[0x40000];
79static int CDRead(
char *path, u_int *buffer,
int *out_size);
99 for (i = 0; i < header_num; i++, record++) {
100 if (strcasecmp((
char *) record->
name, path) == 0) {
117 while ((ch = *path) != 0) {
120 node = search_tree(node, word);
136 node = search_tree(node, word);
149 for (i = 0; i < 32; i++) {
150 bg_read_info[i].
busy =
false;
159int LoadFileBG(
char *name, u_long128 *buffer,
int *out_size) {
182 for (i = 0; i < 32; i++, info++) {
183 if (info->
busy == 0) {
192 if ((
int) buffer > 0x2000000) {
193 printf(
"address error\n");
199 if ((
int) buffer % 64) {
200 printf(
"/*/*/*/*/not 64byte align at %x %s\n", buffer, name);
207 header = SearchFile(name);
214 strcpy(info->
name, name);
222 *out_size = header->
size;
231 if (index < 0 || index >= 32) {
235 return bg_read_info[index].
busy ? &bg_read_info[index] : 0;
250 vsync = MGGetVSyncCount();
252 if (old_vsync == vsync) {
260 mode.datapattern = 0;
263 for (i = 0; i < 32; i++, info++) {
265 if (info->
id != 0 && info->
done == 0) {
269 if (info->
id == 0 && info->
done == 0) {
282 }
else if (info->
id != 0) {
287 if (sceCdGetError()) {
288 printf(
"error at %s\n", info->
name);
304 for (i = 0; i < 32; i++, info++) {
310 if (info->
done == 0) {
334 if (strcasecmp(node->
name, name) == 0) {
341 found = search_tree(node, name);
358 sibling = parent->
child;
361 parent->
child = child_node;
366 if (sibling->
next == 0) {
367 sibling->
next = child_node;
371 sibling = sibling->
next;
380static char *create_word_tree(
char *index_image,
int size,
char *tree_buffer) {
393 bottom = tree_buffer;
394 top = tree_buffer + size - 1;
399 tree->
name = tree_buffer + 16;
402 header_num = *(u_int *) index_image >> 5;
404 for (i = 0; i < header_num; i++) {
406 path = (
char *) (record->
name + (
int) index_image);
409 while ((ch = *cursor) != 0) {
424 if (ch ==
'/' || ch == 0) {
431 node = search_tree(parent, word);
435 memset(bottom, 0, 16);
437 top -= strlen(word) + 1;
440 add_tree(parent, node);
448 copy_data_head(node->
data, record);
462 printf(
"file header size = %d\n", size - (top - bottom));
482 if (sceCdSearchFile(&file,
"\\DATA.DAT;1")) {
485 if (sceCdGetError() == 0) {
491 data_sector = file.
lsn;
492 fd = sceOpen(
"cdrom0:\\DATA.HD2;1", SCE_RDONLY);
495 printf(
"File open error \"\"\n \n \n");
496 __assert(
"etc.cpp", 565,
"FALSE");
499 size = sceLseek(fd, 0, SCE_SEEK_END);
500 sceLseek(fd, 0, SCE_SEEK_SET);
501 sceRead(fd, header_buff, size);
505 header_num = (u_int) records->
name >> 5;
507 for (i = 0; i < header_num; i++) {
511 records[i].
name += (int) header_buff;
513 for (cursor = (
char *) records[i].
name; (ch = *cursor) != 0; cursor++) {
522 char index_image[307200];
530 if (sceCdSearchFile(&file,
"\\DATA.DAT;1")) {
533 if (sceCdGetError() == 0) {
539 data_sector = file.
lsn;
540 fd = sceOpen(
"cdrom0:\\DATA.HD2;1", SCE_RDONLY);
543 printf(
"File open error \"\"\n \n \n");
546 __assert(
"etc.cpp", 556,
"FALSE");
549 size = sceLseek(fd, 0, SCE_SEEK_END);
550 sceLseek(fd, 0, SCE_SEEK_SET);
551 sceRead(fd, index_image, size);
553 create_word_tree(index_image,
sizeof header_buff, (
char *) header_buff);
557void InitMemoryFile() {
560int LoadFile(
char *path,
void *buffer,
int *out_size) {
561 if (!LoadFile2(path, buffer, out_size, 0)) {
562 printf(
"File open error \"%s\"\n \n \n", path);
564 __assert(
"etc.cpp", 753,
"FALSE");
566 __assert(
"etc.cpp", 740,
"FALSE");
575int LoadFile2(
char *path,
void *buffer,
int *out_size,
int mode) {
589 char sim[16] =
"sim:";
590 char host[16] =
"host:";
595 while ((ch = *cursor) != 0) {
606 file_name = cursor + 1;
613 if (memcmp(device,
"host", 4) != 0 && memcmp(CurrentDir,
"host:", 4) == 0) {
617 if ((
int) buffer > 0x2000000) {
618 printf(
"address error\n");
624 char full_path[256] =
"";
626 strcat(full_path, file_name);
627 return CDRead(full_path, (u_int *) buffer, out_size);
630static int CDRead(
char *path, u_int *buffer,
int *out_size) {
642 header = SearchFile(path);
651 mode.datapattern = 0;
654 if (sceCdRead(header->
sector + data_sector, header->
sectors, buffer, &mode)) {
657 if (sceCdGetError() == 0) {
664 *out_size = header->
size;
670int WriteFile(
char *path,
void *buffer,
int size) {
673 fd = sceOpen(path, SCE_WRONLY | SCE_CREAT | SCE_TRUNC);
679 sceWrite(fd, buffer, size);
684int LoadPackFile(
char *path, u_int *buffer,
int *out_size) {
685 packfile_buff = buffer;
687 if (!LoadFile2(path, buffer, out_size, 0)) {
695u_int *GetPackFile(
char *name,
int *out_size) {
696 return GetPackFile(packfile_buff, name, out_size);
701u_int *GetPackFile(u_int *pack,
char *name,
int *out_size) {
713 while ((ch = *name) != 0) {
715 base_name = name + 1;
723 while (entry->
name[0]) {
724 if (strcasecmp(entry->
name, base_name) == 0) {
725 data = (u_int *) ((
char *) entry + entry->
offset);
728 *out_size = entry->
size;
740u_int *GetPackFile(u_int *pack,
int index,
char **out_name,
int *out_size) {
752 while (entry->
name[0]) {
754 data = (u_int *) ((
char *) entry + entry->
offset);
757 *out_size = entry->
size;
760 *out_name = entry->
name;
773int GetPackFileExt(u_int *pack,
char *extension, u_int **files,
int max_files,
int *sizes,
char **names) {
786 data = GetPackFile(pack, i, &name, &size);
794 while ((ch = *ext_start) != 0) {
803 if (strcasecmp(extension, ext_start) == 0) {
804 files[found_count] = data;
807 names[found_count] = name;
811 sizes[found_count] = size;
816 if (found_count >= max_files) {