diff options
| -rw-r--r-- | saga/math.cpp | 72 | ||||
| -rw-r--r-- | saga/math.h | 35 | ||||
| -rw-r--r-- | saga/math_mod.h | 42 | ||||
| -rw-r--r-- | saga/module.mk | 5 | ||||
| -rw-r--r-- | saga/objectmap.cpp | 34 | ||||
| -rw-r--r-- | saga/reinherit.h | 7 | ||||
| -rw-r--r-- | saga/saga.cpp | 7 | ||||
| -rw-r--r-- | saga/sysio.cpp | 65 | ||||
| -rw-r--r-- | saga/xmidi.cpp | 832 | ||||
| -rw-r--r-- | saga/xmidi.h | 117 | ||||
| -rw-r--r-- | saga/xmidi_mod.h | 115 | 
11 files changed, 34 insertions, 1297 deletions
| diff --git a/saga/math.cpp b/saga/math.cpp deleted file mode 100644 index 1c3b12fc93..0000000000 --- a/saga/math.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ -/* - - Description:    -  -    Math routines - - Notes:  -*/ - -#include <stdio.h> -#include <stdlib.h> - -#include "reinherit.h" - -namespace Saga { - -int -MATH_HitTestPoly(R_POINT * points, unsigned int npoints, R_POINT test_point) -{ -	int yflag0; -	int yflag1; -	int inside_flag = 0; -	unsigned int pt; - -	R_POINT *vtx0 = &points[npoints - 1]; -	R_POINT *vtx1 = &points[0]; - -	yflag0 = (vtx0->y >= test_point.y); - -	for (pt = 0; pt < npoints; pt++, vtx1++) { - -		yflag1 = (vtx1->y >= test_point.y); - -		if (yflag0 != yflag1) { - -			if (((vtx1->y - test_point.y) * (vtx0->x - vtx1->x) >= -				(vtx1->x - test_point.x) * (vtx0->y - -				    vtx1->y)) == yflag1) { - -				inside_flag = !inside_flag; -			} -		} -		yflag0 = yflag1; -		vtx0 = vtx1; -	} - -	return inside_flag; -} - -} // End of namespace Saga diff --git a/saga/math.h b/saga/math.h deleted file mode 100644 index 645fd33bd7..0000000000 --- a/saga/math.h +++ /dev/null @@ -1,35 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ -/* - - Description:    -  -    Math routines implementation header - - Notes:  -*/ - -#ifndef SAGA_MATH_H__ -#define  SAGA_MATH_H__ - -#endif				/* SAGA_MATH_H__ */ diff --git a/saga/math_mod.h b/saga/math_mod.h deleted file mode 100644 index 13219fbebd..0000000000 --- a/saga/math_mod.h +++ /dev/null @@ -1,42 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ -/* - - Description:    -  -    Math routines public header - - Notes:  -*/ - -#ifndef SAGA_MATH_MOD_H__ -#define SAGA_MATH_MOD_H__ - -namespace Saga { - -int -MATH_HitTestPoly(R_POINT * points, unsigned int npoints, R_POINT test_point); - -} // End of namespace Saga - -#endif				/* SAGA_MATH_MOD_H__ */ diff --git a/saga/module.mk b/saga/module.mk index fec1996432..766f04a96e 100644 --- a/saga/module.mk +++ b/saga/module.mk @@ -18,7 +18,6 @@ MODULE_OBJS = \  	saga/interface.o \  	saga/isomap.o \  	saga/ite_introproc.o \ -	saga/math.o \  	saga/objectmap.o \  	saga/palanim.o \  	saga/render.o \ @@ -36,7 +35,6 @@ MODULE_OBJS = \  	saga/sthread.o \  	saga/text.o \  	saga/transitions.o \ -	saga/xmidi.o \  	saga/ys_binread.o \  	saga/ys_binwrite.o \  	saga/ys_dl_list.o \ @@ -44,8 +42,7 @@ MODULE_OBJS = \  	saga/sysinput.o \  	saga/systimer.o \  	saga/sysmusic.o \ -	saga/syssound.o \ -	saga/sysio.o +	saga/syssound.o  MODULE_DIRS += \  	saga diff --git a/saga/objectmap.cpp b/saga/objectmap.cpp index c19891179a..5105bb54df 100644 --- a/saga/objectmap.cpp +++ b/saga/objectmap.cpp @@ -43,7 +43,6 @@  #include "cvar_mod.h"  #include "console_mod.h"  #include "gfx_mod.h" -#include "math_mod.h"  #include "font_mod.h"  /* @@ -465,6 +464,39 @@ int OBJECTMAP_Draw(R_SURFACE * ds, R_POINT * imouse_pt, int color, int color2)  	return R_SUCCESS;  } +static bool +MATH_HitTestPoly(R_POINT * points, unsigned int npoints, R_POINT test_point) +{ +	int yflag0; +	int yflag1; +	bool inside_flag = false; +	unsigned int pt; + +	R_POINT *vtx0 = &points[npoints - 1]; +	R_POINT *vtx1 = &points[0]; + +	yflag0 = (vtx0->y >= test_point.y); + +	for (pt = 0; pt < npoints; pt++, vtx1++) { + +		yflag1 = (vtx1->y >= test_point.y); + +		if (yflag0 != yflag1) { + +			if (((vtx1->y - test_point.y) * (vtx0->x - vtx1->x) >= +				(vtx1->x - test_point.x) * (vtx0->y - +				    vtx1->y)) == yflag1) { + +				inside_flag = !inside_flag; +			} +		} +		yflag0 = yflag1; +		vtx0 = vtx1; +	} + +	return inside_flag; +} +  int OBJECTMAP_HitTest(R_POINT * imouse_pt, int *object_num)  { diff --git a/saga/reinherit.h b/saga/reinherit.h index d9b4890256..bb48402dcd 100644 --- a/saga/reinherit.h +++ b/saga/reinherit.h @@ -173,13 +173,6 @@ int TRANSITION_Dissolve(uchar * dst_img,  \*--------------------------------------------------------------------------*/  /* - * System : IO -\*--------------------------------------------------------------------------*/ - -int SYSIO_Init(void); -int SYSIO_Shutdown(void); - -/*   * System : Sound  \*--------------------------------------------------------------------------*/  int SYSSOUND_Init(int enabled); diff --git a/saga/saga.cpp b/saga/saga.cpp index 78252619b0..7fcea4dcf2 100644 --- a/saga/saga.cpp +++ b/saga/saga.cpp @@ -231,11 +231,6 @@ void SagaEngine::go() {  	/* System initialization  	 * \*------------------------------------------------------------- */ -	if (SYSIO_Init() != R_SUCCESS) { - -		return; -	} -  	/* Must initialize system timer module first */  	if (SYSTIMER_InitMSCounter() != R_SUCCESS) { @@ -329,8 +324,6 @@ void R_Shutdown(int param) {  	SYSMUSIC_Shutdown();  	SYSSOUND_Shutdown(); -	SYSIO_Shutdown(); -  	/*  exit(param); */  } diff --git a/saga/sysio.cpp b/saga/sysio.cpp deleted file mode 100644 index 4f688ba607..0000000000 --- a/saga/sysio.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ - -#include "reinherit.h" - -#include "SDL.h" - -namespace Saga { - -/* - * Uses the following modules: -\*--------------------------------------------------------------------------*/ - -/* - * Begin module component -\*--------------------------------------------------------------------------*/ - -int SYSIO_Init(void) -{ - -	int result; - -	/* Initialize SDL library */ -	result = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO); - -	if (result != 0) { - -		R_printf(R_STDERR, "SDL library initialization failed.\n"); - -		return R_FAILURE; -	} - -	R_printf(R_STDOUT, "SDL library initialized.\n"); - -	return R_SUCCESS; -} - -int SYSIO_Shutdown(void) -{ - -	return R_SUCCESS; -} - -} // End of namespace Saga - diff --git a/saga/xmidi.cpp b/saga/xmidi.cpp deleted file mode 100644 index 345fa07c3e..0000000000 --- a/saga/xmidi.cpp +++ /dev/null @@ -1,832 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ -/* - Description:    -  -    XMIDI conversion routines - - Notes:  -  -    Code adapted from XMILoader by Keet ( fox@foxpaws.net ), (C)2000 -*/ - -#include "reinherit.h" - -#include "yslib.h" - -/* Begin module component -\*--------------------------------------------------------------------------*/ -#include "xmidi_mod.h" -#include "xmidi.h" - -namespace Saga { - -int -ConvertEventListToSMF(XMIDIEVENT_LIST * event_list, -    uchar ** smf_ptr, size_t * smf_len) -/*--------------------------------------------------------------------------*\ - * Given a pointer to an event list structure, this function creates and  - * returns a pointer to a Standard Midi File (SMF) image and the image's - * length in bytes. -\*--------------------------------------------------------------------------*/ -{ -	YS_IGNORE_PARAM(event_list); -	YS_IGNORE_PARAM(smf_ptr); -	YS_IGNORE_PARAM(smf_len); - -#if 0 -	SMF_HEADER_CHUNK smfh; -	SMF_TRACK_CHUNK smft; - -	XMIDIEVENT *event_p; - -	uchar *write_p = NULL; -	uchar *smf_buf = NULL; - -	size_t alloc_size; - -	int vlq_len; - -	if ((smf_ptr == NULL) || (smf_len == NULL)) { - -		return R_FAILURE; -	} - -	/* Allocate memory for SMF image -	 * \*---------------------------------------------------------------------- */ -	alloc_size = event_list->smf_size + MIDI_HEADER_LEN + -	    MIDI_TRACK_CHUNK_LEN; - -	/* SMF requires an even size */ -	if (alloc_size % 2) { -		alloc_size++; -	} - -	smf_buf = malloc(alloc_size); -	if (smf_buf == NULL) { -		R_printf(R_STDERR, "Memory allocation error.\n"); - -		return R_FAILURE; -	} - -	memset(smf_ptr, 0, alloc_size); - -	/* Write header chunk -	 * \*---------------------------------------------------------------------- */ -	write_p = smf_buf; - -	smfh.smf_header_len = MIDI_HEADER_CHUNK_LEN; -	smfh.smf_format = 0; -	smfh.smf_ntracks = 1; -	smfh.time_division.ppqn = XMIDI_TIMEDIV; - -	memcpy(write_p, MIDI_HEADER_TAG, 4); -	write_p += 4; - -	ys_write_u32_be(smfh.smf_header_len, write_p, &write_p); -	ys_write_u16_be(smfh.smf_format, write_p, &write_p); -	ys_write_u16_be(smfh.smf_ntracks, write_p, &write_p); -	ys_write_u16_be(smfh.time_division.ppqn, write_p, &write_p); - -	/* Write track chunk -	 * \*---------------------------------------------------------------------- */ -	memcpy(write_p, MIDI_TRACK_TAG, 4); -	write_p += 4; - -	smft.smf_track_len = event_list->smf_size; - -	ys_write_u32_be(smft.smf_track_len, write_p, &write_p); - -	/* Write MIDI events -	 * \*---------------------------------------------------------------------- */ -	event_p = event_list->head; - -	while (event_p != NULL) { - -		vlq_len = WriteVLQ_DW(write_p, event_p->delta_time); -		write_p += vlq_len; - -		/* -		 * R_printf( R_STDOUT,  -		 * "Wrote %d len VLQ. (%d)\n", -		 * vlq_len, -		 * event_p->delta_time ); -		 */ - -		switch (event_p->event) { - -		case MIDI_NOTE_ON: -		case MIDI_NOTE_OFF: -		case MIDI_AFTERTOUCH: -		case MIDI_CONTROLCHANGE: -		case MIDI_PITCHWHEEL: - -			*write_p++ = -			    (uchar) (event_p->event | (uchar) event_p-> -			    channel); -			*write_p++ = event_p->op1; -			*write_p++ = event_p->op2; -			break; - -		case MIDI_PROGRAMCHANGE: -		case MIDI_CHANNELPRESSURE: - -			*write_p = -			    (uchar) (event_p->event | (uchar) event_p-> -			    channel); -			*write_p = event_p->op1; -			break; - -		case MIDI_SYSTEMEXCLUSIVE: - -			*write_p = (uchar) MIDI_NONMIDI; - -			switch (event_p->sysex_op) { - -			case MIDI_SYSEX_TRACKEND: - -				*write_p++ = event_p->sysex_op; -				*write_p++ = (uchar) 0; -				break; - -			case MIDI_SYSEX_TEMPO: - -				*write_p++ = event_p->sysex_op; -				*write_p++ = (uchar) 3; -				/* -				 *write_p++ = event_p->op1; -				 *write_p++ = event_p->op2; -				 *write_p++ = event_p->op3; -				 */ - -				/* Override tempo change */ -				*write_p++ = (uchar) 0x07; -				*write_p++ = (uchar) 0xA1; -				*write_p++ = (uchar) 0x20; -				break; - -			case MIDI_SYSEX_TIMESIG: - -				*write_p++ = event_p->sysex_op; -				*write_p++ = (uchar) 4; -				*write_p++ = event_p->op1; -				*write_p++ = event_p->op2; -				*write_p++ = event_p->op3; -				*write_p++ = event_p->op4; -				break; - -			default: - -				R_printf(R_STDERR, -				    "Error, invalid sysex event type (%d): " -				    "Aborting.\n", event_p->sysex_op); - -				return R_FAILURE; -				break; - -			} -			break; - -		default: -			R_printf(R_STDERR, -			    "Invalid event code encountered; " "aborting.\n"); - -			return R_FAILURE; -			break; -		} - -		event_p = event_p->next_event; -	} - -	*smf_ptr = smf_buf; -	*smf_len = alloc_size; -#endif -	return R_SUCCESS; -} - -int WriteVLQ_DW(char *write_ptr, uint32 value) -{ - -	int vlq_len = 1; -	uint32 pack = value & 0x7F; -	uint x; - -	while (value >>= 7) { -		pack <<= 8; -		pack |= ((value & 0x7F) | 0x80); -		vlq_len++; -	} -	for (x = 0; x < sizeof(uint32); x++) { -		*write_ptr++ = ((char *)(&pack))[x]; -	} - -	return vlq_len; -} - -int XMIDI_Read(const uchar * XMI_img, XMIDIEVENT_LIST * event_list) -{ -	/* XMI header data */ -	const uchar *XMIDI_data; -	uint n_tracks; - -	/* XMIDI data */ -	IFF_ID_CHUNK cat_chunk; -	IFF_ID_CHUNK id_chunk;	/* Present after categeory chunk */ -	XMI_TIMB_CHUNK timbre_chunk;	/* Present after id chunk */ -	XMI_EVENT_CHUNK event_chunk; - -	const uchar *read_p; - -	const uchar *event_data; -	size_t event_data_len; - -	if (XMIDI_ReadXMIHeader(XMI_img, &XMIDI_data, &n_tracks) != R_SUCCESS) { - -		return R_FAILURE; -	} - -	read_p = XMIDI_data; - -	/* Read category chunk -	 * \*------------------------------------------------------------- */ -	ReadIFF_IDChunk(&cat_chunk, read_p, &read_p); - -	if (memcmp(cat_chunk.id_4cc, IFF_CATEGORY_4CC, 4) != 0) { - -		R_printf(R_STDERR, "Error: Category chunk not present.\n"); -		Print4CC(cat_chunk.id_4cc); - -		return R_FAILURE; -	} - -	if (memcmp(cat_chunk.desc_4cc, XMIDI_DESC_4CC, 4) != 0) { - -		R_printf(R_STDERR, -		    "Error: Incorrect category description field.\n"); -		Print4CC(cat_chunk.desc_4cc); - -		return R_FAILURE; -	} - -	/* Read XMIDI ID Chunk -	 * \*------------------------------------------------------------- */ -	ReadIFF_IDChunk(&id_chunk, read_p, &read_p); - -	if (memcmp(id_chunk.id_4cc, IFF_FORMAT_4CC, 4) != 0) { - -		R_printf(R_STDERR, "Error: ID chunk not present.\n"); -		Print4CC(id_chunk.id_4cc); - -		return R_FAILURE; -	} - -	if (memcmp(id_chunk.desc_4cc, XMIDI_DESC_4CC, 4) != 0) { - -		R_printf(R_STDERR, -		    "Error: XMID tag not present in ID chunk: " -		    "Not XMIDI data.\n"); -		Print4CC(id_chunk.desc_4cc); - -		return R_FAILURE; -	} - -	/* Read XMIDI Timbre Chunk -	 * \*------------------------------------------------------------- */ -	ys_read_4cc(timbre_chunk.id_4cc, read_p, &read_p); -	timbre_chunk.chunk_len = ys_read_u32_be(read_p, &read_p); - -	if (memcmp(timbre_chunk.id_4cc, XMIDI_TIMBRE_4CC, 4) != 0) { - -		R_printf(R_STDERR, "Error: Timbre chunk not present.\n"); -		Print4CC(timbre_chunk.id_4cc); - -		return R_FAILURE; -	} - -	/* Read XMIDI Event Chunk -	 * \*------------------------------------------------------------- */ -	read_p += timbre_chunk.chunk_len; - -	ys_read_4cc(event_chunk.id_4cc, read_p, &read_p); -	event_chunk.chunk_len = ys_read_u32_be(read_p, &read_p); - -	if (memcmp(event_chunk.id_4cc, XMIDI_EVENT_4CC, 4) != 0) { - -		R_printf(R_STDERR, "Error: Event chunk not present.\n"); -		Print4CC(event_chunk.id_4cc); - -		return R_FAILURE; -	} - -	/* Read XMIDI Event data -	 * \*------------------------------------------------------------- */ -	event_data = read_p; -	event_data_len = event_chunk.chunk_len; - -	R_printf(R_STDOUT, -	    "Converting %d bytes of event data:\n", event_data_len); - -	XMIDI_ReadEvents(event_list, event_data, event_data_len, n_tracks); - -	/* Process XMIDI Event data -	 * \*------------------------------------------------------------- */ -	ProcessEventList(event_list); - -	return R_SUCCESS; -} - -int -ReadIFF_IDChunk(IFF_ID_CHUNK * chunk, -    const uchar * read_p, const uchar ** read_pp) -{ -	const uchar *chunk_p = read_p; - -	ys_read_4cc(chunk->id_4cc, chunk_p, &chunk_p); - -	chunk->chunk_len = ys_read_u32_be(chunk_p, &chunk_p); - -	ys_read_4cc(chunk->desc_4cc, chunk_p, &chunk_p); - -	if (read_pp != NULL) { -		*read_pp = chunk_p; -	} - -	return R_SUCCESS; -} - -int Print4CC(char *fourcc) -{ -	R_printf(R_STDERR, -	    "FourCC: %c%c%c%c (%X %X %X %X)\n", -	    fourcc[0], fourcc[1], fourcc[2], fourcc[3], -	    fourcc[0], fourcc[1], fourcc[2], fourcc[3]); - -	return R_SUCCESS; -} - -int -XMIDI_ReadXMIHeader(const uchar * XMI_img, -    const uchar ** XMIDI_data, uint * n_tracks) -{ -	const uchar *read_p; - -	IFF_ID_CHUNK id_chunk; -	XMI_INFO_CHUNK info_chunk; - -	*n_tracks = 0; -	*XMIDI_data = NULL; - -	/* Read ID chunk -	 * \*------------------------------------------------------------ */ -	read_p = XMI_img; - -	ys_read_4cc(id_chunk.id_4cc, read_p, &read_p); -	id_chunk.chunk_len = ys_read_u32_be(read_p, &read_p); -	ys_read_4cc(id_chunk.desc_4cc, read_p, &read_p); - -	if (memcmp(id_chunk.id_4cc, IFF_FORMAT_4CC, 4) != 0) { -		R_printf(R_STDERR, "Error: ID chunk not present.\n"); - -		return R_FAILURE; -	} - -	if (memcmp(id_chunk.desc_4cc, XMI_DESC_4CC, 4) != 0) { -		R_printf(R_STDERR, -		    "Error: XDIR tag not present in ID chunk.\n"); - -		return R_FAILURE; -	} - -	/* Read INFO chunk -	 * \*------------------------------------------------------------ */ -	ys_read_4cc(info_chunk.id_4cc, read_p, &read_p); -	info_chunk.chunk_len = ys_read_u32_be(read_p, &read_p); -	info_chunk.n_tracks = ys_read_u16_le(read_p, &read_p); - -	if (memcmp(info_chunk.id_4cc, XMI_INFO_4CC, 4) != 0) { - -		R_printf(R_STDERR, "Error: INFO chunk not present.\n"); - -		return R_FAILURE; -	} - -	*n_tracks = info_chunk.n_tracks; - -	*XMIDI_data = XMI_img + -	    (id_chunk.chunk_len + IFF_ID_CHUNK_HEADERLEN - 4); - -	return R_SUCCESS; -} - -int -XMIDI_ReadEvents(XMIDIEVENT_LIST * event_list, -    const uchar * event_data, size_t event_data_len, uint n_tracks) -{ - -	const uchar *event_data_ptr = event_data; -	size_t event_bytes_left = event_data_len; - -	ulong new_event_time = 0; -	ulong event_time = 0; -	ulong event_len; - -	ulong vlq_len; -	uint data_byte; - -	int channel; -	int event; - -	/*int tempo = MIDI_STD_TEMPO; */ - -	unsigned int sysex_op; -	unsigned int op1; -	unsigned int op2; -	unsigned int op3; -	unsigned int op4; - -	/* Set initial tempo */ -	/* -	 * AddEventToList( event_list, MIDI_SYSEX_TEMPO_LEN + GetLengthAsVLQ( 0 ), 0, MIDI_SYSTEMEXCLUSIVE, 0, MIDI_SYSEX_TEMPO, 0, ); -	 */ - -	while (event_bytes_left > 0) { - -		vlq_len = ReadVLQ2_DW(event_data_ptr, -							  (uint32)event_bytes_left, (uint32 *)&new_event_time); - -		event_time += new_event_time; -		event_data_ptr += vlq_len; -		event_bytes_left -= vlq_len; - -		/* -		 * vlq_len = GetLengthAsVLQ( new_event_time ); -		 * R_printf( R_STDOUT, "Count: %d len VLQ (%d)\n", vlq_len, new_event_time ); -		 */ - -		data_byte = *event_data_ptr++; - -		channel = data_byte & 0x0FU; -		event = data_byte & 0xF0U; - -		switch (event) { - -		case MIDI_NOTE_ON: - -#ifdef XMIPLAY_VERBOSE -			R_printf(R_STDOUT, "MIDI_NOTE_ON event:\n"); -#endif - -			op1 = *(event_data_ptr++); -			op2 = *(event_data_ptr++); - -			AddEventToList(event_list, -			    MIDI_NOTE_ON_LEN, -			    event_time, event, channel, 0, op1, op2, 0, 0); - -			vlq_len = -			    ReadVLQ_DW(event_data_ptr, (uint32)event_bytes_left, -						   (uint32 *)&event_len); -			AddEventToList(event_list, MIDI_NOTE_OFF_LEN, -			    event_time + event_len, MIDI_NOTE_OFF, channel, 0, -			    op1, MIDI_STD_VELOCITY, 0, 0); - -			event_data_ptr += (vlq_len); -			event_bytes_left -= (2 + vlq_len); -			break; - -		case MIDI_AFTERTOUCH: -#ifdef XMIPLAY_VERBOSE -			R_printf(R_STDOUT, "MIDI_AFTERTOUCH event:\n"); -#endif -			op1 = *(event_data_ptr++); -			op2 = *(event_data_ptr++); - -			AddEventToList(event_list, -			    MIDI_AFTERTOUCH_LEN, -			    event_time, event, channel, 0, op1, op2, 0, 0); - -			event_bytes_left -= 2; -			break; - -		case MIDI_CONTROLCHANGE: -#ifdef XMIPLAY_VERBOSE -			R_printf(R_STDOUT, "MIDI_CONTROLCHANGE event:\n"); -#endif -			op1 = *(event_data_ptr++); -			op2 = *(event_data_ptr++); - -			AddEventToList(event_list, -			    MIDI_CONTROLCHANGE_LEN, -			    event_time, event, channel, 0, op1, op2, 0, 0); - -			event_bytes_left -= 2; -			break; - -		case MIDI_PITCHWHEEL: -#ifdef XMIPLAY_VERBOSE -			R_printf(R_STDOUT, "MIDI_PITCHWHEEL event:\n"); -#endif -			op1 = *(event_data_ptr++); -			op2 = *(event_data_ptr++); - -			AddEventToList(event_list, -			    MIDI_PITCHWHEEL_LEN, -			    event_time, event, channel, 0, op1, op2, 0, 0); - -			event_bytes_left -= 2; -			break; - -		case MIDI_PROGRAMCHANGE: -#ifdef XMIPLAY_VERBOSE -			R_printf(R_STDOUT, "MIDI_PROGRAMCHANGE event:\n"); -#endif -			op1 = *(event_data_ptr++); -			AddEventToList(event_list, MIDI_PROGRAMCHANGE_LEN, -			    event_time, event, channel, 0, op1, 0, 0, 0); - -			event_bytes_left--; -			break; - -		case MIDI_CHANNELPRESSURE: -#ifdef XMIPLAY_VERBOSE -			R_printf(R_STDOUT, "MIDI_CHANNELPRESSURE event:\n"); -#endif -			op1 = *(event_data_ptr++); -			AddEventToList(event_list, MIDI_CHANNELPRESSURE_LEN, -			    event_time, event, channel, 0, op1, 0, 0, 0); - -			event_bytes_left--; -			break; - -		case MIDI_SYSTEMEXCLUSIVE: - -			sysex_op = (byte) * event_data_ptr++; -			event_bytes_left--; - -			if (data_byte == MIDI_NONMIDI) { - -				switch (sysex_op) { - -				case MIDI_SYSEX_TRACKEND: -					R_printf(R_STDOUT, -					    "Track end encountered.\n"); -					AddEventToList(event_list, -					    MIDI_SYSEX_TRACKEND_LEN, -					    event_time, event, channel, -					    sysex_op, op1, op2, 0, 0); -					event_bytes_left = 0; -					break; - -				case MIDI_SYSEX_TEMPO: -					event_data_ptr++;	/*(skip length VLQ) (always 3) */ - -					op1 = (byte) * event_data_ptr++; -					op2 = (byte) * event_data_ptr++; -					op3 = (byte) * event_data_ptr++; -					AddEventToList(event_list, -					    MIDI_SYSEX_TEMPO_LEN, event_time, -					    event, channel, sysex_op, op1, op2, -					    op3, 0); -					/* -					 * R_printf( R_STDOUT, "Adding tempo change event. :%X %X %X\n", op1, op2, op3 ); -					 */ -					event_bytes_left -= 4; -					break; - -				case MIDI_SYSEX_TIMESIG: -					event_data_ptr++;	/*(skip length VLQ) (always 4) */ - -					op1 = (byte) * event_data_ptr++; -					op2 = (byte) * event_data_ptr++; -					op3 = (byte) * event_data_ptr++; -					op4 = (byte) * event_data_ptr++; -					AddEventToList(event_list, -					    MIDI_SYSEX_TIMESIG_LEN, event_time, -					    event, channel, sysex_op, op1, op2, -					    op3, op4); - -					/* -					 * R_printf( R_STDOUT, "Adding time signature event. :%X %X %X %X\n", op1, op2, op3, op4 ); -					 */ -					event_bytes_left -= 5; -					break; - -				default: -					R_printf(R_STDERR, -					    "Unhandled sysex nonmidi event, aborting.\n"); -					R_printf(R_STDERR, "%X %X %X %X", -					    *event_data_ptr, -					    *(event_data_ptr + 1), -					    *(event_data_ptr + 2), -					    *(event_data_ptr + 3)); - -					event_bytes_left = 0; -					break; - -				} -			} else { -				R_printf(R_STDERR, -				    "Unhandled sysex event, aborting.\n"); -				event_bytes_left = 0; -			} - -			break; - -		default: -			R_printf(R_STDERR, -			    "Invalid event code encountered; aborting.\n"); -			event_bytes_left = 0; -			break; -		} - -	}			/* end while ( event_bytes_left > 0 ) */ - -	return R_SUCCESS; -} - -int GetLengthAsVLQ(uint32 data) -{ - -	int len = 1; - -	while (data >>= 7) -		len++; -	return len; - -} - -uint32 ReadVLQ_DW(const uchar *data, uint32 bytes_left, uint32 * value) -{ -	byte byte; -	uint32 vlq_len = 0; -	*value = 0; - -	do { -		if (bytes_left <= 0) -			return 0; -		byte = *data++; -		bytes_left--; -		vlq_len++; -		*value = (*value << 7) | (byte & 0x7F); -	} while (byte & 0x80); - -	return vlq_len; -} - -uint32 ReadVLQ2_DW(const uchar *data, uint32 bytes_left, uint32 * value) -{ - -	byte byte; -	uint32 vlq_len = 0; -	*value = 0; - -	while (!((byte = *data++) & 0x80)) { -		if (bytes_left <= 0) -			return 0; -		bytes_left--; -		vlq_len++; -		(*value) += byte; -	} - -	return vlq_len; -} - -int -AddEventToList(XMIDIEVENT_LIST * event_list, int smf_size, int time, int event, -    int channel, int sysex_op, int op1, int op2, int op3, int op4) -{ - -	XMIDIEVENT *new_event; -	XMIDIEVENT *search_ptr = event_list->tail; - -	new_event = (XMIDIEVENT *)malloc(sizeof(XMIDIEVENT)); - -	if (new_event == NULL) { -		R_printf(R_STDERR, -		    "Error: Out of memory allocating XMIDI event list entry."); -		return -1; -	} - -	new_event->next_event = NULL; -	new_event->prev_event = NULL; - -	if (event_list->head == NULL) { -		/* Set up new list */ -		event_list->head = new_event; -		event_list->tail = new_event; -	} else { -		/* List isn't empty */ -		if ((unsigned int)time >= event_list->tail->delta_time) { - -			/* If this is the most recent event, append */ -			event_list->tail->next_event = new_event; -			new_event->prev_event = event_list->tail; -			event_list->tail = new_event; - -		} else { -			/* Otherwise scan list backwards and insert in proper position */ -			while (search_ptr != NULL) { - -				if ((unsigned int)time >= -				    search_ptr->delta_time) { -					/* Insert entry */ -					new_event->next_event = -					    search_ptr->next_event; -					new_event->prev_event = search_ptr; - -					search_ptr->next_event->prev_event = -					    new_event; -					search_ptr->next_event = new_event; -					break; -				} -				search_ptr = search_ptr->prev_event; -			} -		} -	} - -	new_event->smf_size = smf_size; -	new_event->delta_time = time; - -	new_event->sysex_op = sysex_op; -	new_event->event = (byte) event; -	new_event->channel = (byte) channel; -	new_event->op1 = (byte) op1; -	new_event->op2 = (byte) op2; -	new_event->op3 = (byte) op3; -	new_event->op4 = (byte) op4; - -#ifdef XMIPLAY_VERBOSE -	R_printf(R_STDOUT, -	    "Added event: Time: %d Tempo: %d Event: %d Chan: %d Op1: %d Op2: %d\n", -	    new_event->delta_time, new_event->tempo, new_event->event, -	    new_event->channel, new_event->op1, new_event->op2); -#endif -	return 0; -} - -int ProcessEventList(XMIDIEVENT_LIST * event_list) -{ -	XMIDIEVENT *convert_ptr = event_list->head; -	int last_time = 0; -	int delta = 0; - -	while (convert_ptr != NULL) { - -		delta = convert_ptr->delta_time - last_time; -		if (delta < 0) -			R_printf(R_STDERR, -			    "Error: Negative delta time found."); -		last_time = convert_ptr->delta_time; -		convert_ptr->delta_time = delta; - -		/* Update smf size count */ -		event_list->smf_size += -		    (convert_ptr->smf_size + GetLengthAsVLQ(delta)); -		convert_ptr = convert_ptr->next_event; -	} - -	R_printf(R_STDOUT, -	    "ProcessEventList(): %d bytes of SMF data processed.\n", -	    event_list->smf_size); - -	return 0; -} - -int XMIDI_Free(XMIDIEVENT_LIST * event_list) -{ - -	XMIDIEVENT *free_ptr = event_list->head; -	XMIDIEVENT *temp_ptr; - -	while (free_ptr != NULL) { -		temp_ptr = free_ptr->next_event; -		free(free_ptr); -		free_ptr = temp_ptr; -	} - -	return 0; - -} - -} // End of namespace Saga - diff --git a/saga/xmidi.h b/saga/xmidi.h deleted file mode 100644 index 81b9f69fac..0000000000 --- a/saga/xmidi.h +++ /dev/null @@ -1,117 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ -/* - Description:    -  -    XMIDI conversion routines - - Notes:  -  -    Code adapted from XMILoader by Keet ( fox@foxpaws.net ), (C)2000 -*/ - -#ifndef SAGA_XMIDI_H_ -#define SAGA_XMIDI_H_ - -namespace Saga { - -#define XMIDI_TIMEDIV 0x3C - -/* XMIDI/IFF 4CC codes -\*--------------------------------------------------------------------------*/ -#define IFF_FORMAT_4CC   "FORM" -#define IFF_CATEGORY_4CC "CAT " - -#define XMI_DESC_4CC     "XDIR" -#define XMI_INFO_4CC     "INFO" - -#define XMIDI_DESC_4CC   "XMID" -#define XMIDI_TIMBRE_4CC "TIMB" -#define XMIDI_EVENT_4CC  "EVNT" - -/* IFF/XMI Data structures -\*--------------------------------------------------------------------------*/ - -struct IFF_ID_CHUNK { -	char id_4cc[4];	/* 4cc */ -	ulong chunk_len;	/* u32_be */ -	char desc_4cc[4];	/* 4cc */ -}; - -#define IFF_ID_CHUNK_HEADERLEN 12 - -struct XMI_INFO_CHUNK { -	char id_4cc[4];	/* 4cc */ -	ulong chunk_len;	/* u32_be */ -	uint n_tracks;	/* u16_le */ -}; - -struct XMI_TIMB_CHUNK { -	char id_4cc[4];	/* 4cc */ -	ulong chunk_len;	/* u32_be */ -}; - -struct XMI_EVENT_CHUNK { -	char id_4cc[4];	/* 4cc */ -	ulong chunk_len;	/* u32_be */ -}; - -typedef struct SMF_HEADER_CHUNK_tag { -	char smf_id[4];	/* u8 */ -	unsigned int smf_header_len;	/* u32_be */ -	unsigned short smf_format;	/* u16_be */ -	unsigned short smf_ntracks;	/* u16_be */ -	union { -		unsigned short ppqn;	/* u16_be */ -		signed char smpte[2]; -	} time_division; -} SMF_HEADER_CHUNK; - -struct SMF_TRACK_CHUNK { -	char smf_track_id[4]; -	unsigned int smf_track_len; -}; - -#define MIDI_HEADER_LEN 14 -#define MIDI_HEADER_CHUNK_LEN 6 -#define MIDI_TRACK_CHUNK_LEN 8 - -#define MIDI_HEADER_TAG "MThd" -#define MIDI_TRACK_TAG  "MTrk" - -int XMIDI_ReadXMIHeader(const uchar *XMI_img, const uchar **XMIDI_data, uint *n_tracks); -int ReadIFF_IDChunk(IFF_ID_CHUNK *chunk, const uchar *read_p, const uchar **read_pp); -int Print4CC(char *fourcc); -int XMIDI_ReadEvents(XMIDIEVENT_LIST *event_list, const uchar *event_data,  -					 size_t event_data_len, uint n_tracks); -int WriteVLQ_DW(char *write_ptr, uint32 value); -uint32 ReadVLQ_DW(const uchar *data, uint32 bytes_left, uint32 *value); -uint32 ReadVLQ2_DW(const uchar *data, uint32 bytes_left, uint32 *value); -int GetLengthAsVLQ(uint32 data); -int AddEventToList(XMIDIEVENT_LIST *event_list, int smf_size, int time, -	    int event, int channel, int sysex_op, int op1, int op2, int op3, int op4); -int ProcessEventList(XMIDIEVENT_LIST *event_list); -void PrintMidiOutError(unsigned long err); -}				// End of namespace Saga - -#endif				/* SAGA_XMIDI_H_ */ diff --git a/saga/xmidi_mod.h b/saga/xmidi_mod.h deleted file mode 100644 index 8743f78c32..0000000000 --- a/saga/xmidi_mod.h +++ /dev/null @@ -1,115 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2004 The ScummVM project - * - * The ReInherit Engine is (C)2000-2003 by Daniel Balsom. - * - * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. - * - * $Header$ - * - */ -/* - Description:    -  -    XMIDI conversion routines - module header - - Notes:  -*/ - -#ifndef SAGA_XMIDI_MOD_H_ -#define SAGA_XMIDI_MOD_H_ - -namespace Saga { - -#define MIDI_STD_VELOCITY 0x7F -#define MIDI_STD_TEMPO    0x0007A120L	/* 500000 */ - -/* MIDI Events  -\*--------------------------------------------------------------------------*/ -enum R_MIDI_EVENTS { -	MIDI_NOTE_ON = 0x90, -	MIDI_NOTE_OFF = 0x80, -	MIDI_AFTERTOUCH = 0xA0, -	MIDI_CONTROLCHANGE = 0xB0, -	MIDI_PROGRAMCHANGE = 0xC0, -	MIDI_CHANNELPRESSURE = 0xD0, -	MIDI_PITCHWHEEL = 0xE0, -	MIDI_SYSTEMEXCLUSIVE = 0xF0, - -	MIDI_NONMIDI = 0xFF, - -	MIDI_SYSEX_SEQNUM = 0x00, -	MIDI_SYSEX_TEXT = 0x01, -	MIDI_SYSEX_COPYRIGHT = 0x02, -	MIDI_SYSEX_SEQNAME = 0x03, -	MIDI_SYSEX_INSTRUMENT = 0x04, -	MIDI_SYSEX_LYRIC = 0x05, -	MIDI_SYSEX_MARKER = 0x06, -	MIDI_SYSEX_CUEPOINT = 0x07, - -	MIDI_SYSEX_CHANNEL = 0x20, -	MIDI_SYSEX_PORTNUM = 0x21, -	MIDI_SYSEX_TRACKEND = 0x2F, -	MIDI_SYSEX_TEMPO = 0x51, -	MIDI_SYSEX_TIMESIG = 0x58, - -	MIDI_SYSEX_PROPRIETARY = 0x7F -}; - -enum MIDI_EVENT_LENGTHS { -	MIDI_NOTE_ON_LEN = 3, -	MIDI_NOTE_OFF_LEN = 3, -	MIDI_AFTERTOUCH_LEN = 3, -	MIDI_CONTROLCHANGE_LEN = 3, -	MIDI_PITCHWHEEL_LEN = 3, - -	MIDI_PROGRAMCHANGE_LEN = 2, -	MIDI_CHANNELPRESSURE_LEN = 2, - -	MIDI_SYSEX_TRACKEND_LEN = 3, -	MIDI_SYSEX_TEMPO_LEN = 6, -	MIDI_SYSEX_TIMESIG_LEN = 7 -}; - -struct XMIDIEVENT { -	XMIDIEVENT *prev_event; -	XMIDIEVENT *next_event; - -	size_t smf_size;	/* Size of event in SMF format */ - -	ulong delta_time; - -	uchar event; -	uchar channel; -	uchar sysex_op; -	uchar op1; -	uchar op2; -	uchar op3; -	uchar op4; -	uchar pad; -}; - -struct XMIDIEVENT_LIST { -	XMIDIEVENT *head; -	XMIDIEVENT *tail; -	int smf_size; -}; - -int XMIDI_Read(const uchar *XMI_img, XMIDIEVENT_LIST *event_list); -int XMIDI_Free(XMIDIEVENT_LIST *event_list); - -}				// End of namespace Saga - -#endif				/* SAGA_XMIDI_MOD_H_ */ | 
