-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathFILE.C
137 lines (111 loc) · 2.36 KB
/
FILE.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "FILE.H"
#include "CD.H"
#include <sys/types.h>
#include <LIBCD.H>
#include <STDIO.H>
#if !DISC_VERSION
#include <LIBSN.H>
#endif
int FILE_Load(char* szFileName, void* pDest)//5E528(<), 5E5D8(<) (F) (*) (*) (D) (D)
{
#if DISC_VERSION
CdlFILE fp;
char buf[80];
DEL_ChangeCDMode(0);
sprintf(buf, "\\%s;1", szFileName);
CdSearchFile(&fp, buf);
cdCurrentSector = CdPosToInt(&fp.pos);
return DEL_CDFS_Read((char*)pDest, fp.size);
#else
int nHandle;
unsigned long dwFileSize;
unsigned long dwBytesRead;
printf("Open\n");
nHandle = PCopen(szFileName, 0, 0);
if (nHandle < 0)
{
printf("FILE_Load: '%s' Could not open!\n", szFileName);
S_ExitSystem("Can't open file");
}
printf("Seek\n");
dwFileSize = PClseek(nHandle, 0, 2);
PClseek(nHandle, 0, 0);
printf("Read\n");
dwBytesRead = PCread(nHandle, (char*)pDest, dwFileSize);
printf("Close\n");
PCclose(nHandle);
return dwFileSize == dwBytesRead;
#endif
}
unsigned long FILE_Length(char* szFileName)//5E60C(<), 5E578(<) (F) (*) (*) (D) (D)
{
#if DISC_VERSION
CdlFILE fp;
char buf[80];
DEL_ChangeCDMode(0);
sprintf(buf, "\\%s;1", szFileName);
if (CdSearchFile(&fp, buf))
{
return fp.size;
}
else
{
return -1;
}
#else
int nHandle;
unsigned long dwFileSize;
printf("Open\n");
nHandle = PCopen(szFileName, 0, 0);
if (nHandle < 0)
{
printf("FILE_Length: '%s' Could not find!\n", szFileName);
return -1;
}
else
{
printf("Seek\n");
dwFileSize = PClseek(nHandle, 0, 2);
printf("Close\n");
PCclose(nHandle);
return dwFileSize;
}
#endif
}
#if !DISC_VERSION
int FILE_Read(char* pDest, int nItemSize, int nItems, int nHandle)//5E6A8(<), ? (F) (*) (D)
{
int nAmount = nItemSize * nItems;
return PCread(nHandle, pDest, nAmount);
}
#endif
void RelocateModule(unsigned long Module, unsigned long* RelocData)//5E6D4(<), 5F430(<) (F) (*)
{
unsigned int* rel;
if (*RelocData != -1)
{
do
{
rel = (unsigned int*)(Module + (*RelocData & -4));
switch (*RelocData++ & 3)
{
case 0:
//loc_5E738
((unsigned int*)rel)[0] += Module;
break;
case 1:
//loc_5E744
((unsigned short*)rel)[0] = (Module + *RelocData++ + 0x8000) >> 16;
break;
case 2:
//loc_5E760:
((unsigned short*)rel)[0] += Module;
break;
case 3:
//loc_5E774
((unsigned int*)rel)[0] += ((Module << 4) >> 6);
break;
}
} while (*RelocData != -1);
}//locret_5E794
}