Rev 5276 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5276 | Rev 5331 | ||
---|---|---|---|
1 | #include "kosSyst.h" |
1 | #include "kosSyst.h" |
2 | #include "kosFile.h" |
2 | #include "kosFile.h" |
3 | //#include "string.h" |
3 | //#include "string.h" |
4 | 4 | ||
5 | CKosFile::CKosFile(char *fileName) |
5 | CKosFile::CKosFile(char *fileName) |
6 | { |
6 | { |
7 | // |
7 | // |
8 | rtlDebugOutString(fileName); |
8 | //rtlDebugOutString(fileName); |
9 | this->fileInfo.bufferPtr = new Byte[FILE_BUFFER_SIZE]; |
9 | this->fileInfo.bufferPtr = new Byte[FILE_BUFFER_SIZE]; |
10 | // |
10 | // |
11 | this->filePointer = 0; |
11 | this->filePointer = 0; |
12 | this->bufferPointer = 0; |
12 | this->bufferPointer = 0; |
13 | this->validBuffer = false; |
13 | this->validBuffer = false; |
14 | // |
14 | // |
15 | strcpy( this->fileInfo.fileURL, fileName ); |
15 | strcpy( this->fileInfo.fileURL, fileName ); |
16 | } |
16 | } |
17 | 17 | ||
18 | 18 | ||
19 | CKosFile::~CKosFile(void) |
19 | CKosFile::~CKosFile(void) |
20 | { |
20 | { |
21 | // |
21 | // |
22 | delete this->fileInfo.bufferPtr; |
22 | delete this->fileInfo.bufferPtr; |
23 | } |
23 | } |
24 | 24 | ||
25 | void CKosFile::ValidateBuffer() |
25 | void CKosFile::ValidateBuffer() |
26 | { |
26 | { |
27 | // |
27 | // |
28 | if ( this->validBuffer ) |
28 | if ( this->validBuffer ) |
29 | { |
29 | { |
30 | // |
30 | // |
31 | if ( this->filePointer < this->bufferPointer |
31 | if ( this->filePointer < this->bufferPointer |
32 | || this->filePointer >= (this->bufferPointer + FILE_BUFFER_SIZE) ) |
32 | || this->filePointer >= (this->bufferPointer + FILE_BUFFER_SIZE) ) |
33 | { |
33 | { |
34 | // |
34 | // |
35 | this->validBuffer = false; |
35 | this->validBuffer = false; |
36 | } |
36 | } |
37 | } |
37 | } |
38 | } |
38 | } |
39 | 39 | ||
40 | 40 | ||
41 | void CKosFile::UpdateBuffer(void) |
41 | void CKosFile::UpdateBuffer(void) |
42 | { |
42 | { |
43 | // |
43 | // |
44 | if ( ! this->validBuffer ) |
44 | if ( ! this->validBuffer ) |
45 | { |
45 | { |
46 | // |
46 | // |
47 | this->fileInfo.OffsetLow = this->filePointer / OS_BLOCK_SIZE; |
47 | this->fileInfo.OffsetLow = this->filePointer / OS_BLOCK_SIZE; |
48 | this->fileInfo.OffsetHigh = 0; |
48 | this->fileInfo.OffsetHigh = 0; |
49 | // |
49 | // |
50 | this->bufferPointer = this->fileInfo.OffsetLow * OS_BLOCK_SIZE; |
50 | this->bufferPointer = this->fileInfo.OffsetLow * OS_BLOCK_SIZE; |
51 | // |
51 | // |
52 | this->fileInfo.dataCount = FILE_BUFFER_BLOCKS; |
52 | this->fileInfo.dataCount = FILE_BUFFER_BLOCKS; |
53 | // |
53 | // |
54 | this->fileInfo.rwMode = 0; |
54 | this->fileInfo.rwMode = 0; |
55 | // |
55 | // |
56 | Dword rr = kos_FileSystemAccess( &(this->fileInfo) ); |
56 | Dword rr = kos_FileSystemAccess( &(this->fileInfo) ); |
57 | this->validBuffer = ( rr == 0 ); |
57 | this->validBuffer = ( rr == 0 ); |
58 | } |
58 | } |
59 | } |
59 | } |
60 | 60 | ||
61 | 61 | ||
62 | int CKosFile::Seek(int seekFrom, int seekStep) |
62 | int CKosFile::Seek(int seekFrom, int seekStep) |
63 | { |
63 | { |
64 | // |
64 | // |
65 | switch ( seekFrom ) |
65 | switch ( seekFrom ) |
66 | { |
66 | { |
67 | // |
67 | // |
68 | case SEEK_SET: |
68 | case SEEK_SET: |
69 | // |
69 | // |
70 | this->filePointer = seekStep; |
70 | this->filePointer = seekStep; |
71 | break; |
71 | break; |
72 | // |
72 | // |
73 | case SEEK_CUR: |
73 | case SEEK_CUR: |
74 | // |
74 | // |
75 | this->filePointer += seekStep; |
75 | this->filePointer += seekStep; |
76 | break; |
76 | break; |
77 | } |
77 | } |
78 | // |
78 | // |
79 | this->ValidateBuffer(); |
79 | this->ValidateBuffer(); |
80 | // |
80 | // |
81 | return this->filePointer; |
81 | return this->filePointer; |
82 | } |
82 | } |
83 | 83 | ||
84 | 84 | ||
85 | int CKosFile::Read(Byte *targetPtr, int readCount) |
85 | int CKosFile::Read(Byte *targetPtr, int readCount) |
86 | { |
86 | { |
87 | int bufferLeast, result; |
87 | int bufferLeast, result; |
88 | 88 | ||
89 | // |
89 | // |
90 | result = 0; |
90 | result = 0; |
91 | // |
91 | // |
92 | do |
92 | do |
93 | { |
93 | { |
94 | // |
94 | // |
95 | this->UpdateBuffer(); |
95 | this->UpdateBuffer(); |
96 | // |
96 | // |
97 | if ( ! this->validBuffer ) return result; |
97 | if ( ! this->validBuffer ) return result; |
98 | // |
98 | // |
99 | bufferLeast = FILE_BUFFER_SIZE - (this->filePointer - this->bufferPointer); |
99 | bufferLeast = FILE_BUFFER_SIZE - (this->filePointer - this->bufferPointer); |
100 | // |
100 | // |
101 | if ( bufferLeast > readCount ) bufferLeast = readCount; |
101 | if ( bufferLeast > readCount ) bufferLeast = readCount; |
102 | // |
102 | // |
103 | if ( bufferLeast ) |
103 | if ( bufferLeast ) |
104 | { |
104 | { |
105 | // |
105 | // |
106 | memcpy( |
106 | memcpy( |
107 | targetPtr, |
107 | targetPtr, |
108 | this->fileInfo.bufferPtr + (this->filePointer - this->bufferPointer), |
108 | this->fileInfo.bufferPtr + (this->filePointer - this->bufferPointer), |
109 | bufferLeast |
109 | bufferLeast |
110 | ); |
110 | ); |
111 | // |
111 | // |
112 | targetPtr += bufferLeast; |
112 | targetPtr += bufferLeast; |
113 | readCount -= bufferLeast; |
113 | readCount -= bufferLeast; |
114 | this->filePointer += bufferLeast; |
114 | this->filePointer += bufferLeast; |
115 | // |
115 | // |
116 | result += bufferLeast; |
116 | result += bufferLeast; |
117 | } |
117 | } |
118 | // |
118 | // |
119 | this->ValidateBuffer(); |
119 | this->ValidateBuffer(); |
120 | } |
120 | } |
121 | while ( readCount > 0 ); |
121 | while ( readCount > 0 ); |
122 | // |
122 | // |
123 | return result; |
123 | return result; |
124 | } |
124 | } |
125 | 125 | ||
126 | 126 | ||
127 | int CKosFile::Write(Byte *sourcePtr, int writeCount) |
127 | int CKosFile::Write(Byte *sourcePtr, int writeCount) |
128 | { |
128 | { |
129 | return 0; |
129 | return 0; |
130 | } |
130 | } |
131 | 131 | ||
132 | void CKosFile::LoadTex(Byte *targetPtr, Byte Size, int width, int height) |
132 | void CKosFile::LoadTex(Byte *targetPtr, Byte Size, int width, int height) |
133 | { |
133 | { |
134 | this->Read(targetPtr, width * height * Size); |
134 | this->Read(targetPtr, width * height * Size); |
135 | }> |
135 | }> |