ScummVM API documentation
resman.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef SWORD1_RESMAN_H
23#define SWORD1_RESMAN_H
24
25#include "sword1/memman.h"
26#include "sword1/swordres.h"
27#include "common/file.h"
28#include "sword1/sworddefs.h"
29#include "common/endian.h"
30#include "common/mutex.h"
31
32namespace Sword1 {
33
34#define MAX_LABEL_SIZE (31+1)
35
36#if defined(__PSP__)
37#define MAX_OPEN_CLUS 4 // the PSP can't have more than 8 files open simultaneously
38 // since we also need filehandles for music and sometimes savegames
39 // set the maximum number of open clusters to 4.
40#else
41#define MAX_OPEN_CLUS 8 // don't open more than 8 files at once
42#endif
43
44struct Grp {
45 uint32 noRes;
46 MemHandle *resHandle;
47 uint32 *offset;
48 uint32 *length;
49};
50
51struct Clu {
52 uint32 refCount;
53 Common::File *file;
54 char label[MAX_LABEL_SIZE];
55 uint32 noGrp;
56 Grp *grp;
57 Clu *nextOpen;
58};
59
60struct Prj {
61 uint32 noClu;
62 Clu *clu;
63};
64
65class ResMan {
66public:
67 ResMan(const char *fileName, bool isMacFile, bool isKorean);
68 ~ResMan();
69 void flush();
70 void resClose(uint32 id);
71 void resOpen(uint32 id);
72 void *fetchRes(uint32 id);
73 void dumpRes(uint32 id);
74 void *openFetchRes(uint32 id);
75 void *cptResOpen(uint32 id);
76 Header *lockScript(uint32 scrID);
77 void unlockScript(uint32 scrID);
78 FrameHeader *fetchFrame(void *resourceData, uint32 frameNo);
79
80 uint16 getUint16(uint16 value) {
81 return (_isBigEndian) ? FROM_BE_16(value) : FROM_LE_16(value);
82 }
83 uint32 getUint32(uint32 value) {
84 return (_isBigEndian) ? FROM_BE_32(value) : FROM_LE_32(value);
85 }
86 uint16 getLEUint16(uint16 value) {
87 return FROM_LE_16(value);
88 }
89 uint32 getLEUint32(uint32 value) {
90 return FROM_LE_32(value);
91 }
92 uint16 readUint16(const void *ptr) {
93 return (_isBigEndian) ? READ_BE_UINT16(ptr) : READ_LE_UINT16(ptr);
94 }
95 uint32 readUint32(const void *ptr) {
96 return (_isBigEndian) ? READ_BE_UINT32(ptr) : READ_LE_UINT32(ptr);
97 }
98 uint32 readLEUint32(const void *ptr) {
99 return READ_LE_UINT32(ptr);
100 }
101 uint16 toUint16(uint16 value) {
102 return (_isBigEndian) ? TO_BE_16(value) : TO_LE_16(value);
103 }
104 uint32 toUint32(uint32 value) {
105 return (_isBigEndian) ? TO_BE_32(value) : TO_LE_32(value);
106 }
107
108 uint32 getDeathFontId();
109
110private:
111 uint32 resLength(uint32 id);
112 MemHandle *resHandle(uint32 id);
113 uint32 resOffset(uint32 id);
114 Common::File *resFile(uint32 id);
115
116 void openCptResourceBigEndian(uint32 id);
117 void openScriptResourceBigEndian(uint32 id);
118 void openCptResourceLittleEndian(uint32 id);
119 void openScriptResourceLittleEndian(uint32 id);
120
121 void loadCluDescript(const char *fileName);
122 void freeCluDescript();
123 Prj _prj;
124 MemMan *_memMan;
125 static const uint32 _scriptList[TOTAL_SECTIONS]; //a table of resource tags
126 Clu *_openCluStart, *_openCluEnd;
127 int _openClus;
128 bool _isBigEndian;
129 bool _isKorTrs = false;
130
131 Common::Mutex _resourceAccessMutex;
132
133 uint32 _srIdList[29] = {
134 // the file numbers differ for the control panel file IDs, so we need this array
135 OTHER_SR_FONT, // SR_FONT
136 0x04050000, // SR_BUTTON
137 OTHER_SR_REDFONT, // SR_REDFONT
138 0x04050001, // SR_PALETTE
139 0x04050002, // SR_PANEL_ENGLISH
140 0x04050003, // SR_PANEL_FRENCH
141 0x04050004, // SR_PANEL_GERMAN
142 0x04050005, // SR_PANEL_ITALIAN
143 0x04050006, // SR_PANEL_SPANISH
144 0x04050007, // SR_PANEL_AMERICAN
145 0x04050008, // SR_TEXT_BUTTON
146 0x04050009, // SR_SPEED
147 0x0405000A, // SR_SCROLL1
148 0x0405000B, // SR_SCROLL2
149 0x0405000C, // SR_CONFIRM
150 0x0405000D, // SR_VOLUME
151 0x0405000E, // SR_VLIGHT
152 0x0405000F, // SR_VKNOB
153 0x04050010, // SR_WINDOW
154 0x04050011, // SR_SLAB1
155 0x04050012, // SR_SLAB2
156 0x04050013, // SR_SLAB3
157 0x04050014, // SR_SLAB4
158 0x04050015, // SR_BUTUF
159 0x04050016, // SR_BUTUS
160 0x04050017, // SR_BUTDS
161 0x04050018, // SR_BUTDF
162 0x04050019, // SR_DEATHPANEL
163 SR_DEATHFONT,
164 };
165};
166
167} // End of namespace Sword1
168
169#endif //RESMAN_H
Definition: file.h:47
Definition: mutex.h:67
Definition: memman.h:43
Definition: resman.h:65
Definition: animation.h:38
Definition: resman.h:51
Definition: sworddefs.h:108
Definition: resman.h:44
Definition: sworddefs.h:100
Definition: memman.h:29
Definition: resman.h:60