aboutsummaryrefslogtreecommitdiff
path: root/engines/cruise/background.cpp
blob: 11d70c06de43608829ecf2182a272272e8d3a64a (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#include "cruise/cruise_main.h"

namespace Cruise {

uint8 colorMode = 0;

uint8 *backgroundPtrtable[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };	// wasn't initialized in original, but it's probably better
backgroundTableStruct backgroundTable[8];

char hwPage[64000];

char *hwMemAddr[] = {
	hwPage,
};

short int cvtPalette[0x20];

int loadMEN(uint8 **ptr) {
	char *localPtr = (char *)*ptr;

	if (!strcmp(localPtr, "MEN")) {
		localPtr += 4;

		titleColor = *(localPtr++);
		selectColor = *(localPtr++);
		itemColor = *(localPtr++);
		subColor = *(localPtr++);

		*ptr = (uint8 *) localPtr;

		return 1;
	} else {
		return 0;
	}
}

int CVTLoaded;

int loadCVT(uint8 **ptr) {
	char *localPtr = (char *)*ptr;

	if (!strcmp(localPtr, "CVT")) {
		int i;
		localPtr += 4;

		for (i = 0; i < 0x20; i++) {
			cvtPalette[i] = *(localPtr++);
		}

		*ptr = (uint8 *) localPtr;

		CVTLoaded = 1;

		return 1;
	} else {
		CVTLoaded = 0;
		return 0;
	}
}

extern int lastFileSize;

int loadBackground(const char *name, int idx) {
	uint8 *ptr;
	uint8 *ptr2;
	uint8 *ptrToFree;

	printf("Loading BG: %s\n", name);

	if (!backgroundPtrtable[idx]) {
		backgroundPtrtable[idx] = (uint8 *)mallocAndZero(320 * 200);
	}

	if (!backgroundPtrtable[idx]) {
		backgroundTable[idx].name[0] = 0;
		return (-2);
	}

	ptrToFree = gfxModuleData.pPage10;
	if (loadFileSub1(&ptrToFree, name, NULL) < 0) {
		if (ptrToFree != gfxModuleData.pPage10)
			free(ptrToFree);

		return (-18);
	}

	if (lastFileSize == 32078 || lastFileSize == 32080 || lastFileSize == 32034) {
		colorMode = 0;
	} else {
		colorMode = 1;
	}

	ptr = ptrToFree;
	ptr2 = ptrToFree;

	if (!strcmp(name, "LOGO.PI1")) {
		oldSpeedGame = speedGame;
		flagSpeed = 1;
		speedGame = 1;
	} else if (flagSpeed) {
		speedGame = oldSpeedGame;
		flagSpeed = 0;
	}

	if (!strcmp((char*)ptr, "PAL")) {
		printf("Pal loading unsupported !\n");
		ASSERT(0);
	} else {
		int mode = ptr2[1];
		ptr2 += 2;
		// read palette
		switch(mode)
		{
		case 4: // color on 3 bit
			{
				uint16 oldPalette[32];

				memcpy(oldPalette, ptr2, 0x20);
				ptr2 += 0x20;
				flipGen(oldPalette, 0x20);

				for(unsigned long int i=0; i<32; i++)
				{
					gfxModuleData_convertOldPalColor(oldPalette[i], &palScreen[idx][i*3]);
				}
				ptr2 += 32000;
				break;
			}
		case 5: // color on 4 bit
			{
				for(unsigned long int i=0; i<32; i++)
				{
					uint8* inPtr = ptr2 + i * 2;
					uint8* outPtr = palScreen[idx] +i * 3;
					
					outPtr[2] = ((inPtr[1])&0x0F) << 4;
					outPtr[1] = (((inPtr[1])&0xF0) >> 4) << 4;
					outPtr[0] = ((inPtr[0])&0x0F) << 4;
				}
				ptr2 += 2*32;
				break;
			}
		case 8:
			memcpy(palScreen[idx], ptr2, 256*3);
			ptr2 += 256*3;
			break;

		default:
			ASSERT(0);
		}

		gfxModuleData_setPal256(palScreen[idx]);

		loadMEN(&ptr2);
		loadCVT(&ptr2);

		// read image data
		gfxModuleData_gfxClearFrameBuffer(backgroundPtrtable[idx]);

		switch(mode)
		{
		case 4:
			convertGfxFromMode4(ptr2, 320, 200, backgroundPtrtable[idx]);
			break;
		case 5:
			convertGfxFromMode5(ptr2, 320, 200, backgroundPtrtable[idx]);
			break;
		case 8:
			memcpy(backgroundPtrtable[idx], ptr2, 320 * 200);
			break;
		}
	}


	strcpy(backgroundTable[idx].name, name);

	return (0);
}

} // End of namespace Cruise