aboutsummaryrefslogtreecommitdiff
path: root/engines/parallaction/music.cpp
blob: 8b0aa3526281e2ee68e361945d1ff9f883f0343e (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
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2006 The ScummVM project
 *
 * 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 "common/file.h"
#include "parallaction/parallaction.h"

namespace Parallaction {

// NOTE: these two guys are never changed.
static int16 _musicFlag2 = 1;
static int16 _musicFlag1 = 1;

static bool _allocated = false;
static bool _playing = false;
// UNUSED
// static char byte_14D22[10] = { 0 };
static const char *_musicFilesNames[] = { "intro", "dino", "donna", "nuts", "soft", "boogie2" };
static uint16 _musicFilesSizes[] = { 18805, 5486, 6195, 13006, 15818, 7507 };
static byte *_musicBits = NULL;

// TODO
// move this into a proper midi driver and decode the numeric commands
void _music_command(const void*, const void*, const void*, const void*) {

}

void stopMusic() {

	if (_musicFlag1 == 0 && _musicFlag2 == 0) return;
	if (_playing == false) return;
	if (_allocated == false) return;

	_music_command((const void*)4, (const void*)0, (const void*)0, (const void*)0);     // stop
	_music_command((const void*)5, (const void*)0, (const void*)0, (const void*)0);     // reset timer

	memFree(_musicBits);

	_allocated = false;
	_playing = false;

	return;
}

void playMusic() {

	if (_musicFlag1 == 0 && _musicFlag2 == 0) return;
	if (_playing == true) return;
	if (_allocated == false) return;

	_music_command(0, 0, 0, 0);     // init driver
	_music_command((const void*)1, 0, 0, 0);     // init timer
	_music_command((const void*)17, (const void*)1, 0, 0);    // set source segment
	_music_command((const void*)7, (const void*)1, 0, 0);     // set source offset and do SOMETHING

	// FIXME: casting pointer to uint32
	_music_command((const void*)2, (const void*)_musicBits, 0, 0);    // play

	_playing = true;

	return;
}

void loadMusic(const char *filename) {

	uint16 _di = 0;

	if (!scumm_strnicmp(_location, "museo", 5)) return;
	if (!scumm_strnicmp(_location, "intgrottadopo", 13)) return;
	if (!scumm_strnicmp(_location, "caveau", 6)) return;
	if (!scumm_strnicmp(_location, "estgrotta", 9)) return;
	if (!scumm_strnicmp(_location, "plaza1", 6)) return;
	if (!scumm_strnicmp(_location, "endtgz", 6)) return;

	if (_musicFlag1 == 0 && _musicFlag2 == 0) return;
	if (_allocated == true) return;

//  UNUSED
//	strcpy(byte_14D22, filename);

	for (uint16 _si = 0; _si < 6; _si++) {
		if (!strcmp(filename, _musicFilesNames[_si])) {
			_di = _musicFilesSizes[_si];
		}
	}

	if (_di == 0 ) return;

	char path[PATH_LEN];
	sprintf(path, "%s.mid", filename);

	Common::File stream;

	if (!stream.open(path))
		return;

	_musicBits = (byte*)memAlloc(_di);
	if (!_musicBits) return;

	stream.read(_musicBits, _di);
	stream.close();

	_allocated = true;

	return;
}

} // namespace Parallaction