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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 
24 
25 #include "agos/agos.h"
26 #include "agos/intern.h"
27 #include "agos/sound.h"
28 #include "agos/vga.h"
29 
30 namespace AGOS {
31 
setupVideoOpcodes(VgaOpcodeProc * op)32 void AGOSEngine_Simon1::setupVideoOpcodes(VgaOpcodeProc *op) {
33 	AGOSEngine::setupVideoOpcodes(op);
34 
35 	op[11] = &AGOSEngine::vc11_clearPathFinder;
36 	op[17] = &AGOSEngine::vc17_setPathfinderItem;
37 	op[22] = &AGOSEngine::vc22_setPalette;
38 	op[32] = &AGOSEngine::vc32_copyVar;
39 	op[37] = &AGOSEngine::vc37_addToSpriteY;
40 	op[48] = &AGOSEngine::vc48_setPathFinder;
41 	op[59] = &AGOSEngine::vc59_ifSpeech;
42 	op[60] = &AGOSEngine::vc60_stopAnimation;
43 	op[61] = &AGOSEngine::vc61_setMaskImage;
44 	op[62] = &AGOSEngine::vc62_fastFadeOut;
45 	op[63] = &AGOSEngine::vc63_fastFadeIn;
46 }
47 
vc11_clearPathFinder()48 void AGOSEngine::vc11_clearPathFinder() {
49 	memset(&_pathFindArray, 0, sizeof(_pathFindArray));
50 }
51 
vc17_setPathfinderItem()52 void AGOSEngine::vc17_setPathfinderItem() {
53 	uint16 a = vcReadNextWord();
54 	_pathFindArray[a - 1] = (const uint16 *)_vcPtr;
55 
56 	int end = (getGameType() == GType_FF || getGameType() == GType_PP) ? 9999 : 999;
57 	while (readUint16Wrapper(_vcPtr) != end)
58 		_vcPtr += 4;
59 	_vcPtr += 2;
60 }
61 
62 static const uint8 customPalette[96] = {
63 	0x00, 0x00, 0x00,
64 	0x99, 0x22, 0xFF,
65 	0x66, 0xCC, 0xFF,
66 	0xFF, 0x99, 0xFF,
67 	0xFF, 0xFF, 0xFF,
68 	0x66, 0x44, 0xBB,
69 	0x77, 0x55, 0xCC,
70 	0x88, 0x77, 0xCC,
71 	0xCC, 0xAA, 0xDD,
72 	0x33, 0x00, 0x09,
73 	0x66, 0x44, 0xCC,
74 	0x88, 0x55, 0xCC,
75 	0xAA, 0x77, 0xEE,
76 	0x00, 0x00, 0x00,
77 	0x00, 0x00, 0x00,
78 	0x00, 0x00, 0x00,
79 	0x00, 0x00, 0x00,
80 	0xFF, 0xFF, 0xFF,
81 	0x33, 0x00, 0x00,
82 	0xCC, 0xCC, 0xDD,
83 	0x88, 0x99, 0xBB,
84 	0x44, 0x77, 0xAA,
85 	0x44, 0x44, 0x66,
86 	0x44, 0x44, 0x00,
87 	0x44, 0x66, 0x00,
88 	0x88, 0x99, 0x00,
89 	0x99, 0x44, 0x00,
90 	0xBB, 0x44, 0x22,
91 	0xFF, 0x55, 0x33,
92 	0xFF, 0x88, 0x88,
93 	0xFF, 0xBB, 0x33,
94 	0xFF, 0xFF, 0x77,
95 };
96 
vc22_setPalette()97 void AGOSEngine_Simon1::vc22_setPalette() {
98 	byte *offs, *palptr = 0, *src;
99 	uint16 a = 0, b, num, palSize = 0;
100 
101 	a = vcReadNextWord();
102 	b = vcReadNextWord();
103 
104 	if (getGameType() == GType_FF || getGameType() == GType_PP) {
105 		num = 256;
106 		palSize = 768;
107 
108 		palptr = _displayPalette;
109 	} else {
110 		num = a == 0 ? 32 : 16;
111 		palSize = 96;
112 
113 		palptr = &_displayPalette[(a * 3 * 16)];
114 	}
115 
116 	offs = _curVgaFile1 + 6;
117 	src = offs + b * palSize;
118 
119 	do {
120 		palptr[0] = src[0] * 4;
121 		palptr[1] = src[1] * 4;
122 		palptr[2] = src[2] * 4;
123 
124 		palptr += 3;
125 		src += 3;
126 	} while (--num);
127 
128 	if (getFeatures() & GF_32COLOR) {
129 		// Custom palette used for verb area
130 		palptr = &_displayPalette[(13 * 3 * 16)];
131 		for (uint8 c = 0; c < 32; c++) {
132 			palptr[0] = customPalette[c * 3 + 0];
133 			palptr[1] = customPalette[c * 3 + 1];
134 			palptr[2] = customPalette[c * 3 + 2];
135 
136 			palptr += 3;
137 		};
138 	}
139 
140 	_paletteFlag = 2;
141 	_vgaSpriteChanged++;
142 }
143 
vc32_copyVar()144 void AGOSEngine::vc32_copyVar() {
145 	uint16 a = vcReadVar(vcReadNextWord());
146 	vcWriteVar(vcReadNextWord(), a);
147 }
148 
vc37_addToSpriteY()149 void AGOSEngine::vc37_addToSpriteY() {
150 	VgaSprite *vsp = findCurSprite();
151 	vsp->y += vcReadVar(vcReadNextWord());
152 
153 	vsp->windowNum |= 0x8000;
154 	dirtyBackGround();
155 	_vgaSpriteChanged++;
156 }
157 
vc45_setSpriteX()158 void AGOSEngine::vc45_setSpriteX() {
159 	VgaSprite *vsp = findCurSprite();
160 	vsp->x = vcReadVar(vcReadNextWord());
161 
162 	vsp->windowNum |= 0x8000;
163 	dirtyBackGround();
164 	_vgaSpriteChanged++;
165 }
166 
vc46_setSpriteY()167 void AGOSEngine::vc46_setSpriteY() {
168 	VgaSprite *vsp = findCurSprite();
169 	vsp->y = vcReadVar(vcReadNextWord());
170 
171 	vsp->windowNum |= 0x8000;
172 	dirtyBackGround();
173 	_vgaSpriteChanged++;
174 }
175 
vc47_addToVar()176 void AGOSEngine::vc47_addToVar() {
177 	uint16 var = vcReadNextWord();
178 	vcWriteVar(var, vcReadVar(var) + vcReadVar(vcReadNextWord()));
179 }
180 
vc48_setPathFinder()181 void AGOSEngine::vc48_setPathFinder() {
182 	uint16 a = (uint16)_variableArrayPtr[12];
183 	const uint16 *p = _pathFindArray[a - 1];
184 
185 	uint b = (uint16)_variableArray[13];
186 	p += b * 2 + 1;
187 	int c = _variableArray[14];
188 
189 	int step;
190 	int y1, y2;
191 	int16 *vp;
192 
193 	step = 2;
194 	if (c < 0) {
195 		c = -c;
196 		step = -2;
197 	}
198 
199 	vp = &_variableArray[20];
200 
201 	do {
202 		y2 = readUint16Wrapper(p);
203 		p += step;
204 		y1 = readUint16Wrapper(p) - y2;
205 
206 		vp[0] = y1 / 2;
207 		vp[1] = y1 - (y1 / 2);
208 
209 		vp += 2;
210 	} while (--c);
211 }
212 
vc59_ifSpeech()213 void AGOSEngine::vc59_ifSpeech() {
214 	if (!_sound->isVoiceActive())
215 		vcSkipNextInstruction();
216 }
217 
vc61_setMaskImage()218 void AGOSEngine::vc61_setMaskImage() {
219 	VgaSprite *vsp = findCurSprite();
220 
221 	vsp->image = vcReadVarOrWord();
222 	vsp->x += vcReadNextWord();
223 	vsp->y += vcReadNextWord();
224 	vsp->flags = kDFMasked | kDFSkipStoreBG;
225 
226 	vsp->windowNum |= 0x8000;
227 	dirtyBackGround();
228 	_vgaSpriteChanged++;
229 }
230 
231 } // End of namespace AGOS
232