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 #include "agos/agos.h"
24 #include "agos/intern.h"
25 #include "agos/midi.h"
26 #include "agos/sound.h"
27
28 #include "graphics/surface.h"
29
30 namespace AGOS {
31
setupVideoOpcodes(VgaOpcodeProc * op)32 void AGOSEngine_Simon2::setupVideoOpcodes(VgaOpcodeProc *op) {
33 AGOSEngine_Simon1::setupVideoOpcodes(op);
34
35 op[56] = &AGOSEngine::vc56_delayLong;
36 op[58] = &AGOSEngine::vc58_changePriority;
37 op[59] = &AGOSEngine::vc59_stopAnimations;
38 op[64] = &AGOSEngine::vc64_ifSpeech;
39 op[65] = &AGOSEngine::vc65_slowFadeIn;
40 op[66] = &AGOSEngine::vc66_ifEqual;
41 op[67] = &AGOSEngine::vc67_ifLE;
42 op[68] = &AGOSEngine::vc68_ifGE;
43 op[69] = &AGOSEngine::vc69_playSeq;
44 op[70] = &AGOSEngine::vc70_joinSeq;
45 op[71] = &AGOSEngine::vc71_ifSeqWaiting;
46 op[72] = &AGOSEngine::vc72_segue;
47 op[73] = &AGOSEngine::vc73_setMark;
48 op[74] = &AGOSEngine::vc74_clearMark;
49 }
50
vc56_delayLong()51 void AGOSEngine::vc56_delayLong() {
52 uint16 num = vcReadVarOrWord() * _frameCount;
53
54 addVgaEvent(num + _vgaBaseDelay, ANIMATE_EVENT, _vcPtr, _vgaCurSpriteId, _vgaCurZoneNum);
55 _vcPtr = (byte *)&_vcGetOutOfCode;
56 }
57
vc58_changePriority()58 void AGOSEngine::vc58_changePriority() {
59 uint16 sprite = _vgaCurSpriteId;
60 uint16 file = _vgaCurZoneNum;
61 const byte *vcPtrOrg;
62 uint16 tmp;
63
64 _vgaCurZoneNum = vcReadNextWord();
65 _vgaCurSpriteId = vcReadNextWord();
66
67 tmp = to16Wrapper(vcReadNextWord());
68
69 vcPtrOrg = _vcPtr;
70 _vcPtr = (byte *)&tmp;
71 vc23_setPriority();
72
73 _vcPtr = vcPtrOrg;
74 _vgaCurSpriteId = sprite;
75 _vgaCurZoneNum = file;
76 }
77
vc59_stopAnimations()78 void AGOSEngine::vc59_stopAnimations() {
79 uint16 file = vcReadNextWord();
80 uint16 start = vcReadNextWord();
81 uint16 end = vcReadNextWord() + 1;
82
83 do {
84 vcStopAnimation(file, start);
85 } while (++start != end);
86 }
87
vc64_ifSpeech()88 void AGOSEngine::vc64_ifSpeech() {
89 if ((getGameType() == GType_SIMON2 && _subtitles && _language != Common::HE_ISR) ||
90 !_sound->isVoiceActive()) {
91 vcSkipNextInstruction();
92 }
93 }
94
vc65_slowFadeIn()95 void AGOSEngine::vc65_slowFadeIn() {
96 _fastFadeInFlag = 624;
97 _fastFadeCount = 208;
98 if (_windowNum != 4) {
99 _fastFadeInFlag = 768;
100 _fastFadeCount = 256;
101 }
102 _fastFadeInFlag |= 0x8000;
103 _fastFadeOutFlag = false;
104 }
105
vc66_ifEqual()106 void AGOSEngine::vc66_ifEqual() {
107 uint16 a = vcReadNextWord();
108 uint16 b = vcReadNextWord();
109
110 if (vcReadVar(a) != vcReadVar(b))
111 vcSkipNextInstruction();
112 }
113
vc67_ifLE()114 void AGOSEngine::vc67_ifLE() {
115 uint16 a = vcReadNextWord();
116 uint16 b = vcReadNextWord();
117
118 if (vcReadVar(a) >= vcReadVar(b))
119 vcSkipNextInstruction();
120 }
121
vc68_ifGE()122 void AGOSEngine::vc68_ifGE() {
123 uint16 a = vcReadNextWord();
124 uint16 b = vcReadNextWord();
125
126 if (vcReadVar(a) <= vcReadVar(b))
127 vcSkipNextInstruction();
128 }
129
vc69_playSeq()130 void AGOSEngine::vc69_playSeq() {
131 int16 track = vcReadNextWord();
132 int16 loop = vcReadNextWord();
133
134 // Jamieson630:
135 // This is a "play track". The original
136 // design stored the track to play if one was
137 // already in progress, so that the next time a
138 // "fill MIDI stream" event occurred, the MIDI
139 // player would find the change and switch
140 // tracks. We use a different architecture that
141 // allows for an immediate response here, but
142 // we'll simulate the variable changes so other
143 // scripts don't get thrown off.
144 // NOTE: This opcode looks very similar in function
145 // to vc72(), except that vc72() may allow for
146 // specifying a non-valid track number (999 or -1)
147 // as a means of stopping what music is currently
148 // playing.
149 _midi->setLoop(loop != 0);
150 _midi->startTrack(track);
151 }
152
vc70_joinSeq()153 void AGOSEngine::vc70_joinSeq() {
154 // Simon2
155 uint16 track = vcReadNextWord();
156 uint16 loop = vcReadNextWord();
157
158 // Jamieson630:
159 // This sets the "on end of track" action.
160 // It specifies whether to loop the current
161 // track and, if not, whether to switch to
162 // a different track upon completion.
163 if (track != 0xFFFF && track != 999)
164 _midi->queueTrack(track, loop != 0);
165 else
166 _midi->setLoop(loop != 0);
167 }
168
vc71_ifSeqWaiting()169 void AGOSEngine::vc71_ifSeqWaiting() {
170 // Jamieson630:
171 // This command skips the next instruction
172 // unless (1) there is a track playing, AND
173 // (2) there is a track queued to play after it.
174 if (!_midi->isPlaying(true))
175 vcSkipNextInstruction();
176 }
177
vc72_segue()178 void AGOSEngine::vc72_segue() {
179 // Jamieson630:
180 // This is a "play or stop track". Note that
181 // this opcode looks very similar in function
182 // to vc69(), except that this opcode may allow
183 // for specifying a track of 999 or -1 in order to
184 // stop the music. We'll code it that way for now.
185
186 // NOTE: It's possible that when "stopping" a track,
187 // we're supposed to just go on to the next queued
188 // track, if any. Must find out if there is ANY
189 // case where this is used to stop a track in the
190 // first place.
191
192 int16 track = vcReadNextWord();
193 int16 loop = vcReadNextWord();
194
195 if (track == -1 || track == 999) {
196 stopMusic();
197 } else {
198 _midi->setLoop(loop != 0);
199 _midi->startTrack(track);
200 }
201 }
202
vc73_setMark()203 void AGOSEngine::vc73_setMark() {
204 _marks |= (1 << vcReadNextWord());
205 }
206
vc74_clearMark()207 void AGOSEngine::vc74_clearMark() {
208 _marks &= ~(1 << vcReadNextWord());
209 }
210
clearVideoWindow(uint16 num,uint16 color)211 void AGOSEngine_Simon2::clearVideoWindow(uint16 num, uint16 color) {
212 const uint16 *vlut = &_videoWindows[num * 4];
213
214 uint16 xoffs = vlut[0] * 16;
215 uint16 yoffs = vlut[1];
216 uint16 dstWidth = _videoWindows[18] * 16;
217 // TODO: Is there any known connection between dstWidth and the pitch
218 // of the _window4BackScn Surface? If so, we might be able to pass
219 // yoffs as proper y parameter to getBasePtr.
220 byte *dst = (byte *)_window4BackScn->getBasePtr(xoffs, 0) + yoffs * dstWidth;
221
222 setMoveRect(0, 0, vlut[2] * 16, vlut[3]);
223
224 for (uint h = 0; h < vlut[3]; h++) {
225 memset(dst, color, vlut[2] * 16);
226 dst += dstWidth;
227 }
228
229 _window4Flag = 1;
230 }
231
232 } // End of namespace AGOS
233