This repository has been archived by the owner on Mar 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
resource.h
157 lines (136 loc) · 3.27 KB
/
resource.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Another World engine rewrite
* Copyright (C) 2004-2005 Gregory Montoir ([email protected])
*/
#ifndef RESOURCE_H__
#define RESOURCE_H__
#include "intern.h"
struct MemEntry {
uint8_t status; // 0x0
uint8_t type; // 0x1, Resource::ResType
uint8_t *bufPtr; // 0x2
uint8_t rankNum; // 0x6
uint8_t bankNum; // 0x7
uint32_t bankPos; // 0x8
uint32_t packedSize; // 0xC
uint32_t unpackedSize; // 0x12
};
struct AmigaMemEntry {
uint8_t type;
uint8_t bank;
uint32_t offset;
uint32_t packedSize;
uint32_t unpackedSize;
};
struct DemoJoy {
uint8_t keymask;
uint8_t counter;
uint8_t *bufPtr;
int bufPos, bufSize;
bool start() {
if (bufSize > 0) {
keymask = bufPtr[0];
counter = bufPtr[1];
bufPos = 2;
return true;
}
return false;
}
uint8_t update() {
if (bufPos >= 0 && bufPos < bufSize) {
if (counter == 0) {
keymask = bufPtr[bufPos++];
counter = bufPtr[bufPos++];
} else {
--counter;
}
return keymask;
}
return 0;
}
};
struct ResourceNth;
struct ResourceWin31;
struct Resource3do;
struct Video;
typedef void (*PreloadSoundProc)(void *userdata, int num, const uint8_t *data);
struct Resource {
enum ResType {
RT_SOUND = 0,
RT_MUSIC = 1,
RT_BITMAP = 2, // full screen 4bpp video buffer, size=200*320/2
RT_PALETTE = 3, // palette (1024=vga + 1024=ega), size=2048
RT_BYTECODE = 4,
RT_SHAPE = 5,
RT_BANK = 6, // common part shapes (bank2.mat)
};
enum DataType {
DT_DOS,
DT_AMIGA,
DT_ATARI,
DT_15TH_EDITION,
DT_20TH_EDITION,
DT_WIN31,
DT_3DO,
DT_ATARI_DEMO, // ST Action Issue44 Disk28
};
enum {
MEM_BLOCK_SIZE = 1 * 1024 * 1024,
ENTRIES_COUNT = 146,
ENTRIES_COUNT_20TH = 178,
};
enum {
STATUS_NULL,
STATUS_LOADED,
STATUS_TOLOAD,
};
static const AmigaMemEntry _memListAmigaFR[ENTRIES_COUNT];
static const AmigaMemEntry _memListAmigaEN[ENTRIES_COUNT];
static const AmigaMemEntry _memListAtariEN[ENTRIES_COUNT];
static const uint8_t _memListParts[][4];
Video *_vid;
const char *_dataDir;
MemEntry _memList[ENTRIES_COUNT_20TH];
uint16_t _numMemList;
uint16_t _currentPart, _nextPart;
uint8_t *_memPtrStart, *_scriptBakPtr, *_scriptCurPtr, *_vidCurPtr;
bool _useSegVideo2;
uint8_t *_segVideoPal;
uint8_t *_segCode;
uint8_t *_segVideo1;
uint8_t *_segVideo2;
const char *_bankPrefix;
bool _hasPasswordScreen;
DataType _dataType;
ResourceNth *_nth;
ResourceWin31 *_win31;
Resource3do *_3do;
Language _lang;
const AmigaMemEntry *_amigaMemList;
DemoJoy _demo3Joy;
Resource(Video *vid, const char *dataDir);
~Resource();
DataType getDataType() const { return _dataType; }
void detectVersion();
const char *getGameTitle(Language lang) const;
bool readBank(const MemEntry *me, uint8_t *dstBuf);
void readEntries();
void readEntriesAmiga(const AmigaMemEntry *entries, int count);
void dumpEntries();
void load();
void invalidateAll();
void invalidateRes();
void update(uint16_t num, PreloadSoundProc, void *);
void loadBmp(int num);
uint8_t *loadDat(int num);
void loadFont();
void loadHeads();
uint8_t *loadWav(int num);
const char *getString(int num);
const char *getMusicPath(int num, char *buf, int bufSize, uint32_t *offset = 0);
void setupPart(int part);
void allocMemBlock();
void freeMemBlock();
void readDemo3Joy();
};
#endif